v0.14.0
adolc_plasticity.cpp
Go to the documentation of this file.
1 /**
2  * \file adolc_plasticity.cpp
3  * \ingroup adoc_plasticity
4  * \example adolc_plasticity.cpp
5  *
6  * \brife Implementation of plasticity problem using ADOLC-C
7  *
8  */
9 #include <MoFEM.hpp>
10 #include <MatrixFunction.hpp>
11 
12 using namespace MoFEM;
13 
14 constexpr int SPACE_DIM =
15  EXECUTABLE_DIMENSION; //< Space dimension of problem, mesh
16 
18 
19 /** Select finite element type for integration on domain based on problem
20  * dimension
21  */
23 
24 /** Select finite element type for integrate on boundary based on problem
25  * dimension
26  */
27 using BoundaryEle =
29 /** Operators used to assemble domain integrals
30  */
32 
33 /** Operators used to assemble boundary integrals
34  */
36 
37 /** Linear forms used to integrate body forces
38  */
39 using DomainNaturalBC =
41 
42 /** Select linear froms reading data from blockest (e.g. "BODY_FORCE") and
43  * applying body force.
44  */
45 using OpBodyForce =
47 
48 // Select natural BC boundary condition
49 
50 // Use natural boundary conditions implemented with adv-1 example which includes
51 // spring BC
52 #include <ContactNaturalBC.hpp>
53 
54 /** Use Gauss quadrature rule and PETSc assembly to integrate neural boundary
55  * conditions. Select linear forms operators.
56  */
57 using BoundaryRhsBCs =
59 
60 /* Use specialization from adv-1 integrating boundary conditions on forces and
61  * with springs. OP is used to integrate the right hand side
62  */
63 using OpBoundaryRhsBCs =
65 
66 /** Use Gauss quadrature rule and PETSc assembly to integrate neural boundary
67  * conditions. Select bi-linear forms operators.
68  */
69 using BoundaryLhsBCs =
71 
72 /** Use specialization from adv-1 integrating boundary conditions on forces and
73  * with springs
74  */
75 using OpBoundaryLhsBCs =
77 
78 // Note: We create only skin post-processing mesh.
79 
80 template <int DIM>
81 struct ElementsAndOps; //< Select finite elements and operators used for
82  // postprocessing and contact space
83 
84 template <> struct ElementsAndOps<2> {
88  static constexpr FieldSpace CONTACT_SPACE = HCURL;
89 };
90 
91 template <> struct ElementsAndOps<3> {
95  static constexpr FieldSpace CONTACT_SPACE = HDIV;
96 };
97 // Define contact space by dimension
101 
105 
106 #include <ADOLCPlasticity.hpp>
108 using namespace ADOLCPlasticity;
109 double scale = 1.;
110 #ifdef ADD_CONTACT
111 #ifdef PYTHON_SDF
112 #include <boost/python.hpp>
113 #include <boost/python/def.hpp>
114 #include <boost/python/numpy.hpp>
115 namespace bp = boost::python;
116 namespace np = boost::python::numpy;
117 #endif
118 namespace ContactOps {
119 
120 double cn_contact = 0.1;
121 
122 }; // namespace ContactOps
123 
124 #include <ContactOps.hpp>
125 #endif // ADD_CONTACT
126 
128 
129  PlasticProblem(MoFEM::Interface &m_field) : mField(m_field) {}
130 
131  MoFEMErrorCode runProblem();
132 
133 private:
135 
136  MoFEMErrorCode readMesh();
137  MoFEMErrorCode setupProblem();
138  MoFEMErrorCode boundaryCondition();
139  MoFEMErrorCode assembleSystem();
140  MoFEMErrorCode solveSystem();
141  MoFEMErrorCode gettingNorms();
142  MoFEMErrorCode outputResults();
143  MoFEMErrorCode checkResults();
144 
145  int approxOrder = 2;
146  int geom_order = 2;
148  boost::shared_ptr<ClosestPointProjection> cpPtr; ///< Closest point
149  ///< projection
150 #ifdef ADD_CONTACT
151 #ifdef PYTHON_SDF
152  boost::shared_ptr<ContactOps::SDFPython> sdfPythonPtr;
153 #endif
154 #endif // ADD_CONTACT
155 };
156 
157 //! [Run problem]
160  CHKERR readMesh();
161  CHKERR setupProblem();
162  CHKERR boundaryCondition();
163  CHKERR assembleSystem();
164  CHKERR solveSystem();
165  CHKERR gettingNorms();
166  CHKERR outputResults();
167  CHKERR checkResults();
169 }
170 //! [Run problem]
171 
172 //! [Read mesh]
175  auto simple = mField.getInterface<Simple>();
176  CHKERR simple->getOptions();
177  CHKERR simple->loadFile();
178 
179  if (simple->getDim() != SPACE_DIM)
180  SETERRQ2(PETSC_COMM_WORLD, MOFEM_DATA_INCONSISTENCY,
181  "Wrong dimension of mesh %d != %d", simple->getDim(), SPACE_DIM);
182 
184 }
185 //! [Read mesh]
186 
187 //! [Set up problem]
190  Simple *simple = mField.getInterface<Simple>();
191 
192  enum bases { AINSWORTH, DEMKOWICZ, LASBASETOPT };
193  const char *list_bases[LASBASETOPT] = {"ainsworth", "demkowicz"};
194  PetscInt choice_base_value = AINSWORTH;
195  CHKERR PetscOptionsGetEList(PETSC_NULL, NULL, "-base", list_bases,
196  LASBASETOPT, &choice_base_value, PETSC_NULL);
197  CHKERR PetscOptionsGetInt(PETSC_NULL, "", "-order", &approxOrder, PETSC_NULL);
198  CHKERR PetscOptionsGetInt(PETSC_NULL, "", "-geom_order", &geom_order,
199  PETSC_NULL);
200 
201  switch (choice_base_value) {
202  case AINSWORTH:
203  approxBase = AINSWORTH_LEGENDRE_BASE;
204  MOFEM_LOG("WORLD", Sev::inform)
205  << "Set AINSWORTH_LEGENDRE_BASE for displacements";
206  break;
207  case DEMKOWICZ:
208  approxBase = DEMKOWICZ_JACOBI_BASE;
209  MOFEM_LOG("WORLD", Sev::inform)
210  << "Set DEMKOWICZ_JACOBI_BASE for displacements";
211  break;
212  default:
213  approxBase = LASTBASE;
214  break;
215  }
216 
217  // Add field
218  CHKERR simple->addDomainField("U", H1, approxBase, SPACE_DIM);
219  CHKERR simple->addBoundaryField("U", H1, approxBase, SPACE_DIM);
220  CHKERR simple->addDataField("GEOMETRY", H1, approxBase, SPACE_DIM);
221 
222 #ifdef ADD_CONTACT
223  CHKERR simple->addDomainField("SIGMA", CONTACT_SPACE, DEMKOWICZ_JACOBI_BASE,
224  SPACE_DIM);
225  CHKERR simple->addBoundaryField("SIGMA", CONTACT_SPACE, DEMKOWICZ_JACOBI_BASE,
226  SPACE_DIM);
227  auto get_skin = [&]() {
228  Range body_ents;
229  CHKERR mField.get_moab().get_entities_by_dimension(0, SPACE_DIM, body_ents);
230  Skinner skin(&mField.get_moab());
231  Range skin_ents;
232  CHKERR skin.find_skin(0, body_ents, false, skin_ents);
233  return skin_ents;
234  };
235 
236  auto filter_blocks = [&](auto skin) {
237  bool is_contact_block = false;
238  Range contact_range;
239  for (auto m :
240  mField.getInterface<MeshsetsManager>()->getCubitMeshsetPtr(std::regex(
241 
242  (boost::format("%s(.*)") % "CONTACT").str()
243 
244  ))
245 
246  ) {
247  is_contact_block =
248  true; ///< bloks interation is collectibe, so that is set irrespective
249  ///< if there are enerities in given rank or not in the block
250  MOFEM_LOG("CONTACT", Sev::inform)
251  << "Find contact block set: " << m->getName();
252  auto meshset = m->getMeshset();
253  Range contact_meshset_range;
254  CHKERR mField.get_moab().get_entities_by_dimension(
255  meshset, SPACE_DIM - 1, contact_meshset_range, true);
256 
257  CHKERR mField.getInterface<CommInterface>()->synchroniseEntities(
258  contact_meshset_range);
259  contact_range.merge(contact_meshset_range);
260  }
261  if (is_contact_block) {
262  MOFEM_LOG("SYNC", Sev::inform)
263  << "Nb entities in contact surface: " << contact_range.size();
264  MOFEM_LOG_SYNCHRONISE(mField.get_comm());
265  skin = intersect(skin, contact_range);
266  }
267  return skin;
268  };
269 
270  auto filter_true_skin = [&](auto skin) {
271  Range boundary_ents;
272  ParallelComm *pcomm =
273  ParallelComm::get_pcomm(&mField.get_moab(), MYPCOMM_INDEX);
274  CHKERR pcomm->filter_pstatus(skin, PSTATUS_SHARED | PSTATUS_MULTISHARED,
275  PSTATUS_NOT, -1, &boundary_ents);
276  return boundary_ents;
277  };
278 
279  auto boundary_ents = filter_true_skin(filter_blocks(get_skin()));
280 #ifdef ADD_CONTACT
281  CHKERR simple->setFieldOrder("SIGMA", 0);
282  CHKERR simple->setFieldOrder("SIGMA", approxOrder - 1, &boundary_ents);
283  CHKERR PetscOptionsGetScalar(PETSC_NULL, "", "-cn_contact",
284  &ContactOps::cn_contact, PETSC_NULL);
285  MOFEM_LOG("CONTACT", Sev::inform) << "cn_contact " << ContactOps::cn_contact;
286 
287 #endif
288 
289 #ifdef PYTHON_SDF
290  sdfPythonPtr = boost::make_shared<ContactOps::SDFPython>();
291  CHKERR sdfPythonPtr->sdfInit("sdf.py");
292  ContactOps::sdfPythonWeakPtr = sdfPythonPtr;
293 #endif
294 #endif
295 
296  CHKERR simple->setFieldOrder("U", approxOrder);
297  CHKERR simple->setFieldOrder("GEOMETRY", geom_order);
298  CHKERR simple->setUp();
299 
300  auto project_ho_geometry = [&]() {
301  Projection10NodeCoordsOnField ent_method(mField, "GEOMETRY");
302  return mField.loop_dofs("GEOMETRY", ent_method);
303  };
304  PetscBool project_geometry = PETSC_TRUE;
305  CHKERR PetscOptionsGetBool(PETSC_NULL, "", "-project_geometry",
306  &project_geometry, PETSC_NULL);
307  if (project_geometry) {
308  CHKERR project_ho_geometry();
309  }
310 
311  //! [Material models selection]
312 
313  /**
314  * FIXME: Here only array of material models is initalized. Each model has
315  * unique set of the ADOL-C tags. Pointer is attached based on block name to
316  * which entity belongs. That will enable heterogeneity of the model, in
317  * addition of heterogeneity of the material properties.
318  */
319 
320  enum MaterialModel {
321  VonMisses,
322  VonMissesPlaneStress,
323  Paraboloidal,
324  LastModel
325  };
326  const char *list_materials[LastModel] = {"VonMisses", "VonMissesPlaneStress",
327  "Paraboloidal"};
328  PetscInt choice_material = VonMisses;
329  CHKERR PetscOptionsGetEList(PETSC_NULL, NULL, "-material", list_materials,
330  LastModel, &choice_material, PETSC_NULL);
331 
332  switch (choice_material) {
333  case VonMisses:
334  cpPtr = createMaterial<J2Plasticity<3>>();
335  break;
336  case VonMissesPlaneStress:
337  if (SPACE_DIM != 2)
338  SETERRQ(PETSC_COMM_WORLD, MOFEM_DATA_INCONSISTENCY,
339  "VonMissesPlaneStrain is only for 2D case");
340  cpPtr = createMaterial<J2Plasticity<2>>();
341  break;
342  case Paraboloidal:
343  cpPtr = createMaterial<ParaboloidalPlasticity>();
344  break;
345  default:
346  SETERRQ(PETSC_COMM_WORLD, MOFEM_DATA_INCONSISTENCY, "Wrong material model");
347  }
348 
349  if (approxBase == DEMKOWICZ_JACOBI_BASE && SPACE_DIM == 2)
350  cpPtr->integrationRule = [](int, int, int p) { return 2 * (p - 2); };
351 
352  //! [Material models selection]
353 
355 }
356 //! [Set up problem]
357 
358 //! [Boundary condition]
361  auto *pipeline_mng = mField.getInterface<PipelineManager>();
362  auto simple = mField.getInterface<Simple>();
363  auto bc_mng = mField.getInterface<BcManager>();
364  auto time_scale = boost::make_shared<TimeScale>();
365 
366  auto rule = [](int, int, int p) { return 2 * p; };
367  CHKERR pipeline_mng->setDomainRhsIntegrationRule(cpPtr->integrationRule);
368  CHKERR pipeline_mng->setDomainLhsIntegrationRule(cpPtr->integrationRule);
369  CHKERR pipeline_mng->setBoundaryRhsIntegrationRule(rule);
370  CHKERR pipeline_mng->setBoundaryLhsIntegrationRule(rule);
371 
373  pipeline_mng->getOpBoundaryLhsPipeline(), {HDIV}, "GEOMETRY");
374  pipeline_mng->getOpBoundaryLhsPipeline().push_back(
376 
378  pipeline_mng->getOpBoundaryRhsPipeline(), {HDIV}, "GEOMETRY");
379  pipeline_mng->getOpBoundaryRhsPipeline().push_back(
381 
382  // Add Natural BCs to RHS
384  pipeline_mng->getOpBoundaryRhsPipeline(), mField, "U", {time_scale},
385  Sev::inform);
386  // Add Natural BCs to LHS
388  pipeline_mng->getOpBoundaryLhsPipeline(), mField, "U", Sev::inform);
389 
390 #ifdef ADD_CONTACT
391  CHKERR
392  ContactOps::opFactoryBoundaryLhs<SPACE_DIM, PETSC, GAUSS, BoundaryEleOp>(
393  pipeline_mng->getOpBoundaryLhsPipeline(), "SIGMA", "U");
394  CHKERR
395  ContactOps::opFactoryBoundaryToDomainLhs<SPACE_DIM, PETSC, GAUSS, DomainEle>(
396  mField, pipeline_mng->getOpBoundaryLhsPipeline(),
397  simple->getDomainFEName(), "SIGMA", "U", "GEOMETRY",
398  cpPtr->integrationRule);
399 
400  CHKERR
401  ContactOps::opFactoryBoundaryRhs<SPACE_DIM, PETSC, GAUSS, BoundaryEleOp>(
402  pipeline_mng->getOpBoundaryRhsPipeline(), "SIGMA", "U");
403 #endif // ADD_CONTACT
404 
405  //! Add body froces
407  pipeline_mng->getOpDomainRhsPipeline(), mField, "U", {time_scale},
408  "BODY_FORCE", Sev::inform);
409 
410  // Essential BC
411  CHKERR bc_mng->removeBlockDOFsOnEntities(simple->getProblemName(), "REMOVE_X",
412  "U", 0, 0);
413  CHKERR bc_mng->removeBlockDOFsOnEntities(simple->getProblemName(), "REMOVE_Y",
414  "U", 1, 1);
415  CHKERR bc_mng->removeBlockDOFsOnEntities(simple->getProblemName(), "REMOVE_Z",
416  "U", 2, 2);
417 #ifdef ADD_CONTACT
418  for (auto b : {"FIX_X", "REMOVE_X"})
419  CHKERR bc_mng->removeBlockDOFsOnEntities(simple->getProblemName(), b,
420  "SIGMA", 0, 0, false, true);
421  for (auto b : {"FIX_Y", "REMOVE_Y"})
422  CHKERR bc_mng->removeBlockDOFsOnEntities(simple->getProblemName(), b,
423  "SIGMA", 1, 1, false, true);
424  for (auto b : {"FIX_Z", "REMOVE_Z"})
425  CHKERR bc_mng->removeBlockDOFsOnEntities(simple->getProblemName(), b,
426  "SIGMA", 2, 2, false, true);
427  for (auto b : {"FIX_ALL", "REMOVE_ALL"})
428  CHKERR bc_mng->removeBlockDOFsOnEntities(simple->getProblemName(), b,
429  "SIGMA", 0, 3, false, true);
430  CHKERR bc_mng->removeBlockDOFsOnEntities(
431  simple->getProblemName(), "NO_CONTACT", "SIGMA", 0, 3, false, true);
432 #endif
433 
434  CHKERR bc_mng->pushMarkDOFsOnEntities<DisplacementCubitBcData>(
435  simple->getProblemName(), "U");
436 
438 }
439 //! [Boundary condition]
440 
441 //! [Push operators to pipeline]
444  auto *simple = mField.getInterface<Simple>();
445  auto *pipeline_mng = mField.getInterface<PipelineManager>();
446 
447  // assemble operator to the right hand side
448  auto add_domain_ops_lhs = [&](auto &pip) {
450  // push forward finite element bases from reference to physical element
452  "GEOMETRY");
453  // create local common data
454  auto common_data_ptr = boost::make_shared<ADOLCPlasticity::CommonData>();
455  // calculate displacement gradients at integration points
457  "U", common_data_ptr->getGardAtGaussPtsPtr()));
458  // assemble tangent operator
459  CHKERR opFactoryDomainLhs<SPACE_DIM, PETSC, GAUSS, DomainEleOp>(
460  mField, "U", pip, "ADOLCMAT", common_data_ptr, cpPtr);
462  };
463 
464  auto add_domain_ops_rhs = [&](auto &pip) {
466  // push forward finite element bases from reference to physical element
468  "GEOMETRY");
469  // create local common data
470  auto common_data_ptr = boost::make_shared<ADOLCPlasticity::CommonData>();
471  // calculate displacement gradients at integration points
473  "U", common_data_ptr->getGardAtGaussPtsPtr()));
474  // assemble residual
475  CHKERR opFactoryDomainRhs<SPACE_DIM, PETSC, GAUSS, DomainEleOp>(
476  mField, "U", pip, "ADOLCMAT", common_data_ptr, cpPtr, Sev::inform);
477 #ifdef ADD_CONTACT
478  CHKERR ContactOps::opFactoryDomainRhs<SPACE_DIM, PETSC, GAUSS, DomainEleOp>(
479  pip, "SIGMA", "U");
480 #endif // ADD_CONTACT
482  };
483 
484  // Push operators to the left hand side pipeline. Indicate that domain (i.e.
485  // volume/interior) element is used.
486  CHKERR add_domain_ops_lhs(pipeline_mng->getOpDomainLhsPipeline());
487  // Push operators to the right hand side pipeline.
488  CHKERR add_domain_ops_rhs(pipeline_mng->getOpDomainRhsPipeline());
489 
491 }
492 //! [Push operators to pipeline]
493 
494 /**
495  * @brief Monitor solution
496  *
497  * This functions is called by TS solver at the end of each step. It is used
498  * to output results to the hard drive.
499  */
500 struct Monitor : public FEMethod {
502  std::pair<boost::shared_ptr<PostProcEleDomain>,
503  boost::shared_ptr<PostProcEleBdy>>
504  pair_post_proc_fe,
505  boost::shared_ptr<DomainEle> reaction_fe,
506  std::vector<boost::shared_ptr<ScalingMethod>> smv)
507  : dM(dm), reactionFE(reaction_fe), vecOfTimeScalingMethods(smv) {
508  fRes = createDMVector(dM);
509  domainPostProcFe = pair_post_proc_fe.first;
510  skinPostProcFe = pair_post_proc_fe.second;
511 
512  MoFEM::Interface *m_field_ptr;
513  CHKERR DMoFEMGetInterfacePtr(dM, &m_field_ptr);
514 #ifdef ADD_CONTACT
515  auto get_integrate_traction = [&]() {
516  auto integrate_traction = boost::make_shared<BoundaryEle>(*m_field_ptr);
517  auto common_data_ptr = boost::make_shared<ContactOps::CommonData>();
520  integrate_traction->getOpPtrVector(), {HDIV}, "GEOMETRY")),
521  "Apply transform");
522  // We have to integrate on curved face geometry, thus integration weight
523  // have to adjusted.
524  integrate_traction->getOpPtrVector().push_back(
526  integrate_traction->getRuleHook = [](int, int, int approx_order) {
527  return 2 * approx_order + 2 - 1;
528  };
529 
532  BoundaryEleOp>(
533  integrate_traction->getOpPtrVector(), "SIGMA", 0)),
534  "push operators to calculate traction");
535 
536  return integrate_traction;
537  };
538 
539  integrateTraction = get_integrate_traction();
540 #endif
541  }
544  int save_every_nth_step = 1;
545  CHKERR PetscOptionsGetInt(PETSC_NULL, "", "-save_every_nth_step",
546  &save_every_nth_step, PETSC_NULL);
547 #ifdef ADD_CONTACT
548  auto print_traction = [&](const std::string msg) {
550  MoFEM::Interface *m_field_ptr;
551  CHKERR DMoFEMGetInterfacePtr(dM, &m_field_ptr);
552  if (!m_field_ptr->get_comm_rank()) {
553  const double *t_ptr;
554  CHKERR VecGetArrayRead(ContactOps::CommonData::totalTraction, &t_ptr);
555  MOFEM_LOG_C("CONTACT", Sev::inform, "%s time %3.4e %3.4e %3.4e %3.4e",
556  msg.c_str(), ts_t, t_ptr[0], t_ptr[1], t_ptr[2]);
557  CHKERR VecRestoreArrayRead(ContactOps::CommonData::totalTraction,
558  &t_ptr);
559  }
561  };
562 #endif
563 
564  auto make_vtk = [&]() {
566  if (domainPostProcFe) {
567  CHKERR DMoFEMLoopFiniteElements(dM, "dFE", domainPostProcFe,
568  getCacheWeakPtr());
569  CHKERR domainPostProcFe->writeFile(
570  "out_plastic_" + boost::lexical_cast<std::string>(ts_step) +
571  ".h5m");
572  }
573  if (skinPostProcFe) {
574  CHKERR DMoFEMLoopFiniteElements(dM, "bFE", skinPostProcFe,
575  getCacheWeakPtr());
576  CHKERR skinPostProcFe->writeFile(
577  "out_skin_plastic_" + boost::lexical_cast<std::string>(ts_step) +
578  ".h5m");
579  }
581  };
582 
583  if (!(ts_step % save_every_nth_step)) {
584  CHKERR make_vtk();
585  }
586  if (reactionFE) {
587  CHKERR VecZeroEntries(fRes);
588  reactionFE->f = fRes;
589  CHKERR DMoFEMLoopFiniteElements(dM, "dFE", reactionFE, getCacheWeakPtr());
590  CHKERR VecAssemblyBegin(fRes);
591  CHKERR VecAssemblyEnd(fRes);
592  CHKERR VecGhostUpdateBegin(fRes, ADD_VALUES, SCATTER_REVERSE);
593  CHKERR VecGhostUpdateEnd(fRes, ADD_VALUES, SCATTER_REVERSE);
594 
595  MoFEM::Interface *m_field_ptr;
596  CHKERR DMoFEMGetInterfacePtr(dM, &m_field_ptr);
598  *m_field_ptr, reactionFE, fRes)();
599 
600  double nrm;
601  CHKERR VecNorm(fRes, NORM_2, &nrm);
602  MOFEM_LOG("PlasticPrb", Sev::verbose)
603  << "Residual norm " << nrm << " at time step " << ts_step;
604  }
605 
606 #ifdef ADD_CONTACT
607  auto calculate_traction = [&] {
610  CHKERR DMoFEMLoopFiniteElements(dM, "bFE", integrateTraction);
614  };
615 #endif
616 
617  auto get_min_max_displacement = [&]() {
619  MoFEM::Interface *m_field_ptr;
620  CHKERR DMoFEMGetInterfacePtr(dM, &m_field_ptr);
621 
622  std::array<double, 4> a_min = {DBL_MAX, DBL_MAX, DBL_MAX, 0};
623  std::array<double, 4> a_max = {-DBL_MAX, -DBL_MAX, -DBL_MAX, 0};
624 
625  auto get_min_max = [&](boost::shared_ptr<FieldEntity> field_entity_ptr) {
627  int d = 0;
628  for (auto v : field_entity_ptr->getEntFieldData()) {
629  a_min[d] = std::min(a_min[d], v);
630  a_max[d] = std::max(a_max[d], v);
631  ++d;
632  }
634  };
635 
636  a_min[SPACE_DIM] = 0;
637  a_max[SPACE_DIM] = 0;
638 
639  Range verts;
640  CHKERR m_field_ptr->get_field_entities_by_type("U", MBVERTEX, verts);
641  CHKERR m_field_ptr->getInterface<FieldBlas>()->fieldLambdaOnEntities(
642  get_min_max, "U", &verts);
643 
644  auto mpi_reduce = [&](auto &a, auto op) {
645  std::array<double, 3> a_mpi = {0, 0, 0};
646  MPI_Allreduce(a.data(), a_mpi.data(), 3, MPI_DOUBLE, op,
647  m_field_ptr->get_comm());
648  return a_mpi;
649  };
650 
651  auto a_min_mpi = mpi_reduce(a_min, MPI_MIN);
652  auto a_max_mpi = mpi_reduce(a_max, MPI_MAX);
653 
654  MOFEM_LOG("PlasticPrb", Sev::inform)
655  << "Min displacement " << a_min_mpi[0] << " " << a_min_mpi[1] << " "
656  << a_min_mpi[2];
657  MOFEM_LOG("PlasticPrb", Sev::inform)
658  << "Max displacement " << a_max_mpi[0] << " " << a_max_mpi[1] << " "
659  << a_max_mpi[2];
661  };
662  CHKERR get_min_max_displacement();
663 #ifdef ADD_CONTACT
664  CHKERR calculate_traction();
665  CHKERR print_traction("Contact force");
666 #endif
667  double scale = 1;
668  for (auto s : vecOfTimeScalingMethods) {
669  scale *= s->getScale(this->ts_t);
670  }
671 
672  MOFEM_LOG("PlasticPrb", Sev::inform)
673  << "Time: " << this->ts_t << " scale: " << scale;
674 
676  }
677 
678 private:
680  boost::shared_ptr<PostProcEleDomain> domainPostProcFe;
681  boost::shared_ptr<PostProcEleBdy> skinPostProcFe;
682  boost::shared_ptr<FEMethod> reactionFE;
683 
684  boost::shared_ptr<BoundaryEle> integrateTraction;
685 
688 };
689 
690 static boost::shared_ptr<TSUpdate> ts_update_ptr = nullptr;
691 
692 //! [Solve]
695  auto *simple = mField.getInterface<Simple>();
696  auto *pipeline_mng = mField.getInterface<PipelineManager>();
697 
698  auto dm = simple->getDM();
699  auto time_scale = boost::make_shared<TimeScale>();
700  auto snes_ctx_ptr = getDMSnesCtx(simple->getDM());
701 
702  // Setup postprocessing
703  auto create_post_proc_fe = [dm, this, simple]() {
704  //! [DG projection]
705  // Post-process domain, i.e. volume elements. If 3d case creates stresses
706  // are evaluated at points which are trace of the volume element on boundary
707  auto post_proc_ele_domain = [this](auto &pip_domain, auto &fe_name) {
708  // Push bases on reference element to the phyiscal element
710  pip_domain, {H1, HDIV}, "GEOMETRY");
711 
712  // calculate displacement gradients at nodes of post processing mesh. For
713  // gradient DG projection is obsolete, since displacements can be
714  // evaluated at arbitrary points.
715  auto grad_ptr = boost::make_shared<MatrixDouble>();
716  pip_domain.push_back(
718  grad_ptr));
719 
720  // Create operator to run (neted) pipeline in operator. InteriorElem
721  // element will have iteration rule and bases as domain element used to
722  // solve problem, and remember history variables.
723  using InteriorElem = DomainEle;
724  auto op_this = new OpLoopThis<InteriorElem>(mField, fe_name, Sev::noisy);
725  // add interior element to post-processing pipeline
726  pip_domain.push_back(op_this);
727 
728  // get pointer to interior element, which is in essence pipeline which
729  // pipeline.
730  auto fe_physics = op_this->getThisFEPtr();
731 
732  auto evaluate_stress_on_physical_element = [&]() {
733  // evaluate stress and plastic strain at Gauss points
734  fe_physics->getRuleHook = cpPtr->integrationRule;
736  fe_physics->getOpPtrVector(), {H1});
737  auto common_data_ptr =
738  boost::make_shared<ADOLCPlasticity::CommonData>();
739  // note that gradient of displacements is evaluate again, at
740  // physical nodes
741  fe_physics->getOpPtrVector().push_back(
743  "U", common_data_ptr->getGardAtGaussPtsPtr()));
744 
745  CHKERR cpPtr->addMatBlockOps(mField, fe_physics->getOpPtrVector(),
746  "ADOLCMAT", Sev::noisy);
747  fe_physics->getOpPtrVector().push_back(
748  getRawPtrOpCalculateStress<SPACE_DIM>(mField, common_data_ptr,
749  cpPtr, false));
750  return common_data_ptr;
751  };
752 
753  auto dg_projection_froward_and_back = [&](auto &common_data_ptr) {
754  // here we do actual projection of stress and plastic strain to DG space
755  int dg_order = approxOrder - 1;
756  auto entity_data_l2 =
757  boost::make_shared<EntitiesFieldData>(MBENTITYSET);
758  auto mass_ptr =
759  boost::make_shared<MatrixDouble>(); //< projection operator (mass
760  // matrix)
761  fe_physics->getOpPtrVector().push_back(new OpDGProjectionMassMatrix(
762  dg_order, mass_ptr, entity_data_l2, approxBase, L2));
763 
764  auto coeffs_ptr_stress = boost::make_shared<MatrixDouble>();
765  // project stress on DG space on physical element
766  fe_physics->getOpPtrVector().push_back(new OpDGProjectionCoefficients(
767  common_data_ptr->getStressMatrixPtr(), coeffs_ptr_stress, mass_ptr,
768  entity_data_l2, approxBase, L2));
769  // project strains plastic strains DG space on physical element
770  auto coeffs_ptr_plastic_strain = boost::make_shared<MatrixDouble>();
771  fe_physics->getOpPtrVector().push_back(new OpDGProjectionCoefficients(
772  common_data_ptr->getPlasticStrainMatrixPtr(),
773  coeffs_ptr_plastic_strain, mass_ptr, entity_data_l2, approxBase,
774  L2));
775 
776  // project stress and plastic strain for DG space on post-process
777  // element
778  pip_domain.push_back(new OpDGProjectionEvaluation(
779  common_data_ptr->getStressMatrixPtr(), coeffs_ptr_stress,
780  entity_data_l2, approxBase, L2));
781  pip_domain.push_back(new OpDGProjectionEvaluation(
782  common_data_ptr->getPlasticStrainMatrixPtr(),
783  coeffs_ptr_plastic_strain, entity_data_l2, approxBase, L2));
784  };
785 
786  auto common_data_ptr = evaluate_stress_on_physical_element();
787  dg_projection_froward_and_back(common_data_ptr);
788 
789  return boost::make_tuple(grad_ptr, common_data_ptr->getStressMatrixPtr(),
790  common_data_ptr->getPlasticStrainMatrixPtr());
791  };
792  //! [DG projection]
793 
794  // Create tags on post-processing mesh, i.e. those tags are visible in
795  // Preview
796  auto add_post_proc_map = [&](auto post_proc_fe, auto u_ptr, auto grad_ptr,
797  auto stress_ptr, auto plastic_strain_ptr,
798  auto contact_stress_ptr, auto X_ptr) {
799  using OpPPMapSPACE_DIM = OpPostProcMapInMoab<SPACE_DIM, SPACE_DIM>;
800  post_proc_fe->getOpPtrVector().push_back(
801 
802  new OpPPMapSPACE_DIM(
803 
804  post_proc_fe->getPostProcMesh(), post_proc_fe->getMapGaussPts(),
805 
806  {},
807 
808  {{"U", u_ptr}, {"GEOMETRY", X_ptr}},
809 
810  {{"GRAD", grad_ptr}, {"SIGMA", contact_stress_ptr}},
811 
812  {}
813 
814  )
815 
816  );
817 
818  using OpPPMap3D = OpPostProcMapInMoab<3, 3>;
819  post_proc_fe->getOpPtrVector().push_back(
820 
821  new OpPPMap3D(
822 
823  post_proc_fe->getPostProcMesh(), post_proc_fe->getMapGaussPts(),
824 
825  {},
826 
827  {},
828 
829  {},
830 
831  {{"STRESS", stress_ptr}, {"PLASTIC_STRAIN", plastic_strain_ptr}}
832 
833  )
834 
835  );
836 
837  return post_proc_fe;
838  };
839 
840  auto vol_post_proc = [this, simple, post_proc_ele_domain,
841  add_post_proc_map]() {
842  PetscBool post_proc_vol = PETSC_FALSE;
843  if (SPACE_DIM == 2)
844  post_proc_vol = PETSC_TRUE;
845 
846  CHKERR PetscOptionsGetBool(PETSC_NULL, "", "-post_proc_vol",
847  &post_proc_vol, PETSC_NULL);
848  if (post_proc_vol == PETSC_FALSE)
849  return boost::shared_ptr<PostProcEleDomain>();
850  auto post_proc_fe = boost::make_shared<PostProcEleDomain>(mField);
851  auto u_ptr = boost::make_shared<MatrixDouble>();
852  post_proc_fe->getOpPtrVector().push_back(
854  auto X_ptr = boost::make_shared<MatrixDouble>();
855  post_proc_fe->getOpPtrVector().push_back(
856  new OpCalculateVectorFieldValues<SPACE_DIM>("GEOMETRY", X_ptr));
857  auto contact_stress_ptr = boost::make_shared<MatrixDouble>();
858 #ifdef ADD_CONTACT
859  post_proc_fe->getOpPtrVector().push_back(
861  "SIGMA", contact_stress_ptr));
862 #else
863  contact_stress_ptr = nullptr;
864 #endif
865  auto [grad_ptr, stress_ptr, plastic_strain_ptr] = post_proc_ele_domain(
866  post_proc_fe->getOpPtrVector(), simple->getDomainFEName());
867 
868  return add_post_proc_map(post_proc_fe, u_ptr, grad_ptr, stress_ptr,
869  plastic_strain_ptr, contact_stress_ptr, X_ptr);
870  };
871 
872  auto skin_post_proc = [this, simple, post_proc_ele_domain,
873  add_post_proc_map]() {
874  // create skin of the volume mesh for post-processing,
875  // i.e. boundary of the volume mesh
876  PetscBool post_proc_skin = PETSC_TRUE;
877  if (SPACE_DIM == 2)
878  post_proc_skin = PETSC_FALSE;
879 
880  CHKERR PetscOptionsGetBool(PETSC_NULL, "", "-post_proc_skin",
881  &post_proc_skin, PETSC_NULL);
882 
883  if (post_proc_skin == PETSC_FALSE)
884  return boost::shared_ptr<PostProcEleBdy>();
885 
886  auto post_proc_fe = boost::make_shared<PostProcEleBdy>(mField);
887  auto u_ptr = boost::make_shared<MatrixDouble>();
888  post_proc_fe->getOpPtrVector().push_back(
890  auto X_ptr = boost::make_shared<MatrixDouble>();
891  post_proc_fe->getOpPtrVector().push_back(
892  new OpCalculateVectorFieldValues<SPACE_DIM>("GEOMETRY", X_ptr));
893  auto contact_stress_ptr = boost::make_shared<MatrixDouble>();
894  auto op_loop_side =
895  new OpLoopSide<SideEle>(mField, simple->getDomainFEName(), SPACE_DIM);
896  auto [grad_ptr, stress_ptr, plastic_strain_ptr] = post_proc_ele_domain(
897  op_loop_side->getOpPtrVector(), simple->getDomainFEName());
898 #ifdef ADD_CONTACT
899  op_loop_side->getOpPtrVector().push_back(
901  "SIGMA", contact_stress_ptr));
902 #else
903  contact_stress_ptr = nullptr;
904 #endif
905  post_proc_fe->getOpPtrVector().push_back(op_loop_side);
906 
907  return add_post_proc_map(post_proc_fe, u_ptr, grad_ptr, stress_ptr,
908  plastic_strain_ptr, contact_stress_ptr, X_ptr);
909  };
910 
911  return std::make_pair(vol_post_proc(), skin_post_proc());
912  };
913 
914  auto create_reaction_fe = [&]() {
915  auto fe_ptr = boost::make_shared<DomainEle>(mField);
916  fe_ptr->getRuleHook = cpPtr->integrationRule;
917 
918  auto &pip = fe_ptr->getOpPtrVector();
920  auto common_data_ptr = boost::make_shared<ADOLCPlasticity::CommonData>();
922  "U", common_data_ptr->getGardAtGaussPtsPtr()));
923  CHKERR opFactoryDomainRhs<SPACE_DIM, PETSC, GAUSS, DomainEleOp>(
924  mField, "U", pip, "ADOLCMAT", common_data_ptr, cpPtr, Sev::noisy);
925 
926  return fe_ptr;
927  };
928 
929  auto add_extra_finite_elements_to_ksp_solver_pipelines = [&]() {
931 
932  auto pre_proc_ptr = boost::make_shared<FEMethod>();
933  auto post_proc_rhs_ptr = boost::make_shared<FEMethod>();
934  auto post_proc_lhs_ptr = boost::make_shared<FEMethod>();
935 
936  auto get_bc_hook_rhs = [this, pre_proc_ptr, time_scale]() {
939  {time_scale}, false)();
941  };
942 
943  pre_proc_ptr->preProcessHook = get_bc_hook_rhs;
944 
945  auto get_post_proc_hook_rhs = [this, post_proc_rhs_ptr]() {
948  mField, post_proc_rhs_ptr, nullptr, Sev::verbose)();
950  mField, post_proc_rhs_ptr, 1.)();
952  };
953  auto get_post_proc_hook_lhs = [this, post_proc_lhs_ptr]() {
956  mField, post_proc_lhs_ptr, 1.)();
958  };
959  post_proc_rhs_ptr->postProcessHook = get_post_proc_hook_rhs;
960  post_proc_lhs_ptr->postProcessHook = get_post_proc_hook_lhs;
961 
962  // This is low level pushing finite elements (pipelines) to solver
963  auto ts_ctx_ptr = getDMTsCtx(simple->getDM());
964  ts_ctx_ptr->getPreProcessIFunction().push_front(pre_proc_ptr);
965  ts_ctx_ptr->getPreProcessIJacobian().push_front(pre_proc_ptr);
966  ts_ctx_ptr->getPostProcessIFunction().push_back(post_proc_rhs_ptr);
967  ts_ctx_ptr->getPostProcessIJacobian().push_back(post_proc_lhs_ptr);
969  };
970 
971  // Add extra finite elements to SNES solver pipelines to resolve essential
972  // boundary conditions
973  CHKERR add_extra_finite_elements_to_ksp_solver_pipelines();
974 
975  auto create_monitor_fe = [dm, time_scale](auto &&post_proc_fe,
976  auto &&reaction_fe) {
977  return boost::make_shared<Monitor>(
978  dm, post_proc_fe, reaction_fe,
979  std::vector<boost::shared_ptr<ScalingMethod>>{time_scale});
980  };
981 
982  //! [Set up post-step]
983  auto set_up_post_step = [&](auto ts) {
985 
986  // create finite element (pipeline) and populate it with operators to
987  // update history variables
988  auto create_update_ptr = [&]() {
989  auto fe_ptr = boost::make_shared<DomainEle>(mField);
990  fe_ptr->getRuleHook = cpPtr->integrationRule;
991  AddHOOps<SPACE_DIM, SPACE_DIM, SPACE_DIM>::add(fe_ptr->getOpPtrVector(),
992  {H1});
993  auto common_data_ptr = boost::make_shared<ADOLCPlasticity::CommonData>();
994  fe_ptr->getOpPtrVector().push_back(
996  "U", common_data_ptr->getGardAtGaussPtsPtr()));
998  opFactoryDomainUpdate<SPACE_DIM>(mField, fe_ptr->getOpPtrVector(),
999  "ADOLCMAT", common_data_ptr, cpPtr),
1000  "push update ops");
1001  return fe_ptr;
1002  };
1003 
1004  // ts_update_ptr is global static variable
1005  ts_update_ptr =
1006  createTSUpdate(simple->getDomainFEName(), create_update_ptr());
1007 
1008  //! [TS post-step function]
1009  // This is pure "C" function which we can to the TS solver
1010  auto ts_step_post_proc = [](TS ts) {
1012  if (ts_update_ptr)
1013  CHKERR ts_update_ptr->postProcess(ts);
1015  };
1016  //! [TS post-step function]
1017 
1018  // finally set up post-step
1019  CHKERR TSSetPostStep(ts, ts_step_post_proc);
1021  };
1022  //! [Set up post-step]
1023 
1024  // Set monitor which postprocessing results and saves them to the hard drive
1025  auto set_up_monitor = [&](auto ts) {
1027  boost::shared_ptr<FEMethod> null_fe;
1028  auto monitor_ptr =
1029  create_monitor_fe(create_post_proc_fe(), create_reaction_fe());
1030  CHKERR DMMoFEMTSSetMonitor(dm, ts, simple->getDomainFEName(), null_fe,
1031  null_fe, monitor_ptr);
1033  };
1034 
1035  auto set_section_monitor = [&](auto solver) {
1037  SNES snes;
1038  CHKERR TSGetSNES(solver, &snes);
1039  CHKERR SNESMonitorSet(snes,
1040  (MoFEMErrorCode(*)(SNES, PetscInt, PetscReal,
1041  void *))MoFEMSNESMonitorFields,
1042  (void *)(snes_ctx_ptr.get()), nullptr);
1044  };
1045 
1046  auto set_up_adapt = [&](auto ts) {
1048  CHKERR TSAdaptRegister(TSADAPTMOFEM, TSAdaptCreateMoFEM);
1049  TSAdapt adapt;
1050  CHKERR TSGetAdapt(ts, &adapt);
1052  };
1053 
1054  //! [Create TS]
1055  auto ts = pipeline_mng->createTSIM();
1056 
1057  // Set time solver
1058  double ftime = 1;
1059  CHKERR TSSetMaxTime(ts, ftime);
1060  CHKERR TSSetExactFinalTime(ts, TS_EXACTFINALTIME_MATCHSTEP);
1061  auto D = createDMVector(simple->getDM());
1062 #ifdef ADD_CONTACT
1064 #endif
1065  CHKERR TSSetSolution(ts, D);
1066  CHKERR set_section_monitor(ts);
1067 
1068  // Set monitor, step adaptivity, and post-step to update history variables
1069  CHKERR set_up_monitor(ts);
1070  CHKERR set_up_post_step(ts);
1071  CHKERR set_up_adapt(ts);
1072  CHKERR TSSetFromOptions(ts);
1073 
1074  CHKERR TSSolve(ts, NULL);
1075  //! [Create TS]
1076 
1077  CHKERR TSGetTime(ts, &ftime);
1078 
1079  PetscInt steps, snesfails, rejects, nonlinits, linits;
1080  CHKERR TSGetStepNumber(ts, &steps);
1081  CHKERR TSGetSNESFailures(ts, &snesfails);
1082  CHKERR TSGetStepRejections(ts, &rejects);
1083  CHKERR TSGetSNESIterations(ts, &nonlinits);
1084  CHKERR TSGetKSPIterations(ts, &linits);
1085  MOFEM_LOG_C("PlasticPrb", Sev::inform,
1086  "steps %d (%d rejected, %d SNES fails), ftime %g, nonlinits "
1087  "%d, linits %d",
1088  steps, rejects, snesfails, ftime, nonlinits, linits);
1089 
1091 }
1092 //! [Solve]
1093 
1094 //! [Getting norms]
1097 
1098  auto simple = mField.getInterface<Simple>();
1099  auto dm = simple->getDM();
1100 
1101  auto T = createDMVector(simple->getDM());
1102  CHKERR DMoFEMMeshToLocalVector(simple->getDM(), T, INSERT_VALUES,
1103  SCATTER_FORWARD);
1104  double nrm2;
1105  CHKERR VecNorm(T, NORM_2, &nrm2);
1106  MOFEM_LOG("PlasticPrb", Sev::inform) << "Solution norm " << nrm2;
1107 
1108  auto post_proc_norm_fe = boost::make_shared<DomainEle>(mField);
1109 
1110  post_proc_norm_fe->getRuleHook = cpPtr->integrationRule;
1111 
1113  post_proc_norm_fe->getOpPtrVector(), {H1});
1114 
1115  enum NORMS { U_NORM_L2 = 0, PIOLA_NORM, LAST_NORM };
1116  auto norms_vec =
1118  (mField.get_comm_rank() == 0) ? LAST_NORM : 0, LAST_NORM);
1119  CHKERR VecZeroEntries(norms_vec);
1120 
1121  auto u_ptr = boost::make_shared<MatrixDouble>();
1122  post_proc_norm_fe->getOpPtrVector().push_back(
1123  new OpCalculateVectorFieldValues<SPACE_DIM>("U", u_ptr));
1124 
1125  post_proc_norm_fe->getOpPtrVector().push_back(
1126  new OpCalcNormL2Tensor1<SPACE_DIM>(u_ptr, norms_vec, U_NORM_L2));
1127 
1128  CHKERR DMoFEMLoopFiniteElements(dm, simple->getDomainFEName(),
1129  post_proc_norm_fe);
1130 
1131  CHKERR VecAssemblyBegin(norms_vec);
1132  CHKERR VecAssemblyEnd(norms_vec);
1133 
1134  MOFEM_LOG_CHANNEL("SELF"); // Clear channel from old tags
1135  if (mField.get_comm_rank() == 0) {
1136  const double *norms;
1137  CHKERR VecGetArrayRead(norms_vec, &norms);
1138  MOFEM_TAG_AND_LOG("SELF", Sev::inform, "example")
1139  << "norm_u: " << std::scientific << std::sqrt(norms[U_NORM_L2]);
1140  CHKERR VecRestoreArrayRead(norms_vec, &norms);
1141  }
1142 
1144 }
1145 //! [Getting norms]
1146 
1147 //! [Postprocessing results]
1150  PetscInt test_nb = 0;
1151  PetscBool test_flg = PETSC_FALSE;
1152  CHKERR PetscOptionsGetInt(PETSC_NULL, "", "-test", &test_nb, &test_flg);
1153 
1154  if (test_flg) {
1155  auto simple = mField.getInterface<Simple>();
1156  auto T = createDMVector(simple->getDM());
1157  CHKERR DMoFEMMeshToLocalVector(simple->getDM(), T, INSERT_VALUES,
1158  SCATTER_FORWARD);
1159  double nrm2;
1160  CHKERR VecNorm(T, NORM_2, &nrm2);
1161  MOFEM_LOG("PlasticPrb", Sev::verbose) << "Regression norm " << nrm2;
1162  double regression_value = 0;
1163  switch (test_nb) {
1164  default:
1165  SETERRQ(PETSC_COMM_WORLD, MOFEM_ATOM_TEST_INVALID, "Wrong test number.");
1166  break;
1167  }
1168  if (fabs(nrm2 - regression_value) > 1e-2)
1169  SETERRQ2(PETSC_COMM_WORLD, MOFEM_ATOM_TEST_INVALID,
1170  "Regression test field; wrong norm value. %6.4e != %6.4e", nrm2,
1171  regression_value);
1172  }
1174 }
1175 //! [Postprocessing results]
1176 
1177 //! [Check]
1180 #ifdef ADD_CONTACT
1182 #endif
1184 }
1185 //! [Check]
1186 
1187 static char help[] = "...\n\n";
1188 
1189 int main(int argc, char *argv[]) {
1190 
1191 #ifdef ADD_CONTACT
1192 #ifdef PYTHON_SDF
1193  Py_Initialize();
1194  np::initialize();
1195 #endif
1196 #endif // ADD_CONTACT
1197 
1198  // Initialisation of MoFEM/PETSc and MOAB data structures
1199  const char param_file[] = "param_file.petsc";
1200  MoFEM::Core::Initialize(&argc, &argv, param_file, help);
1201 
1202  // Add logging channel for example
1203  auto core_log = logging::core::get();
1204  core_log->add_sink(
1205  LogManager::createSink(LogManager::getStrmWorld(), "PlasticPrb"));
1206  LogManager::setLog("PlasticPrb");
1207  MOFEM_LOG_TAG("PlasticPrb", "PlasticPrb");
1208  MOFEM_LOG("PlasticPrb", Sev::inform) << "SPACE_DIM " << SPACE_DIM;
1209 #ifdef ADD_CONTACT
1210  core_log->add_sink(
1211  LogManager::createSink(LogManager::getStrmWorld(), "CONTACT"));
1212  LogManager::setLog("CONTACT");
1213  MOFEM_LOG_TAG("CONTACT", "Contact");
1214 #endif // ADD_CONTACT
1215 
1216  try {
1217 
1218  //! [Register MoFEM discrete manager in PETSc]
1219  DMType dm_name = "DMMOFEM";
1220  CHKERR DMRegister_MoFEM(dm_name);
1221  //! [Register MoFEM discrete manager in PETSc
1222 
1223  //! [Create MoAB]
1224  moab::Core mb_instance; ///< mesh database
1225  moab::Interface &moab = mb_instance; ///< mesh database interface
1226  //! [Create MoAB]
1227 
1228  //! [Create MoFEM]
1229  MoFEM::Core core(moab); ///< finite element database
1230  MoFEM::Interface &m_field = core; ///< finite element database interface
1231  //! [Create MoFEM]
1232 
1233  //! [PlasticProblem]
1234  PlasticProblem ex(m_field);
1235  CHKERR ex.runProblem();
1236  //! [PlasticProblem]
1237  }
1238  CATCH_ERRORS;
1239 
1241 #ifdef ADD_CONTACT
1242 #ifdef PYTHON_SDF
1243  if (Py_FinalizeEx() < 0) {
1244  exit(120);
1245  }
1246 #endif
1247 #endif // ADD_CONTACT
1248  return 0;
1249 }
MoFEM::NaturalBC::Assembly::LinearForm
Definition: Natural.hpp:67
MoFEMFunctionReturnHot
#define MoFEMFunctionReturnHot(a)
Last executable line of each PETSc function used for error handling. Replaces return()
Definition: definitions.h:460
MoFEM::UnknownInterface::getInterface
MoFEMErrorCode getInterface(IFACE *&iface) const
Get interface reference to pointer of interface.
Definition: UnknownInterface.hpp:93
MoFEM::EntitiesFieldData::EntData
Data on single entity (This is passed as argument to DataOperator::doWork)
Definition: EntitiesFieldData.hpp:128
EXECUTABLE_DIMENSION
#define EXECUTABLE_DIMENSION
Definition: plastic.cpp:13
SPACE_DIM
constexpr int SPACE_DIM
Definition: adolc_plasticity.cpp:14
BoundaryEle
ElementsAndOps< SPACE_DIM >::BoundaryEle BoundaryEle
Definition: child_and_parent.cpp:39
Monitor::vecOfTimeScalingMethods
VecOfTimeScalingMethods vecOfTimeScalingMethods
Definition: adolc_plasticity.cpp:687
MYPCOMM_INDEX
#define MYPCOMM_INDEX
default communicator number PCOMM
Definition: definitions.h:228
PlasticProblem::solveSystem
MoFEMErrorCode solveSystem()
[Solve]
Definition: adolc_plasticity.cpp:693
MoFEM::EssentialPreProcReaction< DisplacementCubitBcData >
Specialization for DisplacementCubitBcData.
Definition: EssentialDisplacementCubitBcData.hpp:157
MoFEM::CoreTmp< 0 >
Core (interface) class.
Definition: Core.hpp:82
H1
@ H1
continuous field
Definition: definitions.h:85
scale
double scale
Definition: adolc_plasticity.cpp:109
LASTBASE
@ LASTBASE
Definition: definitions.h:69
MoFEM::OpLoopThis
Execute "this" element in the operator.
Definition: DGProjection.hpp:68
MOFEM_LOG_CHANNEL
#define MOFEM_LOG_CHANNEL(channel)
Set and reset channel.
Definition: LogManager.hpp:284
ADOLCPlasticity::createTSUpdate
boost::shared_ptr< TSUpdate > createTSUpdate(std::string fe_name, boost::shared_ptr< FEMethod > fe_ptr)
ContactOps
Definition: contact.cpp:99
MoFEM::FEMethod
structure for User Loop Methods on finite elements
Definition: LoopMethods.hpp:369
MoFEM::OpFluxRhsImpl
Definition: Natural.hpp:39
MoFEM::PipelineManager::ElementsAndOpsByDim
Definition: PipelineManager.hpp:38
MoFEM::EssentialPostProcLhs< DisplacementCubitBcData >
Specialization for DisplacementCubitBcData.
Definition: EssentialDisplacementCubitBcData.hpp:134
MoFEM::CoreInterface::get_comm
virtual MPI_Comm & get_comm() const =0
MoFEM::NaturalBC::Assembly::BiLinearForm
Definition: Natural.hpp:74
CHK_THROW_MESSAGE
#define CHK_THROW_MESSAGE(err, msg)
Check and throw MoFEM exception.
Definition: definitions.h:609
L2
@ L2
field with C-1 continuity
Definition: definitions.h:88
MoFEM::Exceptions::MoFEMErrorCode
PetscErrorCode MoFEMErrorCode
MoFEM/PETSc error code.
Definition: Exceptions.hpp:56
MoFEM::OpCalculateVectorFieldValues
Get values at integration pts for tensor filed rank 1, i.e. vector field.
Definition: UserDataOperators.hpp:466
MoFEM::CoreInterface::get_comm_rank
virtual int get_comm_rank() const =0
PostProcEleDomain
PostProcEleByDim< SPACE_DIM >::PostProcEleDomain PostProcEleDomain
Definition: dynamic_first_order_con_law.cpp:53
ts_update_ptr
static boost::shared_ptr< TSUpdate > ts_update_ptr
Definition: adolc_plasticity.cpp:690
MoFEM::EssentialPostProcRhs< DisplacementCubitBcData >
Specialization for DisplacementCubitBcData.
Definition: EssentialDisplacementCubitBcData.hpp:113
MoFEM::PETSC
@ PETSC
Definition: FormsIntegrators.hpp:105
MoFEM::PipelineManager
PipelineManager interface.
Definition: PipelineManager.hpp:24
MoFEM.hpp
MoFEM::OpDGProjectionCoefficients
Definition: DGProjection.hpp:119
MoFEM::DMoFEMMeshToLocalVector
PetscErrorCode DMoFEMMeshToLocalVector(DM dm, Vec l, InsertMode mode, ScatterMode scatter_mode)
set local (or ghosted) vector values on mesh for partition only
Definition: DMMoFEM.cpp:523
MoFEM::DisplacementCubitBcData
Definition of the displacement bc data structure.
Definition: BCData.hpp:76
MoFEM::Projection10NodeCoordsOnField
Projection of edge entities with one mid-node on hierarchical basis.
Definition: Projection10NodeCoordsOnField.hpp:24
MoFEM::CoreTmp< 0 >::Finalize
static MoFEMErrorCode Finalize()
Checks for options to be called at the conclusion of the program.
Definition: Core.cpp:112
help
static char help[]
[Check]
Definition: adolc_plasticity.cpp:1187
Monitor::postProcess
MoFEMErrorCode postProcess()
function is run at the end of loop
Definition: adolc_plasticity.cpp:542
MoFEM::Simple
Simple interface for fast problem set-up.
Definition: Simple.hpp:27
geom_order
int geom_order
Order if fixed.
Definition: plastic.cpp:137
MoFEM::DeprecatedCoreInterface
Deprecated interface functions.
Definition: DeprecatedCoreInterface.hpp:16
MoFEM::OpFluxLhsImpl
Definition: Natural.hpp:43
MoFEM::Interface
DeprecatedCoreInterface Interface
Definition: Interface.hpp:2010
PlasticProblem
Definition: adolc_plasticity.cpp:127
CONTACT_SPACE
constexpr FieldSpace CONTACT_SPACE
Definition: adolc_plasticity.cpp:100
PlasticProblem::outputResults
MoFEMErrorCode outputResults()
[Getting norms]
Definition: adolc_plasticity.cpp:1148
ElementsAndOps< 2 >::SideEle
PipelineManager::ElementsAndOpsByDim< 2 >::FaceSideEle SideEle
Definition: plastic.cpp:29
FieldSpace
FieldSpace
approximation spaces
Definition: definitions.h:82
Monitor::reactionFE
boost::shared_ptr< FEMethod > reactionFE
Definition: adolc_plasticity.cpp:682
PlasticProblem::gettingNorms
MoFEMErrorCode gettingNorms()
[Solve]
Definition: adolc_plasticity.cpp:1095
save_every_nth_step
int save_every_nth_step
Definition: photon_diffusion.cpp:67
CHKERR
#define CHKERR
Inline error check.
Definition: definitions.h:548
MoFEM::createDMVector
auto createDMVector(DM dm)
Get smart vector from DM.
Definition: DMMoFEM.hpp:1099
MoFEM::EssentialPreProc< DisplacementCubitBcData >
Specialization for DisplacementCubitBcData.
Definition: EssentialDisplacementCubitBcData.hpp:91
Monitor::skinPostProcFe
boost::shared_ptr< PostProcEleBdy > skinPostProcFe
Definition: adolc_plasticity.cpp:681
MoFEM
implementation of Data Operators for Forces and Sources
Definition: Common.hpp:10
Monitor::domainPostProcFe
boost::shared_ptr< PostProcEleDomain > domainPostProcFe
Definition: adolc_plasticity.cpp:680
a
constexpr double a
Definition: approx_sphere.cpp:30
MoFEM::BcManager
Simple interface for fast problem set-up.
Definition: BcManager.hpp:25
BoundaryEleOp
ContactOps::CommonData::totalTraction
static SmartPetscObj< Vec > totalTraction
Definition: ContactOps.hpp:29
MOFEM_LOG_C
#define MOFEM_LOG_C(channel, severity, format,...)
Definition: LogManager.hpp:311
PlasticProblem::setupProblem
MoFEMErrorCode setupProblem()
[Read mesh]
Definition: adolc_plasticity.cpp:188
simple
void simple(double P1[], double P2[], double P3[], double c[], const int N)
Definition: acoustic.cpp:69
MOFEM_LOG_SYNCHRONISE
#define MOFEM_LOG_SYNCHRONISE(comm)
Synchronise "SYNC" channel.
Definition: LogManager.hpp:345
Monitor::Monitor
Monitor(SmartPetscObj< DM > dm, std::pair< boost::shared_ptr< PostProcEleDomain >, boost::shared_ptr< PostProcEleBdy >> pair_post_proc_fe, boost::shared_ptr< DomainEle > reaction_fe, std::vector< boost::shared_ptr< ScalingMethod >> smv)
Definition: adolc_plasticity.cpp:501
ElementsAndOps< 3 >::SideEle
PipelineManager::ElementsAndOpsByDim< 3 >::FaceSideEle SideEle
Definition: plastic.cpp:36
MoFEM::DMRegister_MoFEM
PetscErrorCode DMRegister_MoFEM(const char sname[])
Register MoFEM problem.
Definition: DMMoFEM.cpp:43
SideEle
ElementsAndOps< SPACE_DIM >::SideEle SideEle
Definition: plastic.cpp:61
MoFEM::OpCalculateHVecTensorField
Calculate tenor field using vectorial base, i.e. Hdiv/Hcurl.
Definition: UserDataOperators.hpp:2572
MoFEM::GAUSS
@ GAUSS
Definition: FormsIntegrators.hpp:136
MatrixFunction.hpp
MoFEM::AddFluxToLhsPipelineImpl
Definition: Natural.hpp:49
MoFEM::OpCalcNormL2Tensor1
Get norm of input MatrixDouble for Tensor1.
Definition: NormsOperators.hpp:44
TSADAPTMOFEM
#define TSADAPTMOFEM
Definition: TsCtx.hpp:10
MOFEM_LOG_TAG
#define MOFEM_LOG_TAG(channel, tag)
Tag channel.
Definition: LogManager.hpp:339
MoFEM::AddFluxToRhsPipelineImpl
Definition: Natural.hpp:46
ADOLCPlasticity
Definition: ADOLCPlasticity.hpp:24
PostProcEleBdy
PostProcEleByDim< SPACE_DIM >::PostProcEleBdy PostProcEleBdy
Definition: dynamic_first_order_con_law.cpp:55
PlasticProblem::readMesh
MoFEMErrorCode readMesh()
[Run problem]
Definition: adolc_plasticity.cpp:173
BiLinearForm
MoFEM::OpSetHOWeightsOnSubDim
Definition: HODataOperators.hpp:145
MoFEM::PostProcBrokenMeshInMoabBase
Definition: PostProcBrokenMeshInMoabBase.hpp:94
ContactOps.hpp
PlasticProblem::boundaryCondition
MoFEMErrorCode boundaryCondition()
[Set up problem]
Definition: adolc_plasticity.cpp:359
PlasticProblem::assembleSystem
MoFEMErrorCode assembleSystem()
[Boundary condition]
Definition: adolc_plasticity.cpp:442
MoFEM::AddHOOps
Add operators pushing bases from local to physical configuration.
Definition: HODataOperators.hpp:413
MoFEM::OpCalculateVectorFieldGradient
Get field gradients at integration pts for scalar filed rank 0, i.e. vector field.
Definition: UserDataOperators.hpp:1535
ContactOps::CommonData::createTotalTraction
static auto createTotalTraction(MoFEM::Interface &m_field)
Definition: ContactOps.hpp:31
ContactOps::cn_contact
double cn_contact
Definition: contact.cpp:100
PlasticProblem::checkResults
MoFEMErrorCode checkResults()
[Postprocessing results]
Definition: adolc_plasticity.cpp:1178
v
const double v
phase velocity of light in medium (cm/ns)
Definition: initial_diffusion.cpp:40
ElementsAndOps
Definition: child_and_parent.cpp:18
DomainEle
PipelineManager::ElementsAndOpsByDim< SPACE_DIM >::DomainEle DomainEle
Definition: adolc_plasticity.cpp:22
Range
DomainEleOp
Monitor::fRes
SmartPetscObj< Vec > fRes
Definition: adolc_plasticity.cpp:686
MoFEM::CoreTmp< 0 >::Initialize
static MoFEMErrorCode Initialize(int *argc, char ***args, const char file[], const char help[])
Initializes the MoFEM database PETSc, MOAB and MPI.
Definition: Core.cpp:72
EntData
EntitiesFieldData::EntData EntData
Definition: adolc_plasticity.cpp:17
MOFEM_TAG_AND_LOG
#define MOFEM_TAG_AND_LOG(channel, severity, tag)
Tag and log in channel.
Definition: LogManager.hpp:362
main
int main(int argc, char *argv[])
Definition: adolc_plasticity.cpp:1189
MOFEM_LOG
#define MOFEM_LOG(channel, severity)
Log.
Definition: LogManager.hpp:308
MoFEM::NaturalBC::Assembly
Assembly methods.
Definition: Natural.hpp:65
CATCH_ERRORS
#define CATCH_ERRORS
Catch errors.
Definition: definitions.h:385
DEMKOWICZ_JACOBI_BASE
@ DEMKOWICZ_JACOBI_BASE
Definition: definitions.h:66
MoFEM::CommInterface
Managing BitRefLevels.
Definition: CommInterface.hpp:21
MoFEM::OpDGProjectionEvaluation
Definition: DGProjection.hpp:136
MoFEM::Core
CoreTmp< 0 > Core
Definition: Core.hpp:1148
MoFEM::DMoFEMGetInterfacePtr
PetscErrorCode DMoFEMGetInterfacePtr(DM dm, MoFEM::Interface **m_field_ptr)
Get pointer to MoFEM::Interface.
Definition: DMMoFEM.cpp:414
ADOLCPlasticityMaterialModels.hpp
Matetial models for plasticity.
UserDataOperator
ForcesAndSourcesCore::UserDataOperator UserDataOperator
Definition: HookeElement.hpp:75
ADOLCPlasticity.hpp
Monitor
[Push operators to pipeline]
Definition: dynamic_first_order_con_law.cpp:783
approx_order
int approx_order
Definition: test_broken_space.cpp:50
MoFEM::VecOfTimeScalingMethods
std::vector< boost::shared_ptr< ScalingMethod > > VecOfTimeScalingMethods
Vector of time scaling methods.
Definition: Natural.hpp:20
MoFEM::DMMoFEMTSSetMonitor
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.
Definition: DMMoFEM.cpp:1056
AINSWORTH_LEGENDRE_BASE
@ AINSWORTH_LEGENDRE_BASE
Ainsworth Cole (Legendre) approx. base .
Definition: definitions.h:60
Monitor::integrateTraction
boost::shared_ptr< BoundaryEle > integrateTraction
Definition: adolc_plasticity.cpp:684
HCURL
@ HCURL
field with continuous tangents
Definition: definitions.h:86
MOFEM_DATA_INCONSISTENCY
@ MOFEM_DATA_INCONSISTENCY
Definition: definitions.h:31
MoFEM::MeshsetsManager
Interface for managing meshsets containing materials and boundary conditions.
Definition: MeshsetsManager.hpp:104
MoFEM::PetscOptionsGetEList
PetscErrorCode PetscOptionsGetEList(PetscOptions *, const char pre[], const char name[], const char *const *list, PetscInt next, PetscInt *value, PetscBool *set)
Definition: DeprecatedPetsc.hpp:203
MoFEM::createVectorMPI
auto createVectorMPI(MPI_Comm comm, PetscInt n, PetscInt N)
Create MPI Vector.
Definition: PetscSmartObj.hpp:202
sdf_hertz_2d_axisymm_plane.d
float d
Definition: sdf_hertz_2d_axisymm_plane.py:4
MoFEM::MoFEMSNESMonitorFields
MoFEMErrorCode MoFEMSNESMonitorFields(SNES snes, PetscInt its, PetscReal fgnorm, SnesCtx *snes_ctx)
Sens monitor printing residual field by field.
Definition: SnesCtx.cpp:232
FieldApproximationBase
FieldApproximationBase
approximation base
Definition: definitions.h:58
PlasticProblem::cpPtr
boost::shared_ptr< ClosestPointProjection > cpPtr
Definition: adolc_plasticity.cpp:148
ReactionDiffusionEquation::D
const double D
diffusivity
Definition: reaction_diffusion.cpp:20
ContactNaturalBC.hpp
m
FTensor::Index< 'm', 3 > m
Definition: shallow_wave.cpp:80
PlasticProblem::PlasticProblem
PlasticProblem(MoFEM::Interface &m_field)
Definition: adolc_plasticity.cpp:129
MOFEM_ATOM_TEST_INVALID
@ MOFEM_ATOM_TEST_INVALID
Definition: definitions.h:40
MoFEM::getDMSnesCtx
auto getDMSnesCtx(DM dm)
Get SNES context data structure used by DM.
Definition: DMMoFEM.hpp:1127
MoFEMFunctionBeginHot
#define MoFEMFunctionBeginHot
First executable line of each MoFEM function, used for error handling. Final line of MoFEM functions ...
Definition: definitions.h:453
MoFEM::PetscOptionsGetScalar
PetscErrorCode PetscOptionsGetScalar(PetscOptions *, const char pre[], const char name[], PetscScalar *dval, PetscBool *set)
Definition: DeprecatedPetsc.hpp:162
DomainEle
ElementsAndOps< SPACE_DIM >::DomainEle DomainEle
Definition: child_and_parent.cpp:34
MoFEM::MeshsetsManager::getCubitMeshsetPtr
MoFEMErrorCode getCubitMeshsetPtr(const int ms_id, const CubitBCType cubit_bc_type, const CubitMeshSets **cubit_meshset_ptr) const
get cubit meshset
Definition: MeshsetsManager.cpp:578
MoFEM::SmartPetscObj< DM >
PlasticProblem::runProblem
MoFEMErrorCode runProblem()
[Run problem]
Definition: adolc_plasticity.cpp:158
MoFEM::CoreInterface::get_field_entities_by_type
virtual MoFEMErrorCode get_field_entities_by_type(const std::string name, EntityType type, Range &ents) const =0
get entities in the field by type
ContactOps::opFactoryCalculateTraction
MoFEMErrorCode opFactoryCalculateTraction(boost::ptr_deque< ForcesAndSourcesCore::UserDataOperator > &pip, std::string sigma, bool is_axisymmetric=false)
Definition: ContactOps.hpp:1364
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:586
convert.int
int
Definition: convert.py:64
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:429
HDIV
@ HDIV
field with continuous normal traction
Definition: definitions.h:87
MoFEM::FieldBlas
Basic algebra on fields.
Definition: FieldBlas.hpp:21
MoFEM::getDMTsCtx
auto getDMTsCtx(DM dm)
Get TS context data structure used by DM.
Definition: DMMoFEM.hpp:1141
MoFEM::OpLoopSide
Element used to execute operators on side of the element.
Definition: ForcesAndSourcesCore.hpp:1290
MoFEMFunctionBegin
#define MoFEMFunctionBegin
First executable line of each MoFEM function, used for error handling. Final line of MoFEM functions ...
Definition: definitions.h:359
PlasticProblem::mField
MoFEM::Interface & mField
Definition: adolc_plasticity.cpp:134
MoFEM::OpPostProcMapInMoab
Post post-proc data at points from hash maps.
Definition: PostProcBrokenMeshInMoabBase.hpp:698
MoFEM::PetscOptionsGetBool
PetscErrorCode PetscOptionsGetBool(PetscOptions *, const char pre[], const char name[], PetscBool *bval, PetscBool *set)
Definition: DeprecatedPetsc.hpp:182
MoFEM::TSAdaptCreateMoFEM
PetscErrorCode TSAdaptCreateMoFEM(TSAdapt adapt)
Craete MOFEM adapt.
Definition: TsCtx.cpp:797
MoFEM::OpDGProjectionMassMatrix
Definition: DGProjection.hpp:106