v0.10.0
Classes | Functions | Variables
prism_polynomial_approximation.cpp File Reference
#include <MoFEM.hpp>

Go to the source code of this file.

Classes

struct  ApproxFunction
 
struct  PrismOpCheck
 
struct  PrismOpRhs
 
struct  PrismOpLhs
 
struct  PrismFE
 

Functions

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

Variables

static char help [] = "...\n\n"
 
static constexpr int approx_order = 6
 

Function Documentation

◆ main()

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

Definition at line 108 of file prism_polynomial_approximation.cpp.

108  {
109 
110  MoFEM::Core::Initialize(&argc, &argv, (char *)0, help);
111 
112  try {
113 
114  moab::Core mb_instance;
115  moab::Interface &moab = mb_instance;
116 
117  ParallelComm *pcomm = ParallelComm::get_pcomm(&moab, MYPCOMM_INDEX);
118  if (pcomm == NULL)
119  pcomm = new ParallelComm(&moab, PETSC_COMM_WORLD);
120 
121  std::array<double, 18> one_prism_coords = {0, 0, 0, 1, 0, 0, 0, 1, 0,
122  0, 0, 1, 1, 0, 1, 0, 1, 1};
123  std::array<EntityHandle, 6> one_prism_nodes;
124  for (int n = 0; n != 6; ++n)
125  CHKERR moab.create_vertex(&one_prism_coords[3 * n], one_prism_nodes[n]);
126  EntityHandle one_prism;
127  CHKERR moab.create_element(MBPRISM, one_prism_nodes.data(), 6, one_prism);
128  Range one_prism_range;
129  one_prism_range.insert(one_prism);
130  Range one_prism_adj_ents;
131  for (int d = 1; d != 3; ++d)
132  CHKERR moab.get_adjacencies(one_prism_range, d, true, one_prism_adj_ents,
133  moab::Interface::UNION);
134 
135  MoFEM::Core core(moab);
136  MoFEM::Interface &m_field = core;
137 
138  PrismsFromSurfaceInterface *prisms_from_surface_interface;
139  CHKERR m_field.getInterface(prisms_from_surface_interface);
140  BitRefLevel bit_level0;
141  bit_level0.set(0);
142  CHKERR m_field.getInterface<BitRefManager>()->setEntitiesBitRefLevel(
143  one_prism_range, bit_level0);
144  CHKERR prisms_from_surface_interface->seedPrismsEntities(one_prism_range,
145  bit_level0);
146 
147  // Fields
148  CHKERR m_field.add_field("FIELD1", H1, AINSWORTH_LEGENDRE_BASE, 1);
149  CHKERR m_field.add_ents_to_field_by_type(0, MBPRISM, "FIELD1");
150 
151  CHKERR m_field.set_field_order(0, MBVERTEX, "FIELD1", 1);
152  CHKERR m_field.set_field_order(0, MBEDGE, "FIELD1", approx_order + 1);
153  CHKERR m_field.set_field_order(0, MBTRI, "FIELD1", approx_order + 1);
154  CHKERR m_field.set_field_order(0, MBQUAD, "FIELD1", approx_order + 1);
155  CHKERR m_field.set_field_order(0, MBPRISM, "FIELD1", approx_order + 1);
156  CHKERR m_field.build_fields();
157 
158  // FE
159  CHKERR m_field.add_finite_element("PRISM");
160 
161  // Define rows/cols and element data
162  CHKERR m_field.modify_finite_element_add_field_row("PRISM", "FIELD1");
163  CHKERR m_field.modify_finite_element_add_field_col("PRISM", "FIELD1");
164  CHKERR m_field.modify_finite_element_add_field_data("PRISM", "FIELD1");
165  CHKERR m_field.add_ents_to_finite_element_by_type(0, MBPRISM, "PRISM");
166 
167  // build finite elemnts
168  CHKERR m_field.build_finite_elements();
169  // //build adjacencies
170  CHKERR m_field.build_adjacencies(bit_level0);
171 
172  // Problem
173  CHKERR m_field.add_problem("TEST_PROBLEM");
174 
175  // set finite elements for problem
176  CHKERR m_field.modify_problem_add_finite_element("TEST_PROBLEM", "PRISM");
177  // set refinement level for problem
178  CHKERR m_field.modify_problem_ref_level_add_bit("TEST_PROBLEM", bit_level0);
179 
180  // build problem
181  ProblemsManager *prb_mng_ptr;
182  CHKERR m_field.getInterface(prb_mng_ptr);
183  CHKERR prb_mng_ptr->buildProblem("TEST_PROBLEM", true);
184  // partition
185  CHKERR prb_mng_ptr->partitionSimpleProblem("TEST_PROBLEM");
186  CHKERR prb_mng_ptr->partitionFiniteElements("TEST_PROBLEM");
187  // what are ghost nodes, see Petsc Manual
188  CHKERR prb_mng_ptr->partitionGhostDofs("TEST_PROBLEM");
189 
190  // Create matrices
193  ->createMPIAIJWithArrays<PetscGlobalIdx_mi_tag>("TEST_PROBLEM", A);
195  CHKERR m_field.getInterface<VecManager>()->vecCreateGhost("TEST_PROBLEM",
196  ROW, F);
198  CHKERR m_field.getInterface<VecManager>()->vecCreateGhost("TEST_PROBLEM",
199  COL, D);
200 
201  auto assemble_matrices_and_vectors = [&]() {
203  PrismFE fe(m_field);
204  MatrixDouble inv_jac;
205  fe.getOpPtrVector().push_back(
207  fe.getOpPtrVector().push_back(
209  fe.getOpPtrVector().push_back(
210  new MoFEM::OpSetInvJacH1ForFatPrism(inv_jac));
211  fe.getOpPtrVector().push_back(new PrismOpRhs(F));
212  fe.getOpPtrVector().push_back(new PrismOpLhs(A));
213  CHKERR VecZeroEntries(F);
214  CHKERR MatZeroEntries(A);
215  CHKERR m_field.loop_finite_elements("TEST_PROBLEM", "PRISM", fe);
216  CHKERR VecAssemblyBegin(F);
217  CHKERR VecAssemblyEnd(F);
218  CHKERR MatAssemblyBegin(A, MAT_FINAL_ASSEMBLY);
219  CHKERR MatAssemblyEnd(A, MAT_FINAL_ASSEMBLY);
221  };
222 
223  auto solve_problem = [&] {
225  auto solver = createKSP(PETSC_COMM_WORLD);
226  CHKERR KSPSetOperators(solver, A, A);
227  CHKERR KSPSetFromOptions(solver);
228  CHKERR KSPSetUp(solver);
229  CHKERR KSPSolve(solver, F, D);
230  CHKERR VecGhostUpdateBegin(D, INSERT_VALUES, SCATTER_FORWARD);
231  CHKERR VecGhostUpdateEnd(D, INSERT_VALUES, SCATTER_FORWARD);
232  CHKERR m_field.getInterface<VecManager>()->setLocalGhostVector(
233  "TEST_PROBLEM", COL, D, INSERT_VALUES, SCATTER_REVERSE);
235  };
236 
237  auto check_solution = [&] {
239  PrismFE fe(m_field);
240  boost::shared_ptr<VectorDouble> field_vals_ptr(new VectorDouble());
241  boost::shared_ptr<MatrixDouble> diff_field_vals_ptr(new MatrixDouble());
242  MatrixDouble inv_jac;
243  fe.getOpPtrVector().push_back(
244  new OpCalculateInvJacForFatPrism(inv_jac));
245  fe.getOpPtrVector().push_back(
246  new OpSetInvJacH1ForFatPrism(inv_jac));
247  fe.getOpPtrVector().push_back(
248  new OpCalculateScalarFieldValues("FIELD1", field_vals_ptr));
249  fe.getOpPtrVector().push_back(
250  new OpCalculateScalarFieldGradient<3>("FIELD1", diff_field_vals_ptr));
251  fe.getOpPtrVector().push_back(
252  new PrismOpCheck(field_vals_ptr, diff_field_vals_ptr));
253  CHKERR m_field.loop_finite_elements("TEST_PROBLEM", "PRISM", fe);
255  };
256 
257  CHKERR assemble_matrices_and_vectors();
259  CHKERR check_solution();
260  }
261  CATCH_ERRORS;
262 
264  return 0;
265 }
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
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
Deprecated interface functions.
Problem manager is used to build and partition problems.
virtual MoFEMErrorCode build_adjacencies(const Range &ents, int verb=DEFAULT_VERBOSITY)=0
build adjacencies
CoreTmp< 0 > Core
Definition: Core.hpp:1129
const double D
diffusivity
Operator for fat prism element updating integration weights in the volume.
static constexpr int approx_order
MoFEMErrorCode seedPrismsEntities(Range &prisms, const BitRefLevel &bit, int verb=-1)
Seed prism entities by bit level.
ublas::matrix< double, ublas::row_major, DoubleAllocator > MatrixDouble
Definition: Types.hpp:76
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
MoFEMErrorCode buildProblem(const std::string name, const bool square_matrix, int verb=VERBOSE)
build problem data structures
#define MoFEMFunctionReturn(a)
Last executable line of each PETSc function used for error handling. Replaces return()
Definition: definitions.h:485
static MoFEMErrorCode Initialize(int *argc, char ***args, const char file[], const char help[])
Initializes the MoFEM database PETSc, MOAB and MPI.
Definition: Core.cpp:60
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.
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.
static char help[]
static Index< 'n', 3 > n
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.
const Tensor1_Expr< const dTensor0< T, Dim, i >, typename promote< T, double >::V, Dim, i > d(const Tensor0< T * > &a, const Index< i, Dim > index, const Tensor1< int, Dim > &d_ijk, const Tensor1< double, Dim > &d_xyz)
Definition: dTensor0.hpp:27
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.
Managing BitRefLevels.
Ainsworth Cole (Legendre) approx. base .
Definition: definitions.h:152
Calculate inverse of jacobian for face element.
virtual MoFEMErrorCode modify_problem_ref_level_add_bit(const std::string &name_problem, const BitRefLevel &bit)=0
add ref level to problem
Vector manager is used to create vectors \mofem_vectors.
Definition: VecManager.hpp:36
virtual MoFEMErrorCode add_finite_element(const std::string &fe_name, enum MoFEMTypes bh=MF_EXCL, int verb=DEFAULT_VERBOSITY)=0
add finite element
#define CHKERR
Inline error check.
Definition: definitions.h:604
virtual MoFEMErrorCode modify_finite_element_add_field_data(const std::string &fe_name, const std::string &name_filed)=0
set finite element field data
Transform local reference derivatives of shape functions to global derivatives.
MoFEMErrorCode partitionGhostDofs(const std::string name, int verb=VERBOSE)
determine ghost nodes
#define MYPCOMM_INDEX
default communicator number PCOMM
Definition: definitions.h:292
std::bitset< BITREFLEVEL_SIZE > BitRefLevel
Bit structure attached to each entity identifying to what mesh entity is attached.
Definition: Types.hpp:51
virtual MoFEMErrorCode build_fields(int verb=DEFAULT_VERBOSITY)=0
auto createKSP
Definition: AuxPETSc.hpp:289
virtual MoFEMErrorCode add_problem(const std::string &name, enum MoFEMTypes bh=MF_EXCL, int verb=DEFAULT_VERBOSITY)=0
Add problem.
Get field gradients at integration pts for scalar filed rank 0, i.e. vector field.
DeprecatedCoreInterface Interface
Definition: Interface.hpp:1943
MoFEMErrorCode partitionFiniteElements(const std::string name, bool part_from_moab=false, int low_proc=-1, int hi_proc=-1, int verb=VERBOSE)
partition finite elementsFunction which partition finite elements based on dofs partitioning....
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
Core (interface) class.
Definition: Core.hpp:77
#define MoFEMFunctionBegin
First executable line of each MoFEM function, used for error handling. Final line of MoFEM functions ...
Definition: definitions.h:415
#define CATCH_ERRORS
Catch errors.
Definition: definitions.h:441
continuous field
Definition: definitions.h:177
ublas::vector< double, DoubleAllocator > VectorDouble
Definition: Types.hpp:74
Get value at integration points for scalar field.
MoFEMErrorCode partitionSimpleProblem(const std::string name, int verb=VERBOSE)
partition problem dofs
static MoFEMErrorCode Finalize()
Checks for options to be called at the conclusion of the program.
Definition: Core.cpp:100
virtual MoFEMErrorCode build_finite_elements(int verb=DEFAULT_VERBOSITY)=0
Build finite elementsBuild finite element data structures. Have to be run before problem and adjacenc...
Matrix manager is used to build and partition problems.
DEPRECATED MoFEMErrorCode loop_finite_elements(const Problem *problem_ptr, const std::string &fe_name, FEMethod &method, int lower_rank, int upper_rank, MoFEMTypes bh, int verb=DEFAULT_VERBOSITY)

Variable Documentation

◆ approx_order

constexpr int approx_order = 6
static

◆ help

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