v0.14.0
Loading...
Searching...
No Matches
Functions | Variables
fluid_pressure_element.cpp File Reference

Atom test for fluid pressure element. More...

#include <BasicFiniteElements.hpp>

Go to the source code of this file.

Functions

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

Variables

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

Detailed Description

Atom test for fluid pressure element.

Definition in file fluid_pressure_element.cpp.

Function Documentation

◆ main()

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

add probelem which will be solved, could be more than one problem

Definition at line 18 of file fluid_pressure_element.cpp.

18 {
19
20 MoFEM::Core::Initialize(&argc, &argv, (char *)0, help);
21
22 try {
23
24 moab::Core mb_instance;
25 moab::Interface &moab = mb_instance;
26
27 PetscBool flg = PETSC_TRUE;
28 char mesh_file_name[255];
29 CHKERR PetscOptionsGetString(PETSC_NULL, PETSC_NULL, "-my_file",
30 mesh_file_name, 255, &flg);
31 if (flg != PETSC_TRUE) {
32 SETERRQ(PETSC_COMM_SELF, 1, "*** ERROR -my_file (MESH FILE NEEDED)");
33 }
34
35 const char *option;
36 option = ""; //"PARALLEL=BCAST;";//;DEBUG_IO";
37 rval = moab.load_file(mesh_file_name, 0, option);
38
39 // Create MoFEM (Joseph) database
40 MoFEM::Core core(moab);
41 MoFEM::Interface &m_field = core;
42
43 // set entitities bit level
44 BitRefLevel bit_level0;
45 bit_level0.set(0);
46 EntityHandle meshset_level0;
47 rval = moab.create_meshset(MESHSET_SET, meshset_level0);
48 CHKERR m_field.getInterface<BitRefManager>()->setBitRefLevelByDim(
49 0, 3, bit_level0);
50
51 // Definitions
52
53 // add DISPLACEMENT field, Hilbert space H1, vector field rank 3 (displacemnt
54 // has three components ux,uy,uz)
55 CHKERR m_field.add_field("DISPLACEMENT", H1, AINSWORTH_LEGENDRE_BASE, 3);
56
57 // add entities on which DISPLACEMENT field is approximated, you can add
58 // entities form several approximation levels at once. You can as well
59 // approximate field only on some mesh subdomain, in that case displacements
60 // are approximated on root moab mesh.
61 CHKERR m_field.add_ents_to_field_by_type(0, MBTET, "DISPLACEMENT");
62
63 // set app. order for displacement field. it is set uniform approximation
64 // order. in genreal every entity can have arbitrary approximation level,
65 // ranging from 1 to 10 and more.
66 int order = 1;
67 CHKERR m_field.set_field_order(0, MBTET, "DISPLACEMENT", order);
68 CHKERR m_field.set_field_order(0, MBTRI, "DISPLACEMENT", order);
69 CHKERR m_field.set_field_order(0, MBEDGE, "DISPLACEMENT", order);
70 CHKERR m_field.set_field_order(0, MBVERTEX, "DISPLACEMENT", 1);
71
72 // define fluid pressure finite elements
73 FluidPressure fluid_pressure_fe(m_field);
74 fluid_pressure_fe.addNeumannFluidPressureBCElements("DISPLACEMENT");
75
76 /// add probelem which will be solved, could be more than one problem
77 // operating on some subset of defined approximation spaces
78 CHKERR m_field.add_problem("TEST_PROBLEM");
79 // mesh could have several Refinement levels which share some subset of
80 // entities between them. below defines on which set of entities (on
81 // Refinement level 0) build approximation spaces for TEST_PROBLEM
82 CHKERR m_field.modify_problem_ref_level_add_bit("TEST_PROBLEM", bit_level0);
83
84 // add finite element to test problem
85 CHKERR m_field.modify_problem_add_finite_element("TEST_PROBLEM",
86 "FLUID_PRESSURE_FE");
87
88 // construct data structures for fields and finite elements. at that points
89 // entities, finite elements or dofs have unique uid, but are not
90 // partitioned or numbered. user can add entities to mesh, add dofs or
91 // elements if necessary. in case of modifications data structures are
92 // updated.
93 CHKERR m_field.build_fields();
95 CHKERR m_field.build_adjacencies(bit_level0);
96
97 ProblemsManager *prb_mng_ptr;
98 CHKERR m_field.getInterface(prb_mng_ptr);
99 CHKERR prb_mng_ptr->buildProblem("TEST_PROBLEM", true);
100 // to solve problem it need to be represented in matrix vector form. this
101 // demand numeration of dofs and problem partitioning.
102 CHKERR prb_mng_ptr->partitionSimpleProblem("TEST_PROBLEM");
103 CHKERR prb_mng_ptr->partitionFiniteElements("TEST_PROBLEM");
104 // what are ghost nodes, see Petsc Manual
105 CHKERR prb_mng_ptr->partitionGhostDofs("TEST_PROBLEM");
106
107 // create vector for problem
108 Vec F;
109 CHKERR m_field.getInterface<VecManager>()->vecCreateGhost("TEST_PROBLEM",
110 ROW, &F);
111 CHKERR fluid_pressure_fe.setNeumannFluidPressureFiniteElementOperators(
112 "DISPLACEMENT", F, false, false);
113
114 CHKERR VecZeroEntries(F);
115 CHKERR m_field.loop_finite_elements("TEST_PROBLEM", "FLUID_PRESSURE_FE",
116 fluid_pressure_fe.getLoopFe());
117 CHKERR VecAssemblyBegin(F);
118 CHKERR VecAssemblyEnd(F);
119 CHKERR m_field.getInterface<VecManager>()->setGlobalGhostVector(
120 "TEST_PROBLEM", ROW, F, INSERT_VALUES, SCATTER_REVERSE);
121
122 // CHKERR VecView(F,PETSC_VIEWER_STDOUT_WORLD);
123
124 // PetscViewer viewer;
125 // CHKERR
126 // PetscViewerASCIIOpen(PETSC_COMM_WORLD,"fluid_pressure_element.txt",&viewer);
127 // CHKERR VecChop(F,1e-4);
128 // CHKERR VecView(F,viewer);
129 // CHKERR PetscViewerDestroy(&viewer);
130
131 double sum = 0;
132 CHKERR VecSum(F, &sum);
133 CHKERR PetscPrintf(PETSC_COMM_WORLD, "sum = %4.3e\n", sum);
134 if (fabs(sum - 1.0) > 1e-8) {
135 SETERRQ(PETSC_COMM_WORLD, MOFEM_ATOM_TEST_INVALID, "Failed to pass test");
136 }
137 double fnorm;
138 CHKERR VecNorm(F, NORM_2, &fnorm);
139 CHKERR PetscPrintf(PETSC_COMM_WORLD, "fnorm = %9.8e\n", fnorm);
140 if (fabs(fnorm - 6.23059402e-01) > 1e-6) {
141 SETERRQ(PETSC_COMM_WORLD, MOFEM_ATOM_TEST_INVALID, "Failed to pass test");
142 }
143
144 // std::map<EntityHandle,VectorDouble > tags_vals;
145 // for(_IT_GET_DOFS_FIELD_BY_NAME_FOR_LOOP_(m_field,"DISPLACEMENT",dof)) {
146 // tags_vals[dof->getEnt()].resize(3);
147 // tags_vals[dof->getEnt()][dof->getDofCoeffIdx()] = dof->getFieldData();
148 // }
149 // std::vector<EntityHandle> ents;
150 // ents.resize(tags_vals.size());
151 // std::vector<double> vals(3*tags_vals.size());
152 // int idx = 0;
153 // for(std::map<EntityHandle,VectorDouble >::iterator mit =
154 // tags_vals.begin();
155 // mit!=tags_vals.end();mit++,idx++) {
156 // ents[idx] = mit->first;
157 // vals[3*idx + 0] = mit->second[0];
158 // vals[3*idx + 1] = mit->second[1];
159 // vals[3*idx + 2] = mit->second[2];
160 // }
161 //
162 // double def_VAL[3] = {0,0,0};
163 // Tag th_vals;
164 // rval =
165 // moab.tag_get_handle("FLUID_PRESURE_FORCES",3,MB_TYPE_DOUBLE,th_vals,MB_TAG_CREAT|MB_TAG_SPARSE,def_VAL);
166 // rval = moab.tag_set_data(th_vals,&ents[0],ents.size(),&vals[0]);
167 //
168 // EntityHandle out_meshset;
169 // rval = moab.create_meshset(MESHSET_SET,out_meshset);
170 // CHKERR
171 // m_field.get_problem_finite_elements_entities("TEST_PROBLEM","FLUID_PRESSURE_FE",out_meshset);
172 // rval = moab.write_file("out.vtk","VTK","",&out_meshset,1);
173 // rval = moab.delete_entities(&out_meshset,1);
174
175 // destroy vector
176 CHKERR VecDestroy(&F);
177 }
179
181
182 return 0;
183}
@ ROW
#define CATCH_ERRORS
Catch errors.
@ AINSWORTH_LEGENDRE_BASE
Ainsworth Cole (Legendre) approx. base .
Definition definitions.h:60
@ H1
continuous field
Definition definitions.h:85
@ MOFEM_ATOM_TEST_INVALID
Definition definitions.h:40
#define CHKERR
Inline error check.
constexpr int order
static char help[]
@ F
virtual MoFEMErrorCode build_finite_elements(int verb=DEFAULT_VERBOSITY)=0
Build finite elements.
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
char mesh_file_name[255]
static MoFEMErrorCodeGeneric< moab::ErrorCode > rval
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)
Fluid pressure forces.
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.
MoFEMErrorCode getInterface(IFACE *&iface) const
Get interface refernce to pointer of interface.
Vector manager is used to create vectors \mofem_vectors.

Variable Documentation

◆ help

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

Definition at line 16 of file fluid_pressure_element.cpp.