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