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

Go to the source code of this file.

Classes

struct  ApproxFunctions
 
struct  OpAssembleMat
 
struct  OpAssembleVec
 
struct  OpValsDiffVals
 
struct  OpCheckValsDiffVals
 

Typedefs

using FaceEle = MoFEM::FaceElementForcesAndSourcesCoreSwitch< FaceElementForcesAndSourcesCore::NO_HO_GEOMETRY|FaceElementForcesAndSourcesCore::NO_CONTRAVARIANT_TRANSFORM_HDIV|FaceElementForcesAndSourcesCore::NO_COVARIANT_TRANSFORM_HCURL >
 
using FaceEleOp = FaceEle::UserDataOperator
 
using EntData = DataForcesAndSourcesCore::EntData
 

Functions

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

Variables

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

Typedef Documentation

◆ EntData

◆ FaceEle

using FaceEle = MoFEM::FaceElementForcesAndSourcesCoreSwitch< FaceElementForcesAndSourcesCore::NO_HO_GEOMETRY | FaceElementForcesAndSourcesCore::NO_CONTRAVARIANT_TRANSFORM_HDIV | FaceElementForcesAndSourcesCore::NO_COVARIANT_TRANSFORM_HCURL>

Definition at line 32 of file h1_check_approximation_2d.cpp.

◆ FaceEleOp

using FaceEleOp = FaceEle::UserDataOperator

Definition at line 34 of file h1_check_approximation_2d.cpp.

Function Documentation

◆ main()

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

Definition at line 228 of file h1_check_approximation_2d.cpp.

228  {
229 
230  MoFEM::Core::Initialize(&argc, &argv, (char *)0, help);
231 
232  try {
233 
234  DMType dm_name = "DMMOFEM";
235  CHKERR DMRegister_MoFEM(dm_name);
236 
237  moab::Core mb_instance;
238  moab::Interface &moab = mb_instance;
239 
240  // Create MoFEM instance
241  MoFEM::Core core(moab);
242  MoFEM::Interface &m_field = core;
243 
244  Simple *simple_interface = m_field.getInterface<Simple>();
245  Basic *basic_interface = m_field.getInterface<Basic>();
246  CHKERR simple_interface->getOptions();
247  CHKERR simple_interface->loadFile("", "rectangle.h5m");
248 
249  // Declare elements
250  enum bases { AINSWORTH, DEMKOWICZ, BERNSTEIN, LASBASETOP };
251  const char *list_bases[] = {"ainsworth", "demkowicz", "bernstein"};
252  PetscBool flg;
253  PetscInt choice_base_value = AINSWORTH;
254  CHKERR PetscOptionsGetEList(PETSC_NULL, NULL, "-base", list_bases,
255  LASBASETOP, &choice_base_value, &flg);
256 
257  if (flg != PETSC_TRUE)
258  SETERRQ(PETSC_COMM_SELF, MOFEM_IMPOSIBLE_CASE, "base not set");
260  if (choice_base_value == AINSWORTH)
262  else if (choice_base_value == DEMKOWICZ)
263  base = DEMKOWICZ_JACOBI_BASE;
264  else if (choice_base_value == BERNSTEIN)
266 
267  CHKERR simple_interface->addDomainField("FIELD1", H1, base, 1);
268  constexpr int order = 5;
269  CHKERR simple_interface->setFieldOrder("FIELD1", order);
270  CHKERR simple_interface->setUp();
271  auto dm = simple_interface->getDM();
272 
273  VectorDouble vals;
274  MatrixDouble jac(2, 2), inv_jac(2, 2), diff_vals;
275 
276  auto assemble_matrices_and_vectors = [&]() {
278  basic_interface->getOpDomainRhsPipeline().push_back(new OpAssembleVec());
279 
280  basic_interface->getOpDomainLhsPipeline().push_back(
281  new OpCalculateInvJacForFace(inv_jac));
282  basic_interface->getOpDomainLhsPipeline().push_back(new OpAssembleMat());
283 
284  auto integration_rule = [](int, int, int p_data) { return 2 * p_data; };
285  CHKERR basic_interface->setDomainRhsIntegrationRule(integration_rule);
286  CHKERR basic_interface->setDomainLhsIntegrationRule(integration_rule);
287 
289  };
290 
291  auto solve_problem = [&] {
293  auto solver = basic_interface->createKSP();
294  CHKERR KSPSetFromOptions(solver);
295  CHKERR KSPSetUp(solver);
296 
297  auto D = smartCreateDMDVector(dm);
298  auto F = smartVectorDuplicate(D);
299 
300  CHKERR KSPSolve(solver, F, D);
301  CHKERR VecGhostUpdateBegin(D, INSERT_VALUES, SCATTER_FORWARD);
302  CHKERR VecGhostUpdateEnd(D, INSERT_VALUES, SCATTER_FORWARD);
303  CHKERR DMoFEMMeshToLocalVector(dm, D, INSERT_VALUES, SCATTER_REVERSE);
305  };
306 
307  auto check_solution = [&] {
309 
310  boost::shared_ptr<VectorDouble> ptr_values(new VectorDouble());
311  boost::shared_ptr<MatrixDouble> ptr_diff_vals(new MatrixDouble());
312 
313  basic_interface->getDomainLhsFE().reset();
314  basic_interface->getOpDomainRhsPipeline().clear();
315 
316  basic_interface->getOpDomainRhsPipeline().push_back(
317  new OpCalculateInvJacForFace(inv_jac));
318  basic_interface->getOpDomainRhsPipeline().push_back(
319  new OpSetInvJacH1ForFace(inv_jac));
320  basic_interface->getOpDomainRhsPipeline().push_back(
321  new OpValsDiffVals(vals, diff_vals));
322  basic_interface->getOpDomainRhsPipeline().push_back(
323  new OpCalculateScalarFieldValues("FIELD1", ptr_values));
324  basic_interface->getOpDomainRhsPipeline().push_back(
325  new OpCalculateScalarFieldGradient<2>("FIELD1", ptr_diff_vals));
326  basic_interface->getOpDomainRhsPipeline().push_back(
327  new OpCheckValsDiffVals(vals, diff_vals, ptr_values, ptr_diff_vals));
328 
329  CHKERR basic_interface->loopFiniteElements();
330 
332  };
333 
334  CHKERR assemble_matrices_and_vectors();
336  CHKERR check_solution();
337  }
338  CATCH_ERRORS;
339 
341 }
MoFEMErrorCode setUp(const PetscBool is_partitioned=PETSC_TRUE)
Setup problem.
Definition: Simple.cpp:433
MoFEMErrorCode getDM(DM *dm)
Get DM.
Definition: Simple.cpp:443
PetscErrorCode DMoFEMMeshToLocalVector(DM dm, Vec l, InsertMode mode, ScatterMode scatter_mode)
set local (or ghosted) vector values on mesh for partition only
Definition: DMMMoFEM.cpp:434
ublas::matrix< double, ublas::row_major, DoubleAllocator > MatrixDouble
Definition: Types.hpp:74
#define MoFEMFunctionReturn(a)
Last executable line of each PETSc function used for error handling. Replaces return()
Definition: definitions.h:481
static char help[]
Core (interface) class.
Definition: Core.hpp:50
SmartPetscObj< Vec > smartVectorDuplicate(SmartPetscObj< Vec > &vec)
Create duplicate vector of smart vector.
Definition: AuxPETSc.hpp:238
Simple interface for fast problem set-up.
Definition: Simple.hpp:36
static MoFEMErrorCode Initialize(int *argc, char ***args, const char file[], const char help[])
Initializes the MoFEM database PETSc, MOAB and MPI.
Definition: Core.cpp:51
PetscErrorCode solve_problem(MoFEM::Interface &m_field, const string &problem_name, const string &fe_name, const string &re_field, const string &im_field, InsertMode mode, FUNEVAL &fun_evaluator, PetscBool is_partitioned)
MoFEMErrorCode getInterface(const MOFEMuuid &uuid, IFACE *&iface) const
Get interface by uuid and return reference to pointer of interface.
Basic interface.
Definition: Basic.hpp:36
Calculate inverse of jacobian for face element.
FieldApproximationBase
approximation base
Definition: definitions.h:148
MoFEMErrorCode loadFile(const std::string options="PARALLEL=READ_PART;" "PARALLEL_RESOLVE_SHARED_ENTS;" "PARTITION=PARALLEL_PARTITION;", const std::string mesh_file_name="")
Load mesh file.
Definition: Simple.cpp:61
PetscErrorCode PetscOptionsGetEList(PetscOptions *, const char pre[], const char name[], const char *const *list, PetscInt next, PetscInt *value, PetscBool *set)
PetscErrorCode DMRegister_MoFEM(const char sname[])
Register MoFEM problem.
Definition: DMMMoFEM.cpp:53
Ainsworth Cole (Legendre) approx. base .
Definition: definitions.h:150
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:105
#define CHKERR
Inline error check.
Definition: definitions.h:600
Transform local reference derivatives of shape functions to global derivatives.
Get field gradients at integration pts for scalar filed rank 0, i.e. vector field.
MoFEMErrorCode getOptions()
get options
Definition: Simple.cpp:47
#define MoFEMFunctionBegin
First executable line of each MoFEM function, used for error handling. Final line of MoFEM functions ...
Definition: definitions.h:411
#define CATCH_ERRORS
Catch errors.
Definition: definitions.h:437
continuous field
Definition: definitions.h:175
ublas::vector< double, DoubleAllocator > VectorDouble
Definition: Types.hpp:72
auto smartCreateDMDVector
Get smart vector from DM.
Definition: DMMoFEM.hpp:930
MoFEMErrorCode setFieldOrder(const std::string field_name, const int order, const Range *ents=NULL)
Set field order.
Definition: Simple.cpp:249
Get value at integration points for scalar field.
static MoFEMErrorCode Finalize()
Checks for options to be called at the conclusion of the program.
Definition: Core.cpp:61

Variable Documentation

◆ help

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

Definition at line 27 of file h1_check_approximation_2d.cpp.