libMesh
system.h
Go to the documentation of this file.
1 // The libMesh Finite Element Library.
2 // Copyright (C) 2002-2026 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 #include <optional>
44 
45 // This define may be useful in --disable-optional builds when it is
46 // possible that libmesh will not have any solvers available.
47 #if defined(LIBMESH_HAVE_PETSC) || \
48  defined(LIBMESH_HAVE_EIGEN) || \
49  defined(LIBMESH_HAVE_LASPACK) || \
50  defined(LIBMESH_TRILINOS_HAVE_AZTECOO)
51 #define LIBMESH_HAVE_SOLVER 1
52 #endif
53 
54 namespace libMesh
55 {
56 
57 // Forward Declarations
58 class System;
59 class EquationSystems;
60 class MeshBase;
61 class Xdr;
62 class DofMap;
63 template <typename Output> class FunctionBase;
64 class ParameterVector;
65 class Point;
66 class SensitivityData;
67 class Matrix;
68 template <typename T> class NumericVector;
69 template <typename T> class SparseMatrix;
70 template <typename T> class VectorValue;
71 typedef VectorValue<Number> NumberVectorValue;
73 class SystemSubset;
74 class FEType;
75 class SystemNorm;
76 enum FEMNormType : int;
77 class Variable;
78 class VariableGroup;
79 
98 class System : public ReferenceCountedObject<System>,
99  public ParallelObject
100 {
101 public:
102 
107  System (EquationSystems & es,
108  const std::string & name,
109  const unsigned int number);
110 
121  System (const System &) = delete;
122  System & operator= (const System &) = delete;
123  System (System &&) = default;
124  System & operator= (System &&) = delete;
125  virtual ~System ();
126 
134  {
135  public:
139  virtual ~Initialization () = default;
140 
146  virtual void initialize () = 0;
147  };
148 
149 
150 
157  class Assembly
158  {
159  public:
163  virtual ~Assembly () = default;
164 
170  virtual void assemble () = 0;
171  };
172 
173 
174 
182  {
183  public:
187  virtual ~Constraint () = default;
188 
194  virtual void constrain () = 0;
195  };
196 
197 
198 
205  class QOI
206  {
207  public:
211  virtual ~QOI () = default;
212 
218  virtual void qoi (const QoISet & qoi_indices) = 0;
219  };
220 
221 
222 
230  {
231  public:
235  virtual ~QOIDerivative () = default;
236 
242  virtual void qoi_derivative (const QoISet & qoi_indices,
243  bool include_liftfunc,
244  bool apply_constraints) = 0;
245  };
246 
250  typedef System sys_type;
251 
255  sys_type & system () { return *this; }
256 
261  virtual void clear ();
262 
267  void init ();
268 
277  virtual void reinit ();
278 
285  virtual void reinit_constraints ();
286 
290  virtual void reinit_mesh();
291 
295  bool is_initialized() const;
296 
301  virtual void update ();
302 
309  virtual void assemble ();
310 
315  virtual void assemble_qoi (const QoISet & qoi_indices = QoISet());
316 
321  virtual void assemble_qoi_derivative (const QoISet & qoi_indices = QoISet(),
322  bool include_liftfunc = true,
323  bool apply_constraints = true);
324 
337 
343  virtual void restrict_solve_to (const SystemSubset * subset,
344  const SubsetSolveMode subset_solve_mode=SUBSET_ZERO);
345 
349  virtual void solve () {}
350 
360  virtual std::pair<unsigned int, Real>
362 
373  virtual std::pair<unsigned int, Real>
375  const ParameterVector & weights);
376 
387  virtual std::pair<unsigned int, Real>
388  adjoint_solve (const QoISet & qoi_indices = QoISet());
389 
404  virtual std::pair<unsigned int, Real>
406  const ParameterVector & weights,
407  const QoISet & qoi_indices = QoISet());
412  { return adjoint_already_solved;}
413 
417  void set_adjoint_already_solved(bool setting)
418  { adjoint_already_solved = setting;}
419 
420 
438  virtual void qoi_parameter_sensitivity (const QoISet & qoi_indices,
439  const ParameterVector & parameters,
440  SensitivityData & sensitivities);
441 
447  virtual void adjoint_qoi_parameter_sensitivity (const QoISet & qoi_indices,
448  const ParameterVector & parameters,
449  SensitivityData & sensitivities);
450 
456  virtual void forward_qoi_parameter_sensitivity (const QoISet & qoi_indices,
457  const ParameterVector & parameters,
458  SensitivityData & sensitivities);
459 
470  virtual void qoi_parameter_hessian(const QoISet & qoi_indices,
471  const ParameterVector & parameters,
472  SensitivityData & hessian);
473 
486  virtual void qoi_parameter_hessian_vector_product(const QoISet & qoi_indices,
487  const ParameterVector & parameters,
488  const ParameterVector & vector,
489  SensitivityData & product);
490 
496  virtual bool compare (const System & other_system,
497  const Real threshold,
498  const bool verbose) const;
499 
503  const std::string & name () const;
504 
510  virtual std::string system_type () const { return "Basic"; }
511 
524  FunctionBase<Gradient> * g = nullptr,
525  std::optional<ConstElemRange> active_local_range = std::nullopt,
526  std::optional<std::vector<unsigned int>> variable_numbers = std::nullopt) const;
527 
540  FEMFunctionBase<Gradient> * g = nullptr,
541  std::optional<ConstElemRange> active_local_range = std::nullopt,
542  std::optional<std::vector<unsigned int>> variable_numbers = std::nullopt) const;
543 
551  typedef Number (*ValueFunctionPointer)(const Point & p,
552  const Parameters & Parameters,
553  const std::string & sys_name,
554  const std::string & unknown_name);
555  typedef Gradient (*GradientFunctionPointer)(const Point & p,
556  const Parameters & parameters,
557  const std::string & sys_name,
558  const std::string & unknown_name);
561  const Parameters & parameters,
562  std::optional<ConstElemRange> active_local_range = std::nullopt,
563  std::optional<std::vector<unsigned int>> variable_numbers = std::nullopt) const;
564 
580  void project_vector (NumericVector<Number> & new_vector,
582  FunctionBase<Gradient> * g = nullptr,
583  int is_adjoint = -1,
584  std::optional<ConstElemRange> active_local_range = std::nullopt,
585  std::optional<std::vector<unsigned int>> variable_numbers = std::nullopt) const;
586 
602  void project_vector (NumericVector<Number> & new_vector,
604  FEMFunctionBase<Gradient> * g = nullptr,
605  int is_adjoint = -1,
606  std::optional<ConstElemRange> active_local_range = std::nullopt,
607  std::optional<std::vector<unsigned int>> variable_numbers = std::nullopt) const;
608 
626  const Parameters & parameters,
627  NumericVector<Number> & new_vector,
628  int is_adjoint = -1,
629  std::optional<ConstElemRange> active_local_range = std::nullopt,
630  std::optional<std::vector<unsigned int>> variable_numbers = std::nullopt) const;
631 
646  void boundary_project_solution (const std::set<boundary_id_type> & b,
647  const std::vector<unsigned int> & variables,
649  FunctionBase<Gradient> * g = nullptr,
650  std::optional<ConstElemRange> active_local_range = std::nullopt);
651 
666  void boundary_project_solution (const std::set<boundary_id_type> & b,
667  const std::vector<unsigned int> & variables,
670  const Parameters & parameters,
671  std::optional<ConstElemRange> active_local_range = std::nullopt);
672 
690  void boundary_project_vector (const std::set<boundary_id_type> & b,
691  const std::vector<unsigned int> & variables,
692  NumericVector<Number> & new_vector,
694  FunctionBase<Gradient> * g = nullptr,
695  int is_adjoint = -1,
696  std::optional<ConstElemRange> active_local_range = std::nullopt) const;
697 
715  void boundary_project_vector (const std::set<boundary_id_type> & b,
716  const std::vector<unsigned int> & variables,
719  const Parameters & parameters,
720  NumericVector<Number> & new_vector,
721  int is_adjoint = -1,
722  std::optional<ConstElemRange> active_local_range = std::nullopt) const;
723 
727  unsigned int number () const;
728 
734  void update_global_solution (std::vector<Number> & global_soln) const;
735 
741  void update_global_solution (std::vector<Number> & global_soln,
742  const processor_id_type dest_proc) const;
743 
747  const MeshBase & get_mesh() const;
748 
752  MeshBase & get_mesh();
753 
757  const DofMap & get_dof_map() const;
758 
762  DofMap & get_dof_map();
763 
768 
773 
778  bool active () const;
779 
783  void activate ();
784 
788  void deactivate ();
789 
798  void set_basic_system_only ();
799 
803  typedef std::map<std::string, std::unique_ptr<NumericVector<Number>>, std::less<>>::iterator vectors_iterator;
804  typedef std::map<std::string, std::unique_ptr<NumericVector<Number>>, std::less<>>::const_iterator const_vectors_iterator;
805 
810 
815 
820 
825 
829  typedef std::map<std::string, std::unique_ptr<SparseMatrix<Number>>, std::less<>>::iterator matrices_iterator;
830  typedef std::map<std::string, std::unique_ptr<SparseMatrix<Number>>, std::less<>>::const_iterator const_matrices_iterator;
831 
836 
841 
846 
851 
870  NumericVector<Number> & add_vector (std::string_view vec_name,
871  const bool projections=true,
872  const ParallelType type = PARALLEL);
873 
877  void remove_vector(std::string_view vec_name);
878 
885  { return _solution_projection; }
886 
891  bool have_vector (std::string_view vec_name) const;
892 
897  const NumericVector<Number> * request_vector (std::string_view vec_name) const;
898 
903  NumericVector<Number> * request_vector (std::string_view vec_name);
904 
910  const NumericVector<Number> * request_vector (const unsigned int vec_num) const;
911 
917  NumericVector<Number> * request_vector (const unsigned int vec_num);
918 
924  const NumericVector<Number> & get_vector (std::string_view vec_name) const;
925 
931  NumericVector<Number> & get_vector (std::string_view vec_name);
932 
938  const NumericVector<Number> & get_vector (const unsigned int vec_num) const;
939 
945  NumericVector<Number> & get_vector (const unsigned int vec_num);
946 
951  const std::string & vector_name (const unsigned int vec_num) const;
952 
956  const std::string & vector_name (const NumericVector<Number> & vec_reference) const;
957 
968  void set_vector_as_adjoint (const std::string & vec_name, int qoi_num);
969 
975  int vector_is_adjoint (std::string_view vec_name) const;
976 
982  void set_vector_preservation (const std::string & vec_name, bool preserve);
983 
989  bool vector_preservation (std::string_view vec_name) const;
990 
996  NumericVector<Number> & add_adjoint_solution(unsigned int i=0);
997 
1002  NumericVector<Number> & get_adjoint_solution(unsigned int i=0);
1003 
1008  const NumericVector<Number> & get_adjoint_solution(unsigned int i=0) const;
1009 
1015  NumericVector<Number> & add_sensitivity_solution(unsigned int i=0);
1016 
1021  NumericVector<Number> & get_sensitivity_solution(unsigned int i=0);
1022 
1027  const NumericVector<Number> & get_sensitivity_solution(unsigned int i=0) const;
1028 
1036 
1043 
1049  const NumericVector<Number> & get_weighted_sensitivity_adjoint_solution(unsigned int i=0) const;
1050 
1057 
1063 
1069 
1075  NumericVector<Number> & add_adjoint_rhs(unsigned int i=0);
1076 
1083  NumericVector<Number> & get_adjoint_rhs(unsigned int i=0);
1084 
1089  const NumericVector<Number> & get_adjoint_rhs(unsigned int i=0) const;
1090 
1096  NumericVector<Number> & add_sensitivity_rhs(unsigned int i=0);
1097 
1107  NumericVector<Number> & get_sensitivity_rhs(unsigned int i=0);
1108 
1113  const NumericVector<Number> & get_sensitivity_rhs(unsigned int i=0) const;
1114 
1120  unsigned int n_vectors () const;
1121 
1127  unsigned int n_matrices () const;
1128 
1132  unsigned int n_vars() const;
1133 
1137  unsigned int n_variable_groups() const;
1138 
1144  unsigned int n_components() const;
1145 
1149  dof_id_type n_dofs() const;
1150 
1155  dof_id_type n_active_dofs() const;
1156 
1162 
1168 
1173  dof_id_type n_local_dofs() const;
1174 
1183  unsigned int add_variable (std::string_view var,
1184  const FEType & type,
1185  const std::set<subdomain_id_type> * const active_subdomains = nullptr);
1186 
1196  unsigned int add_variable (std::string_view var,
1197  const Order order = FIRST,
1198  const FEFamily = LAGRANGE,
1199  const std::set<subdomain_id_type> * const active_subdomains = nullptr,
1200  const bool p_refinement = true);
1201 
1210  unsigned int add_variables (const std::vector<std::string> & vars,
1211  const FEType & type,
1212  const std::set<subdomain_id_type> * const active_subdomains = nullptr);
1213 
1232  unsigned int add_variable_array (const std::vector<std::string> & vars,
1233  const FEType & type,
1234  const std::set<subdomain_id_type> * const active_subdomains = nullptr);
1235 
1245  unsigned int add_variables (const std::vector<std::string> & vars,
1246  const Order order = FIRST,
1247  const FEFamily = LAGRANGE,
1248  const std::set<subdomain_id_type> * const active_subdomains = nullptr,
1249  const bool p_refinement = true);
1250 
1254  const Variable & variable (unsigned int var) const;
1255 
1259  const VariableGroup & variable_group (unsigned int vg) const;
1260 
1264  bool has_variable(std::string_view var) const;
1265 
1269  const std::string & variable_name(const unsigned int i) const;
1270 
1275  unsigned int variable_number (std::string_view var) const;
1276 
1281  void get_all_variable_numbers(std::vector<unsigned int> & all_variable_numbers) const;
1282 
1293  unsigned int variable_scalar_number (std::string_view var,
1294  unsigned int component) const;
1295 
1306  unsigned int variable_scalar_number (unsigned int var_num,
1307  unsigned int component) const;
1308 
1309 
1313  const FEType & variable_type (const unsigned int i) const;
1314 
1318  const FEType & variable_type (std::string_view var) const;
1319 
1324  bool identify_variable_groups () const;
1325 
1329  void identify_variable_groups (const bool);
1330 
1336  unsigned int var,
1337  FEMNormType norm_type,
1338  std::set<unsigned int> * skip_dimensions=nullptr) const;
1339 
1345  const SystemNorm & norm,
1346  std::set<unsigned int> * skip_dimensions=nullptr) const;
1347 
1351  void read_header (Xdr & io,
1352  std::string_view version,
1353  const bool read_header=true,
1354  const bool read_additional_data=true,
1355  const bool read_legacy_format=false);
1356 
1361  template <typename ValType>
1362  void read_serialized_data (Xdr & io,
1363  const bool read_additional_data=true);
1371  const bool read_additional_data=true)
1372  { read_serialized_data<Number>(io, read_additional_data); }
1373 
1379  template <typename InValType>
1380  std::size_t read_serialized_vectors (Xdr & io,
1381  const std::vector<NumericVector<Number> *> & vectors) const;
1382 
1390  std::size_t read_serialized_vectors (Xdr & io,
1391  const std::vector<NumericVector<Number> *> & vectors) const
1392  { return read_serialized_vectors<Number>(io, vectors); }
1393 
1400  template <typename InValType>
1401  void read_parallel_data (Xdr & io,
1402  const bool read_additional_data);
1403 
1413  const bool read_additional_data)
1414  { read_parallel_data<Number>(io, read_additional_data); }
1415 
1419  void write_header (Xdr & io,
1420  std::string_view version,
1421  const bool write_additional_data) const;
1422 
1427  void write_serialized_data (Xdr & io,
1428  const bool write_additional_data = true) const;
1429 
1435  std::size_t write_serialized_vectors (Xdr & io,
1436  const std::vector<const NumericVector<Number> *> & vectors) const;
1437 
1444  void write_parallel_data (Xdr & io,
1445  const bool write_additional_data) const;
1446 
1451  std::string get_info () const;
1452 
1456  void attach_init_function (void fptr(EquationSystems & es,
1457  const std::string & name));
1458 
1464  void attach_init_object (Initialization & init);
1465 
1471  const std::string & name));
1472 
1477  void attach_assemble_object (Assembly & assemble);
1478 
1483  const std::string & name));
1484 
1488  void attach_constraint_object (Constraint & constrain);
1489 
1499  bool has_constraint_object () const;
1500 
1504  Constraint& get_constraint_object ();
1505 
1510  void attach_QOI_function (void fptr(EquationSystems & es,
1511  const std::string & name,
1512  const QoISet & qoi_indices));
1513 
1518  void attach_QOI_object (QOI & qoi);
1519 
1525  void attach_QOI_derivative (void fptr(EquationSystems & es,
1526  const std::string & name,
1527  const QoISet & qoi_indices,
1528  bool include_liftfunc,
1529  bool apply_constraints));
1530 
1536  void attach_QOI_derivative_object (QOIDerivative & qoi_derivative);
1537 
1542  virtual void user_initialization ();
1543 
1548  virtual void user_assembly ();
1549 
1554  virtual void user_constrain ();
1555 
1560  virtual void user_QOI (const QoISet & qoi_indices);
1561 
1566  virtual void user_QOI_derivative (const QoISet & qoi_indices = QoISet(),
1567  bool include_liftfunc = true,
1568  bool apply_constraints = true);
1569 
1575  virtual void re_update ();
1576 
1580  virtual void restrict_vectors ();
1581 
1585  virtual void prolong_vectors ();
1586 
1589 
1610 
1615  virtual void disable_cache ();
1616 
1626 
1641 
1642 
1643  //--------------------------------------------------
1644  // The solution and solution access members
1645 
1650  Number current_solution (const dof_id_type global_dof_number) const;
1651 
1655  std::unique_ptr<NumericVector<Number>> solution;
1656 
1667  std::unique_ptr<NumericVector<Number>> current_local_solution;
1668 
1678 
1682  unsigned int n_qois() const;
1683 
1684 public:
1685 
1689  void init_qois(unsigned int n_qois);
1690 
1691  void set_qoi(unsigned int qoi_index, Number qoi_value);
1692  Number get_qoi_value(unsigned int qoi_index) const;
1693 
1694  void set_qoi(std::vector<Number> new_qoi);
1695 
1699  std::vector<Number> get_qoi_values() const;
1700 
1701  void set_qoi_error_estimate(unsigned int qoi_index, Number qoi_error_estimate);
1702  Number get_qoi_error_estimate_value(unsigned int qoi_index) const;
1703 
1725  Number point_value(unsigned int var, const Point & p,
1726  const bool insist_on_success = true,
1727  const NumericVector<Number> * sol = nullptr) const;
1728 
1738  Number point_value(unsigned int var, const Point & p, const Elem & e,
1739  const NumericVector<Number> * sol = nullptr) const;
1740 
1747  Number point_value(unsigned int var, const Point & p, const Elem * e) const;
1748 
1755  Number point_value(unsigned int var, const Point & p, const NumericVector<Number> * sol) const;
1756 
1761  Gradient point_gradient(unsigned int var, const Point & p,
1762  const bool insist_on_success = true,
1763  const NumericVector<Number> * sol = nullptr) const;
1764 
1769  Gradient point_gradient(unsigned int var, const Point & p, const Elem & e,
1770  const NumericVector<Number> * sol = nullptr) const;
1771 
1778  Gradient point_gradient(unsigned int var, const Point & p, const Elem * e) const;
1779 
1786  Gradient point_gradient(unsigned int var, const Point & p, const NumericVector<Number> * sol) const;
1787 
1792  Tensor point_hessian(unsigned int var, const Point & p,
1793  const bool insist_on_success = true,
1794  const NumericVector<Number> * sol = nullptr) const;
1795 
1801  Tensor point_hessian(unsigned int var, const Point & p, const Elem & e,
1802  const NumericVector<Number> * sol = nullptr) const;
1803 
1810  Tensor point_hessian(unsigned int var, const Point & p, const Elem * e) const;
1811 
1818  Tensor point_hessian(unsigned int var, const Point & p, const NumericVector<Number> * sol) const;
1819 
1820 
1825  void local_dof_indices (const unsigned int var,
1826  std::set<dof_id_type> & var_indices) const;
1827 
1832  void zero_variable (NumericVector<Number> & v, unsigned int var_num) const;
1833 
1838  {
1839  return project_with_constraints;
1840  }
1841 
1842  void set_project_with_constraints(bool _project_with_constraints)
1843  {
1844  project_with_constraints = _project_with_constraints;
1845  }
1846 
1852  bool & hide_output() { return _hide_output; }
1853 
1854 #ifdef LIBMESH_HAVE_METAPHYSICL
1855 
1865  void projection_matrix (SparseMatrix<Number> & proj_mat) const;
1866 #endif // LIBMESH_HAVE_METAPHYSICL
1867 
1885  SparseMatrix<Number> & add_matrix (std::string_view mat_name,
1886  ParallelType type = PARALLEL,
1887  MatrixBuildType mat_build_type = MatrixBuildType::AUTOMATIC);
1888 
1904  template <template <typename> class>
1905  SparseMatrix<Number> & add_matrix (std::string_view mat_name, ParallelType = PARALLEL);
1906 
1920  SparseMatrix<Number> & add_matrix (std::string_view mat_name,
1921  std::unique_ptr<SparseMatrix<Number>> matrix,
1922  ParallelType type = PARALLEL);
1923 
1927  void remove_matrix(std::string_view mat_name);
1928 
1933  inline bool have_matrix (std::string_view mat_name) const { return _matrices.count(mat_name); }
1934 
1940  const SparseMatrix<Number> * request_matrix (std::string_view mat_name) const;
1941 
1947  SparseMatrix<Number> * request_matrix (std::string_view mat_name);
1948 
1953  const SparseMatrix<Number> & get_matrix (std::string_view mat_name) const;
1954 
1959  SparseMatrix<Number> & get_matrix (std::string_view mat_name);
1960 
1964  void prefer_hash_table_matrix_assembly(bool preference);
1965 
1970 
1974  [[nodiscard]] bool prefix_with_name() const { return _prefix_with_name; }
1975 
1980  std::string prefix() const { return this->name() + "_"; }
1981 
1985  virtual void create_static_condensation();
1986 
1990  bool has_static_condensation() const;
1991 
1992  /*
1993  * If we have e.g. a element space constrained by spline values, we
1994  * can directly project functions only on the constrained basis; to
1995  * get consistent constraining values we have to solve for them.
1996  *
1997  * Constrain the new vector using the requested adjoint rather than
1998  * primal constraints if is_adjoint is non-negative.
1999  */
2001  int is_adjoint = -1) const;
2002 
2003 protected:
2004 
2011  virtual void init_data ();
2012 
2017  virtual void add_matrices() {}
2018 
2022  virtual void init_matrices ();
2023 
2028  bool can_add_matrices() const { return !_matrices_initialized; }
2029 
2038  int is_adjoint = -1,
2039  std::optional<ConstElemRange> active_local_range = std::nullopt,
2040  std::optional<std::vector<unsigned int>> variable_numbers = std::nullopt) const;
2041 
2050  void project_vector (const NumericVector<Number> &,
2052  int is_adjoint = -1,
2053  std::optional<ConstElemRange> active_local_range = std::nullopt,
2054  std::optional<std::vector<unsigned int>> variable_numbers = std::nullopt) const;
2055 
2059  virtual bool condense_constrained_dofs() const { return false; }
2060 
2061 private:
2066  ParallelType type);
2067 
2073  unsigned int var,
2074  FEMNormType norm_type) const;
2075 
2085  template <typename iterator_type, typename InValType>
2087  const iterator_type begin,
2088  const iterator_type end,
2089  const InValType dummy,
2090  Xdr & io,
2091  const std::vector<NumericVector<Number> *> & vecs,
2092  const unsigned int var_to_read=libMesh::invalid_uint) const;
2093 
2102  unsigned int read_SCALAR_dofs (const unsigned int var,
2103  Xdr & io,
2104  NumericVector<Number> * vec) const;
2105 
2114  template <typename InValType>
2116  NumericVector<Number> * vec);
2117 
2127  NumericVector<Number> & vec)
2128  { return read_serialized_vector<Number>(io, &vec); }
2129 
2136  template <typename iterator_type>
2137  std::size_t write_serialized_blocked_dof_objects (const std::vector<const NumericVector<Number> *> & vecs,
2138  const dof_id_type n_objects,
2139  const iterator_type begin,
2140  const iterator_type end,
2141  Xdr & io,
2142  const unsigned int var_to_write=libMesh::invalid_uint) const;
2143 
2149  unsigned int write_SCALAR_dofs (const NumericVector<Number> & vec,
2150  const unsigned int var,
2151  Xdr & io) const;
2152 
2160  const NumericVector<Number> & vec) const;
2161 
2166  const std::string & name);
2167 
2172 
2177  const std::string & name);
2178 
2183 
2188  const std::string & name);
2189 
2194 
2199  const std::string & name,
2200  const QoISet & qoi_indices);
2201 
2206 
2211  const std::string & name,
2212  const QoISet & qoi_indices,
2213  bool include_liftfunc,
2214  bool apply_constraints);
2215 
2220 
2225  std::unique_ptr<DofMap> _dof_map;
2226 
2232 
2238 
2242  const std::string _sys_name;
2243 
2247  const unsigned int _sys_number;
2248 
2252  bool _active;
2253 
2260  std::map<std::string, std::unique_ptr<NumericVector<Number>>, std::less<>> _vectors;
2261 
2266  std::map<std::string, bool, std::less<>> _vector_projections;
2267 
2272  std::map<std::string, int, std::less<>> _vector_is_adjoint;
2273 
2277  std::map<std::string, std::unique_ptr<SparseMatrix<Number>>, std::less<>> _matrices;
2278 
2282  std::map<std::string, ParallelType, std::less<>> _matrix_types;
2283 
2288 
2295 
2301 
2307 
2314 
2325  std::vector<unsigned int> _written_var_indices;
2326 
2333 
2339 
2344 
2349 
2354 
2359 
2367  std::vector<Number> _qoi;
2368 
2377  std::vector<Number> _qoi_error_estimates;
2378 };
2379 
2380 
2381 
2382 // ------------------------------------------------------------
2383 // System inline methods
2384 inline
2385 const std::string & System::name() const
2386 {
2387  return _sys_name;
2388 }
2389 
2390 
2391 
2392 inline
2393 unsigned int System::number() const
2394 {
2395  return _sys_number;
2396 }
2397 
2398 
2399 
2400 inline
2402 {
2403  return _mesh;
2404 }
2405 
2406 
2407 
2408 inline
2410 {
2411  return _mesh;
2412 }
2413 
2414 
2415 
2416 inline
2418 {
2419  return *_dof_map;
2420 }
2421 
2422 
2423 
2424 inline
2426 {
2427  return *_dof_map;
2428 }
2429 
2430 
2431 
2432 inline
2433 bool System::active() const
2434 {
2435  return _active;
2436 }
2437 
2438 
2439 
2440 inline
2442 {
2443  _active = true;
2444 }
2445 
2446 
2447 
2448 inline
2450 {
2451  _active = false;
2452 }
2453 
2454 
2455 
2456 inline
2458 {
2459  return _is_initialized;
2460 }
2461 
2462 
2463 
2464 inline
2466 {
2467  _basic_system_only = true;
2468 }
2469 
2470 
2471 
2472 inline
2473 unsigned int
2474 System::variable_scalar_number (std::string_view var,
2475  unsigned int component) const
2476 {
2477  return variable_scalar_number(this->variable_number(var), component);
2478 }
2479 
2480 
2481 
2482 inline
2484 {
2485  return this->n_dofs() - this->n_constrained_dofs();
2486 }
2487 
2488 
2489 
2490 inline
2491 bool System::have_vector (std::string_view vec_name) const
2492 {
2493  return (_vectors.count(vec_name));
2494 }
2495 
2496 
2497 
2498 inline
2499 unsigned int System::n_vectors () const
2500 {
2501  return cast_int<unsigned int>(_vectors.size());
2502 }
2503 
2504 inline
2506 {
2507  return _vectors.begin();
2508 }
2509 
2510 inline
2512 {
2513  return _vectors.begin();
2514 }
2515 
2516 inline
2518 {
2519  return _vectors.end();
2520 }
2521 
2522 inline
2524 {
2525  return _vectors.end();
2526 }
2527 
2528 inline
2530 {
2531  return _matrices.begin();
2532 }
2533 
2534 inline
2536 {
2537  return _matrices.begin();
2538 }
2539 
2540 inline
2542 {
2543  return _matrices.end();
2544 }
2545 
2546 inline
2548 {
2549  return _matrices.end();
2550 }
2551 
2552 inline
2554 {
2555  libmesh_not_implemented();
2556 }
2557 
2558 inline
2560 
2561 inline
2562 unsigned int System::n_qois() const
2563 {
2564  libmesh_assert_equal_to(this->_qoi.size(), this->_qoi_error_estimates.size());
2565 
2566  return cast_int<unsigned int>(this->_qoi.size());
2567 }
2568 
2569 inline
2570 std::pair<unsigned int, Real>
2572 {
2573  libmesh_not_implemented();
2574 }
2575 
2576 inline
2577 std::pair<unsigned int, Real>
2579  const ParameterVector &)
2580 {
2581  libmesh_not_implemented();
2582 }
2583 
2584 inline
2585 std::pair<unsigned int, Real>
2587 {
2588  libmesh_not_implemented();
2589 }
2590 
2591 inline
2592 std::pair<unsigned int, Real>
2594  const ParameterVector &,
2595  const QoISet &)
2596 {
2597  libmesh_not_implemented();
2598 }
2599 
2600 inline
2601 void
2603  const ParameterVector &,
2604  SensitivityData &)
2605 {
2606  libmesh_not_implemented();
2607 }
2608 
2609 inline
2610 void
2612  const ParameterVector &,
2613  SensitivityData &)
2614 {
2615  libmesh_not_implemented();
2616 }
2617 
2618 inline
2619 void
2621  const ParameterVector &,
2622  SensitivityData &)
2623 {
2624  libmesh_not_implemented();
2625 }
2626 
2627 inline
2628 void
2630  const ParameterVector &,
2631  const ParameterVector &,
2632  SensitivityData &)
2633 {
2634  libmesh_not_implemented();
2635 }
2636 
2637 inline
2638 unsigned int System::n_matrices () const
2639 {
2640  return cast_int<unsigned int>(_matrices.size());
2641 }
2642 
2643 template <template <typename> class MatrixType>
2644 inline
2646 System::add_matrix (std::string_view mat_name,
2647  const ParallelType type)
2648 {
2649  // Return the matrix if it is already there.
2650  auto it = this->_matrices.find(mat_name);
2651  if (it != this->_matrices.end())
2652  return *it->second;
2653 
2654  // Otherwise build the matrix to return.
2655  auto pr = _matrices.emplace(mat_name, std::make_unique<MatrixType<Number>>(this->comm()));
2656  _matrix_types.emplace(mat_name, type);
2657 
2658  SparseMatrix<Number> & mat = *(pr.first->second);
2659 
2660  // Initialize it first if we've already initialized the others.
2661  this->late_matrix_init(mat, type);
2662 
2663  return mat;
2664 }
2665 
2666 inline void
2668 {
2669  libmesh_error_msg_if(
2671  "System::prefer_hash_table_matrix_assembly() should be called before matrices are initialized");
2673 }
2674 } // namespace libMesh
2675 
2676 #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:1147
matrices_iterator matrices_begin()
Beginning of matrices container.
Definition: system.h:2529
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:1390
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:1366
std::map< std::string, std::unique_ptr< NumericVector< Number > >, std::less<> >::iterator vectors_iterator
Vector iterator typedefs.
Definition: system.h:803
vectors_iterator vectors_end()
End of vectors container.
Definition: system.h:2517
bool is_initialized() const
Definition: system.h:2457
Real time
For time-dependent problems, this is the time t at the beginning of the current timestep.
Definition: system.h:1677
bool can_add_matrices() const
Definition: system.h:2028
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:1409
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:1521
This is the EquationSystems class.
unsigned int variable_scalar_number(std::string_view var, unsigned int component) const
Definition: system.h:2474
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:173
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:1412
virtual void create_static_condensation()
Request that static condensation be performed for this system.
Definition: system.C:2664
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:733
Abstract base class to be used for system initialization.
Definition: system.h:133
void write_parallel_data(Xdr &io, const bool write_additional_data) const
Writes additional data, namely vectors, for this System.
Definition: system_io.C:1321
const Variable & variable(unsigned int var) const
Return a constant reference to Variable var.
Definition: system.C:2704
Assembly * _assemble_system_object
Object that assembles the system.
Definition: system.h:2182
Gradient point_gradient(unsigned int var, const Point &p, const bool insist_on_success=true, const NumericVector< Number > *sol=nullptr) const
Definition: system.C:2348
bool _basic_system_only
Holds true if the components of more advanced system types (e.g.
Definition: system.h:2300
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:303
virtual void init_matrices()
Initializes the matrices associated with this system.
Definition: system.C:311
bool _is_initialized
true when additional vectors and variables do not require immediate initialization, false otherwise.
Definition: system.h:2306
void(* _constrain_system_function)(EquationSystems &es, const std::string &name)
Function to impose constraints.
Definition: system.h:2187
void set_adjoint_already_solved(bool setting)
Setter for the adjoint_already_solved boolean.
Definition: system.h:417
This class provides the ability to map between arbitrary, user-defined strings and several data types...
Definition: parameters.h:74
NumericVector< Number > & add_adjoint_solution(unsigned int i=0)
Definition: system.C:1220
virtual bool condense_constrained_dofs() const
Whether this object should condense out constrained degrees of freedom.
Definition: system.h:2059
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:2611
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:2553
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:1120
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:2184
virtual void reinit()
Reinitializes degrees of freedom and other required data on the current mesh.
Definition: system.C:442
unsigned int n_qois() const
Number of currently active quantities of interest.
Definition: system.h:2562
unsigned int n_components() const
Definition: system.C:2694
virtual void disable_cache()
Avoids use of any cached data that might affect any solve result.
Definition: system.h:2559
bool active() const
Definition: system.h:2433
int extra_quadrature_order
A member int that can be employed to indicate increased or reduced quadrature order.
Definition: system.h:1640
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:618
sys_type & system()
Definition: system.h:255
NumericVector< Number > & get_sensitivity_solution(unsigned int i=0)
Definition: system.C:1179
void read_serialized_data(Xdr &io, const bool read_additional_data=true)
Non-templated version for backward compatibility.
Definition: system.h:1370
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:1915
const unsigned int _sys_number
The number associated with this system.
Definition: system.h:2247
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:576
NumericVector< Number > & get_sensitivity_rhs(unsigned int i=0)
Definition: system.C:1324
int vector_is_adjoint(std::string_view vec_name) const
Definition: system.C:1160
virtual void assemble()=0
Assembly function.
Constraint * _constrain_system_object
Object that constrains the system.
Definition: system.h:2193
const EquationSystems & get_equation_systems() const
Definition: system.h:767
unsigned int n_variable_groups() const
Definition: system.C:2699
virtual void assemble()
Prepares matrix and _dof_map for matrix assembly.
Definition: system.C:554
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:1386
virtual void init_data()
Initializes the data for the system.
Definition: system.C:207
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:2169
std::map< std::string, std::unique_ptr< SparseMatrix< Number > >, std::less<> >::iterator matrices_iterator
Matrix iterator typedefs.
Definition: system.h:829
Number point_value(unsigned int var, const Point &p, const bool insist_on_success=true, const NumericVector< Number > *sol=nullptr) const
Definition: system.C:2219
std::unique_ptr< DofMap > _dof_map
Data structure describing the relationship between nodes, variables, etc...
Definition: system.h:2225
virtual void user_initialization()
Calls user&#39;s attached initialization function, or is overridden by the user in derived classes...
Definition: system.C:2095
std::map< std::string, std::unique_ptr< NumericVector< Number > >, std::less<> > _vectors
Some systems need an arbitrary number of vectors.
Definition: system.h:2260
bool _active
Flag stating if the system is active or not.
Definition: system.h:2252
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:756
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:1403
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:1314
This class defines a vector in LIBMESH_DIM dimensional Real or Complex space.
bool has_static_condensation() const
Definition: system.C:2669
The libMesh namespace provides an interface to certain functionality in the library.
vectors_iterator vectors_begin()
Beginning of vectors container.
Definition: system.h:2505
std::map< std::string, std::unique_ptr< SparseMatrix< Number > >, std::less<> >::const_iterator const_matrices_iterator
Definition: system.h:830
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:2081
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:2602
dof_id_type n_local_dofs() const
Definition: system.C:155
Abstract base class to be used for system assembly.
Definition: system.h:157
NumericVector< Number > & add_weighted_sensitivity_solution()
Definition: system.C:1199
void(* _qoi_evaluate_function)(EquationSystems &es, const std::string &name, const QoISet &qoi_indices)
Function to evaluate quantity of interest.
Definition: system.h:2198
const SparseMatrix< Number > * request_matrix(std::string_view mat_name) const
Definition: system.C:1087
System sys_type
The type of system.
Definition: system.h:250
Parameters parameters
Parameters for the system. If a parameter is not provided, it should be retrieved from the EquationSy...
Definition: system.h:1588
void init()
Initializes degrees of freedom on the current mesh.
Definition: system.C:196
const MeshBase & get_mesh() const
Definition: system.h:2401
NumericVector< Number > & get_weighted_sensitivity_solution()
Definition: system.C:1206
bool adjoint_already_solved
Has the adjoint problem already been solved? If the user sets adjoint_already_solved to true...
Definition: system.h:2332
dof_id_type n_dofs() const
Definition: system.C:118
uint8_t processor_id_type
Definition: id_types.h:104
This is the MeshBase class.
Definition: mesh_base.h:80
virtual void prolong_vectors()
Prolong vectors after the mesh has refined.
Definition: system.C:432
Number current_solution(const dof_id_type global_dof_number) const
Definition: system.C:162
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:2137
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:1398
std::map< std::string, std::unique_ptr< SparseMatrix< Number > >, std::less<> > _matrices
Some systems need an arbitrary number of matrices.
Definition: system.h:2277
bool have_matrix(std::string_view mat_name) const
Definition: system.h:1933
QOIDerivative * _qoi_evaluate_derivative_object
Object to compute derivatives of quantities of interest.
Definition: system.h:2219
NumericVector< Number > & add_weighted_sensitivity_adjoint_solution(unsigned int i=0)
Definition: system.C:1252
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:590
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:2620
void attach_constraint_object(Constraint &constrain)
Register a user object for imposing constraints.
Definition: system.C:2007
This class handles the numbering of degrees of freedom on a mesh.
Definition: dof_map.h:179
void attach_init_object(Initialization &init)
Register a user class to use to initialize the system.
Definition: system.C:1945
void set_basic_system_only()
Sets the system to be "basic only": i.e.
Definition: system.h:2465
bool has_variable(std::string_view var) const
Definition: system.C:1393
unsigned int number() const
Definition: system.h:2393
std::vector< Number > _qoi
Values of the quantities of interest.
Definition: system.h:2367
void remove_vector(std::string_view vec_name)
Removes the additional vector vec_name from this system.
Definition: system.C:861
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:2272
Constraint & get_constraint_object()
Return the user object for imposing constraints.
Definition: system.C:2024
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:2629
Data structure for holding completed parameter sensitivity calculations.
dof_id_type numeric_index_type
Definition: id_types.h:99
void deactivate()
Deactivates the system.
Definition: system.h:2449
void remove_matrix(std::string_view mat_name)
Removes the additional matrix mat_name from this system.
Definition: system.C:1076
std::string prefix() const
Definition: system.h:1980
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:1625
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:2499
Manages consistently variables, degrees of freedom, and coefficient vectors.
Definition: system.h:98
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:1450
System & operator=(const System &)=delete
bool & hide_output()
Definition: system.h:1852
bool _prefer_hash_table_matrix_assembly
Whether to use hash table matrix assembly if the matrix sub-classes support it.
Definition: system.h:2348
virtual void add_matrices()
Insertion point for adding matrices in derived classes before init_matrices() is called.
Definition: system.h:2017
bool has_constraint_object() const
Definition: system.C:2019
std::string get_info() const
Definition: system.C:1827
numeric_index_type read_serialized_vector(Xdr &io, NumericVector< Number > *vec)
Reads a vector for this System.
Definition: system_io.C:989
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:1655
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:2064
Real calculate_norm(const NumericVector< Number > &v, unsigned int var, FEMNormType norm_type, std::set< unsigned int > *skip_dimensions=nullptr) const
Definition: system.C:1511
bool project_with_constraints
Do we want to apply constraints while projecting vectors ?
Definition: system.h:2343
bool have_vector(std::string_view vec_name) const
Definition: system.h:2491
QOI * _qoi_evaluate_object
Object to compute quantities of interest.
Definition: system.h:2205
virtual std::pair< unsigned int, Real > sensitivity_solve(const ParameterVector &parameters)
Solves the sensitivity system, for the provided parameters.
Definition: system.h:2571
Initialization * _init_system_object
Object that initializes the system.
Definition: system.h:2171
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:2586
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:2032
bool _hide_output
Are we allowed to write this system to file? If _hide_output is true, then EquationSystems::write wil...
Definition: system.h:2338
unsigned int _additional_data_written
This flag is used only when reading in a system from file.
Definition: system.h:2313
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:1344
const std::string & variable_name(const unsigned int i) const
Definition: system.C:2679
void(* _init_system_function)(EquationSystems &es, const std::string &name)
Function that initializes the system.
Definition: system.h:2165
dof_id_type n_active_dofs() const
Definition: system.h:2483
std::map< std::string, ParallelType, std::less<> > _matrix_types
Holds the types of the matrices.
Definition: system.h:2282
virtual void restrict_vectors()
Restrict vectors after the mesh has coarsened.
Definition: system.C:374
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:1959
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:2018
unsigned int n_matrices() const
Definition: system.h:2638
This class implements reference counting.
void project_solution(FunctionBase< Number > *f, FunctionBase< Gradient > *g=nullptr, std::optional< ConstElemRange > active_local_range=std::nullopt, std::optional< std::vector< unsigned int >> variable_numbers=std::nullopt) const
Projects arbitrary functions onto the current solution.
void set_project_with_constraints(bool _project_with_constraints)
Definition: system.h:1842
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:215
void activate()
Activates the system.
Definition: system.h:2441
NumericVector< Number > & add_adjoint_rhs(unsigned int i=0)
Definition: system.C:1284
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:545
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:2151
virtual void reinit_constraints()
Reinitializes the constraints for this system.
Definition: system.C:483
bool identify_variable_groups() const
Definition: system.C:2684
bool is_adjoint_already_solved() const
Accessor for the adjoint_already_solved boolean.
Definition: system.h:411
virtual void solve()
Solves the system.
Definition: system.h:349
This class implements a C++ interface to the XDR (eXternal Data Representation) format.
Definition: xdr_cxx.h:67
void boundary_project_solution(const std::set< boundary_id_type > &b, const std::vector< unsigned int > &variables, FunctionBase< Number > *f, FunctionBase< Gradient > *g=nullptr, std::optional< ConstElemRange > active_local_range=std::nullopt)
Projects arbitrary boundary functions onto a vector of degree of freedom values for the current syste...
virtual void reinit_mesh()
Reinitializes the system with a new mesh.
Definition: system.C:289
const NumericVector< Number > * request_vector(std::string_view vec_name) const
Definition: system.C:879
EquationSystems & get_equation_systems()
Definition: system.h:772
void attach_assemble_object(Assembly &assemble)
Register a user object to use in assembling the system matrix and RHS.
Definition: system.C:1976
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:2294
EquationSystems & _equation_systems
Constant reference to the EquationSystems object used for the simulation.
Definition: system.h:2231
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:2114
virtual std::string system_type() const
Definition: system.h:510
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:302
const std::string & vector_name(const unsigned int vec_num) const
Definition: system.C:971
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:2050
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:2667
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:2109
virtual ~QOIDerivative()=default
Destructor.
virtual void update()
Update the local values to reflect the solution on neighboring processors.
Definition: system.C:498
const FEType & variable_type(const unsigned int i) const
Definition: system.C:2721
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:1125
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:551
void set_qoi_error_estimate(unsigned int qoi_index, Number qoi_error_estimate)
Definition: system.C:2204
auto norm(const T &a)
Definition: tensor_tools.h:74
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:2578
bool _matrices_initialized
false when additional matrices being added require initialization, true otherwise.
Definition: system.h:2287
static const Real b
bool _require_sparsity_pattern
Whether any of our matrices require an initial sparsity pattern computation in order to determine pre...
Definition: system.h:2353
const std::string _sys_name
A name associated with this system.
Definition: system.h:2242
Tensor point_hessian(unsigned int var, const Point &p, const bool insist_on_success=true, const NumericVector< Number > *sol=nullptr) const
Definition: system.C:2492
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:884
static const bool value
Definition: xdr_io.C:55
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:2377
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:1232
virtual void re_update()
Re-update the local values when the mesh has changed.
Definition: system.C:521
Abstract base class to be used for system constraints.
Definition: system.h:181
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:1667
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:2593
virtual bool compare(const System &other_system, const Real threshold, const bool verbose) const
Definition: system.C:606
void set_qoi(unsigned int qoi_index, Number qoi_value)
Definition: system.C:2176
dof_id_type n_local_constrained_dofs() const
Definition: system.C:140
bool get_project_with_constraints()
Setter and getter functions for project_with_constraints boolean.
Definition: system.h:1837
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:942
const std::string & name() const
Definition: system.h:2385
void attach_constraint_function(void fptr(EquationSystems &es, const std::string &name))
Register a user function for imposing constraints.
Definition: system.C:1990
Gradient(* GradientFunctionPointer)(const Point &p, const Parameters &parameters, const std::string &sys_name, const std::string &unknown_name)
Definition: system.h:555
virtual void user_constrain()
Calls user&#39;s attached constraint function, or is overridden by the user in derived classes...
Definition: system.C:2123
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:1492
Number get_qoi_error_estimate_value(unsigned int qoi_index) const
Definition: system.C:2211
virtual void assemble_qoi(const QoISet &qoi_indices=QoISet())
Calls user qoi function.
Definition: system.C:565
NumericVector< Number > & add_sensitivity_solution(unsigned int i=0)
Definition: system.C:1169
FEFamily
defines an enum for finite element families.
unsigned int n_vars() const
Definition: system.C:2674
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:2176
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:1969
virtual ~System()
Definition: system.C:111
numeric_index_type read_serialized_vector(Xdr &io, NumericVector< Number > &vec)
Non-templated version for backward compatibility.
Definition: system.h:2126
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:1609
std::map< std::string, std::unique_ptr< NumericVector< Number > >, std::less<> >::const_iterator const_vectors_iterator
Definition: system.h:804
System(EquationSystems &es, const std::string &name, const unsigned int number)
Constructor.
Definition: system.C:64
bool vector_preservation(std::string_view vec_name) const
Definition: system.C:1135
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:998
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:2417
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:2358
void late_matrix_init(SparseMatrix< Number > &mat, ParallelType type)
Helper function to keep DofMap forward declarable in system.h.
Definition: system.C:1063
const SparseMatrix< Number > & get_matrix(std::string_view mat_name) const
Definition: system.C:1111
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:2237
void project_vector(NumericVector< Number > &new_vector, FunctionBase< Number > *f, FunctionBase< Gradient > *g=nullptr, int is_adjoint=-1, std::optional< ConstElemRange > active_local_range=std::nullopt, std::optional< std::vector< unsigned int >> variable_numbers=std::nullopt) const
Projects arbitrary functions onto a vector of degree of freedom values for the current system...
void read_serialized_data(Xdr &io, const bool read_additional_data=true)
Reads additional data, namely vectors, for this System.
Definition: system_io.C:533
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, std::optional< ConstElemRange > active_local_range=std::nullopt) const
Projects arbitrary boundary functions onto a vector of degree of freedom values for the current syste...
matrices_iterator matrices_end()
End of matrices container.
Definition: system.h:2541
const VariableGroup & variable_group(unsigned int vg) const
Return a constant reference to VariableGroup vg.
Definition: system.C:2709
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:1928
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:2266
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:1629
Abstract base class to be used for quantities of interest.
Definition: system.h:205
const NumericVector< Number > & get_vector(std::string_view vec_name) const
Definition: system.C:931
NumericVector< Number > & get_weighted_sensitivity_adjoint_solution(unsigned int i=0)
Definition: system.C:1264
This class defines a tensor in LIBMESH_DIM dimensional Real or Complex space.
dof_id_type n_constrained_dofs() const
Definition: system.C:125
std::vector< unsigned int > _written_var_indices
This vector is used only when reading in a system from file.
Definition: system.h:2325
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:2191
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:2210
ParallelType
Defines an enum for parallel data structure types.
Abstract base class to be used for derivatives of quantities of interest.
Definition: system.h:229
NumericVector< Number > & get_adjoint_rhs(unsigned int i=0)
Definition: system.C:1294
bool prefix_with_name() const
Definition: system.h:1974
dof_id_type write_serialized_vector(Xdr &io, const NumericVector< Number > &vec) const
Writes a vector for this System.
Definition: system_io.C:1971