v0.13.2
Loading...
Searching...
No Matches
forces_and_sources_testing_flat_prism_element.cpp
Go to the documentation of this file.
1/** \file forces_and_sources_testing_flat_prism_element.cpp
2 * \brief test for flat prism element
3 * \example forces_and_sources_testing_flat_prism_element.cpp
4 *
5 */
6
7
8
9#include <MoFEM.hpp>
10
11namespace bio = boost::iostreams;
12using bio::stream;
13using bio::tee_device;
14
15using namespace MoFEM;
16
17static char help[] = "...\n\n";
18
19int main(int argc, char *argv[]) {
20
21 MoFEM::Core::Initialize(&argc, &argv, (char *)0, help);
22
23 try {
24
25 moab::Core mb_instance;
26 moab::Interface &moab = mb_instance;
27
28 PetscBool flg = PETSC_TRUE;
29 char mesh_file_name[255];
30#if PETSC_VERSION_GE(3, 6, 4)
31 CHKERR PetscOptionsGetString(PETSC_NULL, "", "-my_file", mesh_file_name,
32 255, &flg);
33#else
34 CHKERR PetscOptionsGetString(PETSC_NULL, PETSC_NULL, "-my_file",
35 mesh_file_name, 255, &flg);
36#endif
37 if (flg != PETSC_TRUE) {
38 SETERRQ(PETSC_COMM_SELF, 1, "*** ERROR -my_file (MESH FILE NEEDED)");
39 }
40
41 const char *option;
42 option = "";
43 CHKERR moab.load_file(mesh_file_name, 0, option);
44
45 // Create MoFEM (Joseph) database
46 MoFEM::Core core(moab);
47 MoFEM::Interface &m_field = core;
48 PrismInterface *interface;
49 CHKERR m_field.getInterface(interface);
50
51 // set entitities bit level
52 CHKERR m_field.getInterface<BitRefManager>()->setBitRefLevelByDim(
53 0, 3, BitRefLevel().set(0));
54 std::vector<BitRefLevel> bit_levels;
55 bit_levels.push_back(BitRefLevel().set(0));
56
57 int ll = 1;
58 // for(_IT_CUBITMESHSETS_BY_BCDATA_TYPE_FOR_LOOP_(m_field,SIDESET|INTERFACESET,cit))
59 // {
61 CHKERR PetscPrintf(PETSC_COMM_WORLD, "Insert Interface %d\n",
62 cit->getMeshsetId());
63 EntityHandle cubit_meshset = cit->getMeshset();
64 {
65 // get tet enties form back bit_level
66 EntityHandle ref_level_meshset = 0;
67 CHKERR moab.create_meshset(MESHSET_SET, ref_level_meshset);
68 ;
70 ->getEntitiesByTypeAndRefLevel(bit_levels.back(),
71 BitRefLevel().set(), MBTET,
72 ref_level_meshset);
74 ->getEntitiesByTypeAndRefLevel(bit_levels.back(),
75 BitRefLevel().set(), MBPRISM,
76 ref_level_meshset);
77 Range ref_level_tets;
78 CHKERR moab.get_entities_by_handle(ref_level_meshset, ref_level_tets,
79 true);
80 ;
81 // get faces and test to split
82 CHKERR interface->getSides(cubit_meshset, bit_levels.back(), true, 0);
83 // set new bit level
84 bit_levels.push_back(BitRefLevel().set(ll++));
85 // split faces and
86 CHKERR interface->splitSides(ref_level_meshset, bit_levels.back(),
87 cubit_meshset, true, true, 0);
88 // clean meshsets
89 CHKERR moab.delete_entities(&ref_level_meshset, 1);
90 ;
91 }
92 // update cubit meshsets
93 for (_IT_CUBITMESHSETS_FOR_LOOP_(m_field, ciit)) {
94 EntityHandle cubit_meshset = ciit->meshset;
96 ->updateMeshsetByEntitiesChildren(cubit_meshset, bit_levels.back(),
97 cubit_meshset, MBMAXTYPE, true);
98 }
99 }
100
101 // Fields
102 CHKERR m_field.add_field("FIELD1", H1, AINSWORTH_LEGENDRE_BASE, 3);
103 CHKERR m_field.add_field("MESH_NODE_POSITIONS", H1, AINSWORTH_LEGENDRE_BASE,
104 3);
105 CHKERR m_field.add_field("FIELD2", NOFIELD, NOBASE, 3);
106
107 {
108 // Creating and adding no field entities.
109 const double coords[] = {0, 0, 0};
110 EntityHandle no_field_vertex;
111 CHKERR m_field.get_moab().create_vertex(coords, no_field_vertex);
112 ;
113 Range range_no_field_vertex;
114 range_no_field_vertex.insert(no_field_vertex);
115 CHKERR m_field.getInterface<BitRefManager>()->setBitRefLevel(
116 range_no_field_vertex, BitRefLevel().set());
117 EntityHandle meshset = m_field.get_field_meshset("FIELD2");
118 CHKERR m_field.get_moab().add_entities(meshset, range_no_field_vertex);
119 ;
120 }
121
122 // FE
123 CHKERR m_field.add_finite_element("TEST_FE1");
124 CHKERR m_field.add_finite_element("TEST_FE2");
125
126 // Define rows/cols and element data
127 CHKERR m_field.modify_finite_element_add_field_row("TEST_FE1", "FIELD1");
128 CHKERR m_field.modify_finite_element_add_field_col("TEST_FE1", "FIELD1");
129 CHKERR m_field.modify_finite_element_add_field_data("TEST_FE1", "FIELD1");
131 "MESH_NODE_POSITIONS");
132
133 CHKERR m_field.modify_finite_element_add_field_row("TEST_FE2", "FIELD1");
134 // CHKERR m_field.modify_finite_element_add_field_row("TEST_FE2","FIELD2");
135 // CHKERR m_field.modify_finite_element_add_field_col("TEST_FE2","FIELD1");
136 CHKERR m_field.modify_finite_element_add_field_col("TEST_FE2", "FIELD2");
137 CHKERR m_field.modify_finite_element_add_field_data("TEST_FE2", "FIELD1");
138 CHKERR m_field.modify_finite_element_add_field_data("TEST_FE2", "FIELD2");
139
140 // Problem
141 CHKERR m_field.add_problem("TEST_PROBLEM");
142
143 // set finite elements for problem
144 CHKERR m_field.modify_problem_add_finite_element("TEST_PROBLEM",
145 "TEST_FE1");
146 CHKERR m_field.modify_problem_add_finite_element("TEST_PROBLEM",
147 "TEST_FE2");
148 // set refinement level for problem
149 CHKERR m_field.modify_problem_ref_level_add_bit("TEST_PROBLEM",
150 bit_levels.back());
151
152 // meshset consisting all entities in mesh
153 EntityHandle root_set = moab.get_root_set();
154 // add entities to field
155 CHKERR m_field.add_ents_to_field_by_type(root_set, MBTET, "FIELD1");
156 CHKERR m_field.add_ents_to_field_by_type(root_set, MBTET,
157 "MESH_NODE_POSITIONS");
158 // add entities to finite element
159 CHKERR m_field.add_ents_to_finite_element_by_type(root_set, MBPRISM,
160 "TEST_FE1", 10);
161 CHKERR m_field.add_ents_to_finite_element_by_type(root_set, MBPRISM,
162 "TEST_FE2", 10);
163
164 // set app. order
165 // see Hierarchic Finite Element Bases on Unstructured Tetrahedral Meshes
166 // (Mark Ainsworth & Joe Coyle)
167 int order = 3;
168 CHKERR m_field.set_field_order(root_set, MBTET, "FIELD1", order);
169 CHKERR m_field.set_field_order(root_set, MBTRI, "FIELD1", order);
170 CHKERR m_field.set_field_order(root_set, MBEDGE, "FIELD1", order);
171 CHKERR m_field.set_field_order(root_set, MBVERTEX, "FIELD1", 1);
172
173 CHKERR m_field.set_field_order(root_set, MBTET, "MESH_NODE_POSITIONS", 2);
174 CHKERR m_field.set_field_order(root_set, MBTRI, "MESH_NODE_POSITIONS", 2);
175 CHKERR m_field.set_field_order(root_set, MBEDGE, "MESH_NODE_POSITIONS", 2);
176 CHKERR m_field.set_field_order(root_set, MBVERTEX, "MESH_NODE_POSITIONS",
177 1);
178
179 /****/
180 // build database
181 // build field
182 CHKERR m_field.build_fields();
183 // set FIELD1 from positions of 10 node tets
184 Projection10NodeCoordsOnField ent_method_field1(m_field, "FIELD1");
185 CHKERR m_field.loop_dofs("FIELD1", ent_method_field1);
186 Projection10NodeCoordsOnField ent_method_mesh_positions(
187 m_field, "MESH_NODE_POSITIONS");
188 CHKERR m_field.loop_dofs("MESH_NODE_POSITIONS", ent_method_mesh_positions);
189
190 // build finite elemnts
192 // build adjacencies
193 CHKERR m_field.build_adjacencies(bit_levels.back());
194 // build problem
195 ProblemsManager *prb_mng_ptr;
196 CHKERR m_field.getInterface(prb_mng_ptr);
197 CHKERR prb_mng_ptr->buildProblem("TEST_PROBLEM", false);
198
199 /****/
200 // mesh partitioning
201 // partition
202 CHKERR prb_mng_ptr->partitionSimpleProblem("TEST_PROBLEM");
203 CHKERR prb_mng_ptr->partitionFiniteElements("TEST_PROBLEM");
204 // what are ghost nodes, see Petsc Manual
205 CHKERR prb_mng_ptr->partitionGhostDofs("TEST_PROBLEM");
206
207 typedef tee_device<std::ostream, std::ofstream> TeeDevice;
208 typedef stream<TeeDevice> TeeStream;
209
210 std::ofstream ofs("forces_and_sources_testing_flat_prism_element.txt");
211 TeeDevice my_tee(std::cout, ofs);
212 TeeStream my_split(my_tee);
213
214 struct MyOp
216
217 TeeStream &mySplit;
218 MyOp(TeeStream &mySplit, const char type)
220 "FIELD1", "FIELD1", type),
221 mySplit(mySplit) {}
222
223 MoFEMErrorCode doWork(int side, EntityType type,
226
227 if (data.getFieldData().empty())
229
230 const double eps = 1e-4;
231 for (DoubleAllocator::iterator it = getNormal().data().begin();
232 it != getNormal().data().end(); it++) {
233 *it = fabs(*it) < eps ? 0.0 : *it;
234 }
235 for (DoubleAllocator::iterator it =
236 getNormalsAtGaussPtsF3().data().begin();
237 it != getNormalsAtGaussPtsF3().data().end(); it++) {
238 *it = fabs(*it) < eps ? 0.0 : *it;
239 }
240 for (DoubleAllocator::iterator it =
241 getTangent1AtGaussPtF3().data().begin();
242 it != getTangent1AtGaussPtF3().data().end(); it++) {
243 *it = fabs(*it) < eps ? 0.0 : *it;
244 }
245 for (DoubleAllocator::iterator it =
246 getTangent2AtGaussPtF3().data().begin();
247 it != getTangent2AtGaussPtF3().data().end(); it++) {
248 *it = fabs(*it) < eps ? 0.0 : *it;
249 }
250 for (DoubleAllocator::iterator it =
251 getNormalsAtGaussPtsF4().data().begin();
252 it != getNormalsAtGaussPtsF4().data().end(); it++) {
253 *it = fabs(*it) < eps ? 0.0 : *it;
254 }
255 for (DoubleAllocator::iterator it =
256 getTangent1AtGaussPtF4().data().begin();
257 it != getTangent1AtGaussPtF4().data().end(); it++) {
258 *it = fabs(*it) < eps ? 0.0 : *it;
259 }
260 for (DoubleAllocator::iterator it =
261 getTangent2AtGaussPtF4().data().begin();
262 it != getTangent2AtGaussPtF4().data().end(); it++) {
263 *it = fabs(*it) < eps ? 0.0 : *it;
264 }
265
266 mySplit << "NH1" << std::endl;
267 mySplit << "side: " << side << " type: " << type << std::endl;
268 mySplit << data << std::endl;
269 mySplit << std::setprecision(3) << getCoords() << std::endl;
270 mySplit << std::setprecision(3) << getCoordsAtGaussPts() << std::endl;
271 mySplit << std::setprecision(3) << getArea(0) << std::endl;
272 mySplit << std::setprecision(3) << getArea(1) << std::endl;
273 mySplit << std::setprecision(3) << "normal F3 " << getNormalF3()
274 << std::endl;
275 mySplit << std::setprecision(3) << "normal F4 " << getNormalF4()
276 << std::endl;
277 mySplit << std::setprecision(3) << "normal at Gauss pt F3 "
278 << getNormalsAtGaussPtsF3() << std::endl;
279 mySplit << std::setprecision(3) << getTangent1AtGaussPtF3()
280 << std::endl;
281 mySplit << std::setprecision(3) << getTangent2AtGaussPtF3()
282 << std::endl;
283 mySplit << std::setprecision(3) << "normal at Gauss pt F4 "
284 << getNormalsAtGaussPtsF4() << std::endl;
285 mySplit << std::setprecision(3) << getTangent1AtGaussPtF4()
286 << std::endl;
287 mySplit << std::setprecision(3) << getTangent2AtGaussPtF4()
288 << std::endl;
290 }
291
292 MoFEMErrorCode doWork(int row_side, int col_side, EntityType row_type,
293 EntityType col_type,
295 EntitiesFieldData::EntData &col_data) {
297
298 if (row_data.getFieldData().empty())
300
301 mySplit << "NH1NH1" << std::endl;
302 mySplit << "row side: " << row_side << " row_type: " << row_type
303 << std::endl;
304 mySplit << row_data << std::endl;
305 mySplit << "NH1NH1" << std::endl;
306 mySplit << "col side: " << col_side << " col_type: " << col_type
307 << std::endl;
308 mySplit << row_data << std::endl;
309
311 }
312 };
313
314 struct MyOp2
316
317 TeeStream &mySplit;
318 MyOp2(TeeStream &my_split, const char type)
320 "FIELD1", "FIELD2", type),
321 mySplit(my_split) {}
322
323 MoFEMErrorCode doWork(int side, EntityType type,
326
327 if (type != MBENTITYSET)
329
330 mySplit << "NOFIELD" << std::endl;
331 mySplit << "side: " << side << " type: " << type << std::endl;
332 mySplit << data << std::endl;
334 }
335
336 MoFEMErrorCode doWork(int row_side, int col_side, EntityType row_type,
337 EntityType col_type,
339 EntitiesFieldData::EntData &col_data) {
341
342 unSetSymm();
343
344 if (col_type != MBENTITYSET)
346
347 mySplit << "NOFILEDH1" << std::endl;
348 mySplit << "row side: " << row_side << " row_type: " << row_type
349 << std::endl;
350 mySplit << row_data << std::endl;
351 mySplit << "col side: " << col_side << " col_type: " << col_type
352 << std::endl;
353 mySplit << col_data << std::endl;
354
356 }
357 };
358
360 fe1.getOpPtrVector().push_back(
361 new MyOp(my_split, ForcesAndSourcesCore::UserDataOperator::OPROW));
362 fe1.getOpPtrVector().push_back(
363 new MyOp(my_split, ForcesAndSourcesCore::UserDataOperator::OPROWCOL));
364 CHKERR m_field.loop_finite_elements("TEST_PROBLEM", "TEST_FE1", fe1);
365
367 fe2.getOpPtrVector().push_back(
368 new MyOp2(my_split, ForcesAndSourcesCore::UserDataOperator::OPCOL));
369 fe2.getOpPtrVector().push_back(
370 new MyOp2(my_split, ForcesAndSourcesCore::UserDataOperator::OPROWCOL));
371 CHKERR m_field.loop_finite_elements("TEST_PROBLEM", "TEST_FE2", fe2);
372 }
374
376
377 return 0;
378}
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
@ NOBASE
Definition: definitions.h:59
#define MoFEMFunctionReturnHot(a)
Last executable line of each PETSc function used for error handling. Replaces return()
Definition: definitions.h:447
@ NOFIELD
scalar or vector of scalars describe (no true field)
Definition: definitions.h:84
@ H1
continuous field
Definition: definitions.h:85
@ SIDESET
Definition: definitions.h:147
#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_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.
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.
#define _IT_CUBITMESHSETS_FOR_LOOP_(MESHSET_MANAGER, IT)
Iterator that loops over all the Cubit MeshSets in a moFEM field.
#define _IT_CUBITMESHSETS_BY_SET_TYPE_FOR_LOOP_(MESHSET_MANAGER, CUBITBCTYPE, IT)
Iterator that loops over a specific Cubit MeshSet having a particular BC meshset in a moFEM field.
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
char mesh_file_name[255]
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
PetscErrorCode PetscOptionsGetString(PetscOptions *, const char pre[], const char name[], char str[], size_t size, PetscBool *set)
Managing BitRefLevels.
virtual moab::Interface & get_moab()=0
virtual EntityHandle get_field_meshset(const std::string name) const =0
get field meshset
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
void unSetSymm()
unset if operator is executed for non symmetric problem
Deprecated interface functions.
Data on single entity (This is passed as argument to DataOperator::doWork)
const VectorDouble & getFieldData() const
get dofs values
MatrixDouble & getCoordsAtGaussPts()
Gauss points and weight, matrix (nb. of points x 3)
boost::ptr_deque< UserDataOperator > & getOpPtrVector()
Use to push back operator for row operator.
Create interface from given surface and insert flat prisms in-between.
MoFEMErrorCode getSides(const int msId, const CubitBCType cubit_bc_type, const BitRefLevel mesh_bit_level, const bool recursive, int verb=QUIET)
Store tetrahedra from each side of the interface separately in two child meshsets of the parent meshs...
MoFEMErrorCode splitSides(const EntityHandle meshset, const BitRefLevel &bit, const int msId, const CubitBCType cubit_bc_type, const bool add_interface_entities, const bool recursive=false, int verb=QUIET)
Split nodes and other entities of tetrahedra on both sides of the interface and insert flat prisms in...
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.
MoFEMErrorCode doWork(int side, EntityType type, EntitiesFieldData::EntData &data)
Operator for linear form, usually to calculate values on right hand side.
Operator used to check consistency between local coordinates and global cooridnates for integrated po...
MoFEMErrorCode doWork(int side, EntityType type, EntitiesFieldData::EntData &data)
Operator for linear form, usually to calculate values on right hand side.