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 double thickness = 0;
41
42 PetscOptionsBegin(PETSC_COMM_WORLD, "", "none", "none");
43 CHKERR PetscOptionsString(
"-my_file",
"mesh file name",
"",
"mesh.h5m",
44 mesh_file_name, 255, &flg_file);
45
46 CHKERR PetscOptionsString(
"-my_data_x",
"data file name",
"",
"data_x.h5m",
47 data_file_name1, 255, PETSC_NULLPTR);
48
49 CHKERR PetscOptionsString(
"-my_data_y",
"data file name",
"",
"data_y.h5m",
50 data_file_name2, 255, PETSC_NULLPTR);
51
52 CHKERR PetscOptionsInt(
"-my_order",
"default approximation order",
"", 1,
53 &
order, PETSC_NULLPTR);
54
55 CHKERR PetscOptionsInt(
"-my_nparts",
"number of parts",
"", 1, &n_partas,
56 &flg_n_part);
57
58 CHKERR PetscOptionsScalar(
"-my_thinckness",
"top layer thickness",
"",
59 thickness, &thickness, &flg_thickness);
60
61 PetscOptionsEnd();
62
63 if (flg_file != PETSC_TRUE) {
64 SETERRQ(PETSC_COMM_SELF, 1, "*** ERROR -my_file (MESH FILE NEEDED)");
65 }
66
67 if (flg_n_part != PETSC_TRUE) {
68 SETERRQ(PETSC_COMM_SELF, 1, "*** ERROR partitioning number not given");
69 }
70
71 if (flg_thickness != PETSC_TRUE) {
72 SETERRQ(PETSC_COMM_SELF, 1, "*** ERROR thickness of top layer not given");
73 }
74
75 const char *option;
76 option = "";
77 CHKERR moab.load_file(mesh_file_name, 0, option);
78 ParallelComm *pcomm = ParallelComm::get_pcomm(&moab,
MYPCOMM_INDEX);
79 if (pcomm == nullptr)
80 pcomm = new ParallelComm(&moab, PETSC_COMM_WORLD);
81
84
86
87
88
89
91 bit_level0.set(0);
93 root_set, 3, bit_level0);
94
97
99
101 CHKERR meshsets_manager_ptr->getEntitiesByDimension(101,
SIDESET, 2,
105
109
113
115
118 "DISP_X");
120 "DISP_X");
122 "DISP_X");
124 "DISP_Y");
125
126
128 "DISP_MAP_ELEMENT");
129
130
132
134
135
136 DM dm_disp;
137 DMType dm_name = "DM_DISP";
138
140 CHKERR DMCreate(PETSC_COMM_WORLD, &dm_disp);
141 CHKERR DMSetType(dm_disp, dm_name);
142
144
145
146 CHKERR DMSetFromOptions(dm_disp);
147
149
151
153
154
155
156
157 string file1(data_file_name1);
159 CHKERR data_from_files.fromOptions();
160 CHKERR data_from_files.loadFileData();
161
162 string file2(data_file_name2);
164 CHKERR data_from_files2.fromOptions();
165 CHKERR data_from_files2.loadFileData();
166
167 auto &list_of_operators = fe_face.getOpPtrVector();
168
171 CHKERR DMCreateMatrix(dm_disp, &A);
173 &Fx);
175 &Dx);
177 CHKERR VecDuplicate(Fx, &Fy);
178 CHKERR VecDuplicate(Dx, &Dy);
179
181 CHKERR VecZeroEntries(Fx);
182 CHKERR VecZeroEntries(Fy);
183
185 common_data.globA =
A;
186
187 common_data.globF = Fx;
188
189 auto det_ptr = boost::make_shared<VectorDouble>();
190 auto jac_ptr = boost::make_shared<MatrixDouble>();
191 auto inv_jac_ptr = boost::make_shared<MatrixDouble>();
193 list_of_operators.push_back(
196 list_of_operators.push_back(
197 new OpCalculateLhs(
"DISP_X",
"DISP_X", common_data, data_from_files));
198 list_of_operators.push_back(
200 list_of_operators.push_back(
new OpAssembleRhs(
"DISP_X", common_data));
201
203
204
205 CHKERR MatAssemblyBegin(A, MAT_FINAL_ASSEMBLY);
206 CHKERR MatAssemblyEnd(A, MAT_FINAL_ASSEMBLY);
207 CHKERR VecGhostUpdateBegin(Fx, ADD_VALUES, SCATTER_REVERSE);
208 CHKERR VecGhostUpdateEnd(Fx, ADD_VALUES, SCATTER_REVERSE);
209 CHKERR VecAssemblyBegin(Fx);
210 CHKERR VecAssemblyEnd(Fx);
211
212
213 common_data.globF = Fy;
214 list_of_operators.clear();
216 list_of_operators.push_back(
219 list_of_operators.push_back(
221 list_of_operators.push_back(
new OpAssembleRhs(
"DISP_X", common_data));
222
223
225
226 CHKERR VecGhostUpdateBegin(Fy, ADD_VALUES, SCATTER_REVERSE);
227 CHKERR VecGhostUpdateEnd(Fy, ADD_VALUES, SCATTER_REVERSE);
228 CHKERR VecAssemblyBegin(Fy);
229 CHKERR VecAssemblyEnd(Fy);
230
231
232
233
234
235
236
237 {
238 KSP ksp;
239 CHKERR KSPCreate(PETSC_COMM_WORLD, &ksp);
240 CHKERR KSPSetOperators(ksp, A, A);
241 CHKERR KSPSetFromOptions(ksp);
242 CHKERR KSPSolve(ksp, Fx, Dx);
243 CHKERR KSPSolve(ksp, Fy, Dy);
244 }
245
246 CHKERR VecGhostUpdateBegin(Dx, INSERT_VALUES, SCATTER_FORWARD);
247 CHKERR VecGhostUpdateEnd(Dx, INSERT_VALUES, SCATTER_FORWARD);
249 "DM_DISP",
COL, Dx, INSERT_VALUES, SCATTER_REVERSE);
250 CHKERR VecGhostUpdateBegin(Dy, INSERT_VALUES, SCATTER_FORWARD);
251 CHKERR VecGhostUpdateEnd(Dy, INSERT_VALUES, SCATTER_FORWARD);
253 "DM_DISP",
"DISP_X",
"DISP_Y",
COL, Dy, INSERT_VALUES, SCATTER_REVERSE);
254
255
256 double sum_dx = 0;
257 int nb_dx = 0;
259 MBVERTEX, dof)) {
260 sum_dx += (*dof)->getFieldData();
261 nb_dx++;
262 }
263 sum_dx /= nb_dx;
265 MBVERTEX, dof)) {
266 (*dof)->getFieldData() -= sum_dx;
267 }
268 double sum_dy = 0;
269 int nb_dy = 0;
271 MBVERTEX, dof)) {
272 sum_dy += (*dof)->getFieldData();
273 nb_dy++;
274 }
275 sum_dy /= nb_dy;
277 MBVERTEX, dof)) {
278 (*dof)->getFieldData() -= sum_dy;
279 }
280
284
287
288 auto disp_x_ptr = boost::make_shared<VectorDouble>();
289 auto disp_y_ptr = boost::make_shared<VectorDouble>();
290 post_proc.getOpPtrVector().push_back(
292 post_proc.getOpPtrVector().push_back(
294 post_proc.getOpPtrVector().push_back(
new OpPPMap(
295 post_proc.getPostProcMesh(), post_proc.getMapGaussPts(),
297 {"DISP_Y", disp_y_ptr}},
300
302 CHKERR post_proc.writeFile(
"out_disp.h5m");
303
309 CHKERR DMDestroy(&dm_disp);
310
311
313
314
315 {
317 Range ents_2nd_layer;
319 ents_2nd_layer, true);
321 CHKERR moab.get_connectivity(ents_2nd_layer, tris_nodes,
true);
322 std::map<EntityHandle, EntityHandle> map_nodes;
323 for (Range::iterator nit = tris_nodes.begin(); nit != tris_nodes.end();
324 nit++) {
325 double coords[3];
326 CHKERR moab.get_coords(&*nit, 1, coords);
327 coords[2] += thickness;
328 CHKERR moab.create_vertex(coords, map_nodes[*nit]);
329 }
330
333 for (Range::iterator tit = ents_2nd_layer.begin();
334 tit != ents_2nd_layer.end(); tit++) {
335 int num_nodes;
337 CHKERR moab.get_connectivity(*tit, conn, num_nodes);
339 for (
int n = 0;
n != 3;
n++) {
340 conn_prism[
n] = conn[
n];
341 conn_prism[
n + 3] = map_nodes[conn[
n]];
342 }
344 CHKERR moab.create_element(MBPRISM, conn_prism, 6, prism);
346 CHKERR moab.get_adjacencies(&prism, 1, 2,
true, adj);
347 CHKERR moab.get_adjacencies(&prism, 1, 1,
true, adj);
348 prisms.insert(prism);
350 CHKERR moab.side_element(prism, 2, 4, tri);
351 top_tris.insert(tri);
352 }
354 CHKERR mmanager_ptr->addEntitiesToMeshset(
SIDESET, 202, top_tris);
358 mat_elastic.
data.Young = 1;
359 mat_elastic.
data.Poisson = 0;
361 mat_elastic);
362 }
363
364 {
365
367 Range ents_1st_layer;
369 ents_1st_layer, true);
370 int num_nodes;
372 CHKERR moab.get_connectivity(ents_1st_layer[0], conn, num_nodes);
373 Skinner skin(&moab);
375 CHKERR skin.find_skin(0, ents_1st_layer,
false, skin_edges);
377 CHKERR moab.get_adjacencies(&*ents_1st_layer.begin(), 1, 1,
false, edges);
380 CHKERR moab.add_entities(meshset, conn, 1);
381 CHKERR moab.add_entities(meshset, skin_edges);
382 }
383
384 {
386 CHKERR moab.get_entities_by_dimension(0, 3, ents3d,
false);
388 ents3d, 3, 2, n_partas);
389 }
390
391 CHKERR moab.write_file(
"analysis_mesh.h5m");
392 }
394
396
397 PetscFunctionReturn(0);
398}
#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.