LCOV - code coverage report
Current view: top level - include/base - dof_map.h (source / functions) Hit Total Coverage
Test: libMesh/libmesh: #4475 (55045b) with base a68cc6 Lines: 220 235 93.6 %
Date: 2026-06-03 14:29:06 Functions: 67 76 88.2 %
Legend: Lines: hit not hit

          Line data    Source code
       1             : // The libMesh Finite Element Library.
       2             : // Copyright (C) 2002-2026 Benjamin S. Kirk, John W. Peterson, Roy H. Stogner
       3             : 
       4             : // This library is free software; you can redistribute it and/or
       5             : // modify it under the terms of the GNU Lesser General Public
       6             : // License as published by the Free Software Foundation; either
       7             : // version 2.1 of the License, or (at your option) any later version.
       8             : 
       9             : // This library is distributed in the hope that it will be useful,
      10             : // but WITHOUT ANY WARRANTY; without even the implied warranty of
      11             : // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
      12             : // Lesser General Public License for more details.
      13             : 
      14             : // You should have received a copy of the GNU Lesser General Public
      15             : // License along with this library; if not, write to the Free Software
      16             : // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
      17             : 
      18             : 
      19             : 
      20             : #ifndef LIBMESH_DOF_MAP_H
      21             : #define LIBMESH_DOF_MAP_H
      22             : 
      23             : // Local Includes
      24             : #include "libmesh/libmesh_common.h"
      25             : #include "libmesh/reference_counted_object.h"
      26             : #include "libmesh/libmesh.h" // libMesh::invalid_uint
      27             : #include "libmesh/variable.h"
      28             : #include "libmesh/threads.h"
      29             : #include "libmesh/threads_allocators.h"
      30             : #include "libmesh/elem_range.h"
      31             : #include "libmesh/ghosting_functor.h"
      32             : #include "libmesh/sparsity_pattern.h"
      33             : #include "libmesh/parallel_object.h"
      34             : #include "libmesh/point.h"
      35             : #include "libmesh/utility.h"
      36             : #include "libmesh/elem.h"
      37             : #include "libmesh/fe_interface.h"
      38             : #include "libmesh/libmesh_logging.h"
      39             : #include "libmesh/enum_elem_type.h"
      40             : #include "libmesh/mesh_subdivision_support.h"
      41             : #include "libmesh/dof_map_base.h"
      42             : 
      43             : // TIMPI includes
      44             : #include "timpi/parallel_implementation.h"
      45             : #include "timpi/parallel_sync.h"
      46             : 
      47             : // C++ Includes
      48             : #include <algorithm>
      49             : #include <cstddef>
      50             : #include <iterator>
      51             : #include <map>
      52             : #include <string>
      53             : #include <vector>
      54             : #include <memory>
      55             : 
      56             : namespace libMesh
      57             : {
      58             : 
      59             : // Forward Declarations
      60             : class CouplingMatrix;
      61             : class DefaultCoupling;
      62             : class DirichletBoundary;
      63             : class DirichletBoundaries;
      64             : class DofMap;
      65             : class DofObject;
      66             : class FEType;
      67             : class MeshBase;
      68             : class PeriodicBoundaryBase;
      69             : class PeriodicBoundaries;
      70             : class System;
      71             : class NonlinearImplicitSystem;
      72             : class StaticCondensationDofMap;
      73             : template <typename T> class DenseVectorBase;
      74             : template <typename T> class DenseVector;
      75             : template <typename T> class DenseMatrix;
      76             : template <typename T> class SparseMatrix;
      77             : template <typename T> class NumericVector;
      78             : enum Order : int;
      79             : 
      80             : 
      81             : 
      82             : // ------------------------------------------------------------
      83             : // Do we need constraints for anything?
      84             : 
      85             : #if defined(LIBMESH_ENABLE_AMR) ||              \
      86             :   defined(LIBMESH_ENABLE_PERIODIC) ||           \
      87             :   defined(LIBMESH_ENABLE_DIRICHLET)
      88             : #  define LIBMESH_ENABLE_CONSTRAINTS 1
      89             : #endif
      90             : 
      91             : // ------------------------------------------------------------
      92             : // AMR constraint matrix types
      93             : 
      94             : #ifdef LIBMESH_ENABLE_CONSTRAINTS
      95             : /**
      96             :  * A row of the Dof constraint matrix.
      97             :  */
      98             : typedef std::map<dof_id_type, Real,
      99             :                  std::less<dof_id_type>,
     100             :                  Threads::scalable_allocator<std::pair<const dof_id_type, Real>>> DofConstraintRow;
     101             : 
     102             : /**
     103             :  * The constraint matrix storage format.
     104             :  * We're using a class instead of a typedef to allow forward
     105             :  * declarations and future flexibility.  Don't delete this from
     106             :  * a pointer-to-std-map; the destructor isn't virtual!
     107             :  */
     108      235850 : class DofConstraints : public std::map<dof_id_type,
     109             :                                        DofConstraintRow,
     110             :                                        std::less<dof_id_type>,
     111             :                                        Threads::scalable_allocator<std::pair<const dof_id_type, DofConstraintRow>>>
     112             : {
     113             : };
     114             : 
     115             : /**
     116             :  * Storage for DofConstraint right hand sides for a particular
     117             :  * problem.  Each dof id with a non-zero constraint offset
     118             :  * stores it in such a structure.
     119             :  */
     120      235714 : class DofConstraintValueMap :
     121             :     public std::map<dof_id_type, Number,
     122             :                     std::less<dof_id_type>,
     123             :                     Threads::scalable_allocator<std::pair<const dof_id_type, Number>>>
     124             : {
     125             : };
     126             : 
     127             : /**
     128             :  * Storage for DofConstraint right hand sides for all adjoint
     129             :  * problems.
     130             :  */
     131      235714 : class AdjointDofConstraintValues :
     132             :     public std::map<unsigned int, DofConstraintValueMap,
     133             :                     std::less<unsigned int>,
     134             :                     Threads::scalable_allocator
     135             :                     <std::pair<const unsigned int, DofConstraintValueMap>>>
     136             : {
     137             : };
     138             : 
     139             : #ifdef LIBMESH_ENABLE_NODE_CONSTRAINTS
     140             : /**
     141             :  * A row of the Node constraint mapping.  Currently this just
     142             :  * stores the topology of the constrained Nodes, but for forward
     143             :  * compatibility we also include coefficients, so we could add
     144             :  * Lagrange-positioned-node constraints later.
     145             :  */
     146             : typedef std::map<const Node *, Real,
     147             :                  std::less<const Node *>,
     148             :                  Threads::scalable_allocator<std::pair<const Node * const, Real>>> NodeConstraintRow;
     149             : 
     150             : /**
     151             :  * The Node constraint storage format.
     152             :  * We're using a class instead of a typedef to allow forward
     153             :  * declarations and future flexibility.  Don't delete this from
     154             :  * a pointer-to-std-map; the destructor isn't virtual!
     155             :  */
     156        6888 : class NodeConstraints : public std::map<const Node *,
     157             :                                         std::pair<NodeConstraintRow,Point>,
     158             :                                         std::less<const Node *>,
     159             :                                         Threads::scalable_allocator<std::pair<const Node * const, std::pair<NodeConstraintRow,Point>>>>
     160             : {
     161             : };
     162             : #endif // LIBMESH_ENABLE_NODE_CONSTRAINTS
     163             : 
     164             : #endif // LIBMESH_ENABLE_CONSTRAINTS
     165             : 
     166             : 
     167             : 
     168             : /**
     169             :  * This class handles the numbering of degrees of freedom on a mesh.
     170             :  * For systems of equations the class supports a fixed number of variables.
     171             :  * The degrees of freedom are numbered such that sequential, contiguous blocks
     172             :  * belong to distinct processors.  This is so that the resulting data
     173             :  * structures will work well with parallel linear algebra packages.
     174             :  *
     175             :  * \author Benjamin S. Kirk
     176             :  * \date 2002-2007
     177             :  * \brief Manages the degrees of freedom (DOFs) in a simulation.
     178             :  */
     179             : class DofMap : public DofMapBase,
     180             :                public ReferenceCountedObject<DofMap>
     181             : {
     182             : public:
     183             : 
     184             :   /**
     185             :    * Constructor.  Requires the number of the system for which we
     186             :    * will be numbering degrees of freedom & the parent object
     187             :    * we are contained in, which defines our communication space.
     188             :    */
     189             :   explicit
     190             :   DofMap(const unsigned int sys_number,
     191             :          MeshBase & mesh);
     192             : 
     193             :   /**
     194             :    * Destructor.
     195             :    */
     196             :   ~DofMap();
     197             : 
     198             :   /**
     199             :    * Backwards compatibility for prior AugmentSparsityPattern users.
     200             :    */
     201             :   class AugmentSparsityPattern : public SparsityPattern::AugmentSparsityPattern
     202             :   {};
     203             : 
     204             :   /**
     205             :    * Abstract base class to be used to add user-defined parallel
     206             :    * degree of freedom couplings.
     207             :    */
     208             :   class AugmentSendList
     209             :   {
     210             :   public:
     211             :     virtual ~AugmentSendList () = default;
     212             : 
     213             :     /**
     214             :      * User-defined function to augment the send list.
     215             :      */
     216             :     virtual void augment_send_list (std::vector<dof_id_type> & send_list) = 0;
     217             :   };
     218             : 
     219             :   /**
     220             :    * Additional matrices may be attached to this \p DofMap.
     221             :    * They are initialized to the same sparsity structure as
     222             :    * the major matrix.
     223             :    */
     224             :   void attach_matrix (SparseMatrix<Number> & matrix);
     225             : 
     226             :   /**
     227             :    * Additional matrices may be be temporarily initialized by this \p
     228             :    * DofMap.
     229             :    * They are initialized to the same sparsity structure as
     230             :    * the major matrix.
     231             :    */
     232             :   void update_sparsity_pattern(SparseMatrix<Number> & matrix) const;
     233             : 
     234             :   /**
     235             :    * Matrices should not be attached more than once.  We can test for
     236             :    * an already-attached matrix if necessary using \p is_attached
     237             :    */
     238             :   bool is_attached (SparseMatrix<Number> & matrix);
     239             : 
     240             :   /**
     241             :    * Distribute dofs on the current mesh.  Also builds the send list for
     242             :    * processor \p proc_id, which defaults to 0 for ease of use in serial
     243             :    * applications.
     244             :    * \returns The total number of DOFs for the System, summed across all procs.
     245             :    */
     246             :   std::size_t distribute_dofs (MeshBase &);
     247             : 
     248             :   /**
     249             :    * Computes the sparsity pattern for the matrices corresponding to
     250             :    * \p proc_id and sends that data to Linear Algebra packages for
     251             :    * preallocation of sparse matrices.
     252             :    */
     253             :   void compute_sparsity (const MeshBase &);
     254             : 
     255             :   /**
     256             :    * Returns true iff a sparsity pattern has already been computed.
     257             :    */
     258             :   bool computed_sparsity_already () const;
     259             : 
     260             :   /**
     261             :    * Sets the current policy for constructing sparsity patterns: if
     262             :    * \p use_constraints is true (for robustness), we explicitly
     263             :    * account for sparsity entries created by constraint matrix pre-
     264             :    * and post- application.  If \p use_constraints is false (for
     265             :    * speed), we calculate only the sparsity pattern of an
     266             :    * unconstrained matrix.  This is false by default, because in
     267             :    * nearly all applications our constraints do not increase the
     268             :    * number of non-zeros required in a sparse matrix.
     269             :    */
     270             :   void set_constrained_sparsity_construction(bool use_constraints);
     271             : 
     272             :   /**
     273             :    * Sets need_full_sparsity_pattern to true regardless of the requirements by matrices
     274             :    */
     275             :   void full_sparsity_pattern_needed();
     276             : 
     277             :   /**
     278             :    * Returns true iff the current policy when constructing sparsity
     279             :    * patterns is to explicitly account for sparsity entries created by
     280             :    * constraint matrix pre- and post- application.
     281             :    */
     282             :   bool constrained_sparsity_construction();
     283             : 
     284             :   /**
     285             :    * Clears the sparsity pattern
     286             :    */
     287             :   void clear_sparsity();
     288             : 
     289             :   /**
     290             :    * Remove any default ghosting functor(s).  User-added ghosting
     291             :    * functors will be unaffected.
     292             :    *
     293             :    * Unless user-added equivalent ghosting functors exist, removing
     294             :    * the default coupling functor is only safe for explicit solves,
     295             :    * and removing the default algebraic ghosting functor is only safe
     296             :    * for codes where no evaluations on neighbor cells (e.g. no jump
     297             :    * error estimators) are done.
     298             :    *
     299             :    * Defaults can be restored manually via add_default_ghosting(), or
     300             :    * automatically if clear() returns the DofMap to a default state.
     301             :    */
     302             :   void remove_default_ghosting();
     303             : 
     304             :   /**
     305             :    * Add the default functor(s) for coupling and algebraic ghosting.
     306             :    * User-added ghosting functors will be unaffected.
     307             :    */
     308             :   void add_default_ghosting();
     309             : 
     310             :   /**
     311             :    * Iterator type for coupling and algebraic ghosting functor ranges.
     312             :    * This has changed in the past and may change again; code should
     313             :    * use auto or the type here.
     314             :    */
     315             :   typedef std::vector<GhostingFunctor *>::const_iterator GhostingFunctorIterator;
     316             : 
     317             :   /**
     318             :    * Adds a functor which can specify coupling requirements for
     319             :    * creation of sparse matrices.
     320             :    * Degree of freedom pairs which match the elements and variables
     321             :    * returned by these functors will be added to the sparsity pattern,
     322             :    * and the degrees of freedom which live on other processors will be
     323             :    * added to the send_list for use on ghosted vectors, and the
     324             :    * elements which live on other processors will be ghosted on a
     325             :    * distributed mesh.
     326             :    *
     327             :    * GhostingFunctor memory must be managed by the code which calls
     328             :    * this function; the GhostingFunctor lifetime is expected to extend
     329             :    * until either the functor is removed or the DofMap is destructed.
     330             :    *
     331             :    * When \p to_mesh is true, the \p coupling_functor is also added to
     332             :    * our associated mesh, to ensure that coupled elements do not get
     333             :    * lost during mesh distribution.  (if coupled elements were
     334             :    * *already* lost there's no getting them back after the fact,
     335             :    * sorry)
     336             :    *
     337             :    * If \p to_mesh is false, no change to mesh ghosting is made;
     338             :    * the Mesh must already have ghosting functor(s) specifying a
     339             :    * superset of \p coupling_functor or this is a horrible bug.
     340             :    */
     341             :   void add_coupling_functor(GhostingFunctor & coupling_functor,
     342             :                             bool to_mesh = true);
     343             : 
     344             :   /**
     345             :    * Adds a functor which can specify coupling requirements for
     346             :    * creation of sparse matrices.
     347             :    *
     348             :    * GhostingFunctor memory when using this method is managed by the
     349             :    * shared_ptr mechanism.
     350             :    */
     351             :   void add_coupling_functor(std::shared_ptr<GhostingFunctor> coupling_functor,
     352             :                             bool to_mesh = true)
     353             :   { _shared_functors[coupling_functor.get()] = coupling_functor;
     354             :     this->add_coupling_functor(*coupling_functor, to_mesh); }
     355             : 
     356             :   /**
     357             :    * Removes a functor which was previously added to the set of
     358             :    * coupling functors, from both this DofMap and from the underlying
     359             :    * mesh.
     360             :    */
     361             :   void remove_coupling_functor(GhostingFunctor & coupling_functor);
     362             : 
     363             :   /**
     364             :    * Beginning of range of coupling functors
     365             :    */
     366      317508 :   GhostingFunctorIterator coupling_functors_begin() const
     367      646960 :   { return _coupling_functors.begin(); }
     368             : 
     369             :   /**
     370             :    * End of range of coupling functors
     371             :    */
     372      317508 :   GhostingFunctorIterator coupling_functors_end() const
     373      646960 :   { return _coupling_functors.end(); }
     374             : 
     375             :   /**
     376             :    * Default coupling functor
     377             :    */
     378           0 :   DefaultCoupling & default_coupling() { return *_default_coupling; }
     379             : 
     380             :   /**
     381             :    * Adds a functor which can specify algebraic ghosting requirements
     382             :    * for use with distributed vectors.  Degrees of freedom on other
     383             :    * processors which match the elements and variables returned by
     384             :    * these functors will be added to the send_list, and the elements
     385             :    * on other processors will be ghosted on a distributed mesh, so
     386             :    * that the elements can always be found and the solutions on them
     387             :    * will always be evaluable.
     388             :    *
     389             :    * GhostingFunctor memory must be managed by the code which calls
     390             :    * this function; the GhostingFunctor lifetime is expected to extend
     391             :    * until either the functor is removed or the DofMap is destructed.
     392             :    *
     393             :    * When \p to_mesh is true, the \p coupling_functor is also added to
     394             :    * our associated mesh, to ensure that evaluable elements do not get
     395             :    * lost during mesh distribution.  (if evaluable elements were
     396             :    * *already* lost there's no getting them back after the fact,
     397             :    * sorry)
     398             :    *
     399             :    * If \p to_mesh is false, no change to mesh ghosting is made;
     400             :    * the Mesh must already have ghosting functor(s) specifying a
     401             :    * superset of \p evaluable_functor or this is a horrible bug.
     402             :    */
     403             :   void add_algebraic_ghosting_functor(GhostingFunctor & evaluable_functor,
     404             :                                       bool to_mesh = true);
     405             : 
     406             :   /**
     407             :    * Adds a functor which can specify algebraic ghosting requirements
     408             :    * for use with distributed vectors.
     409             :    *
     410             :    * GhostingFunctor memory when using this method is managed by the
     411             :    * shared_ptr mechanism.
     412             :    */
     413             :   void add_algebraic_ghosting_functor(std::shared_ptr<GhostingFunctor> evaluable_functor,
     414             :                                       bool to_mesh = true)
     415             :   { _shared_functors[evaluable_functor.get()] = evaluable_functor;
     416             :     this->add_algebraic_ghosting_functor(*evaluable_functor, to_mesh); }
     417             : 
     418             :   /**
     419             :    * Removes a functor which was previously added to the set of
     420             :    * algebraic ghosting functors, from both this DofMap and from the
     421             :    * underlying mesh.
     422             :    */
     423             :   void remove_algebraic_ghosting_functor(GhostingFunctor & evaluable_functor);
     424             : 
     425             :   /**
     426             :    * Beginning of range of algebraic ghosting functors
     427             :    */
     428        1754 :   GhostingFunctorIterator algebraic_ghosting_functors_begin() const
     429        9676 :   { return _algebraic_ghosting_functors.begin(); }
     430             : 
     431             :   /**
     432             :    * End of range of algebraic ghosting functors
     433             :    */
     434        1754 :   GhostingFunctorIterator algebraic_ghosting_functors_end() const
     435        9676 :   { return _algebraic_ghosting_functors.end(); }
     436             : 
     437             :   /**
     438             :    * Default algebraic ghosting functor
     439             :    */
     440           0 :   DefaultCoupling & default_algebraic_ghosting() { return *_default_evaluating; }
     441             : 
     442             :   /**
     443             :    * Attach an object to use to populate the
     444             :    * sparsity pattern with extra entries.
     445             :    *
     446             :    * Care must be taken that when adding entries they are sorted into the Rows
     447             :    *
     448             :    * Further, you _must_ modify n_nz and n_oz properly!
     449             :    *
     450             :    * This is an advanced function... use at your own peril!
     451             :    */
     452             :   void attach_extra_sparsity_object (SparsityPattern::AugmentSparsityPattern & asp)
     453             :   {
     454             :     _augment_sparsity_pattern = &asp;
     455             :   }
     456             : 
     457             :   /**
     458             :    * Attach a function pointer to use as a callback to populate the
     459             :    * sparsity pattern with extra entries.
     460             :    *
     461             :    * Care must be taken that when adding entries they are sorted into the Rows
     462             :    *
     463             :    * Further, you _must_ modify n_nz and n_oz properly!
     464             :    *
     465             :    * This is an advanced function... use at your own peril!
     466             :    */
     467             :   void attach_extra_sparsity_function(void (*func)(SparsityPattern::Graph & sparsity,
     468             :                                                    std::vector<dof_id_type> & n_nz,
     469             :                                                    std::vector<dof_id_type> & n_oz,
     470             :                                                    void *),
     471             :                                       void * context = nullptr)
     472             :   { _extra_sparsity_function = func; _extra_sparsity_context = context; }
     473             : 
     474             :   /**
     475             :    * Attach an object to populate the send_list with extra entries.
     476             :    * This should only add to the send list, but no checking is done
     477             :    * to enforce this behavior.
     478             :    *
     479             :    * This is an advanced function... use at your own peril!
     480             :    */
     481             :   void attach_extra_send_list_object (DofMap::AugmentSendList & asl)
     482             :   {
     483             :     _augment_send_list = &asl;
     484             :   }
     485             : 
     486             :   /**
     487             :    * Attach a function pointer to use as a callback to populate the
     488             :    * send_list with extra entries.
     489             :    */
     490             :   void attach_extra_send_list_function(void (*func)(std::vector<dof_id_type> &, void *),
     491             :                                        void * context = nullptr)
     492             :   { _extra_send_list_function = func; _extra_send_list_context = context; }
     493             : 
     494             :   /**
     495             :    * Takes the \p _send_list vector (which may have duplicate entries)
     496             :    * and sorts it.  The duplicate entries are then removed, resulting in
     497             :    * a sorted \p _send_list with unique entries.  Also calls any user-provided
     498             :    * methods for adding to the send list.
     499             :    */
     500             :   void prepare_send_list ();
     501             : 
     502             :   /**
     503             :    * Clears the \p _send_list vector. This should be done in order to completely
     504             :    * rebuild the send_list from scratch rather than merely adding to the existing
     505             :    * send_list.
     506             :    */
     507       14838 :   void clear_send_list ()
     508             :   {
     509       14838 :     _send_list.clear();
     510       14838 :   }
     511             : 
     512             :   /**
     513             :    * Clears the \p _send_list vector and then rebuilds it. This may be needed
     514             :    * in special situations, for example when an algebraic coupling functor cannot
     515             :    * be added to the \p DofMap until after it is completely setup. Then this method
     516             :    * can be used to rebuild the send_list once the algebraic coupling functor is
     517             :    * added. Note that while this will recommunicate constraints with the updated
     518             :    * send_list, this does assume no new constraints have been added since the previous
     519             :    * reinit_constraints call.
     520             :    */
     521             :   void reinit_send_list (MeshBase & mesh);
     522             : 
     523             : 
     524             :   /**
     525             :    * \returns A constant reference to the \p _send_list for this processor.
     526             :    *
     527             :    * The \p _send_list contains the global indices of all the
     528             :    * variables in the global solution vector that influence the
     529             :    * current processor.  This information can be used for gathers at
     530             :    * each solution step to retrieve solution values needed for
     531             :    * computation.
     532             :    */
     533     2693098 :   const std::vector<dof_id_type> & get_send_list() const { return _send_list; }
     534             : 
     535             :   /**
     536             :    * \returns A constant reference to the \p _n_nz list for this processor.
     537             :    *
     538             :    * The vector contains the bandwidth of the on-processor coupling for each
     539             :    * row of the global matrix that the current processor owns.  This
     540             :    * information can be used to preallocate space for a parallel sparse matrix.
     541             :    */
     542             :   const std::vector<dof_id_type> & get_n_nz() const
     543             :   {
     544             :     libmesh_assert(_sp);
     545             :     return _sp->get_n_nz();
     546             :   }
     547             : 
     548             :   /**
     549             :    * \returns A constant reference to the \p _n_oz list for this processor.
     550             :    *
     551             :    * The vector contains the bandwidth of the off-processor coupling for each
     552             :    * row of the global matrix that the current processor owns.  This
     553             :    * information can be used to preallocate space for a parallel sparse matrix.
     554             :    */
     555             :   const std::vector<dof_id_type> & get_n_oz() const
     556             :   {
     557             :     libmesh_assert(_sp);
     558             :     return _sp->get_n_oz();
     559             :   }
     560             : 
     561             : 
     562             :   /**
     563             :    * \returns A constant pointer to the sparsity pattern stored here,
     564             :    * once that has been computed.  Returns null if no sparsity pattern
     565             :    * has yet been computed.
     566             :    *
     567             :    * If need_full_sparsity_pattern is false, the "sparsity pattern"
     568             :    * may only own n_nz and n_oz lists.
     569             :    */
     570         668 :   const SparsityPattern::Build * get_sparsity_pattern() const
     571             :   {
     572         668 :     return _sp.get();
     573             :   }
     574             : 
     575             :   /**
     576             :    * \returns The number of variables in the system
     577             :    */
     578             :   unsigned int n_vars() const;
     579             : 
     580             :   /**
     581             :    * \returns The name of variable \p i.
     582             :    */
     583             :   const std::string & variable_name(const unsigned int i) const;
     584             : 
     585             :   /**
     586             :    * \returns The total number of scalar components in the system's
     587             :    * variables.  This will equal \p n_vars() in the case of all
     588             :    * scalar-valued variables. If vector variables are involved, we
     589             :    * will need to leverage the \p mesh
     590             :    */
     591             :   unsigned int n_components(const MeshBase & mesh) const;
     592             : 
     593             :   /**
     594             :    * \returns \p true when \p VariableGroup structures should be
     595             :    * automatically identified, \p false otherwise.
     596             :    */
     597             :   bool identify_variable_groups () const;
     598             : 
     599             :   /**
     600             :    * Toggle automatic \p VariableGroup identification.
     601             :    */
     602             :   void identify_variable_groups (const bool);
     603             : 
     604             :   /**
     605             :    * \returns An index, starting from 0 for the first component of the
     606             :    * first variable, and incrementing for each component of each
     607             :    * (potentially vector-valued) variable in the system in order.
     608             :    * For systems with only scalar-valued variables, this will be the
     609             :    * same as \p var_num
     610             :    *
     611             :    * Irony: currently our only non-scalar-valued variable type is
     612             :    * SCALAR.
     613             :    */
     614             :   unsigned int variable_scalar_number (unsigned int var_num,
     615             :                                        unsigned int component) const;
     616             : 
     617             :   /**
     618             :    * \returns The finite element type for variable number \p i.
     619             :    */
     620             :   const FEType & variable_type (const unsigned int i) const;
     621             : 
     622             :   /**
     623             :    * \returns The finite element type for variable \p var.
     624             :    */
     625             :   const FEType & variable_type (std::string_view var) const;
     626             : 
     627             :   /**
     628             :    * \returns The variable number associated with
     629             :    * the user-specified variable named \p var.
     630             :    */
     631             :   unsigned int variable_number (std::string_view var) const;
     632             : 
     633             :   /**
     634             :    * \returns \p true if a variable named \p var exists in this System
     635             :    */
     636             :   bool has_variable(std::string_view var) const;
     637             : 
     638             :   /**
     639             :    * Fills \p all_variable_numbers with all the variable numbers for the
     640             :    * variables that have been added to this system.
     641             :    */
     642             :   void get_all_variable_numbers(std::vector<unsigned int> & all_variable_numbers) const;
     643             : 
     644             :   /**
     645             :    * Adds the variable \p var to the list of variables
     646             :    * for this system. If \p active_subdomains is either \p nullptr
     647             :    * (the default) or points to an empty set, then it will be assumed that
     648             :    * \p var has no subdomain restrictions
     649             :    *
     650             :    * \returns The index number for the new variable.
     651             :    */
     652             :   unsigned int add_variable (System & sys,
     653             :                              std::string_view var,
     654             :                              const FEType & type,
     655             :                              const std::set<subdomain_id_type> * const active_subdomains = nullptr);
     656             : 
     657             :   /**
     658             :    * Adds the variables \p vars to the list of variables
     659             :    * for this system. If \p active_subdomains is either \p nullptr
     660             :    * (the default) or points to an empty set, then it will be assumed that
     661             :    * the \p vars have no subdomain restrictions
     662             :    *
     663             :    * \returns The index number for the last of the new variables.
     664             :    */
     665             :   unsigned int add_variables (System & sys,
     666             :                               const std::vector<std::string> & vars,
     667             :                               const FEType & type,
     668             :                               const std::set<subdomain_id_type> * const active_subdomains = nullptr);
     669             : 
     670             :   /**
     671             :    * Adds variables \p vars to the list of variables
     672             :    * for this system. If \p active_subdomains is either \p nullptr
     673             :    * (the default) or points to an empty set, then it will be assumed that
     674             :    * the \p vars have no subdomain restrictions. This API will end up
     675             :    * calling \p this->add_variables(). However, we will additionally store data
     676             :    * that can be leveraged by the \p DofMap to build degrees of freedom
     677             :    * containers corresponding to all the variables in this variable array
     678             :    *
     679             :    * An 'array variable' is simply a sequence
     680             :    * of contiguous variable numbers defined by pair where the first member of the pair
     681             :    * is the first number in the variable sequence and the second member of the pair is
     682             :    * the number of the last variable in the sequence plus one. Array variables may be
     683             :    * used in tandem with variable grouping by downstream code to build optimized physics
     684             :    * kernels since each variable in the array will have the same shape functions.
     685             :    *
     686             :    * \returns The index number for the last of the new variables.
     687             :    */
     688             :   unsigned int add_variable_array (System & sys,
     689             :                                    const std::vector<std::string> & vars,
     690             :                                    const FEType & type,
     691             :                                    const std::set<subdomain_id_type> * const active_subdomains = nullptr);
     692             : 
     693             :   /**
     694             :    * Specify whether or not we perform an extra (opt-mode enabled) check
     695             :    * for constraint loops. If a constraint loop is present then
     696             :    * the system constraints are not valid, so if \p error_on_constraint_loop
     697             :    * is true we will throw an error in this case.
     698             :    *
     699             :    * \note We previously referred to these types of constraints as
     700             :    * "cyclic" but that has now been deprecated, and these will now
     701             :    * instead be referred to as "constraint loops" in libMesh.
     702             :    */
     703             :   void set_error_on_cyclic_constraint(bool error_on_cyclic_constraint);
     704             :   void set_error_on_constraint_loop(bool error_on_constraint_loop);
     705             : 
     706             :   /**
     707             :    * \returns The \p VariableGroup description object for group \p g.
     708             :    */
     709             :   const VariableGroup & variable_group (const unsigned int c) const;
     710             : 
     711             :   const Variable & variable (const unsigned int c) const override;
     712             : 
     713             :   /**
     714             :    * \returns The approximation order for variable \p c.
     715             :    */
     716             :   Order variable_order (const unsigned int c) const;
     717             : 
     718             :   /**
     719             :    * \returns The approximation order for \p VariableGroup \p vg.
     720             :    */
     721             :   Order variable_group_order (const unsigned int vg) const;
     722             : 
     723             :   /**
     724             :    * \returns The finite element type for \p VariableGroup \p vg.
     725             :    */
     726             :   const FEType & variable_group_type (const unsigned int vg) const;
     727             : 
     728             :   /**
     729             :    * \returns The number of variables in the global solution vector. Defaults
     730             :    * to 1, should be 1 for a scalar equation, 3 for 2D incompressible Navier
     731             :    * Stokes (u,v,p), etc...
     732             :    */
     733    12162049 :   unsigned int n_variable_groups() const
     734    24114553 :   { return cast_int<unsigned int>(_variable_groups.size()); }
     735             : 
     736     1373893 :   unsigned int n_variables() const override
     737     1426193 :   { return cast_int<unsigned int>(_variables.size()); }
     738             : 
     739             :   /**
     740             :    * \returns The variable group number that the provided variable number belongs to
     741             :    */
     742             :   unsigned int var_group_from_var_number(unsigned int var_num) const;
     743             : 
     744             :   /**
     745             :    * \returns \p true if the variables are capable of being stored in a blocked
     746             :    * form.  Presently, this means that there can only be one variable group,
     747             :    * and that the group has more than one variable.
     748             :    */
     749       45104 :   bool has_blocked_representation() const
     750             :   {
     751       46548 :     return ((this->n_variable_groups() == 1) && (this->n_variables() > 1));
     752             :   }
     753             : 
     754             :   /**
     755             :    * \returns The block size, if the variables are amenable to block storage.
     756             :    * Otherwise 1.
     757             :    * This routine was originally designed to enable a blocked storage, but
     758             :    * it turns out this information is still super useful for solvers even when
     759             :    * we do not use the blocked storage (e.g., MATMPIBAIJ in PETSc). For example (in PCHMG),
     760             :    * for a system of PDEs, to construct an efficient multilevel preconditioner, we coarsen
     761             :    * the matrix of one single PDE instead of the entire huge matrix. In order to
     762             :    * accomplish this, we need to know many PDEs we have. Another use case,
     763             :    * the fieldsplit preconditioner can be constructed in place with this info without
     764             :    * involving any user efforts.
     765             :    */
     766       46548 :   unsigned int block_size() const
     767             :   {
     768       45238 :     return (this->has_blocked_representation() ? this->n_variables() : 1);
     769             :   }
     770             : 
     771             :   using DofMapBase::n_dofs;
     772             :   /**
     773             :    * \returns The total number of degrees of freedom for a particular
     774             :    * variable \p vn.
     775             :    */
     776             :   dof_id_type n_dofs(const unsigned int vn) const
     777             :   {
     778             :     dof_id_type n = this->n_local_dofs(vn);
     779             :     this->comm().sum(n);
     780             :     return n;
     781             :   }
     782             : 
     783             :   /**
     784             :    * \returns The number of SCALAR dofs.
     785             :    */
     786      267539 :   dof_id_type n_SCALAR_dofs() const { return _n_SCALAR_dofs; }
     787             : 
     788             :   using DofMapBase::n_local_dofs;
     789             :   /**
     790             :    * \returns The number of degrees of freedom on this processor for a
     791             :    * particular variable \p vn.  This is an O(N) operation on serialized or
     792             :    * O(N/Nproc) operation on distributed meshes.
     793             :    */
     794           0 :   dof_id_type n_local_dofs(const unsigned int vn) const
     795             :   {
     796             :     dof_id_type n;
     797           0 :     this->local_variable_indices(n, _mesh, vn);
     798           0 :     return n;
     799             :   }
     800             : 
     801             :   /**
     802             :    * \returns The number of degrees of freedom on each partition for a
     803             :    * particular variable \p vn.
     804             :    */
     805         804 :   std::vector<dof_id_type> n_dofs_per_processor(const unsigned int vn) const
     806             :   {
     807         804 :     std::vector<dof_id_type> n_local_dofs(this->n_processors(), 0);
     808         804 :     this->comm().allgather(this->n_local_dofs(vn), n_local_dofs);
     809         804 :     return n_local_dofs;
     810             :   }
     811             : 
     812             :   /**
     813             :    * \returns The processor id that owns the dof index \p dof
     814             :    */
     815      261363 :   processor_id_type dof_owner(const dof_id_type dof) const
     816             :   { std::vector<dof_id_type>::const_iterator ub =
     817      261363 :       std::upper_bound(_end_df.begin(), _end_df.end(), dof);
     818        7518 :     libmesh_assert (ub != _end_df.end());
     819      261363 :     return cast_int<processor_id_type>(ub - _end_df.begin());
     820             :   }
     821             : 
     822             :   void dof_indices (const Elem * const elem,
     823             :                     std::vector<dof_id_type> & di) const;
     824             : 
     825             :   /**
     826             :    * Fills the vector \p di with the global degree of freedom indices
     827             :    * for the element.  For one variable, and potentially for a
     828             :    * non-default element p refinement level
     829             :    */
     830             :   void dof_indices (const Elem * const elem,
     831             :                     std::vector<dof_id_type> & di,
     832             :                     const unsigned int vn,
     833             :                     int p_level = -12345) const override;
     834             : 
     835             :   /**
     836             :    * Fills the vector \p di with the global degree of freedom indices
     837             :    * for the element. This will aggregate all the degrees of the freedom
     838             :    * from the variable array that \p vn is a member of, and potentially for a
     839             :    * non-default element p refinement level
     840             :    */
     841             :   void array_dof_indices(const Elem * const elem,
     842             :                          std::vector<dof_id_type> & di,
     843             :                          const unsigned int vn,
     844             :                          int p_level = -12345) const;
     845             : 
     846             :   void array_dof_indices(const Node * const node,
     847             :                          std::vector<dof_id_type> & di,
     848             :                          const unsigned int vn) const;
     849             : 
     850             :   template <typename DofIndicesFunctor>
     851             :   void array_dof_indices(const DofIndicesFunctor & functor,
     852             :                          std::vector<dof_id_type> & di,
     853             :                          const unsigned int vn) const;
     854             : 
     855             :   /**
     856             :    * Retrieves degree of freedom indices for a given \p elem and then performs actions for these
     857             :    * indices defined by the user-provided functors \p scalar_dofs_functor and \p field_dofs_functor.
     858             :    * This API is useful when a user wants to do more than simply fill a degree of freedom container
     859             :    * @param elem The element to get degrees of freedom for
     860             :    * @param di A container for degrees of freedom. It is up to the provided functors how this gets
     861             :    *           filled
     862             :    * @param vn The variable number to retrieve degrees of freedom for
     863             :    * @param scalar_dofs_functor The functor that acts on scalar degrees of freedom. This functor has
     864             :    *                            the interface:
     865             :    *                            void scalar_dofs_functor(const Elem & elem,
     866             :    *                                                    std::vector<dof_id_type> & di,
     867             :    *                                                    const std::vector<dof_id_type> & scalar_dof_indices)
     868             :    *                            where \p di is the degree of freedom container described above and
     869             :    *                            \p scalar_dof_indices are the scalar dof indices available to
     870             :    *                            \p elem
     871             :    * @param field_dofs_functor The functor that acts on "field" (e.g. non-scalar, non-global)
     872             :    *                           degrees of freedom. This functor has
     873             :    *                           the interface:
     874             :    *                           void field_dofs_functor(const Elem & elem,
     875             :    *                                                   const unsigned int node_num,
     876             :    *                                                   const unsigned int var_num,
     877             :    *                                                   std::vector<dof_id_type> & di,
     878             :    *                                                   const dof_id_type field_dof)
     879             :    *                           where \p field_dof represents a field degree of freedom to act on and
     880             :    *                           is associated with \p node_num and \p var_num. If the degree of
     881             :    *                           freedom is elemental than \p node_num will be \p invalid_uint. \p di
     882             :    *                           is again the degree of freedom container provided above
     883             :    */
     884             :   template <typename ScalarDofsFunctor, typename FieldDofsFunctor>
     885             :   void dof_indices(const Elem * const elem,
     886             :                    std::vector<dof_id_type> & di,
     887             :                    const unsigned int vn,
     888             :                    ScalarDofsFunctor scalar_dofs_functor,
     889             :                    FieldDofsFunctor field_dofs_functor,
     890             :                    int p_level = -12345) const;
     891             : 
     892             :   /**
     893             :    * Fills the vector \p di with the global degree of freedom indices
     894             :    * for the \p node.
     895             :    */
     896             :   void dof_indices (const Node * const node,
     897             :                     std::vector<dof_id_type> & di) const;
     898             : 
     899             :   /**
     900             :    * Fills the vector \p di with the global degree of freedom indices
     901             :    * for the \p node, for one variable \p vn.
     902             :    */
     903             :   void dof_indices (const Node * const node,
     904             :                     std::vector<dof_id_type> & di,
     905             :                     const unsigned int vn) const override;
     906             : 
     907             :   /**
     908             :    * Appends to the vector \p di the global degree of freedom indices
     909             :    * for \p elem.node_ref(n), for one variable \p vn.  On hanging
     910             :    * nodes with both vertex and non-vertex DoFs, only those indices
     911             :    * which are directly supported on \p elem are included.
     912             :    */
     913             :   void dof_indices (const Elem & elem,
     914             :                     unsigned int n,
     915             :                     std::vector<dof_id_type> & di,
     916             :                     const unsigned int vn) const;
     917             : 
     918             : #ifdef LIBMESH_ENABLE_AMR
     919             : 
     920             :   /**
     921             :    * Appends to the vector \p di the old global degree of freedom
     922             :    * indices for \p elem.node_ref(n), for one variable \p vn.  On
     923             :    * hanging nodes with both vertex and non-vertex DoFs, only those
     924             :    * indices which are directly supported on \p elem are included.
     925             :    */
     926             :   void old_dof_indices (const Elem & elem,
     927             :                         unsigned int n,
     928             :                         std::vector<dof_id_type> & di,
     929             :                         const unsigned int vn) const;
     930             : 
     931             : #endif // LIBMESH_ENABLE_AMR
     932             : 
     933             :   /**
     934             :    * Fills the vector \p di with the global degree of freedom indices
     935             :    * corresponding to the SCALAR variable vn. If old_dofs=true,
     936             :    * the old SCALAR dof indices are returned.
     937             :    *
     938             :    * \note We do not need to pass in an element since SCALARs are
     939             :    * global variables.
     940             :    */
     941             :   void SCALAR_dof_indices (std::vector<dof_id_type> & di,
     942             :                            const unsigned int vn,
     943             :                            const bool old_dofs=false) const;
     944             : 
     945             :   /**
     946             :    * \returns \p true if degree of freedom index \p dof_index
     947             :    * is either a local index or in the \p send_list.
     948             :    *
     949             :    * \note This is an O(logN) operation for a send_list of size N; we
     950             :    * don't cache enough information for O(1) right now.
     951             :    */
     952             :   bool semilocal_index (dof_id_type dof_index) const;
     953             : 
     954             :   /**
     955             :    * \returns \p true if all degree of freedom indices in \p
     956             :    * dof_indices are either local indices or in the \p send_list.
     957             :    *
     958             :    * \note This is an O(logN) operation for a send_list of size N; we
     959             :    * don't cache enough information for O(1) right now.
     960             :    */
     961             :   bool all_semilocal_indices (const std::vector<dof_id_type> & dof_indices) const;
     962             : 
     963             :   /**
     964             :    * \returns \p true if degree of freedom index \p dof_index
     965             :    * is a local index.
     966             :    */
     967    80001153 :   bool local_index (dof_id_type dof_index) const
     968    86907480 :   { return (dof_index >= this->first_dof()) && (dof_index < this->end_dof()); }
     969             : 
     970             :   /**
     971             :    * \returns \p true iff our solutions can be locally evaluated on
     972             :    * \p obj (which should be an Elem or a Node) for variable number \p
     973             :    * var_num (for all variables, if \p var_num is invalid_uint)
     974             :    */
     975             :   template <typename DofObjectSubclass>
     976             :   bool is_evaluable(const DofObjectSubclass & obj,
     977             :                     unsigned int var_num = libMesh::invalid_uint) const;
     978             : 
     979             :   /**
     980             :    * Allow the implicit_neighbor_dofs flag to be set programmatically.
     981             :    * This overrides the --implicit_neighbor_dofs commandline option.
     982             :    * We can use this to set the implicit neighbor dofs option differently
     983             :    * for different systems, whereas the commandline option is the same
     984             :    * for all systems.
     985             :    */
     986             :   void set_implicit_neighbor_dofs(bool implicit_neighbor_dofs);
     987             : 
     988             :   /**
     989             :    * Set the _verify_dirichlet_bc_consistency flag.
     990             :    */
     991             :   void set_verify_dirichlet_bc_consistency(bool val);
     992             : 
     993             :   /**
     994             :    * Tells other library functions whether or not this problem
     995             :    * includes coupling between dofs in neighboring cells, as can
     996             :    * currently be specified on the command line or inferred from
     997             :    * the use of all discontinuous variables.
     998             :    */
     999             :   bool use_coupled_neighbor_dofs(const MeshBase & mesh) const;
    1000             : 
    1001             :   /**
    1002             :    * Builds the local element vector \p Ue from the global vector \p Ug,
    1003             :    * accounting for any constrained degrees of freedom.  For an element
    1004             :    * without constrained degrees of freedom this is the trivial mapping
    1005             :    * \f$ Ue[i] = Ug[dof_indices[i]] \f$
    1006             :    *
    1007             :    * \note The user must ensure that the element vector \p Ue is
    1008             :    * properly sized when calling this method.  This is because there
    1009             :    * is no \p resize() method in the \p DenseVectorBase<> class.
    1010             :    */
    1011             :   void extract_local_vector (const NumericVector<Number> & Ug,
    1012             :                              const std::vector<dof_id_type> & dof_indices,
    1013             :                              DenseVectorBase<Number> & Ue) const;
    1014             : 
    1015             :   /**
    1016             :    * If T == dof_id_type, counts, if T == std::vector<dof_id_type>, fills an
    1017             :    * array of, those dof indices which belong to the given variable number and
    1018             :    * live on the current processor.
    1019             :    */
    1020             :   template <typename T, std::enable_if_t<std::is_same_v<T, dof_id_type> ||
    1021             :                                          std::is_same_v<T, std::vector<dof_id_type>>, int> = 0>
    1022             :   void local_variable_indices(T & idx,
    1023             :                               const MeshBase & mesh,
    1024             :                               unsigned int var_num) const;
    1025             : 
    1026             :   /**
    1027             :    * If T == dof_id_type, counts, if T == std::vector<dof_id_type>, fills an
    1028             :    * array of, those dof indices which belong to the given variable number and
    1029             :    * live on the current processor.
    1030             :    */
    1031             :   template <typename T,
    1032             :             std::enable_if_t<std::is_same_v<T, dof_id_type> ||
    1033             :                                  std::is_same_v<T, std::vector<dof_id_type>>,
    1034             :                              int> = 0>
    1035             :   void local_variable_indices(T & idx, unsigned int var_num) const
    1036             :   { this->local_variable_indices(idx, this->_mesh, var_num); }
    1037             : 
    1038             : #ifdef LIBMESH_ENABLE_CONSTRAINTS
    1039             : 
    1040             :   //--------------------------------------------------------------------
    1041             :   // Constraint-specific methods
    1042             :   /**
    1043             :    * \returns The total number of constrained degrees of freedom
    1044             :    * in the problem.
    1045             :    */
    1046             :   dof_id_type n_constrained_dofs() const;
    1047             : 
    1048             :   /**
    1049             :    * \returns The number of constrained degrees of freedom
    1050             :    * on this processor.
    1051             :    */
    1052             :   dof_id_type n_local_constrained_dofs() const;
    1053             : 
    1054             : #ifdef LIBMESH_ENABLE_NODE_CONSTRAINTS
    1055             :   /**
    1056             :    * \returns The total number of constrained Nodes
    1057             :    * in the mesh.
    1058             :    */
    1059             :   dof_id_type n_constrained_nodes() const
    1060             :   { return cast_int<dof_id_type>(_node_constraints.size()); }
    1061             : #endif // LIBMESH_ENABLE_NODE_CONSTRAINTS
    1062             : 
    1063             :   /**
    1064             :    * Rebuilds the raw degree of freedom and DofObject constraints,
    1065             :    * based on attached DirichletBoundary objects and on non-conforming
    1066             :    * interface in adapted meshes.
    1067             :    *
    1068             :    * A time is specified for use in building time-dependent Dirichlet
    1069             :    * constraints.
    1070             :    */
    1071             :   void create_dof_constraints (const MeshBase &, Real time=0);
    1072             : 
    1073             :   /**
    1074             :    * Gathers constraint equation dependencies from other processors
    1075             :    */
    1076             :   void allgather_recursive_constraints (MeshBase &);
    1077             : 
    1078             :   /**
    1079             :    * Sends constraint equations to constraining processors
    1080             :    */
    1081             :   void scatter_constraints (MeshBase &);
    1082             : 
    1083             :   /**
    1084             :    * Helper function for querying about constraint equations on other
    1085             :    * processors.  If any id in \p requested_dof_ids is constrained on
    1086             :    * another processor, its constraint will be added on this processor
    1087             :    * as well.  If \p look_for_constrainees is true, then constraints
    1088             :    * will also be returned if the id appears as a constraining value
    1089             :    * not just if it appears as a constrained value.
    1090             :    *
    1091             :    * This function operates recursively: if the constraint for a
    1092             :    * constrained dof is newly added locally, then any other dofs which
    1093             :    * constrain it are queried to see if they are in turn constrained,
    1094             :    * and so on.
    1095             :    */
    1096             :   void gather_constraints (MeshBase & mesh,
    1097             :                            std::set<dof_id_type> & unexpanded_dofs,
    1098             :                            bool look_for_constrainees);
    1099             : 
    1100             :   /**
    1101             :    * Postprocesses any constrained degrees of freedom
    1102             :    * to be constrained only in terms of unconstrained dofs, then adds
    1103             :    * unconstrained dofs to the send_list and prepares that for use.
    1104             :    * This should be run after both system (create_dof_constraints) and
    1105             :    * user constraints have all been added.
    1106             :    */
    1107             :   void process_constraints (MeshBase &);
    1108             : 
    1109             :   /**
    1110             :    * Throw an error if we detect any constraint loops, i.e.
    1111             :    * A -> B -> C -> A
    1112             :    * that is, "dof A is constrained in terms of dof B which is
    1113             :    * constrained in terms of dof C which is constrained in terms of
    1114             :    * dof A", since these are not supported by libMesh and give
    1115             :    * erroneous results if they are present.
    1116             :    *
    1117             :    * \note The original "cyclic constraint" terminology was
    1118             :    * unfortunate since the word cyclic is used by some software to
    1119             :    * indicate an actual type of rotational/angular constraint and not
    1120             :    * (as here) a cyclic graph. The former nomenclature will eventually
    1121             :    * be deprecated in favor of "constraint loop".
    1122             :    */
    1123             :   void check_for_cyclic_constraints();
    1124             :   void check_for_constraint_loops();
    1125             : 
    1126             :   /**
    1127             :    * Adds a copy of the user-defined row to the constraint matrix, using
    1128             :    * an inhomogeneous right-hand-side for the constraint equation.
    1129             :    */
    1130             :   void add_constraint_row (const dof_id_type dof_number,
    1131             :                            const DofConstraintRow & constraint_row,
    1132             :                            const Number constraint_rhs,
    1133             :                            const bool forbid_constraint_overwrite);
    1134             : 
    1135             :   /**
    1136             :    * Adds a copy of the user-defined row to the constraint matrix,
    1137             :    * using an inhomogeneous right-hand-side for the adjoint constraint
    1138             :    * equation.
    1139             :    *
    1140             :    * \p forbid_constraint_overwrite here only tests for overwriting
    1141             :    * the rhs.  This method should only be used when an equivalent
    1142             :    * constraint (with a potentially different rhs) already exists for
    1143             :    * the primal problem.
    1144             :    */
    1145             :   void add_adjoint_constraint_row (const unsigned int qoi_index,
    1146             :                                    const dof_id_type dof_number,
    1147             :                                    const DofConstraintRow & constraint_row,
    1148             :                                    const Number constraint_rhs,
    1149             :                                    const bool forbid_constraint_overwrite);
    1150             : 
    1151             :   /**
    1152             :    * Adds a copy of the user-defined row to the constraint matrix, using
    1153             :    * a homogeneous right-hand-side for the constraint equation.
    1154             :    * By default, produces an error if the DOF was already constrained.
    1155             :    */
    1156       19370 :   void add_constraint_row (const dof_id_type dof_number,
    1157             :                            const DofConstraintRow & constraint_row,
    1158             :                            const bool forbid_constraint_overwrite = true)
    1159      232736 :   { add_constraint_row(dof_number, constraint_row, 0., forbid_constraint_overwrite); }
    1160             : 
    1161             :   /**
    1162             :    * \returns An iterator pointing to the first DoF constraint row.
    1163             :    */
    1164             :   DofConstraints::const_iterator constraint_rows_begin() const
    1165             :   { return _dof_constraints.begin(); }
    1166             : 
    1167             :   /**
    1168             :    * \returns An iterator pointing just past the last DoF constraint row.
    1169             :    */
    1170             :   DofConstraints::const_iterator constraint_rows_end() const
    1171             :   { return _dof_constraints.end(); }
    1172             : 
    1173             :   /**
    1174             :    * Provide a const accessor to the DofConstraints map. This allows the user
    1175             :    * to quickly search the data structure rather than just iterating over it.
    1176             :    */
    1177      221857 :   const DofConstraints & get_dof_constraints() const { return _dof_constraints; }
    1178             : 
    1179             :   void stash_dof_constraints()
    1180             :   {
    1181             :     libmesh_assert(_stashed_dof_constraints.empty());
    1182             :     _dof_constraints.swap(_stashed_dof_constraints);
    1183             :   }
    1184             : 
    1185             :   void unstash_dof_constraints()
    1186             :   {
    1187             :     libmesh_assert(_dof_constraints.empty());
    1188             :     _dof_constraints.swap(_stashed_dof_constraints);
    1189             :   }
    1190             : 
    1191             :   /**
    1192             :    * Similar to the stash/unstash_dof_constraints() API, but swaps
    1193             :    * _dof_constraints and _stashed_dof_constraints without asserting
    1194             :    * that the source or destination is empty first.
    1195             :    *
    1196             :    * \note There is an implicit assumption that swapping between sets
    1197             :    * of Constraints does not change the sparsity pattern or expand the
    1198             :    * send_list, since the only thing changed is the DofConstraints
    1199             :    * themselves.  This is intended to work for swapping between
    1200             :    * DofConstraints A and B, where A is used to define the send_list,
    1201             :    * and B is a subset of A.
    1202             :    */
    1203             :   void swap_dof_constraints()
    1204             :   {
    1205             :     _dof_constraints.swap(_stashed_dof_constraints);
    1206             :   }
    1207             : 
    1208             : #ifdef LIBMESH_ENABLE_NODE_CONSTRAINTS
    1209             :   /**
    1210             :    * \returns An iterator pointing to the first Node constraint row.
    1211             :    */
    1212             :   NodeConstraints::const_iterator node_constraint_rows_begin() const
    1213             :   { return _node_constraints.begin(); }
    1214             : 
    1215             :   /**
    1216             :    * \returns An iterator pointing just past the last Node constraint row.
    1217             :    */
    1218             :   NodeConstraints::const_iterator node_constraint_rows_end() const
    1219             :   { return _node_constraints.end(); }
    1220             : #endif // LIBMESH_ENABLE_NODE_CONSTRAINTS
    1221             : 
    1222             :   /**
    1223             :    * \returns \p true if the degree of freedom dof is constrained,
    1224             :    * \p false otherwise.
    1225             :    */
    1226             :   bool is_constrained_dof (const dof_id_type dof) const;
    1227             : 
    1228             :   /**
    1229             :    * \returns \p true if the system has any heterogeneous constraints for
    1230             :    * adjoint solution \p qoi_num, \p false otherwise.
    1231             :    */
    1232             :   bool has_heterogeneous_adjoint_constraints (const unsigned int qoi_num) const;
    1233             : 
    1234             :   /**
    1235             :    * Backwards compatibility with misspelling.
    1236             :    */
    1237        4796 :   bool has_heterogenous_adjoint_constraints (const unsigned int qoi_num) const
    1238             :   {
    1239       83110 :     return this->has_heterogeneous_adjoint_constraints (qoi_num);
    1240             :   }
    1241             : 
    1242             :   /**
    1243             :    * \returns The heterogeneous constraint value if the degree of
    1244             :    * freedom \p dof has a heterogeneous constraint for adjoint solution
    1245             :    * \p qoi_num, zero otherwise.
    1246             :    */
    1247             :   Number has_heterogeneous_adjoint_constraint (const unsigned int qoi_num,
    1248             :                                                const dof_id_type dof) const;
    1249             : 
    1250             :   /**
    1251             :    * Backwards compatibility with misspelling.
    1252             :    */
    1253     1094202 :   Number has_heterogenous_adjoint_constraint (const unsigned int qoi_num,
    1254             :                                               const dof_id_type dof) const
    1255             :   {
    1256     1415182 :     return this->has_heterogeneous_adjoint_constraint (qoi_num, dof);
    1257             :   }
    1258             : 
    1259             :   /**
    1260             :    * \returns A reference to the set of right-hand-side values in
    1261             :    * primal constraint equations
    1262             :    */
    1263             :   DofConstraintValueMap & get_primal_constraint_values();
    1264             : 
    1265             :   /**
    1266             :    * \returns \p true if the Node is constrained,
    1267             :    * false otherwise.
    1268             :    */
    1269             :   bool is_constrained_node (const Node * node) const;
    1270             : 
    1271             :   /**
    1272             :    * Prints (from processor 0) all DoF and Node constraints.  If \p
    1273             :    * print_nonlocal is true, then each constraint is printed once for
    1274             :    * each processor that knows about it, which may be useful for \p
    1275             :    * DistributedMesh debugging.
    1276             :    */
    1277             :   void print_dof_constraints(std::ostream & os=libMesh::out,
    1278             :                              bool print_nonlocal=false) const;
    1279             : 
    1280             :   /**
    1281             :    * Gets a string reporting all DoF and Node constraints local to
    1282             :    * this processor.  If \p print_nonlocal is true, then nonlocal
    1283             :    * constraints which are locally known are included.
    1284             :    */
    1285             :   std::string get_local_constraints(bool print_nonlocal=false) const;
    1286             : 
    1287             : 
    1288             :   /**
    1289             :    * Tests the constrained degrees of freedom on the numeric vector \p v, which
    1290             :    * represents a solution defined on the mesh, returning a pair whose first
    1291             :    * entry is the maximum absolute error on a constrained DoF and whose second
    1292             :    * entry is the maximum relative error.  Useful for debugging purposes.
    1293             :    *
    1294             :    * If \p v == nullptr, the system solution vector is tested.
    1295             :    */
    1296             :   std::pair<Real, Real> max_constraint_error(const System & system,
    1297             :                                              NumericVector<Number> * v = nullptr) const;
    1298             : 
    1299             : #endif // LIBMESH_ENABLE_CONSTRAINTS
    1300             : 
    1301             :   //--------------------------------------------------------------------
    1302             :   // Constraint-specific methods
    1303             :   // Some of these methods are enabled (but inlined away to nothing)
    1304             :   // when constraints are disabled at configure-time.  This is to
    1305             :   // increase API compatibility of user code with different library
    1306             :   // builds.
    1307             : 
    1308             :   /**
    1309             :    * Constrains the element matrix.  This method requires the
    1310             :    * element matrix to be square, in which case the elem_dofs
    1311             :    * correspond to the global DOF indices of both the rows and
    1312             :    * columns of the element matrix.  For this case the rows
    1313             :    * and columns of the matrix necessarily correspond to variables
    1314             :    * of the same approximation order.
    1315             :    *
    1316             :    * If \p asymmetric_constraint_rows is set to true (as it is by
    1317             :    * default), constraint row equations will be reinforced in a way
    1318             :    * which breaks matrix symmetry but makes inexact linear solver
    1319             :    * solutions more likely to satisfy hanging node constraints.
    1320             :    */
    1321             :   void constrain_element_matrix (DenseMatrix<Number> & matrix,
    1322             :                                  std::vector<dof_id_type> & elem_dofs,
    1323             :                                  bool asymmetric_constraint_rows = true) const;
    1324             : 
    1325             :   /**
    1326             :    * Constrains the element matrix.  This method allows the
    1327             :    * element matrix to be non-square, in which case the row_dofs
    1328             :    * and col_dofs may be of different size and correspond to
    1329             :    * variables approximated in different spaces.
    1330             :    */
    1331             :   void constrain_element_matrix (DenseMatrix<Number> & matrix,
    1332             :                                  std::vector<dof_id_type> & row_dofs,
    1333             :                                  std::vector<dof_id_type> & col_dofs,
    1334             :                                  bool asymmetric_constraint_rows = true) const;
    1335             : 
    1336             :   /**
    1337             :    * Constrains the element vector.
    1338             :    */
    1339             :   void constrain_element_vector (DenseVector<Number> & rhs,
    1340             :                                  std::vector<dof_id_type> & dofs,
    1341             :                                  bool asymmetric_constraint_rows = true) const;
    1342             : 
    1343             :   /**
    1344             :    * Constrains the element matrix and vector.  This method requires
    1345             :    * the element matrix to be square, in which case the elem_dofs
    1346             :    * correspond to the global DOF indices of both the rows and
    1347             :    * columns of the element matrix.  For this case the rows
    1348             :    * and columns of the matrix necessarily correspond to variables
    1349             :    * of the same approximation order.
    1350             :    */
    1351             :   void constrain_element_matrix_and_vector (DenseMatrix<Number> & matrix,
    1352             :                                             DenseVector<Number> & rhs,
    1353             :                                             std::vector<dof_id_type> & elem_dofs,
    1354             :                                             bool asymmetric_constraint_rows = true) const;
    1355             : 
    1356             :   /**
    1357             :    * Constrains the element matrix and vector.  This method requires
    1358             :    * the element matrix to be square, in which case the elem_dofs
    1359             :    * correspond to the global DOF indices of both the rows and
    1360             :    * columns of the element matrix.  For this case the rows
    1361             :    * and columns of the matrix necessarily correspond to variables
    1362             :    * of the same approximation order.
    1363             :    *
    1364             :    * The heterogeneous version of this method creates linear systems in
    1365             :    * which heterogeneously constrained degrees of freedom will solve to
    1366             :    * their correct offset values, as would be appropriate for finding
    1367             :    * a solution to a linear problem in a single algebraic solve.  The
    1368             :    * non-heterogeneous version of this method creates linear systems in
    1369             :    * which even heterogeneously constrained degrees of freedom are
    1370             :    * solved without offset values taken into account, as would be
    1371             :    * appropriate for finding linearized updates to a solution in which
    1372             :    * heterogeneous constraints are already satisfied.
    1373             :    *
    1374             :    * By default, the constraints for the primal solution of this
    1375             :    * system are used.  If a non-negative \p qoi_index is passed in,
    1376             :    * then the constraints for the corresponding adjoint solution are
    1377             :    * used instead.
    1378             :    */
    1379             :   void heterogeneously_constrain_element_matrix_and_vector (DenseMatrix<Number> & matrix,
    1380             :                                                             DenseVector<Number> & rhs,
    1381             :                                                             std::vector<dof_id_type> & elem_dofs,
    1382             :                                                             bool asymmetric_constraint_rows = true,
    1383             :                                                             int qoi_index = -1) const;
    1384             : 
    1385             :   /*
    1386             :    * Backwards compatibility with misspelling.
    1387             :    */
    1388           0 :   void heterogenously_constrain_element_matrix_and_vector (DenseMatrix<Number> & matrix,
    1389             :                                                            DenseVector<Number> & rhs,
    1390             :                                                            std::vector<dof_id_type> & elem_dofs,
    1391             :                                                            bool asymmetric_constraint_rows = true,
    1392             :                                                            int qoi_index = -1) const
    1393             :   {
    1394             :     return this->heterogeneously_constrain_element_matrix_and_vector
    1395       15527 :       (matrix, rhs, elem_dofs, asymmetric_constraint_rows, qoi_index);
    1396             :   }
    1397             : 
    1398             :   /**
    1399             :    * Constrains the element vector.  This method requires
    1400             :    * the element matrix to be square and not-yet-constrained, in which
    1401             :    * case the elem_dofs correspond to the global DOF indices of both
    1402             :    * the rows and columns of the element matrix.
    1403             :    *
    1404             :    * The heterogeneous version of this method creates linear systems in
    1405             :    * which heterogeneously constrained degrees of freedom will solve to
    1406             :    * their correct offset values, as would be appropriate for finding
    1407             :    * a solution to a linear problem in a single algebraic solve.  The
    1408             :    * non-heterogeneous version of this method creates linear systems in
    1409             :    * which even heterogeneously constrained degrees of freedom are
    1410             :    * solved without offset values taken into account, as would be
    1411             :    * appropriate for finding linearized updates to a solution in which
    1412             :    * heterogeneous constraints are already satisfied.
    1413             :    *
    1414             :    * Note the sign difference from the nonlinear heterogeneous constraint
    1415             :    * method: Solving u:=K\f has the opposite sign convention from
    1416             :    * u:=u_in-J\r, and we apply heterogeneous constraints accordingly.
    1417             :    *
    1418             :    * By default, the constraints for the primal solution of this
    1419             :    * system are used.  If a non-negative \p qoi_index is passed in,
    1420             :    * then the constraints for the corresponding adjoint solution are
    1421             :    * used instead.
    1422             :    */
    1423             :   void heterogeneously_constrain_element_vector (const DenseMatrix<Number> & matrix,
    1424             :                                                  DenseVector<Number> & rhs,
    1425             :                                                  std::vector<dof_id_type> & elem_dofs,
    1426             :                                                  bool asymmetric_constraint_rows = true,
    1427             :                                                  int qoi_index = -1) const;
    1428             : 
    1429             :   /*
    1430             :    * Backwards compatibility with misspelling.
    1431             :    */
    1432         140 :   void heterogenously_constrain_element_vector (const DenseMatrix<Number> & matrix,
    1433             :                                                 DenseVector<Number> & rhs,
    1434             :                                                 std::vector<dof_id_type> & elem_dofs,
    1435             :                                                 bool asymmetric_constraint_rows = true,
    1436             :                                                 int qoi_index = -1) const
    1437             :   {
    1438             :     return this->heterogeneously_constrain_element_vector
    1439        1680 :       (matrix, rhs, elem_dofs, asymmetric_constraint_rows, qoi_index);
    1440             :   }
    1441             : 
    1442             :   /**
    1443             :    * Constrains the element Jacobian and residual.  The element
    1444             :    * Jacobian is square, and the elem_dofs should correspond to the
    1445             :    * global DOF indices of both the rows and columns of the element
    1446             :    * matrix.
    1447             :    *
    1448             :    * The residual-constraining version of this method creates linear
    1449             :    * systems in which heterogeneously constrained degrees of freedom
    1450             :    * create non-zero residual terms when not at their correct offset
    1451             :    * values, as would be appropriate for finding a solution to a
    1452             :    * nonlinear problem in a quasi-Newton solve.
    1453             :    *
    1454             :    * Note the sign difference from the linear heterogeneous constraint
    1455             :    * method: Solving u:=u_in-J\r has the opposite sign convention from
    1456             :    * u:=K\f, and we apply heterogeneous constraints accordingly.
    1457             :    *
    1458             :    * The \p solution vector passed in should be a serialized or
    1459             :    * ghosted primal solution
    1460             :    */
    1461             :   void heterogeneously_constrain_element_jacobian_and_residual (DenseMatrix<Number> & matrix,
    1462             :                                                                 DenseVector<Number> & rhs,
    1463             :                                                                 std::vector<dof_id_type> & elem_dofs,
    1464             :                                                                 NumericVector<Number> & solution_local) const;
    1465             : 
    1466             :   /**
    1467             :    * Constrains the element residual.  The element Jacobian is square,
    1468             :    * and the elem_dofs should correspond to the global DOF indices of
    1469             :    * both the rows and columns of the element matrix.
    1470             :    *
    1471             :    * The residual-constraining version of this method creates linear
    1472             :    * systems in which heterogeneously constrained degrees of freedom
    1473             :    * create non-zero residual terms when not at their correct offset
    1474             :    * values, as would be appropriate for finding a solution to a
    1475             :    * nonlinear problem in a quasi-Newton solve.
    1476             :    *
    1477             :    * The \p solution vector passed in should be a serialized or
    1478             :    * ghosted primal solution
    1479             :    */
    1480             :   void heterogeneously_constrain_element_residual (DenseVector<Number> & rhs,
    1481             :                                                    std::vector<dof_id_type> & elem_dofs,
    1482             :                                                    NumericVector<Number> & solution_local) const;
    1483             : 
    1484             : 
    1485             :   /**
    1486             :    * Constrains the element residual.  The element Jacobian is square,
    1487             :    * and the elem_dofs should correspond to the global DOF indices of
    1488             :    * both the rows and columns of the element matrix, and the dof
    1489             :    * constraint should not include any heterogeneous terms.
    1490             :    *
    1491             :    * The residual-constraining version of this method creates linear
    1492             :    * systems in which heterogeneously constrained degrees of freedom
    1493             :    * create non-zero residual terms when not at their correct offset
    1494             :    * values, as would be appropriate for finding a solution to a
    1495             :    * nonlinear problem in a quasi-Newton solve.
    1496             :    *
    1497             :    * The \p solution vector passed in should be a serialized or
    1498             :    * ghosted primal solution
    1499             :    */
    1500             :   void constrain_element_residual (DenseVector<Number> & rhs,
    1501             :                                    std::vector<dof_id_type> & elem_dofs,
    1502             :                                    NumericVector<Number> & solution_local) const;
    1503             : 
    1504             :   /**
    1505             :    * Constrains a dyadic element matrix B = v w'.  This method
    1506             :    * requires the element matrix to be square, in which case the
    1507             :    * elem_dofs correspond to the global DOF indices of both the rows
    1508             :    * and columns of the element matrix.  For this case the rows and
    1509             :    * columns of the matrix necessarily correspond to variables of the
    1510             :    * same approximation order.
    1511             :    */
    1512             :   void constrain_element_dyad_matrix (DenseVector<Number> & v,
    1513             :                                       DenseVector<Number> & w,
    1514             :                                       std::vector<dof_id_type> & row_dofs,
    1515             :                                       bool asymmetric_constraint_rows = true) const;
    1516             : 
    1517             :   /**
    1518             :    * Does not actually constrain anything, but modifies \p dofs in the
    1519             :    * same way as any of the constrain functions would do, i.e. adds
    1520             :    * those dofs in terms of which any of the existing dofs is
    1521             :    * constrained.
    1522             :    */
    1523             :   void constrain_nothing (std::vector<dof_id_type> & dofs) const;
    1524             : 
    1525             :   /**
    1526             :    * Constrains the numeric vector \p v, which represents a solution defined on
    1527             :    * the mesh.  This may need to be used after a linear solve, if your linear
    1528             :    * solver's solutions do not satisfy your DoF constraints to a tight enough
    1529             :    * tolerance.
    1530             :    *
    1531             :    * If \p v == nullptr, the system solution vector is constrained
    1532             :    *
    1533             :    * If \p homogeneous == true, heterogeneous constraints are enforced
    1534             :    * as if they were homogeneous.  This might be appropriate for e.g. a
    1535             :    * vector representing a difference between two
    1536             :    * heterogeneously-constrained solutions.
    1537             :    */
    1538             :   void enforce_constraints_exactly (const System & system,
    1539             :                                     NumericVector<Number> * v = nullptr,
    1540             :                                     bool homogeneous = false) const;
    1541             : 
    1542             :   /**
    1543             :    * Heterogeneously constrains the numeric vector \p v, which
    1544             :    * represents an adjoint solution defined on the mesh for quantity
    1545             :    * fo interest \p q.  For homogeneous constraints, use \p
    1546             :    * enforce_constraints_exactly instead
    1547             :    */
    1548             :   void enforce_adjoint_constraints_exactly (NumericVector<Number> & v,
    1549             :                                             unsigned int q) const;
    1550             : 
    1551             :   void enforce_constraints_on_residual (const NonlinearImplicitSystem & system,
    1552             :                                         NumericVector<Number> * rhs,
    1553             :                                         NumericVector<Number> const * solution,
    1554             :                                         bool homogeneous = true) const;
    1555             : 
    1556             :   void enforce_constraints_on_jacobian (const NonlinearImplicitSystem & system,
    1557             :                                         SparseMatrix<Number> * jac) const;
    1558             : 
    1559             : #ifdef LIBMESH_ENABLE_PERIODIC
    1560             : 
    1561             :   //--------------------------------------------------------------------
    1562             :   // PeriodicBoundary-specific methods
    1563             : 
    1564             :   /**
    1565             :    * Adds a copy of the specified periodic boundary to the system.
    1566             :    */
    1567             :   void add_periodic_boundary (const PeriodicBoundaryBase & periodic_boundary);
    1568             : 
    1569             :   /**
    1570             :    * Add a periodic boundary pair
    1571             :    *
    1572             :    * \param boundary - primary boundary
    1573             :    * \param inverse_boundary - inverse boundary
    1574             :    */
    1575             :   void add_periodic_boundary (const PeriodicBoundaryBase & boundary, const PeriodicBoundaryBase & inverse_boundary);
    1576             : 
    1577             :   /**
    1578             :    * \returns \p true if the boundary given by \p boundaryid is periodic,
    1579             :    * false otherwise
    1580             :    */
    1581             :   bool is_periodic_boundary (const boundary_id_type boundaryid) const;
    1582             : 
    1583             :   PeriodicBoundaries * get_periodic_boundaries()
    1584             :   {
    1585             :     return _periodic_boundaries.get();
    1586             :   }
    1587             : 
    1588             :   const PeriodicBoundaries * get_periodic_boundaries() const
    1589             :   {
    1590             :     return _periodic_boundaries.get();
    1591             :   }
    1592             : 
    1593             : #endif // LIBMESH_ENABLE_PERIODIC
    1594             : 
    1595             : 
    1596             : #ifdef LIBMESH_ENABLE_DIRICHLET
    1597             : 
    1598             :   //--------------------------------------------------------------------
    1599             :   // DirichletBoundary-specific methods
    1600             : 
    1601             :   /**
    1602             :    * Adds a copy of the specified Dirichlet boundary to the system.
    1603             :    *
    1604             :    * The constraints implied by DirichletBoundary objects are imposed
    1605             :    * in the same order in which DirichletBoundary objects are added to
    1606             :    * the DofMap. When multiple DirichletBoundary objects would impose
    1607             :    * competing constraints on a given DOF, the *first*
    1608             :    * DirichletBoundary to constrain the DOF "wins". This distinction
    1609             :    * is important when e.g. two surfaces (sidesets) intersect. The
    1610             :    * nodes on the intersection will be constrained according to
    1611             :    * whichever sideset's DirichletBoundary object was added to the
    1612             :    * DofMap first.
    1613             :    */
    1614             :   void add_dirichlet_boundary (const DirichletBoundary & dirichlet_boundary);
    1615             : 
    1616             :   /**
    1617             :    * Adds a copy of the specified Dirichlet boundary to the system,
    1618             :    * corresponding to the adjoint problem defined by Quantity of
    1619             :    * Interest \p q.
    1620             :    */
    1621             :   void add_adjoint_dirichlet_boundary (const DirichletBoundary & dirichlet_boundary,
    1622             :                                        unsigned int q);
    1623             : 
    1624             :   /**
    1625             :    * Removes the specified Dirichlet boundary from the system.
    1626             :    */
    1627             :   void remove_dirichlet_boundary (const DirichletBoundary & dirichlet_boundary);
    1628             : 
    1629             :   /**
    1630             :    * Removes from the system the specified Dirichlet boundary for the
    1631             :    * adjoint equation defined by Quantity of interest index q
    1632             :    */
    1633             :   void remove_adjoint_dirichlet_boundary (const DirichletBoundary & dirichlet_boundary,
    1634             :                                           unsigned int q);
    1635             : 
    1636             :   const DirichletBoundaries * get_dirichlet_boundaries() const
    1637             :   {
    1638             :     return _dirichlet_boundaries.get();
    1639             :   }
    1640             : 
    1641          24 :   DirichletBoundaries * get_dirichlet_boundaries()
    1642             :   {
    1643          24 :     return _dirichlet_boundaries.get();
    1644             :   }
    1645             : 
    1646             :   bool has_adjoint_dirichlet_boundaries(unsigned int q) const;
    1647             : 
    1648             :   const DirichletBoundaries *
    1649             :   get_adjoint_dirichlet_boundaries(unsigned int q) const;
    1650             : 
    1651             :   DirichletBoundaries *
    1652             :   get_adjoint_dirichlet_boundaries(unsigned int q);
    1653             : 
    1654             :   /**
    1655             :    * Check that all the ids in dirichlet_bcids are actually present in the mesh.
    1656             :    * If not, this will throw an error.
    1657             :    */
    1658             :   void check_dirichlet_bcid_consistency (const MeshBase & mesh,
    1659             :                                          const DirichletBoundary & boundary) const;
    1660             : #endif // LIBMESH_ENABLE_DIRICHLET
    1661             : 
    1662             : 
    1663             : #ifdef LIBMESH_ENABLE_AMR
    1664             : 
    1665             :   //--------------------------------------------------------------------
    1666             :   // AMR-specific methods
    1667             : 
    1668             :   /**
    1669             :    * After a mesh is refined and repartitioned it is possible that the
    1670             :    * \p _send_list will need to be augmented.  This is the case when an
    1671             :    * element is refined and its children end up on different processors
    1672             :    * than the parent.  These children will need values from the parent
    1673             :    * when projecting the solution onto the refined mesh, hence the parent's
    1674             :    * DOF indices need to be included in the \p _send_list.
    1675             :    */
    1676             :   // void augment_send_list_for_projection(const MeshBase &);
    1677             : 
    1678             : #ifdef LIBMESH_ENABLE_AMR
    1679             : 
    1680             :   /**
    1681             :    * Fills the vector di with the global degree of freedom indices
    1682             :    * for the element using the \p DofMap::old_dof_object.
    1683             :    * If no variable number is specified then all
    1684             :    * variables are returned.
    1685             :    */
    1686             :   void old_dof_indices (const Elem * const elem,
    1687             :                         std::vector<dof_id_type> & di,
    1688             :                         const unsigned int vn = libMesh::invalid_uint) const;
    1689             : 
    1690             : #endif // LIBMESH_ENABLE_AMR
    1691             : 
    1692             :   /**
    1693             :    * Constrains degrees of freedom on side \p s of element \p elem which
    1694             :    * correspond to variable number \p var and to p refinement levels
    1695             :    * above \p p.
    1696             :    */
    1697             :   void constrain_p_dofs (unsigned int var,
    1698             :                          const Elem * elem,
    1699             :                          unsigned int s,
    1700             :                          unsigned int p);
    1701             : 
    1702             : #endif // LIBMESH_ENABLE_AMR
    1703             : 
    1704             :   /**
    1705             :    * Reinitialize the underlying data structures conformal to the current mesh.
    1706             :    */
    1707             :   void reinit
    1708             :     (MeshBase & mesh,
    1709             :      const std::map<const Node *, std::set<subdomain_id_type>> &
    1710             :        constraining_subdomains);
    1711             : 
    1712             :   /**
    1713             :    * Free all new memory associated with the object, but restore its
    1714             :    * original state, with the mesh pointer and any default ghosting.
    1715             :    */
    1716             :   virtual void clear () override;
    1717             : 
    1718             :   /**
    1719             :    * Prints summary info about the sparsity bandwidth and constraints.
    1720             :    */
    1721             :   void print_info(std::ostream & os=libMesh::out) const;
    1722             : 
    1723             :   /**
    1724             :    * Gets summary info about the sparsity bandwidth and constraints.
    1725             :    */
    1726             :   std::string get_info() const;
    1727             : 
    1728             :   /**
    1729             :    * Degree of freedom coupling.  If left empty each DOF
    1730             :    * couples to all others.  Can be used to reduce memory
    1731             :    * requirements for sparse matrices.  DOF 0 might only
    1732             :    * couple to itself, in which case \p dof_coupling(0,0)
    1733             :    * should be 1 and \p dof_coupling(0,j) = 0 for j not equal
    1734             :    * to 0.
    1735             :    *
    1736             :    * This variable is named as though it were class private,
    1737             :    * but it is in the public interface.  Also there are no
    1738             :    * public methods for accessing it...  This typically means
    1739             :    * you should only use it if you know what you are doing.
    1740             :    */
    1741             :   CouplingMatrix * _dof_coupling;
    1742             : 
    1743             :   /**
    1744             :    * \returns The number of the system we are responsible for.
    1745             :    */
    1746             :   unsigned int sys_number() const;
    1747             : 
    1748             :   /**
    1749             :    * Builds a sparsity pattern for matrices using the current
    1750             :    * degree-of-freedom numbering and coupling.
    1751             :    *
    1752             :    * By default, ignores constraint equations, for build speed; this
    1753             :    * is valid for the combination of !need_full_sparsity_pattern and
    1754             :    * constraints which only come from periodic boundary conditions and
    1755             :    * adaptive mesh refinement, where matrix constraint adds some
    1756             :    * matrix entries but removes equally many (or more) other entries.
    1757             :    *
    1758             :    * Can be told to calculate sparsity for the constrained matrix,
    1759             :    * which may be necessary in the case of spline control node
    1760             :    * constraints or sufficiently many user constraints.
    1761             :    */
    1762             :   std::unique_ptr<SparsityPattern::Build> build_sparsity(const MeshBase & mesh,
    1763             :                                                          bool calculate_constrained = false,
    1764             :                                                          bool use_condensed_system = false) const;
    1765             : 
    1766             :   /**
    1767             :    * Set whether the given variable group should be p-refined on a
    1768             :    * p-refined Elem.  This changes the FEType of the variable group to
    1769             :    * enable or disable p-refinement.
    1770             :    */
    1771             :   void should_p_refine(unsigned int g, bool p_refine);
    1772             : 
    1773             :   /**
    1774             :    * Whether the given variable group should be p-refined
    1775             :    */
    1776             :   bool should_p_refine(unsigned int g) const;
    1777             : 
    1778             :   /**
    1779             :    * Whether the given variable should be p-refined
    1780             :    */
    1781             :   bool should_p_refine_var(unsigned int var) const;
    1782             : 
    1783             :   // Prevent bad user implicit conversions
    1784             :   void should_p_refine(FEFamily, bool) = delete;
    1785             :   void should_p_refine(Order, bool) = delete;
    1786             :   bool should_p_refine(FEFamily) const = delete;
    1787             :   bool should_p_refine(Order) const = delete;
    1788             : 
    1789             :   /**
    1790             :    * Add a static condensation class
    1791             :    */
    1792             :   void create_static_condensation(MeshBase & mesh, System & system);
    1793             : 
    1794             :   /**
    1795             :    * Checks whether we have static condensation
    1796             :    */
    1797       88541 :   bool has_static_condensation() const { return _sc.get(); }
    1798             : 
    1799             :   /**
    1800             :    * @returns the static condensation class. This should have been already added with a call to \p
    1801             :    * add_static_condensation()
    1802             :    */
    1803             :   StaticCondensationDofMap & get_static_condensation();
    1804             : 
    1805             :   /**
    1806             :    * @returns the static condensation class. This should have been already added with a call to \p
    1807             :    * add_static_condensation()
    1808             :    */
    1809             :   const StaticCondensationDofMap & get_static_condensation() const;
    1810             : 
    1811             :   /**
    1812             :    * Calls reinit on the static condensation map if it exists
    1813             :    */
    1814             :   void reinit_static_condensation();
    1815             : 
    1816             : private:
    1817             : 
    1818             :   /**
    1819             :    * Retrieve the array variable bounds for a given variable \p vi. This variable may
    1820             :    * lie anywhere within an array variable range. An 'array variable' is simply a sequence
    1821             :    * of contiguous variable numbers defined by pair where the first member of the pair
    1822             :    * is the first number in the variable sequence and the second member of the pair is
    1823             :    * the number of the last variable in the sequence plus one. Array variables may be
    1824             :    * used in tandem with variable grouping by downstream code to build optimized physics
    1825             :    * kernels since each variable in the array will have the same shape functions.
    1826             :    *
    1827             :    * We note that we store array variables as a container of the above described pairs. Within
    1828             :    * this API we will do a binary search such that the complexity is O(log(N)) where N is the
    1829             :    * number of array variables present in \p this
    1830             :    */
    1831             :   const std::pair<unsigned int, unsigned int> &
    1832             :   get_variable_array(unsigned int vi) const;
    1833             : 
    1834             :   /**
    1835             :    * Helper function that gets the dof indices on the current element
    1836             :    * for a non-SCALAR type variable, where the variable is identified
    1837             :    * by its variable group number \p vg and its offset \p vig from the
    1838             :    * first variable in that group.
    1839             :    *
    1840             :    * In DEBUG mode, the tot_size parameter will add up the total
    1841             :    * number of dof indices that should have been added to di, and v
    1842             :    * will be the variable number corresponding to vg and vig.
    1843             :    */
    1844             :   void _dof_indices (const Elem & elem,
    1845             :                      int p_level,
    1846             :                      std::vector<dof_id_type> & di,
    1847             :                      const unsigned int vg,
    1848             :                      const unsigned int vig,
    1849             :                      const Node * const * nodes,
    1850             :                      unsigned int       n_nodes,
    1851             :                      const unsigned int v
    1852             : #ifdef DEBUG
    1853             :                      ,
    1854             :                      std::size_t & tot_size
    1855             : #endif
    1856             :                     ) const;
    1857             : 
    1858             :   /**
    1859             :    * As above except a \p field_dofs_functor must be provided. This method is useful when the caller
    1860             :    * wants to do more than simply fill a degree of freedom container
    1861             :    * @param field_dofs_functor This functor has the interface:
    1862             :    *                           void field_dofs_functor(const Elem & elem,
    1863             :    *                                                   const unsigned int node_num,
    1864             :    *                                                   const unsigned int var_num,
    1865             :    *                                                   std::vector<dof_id_type> & di,
    1866             :    *                                                   const dof_id_type field_dof)
    1867             :    *                           where \p field_dof represents a field degree of freedom to act on and
    1868             :    *                           is associated with \p node_num and \p var_num. If the degree of
    1869             :    *                           freedom is elemental than \p node_num will be \p invalid_uint. \p di
    1870             :    *                           is the degree of freedom container provided to the \p _dof_indices
    1871             :    *                           method
    1872             :    */
    1873             :   template <typename FieldDofsFunctor>
    1874             :   void _dof_indices (const Elem & elem,
    1875             :                      int p_level,
    1876             :                      std::vector<dof_id_type> & di,
    1877             :                      const unsigned int vg,
    1878             :                      const unsigned int vig,
    1879             :                      const Node * const * nodes,
    1880             :                      unsigned int       n_nodes,
    1881             :                      const unsigned int v,
    1882             : #ifdef DEBUG
    1883             :                      std::size_t & tot_size,
    1884             : #endif
    1885             :                      FieldDofsFunctor field_dofs_functor) const;
    1886             : 
    1887             :   /**
    1888             :    * Helper function that implements the element-nodal versions of
    1889             :    * dof_indices and old_dof_indices
    1890             :    */
    1891             :   void _node_dof_indices (const Elem & elem,
    1892             :                           unsigned int n,
    1893             :                           const DofObject & obj,
    1894             :                           std::vector<dof_id_type> & di,
    1895             :                           const unsigned int vn) const;
    1896             : 
    1897             :   /**
    1898             :    * Invalidates all active DofObject dofs for this system
    1899             :    */
    1900             :   void invalidate_dofs(MeshBase & mesh) const;
    1901             : 
    1902             :   /**
    1903             :    * \returns The Node pointer with index \p i from the \p mesh.
    1904             :    */
    1905             :   DofObject * node_ptr(MeshBase & mesh, dof_id_type i) const;
    1906             : 
    1907             :   /**
    1908             :    * \returns The Elem pointer with index \p i from the \p mesh.
    1909             :    */
    1910             :   DofObject * elem_ptr(MeshBase & mesh, dof_id_type i) const;
    1911             : 
    1912             :   /**
    1913             :    * A member function type like \p node_ptr() or \p elem_ptr().
    1914             :    */
    1915             :   typedef DofObject * (DofMap::*dofobject_accessor)
    1916             :     (MeshBase & mesh, dof_id_type i) const;
    1917             : 
    1918             :   /**
    1919             :    * Helper function for distributing dofs in parallel
    1920             :    */
    1921             :   template<typename iterator_type>
    1922             :   void set_nonlocal_dof_objects(iterator_type objects_begin,
    1923             :                                 iterator_type objects_end,
    1924             :                                 MeshBase & mesh,
    1925             :                                 dofobject_accessor objects);
    1926             : 
    1927             :   /**
    1928             :    * We may have mesh constraint rows with dependent nodes in one
    1929             :    * subdomain but dependency nodes in another subdomain, and we may
    1930             :    * have variables whose subdomain restriction includes the dependent
    1931             :    * subdomain but not the dependency.  In those cases we need to
    1932             :    * place degrees of freedom on dependency nodes anyway.
    1933             :    *
    1934             :    * The set value for node n will include all subdomain ids of
    1935             :    * elements with nodes in subdomains constrained by n.
    1936             :    *
    1937             :    * We use a map<set> rather than a multimap here because we expect
    1938             :    * to be inserting the same subdomain multiple times and we don't
    1939             :    * need duplicate values.
    1940             :    */
    1941             :   std::map<const Node *, std::set<subdomain_id_type>>
    1942             :   calculate_constraining_subdomains();
    1943             : 
    1944             :   /**
    1945             :    * Distributes the global degrees of freedom, for dofs on
    1946             :    * this processor.  In this format the local
    1947             :    * degrees of freedom are in a contiguous block for each
    1948             :    * variable in the system.
    1949             :    * Starts at index next_free_dof, and increments it to
    1950             :    * the post-final index.
    1951             :    *
    1952             :    * Uses the provided constraining_subdomains map from
    1953             :    * calculate_constraining_subdomains() to ensure allocation of all
    1954             :    * DoFs on constraining nodes.
    1955             :    */
    1956             :   void distribute_local_dofs_var_major
    1957             :     (dof_id_type & next_free_dof,
    1958             :      MeshBase & mesh,
    1959             :      const std::map<const Node *, std::set<subdomain_id_type>> &
    1960             :        constraining_subdomains);
    1961             : 
    1962             :   /**
    1963             :    * Distributes the global degrees of freedom for dofs on this
    1964             :    * processor.  In this format all the degrees of freedom at a
    1965             :    * node/element are in contiguous blocks.  Starts at index \p
    1966             :    * next_free_dof, and increments it to the post-final index.  If \p
    1967             :    * build_send_list is \p true, builds the send list.  If \p false,
    1968             :    * clears and reserves the send list.
    1969             :    *
    1970             :    * Uses the provided constraining_subdomains map from
    1971             :    * calculate_constraining_subdomains() to ensure allocation of all
    1972             :    * DoFs on constraining nodes.
    1973             :    *
    1974             :    * \note The degrees of freedom for a given variable are not in
    1975             :    * contiguous blocks, as in the case of \p distribute_local_dofs_var_major.
    1976             :    */
    1977             :   void distribute_local_dofs_node_major
    1978             :     (dof_id_type & next_free_dof,
    1979             :      MeshBase & mesh,
    1980             :      const std::map<const Node *, std::set<subdomain_id_type>> &
    1981             :        constraining_subdomains);
    1982             : 
    1983             :   /*
    1984             :    * Helper method for the above two to count + distriubte SCALAR dofs
    1985             :    */
    1986             :   void distribute_scalar_dofs (dof_id_type & next_free_dof);
    1987             : 
    1988             : #ifdef DEBUG
    1989             :   /*
    1990             :    * Internal assertions for distribute_local_dofs_*
    1991             :    */
    1992             :   void assert_no_nodes_missed(MeshBase & mesh);
    1993             : #endif
    1994             : 
    1995             :   /*
    1996             :    * A utility method for obtaining a set of elements to ghost along
    1997             :    * with merged coupling matrices.
    1998             :    */
    1999             :   typedef std::set<std::unique_ptr<CouplingMatrix>, Utility::CompareUnderlying> CouplingMatricesSet;
    2000             :   static void
    2001             :   merge_ghost_functor_outputs (GhostingFunctor::map_type & elements_to_ghost,
    2002             :                                CouplingMatricesSet & temporary_coupling_matrices,
    2003             :                                const GhostingFunctorIterator & gf_begin,
    2004             :                                const GhostingFunctorIterator & gf_end,
    2005             :                                const MeshBase::const_element_iterator & elems_begin,
    2006             :                                const MeshBase::const_element_iterator & elems_end,
    2007             :                                processor_id_type p);
    2008             : 
    2009             :   /**
    2010             :    * Adds entries to the \p _send_list vector corresponding to DoFs
    2011             :    * on elements neighboring the current processor.
    2012             :    */
    2013             :   void add_neighbors_to_send_list(MeshBase & mesh);
    2014             : 
    2015             : #ifdef LIBMESH_ENABLE_CONSTRAINTS
    2016             : 
    2017             :   /**
    2018             :    * Build the constraint matrix C associated with the element
    2019             :    * degree of freedom indices elem_dofs. The optional parameter
    2020             :    * \p called_recursively should be left at the default value
    2021             :    * \p false.  This is used to handle the special case of
    2022             :    * an element's degrees of freedom being constrained in terms
    2023             :    * of other, local degrees of freedom.  The usual case is
    2024             :    * for an elements DOFs to be constrained by some other,
    2025             :    * external DOFs.
    2026             :    */
    2027             :   void build_constraint_matrix (DenseMatrix<Number> & C,
    2028             :                                 std::vector<dof_id_type> & elem_dofs,
    2029             :                                 const bool called_recursively=false) const;
    2030             : 
    2031             :   /**
    2032             :    * Build the constraint matrix C and the forcing vector H
    2033             :    * associated with the element degree of freedom indices elem_dofs.
    2034             :    * The optional parameter \p called_recursively should be left at
    2035             :    * the default value \p false.  This is used to handle the special
    2036             :    * case of an element's degrees of freedom being constrained in
    2037             :    * terms of other, local degrees of freedom.  The usual case is for
    2038             :    * an elements DOFs to be constrained by some other, external DOFs
    2039             :    * and/or Dirichlet conditions.
    2040             :    *
    2041             :    * The forcing vector will depend on which solution's heterogeneous
    2042             :    * constraints are being applied.  For the default \p qoi_index this
    2043             :    * will be the primal solution; for \p qoi_index >= 0 the
    2044             :    * corresponding adjoint solution's constraints will be used.
    2045             :    */
    2046             :   void build_constraint_matrix_and_vector (DenseMatrix<Number> & C,
    2047             :                                            DenseVector<Number> & H,
    2048             :                                            std::vector<dof_id_type> & elem_dofs,
    2049             :                                            int qoi_index = -1,
    2050             :                                            const bool called_recursively=false) const;
    2051             : 
    2052             :   /**
    2053             :    * Finds all the DOFS associated with the element DOFs elem_dofs.
    2054             :    * This will account for off-element couplings via hanging nodes.
    2055             :    */
    2056             :   void find_connected_dofs (std::vector<dof_id_type> & elem_dofs) const;
    2057             : 
    2058             :   /**
    2059             :    * Finds all the DofObjects associated with the set in \p objs.
    2060             :    * This will account for off-element couplings via hanging nodes.
    2061             :    */
    2062             :   void find_connected_dof_objects (std::vector<const DofObject *> & objs) const;
    2063             : 
    2064             :   /**
    2065             :    * Adds entries to the \p _send_list vector corresponding to DoFs
    2066             :    * which are dependencies for constraint equations on the current
    2067             :    * processor.
    2068             :    */
    2069             :   void add_constraints_to_send_list();
    2070             : 
    2071             :   /**
    2072             :    * Adds any spline constraints from the Mesh to our DoF constraints.
    2073             :    * If any Dirichlet constraints exist on spline-constrained nodes,
    2074             :    * l2-projects those constraints onto the spline basis.
    2075             :    */
    2076             :   void process_mesh_constraint_rows(const MeshBase & mesh);
    2077             : 
    2078             : #endif // LIBMESH_ENABLE_CONSTRAINTS
    2079             : 
    2080             :   /**
    2081             :    * This flag indicates whether or not we do an opt-mode check for
    2082             :    * the presence of constraint loops, i.e. cases where the constraint
    2083             :    * graph is cyclic.
    2084             :    */
    2085             :   bool _error_on_constraint_loop;
    2086             : 
    2087             :   /**
    2088             :    * This flag indicates whether or not we explicitly take constraint
    2089             :    * equations into account when computing a sparsity pattern.
    2090             :    */
    2091             :   bool _constrained_sparsity_construction;
    2092             : 
    2093             :   /**
    2094             :    * The variables in this system/degree of freedom map
    2095             :    */
    2096             :   std::vector<Variable> _variables;
    2097             : 
    2098             :   /**
    2099             :    * The variable groups in this system/degree of freedom map
    2100             :    */
    2101             :   std::vector<VariableGroup> _variable_groups;
    2102             : 
    2103             :   /**
    2104             :    * The variable group number for each variable.
    2105             :    */
    2106             :   std::vector<unsigned int> _variable_group_numbers;
    2107             : 
    2108             :   /**
    2109             :    * A map from variable number to variable group number
    2110             :    */
    2111             :   std::unordered_map<unsigned int, unsigned int> _var_to_vg;
    2112             : 
    2113             :   /**
    2114             :    * The variable numbers corresponding to user-specified
    2115             :    * names, useful for name-based lookups.
    2116             :    */
    2117             :   std::map<std::string, unsigned int, std::less<>> _variable_numbers;
    2118             : 
    2119             :   /**
    2120             :    * Array variable information storage. For a given array "variable", the first member of the pair
    2121             :    * denotes the first variable number present in the array variable and the second member of the
    2122             :    * pair denotes the last variable number present in the array variables plus one
    2123             :    */
    2124             :   std::vector<std::pair<unsigned int, unsigned int>> _array_variables;
    2125             : 
    2126             :   /**
    2127             :    * \p true when \p VariableGroup structures should be automatically
    2128             :    * identified, \p false otherwise.  Defaults to \p true.
    2129             :    */
    2130             :   bool _identify_variable_groups = true;
    2131             : 
    2132             :   /**
    2133             :    * The number of the system we manage DOFs for.
    2134             :    */
    2135             :   const unsigned int _sys_number;
    2136             : 
    2137             :   /**
    2138             :    * The mesh that system uses.
    2139             :    */
    2140             :   MeshBase & _mesh;
    2141             : 
    2142             :   /**
    2143             :    * Additional matrices handled by this object.  These pointers do \e
    2144             :    * not handle the memory, instead, \p System, who
    2145             :    * told \p DofMap about them, owns them.
    2146             :    */
    2147             :   std::vector<SparseMatrix<Number> * > _matrices;
    2148             : 
    2149             :   /**
    2150             :    * First DOF index for SCALAR variable v, or garbage for non-SCALAR
    2151             :    * variable v
    2152             :    */
    2153             :   std::vector<dof_id_type> _first_scalar_df;
    2154             : 
    2155             :   /**
    2156             :    * A list containing all the global DOF indices that affect the
    2157             :    * solution on my processor.
    2158             :    */
    2159             :   std::vector<dof_id_type> _send_list;
    2160             : 
    2161             :   /**
    2162             :    * Function object to call to add extra entries to the sparsity pattern
    2163             :    */
    2164             :   SparsityPattern::AugmentSparsityPattern * _augment_sparsity_pattern;
    2165             : 
    2166             :   /**
    2167             :    * A function pointer to a function to call to add extra entries to the sparsity pattern
    2168             :    */
    2169             :   void (*_extra_sparsity_function)(SparsityPattern::Graph &,
    2170             :                                    std::vector<dof_id_type> & n_nz,
    2171             :                                    std::vector<dof_id_type> & n_oz,
    2172             :                                    void *);
    2173             :   /**
    2174             :    * A pointer associated with the extra sparsity that can optionally be passed in
    2175             :    */
    2176             :   void * _extra_sparsity_context;
    2177             : 
    2178             :   /**
    2179             :    * Function object to call to add extra entries to the send list
    2180             :    */
    2181             :   AugmentSendList * _augment_send_list;
    2182             : 
    2183             :   /**
    2184             :    * A function pointer to a function to call to add extra entries to the send list
    2185             :    */
    2186             :   void (*_extra_send_list_function)(std::vector<dof_id_type> &, void *);
    2187             : 
    2188             :   /**
    2189             :    * A pointer associated with the extra send list that can optionally be passed in
    2190             :    */
    2191             :   void * _extra_send_list_context;
    2192             : 
    2193             :   /**
    2194             :    * The default coupling GhostingFunctor, used to implement standard
    2195             :    * libMesh sparsity pattern construction.
    2196             :    *
    2197             :    * We use a std::unique_ptr here to reduce header dependencies.
    2198             :    */
    2199             :   std::unique_ptr<DefaultCoupling> _default_coupling;
    2200             : 
    2201             :   /**
    2202             :    * The default algebraic GhostingFunctor, used to implement standard
    2203             :    * libMesh send_list construction.
    2204             :    *
    2205             :    * We use a std::unique_ptr here to reduce header dependencies.
    2206             :    */
    2207             :   std::unique_ptr<DefaultCoupling> _default_evaluating;
    2208             : 
    2209             :   /**
    2210             :    * The list of all GhostingFunctor objects to be used when
    2211             :    * distributing ghosted vectors.
    2212             :    *
    2213             :    * The library should automatically refer these functors to the
    2214             :    * MeshBase, too, so any algebraically ghosted dofs will live on
    2215             :    * geometrically ghosted elements.
    2216             :    *
    2217             :    * Keep these in a vector so any parallel computation is done in the
    2218             :    * same order on all processors.
    2219             :    */
    2220             :   std::vector<GhostingFunctor *> _algebraic_ghosting_functors;
    2221             : 
    2222             :   /**
    2223             :    * The list of all GhostingFunctor objects to be used when
    2224             :    * coupling degrees of freedom in matrix sparsity patterns.
    2225             :    *
    2226             :    * These objects will *also* be used as algebraic ghosting functors,
    2227             :    * but not vice-versa.
    2228             :    *
    2229             :    * The library should automatically refer these functors to the
    2230             :    * MeshBase, too, so any dofs coupled to local dofs will live on
    2231             :    * geometrically ghosted elements.
    2232             :    */
    2233             :   std::vector<GhostingFunctor *> _coupling_functors;
    2234             : 
    2235             :   /**
    2236             :    * Hang on to references to any GhostingFunctor objects we were
    2237             :    * passed in shared_ptr form
    2238             :    */
    2239             :   std::map<GhostingFunctor *, std::shared_ptr<GhostingFunctor> > _shared_functors;
    2240             : 
    2241             :   /**
    2242             :    * Default false; set to true if any attached matrix requires a full
    2243             :    * sparsity pattern.
    2244             :    */
    2245             :   bool need_full_sparsity_pattern;
    2246             : 
    2247             :   /**
    2248             :    * The sparsity pattern of the global matrix.  If
    2249             :    * need_full_sparsity_pattern is true, we save the entire sparse
    2250             :    * graph here.  Otherwise we save just the n_nz and n_oz vectors.
    2251             :    */
    2252             :   std::unique_ptr<SparsityPattern::Build> _sp;
    2253             : 
    2254             :   /**
    2255             :    * The total number of SCALAR dofs associated to
    2256             :    * all SCALAR variables.
    2257             :    */
    2258             :   dof_id_type _n_SCALAR_dofs;
    2259             : 
    2260             : #ifdef LIBMESH_ENABLE_AMR
    2261             : 
    2262             :   /**
    2263             :    * First old DOF index for SCALAR variable v, or garbage for
    2264             :    * non-SCALAR variable v
    2265             :    */
    2266             :   std::vector<dof_id_type> _first_old_scalar_df;
    2267             : #endif
    2268             : 
    2269             : #ifdef LIBMESH_ENABLE_CONSTRAINTS
    2270             :   /**
    2271             :    * Data structure containing DOF constraints.  The ith
    2272             :    * entry is the constraint matrix row for DOF i.
    2273             :    */
    2274             :   DofConstraints _dof_constraints, _stashed_dof_constraints;
    2275             : 
    2276             :   DofConstraintValueMap      _primal_constraint_values;
    2277             : 
    2278             :   AdjointDofConstraintValues _adjoint_constraint_values;
    2279             : #endif
    2280             : 
    2281             : #ifdef LIBMESH_ENABLE_NODE_CONSTRAINTS
    2282             :   /**
    2283             :    * Data structure containing DofObject constraints.
    2284             :    */
    2285             :   NodeConstraints _node_constraints;
    2286             : #endif // LIBMESH_ENABLE_NODE_CONSTRAINTS
    2287             : 
    2288             : 
    2289             : #ifdef LIBMESH_ENABLE_PERIODIC
    2290             :   /**
    2291             :    * Data structure containing periodic boundaries.  The ith
    2292             :    * entry is the constraint matrix row for boundaryid i.
    2293             :    */
    2294             :   std::unique_ptr<PeriodicBoundaries> _periodic_boundaries;
    2295             : #endif
    2296             : 
    2297             : #ifdef LIBMESH_ENABLE_DIRICHLET
    2298             :   /**
    2299             :    * Data structure containing Dirichlet functions.  The ith
    2300             :    * entry is the constraint matrix row for boundaryid i.
    2301             :    */
    2302             :   std::unique_ptr<DirichletBoundaries> _dirichlet_boundaries;
    2303             : 
    2304             :   /**
    2305             :    * Data structure containing Dirichlet functions.  The ith
    2306             :    * entry is the constraint matrix row for boundaryid i.
    2307             :    */
    2308             :   std::vector<std::unique_ptr<DirichletBoundaries>> _adjoint_dirichlet_boundaries;
    2309             : #endif
    2310             : 
    2311             :   friend class SparsityPattern::Build;
    2312             : 
    2313             :   /**
    2314             :    * Bools to indicate if we override the --implicit_neighbor_dofs
    2315             :    * commandline options.
    2316             :    */
    2317             :   bool _implicit_neighbor_dofs_initialized;
    2318             :   bool _implicit_neighbor_dofs;
    2319             : 
    2320             :   /**
    2321             :    * Flag which determines whether we should do some additional
    2322             :    * checking of the consistency of the DirichletBoundary objects
    2323             :    * added by the user. Defaults to true, but can be disabled in cases
    2324             :    * where you only want to add DirichletBoundary objects "locally"
    2325             :    * and can guarantee that no repartitioning will be done, since
    2326             :    * repartitioning could cause processors to own new boundary sides
    2327             :    * for which they no longer have the proper DirichletBoundary
    2328             :    * objects stored.
    2329             :    */
    2330             :   bool _verify_dirichlet_bc_consistency;
    2331             : 
    2332             :   /// Static condensation class
    2333             :   std::unique_ptr<StaticCondensationDofMap> _sc;
    2334             : };
    2335             : 
    2336             : 
    2337             : // ------------------------------------------------------------
    2338             : // Dof Map inline member functions
    2339             : inline
    2340    44162824 : unsigned int DofMap::sys_number() const
    2341             : {
    2342   307526308 :   return _sys_number;
    2343             : }
    2344             : 
    2345             : 
    2346             : 
    2347             : inline
    2348    49006647 : const VariableGroup & DofMap::variable_group (const unsigned int g) const
    2349             : {
    2350    49006647 :   libmesh_assert_less (g, _variable_groups.size());
    2351             : 
    2352   316600273 :   return _variable_groups[g];
    2353             : }
    2354             : 
    2355             : 
    2356             : 
    2357             : inline
    2358    66657693 : const Variable & DofMap::variable (const unsigned int c) const
    2359             : {
    2360     6328237 :   libmesh_assert_less (c, _variables.size());
    2361             : 
    2362    71775683 :   return _variables[c];
    2363             : }
    2364             : 
    2365             : 
    2366             : 
    2367             : inline
    2368             : Order DofMap::variable_order (const unsigned int c) const
    2369             : {
    2370             :   libmesh_assert_less (c, _variables.size());
    2371             : 
    2372             :   return _variables[c].type().order;
    2373             : }
    2374             : 
    2375             : 
    2376             : 
    2377             : inline
    2378             : Order DofMap::variable_group_order (const unsigned int vg) const
    2379             : {
    2380             :   libmesh_assert_less (vg, _variable_groups.size());
    2381             : 
    2382             :   return _variable_groups[vg].type().order;
    2383             : }
    2384             : 
    2385             : 
    2386             : 
    2387             : inline
    2388     2169189 : const FEType & DofMap::variable_type (const unsigned int c) const
    2389             : {
    2390     2169189 :   libmesh_assert_less (c, _variables.size());
    2391             : 
    2392    15438377 :   return _variables[c].type();
    2393             : }
    2394             : 
    2395             : 
    2396             : 
    2397             : inline
    2398             : const FEType & DofMap::variable_group_type (const unsigned int vg) const
    2399             : {
    2400             :   libmesh_assert_less (vg, _variable_groups.size());
    2401             : 
    2402             :   return _variable_groups[vg].type();
    2403             : }
    2404             : 
    2405             : 
    2406             : #ifdef LIBMESH_ENABLE_CONSTRAINTS
    2407             : 
    2408             : 
    2409             : inline
    2410     1422756 : bool DofMap::is_constrained_node (const Node *
    2411             : #ifdef LIBMESH_ENABLE_NODE_CONSTRAINTS
    2412             :                                   node
    2413             : #endif
    2414             :                                   ) const
    2415             : {
    2416             : #ifdef LIBMESH_ENABLE_NODE_CONSTRAINTS
    2417     1422756 :   if (_node_constraints.count(node))
    2418       17734 :     return true;
    2419             : #endif
    2420             : 
    2421     1405022 :   return false;
    2422             : }
    2423             : 
    2424             : 
    2425             : inline
    2426    52897450 : bool DofMap::is_constrained_dof (const dof_id_type dof) const
    2427             : {
    2428    52897450 :   if (_dof_constraints.count(dof))
    2429     5772734 :     return true;
    2430             : 
    2431    47124716 :   return false;
    2432             : }
    2433             : 
    2434             : 
    2435             : inline
    2436       83110 : bool DofMap::has_heterogeneous_adjoint_constraints (const unsigned int qoi_num) const
    2437             : {
    2438             :   AdjointDofConstraintValues::const_iterator it =
    2439        4796 :     _adjoint_constraint_values.find(qoi_num);
    2440       87906 :   if (it == _adjoint_constraint_values.end())
    2441        1892 :     return false;
    2442       29012 :   if (it->second.empty())
    2443       25920 :     return false;
    2444             : 
    2445          24 :   return true;
    2446             : }
    2447             : 
    2448             : 
    2449             : inline
    2450     1415182 : Number DofMap::has_heterogeneous_adjoint_constraint (const unsigned int qoi_num,
    2451             :                                                     const dof_id_type dof) const
    2452             : {
    2453             :   AdjointDofConstraintValues::const_iterator it =
    2454     1094202 :     _adjoint_constraint_values.find(qoi_num);
    2455     1415182 :   if (it != _adjoint_constraint_values.end())
    2456             :     {
    2457             :       DofConstraintValueMap::const_iterator rhsit =
    2458      104428 :         it->second.find(dof);
    2459      425408 :       if (rhsit == it->second.end())
    2460      154302 :         return 0;
    2461             :       else
    2462        1820 :         return rhsit->second;
    2463             :     }
    2464             : 
    2465      989774 :   return 0;
    2466             : }
    2467             : 
    2468             : 
    2469             : 
    2470             : inline
    2471             : DofConstraintValueMap & DofMap::get_primal_constraint_values()
    2472             : {
    2473             :   return _primal_constraint_values;
    2474             : }
    2475             : 
    2476             : 
    2477             : 
    2478             : #else
    2479             : 
    2480             : //--------------------------------------------------------------------
    2481             : // Constraint-specific methods get inlined into nothing if
    2482             : // constraints are disabled, so there's no reason for users not to
    2483             : // use them.
    2484             : 
    2485             : inline void DofMap::constrain_element_matrix (DenseMatrix<Number> &,
    2486             :                                               std::vector<dof_id_type> &,
    2487             :                                               bool) const {}
    2488             : 
    2489             : inline void DofMap::constrain_element_matrix (DenseMatrix<Number> &,
    2490             :                                               std::vector<dof_id_type> &,
    2491             :                                               std::vector<dof_id_type> &,
    2492             :                                               bool) const {}
    2493             : 
    2494             : inline void DofMap::constrain_element_vector (DenseVector<Number> &,
    2495             :                                               std::vector<dof_id_type> &,
    2496             :                                               bool) const {}
    2497             : 
    2498             : inline void DofMap::constrain_element_matrix_and_vector (DenseMatrix<Number> &,
    2499             :                                                          DenseVector<Number> &,
    2500             :                                                          std::vector<dof_id_type> &,
    2501             :                                                          bool) const {}
    2502             : 
    2503             : inline void DofMap::heterogeneously_constrain_element_matrix_and_vector
    2504             :   (DenseMatrix<Number> &, DenseVector<Number> &,
    2505             :    std::vector<dof_id_type> &, bool, int) const {}
    2506             : 
    2507             : inline void DofMap::heterogeneously_constrain_element_vector
    2508             :   (const DenseMatrix<Number> &, DenseVector<Number> &,
    2509             :    std::vector<dof_id_type> &, bool, int) const {}
    2510             : 
    2511             : inline void DofMap::constrain_element_dyad_matrix (DenseVector<Number> &,
    2512             :                                                    DenseVector<Number> &,
    2513             :                                                    std::vector<dof_id_type> &,
    2514             :                                                    bool) const {}
    2515             : 
    2516             : inline void DofMap::constrain_nothing (std::vector<dof_id_type> &) const {}
    2517             : 
    2518             : inline void DofMap::enforce_constraints_exactly (const System &,
    2519             :                                                  NumericVector<Number> *,
    2520             :                                                  bool) const {}
    2521             : 
    2522             : inline void DofMap::enforce_adjoint_constraints_exactly (NumericVector<Number> &,
    2523             :                                                          unsigned int) const {}
    2524             : 
    2525             : 
    2526             : inline void DofMap::enforce_constraints_on_residual
    2527             :   (const NonlinearImplicitSystem &,
    2528             :    NumericVector<Number> *,
    2529             :    NumericVector<Number> const *,
    2530             :    bool) const {}
    2531             : 
    2532             : inline void DofMap::enforce_constraints_on_jacobian
    2533             :   (const NonlinearImplicitSystem &,
    2534             :    SparseMatrix<Number> *) const {}
    2535             : 
    2536             : #endif // LIBMESH_ENABLE_CONSTRAINTS
    2537             : 
    2538             : 
    2539             : 
    2540             : inline
    2541             : void DofMap::set_constrained_sparsity_construction(bool use_constraints)
    2542             : {
    2543             :   // This got only partly finished...
    2544             :   if (use_constraints)
    2545             :     libmesh_not_implemented();
    2546             : 
    2547             : #ifdef LIBMESH_ENABLE_CONSTRAINTS
    2548             :   _constrained_sparsity_construction = use_constraints;
    2549             : #endif
    2550             :   libmesh_ignore(use_constraints);
    2551             : }
    2552             : 
    2553             : inline
    2554             : void DofMap::full_sparsity_pattern_needed()
    2555             : {
    2556             :   need_full_sparsity_pattern = true;
    2557             : }
    2558             : 
    2559             : inline
    2560             : bool DofMap::constrained_sparsity_construction()
    2561             : {
    2562             : #ifdef LIBMESH_ENABLE_CONSTRAINTS
    2563             :   return _constrained_sparsity_construction;
    2564             : #else
    2565             :   return true;
    2566             : #endif
    2567             : }
    2568             : 
    2569             : inline
    2570             : void DofMap::should_p_refine(const unsigned int g, const bool p_refine)
    2571             : {
    2572             : #ifdef LIBMESH_ENABLE_AMR
    2573             :   VariableGroup & var = _variable_groups[g];
    2574             :   var.type().p_refinement = p_refine;
    2575             : 
    2576             :   for (auto v : make_range(var.first_scalar_number(0),
    2577             :                            var.first_scalar_number(0) +
    2578             :                            var.n_variables()))
    2579             :     this->_variables[v].type().p_refinement = p_refine;
    2580             : 
    2581             : 
    2582             : #else
    2583             :   libmesh_ignore(g, p_refine);
    2584             : #endif
    2585             : }
    2586             : 
    2587             : inline
    2588             : bool DofMap::should_p_refine(const unsigned int g) const
    2589             : {
    2590             : #ifdef LIBMESH_ENABLE_AMR
    2591             :   const VariableGroup & var = this->variable_group(g);
    2592             :   return var.type().p_refinement;
    2593             : #else
    2594             :   libmesh_ignore(g);
    2595             :   return false;
    2596             : #endif
    2597             : }
    2598             : 
    2599             : inline
    2600             : unsigned int DofMap::var_group_from_var_number(const unsigned int var_num) const
    2601             : {
    2602             :   libmesh_assert(var_num < n_variables());
    2603             :   return libmesh_map_find(_var_to_vg, var_num);
    2604             : }
    2605             : 
    2606             : inline
    2607             : bool DofMap::should_p_refine_var(const unsigned int var) const
    2608             : {
    2609             : #ifdef LIBMESH_ENABLE_AMR
    2610             :   const auto vg = this->var_group_from_var_number(var);
    2611             :   return this->should_p_refine(vg);
    2612             : #else
    2613             :   libmesh_ignore(var);
    2614             :   return false;
    2615             : #endif
    2616             : }
    2617             : 
    2618             : template <typename FieldDofsFunctor>
    2619   273057011 : void DofMap::_dof_indices (const Elem & elem,
    2620             :                            int p_level,
    2621             :                            std::vector<dof_id_type> & di,
    2622             :                            const unsigned int vg,
    2623             :                            const unsigned int vig,
    2624             :                            const Node * const * nodes,
    2625             :                            unsigned int       n_nodes,
    2626             :                            const unsigned int v,
    2627             : #ifdef DEBUG
    2628             :                            std::size_t & tot_size,
    2629             : #endif
    2630             :                            FieldDofsFunctor field_dofs_functor) const
    2631             : {
    2632    24007784 :   const VariableGroup & var = this->variable_group(vg);
    2633             : 
    2634   273057011 :   if (var.active_on_subdomain(elem.subdomain_id()))
    2635             :     {
    2636   272918746 :       const ElemType type        = elem.type();
    2637    24060245 :       const unsigned int sys_num = this->sys_number();
    2638             : #ifdef LIBMESH_ENABLE_INFINITE_ELEMENTS
    2639    31522603 :       const bool is_inf          = elem.infinite();
    2640             : #endif
    2641             : 
    2642             :       const bool extra_hanging_dofs =
    2643   272918746 :         FEInterface::extra_hanging_dofs(var.type());
    2644             : 
    2645   272918746 :       FEType fe_type = var.type();
    2646             : 
    2647   272918746 :       const bool add_p_level = fe_type.p_refinement;
    2648             : 
    2649             : #ifdef DEBUG
    2650             :       // The number of dofs per element is non-static for subdivision FE
    2651    23997153 :       if (var.type().family == SUBDIVISION)
    2652        3936 :         tot_size += n_nodes;
    2653             :       else
    2654             :         // FIXME: Is the passed-in p_level just elem.p_level()? If so,
    2655             :         // this seems redundant.
    2656    23993217 :         tot_size += FEInterface::n_dofs(fe_type, add_p_level*p_level, &elem);
    2657             : #endif
    2658             : 
    2659             :       // The total Order is not required when getting the function
    2660             :       // pointer, it is only needed when the function is called (see
    2661             :       // below).
    2662             :       const FEInterface::n_dofs_at_node_ptr ndan =
    2663   272918746 :         FEInterface::n_dofs_at_node_function(fe_type, &elem);
    2664             : 
    2665             :       // Get the node-based DOF numbers
    2666  1630567524 :       for (unsigned int n=0; n != n_nodes; n++)
    2667             :         {
    2668  1357648778 :           const Node & node = *nodes[n];
    2669             : 
    2670             :           // Cache the intermediate lookups that are common to every
    2671             :           // component
    2672             : #ifdef DEBUG
    2673             :           const std::pair<unsigned int, unsigned int>
    2674   121249204 :             vg_and_offset = node.var_to_vg_and_offset(sys_num,v);
    2675   121249204 :           libmesh_assert_equal_to (vg, vg_and_offset.first);
    2676   121249204 :           libmesh_assert_equal_to (vig, vg_and_offset.second);
    2677             : #endif
    2678  1357648778 :           const unsigned int n_comp = node.n_comp_group(sys_num,vg);
    2679             : 
    2680             :           // There is a potential problem with h refinement.  Imagine a
    2681             :           // quad9 that has a linear FE on it.  Then, on the hanging side,
    2682             :           // it can falsely identify a DOF at the mid-edge node. This is why
    2683             :           // we go through FEInterface instead of node.n_comp() directly.
    2684  1357648778 :           const unsigned int nc =
    2685             : #ifdef LIBMESH_ENABLE_INFINITE_ELEMENTS
    2686    58091261 :             is_inf ?
    2687       82442 :             FEInterface::n_dofs_at_node(fe_type, add_p_level*p_level, &elem, n) :
    2688             : #endif
    2689  1358045445 :             ndan (type, fe_type.order + add_p_level*p_level, n);
    2690             : 
    2691             :           // If this is a non-vertex on a hanging node with extra
    2692             :           // degrees of freedom, we use the non-vertex dofs (which
    2693             :           // come in reverse order starting from the end, to
    2694             :           // simplify p refinement)
    2695  1357648778 :           if (extra_hanging_dofs && !elem.is_vertex(n))
    2696             :             {
    2697    45247082 :               const int dof_offset = n_comp - nc;
    2698             : 
    2699             :               // We should never have fewer dofs than necessary on a
    2700             :               // node unless we're getting indices on a parent element,
    2701             :               // and we should never need the indices on such a node
    2702    45247082 :               if (dof_offset < 0)
    2703             :                 {
    2704           0 :                   libmesh_assert(!elem.active());
    2705           0 :                   di.resize(di.size() + nc, DofObject::invalid_id);
    2706             :                 }
    2707             :               else
    2708   112483055 :                 for (int i=int(n_comp)-1; i>=dof_offset; i--)
    2709             :                   {
    2710     5210038 :                     const dof_id_type d =
    2711    67235973 :                       node.dof_number(sys_num, vg, vig, i, n_comp);
    2712     5210038 :                     libmesh_assert_not_equal_to (d, DofObject::invalid_id);
    2713    67235973 :                     field_dofs_functor(elem, n, v, di, d);
    2714             :                   }
    2715             :             }
    2716             :           // If this is a vertex or an element without extra hanging
    2717             :           // dofs, our dofs come in forward order coming from the
    2718             :           // beginning
    2719             :           else
    2720             :             {
    2721             :               // We have a good component index only if it's being
    2722             :               // used on this FE type (nc) *and* it's available on
    2723             :               // this DofObject (n_comp).
    2724  1312401696 :               const unsigned int good_nc = std::min(n_comp, nc);
    2725  2542687826 :               for (unsigned int i=0; i!=good_nc; ++i)
    2726             :                 {
    2727   108674456 :                   const dof_id_type d =
    2728  1230062627 :                     node.dof_number(sys_num, vg, vig, i, n_comp);
    2729   108674456 :                   libmesh_assert_not_equal_to (d, DofObject::invalid_id);
    2730   108674456 :                   libmesh_assert_less (d, this->n_dofs());
    2731  1230286130 :                   field_dofs_functor(elem, n, v, di, d);
    2732             :                 }
    2733             : 
    2734             :               // With fewer good component indices than we need, e.g.
    2735             :               // due to subdomain expansion, the remaining expected
    2736             :               // indices are marked invalid.
    2737  1312401696 :               if (n_comp < nc)
    2738           0 :                 for (unsigned int i=n_comp; i!=nc; ++i)
    2739           0 :                   di.push_back(DofObject::invalid_id);
    2740             :             }
    2741             :         }
    2742             : 
    2743             :       // If there are any element-based DOF numbers, get them
    2744   272918746 :       const unsigned int nc = FEInterface::n_dofs_per_elem(fe_type, add_p_level*p_level, &elem);
    2745             : 
    2746             :       // We should never have fewer dofs than necessary on an
    2747             :       // element unless we're getting indices on a parent element
    2748             :       // (and we should never need those indices) or off-domain for a
    2749             :       // subdomain-restricted variable (where invalid_id is the
    2750             :       // correct thing to return)
    2751   272918746 :       if (nc != 0)
    2752             :         {
    2753     1715932 :           const unsigned int n_comp = elem.n_comp_group(sys_num,vg);
    2754    19750561 :           if (elem.n_systems() > sys_num && nc <= n_comp)
    2755             :             {
    2756   108297061 :               for (unsigned int i=0; i<nc; i++)
    2757             :                 {
    2758     7739681 :                   const dof_id_type d =
    2759    88382547 :                     elem.dof_number(sys_num, vg, vig, i, n_comp);
    2760     7739681 :                   libmesh_assert_not_equal_to (d, DofObject::invalid_id);
    2761             : 
    2762    88546500 :                   field_dofs_functor(elem, invalid_uint, v, di, d);
    2763             :                 }
    2764             :             }
    2765             :           else
    2766             :             {
    2767           0 :               libmesh_assert(!elem.active() || fe_type.family == LAGRANGE || fe_type.family == SUBDIVISION);
    2768           0 :               di.resize(di.size() + nc, DofObject::invalid_id);
    2769             :             }
    2770             :         }
    2771             :     }
    2772   273057011 : }
    2773             : 
    2774             : 
    2775             : 
    2776             : template <typename ScalarDofsFunctor, typename FieldDofsFunctor>
    2777   115125042 : void DofMap::dof_indices (const Elem * const elem,
    2778             :                           std::vector<dof_id_type> & di,
    2779             :                           const unsigned int vn,
    2780             :                           ScalarDofsFunctor scalar_dofs_functor,
    2781             :                           FieldDofsFunctor field_dofs_functor,
    2782             :                           int p_level) const
    2783             : {
    2784             :   // We now allow elem==nullptr to request just SCALAR dofs
    2785             :   // libmesh_assert(elem);
    2786             : 
    2787             :   // dof_indices() is a relatively light-weight function that is
    2788             :   // called millions of times in normal codes. Therefore, it is not a
    2789             :   // good candidate for logging, since the cost of the logging code
    2790             :   // itself is roughly on par with the time required to call
    2791             :   // dof_indices().
    2792             :   // LOG_SCOPE("dof_indices()", "DofMap");
    2793             : 
    2794             :   // Clear the DOF indices vector
    2795    11033976 :   di.clear();
    2796             : 
    2797             :   // Use the default p refinement level?
    2798   115125042 :   if (p_level == -12345)
    2799   113577082 :     p_level = elem ? elem->p_level() : 0;
    2800             : 
    2801   115188166 :   const unsigned int vg = this->_variable_group_numbers[vn];
    2802    11033976 :   const VariableGroup & var = this->variable_group(vg);
    2803   115125042 :   const unsigned int vig = vn - var.number();
    2804             : 
    2805             : #ifdef DEBUG
    2806             :   // Check that sizes match in DEBUG mode
    2807    11033976 :   std::size_t tot_size = 0;
    2808             : #endif
    2809             : 
    2810   115125042 :   if (elem && elem->type() == TRI3SUBDIVISION)
    2811             :     {
    2812             :       // Subdivision surface FE require the 1-ring around elem
    2813        2712 :       const Tri3Subdivision * sd_elem = static_cast<const Tri3Subdivision *>(elem);
    2814             : 
    2815             :       // Ghost subdivision elements have no real dofs
    2816       29832 :       if (!sd_elem->is_ghost())
    2817             :         {
    2818             :           // Determine the nodes contributing to element elem
    2819        4608 :           std::vector<const Node *> elem_nodes;
    2820       25344 :           MeshTools::Subdivision::find_one_ring(sd_elem, elem_nodes);
    2821             : 
    2822       25344 :           _dof_indices(*elem, p_level, di, vg, vig, elem_nodes.data(),
    2823             :                        cast_int<unsigned int>(elem_nodes.size()), vn,
    2824             : #ifdef DEBUG
    2825             :                        tot_size,
    2826             : #endif
    2827             :                        field_dofs_functor);
    2828             :         }
    2829             : 
    2830       29832 :       return;
    2831             :     }
    2832             : 
    2833             :   // Get the dof numbers
    2834   115193161 :   if (var.type().family == SCALAR &&
    2835     1027177 :       (!elem ||
    2836     1027209 :        var.active_on_subdomain(elem->subdomain_id())))
    2837             :     {
    2838             : #ifdef DEBUG
    2839       97951 :       tot_size += var.type().order;
    2840             : #endif
    2841      195902 :       std::vector<dof_id_type> di_new;
    2842     1027209 :       this->SCALAR_dof_indices(di_new,vn);
    2843     1027209 :       scalar_dofs_functor(*elem, di, di_new);
    2844             :     }
    2845   114068001 :   else if (elem)
    2846   114068001 :     _dof_indices(*elem, p_level, di, vg, vig, elem->get_nodes(),
    2847   114068001 :                  elem->n_nodes(), vn,
    2848             : #ifdef DEBUG
    2849             :                  tot_size,
    2850             : #endif
    2851             :                  field_dofs_functor);
    2852             : 
    2853             : #ifdef DEBUG
    2854    11031264 :   libmesh_assert_equal_to (tot_size, di.size());
    2855             : #endif
    2856             : }
    2857             : 
    2858             : inline
    2859         124 : StaticCondensationDofMap & DofMap::get_static_condensation()
    2860             : {
    2861         124 :   libmesh_assert(_sc);
    2862         124 :   return *_sc;
    2863             : }
    2864             : 
    2865             : inline
    2866          28 : const StaticCondensationDofMap & DofMap::get_static_condensation() const
    2867             : {
    2868          28 :   libmesh_assert(_sc);
    2869          28 :   return *_sc;
    2870             : }
    2871             : 
    2872             : inline const std::pair<unsigned int, unsigned int> &
    2873         104 : DofMap::get_variable_array(const unsigned int vi) const
    2874             : {
    2875          88 :   auto it = std::upper_bound(
    2876             :       _array_variables.begin(),
    2877             :       _array_variables.end(),
    2878             :       vi,
    2879         136 :       [](unsigned int value, const std::pair<unsigned int, unsigned int> & b) { return value < b.first; });
    2880             : 
    2881          16 :   libmesh_assert_msg(it != _array_variables.begin(),
    2882             :                      "Passed in " << std::to_string(vi) << " is not in any of our array variables");
    2883          16 :   --it;
    2884          16 :   libmesh_assert_msg(vi < it->second,
    2885             :                      "Passed in " << std::to_string(vi) << " is not in any of our array variables");
    2886         120 :   return *it;
    2887             : }
    2888             : 
    2889             : template <typename DofIndicesFunctor>
    2890         120 : void DofMap::array_dof_indices(const DofIndicesFunctor & functor,
    2891             :                                std::vector<dof_id_type> & di,
    2892             :                                const unsigned int vn) const
    2893             : {
    2894         136 :   const auto [begin, end] = this->get_variable_array(vn);
    2895         104 :   functor(di, begin);
    2896             : 
    2897         120 :   const unsigned int count = end - begin;
    2898             :   // We make count, which could be >> ntest, the inner index in hopes of vectorization
    2899         120 :   if (count > 1)
    2900             :     {
    2901          40 :       const dof_id_type component_size = di.size();
    2902         120 :       di.resize(count * component_size);
    2903             : 
    2904        1512 :       const auto pack_container = [&di,
    2905             :                                    component_size](const unsigned int j,
    2906             :                                                    const std::vector<dof_id_type> & j_dof_indices,
    2907          32 :                                                    const unsigned int stride) {
    2908          32 :         if (&j_dof_indices != &di)
    2909           4 :           libmesh_assert(j_dof_indices.size() == component_size);
    2910        1568 :         for (const auto i : make_range(component_size))
    2911        1536 :           di[j * component_size + i] = j_dof_indices[i] + stride * j;
    2912             :       };
    2913         104 :       pack_container(0, di, 0);
    2914             : 
    2915         120 :       const auto & fe_type = _variable_groups[libmesh_map_find(_var_to_vg, vn)].type();
    2916         136 :       if (const bool lagrange = fe_type.family == LAGRANGE;
    2917         120 :           lagrange || (FEInterface::get_continuity(fe_type) == DISCONTINUOUS))
    2918             :         {
    2919          90 :           const auto stride = lagrange ? 1 : component_size;
    2920         180 :           for (const auto j : make_range((unsigned int)1, count))
    2921          78 :             pack_container(j, di, stride);
    2922             :         }
    2923             :       else
    2924             :         {
    2925          30 :           static thread_local std::vector<dof_id_type> work_dof_indices;
    2926           4 :           unsigned int j = 1;
    2927          60 :           for (const auto i : make_range(begin + 1, end))
    2928             :             {
    2929          26 :               functor(work_dof_indices, i);
    2930          30 :               pack_container(j++, work_dof_indices, 0);
    2931             :             }
    2932             :         }
    2933             :     }
    2934         120 : }
    2935             : 
    2936             : inline
    2937    10518910 : unsigned int DofMap::n_vars() const
    2938             : {
    2939    21019678 :   return cast_int<unsigned int>(_variables.size());
    2940             : }
    2941             : 
    2942             : inline
    2943     2519416 : const std::string & DofMap::variable_name (const unsigned int i) const
    2944             : {
    2945     2519416 :   libmesh_assert_less (i, _variables.size());
    2946             : 
    2947    30710153 :   return _variables[i].name();
    2948             : }
    2949             : 
    2950             : inline
    2951        1230 : bool DofMap::identify_variable_groups () const
    2952             : {
    2953       42568 :   return _identify_variable_groups;
    2954             : }
    2955             : 
    2956             : inline
    2957           0 : void DofMap::identify_variable_groups (const bool ivg)
    2958             : {
    2959           0 :   _identify_variable_groups = ivg;
    2960           0 : }
    2961             : 
    2962             : inline
    2963      245617 : unsigned int DofMap::n_components(const MeshBase & mesh) const
    2964             : {
    2965      252793 :   if (_variables.empty())
    2966        6854 :     return 0;
    2967             : 
    2968         322 :   const Variable & last = _variables.back();
    2969       11387 :   return last.first_scalar_number() + last.n_components(mesh);
    2970             : }
    2971             : 
    2972             : inline
    2973             : unsigned int
    2974      537987 : DofMap::variable_scalar_number (unsigned int var_num,
    2975             :                                 unsigned int component) const
    2976             : {
    2977     7189846 :   return _variables[var_num].first_scalar_number() + component;
    2978             : }
    2979             : 
    2980             : inline
    2981       34524 : const FEType & DofMap::variable_type (std::string_view var) const
    2982             : {
    2983       35430 :   return _variables[this->variable_number(var)].type();
    2984             : }
    2985             : 
    2986         894 : inline bool DofMap::has_variable(std::string_view var) const
    2987             : {
    2988         894 :   return _variable_numbers.count(var);
    2989             : }
    2990             : 
    2991      385575 : inline unsigned int DofMap::variable_number(std::string_view var) const
    2992             : {
    2993     8938502 :   auto var_num = libmesh_map_find(_variable_numbers, var);
    2994      385575 :   libmesh_assert_equal_to(_variables[var_num].name(), var);
    2995      385575 :   return var_num;
    2996             : }
    2997             : 
    2998             : } // namespace libMesh
    2999             : 
    3000             : #endif // LIBMESH_DOF_MAP_H

Generated by: LCOV version 1.14