v0.15.5
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 boost::shared_ptr<DomainEle> reaction_fe,
17 std::tuple<SmartPetscObj<Vec>, SmartPetscObj<VecScatter>> ux_scatter,
18 std::tuple<SmartPetscObj<Vec>, SmartPetscObj<VecScatter>> uy_scatter,
19 std::tuple<SmartPetscObj<Vec>, SmartPetscObj<VecScatter>> uz_scatter,
20 std::array<double, 3> pass_field_eval_coords,
21 boost::shared_ptr<SetPtsData> pass_field_eval_data,
22 boost::shared_ptr<std::map<std::string, boost::shared_ptr<VectorDouble>>>
23 scalar_field_ptrs,
24 boost::shared_ptr<std::map<std::string, boost::shared_ptr<MatrixDouble>>>
25 vec_field_ptrs,
26 boost::shared_ptr<std::map<std::string, boost::shared_ptr<MatrixDouble>>>
27 sym_tensor_field_ptrs,
28 boost::shared_ptr<std::map<std::string, boost::shared_ptr<MatrixDouble>>>
29 tensor_field_ptrs)
30 : dM(dm), reactionFe(reaction_fe), uXScatter(ux_scatter),
31 uYScatter(uy_scatter), uZScatter(uz_scatter),
32 fieldEvalCoords(pass_field_eval_coords),
33 fieldEvalData(pass_field_eval_data), scalarFieldPtrs(scalar_field_ptrs),
34 vecFieldPtrs(vec_field_ptrs), symTensorFieldPtrs(sym_tensor_field_ptrs),
35 tensorFieldPtrs(tensor_field_ptrs) {
36 postProcFe = pair_post_proc_fe.first;
37 skinPostProcFe = pair_post_proc_fe.second;
38 };
39
40 virtual ~Monitor() = default;
41
42 MoFEMErrorCode preProcess() { return 0; }
43 MoFEMErrorCode operator()() { return 0; }
44
45private:
46 DM dM;
47 boost::shared_ptr<PostProcEle> postProcFe;
48 boost::shared_ptr<SkinPostProcEle> skinPostProcFe;
49 boost::shared_ptr<DomainEle> reactionFe;
50 std::tuple<SmartPetscObj<Vec>, SmartPetscObj<VecScatter>> uXScatter;
51 std::tuple<SmartPetscObj<Vec>, SmartPetscObj<VecScatter>> uYScatter;
52 std::tuple<SmartPetscObj<Vec>, SmartPetscObj<VecScatter>> uZScatter;
53 std::array<double, 3> fieldEvalCoords;
54 boost::shared_ptr<SetPtsData> fieldEvalData;
55 boost::shared_ptr<std::map<std::string, boost::shared_ptr<VectorDouble>>>
57 boost::shared_ptr<std::map<std::string, boost::shared_ptr<MatrixDouble>>>
59 boost::shared_ptr<std::map<std::string, boost::shared_ptr<MatrixDouble>>>
61 boost::shared_ptr<std::map<std::string, boost::shared_ptr<MatrixDouble>>>
63
64protected:
65 MoFEMErrorCode postProcess();
66};
67
68template <int DIM> MoFEMErrorCode Monitor<DIM>::postProcess() {
70
71 MoFEM::Interface *m_field_ptr;
72 CHKERR DMoFEMGetInterfacePtr(dM, &m_field_ptr);
73 auto *simple = m_field_ptr->getInterface<Simple>();
74
75 if (do_eval_field) {
76
77 CHKERR m_field_ptr->getInterface<FieldEvaluatorInterface>()
78 ->evalFEAtThePoint<DIM>(
79 fieldEvalCoords.data(), 1e-12, simple->getProblemName(),
80 simple->getDomainFEName(), fieldEvalData,
81 m_field_ptr->get_comm_rank(), m_field_ptr->get_comm_rank(),
82 getCacheWeakPtr().lock(), MF_EXIST, QUIET);
83
84 auto process_scalar_field =
85 [](const std::string label,
86 const boost::shared_ptr<VectorDouble> scalarFieldPtr) {
87 if (scalarFieldPtr->size()) {
88 auto t_scalar_holder = getFTensor0FromVec(*scalarFieldPtr);
89
90 MOFEM_LOG("SYNC", Sev::inform)
91 << "For " << label << " field, " << t_scalar_holder;
92 }
93 };
94
95 auto process_vector_field =
96 [](const std::string label,
97 const boost::shared_ptr<MatrixDouble> vecFieldPtr) {
98 if (vecFieldPtr->size1()) {
99 auto t_vec_holder = getFTensor1FromMat<DIM>(*vecFieldPtr);
100
101 std::string vec_holder_string = "";
102 for (int i = 0; i < DIM; i++) {
103 vec_holder_string +=
104 " " + boost::lexical_cast<std::string>(t_vec_holder(i));
105 }
106
107 MOFEM_LOG("SYNC", Sev::inform)
108 << "For " << label << " field," << vec_holder_string;
109 }
110 };
111
112 auto process_sym_tensor_field =
113 [](const std::string label,
114 const boost::shared_ptr<MatrixDouble> symTensorFieldPtr) {
115 if (symTensorFieldPtr->size1()) {
116 auto t_sym_tensor_holder =
117 getFTensor2SymmetricFromMat<DIM>(*symTensorFieldPtr);
118
119 std::string sym_tensor_holder_string = "";
120 for (int i = 0; i < DIM; i++) {
121 for (int j = i; j < DIM; j++) {
122 sym_tensor_holder_string +=
123 ", entry " + boost::lexical_cast<std::string>(i) +
124 boost::lexical_cast<std::string>(j) + " = ";
125 sym_tensor_holder_string +=
126 boost::lexical_cast<std::string>(t_sym_tensor_holder(i, j));
127 }
128 }
129
130 MOFEM_LOG("SYNC", Sev::inform)
131 << "For " << label << " field" << sym_tensor_holder_string;
132 }
133 };
134
135 auto process_tensor_field =
136 [](const std::string label,
137 const boost::shared_ptr<MatrixDouble> tensorFieldPtr) {
138 if (tensorFieldPtr->size1()) {
139 auto t_tensor_holder =
140 getFTensor2FromMat<DIM, DIM>(*tensorFieldPtr);
141
142 std::string tensor_holder_string = "";
143 for (int i = 0; i < DIM; i++) {
144 for (int j = 0; j < DIM; j++) {
145 tensor_holder_string +=
146 ", entry " + boost::lexical_cast<std::string>(i) +
147 boost::lexical_cast<std::string>(j) + " = ";
148 tensor_holder_string +=
149 boost::lexical_cast<std::string>(t_tensor_holder(i, j));
150 }
151 }
152
153 MOFEM_LOG("SYNC", Sev::inform)
154 << "For " << label << " field" << tensor_holder_string;
155 }
156 };
157
158 auto process_fields = [](auto &fieldPtr, auto process_field) {
159 for (const auto &pair : fieldPtr) {
160 const std::string &label = pair.first;
161 const boost::shared_ptr<MatrixDouble> &ptr = pair.second;
162
163 if (ptr) {
164 process_field(label, ptr);
165 }
166 }
167 };
168
169 if (scalarFieldPtrs) {
170 for (const auto &pair : *scalarFieldPtrs) {
171 const std::string &label = pair.first;
172 const boost::shared_ptr<VectorDouble> &ptr = pair.second;
173
174 if (ptr) {
175 process_scalar_field(label, ptr);
176 }
177 }
178 }
179
180 if (vecFieldPtrs) {
181 for (const auto &pair : *vecFieldPtrs) {
182 const std::string &label = pair.first;
183 const boost::shared_ptr<MatrixDouble> &ptr = pair.second;
184
185 if (ptr) {
186 process_vector_field(label, ptr);
187 }
188 }
189 }
190
191 if (symTensorFieldPtrs) {
192 for (const auto &pair : *symTensorFieldPtrs) {
193 const std::string &label = pair.first;
194 const boost::shared_ptr<MatrixDouble> &ptr = pair.second;
195
196 if (ptr) {
197 process_sym_tensor_field(label, ptr);
198 }
199 }
200 }
201
202 if (tensorFieldPtrs) {
203 for (const auto &pair : *tensorFieldPtrs) {
204 const std::string &label = pair.first;
205 const boost::shared_ptr<MatrixDouble> &ptr = pair.second;
206
207 if (ptr) {
208 process_tensor_field(label, ptr);
209 }
210 }
211 }
212 }
213
214 MOFEM_LOG_SEVERITY_SYNC(m_field_ptr->get_comm(), Sev::inform);
215
216 auto make_vtk = [&]() {
218 if (postProcFe) {
219 CHKERR DMoFEMLoopFiniteElements(dM, "dFE", postProcFe, getCacheWeakPtr());
220 CHKERR postProcFe->writeFile(
221 "out_plastic_" + boost::lexical_cast<std::string>(ts_step) + ".h5m");
222 }
223 if (skinPostProcFe) {
224 CHKERR DMoFEMLoopFiniteElements(dM, "bFE", skinPostProcFe,
225 getCacheWeakPtr());
226 CHKERR skinPostProcFe->writeFile(
227 "out_skin_plastic_" + boost::lexical_cast<std::string>(ts_step) +
228 ".h5m");
229 }
231 };
232
233 auto calculate_reaction = [&]() {
235 auto r = createDMVector(dM);
236 reactionFe->f = r;
237 CHKERR VecZeroEntries(r);
238 CHKERR DMoFEMLoopFiniteElements(dM, "dFE", reactionFe, getCacheWeakPtr());
239
240#ifndef NDEBUG
241 auto post_proc_residual = [&](auto dm, auto f_res, auto out_name) {
243 auto post_proc_fe =
244 boost::make_shared<PostProcBrokenMeshInMoab<DomainEle>>(*m_field_ptr);
245 using OpPPMap = OpPostProcMapInMoab<DIM, DIM>;
246 auto u_vec = boost::make_shared<MatrixDouble>();
247 post_proc_fe->getOpPtrVector().push_back(
248 new OpCalculateVectorFieldValues<DIM>("U", u_vec, f_res));
249 post_proc_fe->getOpPtrVector().push_back(
250
251 new OpPPMap(
252
253 post_proc_fe->getPostProcMesh(), post_proc_fe->getMapGaussPts(),
254
255 {},
256
257 {{"RES", u_vec}},
258
259 {}, {})
260
261 );
262
263 CHKERR DMoFEMLoopFiniteElements(dM, "dFE", post_proc_fe);
264 post_proc_fe->writeFile("res.h5m");
266 };
267
268 CHKERR post_proc_residual(dM, r, "reaction");
269#endif // NDEBUG
270
272 };
273
274 auto print_max_min = [&](auto &tuple, const std::string msg) {
276 CHKERR VecScatterBegin(std::get<1>(tuple), ts_u, std::get<0>(tuple),
277 INSERT_VALUES, SCATTER_FORWARD);
278 CHKERR VecScatterEnd(std::get<1>(tuple), ts_u, std::get<0>(tuple),
279 INSERT_VALUES, SCATTER_FORWARD);
280 double max, min;
281 CHKERR VecMax(std::get<0>(tuple), PETSC_NULLPTR, &max);
282 CHKERR VecMin(std::get<0>(tuple), PETSC_NULLPTR, &min);
283 MOFEM_LOG_C("PLASTICITY", Sev::inform, "%s time %3.4e min %3.4e max %3.4e",
284 msg.c_str(), ts_t, min, max);
286 };
287
288 int se = 1;
289 CHKERR PetscOptionsGetInt(PETSC_NULLPTR, "", "-save_every", &se, PETSC_NULLPTR);
290 if (!(ts_step % se)) {
291 CHKERR make_vtk();
292 }
293 if (reactionFe)
294 CHKERR calculate_reaction();
295 CHKERR print_max_min(uXScatter, "Ux");
296 CHKERR print_max_min(uYScatter, "Uy");
297 if (DIM == 3)
298 CHKERR print_max_min(uZScatter, "Uz");
299
301}
302
303}; // 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< DomainEle > reactionFe
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, 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, 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:119