Commit 7e50a635 authored by GILLES Sebastien's avatar GILLES Sebastien

#20 Second Piola Kirchhoff operator: separate the cases in which inversion occurs or not.

parent 4dc2a972
Pipeline #101474 failed
......@@ -171,6 +171,20 @@ namespace MoReFEM
void SameUnknown(::MoReFEM::Internal::assemble_into_matrix do_assemble_into_matrix,
::MoReFEM::Internal::assemble_into_vector do_assemble_into_vector) const;
/*!
* \brief Case when the test function uses up the same \a Unknown but the values are not physical and an exception should be thrown.
*
* \param[in] do_assemble_into_matrix Whether we're assembling into a matrix or not.
* \param[in] do_assemble_into_vector Whether we're assembling into a vector or not.
*
* The three cases yes/yes, yes/no and no/yes are considered in the unit tests.
*/
void SameUnknownInverted(::MoReFEM::Internal::assemble_into_matrix do_assemble_into_matrix,
::MoReFEM::Internal::assemble_into_vector do_assemble_into_vector) const;
/*!
* \brief Case when the test function uses up a different \a Unknown with the same shape label.
*
......
......@@ -68,14 +68,6 @@ namespace MoReFEM
GlobalVector previous_iteration_p1(vector_p1);
GlobalMatrix matrix_inverted_elements_p1_p1(numbering_subset_p1, numbering_subset_p1);
AllocateGlobalMatrix(god_of_dof, matrix_inverted_elements_p1_p1);
GlobalVector vector_inverted_elements_p1(numbering_subset_p1);
AllocateGlobalVector(god_of_dof, vector_inverted_elements_p1);
GlobalVector previous_iteration_inverted_elements_p1(vector_inverted_elements_p1);
const auto& mesh = god_of_dof.GetMesh();
const auto dimension = mesh.GetDimension();
......@@ -84,24 +76,15 @@ namespace MoReFEM
vector_p1.ZeroEntries(__FILE__, __LINE__);
previous_iteration_p1.ZeroEntries(__FILE__, __LINE__);
matrix_inverted_elements_p1_p1.ZeroEntries(__FILE__, __LINE__);
vector_inverted_elements_p1.ZeroEntries(__FILE__, __LINE__);
previous_iteration_inverted_elements_p1.ZeroEntries(__FILE__, __LINE__);
switch(dimension)
{
case 3:
previous_iteration_p1.SetValue(3, 2., INSERT_VALUES, __FILE__, __LINE__);
previous_iteration_inverted_elements_p1.SetValue(3, -2., INSERT_VALUES, __FILE__, __LINE__);
[[fallthrough]];
case 2:
previous_iteration_p1.SetValue(2, 2., INSERT_VALUES, __FILE__, __LINE__);
previous_iteration_inverted_elements_p1.SetValue(2, -2., INSERT_VALUES, __FILE__, __LINE__);
[[fallthrough]];
case 1:
previous_iteration_inverted_elements_p1.SetValue(0, 1., INSERT_VALUES, __FILE__, __LINE__);
previous_iteration_inverted_elements_p1.SetValue(1, 2., INSERT_VALUES, __FILE__, __LINE__);
previous_iteration_p1.SetValue(0, -1., INSERT_VALUES, __FILE__, __LINE__);
previous_iteration_p1.SetValue(1, -2., INSERT_VALUES, __FILE__, __LINE__);
break;
......@@ -112,22 +95,12 @@ namespace MoReFEM
GlobalMatrixWithCoefficient matrix(matrix_p1_p1, 1.);
GlobalVectorWithCoefficient vec(vector_p1, 1.);
previous_iteration_inverted_elements_p1.Assembly(__FILE__, __LINE__);
GlobalMatrixWithCoefficient matrix_inverted_elements(matrix_inverted_elements_p1_p1, 1.);
GlobalVectorWithCoefficient vec_inverted_elements(vector_inverted_elements_p1, 1.);
if (do_assemble_into_matrix == assemble_into_matrix::yes
&& do_assemble_into_vector == assemble_into_vector::yes)
{
pk2_operator.Assemble(std::make_tuple(std::ref(matrix), std::ref(vec)),
previous_iteration_p1);
BOOST_CHECK_THROW(pk2_operator.Assemble(std::make_tuple(std::ref(matrix_inverted_elements), std::ref(vec_inverted_elements)),
previous_iteration_inverted_elements_p1), Exception);
/* BOOST_CHECK_NO_THROW */(CheckMatrix(god_of_dof,
matrix_p1_p1,
GetExpectedMatrixP1P1(dimension),
......@@ -146,9 +119,6 @@ namespace MoReFEM
pk2_operator.Assemble(std::make_tuple(std::ref(matrix)),
previous_iteration_p1);
BOOST_CHECK_THROW(pk2_operator.Assemble(std::make_tuple(std::ref(matrix_inverted_elements)),
previous_iteration_inverted_elements_p1), Exception);
/* BOOST_CHECK_NO_THROW */(CheckMatrix(god_of_dof,
matrix_p1_p1,
GetExpectedMatrixP1P1(dimension),
......@@ -161,9 +131,6 @@ namespace MoReFEM
pk2_operator.Assemble(std::make_tuple(std::ref(vec)),
previous_iteration_p1);
BOOST_CHECK_THROW(pk2_operator.Assemble(std::make_tuple(std::ref(vec_inverted_elements)),
previous_iteration_inverted_elements_p1), Exception);
/* BOOST_CHECK_NO_THROW */(CheckVector(god_of_dof,
vector_p1,
GetExpectedVectorP1P1(dimension),
......@@ -174,6 +141,95 @@ namespace MoReFEM
}
}
void Model::SameUnknownInverted(::MoReFEM::Internal::assemble_into_matrix do_assemble_into_matrix,
::MoReFEM::Internal::assemble_into_vector do_assemble_into_vector) const
{
const auto& god_of_dof = GetGodOfDof(EnumUnderlyingType(MeshIndex::mesh));
decltype(auto) unknown_manager = UnknownManager::GetInstance(__FILE__, __LINE__);
const auto& felt_space =
god_of_dof.GetFEltSpace(EnumUnderlyingType(FEltSpaceIndex::felt_space));
const auto& displacement_p1_ptr =
unknown_manager.GetUnknownPtr(EnumUnderlyingType(UnknownIndex::displacement_p1));
StiffnessOperatorType pk2_operator(felt_space,
displacement_p1_ptr,
displacement_p1_ptr,
*solid_,
GetTimeManager(),
hyperelastic_law_parent::GetHyperelasticLawPtr(),
nullptr,
nullptr);
decltype(auto) numbering_subset_p1 =
god_of_dof.GetNumberingSubset(EnumUnderlyingType(NumberingSubsetIndex::displacement_p1));
GlobalMatrix matrix_p1_p1(numbering_subset_p1, numbering_subset_p1);
AllocateGlobalMatrix(god_of_dof, matrix_p1_p1);
GlobalVector vector_p1(numbering_subset_p1);
AllocateGlobalVector(god_of_dof, vector_p1);
GlobalVector previous_iteration_p1(vector_p1);
const auto& mesh = god_of_dof.GetMesh();
const auto dimension = mesh.GetDimension();
{
matrix_p1_p1.ZeroEntries(__FILE__, __LINE__);
vector_p1.ZeroEntries(__FILE__, __LINE__);
previous_iteration_p1.ZeroEntries(__FILE__, __LINE__);
switch(dimension)
{
case 3:
previous_iteration_p1.SetValue(3, -2., INSERT_VALUES, __FILE__, __LINE__);
[[fallthrough]];
case 2:
previous_iteration_p1.SetValue(2, -2., INSERT_VALUES, __FILE__, __LINE__);
[[fallthrough]];
case 1:
previous_iteration_p1.SetValue(0, 1., INSERT_VALUES, __FILE__, __LINE__);
previous_iteration_p1.SetValue(1, 2., INSERT_VALUES, __FILE__, __LINE__);
break;
}
previous_iteration_p1.Assembly(__FILE__, __LINE__);
GlobalMatrixWithCoefficient matrix_inverted_elements(matrix_p1_p1, 1.);
GlobalVectorWithCoefficient vec_inverted_elements(vector_p1, 1.);
if (do_assemble_into_matrix == assemble_into_matrix::yes
&& do_assemble_into_vector == assemble_into_vector::yes)
{
BOOST_CHECK_THROW(pk2_operator.Assemble(std::make_tuple(std::ref(matrix_inverted_elements), std::ref(vec_inverted_elements)),
previous_iteration_p1), Exception);
}
else if (do_assemble_into_matrix == assemble_into_matrix::yes
&& do_assemble_into_vector == assemble_into_vector::no)
{
BOOST_CHECK_THROW(pk2_operator.Assemble(std::make_tuple(std::ref(matrix_inverted_elements)),
previous_iteration_p1), Exception);
}
else if (do_assemble_into_matrix == assemble_into_matrix::no
&& do_assemble_into_vector == assemble_into_vector::yes)
{
BOOST_CHECK_THROW(pk2_operator.Assemble(std::make_tuple(std::ref(vec_inverted_elements)),
previous_iteration_p1), Exception);
}
}
}
......
......@@ -63,19 +63,19 @@ PRAGMA_DIAGNOSTIC(push)
BOOST_FIXTURE_TEST_SUITE(same_unknown_for_test, fixture_type)
BOOST_AUTO_TEST_CASE(same_unknown_for_test_matrix_only)
BOOST_AUTO_TEST_CASE(matrix_only)
{
GetModel().SameUnknown(assemble_into_matrix::yes, assemble_into_vector::no);
}
BOOST_AUTO_TEST_CASE(same_unknown_for_test_vector_only)
BOOST_AUTO_TEST_CASE(vector_only)
{
GetModel().SameUnknown(assemble_into_matrix::no, assemble_into_vector::yes);
}
BOOST_AUTO_TEST_CASE(same_unknown_for_test_matrix_and_vector)
BOOST_AUTO_TEST_CASE(matrix_and_vector)
{
GetModel().SameUnknown(assemble_into_matrix::yes, assemble_into_vector::yes);
}
......@@ -83,6 +83,28 @@ BOOST_FIXTURE_TEST_SUITE(same_unknown_for_test, fixture_type)
BOOST_AUTO_TEST_SUITE_END()
BOOST_FIXTURE_TEST_SUITE(same_unknown_triangles_inverted, fixture_type)
BOOST_AUTO_TEST_CASE(matrix_only)
{
GetModel().SameUnknownInverted(assemble_into_matrix::yes, assemble_into_vector::no);
}
BOOST_AUTO_TEST_CASE(vector_only)
{
GetModel().SameUnknownInverted(assemble_into_matrix::no, assemble_into_vector::yes);
}
BOOST_AUTO_TEST_CASE(matrix_and_vector)
{
GetModel().SameUnknownInverted(assemble_into_matrix::yes, assemble_into_vector::yes);
}
BOOST_AUTO_TEST_SUITE_END()
BOOST_FIXTURE_TEST_SUITE(different_unknown, fixture_type)
BOOST_AUTO_TEST_CASE(unknown_p1_test_p1)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment