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;
42 PetscOptionsBegin(PETSC_COMM_WORLD,
"",
"none",
"none");
43 CHKERR PetscOptionsString(
"-my_file",
"mesh file name",
"",
"mesh.h5m",
44 mesh_file_name, 255, &flg_file);
46 CHKERR PetscOptionsString(
"-my_data_x",
"data file name",
"",
"data_x.h5m",
47 data_file_name1, 255, PETSC_NULLPTR);
49 CHKERR PetscOptionsString(
"-my_data_y",
"data file name",
"",
"data_y.h5m",
50 data_file_name2, 255, PETSC_NULLPTR);
52 CHKERR PetscOptionsInt(
"-my_order",
"default approximation order",
"", 1,
53 &
order, PETSC_NULLPTR);
55 CHKERR PetscOptionsInt(
"-my_nparts",
"number of parts",
"", 1, &n_partas,
58 CHKERR PetscOptionsScalar(
"-my_thinckness",
"top layer thickness",
"",
59 thickness, &thickness, &flg_thickness);
63 if (flg_file != PETSC_TRUE) {
64 SETERRQ(PETSC_COMM_SELF, 1,
"*** ERROR -my_file (MESH FILE NEEDED)");
67 if (flg_n_part != PETSC_TRUE) {
68 SETERRQ(PETSC_COMM_SELF, 1,
"*** ERROR partitioning number not given");
71 if (flg_thickness != PETSC_TRUE) {
72 SETERRQ(PETSC_COMM_SELF, 1,
"*** ERROR thickness of top layer not given");
77 CHKERR moab.load_file(mesh_file_name, 0, option);
78 ParallelComm *pcomm = ParallelComm::get_pcomm(&moab,
MYPCOMM_INDEX);
80 pcomm =
new ParallelComm(&moab, PETSC_COMM_WORLD);
93 root_set, 3, bit_level0);
101 CHKERR meshsets_manager_ptr->getEntitiesByDimension(101,
SIDESET, 2,
137 DMType dm_name =
"DM_DISP";
140 CHKERR DMCreate(PETSC_COMM_WORLD, &dm_disp);
141 CHKERR DMSetType(dm_disp, dm_name);
146 CHKERR DMSetFromOptions(dm_disp);
157 string file1(data_file_name1);
162 string file2(data_file_name2);
171 CHKERR DMCreateMatrix(dm_disp, &
A);
177 CHKERR VecDuplicate(Fx, &Fy);
178 CHKERR VecDuplicate(Dx, &Dy);
181 CHKERR VecZeroEntries(Fx);
182 CHKERR VecZeroEntries(Fy);
185 common_data.globA =
A;
187 common_data.globF = Fx;
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));
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);
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));
226 CHKERR VecGhostUpdateBegin(Fy, ADD_VALUES, SCATTER_REVERSE);
227 CHKERR VecGhostUpdateEnd(Fy, ADD_VALUES, SCATTER_REVERSE);
228 CHKERR VecAssemblyBegin(Fy);
229 CHKERR VecAssemblyEnd(Fy);
239 CHKERR KSPCreate(PETSC_COMM_WORLD, &ksp);
241 CHKERR KSPSetFromOptions(ksp);
242 CHKERR KSPSolve(ksp, Fx, Dx);
243 CHKERR KSPSolve(ksp, Fy, Dy);
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);
260 sum_dx += (*dof)->getFieldData();
266 (*dof)->getFieldData() -= sum_dx;
272 sum_dy += (*dof)->getFieldData();
278 (*dof)->getFieldData() -= sum_dy;
288 auto disp_x_ptr = boost::make_shared<VectorDouble>();
289 auto disp_y_ptr = boost::make_shared<VectorDouble>();
297 {
"DISP_Y", disp_y_ptr}},
302 CHKERR post_proc.writeFile(
"out_disp.h5m");
309 CHKERR DMDestroy(&dm_disp);
312 CHKERR m_field.delete_finite_element(
"DISP_MAP_ELEMENT");
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();
326 CHKERR moab.get_coords(&*nit, 1, coords);
327 coords[2] += thickness;
328 CHKERR moab.create_vertex(coords, map_nodes[*nit]);
333 for (Range::iterator tit = ents_2nd_layer.begin();
334 tit != ents_2nd_layer.end(); tit++) {
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]];
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);
354 CHKERR mmanager_ptr->addEntitiesToMeshset(
SIDESET, 202, top_tris);
358 mat_elastic.
data.Young = 1;
359 mat_elastic.
data.Poisson = 0;
367 Range ents_1st_layer;
369 ents_1st_layer,
true);
372 CHKERR moab.get_connectivity(ents_1st_layer[0], conn, num_nodes);
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);
386 CHKERR moab.get_entities_by_dimension(0, 3, ents3d,
false);
388 ents3d, 3, 2, n_partas);
391 CHKERR moab.write_file(
"analysis_mesh.h5m");
397 PetscFunctionReturn(0);