v0.13.2
Loading...
Searching...
No Matches
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
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
136 auto dofs_ptr = m_field.get_dofs();
138 for (_IT_GET_DOFS_FIELD_BY_NAME_FOR_LOOP_(m_field, "MESH_NODE_POSITIONS",
139 dof_ptr)) {
140 dofs_view.insert(*dof_ptr);
141 }
142 for (DofEntity_multiIndex_uid_view::iterator dit = dofs_view.begin();
143 dit != dofs_view.end(); dit++) {
144 // if(dof_ptr->getEntType()!=MBEDGE) continue;
145
146 if ((*dit)->getDofCoeffIdx() == 0) {
147 // Round and truncate to 3 decimal places
148 double fval = (*dit)->getFieldData();
149 std::cout << boost::format("%.3lf") % roundn(fval) << " ";
150 myfile << boost::format("%.3lf") % roundn(fval) << " ";
151 }
152 if ((*dit)->getDofCoeffIdx() == 1) {
153 // Round and truncate to 3 decimal places
154 double fval = (*dit)->getFieldData();
155 std::cout << boost::format("%.3lf") % roundn(fval) << " ";
156 myfile << boost::format("%.3lf") % roundn(fval) << " ";
157 }
158 if ((*dit)->getDofCoeffIdx() == 2) {
159 // Round and truncate to 3 decimal places
160 double fval = (*dit)->getFieldData();
161 std::cout << boost::format("%.3lf") % roundn(fval) << std::endl;
162 myfile << boost::format("%.3lf") % roundn(fval) << std::endl;
163 }
164 }
165 }
167
169}
#define CATCH_ERRORS
Catch errors.
Definition: definitions.h:372
@ AINSWORTH_LEGENDRE_BASE
Ainsworth Cole (Legendre) approx. base .
Definition: definitions.h:60
@ H1
continuous field
Definition: definitions.h:85
#define CHKERR
Inline error check.
Definition: definitions.h:535
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
virtual const DofEntity_multiIndex * get_dofs() const =0
Get the dofs object.
#define _IT_GET_DOFS_FIELD_BY_NAME_FOR_LOOP_(MFIELD, NAME, IT)
Definition: Interface.hpp:1843
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 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 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_row(const std::string &fe_name, const std::string name_row)=0
set field row 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_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.
MoFEMErrorCode partitionGhostDofs(const std::string name, int verb=VERBOSE)
determine ghost nodes
MoFEMErrorCode buildProblem(const std::string name, const bool square_matrix, int verb=VERBOSE)
build problem data structures
MoFEMErrorCode partitionProblem(const std::string name, int verb=VERBOSE)
partition problem dofs (collective)
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 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
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
char mesh_file_name[255]
std::bitset< BITREFLEVEL_SIZE > BitRefLevel
Bit structure attached to each entity identifying to what mesh entity is attached.
Definition: Types.hpp:40
PetscErrorCode PetscOptionsGetString(PetscOptions *, const char pre[], const char name[], char str[], size_t size, PetscBool *set)
double roundn(double n)
static char help[]
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.
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.
Problem manager is used to build and partition problems.
Projection of edge entities with one mid-node on hierarchical basis.
MoFEMErrorCode getInterface(IFACE *&iface) const
Get interface refernce to pointer of interface.

◆ 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}
FTensor::Index< 'n', SPACE_DIM > n
#define RND_EPS

Variable Documentation

◆ help

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

Definition at line 7 of file projection_from_10node_tet.cpp.