v0.13.1
prism_elements_from_surface.cpp
Go to the documentation of this file.
1/** \file prism_elements_from_surface.cpp
2 \example prism_elements_from_surface.cpp
3 \brief Adding prims on the surface and checking conformity between quads,
4 triangles and prism
5
6*/
7
8
9
10#include <MoFEM.hpp>
11
12using namespace MoFEM;
13
14static char help[] = "...\n\n";
15
16static constexpr int precision_exponent = 5;
17static constexpr int number_of_prisms_layers = 18;
18static constexpr double delta =
19 1. / static_cast<double>(number_of_prisms_layers);
20static constexpr std::array<double, 3> d3 = {0, 0, 0};
21static constexpr std::array<double, 3> d4 = {0, 0, delta};
22
24
26
27 inline static double getArg(double x) {
28 return std::round(x * pow(10., precision_exponent - 1));
29 };
30
31 int x, y, z;
32 EntityHandle node;
33 CoordsAndHandle(const double *coords, EntityHandle v)
34 : x(getArg(coords[0])), y(getArg(coords[1])), z(getArg(coords[2])),
35 node(v) {}
36};
37
38typedef multi_index_container<
40 indexed_by<
41
42 hashed_unique<composite_key<
43 CoordsAndHandle, member<CoordsAndHandle, int, &CoordsAndHandle::x>,
44 member<CoordsAndHandle, int, &CoordsAndHandle::y>,
45 member<CoordsAndHandle, int, &CoordsAndHandle::z>>>
46
47 >>
49
51
52 PrismOp(moab::Interface &post_proc, MapCoords &map_coords);
55
56public:
59 std::vector<EntityHandle> nodeHandles;
60};
61
63
64 PrismFE(MoFEM::Interface &m_field, MatrixDouble &tri_coords);
65
68
69 MoFEMErrorCode setGaussPtsTrianglesOnly(int order_triangles_only);
70
72
73private:
75 EntityHandle prims;
76};
77
78template <typename OP> struct Op : public OP {
79
80 Op(moab::Interface &post_proc, MapCoords &map_coords, EntityHandle prism);
83
84public:
87 EntityHandle prism;
88 std::vector<EntityHandle> nodeHandles;
89};
90
92
93 TriFE(MoFEM::Interface &m_field, MatrixDouble &tri_coords,
94 EntityHandle prims);
95
96 int getRule(int order_row, int order_col, int order_data);
97
98 MoFEMErrorCode setGaussPts(int order_row, int order_col, int order_data);
99
100private:
102 EntityHandle prism;
103};
104
106
107 QuadFE(MoFEM::Interface &m_field, std::array<Range, 3> &edges_blocks,
108 EntityHandle prims);
109
110 int getRule(int order_row, int order_col, int order_data);
111
112 MoFEMErrorCode setGaussPts(int order_row, int order_col, int order_data);
113
114private:
115 std::array<Range, 3> &edgeBlocks;
116 EntityHandle prism;
117};
118struct EdgeFE : public EdgeEle {
119
120 EdgeFE(MoFEM::Interface &m_field, std::array<Range, 3> &edges_blocks,
121 EntityHandle prims);
122
123 int getRule(int order_row, int order_col, int order_data);
124
125 MoFEMErrorCode setGaussPts(int order_row, int order_col, int order_data);
126
127private:
128 std::array<Range, 3> &edgeBlocks;
129 EntityHandle prism;
130};
131
132int main(int argc, char *argv[]) {
133
134 MoFEM::Core::Initialize(&argc, &argv, (char *)0, help);
135
136 try {
137
138 moab::Core mb_instance;
139 moab::Interface &moab = mb_instance;
140 int rank;
141 MPI_Comm_rank(PETSC_COMM_WORLD, &rank);
142
143 // Read parameters from line command
144 PetscBool flg = PETSC_TRUE;
145 char mesh_file_name[255];
146 CHKERR PetscOptionsGetString(PETSC_NULL, "", "-my_file", mesh_file_name,
147 255, &flg);
148 if (flg != PETSC_TRUE)
149 SETERRQ(PETSC_COMM_SELF, MOFEM_INVALID_DATA,
150 "error -my_file (MESH FILE NEEDED)");
151
152 // Read mesh to MOAB
153 const char *option;
154 option = ""; //"PARALLEL=BCAST;";//;DEBUG_IO";
155 CHKERR moab.load_file(mesh_file_name, 0, option);
156
157 Range tris;
158 CHKERR moab.get_entities_by_type(0, MBTRI, tris, false);
159 Range tris_verts;
160 CHKERR moab.get_connectivity(tris, tris_verts);
161 MatrixDouble tri_coords(tris_verts.size(), 3);
162 CHKERR moab.get_coords(tris_verts, &tri_coords(0, 0));
163
164 MoFEM::Core core(moab);
165 MoFEM::Interface &m_field = core;
166
167 std::array<Range, 3> edge_block;
168 for (auto b : {1, 2, 3})
170 b, BLOCKSET, 1, edge_block[b - 1]);
171
172 PrismsFromSurfaceInterface *prisms_from_surface_interface;
173 CHKERR m_field.getInterface(prisms_from_surface_interface);
174
175 Range prisms;
176 CHKERR prisms_from_surface_interface->createPrisms(tris, prisms);
177 prisms_from_surface_interface->setThickness(prisms, d3.data(), d4.data());
178 Range add_prims_layer;
179 Range extrude_prisms = prisms;
180
181 for (int ll = 1; ll != number_of_prisms_layers; ++ll) {
182 prisms_from_surface_interface->createdVertices.clear();
183 CHKERR prisms_from_surface_interface->createPrismsFromPrisms(
184 extrude_prisms, false, add_prims_layer);
185 prisms_from_surface_interface->setThickness(add_prims_layer, d3.data(),
186 d4.data());
187 extrude_prisms = add_prims_layer;
188 prisms.merge(add_prims_layer);
189 add_prims_layer.clear();
190 }
191
192 EntityHandle meshset;
193 CHKERR moab.create_meshset(MESHSET_SET | MESHSET_TRACK_OWNER, meshset);
194 CHKERR moab.add_entities(meshset, prisms);
195
196 MapCoords map_coords;
197 Range verts;
198 CHKERR moab.get_connectivity(prisms, verts);
199 MatrixDouble coords(verts.size(), 3);
200 CHKERR moab.get_coords(verts, &coords(0, 0));
201
202 for (size_t v = 0; v != verts.size(); ++v)
203 map_coords.insert(CoordsAndHandle(&coords(v, 0), verts[v]));
204
205 EntityHandle one_prism_meshset;
206 CHKERR moab.create_meshset(MESHSET_SET | MESHSET_TRACK_OWNER,
207 one_prism_meshset);
208
209 std::array<double, 18> one_prism_coords = {0, 0, 0, 1, 0, 0, 0, 1, 0,
210 0, 0, 1, 1, 0, 1, 0, 1, 1};
211 std::array<EntityHandle, 6> one_prism_nodes;
212 for (int n = 0; n != 6; ++n)
213 CHKERR moab.create_vertex(&one_prism_coords[3 * n], one_prism_nodes[n]);
214 EntityHandle one_prism;
215 CHKERR m_field.get_moab().create_element(MBPRISM, one_prism_nodes.data(), 6,
216 one_prism);
217 Range one_prism_range;
218 one_prism_range.insert(one_prism);
219 CHKERR moab.add_entities(one_prism_meshset, one_prism_range);
220 Range one_prism_verts;
221 CHKERR moab.get_connectivity(one_prism_range, one_prism_verts);
222 CHKERR moab.add_entities(one_prism_meshset, one_prism_verts);
223 Range one_prism_adj_ents;
224 for (int d = 1; d != 3; ++d)
225 CHKERR moab.get_adjacencies(one_prism_range, d, true, one_prism_adj_ents,
226 moab::Interface::UNION);
227 CHKERR moab.add_entities(one_prism_meshset, one_prism_adj_ents);
228
229 BitRefLevel bit_level0;
230 bit_level0.set(0);
231 CHKERR m_field.getInterface<BitRefManager>()->setEntitiesBitRefLevel(
232 one_prism_range, bit_level0);
233 CHKERR prisms_from_surface_interface->seedPrismsEntities(one_prism_range,
234 bit_level0);
235
236 // Fields
237 CHKERR m_field.add_field("FIELD1", H1, AINSWORTH_LEGENDRE_BASE, 1);
238 CHKERR m_field.add_ents_to_field_by_type(one_prism_meshset, MBPRISM,
239 "FIELD1", VERY_NOISY);
240
241 CHKERR m_field.set_field_order(one_prism_meshset, MBVERTEX, "FIELD1", 1);
242 CHKERR m_field.set_field_order(one_prism_meshset, MBEDGE, "FIELD1", 5,
243 VERY_NOISY);
244 CHKERR m_field.set_field_order(one_prism_meshset, MBTRI, "FIELD1", 5);
245 CHKERR m_field.set_field_order(one_prism_meshset, MBQUAD, "FIELD1", 5,
246 VERY_NOISY);
247 CHKERR m_field.set_field_order(one_prism_meshset, MBPRISM, "FIELD1", 7,
248 VERY_NOISY);
250
251 // FE
252 CHKERR m_field.add_finite_element("PRISM");
253 CHKERR m_field.add_finite_element("EDGE");
254 CHKERR m_field.add_finite_element("TRI");
255 CHKERR m_field.add_finite_element("QUAD");
256
257 // Define rows/cols and element data
258 CHKERR m_field.modify_finite_element_add_field_row("PRISM", "FIELD1");
259 CHKERR m_field.modify_finite_element_add_field_col("PRISM", "FIELD1");
260 CHKERR m_field.modify_finite_element_add_field_data("PRISM", "FIELD1");
261 // Define rows/cols and element data
262 CHKERR m_field.modify_finite_element_add_field_row("EDGE", "FIELD1");
263 CHKERR m_field.modify_finite_element_add_field_col("EDGE", "FIELD1");
264 CHKERR m_field.modify_finite_element_add_field_data("EDGE", "FIELD1");
265 // Define rows/cols and element data
266 CHKERR m_field.modify_finite_element_add_field_row("TRI", "FIELD1");
267 CHKERR m_field.modify_finite_element_add_field_col("TRI", "FIELD1");
268 CHKERR m_field.modify_finite_element_add_field_data("TRI", "FIELD1");
269 // Define rows/cols and element data
270 CHKERR m_field.modify_finite_element_add_field_row("QUAD", "FIELD1");
271 CHKERR m_field.modify_finite_element_add_field_col("QUAD", "FIELD1");
272 CHKERR m_field.modify_finite_element_add_field_data("QUAD", "FIELD1");
273
274 CHKERR m_field.add_ents_to_finite_element_by_type(one_prism_meshset, MBEDGE,
275 "EDGE");
276 CHKERR m_field.add_ents_to_finite_element_by_type(one_prism_meshset, MBTRI,
277 "TRI");
278 CHKERR m_field.add_ents_to_finite_element_by_type(one_prism_meshset, MBQUAD,
279 "QUAD");
280 CHKERR m_field.add_ents_to_finite_element_by_type(one_prism_meshset,
281 MBPRISM, "PRISM");
282
283 // build finite elemnts
285 // //build adjacencies
286 CHKERR m_field.build_adjacencies(bit_level0);
287
288 // Problem
289 CHKERR m_field.add_problem("TEST_PROBLEM");
290
291 // set finite elements for problem
292 CHKERR m_field.modify_problem_add_finite_element("TEST_PROBLEM", "PRISM");
293 CHKERR m_field.modify_problem_add_finite_element("TEST_PROBLEM", "EDGE");
294 CHKERR m_field.modify_problem_add_finite_element("TEST_PROBLEM", "TRI");
295 CHKERR m_field.modify_problem_add_finite_element("TEST_PROBLEM", "QUAD");
296 // set refinement level for problem
297 CHKERR m_field.modify_problem_ref_level_add_bit("TEST_PROBLEM", bit_level0);
298
299 // build problem
300 ProblemsManager *prb_mng_ptr;
301 CHKERR m_field.getInterface(prb_mng_ptr);
302 CHKERR prb_mng_ptr->buildProblem("TEST_PROBLEM", true);
303 // partition
304 CHKERR prb_mng_ptr->partitionSimpleProblem("TEST_PROBLEM");
305 CHKERR prb_mng_ptr->partitionFiniteElements("TEST_PROBLEM");
306 // what are ghost nodes, see Petsc Manual
307 CHKERR prb_mng_ptr->partitionGhostDofs("TEST_PROBLEM");
308
309 PrismFE fe_prism(m_field, tri_coords);
310 fe_prism.getOpPtrVector().push_back(new PrismOp(moab, map_coords));
311 CHKERR m_field.loop_finite_elements("TEST_PROBLEM", "PRISM", fe_prism);
312
313 EdgeFE fe_edge(m_field, edge_block, one_prism);
314 fe_edge.getOpPtrVector().push_back(
316 moab, map_coords, one_prism));
317 CHKERR m_field.loop_finite_elements("TEST_PROBLEM", "EDGE", fe_edge);
318
319 TriFE fe_tri(m_field, tri_coords, one_prism);
320 fe_tri.getOpPtrVector().push_back(
322 moab, map_coords, one_prism));
323 CHKERR m_field.loop_finite_elements("TEST_PROBLEM", "TRI", fe_tri);
324
325 QuadFE fe_quad(m_field, edge_block, one_prism);
326 fe_quad.getOpPtrVector().push_back(
328 moab, map_coords, one_prism));
329 CHKERR m_field.loop_finite_elements("TEST_PROBLEM", "QUAD", fe_quad);
330
331 CHKERR moab.write_file("prism_mesh.vtk", "VTK", "", &meshset, 1);
332 CHKERR moab.write_file("one_prism_mesh.vtk", "VTK", "", &one_prism_meshset,
333 1);
334 }
336
338 return 0;
339}
340
343 "FIELD1", "FIELD1", ForcesAndSourcesCore::UserDataOperator::OPROW),
344 postProc(post_proc), mapCoords(map_coords) {}
345
348 constexpr double def_val[] = {0, 0, 0};
350 switch (type) {
351 case MBVERTEX:
352 case MBEDGE:
353 case MBTRI:
354 case MBQUAD:
355 case MBPRISM:
356 break;
357 default:
359 }
360 if (type == MBTRI && (side != 3 && side != 4))
362 if (type == MBQUAD && (side == 3 || side == 4))
364
365 const int nb_dofs = data.getIndices().size();
366 for (int dd = 0; dd != nb_dofs; ++dd)
367 data.getFieldDofs()[dd]->getFieldData() = data.getIndices()[dd];
368
369 if (type == MBVERTEX) {
370 const size_t nb_gauss_pts = getGaussPts().size2();
371 auto &coords_at_pts = getGaussPts();
372 nodeHandles.reserve(nb_gauss_pts);
373 nodeHandles.clear();
374 for (size_t gg = 0; gg != nb_gauss_pts; ++gg) {
375 auto t = boost::make_tuple(CoordsAndHandle::getArg(coords_at_pts(0, gg)),
376 CoordsAndHandle::getArg(coords_at_pts(1, gg)),
377 CoordsAndHandle::getArg(coords_at_pts(2, gg)));
378
379 auto it = mapCoords.find(t);
380 if (it != mapCoords.end())
381 nodeHandles.emplace_back(it->node);
382 else
383 SETERRQ(PETSC_COMM_SELF, MOFEM_DATA_INCONSISTENCY, "Vertex not found");
384 }
385
386 MatrixDouble node_coords(nb_gauss_pts, 3);
387 CHKERR postProc.get_coords(&nodeHandles[0], nodeHandles.size(),
388 &node_coords(0, 0));
389 for (size_t gg = 0; gg != nb_gauss_pts; ++gg) {
390 constexpr double eps = 1e-12;
391 for (auto d : {0, 1, 2})
392 if (std::abs(node_coords(gg, d) - getGaussPts()(d, gg)) > eps) {
393 SETERRQ(PETSC_COMM_SELF, MOFEM_ATOM_TEST_INVALID,
394 "Inconsistency between node coords and integration "
395 "points");
396 }
397 for (auto d : {0, 1, 2})
398 if (std::abs(node_coords(gg, d) - getCoordsAtGaussPts()(gg, d)) > eps)
399 SETERRQ(PETSC_COMM_SELF, MOFEM_ATOM_TEST_INVALID,
400 "Inconsistency between node coords and integration "
401 "points");
402 }
403
404 Tag th;
405 CHKERR postProc.tag_get_handle("Coords", 3, MB_TYPE_DOUBLE, th,
406 MB_TAG_CREAT | MB_TAG_DENSE, def_val);
407 CHKERR postProc.tag_set_data(th, &nodeHandles[0], nodeHandles.size(),
408 &getCoordsAtGaussPts()(0, 0));
409 }
410
411 auto to_str = [](auto i) { return boost::lexical_cast<std::string>(i); };
412 std::string tag_name_base =
413 "PrismType" + to_str(type) + "Side" + to_str(side);
414 std::cout << tag_name_base << endl;
415
416 MatrixDouble trans_base = trans(data.getN());
417 if (trans_base.size2() != nodeHandles.size())
418 SETERRQ2(PETSC_COMM_SELF, MOFEM_ATOM_TEST_INVALID, "wrong size %d != %d",
419 trans_base.size2(), nodeHandles.size());
420 for (size_t rr = 0; rr != trans_base.size1(); ++rr) {
421 auto tag_name = tag_name_base + "Base" + to_str(rr);
422 Tag th;
423 CHKERR postProc.tag_get_handle(tag_name.c_str(), 1, MB_TYPE_DOUBLE, th,
424 MB_TAG_CREAT | MB_TAG_DENSE, def_val);
425 CHKERR postProc.tag_set_data(th, &nodeHandles[0], nodeHandles.size(),
426 &trans_base(rr, 0));
427 }
428
430}
431
433 : FatPrismElementForcesAndSourcesCore(m_field), triCoords(tri_coords) {}
434
435int PrismFE::getRuleTrianglesOnly(int order) { return -1; };
437
440 gaussPtsTrianglesOnly.resize(3, triCoords.size1(), false);
441 gaussPtsTrianglesOnly.clear();
442 for (int gg = 0; gg != triCoords.size1(); ++gg)
443 for (int dd = 0; dd != 2; ++dd)
446}
447
452 for (int gg = 0; gg != number_of_prisms_layers + 1; ++gg)
453 gaussPtsThroughThickness(0, gg) = delta * gg;
454
456}
457
459 EntityHandle prism)
460 : FaceElementForcesAndSourcesCore(m_field), triCoords(tri_coords),
461 prism(prism) {}
462
463int TriFE::getRule(int order_row, int order_col, int order_data) { return -1; }
464
465MoFEMErrorCode TriFE::setGaussPts(int order_row, int order_col,
466 int order_data) {
468
469 const EntityHandle ent = numeredEntFiniteElementPtr->getEnt();
470 int side, sense, offset;
471 CHKERR mField.get_moab().side_number(prism, ent, side, sense, offset);
472 std::array<int, 2> swap = {0, 1};
473 if (side == 3)
474 swap = std::array<int, 2>{1, 0};
475
476 gaussPts.resize(3, triCoords.size1(), false);
477 gaussPts.clear();
478 for (int gg = 0; gg != triCoords.size1(); ++gg)
479 for (int dd = 0; dd != 2; ++dd)
480 gaussPts(dd, gg) = triCoords(gg, swap[dd]);
481
483}
484
485QuadFE::QuadFE(MoFEM::Interface &m_field, std::array<Range, 3> &edge_blocks,
486 EntityHandle prism)
487 : FaceElementForcesAndSourcesCore(m_field), edgeBlocks(edge_blocks),
488 prism(prism) {}
489
490int QuadFE::getRule(int order_row, int order_col, int order_data) { return -1; }
491
492MoFEMErrorCode QuadFE::setGaussPts(int order_row, int order_col,
493 int order_data) {
495
496 const EntityHandle ent = numeredEntFiniteElementPtr->getEnt();
497 int side, sense, offset;
498 CHKERR mField.get_moab().side_number(prism, ent, side, sense, offset);
499
500 Range edge_verts;
501 CHKERR mField.get_moab().get_connectivity(edgeBlocks[side], edge_verts);
502 MatrixDouble edge_coords(edge_verts.size(), 3);
503 CHKERR mField.get_moab().get_coords(edge_verts, &edge_coords(0, 0));
504
505 constexpr double normal[3][2] = {{-1, 0}, {-0.5, 0.5}, {0, 1}};
506 constexpr double origin[3][2] = {{1, 0}, {1, 0}, {0, 0}};
507 constexpr int swap[3][2] = {{0, 1}, {0, 1}, {1, 0}};
508 gaussPts.resize(3, edge_verts.size() * (number_of_prisms_layers + 1), false);
509 int gg = 0;
510 for (size_t rr = 0; rr != edge_verts.size(); ++rr) {
511 const double x = edge_coords(rr, 0) - origin[side][0];
512 const double y = edge_coords(rr, 1) - origin[side][1];
513 const double edge_dist = x * normal[side][0] + y * normal[side][1];
514 for (size_t cc = 0; cc != number_of_prisms_layers + 1; ++cc, ++gg) {
515 gaussPts(swap[side][0], gg) = edge_dist;
516 gaussPts(swap[side][1], gg) = delta * cc;
517 }
518 }
519
521}
522
523EdgeFE::EdgeFE(MoFEM::Interface &m_field, std::array<Range, 3> &edge_blocks,
524 EntityHandle prism)
525 : EdgeEle(m_field), edgeBlocks(edge_blocks),
526 prism(prism) {}
527
528int EdgeFE::getRule(int order_row, int order_col, int order_data) { return -1; }
529
530MoFEMErrorCode EdgeFE::setGaussPts(int order_row, int order_col,
531 int order_data) {
533
534 const EntityHandle ent = numeredEntFiniteElementPtr->getEnt();
535 int side, sense, offset;
536 CHKERR mField.get_moab().side_number(prism, ent, side, sense, offset);
537
538 if (side >= 3 && side <= 5) {
539
540 gaussPts.resize(2, number_of_prisms_layers + 1, false);
541 for (size_t gg = 0; gg != number_of_prisms_layers + 1; ++gg)
542 gaussPts(0, gg) = delta * gg;
543
544 // cerr << gaussPts << endl;
545
546 } else {
547
548 constexpr double normal[3][2] = {{1, 0}, {-0.5, 0.5}, {0, 1}};
549 constexpr double origin[3][2] = {{0, 1}, {1, 0}, {0, 0}};
550 constexpr int side_map[9] = {0, 1, 2, -1, -1, -1, 0, 1, 2};
551
552 int num_nodes;
553 const EntityHandle *conn;
554 CHKERR mField.get_moab().get_connectivity(ent, conn, num_nodes, true);
555 MatrixDouble coords(num_nodes, 3);
556 CHKERR mField.get_moab().get_coords(conn, num_nodes,
557 &*coords.data().begin());
558 side = side_map[side];
559
560 Range edge_verts;
561 CHKERR mField.get_moab().get_connectivity(edgeBlocks[side], edge_verts);
562 MatrixDouble edge_coords(edge_verts.size(), 3);
563 CHKERR mField.get_moab().get_coords(edge_verts, &edge_coords(0, 0));
564 gaussPts.resize(2, edge_verts.size(), false);
565
566 for (size_t gg = 0; gg != edge_verts.size(); ++gg) {
567 const double x = edge_coords(gg, 0) - origin[side][0];
568 const double y = edge_coords(gg, 1) - origin[side][1];
569 const double edge_dist = x * normal[side][0] + y * normal[side][1];
570 gaussPts(0, gg) = edge_dist;
571 }
572 }
573
575}
576
577template <typename OP>
578Op<OP>::Op(moab::Interface &post_proc, MapCoords &map_coords,
579 EntityHandle prism)
580 : OP("FIELD1", "FIELD1", ForcesAndSourcesCore::UserDataOperator::OPROW),
581 postProc(post_proc), mapCoords(map_coords), prism(prism) {}
582
583template <typename OP>
586 constexpr double def_val[] = {0, 0, 0};
588 switch (type) {
589 case MBVERTEX:
590 case MBEDGE:
591 case MBTRI:
592 case MBQUAD:
593 break;
594 default:
596 }
597
598 const int nb_dofs = data.getIndices().size();
599 for (int dd = 0; dd != nb_dofs; ++dd)
600 if (data.getFieldData()[dd] != data.getIndices()[dd]) {
601 std::cerr << "Indices: " << data.getIndices() << std::endl;
602 std::cerr << "Local indices: " << data.getLocalIndices() << std::endl;
603 std::cerr << "Data: " << data.getFieldData() << std::endl;
604 SETERRQ2(PETSC_COMM_SELF, MOFEM_ATOM_TEST_INVALID,
605 "Indicices/data inconsistency %3.1f != %d",
606 data.getFieldData()[dd], data.getIndices()[dd]);
607 }
608
609 const EntityHandle fe_ent = OP::getFEEntityHandle();
610 const EntityHandle ent = OP::getSideEntity(side, type);
611 int side_prism, sense, offset;
612 if (type == MBVERTEX) {
613 CHKERR postProc.side_number(prism, fe_ent, side_prism, sense, offset);
614 } else
615 CHKERR postProc.side_number(prism, ent, side_prism, sense, offset);
616
617 if (type == MBVERTEX) {
618 auto &coords_at_pts = OP::getCoordsAtGaussPts();
619 const size_t nb_gauss_pts = coords_at_pts.size1();
620
621 nodeHandles.reserve(nb_gauss_pts);
622 nodeHandles.clear();
623 for (size_t gg = 0; gg != nb_gauss_pts; ++gg) {
624 auto t = boost::make_tuple(CoordsAndHandle::getArg(coords_at_pts(gg, 0)),
625 CoordsAndHandle::getArg(coords_at_pts(gg, 1)),
626 CoordsAndHandle::getArg(coords_at_pts(gg, 2)));
627
628 auto it = mapCoords.find(t);
629 if (it != mapCoords.end())
630 nodeHandles.emplace_back(it->node);
631 else
632 SETERRQ(PETSC_COMM_SELF, MOFEM_DATA_INCONSISTENCY, "Vertex not found");
633 }
634 }
635
636 auto to_str = [](auto i) { return boost::lexical_cast<std::string>(i); };
637 std::string tag_name_base =
638 "FEType" + to_str(OP::getNumeredEntFiniteElementPtr()->getEntType()) +
639 "Type" + to_str(type) + "Side" + to_str(side_prism);
640
641 std::string tag_prism_name_base =
642 "PrismType" + to_str(type) + "Side" + to_str(side_prism);
643
644 MatrixDouble trans_base = trans(data.getN());
645 MatrixDouble prism_base(trans_base.size1(), trans_base.size2());
646 if (trans_base.size2() != nodeHandles.size())
647 SETERRQ2(PETSC_COMM_SELF, MOFEM_ATOM_TEST_INVALID, "wrong size %d != %d",
648 trans_base.size2(), nodeHandles.size());
649
650 for (size_t rr = 0; rr != trans_base.size1(); ++rr) {
651
652 std::string tag_name = tag_name_base + "Base";
653 if (type == MBVERTEX) {
654 EntityHandle node = data.getFieldDofs()[rr]->getEnt();
655 int prism_mode_side;
656 CHKERR postProc.side_number(prism, node, prism_mode_side, sense, offset);
657 tag_name += to_str(prism_mode_side);
658 } else {
659 tag_name += to_str(rr);
660 }
661
662 std::cout << tag_name << endl;
663
664 Tag th;
665 CHKERR postProc.tag_get_handle(tag_name.c_str(), 1, MB_TYPE_DOUBLE, th,
666 MB_TAG_CREAT | MB_TAG_DENSE, def_val);
667 CHKERR postProc.tag_set_data(th, &nodeHandles[0], nodeHandles.size(),
668 &trans_base(rr, 0));
669
670 if (type != MBVERTEX) {
671 auto tag_prism_name = tag_prism_name_base + "Base" + to_str(rr);
672 Tag th_prism;
673 CHKERR postProc.tag_get_handle(tag_prism_name.c_str(), th_prism);
674 CHKERR postProc.tag_get_data(th_prism, &nodeHandles[0],
675 nodeHandles.size(), &prism_base(rr, 0));
676 }
677 }
678
679 auto sum_matrix = [](MatrixDouble &m) {
680 double s = 0;
681 for (unsigned int ii = 0; ii < m.size1(); ii++) {
682 for (unsigned int jj = 0; jj < m.size2(); jj++) {
683 s += std::abs(m(ii, jj));
684 }
685 }
686 return s;
687 };
688
689 if (type != MBVERTEX) {
690 prism_base -= trans_base;
691 double sum = sum_matrix(prism_base);
692 constexpr double eps = 1e-6;
693
694 if (std::abs(sum) > eps)
695 cout << "Inconsistent base " << tag_prism_name_base << " "
696 << tag_name_base << " sum " << sum << endl;
697
698 if (std::abs(sum) > eps)
699 SETERRQ2(PETSC_COMM_SELF, MOFEM_ATOM_TEST_INVALID,
700 "Inconsistent base %s sum %6.4e", tag_prism_name_base.c_str(),
701 sum);
702 }
703
705}
ForcesAndSourcesCore::UserDataOperator UserDataOperator
static const double eps
@ VERY_NOISY
Definition: definitions.h:212
#define CATCH_ERRORS
Catch errors.
Definition: definitions.h:372
@ AINSWORTH_LEGENDRE_BASE
Ainsworth Cole (Legendre) approx. base .
Definition: definitions.h:60
#define MoFEMFunctionReturnHot(a)
Last executable line of each PETSc function used for error handling. Replaces return()
Definition: definitions.h:447
@ H1
continuous field
Definition: definitions.h:85
#define MoFEMFunctionBegin
First executable line of each MoFEM function, used for error handling. Final line of MoFEM functions ...
Definition: definitions.h:346
@ BLOCKSET
Definition: definitions.h:148
@ MOFEM_ATOM_TEST_INVALID
Definition: definitions.h:40
@ MOFEM_DATA_INCONSISTENCY
Definition: definitions.h:31
@ MOFEM_INVALID_DATA
Definition: definitions.h:36
#define MoFEMFunctionReturn(a)
Last executable line of each PETSc function used for error handling. Replaces return()
Definition: definitions.h:416
#define CHKERR
Inline error check.
Definition: definitions.h:535
static double sum_matrix(MatrixDouble &m)
FTensor::Index< 'n', SPACE_DIM > n
FTensor::Index< 'm', SPACE_DIM > m
static const double edge_coords[6][6]
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 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 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_data(const std::string &fe_name, const std::string &name_filed)=0
set finite element field data
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 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.
virtual MoFEMErrorCode loop_finite_elements(const std::string &problem_name, const std::string &fe_name, FEMethod &method, boost::shared_ptr< NumeredEntFiniteElement_multiIndex > fe_ptr=nullptr, MoFEMTypes bh=MF_EXIST, CacheTupleWeakPtr cache_ptr=CacheTupleSharedPtr(), int verb=DEFAULT_VERBOSITY)=0
Make a loop over finite elements.
MoFEMErrorCode getEntitiesByDimension(const int ms_id, const unsigned int cubit_bc_type, const int dimension, Range &entities, const bool recursive=true) const
get entities from CUBIT/meshset of a particular entity dimension
MoFEMErrorCode partitionGhostDofs(const std::string name, int verb=VERBOSE)
determine ghost nodes
MoFEMErrorCode partitionSimpleProblem(const std::string name, int verb=VERBOSE)
partition problem dofs
MoFEMErrorCode buildProblem(const std::string name, const bool square_matrix, int verb=VERBOSE)
build problem data structures
MoFEMErrorCode partitionFiniteElements(const std::string name, bool part_from_moab=false, int low_proc=-1, int hi_proc=-1, int verb=VERBOSE)
partition finite elements
virtual MoFEMErrorCode modify_problem_add_finite_element(const std::string &name_problem, const std::string &fe_name)=0
add finite element to problem, this add entities assigned to finite element to a particular problem
virtual MoFEMErrorCode add_problem(const std::string &name, enum MoFEMTypes bh=MF_EXCL, int verb=DEFAULT_VERBOSITY)=0
Add problem.
virtual MoFEMErrorCode modify_problem_ref_level_add_bit(const std::string &name_problem, const BitRefLevel &bit)=0
add ref level to problem
FTensor::Index< 'i', SPACE_DIM > i
const double v
phase velocity of light in medium (cm/ns)
char mesh_file_name[255]
FTensor::Tensor1< double, SPACE_DIM > normal(FTensor::Tensor1< T1, 3 > &t_coords, FTensor::Tensor1< T2, SPACE_DIM > &t_disp)
Definition: ContactOps.hpp:65
const Tensor1_Expr< const dTensor0< T, Dim, i >, typename promote< T, double >::V, Dim, i > d(const Tensor0< T * > &a, const Index< i, Dim > index, const Tensor1< int, Dim > &d_ijk, const Tensor1< double, Dim > &d_xyz)
Definition: dTensor0.hpp:27
const Tensor2_symmetric_Expr< const ddTensor0< T, Dim, i, j >, typename promote< T, double >::V, Dim, i, j > dd(const Tensor0< T * > &a, const Index< i, Dim > index1, const Index< j, Dim > index2, const Tensor1< int, Dim > &d_ijk, const Tensor1< double, Dim > &d_xyz)
Definition: ddTensor0.hpp:33
PetscErrorCode MoFEMErrorCode
MoFEM/PETSc error code.
Definition: Exceptions.hpp:56
std::bitset< BITREFLEVEL_SIZE > BitRefLevel
Bit structure attached to each entity identifying to what mesh entity is attached.
Definition: Types.hpp:40
implementation of Data Operators for Forces and Sources
Definition: MoFEM.hpp:24
CoreTmp< 0 > Core
Definition: Core.hpp:1086
PetscErrorCode PetscOptionsGetString(PetscOptions *, const char pre[], const char name[], char str[], size_t size, PetscBool *set)
DeprecatedCoreInterface Interface
Definition: Interface.hpp:1955
constexpr double t
plate stiffness
Definition: plate.cpp:59
int main(int argc, char *argv[])
static constexpr int number_of_prisms_layers
static constexpr int precision_exponent
static char help[]
static constexpr std::array< double, 3 > d4
static constexpr double delta
multi_index_container< CoordsAndHandle, indexed_by< hashed_unique< composite_key< CoordsAndHandle, member< CoordsAndHandle, int, &CoordsAndHandle::x >, member< CoordsAndHandle, int, &CoordsAndHandle::y >, member< CoordsAndHandle, int, &CoordsAndHandle::z > > > > > MapCoords
static constexpr std::array< double, 3 > d3
static double getArg(double x)
CoordsAndHandle(const double *coords, EntityHandle v)
std::array< Range, 3 > & edgeBlocks
EdgeFE(MoFEM::Interface &m_field, std::array< Range, 3 > &edges_blocks, EntityHandle prims)
int getRule(int order_row, int order_col, int order_data)
another variant of getRule
MoFEMErrorCode setGaussPts(int order_row, int order_col, int order_data)
set user specific integration rule
Managing BitRefLevels.
virtual moab::Interface & get_moab()=0
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.
Core (interface) class.
Definition: Core.hpp:82
static MoFEMErrorCode Initialize(int *argc, char ***args, const char file[], const char help[])
Initializes the MoFEM database PETSc, MOAB and MPI.
Definition: Core.cpp:72
static MoFEMErrorCode Finalize()
Checks for options to be called at the conclusion of the program.
Definition: Core.cpp:112
Deprecated interface functions.
Data on single entity (This is passed as argument to DataOperator::doWork)
MatrixDouble & getN(const FieldApproximationBase base)
get base functions this return matrix (nb. of rows is equal to nb. of Gauss pts, nb....
const VectorDouble & getFieldData() const
get dofs values
const VectorInt & getLocalIndices() const
get local indices of dofs on entity
const VectorDofs & getFieldDofs() const
get dofs data stature FEDofEntity
const VectorInt & getIndices() const
Get global indices of dofs on entity.
boost::shared_ptr< const NumeredEntFiniteElement > numeredEntFiniteElementPtr
structure to get information form mofem into EntitiesFieldData
boost::ptr_vector< UserDataOperator > & getOpPtrVector()
Use to push back operator for row operator.
MatrixDouble gaussPts
Matrix of integration points.
Interface for managing meshsets containing materials and boundary conditions.
std::map< EntityHandle, EntityHandle > createdVertices
MoFEMErrorCode createPrisms(const Range &ents, const SwapType swap_type, Range &prisms, int verb=-1)
Make prisms from triangles.
MoFEMErrorCode setThickness(const Range &prisms, const double director3[], const double director4[])
MoFEMErrorCode seedPrismsEntities(Range &prisms, const BitRefLevel &bit, int verb=-1)
Seed prism entities by bit level.
MoFEMErrorCode createPrismsFromPrisms(const Range &prisms, bool from_down, Range &out_prisms, int verb=-1)
Make prisms by extruding top or bottom prisms.
Problem manager is used to build and partition problems.
MoFEMErrorCode getInterface(IFACE *&iface) const
Get interface refernce to pointer of interface.
Op(moab::Interface &post_proc, MapCoords &map_coords, EntityHandle prism)
MapCoords & mapCoords
MoFEMErrorCode doWork(int side, EntityType type, EntitiesFieldData::EntData &data)
moab::Interface & postProc
EntityHandle prism
std::vector< EntityHandle > nodeHandles
int getRuleThroughThickness(int order)
PrismFE(MoFEM::Interface &m_field, MatrixDouble &tri_coords)
MoFEMErrorCode setGaussPtsTrianglesOnly(int order_triangles_only)
MoFEMErrorCode setGaussPtsThroughThickness(int order_thickness)
MatrixDouble & triCoords
int getRuleTrianglesOnly(int order)
std::vector< EntityHandle > nodeHandles
PrismOp(moab::Interface &post_proc, MapCoords &map_coords)
MoFEMErrorCode doWork(int side, EntityType type, EntitiesFieldData::EntData &data)
Operator for linear form, usually to calculate values on right hand side.
moab::Interface & postProc
std::array< Range, 3 > & edgeBlocks
int getRule(int order_row, int order_col, int order_data)
another variant of getRule
QuadFE(MoFEM::Interface &m_field, std::array< Range, 3 > &edges_blocks, EntityHandle prims)
MoFEMErrorCode setGaussPts(int order_row, int order_col, int order_data)
set user specific integration rule
MoFEMErrorCode setGaussPts(int order_row, int order_col, int order_data)
set user specific integration rule
MatrixDouble & triCoords
TriFE(MoFEM::Interface &m_field, MatrixDouble &tri_coords, EntityHandle prims)
int getRule(int order_row, int order_col, int order_data)
another variant of getRule