v0.16.0
Loading...
Searching...
No Matches
EshelbianTestingMonitor.cpp
Go to the documentation of this file.
1/** @file
2 @brief Contains definition of EshelbianTestingMonitor class.
3 @ingroup EshelbianPlasticty
4*/
5
7 using SetPtsData = FieldEvaluatorInterface::SetPtsData;
8
10 boost::shared_ptr<EshelbianMonitor> base_monitor_ptr)
11 : baseMonitorPtr(base_monitor_ptr), eP(baseMonitorPtr->getEpCore()),
12 ptsHashMap(baseMonitorPtr->getHashMap()),
13 reactionForcesMap(baseMonitorPtr->getReactionMap()),
14 gEnergy(baseMonitorPtr->getEnergy()),
15 dataFieldEval(baseMonitorPtr->getDataField()) {
16
17 PetscBool test_cook_flg = PETSC_FALSE;
18 PetscInt atom_test = 0;
19 CHK_THROW_MESSAGE(PetscOptionsGetBool(PETSC_NULLPTR, "", "-test_cook_pts",
20 &test_cook_flg, PETSC_NULLPTR),
21 "get post proc points");
22 CHKERR PetscOptionsGetInt(PETSC_NULLPTR, "", "-atom_test", &atom_test,
23 PETSC_NULLPTR);
24
25 if (test_cook_flg) {
26 ptsHashMap["Point A"] = {48., 60., 4.999};
27 ptsHashMap["Point B"] = {48. / 2., 44. + (60. - 44.) / 2., 0.};
28 ptsHashMap["Point C"] = {48. / 2., (44. - 0.) / 2., 0.};
29 }
30 if (atom_test == 14) {
31 // Points for atom test 14: check external strain
32 ptsHashMap["Point (2.5, 0., 0.)"] = {2.5, 0, 0.};
33 }
34 }
35
36 MoFEMErrorCode preProcess() { return 0; }
37
38 MoFEMErrorCode operator()() { return 0; }
39
40 MoFEMErrorCode postProcess() {
42
43 MOFEM_LOG("EP", Sev::inform) << "Testing Monitor postProcess";
44
45 PetscBool test_cook_flg = PETSC_FALSE;
46 PetscInt atom_test = 0;
47 char reaction_block_name[255] = "FIX_ALL";
48 CHK_THROW_MESSAGE(PetscOptionsGetBool(PETSC_NULLPTR, "", "-test_cook_pts",
49 &test_cook_flg, PETSC_NULLPTR),
50 "get post proc points");
51 CHKERR PetscOptionsGetInt(PETSC_NULLPTR, "", "-atom_test", &atom_test,
52 PETSC_NULLPTR);
53 CHKERR PetscOptionsGetString(PETSC_NULLPTR, "", "-atom_test_reaction_block",
54 reaction_block_name, 255, PETSC_NULLPTR);
55
56 if (test_cook_flg) {
57 // Points for Cook beam
58 for (auto &pts : ptsHashMap) {
59 CHKERR baseMonitorPtr->postProcAtPoints(pts.second, pts.first);
61 }
62 }
63
64 switch (atom_test) {
65 case 14:
66 // Points for external strain
67 for (auto &pts : ptsHashMap) {
68 CHKERR checkExternalStrain(pts.second, pts.first, atom_test);
69 }
70 break;
71 case 15:
72 if (ts_t > 0.0) {
73 // L = 5, ty = tz = 1, A = 1, UDL Top face 0.1,
74 // Moment at x = 0 should be 0.25.
75 if (std::abs(reactionForcesMap[reaction_block_name][5] - 0.25) > 1e-3) {
77 SETERRQ(
78 PETSC_COMM_WORLD, MOFEM_ATOM_TEST_INVALID,
79 "Atom test 15 failed: reaction moment does not match expected "
80 "value. Got [%3.6e], expected [0.25].",
81 reactionForcesMap[reaction_block_name][5]);
82 }
83 }
84 break;
85 case 16:
86 if (ts_t > 0.0) {
87 // L = 5, ty = tz = 1, A = 1, E = 1000 * exp(0.1*x), u = 0.1, F = 1000 *
88 // 0.1/(1-exp(-0.5)) = 25.4149, so reaction force should
89 // be -25.4149
90 if (std::abs(reactionForcesMap[reaction_block_name][0] - (-25.4149)) >
91 1e-4) {
93 SETERRQ(PETSC_COMM_WORLD, MOFEM_ATOM_TEST_INVALID,
94 "Atom test 16 failed: reaction force does not match expected "
95 "value. Got [%3.6e, %3.6e, %3.6e], expected [-25.4149, 0.0, "
96 "0.0].",
97 reactionForcesMap[reaction_block_name][0],
98 reactionForcesMap[reaction_block_name][1],
99 reactionForcesMap[reaction_block_name][2]);
100 }
101 }
102 break;
103 case 17:
104 if (ts_t > 0.0) {
105 if (std::abs(*gEnergy - 1.27096) > 1e-5) {
107 SETERRQ(PETSC_COMM_WORLD, MOFEM_ATOM_TEST_INVALID,
108 "Atom test 17 failed: strain energy does not match expected "
109 "value. Got %3.6e, expected 1.27096.",
110 *gEnergy);
111 }
112 }
113 break;
114 case 18:
115 if (ts_step == 4) {
116 if (std::abs(eP.loadFactor - 12.5325) > 1e-5) {
118 SETERRQ(PETSC_COMM_WORLD, MOFEM_ATOM_TEST_INVALID,
119 "Atom test 18 failed: load factor does not match expected "
120 "value. Got %3.6e, expected 12.5325.",
121 eP.loadFactor);
122 }
123 }
124 break;
125 case 19:
126 if (ts_t > 0.0) {
127 if (std::abs(reactionForcesMap["SPRING_BC"][2] - 2.016e1) > 1e-3) {
129 SETERRQ(
130 PETSC_COMM_WORLD, MOFEM_ATOM_TEST_INVALID,
131 "Atom test 19 failed: reaction force does not match expected "
132 "value. Got [%3.6e], expected [2.016e1].",
133 reactionForcesMap["SPRING_BC"][2]);
134 }
135 }
136 break;
137 default:
138 break;
139 }
140
142 }
143
144 MoFEMErrorCode checkExternalStrain(std::array<double, 3> point,
145 std::string str, PetscInt atom_test);
146
147 protected:
148 boost::shared_ptr<EshelbianMonitor> baseMonitorPtr;
150 std::map<std::string, std::array<double, 6>> &reactionForcesMap;
151 boost::shared_ptr<SetPtsData> dataFieldEval;
152 std::map<std::string, std::array<double, 3>> &ptsHashMap;
153 boost::shared_ptr<double> gEnergy;
154};
155
157 std::array<double, 3> point, std::string str, PetscInt atom_test) {
159
160 dataFieldEval->setEvalPoints(point.data(), point.size() / 3);
161 auto vec = createVectorMPI(eP.mField.get_comm(), 1, 1);
162 auto w_l2_at_pts = eP.dataAtPts->getSmallWL2AtPts();
163 w_l2_at_pts->resize(0, 0, false);
164
165 if (auto fe_ptr = dataFieldEval->feMethodPtr) {
166 CHKERR eP.mField.getInterface<FieldEvaluatorInterface>()
167 ->evalFEAtThePoint<SPACE_DIM>(
168 point.data(), 1e-12, problemPtr->getName(), "EP", dataFieldEval,
170 MF_EXIST, QUIET);
171 }
172 if (w_l2_at_pts->size1() == 0 || w_l2_at_pts->size2() == 0) {
173 CHKERR VecSetValue(vec, 0, 0.0, ADD_VALUES);
174 } else if (w_l2_at_pts->size1() == 1 || w_l2_at_pts->size2() == 1) {
175 auto add = [&]() {
176 std::ostringstream s;
177 s << str << " elem " << getFEEntityHandle() << " ";
178 return s.str();
179 };
180 MOFEM_LOG("EPSYNC", Sev::inform)
181 << add() << "comm rank " << eP.mField.get_comm_rank();
182 MOFEM_LOG("EPSYNC", Sev::inform)
183 << add() << "point " << getVectorAdaptor(point.data(), 3);
184 MOFEM_LOG("EPSYNC", Sev::inform)
185 << add() << "w " << *w_l2_at_pts;
186 double disp_at_point = (*w_l2_at_pts)(0, 0);
187 CHKERR VecSetValue(vec, 0, disp_at_point, ADD_VALUES);
188 } else {
189 SETERRQ(PETSC_COMM_WORLD, MOFEM_DATA_INCONSISTENCY,
190 "Unexpected displacement data shape (%ld, %ld).",
191 static_cast<long>(w_l2_at_pts->size1()),
192 static_cast<long>(w_l2_at_pts->size2()));
193 }
194
196 if (ts_t > 0.0) {
197 CHKERR VecAssemblyBegin(vec);
198 CHKERR VecAssemblyEnd(vec);
199 double error;
200 PetscInt idx = 0;
201 if (eP.mField.get_comm_rank() == 0) {
202 CHKERR VecGetValues(vec, 1, &idx, &error);
203 }
204 MPI_Bcast(&error, 1, MPI_DOUBLE, 0, PETSC_COMM_WORLD);
205 // Check if the displacement is correct for the applied external
206 // strain For the bar problem, we expect a displacement of 0.25 at
207 // point A
208 if (std::abs(error - 0.25) > 1e-5) {
209 SETERRQ(PETSC_COMM_WORLD, MOFEM_ATOM_TEST_INVALID,
210 "Atom test %d failed: wrong displacement %.12g.", atom_test,
211 error);
212 }
213 }
215}
#define MOFEM_LOG_SEVERITY_SYNC(comm, severity)
Synchronise "SYNC" on curtain severity level.
#define MOFEM_LOG_SYNCHRONISE(comm)
Synchronise "SYNC" channel.
@ QUIET
@ MF_EXIST
#define CHK_THROW_MESSAGE(err, msg)
Check and throw MoFEM exception.
#define MoFEMFunctionBegin
First executable line of each MoFEM function, used for error handling. Final line of MoFEM functions ...
@ MOFEM_ATOM_TEST_INVALID
Definition definitions.h:40
@ MOFEM_DATA_INCONSISTENCY
Definition definitions.h:31
#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.
MoFEM::Interface & mField
boost::shared_ptr< DataAtIntegrationPts > dataAtPts
std::map< std::string, std::array< double, 3 > > & ptsHashMap
boost::shared_ptr< double > gEnergy
boost::shared_ptr< EshelbianMonitor > baseMonitorPtr
std::map< std::string, std::array< double, 6 > > & reactionForcesMap
EshelbianTestingMonitor(EshelbianCore &ep, boost::shared_ptr< EshelbianMonitor > base_monitor_ptr)
boost::shared_ptr< SetPtsData > dataFieldEval
MoFEMErrorCode checkExternalStrain(std::array< double, 3 > point, std::string str, PetscInt atom_test)
FieldEvaluatorInterface::SetPtsData SetPtsData
virtual MPI_Comm & get_comm() const =0
virtual int get_comm_rank() const =0
MoFEMErrorCode getInterface(IFACE *&iface) const
Get interface reference to pointer of interface.
int atom_test
Atom test.
Definition plastic.cpp:122