v0.16.0
Loading...
Searching...
No Matches
PlasticOpsMonitor.hpp
Go to the documentation of this file.
1
2
3/** \file PlasticOpsMonitor.hpp
4 * \example mofem/tutorials/adv-0_plasticity/src/PlasticOpsMonitor.hpp
5 */
6
7namespace PlasticOps {
8
9template <int DIM> struct Monitor : public FEMethod {
10
12 DM dm,
13 std::pair<boost::shared_ptr<PostProcEle>,
14 boost::shared_ptr<SkinPostProcEle>>
15 pair_post_proc_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 std::array<double, 3> pass_field_eval_coords,
20 boost::shared_ptr<SetPtsData> pass_field_eval_data,
21 boost::shared_ptr<std::map<std::string, boost::shared_ptr<VectorDouble>>>
22 scalar_field_ptrs,
23 boost::shared_ptr<std::map<std::string, boost::shared_ptr<MatrixDouble>>>
24 vec_field_ptrs,
25 boost::shared_ptr<std::map<std::string, boost::shared_ptr<MatrixDouble>>>
26 sym_tensor_field_ptrs,
27 boost::shared_ptr<std::map<std::string, boost::shared_ptr<MatrixDouble>>>
28 tensor_field_ptrs)
29 : dM(dm), uXScatter(ux_scatter), uYScatter(uy_scatter),
30 uZScatter(uz_scatter), fieldEvalCoords(pass_field_eval_coords),
31 fieldEvalData(pass_field_eval_data), scalarFieldPtrs(scalar_field_ptrs),
32 vecFieldPtrs(vec_field_ptrs), symTensorFieldPtrs(sym_tensor_field_ptrs),
33 tensorFieldPtrs(tensor_field_ptrs) {
34 postProcFe = pair_post_proc_fe.first;
35 skinPostProcFe = pair_post_proc_fe.second;
36 };
37
38 virtual ~Monitor() = default;
39
40 MoFEMErrorCode preProcess() { return 0; }
41 MoFEMErrorCode operator()() { return 0; }
42
43private:
44 DM dM;
45 boost::shared_ptr<PostProcEle> postProcFe;
46 boost::shared_ptr<SkinPostProcEle> skinPostProcFe;
47 std::tuple<SmartPetscObj<Vec>, SmartPetscObj<VecScatter>> uXScatter;
48 std::tuple<SmartPetscObj<Vec>, SmartPetscObj<VecScatter>> uYScatter;
49 std::tuple<SmartPetscObj<Vec>, SmartPetscObj<VecScatter>> uZScatter;
50 std::array<double, 3> fieldEvalCoords;
51 boost::shared_ptr<SetPtsData> fieldEvalData;
52 boost::shared_ptr<std::map<std::string, boost::shared_ptr<VectorDouble>>>
54 boost::shared_ptr<std::map<std::string, boost::shared_ptr<MatrixDouble>>>
56 boost::shared_ptr<std::map<std::string, boost::shared_ptr<MatrixDouble>>>
58 boost::shared_ptr<std::map<std::string, boost::shared_ptr<MatrixDouble>>>
60
61protected:
62 MoFEMErrorCode postProcess();
63};
64
65template <int DIM> MoFEMErrorCode Monitor<DIM>::postProcess() {
67
68 MoFEM::Interface *m_field_ptr;
69 CHKERR DMoFEMGetInterfacePtr(dM, &m_field_ptr);
70 auto *simple = m_field_ptr->getInterface<Simple>();
71
72 if (do_eval_field) {
73
74 CHKERR m_field_ptr->getInterface<FieldEvaluatorInterface>()
75 ->evalFEAtThePoint<DIM>(
76 fieldEvalCoords.data(), 1e-12, simple->getProblemName(),
77 simple->getDomainFEName(), fieldEvalData,
78 m_field_ptr->get_comm_rank(), m_field_ptr->get_comm_rank(),
79 getCacheWeakPtr().lock(), MF_EXIST, QUIET);
80
81 auto process_scalar_field =
82 [](const std::string label,
83 const boost::shared_ptr<VectorDouble> scalarFieldPtr) {
84 if (scalarFieldPtr->size()) {
85 auto t_scalar_holder = getFTensor0FromVec(*scalarFieldPtr);
86
87 MOFEM_LOG("SYNC", Sev::inform)
88 << "For " << label << " field, " << t_scalar_holder;
89 }
90 };
91
92 auto process_vector_field =
93 [](const std::string label,
94 const boost::shared_ptr<MatrixDouble> vecFieldPtr) {
95 if (vecFieldPtr->size1()) {
96 auto t_vec_holder = getFTensor1FromMat<DIM>(*vecFieldPtr);
97
98 std::string vec_holder_string = "";
99 for (int i = 0; i < DIM; i++) {
100 vec_holder_string +=
101 " " + boost::lexical_cast<std::string>(t_vec_holder(i));
102 }
103
104 MOFEM_LOG("SYNC", Sev::inform)
105 << "For " << label << " field," << vec_holder_string;
106 }
107 };
108
109 auto process_sym_tensor_field =
110 [](const std::string label,
111 const boost::shared_ptr<MatrixDouble> symTensorFieldPtr) {
112 if (symTensorFieldPtr->size1()) {
113 auto t_sym_tensor_holder =
114 getFTensor2SymmetricFromMat<DIM>(*symTensorFieldPtr);
115
116 std::string sym_tensor_holder_string = "";
117 for (int i = 0; i < DIM; i++) {
118 for (int j = i; j < DIM; j++) {
119 sym_tensor_holder_string +=
120 ", entry " + boost::lexical_cast<std::string>(i) +
121 boost::lexical_cast<std::string>(j) + " = ";
122 sym_tensor_holder_string +=
123 boost::lexical_cast<std::string>(t_sym_tensor_holder(i, j));
124 }
125 }
126
127 MOFEM_LOG("SYNC", Sev::inform)
128 << "For " << label << " field" << sym_tensor_holder_string;
129 }
130 };
131
132 auto process_tensor_field =
133 [](const std::string label,
134 const boost::shared_ptr<MatrixDouble> tensorFieldPtr) {
135 if (tensorFieldPtr->size1()) {
136 auto t_tensor_holder =
137 getFTensor2FromMat<DIM, DIM>(*tensorFieldPtr);
138
139 std::string tensor_holder_string = "";
140 for (int i = 0; i < DIM; i++) {
141 for (int j = 0; j < DIM; j++) {
142 tensor_holder_string +=
143 ", entry " + boost::lexical_cast<std::string>(i) +
144 boost::lexical_cast<std::string>(j) + " = ";
145 tensor_holder_string +=
146 boost::lexical_cast<std::string>(t_tensor_holder(i, j));
147 }
148 }
149
150 MOFEM_LOG("SYNC", Sev::inform)
151 << "For " << label << " field" << tensor_holder_string;
152 }
153 };
154
155 if (scalarFieldPtrs) {
156 for (const auto &pair : *scalarFieldPtrs) {
157 const std::string &label = pair.first;
158 const boost::shared_ptr<VectorDouble> &ptr = pair.second;
159
160 if (ptr) {
161 process_scalar_field(label, ptr);
162 }
163 }
164 }
165
166 if (vecFieldPtrs) {
167 for (const auto &pair : *vecFieldPtrs) {
168 const std::string &label = pair.first;
169 const boost::shared_ptr<MatrixDouble> &ptr = pair.second;
170
171 if (ptr) {
172 process_vector_field(label, ptr);
173 }
174 }
175 }
176
177 if (symTensorFieldPtrs) {
178 for (const auto &pair : *symTensorFieldPtrs) {
179 const std::string &label = pair.first;
180 const boost::shared_ptr<MatrixDouble> &ptr = pair.second;
181
182 if (ptr) {
183 process_sym_tensor_field(label, ptr);
184 }
185 }
186 }
187
188 if (tensorFieldPtrs) {
189 for (const auto &pair : *tensorFieldPtrs) {
190 const std::string &label = pair.first;
191 const boost::shared_ptr<MatrixDouble> &ptr = pair.second;
192
193 if (ptr) {
194 process_tensor_field(label, ptr);
195 }
196 }
197 }
198 }
199
200 MOFEM_LOG_SEVERITY_SYNC(m_field_ptr->get_comm(), Sev::inform);
201
202 auto make_vtk = [&]() {
204 if (postProcFe) {
205 CHKERR DMoFEMLoopFiniteElements(dM, "dFE", postProcFe, getCacheWeakPtr());
206 CHKERR postProcFe->writeFile(
207 "out_plastic_" + boost::lexical_cast<std::string>(ts_step) + ".h5m");
208 }
209 if (skinPostProcFe) {
210 CHKERR DMoFEMLoopFiniteElements(dM, "bFE", skinPostProcFe,
211 getCacheWeakPtr());
212 CHKERR skinPostProcFe->writeFile(
213 "out_skin_plastic_" + boost::lexical_cast<std::string>(ts_step) +
214 ".h5m");
215 }
217 };
218
219 auto calculate_reaction = [&]() {
221 auto pip = m_field_ptr->getInterface<PipelineManager>();
222 if (!pip->getEvaluationFE())
223 return 0;
224 auto r = createDMVector(dM);
225 pip->getEvaluationFE()->f = r;
226 CHKERR VecZeroEntries(r);
227 CHKERR pip->loopFiniteElementsEvaluation();
228
229#ifndef NDEBUG
230 auto post_proc_residual = [&](auto dm, auto f_res, auto out_name) {
232 auto post_proc_fe =
233 boost::make_shared<PostProcBrokenMeshInMoab<DomainEle>>(*m_field_ptr);
234 using OpPPMap = OpPostProcMapInMoab<DIM, DIM>;
235 auto u_vec = boost::make_shared<MatrixDouble>();
236 post_proc_fe->getOpPtrVector().push_back(
237 new OpCalculateVectorFieldValues<DIM>("U", u_vec, f_res));
238 post_proc_fe->getOpPtrVector().push_back(
239
240 new OpPPMap(
241
242 post_proc_fe->getPostProcMesh(), post_proc_fe->getMapGaussPts(),
243
244 {},
245
246 {{"RES", u_vec}},
247
248 {}, {})
249
250 );
251
252 CHKERR DMoFEMLoopFiniteElements(dM, "dFE", post_proc_fe);
253 post_proc_fe->writeFile("res.h5m");
255 };
256
257 CHKERR post_proc_residual(dM, r, "reaction");
258#endif // NDEBUG
259
261 };
262
263 auto print_max_min = [&](auto &tuple, const std::string msg) {
265 CHKERR VecScatterBegin(std::get<1>(tuple), ts_u, std::get<0>(tuple),
266 INSERT_VALUES, SCATTER_FORWARD);
267 CHKERR VecScatterEnd(std::get<1>(tuple), ts_u, std::get<0>(tuple),
268 INSERT_VALUES, SCATTER_FORWARD);
269 double max, min;
270 CHKERR VecMax(std::get<0>(tuple), PETSC_NULLPTR, &max);
271 CHKERR VecMin(std::get<0>(tuple), PETSC_NULLPTR, &min);
272 MOFEM_LOG_C("PLASTICITY", Sev::inform, "%s time %3.4e min %3.4e max %3.4e",
273 msg.c_str(), ts_t, min, max);
275 };
276
277 int se = 1;
278 CHKERR PetscOptionsGetInt(PETSC_NULLPTR, "", "-save_every", &se, PETSC_NULLPTR);
279 if (!(ts_step % se)) {
280 CHKERR make_vtk();
281 }
282 CHKERR calculate_reaction();
283 CHKERR print_max_min(uXScatter, "Ux");
284 CHKERR print_max_min(uYScatter, "Uy");
285 if (DIM == 3)
286 CHKERR print_max_min(uZScatter, "Uz");
287
289}
290
291}; // namespace PlasticOps
#define MOFEM_LOG_SEVERITY_SYNC(comm, severity)
Synchronise "SYNC" on curtain severity level.
#define MOFEM_LOG_C(channel, severity, format,...)
void simple(double P1[], double P2[], double P3[], double c[], const int N)
Definition acoustic.cpp:69
@ QUIET
@ MF_EXIST
#define MoFEMFunctionBegin
First executable line of each MoFEM function, used for error handling. Final line of MoFEM functions ...
#define MoFEMFunctionReturn(a)
Last executable line of each PETSc function used for error handling. Replaces return()
#define CHKERR
Inline error check.
#define MOFEM_LOG(channel, severity)
Log.
FTensor::Index< 'i', SPACE_DIM > i
FTensor::Index< 'j', 3 > j
OpPostProcMapInMoab< SPACE_DIM, SPACE_DIM > OpPPMap
virtual MPI_Comm & get_comm() const =0
virtual int get_comm_rank() const =0
Deprecated interface functions.
Post post-proc data at points from hash maps.
MoFEMErrorCode getInterface(IFACE *&iface) const
Get interface reference to pointer of interface.
std::tuple< SmartPetscObj< Vec >, SmartPetscObj< VecScatter > > uYScatter
std::array< double, 3 > fieldEvalCoords
std::tuple< SmartPetscObj< Vec >, SmartPetscObj< VecScatter > > uZScatter
MoFEMErrorCode operator()()
boost::shared_ptr< SetPtsData > fieldEvalData
boost::shared_ptr< PostProcEle > postProcFe
MoFEMErrorCode preProcess()
virtual ~Monitor()=default
boost::shared_ptr< std::map< std::string, boost::shared_ptr< MatrixDouble > > > symTensorFieldPtrs
boost::shared_ptr< std::map< std::string, boost::shared_ptr< MatrixDouble > > > tensorFieldPtrs
boost::shared_ptr< SkinPostProcEle > skinPostProcFe
MoFEMErrorCode postProcess()
boost::shared_ptr< std::map< std::string, boost::shared_ptr< MatrixDouble > > > vecFieldPtrs
boost::shared_ptr< std::map< std::string, boost::shared_ptr< VectorDouble > > > scalarFieldPtrs
Monitor(DM dm, std::pair< boost::shared_ptr< PostProcEle >, boost::shared_ptr< SkinPostProcEle > > pair_post_proc_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, std::array< double, 3 > pass_field_eval_coords, boost::shared_ptr< SetPtsData > pass_field_eval_data, boost::shared_ptr< std::map< std::string, boost::shared_ptr< VectorDouble > > > scalar_field_ptrs, boost::shared_ptr< std::map< std::string, boost::shared_ptr< MatrixDouble > > > vec_field_ptrs, boost::shared_ptr< std::map< std::string, boost::shared_ptr< MatrixDouble > > > sym_tensor_field_ptrs, boost::shared_ptr< std::map< std::string, boost::shared_ptr< MatrixDouble > > > tensor_field_ptrs)
std::tuple< SmartPetscObj< Vec >, SmartPetscObj< VecScatter > > uXScatter
PetscBool do_eval_field
Evaluate field.
Definition plastic.cpp:120