v0.13.0
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 /* This file is part of MoFEM.
9  * MoFEM is free software: you can redistribute it and/or modify it under
10  * the terms of the GNU Lesser General Public License as published by the
11  * Free Software Foundation, either version 3 of the License, or (at your
12  * option) any later version.
13  *
14  * MoFEM is distributed in the hope that it will be useful, but WITHOUT
15  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
16  * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
17  * License for more details.
18  *
19  * You should have received a copy of the GNU Lesser General Public
20  * License along with MoFEM. If not, see <http://www.gnu.org/licenses/>. */
21 
22 #include <MoFEM.hpp>
23 
24 using namespace MoFEM;
25 
26 static char help[] = "...\n\n";
27 
28 static constexpr int precision_exponent = 5;
29 static constexpr int number_of_prisms_layers = 18;
30 static constexpr double delta =
31  1. / static_cast<double>(number_of_prisms_layers);
32 static constexpr std::array<double, 3> d3 = {0, 0, 0};
33 static constexpr std::array<double, 3> d4 = {0, 0, delta};
34 
36 
38 
39  inline static double getArg(double x) {
40  return std::round(x * pow(10., precision_exponent - 1));
41  };
42 
43  int x, y, z;
45  CoordsAndHandle(const double *coords, EntityHandle v)
46  : x(getArg(coords[0])), y(getArg(coords[1])), z(getArg(coords[2])),
47  node(v) {}
48 };
49 
50 typedef multi_index_container<
52  indexed_by<
53 
54  hashed_unique<composite_key<
55  CoordsAndHandle, member<CoordsAndHandle, int, &CoordsAndHandle::x>,
56  member<CoordsAndHandle, int, &CoordsAndHandle::y>,
57  member<CoordsAndHandle, int, &CoordsAndHandle::z>>>
58 
59  >>
61 
63 
64  PrismOp(moab::Interface &post_proc, MapCoords &map_coords);
65  MoFEMErrorCode doWork(int side, EntityType type,
67 
68 public:
71  std::vector<EntityHandle> nodeHandles;
72 };
73 
75 
76  PrismFE(MoFEM::Interface &m_field, MatrixDouble &tri_coords);
77 
78  int getRuleTrianglesOnly(int order);
79  int getRuleThroughThickness(int order);
80 
81  MoFEMErrorCode setGaussPtsTrianglesOnly(int order_triangles_only);
82 
83  MoFEMErrorCode setGaussPtsThroughThickness(int order_thickness);
84 
85 private:
88 };
89 
90 template <typename OP> struct Op : public OP {
91 
92  Op(moab::Interface &post_proc, MapCoords &map_coords, EntityHandle prism);
93  MoFEMErrorCode doWork(int side, EntityType type,
95 
96 public:
100  std::vector<EntityHandle> nodeHandles;
101 };
102 
104 
105  TriFE(MoFEM::Interface &m_field, MatrixDouble &tri_coords,
106  EntityHandle prims);
107 
108  int getRule(int order_row, int order_col, int order_data);
109 
110  MoFEMErrorCode setGaussPts(int order_row, int order_col, int order_data);
111 
112 private:
115 };
116 
118 
119  QuadFE(MoFEM::Interface &m_field, std::array<Range, 3> &edges_blocks,
120  EntityHandle prims);
121 
122  int getRule(int order_row, int order_col, int order_data);
123 
124  MoFEMErrorCode setGaussPts(int order_row, int order_col, int order_data);
125 
126 private:
127  std::array<Range, 3> &edgeBlocks;
129 };
130 struct EdgeFE : public EdgeEle {
131 
132  EdgeFE(MoFEM::Interface &m_field, std::array<Range, 3> &edges_blocks,
133  EntityHandle prims);
134 
135  int getRule(int order_row, int order_col, int order_data);
136 
137  MoFEMErrorCode setGaussPts(int order_row, int order_col, int order_data);
138 
139 private:
140  std::array<Range, 3> &edgeBlocks;
142 };
143 
144 int main(int argc, char *argv[]) {
145 
146  MoFEM::Core::Initialize(&argc, &argv, (char *)0, help);
147 
148  try {
149 
150  moab::Core mb_instance;
151  moab::Interface &moab = mb_instance;
152  int rank;
153  MPI_Comm_rank(PETSC_COMM_WORLD, &rank);
154 
155  // Read parameters from line command
156  PetscBool flg = PETSC_TRUE;
157  char mesh_file_name[255];
158  CHKERR PetscOptionsGetString(PETSC_NULL, "", "-my_file", mesh_file_name,
159  255, &flg);
160  if (flg != PETSC_TRUE)
161  SETERRQ(PETSC_COMM_SELF, MOFEM_INVALID_DATA,
162  "error -my_file (MESH FILE NEEDED)");
163 
164  // Read mesh to MOAB
165  const char *option;
166  option = ""; //"PARALLEL=BCAST;";//;DEBUG_IO";
167  CHKERR moab.load_file(mesh_file_name, 0, option);
168 
169  Range tris;
170  CHKERR moab.get_entities_by_type(0, MBTRI, tris, false);
171  Range tris_verts;
172  CHKERR moab.get_connectivity(tris, tris_verts);
173  MatrixDouble tri_coords(tris_verts.size(), 3);
174  CHKERR moab.get_coords(tris_verts, &tri_coords(0, 0));
175 
176  MoFEM::Core core(moab);
177  MoFEM::Interface &m_field = core;
178 
179  std::array<Range, 3> edge_block;
180  for (auto b : {1, 2, 3})
182  b, BLOCKSET, 1, edge_block[b - 1]);
183 
184  PrismsFromSurfaceInterface *prisms_from_surface_interface;
185  CHKERR m_field.getInterface(prisms_from_surface_interface);
186 
187  Range prisms;
188  CHKERR prisms_from_surface_interface->createPrisms(tris, prisms);
189  prisms_from_surface_interface->setThickness(prisms, d3.data(), d4.data());
190  Range add_prims_layer;
191  Range extrude_prisms = prisms;
192 
193  for (int ll = 1; ll != number_of_prisms_layers; ++ll) {
194  prisms_from_surface_interface->createdVertices.clear();
195  CHKERR prisms_from_surface_interface->createPrismsFromPrisms(
196  extrude_prisms, false, add_prims_layer);
197  prisms_from_surface_interface->setThickness(add_prims_layer, d3.data(),
198  d4.data());
199  extrude_prisms = add_prims_layer;
200  prisms.merge(add_prims_layer);
201  add_prims_layer.clear();
202  }
203 
204  EntityHandle meshset;
205  CHKERR moab.create_meshset(MESHSET_SET | MESHSET_TRACK_OWNER, meshset);
206  CHKERR moab.add_entities(meshset, prisms);
207 
208  MapCoords map_coords;
209  Range verts;
210  CHKERR moab.get_connectivity(prisms, verts);
211  MatrixDouble coords(verts.size(), 3);
212  CHKERR moab.get_coords(verts, &coords(0, 0));
213 
214  for (size_t v = 0; v != verts.size(); ++v)
215  map_coords.insert(CoordsAndHandle(&coords(v, 0), verts[v]));
216 
217  EntityHandle one_prism_meshset;
218  CHKERR moab.create_meshset(MESHSET_SET | MESHSET_TRACK_OWNER,
219  one_prism_meshset);
220 
221  std::array<double, 18> one_prism_coords = {0, 0, 0, 1, 0, 0, 0, 1, 0,
222  0, 0, 1, 1, 0, 1, 0, 1, 1};
223  std::array<EntityHandle, 6> one_prism_nodes;
224  for (int n = 0; n != 6; ++n)
225  CHKERR moab.create_vertex(&one_prism_coords[3 * n], one_prism_nodes[n]);
226  EntityHandle one_prism;
227  CHKERR m_field.get_moab().create_element(MBPRISM, one_prism_nodes.data(), 6,
228  one_prism);
229  Range one_prism_range;
230  one_prism_range.insert(one_prism);
231  CHKERR moab.add_entities(one_prism_meshset, one_prism_range);
232  Range one_prism_verts;
233  CHKERR moab.get_connectivity(one_prism_range, one_prism_verts);
234  CHKERR moab.add_entities(one_prism_meshset, one_prism_verts);
235  Range one_prism_adj_ents;
236  for (int d = 1; d != 3; ++d)
237  CHKERR moab.get_adjacencies(one_prism_range, d, true, one_prism_adj_ents,
238  moab::Interface::UNION);
239  CHKERR moab.add_entities(one_prism_meshset, one_prism_adj_ents);
240 
241  BitRefLevel bit_level0;
242  bit_level0.set(0);
243  CHKERR m_field.getInterface<BitRefManager>()->setEntitiesBitRefLevel(
244  one_prism_range, bit_level0);
245  CHKERR prisms_from_surface_interface->seedPrismsEntities(one_prism_range,
246  bit_level0);
247 
248  // Fields
249  CHKERR m_field.add_field("FIELD1", H1, AINSWORTH_LEGENDRE_BASE, 1);
250  CHKERR m_field.add_ents_to_field_by_type(one_prism_meshset, MBPRISM,
251  "FIELD1", VERY_NOISY);
252 
253  CHKERR m_field.set_field_order(one_prism_meshset, MBVERTEX, "FIELD1", 1);
254  CHKERR m_field.set_field_order(one_prism_meshset, MBEDGE, "FIELD1", 5,
255  VERY_NOISY);
256  CHKERR m_field.set_field_order(one_prism_meshset, MBTRI, "FIELD1", 5);
257  CHKERR m_field.set_field_order(one_prism_meshset, MBQUAD, "FIELD1", 5,
258  VERY_NOISY);
259  CHKERR m_field.set_field_order(one_prism_meshset, MBPRISM, "FIELD1", 7,
260  VERY_NOISY);
261  CHKERR m_field.build_fields(VERY_NOISY);
262 
263  // FE
264  CHKERR m_field.add_finite_element("PRISM");
265  CHKERR m_field.add_finite_element("EDGE");
266  CHKERR m_field.add_finite_element("TRI");
267  CHKERR m_field.add_finite_element("QUAD");
268 
269  // Define rows/cols and element data
270  CHKERR m_field.modify_finite_element_add_field_row("PRISM", "FIELD1");
271  CHKERR m_field.modify_finite_element_add_field_col("PRISM", "FIELD1");
272  CHKERR m_field.modify_finite_element_add_field_data("PRISM", "FIELD1");
273  // Define rows/cols and element data
274  CHKERR m_field.modify_finite_element_add_field_row("EDGE", "FIELD1");
275  CHKERR m_field.modify_finite_element_add_field_col("EDGE", "FIELD1");
276  CHKERR m_field.modify_finite_element_add_field_data("EDGE", "FIELD1");
277  // Define rows/cols and element data
278  CHKERR m_field.modify_finite_element_add_field_row("TRI", "FIELD1");
279  CHKERR m_field.modify_finite_element_add_field_col("TRI", "FIELD1");
280  CHKERR m_field.modify_finite_element_add_field_data("TRI", "FIELD1");
281  // Define rows/cols and element data
282  CHKERR m_field.modify_finite_element_add_field_row("QUAD", "FIELD1");
283  CHKERR m_field.modify_finite_element_add_field_col("QUAD", "FIELD1");
284  CHKERR m_field.modify_finite_element_add_field_data("QUAD", "FIELD1");
285 
286  CHKERR m_field.add_ents_to_finite_element_by_type(one_prism_meshset, MBEDGE,
287  "EDGE");
288  CHKERR m_field.add_ents_to_finite_element_by_type(one_prism_meshset, MBTRI,
289  "TRI");
290  CHKERR m_field.add_ents_to_finite_element_by_type(one_prism_meshset, MBQUAD,
291  "QUAD");
292  CHKERR m_field.add_ents_to_finite_element_by_type(one_prism_meshset,
293  MBPRISM, "PRISM");
294 
295  // build finite elemnts
296  CHKERR m_field.build_finite_elements();
297  // //build adjacencies
298  CHKERR m_field.build_adjacencies(bit_level0);
299 
300  // Problem
301  CHKERR m_field.add_problem("TEST_PROBLEM");
302 
303  // set finite elements for problem
304  CHKERR m_field.modify_problem_add_finite_element("TEST_PROBLEM", "PRISM");
305  CHKERR m_field.modify_problem_add_finite_element("TEST_PROBLEM", "EDGE");
306  CHKERR m_field.modify_problem_add_finite_element("TEST_PROBLEM", "TRI");
307  CHKERR m_field.modify_problem_add_finite_element("TEST_PROBLEM", "QUAD");
308  // set refinement level for problem
309  CHKERR m_field.modify_problem_ref_level_add_bit("TEST_PROBLEM", bit_level0);
310 
311  // build problem
312  ProblemsManager *prb_mng_ptr;
313  CHKERR m_field.getInterface(prb_mng_ptr);
314  CHKERR prb_mng_ptr->buildProblem("TEST_PROBLEM", true);
315  // partition
316  CHKERR prb_mng_ptr->partitionSimpleProblem("TEST_PROBLEM");
317  CHKERR prb_mng_ptr->partitionFiniteElements("TEST_PROBLEM");
318  // what are ghost nodes, see Petsc Manual
319  CHKERR prb_mng_ptr->partitionGhostDofs("TEST_PROBLEM");
320 
321  PrismFE fe_prism(m_field, tri_coords);
322  fe_prism.getOpPtrVector().push_back(new PrismOp(moab, map_coords));
323  CHKERR m_field.loop_finite_elements("TEST_PROBLEM", "PRISM", fe_prism);
324 
325  EdgeFE fe_edge(m_field, edge_block, one_prism);
326  fe_edge.getOpPtrVector().push_back(
328  moab, map_coords, one_prism));
329  CHKERR m_field.loop_finite_elements("TEST_PROBLEM", "EDGE", fe_edge);
330 
331  TriFE fe_tri(m_field, tri_coords, one_prism);
332  fe_tri.getOpPtrVector().push_back(
334  moab, map_coords, one_prism));
335  CHKERR m_field.loop_finite_elements("TEST_PROBLEM", "TRI", fe_tri);
336 
337  QuadFE fe_quad(m_field, edge_block, one_prism);
338  fe_quad.getOpPtrVector().push_back(
340  moab, map_coords, one_prism));
341  CHKERR m_field.loop_finite_elements("TEST_PROBLEM", "QUAD", fe_quad);
342 
343  CHKERR moab.write_file("prism_mesh.vtk", "VTK", "", &meshset, 1);
344  CHKERR moab.write_file("one_prism_mesh.vtk", "VTK", "", &one_prism_meshset,
345  1);
346  }
347  CATCH_ERRORS;
348 
350  return 0;
351 }
352 
355  "FIELD1", "FIELD1", ForcesAndSourcesCore::UserDataOperator::OPROW),
356  postProc(post_proc), mapCoords(map_coords) {}
357 
358 MoFEMErrorCode PrismOp::doWork(int side, EntityType type,
360  constexpr double def_val[] = {0, 0, 0};
362  switch (type) {
363  case MBVERTEX:
364  case MBEDGE:
365  case MBTRI:
366  case MBQUAD:
367  case MBPRISM:
368  break;
369  default:
371  }
372  if (type == MBTRI && (side != 3 && side != 4))
374  if (type == MBQUAD && (side == 3 || side == 4))
376 
377  const int nb_dofs = data.getIndices().size();
378  for (int dd = 0; dd != nb_dofs; ++dd)
379  data.getFieldDofs()[dd]->getFieldData() = data.getIndices()[dd];
380 
381  if (type == MBVERTEX) {
382  const size_t nb_gauss_pts = getGaussPts().size2();
383  auto &coords_at_pts = getGaussPts();
384  nodeHandles.reserve(nb_gauss_pts);
385  nodeHandles.clear();
386  for (size_t gg = 0; gg != nb_gauss_pts; ++gg) {
387  auto t = boost::make_tuple(CoordsAndHandle::getArg(coords_at_pts(0, gg)),
388  CoordsAndHandle::getArg(coords_at_pts(1, gg)),
389  CoordsAndHandle::getArg(coords_at_pts(2, gg)));
390 
391  auto it = mapCoords.find(t);
392  if (it != mapCoords.end())
393  nodeHandles.emplace_back(it->node);
394  else
395  SETERRQ(PETSC_COMM_SELF, MOFEM_DATA_INCONSISTENCY, "Vertex not found");
396  }
397 
398  MatrixDouble node_coords(nb_gauss_pts, 3);
399  CHKERR postProc.get_coords(&nodeHandles[0], nodeHandles.size(),
400  &node_coords(0, 0));
401  for (size_t gg = 0; gg != nb_gauss_pts; ++gg) {
402  constexpr double eps = 1e-12;
403  for (auto d : {0, 1, 2})
404  if (std::abs(node_coords(gg, d) - getGaussPts()(d, gg)) > eps) {
405  SETERRQ(PETSC_COMM_SELF, MOFEM_ATOM_TEST_INVALID,
406  "Inconsistency between node coords and integration "
407  "points");
408  }
409  for (auto d : {0, 1, 2})
410  if (std::abs(node_coords(gg, d) - getCoordsAtGaussPts()(gg, d)) > eps)
411  SETERRQ(PETSC_COMM_SELF, MOFEM_ATOM_TEST_INVALID,
412  "Inconsistency between node coords and integration "
413  "points");
414  }
415 
416  Tag th;
417  CHKERR postProc.tag_get_handle("Coords", 3, MB_TYPE_DOUBLE, th,
418  MB_TAG_CREAT | MB_TAG_DENSE, def_val);
419  CHKERR postProc.tag_set_data(th, &nodeHandles[0], nodeHandles.size(),
420  &getCoordsAtGaussPts()(0, 0));
421  }
422 
423  auto to_str = [](auto i) { return boost::lexical_cast<std::string>(i); };
424  std::string tag_name_base =
425  "PrismType" + to_str(type) + "Side" + to_str(side);
426  std::cout << tag_name_base << endl;
427 
428  MatrixDouble trans_base = trans(data.getN());
429  if (trans_base.size2() != nodeHandles.size())
430  SETERRQ2(PETSC_COMM_SELF, MOFEM_ATOM_TEST_INVALID, "wrong size %d != %d",
431  trans_base.size2(), nodeHandles.size());
432  for (size_t rr = 0; rr != trans_base.size1(); ++rr) {
433  auto tag_name = tag_name_base + "Base" + to_str(rr);
434  Tag th;
435  CHKERR postProc.tag_get_handle(tag_name.c_str(), 1, MB_TYPE_DOUBLE, th,
436  MB_TAG_CREAT | MB_TAG_DENSE, def_val);
437  CHKERR postProc.tag_set_data(th, &nodeHandles[0], nodeHandles.size(),
438  &trans_base(rr, 0));
439  }
440 
442 }
443 
445  : FatPrismElementForcesAndSourcesCore(m_field), triCoords(tri_coords) {}
446 
447 int PrismFE::getRuleTrianglesOnly(int order) { return -1; };
448 int PrismFE::getRuleThroughThickness(int order) { return -1; };
449 
452  gaussPtsTrianglesOnly.resize(3, triCoords.size1(), false);
453  gaussPtsTrianglesOnly.clear();
454  for (int gg = 0; gg != triCoords.size1(); ++gg)
455  for (int dd = 0; dd != 2; ++dd)
456  gaussPtsTrianglesOnly(dd, gg) = triCoords(gg, dd);
458 }
459 
463  gaussPtsThroughThickness.clear();
464  for (int gg = 0; gg != number_of_prisms_layers + 1; ++gg)
465  gaussPtsThroughThickness(0, gg) = delta * gg;
466 
468 }
469 
471  EntityHandle prism)
472  : FaceElementForcesAndSourcesCore(m_field), triCoords(tri_coords),
473  prism(prism) {}
474 
475 int TriFE::getRule(int order_row, int order_col, int order_data) { return -1; }
476 
477 MoFEMErrorCode TriFE::setGaussPts(int order_row, int order_col,
478  int order_data) {
480 
481  const EntityHandle ent = numeredEntFiniteElementPtr->getEnt();
482  int side, sense, offset;
483  CHKERR mField.get_moab().side_number(prism, ent, side, sense, offset);
484  std::array<int, 2> swap = {0, 1};
485  if (side == 3)
486  swap = std::array<int, 2>{1, 0};
487 
488  gaussPts.resize(3, triCoords.size1(), false);
489  gaussPts.clear();
490  for (int gg = 0; gg != triCoords.size1(); ++gg)
491  for (int dd = 0; dd != 2; ++dd)
492  gaussPts(dd, gg) = triCoords(gg, swap[dd]);
493 
495 }
496 
497 QuadFE::QuadFE(MoFEM::Interface &m_field, std::array<Range, 3> &edge_blocks,
498  EntityHandle prism)
499  : FaceElementForcesAndSourcesCore(m_field), edgeBlocks(edge_blocks),
500  prism(prism) {}
501 
502 int QuadFE::getRule(int order_row, int order_col, int order_data) { return -1; }
503 
504 MoFEMErrorCode QuadFE::setGaussPts(int order_row, int order_col,
505  int order_data) {
507 
508  const EntityHandle ent = numeredEntFiniteElementPtr->getEnt();
509  int side, sense, offset;
510  CHKERR mField.get_moab().side_number(prism, ent, side, sense, offset);
511 
512  Range edge_verts;
513  CHKERR mField.get_moab().get_connectivity(edgeBlocks[side], edge_verts);
514  MatrixDouble edge_coords(edge_verts.size(), 3);
515  CHKERR mField.get_moab().get_coords(edge_verts, &edge_coords(0, 0));
516 
517  constexpr double normal[3][2] = {{-1, 0}, {-0.5, 0.5}, {0, 1}};
518  constexpr double origin[3][2] = {{1, 0}, {1, 0}, {0, 0}};
519  constexpr int swap[3][2] = {{0, 1}, {0, 1}, {1, 0}};
520  gaussPts.resize(3, edge_verts.size() * (number_of_prisms_layers + 1), false);
521  int gg = 0;
522  for (size_t rr = 0; rr != edge_verts.size(); ++rr) {
523  const double x = edge_coords(rr, 0) - origin[side][0];
524  const double y = edge_coords(rr, 1) - origin[side][1];
525  const double edge_dist = x * normal[side][0] + y * normal[side][1];
526  for (size_t cc = 0; cc != number_of_prisms_layers + 1; ++cc, ++gg) {
527  gaussPts(swap[side][0], gg) = edge_dist;
528  gaussPts(swap[side][1], gg) = delta * cc;
529  }
530  }
531 
533 }
534 
535 EdgeFE::EdgeFE(MoFEM::Interface &m_field, std::array<Range, 3> &edge_blocks,
536  EntityHandle prism)
537  : EdgeEle(m_field), edgeBlocks(edge_blocks),
538  prism(prism) {}
539 
540 int EdgeFE::getRule(int order_row, int order_col, int order_data) { return -1; }
541 
542 MoFEMErrorCode EdgeFE::setGaussPts(int order_row, int order_col,
543  int order_data) {
545 
546  const EntityHandle ent = numeredEntFiniteElementPtr->getEnt();
547  int side, sense, offset;
548  CHKERR mField.get_moab().side_number(prism, ent, side, sense, offset);
549 
550  if (side >= 3 && side <= 5) {
551 
552  gaussPts.resize(2, number_of_prisms_layers + 1, false);
553  for (size_t gg = 0; gg != number_of_prisms_layers + 1; ++gg)
554  gaussPts(0, gg) = delta * gg;
555 
556  // cerr << gaussPts << endl;
557 
558  } else {
559 
560  constexpr double normal[3][2] = {{1, 0}, {-0.5, 0.5}, {0, 1}};
561  constexpr double origin[3][2] = {{0, 1}, {1, 0}, {0, 0}};
562  constexpr int side_map[9] = {0, 1, 2, -1, -1, -1, 0, 1, 2};
563 
564  int num_nodes;
565  const EntityHandle *conn;
566  CHKERR mField.get_moab().get_connectivity(ent, conn, num_nodes, true);
567  MatrixDouble coords(num_nodes, 3);
568  CHKERR mField.get_moab().get_coords(conn, num_nodes,
569  &*coords.data().begin());
570  side = side_map[side];
571 
572  Range edge_verts;
573  CHKERR mField.get_moab().get_connectivity(edgeBlocks[side], edge_verts);
574  MatrixDouble edge_coords(edge_verts.size(), 3);
575  CHKERR mField.get_moab().get_coords(edge_verts, &edge_coords(0, 0));
576  gaussPts.resize(2, edge_verts.size(), false);
577 
578  for (size_t gg = 0; gg != edge_verts.size(); ++gg) {
579  const double x = edge_coords(gg, 0) - origin[side][0];
580  const double y = edge_coords(gg, 1) - origin[side][1];
581  const double edge_dist = x * normal[side][0] + y * normal[side][1];
582  gaussPts(0, gg) = edge_dist;
583  }
584  }
585 
587 }
588 
589 template <typename OP>
590 Op<OP>::Op(moab::Interface &post_proc, MapCoords &map_coords,
591  EntityHandle prism)
592  : OP("FIELD1", "FIELD1", ForcesAndSourcesCore::UserDataOperator::OPROW),
593  postProc(post_proc), mapCoords(map_coords), prism(prism) {}
594 
595 template <typename OP>
596 MoFEMErrorCode Op<OP>::doWork(int side, EntityType type,
598  constexpr double def_val[] = {0, 0, 0};
600  switch (type) {
601  case MBVERTEX:
602  case MBEDGE:
603  case MBTRI:
604  case MBQUAD:
605  break;
606  default:
608  }
609 
610  const int nb_dofs = data.getIndices().size();
611  for (int dd = 0; dd != nb_dofs; ++dd)
612  if (data.getFieldData()[dd] != data.getIndices()[dd]) {
613  std::cerr << "Indices: " << data.getIndices() << std::endl;
614  std::cerr << "Local indices: " << data.getLocalIndices() << std::endl;
615  std::cerr << "Data: " << data.getFieldData() << std::endl;
616  SETERRQ2(PETSC_COMM_SELF, MOFEM_ATOM_TEST_INVALID,
617  "Indicices/data inconsistency %3.1f != %d",
618  data.getFieldData()[dd], data.getIndices()[dd]);
619  }
620 
621  const EntityHandle fe_ent = OP::getFEEntityHandle();
622  const EntityHandle ent = OP::getSideEntity(side, type);
623  int side_prism, sense, offset;
624  if (type == MBVERTEX) {
625  CHKERR postProc.side_number(prism, fe_ent, side_prism, sense, offset);
626  } else
627  CHKERR postProc.side_number(prism, ent, side_prism, sense, offset);
628 
629  if (type == MBVERTEX) {
630  auto &coords_at_pts = OP::getCoordsAtGaussPts();
631  const size_t nb_gauss_pts = coords_at_pts.size1();
632 
633  nodeHandles.reserve(nb_gauss_pts);
634  nodeHandles.clear();
635  for (size_t gg = 0; gg != nb_gauss_pts; ++gg) {
636  auto t = boost::make_tuple(CoordsAndHandle::getArg(coords_at_pts(gg, 0)),
637  CoordsAndHandle::getArg(coords_at_pts(gg, 1)),
638  CoordsAndHandle::getArg(coords_at_pts(gg, 2)));
639 
640  auto it = mapCoords.find(t);
641  if (it != mapCoords.end())
642  nodeHandles.emplace_back(it->node);
643  else
644  SETERRQ(PETSC_COMM_SELF, MOFEM_DATA_INCONSISTENCY, "Vertex not found");
645  }
646  }
647 
648  auto to_str = [](auto i) { return boost::lexical_cast<std::string>(i); };
649  std::string tag_name_base =
650  "FEType" + to_str(OP::getNumeredEntFiniteElementPtr()->getEntType()) +
651  "Type" + to_str(type) + "Side" + to_str(side_prism);
652 
653  std::string tag_prism_name_base =
654  "PrismType" + to_str(type) + "Side" + to_str(side_prism);
655 
656  MatrixDouble trans_base = trans(data.getN());
657  MatrixDouble prism_base(trans_base.size1(), trans_base.size2());
658  if (trans_base.size2() != nodeHandles.size())
659  SETERRQ2(PETSC_COMM_SELF, MOFEM_ATOM_TEST_INVALID, "wrong size %d != %d",
660  trans_base.size2(), nodeHandles.size());
661 
662  for (size_t rr = 0; rr != trans_base.size1(); ++rr) {
663 
664  std::string tag_name = tag_name_base + "Base";
665  if (type == MBVERTEX) {
666  EntityHandle node = data.getFieldDofs()[rr]->getEnt();
667  int prism_mode_side;
668  CHKERR postProc.side_number(prism, node, prism_mode_side, sense, offset);
669  tag_name += to_str(prism_mode_side);
670  } else {
671  tag_name += to_str(rr);
672  }
673 
674  std::cout << tag_name << endl;
675 
676  Tag th;
677  CHKERR postProc.tag_get_handle(tag_name.c_str(), 1, MB_TYPE_DOUBLE, th,
678  MB_TAG_CREAT | MB_TAG_DENSE, def_val);
679  CHKERR postProc.tag_set_data(th, &nodeHandles[0], nodeHandles.size(),
680  &trans_base(rr, 0));
681 
682  if (type != MBVERTEX) {
683  auto tag_prism_name = tag_prism_name_base + "Base" + to_str(rr);
684  Tag th_prism;
685  CHKERR postProc.tag_get_handle(tag_prism_name.c_str(), th_prism);
686  CHKERR postProc.tag_get_data(th_prism, &nodeHandles[0],
687  nodeHandles.size(), &prism_base(rr, 0));
688  }
689  }
690 
691  auto sum_matrix = [](MatrixDouble &m) {
692  double s = 0;
693  for (unsigned int ii = 0; ii < m.size1(); ii++) {
694  for (unsigned int jj = 0; jj < m.size2(); jj++) {
695  s += std::abs(m(ii, jj));
696  }
697  }
698  return s;
699  };
700 
701  if (type != MBVERTEX) {
702  prism_base -= trans_base;
703  double sum = sum_matrix(prism_base);
704  constexpr double eps = 1e-6;
705 
706  if (std::abs(sum) > eps)
707  cout << "Inconsistent base " << tag_prism_name_base << " "
708  << tag_name_base << " sum " << sum << endl;
709 
710  if (std::abs(sum) > eps)
711  SETERRQ2(PETSC_COMM_SELF, MOFEM_ATOM_TEST_INVALID,
712  "Inconsistent base %s sum %6.4e", tag_prism_name_base.c_str(),
713  sum);
714  }
715 
717 }
static Index< 'n', 3 > n
ForcesAndSourcesCore::UserDataOperator UserDataOperator
static const double eps
@ VERY_NOISY
Definition: definitions.h:225
#define CATCH_ERRORS
Catch errors.
Definition: definitions.h:385
@ AINSWORTH_LEGENDRE_BASE
Ainsworth Cole (Legendre) approx. base .
Definition: definitions.h:73
#define MoFEMFunctionReturnHot(a)
Last executable line of each PETSc function used for error handling. Replaces return()
Definition: definitions.h:460
@ H1
continuous field
Definition: definitions.h:98
#define MoFEMFunctionBegin
First executable line of each MoFEM function, used for error handling. Final line of MoFEM functions ...
Definition: definitions.h:359
@ BLOCKSET
Definition: definitions.h:161
@ MOFEM_ATOM_TEST_INVALID
Definition: definitions.h:53
@ MOFEM_DATA_INCONSISTENCY
Definition: definitions.h:44
@ MOFEM_INVALID_DATA
Definition: definitions.h:49
#define MoFEMFunctionReturn(a)
Last executable line of each PETSc function used for error handling. Replaces return()
Definition: definitions.h:429
#define CHKERR
Inline error check.
Definition: definitions.h:548
static double sum_matrix(MatrixDouble &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.
EdgeElementForcesAndSourcesCoreSwitch< 0 > EdgeElementForcesAndSourcesCore
Edge finite element default.
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
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:77
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
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
PetscErrorCode MoFEMErrorCode
MoFEM/PETSc error code.
Definition: Exceptions.hpp:67
UBlasMatrix< double > MatrixDouble
Definition: Types.hpp:88
std::bitset< BITREFLEVEL_SIZE > BitRefLevel
Bit structure attached to each entity identifying to what mesh entity is attached.
Definition: Types.hpp:51
implementation of Data Operators for Forces and Sources
Definition: Common.hpp:21
CoreTmp< 0 > Core
Definition: Core.hpp:1096
PetscErrorCode PetscOptionsGetString(PetscOptions *, const char pre[], const char name[], char str[], size_t size, PetscBool *set)
DeprecatedCoreInterface Interface
Definition: Interface.hpp:1965
constexpr double t
plate stiffness
Definition: plate.cpp:76
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
FTensor::Index< 'm', 3 > m
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 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 moab::Interface & get_moab()=0
Core (interface) class.
Definition: Core.hpp:92
static MoFEMErrorCode Initialize(int *argc, char ***args, const char file[], const char help[])
Initializes the MoFEM database PETSc, MOAB and MPI.
Definition: Core.cpp:85
static MoFEMErrorCode Finalize()
Checks for options to be called at the conclusion of the program.
Definition: Core.cpp:125
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
MatrixDouble gaussPts
Matrix of integration points.
boost::ptr_vector< UserDataOperator > & getOpPtrVector()
Use to push back operator for row operator.
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)
QuadFE(MoFEM::Interface &m_field, std::array< Range, 3 > &edges_blocks, EntityHandle prims)
MoFEMErrorCode setGaussPts(int order_row, int order_col, int order_data)
MoFEMErrorCode setGaussPts(int order_row, int order_col, int order_data)
MatrixDouble & triCoords
TriFE(MoFEM::Interface &m_field, MatrixDouble &tri_coords, EntityHandle prims)
int getRule(int order_row, int order_col, int order_data)