9 using VolEle = VolumeElementForcesAndSourcesCore;
10 using VolOp = VolumeElementForcesAndSourcesCore::UserDataOperator;
12 using PtsHashMap = std::map<std::string, std::array<double, 3>>;
14 PipelineManager::ElementsAndOpsByDim<SPACE_DIM>::FaceSideEle;
23 "build field evaluator tree");
29 "set element for post energy");
33 "get write restart option");
35 "-write_restart_every",
37 "get write restart option");
40 "-write_restart_every must be positive");
42 MOFEM_LOG(
"EP", Sev::inform) <<
"EshelbianMonitor writeRestart "
45 MOFEM_LOG(
"EP", Sev::inform) <<
"EshelbianMonitor writeRestartEvery "
60 MOFEM_LOG(
"EP", Sev::inform) <<
"Monitor postProcess";
86 MoFEMErrorCode
postProcAtPoints(std::array<double, 3> point, std::string str);
126 std::ostringstream ss;
127 ss << boost::str(boost::format(
"%d") %
static_cast<int>(ts_step));
135 auto get_ents_on_mesh_skin = [&]() {
136 std::map<std::string, Range> boundary_entities_vec;
138 auto get_block_vec_impl = [&](
auto block_name) {
142 (boost::format(
"%s(.*)") % block_name).str()
147 auto add_blockset_ents_impl = [&](
auto &&vec) {
149 for (
auto it : vec) {
150 Range boundary_entities;
152 boundary_entities,
true);
153 std::string meshset_name = it->getName();
154 boundary_entities_vec[meshset_name] = boundary_entities;
155 boundary_entities.clear();
160 for (
auto block_name :
161 {
"SPATIAL_DISP",
"FIX",
"CONTACT",
"SPATIAL_ROTATION",
162 "NORMAL_DISPLACEMENT",
"ANALYTICAL_DISPLACEMENT",
"SPRING_BC"}) {
164 "add blockset entities");
167 return boundary_entities_vec;
170 auto boundary_entities_vec = get_ents_on_mesh_skin();
172 std::vector<std::tuple<std::string, Range, std::array<double, 6>>>
174 for (
const auto &pair : boundary_entities_vec) {
175 reactionForces.push_back(
176 std::make_tuple(pair.first, pair.second,
177 std::array<double, 6>{0.0, 0.0, 0.0, 0.0, 0.0, 0.0}));
180 auto integration_rule_face = [](int, int,
int approx_order) {
183 auto face_fe = boost::make_shared<FaceElementForcesAndSourcesCore>(
eP.
mField);
184 face_fe->getRuleHook = integration_rule_face;
186 EshelbianPlasticity::AddHOOps<SPACE_DIM - 1, SPACE_DIM, SPACE_DIM>::add(
192 face_fe->getOpPtrVector().push_back(op_side);
193 auto side_fe_ptr = op_side->getSideFEPtr();
195 boost::make_shared<EshelbianPlasticity::CGGUserPolynomialBase>();
196 side_fe_ptr->getUserPolynomialBase() = base_ptr;
198 EshelbianPlasticity::AddHOOps<SPACE_DIM, SPACE_DIM, SPACE_DIM>::add(
201 auto piola_scale_ptr = boost::make_shared<double>(1.0);
202 side_fe_ptr->getOpPtrVector().push_back(
203 new OpCalculateHVecTensorField<SPACE_DIM, SPACE_DIM>(
205 constexpr bool add_bubble_field =
false;
206 if (add_bubble_field) {
207 side_fe_ptr->getOpPtrVector().push_back(
208 new OpCalculateHTensorTensorField<3, 3>(
211 side_fe_ptr->getOpPtrVector().push_back(
213 side_fe_ptr->getOpPtrVector().push_back(
new OpCalculateVectorFieldValues<3>(
215 for (
auto &[
name, ents, reaction_vec] : reactionForces) {
216 face_fe->getOpPtrVector().push_back(
223 for (
auto &[
name, ents, reaction_vec] : reactionForces) {
224 std::array<double, 6> block_reaction_force{0.0, 0.0, 0.0, 0.0, 0.0, 0.0};
226 MPI_Allreduce(reaction_vec.data(), &block_reaction_force, 6, MPI_DOUBLE,
229 for (
auto &force : block_reaction_force) {
230 if (std::abs(force) < 1e-12) {
237 "Step %d time %3.4g Block %s Reaction force [%3.6e, "
239 ts_step, ts_t,
name.c_str(), block_reaction_force[0],
240 block_reaction_force[1], block_reaction_force[2]);
242 "Step %d time %3.4g Block %s Moment [%3.6e, %3.6e, %3.6e]",
243 ts_step, ts_t,
name.c_str(), block_reaction_force[3],
244 block_reaction_force[4], block_reaction_force[5]);
254 const bool has_ts = (ts != PETSC_NULLPTR);
264 double body_energy = 0;
265 MPI_Allreduce(
gEnergy.get(), &body_energy, 1, MPI_DOUBLE, MPI_SUM,
273 "Step %d time %3.4g strain energy %3.12e crack "
278 if (crack_faces.empty()) {
283 (boost::format(
"crack_faces_step_%d.vtk") % ts_step).str(),
287 (boost::format(
"front_edges_step_%d.vtk") % ts_step).str(),
292 MOFEM_LOG_C(
"EP", Sev::inform,
"Step %d time %3.4g strain energy %3.6e",
293 ts_step, ts_t, body_energy);
304 CHKERR PetscViewerBinaryOpen(PETSC_COMM_WORLD,
306 FILE_MODE_WRITE, &viewer);
307 CHKERR PetscViewerBinarySetSkipInfo(viewer, PETSC_TRUE);
308 CHKERR VecView(ts_u, viewer);
309 CHKERR PetscViewerDestroy(&viewer);
320 PETSC_NULLPTR, PETSC_NULLPTR,
330 MPI_Allreduce(MPI_IN_PLACE, &nb_front_faces, 1, MPI_INT, MPI_SUM,
332 if (nb_front_faces > 0) {
341 auto get_material_force_tags = [&]() {
343 std::vector<Tag> tags;
344 for (
const auto *
name : {
"MaterialForce",
"FacePressure"}) {
346 const auto rval = moab.tag_get_handle(
name, tag);
347 if (rval == MB_SUCCESS)
349 else if (rval != MB_TAG_NOT_FOUND)
355 bool post_process_skeleton =
false;
357 post_process_skeleton =
true;
359 if (post_process_skeleton) {
361 1,
"out_skeleton_" +
getStep() +
".h5m", PETSC_NULLPTR,
362 get_material_force_tags(), ts);
369 std::ifstream file(
"points.txt");
371 if (!file.is_open()) {
377 while (std::getline(file, line)) {
378 std::istringstream iss(line);
380 double col2, col3, col4;
382 if (iss >> col1 >> col2 >> col3 >> col4) {
384 <<
"Read: " << col1 <<
", " << col2 <<
", " << col3 <<
", " << col4;
387 MOFEM_LOG(
"EP", Sev::error) <<
"Error parsing line: " << line;
398 std::array<double, SPACE_DIM> field_eval_coords{};
401 CHKERR PetscOptionsGetRealArray(
402 PETSC_NULLPTR, PETSC_NULLPTR,
"-field_eval_coords",
407 "-field_eval_coords requires exactly three coordinates");
410 ptsHashMap[
"field_eval_coords"] = field_eval_coords;
412 "FieldEvaluator added command-line point [%6.4e, %6.4e, "
414 field_eval_coords[0], field_eval_coords[1],
415 field_eval_coords[2]);
418 PetscBool test_cook_pts = PETSC_FALSE;
419 CHKERR PetscOptionsGetBool(PETSC_NULLPTR,
"",
"-test_cook_pts",
420 &test_cook_pts, PETSC_NULLPTR);
423 ptsHashMap[
"Point B"] = {48. / 2., 44. + (60. - 44.) / 2., 0.};
424 ptsHashMap[
"Point C"] = {48. / 2., (44. - 0.) / 2., 0.};
433 auto no_rule = [](int, int, int) {
return -1; };
434 vol_ele->getRuleHook = no_rule;
435 vol_ele->getUserPolynomialBase() =
436 boost::make_shared<CGGUserPolynomialBase>();
437 EshelbianPlasticity::AddHOOps<SPACE_DIM, SPACE_DIM, SPACE_DIM>::add(
441 auto piola_scale_ptr = boost::make_shared<double>(1.0);
442 vol_ele->getOpPtrVector().push_back(
new OpCalculateHVecTensorField<3, 3>(
444 vol_ele->getOpPtrVector().push_back(
new OpCalculateHTensorTensorField<3, 3>(
446 SmartPetscObj<Vec>(), MBMAXTYPE));
447 vol_ele->getOpPtrVector().push_back(
new OpCalculateL2RotationValues(
451 vol_ele->getOpPtrVector().push_back(
new OpCalculateHVecTensorField<3, 3>(
455 eP, vol_ele->getOpPtrVector(),
eP.
dataAtPts, PhysicalEquations::PREVIOUS);
458 vol_ele->getOpPtrVector().push_back(
new OpCalculateL2RotationValues(
459 eP.
rotAxis, boost::make_shared<MatrixDouble>(),
462 vol_ele->getOpPtrVector().push_back(
new OpCalculateVectorFieldValues<3>(
466 vol_ele->getOpPtrVector().push_back(
new OpCalculateVectorFieldValues<3>(
468 vol_ele->getOpPtrVector().push_back(
new OpCalculateVectorFieldGradient<3, 3>(
471 CHKERR addCalculatePlasticLogarithmicStretchFieldValues(
474 vol_ele->getOpPtrVector().push_back(
495 dataFieldEval->setEvalPoints(point.data(), point.size() / 3);
496 auto point_found_ptr = boost::make_shared<int>(0);
498 struct OpPrint :
public VolOp {
501 std::array<double, 3> point;
503 boost::shared_ptr<int> pointFoundPtr;
507 OpPrint(
EshelbianCore &
ep, std::array<double, 3> &point, std::string &str,
508 boost::shared_ptr<int> point_found_ptr, PetscInt step,
double time)
510 str(str), pointFoundPtr(point_found_ptr), step(step), time(time) {}
512 MoFEMErrorCode doWork(
int side, EntityType
type,
513 EntitiesFieldData::EntData &
data) {
516 const int nb_gauss_pts = getGaussPts().size2();
520 auto t_h = eP.
dataAtPts->getFTensorSmallH(nb_gauss_pts);
521 auto t_approx_P = eP.
dataAtPts->getFTensorApproxP(nb_gauss_pts);
523 getFTensor1FromMat<SPACE_DIM>(*eP.
dataAtPts->getSmallWL2AtPts());
528 const double jac = determinantTensor3by3(t_h);
530 t_cauchy(
i,
j) = (1. / jac) * (t_approx_P(
i,
k) * t_h(
j,
k));
533 std::ostringstream s;
534 s << str <<
" elem " << getFEEntityHandle() <<
" ";
538 auto print_tensor = [](
auto &
t) {
539 std::ostringstream s;
544 std::ostringstream print;
548 << add() <<
"point " << getVectorAdaptor(point.data(), 3);
550 << add() <<
"coords at gauss pts " << getCoordsAtGaussPts();
552 << add() <<
"w " << *(eP.
dataAtPts->getSmallWL2AtPts());
554 << add() <<
"Piola " << *(eP.
dataAtPts->getApproxPAtPts());
556 << add() <<
"Cauchy " << print_tensor(t_cauchy);
558 "EPSYNC", Sev::inform,
559 "FieldEvaluator step %d time %6.4e label \"%s\" point [%6.4e, "
561 step, time, str.c_str(), point[0], point[1], point[2]);
563 "FieldEvaluator displacement [Ux, Uy, Uz] = [%6.4e, "
565 t_disp(0), t_disp(1), t_disp(2));
567 "EPSYNC", Sev::inform,
568 "FieldEvaluator Cauchy stress [Sxx, Syy, Szz, Sxy, Syz, Sxz] "
569 "= [%6.4e, %6.4e, %6.4e, %6.4e, %6.4e, %6.4e]",
570 t_cauchy(0, 0), t_cauchy(1, 1), t_cauchy(2, 2),
571 t_cauchy(0, 1), t_cauchy(1, 2), t_cauchy(0, 2));
579 fe_ptr->data_ctx |= PetscData::CtxSetTime;
589 fe_ptr->getOpPtrVector().push_back(
590 new OpPrint(
eP, point, str, point_found_ptr, ts_step, time));
592 ->evalFEAtThePoint<SPACE_DIM>(
593 point.data(), 1e-12, problemPtr->getName(),
"EP",
dataFieldEval,
596 fe_ptr->getOpPtrVector().pop_back();
599 int global_point_found = 0;
600 MPI_Allreduce(point_found_ptr.get(), &global_point_found, 1, MPI_INT, MPI_SUM,
604 "FieldEvaluator did not find point [%6.4e, %6.4e, %6.4e] in "
606 point[0], point[1], point[2]);
#define MOFEM_LOG_SEVERITY_SYNC(comm, severity)
Synchronise "SYNC" on curtain severity level.
#define MOFEM_LOG_C(channel, severity, format,...)
boost::shared_ptr< DataAtIntegrationPts > data
#define CHK_THROW_MESSAGE(err, msg)
Check and throw MoFEM exception.
#define MoFEMFunctionReturnHot(a)
Last executable line of each PETSc function used for error handling. Replaces return()
#define MoFEMFunctionBegin
First executable line of each MoFEM function, used for error handling. Final line of MoFEM functions ...
#define CHK_MOAB_THROW(err, msg)
Check error code of MoAB function and throw MoFEM exception.
@ MOFEM_DATA_INCONSISTENCY
#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.
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
constexpr double t
plate stiffness
static constexpr int approx_order
boost::shared_ptr< Range > frontAdjEdges
MoFEM::Interface & mField
const std::string spatialL2Disp
MoFEMErrorCode postProcessSkeletonResults(const int tag, const std::string file, Vec f_residual=PETSC_NULLPTR, std::vector< Tag > tags_to_transfer={}, TS ts=PETSC_NULLPTR)
const std::string materialH1Positions
static PetscBool crackingOn
MoFEMErrorCode postProcessRestartMesh(const int tag, const std::string file, std::vector< Tag > tags_to_transfer={})
MoFEMErrorCode postProcessResults(const int tag, const std::string file, Vec f_residual=PETSC_NULLPTR, Vec var_vec=PETSC_NULLPTR, Vec gradient=PETSC_NULLPTR, std::vector< Tag > tags_to_transfer={}, TS ts=PETSC_NULLPTR)
const std::string spatialH1Disp
MoFEMErrorCode calculateCrackArea(boost::shared_ptr< double > &area_ptr)
const std::string plasticHField
const std::string piolaStress
static PetscBool physicalTimeFlg
const std::string bubbleField
static double currentPhysicalTime
boost::shared_ptr< PhysicalEquations > physicalEquations
const std::string rotAxis
const std::string skinElement
MoFEMErrorCode setBaseVolumeElementOps(const int tag, const bool do_rhs, const bool do_lhs, const bool calc_rates, boost::shared_ptr< VolumeElementForcesAndSourcesCore > fe, const bool add_bubble=true)
boost::shared_ptr< double > currentCrackAreaPtr
MoFEMErrorCode calculateFaceMaterialForce(const int tag, TS ts, SmartPetscObj< Vec > *adjoint_gradient_vector=nullptr)
boost::shared_ptr< DataAtIntegrationPts > dataAtPts
boost::shared_ptr< Range > crackFaces
SmartPetscObj< Vec > solTSStep
boost::shared_ptr< Range > frontEdges
MoFEMErrorCode setElementForPostProcessEnergy()
PetscInt writeRestartEvery
boost::shared_ptr< double > gEnergy
MoFEMErrorCode preProcess()
boost::shared_ptr< double > & getEnergy()
MoFEMErrorCode postProcessMaterialForces()
boost::shared_ptr< VolEle > volPostProcEnergy
MoFEMErrorCode setElementForFieldEval()
PipelineManager::ElementsAndOpsByDim< SPACE_DIM >::FaceSideEle FaceSideEle
virtual ~EshelbianMonitor()
MoFEMErrorCode operator()()
std::map< std::string, std::array< double, 6 > > & getReactionMap()
EshelbianCore & getEpCore()
std::map< std::string, std::array< double, 6 > > reactionForcesMap
boost::shared_ptr< SetPtsData > dataFieldEval
EshelbianMonitor(EshelbianCore &ep)
MoFEMErrorCode saveRestartFile()
static SmartPetscObj< Vec > adjointGradientVector
MoFEMErrorCode postProcessPoints()
MoFEMErrorCode postProcessSkin()
boost::shared_ptr< SetPtsData > & getDataField()
MoFEMErrorCode calculateReactionForces()
MoFEMErrorCode readPtsFromOptions()
std::map< std::string, std::array< double, 3 > > PtsHashMap
VolumeElementForcesAndSourcesCore VolEle
MoFEMErrorCode postProcAtPoints(std::array< double, 3 > point, std::string str)
VolumeElementForcesAndSourcesCore::UserDataOperator VolOp
MoFEMErrorCode postProcessSkeletonResults()
MoFEMErrorCode postProcess()
MoFEMErrorCode calculateEnergy()
FieldEvaluatorInterface::SetPtsData SetPtsData
MoFEMErrorCode readPtsFromFile()
PtsHashMap & getHashMap()
virtual moab::Interface & get_moab()=0
virtual MPI_Comm & get_comm() const =0
virtual int get_comm_rank() const =0
@ OPROW
operator doWork function is executed on FE rows
MoFEMErrorCode getInterface(IFACE *&iface) const
Get interface reference to pointer of interface.
VolEle::UserDataOperator VolOp
PetscBool do_eval_field
Evaluate field.