v0.15.0
Loading...
Searching...
No Matches
ProblemsManager.hpp
Go to the documentation of this file.
1/** \file ProblemsManager.hpp
2 * \brief Interface for building, partitioning, and managing finite element problems
3 * \ingroup mofem_problems_manager
4 *
5 * The ProblemsManager provides comprehensive functionality for creating and managing
6 * finite element problems within the MoFEM framework. It serves as the bridge between
7 * the Core interface (fields, DOFs, finite elements) and PETSc's parallel computing
8 * infrastructure (Discrete Manager - DM).
9 *
10 * Key capabilities include:
11 * - Building problems from fields and finite elements
12 * - Partitioning for parallel computation (distributed and non-distributed meshes)
13 * - Managing sub-problems and composite multi-physics problems
14 * - Handling broken DOFs for discontinuous finite element spaces
15 * - DOF removal for boundary conditions and model reduction
16 * - Integration with PETSc DM for parallel matrix/vector operations
17 *
18 */
19
20#ifndef __PROBLEMSMANAGER_HPP__
21#define __PROBLEMSMANAGER_HPP__
22
23#include "UnknownInterface.hpp"
24
25namespace MoFEM {
26
27/**
28 * \brief Problem manager is used to build and partition problems
29 * \ingroup mofem_problems_manager
30 *
31 * \section pm_overview Overview
32 *
33 * The ProblemsManager serves as the central interface for creating, configuring,
34 * and managing finite element problems within the MoFEM framework. It acts as a
35 * bridge between the Core interface (which manages the fundamental MoFEM data
36 * structures like fields, finite elements, and DOFs) and the PETSc Discrete
37 * Manager (DM) system for parallel computing.
38 *
39 * \section pm_core_connection Connection to Core Interface
40 *
41 * The ProblemsManager operates on top of the MoFEM::Core interface:
42 * - **Fields and DOFs**: Uses fields and DOFs defined in Core to construct problems
43 * - **Finite Elements**: Manages finite elements from Core's registry
44 * - **Problem Objects**: Creates Problem instances that aggregate Core's components
45 * - **Data Consistency**: Ensures DOF numbering and field associations remain consistent
46 *
47 * \section pm_dm_integration Integration with PETSc Discrete Manager (DM)
48 *
49 * The ProblemsManager creates and configures PETSc DM objects:
50 * - **Matrix/Vector Layout**: Defines parallel distribution of DOFs for PETSc matrices/vectors
51 * - **Ghost DOFs**: Manages inter-processor DOF dependencies for parallel assembly
52 * - **Partitioning**: Distributes computational load across MPI processes
53 * - **Local/Global Mappings**: Establishes DOF index mappings between local and global numbering
54 *
55 * \section pm_mesh_types Distributed vs Non-Distributed Meshes
56 *
57 * \subsection pm_nondist Non-Distributed Meshes
58 * - **Single Process Ownership**: Each mesh entity owned by exactly one processor
59 * - **Sequential Building**: Problem built on rank 0, then partitioned
60 * - **Simple Partitioning**: Uses METIS/ParMETIS for load balancing
61 * - **Ghost Creation**: Explicit ghost DOF creation after partitioning
62 * - **Use Case**: Traditional finite element problems with post-partitioning
63 *
64 * \subsection pm_dist Distributed Meshes
65 * - **MOAB Integration**: Leverages MOAB's parallel mesh capabilities
66 * - **Pre-Partitioned**: Mesh already distributed during loading
67 * - **Shared Entities**: Mesh entities can be shared between processors
68 * - **Automatic Ghosts**: Ghost DOFs determined from mesh sharing information
69 * - **Use Case**: Large-scale problems requiring parallel mesh I/O
70 *
71 * \section pm_problem_types Problem Types
72 *
73 * \subsection pm_subproblems Sub-Problems
74 * - **Focused Analysis**: Extract subset of DOFs/elements for specialized computation
75 * - **Field Restriction**: Include only specific fields or DOF ranges
76 * - **Boundary Conditions**: Apply specialized constraints to problem subset
77 * - **Solver Optimization**: Use targeted solvers for specific physics
78 * - **Example**: Solve only displacement DOFs while keeping pressure DOFs fixed
79 *
80 * \subsection pm_composite Composite Problems
81 * - **Block Structure**: Combine multiple sub-problems into unified matrix system
82 * - **Multi-Physics**: Couple different physical phenomena (fluid-structure, etc.)
83 * - **Block Matrices**: Create structured matrix layouts for specialized solvers
84 * - **Field Coupling**: Define interactions between different field types
85 * - **Example**: Stokes flow with displacement-pressure-velocity blocks
86 *
87 * \section pm_broken_dofs Broken DOFs (Discontinuous Spaces)
88 *
89 * Broken DOFs support discontinuous finite element spaces:
90 * - **Element-Wise DOFs**: DOFs belong to elements rather than mesh entities
91 * - **Interface Handling**: Special treatment for inter-element connections
92 * - **Discontinuous Galerkin**: Support for DG methods with interface terms
93 * - **Side DOFs**: DOFs associated with element faces for flux calculations
94 * - **Broken Space Functions**: `getSideDofsOnBrokenSpaceEntities()` manages interface DOFs
95 *
96 * \section pm_dof_removal DOF Removal Operations
97 *
98 * DOF removal serves multiple purposes:
99 *
100 * \subsection pm_boundary_conditions Boundary Condition Enforcement
101 * - **Dirichlet Constraints**: Remove DOFs with prescribed values
102 * - **Symmetry Conditions**: Eliminate DOFs with geometric constraints
103 * - **Contact Constraints**: Remove DOFs involved in contact conditions
104 *
105 * \subsection pm_model_reduction Model Reduction
106 * - **Inactive Regions**: Remove DOFs in non-participating mesh regions
107 * - **Dimensional Reduction**: Eliminate DOFs for plane stress/strain assumptions
108 * - **Adaptive Refinement**: Remove DOFs from coarsened elements
109 *
110 * \subsection pm_numerical_efficiency Numerical Efficiency
111 * - **Zero DOFs**: Remove DOFs that remain zero throughout simulation
112 * - **Singular Systems**: Eliminate redundant DOFs to improve conditioning
113 * - **Memory Optimization**: Reduce matrix storage requirements
114 *
115 * The removal process:
116 * 1. **Identification**: Mark DOFs for removal based on criteria
117 * 2. **Dependency Check**: Verify no essential DOFs depend on removed ones
118 * 3. **Index Renumbering**: Compact DOF indices to eliminate gaps
119 * 4. **Matrix/Vector Update**: Adjust PETSc data structures accordingly
120 * 5. **Solver Configuration**: Update preconditioners and solver contexts
121 *
122 * \section pm_workflow Typical Workflow
123 *
124 * 1. **Problem Definition**: Define fields, finite elements, and DOFs via Core
125 * 2. **Problem Building**: Use `buildProblem*()` to create Problem object
126 * 3. **Partitioning**: Apply `partition*()` functions for parallel distribution
127 * 4. **Ghost Setup**: Configure ghost DOFs for parallel assembly
128 * 5. **Constraint Application**: Remove DOFs for boundary conditions
129 * 6. **DM Creation**: Generate PETSc DM for solver integration
130 * 7. **Matrix Assembly**: Use Problem for parallel finite element assembly
131 *
132 */
134
135 MoFEMErrorCode query_interface(boost::typeindex::type_index type_index,
136 UnknownInterface **iface) const;
137
139 ProblemsManager(const MoFEM::Core &core);
140 virtual ~ProblemsManager() = default;
141
142 PetscBool buildProblemFromFields; ///< If set to true, problem is build from
143 /// DOFs in fields, not from DOFs on elements
144
146
147 /**
148 * \brief Get command line options for ProblemsManager
149 * \ingroup mofem_problems_manager
150 *
151 * Retrieves configuration options from command line arguments that control
152 * problem building behavior, such as buildProblemFromFields and
153 * synchroniseProblemEntities flags.
154 *
155 * @return MoFEMErrorCode Error code indicating success or failure
156 */
158
159 /**
160 * \brief Set partition tag to each finite element in the problem
161 * \deprecated Use CommInterface
162 * \ingroup mofem_problems_manager
163 *
164 * This will use one of the mesh partitioning programs available from PETSc
165 * See
166 * <http://www.mcs.anl.gov/petsc/petsc-current/docs/manualpages/Mat/MatPartitioningType.html>
167 *
168 * @param ents Entities to partition
169 * @param dim Dimension of entities to partition
170 * @param adj_dim Adjacency dimension
171 * @param n_parts Number of partitions
172 * @param verb Verbosity level
173 * @return Error code
174 */
175 DEPRECATED MoFEMErrorCode partitionMesh(const Range &ents, const int dim,
176 const int adj_dim, const int n_parts,
177 Tag *th_vertex_weights = nullptr,
178 Tag *th_edge_weights = nullptr,
179 Tag *th_part_weights = nullptr,
180 int verb = VERBOSE,
181 const bool debug = false);
182
183 /** \brief build problem data structures
184 * \ingroup mofem_problems_manager
185 *
186 * \note If square_matrix is set to true, that indicate that problem is
187 * structurally
188 * symmetric, i.e. rows and columns have the same dofs and are indexed in the
189 * same
190 * way.
191 *
192 * @param name problem name
193 * @param square_matrix structurally symmetric problem
194 * @param verb verbosity level
195 * @return error code
196 *
197 */
198 MoFEMErrorCode buildProblem(const std::string name, const bool square_matrix,
199 int verb = VERBOSE);
200
201 /** \brief build problem data structures
202 * \ingroup mofem_problems_manager
203 *
204 * \note If square_matrix is set to true, that indicate that problem is
205 * structurally
206 * symmetric, i.e. rows and columns have the same dofs and are indexed in the
207 * same
208 * way.
209 *
210 * @param problem pointer
211 * @param square_matrix structurally symmetric problem
212 * @param verb verbosity level
213 * @return error code
214 *
215 */
216 MoFEMErrorCode buildProblem(Problem *problem_ptr, const bool square_matrix,
217 int verb = VERBOSE);
218
219 /** \brief build problem data structures, assuming that mesh is distributed (collective)
220 * \ingroup mofem_problems_manager
221 *
222 * Mesh is distributed, that means that each processor keeps only own part of
223 * the mesh and shared entities.
224 *
225 * Collective - need to be run on all processors in communicator, i.e. each
226 * function has to call this function.
227 *
228 * @param name problem name to build
229 * @param square_matrix true if problem has structurally symmetric matrix
230 * @param verb verbosity level
231 * @return MoFEMErrorCode Error code indicating success or failure
232 */
233 MoFEMErrorCode buildProblemOnDistributedMesh(const std::string name,
234 const bool square_matrix,
235 int verb = VERBOSE);
236
237 /** \brief build problem data structures, assuming that mesh is distributed (collective)
238 * \ingroup mofem_problems_manager
239 *
240 * Mesh is distributed, that means that each processor keeps only own part of
241 * the mesh and shared entities.
242 *
243 * Collective - need to be run on all processors in communicator, i.e. each
244 * function has to call this function.
245 *
246 * @param problem_ptr pointer to problem structure
247 * @param square_matrix true if problem has structurally symmetric matrix
248 * @param verb verbosity level
249 * @return MoFEMErrorCode Error code indicating success or failure
250 */
252 const bool square_matrix = true,
253 int verb = VERBOSE);
254
255 /**
256 * \brief build sub problem
257 * \ingroup mofem_problems_manager
258 *
259 * Creates a sub-problem from a main problem by selecting specific fields
260 * for rows and columns. This is useful for creating focused problems that
261 * operate on subsets of the full problem's fields.
262 *
263 * @param out_name name of the output sub-problem to create
264 * @param fields_row vector of field names for problem rows
265 * @param fields_col vector of field names for problem columns
266 * @param main_problem name of the main problem to extract from
267 * @param square_matrix true if the sub-problem matrix is structurally symmetric
268 * @param entityMapRow optional map restricting row fields to specific entities
269 * @param entityMapCol optional map restricting column fields to specific entities
270 * @param verb verbosity level
271 * @return MoFEMErrorCode Error code indicating success or failure
272 */
274 const std::string out_name, const std::vector<std::string> &fields_row,
275 const std::vector<std::string> &fields_col,
276 const std::string main_problem, const bool square_matrix = true,
277 const map<std::string, boost::shared_ptr<Range>> *entityMapRow = nullptr,
278 const map<std::string, boost::shared_ptr<Range>> *entityMapCol = nullptr,
279 int verb = VERBOSE);
280
281 /**
282 * \brief build composite problem
283 * \ingroup mofem_problems_manager
284 *
285 * Creates a composite problem by combining multiple existing problems.
286 * The resulting problem contains DOFs from all constituent problems,
287 * arranged in block matrix structure.
288 *
289 * @param out_name name of the composite problem to create
290 * @param add_row_problems vector of problem names contributing to rows
291 * @param add_col_problems vector of problem names contributing to columns
292 * @param square_matrix true if the composite matrix is structurally symmetric
293 * @param verb verbosity level
294 * @return MoFEMErrorCode Error code indicating success or failure
295 */
297 buildComposedProblem(const std::string out_name,
298 const std::vector<std::string> add_row_problems,
299 const std::vector<std::string> add_col_problems,
300 const bool square_matrix = true, int verb = 1);
301
302 /**
303 * \brief build indexing and partition problem inheriting indexing and
304 * partitioning from two other problems
305 * \ingroup mofem_problems_manager
306 *
307 * Transfers DOF indexing and partitioning information from existing problems
308 * to a new problem. This is useful for maintaining consistent partitioning
309 * across related problems in multi-physics simulations.
310 *
311 * @param name name of the target problem to inherit partitioning
312 * @param problem_for_rows source problem for row DOF indexing and partitioning
313 * @param copy_rows if true, copy row DOF indices; if false, only copy partition info
314 * @param problem_for_cols source problem for column DOF indexing and partitioning
315 * @param copy_cols if true, copy column DOF indices; if false, only copy partition info
316 * @param verb verbosity level
317 * @return MoFEMErrorCode Error code indicating success or failure
318 *
319 * If copy_rows/copy_cols is set to false only partition is copied between
320 * problems.
321 */
322 MoFEMErrorCode inheritPartition(const std::string name,
323 const std::string problem_for_rows,
324 bool copy_rows,
325 const std::string problem_for_cols,
326 bool copy_cols, int verb = VERBOSE);
327
328 /** \brief partition problem dofs
329 * \ingroup mofem_problems_manager
330 *
331 * Partitions DOFs for sequential/simple problems where the mesh is not
332 * distributed across processors. Creates local DOF numbering and assigns
333 * ownership to processors.
334 *
335 * @param name problem name to partition
336 * @param verb verbosity level
337 * @return MoFEMErrorCode Error code indicating success or failure
338 */
339 MoFEMErrorCode partitionSimpleProblem(const std::string name,
340 int verb = VERBOSE);
341
342 /** \brief partition problem dofs (collective)
343 * \ingroup mofem_problems_manager
344 *
345 * Partitions DOFs for distributed problems where the mesh is already
346 * distributed across processors. Must be called collectively on all
347 * processors in the communicator.
348 *
349 * @param name problem name to partition
350 * @param verb verbosity level
351 * @return MoFEMErrorCode Error code indicating success or failure
352 */
353 MoFEMErrorCode partitionProblem(const std::string name, int verb = VERBOSE);
354
355 /**
356 * \brief Print partition information for debugging
357 * \ingroup mofem_problems_manager
358 *
359 * Outputs detailed information about how DOFs and finite elements are
360 * distributed across processors for the given problem.
361 *
362 * @param problem_ptr pointer to the problem structure
363 * @param verb verbosity level
364 * @return MoFEMErrorCode Error code indicating success or failure
365 */
367 int verb = VERBOSE);
368
369 /**
370 * \brief Debug partition information
371 * \ingroup mofem_problems_manager
372 *
373 * Performs detailed analysis and validation of problem partitioning,
374 * checking for inconsistencies and reporting partition quality metrics.
375 *
376 * @param problem_ptr pointer to the problem structure
377 * @param verb verbosity level
378 * @return MoFEMErrorCode Error code indicating success or failure
379 */
381 int verb = VERBOSE);
382
383 /** \brief partition finite elements
384 * \ingroup mofem_problems_manager
385 *
386 * Function which partition finite elements based on dofs partitioning.
387 * In addition it sets information about local row and cols dofs at given
388 * element on partition. Can optionally use MOAB's partitioning information
389 * or restrict partitioning to specific processor ranges.
390 *
391 * @param name problem name to partition finite elements for
392 * @param part_from_moab if true, use MOAB's existing partition information
393 * @param low_proc lowest processor rank to include (-1 for all)
394 * @param hi_proc highest processor rank to include (-1 for all)
395 * @param verb verbosity level
396 * @return MoFEMErrorCode Error code indicating success or failure
397 */
398 MoFEMErrorCode partitionFiniteElements(const std::string name,
399 bool part_from_moab = false,
400 int low_proc = -1, int hi_proc = -1,
401 int verb = VERBOSE);
402
403 /** \brief determine ghost nodes
404 * \ingroup mofem_problems_manager
405 *
406 * Identifies and marks DOFs as ghost DOFs for parallel computations.
407 * DOFs are ghost dofs if they are used by elements on a given partition
408 * but not owned by that partition.
409 *
410 * @param name problem name to determine ghost DOFs for
411 * @param verb verbosity level
412 * @return MoFEMErrorCode Error code indicating success or failure
413 */
414 MoFEMErrorCode partitionGhostDofs(const std::string name, int verb = VERBOSE);
415
416 /** \brief determine ghost nodes on distributed meshes
417 * \ingroup mofem_problems_manager
418 *
419 * Identifies and marks DOFs as ghost DOFs specifically for distributed meshes.
420 * This function is similar to partitionGhostDofs but exploits the fact that
421 * the mesh is distributed across processors. DOFs are ghosted if they are
422 * shared but not owned by the current partition.
423 *
424 * @param name problem name to determine ghost DOFs for
425 * @param verb verbosity level
426 * @return MoFEMErrorCode Error code indicating success or failure
427 */
429 int verb = VERBOSE);
430
431 /**
432 * @brief Create finite element meshset for the problem
433 * \ingroup mofem_problems_manager
434 *
435 * Creates or retrieves the meshset entity that contains all finite elements
436 * of a specific type within a problem. The meshset entity must be created
437 * before calling this function.
438 *
439 * @param prb_name name of the problem
440 * @param fe_name name of the finite element type
441 * @param meshset pointer to store the meshset handle
442 * @return MoFEMErrorCode Error code indicating success or failure
443 */
444 MoFEMErrorCode getFEMeshset(const std::string prb_name,
445 const std::string &fe_name,
446 EntityHandle *meshset) const;
447
448 /**
449 * \brief Get layout of elements in the problem
450 * \ingroup mofem_problems_manager
451 *
452 * In layout is stored information how many elements is on each processor, for
453 * more information look int petsc documentation
454 * <http://www.mcs.anl.gov/petsc/petsc-current/docs/manualpages/IS/PetscLayoutCreate.html#PetscLayoutCreate>
455 *
456 * @param name problem name
457 * @param fe_name finite elements
458 * @param layout layout
459 * @param verb verbosity level
460 * @return error code
461 */
462 MoFEMErrorCode getProblemElementsLayout(const std::string name,
463 const std::string &fe_name,
464 PetscLayout *layout) const;
465
466 /**
467 * @brief Remove DOFs from problem
468 * @ingroup mofem_problems_manager
469 *
470 * Remove DOFs from problem which are on entities on the given range and given
471 * field name. On the finite element level, DOFs can be still accessed however
472 * local PETSc indices and global PETSc indices are marked with the index -1.
473 *
474 * @note If the index is marked -1 it is not assembled and dropped by
475 * VecSetValues and MatSetValues.
476 *
477 * @todo Not yet implemented update for AO maps and IS ranges if removed
478 * entities in composite problem or sub-problem
479 *
480 * @param problem_name name of the problem
481 * @param field_name name of the field
482 * @param ents entities on which DOFs are removed
483 * @param lo_coeff low dof coefficient (rank)
484 * @param hi_coeff high dof coefficient (rank)
485 * @param verb verbosity level
486 * @param debug to debug and seek for inconsistencies set to true
487 * @return MoFEMErrorCode
488 */
490 const std::string problem_name, const std::string field_name,
491 const Range ents, const int lo_coeff = 0,
492 const int hi_coeff = MAX_DOFS_ON_ENTITY, const int lo_order = 0,
493 const int hi_order = 100, int verb = VERBOSE, const bool debug = false);
494
495 /**
496 * @copydoc removeDofsOnEntities
497 *
498 * \note Use this function for non-distributed meshes
499 */
501 const std::string problem_name, const std::string field_name,
502 const Range ents, const int lo_coeff = 0,
503 const int hi_coeff = MAX_DOFS_ON_ENTITY, const int lo_order = 0,
504 const int hi_order = 100, int verb = VERBOSE, const bool debug = false);
505
506 /**
507 * @brief Remove DOFs from problem by bit ref level
508 * @ingroup mofem_problems_manager
509 *
510 * See for more detail other implementation for removeDofsOnEntities.
511 *
512 * @param problem_name name of the problem
513 * @param field_name name of the field
514 * @param bit_ref_level bit ref level on which DOFs are removed
515 * @param bit_ref_mask bit ref mask on which DOFs are removed
516 * @param ents_ptr filter entities with given bit and mask
517 * @param lo_coeff low dof coefficient (rank)
518 * @param hi_coeff high dof coefficient (rank)
519 * @param verb verbosity level
520 * @param debug to debug and seek for inconsistencies set to true
521 * @return MoFEMErrorCode
522 */
524 const std::string problem_name, const std::string field_name,
525 const BitRefLevel bit_ref_level, const BitRefLevel bit_ref_mask,
526 Range *ents_ptr = nullptr, const int lo_coeff = 0,
527 const int hi_coeff = MAX_DOFS_ON_ENTITY, const int lo_order = 0,
528 const int hi_order = 100, int verb = VERBOSE, const bool debug = false);
529
530 /**
531 * @copydoc removeDofsOnEntities
532 *
533 * \note Use this function for non distributed meshes
534 */
536 const std::string problem_name, const std::string field_name,
537 const BitRefLevel bit_ref_level, const BitRefLevel bit_ref_mask,
538 Range *ents_ptr = nullptr, const int lo_coeff = 0,
539 const int hi_coeff = MAX_DOFS_ON_ENTITY, const int lo_order = 0,
540 const int hi_order = 100, int verb = VERBOSE, const bool debug = false);
541
542
543 /**
544 * @brief Remove DOFs from problem on broken space
545 * \ingroup mofem_problems_manager
546 *
547 * Removes specified DOFs from the problem for broken (discontinuous) spaces.
548 * The DOFs are marked as inactive by setting their indices to -1, which
549 * causes them to be skipped during assembly operations.
550 *
551 * @param problem_name name of the problem
552 * @param rc row or column data specification
553 * @param vec_dof_view vector of DOF entities to remove
554 * @param verb verbosity level
555 * @param debug enable debug output for inconsistency checking
556 * @return MoFEMErrorCode Error code indicating success or failure
557 */
559 removeDofs(const std::string problem_name, RowColData rc,
560 std::vector<boost::weak_ptr<NumeredDofEntity>> &vec_dof_view,
561 int verb = VERBOSE, const bool debug = false);
562
563 /**
564 * @brief Get DOFs on side entities for broken space
565 * \ingroup mofem_problems_manager
566 *
567 * Retrieves DOFs associated with side entities in broken (discontinuous) spaces.
568 * The DOFs are connected through a bridge entity of specified dimension.
569 * This is useful for implementing interface conditions in discontinuous Galerkin methods.
570 *
571 * @param vec_dof_view output vector to store the DOF entities
572 * @param problem_name name of the problem
573 * @param rc row or column data specification
574 * @param field_name name of the field
575 * @param ents range of side entities to process
576 * @param bridge_dim dimension of bridge entity connecting DOFs to side entities
577 * @param lo_coeff lowest coefficient (rank) to include
578 * @param hi_coeff highest coefficient (rank) to include
579 * @param lo_order lowest polynomial order to include
580 * @param hi_order highest polynomial order to include
581 * @param verb verbosity level
582 * @param debug enable debug output for inconsistency checking
583 * @return MoFEMErrorCode Error code indicating success or failure
584 */
586
587 std::vector<boost::weak_ptr<NumeredDofEntity>> &vec_dof_view,
588
589 const std::string problem_name, RowColData rc,
590 const std::string field_name, const Range ents, int bridge_dim,
591 const int lo_coeff = 0, const int hi_coeff = MAX_DOFS_ON_ENTITY,
592 const int lo_order = 0, const int hi_order = 100, int verb = VERBOSE,
593 const bool debug = false
594
595 ) const;
596
597
598 enum MarkOP { OR, AND };
599
600 /**
601 * @brief Create vector with marked indices
602 *
603 * Vector with local DOFs marked by entities
604 *
605 *
606 * @param problem_name
607 * @param row
608 * @param ents
609 * @param marker
610 * @return MoFEMErrorCode
611 */
612 MoFEMErrorCode markDofs(const std::string problem_name, RowColData rc,
613 const enum MarkOP op, const Range ents,
614 std::vector<unsigned char> &marker) const;
615
616 /**
617 * @deprecated use function with MarkOP
618 */
620 markDofs(const std::string problem_name, RowColData rc, const Range ents,
621 std::vector<unsigned char> &marker) const {
622 return markDofs(problem_name, rc, MarkOP::OR, ents, marker);
623 }
624
625 /**
626 * @brief Modify DOF markers for specific field and coefficient range
627 * \ingroup mofem_problems_manager
628 *
629 * Modifies the marker flags for DOFs associated with a specific field within
630 * a defined coefficient range. This allows selective marking/unmarking of DOFs
631 * based on field and polynomial order criteria using bitwise operations.
632 *
633 * @param problem_name name of the problem
634 * @param rc row or column data specification
635 * @param field_name name of the field to process
636 * @param lo lowest coefficient (rank) to include
637 * @param hi highest coefficient (rank) to include
638 * @param op marking operation (OR, AND, XOR) to apply
639 * @param c marker value to apply with the operation
640 * @param marker reference to marker vector to modify
641 * @return MoFEMErrorCode Error code indicating success or failure
642 */
643 MoFEMErrorCode modifyMarkDofs(const std::string problem_name, RowColData rc,
644 const std::string field_name, const int lo,
645 const int hi, const enum MarkOP op,
646 const unsigned char c,
647 std::vector<unsigned char> &marker) const;
648
649 /**
650 * @brief Create vector with marked DOF indices based on DOF view
651 * \ingroup mofem_problems_manager
652 *
653 * Creates or modifies a marker vector based on a DOF view, allowing selective
654 * marking of DOFs that are present in the view. This is useful for creating
655 * masks or index sets for specific DOF collections in matrix/vector operations.
656 *
657 * @param problem_name name of the problem
658 * @param rc row or column data specification
659 * @param vec_dof_view vector of DOF entities to process for marking
660 * @param op marking operation (OR, AND, XOR) to apply
661 * @param marker reference to marker vector to create/modify
662 * @return MoFEMErrorCode Error code indicating success or failure
663 */
665 markDofs(const std::string problem_name, RowColData rc,
666 std::vector<boost::weak_ptr<NumeredDofEntity>> &vec_dof_view,
667 const enum MarkOP op, std::vector<unsigned char> &marker) const;
668
669 /**
670 * @brief Add empty field blocks to optimize matrix storage
671 * \ingroup mofem_problems_manager
672 *
673 * Marks field combinations as empty blocks in the matrix structure to optimize
674 * memory usage and computational efficiency. The MatrixManager assumes all field
675 * combinations result in non-zero blocks, but this allows specification of
676 * blocks that will remain zero for the entire problem duration.
677 *
678 * @param problem_name name of the problem to modify
679 * @param row_field name of the field for matrix row blocks
680 * @param col_field name of the field for matrix column blocks
681 * @return MoFEMErrorCode Error code indicating success or failure
682 */
683 MoFEMErrorCode addFieldToEmptyFieldBlocks(const std::string problem_name,
684 const std::string row_field,
685 const std::string col_field) const;
686
687private:
689};
690} // namespace MoFEM
691
692#endif //__PROBLEMSMANAGER_HPP__
693
694/**
695 * \defgroup mofem_problems_manager ProblemsManager
696 * \brief Adding and managing problems
697 *
698 * \ingroup mofem
699 */
MoFEM interface.
@ VERBOSE
RowColData
RowColData.
#define MAX_DOFS_ON_ENTITY
Maximal number of DOFs on entity.
#define DEPRECATED
Definition definitions.h:17
MoFEMErrorCode buildProblemOnDistributedMesh(const std::string name, const bool square_matrix, int verb=VERBOSE)
build problem data structures, assuming that mesh is distributed (collective)
MoFEMErrorCode partitionGhostDofs(const std::string name, int verb=VERBOSE)
determine ghost nodes
MoFEMErrorCode printPartitionedProblem(const Problem *problem_ptr, int verb=VERBOSE)
Print partition information for debugging.
MoFEMErrorCode addFieldToEmptyFieldBlocks(const std::string problem_name, const std::string row_field, const std::string col_field) const
Add empty field blocks to optimize matrix storage.
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
Modify DOF markers for specific field and coefficient range.
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 getSideDofsOnBrokenSpaceEntities(std::vector< boost::weak_ptr< NumeredDofEntity > > &vec_dof_view, const std::string problem_name, RowColData rc, const std::string field_name, const Range ents, int bridge_dim, 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) const
Get DOFs on side entities for broken space.
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 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
MoFEMErrorCode partitionProblem(const std::string name, int verb=VERBOSE)
partition problem dofs (collective)
MoFEMErrorCode removeDofs(const std::string problem_name, RowColData rc, std::vector< boost::weak_ptr< NumeredDofEntity > > &vec_dof_view, int verb=VERBOSE, const bool debug=false)
Remove DOFs from problem on broken space.
MoFEMErrorCode partitionGhostDofsOnDistributedMesh(const std::string name, int verb=VERBOSE)
determine ghost nodes on distributed meshes
MoFEMErrorCode getProblemElementsLayout(const std::string name, const std::string &fe_name, PetscLayout *layout) const
Get layout of elements in the problem.
MoFEMErrorCode getFEMeshset(const std::string prb_name, const std::string &fe_name, EntityHandle *meshset) const
Create finite element meshset for the problem.
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 debugPartitionedProblem(const Problem *problem_ptr, int verb=VERBOSE)
Debug partition information.
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.
MoFEMErrorCode getOptions()
Get command line options for ProblemsManager.
auto marker
set bit to marker
const double c
speed of light (cm/ns)
PetscErrorCode MoFEMErrorCode
MoFEM/PETSc error code.
std::bitset< BITREFLEVEL_SIZE > BitRefLevel
Bit structure attached to each entity identifying to what mesh entity is attached.
Definition Types.hpp:40
implementation of Data Operators for Forces and Sources
Definition Common.hpp:10
static const bool debug
constexpr auto field_name
Core (interface) class.
Definition Core.hpp:82
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.
PetscLogEvent MOFEM_EVENT_ProblemsManager
virtual ~ProblemsManager()=default
PetscBool synchroniseProblemEntities
DOFs in fields, not from DOFs on elements.
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.
base class for all interface classes