v0.14.0
Macros | Functions | Variables
projection_from_10node_tet.cpp File Reference
#include <MoFEM.hpp>

Go to the source code of this file.

Macros

#define RND_EPS   1e-6
 

Functions

double roundn (double n)
 
int main (int argc, char *argv[])
 

Variables

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

Macro Definition Documentation

◆ RND_EPS

#define RND_EPS   1e-6

Definition at line 10 of file projection_from_10node_tet.cpp.

Function Documentation

◆ main()

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

Definition at line 27 of file projection_from_10node_tet.cpp.

27  {
28 
29  MoFEM::Core::Initialize(&argc, &argv, (char *)0, help);
30 
31  try {
32 
33  moab::Core mb_instance;
34  moab::Interface &moab = mb_instance;
35  int rank;
36  MPI_Comm_rank(PETSC_COMM_WORLD, &rank);
37  /*if(rank==0) {
38  EntityHandle dummy_meshset;
39  CHKERR moab.create_meshset(MESHSET_SET,dummy_meshset);
40  }*/
41 
42  PetscBool flg = PETSC_TRUE;
43  char mesh_file_name[255];
44 #if PETSC_VERSION_GE(3, 6, 4)
45  CHKERR PetscOptionsGetString(PETSC_NULL, "", "-my_file", mesh_file_name,
46  255, &flg);
47 #else
48  CHKERR PetscOptionsGetString(PETSC_NULL, PETSC_NULL, "-my_file",
49  mesh_file_name, 255, &flg);
50 #endif
51  if (flg != PETSC_TRUE) {
52  SETERRQ(PETSC_COMM_SELF, 1, "*** ERROR -my_file (MESH FILE NEEDED)");
53  }
54 
55  const char *option;
56  option = ""; //"PARALLEL=BCAST;";//;DEBUG_IO";
57  CHKERR moab.load_file(mesh_file_name, 0, option);
58 
59  MoFEM::Core core(moab);
60  MoFEM::Interface &m_field = core;
61 
62  // add filds
63  CHKERR m_field.add_field("MESH_NODE_POSITIONS", H1, AINSWORTH_LEGENDRE_BASE,
64  3);
65 
66  // add finite elements
67  CHKERR m_field.add_finite_element("TET_ELEM");
69  "MESH_NODE_POSITIONS");
71  "MESH_NODE_POSITIONS");
73  "MESH_NODE_POSITIONS");
74 
75  // add problems
76  // CHKERR m_field.add_problem("EDGE_PROJECTOR_PROBLEM");
77  CHKERR m_field.add_problem("TET_PROBLEM");
78 
79  // define problems and finite elements
80  CHKERR m_field.modify_problem_add_finite_element("TET_PROBLEM", "TET_ELEM");
81 
82  BitRefLevel bit_level0;
83  bit_level0.set(0);
84  CHKERR m_field.getInterface<BitRefManager>()->setBitRefLevelByDim(
85  0, 3, bit_level0);
86  Range tets;
87  CHKERR moab.get_entities_by_type(0, MBTET, tets, true);
88  Range edges;
89  CHKERR moab.get_entities_by_type(0, MBEDGE, edges, true);
90  CHKERR m_field.getInterface<BitRefManager>()->setElementsBitRefLevel(edges);
91 
92  // add ents to field and set app. order
93 
94  CHKERR m_field.add_ents_to_field_by_type(0, MBTET, "MESH_NODE_POSITIONS");
95  CHKERR m_field.set_field_order(0, MBVERTEX, "MESH_NODE_POSITIONS", 1);
96  CHKERR m_field.set_field_order(0, MBEDGE, "MESH_NODE_POSITIONS", 2);
97  CHKERR m_field.set_field_order(0, MBTRI, "MESH_NODE_POSITIONS", 2);
98  CHKERR m_field.set_field_order(0, MBTET, "MESH_NODE_POSITIONS", 2);
99 
100  // add finite elements entities
101  CHKERR m_field.add_ents_to_finite_element_by_type(tets, MBTET, "TET_ELEM");
102 
103  // set problem level
104  CHKERR m_field.modify_problem_ref_level_add_bit("TET_PROBLEM", bit_level0);
105 
106  // build fields
107  CHKERR m_field.build_fields();
108  // build finite elements
109  CHKERR m_field.build_finite_elements();
110  // build adjacencies
111  CHKERR m_field.build_adjacencies(bit_level0);
112  // build problem
113  ProblemsManager *prb_mng_ptr;
114  CHKERR m_field.getInterface(prb_mng_ptr);
115  CHKERR prb_mng_ptr->buildProblem("TET_PROBLEM", false);
116 
117  // partition
118  CHKERR prb_mng_ptr->partitionProblem("TET_PROBLEM");
119  CHKERR prb_mng_ptr->partitionFiniteElements("TET_PROBLEM");
120  // what are ghost nodes, see Petsc Manual
121  CHKERR prb_mng_ptr->partitionGhostDofs("TET_PROBLEM");
122 
123  Projection10NodeCoordsOnField ent_method(m_field, "MESH_NODE_POSITIONS");
124  CHKERR m_field.loop_dofs("MESH_NODE_POSITIONS", ent_method);
125 
126  // Open mesh_file_name.txt for writing
127  std::ofstream myfile;
128  myfile.open("10node_sphere.txt");
129 
130  // Output displacements
131  std::cout << "<<<< Dofs (X-Translation, Y-Translation, Z-Translation) >>>>>"
132  << std::endl;
133  myfile << "<<<< Dofs (X-Translation, Y-Translation, Z-Translation) >>>>>"
134  << std::endl;
135 
137  for (_IT_GET_DOFS_FIELD_BY_NAME_FOR_LOOP_(m_field, "MESH_NODE_POSITIONS",
138  dof_ptr)) {
139  dofs_view.insert(*dof_ptr);
140  }
141  for (DofEntity_multiIndex_uid_view::iterator dit = dofs_view.begin();
142  dit != dofs_view.end(); dit++) {
143  // if(dof_ptr->getEntType()!=MBEDGE) continue;
144 
145  if ((*dit)->getDofCoeffIdx() == 0) {
146  // Round and truncate to 3 decimal places
147  double fval = (*dit)->getFieldData();
148  std::cout << boost::format("%.3lf") % roundn(fval) << " ";
149  myfile << boost::format("%.3lf") % roundn(fval) << " ";
150  }
151  if ((*dit)->getDofCoeffIdx() == 1) {
152  // Round and truncate to 3 decimal places
153  double fval = (*dit)->getFieldData();
154  std::cout << boost::format("%.3lf") % roundn(fval) << " ";
155  myfile << boost::format("%.3lf") % roundn(fval) << " ";
156  }
157  if ((*dit)->getDofCoeffIdx() == 2) {
158  // Round and truncate to 3 decimal places
159  double fval = (*dit)->getFieldData();
160  std::cout << boost::format("%.3lf") % roundn(fval) << std::endl;
161  myfile << boost::format("%.3lf") % roundn(fval) << std::endl;
162  }
163  }
164  }
165  CATCH_ERRORS;
166 
168 }

◆ roundn()

double roundn ( double  n)

Definition at line 11 of file projection_from_10node_tet.cpp.

11  {
12 
13  // break n into fractional part (fract) and integral part (intp)
14  double fract, intp;
15  fract = modf(n, &intp);
16 
17  // case where n approximates zero, set n to "positive" zero
18  if (std::abs(intp) == 0) {
19  if (std::abs(fract) <= RND_EPS) {
20  n = 0.000;
21  }
22  }
23 
24  return n;
25 }

Variable Documentation

◆ help

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

Definition at line 7 of file projection_from_10node_tet.cpp.

MoFEM::UnknownInterface::getInterface
MoFEMErrorCode getInterface(IFACE *&iface) const
Get interface refernce to pointer of interface.
Definition: UnknownInterface.hpp:93
roundn
double roundn(double n)
Definition: projection_from_10node_tet.cpp:11
MoFEM::CoreInterface::loop_dofs
virtual MoFEMErrorCode loop_dofs(const Problem *problem_ptr, const std::string &field_name, RowColData rc, DofMethod &method, int lower_rank, int upper_rank, int verb=DEFAULT_VERBOSITY)=0
Make a loop over dofs.
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
MoFEM::ProblemsManager
Problem manager is used to build and partition problems.
Definition: ProblemsManager.hpp:21
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
MoFEM::Projection10NodeCoordsOnField
Projection of edge entities with one mid-node on hierarchical basis.
Definition: Projection10NodeCoordsOnField.hpp:24
MoFEM::CoreTmp< 0 >::Finalize
static MoFEMErrorCode Finalize()
Checks for options to be called at the conclusion of the program.
Definition: Core.cpp:112
help
static char help[]
Definition: projection_from_10node_tet.cpp:7
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::DofEntity_multiIndex_uid_view
multi_index_container< boost::shared_ptr< DofEntity >, indexed_by< ordered_unique< const_mem_fun< DofEntity, UId, &DofEntity::getLocalUniqueId > > > > DofEntity_multiIndex_uid_view
multi-index view on DofEntity by uid
Definition: DofsMultiIndices.hpp:337
MoFEM::DeprecatedCoreInterface
Deprecated interface functions.
Definition: DeprecatedCoreInterface.hpp:16
MoFEM::Interface
DeprecatedCoreInterface Interface
Definition: Interface.hpp:1975
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
CHKERR
#define CHKERR
Inline error check.
Definition: definitions.h:535
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::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::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::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:23
convert.n
n
Definition: convert.py:82
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:372
_IT_GET_DOFS_FIELD_BY_NAME_FOR_LOOP_
#define _IT_GET_DOFS_FIELD_BY_NAME_FOR_LOOP_(MFIELD, NAME, IT)
Definition: Interface.hpp:1843
MoFEM::Core
CoreTmp< 0 > Core
Definition: Core.hpp:1094
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::CoreInterface::build_fields
virtual MoFEMErrorCode build_fields(int verb=DEFAULT_VERBOSITY)=0
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_filed)=0
set finite element field data
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::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.
RND_EPS
#define RND_EPS
Definition: projection_from_10node_tet.cpp:10
MoFEM::ProblemsManager::partitionProblem
MoFEMErrorCode partitionProblem(const std::string name, int verb=VERBOSE)
partition problem dofs (collective)
Definition: ProblemsManager.cpp:1683