v0.14.0
hdiv_divergence_operator.cpp
Go to the documentation of this file.
1 /**
2  * \file hdiv_divergence_operator.cpp
3  * \example hdiv_divergence_operator.cpp
4  *
5  * Using PipelineManager interface calculate the divergence of base functions,
6  * and integral of flux on the boundary. Since the h-div space is used, volume
7  * integral and boundary integral should give the same result.
8  */
9 
10 
11 
12 #include <MoFEM.hpp>
13 
14 using namespace MoFEM;
15 
16 static char help[] = "...\n\n";
17 
20 
21  double &dIv;
22  OpVolDivergence(double &div)
24  "HDIV", UserDataOperator::OPROW),
25  dIv(div) {}
26 
27  MoFEMErrorCode doWork(int side, EntityType type,
29 };
30 
33 
34  double &dIv;
35  OpFacesFluxes(double &div)
37  "HDIV", UserDataOperator::OPROW),
38  dIv(div) {}
39 
40  MoFEMErrorCode doWork(int side, EntityType type,
42 };
43 
44 int main(int argc, char *argv[]) {
45 
46  MoFEM::Core::Initialize(&argc, &argv, (char *)0, help);
47 
48  try {
49 
50  enum bases { AINSWORTH, DEMKOWICZ, LASTOP };
51 
52  const char *list[] = {"ainsworth", "demkowicz"};
53 
54  PetscBool flg;
55  PetscInt choice_value = AINSWORTH;
56  CHKERR PetscOptionsGetEList(PETSC_NULL, NULL, "-base", list, LASTOP,
57  &choice_value, &flg);
58  if (flg != PETSC_TRUE) {
59  SETERRQ(PETSC_COMM_SELF, MOFEM_IMPOSSIBLE_CASE, "base not set");
60  }
61 
62  PetscBool ho_geometry = PETSC_FALSE;
63  CHKERR PetscOptionsGetBool(PETSC_NULL, "", "-ho_geometry", &ho_geometry,
64  PETSC_NULL);
65 
66  PetscInt ho_choice_value = AINSWORTH;
67  CHKERR PetscOptionsGetEList(PETSC_NULL, NULL, "-ho_base", list, LASTOP,
68  &ho_choice_value, &flg);
69 
70  DMType dm_name = "DMMOFEM";
71  CHKERR DMRegister_MoFEM(dm_name);
72 
73  // Create MoAB
74  moab::Core mb_instance; ///< database
75  moab::Interface &moab = mb_instance; ///< interface
76 
77  // Create MoFEM
78  MoFEM::Core core(moab);
79  MoFEM::Interface &m_field = core;
80 
81  Simple *simple_interface = m_field.getInterface<Simple>();
82  PipelineManager *pipeline_mng = m_field.getInterface<PipelineManager>();
83  CHKERR simple_interface->getOptions();
84  CHKERR simple_interface->loadFile("");
85 
86  // fields
87  switch (choice_value) {
88  case AINSWORTH:
89  CHKERR simple_interface->addDomainField("HDIV", HDIV,
91  CHKERR simple_interface->addBoundaryField("HDIV", HDIV,
93  break;
94  case DEMKOWICZ:
95  CHKERR simple_interface->addDomainField("HDIV", HDIV,
97  CHKERR simple_interface->addBoundaryField("HDIV", HDIV,
99  break;
100  }
101 
102  if (ho_geometry == PETSC_TRUE) {
103  switch (ho_choice_value) {
104  case AINSWORTH:
105  CHKERR simple_interface->addDataField("MESH_NODE_POSITIONS", H1,
107  case DEMKOWICZ:
108  CHKERR simple_interface->addDataField("MESH_NODE_POSITIONS", H1,
110  }
111  }
112 
113  constexpr int order = 3;
114  CHKERR simple_interface->setFieldOrder("HDIV", order);
115  if (ho_geometry == PETSC_TRUE)
116  CHKERR simple_interface->setFieldOrder("MESH_NODE_POSITIONS", 2);
117  CHKERR simple_interface->setUp();
118 
119  /// This has no real effect, folling line are only for atom test purpose
120  pipeline_mng->getDomainLhsFE().reset();
121  pipeline_mng->getDomainRhsFE().reset();
122  pipeline_mng->getBoundaryLhsFE().reset();
123  pipeline_mng->getBoundaryRhsFE().reset();
124  pipeline_mng->getSkeletonLhsFE().reset();
125  pipeline_mng->getSkeletonRhsFE().reset();
126 
127  auto integration_rule = [](int, int, int p_data) { return 2 * p_data; };
128  CHKERR pipeline_mng->setDomainRhsIntegrationRule(integration_rule);
129  CHKERR pipeline_mng->setBoundaryRhsIntegrationRule(integration_rule);
130 
131  double divergence_vol = 0;
132  double divergence_skin = 0;
133 
134  auto jac_ptr = boost::make_shared<MatrixDouble>();
135  auto inv_jac_ptr = boost::make_shared<MatrixDouble>();
136  auto det_ptr = boost::make_shared<VectorDouble>();
137  pipeline_mng->getOpDomainRhsPipeline().push_back(
138  new OpCalculateHOJac<3>(jac_ptr));
139  pipeline_mng->getOpDomainRhsPipeline().push_back(
140  new OpInvertMatrix<3>(jac_ptr, det_ptr, inv_jac_ptr));
141  pipeline_mng->getOpDomainRhsPipeline().push_back(
142  new OpSetHOContravariantPiolaTransform(HDIV, det_ptr, jac_ptr));
143  pipeline_mng->getOpDomainRhsPipeline().push_back(
144  new OpSetHOInvJacVectorBase(HDIV, inv_jac_ptr));
145  pipeline_mng->getOpDomainRhsPipeline().push_back(
146  new OpSetHOWeights(det_ptr));
147  pipeline_mng->getOpDomainRhsPipeline().push_back(
148  new OpVolDivergence(divergence_vol));
149 
150  if (m_field.check_field("MESH_NODE_POSITIONS"))
151  pipeline_mng->getOpBoundaryRhsPipeline().push_back(
152  new OpGetHONormalsOnFace("MESH_NODE_POSITIONS"));
153  pipeline_mng->getOpBoundaryRhsPipeline().push_back(
155  pipeline_mng->getOpBoundaryRhsPipeline().push_back(
156  new OpFacesFluxes(divergence_skin));
157 
158  // project geometry form 10 node tets on higher order approx. functions
159  if (ho_geometry == PETSC_TRUE) {
160  Projection10NodeCoordsOnField ent_method(m_field, "MESH_NODE_POSITIONS");
161  CHKERR m_field.loop_dofs("MESH_NODE_POSITIONS", ent_method);
162  }
163  CHKERR pipeline_mng->loopFiniteElements();
164 
165  MOFEM_LOG("WORLD", Sev::inform)
166  << "divergence_vol " << std::setprecision(12) << divergence_vol;
167  MOFEM_LOG("WORLD", Sev::inform)
168  << "divergence_skin " << std::setprecision(12) << divergence_skin;
169 
170  constexpr double eps = 1e-8;
171  const double error = divergence_skin - divergence_vol;
172  if (fabs(error) > eps)
173  SETERRQ1(PETSC_COMM_SELF, MOFEM_ATOM_TEST_INVALID,
174  "invalid surface flux or divergence or both error = %3.4e",
175  error);
176  }
177  CATCH_ERRORS;
178 
180 }
181 
183 OpVolDivergence::doWork(int side, EntityType type,
186 
187  if (CN::Dimension(type) < 2)
189 
190  if (data.getFieldData().size() == 0)
192 
193  int nb_gauss_pts = data.getDiffN().size1();
194  int nb_dofs = data.getFieldData().size();
195 
196  VectorDouble div_vec;
197  div_vec.resize(nb_dofs, 0);
198 
200  auto t_base_diff_hdiv = data.getFTensor2DiffN<3, 3>();
201 
202  for (size_t gg = 0; gg < nb_gauss_pts; gg++) {
203  for (size_t dd = 0; dd != div_vec.size(); dd++) {
204  double w = getGaussPts()(3, gg) * getVolume();
205  dIv += t_base_diff_hdiv(i, i) * w;
206  ++t_base_diff_hdiv;
207  }
208  }
209 
211 }
212 
216 
217  if (CN::Dimension(type) != 2)
219 
220  int nb_gauss_pts = data.getN().size1();
221  int nb_dofs = data.getFieldData().size();
222 
223  for (int gg = 0; gg < nb_gauss_pts; gg++) {
224  for (int dd = 0; dd < nb_dofs; dd++) {
225 
226  double w = getGaussPts()(2, gg);
227  const double n0 = getNormalsAtGaussPts(gg)[0];
228  const double n1 = getNormalsAtGaussPts(gg)[1];
229  const double n2 = getNormalsAtGaussPts(gg)[2];
230  if (getFEType() == MBTRI) {
231  w *= 0.5;
232  }
233 
234  dIv += (n0 * data.getVectorN<3>(gg)(dd, 0) +
235  n1 * data.getVectorN<3>(gg)(dd, 1) +
236  n2 * data.getVectorN<3>(gg)(dd, 2)) *
237  w;
238  }
239  }
240 
242 }
MoFEMFunctionReturnHot
#define MoFEMFunctionReturnHot(a)
Last executable line of each PETSc function used for error handling. Replaces return()
Definition: definitions.h:447
MoFEM::UnknownInterface::getInterface
MoFEMErrorCode getInterface(IFACE *&iface) const
Get interface refernce 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:127
main
int main(int argc, char *argv[])
Definition: hdiv_divergence_operator.cpp:44
MoFEM::CoreInterface::loop_dofs
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.
MoFEM::CoreTmp< 0 >
Core (interface) class.
Definition: Core.hpp:82
H1
@ H1
continuous field
Definition: definitions.h:85
PlasticOps::w
double w(double eqiv, double dot_tau, double f, double sigma_y, double sigma_Y)
Definition: PlasticOpsGeneric.hpp:276
MoFEM::OpSetHOContravariantPiolaTransform
Apply contravariant (Piola) transfer to Hdiv space for HO geometry.
Definition: HODataOperators.hpp:180
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:1241
OpFacesFluxes
Definition: hdiv_divergence_operator.cpp:31
MoFEM::Simple::loadFile
MoFEMErrorCode loadFile(const std::string options, const std::string mesh_file_name, LoadFileFunc loadFunc=defaultLoadFileFunc)
Load mesh file.
Definition: Simple.cpp:194
MoFEM::PipelineManager
PipelineManager interface.
Definition: PipelineManager.hpp:24
MoFEM.hpp
MoFEM::Projection10NodeCoordsOnField
Projection of edge entities with one mid-node on hierarchical basis.
Definition: Projection10NodeCoordsOnField.hpp:24
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:1316
OpVolDivergence::doWork
MoFEMErrorCode doWork(int side, EntityType type, EntitiesFieldData::EntData &data)
Operator for linear form, usually to calculate values on right hand side.
Definition: hdiv_divergence_operator.cpp:183
MoFEM::Simple
Simple interface for fast problem set-up.
Definition: Simple.hpp:27
MOFEM_IMPOSSIBLE_CASE
@ MOFEM_IMPOSSIBLE_CASE
Definition: definitions.h:35
order
constexpr int order
Definition: dg_projection.cpp:18
OpFacesFluxes::dIv
double & dIv
Definition: hdiv_divergence_operator.cpp:34
MoFEM::DeprecatedCoreInterface
Deprecated interface functions.
Definition: DeprecatedCoreInterface.hpp:16
MoFEM::Interface
DeprecatedCoreInterface Interface
Definition: Interface.hpp:1975
MoFEM::Simple::getOptions
MoFEMErrorCode getOptions()
get options
Definition: Simple.cpp:180
MoFEM::EntitiesFieldData::EntData::getFTensor2DiffN
FTensor::Tensor2< FTensor::PackPtr< double *, Tensor_Dim0 *Tensor_Dim1 >, Tensor_Dim0, Tensor_Dim1 > getFTensor2DiffN(FieldApproximationBase base)
Get derivatives of base functions for Hdiv space.
Definition: EntitiesFieldData.cpp:660
help
static char help[]
Definition: hdiv_divergence_operator.cpp:16
CHKERR
#define CHKERR
Inline error check.
Definition: definitions.h:535
MoFEM
implementation of Data Operators for Forces and Sources
Definition: Common.hpp:10
OpVolDivergence::OpVolDivergence
OpVolDivergence(double &div)
Definition: hdiv_divergence_operator.cpp:22
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
OpVolDivergence::dIv
double & dIv
Definition: hdiv_divergence_operator.cpp:21
MoFEM::Simple::addDomainField
MoFEMErrorCode addDomainField(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_ZERO, int verb=-1)
Add field on domain.
Definition: Simple.cpp:264
MoFEM::DMRegister_MoFEM
PetscErrorCode DMRegister_MoFEM(const char sname[])
Register MoFEM problem.
Definition: DMMoFEM.cpp:47
MoFEM::FaceElementForcesAndSourcesCore
Face finite element.
Definition: FaceElementForcesAndSourcesCore.hpp:23
MoFEM::OpCalculateHOJac< 3 >
Definition: HODataOperators.hpp:269
MoFEM::OpGetHONormalsOnFace
Calculate normals at Gauss points of triangle element.
Definition: HODataOperators.hpp:281
MoFEM::CoreInterface::check_field
virtual bool check_field(const std::string &name) const =0
check if field is in database
MoFEM::VolumeElementForcesAndSourcesCore
Volume finite element base.
Definition: VolumeElementForcesAndSourcesCore.hpp:26
i
FTensor::Index< 'i', SPACE_DIM > i
Definition: hcurl_divergence_operator_2d.cpp:27
MoFEM::Simple::addDataField
MoFEMErrorCode addDataField(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_ZERO, int verb=-1)
Add field on domain.
Definition: Simple.cpp:320
MoFEM::VolumeElementForcesAndSourcesCore::UserDataOperator
Definition: VolumeElementForcesAndSourcesCore.hpp:108
FTensor::Index< 'i', 3 >
MoFEM::Simple::setFieldOrder
MoFEMErrorCode setFieldOrder(const std::string field_name, const int order, const Range *ents=NULL)
Set field order.
Definition: Simple.cpp:473
MoFEM::EntitiesFieldData::EntData::getVectorN
const MatrixAdaptor getVectorN(const FieldApproximationBase base, const int gg)
get Hdiv of base functions at Gauss pts
Definition: EntitiesFieldData.hpp:1434
integration_rule
auto integration_rule
Definition: free_surface.cpp:185
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
MOFEM_LOG
#define MOFEM_LOG(channel, severity)
Log.
Definition: LogManager.hpp:308
CATCH_ERRORS
#define CATCH_ERRORS
Catch errors.
Definition: definitions.h:372
DEMKOWICZ_JACOBI_BASE
@ DEMKOWICZ_JACOBI_BASE
Definition: definitions.h:66
OpVolDivergence
Definition: hdiv_divergence_operator.cpp:18
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:1305
MoFEM::Core
CoreTmp< 0 > Core
Definition: Core.hpp:1094
eps
static const double eps
Definition: check_base_functions_derivatives_on_tet.cpp:11
OpFacesFluxes::doWork
MoFEMErrorCode doWork(int side, EntityType type, EntitiesFieldData::EntData &data)
Operator for linear form, usually to calculate values on right hand side.
Definition: hdiv_divergence_operator.cpp:213
MoFEM::OpSetHOWeights
Set inverse jacobian to base functions.
Definition: HODataOperators.hpp:159
AINSWORTH_LEGENDRE_BASE
@ AINSWORTH_LEGENDRE_BASE
Ainsworth Cole (Legendre) approx. base .
Definition: definitions.h:60
MoFEM::PetscOptionsGetEList
PetscErrorCode PetscOptionsGetEList(PetscOptions *, const char pre[], const char name[], const char *const *list, PetscInt next, PetscInt *value, PetscBool *set)
Definition: DeprecatedPetsc.hpp:203
MoFEM::OpInvertMatrix
Definition: UserDataOperators.hpp:3254
OpFacesFluxes::OpFacesFluxes
OpFacesFluxes(double &div)
Definition: hdiv_divergence_operator.cpp:35
MoFEM::Types::VectorDouble
UBlasVector< double > VectorDouble
Definition: Types.hpp:68
MoFEM::Simple::addBoundaryField
MoFEMErrorCode addBoundaryField(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_ZERO, int verb=-1)
Add field on boundary.
Definition: Simple.cpp:282
MoFEM::OpSetHOInvJacVectorBase
transform local reference derivatives of shape function to global derivatives if higher order geometr...
Definition: HODataOperators.hpp:91
MOFEM_ATOM_TEST_INVALID
@ MOFEM_ATOM_TEST_INVALID
Definition: definitions.h:40
MoFEMFunctionBeginHot
#define MoFEMFunctionBeginHot
First executable line of each MoFEM function, used for error handling. Final line of MoFEM functions ...
Definition: definitions.h:440
MoFEM::Simple::setUp
MoFEMErrorCode setUp(const PetscBool is_partitioned=PETSC_TRUE)
Setup problem.
Definition: Simple.cpp:611
FractureMechanics::LASTOP
@ LASTOP
Definition: CrackFrontElement.hpp:23
convert.int
int
Definition: convert.py:64
MoFEMFunctionReturn
#define MoFEMFunctionReturn(a)
Last executable line of each PETSc function used for error handling. Replaces return()
Definition: definitions.h:416
HDIV
@ HDIV
field with continuous normal traction
Definition: definitions.h:87
MoFEMFunctionBegin
#define MoFEMFunctionBegin
First executable line of each MoFEM function, used for error handling. Final line of MoFEM functions ...
Definition: definitions.h:346
MoFEM::PetscOptionsGetBool
PetscErrorCode PetscOptionsGetBool(PetscOptions *, const char pre[], const char name[], PetscBool *bval, PetscBool *set)
Definition: DeprecatedPetsc.hpp:182