Page Menu
Home
c4science
Search
Configure Global Search
Log In
Files
F73934529
test_model.cpp
No One
Temporary
Actions
Download File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Subscribers
None
File Metadata
Details
File Info
Storage
Attached
Created
Thu, Jul 25, 08:57
Size
2 KB
Mime Type
text/x-c
Expires
Sat, Jul 27, 08:57 (2 d)
Engine
blob
Format
Raw Data
Handle
19300676
Attached To
rTAMAAS tamaas
test_model.cpp
View Options
/**
*
* @author Lucas Frérot <lucas.frerot@epfl.ch>
*
* @section LICENSE
*
* Copyright (©) 2017 EPFL (Ecole Polytechnique Fédérale de
* Lausanne) Laboratory (LSMS - Laboratoire de Simulation en Mécanique des
* Solides)
*
* Tamaas is free software: you can redistribute it and/or modify it under the
* terms of the GNU Lesser General Public License as published by the Free
* Software Foundation, either version 3 of the License, or (at your option) any
* later version.
*
* Tamaas is distributed in the hope that it will be useful, but WITHOUT ANY
* WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
* A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
* details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with Tamaas. If not, see <http://www.gnu.org/licenses/>.
*
*/
/* -------------------------------------------------------------------------- */
#include "model_factory.hh"
#include "test.hh"
#include <random>
/* -------------------------------------------------------------------------- */
using
namespace
tamaas
;
TEST
(
TestModel
,
applyElasticity
)
{
auto
model
=
ModelFactory
::
createModel
(
model_type
::
volume_2d
,
{
1.
,
1.
,
1.
},
{
1
,
1
,
1
});
Grid
<
Real
,
3
>
gradient
({
1
,
1
,
1
},
9
),
stress
({
1
,
1
,
1
},
9
);
// Random data objects
std
::
random_device
rnd
;
std
::
mt19937
mt
(
rnd
());
std
::
normal_distribution
<>
dis
(
0
,
1
);
// Filling gradient with random data (sequential)
for
(
auto
&
du
:
gradient
)
du
=
dis
(
mt
);
std
::
uniform_real_distribution
<>
unif
(
0
,
0.5
);
model
->
setElasticity
(
std
::
abs
(
dis
(
mt
))
*
unif
(
mt
),
unif
(
mt
));
// Computing stresses with seperate array
model
->
applyElasticity
(
stress
,
gradient
);
// Checking correct isotropic elasticity
auto
mu
=
model
->
getShearModulus
(),
nu
=
model
->
getPoissonRatio
();
auto
lambda
=
2
*
mu
*
nu
/
(
1
-
2
*
nu
);
MatrixProxy
<
Real
,
3
,
3
>
grad
(
gradient
(
0
));
auto
trace
=
grad
.
trace
();
Matrix
<
Real
,
3
,
3
>
sigma
;
for
(
UInt
i
=
0
;
i
<
3
;
++
i
)
for
(
UInt
j
=
0
;
j
<
3
;
++
j
)
sigma
(
i
,
j
)
=
(
i
==
j
)
*
lambda
*
trace
+
mu
*
(
grad
(
i
,
j
)
+
grad
(
j
,
i
));
EXPECT_TRUE
(
compare
(
stress
,
sigma
,
AreFloatEqual
()))
<<
"Elasticity fail"
;
// Computing stress with same array
model
->
applyElasticity
(
gradient
,
gradient
);
EXPECT_TRUE
(
compare
(
gradient
,
stress
,
AreFloatEqual
()))
<<
"Applying elasticity in-place fail"
;
}
Event Timeline
Log In to Comment