Skip to content

Commit 22db5bf

Browse files
authored
Merge pull request #4140 from lindsayad/sc-as-dof-map
StaticCondensation can also be a DofMap
2 parents a988900 + f82ac57 commit 22db5bf

32 files changed

+1607
-709
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -239,3 +239,4 @@ installed
239239
# VSCode related things
240240
.cache
241241
.vscode
242+
compile_commands.json

Makefile.in

Lines changed: 263 additions & 35 deletions
Large diffs are not rendered by default.

include/Makefile.in

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -621,6 +621,7 @@ include_HEADERS = \
621621
base/auto_ptr.h \
622622
base/dirichlet_boundaries.h \
623623
base/dof_map.h \
624+
base/dof_map_base.h \
624625
base/dof_object.h \
625626
base/factory.h \
626627
base/float128_shims.h \
@@ -888,6 +889,7 @@ include_HEADERS = \
888889
numerics/sparse_matrix.h \
889890
numerics/sparse_shell_matrix.h \
890891
numerics/static_condensation.h \
892+
numerics/static_condensation_dof_map.h \
891893
numerics/static_condensation_preconditioner.h \
892894
numerics/sum_shell_matrix.h \
893895
numerics/tensor_shell_matrix.h \

include/base/dof_map.h

Lines changed: 30 additions & 129 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@
3838
#include "libmesh/libmesh_logging.h"
3939
#include "libmesh/enum_elem_type.h"
4040
#include "libmesh/mesh_subdivision_support.h"
41+
#include "libmesh/dof_map_base.h"
4142

4243
// TIMPI includes
4344
#include "timpi/parallel_implementation.h"
@@ -68,7 +69,7 @@ class PeriodicBoundaryBase;
6869
class PeriodicBoundaries;
6970
class System;
7071
class NonlinearImplicitSystem;
71-
class StaticCondensation;
72+
class StaticCondensationDofMap;
7273
template <typename T> class DenseVectorBase;
7374
template <typename T> class DenseVector;
7475
template <typename T> class DenseMatrix;
@@ -175,8 +176,8 @@ class NodeConstraints : public std::map<const Node *,
175176
* \date 2002-2007
176177
* \brief Manages the degrees of freedom (DOFs) in a simulation.
177178
*/
178-
class DofMap : public ReferenceCountedObject<DofMap>,
179-
public ParallelObject
179+
class DofMap : public DofMapBase,
180+
public ReferenceCountedObject<DofMap>
180181
{
181182
public:
182183

@@ -594,10 +595,7 @@ class DofMap : public ReferenceCountedObject<DofMap>,
594595
*/
595596
const VariableGroup & variable_group (const unsigned int c) const;
596597

597-
/**
598-
* \returns The variable description object for variable \p c.
599-
*/
600-
const Variable & variable (const unsigned int c) const;
598+
const Variable & variable (const unsigned int c) const override;
601599

602600
/**
603601
* \returns The approximation order for variable \p c.
@@ -627,12 +625,7 @@ class DofMap : public ReferenceCountedObject<DofMap>,
627625
unsigned int n_variable_groups() const
628626
{ return cast_int<unsigned int>(_variable_groups.size()); }
629627

630-
/**
631-
* \returns The number of variables in the global solution vector. Defaults
632-
* to 1, should be 1 for a scalar equation, 3 for 2D incompressible Navier
633-
* Stokes (u,v,p), etc...
634-
*/
635-
unsigned int n_variables() const
628+
unsigned int n_variables() const override
636629
{ return cast_int<unsigned int>(_variables.size()); }
637630

638631
/**
@@ -667,11 +660,7 @@ class DofMap : public ReferenceCountedObject<DofMap>,
667660
return (this->has_blocked_representation() ? this->n_variables() : 1);
668661
}
669662

670-
/**
671-
* \returns The total number of degrees of freedom in the problem.
672-
*/
673-
dof_id_type n_dofs() const { return _n_dfs; }
674-
663+
using DofMapBase::n_dofs;
675664
/**
676665
* \returns The total number of degrees of freedom for a particular
677666
* variable \p vn.
@@ -688,12 +677,7 @@ class DofMap : public ReferenceCountedObject<DofMap>,
688677
*/
689678
dof_id_type n_SCALAR_dofs() const { return _n_SCALAR_dofs; }
690679

691-
/**
692-
* \returns The number of degrees of freedom on this processor.
693-
*/
694-
dof_id_type n_local_dofs () const
695-
{ return this->n_dofs_on_processor (this->processor_id()); }
696-
680+
using DofMapBase::n_local_dofs;
697681
/**
698682
* \returns The number of degrees of freedom on this processor for a
699683
* particular variable \p vn. This is an O(N) operation on serialized or
@@ -706,15 +690,6 @@ class DofMap : public ReferenceCountedObject<DofMap>,
706690
return n;
707691
}
708692

709-
/**
710-
* \returns The number of degrees of freedom on partition \p proc.
711-
*/
712-
dof_id_type n_dofs_on_processor(const processor_id_type proc) const
713-
{
714-
libmesh_assert_less (proc, _first_df.size());
715-
return cast_int<dof_id_type>(_end_df[proc] - _first_df[proc]);
716-
}
717-
718693
/**
719694
* \returns The number of degrees of freedom on each partition for a
720695
* particular variable \p vn.
@@ -726,39 +701,6 @@ class DofMap : public ReferenceCountedObject<DofMap>,
726701
return n_local_dofs;
727702
}
728703

729-
/**
730-
* \returns The first dof index that is local to partition \p proc.
731-
*/
732-
dof_id_type first_dof(const processor_id_type proc) const
733-
{ libmesh_assert_less (proc, _first_df.size()); return _first_df[proc]; }
734-
735-
dof_id_type first_dof() const
736-
{ return this->first_dof(this->processor_id()); }
737-
738-
#ifdef LIBMESH_ENABLE_AMR
739-
/**
740-
* \returns The first old dof index that is local to partition \p proc.
741-
*/
742-
dof_id_type first_old_dof(const processor_id_type proc) const
743-
{ libmesh_assert_less (proc, _first_old_df.size()); return _first_old_df[proc]; }
744-
745-
dof_id_type first_old_dof() const
746-
{ return this->first_old_dof(this->processor_id()); }
747-
748-
#endif //LIBMESH_ENABLE_AMR
749-
750-
/**
751-
* \returns The first dof index that is after all indices local to
752-
* processor \p proc.
753-
*
754-
* Analogous to the end() member function of STL containers.
755-
*/
756-
dof_id_type end_dof(const processor_id_type proc) const
757-
{ libmesh_assert_less (proc, _end_df.size()); return _end_df[proc]; }
758-
759-
dof_id_type end_dof() const
760-
{ return this->end_dof(this->processor_id()); }
761-
762704
/**
763705
* \returns The processor id that owns the dof index \p dof
764706
*/
@@ -769,25 +711,6 @@ class DofMap : public ReferenceCountedObject<DofMap>,
769711
return cast_int<processor_id_type>(ub - _end_df.begin());
770712
}
771713

772-
#ifdef LIBMESH_ENABLE_AMR
773-
/**
774-
* \returns The first old dof index that is after all indices local
775-
* to processor \p proc.
776-
*
777-
* Analogous to the end() member function of STL containers.
778-
*/
779-
dof_id_type end_old_dof(const processor_id_type proc) const
780-
{ libmesh_assert_less (proc, _end_old_df.size()); return _end_old_df[proc]; }
781-
782-
dof_id_type end_old_dof() const
783-
{ return this->end_old_dof(this->processor_id()); }
784-
785-
#endif //LIBMESH_ENABLE_AMR
786-
787-
/**
788-
* Fills the vector \p di with the global degree of freedom indices
789-
* for the element.
790-
*/
791714
void dof_indices (const Elem * const elem,
792715
std::vector<dof_id_type> & di) const;
793716

@@ -799,7 +722,7 @@ class DofMap : public ReferenceCountedObject<DofMap>,
799722
void dof_indices (const Elem * const elem,
800723
std::vector<dof_id_type> & di,
801724
const unsigned int vn,
802-
int p_level = -12345) const;
725+
int p_level = -12345) const override;
803726

804727
/**
805728
* Retrieves degree of freedom indices for a given \p elem and then performs actions for these
@@ -851,7 +774,7 @@ class DofMap : public ReferenceCountedObject<DofMap>,
851774
*/
852775
void dof_indices (const Node * const node,
853776
std::vector<dof_id_type> & di,
854-
const unsigned int vn) const;
777+
const unsigned int vn) const override;
855778

856779
/**
857780
* Appends to the vector \p di the global degree of freedom indices
@@ -972,6 +895,18 @@ class DofMap : public ReferenceCountedObject<DofMap>,
972895
const MeshBase & mesh,
973896
unsigned int var_num) const;
974897

898+
/**
899+
* If T == dof_id_type, counts, if T == std::vector<dof_id_type>, fills an
900+
* array of, those dof indices which belong to the given variable number and
901+
* live on the current processor.
902+
*/
903+
template <typename T,
904+
std::enable_if_t<std::is_same_v<T, dof_id_type> ||
905+
std::is_same_v<T, std::vector<dof_id_type>>,
906+
int> = 0>
907+
void local_variable_indices(T & idx, unsigned int var_num) const
908+
{ this->local_variable_indices(idx, this->_mesh, var_num); }
909+
975910
#ifdef LIBMESH_ENABLE_CONSTRAINTS
976911

977912
//--------------------------------------------------------------------
@@ -1624,11 +1559,6 @@ class DofMap : public ReferenceCountedObject<DofMap>,
16241559
std::vector<dof_id_type> & di,
16251560
const unsigned int vn = libMesh::invalid_uint) const;
16261561

1627-
/**
1628-
* \returns The total number of degrees of freedom on old_dof_objects
1629-
*/
1630-
dof_id_type n_old_dofs() const { return _n_old_dfs; }
1631-
16321562
#endif // LIBMESH_ENABLE_AMR
16331563

16341564
/**
@@ -1655,7 +1585,7 @@ class DofMap : public ReferenceCountedObject<DofMap>,
16551585
* Free all new memory associated with the object, but restore its
16561586
* original state, with the mesh pointer and any default ghosting.
16571587
*/
1658-
void clear ();
1588+
virtual void clear () override;
16591589

16601590
/**
16611591
* Prints summary info about the sparsity bandwidth and constraints.
@@ -1702,7 +1632,8 @@ class DofMap : public ReferenceCountedObject<DofMap>,
17021632
* constraints or sufficiently many user constraints.
17031633
*/
17041634
std::unique_ptr<SparsityPattern::Build> build_sparsity(const MeshBase & mesh,
1705-
bool calculate_constrained = false) const;
1635+
bool calculate_constrained = false,
1636+
bool use_condensed_system = false) const;
17061637

17071638
/**
17081639
* Describe whether the given variable group should be p-refined. If this API is not called with
@@ -1729,18 +1660,18 @@ class DofMap : public ReferenceCountedObject<DofMap>,
17291660
/**
17301661
* Add a static condensation class
17311662
*/
1732-
void add_static_condensation(const StaticCondensation & sc) { _sc = &sc; }
1663+
void create_static_condensation(const MeshBase & mesh, System & system);
17331664

17341665
/**
17351666
* Checks whether we have static condensation
17361667
*/
1737-
bool has_static_condensation() const { return _sc; }
1668+
bool has_static_condensation() const { return _sc.get(); }
17381669

17391670
/**
17401671
* @returns the static condensation class. This should have been already added with a call to \p
17411672
* add_static_condensation()
17421673
*/
1743-
const StaticCondensation & get_static_condensation() const;
1674+
StaticCondensationDofMap & get_static_condensation();
17441675

17451676
private:
17461677

@@ -2040,16 +1971,6 @@ class DofMap : public ReferenceCountedObject<DofMap>,
20401971
*/
20411972
std::vector<SparseMatrix<Number> * > _matrices;
20421973

2043-
/**
2044-
* First DOF index on processor \p p.
2045-
*/
2046-
std::vector<dof_id_type> _first_df;
2047-
2048-
/**
2049-
* Last DOF index (plus 1) on processor \p p.
2050-
*/
2051-
std::vector<dof_id_type> _end_df;
2052-
20531974
/**
20541975
* First DOF index for SCALAR variable v, or garbage for non-SCALAR
20551976
* variable v
@@ -2152,11 +2073,6 @@ class DofMap : public ReferenceCountedObject<DofMap>,
21522073
*/
21532074
std::unique_ptr<SparsityPattern::Build> _sp;
21542075

2155-
/**
2156-
* Total number of degrees of freedom.
2157-
*/
2158-
dof_id_type _n_dfs;
2159-
21602076
/**
21612077
* The total number of SCALAR dofs associated to
21622078
* all SCALAR variables.
@@ -2165,21 +2081,6 @@ class DofMap : public ReferenceCountedObject<DofMap>,
21652081

21662082
#ifdef LIBMESH_ENABLE_AMR
21672083

2168-
/**
2169-
* Total number of degrees of freedom on old dof objects
2170-
*/
2171-
dof_id_type _n_old_dfs;
2172-
2173-
/**
2174-
* First old DOF index on processor \p p.
2175-
*/
2176-
std::vector<dof_id_type> _first_old_df;
2177-
2178-
/**
2179-
* Last old DOF index (plus 1) on processor \p p.
2180-
*/
2181-
std::vector<dof_id_type> _end_old_df;
2182-
21832084
/**
21842085
* First old DOF index for SCALAR variable v, or garbage for
21852086
* non-SCALAR variable v
@@ -2256,7 +2157,7 @@ class DofMap : public ReferenceCountedObject<DofMap>,
22562157
bool _verify_dirichlet_bc_consistency;
22572158

22582159
/// Static condensation class
2259-
const StaticCondensation * _sc;
2160+
std::unique_ptr<StaticCondensationDofMap> _sc;
22602161
};
22612162

22622163

@@ -2780,7 +2681,7 @@ void DofMap::dof_indices (const Elem * const elem,
27802681
}
27812682

27822683
inline
2783-
const StaticCondensation & DofMap::get_static_condensation() const
2684+
StaticCondensationDofMap & DofMap::get_static_condensation()
27842685
{
27852686
libmesh_assert(_sc);
27862687
return *_sc;

0 commit comments

Comments
 (0)