v0.16.3
Loading...
Searching...
No Matches
Public Member Functions | Private Member Functions | Private Attributes | List of all members
ElasticAdaptiveExample Struct Reference

#include "tutorials/vec-8_elasticity_adaptive/src/ElasticAdaptiveExample.hpp"

Inheritance diagram for ElasticAdaptiveExample:
[legend]
Collaboration diagram for ElasticAdaptiveExample:
[legend]

Public Member Functions

 ElasticAdaptiveExample (MoFEM::Interface &m_field)
 
MoFEMErrorCode runProblem ()
 [Run problem]
 
- Public Member Functions inherited from ElasticExample
 ElasticExample (MoFEM::Interface &m_field)
 
virtual ~ElasticExample ()=default
 
MoFEMErrorCode runProblem ()
 [Run problem]
 

Private Member Functions

MoFEMErrorCode readMesh ()
 [Run problem]
 
MoFEMErrorCode setupAdaptivity ()
 [Read mesh]
 
MoFEMErrorCode computeErrorNorms ()
 [Postprocess results]
 
MoFEMErrorCode outputResults (int ref_iter=-1)
 [Postprocess results]
 
MoFEMErrorCode refineOrder (int ref_level)
 
MoFEMErrorCode computeErrorIndicators ()
 
MoFEMErrorCode refineGeometry ()
 
MoFEMErrorCode calculateGeometryError ()
 Calculate geometry error and save on a tag.
 
MoFEMErrorCode kspSetUpAndSolve (SmartPetscObj< KSP > solver) override
 [Set up problem]
 

Private Attributes

int oRder = 2
 
PetscBool refGeom = PETSC_FALSE
 
int refAdaptNum = 0
 
double refAdaptThreshold = 1
 
double refGeomThreshold = 1
 
std::array< double, 2 > meanError = {0.0, 0.0}
 
double errorIndicMean = 0.0
 
int atomTest = 0
 

Additional Inherited Members

- Protected Types inherited from ElasticExample
using Pipeline = boost::ptr_deque< ForcesAndSourcesCore::UserDataOperator >
 
- Protected Member Functions inherited from ElasticExample
virtual MoFEMErrorCode setupProblem ()
 [Read mesh]
 
virtual MoFEMErrorCode boundaryCondition ()
 [Set up problem]
 
virtual MoFEMErrorCode assembleSystem ()
 
virtual MoFEMErrorCode solveSystem ()
 [Solve]
 
virtual MoFEMErrorCode outputResults ()
 [Solve]
 
virtual MoFEMErrorCode checkResults ()
 [Postprocess results]
 
virtual MoFEMErrorCode addDomainMaterialOps (Pipeline &lhs_pipeline, Pipeline &rhs_pipeline)
 Add constitutive operators to the domain assembly pipelines.
 
virtual MoFEMErrorCode setUpSolver (SmartPetscObj< KSP > solver)
 [Push operators to pipeline]
 
- Protected Attributes inherited from ElasticExample
MoFEM::Interface & mField
 
boost::shared_ptr< MatrixDouble > vectorFieldPtr = nullptr
 

Detailed Description

Definition at line 12 of file ElasticAdaptiveExample.hpp.

Constructor & Destructor Documentation

◆ ElasticAdaptiveExample()

ElasticAdaptiveExample::ElasticAdaptiveExample ( MoFEM::Interface &  m_field)
inline

Definition at line 14 of file ElasticAdaptiveExample.hpp.

Member Function Documentation

◆ calculateGeometryError()

MoFEMErrorCode ElasticAdaptiveExample::calculateGeometryError ( )
private

Calculate geometry error and save on a tag.

Definition at line 14 of file HighOrderGeometryRef.hpp.

14 {
16 auto simple = mField.getInterface<Simple>();
17
18 double def_val_tag = 0.0;
19 Tag tag_err;
20 CHKERR mField.get_moab().tag_get_handle("GEOMETRY_ERROR", 1, MB_TYPE_DOUBLE,
21 tag_err, MB_TAG_CREAT | MB_TAG_SPARSE,
22 &def_val_tag);
23
24 auto LoCoordsPtr = boost::make_shared<MatrixDouble>();
25 auto *op_ptr = new BoundaryEleOp(NOSPACE, BoundaryEleOp::OPSPACE);
26 op_ptr->doWorkRhsHook = [&](DataOperator *base_op_ptr, int side,
27 EntityType type,
28 EntitiesFieldData::EntData &data) {
30 auto op_ptr = static_cast<BoundaryEleOp *>(base_op_ptr);
31 *LoCoordsPtr = op_ptr->getCoordsAtGaussPts();
33 };
34
35 auto *op_ptr_ho = new BoundaryEleOp(NOSPACE, BoundaryEleOp::OPSPACE);
36 op_ptr_ho->doWorkRhsHook = [&](DataOperator *base_op_ptr, int side,
37 EntityType type,
38 EntitiesFieldData::EntData &data) {
40 auto op_ptr_ho = static_cast<BoundaryEleOp *>(base_op_ptr);
41 auto fe_ent = op_ptr_ho->getFEEntityHandle();
43 MatrixDouble &lo_mat = *LoCoordsPtr;
44 MatrixDouble &ho_mat = op_ptr_ho->getCoordsAtGaussPts();
45 auto t_lo_coords = getFTensor1FromMat<SPACE_DIM>(lo_mat);
46 auto t_ho_coords = getFTensor1FromMat<SPACE_DIM>(ho_mat);
47 auto t_w = op_ptr_ho->getFTensor0IntegrationWeight();
48 double err_int = 0;
49 const auto nb_gauss_pts = op_ptr_ho->getGaussPts().size2();
50 // E = sqrt( int (x-xh)*(x-xh) da ) / face_area
51 for (auto gg = 0; gg != nb_gauss_pts; ++gg) {
52 err_int += t_w * ((t_lo_coords(i) - t_ho_coords(i)) *
53 (t_lo_coords(i) - t_ho_coords(i)));
54 ++t_lo_coords;
55 ++t_ho_coords;
56 ++t_w;
57 }
58 const double err_measure = sqrt(err_int) / op_ptr_ho->getMeasure();
59 if (err_measure > std::numeric_limits<float>::epsilon()) {
60 meanError[IndicInds::ERROR_TOT] += err_measure;
62 }
63
64 CHKERR mField.get_moab().tag_set_data(tag_err, &fe_ent, 1, &err_measure);
65 Range adj_tet;
66 CHKERR mField.get_moab().get_adjacencies(&fe_ent, 1, SPACE_DIM, false,
67 adj_tet);
68 if (adj_tet.size() != 1)
71 "There should be only one ent adjacent to the boundary ent");
72 auto tet_ent = *adj_tet.begin();
73 double tet_err_measure = 0;
74 CHKERR mField.get_moab().tag_get_data(tag_err, &tet_ent, 1,
75 &tet_err_measure);
76 if (err_measure > tet_err_measure) {
77 CHKERR mField.get_moab().tag_set_data(tag_err, &tet_ent, 1, &err_measure);
78 }
79
81 };
82
83 auto fe = boost::make_shared<BoundaryEle>(mField);
84 fe->getOpPtrVector().push_back(op_ptr);
85
87 fe->getOpPtrVector(), {NOSPACE}, "GEOMETRY");
88 fe->getOpPtrVector().push_back(op_ptr_ho);
89 auto dm = simple->getDM();
91 DMoFEMLoopFiniteElements(dm, simple->getBoundaryFEName(), fe),
92 "calc metric");
93
95}
std::string type
void simple(double P1[], double P2[], double P3[], double c[], const int N)
Definition acoustic.cpp:69
constexpr int SPACE_DIM
BoundaryEle::UserDataOperator BoundaryEleOp
#define CHK_THROW_MESSAGE(err, msg)
Check and throw MoFEM exception.
@ NOSPACE
Definition definitions.h:83
#define MoFEMFunctionBegin
First executable line of each MoFEM function, used for error handling. Final line of MoFEM functions ...
@ 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.
PetscErrorCode DMoFEMLoopFiniteElements(DM dm, const char fe_name[], MoFEM::FEMethod *method, CacheTupleWeakPtr cache_ptr=CacheTupleSharedPtr())
Executes FEMethod for finite elements in DM.
Definition DMMoFEM.cpp:576
FTensor::Index< 'i', SPACE_DIM > i
UBlasMatrix< double > MatrixDouble
Definition Types.hpp:77
std::array< double, 2 > meanError
MoFEM::Interface & mField
virtual moab::Interface & get_moab()=0
MoFEMErrorCode getInterface(IFACE *&iface) const
Get interface reference to pointer of interface.

◆ computeErrorIndicators()

MoFEMErrorCode ElasticAdaptiveExample::computeErrorIndicators ( )
private

Definition at line 230 of file AdaptiveOrderRef.hpp.

230 {
232 PipelineManager *pipeline_mng = mField.getInterface<PipelineManager>();
233 auto simple = mField.getInterface<Simple>();
234
235 Tag th_error_ind;
236 CHKERR getTagHandle(mField, "SOLUTION_ERROR", MB_TYPE_DOUBLE, th_error_ind);
237
238 auto integration_rule = [](int, int, int p_data) { return 2 * p_data + 1; };
239 CHKERR pipeline_mng->setSkeletonRhsIntegrationRule(integration_rule);
240 auto &skeleton_pipeline = pipeline_mng->getOpSkeletonRhsPipeline();
241
242 if (skeleton_pipeline.empty()) {
243
244 auto op_loop_side =
245 new OpLoopSide<SideEle>(mField, simple->getDomainFEName(), SPACE_DIM);
246
248 op_loop_side->getOpPtrVector(), {H1}, "GEOMETRY");
249
250 // Use HookeOps commonDataFactory to get matStrainPtr and matCauchyStressPtr
251 auto common_ptr = HookeOps::commonDataFactory<SPACE_DIM, GAUSS, DomainEle>(
252 mField, op_loop_side->getOpPtrVector(), "U", "MAT_ELASTIC",
253 Sev::verbose);
254
255 auto mat_jump_ptr = boost::make_shared<MatrixDouble>();
256 op_loop_side->getOpPtrVector().push_back(new OpCalculateTractionJump(
257 "U", common_ptr->getMatCauchyStress(), mat_jump_ptr));
258
259 auto *op_ptr = new BoundaryEleOp(NOSPACE, BoundaryEleOp::OPSPACE);
260 op_ptr->doWorkRhsHook = [this, th_error_ind,
261 mat_jump_ptr](DataOperator *base_op_ptr, int side,
262 EntityType type,
263 EntitiesFieldData::EntData &data) {
266 auto op_ptr = static_cast<BoundaryEleOp *>(base_op_ptr);
267 auto fe_ent = op_ptr->getFEEntityHandle();
268
269 auto t_jump = getFTensor1FromMat<SPACE_DIM>(*mat_jump_ptr);
270 auto t_w = op_ptr->getFTensor0IntegrationWeight();
271 double err_int = 0;
272 const auto nb_gauss_pts = op_ptr->getGaussPts().size2();
273 for (auto gg = 0; gg != nb_gauss_pts; ++gg) {
274 err_int += t_w * (t_jump(i) * t_jump(i));
275 ++t_jump;
276 ++t_w;
277 }
278 double err_measure = sqrt(err_int);
279 CHKERR mField.get_moab().tag_set_data(th_error_ind, &fe_ent, 1,
280 &err_measure);
281
283 };
284
285 skeleton_pipeline.push_back(op_loop_side);
286 skeleton_pipeline.push_back(op_ptr);
287 }
288
289 Range fe_ents;
290 CHKERR mField.get_moab().get_entities_by_dimension(0, SPACE_DIM - 1, fe_ents);
291 double zero = 0;
292 CHKERR mField.get_moab().tag_clear_data(th_error_ind, fe_ents, &zero);
293
294 CHKERR DMoFEMLoopFiniteElements(simple->getDM(), simple->getSkeletonFEName(),
295 pipeline_mng->getSkeletonRhsFE());
296
297 Range domain_ents_part;
298 CHKERR getDomainEntsPart(mField, domain_ents_part);
299
300 ParallelComm *pcomm =
301 ParallelComm::get_pcomm(&mField.get_moab(), MYPCOMM_INDEX);
302 Range empty_range;
303 CHKERR pcomm->reduce_tags(th_error_ind, MPI_SUM, empty_range);
304
305 std::array<double, 3> error_indic_loc = {0.0, 0.0, 0.0};
306
307 for (auto domain_ent : domain_ents_part) {
308 Range face_ents;
309 CHKERR mField.get_moab().get_adjacencies(
310 &domain_ent, 1, SPACE_DIM - 1, true, face_ents, moab::Interface::UNION);
311
312 double err_indic_sum = 0;
313 for (auto face_ent : face_ents) {
314 double err_indic = 0;
315 CHKERR mField.get_moab().tag_get_data(th_error_ind, &face_ent, 1,
316 &err_indic);
317 err_indic_sum += err_indic;
318 }
319 CHKERR mField.get_moab().tag_set_data(th_error_ind, &domain_ent, 1,
320 &err_indic_sum);
321
322 error_indic_loc[IndicInds::ERROR_TOT] += err_indic_sum;
323
324 const EntityHandle *vert_conn;
325 int vert_num;
326 CHKERR mField.get_moab().get_connectivity(domain_ent, vert_conn, vert_num,
327 true);
328 std::vector<double> vpos(3 * vert_num);
329 CHKERR mField.get_moab().get_coords(vert_conn, vert_num, &vpos[0]);
330 double vol = Tools::tetVolume(vpos.data());
331
332 error_indic_loc[IndicInds::ERROR_NORM] += err_indic_sum * vol;
333 }
334
335 CHKERR copyTagOnSkin(mField, "SOLUTION_ERROR", MB_TYPE_DOUBLE);
336
337 error_indic_loc[IndicInds::COUNT_ENTS] =
338 static_cast<double>(domain_ents_part.size());
339
340 std::array<double, 3> error_indic_glob = {0.0, 0.0, 0.0};
341
342 MPI_Allreduce(&error_indic_loc[0], &error_indic_glob[0], 3, MPI_DOUBLE,
343 MPI_SUM, mField.get_comm());
344
345 errorIndicMean = error_indic_glob[IndicInds::ERROR_TOT] /
346 error_indic_glob[IndicInds::COUNT_ENTS];
347
348 MOFEM_LOG("WORLD", Sev::inform) << "Global error indicator (norm): "
349 << error_indic_glob[IndicInds::ERROR_NORM];
350 MOFEM_LOG("WORLD", Sev::inform)
351 << "Global error indicator (mean): " << errorIndicMean;
352
354}
static MoFEMErrorCode getTagHandle(MoFEM::Interface &m_field, const char *name, DataType type, Tag &tag_handle)
static MoFEMErrorCode getDomainEntsPart(MoFEM::Interface &m_field, Range &domain_ents_part)
static MoFEMErrorCode copyTagOnSkin(MoFEM::Interface &m_field, const char *name, DataType type)
#define MYPCOMM_INDEX
default communicator number PCOMM
auto integration_rule
#define MOFEM_LOG(channel, severity)
Log.
virtual MPI_Comm & get_comm() const =0

◆ computeErrorNorms()

MoFEMErrorCode ElasticAdaptiveExample::computeErrorNorms ( )
private

[Postprocess results]

[Error Norms]

Definition at line 216 of file ElasticAdaptiveExample.hpp.

216 {
217 MOFEM_LOG_CHANNEL("WORLD");
218 auto simple = mField.getInterface<Simple>();
220
221 auto integration_rule = [](int, int, int p_data) { return p_data + 1; };
222 auto evaluation_fe = boost::make_shared<DomainEle>(mField);
223 evaluation_fe->getRuleHook = integration_rule;
224
225 auto &evaluation_pipeline = evaluation_fe->getOpPtrVector();
227 {H1}, "GEOMETRY");
228
229 auto u_ptr = boost::make_shared<MatrixDouble>();
230 evaluation_pipeline.push_back(
231 new OpCalculateVectorFieldValues<SPACE_DIM>("U", u_ptr));
232
233 auto analytical_disp_ptr = boost::make_shared<MatrixDouble>();
234
235 evaluation_pipeline.push_back(new OpGetTensor1fromFunc<SPACE_DIM, SPACE_DIM>(
236 analytical_disp_ptr, analyticalDisplacement));
237
238 auto normsVec = createVectorMPI(mField.get_comm(),
239 (mField.get_comm_rank() == 0) ? 1 : 0, 1);
240
241 evaluation_pipeline.push_back(new OpCalcNormL2Tensor1<SPACE_DIM>(
242 u_ptr, normsVec, 0, analytical_disp_ptr));
243
244 CHKERR VecZeroEntries(normsVec);
245 CHKERR DMoFEMLoopFiniteElements(simple->getDM(), simple->getDomainFEName(),
246 evaluation_fe);
247 CHKERR VecAssemblyBegin(normsVec);
248 CHKERR VecAssemblyEnd(normsVec);
249
250 if (mField.get_comm_rank() == 0) {
251 const double *norms;
252 CHKERR VecGetArrayRead(normsVec, &norms);
253 MOFEM_TAG_AND_LOG("SELF", Sev::inform, "Errors")
254 << "Displacement error L2 norm: " << std::scientific
255 << std::sqrt(norms[0]);
256
257 if (atomTest == 3 && std::sqrt(norms[0]) > 2.195e-06) {
258 SETERRQ(PETSC_COMM_SELF, MOFEM_ATOM_TEST_INVALID,
259 "atom test failed: displacement error L2 norm is too high: "
260 "%3.6e",
261 std::sqrt(norms[0]));
262 }
263
264 if (atomTest == 4 && std::sqrt(norms[0]) > 1.995e-07) {
265 SETERRQ(PETSC_COMM_SELF, MOFEM_ATOM_TEST_INVALID,
266 "atom test failed: displacement error L2 norm is too high: "
267 "%3.6e",
268 std::sqrt(norms[0]));
269 }
270
271 CHKERR VecRestoreArrayRead(normsVec, &norms);
272 }
273
275}
MoFEM::VectorFunc analyticalDisplacement
#define MOFEM_TAG_AND_LOG(channel, severity, tag)
Tag and log in channel.
@ H1
continuous field
Definition definitions.h:85
@ MOFEM_ATOM_TEST_INVALID
Definition definitions.h:40
#define MOFEM_LOG_CHANNEL(channel)
Set and reset channel.
auto createVectorMPI(MPI_Comm comm, PetscInt n, PetscInt N)
Create MPI Vector.
virtual int get_comm_rank() const =0

◆ kspSetUpAndSolve()

MoFEMErrorCode ElasticAdaptiveExample::kspSetUpAndSolve ( SmartPetscObj< KSP >  solver)
overrideprivatevirtual

[Set up problem]

Reimplemented from ElasticExample.

Definition at line 155 of file ElasticAdaptiveExample.hpp.

155 {
157
158 MOFEM_LOG_CHANNEL("TIMER");
159 MOFEM_LOG_TAG("TIMER", "timer");
160
161 DM dm;
162 CHKERR KSPGetDM(solver, &dm);
163 auto D = createDMVector(dm);
164 auto F = vectorDuplicate(D);
165
166 CHKERR VecZeroEntries(D);
167 CHKERR VecGhostUpdateBegin(D, INSERT_VALUES, SCATTER_FORWARD);
168 CHKERR VecGhostUpdateEnd(D, INSERT_VALUES, SCATTER_FORWARD);
169 CHKERR DMoFEMMeshToLocalVector(dm, D, INSERT_VALUES, SCATTER_REVERSE);
170
171 BOOST_LOG_SCOPED_THREAD_ATTR("Timeline", attrs::timer());
172 MOFEM_LOG("TIMER", Sev::inform) << "KSPSetUp";
173 CHKERR KSPSetUp(solver);
174 MOFEM_LOG("TIMER", Sev::inform) << "KSPSetUp <= Done";
175 MOFEM_LOG("TIMER", Sev::inform) << "KSPSolve";
176 CHKERR KSPSolve(solver, F, D);
177 MOFEM_LOG("TIMER", Sev::inform) << "KSPSolve <= Done";
178
179 CHKERR VecGhostUpdateBegin(D, INSERT_VALUES, SCATTER_FORWARD);
180 CHKERR VecGhostUpdateEnd(D, INSERT_VALUES, SCATTER_FORWARD);
181 CHKERR DMoFEMMeshToLocalVector(dm, D, INSERT_VALUES, SCATTER_REVERSE);
182
184}
@ F
PetscErrorCode DMoFEMMeshToLocalVector(DM dm, Vec l, InsertMode mode, ScatterMode scatter_mode, RowColData rc=RowColData::COL)
set local (or ghosted) vector values on mesh for partition only
Definition DMMoFEM.cpp:514
auto createDMVector(DM dm, RowColData rc=RowColData::COL)
Get smart vector from DM.
Definition DMMoFEM.hpp:1237
#define MOFEM_LOG_TAG(channel, tag)
Tag channel.
double D
SmartPetscObj< Vec > vectorDuplicate(Vec vec)
Create duplicate vector of smart vector.

◆ outputResults()

MoFEMErrorCode ElasticAdaptiveExample::outputResults ( int  ref_iter = -1)
private

[Postprocess results]

Definition at line 196 of file ElasticAdaptiveExample.hpp.

196 {
198 auto simple = mField.getInterface<Simple>();
199
200 std::ostringstream strm;
201 strm << "out_elastic";
202 if (ref_iter >= 0) {
203 strm << "_" << ref_iter;
204 }
205 strm << ".h5m";
206
209 mField, simple->getDM(), simple->getDomainFEName(), strm.str(), {},
210 {"GEOMETRY_ERROR", "SOLUTION_ERROR", "ORDER"}, Sev::verbose);
212}
ElementsAndOps< SPACE_DIM >::DomainEle DomainEle
ElementsAndOps< SPACE_DIM >::BoundaryEle BoundaryEle
MoFEMErrorCode postProcessElasticResults(MoFEM::Interface &mField, SmartPetscObj< DM > dm, const std::string &domain_fe_name, const std::string &out_file_name, std::vector< std::pair< std::string, SmartPetscObj< Vec > > > extra_vectors={}, const std::vector< std::string > &tags_to_transfer={}, const Sev hooke_ops_sev=Sev::verbose)
ElementsAndOps< SPACE_DIM >::SideEle SideEle
Definition plastic.cpp:61

◆ readMesh()

MoFEMErrorCode ElasticAdaptiveExample::readMesh ( )
privatevirtual

[Run problem]

[Read mesh]

Reimplemented from ElasticExample.

Definition at line 79 of file ElasticAdaptiveExample.hpp.

79 {
81 auto simple = mField.getInterface<Simple>();
82 CHKERR simple->getOptions();
83
84 CHKERR PetscOptionsGetBool(PETSC_NULLPTR, "", "-ref_geom", &refGeom,
85 PETSC_NULLPTR);
86
87 CHKERR PetscOptionsGetInt(PETSC_NULLPTR, "", "-ref_adapt_num", &refAdaptNum,
88 PETSC_NULLPTR);
89
90 if ((refAdaptNum > 0) && refGeom) {
91 SETERRQ(PETSC_COMM_SELF, MOFEM_DATA_INCONSISTENCY,
92 "Adaptive order and geometry refinement cannot be used together");
93 }
94
95 simple->getAddSkeletonFE() = true;
96 CHKERR simple->loadFile();
97
98 // Add meshsets if config file provided
99 CHKERR mField.getInterface<MeshsetsManager>()->setMeshsetFromFile();
100
101 auto update_ghost_ents = [&]() {
103
104 for (auto m : mField.getInterface<MeshsetsManager>()->getCubitMeshsetPtr(
105 std::regex((boost::format("%s(.*)") % "MAT_ELASTIC").str()))
106
107 ) {
108 Range ents;
109 CHKERR mField.get_moab().get_entities_by_handle(m->getMeshset(), ents,
110 true);
111 CHKERR mField.getInterface<CommInterface>()->synchroniseEntities(ents);
112 CHKERR mField.get_moab().add_entities(m->getMeshset(), ents);
113 }
114
116 };
117
118 CHKERR update_ghost_ents();
119
121}
PetscErrorCode PetscOptionsGetInt(PetscOptions *, const char pre[], const char name[], PetscInt *ivalue, PetscBool *set)
PetscErrorCode PetscOptionsGetBool(PetscOptions *, const char pre[], const char name[], PetscBool *bval, PetscBool *set)
FTensor::Index< 'm', 3 > m

◆ refineGeometry()

MoFEMErrorCode ElasticAdaptiveExample::refineGeometry ( )
private

Definition at line 97 of file HighOrderGeometryRef.hpp.

97 {
99 auto simple = mField.getInterface<Simple>();
100
101 CHKERR PetscOptionsGetReal(PETSC_NULLPTR, "", "-ref_geom_threshold",
102 &refGeomThreshold, PETSC_NULLPTR);
103
104 if (Tag tag_err = 0; mField.get_moab().tag_get_handle(
105 "GEOMETRY_ERROR", tag_err) == MB_SUCCESS) {
106
107 std::array<double, 2> mean_error_glob = {0.0, 0.0};
108 MPI_Allreduce(&meanError[0], &mean_error_glob[0], 2, MPI_DOUBLE, MPI_SUM,
109 mField.get_comm());
110 if (mean_error_glob[IndicInds::COUNT_ENTS] > 0) {
111 refGeomThreshold *= (mean_error_glob[IndicInds::ERROR_TOT] /
112 mean_error_glob[IndicInds::COUNT_ENTS]);
113 }
114
115 MOFEM_LOG("WORLD", Sev::inform)
116 << "Geometry refinement threshold = " << refGeomThreshold;
117
118 auto get_ents_to_refine = [&]() {
119 Range outer_ref_ents;
120
121 auto *op_ptr_ref = new BoundaryEleOp(NOSPACE, BoundaryEleOp::OPSPACE);
122 op_ptr_ref->doWorkRhsHook = [&](DataOperator *base_op_ptr, int side,
123 EntityType type,
124 EntitiesFieldData::EntData &data) {
126 auto op_ptr_ref = static_cast<BoundaryEleOp *>(base_op_ptr);
127 auto fe_ent = op_ptr_ref->getFEEntityHandle();
128 double err_measure = 0;
129 CHKERR mField.get_moab().tag_get_data(tag_err, &fe_ent, 1,
130 &err_measure);
131 if (err_measure > refGeomThreshold)
132 outer_ref_ents.insert(fe_ent);
133
135 };
136
137 auto fe = boost::make_shared<BoundaryEle>(mField);
138 fe->getOpPtrVector().push_back(op_ptr_ref);
139 auto dm = simple->getDM();
141 DMoFEMLoopFiniteElements(dm, simple->getBoundaryFEName(), fe),
142 "ref ents");
143 return outer_ref_ents;
144 };
145
146 auto ents_to_ref = get_ents_to_refine();
147
148 Range all_domain_ents;
149 CHKERR mField.get_moab().get_entities_by_handle(simple->getMeshset(),
150 all_domain_ents);
151 Range all_boundary_ents;
152 CHKERR mField.get_moab().get_entities_by_handle(
153 simple->getBoundaryMeshSet(), all_boundary_ents);
154
155 Range tets_to_refine[2];
156 CHKERR mField.get_moab().get_adjacencies(ents_to_ref, SPACE_DIM, false,
157 tets_to_refine[1],
158 moab::Interface::UNION);
159 Range ent_conn;
160 CHKERR mField.get_moab().get_adjacencies(tets_to_refine[1], SPACE_DIM - 1,
161 true, ent_conn,
162 moab::Interface::UNION);
163 CHKERR mField.getInterface<CommInterface>()->synchroniseEntities(ent_conn);
164
165 CHKERR mField.get_moab().get_adjacencies(
166 ent_conn, SPACE_DIM, true, tets_to_refine[0], moab::Interface::UNION);
167 tets_to_refine[0] = subtract(tets_to_refine[0], tets_to_refine[1]);
168
169#ifndef NDEBUG
170 CHKERR CutMeshInterface::SaveData(mField.get_moab())(
171 "ents_to_refine_ho_2.vtk", tets_to_refine[0]);
172 CHKERR CutMeshInterface::SaveData(mField.get_moab())(
173 "ents_to_refine_ho_3.vtk", tets_to_refine[1]);
174#endif
175
176 for (int i = 0; i < 2; ++i) {
177 Range ents_to_refine;
178 ents_to_refine.merge(tets_to_refine[i]);
179 for (int d = 1; d < SPACE_DIM; ++d) {
180 Range lower_dim_ents;
181 CHKERR mField.get_moab().get_adjacencies(
182 tets_to_refine[i], d, true, lower_dim_ents, moab::Interface::UNION);
183 ents_to_refine.merge(lower_dim_ents);
184 }
185 CHKERR mField.getInterface<CommInterface>()->synchroniseEntities(
186 ents_to_refine);
187
188 CHKERR simple->setFieldOrder("U", oRder + i + 1, &ents_to_refine);
189 }
190
191 CHKERR mField.getInterface<CommInterface>()->synchroniseFieldEntities("U");
192 CHKERR simple->reSetUp();
193
194 // save order on tags (volumes and boundary)
195 int orders[] = {oRder, oRder + 1, oRder + 2};
196 Tag tag_order;
197
198 CHKERR getTagHandle(mField, "ORDER", MB_TYPE_INTEGER, tag_order);
199
200 for (int i = 0; i < 2; ++i) {
201 Range adj_faces;
202 CHKERR mField.get_moab().get_adjacencies(tets_to_refine[i], SPACE_DIM - 1,
203 true, adj_faces,
204 moab::Interface::UNION);
205 CHKERR mField.getInterface<CommInterface>()->synchroniseEntities(
206 adj_faces);
207
208 adj_faces = intersect(adj_faces, all_boundary_ents);
209 CHKERR mField.get_moab().tag_clear_data(tag_order, tets_to_refine[i],
210 &orders[i + 1]);
211 CHKERR mField.get_moab().tag_clear_data(tag_order, adj_faces,
212 &orders[i + 1]);
213 }
214 }
216}
PetscErrorCode PetscOptionsGetReal(PetscOptions *, const char pre[], const char name[], PetscReal *dval, PetscBool *set)

◆ refineOrder()

MoFEMErrorCode ElasticAdaptiveExample::refineOrder ( int  ref_level)
private

Definition at line 147 of file AdaptiveOrderRef.hpp.

147 {
149 auto simple = mField.getInterface<Simple>();
150 auto comm = mField.getInterface<CommInterface>();
151
152 CHKERR PetscOptionsGetReal(PETSC_NULLPTR, "", "-ref_adapt_threshold",
153 &refAdaptThreshold, PETSC_NULLPTR);
154
155 Tag th_error_ind, th_order;
156 CHKERR getTagHandle(mField, "SOLUTION_ERROR", MB_TYPE_DOUBLE, th_error_ind);
157 CHKERR getTagHandle(mField, "ORDER", MB_TYPE_INTEGER, th_order);
158
159 std::vector<Range> refinement_levels(ref_level + 2);
160
161 Range domain_ents_part;
162 CHKERR getDomainEntsPart(mField, domain_ents_part);
163
164 for (auto ent : domain_ents_part) {
165 double err_indic = 0;
166 CHKERR mField.get_moab().tag_get_data(th_error_ind, &ent, 1, &err_indic);
167 int order;
168 CHKERR mField.get_moab().tag_get_data(th_order, &ent, 1, &order);
169
170 if (err_indic > refAdaptThreshold * errorIndicMean) {
171 order += 1;
172 refinement_levels[order - oRder].insert(ent);
173 }
174 }
175
176 for (int ll = refinement_levels.size() - 1; ll > 1; ll--) {
177 CHKERR comm->synchroniseEntities(refinement_levels[ll]);
178
179 Range face_ents;
180 CHKERR mField.get_moab().get_adjacencies(refinement_levels[ll],
181 SPACE_DIM - 1, true, face_ents,
182 moab::Interface::UNION);
183 Range tets;
184 CHKERR mField.get_moab().get_adjacencies(face_ents, SPACE_DIM, true, tets,
185 moab::Interface::UNION);
186 tets = subtract(tets, refinement_levels[ll]);
187 refinement_levels[ll - 1].merge(tets);
188 }
189
190 for (int ll = 1; ll < refinement_levels.size(); ll++) {
191
192 if (oRder + ll > 8) {
193 MOFEM_LOG("WORLD", Sev::warning)
194 << "setting approximation order higher than 8 is not currently "
195 "supported"
196 << endl;
197 } else {
198
199 for (auto ent : refinement_levels[ll]) {
200 int order = oRder + ll;
201 CHKERR mField.get_moab().tag_set_data(th_order, &ent, 1, &order);
202 }
203
204 Range ents_to_refine;
205 ents_to_refine.merge(refinement_levels[ll]);
206 for (int d = 1; d < SPACE_DIM; ++d) {
207 Range lower_dim_ents;
208 CHKERR mField.get_moab().get_adjacencies(refinement_levels[ll], d, true,
209 lower_dim_ents,
210 moab::Interface::UNION);
211 ents_to_refine.merge(lower_dim_ents);
212 }
213
214 CHKERR comm->synchroniseEntities(ents_to_refine);
215
216 CHKERR simple->setFieldOrder("U", oRder + ll, &ents_to_refine);
217 }
218 }
219
220 CHKERR copyTagOnSkin(mField, "ORDER", MB_TYPE_INTEGER);
221
222 CHKERR comm->synchroniseFieldEntities("U");
223 CHKERR simple->reSetUp();
224
226
228}
constexpr int order
virtual MoFEMErrorCode boundaryCondition()
[Set up problem]

◆ runProblem()

MoFEMErrorCode ElasticAdaptiveExample::runProblem ( )

[Run problem]

Definition at line 46 of file ElasticAdaptiveExample.hpp.

46 {
54 if (atomTest == 3)
57
58 if (refAdaptNum > 0) {
61 } else {
63 }
64
65 for (int it = 0; it < refAdaptNum; ++it) {
66 CHKERR refineOrder(it + 1);
69 if (it == refAdaptNum - 1 && atomTest == 4)
72 CHKERR outputResults(it + 1);
73 }
75}
MoFEMErrorCode computeErrorNorms()
[Postprocess results]
MoFEMErrorCode refineOrder(int ref_level)
MoFEMErrorCode computeErrorIndicators()
MoFEMErrorCode readMesh()
[Run problem]
MoFEMErrorCode setupAdaptivity()
[Read mesh]
virtual MoFEMErrorCode solveSystem()
[Solve]
virtual MoFEMErrorCode outputResults()
[Solve]
virtual MoFEMErrorCode assembleSystem()
virtual MoFEMErrorCode setupProblem()
[Read mesh]
virtual MoFEMErrorCode checkResults()
[Postprocess results]

◆ setupAdaptivity()

MoFEMErrorCode ElasticAdaptiveExample::setupAdaptivity ( )
private

[Read mesh]

[Set up problem]

Definition at line 125 of file ElasticAdaptiveExample.hpp.

125 {
127
128 Range domainEntities;
129 CHKERR mField.get_moab().get_entities_by_dimension(0, SPACE_DIM,
130 domainEntities);
131 Tag th_order;
132 CHKERR getTagHandle(mField, "ORDER", MB_TYPE_INTEGER, th_order);
133
134 CHKERR PetscOptionsGetInt(PETSC_NULLPTR, "", "-order", &oRder, PETSC_NULLPTR);
135 for (auto ent : domainEntities) {
136 CHKERR mField.get_moab().tag_set_data(th_order, &ent, 1, &oRder);
137 }
138
139 CHKERR copyTagOnSkin(mField, "ORDER", MB_TYPE_INTEGER);
140
141 if (refGeom) {
143 CHKERR refineGeometry(); // optional ho refinement
144 }
145
146 CHKERR PetscOptionsGetInt(PETSC_NULLPTR, "", "-test", &atomTest,
147 PETSC_NULLPTR);
148
150}
MoFEMErrorCode calculateGeometryError()
Calculate geometry error and save on a tag.

Member Data Documentation

◆ atomTest

int ElasticAdaptiveExample::atomTest = 0
private

Definition at line 37 of file ElasticAdaptiveExample.hpp.

◆ errorIndicMean

double ElasticAdaptiveExample::errorIndicMean = 0.0
private

Definition at line 35 of file ElasticAdaptiveExample.hpp.

◆ meanError

std::array<double, 2> ElasticAdaptiveExample::meanError = {0.0, 0.0}
private

Definition at line 34 of file ElasticAdaptiveExample.hpp.

34{0.0, 0.0};

◆ oRder

int ElasticAdaptiveExample::oRder = 2
private

Definition at line 29 of file ElasticAdaptiveExample.hpp.

◆ refAdaptNum

int ElasticAdaptiveExample::refAdaptNum = 0
private

Definition at line 31 of file ElasticAdaptiveExample.hpp.

◆ refAdaptThreshold

double ElasticAdaptiveExample::refAdaptThreshold = 1
private

Definition at line 32 of file ElasticAdaptiveExample.hpp.

◆ refGeom

PetscBool ElasticAdaptiveExample::refGeom = PETSC_FALSE
private

Definition at line 30 of file ElasticAdaptiveExample.hpp.

◆ refGeomThreshold

double ElasticAdaptiveExample::refGeomThreshold = 1
private

Definition at line 33 of file ElasticAdaptiveExample.hpp.


The documentation for this struct was generated from the following files: