23int main(
int argc,
char *argv[]) {
28 moab::Core mb_instance;
29 moab::Interface &moab = mb_instance;
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;
42 double legacy_thickness = 0;
44 PetscOptionsBegin(PETSC_COMM_WORLD,
"",
"none",
"none");
45 CHKERR PetscOptionsString(
"-my_file",
"mesh file name",
"",
"mesh.h5m",
46 mesh_file_name, 255, &flg_file);
48 CHKERR PetscOptionsString(
"-my_data_x",
"data file name",
"",
"data_x.h5m",
49 data_file_name1, 255, PETSC_NULLPTR);
51 CHKERR PetscOptionsString(
"-my_data_y",
"data file name",
"",
"data_y.h5m",
52 data_file_name2, 255, PETSC_NULLPTR);
54 CHKERR PetscOptionsInt(
"-my_order",
"default approximation order",
"", 1,
55 &
order, PETSC_NULLPTR);
57 CHKERR PetscOptionsInt(
"-my_nparts",
"number of parts",
"", 1, &n_partas,
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);
68 if (flg_thickness != PETSC_TRUE &&
69 flg_legacy_thickness == PETSC_TRUE) {
70 thickness = legacy_thickness;
73 if (flg_file != PETSC_TRUE) {
74 SETERRQ(PETSC_COMM_SELF, 1,
"*** ERROR -my_file (MESH FILE NEEDED)");
77 if (flg_n_part != PETSC_TRUE) {
78 SETERRQ(PETSC_COMM_SELF, 1,
"*** ERROR partitioning number not given");
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");
88 CHKERR moab.load_file(mesh_file_name, 0, option);
89 ParallelComm *pcomm = ParallelComm::get_pcomm(&moab,
MYPCOMM_INDEX);
91 pcomm =
new ParallelComm(&moab, PETSC_COMM_WORLD);
96 EntityHandle root_set = moab.get_root_set();
104 root_set, 3, bit_level0);
112 CHKERR meshsets_manager_ptr->getEntitiesByDimension(101,
SIDESET, 2,
148 DMType dm_name =
"DM_DISP";
151 CHKERR DMCreate(PETSC_COMM_WORLD, &dm_disp);
152 CHKERR DMSetType(dm_disp, dm_name);
157 CHKERR DMSetFromOptions(dm_disp);
168 string file1(data_file_name1);
173 string file2(data_file_name2);
182 CHKERR DMCreateMatrix(dm_disp, &
A);
188 CHKERR VecDuplicate(Fx, &Fy);
189 CHKERR VecDuplicate(Dx, &Dy);
192 CHKERR VecZeroEntries(Fx);
193 CHKERR VecZeroEntries(Fy);
196 common_data.globA =
A;
198 common_data.globF = Fx;
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));
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);
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));
237 CHKERR VecGhostUpdateBegin(Fy, ADD_VALUES, SCATTER_REVERSE);
238 CHKERR VecGhostUpdateEnd(Fy, ADD_VALUES, SCATTER_REVERSE);
239 CHKERR VecAssemblyBegin(Fy);
240 CHKERR VecAssemblyEnd(Fy);
250 CHKERR KSPCreate(PETSC_COMM_WORLD, &ksp);
252 CHKERR KSPSetFromOptions(ksp);
253 CHKERR KSPSolve(ksp, Fx, Dx);
254 CHKERR KSPSolve(ksp, Fy, Dy);
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);
271 sum_dx += (*dof)->getFieldData();
277 (*dof)->getFieldData() -= sum_dx;
283 sum_dy += (*dof)->getFieldData();
289 (*dof)->getFieldData() -= sum_dy;
299 auto disp_x_ptr = boost::make_shared<VectorDouble>();
300 auto disp_y_ptr = boost::make_shared<VectorDouble>();
308 {
"DISP_Y", disp_y_ptr}},
313 CHKERR post_proc.writeFile(
"out_disp.h5m");
320 CHKERR DMDestroy(&dm_disp);
323 CHKERR m_field.delete_finite_element(
"DISP_MAP_ELEMENT");
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();
337 CHKERR moab.get_coords(&*nit, 1, coords);
338 coords[2] += thickness;
339 CHKERR moab.create_vertex(coords, map_nodes[*nit]);
344 for (Range::iterator tit = ents_2nd_layer.begin();
345 tit != ents_2nd_layer.end(); tit++) {
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]];
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);
361 CHKERR moab.side_element(prism, 2, 4, tri);
362 top_tris.insert(tri);
365 CHKERR mmanager_ptr->addEntitiesToMeshset(
SIDESET, 202, top_tris);
369 mat_elastic.
data.Young = 1;
370 mat_elastic.
data.Poisson = 0;
378 Range ents_1st_layer;
380 ents_1st_layer,
true);
382 const EntityHandle *conn;
383 CHKERR moab.get_connectivity(ents_1st_layer[0], conn, num_nodes);
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);
397 CHKERR moab.get_entities_by_dimension(0, 3, ents3d,
false);
399 ents3d, 3, 2, n_partas);
402 CHKERR moab.write_file(
"analysis_mesh.h5m");
408 PetscFunctionReturn(0);