23 {
25
26 try {
27
28 moab::Core mb_instance;
29 moab::Interface &moab = mb_instance;
30
31
32 char mesh_file_name[255];
33 char data_file_name1[255];
34 char data_file_name2[255];
35 PetscBool flg_file = PETSC_FALSE;
37 PetscBool flg_n_part = PETSC_FALSE;
38 PetscInt n_partas = 1;
39 PetscBool flg_thickness = PETSC_FALSE;
40 PetscBool flg_legacy_thickness = PETSC_FALSE;
41 double thickness = 0;
42 double legacy_thickness = 0;
43
44 PetscOptionsBegin(PETSC_COMM_WORLD, "", "none", "none");
45 CHKERR PetscOptionsString(
"-my_file",
"mesh file name",
"",
"mesh.h5m",
46 mesh_file_name, 255, &flg_file);
47
48 CHKERR PetscOptionsString(
"-my_data_x",
"data file name",
"",
"data_x.h5m",
49 data_file_name1, 255, PETSC_NULLPTR);
50
51 CHKERR PetscOptionsString(
"-my_data_y",
"data file name",
"",
"data_y.h5m",
52 data_file_name2, 255, PETSC_NULLPTR);
53
54 CHKERR PetscOptionsInt(
"-my_order",
"default approximation order",
"", 1,
55 &
order, PETSC_NULLPTR);
56
57 CHKERR PetscOptionsInt(
"-my_nparts",
"number of parts",
"", 1, &n_partas,
58 &flg_n_part);
59
60 CHKERR PetscOptionsScalar(
"-my_thickness",
"top layer thickness",
"",
61 thickness, &thickness, &flg_thickness);
63 "-my_thinckness", "deprecated alias for -my_thickness", "",
64 legacy_thickness, &legacy_thickness, &flg_legacy_thickness);
65
66 PetscOptionsEnd();
67
68 if (flg_thickness != PETSC_TRUE &&
69 flg_legacy_thickness == PETSC_TRUE) {
70 thickness = legacy_thickness;
71 }
72
73 if (flg_file != PETSC_TRUE) {
74 SETERRQ(PETSC_COMM_SELF, 1, "*** ERROR -my_file (MESH FILE NEEDED)");
75 }
76
77 if (flg_n_part != PETSC_TRUE) {
78 SETERRQ(PETSC_COMM_SELF, 1, "*** ERROR partitioning number not given");
79 }
80
81 if (flg_thickness != PETSC_TRUE &&
82 flg_legacy_thickness != PETSC_TRUE) {
83 SETERRQ(PETSC_COMM_SELF, 1, "*** ERROR thickness of top layer not given");
84 }
85
86 const char *option;
87 option = "";
88 CHKERR moab.load_file(mesh_file_name, 0, option);
89 ParallelComm *pcomm = ParallelComm::get_pcomm(&moab,
MYPCOMM_INDEX);
90 if (pcomm == nullptr)
91 pcomm = new ParallelComm(&moab, PETSC_COMM_WORLD);
92
95
96 EntityHandle root_set = moab.get_root_set();
97
98
99
100
102 bit_level0.set(0);
104 root_set, 3, bit_level0);
105
108
110
112 CHKERR meshsets_manager_ptr->getEntitiesByDimension(101,
SIDESET, 2,
116
120
124
126
129 "DISP_X");
131 "DISP_X");
133 "DISP_X");
135 "DISP_Y");
136
137
139 "DISP_MAP_ELEMENT");
140
141
143
145
146
147 DM dm_disp;
148 DMType dm_name = "DM_DISP";
149
151 CHKERR DMCreate(PETSC_COMM_WORLD, &dm_disp);
152 CHKERR DMSetType(dm_disp, dm_name);
153
155
156
157 CHKERR DMSetFromOptions(dm_disp);
158
160
162
164
165
166
167
168 string file1(data_file_name1);
170 CHKERR data_from_files.fromOptions();
171 CHKERR data_from_files.loadFileData();
172
173 string file2(data_file_name2);
175 CHKERR data_from_files2.fromOptions();
176 CHKERR data_from_files2.loadFileData();
177
178 auto &list_of_operators = fe_face.getOpPtrVector();
179
182 CHKERR DMCreateMatrix(dm_disp, &A);
184 &Fx);
186 &Dx);
188 CHKERR VecDuplicate(Fx, &Fy);
189 CHKERR VecDuplicate(Dx, &Dy);
190
192 CHKERR VecZeroEntries(Fx);
193 CHKERR VecZeroEntries(Fy);
194
196 common_data.globA =
A;
197
198 common_data.globF = Fx;
199
200 auto det_ptr = boost::make_shared<VectorDouble>();
201 auto jac_ptr = boost::make_shared<MatrixDouble>();
202 auto inv_jac_ptr = boost::make_shared<MatrixDouble>();
204 list_of_operators.push_back(
207 list_of_operators.push_back(
208 new OpCalculateLhs(
"DISP_X",
"DISP_X", common_data, data_from_files));
209 list_of_operators.push_back(
211 list_of_operators.push_back(
new OpAssembleRhs(
"DISP_X", common_data));
212
214
215
216 CHKERR MatAssemblyBegin(A, MAT_FINAL_ASSEMBLY);
217 CHKERR MatAssemblyEnd(A, MAT_FINAL_ASSEMBLY);
218 CHKERR VecGhostUpdateBegin(Fx, ADD_VALUES, SCATTER_REVERSE);
219 CHKERR VecGhostUpdateEnd(Fx, ADD_VALUES, SCATTER_REVERSE);
220 CHKERR VecAssemblyBegin(Fx);
221 CHKERR VecAssemblyEnd(Fx);
222
223
224 common_data.globF = Fy;
225 list_of_operators.clear();
227 list_of_operators.push_back(
230 list_of_operators.push_back(
232 list_of_operators.push_back(
new OpAssembleRhs(
"DISP_X", common_data));
233
234
236
237 CHKERR VecGhostUpdateBegin(Fy, ADD_VALUES, SCATTER_REVERSE);
238 CHKERR VecGhostUpdateEnd(Fy, ADD_VALUES, SCATTER_REVERSE);
239 CHKERR VecAssemblyBegin(Fy);
240 CHKERR VecAssemblyEnd(Fy);
241
242
243
244
245
246
247
248 {
249 KSP ksp;
250 CHKERR KSPCreate(PETSC_COMM_WORLD, &ksp);
251 CHKERR KSPSetOperators(ksp, A, A);
252 CHKERR KSPSetFromOptions(ksp);
253 CHKERR KSPSolve(ksp, Fx, Dx);
254 CHKERR KSPSolve(ksp, Fy, Dy);
255 }
256
257 CHKERR VecGhostUpdateBegin(Dx, INSERT_VALUES, SCATTER_FORWARD);
258 CHKERR VecGhostUpdateEnd(Dx, INSERT_VALUES, SCATTER_FORWARD);
260 "DM_DISP",
COL, Dx, INSERT_VALUES, SCATTER_REVERSE);
261 CHKERR VecGhostUpdateBegin(Dy, INSERT_VALUES, SCATTER_FORWARD);
262 CHKERR VecGhostUpdateEnd(Dy, INSERT_VALUES, SCATTER_FORWARD);
264 "DM_DISP",
"DISP_X",
"DISP_Y",
COL, Dy, INSERT_VALUES, SCATTER_REVERSE);
265
266
267 double sum_dx = 0;
268 int nb_dx = 0;
270 MBVERTEX, dof)) {
271 sum_dx += (*dof)->getFieldData();
272 nb_dx++;
273 }
274 sum_dx /= nb_dx;
276 MBVERTEX, dof)) {
277 (*dof)->getFieldData() -= sum_dx;
278 }
279 double sum_dy = 0;
280 int nb_dy = 0;
282 MBVERTEX, dof)) {
283 sum_dy += (*dof)->getFieldData();
284 nb_dy++;
285 }
286 sum_dy /= nb_dy;
288 MBVERTEX, dof)) {
289 (*dof)->getFieldData() -= sum_dy;
290 }
291
295
298
299 auto disp_x_ptr = boost::make_shared<VectorDouble>();
300 auto disp_y_ptr = boost::make_shared<VectorDouble>();
301 post_proc.getOpPtrVector().push_back(
303 post_proc.getOpPtrVector().push_back(
305 post_proc.getOpPtrVector().push_back(
new OpPPMap(
306 post_proc.getPostProcMesh(), post_proc.getMapGaussPts(),
308 {"DISP_Y", disp_y_ptr}},
311
313 CHKERR post_proc.writeFile(
"out_disp.h5m");
314
320 CHKERR DMDestroy(&dm_disp);
321
322
324
325
326 {
328 Range ents_2nd_layer;
330 ents_2nd_layer, true);
332 CHKERR moab.get_connectivity(ents_2nd_layer, tris_nodes,
true);
333 std::map<EntityHandle, EntityHandle> map_nodes;
334 for (Range::iterator nit = tris_nodes.begin(); nit != tris_nodes.end();
335 nit++) {
336 double coords[3];
337 CHKERR moab.get_coords(&*nit, 1, coords);
338 coords[2] += thickness;
339 CHKERR moab.create_vertex(coords, map_nodes[*nit]);
340 }
341
344 for (Range::iterator tit = ents_2nd_layer.begin();
345 tit != ents_2nd_layer.end(); tit++) {
346 int num_nodes;
347 const EntityHandle *conn;
348 CHKERR moab.get_connectivity(*tit, conn, num_nodes);
349 EntityHandle conn_prism[6];
350 for (
int n = 0;
n != 3;
n++) {
351 conn_prism[
n] = conn[
n];
352 conn_prism[
n + 3] = map_nodes[conn[
n]];
353 }
354 EntityHandle prism;
355 CHKERR moab.create_element(MBPRISM, conn_prism, 6, prism);
357 CHKERR moab.get_adjacencies(&prism, 1, 2,
true, adj);
358 CHKERR moab.get_adjacencies(&prism, 1, 1,
true, adj);
359 prisms.insert(prism);
360 EntityHandle tri;
361 CHKERR moab.side_element(prism, 2, 4, tri);
362 top_tris.insert(tri);
363 }
365 CHKERR mmanager_ptr->addEntitiesToMeshset(
SIDESET, 202, top_tris);
369 mat_elastic.
data.Young = 1;
370 mat_elastic.
data.Poisson = 0;
372 mat_elastic);
373 }
374
375 {
376
378 Range ents_1st_layer;
380 ents_1st_layer, true);
381 int num_nodes;
382 const EntityHandle *conn;
383 CHKERR moab.get_connectivity(ents_1st_layer[0], conn, num_nodes);
384 Skinner skin(&moab);
386 CHKERR skin.find_skin(0, ents_1st_layer,
false, skin_edges);
388 CHKERR moab.get_adjacencies(&*ents_1st_layer.begin(), 1, 1,
false, edges);
389 EntityHandle meshset;
391 CHKERR moab.add_entities(meshset, conn, 1);
392 CHKERR moab.add_entities(meshset, skin_edges);
393 }
394
395 {
397 CHKERR moab.get_entities_by_dimension(0, 3, ents3d,
false);
399 ents3d, 3, 2, n_partas);
400 }
401
402 CHKERR moab.write_file(
"analysis_mesh.h5m");
403 }
405
407
408 PetscFunctionReturn(0);
409}
#define CATCH_ERRORS
Catch errors.
@ AINSWORTH_LEGENDRE_BASE
Ainsworth Cole (Legendre) approx. base .
#define MYPCOMM_INDEX
default communicator number PCOMM
#define CHKERR
Inline error check.
PetscErrorCode DMMoFEMAddElement(DM dm, std::string fe_name)
add element to dm
PetscErrorCode DMMoFEMCreateMoFEM(DM dm, MoFEM::Interface *m_field_ptr, const char problem_name[], const MoFEM::BitRefLevel bit_level, const MoFEM::BitRefLevel bit_mask=MoFEM::BitRefLevel().set())
Must be called by user to set MoFEM data structures.
PetscErrorCode DMRegister_MoFEM(const char sname[])
Register MoFEM problem.
PetscErrorCode DMoFEMLoopFiniteElements(DM dm, const char fe_name[], MoFEM::FEMethod *method, CacheTupleWeakPtr cache_ptr=CacheTupleSharedPtr())
Executes FEMethod for finite elements in DM.
#define _IT_GET_DOFS_FIELD_BY_NAME_AND_TYPE_FOR_LOOP_(MFIELD, NAME, TYPE, IT)
loop over all dofs from a moFEM field and particular field
virtual MoFEMErrorCode add_finite_element(const std::string &fe_name, enum MoFEMTypes bh=MF_EXCL, int verb=DEFAULT_VERBOSITY)=0
add finite element
virtual MoFEMErrorCode build_finite_elements(int verb=DEFAULT_VERBOSITY)=0
Build finite elements.
virtual MoFEMErrorCode modify_finite_element_add_field_col(const std::string &fe_name, const std::string name_row)=0
set field col which finite element use
virtual MoFEMErrorCode add_ents_to_finite_element_by_type(const EntityHandle entities, const EntityType type, const std::string name, const bool recursive=true)=0
add entities to finite element
virtual MoFEMErrorCode modify_finite_element_add_field_row(const std::string &fe_name, const std::string name_row)=0
set field row which finite element use
virtual MoFEMErrorCode modify_finite_element_add_field_data(const std::string &fe_name, const std::string name_field)=0
set finite element field data
virtual MoFEMErrorCode build_fields(int verb=DEFAULT_VERBOSITY)=0
virtual MoFEMErrorCode set_field_order(const EntityHandle meshset, const EntityType type, const std::string &name, const ApproximationOrder order, int verb=DEFAULT_VERBOSITY)=0
Set order approximation of the entities in the field.
virtual MoFEMErrorCode add_ents_to_field_by_type(const Range &ents, const EntityType type, const std::string &name, int verb=DEFAULT_VERBOSITY)=0
Add entities to field meshset.
const double n
refractive index of diffusive medium
const FTensor::Tensor2< T, Dim, Dim > Vec
std::bitset< BITREFLEVEL_SIZE > BitRefLevel
Bit structure attached to each entity identifying to what mesh entity is attached.
OpCalculateHOJacForFaceImpl< 2 > OpCalculateHOJacForFace
OpPostProcMapInMoab< SPACE_DIM, SPACE_DIM > OpPPMap
Add operators pushing bases from local to physical configuration.
virtual MoFEMErrorCode build_adjacencies(const Range &ents, int verb=DEFAULT_VERBOSITY)=0
build adjacencies
virtual MoFEMErrorCode add_field(const std::string name, const FieldSpace space, const FieldApproximationBase base, const FieldCoefficientsNumber nb_of_coefficients, const TagType tag_type=MB_TAG_SPARSE, const enum MoFEMTypes bh=MF_EXCL, int verb=DEFAULT_VERBOSITY)=0
Add field.
virtual MoFEMErrorCode delete_finite_element(const std::string name, int verb=DEFAULT_VERBOSITY)=0
Delete finite element from MoFEM database.
static MoFEMErrorCode Initialize(int *argc, char ***args, const char file[], const char help[])
Initializes the MoFEM database PETSc, MOAB and MPI.
static MoFEMErrorCode Finalize()
Checks for options to be called at the conclusion of the program.
Deprecated interface functions.
Elastic material data structure.
Interface for managing meshsets containing materials and boundary conditions.
Specialization for double precision scalar field values calculation.
Operator for inverting matrices at integration points.
Post post-proc data at points from hash maps.
std::map< std::string, ScalarDataPtr > DataMapVec
std::map< std::string, boost::shared_ptr< MatrixDouble > > DataMapMat
MoFEMErrorCode getInterface(IFACE *&iface) const
Get interface reference to pointer of interface.
Vector manager is used to create vectors \mofem_vectors.