v0.13.1
ProblemsManager.hpp
Go to the documentation of this file.
1/** \file ProblemsManager.hpp
2 * \brief Interface managing problems
3 * \ingroup mofem_problems_manager
4 *
5 * Managing problems, build and partitioning.
6 *
7 */
8
9/*
10 * MoFEM is distributed in the hope that it will be useful, but WITHOUT
11 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
12 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
13 * License for more details.
14 *
15 * You should have received a copy of the GNU Lesser General Public
16 * License along with MoFEM. If not, see <http://www.gnu.org/licenses/>
17 */
18
19#ifndef __PROBLEMSMANAGER_HPP__
20#define __PROBLEMSMANAGER_HPP__
21
22#include "UnknownInterface.hpp"
23
24namespace MoFEM {
25
26/**
27 * \brief Problem manager is used to build and partition problems
28 * \ingroup mofem_problems_manager
29 *
30 */
32
33 MoFEMErrorCode query_interface(boost::typeindex::type_index type_index,
34 UnknownInterface **iface) const;
35
37 ProblemsManager(const MoFEM::Core &core);
38 virtual ~ProblemsManager() = default;
39
40 PetscBool buildProblemFromFields; ///< If set to true, problem is build from
41 /// DOFs in fields, not from DOFs on elements
42
44
46
47 /**
48 * \brief Set partition tag to each finite element in the problem
49 * \deprecated Use CommInterface
50 * \ingroup mofem_problems_manager
51 *
52 * This will use one of the mesh partitioning programs available from PETSc
53 * See
54 * <http://www.mcs.anl.gov/petsc/petsc-current/docs/manualpages/Mat/MatPartitioningType.html>
55 *
56 * @param ents Entities to partition
57 * @param dim Dimension of entities to partition
58 * @param adj_dim Adjacency dimension
59 * @param n_parts Number of partitions
60 * @param verb Verbosity level
61 * @return Error code
62 */
63 DEPRECATED MoFEMErrorCode partitionMesh(const Range &ents, const int dim,
64 const int adj_dim, const int n_parts,
65 Tag *th_vertex_weights = nullptr,
66 Tag *th_edge_weights = nullptr,
67 Tag *th_part_weights = nullptr,
68 int verb = VERBOSE,
69 const bool debug = false);
70
71 /** \brief build problem data structures
72 * \ingroup mofem_problems_manager
73 *
74 * \note If square_matrix is set to true, that indicate that problem is
75 * structurally
76 * symmetric, i.e. rows and columns have the same dofs and are indexed in the
77 * same
78 * way.
79 *
80 * @param name problem name
81 * @param square_matrix structurally symmetric problem
82 * @param verb verbosity level
83 * @return error code
84 *
85 */
86 MoFEMErrorCode buildProblem(const std::string name, const bool square_matrix,
87 int verb = VERBOSE);
88
89 /** \brief build problem data structures
90 * \ingroup mofem_problems_manager
91 *
92 * \note If square_matrix is set to true, that indicate that problem is
93 * structurally
94 * symmetric, i.e. rows and columns have the same dofs and are indexed in the
95 * same
96 * way.
97 *
98 * @param problem pointer
99 * @param square_matrix structurally symmetric problem
100 * @param verb verbosity level
101 * @return error code
102 *
103 */
104 MoFEMErrorCode buildProblem(Problem *problem_ptr, const bool square_matrix,
105 int verb = VERBOSE);
106
107 /** \brief build problem data structures, assuming that mesh is distributed
108 (collective)
109 * \ingroup mofem_problems_manager
110
111 Mesh is distributed, that means that each processor keeps only own part of
112 the mesh and shared entities.
113
114 Collective - need to be run on all processors in communicator, i.e. each
115 function has to call this function.
116
117 */
118 MoFEMErrorCode buildProblemOnDistributedMesh(const std::string name,
119 const bool square_matrix,
120 int verb = VERBOSE);
121
122 /** \brief build problem data structures, assuming that mesh is distributed
123 (collective)
124 * \ingroup mofem_problems_manager
125
126 Mesh is distributed, that means that each processor keeps only own part of
127 the mesh and shared entities.
128
129 Collective - need to be run on all processors in communicator, i.e. each
130 function has to call this function.
131
132 */
134 const bool square_matrix = true,
135 int verb = VERBOSE);
136
137 /**
138 * \brief build sub problem
139 * \ingroup mofem_problems_manager
140 *
141 * @param out_name problem
142 * @param fields_row vector of fields composing problem
143 * @param fields_col vector of fields composing problem
144 * @param main_problem main problem
145 * @return error code
146 */
148 const std::string out_name, const std::vector<std::string> &fields_row,
149 const std::vector<std::string> &fields_col,
150 const std::string main_problem, const bool square_matrix = true,
151 const map<std::string, std::pair<EntityType, EntityType>> *entityMapRow =
152 nullptr,
153 const map<std::string, std::pair<EntityType, EntityType>> *entityMapCol =
154 nullptr,
155 int verb = VERBOSE);
156
157 /**
158 * \brief build composite problem
159 * \ingroup mofem_problems_manager
160 *
161 * @param out_name name of build problem
162 * @param add_row_problems vector of add row problems
163 * @param add_col_problems vector of add col problems
164 * @param square_matrix true if structurally squared matrix
165 * @param verb verbosity level
166 * @return error code
167 */
169 buildComposedProblem(const std::string out_name,
170 const std::vector<std::string> add_row_problems,
171 const std::vector<std::string> add_col_problems,
172 const bool square_matrix = true, int verb = 1);
173
174 /**
175 * \brief build indexing and partition problem inheriting indexing and
176 * partitioning from two other problems
177 * \ingroup mofem_problems_manager
178 *
179 * \param name problem name
180 * \param problem_for_rows problem used to index rows
181 * \param copy_rows just copy rows dofs
182 * \param problem_for_cols problem used to index cols
183 * \param copy_cols just copy cols dofs
184 *
185 * If copy_rows/copy_cols is set to false only partition is copied between
186 * problems.
187 *
188 */
189 MoFEMErrorCode inheritPartition(const std::string name,
190 const std::string problem_for_rows,
191 bool copy_rows,
192 const std::string problem_for_cols,
193 bool copy_cols, int verb = VERBOSE);
194
195 /** \brief partition problem dofs
196 * \ingroup mofem_problems_manager
197 *
198 * \param name problem name
199 */
200 MoFEMErrorCode partitionSimpleProblem(const std::string name,
201 int verb = VERBOSE);
202
203 /** \brief partition problem dofs (collective)
204 * \ingroup mofem_problems_manager
205 *
206 * \param name problem name
207 */
208 MoFEMErrorCode partitionProblem(const std::string name, int verb = VERBOSE);
209
211 int verb = VERBOSE);
212
214 int verb = VERBOSE);
215
216 /** \brief partition finite elements
217 * \ingroup mofem_problems_manager
218 *
219 * Function which partition finite elements based on dofs partitioning.<br>
220 * In addition it sets information about local row and cols dofs at given
221 * element on partition.
222 *
223 * @param name
224 * @param part_from_moab
225 * @param low_proc
226 * @param hi_proc
227 * @param verb
228 * @return MoFEMErrorCode
229 *
230 * \param name problem name
231 */
232 MoFEMErrorCode partitionFiniteElements(const std::string name,
233 bool part_from_moab = false,
234 int low_proc = -1, int hi_proc = -1,
235 int verb = VERBOSE);
236
237 /** \brief determine ghost nodes
238 * \ingroup mofem_problems_manager
239 * \param name problem name
240 *
241 * DOFs are ghost dofs if are used by elements on given partitition, but not
242 * owned by that partitition.
243 *
244 */
245 MoFEMErrorCode partitionGhostDofs(const std::string name, int verb = VERBOSE);
246
247 /** \brief determine ghost nodes on distributed meshes
248 * \ingroup mofem_problems_manager
249 * \param name problem name
250 *
251 * It is very similar for partitionGhostDofs, however this explits that mesh
252 * is
253 * distributed.
254 *
255 * DOFs are ghosted if are shered but not owned by partition.
256 *
257 */
259 int verb = VERBOSE);
260
261 /**
262 * \create add entities of finite element in the problem
263 * \ingroup mofem_problems_manager
264 *
265 * \note Meshset entity has to be crated
266 *
267 */
268
269 /**
270 * @brief create add entities of finite element in the problem
271 *
272 * @note Meshset entity has to be crated
273 *
274 * @param prb_name name of the problem
275 * @param fe_name name of the entity
276 * @param meshset pointer meshset handle
277 * @return MoFEMErrorCode
278 */
279 MoFEMErrorCode getFEMeshset(const std::string prb_name,
280 const std::string fe_name,
281 EntityHandle *meshset) const;
282
283 /**
284 * \brief Get layout of elements in the problem
285 * \ingroup mofem_problems_manager
286 *
287 * In layout is stored information how many elements is on each processor, for
288 * more information look int petsc documentation
289 * <http://www.mcs.anl.gov/petsc/petsc-current/docs/manualpages/IS/PetscLayoutCreate.html#PetscLayoutCreate>
290 *
291 * @param name problem name
292 * @param fe_name finite elements
293 * @param layout layout
294 * @param verb verbosity level
295 * @return error code
296 */
297 MoFEMErrorCode getProblemElementsLayout(const std::string name,
298 const std::string fe_name,
299 PetscLayout *layout) const;
300
301 /**
302 * @brief Remove DOFs from problem
303 * @ingroup mofem_problems_manager
304 *
305 * Remove DOFs from problem which are on entities on the given range and given
306 * field name. On the finite element level, DOFs can be still accessed however
307 * local PETSc indices and global PETSc indices are marked with the index -1.
308 *
309 * @note If the index is marked -1 it is not assembled and dropped by
310 * VecSetValues and MatSetValues.
311 *
312 * @todo Not yet implemented update for AO maps and IS ranges if removed
313 * entities in composite problem or sub-problem
314 *
315 * @param problem_name name of the problem
316 * @param field_name name of the field
317 * @param ents entities on which DOFs are removed
318 * @param lo_coeff low dof coefficient (rank)
319 * @param hi_coeff high dof coefficient (rank)
320 * @param verb verbosity level
321 * @param debug to debug and seek for inconsistencies set to true
322 * @return MoFEMErrorCode
323 */
325 const std::string problem_name, const std::string field_name,
326 const Range ents, const int lo_coeff = 0,
327 const int hi_coeff = MAX_DOFS_ON_ENTITY, const int lo_order = 0,
328 const int hi_order = 100, int verb = VERBOSE, const bool debug = false);
329
330 /**
331 * @copydoc removeDofsOnEntities
332 *
333 * \note Use this function for nondistributed meshes
334 */
336 const std::string problem_name, const std::string field_name,
337 const Range ents, const int lo_coeff = 0,
338 const int hi_coeff = MAX_DOFS_ON_ENTITY, const int lo_order = 0,
339 const int hi_order = 100, int verb = VERBOSE, const bool debug = false);
340
341 /**
342 * @brief Remove DOFs from problem by bit ref level
343 * @ingroup mofem_problems_manager
344 *
345 * See for more detail other implementation for removeDofsOnEntities.
346 *
347 * @param problem_name name of the problem
348 * @param field_name name of the field
349 * @param bit_ref_level bit ref level on which DOFs are removed
350 * @param bit_ref_mask bit ref mask on which DOFs are removed
351 * @param ents_ptr filter entities with given bit and mask
352 * @param lo_coeff low dof coefficient (rank)
353 * @param hi_coeff high dof coefficient (rank)
354 * @param verb verbosity level
355 * @param debug to debug and seek for inconsistencies set to true
356 * @return MoFEMErrorCode
357 */
359 const std::string problem_name, const std::string field_name,
360 const BitRefLevel bit_ref_level, const BitRefLevel bit_ref_mask,
361 Range *ents_ptr = nullptr, const int lo_coeff = 0,
362 const int hi_coeff = MAX_DOFS_ON_ENTITY, const int lo_order = 0,
363 const int hi_order = 100, int verb = VERBOSE, const bool debug = false);
364
365 /**
366 * @copydoc removeDofsOnEntities
367 *
368 * \note Use this function for nondistributed meshes
369 */
371 const std::string problem_name, const std::string field_name,
372 const BitRefLevel bit_ref_level, const BitRefLevel bit_ref_mask,
373 Range *ents_ptr = nullptr, const int lo_coeff = 0,
374 const int hi_coeff = MAX_DOFS_ON_ENTITY, const int lo_order = 0,
375 const int hi_order = 100, int verb = VERBOSE, const bool debug = false);
376
377 enum MarkOP { OR, AND };
378
379 /**
380 * @brief Create vector with marked indices
381 *
382 * Vector with local DOFs marked by entities
383 *
384 *
385 * @param problem_name
386 * @param row
387 * @param ents
388 * @param marker
389 * @return MoFEMErrorCode
390 */
391 MoFEMErrorCode markDofs(const std::string problem_name, RowColData rc,
392 const enum MarkOP op, const Range ents,
393 std::vector<unsigned char> &marker) const;
394
395 /**
396 * @deprecated use function with MarkOP
397 */
399 markDofs(const std::string problem_name, RowColData rc, const Range ents,
400 std::vector<unsigned char> &marker) const {
401 return markDofs(problem_name, rc, MarkOP::OR, ents, marker);
402 }
403
404 /**
405 * @brief Mark DOFs
406 *
407 * @param problem_name
408 * @param rc
409 * @param field_name
410 * @param lo
411 * @param hi
412 * @param op
413 * @param marker
414 * @return MoFEMErrorCode
415 */
416 MoFEMErrorCode modifyMarkDofs(const std::string problem_name, RowColData rc,
417 const std::string field_name, const int lo,
418 const int hi, const enum MarkOP op,
419 const unsigned char c,
420 std::vector<unsigned char> &marker) const;
421
422 /**
423 * @brief add empty block to problem
424 *
425 * MatrixManager assumes that all blocks, i.e. all fields combinations are non
426 * zero. This is not always the case, to optimise code and reduce memory usage
427 * user can specifi which blocks are empty.
428 *
429 * @param problem_name problem name
430 * @param row_field row filed name
431 * @param col_field col field name
432 * @return MoFEMErrorCode
433 */
434 MoFEMErrorCode addFieldToEmptyFieldBlocks(const std::string problem_name,
435 const std::string row_field,
436 const std::string col_field) const;
437
438private:
440};
441} // namespace MoFEM
442
443#endif //__PROBLEMSMANAGER_HPP__
444
445/**
446 * \defgroup mofem_problems_manager ProblemsManager
447 * \brief Adding and managing problems
448 *
449 * \ingroup mofem
450 */
MoFEM interface.
@ VERBOSE
Definition: definitions.h:222
RowColData
RowColData.
Definition: definitions.h:136
#define MAX_DOFS_ON_ENTITY
Maximal number of DOFs on entity.
Definition: definitions.h:249
#define DEPRECATED
Definition: definitions.h:30
static const bool debug
const int dim
MoFEMErrorCode buildProblemOnDistributedMesh(const std::string name, const bool square_matrix, int verb=VERBOSE)
build problem data structures, assuming that mesh is distributed (collective)
MoFEMErrorCode getProblemElementsLayout(const std::string name, const std::string fe_name, PetscLayout *layout) const
Get layout of elements in the problem.
MoFEMErrorCode partitionGhostDofs(const std::string name, int verb=VERBOSE)
determine ghost nodes
MoFEMErrorCode partitionSimpleProblem(const std::string name, int verb=VERBOSE)
partition problem dofs
MoFEMErrorCode buildComposedProblem(const std::string out_name, const std::vector< std::string > add_row_problems, const std::vector< std::string > add_col_problems, const bool square_matrix=true, int verb=1)
build composite problem
MoFEMErrorCode getFEMeshset(const std::string prb_name, const std::string fe_name, EntityHandle *meshset) const
create add entities of finite element in the problem
MoFEMErrorCode buildSubProblem(const std::string out_name, const std::vector< std::string > &fields_row, const std::vector< std::string > &fields_col, const std::string main_problem, const bool square_matrix=true, const map< std::string, std::pair< EntityType, EntityType > > *entityMapRow=nullptr, const map< std::string, std::pair< EntityType, EntityType > > *entityMapCol=nullptr, int verb=VERBOSE)
build sub problem
MoFEMErrorCode buildProblem(const std::string name, const bool square_matrix, int verb=VERBOSE)
build problem data structures
DEPRECATED MoFEMErrorCode partitionMesh(const Range &ents, const int dim, const int adj_dim, const int n_parts, Tag *th_vertex_weights=nullptr, Tag *th_edge_weights=nullptr, Tag *th_part_weights=nullptr, int verb=VERBOSE, const bool debug=false)
Set partition tag to each finite element in the problem.
MoFEMErrorCode partitionProblem(const std::string name, int verb=VERBOSE)
partition problem dofs (collective)
MoFEMErrorCode partitionGhostDofsOnDistributedMesh(const std::string name, int verb=VERBOSE)
determine ghost nodes on distributed meshes
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
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
MoFEMErrorCode removeDofsOnEntities(const std::string problem_name, const std::string field_name, const Range ents, const int lo_coeff=0, const int hi_coeff=MAX_DOFS_ON_ENTITY, const int lo_order=0, const int hi_order=100, int verb=VERBOSE, const bool debug=false)
Remove DOFs from problem.
auto marker
set bit to marker
PetscErrorCode MoFEMErrorCode
MoFEM/PETSc error code.
Definition: Exceptions.hpp:67
std::bitset< BITREFLEVEL_SIZE > BitRefLevel
Bit structure attached to each entity identifying to what mesh entity is attached.
Definition: Types.hpp:51
implementation of Data Operators for Forces and Sources
Definition: Common.hpp:21
constexpr auto field_name
Core (interface) class.
Definition: Core.hpp:92
keeps basic data about problem
Problem manager is used to build and partition problems.
DEPRECATED MoFEMErrorCode markDofs(const std::string problem_name, RowColData rc, const Range ents, std::vector< unsigned char > &marker) const
MoFEMErrorCode markDofs(const std::string problem_name, RowColData rc, const enum MarkOP op, const Range ents, std::vector< unsigned char > &marker) const
Create vector with marked indices.
ProblemsManager(const MoFEM::Core &core)
MoFEMErrorCode printPartitionedProblem(const Problem *problem_ptr, int verb=VERBOSE)
MoFEMErrorCode addFieldToEmptyFieldBlocks(const std::string problem_name, const std::string row_field, const std::string col_field) const
add empty block to problem
MoFEMErrorCode modifyMarkDofs(const std::string problem_name, RowColData rc, const std::string field_name, const int lo, const int hi, const enum MarkOP op, const unsigned char c, std::vector< unsigned char > &marker) const
Mark DOFs.
PetscLogEvent MOFEM_EVENT_ProblemsManager
virtual ~ProblemsManager()=default
PetscBool synchroniseProblemEntities
DOFs in fields, not from DOFs on elements.
MoFEMErrorCode debugPartitionedProblem(const Problem *problem_ptr, int verb=VERBOSE)
MoFEMErrorCode query_interface(boost::typeindex::type_index type_index, UnknownInterface **iface) const
MoFEMErrorCode removeDofsOnEntitiesNotDistributed(const std::string problem_name, const std::string field_name, const Range ents, const int lo_coeff=0, const int hi_coeff=MAX_DOFS_ON_ENTITY, const int lo_order=0, const int hi_order=100, int verb=VERBOSE, const bool debug=false)
Remove DOFs from problem.
MoFEMErrorCode getOptions()
base class for all interface classes