179 {
181
182 MOFEM_LOG(
"EP", Sev::inform) <<
"Monitor postProcess";
183
184
185 auto get_ents_on_mesh_skin = [&]() {
186
187 std::map<std::string, Range> boundary_entities_vec;
188
189 auto get_block_vec_impl = [&](auto block_name) {
191 std::regex(
192
193 (boost::format("%s(.*)") % block_name).str()
194
195 ));
196 };
197
198 auto add_blockset_ents_impl = [&](auto &&vec) {
200 for (auto it : vec) {
201 Range boundary_entities;
203 boundary_entities, true);
204 std::string meshset_name = it->getName();
205 boundary_entities_vec[meshset_name] = boundary_entities;
206 boundary_entities.clear();
207 }
209 };
210
211 for (auto block_name : {"SPATIAL_DISP", "FIX", "CONTACT",
212 "SPATIAL_ROTATION", "NORMAL_DISPLACEMENT"}) {
214 "add blockset entities");
215 }
216
217 return boundary_entities_vec;
218 };
219
220 auto boundary_entities_vec = get_ents_on_mesh_skin();
221
222 std::vector<std::tuple<std::string, Range, std::array<double, 6>>>
223 reactionForces;
224 for (const auto &pair : boundary_entities_vec) {
225 reactionForces.push_back(
226 std::make_tuple(pair.first, pair.second,
227 std::array<double, 6>{0.0, 0.0, 0.0, 0.0, 0.0, 0.0}));
228 }
229
232 };
233 auto face_fe =
234 boost::make_shared<FaceElementForcesAndSourcesCore>(
eP.
mField);
235 auto no_rule = [](
int,
int,
int) {
return -1; };
236 face_fe->getRuleHook = integration_rule_face;
238 EshelbianPlasticity::AddHOOps<SPACE_DIM - 1, SPACE_DIM, SPACE_DIM>::add(
241
242 auto op_side =
244 face_fe->getOpPtrVector().push_back(op_side);
245 auto side_fe_ptr = op_side->getSideFEPtr();
246 auto base_ptr =
247 boost::make_shared<EshelbianPlasticity::CGGUserPolynomialBase>();
248 side_fe_ptr->getUserPolynomialBase() = base_ptr;
249 CHKERR EshelbianPlasticity::AddHOOps<SPACE_DIM, SPACE_DIM, SPACE_DIM>::add(
252 auto piola_scale_ptr = boost::make_shared<double>(1.0);
253 side_fe_ptr->getOpPtrVector().push_back(
256 side_fe_ptr->getOpPtrVector().push_back(
257 new OpCalculateHVecTensorField<SPACE_DIM, SPACE_DIM>(
259 side_fe_ptr->getOpPtrVector().push_back(
260 new OpCalculateHTensorTensorField<3, 3>(
262 side_fe_ptr->getOpPtrVector().push_back(
264 side_fe_ptr->getOpPtrVector().push_back(new OpCalculateVectorFieldValues<3>(
266 for (auto &[name, ents, reaction_vec] : reactionForces) {
269 }
270
272 *face_fe);
273
274 for (auto &[name, ents, reaction_vec] : reactionForces) {
275 std::array<double, 6> block_reaction_force{0.0, 0.0, 0.0, 0.0, 0.0, 0.0};
276
277 MPI_Allreduce(reaction_vec.data(), &block_reaction_force, 6, MPI_DOUBLE,
279
280 for (auto &force : block_reaction_force) {
281 if (std::abs(force) < 1e-12) {
282 force = 0.0;
283 }
284 }
286 "EP", Sev::inform,
287 "Step %d time %3.4g Block %s Reaction force [%3.6e, %3.6e, %3.6e]",
288 ts_step, ts_t, name.c_str(), block_reaction_force[0],
289 block_reaction_force[1], block_reaction_force[2]);
291 "Step %d time %3.4g Block %s Moment [%3.6e, %3.6e, %3.6e]",
292 ts_step, ts_t, name.c_str(), block_reaction_force[3],
293 block_reaction_force[4], block_reaction_force[5]);
294 }
295
296 auto get_step = [](auto ts_step) {
297 std::ostringstream ss;
298 ss << boost::str(boost::format("%d") % static_cast<int>(ts_step));
299 std::string s = ss.str();
300 return s;
301 };
302
304 PetscViewer viewer;
305 CHKERR PetscViewerBinaryOpen(
306 PETSC_COMM_WORLD, ("restart_" + get_step(ts_step) + ".dat").c_str(),
307 FILE_MODE_WRITE, &viewer);
308 CHKERR VecView(ts_u, viewer);
309 CHKERR PetscViewerDestroy(&viewer);
310 }
311
313 ".h5m");
314
315
316
317
318 auto get_material_force_tags = [&]() {
320 std::vector<Tag> tag(2);
322 "can't get tag");
324 "can't get tag");
325 return tag;
326 };
328
329
330 bool post_process_skeleton = true;
331#ifndef NDEBUG
332 post_process_skeleton = true;
333#endif
334 if (post_process_skeleton) {
336 1, "out_skeleton_" + get_step(ts_step) + ".h5m", PETSC_NULLPTR,
337 get_material_force_tags());
338 }
339
340
346
347 double body_energy = 0;
348 MPI_Allreduce(
gEnergy.get(), &body_energy, 1, MPI_DOUBLE, MPI_SUM,
351 auto crack_area_ptr = boost::make_shared<double>(0.0);
354 "Step %d time %3.4g strain energy %3.6e crack "
355 "area %3.6e",
356 ts_step, ts_t, body_energy, *crack_area_ptr);
359 if (crack_faces.empty()) {
361 }
364 (boost::format("crack_faces_step_%d.vtk") % ts_step).str(),
365 crack_faces);
368 (boost::format("front_edges_step_%d.vtk") % ts_step).str(),
370 }
371
372 } else {
373 MOFEM_LOG_C(
"EP", Sev::inform,
"Step %d time %3.4g strain energy %3.6e",
374 ts_step, ts_t, body_energy);
375 }
376
377 auto post_proc_at_points = [&](std::array<double, 3> point,
378 std::string str) {
380
381 dataFieldEval->setEvalPoints(point.data(), point.size() / 3);
382
383 struct OpPrint :
public VolOp {
384
386 std::array<double, 3> point;
387 std::string str;
388
390 std::string &str)
391 :
VolOp(ep.spatialL2Disp,
VolOp::OPROW), eP(ep), point(point),
392 str(str) {}
393
395 EntitiesFieldData::EntData &data) {
397 if (type == MBTET) {
398 if (getGaussPts().size2()) {
399
400 auto t_h = getFTensor2FromMat<3, 3>(eP.
dataAtPts->hAtPts);
401 auto t_approx_P =
402 getFTensor2FromMat<3, 3>(eP.
dataAtPts->approxPAtPts);
403
409 t_cauchy(
i,
j) = (1. / jac) * (t_approx_P(
i,
k) * t_h(
j,
k));
410
411 auto add = [&]() {
412 std::ostringstream s;
413 s << str << " elem " << getFEEntityHandle() << " ";
414 return s.str();
415 };
416
417 auto print_tensor = [](
auto &
t) {
418 std::ostringstream s;
420 return s.str();
421 };
422
423 std::ostringstream print;
429 << add() << "coords at gauss pts " << getCoordsAtGaussPts();
431 << add() <<
"w " << eP.
dataAtPts->wL2AtPts;
433 << add() <<
"Piola " << eP.
dataAtPts->approxPAtPts;
435 << add() << "Cauchy " << print_tensor(t_cauchy);
436 }
437 }
439 }
440 };
441
443
444 fe_ptr->getOpPtrVector().push_back(
new OpPrint(
eP, point, str));
446 ->evalFEAtThePoint<SPACE_DIM>(
447 point.data(), 1e-12, problemPtr->getName(),
"EP",
dataFieldEval,
450 fe_ptr->getOpPtrVector().pop_back();
451 }
452
454 };
455
456 auto check_external_strain = [&](std::array<double, 3> point,
459
460 dataFieldEval->setEvalPoints(point.data(), point.size() / 3);
463
466 ->evalFEAtThePoint<SPACE_DIM>(
467 point.data(), 1e-12, problemPtr->getName(),
"EP",
dataFieldEval,
470 }
472 VecSetValue(vec, 0, 0.0, ADD_VALUES);
474 auto add = [&]() {
475 std::ostringstream s;
476 s << str << " elem " << getFEEntityHandle() << " ";
477 return s.str();
478 };
486 VecSetValue(vec, 0, disp_at_point, ADD_VALUES);
487 }
488
490 if (ts_t > 0.0) {
491 CHKERR VecAssemblyBegin(vec);
492 CHKERR VecAssemblyEnd(vec);
493 double error;
494 PetscInt idx = 0;
496 CHKERR VecGetValues(vec, 1, &idx, &error);
497 }
498 MPI_Bcast(&error, 1, MPI_DOUBLE, 0, PETSC_COMM_WORLD);
499
500
501
502 if (std::abs(error - 0.25) > 1e-5) {
504 "Atom test %d failed: wrong displacement.",
atom_test);
505 }
506 }
508 };
509
512 PETSC_NULLPTR);
513
515
518 }
519 } else {
520
522 CHKERR post_proc_at_points(pts.second, pts.first);
524 }
525 }
526
528 }
529
531 }
#define MOFEM_LOG_SEVERITY_SYNC(comm, severity)
Synchronise "SYNC" on curtain severity level.
#define MOFEM_LOG_C(channel, severity, format,...)
@ MOFEM_ATOM_TEST_INVALID
virtual MoFEMErrorCode loop_finite_elements(const std::string problem_name, const std::string &fe_name, FEMethod &method, boost::shared_ptr< NumeredEntFiniteElement_multiIndex > fe_ptr=nullptr, MoFEMTypes bh=MF_EXIST, CacheTupleWeakPtr cache_ptr=CacheTupleSharedPtr(), int verb=DEFAULT_VERBOSITY)=0
Make a loop over finite elements.
FTensor::Index< 'i', SPACE_DIM > i
FTensor::Index< 'j', 3 > j
FTensor::Index< 'k', 3 > k
PetscErrorCode MoFEMErrorCode
MoFEM/PETSc error code.
auto getVectorAdaptor(T1 ptr, const size_t n)
Get Vector adaptor.
auto createVectorMPI(MPI_Comm comm, PetscInt n, PetscInt N)
Create MPI Vector.
MoFEMErrorCode determinantTensor3by3(T1 &t, T2 &det)
Calculate determinant 3 by 3.
constexpr double t
plate stiffness
static constexpr int approx_order
static PetscBool crackingOn
MoFEMErrorCode calculateFaceMaterialForce(const int tag, TS ts)
MoFEMErrorCode calculateCrackArea(boost::shared_ptr< double > area_ptr)
MoFEMErrorCode postProcessSkeletonResults(const int tag, const std::string file, Vec f_residual=PETSC_NULLPTR, std::vector< Tag > tags_to_transfer={})
const std::string skinElement
MoFEMErrorCode postProcessResults(const int tag, const std::string file, Vec f_residual=PETSC_NULLPTR, Vec var_vec=PETSC_NULLPTR, std::vector< Tag > tags_to_transfer={})
boost::shared_ptr< Range > crackFaces
boost::shared_ptr< Range > frontEdges
virtual moab::Interface & get_moab()=0
virtual MPI_Comm & get_comm() const =0
virtual int get_comm_rank() const =0