v0.13.0
Functions | Variables
dm_create_subdm.cpp File Reference
#include <MoFEM.hpp>

Go to the source code of this file.

Functions

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

Variables

static char help [] = "...\n\n"
 
static const bool debug = false
 

Function Documentation

◆ main()

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

Definition at line 28 of file dm_create_subdm.cpp.

28  {
29 
30  // initialize petsc
31  MoFEM::Core::Initialize(&argc, &argv, (char *)0, help);
32 
33  try {
34 
35  PetscBool flg = PETSC_TRUE;
36  char mesh_file_name[255];
37 #if PETSC_VERSION_GE(3, 6, 4)
38  CHKERR PetscOptionsGetString(PETSC_NULL, "", "-my_file", mesh_file_name,
39  255, &flg);
40 #else
41  CHKERR PetscOptionsGetString(PETSC_NULL, PETSC_NULL, "-my_file",
42  mesh_file_name, 255, &flg);
43 #endif
44  if (flg != PETSC_TRUE) {
45  SETERRQ(PETSC_COMM_SELF, 1, "*** ERROR -my_file (MESH FILE NEEDED)");
46  }
47 
48  // register new dm type, i.e. mofem
49  DMType dm_name = "DMMOFEM";
50  CHKERR DMRegister_MoFEM(dm_name);
51  DMType dm_name_sub = "DMSUB";
52  CHKERR DMRegister_MoFEM(dm_name_sub);
53 
54  // craete dm instance
55  DM dm;
56  CHKERR DMCreate(PETSC_COMM_WORLD, &dm);
57  CHKERR DMSetType(dm, dm_name);
58 
59  DM subdm0, subdm1;
60  CHKERR DMCreate(PETSC_COMM_WORLD, &subdm0);
61  CHKERR DMSetType(subdm0, dm_name_sub);
62  CHKERR DMCreate(PETSC_COMM_WORLD, &subdm1);
63  CHKERR DMSetType(subdm1, dm_name_sub);
64 
65  // read mesh and create moab and mofem data structures
66  moab::Core mb_instance;
67  moab::Interface &moab = mb_instance;
68  ParallelComm *pcomm = ParallelComm::get_pcomm(&moab, MYPCOMM_INDEX);
69  auto moab_comm_wrap =
70  boost::make_shared<WrapMPIComm>(PETSC_COMM_WORLD, false);
71  if (pcomm == NULL)
72  pcomm = new ParallelComm(&moab, moab_comm_wrap->get_comm());
73 
74  const char *option;
75  option = "PARALLEL=BCAST_DELETE;PARALLEL_RESOLVE_SHARED_ENTS;PARTITION="
76  "PARALLEL_PARTITION;";
77  CHKERR moab.load_file(mesh_file_name, 0, option);
78 
79  MoFEM::Core core(moab);
80  MoFEM::Interface &m_field = core;
81 
82  EntityHandle root_set = moab.get_root_set();
83  // add all entities to database, all of them will be used
84  BitRefLevel bit_level0;
85  bit_level0.set(0);
86  CHKERR m_field.getInterface<BitRefManager>()->setBitRefLevelByDim(
87  root_set, 3, bit_level0);
88  // define & build field
89  const int field_rank = 1;
90  CHKERR m_field.add_field("FIELD0", H1, AINSWORTH_LEGENDRE_BASE, field_rank);
91  // add entities to field
92  CHKERR m_field.add_ents_to_field_by_type(root_set, MBTET, "FIELD0");
93  // set app. order
94  CHKERR m_field.set_field_order(root_set, MBVERTEX, "FIELD0", 1);
95  CHKERR m_field.add_field("FIELD1", H1, AINSWORTH_LEGENDRE_BASE, field_rank);
96  // add entities to field
97  CHKERR m_field.add_ents_to_field_by_type(root_set, MBTET, "FIELD1");
98  // set app. order
99  CHKERR m_field.set_field_order(root_set, MBVERTEX, "FIELD1", 1);
100  CHKERR m_field.set_field_order(root_set, MBEDGE, "FIELD1", 2);
101 
102  // build data structures for fields
103  CHKERR m_field.build_fields();
104 
105  // define & build finite elements
106  CHKERR m_field.add_finite_element("FE00");
107  // Define rows/cols and element data
108  CHKERR m_field.modify_finite_element_add_field_row("FE00", "FIELD0");
109  CHKERR m_field.modify_finite_element_add_field_col("FE00", "FIELD0");
110  CHKERR m_field.modify_finite_element_add_field_data("FE00", "FIELD0");
111  // add entities to finite element
112  CHKERR m_field.add_ents_to_finite_element_by_type(root_set, MBTET, "FE00");
113 
114  // define & build finite elements
115  CHKERR m_field.add_finite_element("FE11");
116  // Define rows/cols and element data
117  CHKERR m_field.modify_finite_element_add_field_row("FE11", "FIELD1");
118  CHKERR m_field.modify_finite_element_add_field_col("FE11", "FIELD1");
119  CHKERR m_field.modify_finite_element_add_field_data("FE11", "FIELD1");
120  // add entities to finite element
121  CHKERR m_field.add_ents_to_finite_element_by_type(root_set, MBTET, "FE11");
122 
123  // define & build finite elements
124  CHKERR m_field.add_finite_element("FE01");
125  // Define rows/cols and element data
126  CHKERR m_field.modify_finite_element_add_field_row("FE01", "FIELD0");
127  CHKERR m_field.modify_finite_element_add_field_col("FE01", "FIELD1");
128  CHKERR m_field.modify_finite_element_add_field_data("FE01", "FIELD0");
129  CHKERR m_field.modify_finite_element_add_field_data("FE01", "FIELD1");
130  // add entities to finite element
131  CHKERR m_field.add_ents_to_finite_element_by_type(root_set, MBTET, "FE01");
132 
133  // build finite elemnts
134  CHKERR m_field.build_finite_elements();
135  // build adjacencies
136  CHKERR m_field.build_adjacencies(bit_level0);
137 
138  // set dm data structure which created mofem data structures
139  CHKERR DMMoFEMCreateMoFEM(dm, &m_field, "MAIN_PROBLEM", bit_level0);
140  CHKERR DMSetFromOptions(dm);
141  CHKERR DMMoFEMAddElement(dm, "FE00");
142  CHKERR DMMoFEMAddElement(dm, "FE11");
143  CHKERR DMMoFEMAddElement(dm, "FE01");
144  CHKERR DMSetUp(dm);
146  ->checkMPIAIJWithArraysMatrixFillIn<PetscGlobalIdx_mi_tag>(
147  "MAIN_PROBLEM", -1, -1, 1);
148 
149  int nf;
150  char **field_names;
151  IS *fields;
152  CHKERR DMCreateFieldIS(dm, &nf, &field_names, &fields);
153  for (int f = 0; f != nf; f++) {
154  PetscPrintf(PETSC_COMM_WORLD, "%d field %s\n", f, field_names[f]);
155  CHKERR PetscFree(field_names[f]);
156  CHKERR ISDestroy(&(fields[f]));
157  }
158  CHKERR PetscFree(field_names);
159  CHKERR PetscFree(fields);
160 
161  CHKERR DMMoFEMCreateSubDM(subdm0, dm, "SUB0");
162  CHKERR DMMoFEMSetSquareProblem(subdm0, PETSC_TRUE);
163  CHKERR DMMoFEMAddElement(subdm0, "FE11");
164  CHKERR DMMoFEMAddSubFieldRow(subdm0, "FIELD1", MBVERTEX, MBVERTEX);
165  CHKERR DMMoFEMAddSubFieldCol(subdm0, "FIELD1", MBVERTEX, MBVERTEX);
166  CHKERR DMSetUp(subdm0);
168  ->checkMPIAIJWithArraysMatrixFillIn<PetscGlobalIdx_mi_tag>("SUB0", -1,
169  -1, 1);
170  if (debug) {
171  Mat A;
172  CHKERR DMCreateMatrix(subdm0, &A);
173  MatView(A, PETSC_VIEWER_DRAW_WORLD);
174  std::string wait;
175  std::cin >> wait;
176  CHKERR MatDestroy(&A);
177  }
178 
179  CHKERR DMMoFEMCreateSubDM(subdm1, dm, "SUB1");
180  CHKERR DMMoFEMSetSquareProblem(subdm1, PETSC_FALSE);
181  CHKERR DMMoFEMAddElement(subdm1, "FE01");
182  CHKERR DMMoFEMAddSubFieldRow(subdm1, "FIELD0");
183  CHKERR DMMoFEMAddSubFieldCol(subdm1, "FIELD1");
184  CHKERR DMSetUp(subdm1);
186  ->checkMPIAIJWithArraysMatrixFillIn<PetscGlobalIdx_mi_tag>("SUB1", -1,
187  -1, 1);
188 
189  if (debug) {
190  Mat B;
191  CHKERR DMCreateMatrix(subdm1, &B);
192  MatView(B, PETSC_VIEWER_DRAW_WORLD);
193  std::string wait;
194  std::cin >> wait;
195  CHKERR MatDestroy(&B);
196  }
197 
198  // destry dm
199  CHKERR DMDestroy(&dm);
200  CHKERR DMDestroy(&subdm0);
201  CHKERR DMDestroy(&subdm1);
202  }
203  CATCH_ERRORS;
204 
205  // finish work cleaning memory, getting statistics, ect.
207 
208  return 0;
209 }
#define CATCH_ERRORS
Catch errors.
Definition: definitions.h:385
@ AINSWORTH_LEGENDRE_BASE
Ainsworth Cole (Legendre) approx. base .
Definition: definitions.h:73
@ H1
continuous field
Definition: definitions.h:98
#define MYPCOMM_INDEX
default communicator number PCOMM
Definition: definitions.h:228
#define CHKERR
Inline error check.
Definition: definitions.h:548
static char help[]
static const bool debug
PetscErrorCode DMMoFEMCreateSubDM(DM subdm, DM dm, const char problem_name[])
Must be called by user to set Sub DM MoFEM data structures.
Definition: DMMMoFEM.cpp:213
PetscErrorCode DMMoFEMSetSquareProblem(DM dm, PetscBool square_problem)
set squared problem
Definition: DMMMoFEM.cpp:414
PetscErrorCode DMMoFEMAddSubFieldRow(DM dm, const char field_name[], EntityType lo_type=MBVERTEX, EntityType hi_type=MBMAXTYPE)
Definition: DMMMoFEM.cpp:234
PetscErrorCode DMMoFEMCreateMoFEM(DM dm, MoFEM::Interface *m_field_ptr, const char problem_name[], const MoFEM::BitRefLevel bit_level, const MoFEM::BitRefLevel bit_mask=MoFEM::BitRefLevel().set())
Must be called by user to set MoFEM data structures.
Definition: DMMMoFEM.cpp:130
PetscErrorCode DMMoFEMAddElement(DM dm, const char fe_name[])
add element to dm
Definition: DMMMoFEM.cpp:461
PetscErrorCode DMMoFEMAddSubFieldCol(DM dm, const char field_name[], EntityType lo_type=MBVERTEX, EntityType hi_type=MBMAXTYPE)
Definition: DMMMoFEM.cpp:257
PetscErrorCode DMRegister_MoFEM(const char sname[])
Register MoFEM problem.
Definition: DMMMoFEM.cpp:59
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
virtual MoFEMErrorCode add_finite_element(const std::string &fe_name, enum MoFEMTypes bh=MF_EXCL, int verb=DEFAULT_VERBOSITY)=0
add finite element
virtual MoFEMErrorCode build_finite_elements(int verb=DEFAULT_VERBOSITY)=0
Build finite elements.
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
virtual MoFEMErrorCode modify_finite_element_add_field_data(const std::string &fe_name, const std::string &name_filed)=0
set finite element field data
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 build_fields(int verb=DEFAULT_VERBOSITY)=0
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.
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.
char mesh_file_name[255]
std::bitset< BITREFLEVEL_SIZE > BitRefLevel
Bit structure attached to each entity identifying to what mesh entity is attached.
Definition: Types.hpp:51
CoreTmp< 0 > Core
Definition: Core.hpp:1096
PetscErrorCode PetscOptionsGetString(PetscOptions *, const char pre[], const char name[], char str[], size_t size, PetscBool *set)
DeprecatedCoreInterface Interface
Definition: Interface.hpp:1965
double A
Managing BitRefLevels.
virtual MoFEMErrorCode build_adjacencies(const Range &ents, int verb=DEFAULT_VERBOSITY)=0
build adjacencies
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.
Core (interface) class.
Definition: Core.hpp:92
static MoFEMErrorCode Initialize(int *argc, char ***args, const char file[], const char help[])
Initializes the MoFEM database PETSc, MOAB and MPI.
Definition: Core.cpp:85
static MoFEMErrorCode Finalize()
Checks for options to be called at the conclusion of the program.
Definition: Core.cpp:125
Deprecated interface functions.
Matrix manager is used to build and partition problems.
MoFEMErrorCode getInterface(IFACE *&iface) const
Get interface refernce to pointer of interface.

Variable Documentation

◆ debug

const bool debug = false
static

◆ help

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

Definition at line 24 of file dm_create_subdm.cpp.