9 #include "BoostUnitTest.h" 12 #include <boost/filesystem.hpp> 14 #include "nuto/mechanics/MechanicsEnums.h" 17 #include "nuto/math/SparseMatrixCSRVector2.h" 18 #include "nuto/mechanics/dofSubMatrixStorage/BlockScalar.h" 20 #include "nuto/mechanics/elements/ElementBase.h" 21 #include "nuto/mechanics/groups/Group.h" 22 #include "nuto/mechanics/interpolationtypes/InterpolationBase.h" 23 #include "nuto/mechanics/interpolationtypes/InterpolationType.h" 24 #include "nuto/mechanics/structures/unstructured/Structure.h" 25 #include "nuto/mechanics/structures/StructureOutputBlockMatrix.h" 26 #include "nuto/mechanics/structures/StructureOutputBlockVector.h" 27 #include "nuto/mechanics/mesh/MeshGenerator.h" 49 void Run(NuTo::Structure&
s,
const std::string& rVisualizationDirectory)
54 s.SetVerboseLevel(10);
58 SetConstitutiveLaw(s);
59 SetBoundaryConditions(s);
61 s.NodeBuildGlobalDofs();
62 s.CalculateMaximumIndependentSets();
70 Visualize(s, rVisualizationDirectory);
74 void CheckVolume(NuTo::Structure&
s)
76 double volume = s.ElementGroupGetVolume(s.GroupGetElementsTotal());
77 if (s.GetDimension() == 2)
79 if (s.GetDimension() == 1)
82 BOOST_CHECK_CLOSE(volume, lX * lY * lZ, 1.e-6);
85 void SetConstitutiveLaw(NuTo::Structure& s)
88 s.ConstitutiveLawCreate(0, eConstitutiveType::LINEAR_ELASTIC_ENGINEERING_STRESS);
89 s.ConstitutiveLawSetParameterDouble(0, eConstitutiveParameter::YOUNGS_MODULUS, E);
90 s.ConstitutiveLawSetParameterDouble(0, eConstitutiveParameter::POISSONS_RATIO, nu);
91 s.ConstitutiveLawSetParameterDouble(0, eConstitutiveParameter::DENSITY, rho);
92 s.ElementTotalSetConstitutiveLaw(0);
95 void SetBoundaryConditions(NuTo::Structure& s)
99 const NuTo::Node::eDof eDofDispl = NuTo::Node::eDof::DISPLACEMENTS;
102 const auto& nodeOrigin = s.NodeGetAtCoordinate(Eigen::VectorXd::Zero(dimension));
103 for (
int iDim = 1; iDim <
dimension; ++iDim)
104 s.Constraints().Add(eDofDispl,
110 const auto& nodeRotation = s.NodeGetAtCoordinate(Eigen::Vector3d(0, 0, lZ));
123 void CheckStiffness(NuTo::Structure& s)
125 if (s.GetNumTotalDofs() > 50)
127 BOOST_CHECK(s.ElementCheckHessian0(1.e-8, 1.e-6,
true));
128 BOOST_CHECK(s.CheckHessian0(1.e-8, 1.e-6,
true));
131 void Solve(NuTo::Structure& s)
133 s.SolveGlobalSystemStaticElastic();
134 auto internalGradient = s.BuildGlobalInternalGradient();
135 BOOST_CHECK_SMALL(internalGradient.J.CalculateNormL2()[NuTo::Node::eDof::DISPLACEMENTS], 1e-8);
140 double analyticStrainX = deltaL /
lX;
141 double analyticStressX = analyticStrainX *
E;
142 double analyticForce = analyticStressX * lY *
lZ;
144 std::cout <<
"\n ### analytical values ###" << std::endl;
145 std::cout <<
"sigma_xx: " << analyticStressX << std::endl;
146 std::cout <<
"force_x : " << analyticForce << std::endl;
149 int allElements = s.GroupGetElementsTotal();
150 for (
int elementId : s.GroupGetMemberIds(allElements))
152 auto stress = s.ElementGetEngineeringStress(elementId);
153 for (
int iIP = 0; iIP < stress.cols(); ++iIP)
155 double numericStress = stress(0, iIP);
156 std::cout <<
"numeric stress in element " << elementId <<
" at IP " << iIP <<
": " << numericStress
159 BOOST_CHECK_CLOSE_FRACTION(numericStress, analyticStressX, 1.e-6);
165 double numericForce = 0;
167 for (
int nodeId : nodesX0.GetMemberIds())
169 Eigen::VectorXd force;
170 s.NodeInternalForce(nodeId, force);
171 numericForce += force(0);
174 BOOST_CHECK_CLOSE(numericForce, analyticForce, 1.e-6);
177 void CheckMass(NuTo::Structure& s)
179 double analyticMass = lX * lY * lZ *
rho;
181 auto hessian2 = s.BuildGlobalHessian2();
183 double numericMass = 0;
184 numericMass += hessian2.JJ(NuTo::Node::eDof::DISPLACEMENTS, NuTo::Node::eDof::DISPLACEMENTS).Sum();
185 numericMass += hessian2.JK(NuTo::Node::eDof::DISPLACEMENTS, NuTo::Node::eDof::DISPLACEMENTS).Sum();
186 numericMass += hessian2.KJ(NuTo::Node::eDof::DISPLACEMENTS, NuTo::Node::eDof::DISPLACEMENTS).Sum();
187 numericMass += hessian2.KK(NuTo::Node::eDof::DISPLACEMENTS, NuTo::Node::eDof::DISPLACEMENTS).Sum();
189 numericMass /= s.GetDimension();
191 BOOST_CHECK_CLOSE(numericMass, analyticMass, 1.e-6);
193 hessian2 = s.BuildGlobalHessian2Lumped();
196 numericMass += hessian2.JJ(NuTo::Node::eDof::DISPLACEMENTS, NuTo::Node::eDof::DISPLACEMENTS).Sum();
197 numericMass += hessian2.JK(NuTo::Node::eDof::DISPLACEMENTS, NuTo::Node::eDof::DISPLACEMENTS).Sum();
198 numericMass += hessian2.KJ(NuTo::Node::eDof::DISPLACEMENTS, NuTo::Node::eDof::DISPLACEMENTS).Sum();
199 numericMass += hessian2.KK(NuTo::Node::eDof::DISPLACEMENTS, NuTo::Node::eDof::DISPLACEMENTS).Sum();
201 numericMass /= s.GetDimension();
203 BOOST_CHECK_CLOSE(numericMass, analyticMass, 1.e-6);
206 void Visualize(NuTo::Structure& s,
const std::string& rVisualizationDirectory)
208 if (rVisualizationDirectory ==
"")
209 throw NuTo::Exception(__PRETTY_FUNCTION__,
"Provide a valid visualization directory!");
212 boost::filesystem::create_directory(directory);
215 std::string fileName = NuTo::Interpolation::ShapeTypeToString(
interpolationType.GetShapeType());
216 fileName += NuTo::Interpolation::TypeOrderToString(
219 directory /= fileName;
222 s.GroupAddElementsTotal(visualizationGroup);
228 s.ExportVtkDataFileElements(directory.string());
path
Definition: Brick8N.py:8
Definition: ElementUniaxialTest.h:32
Base class for all exceptions thrown in NuTo.
Definition: Exception.h:9
double lX
Definition: ElementUniaxialTest.h:38
eDirection
Definition: DirectionEnum.h:5
double lY
Definition: ElementUniaxialTest.h:39
visualize engineering stress tensor
Definition: DamageLaw.h:5
s
Definition: WaveFieldSynthesis.py:99
std::vector< Equation > Component(const NodeSimple &node, std::vector< eDirection > directions, double value)
constraints components of vector valued nodes in X and/or Y and/or Z
Definition: ConstraintCompanion.cpp:21
interpolationType
Definition: Brick8NCoupling.py:48
double nu
Definition: ElementUniaxialTest.h:43
double lZ
Definition: ElementUniaxialTest.h:40
Definition: ElementUniaxialTest.h:35
visualizationGroup
Definition: Brick8NCoupling.py:139
void CheckSolution(NuTo::Structure &s, double tolerance)
Definition: PlateWithHole.cpp:42
void Run(NuTo::Structure &s, const std::string &rVisualizationDirectory)
provide a structure that contains the geometry of a uniaxial test, starting from (0,0,0) to (lx, ly, lz)
Definition: ElementUniaxialTest.h:49
constexpr int dimension
Definition: single_edge_notched_tension_test.cpp:30
double rho
Definition: ElementUniaxialTest.h:45
double E
Definition: ElementUniaxialTest.h:42
double deltaL
Definition: ElementUniaxialTest.h:44
visualize engineering strain tensor