106 enum bases { AINSWORTH, DEMKOWICZ, LASBASETOPT };
107 const char *list_bases[LASBASETOPT] = {
"ainsworth",
"demkowicz"};
108 PetscInt choice_base_value = AINSWORTH;
110 LASBASETOPT, &choice_base_value, PETSC_NULLPTR);
113 switch (choice_base_value) {
117 <<
"Set AINSWORTH_LEGENDRE_BASE for displacements";
122 <<
"Set DEMKOWICZ_JACOBI_BASE for displacements";
146 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");
187 auto add_domain_ops_lhs = [&](
auto &pip) {
190 CHKERR HenckyOps::opFactoryDomainLhs<SPACE_DIM, PETSC, GAUSS, DomainEleOp>(
191 mField, pip,
"U",
"MAT_ELASTIC", Sev::inform);
195 auto add_domain_ops_rhs = [&](
auto &pip) {
198 CHKERR HenckyOps::opFactoryDomainRhs<SPACE_DIM, PETSC, GAUSS, DomainEleOp>(
199 mField, pip,
"U",
"MAT_ELASTIC", Sev::inform);
203 CHKERR add_domain_ops_lhs(pipeline_mng->getOpDomainLhsPipeline());
204 CHKERR add_domain_ops_rhs(pipeline_mng->getOpDomainRhsPipeline());
223 std::pair<boost::shared_ptr<PostProcEleDomain>,
224 boost::shared_ptr<PostProcEleBdy>>
226 boost::shared_ptr<DomainEle> reaction_fe)
235 auto make_vtk = [&]() {
241 "out_step_" + boost::lexical_cast<std::string>(
ts_step) +
".h5m");
247 "out_skin_" + boost::lexical_cast<std::string>(
ts_step) +
".h5m");
252 auto calculate_reaction = [&]() {
265 CHKERR calculate_reaction();
284 auto dm =
simple->getDM();
285 auto ts = pipeline_mng->createTSIM();
287 PetscBool post_proc_vol;
288 PetscBool post_proc_skin;
291 post_proc_vol = PETSC_TRUE;
292 post_proc_skin = PETSC_FALSE;
294 post_proc_vol = PETSC_FALSE;
295 post_proc_skin = PETSC_TRUE;
303 auto create_post_proc_fe = [dm,
this,
simple, post_proc_vol,
305 auto post_proc_ele_domain = [dm,
this](
auto &pip_domain) {
307 auto common_ptr = commonDataFactory<SPACE_DIM, GAUSS, DomainEleOp>(
308 mField, pip_domain,
"U",
"MAT_ELASTIC", Sev::inform);
312 auto post_proc_map = [
this](
auto &pip,
auto u_ptr,
auto common_ptr) {
317 pip->getOpPtrVector().push_back(
319 new OpPPMap(pip->getPostProcMesh(), pip->getMapGaussPts(), {},
321 {{
"GRAD", common_ptr->matGradPtr},
322 {
"FIRST_PIOLA", common_ptr->getMatFirstPiolaStress()}},
327 auto push_post_proc_bdy = [dm,
this,
simple, post_proc_skin,
328 &post_proc_ele_domain,
329 &post_proc_map](
auto &pip_bdy) {
330 if (post_proc_skin == PETSC_FALSE)
331 return boost::shared_ptr<PostProcEleBdy>();
333 auto u_ptr = boost::make_shared<MatrixDouble>();
334 pip_bdy->getOpPtrVector().push_back(
338 auto common_ptr = post_proc_ele_domain(op_loop_side->getOpPtrVector());
339 pip_bdy->getOpPtrVector().push_back(op_loop_side);
341 CHKERR post_proc_map(pip_bdy, u_ptr, common_ptr);
346 auto push_post_proc_domain = [dm,
this,
simple, post_proc_vol,
347 &post_proc_ele_domain,
348 &post_proc_map](
auto &pip_domain) {
349 if (post_proc_vol == PETSC_FALSE)
350 return boost::shared_ptr<PostProcEleDomain>();
352 auto u_ptr = boost::make_shared<MatrixDouble>();
353 pip_domain->getOpPtrVector().push_back(
355 auto common_ptr = post_proc_ele_domain(pip_domain->getOpPtrVector());
357 CHKERR post_proc_map(pip_domain, u_ptr, common_ptr);
362 auto post_proc_fe_domain = boost::make_shared<PostProcEleDomain>(
mField);
363 auto post_proc_fe_bdy = boost::make_shared<PostProcEleBdy>(
mField);
365 return std::make_pair(push_post_proc_domain(post_proc_fe_domain),
366 push_post_proc_bdy(post_proc_fe_bdy));
369 auto add_extra_finite_elements_to_ksp_solver_pipelines = [&]() {
372 auto pre_proc_ptr = boost::make_shared<FEMethod>();
373 auto post_proc_rhs_ptr = boost::make_shared<FEMethod>();
374 auto post_proc_lhs_ptr = boost::make_shared<FEMethod>();
376 auto time_scale = boost::make_shared<TimeScale>();
378 auto get_bc_hook_rhs = [
this, pre_proc_ptr, time_scale]() {
381 {time_scale},
false)();
385 pre_proc_ptr->preProcessHook = get_bc_hook_rhs;
387 auto get_post_proc_hook_rhs = [
this, post_proc_rhs_ptr]() {
390 mField, post_proc_rhs_ptr,
nullptr, Sev::verbose)();
392 mField, post_proc_rhs_ptr, 1.)();
395 auto get_post_proc_hook_lhs = [
this, post_proc_lhs_ptr]() {
398 mField, post_proc_lhs_ptr, 1.)();
401 post_proc_rhs_ptr->postProcessHook = get_post_proc_hook_rhs;
402 post_proc_lhs_ptr->postProcessHook = get_post_proc_hook_lhs;
406 ts_ctx_ptr->getPreProcessIFunction().push_front(pre_proc_ptr);
407 ts_ctx_ptr->getPreProcessIJacobian().push_front(pre_proc_ptr);
408 ts_ctx_ptr->getPostProcessIFunction().push_back(post_proc_rhs_ptr);
409 ts_ctx_ptr->getPostProcessIJacobian().push_back(post_proc_lhs_ptr);
415 CHKERR add_extra_finite_elements_to_ksp_solver_pipelines();
417 auto create_monitor_fe = [dm](
auto &&post_proc_fe,
auto &&reactionFe) {
418 return boost::make_shared<Monitor>(dm, post_proc_fe, reactionFe);
422 boost::shared_ptr<FEMethod> null_fe;
423 auto monitor_ptr = create_monitor_fe(create_post_proc_fe(), reactionFe);
425 null_fe, monitor_ptr);
429 CHKERR TSSetMaxTime(ts, ftime);
430 CHKERR TSSetExactFinalTime(ts, TS_EXACTFINALTIME_MATCHSTEP);
433 CHKERR TSSetI2Jacobian(ts,
B,
B, PETSC_NULLPTR, PETSC_NULLPTR);
436 CHKERR TSSetFromOptions(ts);
439 CHKERR TSGetTime(ts, &ftime);
441 PetscInt steps, snesfails, rejects, nonlinits, linits;
442 CHKERR TSGetStepNumber(ts, &steps);
443 CHKERR TSGetSNESFailures(ts, &snesfails);
444 CHKERR TSGetStepRejections(ts, &rejects);
445 CHKERR TSGetSNESIterations(ts, &nonlinits);
446 CHKERR TSGetKSPIterations(ts, &linits);
448 "steps %d (%d rejected, %d SNES fails), ftime %g, nonlinits "
450 steps, rejects, snesfails, ftime, nonlinits, linits);
461 auto dm =
simple->getDM();
467 CHKERR VecNorm(T, NORM_2, &nrm2);
468 MOFEM_LOG(
"EXAMPLE", Sev::inform) <<
"Solution norm " << nrm2;
470 auto post_proc_norm_fe = boost::make_shared<DomainEle>(
mField);
472 auto post_proc_norm_rule_hook = [](int, int,
int p) ->
int {
return 2 * p; };
473 post_proc_norm_fe->getRuleHook = post_proc_norm_rule_hook;
476 post_proc_norm_fe->getOpPtrVector(), {H1});
478 enum NORMS { U_NORM_L2 = 0, PIOLA_NORM, LAST_NORM };
482 CHKERR VecZeroEntries(norms_vec);
484 auto u_ptr = boost::make_shared<MatrixDouble>();
485 post_proc_norm_fe->getOpPtrVector().push_back(
488 post_proc_norm_fe->getOpPtrVector().push_back(
491 auto common_ptr = commonDataFactory<SPACE_DIM, GAUSS, DomainEleOp>(
492 mField, post_proc_norm_fe->getOpPtrVector(),
"U",
"MAT_ELASTIC",
495 post_proc_norm_fe->getOpPtrVector().push_back(
497 common_ptr->getMatFirstPiolaStress(), norms_vec, PIOLA_NORM));
502 CHKERR VecAssemblyBegin(norms_vec);
503 CHKERR VecAssemblyEnd(norms_vec);
508 CHKERR VecGetArrayRead(norms_vec, &norms);
510 <<
"norm_u: " << std::scientific << std::sqrt(norms[U_NORM_L2]);
512 <<
"norm_piola: " << std::scientific << std::sqrt(norms[PIOLA_NORM]);
513 CHKERR VecRestoreArrayRead(norms_vec, &norms);
523 PetscInt test_nb = 0;
524 PetscBool test_flg = PETSC_FALSE;
533 CHKERR VecNorm(T, NORM_2, &nrm2);
534 MOFEM_LOG(
"EXAMPLE", Sev::verbose) <<
"Regression norm " << nrm2;
535 double regression_value = 0;
538 regression_value = 1.02789;
541 regression_value = 1.8841e+00;
544 regression_value = 1.8841e+00;
547 regression_value = 4.9625e+00;
550 regression_value = 6.6394e+00;
553 regression_value = 4.98764e+00;
556 regression_value = 4.9473e+00;
559 regression_value = 2.5749e-01;
566 if (fabs(nrm2 - regression_value) > 1e-2)
568 "Regression test field; wrong norm value. %6.4e != %6.4e", nrm2,
584int main(
int argc,
char *argv[]) {
587 const char param_file[] =
"param_file.petsc";
591 auto core_log = logging::core::get();
600 DMType dm_name =
"DMMOFEM";
605 moab::Core mb_instance;
606 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 >::PostProcEleDomain PostProcEleDomain
PostProcEleByDim< SPACE_DIM >::PostProcEleBdy PostProcEleBdy
PetscErrorCode DMoFEMMeshToLocalVector(DM dm, Vec l, InsertMode mode, ScatterMode scatter_mode)
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)
Get smart vector from DM.
auto createDMMatrix(DM dm)
Get smart matrix 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)
PetscErrorCode PetscOptionsGetBool(PetscOptions *, const char pre[], const char name[], PetscBool *bval, 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)
OpPostProcMapInMoab< SPACE_DIM, SPACE_DIM > OpPPMap
#define EXECUTABLE_DIMENSION
ElementsAndOps< SPACE_DIM >::SideEle SideEle
static constexpr int approx_order
MoFEMErrorCode boundaryCondition()
MoFEMErrorCode assembleSystem()
MoFEMErrorCode readMesh()
boost::shared_ptr< DomainEle > reactionFe
FieldApproximationBase base
MoFEMErrorCode checkResults()
MoFEMErrorCode solveSystem()
Example(MoFEM::Interface &m_field)
MoFEMErrorCode runProblem()
MoFEMErrorCode gettingNorms()
[Solve]
MoFEM::Interface & mField
MoFEMErrorCode setupProblem()
MoFEMErrorCode outputResults()
Add operators pushing bases from local to physical configuration.
boost::weak_ptr< CacheTuple > getCacheWeakPtr() const
Get the cache weak ptr object.
Simple interface for fast problem set-up.
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.
Get values at integration pts for tensor field rank 1, i.e. vector field.
Element used to execute operators on side of the element.
Post post-proc data at points from hash maps.
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
time step number
MoFEMErrorCode getInterface(IFACE *&iface) const
Get interface reference to pointer of interface.
[Push operators to pipeline]
Monitor(SmartPetscObj< DM > dm, std::pair< boost::shared_ptr< PostProcEleDomain >, boost::shared_ptr< PostProcEleBdy > > pair_post_proc, boost::shared_ptr< DomainEle > reaction_fe)
MoFEMErrorCode postProcess()
function is run at the end of loop
boost::shared_ptr< DomainEle > reactionFe
boost::shared_ptr< PostProcEleDomain > postProcDomain
boost::shared_ptr< PostProcEleBdy > postProcSkin
PipelineManager::ElementsAndOpsByDim< 2 >::FaceSideEle SideEle
PipelineManager::ElementsAndOpsByDim< 3 >::FaceSideEle SideEle
static char help[]
[Check]