libMesh
static_condensation_dof_map.h
Go to the documentation of this file.
1 // The libMesh Finite Element Library.
2 // Copyright (C) 2002-2025 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 
107  bool initialized() const { return _sc_is_initialized; }
108 
109  virtual void clear() override;
110 
116 
117 private:
136  dof_id_type full_dof_number,
137  bool involved_in_constraints,
138  std::unordered_map<dof_id_type, dof_id_type> & uncondensed_global_to_local_map,
139  std::unordered_set<dof_id_type> & local_uncondensed_dofs_set,
140  std::unordered_map<processor_id_type, std::unordered_set<dof_id_type>> &
141  nonlocal_uncondensed_dofs,
142  std::vector<dof_id_type> & elem_uncondensed_dofs,
143  dof_id_type & uncondensed_local_dof_number,
144  std::unordered_set<dof_id_type> & constraint_dofs);
145 
162  void add_uncondensed_dof(
163  dof_id_type full_dof_number,
164  bool involved_in_constraints,
165  std::unordered_map<dof_id_type, dof_id_type> & uncondensed_global_to_local_map,
166  std::unordered_set<dof_id_type> & local_uncondensed_dofs_set,
167  std::unordered_map<processor_id_type, std::unordered_set<dof_id_type>> &
168  nonlocal_uncondensed_dofs,
169  std::vector<dof_id_type> & elem_uncondensed_dofs,
170  dof_id_type & uncondensed_local_dof_number,
171  std::unordered_set<dof_id_type> & constraint_dofs);
172 
177  struct DofData
178  {
182  std::vector<std::vector<dof_id_type>> reduced_space_indices;
183 
188  std::unordered_map<dof_id_type, dof_id_type> uncondensed_global_to_local_map;
193  std::unordered_map<dof_id_type, dof_id_type> condensed_global_to_local_map;
194  };
195 
197  friend class StaticCondensation;
198 
200  std::unordered_map<dof_id_type, DofData> _elem_to_dof_data;
201 
205  std::vector<dof_id_type> _local_uncondensed_dofs;
206 
209  const DofMap & _dof_map;
210 
212  std::unordered_set<unsigned int> _uncondensed_vars;
213 
216 
218  std::vector<Variable> _reduced_vars;
219 
222 
224  std::unique_ptr<SparsityPattern::Build> _reduced_sp;
225 
227  std::vector<dof_id_type> _reduced_nnz;
228 
230  std::vector<dof_id_type> _reduced_noz;
231 
235  std::unordered_map<dof_id_type, dof_id_type> _full_to_reduced_constraint_dofs;
236 };
237 
238 inline void
239 StaticCondensationDofMap::dont_condense_vars(const std::unordered_set<unsigned int> & vars)
240 {
241  _uncondensed_vars.insert(vars.begin(), vars.end());
242 }
243 
245 {
247  return *_reduced_system;
248 }
249 
250 inline dof_id_type
252 {
253  return libmesh_map_find(_full_to_reduced_constraint_dofs, full_dof);
254 }
255 
256 }
257 
258 #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
MeshBase & mesh
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:75
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:96
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