libMesh
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_SYSTEM_H
21 #define LIBMESH_SYSTEM_H
22 
23 // Local Includes
24 #include "libmesh/elem_range.h"
25 #include "libmesh/enum_subset_solve_mode.h" // SUBSET_ZERO
26 #include "libmesh/enum_parallel_type.h" // PARALLEL
27 #include "libmesh/fem_function_base.h"
28 #include "libmesh/libmesh_common.h"
29 #include "libmesh/parallel_object.h"
30 #include "libmesh/parameters.h"
31 #include "libmesh/qoi_set.h"
32 #include "libmesh/reference_counted_object.h"
33 #include "libmesh/tensor_value.h" // For point_hessian
34 #include "libmesh/enum_matrix_build_type.h" // AUTOMATIC
35 
36 // C++ includes
37 #include <cstddef>
38 #include <set>
39 #include <string>
40 #include <string_view>
41 #include <vector>
42 #include <memory>
43 
44 // This define may be useful in --disable-optional builds when it is
45 // possible that libmesh will not have any solvers available.
46 #if defined(LIBMESH_HAVE_PETSC) || \
47  defined(LIBMESH_HAVE_EIGEN) || \
48  defined(LIBMESH_HAVE_LASPACK) || \
49  defined(LIBMESH_TRILINOS_HAVE_AZTECOO)
50 #define LIBMESH_HAVE_SOLVER 1
51 #endif
52 
53 namespace libMesh
54 {
55 
56 // Forward Declarations
57 class System;
58 class EquationSystems;
59 class MeshBase;
60 class Xdr;
61 class DofMap;
62 template <typename Output> class FunctionBase;
63 class ParameterVector;
64 class Point;
65 class SensitivityData;
66 class Matrix;
67 template <typename T> class NumericVector;
68 template <typename T> class SparseMatrix;
69 template <typename T> class VectorValue;
70 typedef VectorValue<Number> NumberVectorValue;
72 class SystemSubset;
73 class FEType;
74 class SystemNorm;
75 enum FEMNormType : int;
76 class Variable;
77 class VariableGroup;
78 
97 class System : public ReferenceCountedObject<System>,
98  public ParallelObject
99 {
100 public:
101 
106  System (EquationSystems & es,
107  const std::string & name,
108  const unsigned int number);
109 
120  System (const System &) = delete;
121  System & operator= (const System &) = delete;
122  System (System &&) = default;
123  System & operator= (System &&) = delete;
124  virtual ~System ();
125 
133  {
134  public:
138  virtual ~Initialization () = default;
139 
145  virtual void initialize () = 0;
146  };
147 
148 
149 
156  class Assembly
157  {
158  public:
162  virtual ~Assembly () = default;
163 
169  virtual void assemble () = 0;
170  };
171 
172 
173 
181  {
182  public:
186  virtual ~Constraint () = default;
187 
193  virtual void constrain () = 0;
194  };
195 
196 
197 
204  class QOI
205  {
206  public:
210  virtual ~QOI () = default;
211 
217  virtual void qoi (const QoISet & qoi_indices) = 0;
218  };
219 
220 
221 
229  {
230  public:
234  virtual ~QOIDerivative () = default;
235 
241  virtual void qoi_derivative (const QoISet & qoi_indices,
242  bool include_liftfunc,
243  bool apply_constraints) = 0;
244  };
245 
249  typedef System sys_type;
250 
254  sys_type & system () { return *this; }
255 
260  virtual void clear ();
261 
266  void init ();
267 
276  virtual void reinit ();
277 
284  virtual void reinit_constraints ();
285 
289  virtual void reinit_mesh();
290 
294  bool is_initialized() const;
295 
300  virtual void update ();
301 
308  virtual void assemble ();
309 
314  virtual void assemble_qoi (const QoISet & qoi_indices = QoISet());
315 
320  virtual void assemble_qoi_derivative (const QoISet & qoi_indices = QoISet(),
321  bool include_liftfunc = true,
322  bool apply_constraints = true);
323 
336 
342  virtual void restrict_solve_to (const SystemSubset * subset,
343  const SubsetSolveMode subset_solve_mode=SUBSET_ZERO);
344 
348  virtual void solve () {}
349 
359  virtual std::pair<unsigned int, Real>
361 
372  virtual std::pair<unsigned int, Real>
374  const ParameterVector & weights);
375 
386  virtual std::pair<unsigned int, Real>
387  adjoint_solve (const QoISet & qoi_indices = QoISet());
388 
403  virtual std::pair<unsigned int, Real>
405  const ParameterVector & weights,
406  const QoISet & qoi_indices = QoISet());
411  { return adjoint_already_solved;}
412 
416  void set_adjoint_already_solved(bool setting)
417  { adjoint_already_solved = setting;}
418 
419 
437  virtual void qoi_parameter_sensitivity (const QoISet & qoi_indices,
438  const ParameterVector & parameters,
439  SensitivityData & sensitivities);
440 
446  virtual void adjoint_qoi_parameter_sensitivity (const QoISet & qoi_indices,
447  const ParameterVector & parameters,
448  SensitivityData & sensitivities);
449 
455  virtual void forward_qoi_parameter_sensitivity (const QoISet & qoi_indices,
456  const ParameterVector & parameters,
457  SensitivityData & sensitivities);
458 
469  virtual void qoi_parameter_hessian(const QoISet & qoi_indices,
470  const ParameterVector & parameters,
471  SensitivityData & hessian);
472 
485  virtual void qoi_parameter_hessian_vector_product(const QoISet & qoi_indices,
486  const ParameterVector & parameters,
487  const ParameterVector & vector,
488  SensitivityData & product);
489 
495  virtual bool compare (const System & other_system,
496  const Real threshold,
497  const bool verbose) const;
498 
502  const std::string & name () const;
503 
509  virtual std::string system_type () const { return "Basic"; }
510 
519  FunctionBase<Gradient> * g = nullptr) const;
520 
529  FEMFunctionBase<Gradient> * g = nullptr) const;
530 
538  typedef Number (*ValueFunctionPointer)(const Point & p,
539  const Parameters & Parameters,
540  const std::string & sys_name,
541  const std::string & unknown_name);
542  typedef Gradient (*GradientFunctionPointer)(const Point & p,
543  const Parameters & parameters,
544  const std::string & sys_name,
545  const std::string & unknown_name);
548  const Parameters & parameters) const;
549 
561  void project_vector (NumericVector<Number> & new_vector,
563  FunctionBase<Gradient> * g = nullptr,
564  int is_adjoint = -1) const;
565 
577  void project_vector (NumericVector<Number> & new_vector,
579  FEMFunctionBase<Gradient> * g = nullptr,
580  int is_adjoint = -1) const;
581 
595  const Parameters & parameters,
596  NumericVector<Number> & new_vector,
597  int is_adjoint = -1) const;
598 
611  void boundary_project_solution (const std::set<boundary_id_type> & b,
612  const std::vector<unsigned int> & variables,
614  FunctionBase<Gradient> * g = nullptr);
615 
628  void boundary_project_solution (const std::set<boundary_id_type> & b,
629  const std::vector<unsigned int> & variables,
632  const Parameters & parameters);
633 
649  void boundary_project_vector (const std::set<boundary_id_type> & b,
650  const std::vector<unsigned int> & variables,
651  NumericVector<Number> & new_vector,
653  FunctionBase<Gradient> * g = nullptr,
654  int is_adjoint = -1) const;
655 
671  void boundary_project_vector (const std::set<boundary_id_type> & b,
672  const std::vector<unsigned int> & variables,
675  const Parameters & parameters,
676  NumericVector<Number> & new_vector,
677  int is_adjoint = -1) const;
678 
682  unsigned int number () const;
683 
689  void update_global_solution (std::vector<Number> & global_soln) const;
690 
696  void update_global_solution (std::vector<Number> & global_soln,
697  const processor_id_type dest_proc) const;
698 
702  const MeshBase & get_mesh() const;
703 
707  MeshBase & get_mesh();
708 
712  const DofMap & get_dof_map() const;
713 
717  DofMap & get_dof_map();
718 
723 
728 
733  bool active () const;
734 
738  void activate ();
739 
743  void deactivate ();
744 
753  void set_basic_system_only ();
754 
758  typedef std::map<std::string, std::unique_ptr<NumericVector<Number>>, std::less<>>::iterator vectors_iterator;
759  typedef std::map<std::string, std::unique_ptr<NumericVector<Number>>, std::less<>>::const_iterator const_vectors_iterator;
760 
765 
770 
775 
780 
784  typedef std::map<std::string, std::unique_ptr<SparseMatrix<Number>>, std::less<>>::iterator matrices_iterator;
785  typedef std::map<std::string, std::unique_ptr<SparseMatrix<Number>>, std::less<>>::const_iterator const_matrices_iterator;
786 
791 
796 
801 
806 
825  NumericVector<Number> & add_vector (std::string_view vec_name,
826  const bool projections=true,
827  const ParallelType type = PARALLEL);
828 
832  void remove_vector(std::string_view vec_name);
833 
840  { return _solution_projection; }
841 
846  bool have_vector (std::string_view vec_name) const;
847 
852  const NumericVector<Number> * request_vector (std::string_view vec_name) const;
853 
858  NumericVector<Number> * request_vector (std::string_view vec_name);
859 
865  const NumericVector<Number> * request_vector (const unsigned int vec_num) const;
866 
872  NumericVector<Number> * request_vector (const unsigned int vec_num);
873 
879  const NumericVector<Number> & get_vector (std::string_view vec_name) const;
880 
886  NumericVector<Number> & get_vector (std::string_view vec_name);
887 
893  const NumericVector<Number> & get_vector (const unsigned int vec_num) const;
894 
900  NumericVector<Number> & get_vector (const unsigned int vec_num);
901 
906  const std::string & vector_name (const unsigned int vec_num) const;
907 
911  const std::string & vector_name (const NumericVector<Number> & vec_reference) const;
912 
923  void set_vector_as_adjoint (const std::string & vec_name, int qoi_num);
924 
930  int vector_is_adjoint (std::string_view vec_name) const;
931 
937  void set_vector_preservation (const std::string & vec_name, bool preserve);
938 
944  bool vector_preservation (std::string_view vec_name) const;
945 
951  NumericVector<Number> & add_adjoint_solution(unsigned int i=0);
952 
957  NumericVector<Number> & get_adjoint_solution(unsigned int i=0);
958 
963  const NumericVector<Number> & get_adjoint_solution(unsigned int i=0) const;
964 
971 
977 
982  const NumericVector<Number> & get_sensitivity_solution(unsigned int i=0) const;
983 
991 
998 
1004  const NumericVector<Number> & get_weighted_sensitivity_adjoint_solution(unsigned int i=0) const;
1005 
1012 
1018 
1024 
1030  NumericVector<Number> & add_adjoint_rhs(unsigned int i=0);
1031 
1038  NumericVector<Number> & get_adjoint_rhs(unsigned int i=0);
1039 
1044  const NumericVector<Number> & get_adjoint_rhs(unsigned int i=0) const;
1045 
1051  NumericVector<Number> & add_sensitivity_rhs(unsigned int i=0);
1052 
1062  NumericVector<Number> & get_sensitivity_rhs(unsigned int i=0);
1063 
1068  const NumericVector<Number> & get_sensitivity_rhs(unsigned int i=0) const;
1069 
1075  unsigned int n_vectors () const;
1076 
1082  unsigned int n_matrices () const;
1083 
1087  unsigned int n_vars() const;
1088 
1092  unsigned int n_variable_groups() const;
1093 
1099  unsigned int n_components() const;
1100 
1104  dof_id_type n_dofs() const;
1105 
1110  dof_id_type n_active_dofs() const;
1111 
1117 
1123 
1128  dof_id_type n_local_dofs() const;
1129 
1138  unsigned int add_variable (std::string_view var,
1139  const FEType & type,
1140  const std::set<subdomain_id_type> * const active_subdomains = nullptr);
1141 
1149  unsigned int add_variable (std::string_view var,
1150  const Order order = FIRST,
1151  const FEFamily = LAGRANGE,
1152  const std::set<subdomain_id_type> * const active_subdomains = nullptr);
1153 
1162  unsigned int add_variables (const std::vector<std::string> & vars,
1163  const FEType & type,
1164  const std::set<subdomain_id_type> * const active_subdomains = nullptr);
1165 
1184  unsigned int add_variable_array (const std::vector<std::string> & vars,
1185  const FEType & type,
1186  const std::set<subdomain_id_type> * const active_subdomains = nullptr);
1187 
1195  unsigned int add_variables (const std::vector<std::string> & vars,
1196  const Order order = FIRST,
1197  const FEFamily = LAGRANGE,
1198  const std::set<subdomain_id_type> * const active_subdomains = nullptr);
1199 
1203  const Variable & variable (unsigned int var) const;
1204 
1208  const VariableGroup & variable_group (unsigned int vg) const;
1209 
1213  bool has_variable(std::string_view var) const;
1214 
1218  const std::string & variable_name(const unsigned int i) const;
1219 
1224  unsigned int variable_number (std::string_view var) const;
1225 
1230  void get_all_variable_numbers(std::vector<unsigned int> & all_variable_numbers) const;
1231 
1242  unsigned int variable_scalar_number (std::string_view var,
1243  unsigned int component) const;
1244 
1255  unsigned int variable_scalar_number (unsigned int var_num,
1256  unsigned int component) const;
1257 
1258 
1262  const FEType & variable_type (const unsigned int i) const;
1263 
1267  const FEType & variable_type (std::string_view var) const;
1268 
1273  bool identify_variable_groups () const;
1274 
1278  void identify_variable_groups (const bool);
1279 
1285  unsigned int var,
1286  FEMNormType norm_type,
1287  std::set<unsigned int> * skip_dimensions=nullptr) const;
1288 
1294  const SystemNorm & norm,
1295  std::set<unsigned int> * skip_dimensions=nullptr) const;
1296 
1300  void read_header (Xdr & io,
1301  std::string_view version,
1302  const bool read_header=true,
1303  const bool read_additional_data=true,
1304  const bool read_legacy_format=false);
1305 
1313 #ifdef LIBMESH_ENABLE_DEPRECATED
1314  void read_legacy_data (Xdr & io,
1315  const bool read_additional_data=true);
1316 #endif
1317 
1322  template <typename ValType>
1323  void read_serialized_data (Xdr & io,
1324  const bool read_additional_data=true);
1332  const bool read_additional_data=true)
1333  { read_serialized_data<Number>(io, read_additional_data); }
1334 
1340  template <typename InValType>
1341  std::size_t read_serialized_vectors (Xdr & io,
1342  const std::vector<NumericVector<Number> *> & vectors) const;
1343 
1351  std::size_t read_serialized_vectors (Xdr & io,
1352  const std::vector<NumericVector<Number> *> & vectors) const
1353  { return read_serialized_vectors<Number>(io, vectors); }
1354 
1361  template <typename InValType>
1362  void read_parallel_data (Xdr & io,
1363  const bool read_additional_data);
1364 
1374  const bool read_additional_data)
1375  { read_parallel_data<Number>(io, read_additional_data); }
1376 
1380  void write_header (Xdr & io,
1381  std::string_view version,
1382  const bool write_additional_data) const;
1383 
1388  void write_serialized_data (Xdr & io,
1389  const bool write_additional_data = true) const;
1390 
1396  std::size_t write_serialized_vectors (Xdr & io,
1397  const std::vector<const NumericVector<Number> *> & vectors) const;
1398 
1405  void write_parallel_data (Xdr & io,
1406  const bool write_additional_data) const;
1407 
1412  std::string get_info () const;
1413 
1417  void attach_init_function (void fptr(EquationSystems & es,
1418  const std::string & name));
1419 
1425  void attach_init_object (Initialization & init);
1426 
1432  const std::string & name));
1433 
1438  void attach_assemble_object (Assembly & assemble);
1439 
1444  const std::string & name));
1445 
1449  void attach_constraint_object (Constraint & constrain);
1450 
1460  bool has_constraint_object () const;
1461 
1465  Constraint& get_constraint_object ();
1466 
1471  void attach_QOI_function (void fptr(EquationSystems & es,
1472  const std::string & name,
1473  const QoISet & qoi_indices));
1474 
1479  void attach_QOI_object (QOI & qoi);
1480 
1486  void attach_QOI_derivative (void fptr(EquationSystems & es,
1487  const std::string & name,
1488  const QoISet & qoi_indices,
1489  bool include_liftfunc,
1490  bool apply_constraints));
1491 
1497  void attach_QOI_derivative_object (QOIDerivative & qoi_derivative);
1498 
1503  virtual void user_initialization ();
1504 
1509  virtual void user_assembly ();
1510 
1515  virtual void user_constrain ();
1516 
1521  virtual void user_QOI (const QoISet & qoi_indices);
1522 
1527  virtual void user_QOI_derivative (const QoISet & qoi_indices = QoISet(),
1528  bool include_liftfunc = true,
1529  bool apply_constraints = true);
1530 
1536  virtual void re_update ();
1537 
1541  virtual void restrict_vectors ();
1542 
1546  virtual void prolong_vectors ();
1547 
1550 
1571 
1576  virtual void disable_cache ();
1577 
1587 
1602 
1603 
1604  //--------------------------------------------------
1605  // The solution and solution access members
1606 
1611  Number current_solution (const dof_id_type global_dof_number) const;
1612 
1616  std::unique_ptr<NumericVector<Number>> solution;
1617 
1628  std::unique_ptr<NumericVector<Number>> current_local_solution;
1629 
1639 
1643  unsigned int n_qois() const;
1644 
1645 #ifndef LIBMESH_ENABLE_DEPRECATED // We use accessors for these now
1646 private:
1647 #endif
1648 
1654  std::vector<Number> qoi;
1655 
1662  std::vector<Number> qoi_error_estimates;
1663 #ifndef LIBMESH_ENABLE_DEPRECATED
1664 public:
1665 #endif
1666 
1670  void init_qois(unsigned int n_qois);
1671 
1672  void set_qoi(unsigned int qoi_index, Number qoi_value);
1673  Number get_qoi_value(unsigned int qoi_index) const;
1674 
1675  void set_qoi(std::vector<Number> new_qoi);
1676 
1680  std::vector<Number> get_qoi_values() const;
1681 
1682  void set_qoi_error_estimate(unsigned int qoi_index, Number qoi_error_estimate);
1683  Number get_qoi_error_estimate_value(unsigned int qoi_index) const;
1684 
1706  Number point_value(unsigned int var, const Point & p,
1707  const bool insist_on_success = true,
1708  const NumericVector<Number> * sol = nullptr) const;
1709 
1719  Number point_value(unsigned int var, const Point & p, const Elem & e,
1720  const NumericVector<Number> * sol = nullptr) const;
1721 
1728  Number point_value(unsigned int var, const Point & p, const Elem * e) const;
1729 
1736  Number point_value(unsigned int var, const Point & p, const NumericVector<Number> * sol) const;
1737 
1742  Gradient point_gradient(unsigned int var, const Point & p,
1743  const bool insist_on_success = true,
1744  const NumericVector<Number> * sol = nullptr) const;
1745 
1750  Gradient point_gradient(unsigned int var, const Point & p, const Elem & e,
1751  const NumericVector<Number> * sol = nullptr) const;
1752 
1759  Gradient point_gradient(unsigned int var, const Point & p, const Elem * e) const;
1760 
1767  Gradient point_gradient(unsigned int var, const Point & p, const NumericVector<Number> * sol) const;
1768 
1773  Tensor point_hessian(unsigned int var, const Point & p,
1774  const bool insist_on_success = true,
1775  const NumericVector<Number> * sol = nullptr) const;
1776 
1782  Tensor point_hessian(unsigned int var, const Point & p, const Elem & e,
1783  const NumericVector<Number> * sol = nullptr) const;
1784 
1791  Tensor point_hessian(unsigned int var, const Point & p, const Elem * e) const;
1792 
1799  Tensor point_hessian(unsigned int var, const Point & p, const NumericVector<Number> * sol) const;
1800 
1801 
1806  void local_dof_indices (const unsigned int var,
1807  std::set<dof_id_type> & var_indices) const;
1808 
1813  void zero_variable (NumericVector<Number> & v, unsigned int var_num) const;
1814 
1819  {
1820  return project_with_constraints;
1821  }
1822 
1823  void set_project_with_constraints(bool _project_with_constraints)
1824  {
1825  project_with_constraints = _project_with_constraints;
1826  }
1827 
1833  bool & hide_output() { return _hide_output; }
1834 
1835 #ifdef LIBMESH_HAVE_METAPHYSICL
1836 
1846  void projection_matrix (SparseMatrix<Number> & proj_mat) const;
1847 #endif // LIBMESH_HAVE_METAPHYSICL
1848 
1866  SparseMatrix<Number> & add_matrix (std::string_view mat_name,
1867  ParallelType type = PARALLEL,
1868  MatrixBuildType mat_build_type = MatrixBuildType::AUTOMATIC);
1869 
1885  template <template <typename> class>
1886  SparseMatrix<Number> & add_matrix (std::string_view mat_name, ParallelType = PARALLEL);
1887 
1901  SparseMatrix<Number> & add_matrix (std::string_view mat_name,
1902  std::unique_ptr<SparseMatrix<Number>> matrix,
1903  ParallelType type = PARALLEL);
1904 
1908  void remove_matrix(std::string_view mat_name);
1909 
1914  inline bool have_matrix (std::string_view mat_name) const { return _matrices.count(mat_name); }
1915 
1921  const SparseMatrix<Number> * request_matrix (std::string_view mat_name) const;
1922 
1928  SparseMatrix<Number> * request_matrix (std::string_view mat_name);
1929 
1934  const SparseMatrix<Number> & get_matrix (std::string_view mat_name) const;
1935 
1940  SparseMatrix<Number> & get_matrix (std::string_view mat_name);
1941 
1945  void prefer_hash_table_matrix_assembly(bool preference);
1946 
1951 
1955  [[nodiscard]] bool prefix_with_name() const { return _prefix_with_name; }
1956 
1961  std::string prefix() const { return this->name() + "_"; }
1962 
1966  virtual void create_static_condensation();
1967 
1971  bool has_static_condensation() const;
1972 
1973 protected:
1974 
1981  virtual void init_data ();
1982 
1987  virtual void add_matrices() {}
1988 
1992  virtual void init_matrices ();
1993 
1998  bool can_add_matrices() const { return !_matrices_initialized; }
1999 
2008  int is_adjoint = -1) const;
2009 
2018  void project_vector (const NumericVector<Number> &,
2020  int is_adjoint = -1) const;
2021 
2022  /*
2023  * If we have e.g. a element space constrained by spline values, we
2024  * can directly project only on the constrained basis; to get
2025  * consistent constraining values we have to solve for them.
2026  *
2027  * Constrain the new vector using the requested adjoint rather than
2028  * primal constraints if is_adjoint is non-negative.
2029  */
2031  int is_adjoint = -1) const;
2032 
2036  virtual bool condense_constrained_dofs() const { return false; }
2037 
2038 private:
2043  ParallelType type);
2044 
2050  unsigned int var,
2051  FEMNormType norm_type) const;
2052 
2062  template <typename iterator_type, typename InValType>
2064  const iterator_type begin,
2065  const iterator_type end,
2066  const InValType dummy,
2067  Xdr & io,
2068  const std::vector<NumericVector<Number> *> & vecs,
2069  const unsigned int var_to_read=libMesh::invalid_uint) const;
2070 
2079  unsigned int read_SCALAR_dofs (const unsigned int var,
2080  Xdr & io,
2081  NumericVector<Number> * vec) const;
2082 
2091  template <typename InValType>
2093  NumericVector<Number> * vec);
2094 
2104  NumericVector<Number> & vec)
2105  { return read_serialized_vector<Number>(io, &vec); }
2106 
2113  template <typename iterator_type>
2114  std::size_t write_serialized_blocked_dof_objects (const std::vector<const NumericVector<Number> *> & vecs,
2115  const dof_id_type n_objects,
2116  const iterator_type begin,
2117  const iterator_type end,
2118  Xdr & io,
2119  const unsigned int var_to_write=libMesh::invalid_uint) const;
2120 
2126  unsigned int write_SCALAR_dofs (const NumericVector<Number> & vec,
2127  const unsigned int var,
2128  Xdr & io) const;
2129 
2137  const NumericVector<Number> & vec) const;
2138 
2143  const std::string & name);
2144 
2149 
2154  const std::string & name);
2155 
2160 
2165  const std::string & name);
2166 
2171 
2176  const std::string & name,
2177  const QoISet & qoi_indices);
2178 
2183 
2188  const std::string & name,
2189  const QoISet & qoi_indices,
2190  bool include_liftfunc,
2191  bool apply_constraints);
2192 
2197 
2202  std::unique_ptr<DofMap> _dof_map;
2203 
2209 
2215 
2219  const std::string _sys_name;
2220 
2224  const unsigned int _sys_number;
2225 
2229  bool _active;
2230 
2237  std::map<std::string, std::unique_ptr<NumericVector<Number>>, std::less<>> _vectors;
2238 
2243  std::map<std::string, bool, std::less<>> _vector_projections;
2244 
2249  std::map<std::string, int, std::less<>> _vector_is_adjoint;
2250 
2254  std::map<std::string, std::unique_ptr<SparseMatrix<Number>>, std::less<>> _matrices;
2255 
2259  std::map<std::string, ParallelType, std::less<>> _matrix_types;
2260 
2265 
2272 
2278 
2284 
2291 
2302  std::vector<unsigned int> _written_var_indices;
2303 
2310 
2316 
2321 
2326 
2331 
2336 };
2337 
2338 
2339 
2340 // ------------------------------------------------------------
2341 // System inline methods
2342 inline
2343 const std::string & System::name() const
2344 {
2345  return _sys_name;
2346 }
2347 
2348 
2349 
2350 inline
2351 unsigned int System::number() const
2352 {
2353  return _sys_number;
2354 }
2355 
2356 
2357 
2358 inline
2360 {
2361  return _mesh;
2362 }
2363 
2364 
2365 
2366 inline
2368 {
2369  return _mesh;
2370 }
2371 
2372 
2373 
2374 inline
2376 {
2377  return *_dof_map;
2378 }
2379 
2380 
2381 
2382 inline
2384 {
2385  return *_dof_map;
2386 }
2387 
2388 
2389 
2390 inline
2391 bool System::active() const
2392 {
2393  return _active;
2394 }
2395 
2396 
2397 
2398 inline
2400 {
2401  _active = true;
2402 }
2403 
2404 
2405 
2406 inline
2408 {
2409  _active = false;
2410 }
2411 
2412 
2413 
2414 inline
2416 {
2417  return _is_initialized;
2418 }
2419 
2420 
2421 
2422 inline
2424 {
2425  _basic_system_only = true;
2426 }
2427 
2428 
2429 
2430 inline
2431 unsigned int
2432 System::variable_scalar_number (std::string_view var,
2433  unsigned int component) const
2434 {
2435  return variable_scalar_number(this->variable_number(var), component);
2436 }
2437 
2438 
2439 
2440 inline
2442 {
2443  return this->n_dofs() - this->n_constrained_dofs();
2444 }
2445 
2446 
2447 
2448 inline
2449 bool System::have_vector (std::string_view vec_name) const
2450 {
2451  return (_vectors.count(vec_name));
2452 }
2453 
2454 
2455 
2456 inline
2457 unsigned int System::n_vectors () const
2458 {
2459  return cast_int<unsigned int>(_vectors.size());
2460 }
2461 
2462 inline
2464 {
2465  return _vectors.begin();
2466 }
2467 
2468 inline
2470 {
2471  return _vectors.begin();
2472 }
2473 
2474 inline
2476 {
2477  return _vectors.end();
2478 }
2479 
2480 inline
2482 {
2483  return _vectors.end();
2484 }
2485 
2486 inline
2488 {
2489  return _matrices.begin();
2490 }
2491 
2492 inline
2494 {
2495  return _matrices.begin();
2496 }
2497 
2498 inline
2500 {
2501  return _matrices.end();
2502 }
2503 
2504 inline
2506 {
2507  return _matrices.end();
2508 }
2509 
2510 inline
2512 {
2513  libmesh_not_implemented();
2514 }
2515 
2516 inline
2518 
2519 inline
2520 unsigned int System::n_qois() const
2521 {
2522 #ifndef LIBMESH_ENABLE_DEPRECATED
2523  libmesh_assert_equal_to(this->qoi.size(), this->qoi_error_estimates.size());
2524 #endif
2525 
2526  return cast_int<unsigned int>(this->qoi.size());
2527 }
2528 
2529 inline
2530 std::pair<unsigned int, Real>
2532 {
2533  libmesh_not_implemented();
2534 }
2535 
2536 inline
2537 std::pair<unsigned int, Real>
2539  const ParameterVector &)
2540 {
2541  libmesh_not_implemented();
2542 }
2543 
2544 inline
2545 std::pair<unsigned int, Real>
2547 {
2548  libmesh_not_implemented();
2549 }
2550 
2551 inline
2552 std::pair<unsigned int, Real>
2554  const ParameterVector &,
2555  const QoISet &)
2556 {
2557  libmesh_not_implemented();
2558 }
2559 
2560 inline
2561 void
2563  const ParameterVector &,
2564  SensitivityData &)
2565 {
2566  libmesh_not_implemented();
2567 }
2568 
2569 inline
2570 void
2572  const ParameterVector &,
2573  SensitivityData &)
2574 {
2575  libmesh_not_implemented();
2576 }
2577 
2578 inline
2579 void
2581  const ParameterVector &,
2582  SensitivityData &)
2583 {
2584  libmesh_not_implemented();
2585 }
2586 
2587 inline
2588 void
2590  const ParameterVector &,
2591  const ParameterVector &,
2592  SensitivityData &)
2593 {
2594  libmesh_not_implemented();
2595 }
2596 
2597 inline
2598 unsigned int System::n_matrices () const
2599 {
2600  return cast_int<unsigned int>(_matrices.size());
2601 }
2602 
2603 template <template <typename> class MatrixType>
2604 inline
2606 System::add_matrix (std::string_view mat_name,
2607  const ParallelType type)
2608 {
2609  // Return the matrix if it is already there.
2610  auto it = this->_matrices.find(mat_name);
2611  if (it != this->_matrices.end())
2612  return *it->second;
2613 
2614  // Otherwise build the matrix to return.
2615  auto pr = _matrices.emplace(mat_name, std::make_unique<MatrixType<Number>>(this->comm()));
2616  _matrix_types.emplace(mat_name, type);
2617 
2618  SparseMatrix<Number> & mat = *(pr.first->second);
2619 
2620  // Initialize it first if we've already initialized the others.
2621  this->late_matrix_init(mat, type);
2622 
2623  return mat;
2624 }
2625 
2626 inline void
2628 {
2629  libmesh_error_msg_if(
2631  "System::prefer_hash_table_matrix_assembly() should be called before matrices are initialized");
2633 }
2634 } // namespace libMesh
2635 
2636 #endif // LIBMESH_SYSTEM_H
void set_vector_as_adjoint(const std::string &vec_name, int qoi_num)
Allows one to set the QoI index controlling whether the vector identified by vec_name represents a so...
Definition: system.C:1145
matrices_iterator matrices_begin()
Beginning of matrices container.
Definition: system.h:2487
class FEType hides (possibly multiple) FEFamily and approximation orders, thereby enabling specialize...
Definition: fe_type.h:196
std::size_t read_serialized_vectors(Xdr &io, const std::vector< NumericVector< Number > *> &vectors) const
Non-templated version for backward compatibility.
Definition: system.h:1351
unsigned int add_variables(const std::vector< std::string > &vars, const FEType &type, const std::set< subdomain_id_type > *const active_subdomains=nullptr)
Adds the variables vars to the list of variables for this system.
Definition: system.C:1363
std::map< std::string, std::unique_ptr< NumericVector< Number > >, std::less<> >::iterator vectors_iterator
Vector iterator typedefs.
Definition: system.h:758
vectors_iterator vectors_end()
End of vectors container.
Definition: system.h:2475
bool is_initialized() const
Definition: system.h:2415
Real time
For time-dependent problems, this is the time t at the beginning of the current timestep.
Definition: system.h:1638
bool can_add_matrices() const
Definition: system.h:1998
void local_dof_indices(const unsigned int var, std::set< dof_id_type > &var_indices) const
Fills the std::set with the degrees of freedom on the local processor corresponding the the variable ...
Definition: system.C:1405
void write_serialized_data(Xdr &io, const bool write_additional_data=true) const
Writes additional data, namely vectors, for this System.
Definition: system_io.C:1668
This is the EquationSystems class.
unsigned int variable_scalar_number(std::string_view var, unsigned int component) const
Definition: system.h:2432
static unsigned int n_objects()
Prints the number of outstanding (created, but not yet destroyed) objects.
virtual void clear()
Clear all the data structures associated with the system.
Definition: system.C:174
Order
defines an enum for polynomial orders.
Definition: enum_order.h:40
void read_parallel_data(Xdr &io, const bool read_additional_data)
Non-templated version for backward compatibility.
Definition: system.h:1373
virtual void create_static_condensation()
Request that static condensation be performed for this system.
Definition: system.C:2644
void update_global_solution(std::vector< Number > &global_soln) const
Fill the input vector global_soln so that it contains the global solution on all processors.
Definition: system.C:730
Abstract base class to be used for system initialization.
Definition: system.h:132
void write_parallel_data(Xdr &io, const bool write_additional_data) const
Writes additional data, namely vectors, for this System.
Definition: system_io.C:1468
const Variable & variable(unsigned int var) const
Return a constant reference to Variable var.
Definition: system.C:2684
Assembly * _assemble_system_object
Object that assembles the system.
Definition: system.h:2159
Gradient point_gradient(unsigned int var, const Point &p, const bool insist_on_success=true, const NumericVector< Number > *sol=nullptr) const
Definition: system.C:2328
bool _basic_system_only
Holds true if the components of more advanced system types (e.g.
Definition: system.h:2277
const unsigned int invalid_uint
A number which is used quite often to represent an invalid or uninitialized value for an unsigned int...
Definition: libmesh.h:310
virtual void init_matrices()
Initializes the matrices associated with this system.
Definition: system.C:308
bool _is_initialized
true when additional vectors and variables do not require immediate initialization, false otherwise.
Definition: system.h:2283
void(* _constrain_system_function)(EquationSystems &es, const std::string &name)
Function to impose constraints.
Definition: system.h:2164
void set_adjoint_already_solved(bool setting)
Setter for the adjoint_already_solved boolean.
Definition: system.h:416
This class provides the ability to map between arbitrary, user-defined strings and several data types...
Definition: parameters.h:74
void boundary_project_vector(const std::set< boundary_id_type > &b, const std::vector< unsigned int > &variables, NumericVector< Number > &new_vector, FunctionBase< Number > *f, FunctionBase< Gradient > *g=nullptr, int is_adjoint=-1) const
Projects arbitrary boundary functions onto a vector of degree of freedom values for the current syste...
NumericVector< Number > & add_adjoint_solution(unsigned int i=0)
Definition: system.C:1218
virtual bool condense_constrained_dofs() const
Whether this object should condense out constrained degrees of freedom.
Definition: system.h:2036
virtual void forward_qoi_parameter_sensitivity(const QoISet &qoi_indices, const ParameterVector &parameters, SensitivityData &sensitivities)
Solves for parameter sensitivities using the forward method.
Definition: system.h:2571
Data structure for specifying which Parameters should be independent variables in a parameter sensiti...
virtual void assemble_residual_derivatives(const ParameterVector &parameters)
Calls residual parameter derivative function.
Definition: system.h:2511
void write_header(Xdr &io, std::string_view version, const bool write_additional_data) const
Writes the basic data header for this System.
Definition: system_io.C:1267
Data structure for specifying which Quantities of Interest should be calculated in an adjoint or a pa...
Definition: qoi_set.h:45
Number get_qoi_value(unsigned int qoi_index) const
Definition: system.C:2164
virtual void reinit()
Reinitializes degrees of freedom and other required data on the current mesh.
Definition: system.C:439
unsigned int n_qois() const
Number of currently active quantities of interest.
Definition: system.h:2520
unsigned int n_components() const
Definition: system.C:2674
virtual void disable_cache()
Avoids use of any cached data that might affect any solve result.
Definition: system.h:2517
bool active() const
Definition: system.h:2391
int extra_quadrature_order
A member int that can be employed to indicate increased or reduced quadrature order.
Definition: system.h:1601
virtual void initialize()=0
Initialization function.
std::size_t read_serialized_blocked_dof_objects(const dof_id_type n_objects, const iterator_type begin, const iterator_type end, const InValType dummy, Xdr &io, const std::vector< NumericVector< Number > *> &vecs, const unsigned int var_to_read=libMesh::invalid_uint) const
Reads an input vector from the stream io and assigns the values to a set of DofObjects.
Definition: system_io.C:765
sys_type & system()
Definition: system.h:254
NumericVector< Number > & get_sensitivity_solution(unsigned int i=0)
Definition: system.C:1177
void read_serialized_data(Xdr &io, const bool read_additional_data=true)
Non-templated version for backward compatibility.
Definition: system.h:1331
unsigned int write_SCALAR_dofs(const NumericVector< Number > &vec, const unsigned int var, Xdr &io) const
Writes the SCALAR dofs associated with var to the stream io.
Definition: system_io.C:2062
const unsigned int _sys_number
The number associated with this system.
Definition: system.h:2224
virtual void assemble_qoi_derivative(const QoISet &qoi_indices=QoISet(), bool include_liftfunc=true, bool apply_constraints=true)
Calls user qoi derivative function.
Definition: system.C:573
NumericVector< Number > & get_sensitivity_rhs(unsigned int i=0)
Definition: system.C:1322
int vector_is_adjoint(std::string_view vec_name) const
Definition: system.C:1158
virtual void assemble()=0
Assembly function.
Constraint * _constrain_system_object
Object that constrains the system.
Definition: system.h:2170
const EquationSystems & get_equation_systems() const
Definition: system.h:722
unsigned int n_variable_groups() const
Definition: system.C:2679
virtual void assemble()
Prepares matrix and _dof_map for matrix assembly.
Definition: system.C:551
void projection_matrix(SparseMatrix< Number > &proj_mat) const
This method creates a projection matrix which corresponds to the operation of project_vector between ...
unsigned int add_variable_array(const std::vector< std::string > &vars, const FEType &type, const std::set< subdomain_id_type > *const active_subdomains=nullptr)
Adds variables vars to the list of variables for this system.
Definition: system.C:1382
virtual void init_data()
Initializes the data for the system.
Definition: system.C:204
This is the base class from which all geometric element types are derived.
Definition: elem.h:94
FEMNormType
defines an enum for norms defined on vectors of finite element coefficients
void init_qois(unsigned int n_qois)
Accessors for qoi and qoi_error_estimates vectors.
Definition: system.C:2149
std::map< std::string, std::unique_ptr< SparseMatrix< Number > >, std::less<> >::iterator matrices_iterator
Matrix iterator typedefs.
Definition: system.h:784
Number point_value(unsigned int var, const Point &p, const bool insist_on_success=true, const NumericVector< Number > *sol=nullptr) const
Definition: system.C:2199
std::unique_ptr< DofMap > _dof_map
Data structure describing the relationship between nodes, variables, etc...
Definition: system.h:2202
virtual void user_initialization()
Calls user&#39;s attached initialization function, or is overridden by the user in derived classes...
Definition: system.C:2075
std::map< std::string, std::unique_ptr< NumericVector< Number > >, std::less<> > _vectors
Some systems need an arbitrary number of vectors.
Definition: system.h:2237
bool _active
Flag stating if the system is active or not.
Definition: system.h:2229
NumericVector< Number > & add_vector(std::string_view vec_name, const bool projections=true, const ParallelType type=PARALLEL)
Adds the additional vector vec_name to this system.
Definition: system.C:753
void get_all_variable_numbers(std::vector< unsigned int > &all_variable_numbers) const
Fills all_variable_numbers with all the variable numbers for the variables that have been added to th...
Definition: system.C:1399
This class defines a norm/seminorm to be applied to a NumericVector which contains coefficients in a ...
Definition: system_norm.h:49
NumericVector< Number > & add_sensitivity_rhs(unsigned int i=0)
Definition: system.C:1312
void read_legacy_data(Xdr &io, const bool read_additional_data=true)
Reads additional data, namely vectors, for this System.
Definition: system_io.C:302
This class defines a vector in LIBMESH_DIM dimensional Real or Complex space.
bool has_static_condensation() const
Definition: system.C:2649
The libMesh namespace provides an interface to certain functionality in the library.
vectors_iterator vectors_begin()
Beginning of vectors container.
Definition: system.h:2463
std::map< std::string, std::unique_ptr< SparseMatrix< Number > >, std::less<> >::const_iterator const_matrices_iterator
Definition: system.h:785
void attach_QOI_derivative_object(QOIDerivative &qoi_derivative)
Register a user object for evaluating derivatives of a quantity of interest with respect to test func...
Definition: system.C:2061
virtual void adjoint_qoi_parameter_sensitivity(const QoISet &qoi_indices, const ParameterVector &parameters, SensitivityData &sensitivities)
Solves for parameter sensitivities using the adjoint method.
Definition: system.h:2562
dof_id_type n_local_dofs() const
Definition: system.C:156
Abstract base class to be used for system assembly.
Definition: system.h:156
NumericVector< Number > & add_weighted_sensitivity_solution()
Definition: system.C:1197
void(* _qoi_evaluate_function)(EquationSystems &es, const std::string &name, const QoISet &qoi_indices)
Function to evaluate quantity of interest.
Definition: system.h:2175
const SparseMatrix< Number > * request_matrix(std::string_view mat_name) const
Definition: system.C:1085
System sys_type
The type of system.
Definition: system.h:249
Parameters parameters
Parameters for the system. If a parameter is not provided, it should be retrieved from the EquationSy...
Definition: system.h:1549
void init()
Initializes degrees of freedom on the current mesh.
Definition: system.C:193
const MeshBase & get_mesh() const
Definition: system.h:2359
NumericVector< Number > & get_weighted_sensitivity_solution()
Definition: system.C:1204
bool adjoint_already_solved
Has the adjoint problem already been solved? If the user sets adjoint_already_solved to true...
Definition: system.h:2309
dof_id_type n_dofs() const
Definition: system.C:119
uint8_t processor_id_type
Definition: id_types.h:104
This is the MeshBase class.
Definition: mesh_base.h:75
virtual void prolong_vectors()
Prolong vectors after the mesh has refined.
Definition: system.C:429
Number current_solution(const dof_id_type global_dof_number) const
Definition: system.C:163
virtual void user_QOI(const QoISet &qoi_indices)
Calls user&#39;s attached quantity of interest function, or is overridden by the user in derived classes...
Definition: system.C:2117
virtual ~Assembly()=default
Destructor.
Number fptr(const Point &p, const Parameters &, const std::string &libmesh_dbg_var(sys_name), const std::string &unknown_name)
Definition: projection.C:81
unsigned int variable_number(std::string_view var) const
Definition: system.C:1394
std::map< std::string, std::unique_ptr< SparseMatrix< Number > >, std::less<> > _matrices
Some systems need an arbitrary number of matrices.
Definition: system.h:2254
bool have_matrix(std::string_view mat_name) const
Definition: system.h:1914
QOIDerivative * _qoi_evaluate_derivative_object
Object to compute derivatives of quantities of interest.
Definition: system.h:2196
NumericVector< Number > & add_weighted_sensitivity_adjoint_solution(unsigned int i=0)
Definition: system.C:1250
virtual void qoi_derivative(const QoISet &qoi_indices, bool include_liftfunc, bool apply_constraints)=0
Quantity of interest derivative function.
virtual void qoi_parameter_sensitivity(const QoISet &qoi_indices, const ParameterVector &parameters, SensitivityData &sensitivities)
Solves for the derivative of each of the system&#39;s quantities of interest q in qoi[qoi_indices] with r...
Definition: system.C:587
virtual void qoi_parameter_hessian(const QoISet &qoi_indices, const ParameterVector &parameters, SensitivityData &hessian)
For each of the system&#39;s quantities of interest q in qoi[qoi_indices], and for a vector of parameters...
Definition: system.h:2580
void attach_constraint_object(Constraint &constrain)
Register a user object for imposing constraints.
Definition: system.C:1987
This class handles the numbering of degrees of freedom on a mesh.
Definition: dof_map.h:179
void project_solution(FunctionBase< Number > *f, FunctionBase< Gradient > *g=nullptr) const
Projects arbitrary functions onto the current solution.
void attach_init_object(Initialization &init)
Register a user class to use to initialize the system.
Definition: system.C:1925
void set_basic_system_only()
Sets the system to be "basic only": i.e.
Definition: system.h:2423
bool has_variable(std::string_view var) const
Definition: system.C:1389
unsigned int number() const
Definition: system.h:2351
void remove_vector(std::string_view vec_name)
Removes the additional vector vec_name from this system.
Definition: system.C:858
This class defines the notion of a variable in the system.
Definition: variable.h:50
std::map< std::string, int, std::less<> > _vector_is_adjoint
Holds non-negative if a vector by that name should be projected using adjoint constraints/BCs, -1 if primal.
Definition: system.h:2249
Constraint & get_constraint_object()
Return the user object for imposing constraints.
Definition: system.C:2004
virtual void qoi_parameter_hessian_vector_product(const QoISet &qoi_indices, const ParameterVector &parameters, const ParameterVector &vector, SensitivityData &product)
For each of the system&#39;s quantities of interest q in qoi[qoi_indices], and for a vector of parameters...
Definition: system.h:2589
Data structure for holding completed parameter sensitivity calculations.
dof_id_type numeric_index_type
Definition: id_types.h:99
std::vector< Number > qoi
Values of the quantities of interest.
Definition: system.h:1654
void deactivate()
Deactivates the system.
Definition: system.h:2407
void remove_matrix(std::string_view mat_name)
Removes the additional matrix mat_name from this system.
Definition: system.C:1074
std::string prefix() const
Definition: system.h:1961
This is a base class for classes which represent subsets of the dofs of a System. ...
Definition: system_subset.h:42
bool use_fixed_solution
A boolean to be set to true by systems using elem_fixed_solution, for optional use by e...
Definition: system.h:1586
void read_header(Xdr &io, std::string_view version, const bool read_header=true, const bool read_additional_data=true, const bool read_legacy_format=false)
Reads the basic data header for this System.
Definition: system_io.C:97
unsigned int n_vectors() const
Definition: system.h:2457
Manages consistently variables, degrees of freedom, and coefficient vectors.
Definition: system.h:97
void zero_variable(NumericVector< Number > &v, unsigned int var_num) const
Zeroes all dofs in v that correspond to variable number var_num.
Definition: system.C:1446
System & operator=(const System &)=delete
bool & hide_output()
Definition: system.h:1833
bool _prefer_hash_table_matrix_assembly
Whether to use hash table matrix assembly if the matrix sub-classes support it.
Definition: system.h:2325
virtual void add_matrices()
Insertion point for adding matrices in derived classes before init_matrices() is called.
Definition: system.h:1987
bool has_constraint_object() const
Definition: system.C:1999
std::string get_info() const
Definition: system.C:1818
numeric_index_type read_serialized_vector(Xdr &io, NumericVector< Number > *vec)
Reads a vector for this System.
Definition: system_io.C:1136
NumberVectorValue Gradient
virtual void qoi(const QoISet &qoi_indices)=0
Quantity of interest function.
std::unique_ptr< NumericVector< Number > > solution
Data structure to hold solution values.
Definition: system.h:1616
void attach_QOI_derivative(void fptr(EquationSystems &es, const std::string &name, const QoISet &qoi_indices, bool include_liftfunc, bool apply_constraints))
Register a user function for evaluating derivatives of a quantity of interest with respect to test fu...
Definition: system.C:2044
Real calculate_norm(const NumericVector< Number > &v, unsigned int var, FEMNormType norm_type, std::set< unsigned int > *skip_dimensions=nullptr) const
Definition: system.C:1502
bool project_with_constraints
Do we want to apply constraints while projecting vectors ?
Definition: system.h:2320
bool have_vector(std::string_view vec_name) const
Definition: system.h:2449
QOI * _qoi_evaluate_object
Object to compute quantities of interest.
Definition: system.h:2182
virtual std::pair< unsigned int, Real > sensitivity_solve(const ParameterVector &parameters)
Solves the sensitivity system, for the provided parameters.
Definition: system.h:2531
Initialization * _init_system_object
Object that initializes the system.
Definition: system.h:2148
virtual std::pair< unsigned int, Real > adjoint_solve(const QoISet &qoi_indices=QoISet())
Solves the adjoint system, for the specified qoi indices, or for every qoi if qoi_indices is nullptr...
Definition: system.h:2546
void attach_QOI_function(void fptr(EquationSystems &es, const std::string &name, const QoISet &qoi_indices))
Register a user function for evaluating the quantities of interest, whose values should be placed in ...
Definition: system.C:2012
bool _hide_output
Are we allowed to write this system to file? If _hide_output is true, then EquationSystems::write wil...
Definition: system.h:2315
unsigned int _additional_data_written
This flag is used only when reading in a system from file.
Definition: system.h:2290
unsigned int add_variable(std::string_view var, const FEType &type, const std::set< subdomain_id_type > *const active_subdomains=nullptr)
Adds the variable var to the list of variables for this system.
Definition: system.C:1342
const std::string & variable_name(const unsigned int i) const
Definition: system.C:2659
void(* _init_system_function)(EquationSystems &es, const std::string &name)
Function that initializes the system.
Definition: system.h:2142
dof_id_type n_active_dofs() const
Definition: system.h:2441
std::map< std::string, ParallelType, std::less<> > _matrix_types
Holds the types of the matrices.
Definition: system.h:2259
virtual void restrict_vectors()
Restrict vectors after the mesh has coarsened.
Definition: system.C:371
void attach_assemble_function(void fptr(EquationSystems &es, const std::string &name))
Register a user function to use in assembling the system matrix and RHS.
Definition: system.C:1939
auto norm(const T &a) -> decltype(std::abs(a))
Definition: tensor_tools.h:74
std::size_t read_serialized_vectors(Xdr &io, const std::vector< NumericVector< Number > *> &vectors) const
Read a number of identically distributed vectors.
Definition: system_io.C:2165
unsigned int n_matrices() const
Definition: system.h:2598
This class implements reference counting.
void set_project_with_constraints(bool _project_with_constraints)
Definition: system.h:1823
An object whose state is distributed along a set of processors.
This class defines a logically grouped set of variables in the system.
Definition: variable.h:203
std::vector< Number > qoi_error_estimates
Vector to hold error estimates for qois, either from a steady state calculation, or from a single uns...
Definition: system.h:1662
void activate()
Activates the system.
Definition: system.h:2399
NumericVector< Number > & add_adjoint_rhs(unsigned int i=0)
Definition: system.C:1282
virtual void restrict_solve_to(const SystemSubset *subset, const SubsetSolveMode subset_solve_mode=SUBSET_ZERO)
After calling this method, any solve will be restricted to the given subdomain.
Definition: system.C:542
virtual void user_QOI_derivative(const QoISet &qoi_indices=QoISet(), bool include_liftfunc=true, bool apply_constraints=true)
Calls user&#39;s attached quantity of interest derivative function, or is overridden by the user in deriv...
Definition: system.C:2131
virtual void reinit_constraints()
Reinitializes the constraints for this system.
Definition: system.C:480
bool identify_variable_groups() const
Definition: system.C:2664
bool is_adjoint_already_solved() const
Accessor for the adjoint_already_solved boolean.
Definition: system.h:410
virtual void solve()
Solves the system.
Definition: system.h:348
This class implements a C++ interface to the XDR (eXternal Data Representation) format.
Definition: xdr_cxx.h:67
virtual void reinit_mesh()
Reinitializes the system with a new mesh.
Definition: system.C:286
const NumericVector< Number > * request_vector(std::string_view vec_name) const
Definition: system.C:876
EquationSystems & get_equation_systems()
Definition: system.h:727
void attach_assemble_object(Assembly &assemble)
Register a user object to use in assembling the system matrix and RHS.
Definition: system.C:1956
bool _solution_projection
Holds true if the solution vector should be projected onto a changed grid, false if it should be zero...
Definition: system.h:2271
EquationSystems & _equation_systems
Constant reference to the EquationSystems object used for the simulation.
Definition: system.h:2208
std::size_t write_serialized_vectors(Xdr &io, const std::vector< const NumericVector< Number > *> &vectors) const
Serialize & write a number of identically distributed vectors.
Definition: system_io.C:2261
virtual std::string system_type() const
Definition: system.h:509
virtual void constrain()=0
Constraint function.
void read_parallel_data(Xdr &io, const bool read_additional_data)
Reads additional data, namely vectors, for this System.
Definition: system_io.C:449
const std::string & vector_name(const unsigned int vec_num) const
Definition: system.C:968
void attach_QOI_object(QOI &qoi)
Register a user object for evaluating the quantities of interest, whose values should be placed in Sy...
Definition: system.C:2030
void prefer_hash_table_matrix_assembly(bool preference)
Sets whether to use hash table matrix assembly if the matrix sub-classes support it.
Definition: system.h:2627
virtual ~QOI()=default
Destructor.
virtual void user_assembly()
Calls user&#39;s attached assembly function, or is overridden by the user in derived classes.
Definition: system.C:2089
virtual ~QOIDerivative()=default
Destructor.
virtual void update()
Update the local values to reflect the solution on neighboring processors.
Definition: system.C:495
const FEType & variable_type(const unsigned int i) const
Definition: system.C:2701
DIE A HORRIBLE DEATH HERE typedef LIBMESH_DEFAULT_SCALAR_TYPE Real
void set_vector_preservation(const std::string &vec_name, bool preserve)
Allows one to set the boolean controlling whether the vector identified by vec_name should be "preser...
Definition: system.C:1123
Number(* ValueFunctionPointer)(const Point &p, const Parameters &Parameters, const std::string &sys_name, const std::string &unknown_name)
Projects arbitrary functions onto the current solution.
Definition: system.h:538
void set_qoi_error_estimate(unsigned int qoi_index, Number qoi_error_estimate)
Definition: system.C:2184
virtual std::pair< unsigned int, Real > weighted_sensitivity_solve(const ParameterVector &parameters, const ParameterVector &weights)
Assembles & solves the linear system(s) (dR/du)*u_w = sum(w_p*-dR/dp), for those parameters p contain...
Definition: system.h:2538
bool _matrices_initialized
false when additional matrices being added require initialization, true otherwise.
Definition: system.h:2264
bool _require_sparsity_pattern
Whether any of our matrices require an initial sparsity pattern computation in order to determine pre...
Definition: system.h:2330
const std::string _sys_name
A name associated with this system.
Definition: system.h:2219
Tensor point_hessian(unsigned int var, const Point &p, const bool insist_on_success=true, const NumericVector< Number > *sol=nullptr) const
Definition: system.C:2472
bool & project_solution_on_reinit(void)
Tells the System whether or not to project the solution vector onto new grids when the system is rein...
Definition: system.h:839
static const bool value
Definition: xdr_io.C:55
Gradient gptr(const Point &p, const Parameters &, const std::string &libmesh_dbg_var(sys_name), const std::string &unknown_name)
Definition: projection.C:96
NumericVector< Number > & get_adjoint_solution(unsigned int i=0)
Definition: system.C:1230
virtual void re_update()
Re-update the local values when the mesh has changed.
Definition: system.C:518
Abstract base class to be used for system constraints.
Definition: system.h:180
std::unique_ptr< NumericVector< Number > > current_local_solution
All the values I need to compute my contribution to the simulation at hand.
Definition: system.h:1628
virtual std::pair< unsigned int, Real > weighted_sensitivity_adjoint_solve(const ParameterVector &parameters, const ParameterVector &weights, const QoISet &qoi_indices=QoISet())
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.
Definition: system.h:2553
void project_vector(NumericVector< Number > &new_vector, FunctionBase< Number > *f, FunctionBase< Gradient > *g=nullptr, int is_adjoint=-1) const
Projects arbitrary functions onto a vector of degree of freedom values for the current system...
virtual bool compare(const System &other_system, const Real threshold, const bool verbose) const
Definition: system.C:603
void set_qoi(unsigned int qoi_index, Number qoi_value)
Definition: system.C:2156
dof_id_type n_local_constrained_dofs() const
Definition: system.C:141
void boundary_project_solution(const std::set< boundary_id_type > &b, const std::vector< unsigned int > &variables, FunctionBase< Number > *f, FunctionBase< Gradient > *g=nullptr)
Projects arbitrary boundary functions onto a vector of degree of freedom values for the current syste...
bool get_project_with_constraints()
Setter and getter functions for project_with_constraints boolean.
Definition: system.h:1818
unsigned int read_SCALAR_dofs(const unsigned int var, Xdr &io, NumericVector< Number > *vec) const
Reads the SCALAR dofs from the stream io and assigns the values to the appropriate entries of vec...
Definition: system_io.C:1089
const std::string & name() const
Definition: system.h:2343
void attach_constraint_function(void fptr(EquationSystems &es, const std::string &name))
Register a user function for imposing constraints.
Definition: system.C:1970
Gradient(* GradientFunctionPointer)(const Point &p, const Parameters &parameters, const std::string &sys_name, const std::string &unknown_name)
Definition: system.h:542
virtual void user_constrain()
Calls user&#39;s attached constraint function, or is overridden by the user in derived classes...
Definition: system.C:2103
Real discrete_var_norm(const NumericVector< Number > &v, unsigned int var, FEMNormType norm_type) const
Finds the discrete norm for the entries in the vector corresponding to Dofs associated with var...
Definition: system.C:1483
Number get_qoi_error_estimate_value(unsigned int qoi_index) const
Definition: system.C:2191
virtual void assemble_qoi(const QoISet &qoi_indices=QoISet())
Calls user qoi function.
Definition: system.C:562
NumericVector< Number > & add_sensitivity_solution(unsigned int i=0)
Definition: system.C:1167
FEFamily
defines an enum for finite element families.
unsigned int n_vars() const
Definition: system.C:2654
VectorValue< Number > NumberVectorValue
virtual ~Initialization()=default
Destructor.
void(* _assemble_system_function)(EquationSystems &es, const std::string &name)
Function that assembles the system.
Definition: system.h:2153
MatrixBuildType
Defines an enum for matrix build types.
void prefix_with_name(bool value)
Instructs this system to prefix solve options with its name for solvers that leverage prefixes...
Definition: system.h:1950
virtual ~System()
Definition: system.C:112
numeric_index_type read_serialized_vector(Xdr &io, NumericVector< Number > &vec)
Non-templated version for backward compatibility.
Definition: system.h:2103
bool assemble_before_solve
Flag which tells the system to whether or not to call the user assembly function during each call to ...
Definition: system.h:1570
std::map< std::string, std::unique_ptr< NumericVector< Number > >, std::less<> >::const_iterator const_vectors_iterator
Definition: system.h:759
System(EquationSystems &es, const std::string &name, const unsigned int number)
Constructor.
Definition: system.C:63
bool vector_preservation(std::string_view vec_name) const
Definition: system.C:1133
SparseMatrix< Number > & add_matrix(std::string_view mat_name, ParallelType type=PARALLEL, MatrixBuildType mat_build_type=MatrixBuildType::AUTOMATIC)
Adds the additional matrix mat_name to this system.
Definition: system.C:995
SubsetSolveMode
defines an enum for the question what happens to the dofs outside the given subset when a system is s...
const DofMap & get_dof_map() const
Definition: system.h:2375
void solve_for_unconstrained_dofs(NumericVector< Number > &, int is_adjoint=-1) const
bool _prefix_with_name
Whether we are name prefixing solver options.
Definition: system.h:2335
void late_matrix_init(SparseMatrix< Number > &mat, ParallelType type)
Helper function to keep DofMap forward declarable in system.h.
Definition: system.C:1061
const SparseMatrix< Number > & get_matrix(std::string_view mat_name) const
Definition: system.C:1109
A Point defines a location in LIBMESH_DIM dimensional Real space.
Definition: point.h:39
MeshBase & _mesh
Constant reference to the mesh data structure used for the simulation.
Definition: system.h:2214
void read_serialized_data(Xdr &io, const bool read_additional_data=true)
Reads additional data, namely vectors, for this System.
Definition: system_io.C:680
matrices_iterator matrices_end()
End of matrices container.
Definition: system.h:2499
const VariableGroup & variable_group(unsigned int vg) const
Return a constant reference to VariableGroup vg.
Definition: system.C:2689
void ErrorVector unsigned int
Definition: adjoints_ex3.C:360
void attach_init_function(void fptr(EquationSystems &es, const std::string &name))
Register a user function to use in initializing the system.
Definition: system.C:1908
virtual ~Constraint()=default
Destructor.
std::map< std::string, bool, std::less<> > _vector_projections
Holds true if a vector by that name should be projected onto a changed grid, false if it should be ze...
Definition: system.h:2243
std::size_t write_serialized_blocked_dof_objects(const std::vector< const NumericVector< Number > *> &vecs, const dof_id_type n_objects, const iterator_type begin, const iterator_type end, Xdr &io, const unsigned int var_to_write=libMesh::invalid_uint) const
Writes an output vector to the stream io for a set of DofObjects.
Definition: system_io.C:1776
Abstract base class to be used for quantities of interest.
Definition: system.h:204
const NumericVector< Number > & get_vector(std::string_view vec_name) const
Definition: system.C:928
NumericVector< Number > & get_weighted_sensitivity_adjoint_solution(unsigned int i=0)
Definition: system.C:1262
This class defines a tensor in LIBMESH_DIM dimensional Real or Complex space.
dof_id_type n_constrained_dofs() const
Definition: system.C:126
std::vector< unsigned int > _written_var_indices
This vector is used only when reading in a system from file.
Definition: system.h:2302
uint8_t dof_id_type
Definition: id_types.h:67
std::vector< Number > get_qoi_values() const
Returns a copy of qoi, not a reference.
Definition: system.C:2171
void(* _qoi_evaluate_derivative_function)(EquationSystems &es, const std::string &name, const QoISet &qoi_indices, bool include_liftfunc, bool apply_constraints)
Function to evaluate quantity of interest derivative.
Definition: system.h:2187
ParallelType
Defines an enum for parallel data structure types.
Abstract base class to be used for derivatives of quantities of interest.
Definition: system.h:228
NumericVector< Number > & get_adjoint_rhs(unsigned int i=0)
Definition: system.C:1292
bool prefix_with_name() const
Definition: system.h:1955
dof_id_type write_serialized_vector(Xdr &io, const NumericVector< Number > &vec) const
Writes a vector for this System.
Definition: system_io.C:2118