v0.16.3
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. all
226 * functions have 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 */
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. all
244 * functions have 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 /** \brief Rebuild a parent problem in place on a distributed mesh (collective)
256 * \ingroup mofem_problems_manager
257 *
258 * The problem keeps its name, its identity and its DMs. Its selector is set
259 * to target_bit and target_mask (set, never OR-ed), and its numbered DOFs
260 * are rebuilt by buildProblemOnDistributedMesh into staged containers,
261 * which are then published by swapping the problem's container pointers,
262 * sequences and counts. Until that swap the problem is untouched, so a
263 * failure of the build leaves it as it was. Every index is renumbered;
264 * nothing is preserved. The numbered finite elements are cleared and the
265 * ghost DOFs are not set: call partitionFiniteElements and
266 * partitionGhostDofsOnDistributedMesh afterwards, or use
267 * DMMoFEMRebuildProblem, which does that and resets the DM.
268 *
269 * Optionally returns, for the DOFs owned by this rank that exist in both
270 * numberings (same local UID), their old and their new global row indices
271 * in one order, for a VecScatter of retained vectors. The index sets are
272 * collective: pass both pointers on every rank, or none.
273 *
274 * @param name problem name
275 * @param target_bit bit ref level of the rebuilt problem
276 * @param target_mask bit ref mask of the rebuilt problem
277 * @param square_matrix true if rows and columns are the same
278 * @param verb verbosity level
279 * @param old_row_indices old global row indices of the surviving owned DOFs
280 * @param new_row_indices their new global row indices, same order
281 * @return MoFEMErrorCode Error code indicating success or failure
282 */
284 const std::string &name, const BitRefLevel target_bit,
285 const BitRefLevel target_mask, const bool square_matrix,
286 int verb = VERBOSE, SmartPetscObj<IS> *old_row_indices = nullptr,
287 SmartPetscObj<IS> *new_row_indices = nullptr);
288
289 /**
290 * \brief build sub problem
291 * \ingroup mofem_problems_manager
292 *
293 * Creates a sub-problem from a main problem by selecting specific fields
294 * for rows and columns. This is useful for creating focused problems that
295 * operate on subsets of the full problem's fields.
296 *
297 * @param out_name name of the output sub-problem to create
298 * @param fields_row vector of field names for problem rows
299 * @param fields_col vector of field names for problem columns
300 * @param main_problem name of the main problem to extract from
301 * @param square_matrix true if the sub-problem matrix is structurally symmetric
302 * @param entityMapRow optional map restricting row fields to specific entities
303 * @param entityMapCol optional map restricting column fields to specific entities
304 * @param verb verbosity level
305 * @return MoFEMErrorCode Error code indicating success or failure
306 */
308 const std::string out_name, const std::vector<std::string> &fields_row,
309 const std::vector<std::string> &fields_col,
310 const std::string main_problem, const bool square_matrix = true,
311 const map<std::string, boost::shared_ptr<Range>> *entityMapRow = nullptr,
312 const map<std::string, boost::shared_ptr<Range>> *entityMapCol = nullptr,
313 int verb = VERBOSE);
314
315 /**
316 * \brief build composite problem
317 * \ingroup mofem_problems_manager
318 *
319 * Creates a composite problem by combining multiple existing problems.
320 * The resulting problem contains DOFs from all constituent problems,
321 * arranged in block matrix structure.
322 *
323 * @param out_name name of the composite problem to create
324 * @param add_row_problems vector of problem names contributing to rows
325 * @param add_col_problems vector of problem names contributing to columns
326 * @param square_matrix true if the composite matrix is structurally symmetric
327 * @param verb verbosity level
328 * @return MoFEMErrorCode Error code indicating success or failure
329 */
331 buildComposedProblem(const std::string out_name,
332 const std::vector<std::string> add_row_problems,
333 const std::vector<std::string> add_col_problems,
334 const bool square_matrix = true, int verb = 1);
335
336 /**
337 * \brief build indexing and partition problem inheriting indexing and
338 * partitioning from two other problems
339 * \ingroup mofem_problems_manager
340 *
341 * Transfers DOF indexing and partitioning information from existing problems
342 * to a new problem. This is useful for maintaining consistent partitioning
343 * across related problems in multi-physics simulations.
344 *
345 * @param name name of the target problem to inherit partitioning
346 * @param problem_for_rows source problem for row DOF indexing and partitioning
347 * @param copy_rows if true, copy row DOF indices; if false, only copy partition info
348 * @param problem_for_cols source problem for column DOF indexing and partitioning
349 * @param copy_cols if true, copy column DOF indices; if false, only copy partition info
350 * @param verb verbosity level
351 * @return MoFEMErrorCode Error code indicating success or failure
352 *
353 * If copy_rows/copy_cols is set to false only partition is copied between
354 * problems.
355 */
356 MoFEMErrorCode inheritPartition(const std::string name,
357 const std::string problem_for_rows,
358 bool copy_rows,
359 const std::string problem_for_cols,
360 bool copy_cols, int verb = VERBOSE);
361
362 /** \brief partition problem dofs
363 * \ingroup mofem_problems_manager
364 *
365 * Partitions DOFs for sequential/simple problems where the mesh is not
366 * distributed across processors. Creates local DOF numbering and assigns
367 * ownership to processors.
368 *
369 * @param name problem name to partition
370 * @param verb verbosity level
371 * @return MoFEMErrorCode Error code indicating success or failure
372 */
374 int verb = VERBOSE);
375
376 /** \brief partition problem dofs (collective)
377 * \ingroup mofem_problems_manager
378 *
379 * Partitions DOFs for distributed problems where the mesh is already
380 * distributed across processors. Must be called collectively on all
381 * processors in the communicator.
382 *
383 * @param name problem name to partition
384 * @param verb verbosity level
385 * @return MoFEMErrorCode Error code indicating success or failure
386 */
387 MoFEMErrorCode partitionProblem(const std::string name, int verb = VERBOSE);
388
389 /**
390 * \brief Print partition information for debugging
391 * \ingroup mofem_problems_manager
392 *
393 * Outputs detailed information about how DOFs and finite elements are
394 * distributed across processors for the given problem.
395 *
396 * @param problem_ptr pointer to the problem structure
397 * @param verb verbosity level
398 * @return MoFEMErrorCode Error code indicating success or failure
399 */
401 int verb = VERBOSE);
402
403 /**
404 * \brief Debug partition information
405 * \ingroup mofem_problems_manager
406 *
407 * Performs detailed analysis and validation of problem partitioning,
408 * checking for inconsistencies and reporting partition quality metrics.
409 *
410 * @param problem_ptr pointer to the problem structure
411 * @param verb verbosity level
412 * @return MoFEMErrorCode Error code indicating success or failure
413 */
415 int verb = VERBOSE);
416
417 /** \brief partition finite elements
418 * \ingroup mofem_problems_manager
419 *
420 * Function which partition finite elements based on dofs partitioning.
421 * In addition it sets information about local row and cols dofs at given
422 * element on partition. Can optionally use MOAB's partitioning information
423 * or restrict partitioning to specific processor ranges.
424 *
425 * @param name problem name to partition finite elements for
426 * @param part_from_moab if true, use MOAB's existing partition information
427 * @param low_proc lowest processor rank to include (-1 for all)
428 * @param hi_proc highest processor rank to include (-1 for all)
429 * @param verb verbosity level
430 * @return MoFEMErrorCode Error code indicating success or failure
431 */
433 bool part_from_moab = false,
434 int low_proc = -1, int hi_proc = -1,
435 int verb = VERBOSE);
436
437 /** \brief determine ghost nodes
438 * \ingroup mofem_problems_manager
439 *
440 * Identifies and marks DOFs as ghost DOFs for parallel computations.
441 * DOFs are ghost dofs if they are used by elements on a given partition
442 * but not owned by that partition.
443 *
444 * @param name problem name to determine ghost DOFs for
445 * @param verb verbosity level
446 * @return MoFEMErrorCode Error code indicating success or failure
447 */
448 MoFEMErrorCode partitionGhostDofs(const std::string name, int verb = VERBOSE);
449
450 /** \brief determine ghost nodes on distributed meshes
451 * \ingroup mofem_problems_manager
452 *
453 * Identifies and marks DOFs as ghost DOFs specifically for distributed meshes.
454 * This function is similar to partitionGhostDofs but exploits the fact that
455 * the mesh is distributed across processors. DOFs are ghosted if they are
456 * shared but not owned by the current partition.
457 *
458 * @param name problem name to determine ghost DOFs for
459 * @param verb verbosity level
460 * @return MoFEMErrorCode Error code indicating success or failure
461 */
463 int verb = VERBOSE);
464
465 /**
466 * @brief Create finite element meshset for the problem
467 * \ingroup mofem_problems_manager
468 *
469 * Creates or retrieves the meshset entity that contains all finite elements
470 * of a specific type within a problem. The meshset entity must be created
471 * before calling this function.
472 *
473 * @param prb_name name of the problem
474 * @param fe_name name of the finite element type
475 * @param meshset pointer to store the meshset handle
476 * @return MoFEMErrorCode Error code indicating success or failure
477 */
478 MoFEMErrorCode getFEMeshset(const std::string prb_name,
479 const std::string &fe_name,
480 EntityHandle *meshset) const;
481
482 /**
483 * \brief Get layout of elements in the problem
484 * \ingroup mofem_problems_manager
485 *
486 * In layout is stored information how many elements is on each processor, for
487 * more information look int petsc documentation
488 * <http://www.mcs.anl.gov/petsc/petsc-current/docs/manualpages/IS/PetscLayoutCreate.html#PetscLayoutCreate>
489 *
490 * @param name problem name
491 * @param fe_name finite elements
492 * @param layout layout
493 * @param verb verbosity level
494 * @return error code
495 */
497 const std::string &fe_name,
498 PetscLayout *layout) const;
499
500 /**
501 * @brief Remove DOFs from problem
502 * @ingroup mofem_problems_manager
503 *
504 * Remove DOFs from problem which are on entities on the given range and given
505 * field name. On the finite element level, DOFs can be still accessed however
506 * local PETSc indices and global PETSc indices are marked with the index -1.
507 *
508 * @note If the index is marked -1 it is not assembled and dropped by
509 * VecSetValues and MatSetValues.
510 *
511 * @todo Not yet implemented update for AO maps and IS ranges if removed
512 * entities in composite problem or sub-problem
513 *
514 * @param problem_name name of the problem
515 * @param field_name name of the field
516 * @param ents entities on which DOFs are removed
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 Range ents, const int lo_coeff = 0,
526 const int hi_coeff = MAX_DOFS_ON_ENTITY, const int lo_order = 0,
527 const int hi_order = 100, int verb = VERBOSE, const bool debug = false);
528
529 /**
530 * @copydoc removeDofsOnEntities
531 *
532 * \note Use this function for non-distributed meshes
533 */
535 const std::string problem_name, const std::string field_name,
536 const Range ents, const int lo_coeff = 0,
537 const int hi_coeff = MAX_DOFS_ON_ENTITY, const int lo_order = 0,
538 const int hi_order = 100, int verb = VERBOSE, const bool debug = false);
539
540 /**
541 * @brief Remove DOFs from problem by bit ref level
542 * @ingroup mofem_problems_manager
543 *
544 * See for more detail other implementation for removeDofsOnEntities.
545 *
546 * @param problem_name name of the problem
547 * @param field_name name of the field
548 * @param bit_ref_level bit ref level on which DOFs are removed
549 * @param bit_ref_mask bit ref mask on which DOFs are removed
550 * @param ents_ptr filter entities with given bit and mask
551 * @param lo_coeff low dof coefficient (rank)
552 * @param hi_coeff high dof coefficient (rank)
553 * @param verb verbosity level
554 * @param debug to debug and seek for inconsistencies set to true
555 * @return MoFEMErrorCode
556 */
558 const std::string problem_name, const std::string field_name,
559 const BitRefLevel bit_ref_level, const BitRefLevel bit_ref_mask,
560 Range *ents_ptr = nullptr, const int lo_coeff = 0,
561 const int hi_coeff = MAX_DOFS_ON_ENTITY, const int lo_order = 0,
562 const int hi_order = 100, int verb = VERBOSE, const bool debug = false);
563
564 /**
565 * @copydoc removeDofsOnEntities
566 *
567 * \note Use this function for non distributed meshes
568 */
570 const std::string problem_name, const std::string field_name,
571 const BitRefLevel bit_ref_level, const BitRefLevel bit_ref_mask,
572 Range *ents_ptr = nullptr, const int lo_coeff = 0,
573 const int hi_coeff = MAX_DOFS_ON_ENTITY, const int lo_order = 0,
574 const int hi_order = 100, int verb = VERBOSE, const bool debug = false);
575
576
577 /**
578 * @brief Remove DOFs from problem on broken space
579 * \ingroup mofem_problems_manager
580 *
581 * Removes specified DOFs from the problem for broken (discontinuous) spaces.
582 * The DOFs are marked as inactive by setting their indices to -1, which
583 * causes them to be skipped during assembly operations.
584 *
585 * @param problem_name name of the problem
586 * @param rc row or column data specification
587 * @param vec_dof_view vector of DOF entities to remove
588 * @param verb verbosity level
589 * @param debug enable debug output for inconsistency checking
590 * @return MoFEMErrorCode Error code indicating success or failure
591 */
593 removeDofs(const std::string problem_name, RowColData rc,
594 std::vector<boost::weak_ptr<NumeredDofEntity>> &vec_dof_view,
595 int verb = VERBOSE, const bool debug = false);
596
597 /**
598 * @brief Get DOFs on side entities for broken space
599 * \ingroup mofem_problems_manager
600 *
601 * Retrieves DOFs associated with side entities in broken (discontinuous) spaces.
602 * The DOFs are connected through a bridge entity of specified dimension.
603 * This is useful for implementing interface conditions in discontinuous Galerkin methods.
604 *
605 * @param vec_dof_view output vector to store the DOF entities
606 * @param problem_name name of the problem
607 * @param rc row or column data specification
608 * @param field_name name of the field
609 * @param ents range of side entities to process
610 * @param bridge_dim dimension of bridge entity connecting DOFs to side entities
611 * @param lo_coeff lowest coefficient (rank) to include
612 * @param hi_coeff highest coefficient (rank) to include
613 * @param lo_order lowest polynomial order to include
614 * @param hi_order highest polynomial order to include
615 * @param verb verbosity level
616 * @param debug enable debug output for inconsistency checking
617 * @return MoFEMErrorCode Error code indicating success or failure
618 */
620
621 std::vector<boost::weak_ptr<NumeredDofEntity>> &vec_dof_view,
622
623 const std::string problem_name, RowColData rc,
624 const std::string field_name, const Range ents, int bridge_dim,
625 const int lo_coeff = 0, const int hi_coeff = MAX_DOFS_ON_ENTITY,
626 const int lo_order = 0, const int hi_order = 100, int verb = VERBOSE,
627 const bool debug = false
628
629 ) const;
630
631
632 enum MarkOP { OR, AND };
633
634 /**
635 * @brief Create vector with marked indices
636 *
637 * Vector with local DOFs marked by entities
638 *
639 *
640 * @param problem_name
641 * @param row
642 * @param ents
643 * @param marker
644 * @return MoFEMErrorCode
645 */
646 MoFEMErrorCode markDofs(const std::string problem_name, RowColData rc,
647 const enum MarkOP op, const Range ents,
648 std::vector<unsigned char> &marker) const;
649
650 /**
651 * @deprecated use function with MarkOP
652 */
654 markDofs(const std::string problem_name, RowColData rc, const Range ents,
655 std::vector<unsigned char> &marker) const {
656 return markDofs(problem_name, rc, MarkOP::OR, ents, marker);
657 }
658
659 /**
660 * @brief Modify DOF markers for specific field and coefficient range
661 * \ingroup mofem_problems_manager
662 *
663 * Modifies the marker flags for DOFs associated with a specific field within
664 * a defined coefficient range. This allows selective marking/unmarking of DOFs
665 * based on field and polynomial order criteria using bitwise operations.
666 *
667 * @param problem_name name of the problem
668 * @param rc row or column data specification
669 * @param field_name name of the field to process
670 * @param lo lowest coefficient (rank) to include
671 * @param hi highest coefficient (rank) to include
672 * @param op marking operation (OR, AND, XOR) to apply
673 * @param c marker value to apply with the operation
674 * @param marker reference to marker vector to modify
675 * @return MoFEMErrorCode Error code indicating success or failure
676 */
677 MoFEMErrorCode modifyMarkDofs(const std::string problem_name, RowColData rc,
678 const std::string field_name, const int lo,
679 const int hi, const enum MarkOP op,
680 const unsigned char c,
681 std::vector<unsigned char> &marker) const;
682
683 /**
684 * @brief Create vector with marked DOF indices based on DOF view
685 * \ingroup mofem_problems_manager
686 *
687 * Creates or modifies a marker vector based on a DOF view, allowing selective
688 * marking of DOFs that are present in the view. This is useful for creating
689 * masks or index sets for specific DOF collections in matrix/vector operations.
690 *
691 * @param problem_name name of the problem
692 * @param rc row or column data specification
693 * @param vec_dof_view vector of DOF entities to process for marking
694 * @param op marking operation (OR, AND, XOR) to apply
695 * @param marker reference to marker vector to create/modify
696 * @return MoFEMErrorCode Error code indicating success or failure
697 */
699 markDofs(const std::string problem_name, RowColData rc,
700 std::vector<boost::weak_ptr<NumeredDofEntity>> &vec_dof_view,
701 const enum MarkOP op, std::vector<unsigned char> &marker) const;
702
703 /**
704 * @brief Add empty field blocks to optimize matrix storage
705 * \ingroup mofem_problems_manager
706 *
707 * Marks field combinations as empty blocks in the matrix structure to optimize
708 * memory usage and computational efficiency. The MatrixManager assumes all field
709 * combinations result in non-zero blocks, but this allows specification of
710 * blocks that will remain zero for the entire problem duration.
711 *
712 * @param problem_name name of the problem to modify
713 * @param row_field name of the field for matrix row blocks
714 * @param col_field name of the field for matrix column blocks
715 * @return MoFEMErrorCode Error code indicating success or failure
716 */
717 MoFEMErrorCode addFieldToEmptyFieldBlocks(const std::string problem_name,
718 const std::string row_field,
719 const std::string col_field) const;
720
721private:
723};
724} // namespace MoFEM
725
726#endif //__PROBLEMSMANAGER_HPP__
727
728/**
729 * \defgroup mofem_problems_manager ProblemsManager
730 * \brief Adding and managing problems
731 *
732 * \ingroup mofem
733 */
std::string name
MoFEM interface.
@ VERBOSE
RowColData
RowColData.
#define MAX_DOFS_ON_ENTITY
Maximal number of DOFs on entity.
#define DEPRECATED
Definition definitions.h:17
static const bool debug
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 rebuildProblemOnDistributedMesh(const std::string &name, const BitRefLevel target_bit, const BitRefLevel target_mask, const bool square_matrix, int verb=VERBOSE, SmartPetscObj< IS > *old_row_indices=nullptr, SmartPetscObj< IS > *new_row_indices=nullptr)
Rebuild a parent problem in place on a distributed mesh (collective)
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
constexpr auto field_name
Core (interface) class.
Definition Core.hpp:83
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.
intrusive_ptr for managing petsc objects
base class for all interface classes