179 {
181
182 MOFEM_LOG(
"EP", Sev::inform) <<
"Monitor postProcess";
183
184 auto get_step = [](auto ts_step) {
185 std::ostringstream ss;
186 ss << boost::str(boost::format("%d") % static_cast<int>(ts_step));
187 std::string s = ss.str();
188 return s;
189 };
190
191 auto calculate_reaction_forces = [&]() {
193
194
195 auto get_ents_on_mesh_skin = [&]() {
196 std::map<std::string, Range> boundary_entities_vec;
197
198 auto get_block_vec_impl = [&](auto block_name) {
200 std::regex(
201
202 (boost::format("%s(.*)") % block_name).str()
203
204 ));
205 };
206
207 auto add_blockset_ents_impl = [&](auto &&vec) {
209 for (auto it : vec) {
210 Range boundary_entities;
212 boundary_entities, true);
213 std::string meshset_name = it->getName();
214 boundary_entities_vec[meshset_name] = boundary_entities;
215 boundary_entities.clear();
216 }
218 };
219
220 for (auto block_name : {"SPATIAL_DISP", "FIX", "CONTACT",
221 "SPATIAL_ROTATION", "NORMAL_DISPLACEMENT"}) {
223 add_blockset_ents_impl(get_block_vec_impl(block_name)),
224 "add blockset entities");
225 }
226
227 return boundary_entities_vec;
228 };
229
230 auto boundary_entities_vec = get_ents_on_mesh_skin();
231
232 std::vector<std::tuple<std::string, Range, std::array<double, 6>>>
233 reactionForces;
234 for (const auto &pair : boundary_entities_vec) {
235 reactionForces.push_back(std::make_tuple(
236 pair.first, pair.second,
237 std::array<double, 6>{0.0, 0.0, 0.0, 0.0, 0.0, 0.0}));
238 }
239
242 };
243 auto face_fe =
244 boost::make_shared<FaceElementForcesAndSourcesCore>(
eP.
mField);
245 auto no_rule = [](
int,
int,
int) {
return -1; };
246 face_fe->getRuleHook = integration_rule_face;
248 EshelbianPlasticity::AddHOOps<SPACE_DIM - 1, SPACE_DIM, SPACE_DIM>::add(
251
252 auto op_side =
254 face_fe->getOpPtrVector().push_back(op_side);
255 auto side_fe_ptr = op_side->getSideFEPtr();
256 auto base_ptr =
257 boost::make_shared<EshelbianPlasticity::CGGUserPolynomialBase>();
258 side_fe_ptr->getUserPolynomialBase() = base_ptr;
260 EshelbianPlasticity::AddHOOps<SPACE_DIM, SPACE_DIM, SPACE_DIM>::add(
263 auto piola_scale_ptr = boost::make_shared<double>(1.0);
264 side_fe_ptr->getOpPtrVector().push_back(
267 side_fe_ptr->getOpPtrVector().push_back(
268 new OpCalculateHVecTensorField<SPACE_DIM, SPACE_DIM>(
270 piola_scale_ptr));
271 side_fe_ptr->getOpPtrVector().push_back(
272 new OpCalculateHTensorTensorField<3, 3>(
274 side_fe_ptr->getOpPtrVector().push_back(
276 side_fe_ptr->getOpPtrVector().push_back(
277 new OpCalculateVectorFieldValues<3>(
279 for (auto &[name, ents, reaction_vec] : reactionForces) {
282 }
283
286
287 for (auto &[name, ents, reaction_vec] : reactionForces) {
288 std::array<double, 6> block_reaction_force{0.0, 0.0, 0.0,
289 0.0, 0.0, 0.0};
290
291 MPI_Allreduce(reaction_vec.data(), &block_reaction_force, 6, MPI_DOUBLE,
293
294 for (auto &force : block_reaction_force) {
295 if (std::abs(force) < 1e-12) {
296 force = 0.0;
297 }
298 }
300 "Step %d time %3.4g Block %s Reaction force [%3.6e, "
301 "%3.6e, %3.6e]",
302 ts_step, ts_t, name.c_str(), block_reaction_force[0],
303 block_reaction_force[1], block_reaction_force[2]);
305 "Step %d time %3.4g Block %s Moment [%3.6e, %3.6e, %3.6e]",
306 ts_step, ts_t, name.c_str(), block_reaction_force[3],
307 block_reaction_force[4], block_reaction_force[5]);
308 }
310 };
311
312 auto save_restart_file = [&]() {
314
316 PetscViewer viewer;
317 CHKERR PetscViewerBinaryOpen(
318 PETSC_COMM_WORLD, ("restart_" + get_step(ts_step) + ".dat").c_str(),
319 FILE_MODE_WRITE, &viewer);
320 CHKERR PetscViewerBinarySetSkipInfo(viewer, PETSC_TRUE);
321 CHKERR VecView(ts_u, viewer);
322 CHKERR PetscViewerDestroy(&viewer);
323 }
325 };
326
327 auto post_process_skin = [&]() {
330 ".h5m");
332 };
333
334 auto post_process_material_forces = [&]() {
336
339 };
340
341 auto post_process_skeleton_results = [&]() {
343 auto get_material_force_tags = [&]() {
345 std::vector<Tag> tag(2);
347 "can't get tag");
349 "can't get tag");
350 return tag;
351 };
352
353 bool post_process_skeleton = true;
354#ifndef NDEBUG
355 post_process_skeleton = true;
356#endif
357 if (post_process_skeleton) {
359 1, "out_skeleton_" + get_step(ts_step) + ".h5m", PETSC_NULLPTR,
360 get_material_force_tags());
361 }
363 };
364
365 auto calculate_energy = [&]() {
367
373
374 double body_energy = 0;
375 MPI_Allreduce(
gEnergy.get(), &body_energy, 1, MPI_DOUBLE, MPI_SUM,
378 auto crack_area_ptr = boost::make_shared<double>(0.0);
381 "Step %d time %3.4g strain energy %3.6e crack "
382 "area %3.6e",
383 ts_step, ts_t, body_energy, *crack_area_ptr);
386 if (crack_faces.empty()) {
388 }
391 (boost::format("crack_faces_step_%d.vtk") % ts_step).str(),
392 crack_faces);
395 (boost::format("front_edges_step_%d.vtk") % ts_step).str(),
397 }
398
399 } else {
400 MOFEM_LOG_C(
"EP", Sev::inform,
"Step %d time %3.4g strain energy %3.6e",
401 ts_step, ts_t, body_energy);
402 }
404 };
405
406 auto post_proc_at_points = [&](std::array<double, 3> point,
407 std::string str) {
409
410 dataFieldEval->setEvalPoints(point.data(), point.size() / 3);
411
412 struct OpPrint :
public VolOp {
413
415 std::array<double, 3> point;
416 std::string str;
417
419 std::string &str)
420 :
VolOp(ep.spatialL2Disp,
VolOp::OPROW), eP(ep), point(point),
421 str(str) {}
422
424 EntitiesFieldData::EntData &data) {
426 if (type == MBTET) {
427 if (getGaussPts().size2()) {
428
429 auto t_h = getFTensor2FromMat<3, 3>(eP.
dataAtPts->hAtPts);
430 auto t_approx_P =
431 getFTensor2FromMat<3, 3>(eP.
dataAtPts->approxPAtPts);
432
438 t_cauchy(
i,
j) = (1. / jac) * (t_approx_P(
i,
k) * t_h(
j,
k));
439
440 auto add = [&]() {
441 std::ostringstream s;
442 s << str << " elem " << getFEEntityHandle() << " ";
443 return s.str();
444 };
445
446 auto print_tensor = [](
auto &
t) {
447 std::ostringstream s;
449 return s.str();
450 };
451
452 std::ostringstream print;
458 << add() << "coords at gauss pts " << getCoordsAtGaussPts();
460 << add() <<
"w " << eP.
dataAtPts->wL2AtPts;
462 << add() <<
"Piola " << eP.
dataAtPts->approxPAtPts;
464 << add() << "Cauchy " << print_tensor(t_cauchy);
465 }
466 }
468 }
469 };
470
472
473 fe_ptr->getOpPtrVector().push_back(
new OpPrint(
eP, point, str));
475 ->evalFEAtThePoint<SPACE_DIM>(
476 point.data(), 1e-12, problemPtr->getName(),
"EP",
dataFieldEval,
479 fe_ptr->getOpPtrVector().pop_back();
480 }
481
483 };
484
485 auto check_external_strain = [&](std::array<double, 3> point,
488
489 dataFieldEval->setEvalPoints(point.data(), point.size() / 3);
492
495 ->evalFEAtThePoint<SPACE_DIM>(
496 point.data(), 1e-12, problemPtr->getName(),
"EP",
dataFieldEval,
499 }
501 VecSetValue(vec, 0, 0.0, ADD_VALUES);
503 auto add = [&]() {
504 std::ostringstream s;
505 s << str << " elem " << getFEEntityHandle() << " ";
506 return s.str();
507 };
515 VecSetValue(vec, 0, disp_at_point, ADD_VALUES);
516 }
517
519 if (ts_t > 0.0) {
520 CHKERR VecAssemblyBegin(vec);
521 CHKERR VecAssemblyEnd(vec);
522 double error;
523 PetscInt idx = 0;
525 CHKERR VecGetValues(vec, 1, &idx, &error);
526 }
527 MPI_Bcast(&error, 1, MPI_DOUBLE, 0, PETSC_COMM_WORLD);
528
529
530
531 if (std::abs(error - 0.25) > 1e-5) {
533 "Atom test %d failed: wrong displacement.",
atom_test);
534 }
535 }
537 };
538
539 CHKERR save_restart_file();
540 CHKERR calculate_reaction_forces();
541 CHKERR calculate_energy();
542
543 CHKERR post_process_material_forces();
544 CHKERR post_process_skin();
545 CHKERR post_process_skeleton_results();
546
549 PETSC_NULLPTR);
550
552
555 }
556 } else {
557
559 CHKERR post_proc_at_points(pts.second, pts.first);
561 }
562 }
563
565 }
#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