v0.14.0
PlasticOpsMonitor.hpp
Go to the documentation of this file.
1 
2 
3 /** \file PlasticOpsMonitor.hpp
4  * \example PlasticOpsMonitor.hpp
5  */
6 
7 namespace PlasticOps {
8 
9 struct Monitor : public FEMethod {
10 
11  Monitor(SmartPetscObj<DM> dm,
12  std::pair<boost::shared_ptr<PostProcEle>,
13  boost::shared_ptr<SkinPostProcEle>>
14  pair_post_proc_fe,
15  boost::shared_ptr<DomainEle> reaction_fe,
16  std::tuple<SmartPetscObj<Vec>, SmartPetscObj<VecScatter>> ux_scatter,
17  std::tuple<SmartPetscObj<Vec>, SmartPetscObj<VecScatter>> uy_scatter,
18  std::tuple<SmartPetscObj<Vec>, SmartPetscObj<VecScatter>> uz_scatter)
19  : dM(dm), reactionFe(reaction_fe), uXScatter(ux_scatter),
20  uYScatter(uy_scatter), uZScatter(uz_scatter) {
21  postProcFe = pair_post_proc_fe.first;
22  skinPostProcFe = pair_post_proc_fe.second;
23  };
24 
25  MoFEMErrorCode preProcess() { return 0; }
26  MoFEMErrorCode operator()() { return 0; }
27 
30 
31  MoFEM::Interface *m_field_ptr;
32  CHKERR DMoFEMGetInterfacePtr(dM, &m_field_ptr);
33 
34  auto make_vtk = [&]() {
36  if (postProcFe) {
38  getCacheWeakPtr());
39  CHKERR postProcFe->writeFile("out_plastic_" +
40  boost::lexical_cast<std::string>(ts_step) +
41  ".h5m");
42  }
43  if (skinPostProcFe) {
45  getCacheWeakPtr());
46  CHKERR skinPostProcFe->writeFile(
47  "out_skin_plastic_" + boost::lexical_cast<std::string>(ts_step) +
48  ".h5m");
49  }
51  };
52 
53  auto calculate_reaction = [&]() {
55  auto r = createDMVector(dM);
56  reactionFe->f = r;
57  CHKERR VecZeroEntries(r);
58  CHKERR DMoFEMLoopFiniteElements(dM, "dFE", reactionFe, getCacheWeakPtr());
59 
60 #ifndef NDEBUG
61  auto post_proc_residual = [&](auto dm, auto f_res, auto out_name) {
63  auto post_proc_fe =
64  boost::make_shared<PostProcBrokenMeshInMoab<DomainEle>>(
65  *m_field_ptr);
66  using OpPPMap = OpPostProcMapInMoab<SPACE_DIM, SPACE_DIM>;
67  auto u_vec = boost::make_shared<MatrixDouble>();
68  post_proc_fe->getOpPtrVector().push_back(
69  new OpCalculateVectorFieldValues<SPACE_DIM>("U", u_vec, f_res));
70  post_proc_fe->getOpPtrVector().push_back(
71 
72  new OpPPMap(
73 
74  post_proc_fe->getPostProcMesh(), post_proc_fe->getMapGaussPts(),
75 
76  {},
77 
78  {{"RES", u_vec}},
79 
80  {}, {})
81 
82  );
83 
84  CHKERR DMoFEMLoopFiniteElements(dM, "dFE", post_proc_fe);
85  post_proc_fe->writeFile("res.h5m");
87  };
88 
89  CHKERR post_proc_residual(dM, r, "reaction");
90 #endif // NDEBUG
91 
93  };
94 
95  auto print_max_min = [&](auto &tuple, const std::string msg) {
97  CHKERR VecScatterBegin(std::get<1>(tuple), ts_u, std::get<0>(tuple),
98  INSERT_VALUES, SCATTER_FORWARD);
99  CHKERR VecScatterEnd(std::get<1>(tuple), ts_u, std::get<0>(tuple),
100  INSERT_VALUES, SCATTER_FORWARD);
101  double max, min;
102  CHKERR VecMax(std::get<0>(tuple), PETSC_NULL, &max);
103  CHKERR VecMin(std::get<0>(tuple), PETSC_NULL, &min);
104  MOFEM_LOG_C("PLASTICITY", Sev::inform, "%s time %3.4e min %3.4e max %3.4e",
105  msg.c_str(), ts_t, min, max);
107  };
108 
109  int se = 1;
110  CHKERR PetscOptionsGetInt(PETSC_NULL, "", "-save_every", &se, PETSC_NULL);
111  if (!(ts_step % se)) {
112  CHKERR make_vtk();
113  }
114  if (reactionFe)
115  CHKERR calculate_reaction();
116  CHKERR print_max_min(uXScatter, "Ux");
117  CHKERR print_max_min(uYScatter, "Uy");
118  if constexpr (SPACE_DIM == 3)
119  CHKERR print_max_min(uZScatter, "Uz");
120 
122  }
123 
124 private:
125  SmartPetscObj<DM> dM;
126  boost::shared_ptr<PostProcEle> postProcFe;
127  boost::shared_ptr<SkinPostProcEle> skinPostProcFe;
128  boost::shared_ptr<DomainEle> reactionFe;
129  std::tuple<SmartPetscObj<Vec>, SmartPetscObj<VecScatter>> uXScatter;
130  std::tuple<SmartPetscObj<Vec>, SmartPetscObj<VecScatter>> uYScatter;
131  std::tuple<SmartPetscObj<Vec>, SmartPetscObj<VecScatter>> uZScatter;
132 };
133 
134 }; // namespace PlasticOps
PlasticOps::Monitor::operator()
MoFEMErrorCode operator()()
Definition: PlasticOpsMonitor.hpp:26
PlasticOps::Monitor::uXScatter
std::tuple< SmartPetscObj< Vec >, SmartPetscObj< VecScatter > > uXScatter
Definition: PlasticOpsMonitor.hpp:129
MoFEM::Exceptions::MoFEMErrorCode
PetscErrorCode MoFEMErrorCode
MoFEM/PETSc error code.
Definition: Exceptions.hpp:56
PlasticOps::Monitor::dM
SmartPetscObj< DM > dM
Definition: PlasticOpsMonitor.hpp:125
PlasticOps::Monitor::uYScatter
std::tuple< SmartPetscObj< Vec >, SmartPetscObj< VecScatter > > uYScatter
Definition: PlasticOpsMonitor.hpp:130
sdf.r
int r
Definition: sdf.py:8
MoFEM::DeprecatedCoreInterface
Deprecated interface functions.
Definition: DeprecatedCoreInterface.hpp:16
MoFEM::PostProcBrokenMeshInMoab
Definition: PostProcBrokenMeshInMoabBase.hpp:667
PlasticOps::Monitor::skinPostProcFe
boost::shared_ptr< SkinPostProcEle > skinPostProcFe
Definition: PlasticOpsMonitor.hpp:127
FEMethod
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
SPACE_DIM
constexpr int SPACE_DIM
Definition: child_and_parent.cpp:16
MOFEM_LOG_C
#define MOFEM_LOG_C(channel, severity, format,...)
Definition: LogManager.hpp:311
PlasticOps::Monitor::Monitor
Monitor(SmartPetscObj< DM > dm, std::pair< boost::shared_ptr< PostProcEle >, boost::shared_ptr< SkinPostProcEle >> pair_post_proc_fe, boost::shared_ptr< DomainEle > reaction_fe, std::tuple< SmartPetscObj< Vec >, SmartPetscObj< VecScatter >> ux_scatter, std::tuple< SmartPetscObj< Vec >, SmartPetscObj< VecScatter >> uy_scatter, std::tuple< SmartPetscObj< Vec >, SmartPetscObj< VecScatter >> uz_scatter)
Definition: PlasticOpsMonitor.hpp:11
PlasticOps::Monitor::uZScatter
std::tuple< SmartPetscObj< Vec >, SmartPetscObj< VecScatter > > uZScatter
Definition: PlasticOpsMonitor.hpp:131
OpPPMap
OpPostProcMapInMoab< SPACE_DIM, SPACE_DIM > OpPPMap
Definition: photon_diffusion.cpp:29
PlasticOps::Monitor
Definition: PlasticOpsMonitor.hpp:9
PlasticOps
Definition: PlasticNaturalBCs.hpp:13
std
Definition: enable_if.hpp:5
MoFEM::DMoFEMGetInterfacePtr
PetscErrorCode DMoFEMGetInterfacePtr(DM dm, MoFEM::Interface **m_field_ptr)
Get pointer to MoFEM::Interface.
Definition: DMMoFEM.cpp:414
PlasticOps::Monitor::preProcess
MoFEMErrorCode preProcess()
Definition: PlasticOpsMonitor.hpp:25
EigenMatrix::Vec
const FTensor::Tensor2< T, Dim, Dim > Vec
Definition: MatrixFunction.hpp:66
PlasticOps::Monitor::postProcFe
boost::shared_ptr< PostProcEle > postProcFe
Definition: PlasticOpsMonitor.hpp:126
DomainEle
ElementsAndOps< SPACE_DIM >::DomainEle DomainEle
Definition: child_and_parent.cpp:34
PlasticOps::Monitor::reactionFe
boost::shared_ptr< DomainEle > reactionFe
Definition: PlasticOpsMonitor.hpp:128
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
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
PlasticOps::Monitor::postProcess
MoFEMErrorCode postProcess()
Definition: PlasticOpsMonitor.hpp:28
MoFEMFunctionBegin
#define MoFEMFunctionBegin
First executable line of each MoFEM function, used for error handling. Final line of MoFEM functions ...
Definition: definitions.h:359
MoFEM::OpPostProcMapInMoab
Post post-proc data at points from hash maps.
Definition: PostProcBrokenMeshInMoabBase.hpp:698