v0.9.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 /*
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 
24 namespace MoFEM {
25 
28 
29 /**
30  * \brief Problem manager is used to build and partition problems
31  * \ingroup mofem_problems_manager
32  *
33  */
35 
37  UnknownInterface **iface) const;
38 
40  ProblemsManager(const MoFEM::Core &core);
41  virtual ~ProblemsManager() = default;
42 
43  PetscBool buildProblemFromFields; ///< If set to true, problem is build from
44  /// DOFs in fields, not from DOFs on elements
45 
47 
49 
50  /**
51  * \brief Set partition tag to each finite element in the problem
52  * \ingroup mofem_problems_manager
53  *
54  * This will use one of the mesh partitioning programs available from PETSc
55  * See
56  * <http://www.mcs.anl.gov/petsc/petsc-current/docs/manualpages/Mat/MatPartitioningType.html>
57  *
58  * @param ents Entities to partition
59  * @param dim Dimension of entities to partition
60  * @param adj_dim Adjacency dimension
61  * @param n_parts Number of partitions
62  * @param verb Verbosity level
63  * @return Error code
64  */
65  MoFEMErrorCode partitionMesh(const Range &ents, const int dim,
66  const int adj_dim, const int n_parts,
67  Tag *th_vertex_weights = nullptr,
68  Tag *th_edge_weights = nullptr,
69  Tag *th_part_weights = nullptr,
70  int verb = VERBOSE, const bool debug = false);
71 
72  /** \brief build problem data structures
73  * \ingroup mofem_problems_manager
74  *
75  * \note If square_matrix is set to true, that indicate that problem is
76  * structurally
77  * symmetric, i.e. rows and columns have the same dofs and are indexed in the
78  * same
79  * way.
80  *
81  * @param name problem name
82  * @param square_matrix structurally symmetric problem
83  * @param verb verbosity level
84  * @return error code
85  *
86  */
87  MoFEMErrorCode buildProblem(const std::string name, const bool square_matrix,
88  int verb = VERBOSE);
89 
90  /** \brief build problem data structures
91  * \ingroup mofem_problems_manager
92  *
93  * \note If square_matrix is set to true, that indicate that problem is
94  * structurally
95  * symmetric, i.e. rows and columns have the same dofs and are indexed in the
96  * same
97  * way.
98  *
99  * @param problem pointer
100  * @param square_matrix structurally symmetric problem
101  * @param verb verbosity level
102  * @return error code
103  *
104  */
105  MoFEMErrorCode buildProblem(Problem *problem_ptr, const bool square_matrix,
106  int verb = VERBOSE);
107 
108  /** \brief build problem data structures, assuming that mesh is distributed
109  (collective)
110  * \ingroup mofem_problems_manager
111 
112  Mesh is distributed, that means that each processor keeps only own part of
113  the mesh and shared entities.
114 
115  Collective - need to be run on all processors in communicator, i.e. each
116  function has to call this function.
117 
118  */
119  MoFEMErrorCode buildProblemOnDistributedMesh(const std::string name,
120  const bool square_matrix,
121  int verb = VERBOSE);
122 
123  /** \brief build problem data structures, assuming that mesh is distributed
124  (collective)
125  * \ingroup mofem_problems_manager
126 
127  Mesh is distributed, that means that each processor keeps only own part of
128  the mesh and shared entities.
129 
130  Collective - need to be run on all processors in communicator, i.e. each
131  function has to call this function.
132 
133  */
135  const bool square_matrix = true,
136  int verb = VERBOSE);
137 
138  /**
139  * \brief build sub problem
140  * \ingroup mofem_problems_manager
141  *
142  * @param out_name problem
143  * @param fields_row vector of fields composing problem
144  * @param fields_col vector of fields composing problem
145  * @param main_problem main problem
146  * @return error code
147  */
149  const std::string out_name, const std::vector<std::string> &fields_row,
150  const std::vector<std::string> &fields_col,
151  const std::string main_problem, const bool square_matrix = true,
152  const map<std::string, std::pair<EntityType, EntityType>> *entityMapRow =
153  nullptr,
154  const map<std::string, std::pair<EntityType, EntityType>> *entityMapCol =
155  nullptr,
156  int verb = VERBOSE);
157 
158  /**
159  * \brief build composite problem
160  * \ingroup mofem_problems_manager
161  *
162  * @param out_name name of build problem
163  * @param add_row_problems vector of add row problems
164  * @param add_col_problems vector of add col problems
165  * @param square_matrix true if structurally squared matrix
166  * @param verb verbosity level
167  * @return error code
168  */
170  buildCompsedProblem(const std::string out_name,
171  const std::vector<std::string> add_row_problems,
172  const std::vector<std::string> add_col_problems,
173  const bool square_matrix = true, int verb = 1);
174 
175  /**
176  * \brief build indexing and partition problem inheriting indexing and
177  * partitioning from two other problems
178  * \ingroup mofem_problems_manager
179  *
180  * \param name problem name
181  * \param problem_for_rows problem used to index rows
182  * \param copy_rows just copy rows dofs
183  * \param problem_for_cols problem used to index cols
184  * \param copy_cols just copy cols dofs
185  *
186  * If copy_rows/copy_cols is set to false only partition is copied between
187  * problems.
188  *
189  */
190  MoFEMErrorCode inheritPartition(const std::string name,
191  const std::string problem_for_rows,
192  bool copy_rows,
193  const std::string problem_for_cols,
194  bool copy_cols, int verb = VERBOSE);
195 
196  /** \brief partition problem dofs
197  * \ingroup mofem_problems_manager
198  *
199  * \param name problem name
200  */
201  MoFEMErrorCode partitionSimpleProblem(const std::string name,
202  int verb = VERBOSE);
203 
204  /** \brief partition problem dofs (collective)
205  * \ingroup mofem_problems_manager
206  *
207  * \param name problem name
208  */
209  MoFEMErrorCode partitionProblem(const std::string name, int verb = VERBOSE);
210 
212  int verb = VERBOSE);
213 
215  int verb = VERBOSE);
216 
217  /** \brief partition finite elements
218  * \ingroup mofem_problems_manager
219  *
220  * Function which partition finite elements based on dofs partitioning.<br>
221  * In addition it sets information about local row and cols dofs at given
222  * element on partition.
223  *
224  * \param name problem name
225  */
226  MoFEMErrorCode partitionFiniteElements(const std::string name,
227  bool part_from_moab = false,
228  int low_proc = -1, int hi_proc = -1,
229  int verb = VERBOSE);
230 
231  /** \brief determine ghost nodes
232  * \ingroup mofem_problems_manager
233  * \param name problem name
234  *
235  * DOFs are ghost dofs if are used by elements on given partitition, but not
236  * owned by that partitition.
237  *
238  */
239  MoFEMErrorCode partitionGhostDofs(const std::string name, int verb = VERBOSE);
240 
241  /** \brief determine ghost nodes on distributed meshes
242  * \ingroup mofem_problems_manager
243  * \param name problem name
244  *
245  * It is very similar for partitionGhostDofs, however this explits that mesh
246  * is
247  * distributed.
248  *
249  * DOFs are ghosted if are shered but not owned by partition.
250  *
251  */
253  int verb = VERBOSE);
254 
255  /**
256  * \create add entities of finite element in the problem
257  * \ingroup mofem_problems_manager
258  *
259  * \note Meshset entity has to be crated
260  *
261  */
262 
263  /**
264  * @brief create add entities of finite element in the problem
265  *
266  * @note Meshset entity has to be crated
267  *
268  * @param prb_name name of the problem
269  * @param fe_name name of the entity
270  * @param meshset pointer meshset handle
271  * @return MoFEMErrorCode
272  */
273  MoFEMErrorCode getFEMeshset(const std::string prb_name,
274  const std::string fe_name,
275  EntityHandle *meshset) const;
276 
277  /**
278  * \brief Get layout of elements in the problem
279  * \ingroup mofem_problems_manager
280  *
281  * In layout is stored information how many elements is on each processor, for
282  * more information look int petsc documentation
283  * <http://www.mcs.anl.gov/petsc/petsc-current/docs/manualpages/IS/PetscLayoutCreate.html#PetscLayoutCreate>
284  *
285  * @param name problem name
286  * @param fe_name finite elements
287  * @param layout layout
288  * @param verb verbosity level
289  * @return error code
290  */
291  MoFEMErrorCode getProblemElementsLayout(const std::string name,
292  const std::string fe_name,
293  PetscLayout *layout) const;
294 
295  /**
296  * @brief Remove DOFs from problem
297  * @ingroup mofem_problems_manager
298  *
299  * Remove DOFs from problem which are on entities on the given range and given
300  * field name. On the finite element level, DOFs can be still accessed however
301  * local PETSc indices and global PETSc indices are marked with the index -1.
302  *
303  * @note If the index is marked -1 it is not assembled and dropped by
304  * VecSetValues and MatSetValues.
305  *
306  * @todo Not yet implemented update for AO maps and IS ranges if removed
307  * entities in composite problem or sub-problem
308  *
309  * @param problem_name name of the problem
310  * @param field_name name of the field
311  * @param ents entities on which DOFs are removed
312  * @param lo_coeff low dof coefficient (rank)
313  * @param hi_coeff high dof coefficient (rank)
314  * @param verb verbosity level
315  * @param debug to debug and seek for inconsistencies set to true
316  * @return MoFEMErrorCode
317  */
318  MoFEMErrorCode removeDofsOnEntities(const std::string problem_name,
319  const std::string field_name,
320  const Range ents, const int lo_coeff = 0,
321  const int hi_coeff = MAX_DOFS_ON_ENTITY,
322  int verb = VERBOSE,
323  const bool debug = false);
324 
325  /**
326  * @brief Create vector with marked indices
327  *
328  * Vector with local DOFs marked by entities
329  *
330  *
331  * @param problem_name
332  * @param row
333  * @param ents
334  * @param marker
335  * @return MoFEMErrorCode
336  */
337  MoFEMErrorCode markDofs(const std::string problem_name, RowColData rc,
338  const Range ents, std::vector<bool> &marker);
339 
340 private:
342 };
343 } // namespace MoFEM
344 
345 #endif //__PROBLEMSMANAGER_HPP__
346 
347 /**
348  * \defgroup mofem_problems_manager ProblemsManager
349  * \brief Adding and managing problems
350  *
351  * \ingroup mofem
352  */
MoFEM interface unique ID.
Problem manager is used to build and partition problems.
static const MOFEMuuid IDD_MOFEMProblemsManager
PetscLogEvent MOFEM_EVENT_ProblemsManager
MoFEMErrorCode partitionProblem(const std::string name, int verb=VERBOSE)
partition problem dofs (collective)
MoFEMErrorCode buildCompsedProblem(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 buildProblem(const std::string name, const bool square_matrix, int verb=VERBOSE)
build problem data structures
base class for all interface classes
MoFEMErrorCode debugPartitionedProblem(const Problem *problem_ptr, int verb=VERBOSE)
Core (interface) class.
Definition: Core.hpp:50
MoFEM interface.
keeps basic data about problemThis is low level structure with information about problem,...
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, int verb=VERBOSE, const bool debug=false)
Remove DOFs from problemRemove DOFs from problem which are on entities on the given range and given f...
RowColData
RowColData.
Definition: definitions.h:190
std::bitset< BITINTERFACEUID_SIZE > BitIntefaceId
Definition: Types.hpp:56
implementation of Data Operators for Forces and Sources
Definition: Common.hpp:21
MoFEMErrorCode printPartitionedProblem(const Problem *problem_ptr, int verb=VERBOSE)
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 problemThis will use one of the mesh partitioning pro...
MoFEMErrorCode getProblemElementsLayout(const std::string name, const std::string fe_name, PetscLayout *layout) const
Get layout of elements in the problemIn layout is stored information how many elements is on each pro...
MoFEMErrorCode partitionGhostDofsOnDistributedMesh(const std::string name, int verb=VERBOSE)
determine ghost nodes on distributed meshes
ProblemsManager(const MoFEM::Core &core)
MoFEMErrorCode query_interface(const MOFEMuuid &uuid, UnknownInterface **iface) const
PetscErrorCode MoFEMErrorCode
MoFEM/PETSc error code.
Definition: Exceptions.hpp:66
static const bool debug
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
PetscBool synchroniseProblemEntities
DOFs in fields, not from DOFs on elements.
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 partitionGhostDofs(const std::string name, int verb=VERBOSE)
determine ghost nodes
MoFEMErrorCode buildProblemOnDistributedMesh(const std::string name, const bool square_matrix, int verb=VERBOSE)
build problem data structures, assuming that mesh is distributed (collective)Mesh is distributed,...
#define MAX_DOFS_ON_ENTITY
Maximal number of DOFs on entity.
Definition: definitions.h:302
MoFEMErrorCode partitionFiniteElements(const std::string name, bool part_from_moab=false, int low_proc=-1, int hi_proc=-1, int verb=VERBOSE)
partition finite elementsFunction which partition finite elements based on dofs partitioning....
MoFEMErrorCode getOptions()
MoFEMErrorCode markDofs(const std::string problem_name, RowColData rc, const Range ents, std::vector< bool > &marker)
Create vector with marked indices.
virtual ~ProblemsManager()=default
MoFEMErrorCode partitionSimpleProblem(const std::string name, int verb=VERBOSE)
partition problem dofs
MoFEMErrorCode getFEMeshset(const std::string prb_name, const std::string fe_name, EntityHandle *meshset) const
create add entities of finite element in the problem