Commit 864d2654 authored by DIAZ Jerome's avatar DIAZ Jerome Committed by GILLES Sebastien

#20

- Switch from an assert for the test to an exception at run time, handle by a singleton which is initiliazed from a value read in the input file.
- Make the field related to the check for inverted elements optional (some tests and models do not require it) and modify testing suite accordingly for the tests for which this option is relevant.

Integrator note: I merged here two commits, as the first one alone didn't compile.
parent ca2d92f8
......@@ -856,6 +856,7 @@
BE6341F0236A363B00028688 /* CheckInvertedElements.hxx in Headers */ = {isa = PBXBuildFile; fileRef = BE6341EC236A363A00028688 /* CheckInvertedElements.hxx */; };
BE6341F1236A363B00028688 /* EnumInvertedElements.hpp in Headers */ = {isa = PBXBuildFile; fileRef = BE6341ED236A363A00028688 /* EnumInvertedElements.hpp */; };
BE6341F2236A363B00028688 /* CheckInvertedElements.cpp in Sources */ = {isa = PBXBuildFile; fileRef = BE6341EE236A363A00028688 /* CheckInvertedElements.cpp */; };
BE6341F4236A38CE00028688 /* CheckInvertedElements.cpp in Sources */ = {isa = PBXBuildFile; fileRef = BE6341F3236A38CD00028688 /* CheckInvertedElements.cpp */; };
BE63B4131F4F165700F03800 /* Factory.cpp in Sources */ = {isa = PBXBuildFile; fileRef = BE63B4101F4F165700F03800 /* Factory.cpp */; };
BE63B4141F4F165700F03800 /* Factory.hpp in Headers */ = {isa = PBXBuildFile; fileRef = BE63B4111F4F165700F03800 /* Factory.hpp */; };
BE63B4151F4F165700F03800 /* Factory.hxx in Headers */ = {isa = PBXBuildFile; fileRef = BE63B4121F4F165700F03800 /* Factory.hxx */; };
......@@ -3637,6 +3638,7 @@
BE6341EC236A363A00028688 /* CheckInvertedElements.hxx */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.h; path = CheckInvertedElements.hxx; sourceTree = "<group>"; };
BE6341ED236A363A00028688 /* EnumInvertedElements.hpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.h; path = EnumInvertedElements.hpp; sourceTree = "<group>"; };
BE6341EE236A363A00028688 /* CheckInvertedElements.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = CheckInvertedElements.cpp; sourceTree = "<group>"; };
BE6341F3236A38CD00028688 /* CheckInvertedElements.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = CheckInvertedElements.cpp; sourceTree = "<group>"; };
BE63B4101F4F165700F03800 /* Factory.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = Factory.cpp; sourceTree = "<group>"; };
BE63B4111F4F165700F03800 /* Factory.hpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.h; path = Factory.hpp; sourceTree = "<group>"; };
BE63B4121F4F165700F03800 /* Factory.hxx */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.h; path = Factory.hxx; sourceTree = "<group>"; };
......@@ -7052,6 +7054,7 @@
BE6341E9236A361300028688 /* PlaneStressStrain.cpp */,
BE4D0CD121A2E4F900E0D4E7 /* Kappa1.cpp */,
BE4D0CD021A2E4F900E0D4E7 /* Kappa2.cpp */,
BE6341F3236A38CD00028688 /* CheckInvertedElements.cpp */,
);
path = Solid;
sourceTree = "<group>";
......@@ -12019,6 +12022,7 @@
BE3D3ABC22F1BDA300E7794E /* GracefulExit.cpp in Sources */,
BE4D0D5F21A2E4F900E0D4E7 /* Solid.cpp in Sources */,
BE7E553B22EF2D0000BEA053 /* Parallelism.cpp in Sources */,
BE6341F4236A38CE00028688 /* CheckInvertedElements.cpp in Sources */,
BE4D0D7C21A2E4F900E0D4E7 /* LightweightDomainList.cpp in Sources */,
BE4D0D7E21A2E4F900E0D4E7 /* Domain.cpp in Sources */,
BE4D0D1C21A2E4F900E0D4E7 /* ReactionCoefficient.cpp in Sources */,
......@@ -62,6 +62,10 @@
<CommandLineArguments>
<CommandLineArgument
argument = "-i ${HOME}/Codes/MoReFEM/CoreLibrary/Sources/ModelInstances/Hyperelasticity/demo_input_hyperelasticity.lua"
isEnabled = "NO">
</CommandLineArgument>
<CommandLineArgument
argument = "-i ${HOME}/Codes/MoReFEM/CoreLibrary/Sources/ModelInstances/Hyperelasticity/demo_test.lua"
isEnabled = "YES">
</CommandLineArgument>
</CommandLineArguments>
......
......@@ -40,7 +40,7 @@
</Testables>
</TestAction>
<LaunchAction
buildConfiguration = "Debug"
buildConfiguration = "Release"
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
launchStyle = "0"
......
//
// CheckInvertedElements.cpp
// MoReFEM
//
// Created by Jerôme Diaz on 17/10/2019.
// Copyright © 2019 Inria. All rights reserved.
//
#include "Core/InputData/Instances/Parameter/Solid/Solid.hpp"
namespace MoReFEM
{
namespace InputDataNS
{
const std::string& Solid::CheckInvertedElements::NameInFile()
{
static std::string ret("CheckInvertedElements");
return ret;
}
const std::string& Solid::CheckInvertedElements::Description()
{
static std::string ret("If the displacement induced by the applied loading is strong enough"
"it can lead to inverted elements: some vertices of the element are moved"
"such that the volume of the finite element becomes negative. This means"
"that the resulting deformed mesh is no longer valid. This parameter enables a"
"computationally expensive test on all quadrature points to check that the volume"
"of all finite elements remains positive throughout the computation.");
return ret;
}
const std::string& Solid::CheckInvertedElements::Constraint()
{
return Utilities::EmptyString();
}
const std::string& Solid::CheckInvertedElements::DefaultValue()
{
static std::string ret("false");
return ret;
}
} // namespace InputDataNS
} // namespace MoReFEM
/// @} // addtogroup CoreGroup
......@@ -1067,6 +1067,49 @@ namespace MoReFEM
static const std::string& DefaultValue();
};
//! Holds information related to the input parameter Solid::CheckInvertedElements.
struct CheckInvertedElements : public Crtp::InputData<CheckInvertedElements, self, bool>
{
//! Name of the input parameter in Lua input file.
static const std::string& NameInFile();
//! Description of the input parameter.
static const std::string& Description();
/*!
* \return Constraint to fulfill.
*
* Might be left empty; if not the format to respect is the \a LuaOptionFile one. Hereafter some text from \a LuaOptionFile example file:
*
* An age should be greater than 0 and less than, say, 150. It is possible
* to check it with a logical expression (written in Lua). The expression
* should be written with 'v' being the variable to be checked.
* \a constraint = "v >= 0 and v < 150"
*
* It is possible to check whether a variable is in a set of acceptable
* value. This is performed with 'value_in' (a Lua function defined by \a LuaOptionFile).
* \a constraint = "value_in(v, {'Messiah', 'Water Music'})"
*
* If a vector is retrieved, the constraint must be satisfied on every
* element of the vector.
*/
static const std::string& Constraint();
/*!
* \return Default value.
*
* This is intended to be used only when the class is used to create a default file; never when no value has been given
* in the input data file (doing so is too much error prone...)
*
* This is given as a string; if no default value return an empty string. The value must be \a LuaOptionFile-formatted.
*/
static const std::string& DefaultValue();
};
//! Alias to the tuple of structs.
using section_content_type = std::tuple
......@@ -1088,7 +1131,8 @@ namespace MoReFEM
C2,
C3,
C4,
C5
C5,
CheckInvertedElements
>;
......
......@@ -11,6 +11,7 @@ target_sources(${MOREFEM_CORE}
PRIVATE
"${CMAKE_CURRENT_LIST_DIR}/C_i_Mu_i.cpp"
"${CMAKE_CURRENT_LIST_DIR}/CheckInvertedElements.cpp"
"${CMAKE_CURRENT_LIST_DIR}/HyperelasticBulk.cpp"
"${CMAKE_CURRENT_LIST_DIR}/Kappa1.cpp"
"${CMAKE_CURRENT_LIST_DIR}/Kappa2.cpp"
......
......@@ -34,6 +34,8 @@
# include "Core/MoReFEMData/Internal/Parallelism.hpp"
# include "Core/MoReFEMData/Internal/Helper.hpp"
# include "Core/InputData/Instances/Parameter/Solid/Solid.hpp"
# include "FiniteElement/FiniteElementSpace/Internal/CheckInvertedElements.hpp"
namespace MoReFEM
{
......
......@@ -98,6 +98,15 @@ namespace MoReFEM
const auto& binary_output = ipl::Extract<Result::BinaryOutput>::Value(*input_data_);
Utilities::OutputFormat::CreateOrGetInstance(__FILE__, __LINE__, binary_output);
if constexpr (InputDataT::template Find<InputDataNS::Solid::CheckInvertedElements>())
{
const auto& do_check_inverted_elements = ipl::Extract<InputDataNS::Solid::CheckInvertedElements>
::Value(*input_data_);
MoReFEM::Internal::FEltSpaceNS::CheckInvertedElements
::CreateOrGetInstance(__FILE__, __LINE__, do_check_inverted_elements);
}
}
catch(const ExceptionNS::GracefulExit& e)
{
......
......@@ -9,5 +9,16 @@
#ifndef MOREFEM_x_FINITE_ELEMENT_x_FINITE_ELEMENT_SPACE_x_INTERNAL_x_CHECK_INVERTED_ELEMENTS_HXX_
# define MOREFEM_x_FINITE_ELEMENT_x_FINITE_ELEMENT_SPACE_x_INTERNAL_x_CHECK_INVERTED_ELEMENTS_HXX_
namespace MoReFEM::Internal::FEltSpaceNS
{
inline check_inverted_elements_policy CheckInvertedElements::DoCheckInvertedElements() const noexcept
{
return check_inverted_elements_policy_;
}
} // namepsace MoReFEM::Internal::FEltSpaceNS
#endif // MOREFEM_x_FINITE_ELEMENT_x_FINITE_ELEMENT_SPACE_x_INTERNAL_x_CHECK_INVERTED_ELEMENTS_HXX_
......@@ -121,6 +121,7 @@ namespace MoReFEM
InputDataNS::Solid::HyperelasticBulk,
InputDataNS::Solid::Kappa1,
InputDataNS::Solid::Kappa2,
InputDataNS::Solid::CheckInvertedElements,
InputDataNS::Parallelism,
InputDataNS::Result
......
......@@ -516,6 +516,13 @@ Solid = {
}, -- Kappa2
-- If the displacement induced by the applied loading is strong enough it can lead to inverted elements:
-- some vertices of the element are moved such that the volume of the finite element becomes negative.
-- This means that the resulting deformed mesh is no longer valid.
-- This parameter enables a computationally expensive test on all quadrature points to check that the volume
-- of all finite elements remains positive throughout the computation.
CheckInvertedElements = false
} -- Solid
......
......@@ -441,6 +441,13 @@ Solid = {
}, -- Kappa2
-- If the displacement induced by the applied loading is strong enough it can lead to inverted elements:
-- some vertices of the element are moved such that the volume of the finite element becomes negative.
-- This means that the resulting deformed mesh is no longer valid.
-- This parameter enables a computationally expensive test on all quadrature points to check that the volume
-- of all finite elements remains positive throughout the computation.
CheckInvertedElements = false
} -- Solid
......
......@@ -257,7 +257,7 @@ EssentialBoundaryCondition1 = {
-- Values at each of the relevant component.
-- Expected format: { VALUE1, VALUE2, ...}
value = { 0, 0, 0 },
value = { 0., 0., 0. },
-- Index of the domain onto which essential boundary condition is defined.
......@@ -406,7 +406,7 @@ TransientSource1 = {
-- ]]
-- where x, y and z are global coordinates. sin, cos, tan, exp and so forth require a 'math.' preffix.
-- Expected format: { VALUE1, VALUE2, ...}
value = { 0, 300, 0 }
value = { 0., 300., 0. }
} -- TransientSource1
......@@ -434,7 +434,7 @@ Solid = {
-- ]]
-- where x, y and z are global coordinates. sin, cos, tan, exp and so forth require a 'math.' preffix.
-- Expected format: see the variant description...
value = 1
value = 1.
}, -- VolumicMass
......@@ -460,7 +460,7 @@ Solid = {
-- ]]
-- where x, y and z are global coordinates. sin, cos, tan, exp and so forth require a 'math.' preffix.
-- Expected format: see the variant description...
value = 1750000
value = 1750000.
}, -- HyperelasticBulk
......@@ -486,7 +486,7 @@ Solid = {
-- ]]
-- where x, y and z are global coordinates. sin, cos, tan, exp and so forth require a 'math.' preffix.
-- Expected format: see the variant description...
value = 500
value = 500.
}, -- Kappa1
......@@ -515,6 +515,13 @@ Solid = {
value = 403346.153846154
}, -- Kappa2
-- If the displacement induced by the applied loading is strong enough it can lead to inverted elements:
-- some vertices of the element are moved such that the volume of the finite element becomes negative.
-- This means that the resulting deformed mesh is no longer valid.
-- This parameter enables a computationally expensive test on all quadrature points to check that the volume
-- of all finite elements remains positive throughout the computation.
CheckInvertedElements = false
} -- Solid
......
......@@ -137,6 +137,7 @@ namespace MoReFEM
InputDataNS::Solid::Kappa1,
InputDataNS::Solid::Kappa2,
InputDataNS::Solid::HyperelasticBulk,
InputDataNS::Solid::CheckInvertedElements,
InputDataNS::InitialCondition<EnumUnderlyingType(InitialConditionIndex::displacement_initial_condition)>,
InputDataNS::Source::StaticPressure,
......
......@@ -760,6 +760,13 @@ Solid = {
value = 0.3
}, -- HyperelasticBulk
-- If the displacement induced by the applied loading is strong enough it can lead to inverted elements:
-- some vertices of the element are moved such that the volume of the finite element becomes negative.
-- This means that the resulting deformed mesh is no longer valid.
-- This parameter enables a computationally expensive test on all quadrature points to check that the volume
-- of all finite elements remains positive throughout the computation.
CheckInvertedElements = false
} -- Solid
......
......@@ -760,6 +760,13 @@ Solid = {
value = 0.3
}, -- HyperelasticBulk
-- If the displacement induced by the applied loading is strong enough it can lead to inverted elements:
-- some vertices of the element are moved such that the volume of the finite element becomes negative.
-- This means that the resulting deformed mesh is no longer valid.
-- This parameter enables a computationally expensive test on all quadrature points to check that the volume
-- of all finite elements remains positive throughout the computation.
CheckInvertedElements = false
} -- Solid
......
......@@ -26,6 +26,8 @@
# include "Parameters/InitParameterFromInputData/InitParameterFromInputData.hpp"
# include "ParameterInstances/Compound/Solid/Solid.hpp"
# include "FiniteElement/FiniteElementSpace/Internal/CheckInvertedElements.hpp"
# include "Operators/Enum.hpp"
# include "Operators/LocalVariationalOperator/ElementaryData.hpp"
......
......@@ -455,25 +455,36 @@ namespace MoReFEM
const auto& De = derivative_green_lagrange.Update(gradient_displacement);
const auto& transposed_De = derivative_green_lagrange.GetTransposed();
# ifndef NDEBUG
switch (MoReFEM::Internal::FEltSpaceNS::CheckInvertedElements::GetInstance(__FILE__, __LINE__).DoCheckInvertedElements())
{
auto& deformation_gradient =
this->matrix_parent::template GetLocalMatrix<EnumUnderlyingType(LocalMatrixIndex::deformation_gradient)>();
deformation_gradient = gradient_displacement;
for (auto i = 0ul; i < DimensionT; ++i)
deformation_gradient(i, i) += 1.0; // F = Id + grad_y
const double determinant_deformation_gradient = xt::linalg::det(deformation_gradient);
assert(determinant_deformation_gradient > 0. && "Some mesh elements have been inverted."
"Consider using an adaptative loading method"
"(i.e continuation method for static cases or smaller"
"time steps for dynamic ones)." );
}
# endif //NDEBUG
case check_inverted_elements_policy::do_check:
{
auto& deformation_gradient =
this->matrix_parent::template GetLocalMatrix<EnumUnderlyingType(LocalMatrixIndex::deformation_gradient)>();
deformation_gradient = gradient_displacement;
for (auto i = 0ul; i < DimensionT; ++i)
deformation_gradient(i, i) += 1.0; // F = Id + grad_y
const double determinant_deformation_gradient = xt::linalg::det(deformation_gradient);
if (determinant_deformation_gradient <= 0.)
throw Exception("Some mesh elements have been inverted. "
"Consider using an adaptative loading method "
"(i.e continuation method for static cases or smaller "
"time steps for dynamic ones).",
__FILE__, __LINE__);
break;
}
case check_inverted_elements_policy::no_check:
break; // Maybe free the memory allocated for the local matrix deformation gradient?
case check_inverted_elements_policy::from_input_data:
assert(false && "Should not happen");
exit(EXIT_FAILURE);
} // switch
// ===================================================================================
// ===================================================================================
// Then compute the derivates of W, required to build both bilinear and linear terms.
// ===================================================================================
......
......@@ -111,6 +111,7 @@ namespace MoReFEM
InputDataNS::Solid::LameLambda,
InputDataNS::Solid::LameMu,
InputDataNS::Solid::Viscosity,
InputDataNS::Solid::CheckInvertedElements,
InputDataNS::Result
>;
......
......@@ -409,7 +409,13 @@ Solid = {
}, -- Viscosity
-- If the displacement induced by the applied loading is strong enough it can lead to inverted elements:
-- some vertices of the element are moved such that the volume of the finite element becomes negative.
-- This means that the resulting deformed mesh is no longer valid.
-- This parameter enables a computationally expensive test on all quadrature points to check that the volume
-- of all finite elements remains positive throughout the computation.
CheckInvertedElements = false
} -- Solid
......
......@@ -381,7 +381,14 @@ Solid = {
-- For 2D operators, which approximation to use.
-- Expected format: "VALUE"
-- Constraint: value_in(v, {'irrelevant', 'plane_strain', 'plane_stress'})
PlaneStressStrain = "plane_strain"
PlaneStressStrain = "plane_strain",
-- If the displacement induced by the applied loading is strong enough it can lead to inverted elements:
-- some vertices of the element are moved such that the volume of the finite element becomes negative.
-- This means that the resulting deformed mesh is no longer valid.
-- This parameter enables a computationally expensive test on all quadrature points to check that the volume
-- of all finite elements remains positive throughout the computation.
CheckInvertedElements = false
} -- Solid
......
......@@ -381,7 +381,14 @@ Solid = {
-- For 2D operators, which approximation to use.
-- Expected format: "VALUE"
-- Constraint: value_in(v, {'irrelevant', 'plane_strain', 'plane_stress'})
PlaneStressStrain = "plane_strain"
PlaneStressStrain = "plane_strain",
-- If the displacement induced by the applied loading is strong enough it can lead to inverted elements:
-- some vertices of the element are moved such that the volume of the finite element becomes negative.
-- This means that the resulting deformed mesh is no longer valid.
-- This parameter enables a computationally expensive test on all quadrature points to check that the volume
-- of all finite elements remains positive throughout the computation.
CheckInvertedElements = false
} -- Solid
......
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