implicit_system.h
Go to the documentation of this file.
1 // The libMesh Finite Element Library.
2 // Copyright (C) 2002-2018 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
25 
26 // C++ includes
27 #include <cstddef>
28 
29 namespace libMesh
30 {
31 
32 // Forward declarations
33 template <typename T> class LinearSolver;
34 template <typename T> class SparseMatrix;
35 
57 {
58 public:
59 
65  const std::string & name,
66  const unsigned int number);
67 
71  virtual ~ImplicitSystem ();
72 
77 
81  sys_type & system () { return *this; }
82 
87 
92  virtual void clear () override;
93 
98  virtual void reinit () 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 
133  virtual LinearSolver<Number> * get_linear_solver() const;
134 
140  virtual std::pair<unsigned int, Real>
142 
151  virtual void release_linear_solver(LinearSolver<Number> *) const;
152 
160  virtual void assembly (bool /* get_residual */,
161  bool /* get_jacobian */,
162  bool /* apply_heterogeneous_constraints */ = false,
163  bool /* apply_no_constraints */ = false)
164  { libmesh_not_implemented(); }
165 
177  virtual void assemble_residual_derivatives (const ParameterVector & parameters) override;
178 
184  virtual void solve () override
185  { libmesh_not_implemented(); }
186 
194  virtual std::pair<unsigned int, Real>
195  sensitivity_solve (const ParameterVector & parameters) override;
196 
205  virtual std::pair<unsigned int, Real>
206  weighted_sensitivity_solve (const ParameterVector & parameters,
207  const ParameterVector & weights) override;
208 
218  virtual std::pair<unsigned int, Real>
219  adjoint_solve (const QoISet & qoi_indices = QoISet()) override;
220 
233  virtual std::pair<unsigned int, Real>
235  const ParameterVector & weights,
236  const QoISet & qoi_indices = QoISet()) override;
237 
249  virtual void adjoint_qoi_parameter_sensitivity (const QoISet & qoi_indices,
250  const ParameterVector & parameters,
251  SensitivityData & sensitivities) override;
252 
264  virtual void forward_qoi_parameter_sensitivity (const QoISet & qoi_indices,
265  const ParameterVector & parameters,
266  SensitivityData & sensitivities) override;
267 
283  virtual void qoi_parameter_hessian(const QoISet & qoi_indices,
284  const ParameterVector & parameters,
285  SensitivityData & hessian) override;
286 
297  virtual void qoi_parameter_hessian_vector_product(const QoISet & qoi_indices,
298  const ParameterVector & parameters,
299  const ParameterVector & vector,
300  SensitivityData & product) override;
301 
305  typedef std::map<std::string, SparseMatrix<Number> *>::iterator matrices_iterator;
306  typedef std::map<std::string, SparseMatrix<Number> *>::const_iterator const_matrices_iterator;
307 
316  SparseMatrix<Number> & add_matrix (const std::string & mat_name);
317 
321  void remove_matrix(const std::string & mat_name);
322 
327  bool have_matrix (const std::string & mat_name) const;
328 
334  const SparseMatrix<Number> * request_matrix (const std::string & mat_name) const;
335 
341  SparseMatrix<Number> * request_matrix (const std::string & mat_name);
342 
351  const SparseMatrix<Number> & get_matrix (const std::string & mat_name) const;
352 
361  SparseMatrix<Number> & get_matrix (const std::string & mat_name);
362 
366  virtual unsigned int n_matrices () const override;
367 
374 
381 
382 protected:
383 
388  virtual void init_data () override;
389 
393  virtual void init_matrices ();
394 
395 private:
396 
401  void add_system_matrix ();
402 
406  std::map<std::string, SparseMatrix<Number> *> _matrices;
407 
412 };
413 
414 
415 
416 // ------------------------------------------------------------
417 // ImplicitSystem inline methods
418 inline
419 bool ImplicitSystem::have_matrix (const std::string & mat_name) const
420 {
421  return (_matrices.count(mat_name));
422 }
423 
424 
425 inline
426 unsigned int ImplicitSystem::n_matrices () const
427 {
428  return cast_int<unsigned int>(_matrices.size());
429 }
430 
431 } // namespace libMesh
432 
433 #endif // LIBMESH_IMPLICIT_SYSTEM_H
virtual void init_data() override
Manages multiples systems of equations.
virtual void qoi_parameter_hessian_vector_product(const QoISet &qoi_indices, const ParameterVector &parameters, const ParameterVector &vector, SensitivityData &product) override
const SparseMatrix< Number > & get_matrix(const std::string &mat_name) const
bool have_matrix(const std::string &mat_name) const
Specifies parameters for parameter sensitivity calculations.
virtual std::pair< unsigned int, Real > get_linear_solve_parameters() const
Used to specify quantities of interest in a simulation.
Definition: qoi_set.h:45
virtual std::pair< unsigned int, Real > weighted_sensitivity_solve(const ParameterVector &parameters, const ParameterVector &weights) override
virtual std::string system_type() const override
virtual void clear() override
virtual void reinit() override
SparseMatrix< Number > & add_matrix(const std::string &mat_name)
virtual LinearSolver< Number > * get_linear_solver() const
virtual std::pair< unsigned int, Real > sensitivity_solve(const ParameterVector &parameters) override
std::map< std::string, SparseMatrix< Number > * > _matrices
virtual std::pair< unsigned int, Real > adjoint_solve(const QoISet &qoi_indices=QoISet()) override
virtual void release_linear_solver(LinearSolver< Number > *) const
virtual void forward_qoi_parameter_sensitivity(const QoISet &qoi_indices, const ParameterVector &parameters, SensitivityData &sensitivities) override
unsigned int number() const
Definition: system.h:2025
virtual void assembly(bool, bool, bool=false, bool=false)
Holds completed parameter sensitivity calculations.
virtual void adjoint_qoi_parameter_sensitivity(const QoISet &qoi_indices, const ParameterVector &parameters, SensitivityData &sensitivities) override
virtual void disable_cache() override
const SparseMatrix< Number > * request_matrix(const std::string &mat_name) const
virtual void solve() override
ImplicitSystem(EquationSystems &es, const std::string &name, const unsigned int number)
std::map< std::string, SparseMatrix< Number > * >::const_iterator const_matrices_iterator
virtual unsigned int n_matrices() const override
void remove_matrix(const std::string &mat_name)
SparseMatrix< Number > * matrix
virtual void assemble_residual_derivatives(const ParameterVector &parameters) override
std::map< std::string, SparseMatrix< Number > * >::iterator matrices_iterator
virtual void assemble() override
const std::string & name() const
Definition: system.h:2017
virtual void qoi_parameter_hessian(const QoISet &qoi_indices, const ParameterVector &parameters, SensitivityData &hessian) override
virtual std::pair< unsigned int, Real > weighted_sensitivity_adjoint_solve(const ParameterVector &parameters, const ParameterVector &weights, const QoISet &qoi_indices=QoISet()) override
virtual void init_matrices()
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...