v0.14.0
Public Types | Public Member Functions | Public Attributes | List of all members
EshelbianMonitor Struct Reference
Inheritance diagram for EshelbianMonitor:
[legend]
Collaboration diagram for EshelbianMonitor:
[legend]

Public Types

using Ele = ForcesAndSourcesCore
 
using VolEle = VolumeElementForcesAndSourcesCore
 
using VolOp = VolumeElementForcesAndSourcesCore::UserDataOperator
 
using SetPtsData = FieldEvaluatorInterface::SetPtsData
 
using PtsHashMap = std::map< std::string, std::array< double, 3 > >
 

Public Member Functions

 EshelbianMonitor (EshelbianCore &ep)
 
MoFEMErrorCode preProcess ()
 
MoFEMErrorCode operator() ()
 
MoFEMErrorCode postProcess ()
 

Public Attributes

EshelbianCore & eP
 
boost::shared_ptr< SetPtsDatadataFieldEval
 
boost::shared_ptr< VolElevolPostProcEnergy
 
boost::shared_ptr< doublegEnergy
 
PtsHashMap ptsHashMap
 

Detailed Description

Examples
EshelbianPlasticity.cpp.

Definition at line 6 of file EshelbianMonitor.cpp.

Member Typedef Documentation

◆ Ele

using EshelbianMonitor::Ele = ForcesAndSourcesCore

Definition at line 8 of file EshelbianMonitor.cpp.

◆ PtsHashMap

using EshelbianMonitor::PtsHashMap = std::map<std::string, std::array<double, 3> >

Definition at line 12 of file EshelbianMonitor.cpp.

◆ SetPtsData

using EshelbianMonitor::SetPtsData = FieldEvaluatorInterface::SetPtsData

Definition at line 11 of file EshelbianMonitor.cpp.

◆ VolEle

Definition at line 9 of file EshelbianMonitor.cpp.

◆ VolOp

Definition at line 10 of file EshelbianMonitor.cpp.

Constructor & Destructor Documentation

◆ EshelbianMonitor()

EshelbianMonitor::EshelbianMonitor ( EshelbianCore &  ep)
inline

Definition at line 20 of file EshelbianMonitor.cpp.

21  : eP(ep), dataFieldEval(ep.mField.getInterface<FieldEvaluatorInterface>()
22  ->getData<VolEle>()),
23  volPostProcEnergy(new VolEle(ep.mField)), gEnergy(new double) {
24  ierr = ep.mField.getInterface<FieldEvaluatorInterface>()->buildTree3D(
25  dataFieldEval, "EP");
26  CHKERRABORT(PETSC_COMM_WORLD, ierr);
27 
28  auto no_rule = [](int, int, int) { return -1; };
29 
30  auto set_element_for_field_eval = [&]() {
32  boost::shared_ptr<Ele> vol_ele(dataFieldEval->feMethodPtr.lock());
33  vol_ele->getRuleHook = no_rule;
34  vol_ele->getUserPolynomialBase() =
35  boost::shared_ptr<BaseFunction>(new CGGUserPolynomialBase());
36  AddHOOps<SPACE_DIM, SPACE_DIM, SPACE_DIM>::add(vol_ele->getOpPtrVector(),
37  {HDIV, H1, L2});
38 
39  vol_ele->getOpPtrVector().push_back(new OpCalculateHVecTensorField<3, 3>(
40  eP.piolaStress, eP.dataAtPts->getApproxPAtPts()));
41  vol_ele->getOpPtrVector().push_back(
42  new OpCalculateHTensorTensorField<3, 3>(
43  eP.bubbleField, eP.dataAtPts->getApproxPAtPts(), MBMAXTYPE));
44  vol_ele->getOpPtrVector().push_back(
45  new OpCalculateTensor2SymmetricFieldValues<3>(
46  eP.stretchTensor, eP.dataAtPts->getLogStretchTensorAtPts(),
47  MBTET));
48  vol_ele->getOpPtrVector().push_back(new OpCalculateVectorFieldValues<3>(
49  eP.rotAxis, eP.dataAtPts->getRotAxisAtPts(), MBTET));
50  vol_ele->getOpPtrVector().push_back(new OpCalculateVectorFieldValues<3>(
51  eP.spatialL2Disp, eP.dataAtPts->getSmallWL2AtPts(), MBTET));
52 
53  // H1 displacements
54  vol_ele->getOpPtrVector().push_back(new OpCalculateVectorFieldValues<3>(
55  eP.spatialH1Disp, eP.dataAtPts->getSmallWH1AtPts()));
56  vol_ele->getOpPtrVector().push_back(
58  eP.spatialH1Disp, eP.dataAtPts->getSmallWGradH1AtPts()));
59 
60  vol_ele->getOpPtrVector().push_back(
61  new OpCalculateRotationAndSpatialGradient(eP.dataAtPts));
63  };
64 
65  auto set_element_for_post_process = [&]() {
67  volPostProcEnergy->getRuleHook = VolRule();
68 
69  volPostProcEnergy->getUserPolynomialBase() =
70  boost::shared_ptr<BaseFunction>(new CGGUserPolynomialBase());
71  AddHOOps<SPACE_DIM, SPACE_DIM, SPACE_DIM>::add(
72  volPostProcEnergy->getOpPtrVector(), {HDIV, H1, L2});
73 
74  volPostProcEnergy->getOpPtrVector().push_back(
75  new OpCalculateHVecTensorField<3, 3>(
76  eP.piolaStress, eP.dataAtPts->getApproxPAtPts()));
77  volPostProcEnergy->getOpPtrVector().push_back(
78  new OpCalculateHTensorTensorField<3, 3>(
79  eP.bubbleField, eP.dataAtPts->getApproxPAtPts(), MBMAXTYPE));
80  volPostProcEnergy->getOpPtrVector().push_back(
81  new OpCalculateTensor2SymmetricFieldValues<3>(
82  eP.stretchTensor, eP.dataAtPts->getLogStretchTensorAtPts(),
83  MBTET));
84  volPostProcEnergy->getOpPtrVector().push_back(
85  new OpCalculateVectorFieldValues<3>(
86  eP.rotAxis, eP.dataAtPts->getRotAxisAtPts(), MBTET));
87  volPostProcEnergy->getOpPtrVector().push_back(
88  new OpCalculateVectorFieldValues<3>(
89  eP.spatialL2Disp, eP.dataAtPts->getSmallWL2AtPts(), MBTET));
90 
91  // H1 displacements
92  volPostProcEnergy->getOpPtrVector().push_back(
93  new OpCalculateVectorFieldValues<3>(
94  eP.spatialH1Disp, eP.dataAtPts->getSmallWH1AtPts()));
95  volPostProcEnergy->getOpPtrVector().push_back(
97  eP.spatialH1Disp, eP.dataAtPts->getSmallWGradH1AtPts()));
98 
99  volPostProcEnergy->getOpPtrVector().push_back(
100  new OpCalculateRotationAndSpatialGradient(eP.dataAtPts));
101  volPostProcEnergy->getOpPtrVector().push_back(
102  new OpCalculateStrainEnergy(eP.spatialL2Disp, eP.dataAtPts, gEnergy));
104  };
105 
106  auto reads_post_proc_data =
107  [](PtsHashMap &pts_hash_map) {
109  std::ifstream file(
110  "points.txt"); // Open the file with the name "data.txt"
111 
112  if (!file.is_open()) {
114  }
115 
116  std::string line;
117 
118  while (std::getline(file, line)) {
119  std::istringstream iss(line);
120  std::string col1;
121  double col2, col3, col4;
122 
123  if (iss >> col1 >> col2 >> col3 >> col4) {
124  MOFEM_LOG("EP", Sev::verbose) << "Read: " << col1 << ", " << col2
125  << ", " << col3 << ", " << col4;
126  pts_hash_map[col1] = {col2, col3, col4};
127  } else {
128  MOFEM_LOG("EP", Sev::error) << "Error parsing line: " << line;
129  }
130  }
131 
132  file.close(); // Close the file
134  };
135 
136  CHK_THROW_MESSAGE(set_element_for_field_eval(), "set element for field");
137  CHK_THROW_MESSAGE(set_element_for_post_process(), "set element for post");
138 
139  PetscBool test_cook_flg = PETSC_FALSE;
140  CHK_THROW_MESSAGE(PetscOptionsGetBool(PETSC_NULL, "", "-test_cook_pts",
141  &test_cook_flg, PETSC_NULL),
142  "get post proc points");
143  if (test_cook_flg) {
144  ptsHashMap["Point A"] = {48., 60., 4.999};
145  ptsHashMap["Point B"] = {48. / 2., 44. + (60. - 44.) / 2., 0.};
146  ptsHashMap["Point C"] = {48. / 2., (44. - 0.) / 2., 0.};
147  }
148  CHK_MOAB_THROW(reads_post_proc_data(ptsHashMap), "read post proc points");
149  }

Member Function Documentation

◆ operator()()

MoFEMErrorCode EshelbianMonitor::operator() ( )
inline

Definition at line 153 of file EshelbianMonitor.cpp.

153 { return 0; }

◆ postProcess()

MoFEMErrorCode EshelbianMonitor::postProcess ( )
inline

Definition at line 155 of file EshelbianMonitor.cpp.

155  {
157 
158  MOFEM_LOG("EP", Sev::inform) << "Monitor postProcess";
159 
160  auto get_step = [](auto ts_step) {
161  std::ostringstream ss;
162  ss << boost::str(boost::format("%d") % static_cast<int>(ts_step));
163  std::string s = ss.str();
164  return s;
165  };
166 
167  // PetscViewer viewer;
168  // CHKERR PetscViewerBinaryOpen(
169  // PETSC_COMM_WORLD, ("restart_" + get_step(ts_step) + ".dat").c_str(),
170  // FILE_MODE_WRITE, &viewer);
171  // CHKERR VecView(ts_u, viewer);
172  // CHKERR PetscViewerDestroy(&viewer);
173 
174  CHKERR eP.postProcessResults(1, "out_sol_elastic_" + get_step(ts_step) +
175  ".h5m");
176 
177  // Loop boundary elements with traction boundary conditions
178  *gEnergy = 0;
179  CHKERR eP.mField.loop_finite_elements(problemPtr->getName(), "EP",
181 
182  double body_energy = 0;
183  MPI_Allreduce(gEnergy.get(), &body_energy, 1, MPI_DOUBLE, MPI_SUM,
184  eP.mField.get_comm());
185  MOFEM_LOG_C("EP", Sev::inform, "Step %d time %3.4g strain energy %3.6e",
186  ts_step, ts_t, body_energy);
187 
188  auto post_proc_at_points = [&](std::array<double, 3> point,
189  std::string str) {
191 
192  dataFieldEval->setEvalPoints(point.data(), point.size() / 3);
193 
194  struct OpPrint : public VolOp {
195 
196  EshelbianCore &eP;
197  std::array<double, 3> point;
198  std::string str;
199 
200  OpPrint(EshelbianCore &ep, std::array<double, 3> &point,
201  std::string &str)
202  : VolOp(ep.spatialL2Disp, VolOp::OPROW), eP(ep), point(point),
203  str(str) {}
204 
205  MoFEMErrorCode doWork(int side, EntityType type,
208  if (type == MBTET) {
209  if (getGaussPts().size2()) {
210 
211  auto t_h = getFTensor2FromMat<3, 3>(eP.dataAtPts->hAtPts);
212  auto t_approx_P =
213  getFTensor2FromMat<3, 3>(eP.dataAtPts->approxPAtPts);
214 
218  const double jac = determinantTensor3by3(t_h);
220  t_cauchy(i, j) = (1. / jac) * (t_approx_P(i, k) * t_h(j, k));
221 
222  auto add = [&]() {
223  std::ostringstream s;
224  s << str << " elem " << getFEEntityHandle() << " ";
225  return s.str();
226  };
227 
228  auto print_tensor = [](auto &t) {
229  std::ostringstream s;
230  s << t;
231  return s.str();
232  };
233 
234  std::ostringstream print;
235  MOFEM_LOG("EPSYNC", Sev::inform)
236  << add() << "comm rank " << eP.mField.get_comm_rank();
237  MOFEM_LOG("EPSYNC", Sev::inform)
238  << add() << "point " << getVectorAdaptor(point.data(), 3);
239  MOFEM_LOG("EPSYNC", Sev::inform)
240  << add() << "coords at gauss pts " << getCoordsAtGaussPts();
241  MOFEM_LOG("EPSYNC", Sev::inform)
242  << add() << "w " << eP.dataAtPts->wL2AtPts;
243  MOFEM_LOG("EPSYNC", Sev::inform)
244  << add() << "Piola " << eP.dataAtPts->approxPAtPts;
245  MOFEM_LOG("EPSYNC", Sev::inform)
246  << add() << "Cauchy " << print_tensor(t_cauchy);
247  }
248  }
250  }
251  };
252 
253  if (auto fe_ptr = dataFieldEval->feMethodPtr.lock()) {
254 
255  fe_ptr->getOpPtrVector().push_back(new OpPrint(eP, point, str));
256  CHKERR eP.mField.getInterface<FieldEvaluatorInterface>()
257  ->evalFEAtThePoint3D(point.data(), 1e-12, problemPtr->getName(),
258  "EP", dataFieldEval, eP.mField.get_comm_rank(),
259  eP.mField.get_comm_rank(), nullptr, MF_EXIST,
260  QUIET);
261  fe_ptr->getOpPtrVector().pop_back();
262  }
263 
265  };
266 
267  // Points for Cook beam
268  for (auto &pts : ptsHashMap) {
269  CHKERR post_proc_at_points(pts.second, pts.first);
270  MOFEM_LOG_SEVERITY_SYNC(eP.mField.get_comm(), Sev::inform);
271  }
272 
274  }

◆ preProcess()

MoFEMErrorCode EshelbianMonitor::preProcess ( )
inline

Definition at line 151 of file EshelbianMonitor.cpp.

151 { return 0; }

Member Data Documentation

◆ dataFieldEval

boost::shared_ptr<SetPtsData> EshelbianMonitor::dataFieldEval

Definition at line 15 of file EshelbianMonitor.cpp.

◆ eP

EshelbianCore& EshelbianMonitor::eP

Definition at line 14 of file EshelbianMonitor.cpp.

◆ gEnergy

boost::shared_ptr<double> EshelbianMonitor::gEnergy

Definition at line 17 of file EshelbianMonitor.cpp.

◆ ptsHashMap

PtsHashMap EshelbianMonitor::ptsHashMap

Definition at line 18 of file EshelbianMonitor.cpp.

◆ volPostProcEnergy

boost::shared_ptr<VolEle> EshelbianMonitor::volPostProcEnergy

Definition at line 16 of file EshelbianMonitor.cpp.


The documentation for this struct was generated from the following file:
MoFEMFunctionReturnHot
#define MoFEMFunctionReturnHot(a)
Last executable line of each PETSc function used for error handling. Replaces return()
Definition: definitions.h:447
CHK_MOAB_THROW
#define CHK_MOAB_THROW(err, msg)
Check error code of MoAB function and throw MoFEM exception.
Definition: definitions.h:576
MOFEM_LOG_SEVERITY_SYNC
#define MOFEM_LOG_SEVERITY_SYNC(comm, severity)
Synchronise "SYNC" on curtain severity level.
Definition: LogManager.hpp:352
EshelbianMonitor::PtsHashMap
std::map< std::string, std::array< double, 3 > > PtsHashMap
Definition: EshelbianMonitor.cpp:12
CHK_THROW_MESSAGE
#define CHK_THROW_MESSAGE(err, msg)
Check and throw MoFEM exception.
Definition: definitions.h:596
MoFEM::Exceptions::MoFEMErrorCode
PetscErrorCode MoFEMErrorCode
MoFEM/PETSc error code.
Definition: Exceptions.hpp:56
VolRule
Set integration rule.
Definition: simple_interface.cpp:88
FTensor::Tensor2< double, 3, 3 >
EshelbianMonitor::ptsHashMap
PtsHashMap ptsHashMap
Definition: EshelbianMonitor.cpp:18
CHKERR
#define CHKERR
Inline error check.
Definition: definitions.h:535
EshelbianMonitor::volPostProcEnergy
boost::shared_ptr< VolEle > volPostProcEnergy
Definition: EshelbianMonitor.cpp:16
MoFEM::getVectorAdaptor
auto getVectorAdaptor(T1 ptr, const size_t n)
Get Vector adaptor.
Definition: Templates.hpp:31
MOFEM_LOG_C
#define MOFEM_LOG_C(channel, severity, format,...)
Definition: LogManager.hpp:311
convert.type
type
Definition: convert.py:64
EshelbianMonitor::gEnergy
boost::shared_ptr< double > gEnergy
Definition: EshelbianMonitor.cpp:17
t
constexpr double t
plate stiffness
Definition: plate.cpp:59
EshelbianPlasticity::EshelbianCore
enum RotSelector EshelbianCore
Definition: EshelbianPlasticity.cpp:84
MoFEM::VolumeElementForcesAndSourcesCore
Volume finite element base.
Definition: VolumeElementForcesAndSourcesCore.hpp:26
i
FTensor::Index< 'i', SPACE_DIM > i
Definition: hcurl_divergence_operator_2d.cpp:27
EshelbianMonitor::eP
EshelbianCore & eP
Definition: EshelbianMonitor.cpp:14
MoFEM::VolumeElementForcesAndSourcesCore::UserDataOperator
Definition: VolumeElementForcesAndSourcesCore.hpp:108
EntData
EntitiesFieldData::EntData EntData
Definition: child_and_parent.cpp:37
FTensor::Index< 'i', 3 >
MoFEM::determinantTensor3by3
static auto determinantTensor3by3(T &t)
Calculate the determinant of a 3x3 matrix or a tensor of rank 2.
Definition: Templates.hpp:1511
MOFEM_LOG
#define MOFEM_LOG(channel, severity)
Log.
Definition: LogManager.hpp:308
j
FTensor::Index< 'j', 3 > j
Definition: matrix_function.cpp:19
EshelbianMonitor::VolEle
VolumeElementForcesAndSourcesCore VolEle
Definition: EshelbianMonitor.cpp:9
MoFEM::Exceptions::ierr
static MoFEMErrorCodeGeneric< PetscErrorCode > ierr
Definition: Exceptions.hpp:76
EshelbianMonitor::dataFieldEval
boost::shared_ptr< SetPtsData > dataFieldEval
Definition: EshelbianMonitor.cpp:15
QUIET
@ QUIET
Definition: definitions.h:208
k
FTensor::Index< 'k', 3 > k
Definition: matrix_function.cpp:20
MF_EXIST
@ MF_EXIST
Definition: definitions.h:100
convert.int
int
Definition: convert.py:64
MoFEMFunctionReturn
#define MoFEMFunctionReturn(a)
Last executable line of each PETSc function used for error handling. Replaces return()
Definition: definitions.h:416
OpCalculateVectorFieldGradient
MoFEMFunctionBegin
#define MoFEMFunctionBegin
First executable line of each MoFEM function, used for error handling. Final line of MoFEM functions ...
Definition: definitions.h:346
MoFEM::PetscOptionsGetBool
PetscErrorCode PetscOptionsGetBool(PetscOptions *, const char pre[], const char name[], PetscBool *bval, PetscBool *set)
Definition: DeprecatedPetsc.hpp:182