v0.14.0
Functions | Variables
forces_and_sources_hdiv_approximation_functions.cpp File Reference
#include <MoFEM.hpp>

Go to the source code of this file.

Functions

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

Variables

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

Function Documentation

◆ main()

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

Definition at line 13 of file forces_and_sources_hdiv_approximation_functions.cpp.

13  {
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
100  CHKERR m_field.build_finite_elements();
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)
210  : FaceElementForcesAndSourcesCore(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  }
228  CATCH_ERRORS;
229 
231 }

Variable Documentation

◆ help

char help[] = "...\n\n"
static
MoFEMFunctionReturnHot
#define MoFEMFunctionReturnHot(a)
Last executable line of each PETSc function used for error handling. Replaces return()
Definition: definitions.h:460
MoFEM::UnknownInterface::getInterface
MoFEMErrorCode getInterface(IFACE *&iface) const
Get interface reference to pointer of interface.
Definition: UnknownInterface.hpp:93
MoFEM::EntitiesFieldData::EntData
Data on single entity (This is passed as argument to DataOperator::doWork)
Definition: EntitiesFieldData.hpp:128
TeeStream
stream< TeeDevice > TeeStream
Definition: forces_and_sources_testing_contact_prism_element.cpp:10
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.
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
EntityHandle
MoFEM::ProblemsManager
Problem manager is used to build and partition problems.
Definition: ProblemsManager.hpp:21
MoFEM::CoreInterface::modify_finite_element_add_field_row
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
MoFEM::Exceptions::MoFEMErrorCode
PetscErrorCode MoFEMErrorCode
MoFEM/PETSc error code.
Definition: Exceptions.hpp:56
MoFEM::OpHOSetContravariantPiolaTransformOnFace3D
transform Hdiv base fluxes from reference element to physical triangle
Definition: HODataOperators.hpp:298
MoFEM::EntitiesFieldData::EntData::getFieldData
const VectorDouble & getFieldData() const
get dofs values
Definition: EntitiesFieldData.hpp:1254
MoFEM::CoreTmp< 0 >::Finalize
static MoFEMErrorCode Finalize()
Checks for options to be called at the conclusion of the program.
Definition: Core.cpp:112
MoFEM::EntitiesFieldData::EntData::getDiffN
MatrixDouble & getDiffN(const FieldApproximationBase base)
get derivatives of base functions
Definition: EntitiesFieldData.hpp:1329
MoFEM::DataOperator::doWork
virtual MoFEMErrorCode doWork(int row_side, int col_side, EntityType row_type, EntityType col_type, EntitiesFieldData::EntData &row_data, EntitiesFieldData::EntData &col_data)
Operator for bi-linear form, usually to calculate values on left hand side.
Definition: DataOperators.hpp:40
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
TeeDevice
tee_device< std::ostream, std::ofstream > TeeDevice
Definition: forces_and_sources_testing_contact_prism_element.cpp:9
MoFEM::Interface
DeprecatedCoreInterface Interface
Definition: Interface.hpp:2010
MoFEM::CoreInterface::add_ents_to_finite_element_by_type
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
help
static char help[]
Definition: forces_and_sources_hdiv_approximation_functions.cpp:11
CHKERR
#define CHKERR
Inline error check.
Definition: definitions.h:548
MoFEM::CoreInterface::add_finite_element
virtual MoFEMErrorCode add_finite_element(const std::string &fe_name, enum MoFEMTypes bh=MF_EXCL, int verb=DEFAULT_VERBOSITY)=0
add finite element
MoFEM::CoreInterface::modify_finite_element_add_field_col
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
MoFEM::CoreInterface::build_finite_elements
virtual MoFEMErrorCode build_finite_elements(int verb=DEFAULT_VERBOSITY)=0
Build finite elements.
MoFEM::ForcesAndSourcesCore::UserDataOperator
Definition: ForcesAndSourcesCore.hpp:549
MoFEM::FaceElementForcesAndSourcesCore::UserDataOperator
default operator for TRI element
Definition: FaceElementForcesAndSourcesCore.hpp:94
convert.type
type
Definition: convert.py:64
MoFEM::ForcesAndSourcesCore::getRule
virtual int getRule(int order_row, int order_col, int order_data)
another variant of getRule
Definition: ForcesAndSourcesCore.cpp:1955
MoFEM::FaceElementForcesAndSourcesCore
Face finite element.
Definition: FaceElementForcesAndSourcesCore.hpp:23
MoFEM::CoreInterface::modify_finite_element_add_field_data
virtual MoFEMErrorCode modify_finite_element_add_field_data(const std::string &fe_name, const std::string name_field)=0
set finite element field data
MoFEM::VolumeElementForcesAndSourcesCore
Volume finite element base.
Definition: VolumeElementForcesAndSourcesCore.hpp:26
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::VolumeElementForcesAndSourcesCore::UserDataOperator
Definition: VolumeElementForcesAndSourcesCore.hpp:108
Range
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
FTensor::dd
const Tensor2_symmetric_Expr< const ddTensor0< T, Dim, i, j >, typename promote< T, double >::V, Dim, i, j > dd(const Tensor0< T * > &a, const Index< i, Dim > index1, const Index< j, Dim > index2, const Tensor1< int, Dim > &d_ijk, const Tensor1< double, Dim > &d_xyz)
Definition: ddTensor0.hpp:33
CATCH_ERRORS
#define CATCH_ERRORS
Catch errors.
Definition: definitions.h:385
MoFEM::EntitiesFieldData::EntData::getN
MatrixDouble & getN(const FieldApproximationBase base)
get base functions this return matrix (nb. of rows is equal to nb. of Gauss pts, nb....
Definition: EntitiesFieldData.hpp:1318
MoFEM::Core
CoreTmp< 0 > Core
Definition: Core.hpp:1148
MoFEM::ProblemsManager::partitionSimpleProblem
MoFEMErrorCode partitionSimpleProblem(const std::string name, int verb=VERBOSE)
partition problem dofs
Definition: ProblemsManager.cpp:1537
eps
static const double eps
Definition: check_base_functions_derivatives_on_tet.cpp:11
AINSWORTH_LEGENDRE_BASE
@ AINSWORTH_LEGENDRE_BASE
Ainsworth Cole (Legendre) approx. base .
Definition: definitions.h:60
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::CoreInterface::build_adjacencies
virtual MoFEMErrorCode build_adjacencies(const Range &ents, int verb=DEFAULT_VERBOSITY)=0
build adjacencies
MoFEMFunctionBeginHot
#define MoFEMFunctionBeginHot
First executable line of each MoFEM function, used for error handling. Final line of MoFEM functions ...
Definition: definitions.h:453
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.
HDIV
@ HDIV
field with continuous normal traction
Definition: definitions.h:87
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.