18 #ifndef LIBMESH_STATIC_CONDENSATION_H 19 #define LIBMESH_STATIC_CONDENSATION_H 21 #include "libmesh/libmesh_config.h" 24 #if defined(LIBMESH_HAVE_EIGEN) && defined(LIBMESH_HAVE_PETSC) 26 #include "libmesh/petsc_matrix_shell_matrix.h" 27 #include "libmesh/id_types.h" 28 #include "libmesh/libmesh_common.h" 29 #include "libmesh/dense_matrix.h" 30 #include "libmesh/variable.h" 31 #include "libmesh/sparsity_pattern.h" 33 #include <unordered_map> 38 #include "libmesh/ignore_warnings.h" 39 #include <Eigen/Dense> 40 #include "libmesh/restore_warnings.h" 57 typedef Eigen::Matrix<Number, Eigen::Dynamic, Eigen::Dynamic>
EigenMatrix;
65 const DofMap & full_dof_map,
89 virtual void clear() noexcept
override;
91 virtual void zero()
override;
93 virtual std::unique_ptr<SparseMatrix<Number>>
zero_clone()
const override;
95 virtual std::unique_ptr<SparseMatrix<Number>>
clone()
const override;
97 virtual void close()
override;
118 const std::vector<numeric_index_type> & rows,
119 const std::vector<numeric_index_type> & cols)
override;
122 const std::vector<numeric_index_type> & dof_indices)
override;
132 virtual bool closed()
const override;
141 std::vector<numeric_index_type> & indices,
142 std::vector<Number> & values)
const override;
203 const std::vector<dof_id_type> & elem_dof_indices,
204 std::vector<Number> & elem_dof_values_vec,
239 typename std::remove_const<decltype(
Acc.partialPivLu())>::type
AccFactor;
273 std::unique_ptr<StaticCondensationPreconditioner>
_scp;
298 libmesh_assert_msg(
_reduced_solver,
"Reduced system solver not built yet");
306 #include "libmesh/sparse_matrix.h" 307 #include <unordered_set> 314 class StaticCondensationPreconditioner;
315 class StaticCondensationDofMap;
317 class StaticCondensation :
public SparseMatrix<Number>
322 const DofMap & full_dof_map,
323 StaticCondensationDofMap & reduced_dof_map);
325 const std::unordered_set<unsigned int> &
uncondensed_vars()
const { libmesh_not_implemented(); }
329 libmesh_not_implemented();
340 libmesh_not_implemented();
343 virtual void clear()
override { libmesh_not_implemented(); }
344 virtual void zero()
override { libmesh_not_implemented(); }
345 virtual std::unique_ptr<SparseMatrix<Number>>
zero_clone()
const override 347 libmesh_not_implemented();
349 virtual std::unique_ptr<SparseMatrix<Number>>
clone()
const override 351 libmesh_not_implemented();
353 virtual void close()
override { libmesh_not_implemented(); }
362 libmesh_not_implemented();
366 libmesh_not_implemented();
369 const std::vector<numeric_index_type> &,
370 const std::vector<numeric_index_type> &)
override 372 libmesh_not_implemented();
375 const std::vector<numeric_index_type> &)
override 377 libmesh_not_implemented();
381 libmesh_not_implemented();
385 libmesh_not_implemented();
387 virtual Real l1_norm()
const override { libmesh_not_implemented(); }
389 virtual bool closed()
const override { libmesh_not_implemented(); }
392 libmesh_not_implemented();
397 std::vector<numeric_index_type> &,
398 std::vector<Number> &)
const override 400 libmesh_not_implemented();
402 void init() { libmesh_not_implemented(); }
403 void setup() { libmesh_not_implemented(); }
408 #endif // LIBMESH_HAVE_EIGEN && LIBMESH_HAVE_PETSC 409 #endif // LIBMESH_STATIC_CONDENSATION_H void forward_elimination(const NumericVector< Number > &full_rhs)
Takes an incoming "full" RHS from the solver, where full means the union of uncondensed and condennse...
virtual std::unique_ptr< SparseMatrix< Number > > clone() const override
virtual Number operator()(const numeric_index_type i, const numeric_index_type j) const override
virtual void close() override
Calls the SparseMatrix's internal assembly routines, ensuring that the values are consistent across p...
Eigen::Matrix< Number, Eigen::Dynamic, Eigen::Dynamic > EigenMatrix
A class holding degree of freedom information pertinent to static condensation.
static void set_local_vectors(const NumericVector< Number > &global_vector, const std::vector< dof_id_type > &elem_dof_indices, std::vector< Number > &elem_dof_values_vec, EigenVector &elem_dof_values)
Retrieves the degree of freedom values from global_vector corresponding to elem_dof_indices, filling both elem_dof_values_vec and elem_dof_values.
void init()
Size the element matrices.
virtual SparseMatrix< Number > & operator=(const SparseMatrix< Number > &) override
This looks like a copy assignment operator, but note that, unlike normal copy assignment operators...
virtual std::unique_ptr< SparseMatrix< Number > > clone() const override
virtual void clear() override
Restores the SparseMatrix<T> to a pristine state.
void set_current_elem(const Elem &elem)
Set the current element.
StaticCondensationDofMap & _reduced_dof_map
virtual void zero() override
Set all entries to 0.
virtual std::unique_ptr< SparseMatrix< Number > > zero_clone() const override
void backwards_substitution(const NumericVector< Number > &full_rhs, NumericVector< Number > &full_sol)
After performing the solve with the _reduced_rhs and Schur complement matrix (_reduced_sys_mat) to de...
This class allows to use a PETSc shell matrix as a PetscMatrix.
std::unique_ptr< LinearSolver< Number > > _reduced_solver
The solver for the uncondensed degrees of freedom.
void setup()
A no-op to be consistent with shimming from the StaticCondenstionPreconditioner.
ParallelType _parallel_type
The parallel type to use for the reduced matrix.
virtual numeric_index_type row_stop() const override
Eigen::Matrix< Number, Eigen::Dynamic, 1 > EigenVector
virtual bool initialized() const override
virtual void close() override
Calls the SparseMatrix's internal assembly routines, ensuring that the values are consistent across p...
virtual void get_row(numeric_index_type i, std::vector< numeric_index_type > &indices, std::vector< Number > &values) const override
Get a row from the matrix.
std::unique_ptr< NumericVector< Number > > _reduced_sol
solution for the uncondensed degrees of freedom
virtual numeric_index_type col_start() const override
This is the base class from which all geometric element types are derived.
virtual numeric_index_type m() const override
Provides a uniform interface to vector storage schemes for different linear algebra libraries...
virtual numeric_index_type n() const override
virtual SolverPackage solver_package() override
The libMesh namespace provides an interface to certain functionality in the library.
EigenMatrix Acu
condensed-uncondensed matrix entries
EigenMatrix Auu
uncondensed-uncondensed matrix entries
dof_id_type _current_elem_id
The current element ID.
virtual Real l1_norm() const override
virtual numeric_index_type row_start() const override
This is the MeshBase class.
void dont_condense_vars(const std::unordered_set< unsigned int > &vars)
Add vars to the list of variables not to condense.
virtual numeric_index_type row_stop() const override
virtual bool require_sparsity_pattern() const override
virtual numeric_index_type m() const override
virtual numeric_index_type row_start() const override
This class handles the numbering of degrees of freedom on a mesh.
virtual void init(const numeric_index_type, const numeric_index_type, const numeric_index_type, const numeric_index_type, const numeric_index_type=30, const numeric_index_type=10, const numeric_index_type=1) override
Initialize SparseMatrix with the specified sizes.
const std::unordered_set< unsigned int > & uncondensed_vars() const
This base class can be inherited from to provide interfaces to linear solvers from different packages...
This class provides a uniform interface for preconditioners.
virtual void get_transpose(SparseMatrix< Number > &) const override
Copies the transpose of the matrix into dest, which may be *this.
virtual void get_row(numeric_index_type, std::vector< numeric_index_type > &, std::vector< Number > &) const override
Get a row from the matrix.
virtual void add(const numeric_index_type i, const numeric_index_type j, const Number value) override
Add value to the element (i,j).
void apply(const NumericVector< Number > &full_rhs, NumericVector< Number > &full_sol)
Perform our three stages, forward_elimination(), a solve() on the condensed system, and finally a backwards_substitution()
dof_id_type numeric_index_type
virtual Real l1_norm() const override
Manages consistently variables, degrees of freedom, and coefficient vectors.
virtual ~StaticCondensation()
virtual void print_personal(std::ostream &os=libMesh::out) const override
Print the contents of the matrix to the screen in a package-personalized style, if available...
virtual void clear() noexcept override
Restores the SparseMatrix<T> to a pristine state.
Data stored on a per-element basis used to compute element Schur complements and their applications t...
DenseMatrix< Number > _size_one_mat
Helper data member for adding individual matrix elements.
std::unordered_map< dof_id_type, MatrixData > _elem_to_matrix_data
A map from element ID to Schur complement data.
virtual void get_diagonal(NumericVector< Number > &dest) const override
Copies the diagonal part of the matrix into dest.
virtual numeric_index_type col_stop() const override
virtual Number operator()(const numeric_index_type, const numeric_index_type) const override
virtual void add(const numeric_index_type, const numeric_index_type, const Number) override
Add value to the element (i,j).
const DofMap & _full_dof_map
bool _uncondensed_dofs_only
whether this matrix represents uncondensed dofs only.
virtual void print_personal(std::ostream &=libMesh::out) const override
Print the contents of the matrix to the screen in a package-personalized style, if available...
std::unique_ptr< SparseMatrix< Number > > _reduced_sys_mat
global sparse matrix for the uncondensed degrees of freedom
virtual void add_matrix(const DenseMatrix< Number > &, const std::vector< numeric_index_type > &, const std::vector< numeric_index_type > &) override
Add the full matrix dm to the SparseMatrix.
virtual void add_matrix(const DenseMatrix< Number > &dm, const std::vector< numeric_index_type > &rows, const std::vector< numeric_index_type > &cols) override
Add the full matrix dm to the SparseMatrix.
virtual Real linfty_norm() const override
EigenMatrix Auc
uncondensed-condensed matrix entries
std::unique_ptr< NumericVector< Number > > _reduced_rhs
RHS corresponding to the uncondensed degrees of freedom.
DIE A HORRIBLE DEATH HERE typedef LIBMESH_DEFAULT_SCALAR_TYPE Real
EigenMatrix Acc
condensed-condensed matrix entries
virtual void get_diagonal(NumericVector< Number > &) const override
Copies the diagonal part of the matrix into dest.
virtual Real linfty_norm() const override
void apply(const NumericVector< Number > &, NumericVector< Number > &)
std::unique_ptr< StaticCondensationPreconditioner > _scp
Preconditioner object which will call back to us for the preconditioning action.
virtual SparseMatrix< Number > & operator=(const SparseMatrix< Number > &) override
This looks like a copy assignment operator, but note that, unlike normal copy assignment operators...
void uncondensed_dofs_only()
Sets whether this matrix represents uncondensed dofs only.
virtual std::unique_ptr< SparseMatrix< Number > > zero_clone() const override
virtual void add(const Number, const SparseMatrix< Number > &) override
Compute for scalar a, matrix X.
bool _have_cached_values
Whether we have cached values via add_XXX()
std::remove_const< decltype(Acc.partialPivLu())>::type AccFactor
virtual bool closed() const override
const SparseMatrix< Number > & get_condensed_mat() const
virtual void get_transpose(SparseMatrix< Number > &dest) const override
Copies the transpose of the matrix into dest, which may be *this.
StaticCondensation(const MeshBase &mesh, System &system, const DofMap &full_dof_map, StaticCondensationDofMap &reduced_dof_map)
virtual bool closed() const override
virtual void init(ParallelType) override
Initialize this matrix using the sparsity structure computed by dof_map.
SolverPackage
Defines an enum for various linear solver packages.
virtual SolverPackage solver_package() override
virtual void add_matrix(const DenseMatrix< Number > &, const std::vector< numeric_index_type > &) override
Same as add_matrix, but assumes the row and column maps are the same.
LinearSolver< Number > & reduced_system_solver()
virtual void zero() override
Set all entries to 0.
std::unique_ptr< NumericVector< Number > > _ghosted_full_sol
This is a ghosted representation of the full (uncondensed + condensed) solution. Note that...
StaticCondensationPreconditioner & get_preconditioner()
Get the preconditioning wrapper.
ParallelType
Defines an enum for parallel data structure types.
bool _sc_is_initialized
Whether our object has been initialized.