v0.9.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  if (pcomm == NULL)
70  pcomm = new ParallelComm(&moab, PETSC_COMM_WORLD);
71  const char *option;
72  option = "PARALLEL=BCAST_DELETE;PARALLEL_RESOLVE_SHARED_ENTS;PARTITION="
73  "PARALLEL_PARTITION;";
74  CHKERR moab.load_file(mesh_file_name, 0, option);
75 
76  MoFEM::Core core(moab);
77  MoFEM::Interface &m_field = core;
78 
79  EntityHandle root_set = moab.get_root_set();
80  // add all entities to database, all of them will be used
81  BitRefLevel bit_level0;
82  bit_level0.set(0);
83  CHKERR m_field.getInterface<BitRefManager>()->setBitRefLevelByDim(
84  root_set, 3, bit_level0);
85  // define & build field
86  const int field_rank = 1;
87  CHKERR m_field.add_field("FIELD0", H1, AINSWORTH_LEGENDRE_BASE, field_rank);
88  // add entities to field
89  CHKERR m_field.add_ents_to_field_by_type(root_set, MBTET, "FIELD0");
90  // set app. order
91  CHKERR m_field.set_field_order(root_set, MBVERTEX, "FIELD0", 1);
92  CHKERR m_field.add_field("FIELD1", H1, AINSWORTH_LEGENDRE_BASE, field_rank);
93  // add entities to field
94  CHKERR m_field.add_ents_to_field_by_type(root_set, MBTET, "FIELD1");
95  // set app. order
96  CHKERR m_field.set_field_order(root_set, MBVERTEX, "FIELD1", 1);
97  CHKERR m_field.set_field_order(root_set, MBEDGE, "FIELD1", 2);
98 
99  // build data structures for fields
100  CHKERR m_field.build_fields();
101 
102  // define & build finite elements
103  CHKERR m_field.add_finite_element("FE00");
104  // Define rows/cols and element data
105  CHKERR m_field.modify_finite_element_add_field_row("FE00", "FIELD0");
106  CHKERR m_field.modify_finite_element_add_field_col("FE00", "FIELD0");
107  CHKERR m_field.modify_finite_element_add_field_data("FE00", "FIELD0");
108  // add entities to finite element
109  CHKERR m_field.add_ents_to_finite_element_by_type(root_set, MBTET, "FE00");
110 
111  // define & build finite elements
112  CHKERR m_field.add_finite_element("FE11");
113  // Define rows/cols and element data
114  CHKERR m_field.modify_finite_element_add_field_row("FE11", "FIELD1");
115  CHKERR m_field.modify_finite_element_add_field_col("FE11", "FIELD1");
116  CHKERR m_field.modify_finite_element_add_field_data("FE11", "FIELD1");
117  // add entities to finite element
118  CHKERR m_field.add_ents_to_finite_element_by_type(root_set, MBTET, "FE11");
119 
120  // define & build finite elements
121  CHKERR m_field.add_finite_element("FE01");
122  // Define rows/cols and element data
123  CHKERR m_field.modify_finite_element_add_field_row("FE01", "FIELD0");
124  CHKERR m_field.modify_finite_element_add_field_col("FE01", "FIELD1");
125  CHKERR m_field.modify_finite_element_add_field_data("FE01", "FIELD0");
126  CHKERR m_field.modify_finite_element_add_field_data("FE01", "FIELD1");
127  // add entities to finite element
128  CHKERR m_field.add_ents_to_finite_element_by_type(root_set, MBTET, "FE01");
129 
130  // build finite elemnts
131  CHKERR m_field.build_finite_elements();
132  // build adjacencies
133  CHKERR m_field.build_adjacencies(bit_level0);
134 
135  // set dm data structure which created mofem data structures
136  CHKERR DMMoFEMCreateMoFEM(dm, &m_field, "MAIN_PROBLEM", bit_level0);
137  CHKERR DMSetFromOptions(dm);
138  CHKERR DMMoFEMAddElement(dm, "FE00");
139  CHKERR DMMoFEMAddElement(dm, "FE11");
140  CHKERR DMMoFEMAddElement(dm, "FE01");
141  CHKERR DMSetUp(dm);
143  ->checkMPIAIJWithArraysMatrixFillIn<PetscGlobalIdx_mi_tag>(
144  "MAIN_PROBLEM", -1, -1, 1);
145 
146  int nf;
147  char **field_names;
148  IS *fields;
149  CHKERR DMCreateFieldIS(dm, &nf, &field_names, &fields);
150  for (int f = 0; f != nf; f++) {
151  PetscPrintf(PETSC_COMM_WORLD, "%d field %s\n", f, field_names[f]);
152  CHKERR PetscFree(field_names[f]);
153  CHKERR ISDestroy(&(fields[f]));
154  }
155  CHKERR PetscFree(field_names);
156  CHKERR PetscFree(fields);
157 
158  CHKERR DMMoFEMCreateSubDM(subdm0, dm, "SUB0");
159  CHKERR DMMoFEMSetSquareProblem(subdm0, PETSC_TRUE);
160  CHKERR DMMoFEMAddElement(subdm0, "FE11");
161  CHKERR DMMoFEMAddSubFieldRow(subdm0, "FIELD1", MBVERTEX, MBVERTEX);
162  CHKERR DMMoFEMAddSubFieldCol(subdm0, "FIELD1", MBVERTEX, MBVERTEX);
163  CHKERR DMSetUp(subdm0);
165  ->checkMPIAIJWithArraysMatrixFillIn<PetscGlobalIdx_mi_tag>("SUB0", -1,
166  -1, 1);
167  if (debug) {
168  Mat A;
169  CHKERR DMCreateMatrix(subdm0, &A);
170  MatView(A, PETSC_VIEWER_DRAW_WORLD);
171  std::string wait;
172  std::cin >> wait;
173  CHKERR MatDestroy(&A);
174  }
175 
176  CHKERR DMMoFEMCreateSubDM(subdm1, dm, "SUB1");
177  CHKERR DMMoFEMSetSquareProblem(subdm1, PETSC_FALSE);
178  CHKERR DMMoFEMAddElement(subdm1, "FE01");
179  CHKERR DMMoFEMAddSubFieldRow(subdm1, "FIELD0");
180  CHKERR DMMoFEMAddSubFieldCol(subdm1, "FIELD1");
181  CHKERR DMSetUp(subdm1);
183  ->checkMPIAIJWithArraysMatrixFillIn<PetscGlobalIdx_mi_tag>("SUB1", -1,
184  -1, 1);
185 
186  if (debug) {
187  Mat B;
188  CHKERR DMCreateMatrix(subdm1, &B);
189  MatView(B, PETSC_VIEWER_DRAW_WORLD);
190  std::string wait;
191  std::cin >> wait;
192  CHKERR MatDestroy(&B);
193  }
194 
195  // destry dm
196  CHKERR DMDestroy(&dm);
197  CHKERR DMDestroy(&subdm0);
198  CHKERR DMDestroy(&subdm1);
199  }
200  CATCH_ERRORS;
201 
202  // finish work cleaning memory, getting statistics, ect.
204 
205  return 0;
206 }
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
virtual MoFEMErrorCode build_adjacencies(const Range &ents, int verb=DEFAULT_VERBOSITY)=0
build adjacencies
PetscErrorCode DMMoFEMSetSquareProblem(DM dm, PetscBool square_problem)
set squared problemIt if true is assumed that matrix has the same indexing on rows and columns....
Definition: DMMMoFEM.cpp:367
PetscErrorCode DMMoFEMAddSubFieldCol(DM dm, const char field_name[], EntityType lo_type=MBVERTEX, EntityType hi_type=MBMAXTYPE)
Definition: DMMMoFEM.cpp:210
PetscErrorCode DMMoFEMAddElement(DM dm, const char fe_name[])
add element to dm
Definition: DMMMoFEM.cpp:414
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.
Core (interface) class.
Definition: Core.hpp:50
char mesh_file_name[255]
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 DMMoFEMCreateSubDM(DM subdm, DM dm, const char problem_name[])
Must be called by user to set Sub DM MoFEM data structures.
Definition: DMMMoFEM.cpp:166
PetscErrorCode DMMoFEMAddSubFieldRow(DM dm, const char field_name[], EntityType lo_type=MBVERTEX, EntityType hi_type=MBMAXTYPE)
Definition: DMMMoFEM.cpp:187
PetscErrorCode PetscOptionsGetString(PetscOptions *, const char pre[], const char name[], char str[], size_t size, PetscBool *set)
MoFEMErrorCode getInterface(const MOFEMuuid &uuid, IFACE *&iface) const
Get interface by uuid and return reference to pointer of interface.
static char help[]
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.
static const bool debug
Managing BitRefLevels.
PetscErrorCode DMRegister_MoFEM(const char sname[])
Register MoFEM problem.
Definition: DMMMoFEM.cpp:53
Ainsworth Cole (Legendre) approx. base .
Definition: definitions.h:146
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:109
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:596
virtual MoFEMErrorCode modify_finite_element_add_field_data(const std::string &fe_name, const std::string &name_filed)=0
set finite element field data
#define MYPCOMM_INDEX
default communicator number PCOMM
Definition: definitions.h:285
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
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
#define CATCH_ERRORS
Catch errors.
Definition: definitions.h:433
continuous field
Definition: definitions.h:171
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.
static MoFEMErrorCode Finalize()
Checks for options to be called at the conclusion of the program.
Definition: Core.cpp:61

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.