v0.16.0
Loading...
Searching...
No Matches
NonlinearElasticElementInterface.hpp
Go to the documentation of this file.
1/** \file NonlinearElasticElementInterface.hpp
2* \example mofem/users_modules/basic_finite_elements/nonlinear_elastic_materials/src/NonlinearElasticElementInterface.hpp
3
4 \brief Header file for NonlinearElasticElementInterface element implementation
5*/
6
7
8
9#ifndef __NONLINEARELEMENTINTERFACE_HPP__
10#define __NONLINEARELEMENTINTERFACE_HPP__
11
12/** \brief Set of functions declaring elements and setting operators
13 * for generic element interface
14 */
16
18 SmartPetscObj<DM> dM;
19 PetscBool isQuasiStatic;
20
21 PetscInt oRder;
23 BitRefLevel bIt;
24 boost::shared_ptr<NonlinearElasticElement> elasticElementPtr;
25 boost::shared_ptr<ElasticMaterials> elasticMaterialsPtr;
26 boost::shared_ptr<
27 PostProcBrokenMeshInMoab<VolumeElementForcesAndSourcesCore>>
29
32
34 string postion_field,
35 string mesh_posi_field_name = "MESH_NODE_POSITIONS",
36 bool is_displacement_field = true,
37 PetscBool is_quasi_static = PETSC_TRUE)
38 : mField(m_field), positionField(postion_field),
39 meshNodeField(mesh_posi_field_name),
40 isDisplacementField(is_displacement_field),
42 oRder = 1;
43 }
44
46
47 MoFEMErrorCode getCommandLineParameters() {
49 isQuasiStatic = PETSC_FALSE;
50 oRder = 2;
51 CHKERR PetscOptionsGetBool(PETSC_NULLPTR, "-is_quasi_static", &isQuasiStatic,
52 PETSC_NULLPTR);
53 CHKERR PetscOptionsGetInt(PETSC_NULLPTR, "-order", &oRder, PETSC_NULLPTR);
54
56 };
57
58 MoFEMErrorCode addElementFields() {
60 auto simple = mField.getInterface<Simple>();
63 3);
64 CHKERR simple->addBoundaryField(positionField, H1,
66 CHKERR simple->setFieldOrder(positionField, oRder);
67 }
70 3);
71 CHKERR simple->setFieldOrder(meshNodeField, 2);
72 }
73
75 };
76
77 MoFEMErrorCode createElements() {
79
80 elasticElementPtr = boost::make_shared<NonlinearElasticElement>(mField, 2);
81 elasticMaterialsPtr = boost::make_shared<ElasticMaterials>(mField, "HOOKE");
82 CHKERR elasticMaterialsPtr->setBlocks(elasticElementPtr->setOfBlocks);
83
85 elasticElementPtr->getLoopFeRhs().getOpPtrVector(), {H1},
88 elasticElementPtr->getLoopFeLhs().getOpPtrVector(), {H1},
91 elasticElementPtr->getLoopFeEnergy().getOpPtrVector(), {H1},
93 CHKERR elasticElementPtr->addElement("ELASTIC", positionField,
94 meshNodeField, false);
95
96
98 };
99
100 MoFEMErrorCode setOperators() {
102 auto &pipeline_rhs = elasticElementPtr->feRhs.getOpPtrVector();
103 auto &pipeline_lhs = elasticElementPtr->feLhs.getOpPtrVector();
104
105 pipeline_rhs.push_back(new OpSetBc(positionField, true, mBoundaryMarker));
106 pipeline_lhs.push_back(new OpSetBc(positionField, true, mBoundaryMarker));
107
110
111 pipeline_rhs.push_back(new OpUnSetBc(positionField));
112 pipeline_lhs.push_back(new OpUnSetBc(positionField));
114 }
115
116 BitRefLevel getBitRefLevel() { return bIt; };
117 MoFEMErrorCode addElementsToDM(SmartPetscObj<DM> dm) {
119 this->dM = dm;
120 CHKERR DMMoFEMAddElement(dM, "ELASTIC");
121 mField.getInterface<Simple>()->getOtherFiniteElements().push_back(
122 "ELASTIC");
123
125 };
126
127 MoFEMErrorCode setupSolverJacobianSNES() {
129
130 CHKERR DMMoFEMSNESSetJacobian(
131 dM, "ELASTIC", &elasticElementPtr->getLoopFeLhs(), NULL, NULL);
132
134 };
135 MoFEMErrorCode setupSolverFunctionSNES() {
137 CHKERR DMMoFEMSNESSetFunction(dM, "ELASTIC",
138 &elasticElementPtr->getLoopFeRhs(),
139 PETSC_NULLPTR, PETSC_NULLPTR);
141 };
142
143 MoFEMErrorCode setupSolverJacobianTS(const TSType type) {
145 auto &method = elasticElementPtr->getLoopFeLhs();
146 switch (type) {
147 case IM:
148 CHKERR DMMoFEMTSSetIJacobian(dM, "ELASTIC", &method, &method, &method);
149 break;
150 case IM2:
151 CHKERR DMMoFEMTSSetI2Jacobian(dM, "ELASTIC", &method, &method, &method);
152 break;
153 case EX:
154 CHKERR DMMoFEMTSSetRHSJacobian(dM, "ELASTIC", &method, &method, &method);
155 break;
156 default:
157 SETERRQ(PETSC_COMM_SELF, MOFEM_NOT_IMPLEMENTED,
158 "This TS is not yet implemented");
159 break;
160 }
162 };
163
164 MoFEMErrorCode setupSolverFunctionTS(const TSType type) {
166 auto &method = elasticElementPtr->getLoopFeRhs();
167 switch (type) {
168 case IM:
169 CHKERR DMMoFEMTSSetIFunction(dM, "ELASTIC", &method, &method, &method);
170 break;
171 case IM2:
172 CHKERR DMMoFEMTSSetI2Function(dM, "ELASTIC", &method, &method, &method);
173 break;
174 case EX:
175 CHKERR DMMoFEMTSSetRHSFunction(dM, "ELASTIC", &method, &method, &method);
176 break;
177 default:
178 SETERRQ(PETSC_COMM_SELF, MOFEM_NOT_IMPLEMENTED, "Not implemented");
179 break;
180 }
181
183 };
184
185 MoFEMErrorCode updateElementVariables() { return 0; };
186 MoFEMErrorCode postProcessElement(int step) {
188
189 if (elasticElementPtr->setOfBlocks.empty())
191
192 if (!postProcMeshPtr) {
193 postProcMeshPtr = boost::make_shared<
194 PostProcBrokenMeshInMoab<VolumeElementForcesAndSourcesCore>>(mField);
195
196 if (mField.check_field("MESH_NODE_POSITIONS"))
197 CHKERR AddHOOps<3, 3, 3>::add(postProcMeshPtr->getOpPtrVector(), {H1},
198 "MESH_NODE_POSITIONS");
199 auto position_ptr = boost::make_shared<MatrixDouble>();
200 auto mesh_pos_ptr = boost::make_shared<MatrixDouble>();
201 auto position_grad_ptr = boost::make_shared<MatrixDouble>();
202 postProcMeshPtr->getOpPtrVector().push_back(
203 new OpCalculateVectorFieldValues<3>(positionField, position_ptr));
204 postProcMeshPtr->getOpPtrVector().push_back(
205 new OpCalculateVectorFieldValues<3>(meshNodeField, mesh_pos_ptr));
206 postProcMeshPtr->getOpPtrVector().push_back(
207 new OpCalculateVectorFieldGradient<3, 3>(positionField,
208 position_grad_ptr));
209
210 for (auto &sit : elasticElementPtr->setOfBlocks) {
211 postProcMeshPtr->getOpPtrVector().push_back(new PostProcStress(
212 postProcMeshPtr->getPostProcMesh(),
213 postProcMeshPtr->getMapGaussPts(),
214 postProcMeshPtr->getPostProcElements(), positionField, sit.second,
215 position_ptr, mesh_pos_ptr, position_grad_ptr, meshNodeField,
217 }
218 using OpPPMap = OpPostProcMapInMoab<3, 3>;
219 postProcMeshPtr->getOpPtrVector().push_back(new OpPPMap(
220 postProcMeshPtr->getPostProcMesh(),
221 postProcMeshPtr->getMapGaussPts(), {},
222 {{positionField, position_ptr}, {meshNodeField, mesh_pos_ptr}},
223 {{positionField + "_GRAD", position_grad_ptr}}, {}));
224 }
225
226 elasticElementPtr->getLoopFeEnergy().snes_ctx = SnesMethod::CTX_SNESNONE;
227 elasticElementPtr->getLoopFeEnergy().eNergy = 0;
228 // MOFEM_LOG("WORLD", Sev::inform) << "Loop energy\n";
229 CHKERR DMoFEMLoopFiniteElements(dM, "ELASTIC",
230 &elasticElementPtr->getLoopFeEnergy());
231
232 auto E = elasticElementPtr->getLoopFeEnergy().eNergy;
233 // Print elastic energy
234 MOFEM_LOG_C("WORLD", Sev::inform, "%d Time %3.2e Elastic energy %3.2e",
235 step, elasticElementPtr->getLoopFeRhs().ts_t, E);
236
237 CHKERR DMoFEMLoopFiniteElements(dM, "ELASTIC", postProcMeshPtr);
238 auto out_name = "out_vol_" + to_string(step) + ".h5m";
239
240 CHKERR postProcMeshPtr->writeFile(out_name);
241
243 };
244};
245
246#endif //__NONLINEARELEMENTINTERFACE_HPP__
std::string type
#define MOFEM_LOG_C(channel, severity, format,...)
void simple(double P1[], double P2[], double P3[], double c[], const int N)
Definition acoustic.cpp:69
@ AINSWORTH_LEGENDRE_BASE
Ainsworth Cole (Legendre) approx. base .
Definition definitions.h:60
#define MoFEMFunctionReturnHot(a)
Last executable line of each PETSc function used for error handling. Replaces return()
@ H1
continuous field
Definition definitions.h:85
#define MoFEMFunctionBegin
First executable line of each MoFEM function, used for error handling. Final line of MoFEM functions ...
@ MOFEM_NOT_IMPLEMENTED
Definition definitions.h:32
#define MoFEMFunctionReturn(a)
Last executable line of each PETSc function used for error handling. Replaces return()
#define CHKERR
Inline error check.
#define MoFEMFunctionBeginHot
First executable line of each MoFEM function, used for error handling. Final line of MoFEM functions ...
virtual bool check_field(const std::string &name) const =0
check if field is in database
OpPostProcMapInMoab< SPACE_DIM, SPACE_DIM > OpPPMap
Set of functions declaring elements and setting operators for generic element interface.
Deprecated interface functions.
Post post-proc data at points from hash maps.
MoFEMErrorCode getInterface(IFACE *&iface) const
Get interface reference to pointer of interface.
Set of functions declaring elements and setting operators for generic element interface.
NonlinearElasticElementInterface(MoFEM::Interface &m_field, string postion_field, string mesh_posi_field_name="MESH_NODE_POSITIONS", bool is_displacement_field=true, PetscBool is_quasi_static=PETSC_TRUE)
boost::shared_ptr< PostProcBrokenMeshInMoab< VolumeElementForcesAndSourcesCore > > postProcMeshPtr
boost::shared_ptr< ElasticMaterials > elasticMaterialsPtr
MoFEMErrorCode setupSolverJacobianTS(const TSType type)
MoFEMErrorCode setupSolverFunctionTS(const TSType type)
boost::shared_ptr< NonlinearElasticElement > elasticElementPtr
MoFEMErrorCode addElementsToDM(SmartPetscObj< DM > dm)
PetscBool is_quasi_static
Definition plastic.cpp:144