v0.14.0
fluid_pressure_element.cpp
Go to the documentation of this file.
1 /** \file fluid_pressure_element.cpp
2 
3  \brief Atom test for fluid pressure element
4 
5 */
6 
7 
8 
10 using namespace MoFEM;
11 
12 namespace bio = boost::iostreams;
13 using bio::stream;
14 using bio::tee_device;
15 
16 static char help[] = "...\n\n";
17 
18 int main(int argc, char *argv[]) {
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();
94  CHKERR m_field.build_finite_elements();
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);
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  }
178  CATCH_ERRORS;
179 
181 
182  return 0;
183 }
MoFEM::UnknownInterface::getInterface
MoFEMErrorCode getInterface(IFACE *&iface) const
Get interface refernce to pointer of interface.
Definition: UnknownInterface.hpp:93
MoFEM::CoreInterface::loop_finite_elements
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.
FluidPressure::addNeumannFluidPressureBCElements
MoFEMErrorCode addNeumannFluidPressureBCElements(const std::string field_name, const std::string mesh_nodals_positions="MESH_NODE_POSITIONS")
Definition: FluidPressure.cpp:67
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
EntityHandle
MoFEM::ProblemsManager
Problem manager is used to build and partition problems.
Definition: ProblemsManager.hpp:21
BasicFiniteElements.hpp
MoFEM::CoreTmp< 0 >::Finalize
static MoFEMErrorCode Finalize()
Checks for options to be called at the conclusion of the program.
Definition: Core.cpp:112
main
int main(int argc, char *argv[])
Definition: fluid_pressure_element.cpp:18
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.
order
constexpr int order
Definition: dg_projection.cpp:18
MoFEM::DeprecatedCoreInterface
Deprecated interface functions.
Definition: DeprecatedCoreInterface.hpp:16
ROW
@ ROW
Definition: definitions.h:123
MoFEM::Interface
DeprecatedCoreInterface Interface
Definition: Interface.hpp:1975
help
static char help[]
Definition: fluid_pressure_element.cpp:16
MoFEM::Exceptions::rval
static MoFEMErrorCodeGeneric< moab::ErrorCode > rval
Definition: Exceptions.hpp:74
CHKERR
#define CHKERR
Inline error check.
Definition: definitions.h:535
MoFEM
implementation of Data Operators for Forces and Sources
Definition: Common.hpp:10
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.
FluidPressure
Fluid pressure forces.
Definition: FluidPressure.hpp:20
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
MoFEM::VecManager
Vector manager is used to create vectors \mofem_vectors.
Definition: VecManager.hpp:23
mesh_file_name
char mesh_file_name[255]
Definition: mesh_smoothing.cpp:23
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
FluidPressure::getLoopFe
MyTriangleFE & getLoopFe()
Definition: FluidPressure.hpp:35
CATCH_ERRORS
#define CATCH_ERRORS
Catch errors.
Definition: definitions.h:372
MoFEM::Core
CoreTmp< 0 > Core
Definition: Core.hpp:1094
FluidPressure::setNeumannFluidPressureFiniteElementOperators
MoFEMErrorCode setNeumannFluidPressureFiniteElementOperators(string field_name, Vec F, bool allow_negative_pressure=true, bool ho_geometry=false)
Definition: FluidPressure.cpp:131
MoFEM::ProblemsManager::partitionSimpleProblem
MoFEMErrorCode partitionSimpleProblem(const std::string name, int verb=VERBOSE)
partition problem dofs
Definition: ProblemsManager.cpp:1537
AINSWORTH_LEGENDRE_BASE
@ AINSWORTH_LEGENDRE_BASE
Ainsworth Cole (Legendre) approx. base .
Definition: definitions.h:60
EigenMatrix::Vec
const FTensor::Tensor2< T, Dim, Dim > Vec
Definition: MatrixFunction.hpp:66
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::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_ATOM_TEST_INVALID
@ MOFEM_ATOM_TEST_INVALID
Definition: definitions.h: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.
F
@ F
Definition: free_surface.cpp:394