v0.14.0
build_problems.cpp
Go to the documentation of this file.
1 /** \file build_large_problem.cpp
2  \example build_large_problem.cpp
3  \brief Atom test for building problems
4 
5  \bug Not verifying what if partitioned mesh is loaded.
6 
7 */
8 
9 #include <MoFEM.hpp>
10 using namespace MoFEM;
11 
12 static char help[] = "...\n\n";
13 
14 int main(int argc, char *argv[]) {
15 
16  MoFEM::Core::Initialize(&argc, &argv, (char *)0, help);
17 
18  try {
19 
20  moab::Core mb_instance;
21  moab::Interface &moab = mb_instance;
22  int rank;
23  MPI_Comm_rank(PETSC_COMM_WORLD, &rank);
24 
25  PetscBool flg = PETSC_TRUE;
26  char mesh_file_name[255];
27 #if PETSC_VERSION_GE(3, 6, 4)
28  CHKERR PetscOptionsGetString(PETSC_NULL, "", "-my_file", mesh_file_name,
29  255, &flg);
30 #else
31  CHKERR PetscOptionsGetString(PETSC_NULL, PETSC_NULL, "-my_file",
32  mesh_file_name, 255, &flg);
33 #endif
34  if (flg != PETSC_TRUE) {
35  SETERRQ(PETSC_COMM_SELF, 1, "*** ERROR -my_file (MESH FILE NEEDED)");
36  }
37 
38  CHKERR moab.load_file(mesh_file_name, 0, "");
39 
40  // Create MoFEM database
41  MoFEM::Core core(moab);
42  MoFEM::Interface &m_field = core;
43 
44  // set entities bit level
45  BitRefLevel bit_level0;
46  bit_level0.set(0);
47  CHKERR m_field.getInterface<BitRefManager>()->setBitRefLevelByDim(
48  0, 3, bit_level0);
49 
50  // Fields
51  CHKERR m_field.add_field("F1", L2, AINSWORTH_LEGENDRE_BASE, 1);
52  CHKERR m_field.add_field("F2", HDIV, DEMKOWICZ_JACOBI_BASE, 1);
53 
54  // meshset consisting all entities in mesh
55  EntityHandle root_set = moab.get_root_set();
56  // add entities to field
57  CHKERR m_field.add_ents_to_field_by_dim(root_set, 3, "F1", VERBOSE);
58  CHKERR m_field.add_ents_to_field_by_dim(root_set, 3, "F2", VERBOSE);
59 
60  // set app. order
61  // see Hierarchic Finite Element Bases on Unstructured Tetrahedral Meshes
62  // (Mark Ainsworth & Joe Coyle)
63  int order = 2;
64  CHKERR m_field.set_field_order(root_set, MBTET, "F1", order - 1);
65  CHKERR m_field.set_field_order(root_set, MBHEX, "F1", order - 1);
66  CHKERR m_field.set_field_order(root_set, MBTET, "F2", order);
67  CHKERR m_field.set_field_order(root_set, MBTRI, "F2", order);
68  CHKERR m_field.set_field_order(root_set, MBHEX, "F2", order);
69  CHKERR m_field.set_field_order(root_set, MBQUAD, "F2", order);
70 
71  CHKERR m_field.build_fields();
72 
73  // add elements
74  CHKERR m_field.add_finite_element("E1");
75  CHKERR m_field.add_finite_element("E2");
76  CHKERR m_field.add_finite_element("E3");
77 
78  CHKERR m_field.modify_finite_element_add_field_row("E1", "F1");
79  CHKERR m_field.modify_finite_element_add_field_col("E1", "F1");
80  CHKERR m_field.modify_finite_element_add_field_row("E2", "F2");
81  CHKERR m_field.modify_finite_element_add_field_col("E2", "F2");
82  // To build composite problem
83  CHKERR m_field.modify_finite_element_add_field_row("E3", "F1");
84  CHKERR m_field.modify_finite_element_add_field_col("E3", "F2");
85 
86  CHKERR m_field.add_ents_to_finite_element_by_type(root_set, MBTET, "E1");
87  CHKERR m_field.add_ents_to_finite_element_by_type(root_set, MBTET, "E2");
88  CHKERR m_field.add_ents_to_finite_element_by_type(root_set, MBTET, "E3");
89  CHKERR m_field.add_ents_to_finite_element_by_type(root_set, MBHEX, "E1");
90  CHKERR m_field.add_ents_to_finite_element_by_type(root_set, MBHEX, "E2");
91  CHKERR m_field.add_ents_to_finite_element_by_type(root_set, MBHEX, "E3");
92 
93  CHKERR m_field.build_finite_elements();
94  CHKERR m_field.build_adjacencies(bit_level0);
95 
96  // Problems
97  CHKERR m_field.add_problem("P1");
98  CHKERR m_field.add_problem("P2");
99 
100  // set refinement level for problem
101  CHKERR m_field.modify_problem_ref_level_add_bit("P1", bit_level0);
102  CHKERR m_field.modify_problem_ref_level_add_bit("P2", bit_level0);
103 
104  CHKERR m_field.modify_problem_add_finite_element("P1", "E1");
105  CHKERR m_field.modify_problem_add_finite_element("P2", "E2");
106 
107  // build problems
108  ProblemsManager *prb_mng_ptr;
109  CHKERR m_field.getInterface(prb_mng_ptr);
110  CHKERR prb_mng_ptr->buildProblem("P1", true);
111  CHKERR prb_mng_ptr->buildProblem("P2", true);
112  CHKERR prb_mng_ptr->partitionProblem("P1");
113  CHKERR prb_mng_ptr->partitionProblem("P2");
114 
115  CHKERR prb_mng_ptr->partitionFiniteElements("P1");
116  CHKERR prb_mng_ptr->partitionGhostDofs("P1");
118  ->checkMPIAIJWithArraysMatrixFillIn<PetscGlobalIdx_mi_tag>("P1", -1, -1,
119  0);
120  CHKERR prb_mng_ptr->partitionFiniteElements("P2");
121  CHKERR prb_mng_ptr->partitionGhostDofs("P2");
123  ->checkMPIAIJWithArraysMatrixFillIn<PetscGlobalIdx_mi_tag>("P2", -1, -1,
124  0);
125  // compose problem
126  CHKERR m_field.add_problem("P3");
127  CHKERR m_field.modify_problem_ref_level_add_bit("P3", bit_level0);
128  CHKERR m_field.modify_problem_add_finite_element("P3", "E3");
129 
130  CHKERR prb_mng_ptr->buildProblem("P3", false);
131  CHKERR prb_mng_ptr->inheritPartition("P3", "P1", false, "P2", true);
132  CHKERR prb_mng_ptr->partitionFiniteElements("P3");
133  CHKERR prb_mng_ptr->partitionGhostDofs("P3");
135  ->checkMPIAIJWithArraysMatrixFillIn<PetscGlobalIdx_mi_tag>("P3", -1, -1,
136  0);
137  }
138  CATCH_ERRORS;
139 
140  // finish work cleaning memory, getting statistics, etc.
142 
143  return 0;
144 }
MoFEM::UnknownInterface::getInterface
MoFEMErrorCode getInterface(IFACE *&iface) const
Get interface reference to pointer of interface.
Definition: UnknownInterface.hpp:93
MoFEM::ProblemsManager::buildProblem
MoFEMErrorCode buildProblem(const std::string name, const bool square_matrix, int verb=VERBOSE)
build problem data structures
Definition: ProblemsManager.cpp:87
MoFEM::CoreTmp< 0 >
Core (interface) class.
Definition: Core.hpp:82
EntityHandle
MoFEM::ProblemsManager
Problem manager is used to build and partition problems.
Definition: ProblemsManager.hpp:21
MoFEM::ProblemsManager::inheritPartition
MoFEMErrorCode inheritPartition(const std::string name, const std::string problem_for_rows, bool copy_rows, const std::string problem_for_cols, bool copy_cols, int verb=VERBOSE)
build indexing and partition problem inheriting indexing and partitioning from two other problems
Definition: ProblemsManager.cpp:1896
MoFEM::CoreInterface::modify_finite_element_add_field_row
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
L2
@ L2
field with C-1 continuity
Definition: definitions.h:88
MoFEM.hpp
MoFEM::CoreTmp< 0 >::Finalize
static MoFEMErrorCode Finalize()
Checks for options to be called at the conclusion of the program.
Definition: Core.cpp:112
MoFEM::CoreInterface::add_ents_to_field_by_dim
virtual MoFEMErrorCode add_ents_to_field_by_dim(const Range &ents, const int dim, const std::string &name, int verb=DEFAULT_VERBOSITY)=0
Add entities to field meshset.
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
MoFEM::CoreInterface::add_ents_to_finite_element_by_type
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
VERBOSE
@ VERBOSE
Definition: definitions.h:222
help
static char help[]
Definition: build_problems.cpp:12
CHKERR
#define CHKERR
Inline error check.
Definition: definitions.h:548
MoFEM::CoreInterface::add_finite_element
virtual MoFEMErrorCode add_finite_element(const std::string &fe_name, enum MoFEMTypes bh=MF_EXCL, int verb=DEFAULT_VERBOSITY)=0
add finite element
MoFEM
implementation of Data Operators for Forces and Sources
Definition: Common.hpp:10
MoFEM::CoreInterface::modify_finite_element_add_field_col
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
MoFEM::CoreInterface::build_finite_elements
virtual MoFEMErrorCode build_finite_elements(int verb=DEFAULT_VERBOSITY)=0
Build finite elements.
MoFEM::ProblemsManager::partitionFiniteElements
MoFEMErrorCode partitionFiniteElements(const std::string name, bool part_from_moab=false, int low_proc=-1, int hi_proc=-1, int verb=VERBOSE)
partition finite elements
Definition: ProblemsManager.cpp:2167
MoFEM::CoreInterface::modify_problem_ref_level_add_bit
virtual MoFEMErrorCode modify_problem_ref_level_add_bit(const std::string &name_problem, const BitRefLevel &bit)=0
add ref level to problem
mesh_file_name
char mesh_file_name[255]
Definition: mesh_smoothing.cpp:22
MoFEM::MatrixManager
Matrix manager is used to build and partition problems.
Definition: MatrixManager.hpp:21
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::Core
CoreTmp< 0 > Core
Definition: Core.hpp:1148
AINSWORTH_LEGENDRE_BASE
@ AINSWORTH_LEGENDRE_BASE
Ainsworth Cole (Legendre) approx. base .
Definition: definitions.h:60
MoFEM::PetscOptionsGetString
PetscErrorCode PetscOptionsGetString(PetscOptions *, const char pre[], const char name[], char str[], size_t size, PetscBool *set)
Definition: DeprecatedPetsc.hpp:172
MoFEM::CoreInterface::build_fields
virtual MoFEMErrorCode build_fields(int verb=DEFAULT_VERBOSITY)=0
MoFEM::BitRefManager
Managing BitRefLevels.
Definition: BitRefManager.hpp:21
MoFEM::CoreInterface::modify_problem_add_finite_element
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
MoFEM::Types::BitRefLevel
std::bitset< BITREFLEVEL_SIZE > BitRefLevel
Bit structure attached to each entity identifying to what mesh entity is attached.
Definition: Types.hpp:40
MoFEM::CoreInterface::build_adjacencies
virtual MoFEMErrorCode build_adjacencies(const Range &ents, int verb=DEFAULT_VERBOSITY)=0
build adjacencies
MoFEM::CoreInterface::set_field_order
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.
MoFEM::ProblemsManager::partitionGhostDofs
MoFEMErrorCode partitionGhostDofs(const std::string name, int verb=VERBOSE)
determine ghost nodes
Definition: ProblemsManager.cpp:2339
MoFEM::CoreInterface::add_problem
virtual MoFEMErrorCode add_problem(const std::string &name, enum MoFEMTypes bh=MF_EXCL, int verb=DEFAULT_VERBOSITY)=0
Add problem.
HDIV
@ HDIV
field with continuous normal traction
Definition: definitions.h:87
main
int main(int argc, char *argv[])
Definition: build_problems.cpp:14
MoFEM::CoreInterface::add_field
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.
MoFEM::ProblemsManager::partitionProblem
MoFEMErrorCode partitionProblem(const std::string name, int verb=VERBOSE)
partition problem dofs (collective)
Definition: ProblemsManager.cpp:1683