v0.14.0
NonlinearElasticElementInterface.hpp
Go to the documentation of this file.
1 /** \file NonlinearElasticElementInterface.hpp
2 * \example 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;
24  boost::shared_ptr<NonlinearElasticElement> elasticElementPtr;
25  boost::shared_ptr<ElasticMaterials> elasticMaterialsPtr;
26  boost::shared_ptr<PostProcVolumeOnRefinedMesh> postProcMeshPtr;
27 
28  string positionField;
29  string meshNodeField;
30 
32  string postion_field,
33  string mesh_posi_field_name = "MESH_NODE_POSITIONS",
34  bool is_displacement_field = true,
35  PetscBool is_quasi_static = PETSC_TRUE)
36  : mField(m_field), positionField(postion_field),
37  meshNodeField(mesh_posi_field_name),
38  isDisplacementField(is_displacement_field),
40  oRder = 1;
41  }
42 
44 
47  isQuasiStatic = PETSC_FALSE;
48  oRder = 2;
49  CHKERR PetscOptionsGetBool(PETSC_NULL, "-is_quasi_static", &isQuasiStatic,
50  PETSC_NULL);
51  CHKERR PetscOptionsGetInt(PETSC_NULL, "-order", &oRder, PETSC_NULL);
52 
54  };
55 
58  auto simple = mField.getInterface<Simple>();
61  3);
62  CHKERR simple->addBoundaryField(positionField, H1,
64  CHKERR simple->setFieldOrder(positionField, oRder);
65  }
68  3);
69  CHKERR simple->setFieldOrder(meshNodeField, 2);
70  }
71 
73  };
74 
77 
78  elasticElementPtr = boost::make_shared<NonlinearElasticElement>(mField, 2);
79  elasticMaterialsPtr = boost::make_shared<ElasticMaterials>(mField, "HOOKE");
80  CHKERR elasticMaterialsPtr->setBlocks(elasticElementPtr->setOfBlocks);
81 
82  CHKERR addHOOpsVol(meshNodeField, elasticElementPtr->getLoopFeRhs(), true,
83  false, false, false);
84  CHKERR addHOOpsVol(meshNodeField, elasticElementPtr->getLoopFeLhs(), true,
85  false, false, false);
87  true, false, false, false);
88  CHKERR elasticElementPtr->addElement("ELASTIC", positionField,
89  meshNodeField, false);
90 
91 
93  };
94 
97  auto &pipeline_rhs = elasticElementPtr->feRhs.getOpPtrVector();
98  auto &pipeline_lhs = elasticElementPtr->feLhs.getOpPtrVector();
99 
100  pipeline_rhs.push_back(new OpSetBc(positionField, true, mBoundaryMarker));
101  pipeline_lhs.push_back(new OpSetBc(positionField, true, mBoundaryMarker));
102 
103  CHKERR elasticElementPtr->setOperators(positionField, meshNodeField, false,
105 
106  pipeline_rhs.push_back(new OpUnSetBc(positionField));
107  pipeline_lhs.push_back(new OpUnSetBc(positionField));
109  }
110 
112  MoFEMErrorCode addElementsToDM(SmartPetscObj<DM> dm) {
114  this->dM = dm;
115  CHKERR DMMoFEMAddElement(dM, "ELASTIC");
116  mField.getInterface<Simple>()->getOtherFiniteElements().push_back(
117  "ELASTIC");
118 
120  };
121 
124 
126  dM, "ELASTIC", &elasticElementPtr->getLoopFeLhs(), NULL, NULL);
127 
129  };
132  CHKERR DMMoFEMSNESSetFunction(dM, "ELASTIC",
133  &elasticElementPtr->getLoopFeRhs(),
134  PETSC_NULL, PETSC_NULL);
136  };
137 
140  auto &method = elasticElementPtr->getLoopFeLhs();
141  switch (type) {
142  case IM:
143  CHKERR DMMoFEMTSSetIJacobian(dM, "ELASTIC", &method, &method, &method);
144  break;
145  case IM2:
146  CHKERR DMMoFEMTSSetI2Jacobian(dM, "ELASTIC", &method, &method, &method);
147  break;
148  case EX:
149  CHKERR DMMoFEMTSSetRHSJacobian(dM, "ELASTIC", &method, &method, &method);
150  break;
151  default:
152  SETERRQ(PETSC_COMM_SELF, MOFEM_NOT_IMPLEMENTED,
153  "This TS is not yet implemented");
154  break;
155  }
157  };
158 
161  auto &method = elasticElementPtr->getLoopFeRhs();
162  switch (type) {
163  case IM:
164  CHKERR DMMoFEMTSSetIFunction(dM, "ELASTIC", &method, &method, &method);
165  break;
166  case IM2:
167  CHKERR DMMoFEMTSSetI2Function(dM, "ELASTIC", &method, &method, &method);
168  break;
169  case EX:
170  CHKERR DMMoFEMTSSetRHSFunction(dM, "ELASTIC", &method, &method, &method);
171  break;
172  default:
173  SETERRQ(PETSC_COMM_SELF, MOFEM_NOT_IMPLEMENTED, "Not implemented");
174  break;
175  }
176 
178  };
179 
183 
184  if (elasticElementPtr->setOfBlocks.empty())
186 
187  if (!postProcMeshPtr) {
188  postProcMeshPtr = boost::make_shared<PostProcVolumeOnRefinedMesh>(mField);
189 
190  if (mField.check_field("MESH_NODE_POSITIONS"))
191  CHKERR addHOOpsVol("MESH_NODE_POSITIONS", *postProcMeshPtr, true, false,
192  false, false);
193  CHKERR postProcMeshPtr->generateReferenceElementMesh();
194  CHKERR postProcMeshPtr->addFieldValuesPostProc(positionField);
195  CHKERR postProcMeshPtr->addFieldValuesPostProc(meshNodeField);
196  CHKERR postProcMeshPtr->addFieldValuesGradientPostProc(positionField);
197 
198  for (auto &sit : elasticElementPtr->setOfBlocks) {
199  postProcMeshPtr->getOpPtrVector().push_back(new PostProcStress(
200  postProcMeshPtr->postProcMesh, postProcMeshPtr->mapGaussPts,
201  positionField, sit.second, postProcMeshPtr->commonData,
203  }
204  }
205 
206  elasticElementPtr->getLoopFeEnergy().snes_ctx = SnesMethod::CTX_SNESNONE;
207  elasticElementPtr->getLoopFeEnergy().eNergy = 0;
208  // MOFEM_LOG("WORLD", Sev::inform) << "Loop energy\n";
210  &elasticElementPtr->getLoopFeEnergy());
211 
212  auto E = elasticElementPtr->getLoopFeEnergy().eNergy;
213  // Print elastic energy
214  MOFEM_LOG_C("WORLD", Sev::inform, "%d Time %3.2e Elastic energy %3.2e",
215  step, elasticElementPtr->getLoopFeRhs().ts_t, E);
216 
218  auto out_name = "out_vol_" + to_string(step) + ".h5m";
219 
220  CHKERR postProcMeshPtr->writeFile(out_name);
221 
223  };
224 };
225 
226 #endif //__NONLINEARELEMENTINTERFACE_HPP__
GenericElementInterface::EX
@ EX
Definition: GenericElementInterface.hpp:16
MoFEMFunctionReturnHot
#define MoFEMFunctionReturnHot(a)
Last executable line of each PETSc function used for error handling. Replaces return()
Definition: definitions.h:447
MoFEM::UnknownInterface::getInterface
MoFEMErrorCode getInterface(IFACE *&iface) const
Get interface refernce to pointer of interface.
Definition: UnknownInterface.hpp:93
H1
@ H1
continuous field
Definition: definitions.h:85
NonlinearElasticElementInterface::isDisplacementField
bool isDisplacementField
Definition: NonlinearElasticElementInterface.hpp:22
NonlinearElasticElementInterface::elasticMaterialsPtr
boost::shared_ptr< ElasticMaterials > elasticMaterialsPtr
Definition: NonlinearElasticElementInterface.hpp:25
MoFEM::addHOOpsVol
MoFEMErrorCode addHOOpsVol(const std::string field, E &e, bool h1, bool hcurl, bool hdiv, bool l2)
Definition: HODataOperators.hpp:764
NonlinearElasticElementInterface::bIt
BitRefLevel bIt
Definition: NonlinearElasticElementInterface.hpp:23
MoFEM::Exceptions::MoFEMErrorCode
PetscErrorCode MoFEMErrorCode
MoFEM/PETSc error code.
Definition: Exceptions.hpp:56
E
MoFEM::DMMoFEMTSSetRHSJacobian
PetscErrorCode DMMoFEMTSSetRHSJacobian(DM dm, const std::string fe_name, boost::shared_ptr< MoFEM::FEMethod > method, boost::shared_ptr< MoFEM::BasicMethod > pre_only, boost::shared_ptr< MoFEM::BasicMethod > post_only)
set TS the right hand side jacobian
Definition: DMMoFEM.cpp:926
NonlinearElasticElementInterface::setupSolverJacobianTS
MoFEMErrorCode setupSolverJacobianTS(const TSType type)
Definition: NonlinearElasticElementInterface.hpp:138
NonlinearElasticElementInterface::dM
SmartPetscObj< DM > dM
Definition: NonlinearElasticElementInterface.hpp:18
NonlinearElasticElementInterface::oRder
PetscInt oRder
Definition: NonlinearElasticElementInterface.hpp:21
MoFEM::DMMoFEMAddElement
PetscErrorCode DMMoFEMAddElement(DM dm, std::string fe_name)
add element to dm
Definition: DMMoFEM.cpp:501
MoFEM::DeprecatedCoreInterface
Deprecated interface functions.
Definition: DeprecatedCoreInterface.hpp:16
NonlinearElasticElementInterface::~NonlinearElasticElementInterface
~NonlinearElasticElementInterface()
Definition: NonlinearElasticElementInterface.hpp:43
CHKERR
#define CHKERR
Inline error check.
Definition: definitions.h:535
NonlinearElasticElementInterface::mField
MoFEM::Interface & mField
Definition: NonlinearElasticElementInterface.hpp:17
PostProcStress
Definition: PostProcStresses.hpp:17
GenericElementInterface
Set of functions declaring elements and setting operators for generic element interface.
Definition: GenericElementInterface.hpp:13
MoFEM::DMMoFEMTSSetIJacobian
PetscErrorCode DMMoFEMTSSetIJacobian(DM dm, const std::string fe_name, boost::shared_ptr< MoFEM::FEMethod > method, boost::shared_ptr< MoFEM::BasicMethod > pre_only, boost::shared_ptr< MoFEM::BasicMethod > post_only)
set TS Jacobian evaluation function
Definition: DMMoFEM.cpp:857
NonlinearElasticElementInterface::postProcessElement
MoFEMErrorCode postProcessElement(int step)
Definition: NonlinearElasticElementInterface.hpp:181
NonlinearElasticElementInterface::addElementsToDM
MoFEMErrorCode addElementsToDM(SmartPetscObj< DM > dm)
Definition: NonlinearElasticElementInterface.hpp:112
NonlinearElasticElementInterface::createElements
MoFEMErrorCode createElements()
Definition: NonlinearElasticElementInterface.hpp:75
NonlinearElasticElementInterface::meshNodeField
string meshNodeField
Definition: NonlinearElasticElementInterface.hpp:29
MoFEM::DMMoFEMTSSetI2Jacobian
PetscErrorCode DMMoFEMTSSetI2Jacobian(DM dm, const std::string fe_name, boost::shared_ptr< MoFEM::FEMethod > method, boost::shared_ptr< MoFEM::BasicMethod > pre_only, boost::shared_ptr< MoFEM::BasicMethod > post_only)
set TS Jacobian evaluation function
Definition: DMMoFEM.cpp:1021
MOFEM_LOG_C
#define MOFEM_LOG_C(channel, severity, format,...)
Definition: LogManager.hpp:311
MoFEM::DMMoFEMTSSetI2Function
PetscErrorCode DMMoFEMTSSetI2Function(DM dm, const std::string fe_name, boost::shared_ptr< MoFEM::FEMethod > method, boost::shared_ptr< MoFEM::BasicMethod > pre_only, boost::shared_ptr< MoFEM::BasicMethod > post_only)
set TS implicit function evaluation function
Definition: DMMoFEM.cpp:979
is_quasi_static
PetscBool is_quasi_static
Definition: plastic.cpp:190
simple
void simple(double P1[], double P2[], double P3[], double c[], const int N)
Definition: acoustic.cpp:69
convert.type
type
Definition: convert.py:64
NonlinearElasticElementInterface::getCommandLineParameters
MoFEMErrorCode getCommandLineParameters()
Definition: NonlinearElasticElementInterface.hpp:45
NonlinearElasticElementInterface::elasticElementPtr
boost::shared_ptr< NonlinearElasticElement > elasticElementPtr
Definition: NonlinearElasticElementInterface.hpp:24
NonlinearElasticElementInterface::setupSolverJacobianSNES
MoFEMErrorCode setupSolverJacobianSNES()
Definition: NonlinearElasticElementInterface.hpp:122
MoFEM::DMMoFEMSNESSetJacobian
PetscErrorCode DMMoFEMSNESSetJacobian(DM dm, const char fe_name[], MoFEM::FEMethod *method, MoFEM::BasicMethod *pre_only, MoFEM::BasicMethod *post_only)
set SNES Jacobian evaluation function
Definition: DMMoFEM.cpp:763
MoFEM::CoreInterface::check_field
virtual bool check_field(const std::string &name) const =0
check if field is in database
NonlinearElasticElementInterface::getBitRefLevel
BitRefLevel getBitRefLevel()
Definition: NonlinearElasticElementInterface.hpp:111
NonlinearElasticElementInterface::setupSolverFunctionSNES
MoFEMErrorCode setupSolverFunctionSNES()
Definition: NonlinearElasticElementInterface.hpp:130
GenericElementInterface::mBoundaryMarker
BcMarkerPtr mBoundaryMarker
Definition: GenericElementInterface.hpp:20
NonlinearElasticElementInterface::NonlinearElasticElementInterface
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)
Definition: NonlinearElasticElementInterface.hpp:31
NonlinearElasticElementInterface::setOperators
MoFEMErrorCode setOperators()
Definition: NonlinearElasticElementInterface.hpp:95
NonlinearElasticElementInterface::updateElementVariables
MoFEMErrorCode updateElementVariables()
Definition: NonlinearElasticElementInterface.hpp:180
MoFEM::DMMoFEMTSSetRHSFunction
PetscErrorCode DMMoFEMTSSetRHSFunction(DM dm, const std::string fe_name, boost::shared_ptr< MoFEM::FEMethod > method, boost::shared_ptr< MoFEM::BasicMethod > pre_only, boost::shared_ptr< MoFEM::BasicMethod > post_only)
set TS the right hand side function
Definition: DMMoFEM.cpp:886
NonlinearElasticElementInterface::positionField
string positionField
Definition: NonlinearElasticElementInterface.hpp:28
AINSWORTH_LEGENDRE_BASE
@ AINSWORTH_LEGENDRE_BASE
Ainsworth Cole (Legendre) approx. base .
Definition: definitions.h:60
MoFEM::DMMoFEMTSSetIFunction
PetscErrorCode DMMoFEMTSSetIFunction(DM dm, const char fe_name[], MoFEM::FEMethod *method, MoFEM::BasicMethod *pre_only, MoFEM::BasicMethod *post_only)
set TS implicit function evaluation function
Definition: DMMoFEM.cpp:804
GenericElementInterface::TSType
TSType
Definition: GenericElementInterface.hpp:16
MoFEM::Types::BitRefLevel
std::bitset< BITREFLEVEL_SIZE > BitRefLevel
Bit structure attached to each entity identifying to what mesh entity is attached.
Definition: Types.hpp:40
MoFEMFunctionBeginHot
#define MoFEMFunctionBeginHot
First executable line of each MoFEM function, used for error handling. Final line of MoFEM functions ...
Definition: definitions.h:440
MoFEM::DMoFEMLoopFiniteElements
PetscErrorCode DMoFEMLoopFiniteElements(DM dm, const char fe_name[], MoFEM::FEMethod *method, CacheTupleWeakPtr cache_ptr=CacheTupleSharedPtr())
Executes FEMethod for finite elements in DM.
Definition: DMMoFEM.cpp:590
NonlinearElasticElementInterface
Set of functions declaring elements and setting operators for generic element interface.
Definition: NonlinearElasticElementInterface.hpp:15
MoFEM::PetscOptionsGetInt
PetscErrorCode PetscOptionsGetInt(PetscOptions *, const char pre[], const char name[], PetscInt *ivalue, PetscBool *set)
Definition: DeprecatedPetsc.hpp:142
MoFEMFunctionReturn
#define MoFEMFunctionReturn(a)
Last executable line of each PETSc function used for error handling. Replaces return()
Definition: definitions.h:416
NonlinearElasticElementInterface::setupSolverFunctionTS
MoFEMErrorCode setupSolverFunctionTS(const TSType type)
Definition: NonlinearElasticElementInterface.hpp:159
MOFEM_NOT_IMPLEMENTED
@ MOFEM_NOT_IMPLEMENTED
Definition: definitions.h:32
NonlinearElasticElementInterface::addElementFields
MoFEMErrorCode addElementFields()
Definition: NonlinearElasticElementInterface.hpp:56
GenericElementInterface::IM2
@ IM2
Definition: GenericElementInterface.hpp:16
MoFEMFunctionBegin
#define MoFEMFunctionBegin
First executable line of each MoFEM function, used for error handling. Final line of MoFEM functions ...
Definition: definitions.h:346
NonlinearElasticElementInterface::isQuasiStatic
PetscBool isQuasiStatic
Definition: NonlinearElasticElementInterface.hpp:19
NonlinearElasticElementInterface::postProcMeshPtr
boost::shared_ptr< PostProcVolumeOnRefinedMesh > postProcMeshPtr
Definition: NonlinearElasticElementInterface.hpp:26
MoFEM::DMMoFEMSNESSetFunction
PetscErrorCode DMMoFEMSNESSetFunction(DM dm, const char fe_name[], MoFEM::FEMethod *method, MoFEM::BasicMethod *pre_only, MoFEM::BasicMethod *post_only)
set SNES residual evaluation function
Definition: DMMoFEM.cpp:722
GenericElementInterface::IM
@ IM
Definition: GenericElementInterface.hpp:16
MoFEM::PetscOptionsGetBool
PetscErrorCode PetscOptionsGetBool(PetscOptions *, const char pre[], const char name[], PetscBool *bval, PetscBool *set)
Definition: DeprecatedPetsc.hpp:182