v0.14.0
Classes | Typedefs | Functions | Variables
hdiv_check_approx_in_3d.cpp File Reference
#include <MoFEM.hpp>

Go to the source code of this file.

Classes

struct  ApproxFunctions
 
struct  OpCheckValsDiffVals
 

Typedefs

using Ele = MoFEM::PipelineManager::ElementsAndOpsByDim< SPACE_DIM >::DomainEle
 
using EleOp = Ele::UserDataOperator
 
using OpDomainMass = FormsIntegrators< EleOp >::Assembly< PETSC >::BiLinearForm< GAUSS >::OpMass< BASE_DIM, SPACE_DIM >
 OPerator to integrate mass matrix for least square approximation. More...
 
using OpDomainSource = FormsIntegrators< EleOp >::Assembly< PETSC >::LinearForm< GAUSS >::OpSource< BASE_DIM, SPACE_DIM >
 Operator to integrate the right hand side matrix for the problem. More...
 

Functions

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

Variables

static char help [] = "...\n\n"
 
constexpr int BASE_DIM = 3
 
constexpr int SPACE_DIM = 3
 
constexpr double a0 = 0.0
 
constexpr double a1 = 2.0
 
constexpr double a2 = -15.0 * a0
 
constexpr double a3 = -20.0 / 6 * a1
 
constexpr double a4 = 15.0 * a0
 
constexpr double a5 = a1
 
constexpr double a6 = -a0
 

Typedef Documentation

◆ Ele

Definition at line 18 of file hdiv_check_approx_in_3d.cpp.

◆ EleOp

Definition at line 19 of file hdiv_check_approx_in_3d.cpp.

◆ OpDomainMass

using OpDomainMass = FormsIntegrators<EleOp>::Assembly<PETSC>::BiLinearForm< GAUSS>::OpMass<BASE_DIM, SPACE_DIM>

OPerator to integrate mass matrix for least square approximation.

Examples
hdiv_check_approx_in_3d.cpp.

Definition at line 26 of file hdiv_check_approx_in_3d.cpp.

◆ OpDomainSource

using OpDomainSource = FormsIntegrators<EleOp>::Assembly<PETSC>::LinearForm< GAUSS>::OpSource<BASE_DIM, SPACE_DIM>

Operator to integrate the right hand side matrix for the problem.

Examples
hdiv_check_approx_in_3d.cpp.

Definition at line 33 of file hdiv_check_approx_in_3d.cpp.

Function Documentation

◆ main()

int main ( int  argc,
char *  argv[] 
)
Examples
hdiv_check_approx_in_3d.cpp.

Definition at line 129 of file hdiv_check_approx_in_3d.cpp.

129  {
130 
131  MoFEM::Core::Initialize(&argc, &argv, (char *)0, help);
132 
133  try {
134 
135  DMType dm_name = "DMMOFEM";
136  CHKERR DMRegister_MoFEM(dm_name);
137 
138  moab::Core mb_instance;
139  moab::Interface &moab = mb_instance;
140 
141  // Create MoFEM instance
142  MoFEM::Core core(moab);
143  MoFEM::Interface &m_field = core;
144 
145  Simple *simple = m_field.getInterface<Simple>();
146  PipelineManager *pipeline_mng = m_field.getInterface<PipelineManager>();
147  CHKERR simple->getOptions();
148  CHKERR simple->loadFile();
149 
150  // Declare elements
151  enum bases { AINSWORTH, DEMKOWICZ, LASBASETOP };
152  const char *list_bases[] = {"ainsworth", "demkowicz"};
153  PetscBool flg;
154  PetscInt choice_base_value = AINSWORTH;
155  CHKERR PetscOptionsGetEList(PETSC_NULL, NULL, "-base", list_bases,
156  LASBASETOP, &choice_base_value, &flg);
157 
158  if (flg != PETSC_TRUE)
159  SETERRQ(PETSC_COMM_SELF, MOFEM_IMPOSSIBLE_CASE, "base not set");
161  if (choice_base_value == AINSWORTH)
163  else if (choice_base_value == DEMKOWICZ)
164  base = DEMKOWICZ_JACOBI_BASE;
165 
166  AinsworthOrderHooks::broken_nbfacetri_edge_hdiv = [](int p) { return p; };
167  AinsworthOrderHooks::broken_nbfacetri_face_hdiv = [](int p) { return p; };
168  AinsworthOrderHooks::broken_nbvolumetet_edge_hdiv = [](int p) { return p; };
169  AinsworthOrderHooks::broken_nbvolumetet_face_hdiv = [](int p) { return p; };
170  AinsworthOrderHooks::broken_nbvolumetet_volume_hdiv = [](int p) {
171  return p;
172  };
173 
174  CHKERR simple->addDomainField("FIELD1", HDIV, base, 1);
175  constexpr int order = 4;
176  CHKERR simple->setFieldOrder("FIELD1", order);
177  CHKERR simple->setUp();
178  auto dm = simple->getDM();
179 
180  MatrixDouble vals, diff_vals;
181 
182  auto assemble_matrices_and_vectors = [&]() {
184 
186  pipeline_mng->getOpDomainRhsPipeline(), {HDIV});
187  pipeline_mng->getOpDomainRhsPipeline().push_back(
188  new OpDomainSource("FIELD1", ApproxFunctions::fUn));
189 
191  pipeline_mng->getOpDomainLhsPipeline(), {HDIV});
192  pipeline_mng->getOpDomainLhsPipeline().push_back(
193 
194  new OpDomainMass("FIELD1", "FIELD1",
195  [](double x, double, double) { return 1; })
196 
197  );
198 
199  auto integration_rule = [](int, int, int p_data) {
200  return 2 * p_data + 1;
201  };
202  CHKERR pipeline_mng->setDomainRhsIntegrationRule(integration_rule);
203  CHKERR pipeline_mng->setDomainLhsIntegrationRule(integration_rule);
204 
206  };
207 
208  auto solve_problem = [&] {
210  auto solver = pipeline_mng->createKSP();
211  CHKERR KSPSetFromOptions(solver);
212  CHKERR KSPSetUp(solver);
213 
214  auto D = createDMVector(dm);
215  auto F = vectorDuplicate(D);
216 
217  CHKERR KSPSolve(solver, F, D);
218  CHKERR VecGhostUpdateBegin(D, INSERT_VALUES, SCATTER_FORWARD);
219  CHKERR VecGhostUpdateEnd(D, INSERT_VALUES, SCATTER_FORWARD);
220  CHKERR DMoFEMMeshToLocalVector(dm, D, INSERT_VALUES, SCATTER_REVERSE);
222  };
223 
224  auto check_solution = [&] {
226 
227  pipeline_mng->getOpDomainLhsPipeline().clear();
228  pipeline_mng->getOpDomainRhsPipeline().clear();
229 
230  auto ptr_values = boost::make_shared<MatrixDouble>();
231  auto ptr_grad = boost::make_shared<MatrixDouble>();
232 
233  // Change H-curl to H-div in 2D, and apply Piola transform
235  pipeline_mng->getOpDomainRhsPipeline(), {HDIV});
236 
237  // Calculate field values at integration points
238  pipeline_mng->getOpDomainRhsPipeline().push_back(
239  new OpCalculateHVecVectorField<BASE_DIM>("FIELD1", ptr_values));
240  // Gradient
241  pipeline_mng->getOpDomainRhsPipeline().push_back(
243  ptr_grad));
244  pipeline_mng->getOpDomainRhsPipeline().push_back(
245  new OpCheckValsDiffVals(ptr_values, ptr_grad));
246 
247  CHKERR pipeline_mng->loopFiniteElements();
248 
250  };
251 
252  CHKERR assemble_matrices_and_vectors();
253  CHKERR solve_problem();
254  CHKERR check_solution();
255  }
256  CATCH_ERRORS;
257 
259 }

Variable Documentation

◆ a0

constexpr double a0 = 0.0
constexpr
Examples
hdiv_check_approx_in_3d.cpp.

Definition at line 35 of file hdiv_check_approx_in_3d.cpp.

◆ a1

constexpr double a1 = 2.0
constexpr
Examples
hdiv_check_approx_in_3d.cpp.

Definition at line 36 of file hdiv_check_approx_in_3d.cpp.

◆ a2

constexpr double a2 = -15.0 * a0
constexpr
Examples
hdiv_check_approx_in_3d.cpp.

Definition at line 37 of file hdiv_check_approx_in_3d.cpp.

◆ a3

constexpr double a3 = -20.0 / 6 * a1
constexpr
Examples
hdiv_check_approx_in_3d.cpp.

Definition at line 38 of file hdiv_check_approx_in_3d.cpp.

◆ a4

constexpr double a4 = 15.0 * a0
constexpr
Examples
hdiv_check_approx_in_3d.cpp.

Definition at line 39 of file hdiv_check_approx_in_3d.cpp.

◆ a5

constexpr double a5 = a1
constexpr
Examples
hdiv_check_approx_in_3d.cpp.

Definition at line 40 of file hdiv_check_approx_in_3d.cpp.

◆ a6

constexpr double a6 = -a0
constexpr
Examples
hdiv_check_approx_in_3d.cpp.

Definition at line 41 of file hdiv_check_approx_in_3d.cpp.

◆ BASE_DIM

constexpr int BASE_DIM = 3
constexpr
Examples
hdiv_check_approx_in_3d.cpp.

Definition at line 15 of file hdiv_check_approx_in_3d.cpp.

◆ help

char help[] = "...\n\n"
static
Examples
hdiv_check_approx_in_3d.cpp.

Definition at line 13 of file hdiv_check_approx_in_3d.cpp.

◆ SPACE_DIM

constexpr int SPACE_DIM = 3
constexpr
Examples
hdiv_check_approx_in_3d.cpp.

Definition at line 16 of file hdiv_check_approx_in_3d.cpp.

MoFEM::UnknownInterface::getInterface
MoFEMErrorCode getInterface(IFACE *&iface) const
Get interface reference to pointer of interface.
Definition: UnknownInterface.hpp:93
MoFEM::CoreTmp< 0 >
Core (interface) class.
Definition: Core.hpp:82
OpDomainMass
FormsIntegrators< EleOp >::Assembly< PETSC >::BiLinearForm< GAUSS >::OpMass< BASE_DIM, SPACE_DIM > OpDomainMass
OPerator to integrate mass matrix for least square approximation.
Definition: hdiv_check_approx_in_3d.cpp:26
MoFEM::Types::MatrixDouble
UBlasMatrix< double > MatrixDouble
Definition: Types.hpp:77
help
static char help[]
Definition: hdiv_check_approx_in_3d.cpp:13
MoFEM::PipelineManager
PipelineManager interface.
Definition: PipelineManager.hpp:24
MoFEM::DMoFEMMeshToLocalVector
PetscErrorCode DMoFEMMeshToLocalVector(DM dm, Vec l, InsertMode mode, ScatterMode scatter_mode)
set local (or ghosted) vector values on mesh for partition only
Definition: DMMoFEM.cpp:523
MoFEM::CoreTmp< 0 >::Finalize
static MoFEMErrorCode Finalize()
Checks for options to be called at the conclusion of the program.
Definition: Core.cpp:112
ApproxFunctions::fUn
static FTensor::Tensor1< double, BASE_DIM > fUn(const double x, const double y, double z)
Definition: hcurl_check_approx_in_2d.cpp:46
MoFEM::Simple
Simple interface for fast problem set-up.
Definition: Simple.hpp:27
MOFEM_IMPOSSIBLE_CASE
@ MOFEM_IMPOSSIBLE_CASE
Definition: definitions.h:35
MoFEM::OpCalculateHVecVectorGradient
Calculate gradient of vector field.
Definition: UserDataOperators.hpp:2271
order
constexpr int order
Definition: dg_projection.cpp:18
MoFEM::DeprecatedCoreInterface
Deprecated interface functions.
Definition: DeprecatedCoreInterface.hpp:16
MoFEM::Interface
DeprecatedCoreInterface Interface
Definition: Interface.hpp:2010
CHKERR
#define CHKERR
Inline error check.
Definition: definitions.h:548
OpDomainSource
FormsIntegrators< EleOp >::Assembly< PETSC >::LinearForm< GAUSS >::OpSource< BASE_DIM, SPACE_DIM > OpDomainSource
Operator to integrate the right hand side matrix for the problem.
Definition: hdiv_check_approx_in_3d.cpp:33
MoFEM::createDMVector
auto createDMVector(DM dm)
Get smart vector from DM.
Definition: DMMoFEM.hpp:1099
MoFEM::OpCalculateHVecVectorField
Get vector field for H-div approximation.
Definition: UserDataOperators.hpp:2115
simple
void simple(double P1[], double P2[], double P3[], double c[], const int N)
Definition: acoustic.cpp:69
MoFEM::DMRegister_MoFEM
PetscErrorCode DMRegister_MoFEM(const char sname[])
Register MoFEM problem.
Definition: DMMoFEM.cpp:43
MoFEM::AddHOOps
Add operators pushing bases from local to physical configuration.
Definition: HODataOperators.hpp:413
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
MoFEM::vectorDuplicate
SmartPetscObj< Vec > vectorDuplicate(Vec vec)
Create duplicate vector of smart vector.
Definition: PetscSmartObj.hpp:221
CATCH_ERRORS
#define CATCH_ERRORS
Catch errors.
Definition: definitions.h:385
DEMKOWICZ_JACOBI_BASE
@ DEMKOWICZ_JACOBI_BASE
Definition: definitions.h:66
MoFEM::Core
CoreTmp< 0 > Core
Definition: Core.hpp:1148
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
FieldApproximationBase
FieldApproximationBase
approximation base
Definition: definitions.h:58
ReactionDiffusionEquation::D
const double D
diffusivity
Definition: reaction_diffusion.cpp:20
OpCheckValsDiffVals
Definition: hcurl_check_approx_in_2d.cpp:161
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:429
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:359
F
@ F
Definition: free_surface.cpp:394