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;
17 :
eP(ep),
dataFieldEval(ep.mField.getInterface<FieldEvaluatorInterface>()
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");
39 MOFEM_LOG(
"EP", Sev::inform) <<
"EshelbianMonitor writeRestart "
42 MOFEM_LOG(
"EP", Sev::inform) <<
"EshelbianMonitor writeRestartEvery "
57 MOFEM_LOG(
"EP", Sev::inform) <<
"Monitor postProcess";
83 MoFEMErrorCode
postProcAtPoints(std::array<double, 3> point, std::string str);
128 pushOpCalculateStretchFromStress(
141 std::ostringstream ss;
142 ss << boost::str(boost::format(
"%d") %
static_cast<int>(ts_step));
150 auto get_ents_on_mesh_skin = [&]() {
151 std::map<std::string, Range> boundary_entities_vec;
153 auto get_block_vec_impl = [&](
auto block_name) {
157 (boost::format(
"%s(.*)") % block_name).str()
162 auto add_blockset_ents_impl = [&](
auto &&vec) {
164 for (
auto it : vec) {
165 Range boundary_entities;
167 boundary_entities,
true);
168 std::string meshset_name = it->getName();
169 boundary_entities_vec[meshset_name] = boundary_entities;
170 boundary_entities.clear();
175 for (
auto block_name :
176 {
"SPATIAL_DISP",
"FIX",
"CONTACT",
"SPATIAL_ROTATION",
177 "NORMAL_DISPLACEMENT",
"ANALYTICAL_DISPLACEMENT",
"SPRING_BC"}) {
179 "add blockset entities");
182 return boundary_entities_vec;
185 auto boundary_entities_vec = get_ents_on_mesh_skin();
187 std::vector<std::tuple<std::string, Range, std::array<double, 6>>>
189 for (
const auto &pair : boundary_entities_vec) {
190 reactionForces.push_back(
191 std::make_tuple(pair.first, pair.second,
192 std::array<double, 6>{0.0, 0.0, 0.0, 0.0, 0.0, 0.0}));
195 auto integration_rule_face = [](int, int,
int approx_order) {
198 auto face_fe = boost::make_shared<FaceElementForcesAndSourcesCore>(
eP.
mField);
199 auto no_rule = [](int, int, int) {
return -1; };
200 face_fe->getRuleHook = integration_rule_face;
202 EshelbianPlasticity::AddHOOps<SPACE_DIM - 1, SPACE_DIM, SPACE_DIM>::add(
208 face_fe->getOpPtrVector().push_back(op_side);
209 auto side_fe_ptr = op_side->getSideFEPtr();
211 boost::make_shared<EshelbianPlasticity::CGGUserPolynomialBase>();
212 side_fe_ptr->getUserPolynomialBase() = base_ptr;
214 EshelbianPlasticity::AddHOOps<SPACE_DIM, SPACE_DIM, SPACE_DIM>::add(
217 auto piola_scale_ptr = boost::make_shared<double>(1.0);
218 side_fe_ptr->getOpPtrVector().push_back(
219 new OpCalculateHVecTensorField<SPACE_DIM, SPACE_DIM>(
221 constexpr bool add_bubble_field =
false;
222 if (add_bubble_field) {
223 side_fe_ptr->getOpPtrVector().push_back(
224 new OpCalculateHTensorTensorField<3, 3>(
227 side_fe_ptr->getOpPtrVector().push_back(
229 side_fe_ptr->getOpPtrVector().push_back(
new OpCalculateVectorFieldValues<3>(
231 for (
auto &[name, ents, reaction_vec] : reactionForces) {
232 face_fe->getOpPtrVector().push_back(
239 for (
auto &[name, ents, reaction_vec] : reactionForces) {
240 std::array<double, 6> block_reaction_force{0.0, 0.0, 0.0, 0.0, 0.0, 0.0};
242 MPI_Allreduce(reaction_vec.data(), &block_reaction_force, 6, MPI_DOUBLE,
245 for (
auto &force : block_reaction_force) {
246 if (std::abs(force) < 1e-12) {
253 "Step %d time %3.4g Block %s Reaction force [%3.6e, "
255 ts_step, ts_t, name.c_str(), block_reaction_force[0],
256 block_reaction_force[1], block_reaction_force[2]);
258 "Step %d time %3.4g Block %s Moment [%3.6e, %3.6e, %3.6e]",
259 ts_step, ts_t, name.c_str(), block_reaction_force[3],
260 block_reaction_force[4], block_reaction_force[5]);
270 const bool has_ts = (ts != PETSC_NULLPTR);
280 double body_energy = 0;
281 MPI_Allreduce(
gEnergy.get(), &body_energy, 1, MPI_DOUBLE, MPI_SUM,
289 "Step %d time %3.4g strain energy %3.12e crack "
294 if (crack_faces.empty()) {
299 (boost::format(
"crack_faces_step_%d.vtk") % ts_step).str(),
303 (boost::format(
"front_edges_step_%d.vtk") % ts_step).str(),
308 MOFEM_LOG_C(
"EP", Sev::inform,
"Step %d time %3.4g strain energy %3.6e",
309 ts_step, ts_t, body_energy);
319 CHKERR PetscViewerBinaryOpen(PETSC_COMM_WORLD,
320 (
"restart_" +
getStep() +
".dat").c_str(),
321 FILE_MODE_WRITE, &viewer);
322 CHKERR PetscViewerBinarySetSkipInfo(viewer, PETSC_TRUE);
323 CHKERR VecView(ts_u, viewer);
324 CHKERR PetscViewerDestroy(&viewer);
334 PETSC_NULLPTR, PETSC_NULLPTR,
344 MPI_Allreduce(MPI_IN_PLACE, &nb_front_faces, 1, MPI_INT, MPI_SUM,
346 if (nb_front_faces > 0) {
355 auto get_material_force_tags = [&]() {
357 std::vector<Tag> tag(2);
365 bool post_process_skeleton =
false;
367 post_process_skeleton =
true;
369 if (post_process_skeleton) {
371 1,
"out_skeleton_" +
getStep() +
".h5m", PETSC_NULLPTR,
372 get_material_force_tags(), ts);
379 std::ifstream file(
"points.txt");
381 if (!file.is_open()) {
387 while (std::getline(file, line)) {
388 std::istringstream iss(line);
390 double col2, col3, col4;
392 if (iss >> col1 >> col2 >> col3 >> col4) {
394 <<
"Read: " << col1 <<
", " << col2 <<
", " << col3 <<
", " << col4;
397 MOFEM_LOG(
"EP", Sev::error) <<
"Error parsing line: " << line;
408 std::array<double, SPACE_DIM> field_eval_coords{};
411 CHKERR PetscOptionsGetRealArray(
412 PETSC_NULLPTR, PETSC_NULLPTR,
"-field_eval_coords",
417 "-field_eval_coords requires exactly three coordinates");
420 ptsHashMap[
"field_eval_coords"] = field_eval_coords;
422 "FieldEvaluator added command-line point [%6.4e, %6.4e, "
424 field_eval_coords[0], field_eval_coords[1],
425 field_eval_coords[2]);
434 auto no_rule = [](int, int, int) {
return -1; };
435 vol_ele->getRuleHook = no_rule;
436 vol_ele->getUserPolynomialBase() =
437 boost::make_shared<CGGUserPolynomialBase>();
438 EshelbianPlasticity::AddHOOps<SPACE_DIM, SPACE_DIM, SPACE_DIM>::add(
442 auto piola_scale_ptr = boost::make_shared<double>(1.0);
443 vol_ele->getOpPtrVector().push_back(
new OpCalculateHVecTensorField<3, 3>(
445 vol_ele->getOpPtrVector().push_back(
new OpCalculateHTensorTensorField<3, 3>(
447 SmartPetscObj<Vec>(), MBMAXTYPE));
448 vol_ele->getOpPtrVector().push_back(
new OpCalculateVectorFieldValues<3>(
451 pushOpCalculateStretchFromStress(
455 vol_ele->getOpPtrVector().push_back(
456 new OpCalculateTensor2SymmetricFieldValues<3>(
460 vol_ele->getOpPtrVector().push_back(
new OpCalculateHVecTensorField<3, 3>(
464 vol_ele->getOpPtrVector().push_back(
465 new OpCalculateTensor2SymmetricFieldValues<3>(
469 vol_ele->getOpPtrVector().push_back(
new OpCalculateVectorFieldValues<3>(
471 vol_ele->getOpPtrVector().push_back(
new OpCalculateVectorFieldValues<3>(
475 vol_ele->getOpPtrVector().push_back(
new OpCalculateVectorFieldValues<3>(
477 vol_ele->getOpPtrVector().push_back(
new OpCalculateVectorFieldGradient<3, 3>(
480 vol_ele->getOpPtrVector().push_back(
501 dataFieldEval->setEvalPoints(point.data(), point.size() / 3);
502 auto point_found_ptr = boost::make_shared<int>(0);
504 struct OpPrint :
public VolOp {
507 std::array<double, 3> point;
509 boost::shared_ptr<int> pointFoundPtr;
513 OpPrint(
EshelbianCore &ep, std::array<double, 3> &point, std::string &str,
514 boost::shared_ptr<int> point_found_ptr, PetscInt step,
double time)
516 str(str), pointFoundPtr(point_found_ptr), step(step), time(time) {}
518 MoFEMErrorCode doWork(
int side, EntityType
type,
519 EntitiesFieldData::EntData &data) {
522 const int nb_gauss_pts = getGaussPts().size2();
526 auto t_h = eP.
dataAtPts->getFTensorSmallH(nb_gauss_pts);
527 auto t_approx_P = eP.
dataAtPts->getFTensorApproxP(nb_gauss_pts);
529 getFTensor1FromMat<SPACE_DIM>(*eP.
dataAtPts->getSmallWL2AtPts());
534 const double jac = determinantTensor3by3(t_h);
536 t_cauchy(
i,
j) = (1. / jac) * (t_approx_P(
i,
k) * t_h(
j,
k));
539 std::ostringstream s;
540 s << str <<
" elem " << getFEEntityHandle() <<
" ";
544 auto print_tensor = [](
auto &
t) {
545 std::ostringstream s;
550 std::ostringstream print;
554 << add() <<
"point " << getVectorAdaptor(point.data(), 3);
556 << add() <<
"coords at gauss pts " << getCoordsAtGaussPts();
558 << add() <<
"w " << *(eP.
dataAtPts->getSmallWL2AtPts());
560 << add() <<
"Piola " << *(eP.
dataAtPts->getApproxPAtPts());
562 << add() <<
"Cauchy " << print_tensor(t_cauchy);
564 "EPSYNC", Sev::inform,
565 "FieldEvaluator step %d time %6.4e label \"%s\" point [%6.4e, "
567 step, time, str.c_str(), point[0], point[1], point[2]);
569 "FieldEvaluator displacement [Ux, Uy, Uz] = [%6.4e, "
571 t_disp(0), t_disp(1), t_disp(2));
573 "EPSYNC", Sev::inform,
574 "FieldEvaluator Cauchy stress [Sxx, Syy, Szz, Sxy, Syz, Sxz] "
575 "= [%6.4e, %6.4e, %6.4e, %6.4e, %6.4e, %6.4e]",
576 t_cauchy(0, 0), t_cauchy(1, 1), t_cauchy(2, 2),
577 t_cauchy(0, 1), t_cauchy(1, 2), t_cauchy(0, 2));
585 fe_ptr->data_ctx |= PetscData::CtxSetTime;
595 fe_ptr->getOpPtrVector().push_back(
596 new OpPrint(
eP, point, str, point_found_ptr, ts_step, time));
598 ->evalFEAtThePoint<SPACE_DIM>(
599 point.data(), 1e-12, problemPtr->getName(),
"EP",
dataFieldEval,
602 fe_ptr->getOpPtrVector().pop_back();
605 int global_point_found = 0;
606 MPI_Allreduce(point_found_ptr.get(), &global_point_found, 1, MPI_INT, MPI_SUM,
610 "FieldEvaluator did not find point [%6.4e, %6.4e, %6.4e] in "
612 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,...)
#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.
#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< ExternalStrainVec > externalStrainVecPtr
boost::shared_ptr< Range > frontAdjEdges
MoFEM::Interface & mField
const std::string spatialL2Disp
std::map< std::string, boost::shared_ptr< ScalingMethod > > timeScaleMap
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
static enum MaterialModel materialModel
MoFEMErrorCode calculateCrackArea(boost::shared_ptr< double > &area_ptr)
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
static bool isNoStretch()
SmartPetscObj< Vec > solTSStep
boost::shared_ptr< Range > frontEdges
const std::string stretchTensor
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.