libMesh
static_condensation_dof_map.h
Go to the documentation of this file.
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 #ifndef LIBMESH_STATIC_CONDENSATION_DOF_MAP_H
19 #define LIBMESH_STATIC_CONDENSATION_DOF_MAP_H
20 
21 #include "libmesh/libmesh_config.h"
22 
23 #include "libmesh/id_types.h"
24 #include "libmesh/libmesh_common.h"
25 #include "libmesh/dof_map_base.h"
26 #include "libmesh/variable.h"
27 #include "libmesh/sparsity_pattern.h"
28 #include "libmesh/utility.h"
29 
30 #include <unordered_map>
31 #include <memory>
32 #include <vector>
33 
34 namespace libMesh
35 {
36 class MeshBase;
37 class System;
38 class DofMap;
39 class Elem;
40 
60 {
61 public:
62  StaticCondensationDofMap(MeshBase & mesh, System & system, const DofMap & dof_map);
63  virtual ~StaticCondensationDofMap();
64 
65  //
66  // Unique methods
67  //
68 
72  void reinit();
73 
79  void dont_condense_vars(const std::unordered_set<unsigned int> & vars);
80 
84  const std::unordered_set<unsigned int> & uncondensed_vars() const { return _uncondensed_vars; }
85 
86  virtual unsigned int n_variables() const override;
87 
88  virtual const Variable & variable(const unsigned int c) const override;
89 
90  virtual void dof_indices(const Elem * const elem,
91  std::vector<dof_id_type> & di,
92  const unsigned int vn,
93  int p_level = -12345) const override;
94 
95  virtual void dof_indices(const Node * const node,
96  std::vector<dof_id_type> & di,
97  const unsigned int vn) const override;
98 
99  /*
100  * @returns The dummyish reduced system
101  */
102  const System & reduced_system() const;
103 
104  /*
105  * @returns The mesh
106  */
107  const MeshBase & mesh () const { return _mesh; }
108 
112  bool initialized() const { return _sc_is_initialized; }
113 
114  virtual void clear() override;
115 
121 
122 private:
141  dof_id_type full_dof_number,
142  bool involved_in_constraints,
143  std::unordered_map<dof_id_type, dof_id_type> & uncondensed_global_to_local_map,
144  std::unordered_set<dof_id_type> & local_uncondensed_dofs_set,
145  std::unordered_map<processor_id_type, std::unordered_set<dof_id_type>> &
146  nonlocal_uncondensed_dofs,
147  std::vector<dof_id_type> & elem_uncondensed_dofs,
148  dof_id_type & uncondensed_local_dof_number,
149  std::unordered_set<dof_id_type> & constraint_dofs);
150 
167  void add_uncondensed_dof(
168  dof_id_type full_dof_number,
169  bool involved_in_constraints,
170  std::unordered_map<dof_id_type, dof_id_type> & uncondensed_global_to_local_map,
171  std::unordered_set<dof_id_type> & local_uncondensed_dofs_set,
172  std::unordered_map<processor_id_type, std::unordered_set<dof_id_type>> &
173  nonlocal_uncondensed_dofs,
174  std::vector<dof_id_type> & elem_uncondensed_dofs,
175  dof_id_type & uncondensed_local_dof_number,
176  std::unordered_set<dof_id_type> & constraint_dofs);
177 
182  struct DofData
183  {
187  std::vector<std::vector<dof_id_type>> reduced_space_indices;
188 
193  std::unordered_map<dof_id_type, dof_id_type> uncondensed_global_to_local_map;
198  std::unordered_map<dof_id_type, dof_id_type> condensed_global_to_local_map;
199  };
200 
202  friend class StaticCondensation;
203 
205  std::unordered_map<dof_id_type, DofData> _elem_to_dof_data;
206 
210  std::vector<dof_id_type> _local_uncondensed_dofs;
211 
214  const DofMap & _dof_map;
215 
217  std::unordered_set<unsigned int> _uncondensed_vars;
218 
221 
223  std::vector<Variable> _reduced_vars;
224 
227 
229  std::unique_ptr<SparsityPattern::Build> _reduced_sp;
230 
232  std::vector<dof_id_type> _reduced_nnz;
233 
235  std::vector<dof_id_type> _reduced_noz;
236 
240  std::unordered_map<dof_id_type, dof_id_type> _full_to_reduced_constraint_dofs;
241 };
242 
243 inline void
244 StaticCondensationDofMap::dont_condense_vars(const std::unordered_set<unsigned int> & vars)
245 {
246  _uncondensed_vars.insert(vars.begin(), vars.end());
247 }
248 
250 {
252  return *_reduced_system;
253 }
254 
255 inline dof_id_type
257 {
258  return libmesh_map_find(_full_to_reduced_constraint_dofs, full_dof);
259 }
260 
261 }
262 
263 #endif // LIBMESH_STATIC_CONDENSATION_DOF_MAP_H
A class holding degree of freedom information pertinent to static condensation.
A Node is like a Point, but with more information.
Definition: node.h:52
std::unordered_set< unsigned int > _uncondensed_vars
Variables for which we will keep all dofs.
virtual const Variable & variable(const unsigned int c) const override
std::unordered_map< dof_id_type, dof_id_type > _full_to_reduced_constraint_dofs
A small map from full system degrees of freedom to reduced/condensed system degrees of freedom involv...
std::vector< dof_id_type > _reduced_nnz
Number of on-diagonal nonzeros per row in the reduced system.
std::unordered_map< dof_id_type, dof_id_type > condensed_global_to_local_map
A map from the global degree of freedom number for the full system (condensed + uncondensed) to an el...
std::unordered_map< dof_id_type, dof_id_type > uncondensed_global_to_local_map
A map from the global degree of freedom number for the full system (condensed + uncondensed) to an el...
std::vector< dof_id_type > _reduced_noz
Number of off-diagonal nonzeros per row in the reduced system.
std::vector< Variable > _reduced_vars
The variables in the reduced system.
This is the base class from which all geometric element types are derived.
Definition: elem.h:94
dof_id_type get_reduced_from_global_constraint_dof(dof_id_type full_dof) const
Retrieve the dof index in the reduced system corresponding to the provided dof index in the full syst...
The libMesh namespace provides an interface to certain functionality in the library.
Data stored on a per-element basis used to compute element Schur complements and their applications t...
uint8_t processor_id_type
Definition: id_types.h:104
This is the MeshBase class.
Definition: mesh_base.h:80
System * _reduced_system
A dummyish system to help with DofObjects.
std::unordered_map< dof_id_type, DofData > _elem_to_dof_data
A map from element ID to Schur complement data.
std::vector< std::vector< dof_id_type > > reduced_space_indices
The uncondensed degrees of freedom with global numbering corresponding to the the reduced system...
virtual unsigned int n_variables() const override
This class handles the numbering of degrees of freedom on a mesh.
Definition: dof_map.h:179
void add_uncondensed_dof(dof_id_type full_dof_number, bool involved_in_constraints, std::unordered_map< dof_id_type, dof_id_type > &uncondensed_global_to_local_map, std::unordered_set< dof_id_type > &local_uncondensed_dofs_set, std::unordered_map< processor_id_type, std::unordered_set< dof_id_type >> &nonlocal_uncondensed_dofs, std::vector< dof_id_type > &elem_uncondensed_dofs, dof_id_type &uncondensed_local_dof_number, std::unordered_set< dof_id_type > &constraint_dofs)
Add an uncondensed dof.
void dont_condense_vars(const std::unordered_set< unsigned int > &vars)
Add vars to the list of variables not to condense.
This class defines the notion of a variable in the system.
Definition: variable.h:50
StaticCondensationDofMap(MeshBase &mesh, System &system, const DofMap &dof_map)
bool _sc_is_initialized
Whether our object has been initialized.
const std::unordered_set< unsigned int > & uncondensed_vars() const
Manages consistently variables, degrees of freedom, and coefficient vectors.
Definition: system.h:98
std::vector< dof_id_type > _local_uncondensed_dofs
All the uncondensed degrees of freedom (numbered in the "full" uncondensed + condensed space)...
This base class provides a minimal set of interfaces for satisfying user requests for...
Definition: dof_map_base.h:51
libmesh_assert(ctx)
void reinit()
Build the element global to local index maps.
virtual void dof_indices(const Elem *const elem, std::vector< dof_id_type > &di, const unsigned int vn, int p_level=-12345) const override
Fills the vector di with the global degree of freedom indices for the element.
std::unique_ptr< SparsityPattern::Build > _reduced_sp
Owned storage of the reduced system sparsity pattern.
bool initialized() const
Whether we are initialized.
void add_uncondensed_dof_plus_constraint_dofs(dof_id_type full_dof_number, bool involved_in_constraints, std::unordered_map< dof_id_type, dof_id_type > &uncondensed_global_to_local_map, std::unordered_set< dof_id_type > &local_uncondensed_dofs_set, std::unordered_map< processor_id_type, std::unordered_set< dof_id_type >> &nonlocal_uncondensed_dofs, std::vector< dof_id_type > &elem_uncondensed_dofs, dof_id_type &uncondensed_local_dof_number, std::unordered_set< dof_id_type > &constraint_dofs)
Add an uncondensed dof potentially along with constraining dofs which themselves must/will also be un...
uint8_t dof_id_type
Definition: id_types.h:67