libMesh
implicit_system.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 
19 
20 #ifndef LIBMESH_IMPLICIT_SYSTEM_H
21 #define LIBMESH_IMPLICIT_SYSTEM_H
22 
23 // Local Includes
24 #include "libmesh/explicit_system.h"
25 
26 // C++ includes
27 #include <cstddef>
28 #include <memory>
29 
30 namespace libMesh
31 {
32 
33 // Forward declarations
34 template <typename T> class LinearSolver;
35 class StaticCondensation;
36 
58 {
59 public:
60 
65  const std::string & name,
66  const unsigned int number);
67 
73  ImplicitSystem (const ImplicitSystem &) = delete;
74  ImplicitSystem & operator= (const ImplicitSystem &) = delete;
75  ImplicitSystem (ImplicitSystem &&) = default;
77  virtual ~ImplicitSystem ();
78 
83 
87  sys_type & system () { return *this; }
88 
93 
98  virtual void clear () override;
99 
105  virtual void assemble () override;
106 
111  virtual void disable_cache () override;
112 
117  virtual std::string system_type () const override { return "Implicit"; }
118 
134  virtual LinearSolver<Number> * get_linear_solver() const;
135 
141  virtual std::pair<unsigned int, Real>
143 
144 #ifdef LIBMESH_ENABLE_DEPRECATED
145 
152  virtual void release_linear_solver(LinearSolver<Number> *) const;
153 #endif // LIBMESH_ENABLE_DEPRECATED
154 
162  virtual void assembly (bool /* get_residual */,
163  bool /* get_jacobian */,
164  bool /* apply_heterogeneous_constraints */ = false,
165  bool /* apply_no_constraints */ = false)
166  { libmesh_not_implemented(); }
167 
179  virtual void assemble_residual_derivatives (const ParameterVector & parameters) override;
180 
186  virtual void solve () override
187  { libmesh_not_implemented(); }
188 
196  virtual std::pair<unsigned int, Real>
197  sensitivity_solve (const ParameterVector & parameters) override;
198 
207  virtual std::pair<unsigned int, Real>
209  const ParameterVector & weights) override;
210 
220  virtual std::pair<unsigned int, Real>
221  adjoint_solve (const QoISet & qoi_indices = QoISet()) override;
222 
235  virtual std::pair<unsigned int, Real>
237  const ParameterVector & weights,
238  const QoISet & qoi_indices = QoISet()) override;
239 
251  virtual void adjoint_qoi_parameter_sensitivity (const QoISet & qoi_indices,
252  const ParameterVector & parameters,
253  SensitivityData & sensitivities) override;
254 
266  virtual void forward_qoi_parameter_sensitivity (const QoISet & qoi_indices,
267  const ParameterVector & parameters,
268  SensitivityData & sensitivities) override;
269 
285  virtual void qoi_parameter_hessian(const QoISet & qoi_indices,
286  const ParameterVector & parameters,
287  SensitivityData & hessian) override;
288 
299  virtual void qoi_parameter_hessian_vector_product(const QoISet & qoi_indices,
300  const ParameterVector & parameters,
301  const ParameterVector & vector,
302  SensitivityData & product) override;
303 
307  const SparseMatrix<Number> & get_system_matrix() const;
308 
313 
323 
330 
339  mutable std::unique_ptr<LinearSolver<Number>> linear_solver;
340 
341  virtual void create_static_condensation() override;
342 
347 
348 protected:
352  virtual void add_matrices() override;
353 
357  template <typename T>
359 
360 private:
365 
370 };
371 
372 inline
374 {
376  return *_sc_system_matrix;
377 }
378 
379 } // namespace libMesh
380 
381 #endif // LIBMESH_IMPLICIT_SYSTEM_H
This is the EquationSystems class.
virtual void qoi_parameter_hessian_vector_product(const QoISet &qoi_indices, const ParameterVector &parameters, const ParameterVector &vector, SensitivityData &product) override
For each of the system&#39;s quantities of interest q in qoi[qoi_indices], and for a vector of parameters...
void create_static_condensation_system_matrix()
Create the static condensation system matrix.
Data structure for specifying which Parameters should be independent variables in a parameter sensiti...
virtual void create_static_condensation() override
Request that static condensation be performed for this system.
virtual std::pair< unsigned int, Real > get_linear_solve_parameters() const
Data structure for specifying which Quantities of Interest should be calculated in an adjoint or a pa...
Definition: qoi_set.h:45
virtual std::pair< unsigned int, Real > weighted_sensitivity_solve(const ParameterVector &parameters, const ParameterVector &weights) override
Assembles & solves the linear system(s) (dR/du)*u_w = sum(w_p*-dR/dp), for those parameters p contain...
virtual std::string system_type() const override
virtual void clear() override
Clear all the data structures associated with the system.
virtual LinearSolver< Number > * get_linear_solver() const
virtual std::pair< unsigned int, Real > sensitivity_solve(const ParameterVector &parameters) override
Assembles & solves the linear system(s) (dR/du)*u_p = -dR/dp, for those parameters contained within p...
The libMesh namespace provides an interface to certain functionality in the library.
bool zero_out_matrix_and_rhs
By default, the system will zero out the matrix and the right hand side.
virtual std::pair< unsigned int, Real > adjoint_solve(const QoISet &qoi_indices=QoISet()) override
Assembles & solves the linear system (dR/du)^T*z = dq/du, for those quantities of interest q specifie...
StaticCondensation * _sc_system_matrix
The system matrix for static condensation problems.
Parameters parameters
Parameters for the system. If a parameter is not provided, it should be retrieved from the EquationSy...
Definition: system.h:1526
ImplicitSystem & operator=(const ImplicitSystem &)=delete
void setup_static_condensation_preconditioner(T &solver)
Sets up the static condensation preconditioner for the supplied solver.
virtual void release_linear_solver(LinearSolver< Number > *) const
Currently a no-op.
virtual void forward_qoi_parameter_sensitivity(const QoISet &qoi_indices, const ParameterVector &parameters, SensitivityData &sensitivities) override
Solves for the derivative of each of the system&#39;s quantities of interest q in qoi[qoi_indices] with r...
ImplicitSystem sys_type
The type of system.
unsigned int number() const
Definition: system.h:2350
virtual void assembly(bool, bool, bool=false, bool=false)
Assembles a residual in rhs and/or a jacobian in matrix, as requested.
Data structure for holding completed parameter sensitivity calculations.
virtual void adjoint_qoi_parameter_sensitivity(const QoISet &qoi_indices, const ParameterVector &parameters, SensitivityData &sensitivities) override
Solves for the derivative of each of the system&#39;s quantities of interest q in qoi[qoi_indices] with r...
libmesh_assert(ctx)
StaticCondensation & get_static_condensation()
virtual void disable_cache() override
Avoids use of any cached data that might affect any solve result.
virtual void solve() override
For explicit systems, just assemble and solve the system A*x=b.
ExplicitSystem Parent
The type of the parent.
ImplicitSystem(EquationSystems &es, const std::string &name, const unsigned int number)
Constructor.
virtual void add_matrices() override
Adds the system matrix.
SparseMatrix< Number > * matrix
The system matrix.
virtual void assemble_residual_derivatives(const ParameterVector &parameters) override
Residual parameter derivative function.
virtual void assemble() override
Prepares matrix and rhs for system assembly, then calls user assembly function.
const std::string & name() const
Definition: system.h:2342
std::unique_ptr< LinearSolver< Number > > linear_solver
This class handles all the details of interfacing with various linear algebra packages like PETSc or ...
virtual void qoi_parameter_hessian(const QoISet &qoi_indices, const ParameterVector &parameters, SensitivityData &hessian) override
For each of the system&#39;s quantities of interest q in qoi[qoi_indices], and for a vector of parameters...
virtual std::pair< unsigned int, Real > weighted_sensitivity_adjoint_solve(const ParameterVector &parameters, const ParameterVector &weights, const QoISet &qoi_indices=QoISet()) override
Assembles & solves the linear system(s) (dR/du)^T*z_w = sum(w_p*(d^2q/dudp - d^2R/dudp*z)), for those parameters p contained within parameters, weighted by the values w_p found within weights.
const SparseMatrix< Number > & get_system_matrix() const
Manages consistently variables, degrees of freedom, and coefficient vectors for explicit systems...
Manages consistently variables, degrees of freedom, coefficient vectors, and matrices for implicit sy...