v0.14.0
Classes | Typedefs | Functions | Variables
prism_elements_from_surface.cpp File Reference
#include <MoFEM.hpp>

Go to the source code of this file.

Classes

struct  CoordsAndHandle
 
struct  PrismOp
 
struct  PrismFE
 
struct  Op< OP >
 
struct  TriFE
 
struct  QuadFE
 
struct  EdgeFE
 

Typedefs

using EdgeEle = EdgeElementForcesAndSourcesCore
 
typedef 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
 

Functions

int main (int argc, char *argv[])
 

Variables

static char help [] = "...\n\n"
 
static constexpr int precision_exponent = 5
 
static constexpr int number_of_prisms_layers = 18
 
static constexpr double delta
 
static constexpr std::array< double, 3 > d3 = {0, 0, 0}
 
static constexpr std::array< double, 3 > d4 = {0, 0, delta}
 

Typedef Documentation

◆ EdgeEle

Definition at line 23 of file prism_elements_from_surface.cpp.

◆ MapCoords

typedef 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

Function Documentation

◆ main()

int main ( int  argc,
char *  argv[] 
)
Examples
prism_elements_from_surface.cpp.

Definition at line 132 of file prism_elements_from_surface.cpp.

132  {
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(
177  tris, PrismsFromSurfaceInterface::NO_SWAP, prisms);
178  prisms_from_surface_interface->setThickness(prisms, d3.data(), d4.data());
179  Range add_prims_layer;
180  Range extrude_prisms = prisms;
181 
182  for (int ll = 1; ll != number_of_prisms_layers; ++ll) {
183  prisms_from_surface_interface->createdVertices.clear();
184  CHKERR prisms_from_surface_interface->createPrismsFromPrisms(
185  extrude_prisms, false, add_prims_layer);
186  prisms_from_surface_interface->setThickness(add_prims_layer, d3.data(),
187  d4.data());
188  extrude_prisms = add_prims_layer;
189  prisms.merge(add_prims_layer);
190  add_prims_layer.clear();
191  }
192 
193  EntityHandle meshset;
194  CHKERR moab.create_meshset(MESHSET_SET | MESHSET_TRACK_OWNER, meshset);
195  CHKERR moab.add_entities(meshset, prisms);
196 
197  MapCoords map_coords;
198  Range verts;
199  CHKERR moab.get_connectivity(prisms, verts);
200  MatrixDouble coords(verts.size(), 3);
201  CHKERR moab.get_coords(verts, &coords(0, 0));
202 
203  for (size_t v = 0; v != verts.size(); ++v)
204  map_coords.insert(CoordsAndHandle(&coords(v, 0), verts[v]));
205 
206  EntityHandle one_prism_meshset;
207  CHKERR moab.create_meshset(MESHSET_SET | MESHSET_TRACK_OWNER,
208  one_prism_meshset);
209 
210  std::array<double, 18> one_prism_coords = {0, 0, 0, 1, 0, 0, 0, 1, 0,
211  0, 0, 1, 1, 0, 1, 0, 1, 1};
212  std::array<EntityHandle, 6> one_prism_nodes;
213  for (int n = 0; n != 6; ++n)
214  CHKERR moab.create_vertex(&one_prism_coords[3 * n], one_prism_nodes[n]);
215  EntityHandle one_prism;
216  CHKERR m_field.get_moab().create_element(MBPRISM, one_prism_nodes.data(), 6,
217  one_prism);
218  Range one_prism_range;
219  one_prism_range.insert(one_prism);
220  CHKERR moab.add_entities(one_prism_meshset, one_prism_range);
221  Range one_prism_verts;
222  CHKERR moab.get_connectivity(one_prism_range, one_prism_verts);
223  CHKERR moab.add_entities(one_prism_meshset, one_prism_verts);
224  Range one_prism_adj_ents;
225  for (int d = 1; d != 3; ++d)
226  CHKERR moab.get_adjacencies(one_prism_range, d, true, one_prism_adj_ents,
227  moab::Interface::UNION);
228  CHKERR moab.add_entities(one_prism_meshset, one_prism_adj_ents);
229 
230  BitRefLevel bit_level0;
231  bit_level0.set(0);
232  CHKERR m_field.getInterface<BitRefManager>()->setEntitiesBitRefLevel(
233  one_prism_range, bit_level0);
234  CHKERR prisms_from_surface_interface->seedPrismsEntities(one_prism_range,
235  bit_level0);
236 
237  // Fields
238  CHKERR m_field.add_field("FIELD1", H1, AINSWORTH_LEGENDRE_BASE, 1);
239  CHKERR m_field.add_ents_to_field_by_type(one_prism_meshset, MBPRISM,
240  "FIELD1", VERY_NOISY);
241 
242  CHKERR m_field.set_field_order(one_prism_meshset, MBVERTEX, "FIELD1", 1);
243  CHKERR m_field.set_field_order(one_prism_meshset, MBEDGE, "FIELD1", 5,
244  VERY_NOISY);
245  CHKERR m_field.set_field_order(one_prism_meshset, MBTRI, "FIELD1", 5);
246  CHKERR m_field.set_field_order(one_prism_meshset, MBQUAD, "FIELD1", 5,
247  VERY_NOISY);
248  CHKERR m_field.set_field_order(one_prism_meshset, MBPRISM, "FIELD1", 7,
249  VERY_NOISY);
250  CHKERR m_field.build_fields(VERY_NOISY);
251 
252  // FE
253  CHKERR m_field.add_finite_element("PRISM");
254  CHKERR m_field.add_finite_element("EDGE");
255  CHKERR m_field.add_finite_element("TRI");
256  CHKERR m_field.add_finite_element("QUAD");
257 
258  // Define rows/cols and element data
259  CHKERR m_field.modify_finite_element_add_field_row("PRISM", "FIELD1");
260  CHKERR m_field.modify_finite_element_add_field_col("PRISM", "FIELD1");
261  CHKERR m_field.modify_finite_element_add_field_data("PRISM", "FIELD1");
262  // Define rows/cols and element data
263  CHKERR m_field.modify_finite_element_add_field_row("EDGE", "FIELD1");
264  CHKERR m_field.modify_finite_element_add_field_col("EDGE", "FIELD1");
265  CHKERR m_field.modify_finite_element_add_field_data("EDGE", "FIELD1");
266  // Define rows/cols and element data
267  CHKERR m_field.modify_finite_element_add_field_row("TRI", "FIELD1");
268  CHKERR m_field.modify_finite_element_add_field_col("TRI", "FIELD1");
269  CHKERR m_field.modify_finite_element_add_field_data("TRI", "FIELD1");
270  // Define rows/cols and element data
271  CHKERR m_field.modify_finite_element_add_field_row("QUAD", "FIELD1");
272  CHKERR m_field.modify_finite_element_add_field_col("QUAD", "FIELD1");
273  CHKERR m_field.modify_finite_element_add_field_data("QUAD", "FIELD1");
274 
275  CHKERR m_field.add_ents_to_finite_element_by_type(one_prism_meshset, MBEDGE,
276  "EDGE");
277  CHKERR m_field.add_ents_to_finite_element_by_type(one_prism_meshset, MBTRI,
278  "TRI");
279  CHKERR m_field.add_ents_to_finite_element_by_type(one_prism_meshset, MBQUAD,
280  "QUAD");
281  CHKERR m_field.add_ents_to_finite_element_by_type(one_prism_meshset,
282  MBPRISM, "PRISM");
283 
284  // build finite elemnts
285  CHKERR m_field.build_finite_elements();
286  // //build adjacencies
287  CHKERR m_field.build_adjacencies(bit_level0);
288 
289  // Problem
290  CHKERR m_field.add_problem("TEST_PROBLEM");
291 
292  // set finite elements for problem
293  CHKERR m_field.modify_problem_add_finite_element("TEST_PROBLEM", "PRISM");
294  CHKERR m_field.modify_problem_add_finite_element("TEST_PROBLEM", "EDGE");
295  CHKERR m_field.modify_problem_add_finite_element("TEST_PROBLEM", "TRI");
296  CHKERR m_field.modify_problem_add_finite_element("TEST_PROBLEM", "QUAD");
297  // set refinement level for problem
298  CHKERR m_field.modify_problem_ref_level_add_bit("TEST_PROBLEM", bit_level0);
299 
300  // build problem
301  ProblemsManager *prb_mng_ptr;
302  CHKERR m_field.getInterface(prb_mng_ptr);
303  CHKERR prb_mng_ptr->buildProblem("TEST_PROBLEM", true);
304  // partition
305  CHKERR prb_mng_ptr->partitionSimpleProblem("TEST_PROBLEM");
306  CHKERR prb_mng_ptr->partitionFiniteElements("TEST_PROBLEM");
307  // what are ghost nodes, see Petsc Manual
308  CHKERR prb_mng_ptr->partitionGhostDofs("TEST_PROBLEM");
309 
310  PrismFE fe_prism(m_field, tri_coords);
311  fe_prism.getOpPtrVector().push_back(new PrismOp(moab, map_coords));
312  CHKERR m_field.loop_finite_elements("TEST_PROBLEM", "PRISM", fe_prism);
313 
314  EdgeFE fe_edge(m_field, edge_block, one_prism);
315  fe_edge.getOpPtrVector().push_back(
317  moab, map_coords, one_prism));
318  CHKERR m_field.loop_finite_elements("TEST_PROBLEM", "EDGE", fe_edge);
319 
320  TriFE fe_tri(m_field, tri_coords, one_prism);
321  fe_tri.getOpPtrVector().push_back(
323  moab, map_coords, one_prism));
324  CHKERR m_field.loop_finite_elements("TEST_PROBLEM", "TRI", fe_tri);
325 
326  QuadFE fe_quad(m_field, edge_block, one_prism);
327  fe_quad.getOpPtrVector().push_back(
329  moab, map_coords, one_prism));
330  CHKERR m_field.loop_finite_elements("TEST_PROBLEM", "QUAD", fe_quad);
331 
332  CHKERR moab.write_file("prism_mesh.vtk", "VTK", "", &meshset, 1);
333  CHKERR moab.write_file("one_prism_mesh.vtk", "VTK", "", &one_prism_meshset,
334  1);
335  }
336  CATCH_ERRORS;
337 
339  return 0;
340 }

Variable Documentation

◆ d3

constexpr std::array<double, 3> d3 = {0, 0, 0}
staticconstexpr

◆ d4

constexpr std::array<double, 3> d4 = {0, 0, delta}
staticconstexpr

◆ delta

constexpr double delta
staticconstexpr

◆ help

char help[] = "...\n\n"
static

◆ number_of_prisms_layers

constexpr int number_of_prisms_layers = 18
staticconstexpr

◆ precision_exponent

constexpr int precision_exponent = 5
staticconstexpr
MoFEM::UnknownInterface::getInterface
MoFEMErrorCode getInterface(IFACE *&iface) const
Get interface reference to pointer of interface.
Definition: UnknownInterface.hpp:93
MoFEM::CoreInterface::loop_finite_elements
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.
MoFEM::PrismsFromSurfaceInterface
merge node from two bit levels
Definition: PrismsFromSurfaceInterface.hpp:15
MoFEM::ProblemsManager::buildProblem
MoFEMErrorCode buildProblem(const std::string name, const bool square_matrix, int verb=VERBOSE)
build problem data structures
Definition: ProblemsManager.cpp:87
MoFEM::CoreTmp< 0 >
Core (interface) class.
Definition: Core.hpp:82
H1
@ H1
continuous field
Definition: definitions.h:85
EntityHandle
MoFEM::ProblemsManager
Problem manager is used to build and partition problems.
Definition: ProblemsManager.hpp:21
d3
static constexpr std::array< double, 3 > d3
Definition: prism_elements_from_surface.cpp:20
MoFEM::CoreInterface::modify_finite_element_add_field_row
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
PrismOp
Definition: prism_elements_from_surface.cpp:50
MoFEM::Types::MatrixDouble
UBlasMatrix< double > MatrixDouble
Definition: Types.hpp:77
VERY_NOISY
@ VERY_NOISY
Definition: definitions.h:225
EdgeFE
Definition: prism_elements_from_surface.cpp:118
TriFE
Definition: prism_elements_from_surface.cpp:91
MoFEM::CoreTmp< 0 >::Finalize
static MoFEMErrorCode Finalize()
Checks for options to be called at the conclusion of the program.
Definition: Core.cpp:112
MoFEM::CoreInterface::add_ents_to_field_by_type
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.
MoFEM::DeprecatedCoreInterface
Deprecated interface functions.
Definition: DeprecatedCoreInterface.hpp:16
CoordsAndHandle
Definition: prism_elements_from_surface.cpp:25
MoFEM::Interface
DeprecatedCoreInterface Interface
Definition: Interface.hpp:2010
MoFEM::CoreInterface::add_ents_to_finite_element_by_type
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
number_of_prisms_layers
static constexpr int number_of_prisms_layers
Definition: prism_elements_from_surface.cpp:17
CHKERR
#define CHKERR
Inline error check.
Definition: definitions.h:548
MoFEM::CoreInterface::add_finite_element
virtual MoFEMErrorCode add_finite_element(const std::string &fe_name, enum MoFEMTypes bh=MF_EXCL, int verb=DEFAULT_VERBOSITY)=0
add finite element
MoFEM::CoreInterface::get_moab
virtual moab::Interface & get_moab()=0
MoFEM::CoreInterface::modify_finite_element_add_field_col
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
MoFEM::CoreInterface::build_finite_elements
virtual MoFEMErrorCode build_finite_elements(int verb=DEFAULT_VERBOSITY)=0
Build finite elements.
MoFEM::MeshsetsManager::getEntitiesByDimension
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
Definition: MeshsetsManager.cpp:669
MoFEM::PrismsFromSurfaceInterface::seedPrismsEntities
MoFEMErrorCode seedPrismsEntities(Range &prisms, const BitRefLevel &bit, int verb=-1)
Seed prism entities by bit level.
Definition: PrismsFromSurfaceInterface.cpp:110
MoFEM::PrismsFromSurfaceInterface::createPrismsFromPrisms
MoFEMErrorCode createPrismsFromPrisms(const Range &prisms, bool from_down, Range &out_prisms, int verb=-1)
Make prisms by extruding top or bottom prisms.
Definition: PrismsFromSurfaceInterface.cpp:143
help
static char help[]
Definition: prism_elements_from_surface.cpp:14
PrismFE
Definition: prism_elements_from_surface.cpp:62
MoFEM::CoreInterface::modify_finite_element_add_field_data
virtual MoFEMErrorCode modify_finite_element_add_field_data(const std::string &fe_name, const std::string name_field)=0
set finite element field data
MoFEM::ProblemsManager::partitionFiniteElements
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
Definition: ProblemsManager.cpp:2167
MoFEM::CoreInterface::modify_problem_ref_level_add_bit
virtual MoFEMErrorCode modify_problem_ref_level_add_bit(const std::string &name_problem, const BitRefLevel &bit)=0
add ref level to problem
mesh_file_name
char mesh_file_name[255]
Definition: mesh_smoothing.cpp:22
convert.n
n
Definition: convert.py:82
v
const double v
phase velocity of light in medium (cm/ns)
Definition: initial_diffusion.cpp:40
Range
MoFEM::CoreTmp< 0 >::Initialize
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
CATCH_ERRORS
#define CATCH_ERRORS
Catch errors.
Definition: definitions.h:385
MoFEM::Core
CoreTmp< 0 > Core
Definition: Core.hpp:1148
Op
Definition: prism_elements_from_surface.cpp:78
MoFEM::ProblemsManager::partitionSimpleProblem
MoFEMErrorCode partitionSimpleProblem(const std::string name, int verb=VERBOSE)
partition problem dofs
Definition: ProblemsManager.cpp:1537
BLOCKSET
@ BLOCKSET
Definition: definitions.h:161
AINSWORTH_LEGENDRE_BASE
@ AINSWORTH_LEGENDRE_BASE
Ainsworth Cole (Legendre) approx. base .
Definition: definitions.h:60
MoFEM::PetscOptionsGetString
PetscErrorCode PetscOptionsGetString(PetscOptions *, const char pre[], const char name[], char str[], size_t size, PetscBool *set)
Definition: DeprecatedPetsc.hpp:172
MoFEM::MeshsetsManager
Interface for managing meshsets containing materials and boundary conditions.
Definition: MeshsetsManager.hpp:104
QuadFE
Definition: prism_elements_from_surface.cpp:105
MoFEM::CoreInterface::build_fields
virtual MoFEMErrorCode build_fields(int verb=DEFAULT_VERBOSITY)=0
sdf_hertz_2d_axisymm_plane.d
float d
Definition: sdf_hertz_2d_axisymm_plane.py:4
MoFEM::PrismsFromSurfaceInterface::createdVertices
std::map< EntityHandle, EntityHandle > createdVertices
Definition: PrismsFromSurfaceInterface.hpp:24
d4
static constexpr std::array< double, 3 > d4
Definition: prism_elements_from_surface.cpp:21
MoFEM::BitRefManager
Managing BitRefLevels.
Definition: BitRefManager.hpp:21
MoFEM::CoreInterface::modify_problem_add_finite_element
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
MoFEM::Types::BitRefLevel
std::bitset< BITREFLEVEL_SIZE > BitRefLevel
Bit structure attached to each entity identifying to what mesh entity is attached.
Definition: Types.hpp:40
MoFEM::CoreInterface::build_adjacencies
virtual MoFEMErrorCode build_adjacencies(const Range &ents, int verb=DEFAULT_VERBOSITY)=0
build adjacencies
MoFEM::PrismsFromSurfaceInterface::createPrisms
MoFEMErrorCode createPrisms(const Range &ents, const SwapType swap_type, Range &prisms, int verb=-1)
Make prisms from triangles.
Definition: PrismsFromSurfaceInterface.cpp:22
MoFEM::CoreInterface::set_field_order
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.
MoFEM::ProblemsManager::partitionGhostDofs
MoFEMErrorCode partitionGhostDofs(const std::string name, int verb=VERBOSE)
determine ghost nodes
Definition: ProblemsManager.cpp:2339
MoFEM::CoreInterface::add_problem
virtual MoFEMErrorCode add_problem(const std::string &name, enum MoFEMTypes bh=MF_EXCL, int verb=DEFAULT_VERBOSITY)=0
Add problem.
MoFEM::CoreInterface::add_field
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.
MoFEM::PrismsFromSurfaceInterface::setThickness
MoFEMErrorCode setThickness(const Range &prisms, const double director3[], const double director4[])
Definition: PrismsFromSurfaceInterface.cpp:161
MOFEM_INVALID_DATA
@ MOFEM_INVALID_DATA
Definition: definitions.h:36
MapCoords
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
Definition: prism_elements_from_surface.cpp:48