v0.14.0
continuity_check_on_skeleton_with_simple_2d_for_hdiv.cpp
Go to the documentation of this file.
1 /**
2  * \file continuity_check_on_skeleton_with_simple_2d_for_hdiv.cpp
3  * \ingroup mofem_simple_interface
4  * \example continuity_check_on_skeleton_with_simple_2d_for_hdiv.cpp
5  *
6  * \brief Integration on skeleton for 2d
7  *
8  * Teting integration on skeleton and checking of continuity of hcurl space on
9  * edges.
10  */
11 
12 #include <MoFEM.hpp>
13 using namespace MoFEM;
14 
15 static char help[] = "...\n\n";
16 
21 
22 struct CommonData {
23  MatrixDouble dotEdge;
24  MatrixDouble dotEleLeft;
25  MatrixDouble dotEleRight;
26 };
27 
28 struct SkeletonFE : public EdgeEleOp {
29 
30  struct OpFaceSide : public FaceEleOnSideOp {
31 
32  CommonData &elemData;
33  OpFaceSide(CommonData &elem_data)
34  : FaceEleOnSideOp("FIELD", UserDataOperator::OPROW), elemData(elem_data) {}
35 
36  MoFEMErrorCode doWork(int side, EntityType type,
39 
40  if (type == MBEDGE && side == getEdgeSideNumber()) {
41 
42  MatrixDouble diff = getCoordsAtGaussPts() - getEdgeCoordsAtGaussPts();
43 
44  const double eps = 1e-12;
45  if (norm_inf(diff) > eps)
46  SETERRQ(PETSC_COMM_WORLD, MOFEM_ATOM_TEST_INVALID,
47  "coordinates at integration pts are different");
48 
49  const size_t nb_dofs = data.getN().size2() / 3;
50  const size_t nb_integration_pts = data.getN().size1();
51 
52  auto &dir = getDirection();
53  FTensor::Tensor1<double, 2> t_normal{-dir(1), dir(0)};
54  auto t_hdiv_base = data.getFTensor1N<3>();
56  MatrixDouble *ptr_dot_elem_data = nullptr;
57  if (getFEMethod()->nInTheLoop == 0)
58  ptr_dot_elem_data = &elemData.dotEleLeft;
59  else
60  ptr_dot_elem_data = &elemData.dotEleRight;
61  MatrixDouble &dot_elem_data = *ptr_dot_elem_data;
62  dot_elem_data.resize(nb_integration_pts, nb_dofs, false);
63 
64  for (size_t gg = 0; gg != nb_integration_pts; ++gg) {
65  for (size_t bb = 0; bb != nb_dofs; ++bb) {
66  dot_elem_data(gg, bb) = t_normal(i) * t_hdiv_base(i);
67  ++t_hdiv_base;
68  }
69  }
70  }
72  }
73  };
74 
75  CommonData &elemData;
76  FaceEleOnSide faceSideFe;
77 
78  SkeletonFE(MoFEM::Interface &m_field, CommonData &elem_data)
79  : EdgeEle::UserDataOperator("FIELD", UserDataOperator::OPROW),
80  faceSideFe(m_field), elemData(elem_data) {
81 
82  auto jac_ptr = boost::make_shared<MatrixDouble>();
83  faceSideFe.getOpPtrVector().push_back(
84  new OpCalculateHOJacForFace(jac_ptr));
85  faceSideFe.getOpPtrVector().push_back(new OpMakeHdivFromHcurl());
86  faceSideFe.getOpPtrVector().push_back(
88  faceSideFe.getOpPtrVector().push_back(
89  new SkeletonFE::OpFaceSide(elemData));
90 
91  }
92 
93  MoFEMErrorCode doWork(int side, EntityType type,
95 
97  if (type == MBEDGE) {
98 
99  const size_t nb_dofs = data.getN().size2() / 3;
100  const size_t nb_integration_pts = data.getN().size1();
101 
102  auto &dir = getDirection();
103  FTensor::Tensor1<double, 2> t_normal{-dir(1), dir(0)};
104  auto t_hdiv_base = data.getFTensor1N<3>();
106  elemData.dotEdge.resize(nb_integration_pts, nb_dofs, false);
107  elemData.dotEleLeft.resize(nb_integration_pts, 0, false);
108  elemData.dotEleRight.resize(nb_integration_pts, 0, false);
109 
110  for (size_t gg = 0; gg != nb_integration_pts; ++gg) {
111  for (size_t bb = 0; bb != nb_dofs; ++bb) {
112  elemData.dotEdge(gg, bb) = t_normal(i) * t_hdiv_base(i);
113  ++t_hdiv_base;
114  }
115  }
116 
117  CHKERR loopSideFaces("dFE", faceSideFe);
118 
119  auto check_continuity_of_base = [&](auto &vol_dot_data) {
121 
122  if (vol_dot_data.size1() != elemData.dotEdge.size1())
123  SETERRQ(PETSC_COMM_SELF, MOFEM_ATOM_TEST_INVALID,
124  "Inconsistent number of integration points");
125 
126  if (vol_dot_data.size2() != elemData.dotEdge.size2())
127  SETERRQ(PETSC_COMM_SELF, MOFEM_ATOM_TEST_INVALID,
128  "Inconsistent number of base functions");
129  const double eps = 1e-12;
130  for (size_t gg = 0; gg != vol_dot_data.size1(); ++gg)
131  for (size_t bb = 0; bb != vol_dot_data.size2(); ++bb) {
132  const double error =
133  std::abs(vol_dot_data(gg, bb) - elemData.dotEdge(gg, bb));
134  if (error > eps)
135  SETERRQ4(PETSC_COMM_SELF, MOFEM_ATOM_TEST_INVALID,
136  "Inconsistency (%d, %d) %3.4e != %3.4e", gg, bb,
137  vol_dot_data(gg, bb), elemData.dotEdge(gg, bb));
138  }
140  };
141 
142  if (elemData.dotEleLeft.size2() != 0)
143  CHKERR check_continuity_of_base(elemData.dotEleLeft);
144  else if (elemData.dotEleRight.size2() != 0)
145  CHKERR check_continuity_of_base(elemData.dotEleRight);
146 
147  }
149  }
150 };
151 
152 int main(int argc, char *argv[]) {
153 
154  // initialize petsc
155  MoFEM::Core::Initialize(&argc, &argv, (char *)0, help);
156 
157  try {
158 
159  // Create MoAB database
160  moab::Core moab_core;
161  moab::Interface &moab = moab_core;
162 
163  // Create MoFEM database and link it to MoAB
164  MoFEM::Core mofem_core(moab);
165  MoFEM::Interface &m_field = mofem_core;
166 
167  // Register DM Manager
168  DMType dm_name = "DMMOFEM";
169  CHKERR DMRegister_MoFEM(dm_name);
170 
171  // Simple interface
172  Simple *simple_interface;
173  CHKERR m_field.getInterface(simple_interface);
174  {
175  // get options from command line
176  CHKERR simple_interface->getOptions();
177  // load mesh file
178  CHKERR simple_interface->loadFile("");
179 
180  auto get_base = []() -> FieldApproximationBase {
181  enum bases { AINSWORTH, DEMKOWICZ, LASTBASEOP };
182  const char *list_bases[] = {"ainsworth", "demkowicz"};
183  PetscBool flg;
184  PetscInt choice_base_value = AINSWORTH;
185  CHKERR PetscOptionsGetEList(PETSC_NULL, NULL, "-base", list_bases,
186  LASTBASEOP, &choice_base_value, &flg);
187  if (flg == PETSC_TRUE) {
189  if (choice_base_value == AINSWORTH)
191  else if (choice_base_value == DEMKOWICZ)
192  base = DEMKOWICZ_JACOBI_BASE;
193  return base;
194  }
195  return LASTBASE;
196  };
197 
198  // add fields
199  auto base = get_base();
200  CHKERR simple_interface->addDomainField("FIELD", HCURL, base, 1);
201  CHKERR simple_interface->addSkeletonField("FIELD", HCURL, base, 1);
202  // set fields order
203  CHKERR simple_interface->setFieldOrder("FIELD", 2);
204  // setup problem
205  CHKERR simple_interface->setUp();
206  // get dm
207  auto dm = simple_interface->getDM();
208 
209  // create elements
210  CommonData elem_data;
211  boost::shared_ptr<EdgeEle> skeleton_fe =
212  boost::shared_ptr<EdgeEle>(new EdgeEle(m_field));
213 
214  skeleton_fe->getOpPtrVector().push_back(
216  skeleton_fe->getOpPtrVector().push_back(
217  new SkeletonFE(m_field, elem_data));
218 
219  // iterate skeleton finite elements
220  CHKERR DMoFEMLoopFiniteElements(dm, simple_interface->getSkeletonFEName(),
221  skeleton_fe);
222  }
223  }
224  CATCH_ERRORS;
225 
226  // finish work cleaning memory, getting statistics, etc.
228 
229  return 0;
230 }
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::EdgeElementForcesAndSourcesCore
Edge finite element.
Definition: EdgeElementForcesAndSourcesCore.hpp:30
MoFEM::EntitiesFieldData::EntData
Data on single entity (This is passed as argument to DataOperator::doWork)
Definition: EntitiesFieldData.hpp:128
CommonData::dotEdge
MatrixDouble dotEdge
Definition: continuity_check_on_skeleton_with_simple_2d_for_h1.cpp:23
MoFEM::CoreTmp< 0 >
Core (interface) class.
Definition: Core.hpp:82
LASTBASE
@ LASTBASE
Definition: definitions.h:69
FTensor::Tensor1
Definition: Tensor1_value.hpp:8
MoFEM::OpSetContravariantPiolaTransformOnFace2D
OpSetContravariantPiolaTransformOnFace2DImpl< 2 > OpSetContravariantPiolaTransformOnFace2D
Definition: UserDataOperators.hpp:3076
SkeletonFE::OpFaceSide
Definition: continuity_check_on_skeleton_with_simple_2d_for_h1.cpp:30
MoFEM::Exceptions::MoFEMErrorCode
PetscErrorCode MoFEMErrorCode
MoFEM/PETSc error code.
Definition: Exceptions.hpp:56
CommonData::dotEleLeft
MatrixDouble dotEleLeft
Definition: continuity_check_on_skeleton_with_simple_2d_for_h1.cpp:24
MoFEM::Types::MatrixDouble
UBlasMatrix< double > MatrixDouble
Definition: Types.hpp:77
MoFEM::Simple::getSkeletonFEName
const std::string getSkeletonFEName() const
Get the Skeleton FE Name.
Definition: Simple.hpp:382
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.hpp
EdgeEle
MoFEM::EdgeElementForcesAndSourcesCore EdgeEle
Definition: continuity_check_on_skeleton_with_simple_2d_for_hdiv.cpp:18
MoFEM::CoreTmp< 0 >::Finalize
static MoFEMErrorCode Finalize()
Checks for options to be called at the conclusion of the program.
Definition: Core.cpp:112
SkeletonFE::OpFaceSide::doWork
MoFEMErrorCode doWork(int side, EntityType type, EntitiesFieldData::EntData &data)
Operator for linear form, usually to calculate values on right hand side.
Definition: continuity_check_on_skeleton_with_simple_2d_for_hdiv.cpp:36
MoFEM::Simple
Simple interface for fast problem set-up.
Definition: Simple.hpp:27
SkeletonFE
Definition: continuity_check_on_skeleton_with_simple_2d_for_h1.cpp:28
help
static char help[]
Definition: continuity_check_on_skeleton_with_simple_2d_for_hdiv.cpp:15
MoFEM::DeprecatedCoreInterface
Deprecated interface functions.
Definition: DeprecatedCoreInterface.hpp:16
SkeletonFE::doWork
MoFEMErrorCode doWork(int side, EntityType type, EntitiesFieldData::EntData &data)
Operator for linear form, usually to calculate values on right hand side.
Definition: continuity_check_on_skeleton_with_simple_2d_for_hdiv.cpp:93
MoFEM::Simple::addSkeletonField
MoFEMErrorCode addSkeletonField(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 skeleton.
Definition: Simple.cpp:372
MoFEM::Interface
DeprecatedCoreInterface Interface
Definition: Interface.hpp:2010
MoFEM::Simple::getOptions
MoFEMErrorCode getOptions()
get options
Definition: Simple.cpp:180
MoFEM::Simple::getDM
MoFEMErrorCode getDM(DM *dm)
Get DM.
Definition: Simple.cpp:747
CHKERR
#define CHKERR
Inline error check.
Definition: definitions.h:548
MoFEM::FaceElementForcesAndSourcesCore::UserDataOperator
friend class UserDataOperator
Definition: FaceElementForcesAndSourcesCore.hpp:86
MoFEM
implementation of Data Operators for Forces and Sources
Definition: Common.hpp:10
MoFEM::ForcesAndSourcesCore::UserDataOperator
Definition: ForcesAndSourcesCore.hpp:549
convert.type
type
Definition: convert.py:64
CommonData::dotEleRight
MatrixDouble dotEleRight
Definition: continuity_check_on_skeleton_with_simple_2d_for_h1.cpp:25
MoFEM::OpSetContravariantPiolaTransformOnEdge2D
Definition: UserDataOperators.hpp:3086
main
int main(int argc, char *argv[])
Definition: continuity_check_on_skeleton_with_simple_2d_for_hdiv.cpp:152
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:43
SkeletonFE::OpFaceSide::OpFaceSide
OpFaceSide(CommonData &elem_data)
Definition: continuity_check_on_skeleton_with_simple_2d_for_hdiv.cpp:33
MoFEM::ForcesAndSourcesCore::UserDataOperator
friend class UserDataOperator
Definition: ForcesAndSourcesCore.hpp:482
i
FTensor::Index< 'i', SPACE_DIM > i
Definition: hcurl_divergence_operator_2d.cpp:27
FTensor::Index< 'i', 2 >
MoFEM::Simple::setFieldOrder
MoFEMErrorCode setFieldOrder(const std::string field_name, const int order, const Range *ents=NULL)
Set field order.
Definition: Simple.cpp:545
MoFEM::EdgeElementForcesAndSourcesCore::UserDataOperator
default operator for EDGE element
Definition: EdgeElementForcesAndSourcesCore.hpp:68
SkeletonFE::SkeletonFE
SkeletonFE(MoFEM::Interface &m_field, CommonData &elem_data)
Definition: continuity_check_on_skeleton_with_simple_2d_for_hdiv.cpp:78
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
CATCH_ERRORS
#define CATCH_ERRORS
Catch errors.
Definition: definitions.h:385
DEMKOWICZ_JACOBI_BASE
@ DEMKOWICZ_JACOBI_BASE
Definition: definitions.h:66
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
OpFaceSide
Definition: hello_world.cpp:94
eps
static const double eps
Definition: check_base_functions_derivatives_on_tet.cpp:11
MoFEM::EntitiesFieldData::EntData::getFTensor1N
FTensor::Tensor1< FTensor::PackPtr< double *, Tensor_Dim >, Tensor_Dim > getFTensor1N(FieldApproximationBase base)
Get base functions for Hdiv/Hcurl spaces.
Definition: EntitiesFieldData.cpp:640
CommonData
Definition: continuity_check_on_skeleton_with_simple_2d_for_h1.cpp:22
AINSWORTH_LEGENDRE_BASE
@ AINSWORTH_LEGENDRE_BASE
Ainsworth Cole (Legendre) approx. base .
Definition: definitions.h:60
MoFEM::ForcesAndSourcesCore::getOpPtrVector
boost::ptr_deque< UserDataOperator > & getOpPtrVector()
Use to push back operator for row operator.
Definition: ForcesAndSourcesCore.hpp:83
HCURL
@ HCURL
field with continuous tangents
Definition: definitions.h:86
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::OpCalculateHOJacForFace
OpCalculateHOJacForFaceImpl< 2 > OpCalculateHOJacForFace
Definition: HODataOperators.hpp:264
MoFEM::FaceElementForcesAndSourcesCoreOnSide::UserDataOperator
default operator for Face element
Definition: FaceElementForcesAndSourcesCoreOnSide.hpp:92
FieldApproximationBase
FieldApproximationBase
approximation base
Definition: definitions.h:58
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:453
MoFEM::OpMakeHdivFromHcurl
Make Hdiv space from Hcurl space in 2d.
Definition: UserDataOperators.hpp:2985
MoFEM::Simple::setUp
MoFEMErrorCode setUp(const PetscBool is_partitioned=PETSC_TRUE)
Setup problem.
Definition: Simple.cpp:683
MoFEM::DMoFEMLoopFiniteElements
PetscErrorCode DMoFEMLoopFiniteElements(DM dm, const char fe_name[], MoFEM::FEMethod *method, CacheTupleWeakPtr cache_ptr=CacheTupleSharedPtr())
Executes FEMethod for finite elements in DM.
Definition: DMMoFEM.cpp:586
MoFEMFunctionReturn
#define MoFEMFunctionReturn(a)
Last executable line of each PETSc function used for error handling. Replaces return()
Definition: definitions.h:429
MoFEM::FaceElementForcesAndSourcesCoreOnSide
Base face element used to integrate on skeleton.
Definition: FaceElementForcesAndSourcesCoreOnSide.hpp:19
MoFEMFunctionBegin
#define MoFEMFunctionBegin
First executable line of each MoFEM function, used for error handling. Final line of MoFEM functions ...
Definition: definitions.h:359