52#include <HenckyOps.hpp>
95 char meshFileName[255];
97 meshFileName, 255, PETSC_NULL);
109 enum bases { AINSWORTH, DEMKOWICZ, LASBASETOPT };
110 const char *list_bases[LASBASETOPT] = {
"ainsworth",
"demkowicz"};
111 PetscInt choice_base_value = AINSWORTH;
113 LASBASETOPT, &choice_base_value, PETSC_NULL);
116 switch (choice_base_value) {
120 <<
"Set AINSWORTH_LEGENDRE_BASE for displacements";
125 <<
"Set DEMKOWICZ_JACOBI_BASE for displacements";
149 auto time_scale = boost::make_shared<TimeScale>();
160 pipeline_mng->getOpBoundaryRhsPipeline(),
mField,
"U", {time_scale},
161 "FORCE", Sev::inform);
165 pipeline_mng->getOpDomainRhsPipeline(),
mField,
"U", {time_scale},
166 "BODY_FORCE", Sev::inform);
169 CHKERR bc_mng->removeBlockDOFsOnEntities(
simple->getProblemName(),
"REMOVE_X",
171 CHKERR bc_mng->removeBlockDOFsOnEntities(
simple->getProblemName(),
"REMOVE_Y",
173 CHKERR bc_mng->removeBlockDOFsOnEntities(
simple->getProblemName(),
"REMOVE_Z",
176 simple->getProblemName(),
"U");
179 CHKERR bc_mng->addBlockDOFsToMPCs(
simple->getProblemName(),
"U");
191 auto add_domain_ops_lhs = [&](
auto &pip) {
194 CHKERR HenckyOps::opFactoryDomainLhs<SPACE_DIM, PETSC, GAUSS, DomainEleOp>(
195 mField, pip,
"U",
"MAT_ELASTIC", Sev::inform);
199 auto add_domain_ops_rhs = [&](
auto &pip) {
202 CHKERR HenckyOps::opFactoryDomainRhs<SPACE_DIM, PETSC, GAUSS, DomainEleOp>(
203 mField, pip,
"U",
"MAT_ELASTIC", Sev::inform);
207 CHKERR add_domain_ops_lhs(pipeline_mng->getOpDomainLhsPipeline());
208 CHKERR add_domain_ops_rhs(pipeline_mng->getOpDomainRhsPipeline());
232 "out_step_" + boost::lexical_cast<std::string>(
ts_step) +
".h5m");
248 auto dm =
simple->getDM();
249 auto ts = pipeline_mng->createTSIM();
252 auto create_post_proc_fe = [dm,
this,
simple]() {
253 auto post_proc_ele_domain = [dm,
this](
auto &pip_domain) {
255 auto common_ptr = commonDataFactory<SPACE_DIM, GAUSS, DomainEleOp>(
256 mField, pip_domain,
"U",
"MAT_ELASTIC", Sev::inform);
260 auto post_proc_fe_bdy = boost::make_shared<PostProcEleBdy>(
mField);
261 auto u_ptr = boost::make_shared<MatrixDouble>();
262 post_proc_fe_bdy->getOpPtrVector().push_back(
266 auto common_ptr = post_proc_ele_domain(op_loop_side->getOpPtrVector());
267 post_proc_fe_bdy->getOpPtrVector().push_back(op_loop_side);
271 post_proc_fe_bdy->getOpPtrVector().push_back(
275 post_proc_fe_bdy->getPostProcMesh(),
276 post_proc_fe_bdy->getMapGaussPts(),
282 {{
"GRAD", common_ptr->matGradPtr},
283 {
"FIRST_PIOLA", common_ptr->getMatFirstPiolaStress()}},
290 return post_proc_fe_bdy;
293 auto add_extra_finite_elements_to_ksp_solver_pipelines = [&]() {
296 auto pre_proc_ptr = boost::make_shared<FEMethod>();
297 auto post_proc_rhs_ptr = boost::make_shared<FEMethod>();
298 auto post_proc_lhs_ptr = boost::make_shared<FEMethod>();
300 auto time_scale = boost::make_shared<TimeScale>();
302 auto get_bc_hook_rhs = [
this, pre_proc_ptr, time_scale]() {
305 {time_scale},
false)();
309 pre_proc_ptr->preProcessHook = get_bc_hook_rhs;
311 auto get_post_proc_hook_rhs = [
this, post_proc_rhs_ptr]() {
314 mField, post_proc_rhs_ptr,
nullptr, Sev::verbose)();
316 mField, post_proc_rhs_ptr, 1.)();
320 auto get_post_proc_hook_lhs = [
this, post_proc_lhs_ptr]() {
323 mField, post_proc_lhs_ptr, 1.)();
327 post_proc_rhs_ptr->postProcessHook = get_post_proc_hook_rhs;
328 post_proc_lhs_ptr->postProcessHook = get_post_proc_hook_lhs;
332 ts_ctx_ptr->getPreProcessIFunction().push_front(pre_proc_ptr);
333 ts_ctx_ptr->getPreProcessIJacobian().push_front(pre_proc_ptr);
334 ts_ctx_ptr->getPostProcessIFunction().push_back(post_proc_rhs_ptr);
335 ts_ctx_ptr->getPostProcessIJacobian().push_back(post_proc_lhs_ptr);
341 CHKERR add_extra_finite_elements_to_ksp_solver_pipelines();
343 auto create_monitor_fe = [dm](
auto &&post_proc_fe) {
344 return boost::make_shared<Monitor>(dm, post_proc_fe);
348 boost::shared_ptr<FEMethod> null_fe;
349 auto monitor_ptr = create_monitor_fe(create_post_proc_fe());
351 null_fe, monitor_ptr);
355 CHKERR TSSetDuration(ts, PETSC_DEFAULT, ftime);
356 CHKERR TSSetExactFinalTime(ts, TS_EXACTFINALTIME_MATCHSTEP);
361 CHKERR TSSetFromOptions(ts);
364 CHKERR TSGetTime(ts, &ftime);
366 PetscInt steps, snesfails, rejects, nonlinits, linits;
367 CHKERR TSGetStepNumber(ts, &steps);
368 CHKERR TSGetSNESFailures(ts, &snesfails);
369 CHKERR TSGetStepRejections(ts, &rejects);
370 CHKERR TSGetSNESIterations(ts, &nonlinits);
371 CHKERR TSGetKSPIterations(ts, &linits);
373 "steps %d (%d rejected, %d SNES fails), ftime %g, nonlinits "
375 steps, rejects, snesfails, ftime, nonlinits, linits);
386 auto dm =
simple->getDM();
392 CHKERR VecNorm(T, NORM_2, &nrm2);
393 MOFEM_LOG(
"EXAMPLE", Sev::inform) <<
"Solution norm " << nrm2;
395 auto post_proc_norm_fe = boost::make_shared<DomainEle>(
mField);
397 auto post_proc_norm_rule_hook = [](int, int,
int p) ->
int {
return 2 * p; };
398 post_proc_norm_fe->getRuleHook = post_proc_norm_rule_hook;
401 post_proc_norm_fe->getOpPtrVector(), {H1});
403 enum NORMS { U_NORM_L2 = 0, PIOLA_NORM, LAST_NORM };
407 CHKERR VecZeroEntries(norms_vec);
409 auto u_ptr = boost::make_shared<MatrixDouble>();
410 post_proc_norm_fe->getOpPtrVector().push_back(
413 post_proc_norm_fe->getOpPtrVector().push_back(
416 auto common_ptr = commonDataFactory<SPACE_DIM, GAUSS, DomainEleOp>(
417 mField, post_proc_norm_fe->getOpPtrVector(),
"U",
"MAT_ELASTIC",
420 post_proc_norm_fe->getOpPtrVector().push_back(
422 common_ptr->getMatFirstPiolaStress(), norms_vec, PIOLA_NORM));
427 CHKERR VecAssemblyBegin(norms_vec);
428 CHKERR VecAssemblyEnd(norms_vec);
433 CHKERR VecGetArrayRead(norms_vec, &norms);
435 <<
"norm_u: " << std::scientific << std::sqrt(norms[U_NORM_L2]);
437 <<
"norm_piola: " << std::scientific << std::sqrt(norms[PIOLA_NORM]);
438 CHKERR VecRestoreArrayRead(norms_vec, &norms);
448 PetscInt test_nb = 0;
449 PetscBool test_flg = PETSC_FALSE;
458 CHKERR VecNorm(T, NORM_2, &nrm2);
459 MOFEM_LOG(
"EXAMPLE", Sev::verbose) <<
"Regression norm " << nrm2;
460 double regression_value = 0;
463 regression_value = 1.02789;
466 regression_value = 1.8841e+00;
469 regression_value = 1.8841e+00;
472 regression_value = 4.9625e+00;
475 regression_value = 6.6394e+00;
478 regression_value = 4.98764e+00;
481 regression_value = 4.9473e+00;
484 regression_value = 2.5749e-01;
491 if (fabs(nrm2 - regression_value) > 1e-2)
493 "Regression test field; wrong norm value. %6.4e != %6.4e", nrm2,
509int main(
int argc,
char *argv[]) {
512 const char param_file[] =
"param_file.petsc";
516 auto core_log = logging::core::get();
525 DMType dm_name =
"DMMOFEM";
530 moab::Core mb_instance;
531 moab::Interface &moab = mb_instance;
#define MOFEM_LOG_C(channel, severity, format,...)
#define MOFEM_TAG_AND_LOG(channel, severity, tag)
Tag and log in channel.
void simple(double P1[], double P2[], double P3[], double c[], const int N)
ElementsAndOps< SPACE_DIM >::DomainEle DomainEle
ElementsAndOps< SPACE_DIM >::BoundaryEle BoundaryEle
#define CATCH_ERRORS
Catch errors.
FieldApproximationBase
approximation base
@ AINSWORTH_LEGENDRE_BASE
Ainsworth Cole (Legendre) approx. base .
#define MoFEMFunctionReturnHot(a)
Last executable line of each PETSc function used for error handling. Replaces return()
#define MoFEMFunctionBegin
First executable line of each MoFEM function, used for error handling. Final line of MoFEM functions ...
@ MOFEM_ATOM_TEST_INVALID
#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 ...
PostProcEleByDim< SPACE_DIM >::PostProcEleBdy PostProcEleBdy
PetscErrorCode DMoFEMMeshToLocalVector(DM dm, Vec l, InsertMode mode, ScatterMode scatter_mode, RowColData rc=RowColData::COL)
set local (or ghosted) vector values on mesh for partition only
PetscErrorCode DMRegister_MoFEM(const char sname[])
Register MoFEM problem.
PetscErrorCode DMoFEMLoopFiniteElements(DM dm, const char fe_name[], MoFEM::FEMethod *method, CacheTupleWeakPtr cache_ptr=CacheTupleSharedPtr())
Executes FEMethod for finite elements in DM.
auto createDMVector(DM dm, RowColData rc=RowColData::COL)
Get smart vector from DM.
static LoggerType & setLog(const std::string channel)
Set ans resset chanel logger.
#define MOFEM_LOG(channel, severity)
Log.
#define MOFEM_LOG_TAG(channel, tag)
Tag channel.
#define MOFEM_LOG_CHANNEL(channel)
Set and reset channel.
PetscErrorCode MoFEMErrorCode
MoFEM/PETSc error code.
implementation of Data Operators for Forces and Sources
PetscErrorCode DMMoFEMTSSetMonitor(DM dm, TS ts, 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 Monitor To TS solver.
auto getDMTsCtx(DM dm)
Get TS context data structure used by DM.
PetscErrorCode PetscOptionsGetInt(PetscOptions *, const char pre[], const char name[], PetscInt *ivalue, PetscBool *set)
auto createVectorMPI(MPI_Comm comm, PetscInt n, PetscInt N)
Create MPI Vector.
PetscErrorCode PetscOptionsGetEList(PetscOptions *, const char pre[], const char name[], const char *const *list, PetscInt next, PetscInt *value, PetscBool *set)
PetscErrorCode PetscOptionsGetString(PetscOptions *, const char pre[], const char name[], char str[], size_t size, PetscBool *set)
OpPostProcMapInMoab< SPACE_DIM, SPACE_DIM > OpPPMap
static constexpr int approx_order
MoFEMErrorCode boundaryCondition()
MoFEMErrorCode assembleSystem()
MoFEMErrorCode readMesh()
FieldApproximationBase base
Choice of finite element basis functions
MoFEMErrorCode checkResults()
MoFEMErrorCode solveSystem()
Example(MoFEM::Interface &m_field)
MoFEMErrorCode runProblem()
MoFEMErrorCode gettingNorms()
[Solve]
MoFEM::Interface & mField
Reference to MoFEM interface.
MoFEMErrorCode setupProblem()
MoFEMErrorCode outputResults()
Add operators pushing bases from local to physical configuration.
Boundary condition manager for finite element problem setup.
virtual MPI_Comm & get_comm() const =0
virtual int get_comm_rank() const =0
static MoFEMErrorCode Initialize(int *argc, char ***args, const char file[], const char help[])
Initializes the MoFEM database PETSc, MOAB and MPI.
static MoFEMErrorCode Finalize()
Checks for options to be called at the conclusion of the program.
Deprecated interface functions.
Definition of the displacement bc data structure.
Data on single entity (This is passed as argument to DataOperator::doWork)
Class (Function) to enforce essential constrains on the left hand side diagonal.
Class (Function) to enforce essential constrains on the right hand side diagonal.
Class (Function) to calculate residual side diagonal.
Class (Function) to enforce essential constrains.
Structure for user loop methods on finite elements.
static boost::shared_ptr< SinkType > createSink(boost::shared_ptr< std::ostream > stream_ptr, std::string comm_filter)
Create a sink object.
static boost::shared_ptr< std::ostream > getStrmWorld()
Get the strm world object.
Get norm of input MatrixDouble for Tensor1.
Get norm of input MatrixDouble for Tensor2.
Specialization for double precision vector field values calculation.
Element used to execute operators on side of the element.
Post post-proc data at points from hash maps.
Template struct for dimension-specific finite element types.
PipelineManager interface.
Simple interface for fast problem set-up.
MoFEMErrorCode getOptions()
get options
const std::string getDomainFEName() const
Get the Domain FE Name.
intrusive_ptr for managing petsc objects
PetscInt ts_step
Current time step number.
MoFEMErrorCode getInterface(IFACE *&iface) const
Get interface reference to pointer of interface.
[Push operators to pipeline]
boost::shared_ptr< PostProcEleBdy > postProc
MoFEMErrorCode postProcess()
Post-processing function executed at loop completion.
boost::shared_ptr< PostProcEle > postProc
Monitor(SmartPetscObj< DM > dm, boost::shared_ptr< PostProcEleBdy > post_proc)
PipelineManager::ElementsAndOpsByDim< 2 >::FaceSideEle SideEle
PipelineManager::ElementsAndOpsByDim< 3 >::FaceSideEle SideEle
#define EXECUTABLE_DIMENSION
ElementsAndOps< SPACE_DIM >::SideEle SideEle
static char help[]
[Check]