Skip to content

Commit 34a92d2

Browse files
th-skamhugtalbot
andauthored
[HyperElastic] Enable unit tests for off-diagonal elements of the elasticity tensor (#5743)
* [HyperElastic][Test] Test off-diagonal entries in ElasticityTensor - account for the 2 factor * [HyperElastic] Review suggestion - add comments --------- Co-authored-by: Hugo <hugo.talbot@sofa-framework.org>
1 parent 90d3336 commit 34a92d2

File tree

1 file changed

+5
-5
lines changed

1 file changed

+5
-5
lines changed

Sofa/Component/SolidMechanics/FEM/HyperElastic/tests/Material_test.cpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -186,8 +186,7 @@ void testElasticityTensorFromSecondPiolaKirchhoff(
186186

187187
static constexpr Real h = 1e-6;
188188

189-
// for (sofa::Size i = 0; i < Matrix6::size(); ++i)
190-
for (sofa::Size i : {0, 2, 5}) //only the diagonal terms
189+
for (sofa::Size i = 0; i < Matrix6::size(); ++i)
191190
{
192191
const MatrixSym pk2Plus =
193192
perturbedPK2(material, materialParameters, strain, h, i);
@@ -199,12 +198,13 @@ void testElasticityTensorFromSecondPiolaKirchhoff(
199198
const MatrixSym centralDifference = (pk2Plus - pk2Minus) / (2 * h);
200199

201200
//ElasticityTensor = 2 * dPK2/dC
202-
const MatrixSym elasticityTensorApprox = 2 * centralDifference;
201+
MatrixSym elasticityTensorApprox = 2 * centralDifference;
203202

204203
//compare the approximation of the elasticity tensor
205-
// for (sofa::Size j = 0; j < Matrix6::size(); ++j)
206-
for (sofa::Size j : {0, 2, 5}) //only the diagonal terms
204+
for (sofa::Size j = 0; j < Matrix6::size(); ++j)
207205
{
206+
// Off-diagonal terms are stored doubled; the tensor approximation must be scaled accordingly
207+
if (j == 1 || j == 3 || j == 4) elasticityTensorApprox[j] *= 2.;
208208
EXPECT_NEAR(elasticityTensor(i,j), elasticityTensorApprox[j], 1e-7) << "i = " << i << ", j = " << j;
209209
}
210210
}

0 commit comments

Comments
 (0)