v0.14.0
build_large_problem.cpp
Go to the documentation of this file.
1 /** \file build_problems.cpp
2  \example build_problems.cpp
3  \brief atom test build problem
4 */
5 
6 #include <MoFEM.hpp>
7 using namespace MoFEM;
8 
9 static char help[] = "...\n\n";
10 
11 int main(int argc, char *argv[]) {
12 
13  MoFEM::Core::Initialize(&argc, &argv, (char *)0, help);
14 
15  try {
16 
17  moab::Core mb_instance;
18  moab::Interface &moab = mb_instance;
19  int rank;
20  MPI_Comm_rank(PETSC_COMM_WORLD, &rank);
21 
22  PetscBool flg = PETSC_TRUE;
23  char mesh_file_name[255];
24 
25 #if PETSC_VERSION_GE(3, 6, 4)
26  CHKERR PetscOptionsGetString(PETSC_NULL, "", "-my_file", mesh_file_name,
27  255, &flg);
28 #else
29  CHKERR PetscOptionsGetString(PETSC_NULL, PETSC_NULL, "-my_file",
30  mesh_file_name, 255, &flg);
31 #endif
32 
33  if (flg != PETSC_TRUE)
34  SETERRQ1(PETSC_COMM_SELF, MOFEM_NOT_FOUND, "file not found -my_file %s",
36 
37  CHKERR moab.load_file(mesh_file_name, 0, "");
38 
39  // Create MoFEM database
40  MoFEM::Core core(moab);
41  MoFEM::Interface &m_field = core;
42 
43  // set entities bit level
44  CHKERR m_field.getInterface<BitRefManager>()->setBitRefLevelByDim(
45  0, 3, BitRefLevel().set(0));
46 
47  // fields
48  CHKERR m_field.add_field("F1", H1, AINSWORTH_LEGENDRE_BASE, 3,
49  MB_TAG_DENSE);
50 
51  // meshset consisting all entities in mesh
52  EntityHandle root_set = moab.get_root_set();
53  // add entities to field
54  CHKERR m_field.add_ents_to_field_by_type(root_set, MBVERTEX, "F1");
55  CHKERR m_field.add_ents_to_field_by_type(root_set, MBEDGE, "F1");
56  CHKERR m_field.add_ents_to_field_by_type(root_set, MBTRI, "F1");
57  CHKERR m_field.add_ents_to_field_by_type(root_set, MBTET, "F1");
58 
59  // set app. order
60  constexpr int order = 3;
61  CHKERR m_field.set_field_order(root_set, MBVERTEX, "F1", 1);
62  CHKERR m_field.set_field_order(root_set, MBEDGE, "F1", order);
63  CHKERR m_field.set_field_order(root_set, MBTRI, "F1", order);
64  CHKERR m_field.set_field_order(root_set, MBTET, "F1", order);
65 
66  CHKERR m_field.build_fields();
67 
68  // add elements
69  CHKERR m_field.add_finite_element("E1");
70  CHKERR m_field.modify_finite_element_add_field_row("E1", "F1");
71  CHKERR m_field.modify_finite_element_add_field_col("E1", "F1");
72  CHKERR m_field.modify_finite_element_add_field_data("E1", "F1");
73  CHKERR m_field.add_ents_to_finite_element_by_type(root_set, MBTET, "E1");
74  CHKERR m_field.build_finite_elements();
75  CHKERR m_field.build_adjacencies(BitRefLevel().set(0));
76 
77  // Problems
78  CHKERR m_field.add_problem("P1");
79  CHKERR m_field.modify_problem_ref_level_add_bit("P1", BitRefLevel().set(0));
80  CHKERR m_field.modify_problem_add_finite_element("P1", "E1");
81 
82  // build problems
83  auto prb_mng_ptr = m_field.getInterface<ProblemsManager>();
84  CHKERR m_field.getInterface(prb_mng_ptr);
85  CHKERR prb_mng_ptr->buildProblem("P1", true);
86  CHKERR prb_mng_ptr->partitionProblem("P1");
87  CHKERR prb_mng_ptr->partitionFiniteElements("P1");
88  CHKERR prb_mng_ptr->partitionGhostDofs("P1");
89 
90  MOFEM_LOG_CHANNEL("WORLD");
91  MOFEM_LOG("WORLD", Sev::inform) << "Create matrix";
94  ->createMPIAIJWithArrays<PetscGlobalIdx_mi_tag>("P1", A);
95  MOFEM_LOG_CHANNEL("WORLD");
96  MOFEM_LOG("WORLD", Sev::inform) << "Done";
97 
98  auto fe_ptr = boost::make_shared<FEMethod>();
99 
100  auto pre_proc_hook = [&]() {
103  };
104 
105  auto post_proc_hook = [&]() {
108  };
109 
110  auto op_hook = [&]() {
112 
113  MOFEM_LOG_CHANNEL("WORLD");
114  MOFEM_LOG("WORLD", Sev::verbose)
115  << "Iterate finite element " << *(fe_ptr->numeredEntFiniteElementPtr);
116 
117  auto row_dofs = fe_ptr->getRowDofsPtr();
118  for (auto &dof : *row_dofs)
119  MOFEM_LOG("WORLD", Sev::noisy) << *dof << endl;
120 
122  };
123 
124  fe_ptr->preProcessHook = pre_proc_hook;
125  fe_ptr->postProcessHook = post_proc_hook;
126  fe_ptr->operatorHook = op_hook;
127 
128  MOFEM_LOG_CHANNEL("WORLD");
129  MOFEM_LOG("WORLD", Sev::inform) << "Iterate finite elements";
130  CHKERR m_field.loop_finite_elements("P1", "E1", *fe_ptr);
131  MOFEM_LOG("WORLD", Sev::inform) << "Done";
132 
136 
137  auto vol_ptr = boost::make_shared<Vol>(m_field);
138 
139  struct Op : public VolOp {
140 
141  Op() : VolOp("F1", VolOp::OPROWCOL, true) {}
142 
143  MoFEMErrorCode doWork(int row_side, int col_side, EntityType row_type,
144  EntityType col_type, EntData &row_data,
145  EntData &col_data) {
146  return 0;
147  };
148  };
149 
150  vol_ptr->getOpPtrVector().push_back(new Op());
151 
152  MOFEM_LOG_CHANNEL("WORLD");
153  MOFEM_LOG("WORLD", Sev::inform) << "Iterate volume finite elements";
154  CHKERR m_field.loop_finite_elements("P1", "E1", *vol_ptr);
155  MOFEM_LOG("WORLD", Sev::inform) << "Done";
156 
157  }
158  CATCH_ERRORS;
159 
160  // finish work cleaning memory, getting statistics, etc.
162 
163  return 0;
164 }
MoFEM::UnknownInterface::getInterface
MoFEMErrorCode getInterface(IFACE *&iface) const
Get interface reference to pointer of interface.
Definition: UnknownInterface.hpp:93
MoFEM::EntitiesFieldData::EntData
Data on single entity (This is passed as argument to DataOperator::doWork)
Definition: EntitiesFieldData.hpp:128
MoFEM::CoreInterface::loop_finite_elements
virtual MoFEMErrorCode loop_finite_elements(const std::string problem_name, const std::string &fe_name, FEMethod &method, boost::shared_ptr< NumeredEntFiniteElement_multiIndex > fe_ptr=nullptr, MoFEMTypes bh=MF_EXIST, CacheTupleWeakPtr cache_ptr=CacheTupleSharedPtr(), int verb=DEFAULT_VERBOSITY)=0
Make a loop over finite elements.
MoFEM::CoreTmp< 0 >
Core (interface) class.
Definition: Core.hpp:82
H1
@ H1
continuous field
Definition: definitions.h:85
MOFEM_LOG_CHANNEL
#define MOFEM_LOG_CHANNEL(channel)
Set and reset channel.
Definition: LogManager.hpp:284
EntityHandle
MoFEM::ProblemsManager
Problem manager is used to build and partition problems.
Definition: ProblemsManager.hpp:21
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
MoFEM::Exceptions::MoFEMErrorCode
PetscErrorCode MoFEMErrorCode
MoFEM/PETSc error code.
Definition: Exceptions.hpp:56
MoFEM.hpp
A
constexpr AssemblyType A
Definition: operators_tests.cpp:30
MoFEM::CoreTmp< 0 >::Finalize
static MoFEMErrorCode Finalize()
Checks for options to be called at the conclusion of the program.
Definition: Core.cpp:112
MoFEM::ForcesAndSourcesCore::UserDataOperator::OPROWCOL
@ OPROWCOL
operator doWork is executed on FE rows &columns
Definition: ForcesAndSourcesCore.hpp:569
MoFEM::CoreInterface::add_ents_to_field_by_type
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.
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
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::VolumeElementForcesAndSourcesCore::UserDataOperator
friend class UserDataOperator
Definition: VolumeElementForcesAndSourcesCore.hpp:105
MoFEM::CoreInterface::modify_finite_element_add_field_data
virtual MoFEMErrorCode modify_finite_element_add_field_data(const std::string &fe_name, const std::string name_field)=0
set finite element field data
MoFEM::VolumeElementForcesAndSourcesCore
Volume finite element base.
Definition: VolumeElementForcesAndSourcesCore.hpp:26
VolOp
VolEle::UserDataOperator VolOp
Definition: test_cache_on_entities.cpp:23
MOFEM_NOT_FOUND
@ MOFEM_NOT_FOUND
Definition: definitions.h:33
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
MoFEM::VolumeElementForcesAndSourcesCore::UserDataOperator
Definition: VolumeElementForcesAndSourcesCore.hpp:108
EntData
EntitiesFieldData::EntData EntData
Definition: child_and_parent.cpp:37
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
MOFEM_LOG
#define MOFEM_LOG(channel, severity)
Log.
Definition: LogManager.hpp:308
CATCH_ERRORS
#define CATCH_ERRORS
Catch errors.
Definition: definitions.h:385
MoFEM::Core
CoreTmp< 0 > Core
Definition: Core.hpp:1148
Op
Definition: prism_elements_from_surface.cpp:78
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
main
int main(int argc, char *argv[])
Definition: build_large_problem.cpp:11
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::SmartPetscObj< Mat >
MoFEM::CoreInterface::add_problem
virtual MoFEMErrorCode add_problem(const std::string &name, enum MoFEMTypes bh=MF_EXCL, int verb=DEFAULT_VERBOSITY)=0
Add problem.
MoFEMFunctionReturn
#define MoFEMFunctionReturn(a)
Last executable line of each PETSc function used for error handling. Replaces return()
Definition: definitions.h:429
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.
MoFEMFunctionBegin
#define MoFEMFunctionBegin
First executable line of each MoFEM function, used for error handling. Final line of MoFEM functions ...
Definition: definitions.h:359
help
static char help[]
Definition: build_large_problem.cpp:9