v0.13.2
Loading...
Searching...
No Matches
forces_and_sources_hdiv_approximation_functions.cpp
Go to the documentation of this file.
1
2
3#include <MoFEM.hpp>
4
5namespace bio = boost::iostreams;
6using bio::stream;
7using bio::tee_device;
8
9using namespace MoFEM;
10
11static char help[] = "...\n\n";
12
13int main(int argc, char *argv[]) {
14
15 MoFEM::Core::Initialize(&argc, &argv, (char *)0, help);
16
17 try {
18
19 moab::Core mb_instance;
20 moab::Interface &moab = mb_instance;
21 int rank;
22 MPI_Comm_rank(PETSC_COMM_WORLD, &rank);
23
24 // create one tet
25 double tet_coords[] = {0, 0, 0, 2, 0, 0, 0, 2, 0, 0, 0, 2};
26 EntityHandle nodes[4];
27 for (int nn = 0; nn < 4; nn++) {
28 CHKERR moab.create_vertex(&tet_coords[3 * nn], nodes[nn]);
29 }
30 EntityHandle tet;
31 CHKERR moab.create_element(MBTET, nodes, 4, tet);
32
33 // Create MoFEM (Joseph) database
34 MoFEM::Core core(moab);
35 MoFEM::Interface &m_field = core;
36
37 // set entitities bit level
38 BitRefLevel bit_level0;
39 bit_level0.set(0);
40 EntityHandle meshset_level0;
41 CHKERR moab.create_meshset(MESHSET_SET, meshset_level0);
42 CHKERR m_field.getInterface<BitRefManager>()->setBitRefLevelByDim(
43 0, 3, bit_level0);
44
45 // Fields
46 CHKERR m_field.add_field("HDIV", HDIV, AINSWORTH_LEGENDRE_BASE, 1);
47
48 // FE TET
49 CHKERR m_field.add_finite_element("HDIV_TET_FE");
50 // Define rows/cols and element data
51 CHKERR m_field.modify_finite_element_add_field_row("HDIV_TET_FE", "HDIV");
52 CHKERR m_field.modify_finite_element_add_field_col("HDIV_TET_FE", "HDIV");
53 CHKERR m_field.modify_finite_element_add_field_data("HDIV_TET_FE", "HDIV");
54
55 // FE TRI
56 CHKERR m_field.add_finite_element("HDIV_TRI_FE");
57 // Define rows/cols and element data
58 CHKERR m_field.modify_finite_element_add_field_row("HDIV_TRI_FE", "HDIV");
59 CHKERR m_field.modify_finite_element_add_field_col("HDIV_TRI_FE", "HDIV");
60 CHKERR m_field.modify_finite_element_add_field_data("HDIV_TRI_FE", "HDIV");
61
62 // Problem
63 CHKERR m_field.add_problem("TEST_PROBLEM");
64
65 // set finite elements for problem
66 CHKERR m_field.modify_problem_add_finite_element("TEST_PROBLEM",
67 "HDIV_TET_FE");
68 CHKERR m_field.modify_problem_add_finite_element("TEST_PROBLEM",
69 "HDIV_TRI_FE");
70 // set refinement level for problem
71 CHKERR m_field.modify_problem_ref_level_add_bit("TEST_PROBLEM", bit_level0);
72
73 // meshset consisting all entities in mesh
74 EntityHandle root_set = moab.get_root_set();
75 // add entities to field
76 CHKERR m_field.add_ents_to_field_by_type(root_set, MBTET, "HDIV");
77 // add entities to finite element
78 CHKERR m_field.add_ents_to_finite_element_by_type(root_set, MBTET,
79 "HDIV_TET_FE");
80
81 Range tets;
82 CHKERR m_field.getInterface<BitRefManager>()->getEntitiesByTypeAndRefLevel(
83 BitRefLevel().set(0), BitRefLevel().set(), MBTET, tets);
84 Skinner skin(&moab);
85 Range skin_faces; // skin faces from 3d ents
86 CHKERR skin.find_skin(0, tets, false, skin_faces);
87 CHKERR m_field.add_ents_to_finite_element_by_type(skin_faces, MBTRI,
88 "HDIV_TRI_FE");
89
90 // set app. order
91 int order = 4;
92 CHKERR m_field.set_field_order(root_set, MBTET, "HDIV", order);
93 CHKERR m_field.set_field_order(root_set, MBTRI, "HDIV", order);
94
95 /****/
96 // build database
97 // build field
98 CHKERR m_field.build_fields();
99 // build finite elemnts
101 // build adjacencies
102 CHKERR m_field.build_adjacencies(bit_level0);
103 // build problem
104
105 ProblemsManager *prb_mng_ptr;
106 CHKERR m_field.getInterface(prb_mng_ptr);
107 CHKERR prb_mng_ptr->buildProblem("TEST_PROBLEM", true);
108
109 /****/
110 // mesh partitioning
111 // partition
112 CHKERR prb_mng_ptr->partitionSimpleProblem("TEST_PROBLEM");
113 CHKERR prb_mng_ptr->partitionFiniteElements("TEST_PROBLEM");
114 // what are ghost nodes, see Petsc Manual
115 CHKERR prb_mng_ptr->partitionGhostDofs("TEST_PROBLEM");
116
117 typedef tee_device<std::ostream, std::ofstream> TeeDevice;
118 typedef stream<TeeDevice> TeeStream;
119
120 std::ofstream ofs("forces_and_sources_hdiv_approximation_functions.txt");
121 TeeDevice my_tee(std::cout, ofs);
122 TeeStream my_split(my_tee);
123
124 struct OpPrintingHdivApproximationFunctions
126
127 TeeStream &mySplit;
128 OpPrintingHdivApproximationFunctions(TeeStream &my_split)
130 "HDIV", UserDataOperator::OPROW),
131 mySplit(my_split) {}
132
133 MoFEMErrorCode doWork(int side, EntityType type,
136
137 if (data.getFieldData().size() == 0)
139
140 mySplit << std::endl
141 << "type " << type << " side " << side << std::endl;
142 mySplit.precision(5);
143
144 const double eps = 1e-6;
145 for (unsigned int dd = 0; dd < data.getN().data().size(); dd++) {
146 if (fabs(data.getN().data()[dd]) < eps)
147 data.getN().data()[dd] = 0;
148 }
149 for (unsigned int dd = 0; dd < data.getDiffN().data().size();
150 dd++) {
151 if (fabs(data.getDiffN().data()[dd]) < eps)
152 data.getDiffN().data()[dd] = 0;
153 }
154
155 mySplit << std::fixed << data.getN() << std::endl;
156 mySplit << std::fixed << data.getDiffN() << std::endl;
157
159 }
160 };
161
162 struct MyFE : public VolumeElementForcesAndSourcesCore {
163
164 MyFE(MoFEM::Interface &m_field)
166 int getRule(int order) { return 1; };
167 };
168
169 struct OpFacePrintingHdivApproximationFunctions
171
172 TeeStream &mySplit;
173 OpFacePrintingHdivApproximationFunctions(TeeStream &my_split)
175 "HDIV", UserDataOperator::OPROW),
176 mySplit(my_split) {}
177
178 MoFEMErrorCode doWork(int side, EntityType type,
181
182 if (data.getFieldData().size() == 0)
184
185 mySplit << std::endl
186 << "type " << type << " side " << side << std::endl;
187 mySplit.precision(5);
188
189 const double eps = 1e-6;
190 for (unsigned int dd = 0; dd < data.getN().data().size(); dd++) {
191 if (fabs(data.getN().data()[dd]) < eps)
192 data.getN().data()[dd] = 0;
193 }
194 for (unsigned int dd = 0; dd < data.getDiffN().data().size();
195 dd++) {
196 if (fabs(data.getDiffN().data()[dd]) < eps)
197 data.getDiffN().data()[dd] = 0;
198 }
199
200 mySplit << std::fixed << data.getN() << std::endl;
201 // mySplit << std::fixed << data.getDiffN() << std::endl;
202
204 }
205 };
206
207 struct MyFaceFE : public FaceElementForcesAndSourcesCore {
208
209 MyFaceFE(MoFEM::Interface &m_field)
211 int getRule(int order) { return 1; };
212 };
213
214 MyFE tet_fe(m_field);
215 MyFaceFE tri_fe(m_field);
216
217 tet_fe.getOpPtrVector().push_back(
218 new OpPrintingHdivApproximationFunctions(my_split));
219
220 tri_fe.getOpPtrVector().push_back(
222 tri_fe.getOpPtrVector().push_back(
223 new OpFacePrintingHdivApproximationFunctions(my_split));
224
225 CHKERR m_field.loop_finite_elements("TEST_PROBLEM", "HDIV_TET_FE", tet_fe);
226 CHKERR m_field.loop_finite_elements("TEST_PROBLEM", "HDIV_TRI_FE", tri_fe);
227 }
229
231}
int main()
Definition: adol-c_atom.cpp:46
static const double eps
#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
@ HDIV
field with continuous normal traction
Definition: definitions.h:87
#define CHKERR
Inline error check.
Definition: definitions.h:535
#define MoFEMFunctionBeginHot
First executable line of each MoFEM function, used for error handling. Final line of MoFEM functions ...
Definition: definitions.h:440
tee_device< std::ostream, std::ofstream > TeeDevice
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_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 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 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
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: Common.hpp:10
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.
Data on single entity (This is passed as argument to DataOperator::doWork)
MatrixDouble & getDiffN(const FieldApproximationBase base)
get derivatives of base functions
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
virtual int getRule(int order_row, int order_col, int order_data)
another variant of getRule
transform Hdiv base fluxes from reference element to physical triangle
Problem manager is used to build and partition problems.
MoFEMErrorCode getInterface(IFACE *&iface) const
Get interface refernce to pointer of interface.