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/variable.h"
35 #include "libmesh/enum_matrix_build_type.h" // AUTOMATIC
36 
37 // C++ includes
38 #include <cstddef>
39 #include <set>
40 #include <string>
41 #include <string_view>
42 #include <vector>
43 #include <memory>
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 
96 class System : public ReferenceCountedObject<System>,
97  public ParallelObject
98 {
99 public:
100 
105  System (EquationSystems & es,
106  const std::string & name,
107  const unsigned int number);
108 
119  System (const System &) = delete;
120  System & operator= (const System &) = delete;
121  System (System &&) = default;
122  System & operator= (System &&) = delete;
123  virtual ~System ();
124 
132  {
133  public:
137  virtual ~Initialization () = default;
138 
144  virtual void initialize () = 0;
145  };
146 
147 
148 
155  class Assembly
156  {
157  public:
161  virtual ~Assembly () = default;
162 
168  virtual void assemble () = 0;
169  };
170 
171 
172 
180  {
181  public:
185  virtual ~Constraint () = default;
186 
192  virtual void constrain () = 0;
193  };
194 
195 
196 
203  class QOI
204  {
205  public:
209  virtual ~QOI () = default;
210 
216  virtual void qoi (const QoISet & qoi_indices) = 0;
217  };
218 
219 
220 
228  {
229  public:
233  virtual ~QOIDerivative () = default;
234 
240  virtual void qoi_derivative (const QoISet & qoi_indices,
241  bool include_liftfunc,
242  bool apply_constraints) = 0;
243  };
244 
248  typedef System sys_type;
249 
253  sys_type & system () { return *this; }
254 
259  virtual void clear ();
260 
265  void init ();
266 
275  virtual void reinit ();
276 
283  virtual void reinit_constraints ();
284 
288  virtual void reinit_mesh();
289 
293  bool is_initialized() const;
294 
299  virtual void update ();
300 
307  virtual void assemble ();
308 
313  virtual void assemble_qoi (const QoISet & qoi_indices = QoISet());
314 
319  virtual void assemble_qoi_derivative (const QoISet & qoi_indices = QoISet(),
320  bool include_liftfunc = true,
321  bool apply_constraints = true);
322 
335 
341  virtual void restrict_solve_to (const SystemSubset * subset,
342  const SubsetSolveMode subset_solve_mode=SUBSET_ZERO);
343 
347  virtual void solve () {}
348 
358  virtual std::pair<unsigned int, Real>
360 
371  virtual std::pair<unsigned int, Real>
373  const ParameterVector & weights);
374 
385  virtual std::pair<unsigned int, Real>
386  adjoint_solve (const QoISet & qoi_indices = QoISet());
387 
402  virtual std::pair<unsigned int, Real>
404  const ParameterVector & weights,
405  const QoISet & qoi_indices = QoISet());
410  { return adjoint_already_solved;}
411 
415  void set_adjoint_already_solved(bool setting)
416  { adjoint_already_solved = setting;}
417 
418 
436  virtual void qoi_parameter_sensitivity (const QoISet & qoi_indices,
437  const ParameterVector & parameters,
438  SensitivityData & sensitivities);
439 
445  virtual void adjoint_qoi_parameter_sensitivity (const QoISet & qoi_indices,
446  const ParameterVector & parameters,
447  SensitivityData & sensitivities);
448 
454  virtual void forward_qoi_parameter_sensitivity (const QoISet & qoi_indices,
455  const ParameterVector & parameters,
456  SensitivityData & sensitivities);
457 
468  virtual void qoi_parameter_hessian(const QoISet & qoi_indices,
469  const ParameterVector & parameters,
470  SensitivityData & hessian);
471 
484  virtual void qoi_parameter_hessian_vector_product(const QoISet & qoi_indices,
485  const ParameterVector & parameters,
486  const ParameterVector & vector,
487  SensitivityData & product);
488 
494  virtual bool compare (const System & other_system,
495  const Real threshold,
496  const bool verbose) const;
497 
501  const std::string & name () const;
502 
508  virtual std::string system_type () const { return "Basic"; }
509 
518  FunctionBase<Gradient> * g = nullptr) const;
519 
528  FEMFunctionBase<Gradient> * g = nullptr) const;
529 
537  typedef Number (*ValueFunctionPointer)(const Point & p,
538  const Parameters & Parameters,
539  const std::string & sys_name,
540  const std::string & unknown_name);
541  typedef Gradient (*GradientFunctionPointer)(const Point & p,
542  const Parameters & parameters,
543  const std::string & sys_name,
544  const std::string & unknown_name);
547  const Parameters & parameters) const;
548 
560  void project_vector (NumericVector<Number> & new_vector,
562  FunctionBase<Gradient> * g = nullptr,
563  int is_adjoint = -1) const;
564 
576  void project_vector (NumericVector<Number> & new_vector,
578  FEMFunctionBase<Gradient> * g = nullptr,
579  int is_adjoint = -1) const;
580 
594  const Parameters & parameters,
595  NumericVector<Number> & new_vector,
596  int is_adjoint = -1) const;
597 
610  void boundary_project_solution (const std::set<boundary_id_type> & b,
611  const std::vector<unsigned int> & variables,
613  FunctionBase<Gradient> * g = nullptr);
614 
627  void boundary_project_solution (const std::set<boundary_id_type> & b,
628  const std::vector<unsigned int> & variables,
631  const Parameters & parameters);
632 
648  void boundary_project_vector (const std::set<boundary_id_type> & b,
649  const std::vector<unsigned int> & variables,
650  NumericVector<Number> & new_vector,
652  FunctionBase<Gradient> * g = nullptr,
653  int is_adjoint = -1) const;
654 
670  void boundary_project_vector (const std::set<boundary_id_type> & b,
671  const std::vector<unsigned int> & variables,
674  const Parameters & parameters,
675  NumericVector<Number> & new_vector,
676  int is_adjoint = -1) const;
677 
681  unsigned int number () const;
682 
688  void update_global_solution (std::vector<Number> & global_soln) const;
689 
695  void update_global_solution (std::vector<Number> & global_soln,
696  const processor_id_type dest_proc) const;
697 
701  const MeshBase & get_mesh() const;
702 
706  MeshBase & get_mesh();
707 
711  const DofMap & get_dof_map() const;
712 
716  DofMap & get_dof_map();
717 
722 
727 
732  bool active () const;
733 
737  void activate ();
738 
742  void deactivate ();
743 
752  void set_basic_system_only ();
753 
757  typedef std::map<std::string, std::unique_ptr<NumericVector<Number>>, std::less<>>::iterator vectors_iterator;
758  typedef std::map<std::string, std::unique_ptr<NumericVector<Number>>, std::less<>>::const_iterator const_vectors_iterator;
759 
764 
769 
774 
779 
783  typedef std::map<std::string, std::unique_ptr<SparseMatrix<Number>>, std::less<>>::iterator matrices_iterator;
784  typedef std::map<std::string, std::unique_ptr<SparseMatrix<Number>>, std::less<>>::const_iterator const_matrices_iterator;
785 
790 
795 
800 
805 
824  NumericVector<Number> & add_vector (std::string_view vec_name,
825  const bool projections=true,
826  const ParallelType type = PARALLEL);
827 
831  void remove_vector(std::string_view vec_name);
832 
839  { return _solution_projection; }
840 
845  bool have_vector (std::string_view vec_name) const;
846 
851  const NumericVector<Number> * request_vector (std::string_view vec_name) const;
852 
857  NumericVector<Number> * request_vector (std::string_view vec_name);
858 
864  const NumericVector<Number> * request_vector (const unsigned int vec_num) const;
865 
871  NumericVector<Number> * request_vector (const unsigned int vec_num);
872 
878  const NumericVector<Number> & get_vector (std::string_view vec_name) const;
879 
885  NumericVector<Number> & get_vector (std::string_view vec_name);
886 
892  const NumericVector<Number> & get_vector (const unsigned int vec_num) const;
893 
899  NumericVector<Number> & get_vector (const unsigned int vec_num);
900 
905  const std::string & vector_name (const unsigned int vec_num) const;
906 
910  const std::string & vector_name (const NumericVector<Number> & vec_reference) const;
911 
922  void set_vector_as_adjoint (const std::string & vec_name, int qoi_num);
923 
929  int vector_is_adjoint (std::string_view vec_name) const;
930 
936  void set_vector_preservation (const std::string & vec_name, bool preserve);
937 
943  bool vector_preservation (std::string_view vec_name) const;
944 
950  NumericVector<Number> & add_adjoint_solution(unsigned int i=0);
951 
956  NumericVector<Number> & get_adjoint_solution(unsigned int i=0);
957 
962  const NumericVector<Number> & get_adjoint_solution(unsigned int i=0) const;
963 
970 
976 
981  const NumericVector<Number> & get_sensitivity_solution(unsigned int i=0) const;
982 
990 
997 
1003  const NumericVector<Number> & get_weighted_sensitivity_adjoint_solution(unsigned int i=0) const;
1004 
1011 
1017 
1023 
1029  NumericVector<Number> & add_adjoint_rhs(unsigned int i=0);
1030 
1037  NumericVector<Number> & get_adjoint_rhs(unsigned int i=0);
1038 
1043  const NumericVector<Number> & get_adjoint_rhs(unsigned int i=0) const;
1044 
1050  NumericVector<Number> & add_sensitivity_rhs(unsigned int i=0);
1051 
1061  NumericVector<Number> & get_sensitivity_rhs(unsigned int i=0);
1062 
1067  const NumericVector<Number> & get_sensitivity_rhs(unsigned int i=0) const;
1068 
1074  unsigned int n_vectors () const;
1075 
1081  unsigned int n_matrices () const;
1082 
1086  unsigned int n_vars() const;
1087 
1091  unsigned int n_variable_groups() const;
1092 
1098  unsigned int n_components() const;
1099 
1103  dof_id_type n_dofs() const;
1104 
1109  dof_id_type n_active_dofs() const;
1110 
1116 
1122 
1127  dof_id_type n_local_dofs() const;
1128 
1137  unsigned int add_variable (std::string_view var,
1138  const FEType & type,
1139  const std::set<subdomain_id_type> * const active_subdomains = nullptr);
1140 
1148  unsigned int add_variable (std::string_view var,
1149  const Order order = FIRST,
1150  const FEFamily = LAGRANGE,
1151  const std::set<subdomain_id_type> * const active_subdomains = nullptr);
1152 
1161  unsigned int add_variables (const std::vector<std::string> & vars,
1162  const FEType & type,
1163  const std::set<subdomain_id_type> * const active_subdomains = nullptr);
1164 
1172  unsigned int add_variables (const std::vector<std::string> & vars,
1173  const Order order = FIRST,
1174  const FEFamily = LAGRANGE,
1175  const std::set<subdomain_id_type> * const active_subdomains = nullptr);
1176 
1180  const Variable & variable (unsigned int var) const;
1181 
1185  const VariableGroup & variable_group (unsigned int vg) const;
1186 
1190  bool has_variable(std::string_view var) const;
1191 
1195  const std::string & variable_name(const unsigned int i) const;
1196 
1201  unsigned int variable_number (std::string_view var) const;
1202 
1207  void get_all_variable_numbers(std::vector<unsigned int> & all_variable_numbers) const;
1208 
1219  unsigned int variable_scalar_number (std::string_view var,
1220  unsigned int component) const;
1221 
1232  unsigned int variable_scalar_number (unsigned int var_num,
1233  unsigned int component) const;
1234 
1235 
1239  const FEType & variable_type (const unsigned int i) const;
1240 
1244  const FEType & variable_type (std::string_view var) const;
1245 
1250  bool identify_variable_groups () const;
1251 
1255  void identify_variable_groups (const bool);
1256 
1262  unsigned int var,
1263  FEMNormType norm_type,
1264  std::set<unsigned int> * skip_dimensions=nullptr) const;
1265 
1271  const SystemNorm & norm,
1272  std::set<unsigned int> * skip_dimensions=nullptr) const;
1273 
1277  void read_header (Xdr & io,
1278  std::string_view version,
1279  const bool read_header=true,
1280  const bool read_additional_data=true,
1281  const bool read_legacy_format=false);
1282 
1290 #ifdef LIBMESH_ENABLE_DEPRECATED
1291  void read_legacy_data (Xdr & io,
1292  const bool read_additional_data=true);
1293 #endif
1294 
1299  template <typename ValType>
1300  void read_serialized_data (Xdr & io,
1301  const bool read_additional_data=true);
1309  const bool read_additional_data=true)
1310  { read_serialized_data<Number>(io, read_additional_data); }
1311 
1317  template <typename InValType>
1318  std::size_t read_serialized_vectors (Xdr & io,
1319  const std::vector<NumericVector<Number> *> & vectors) const;
1320 
1328  std::size_t read_serialized_vectors (Xdr & io,
1329  const std::vector<NumericVector<Number> *> & vectors) const
1330  { return read_serialized_vectors<Number>(io, vectors); }
1331 
1338  template <typename InValType>
1339  void read_parallel_data (Xdr & io,
1340  const bool read_additional_data);
1341 
1351  const bool read_additional_data)
1352  { read_parallel_data<Number>(io, read_additional_data); }
1353 
1357  void write_header (Xdr & io,
1358  std::string_view version,
1359  const bool write_additional_data) const;
1360 
1365  void write_serialized_data (Xdr & io,
1366  const bool write_additional_data = true) const;
1367 
1373  std::size_t write_serialized_vectors (Xdr & io,
1374  const std::vector<const NumericVector<Number> *> & vectors) const;
1375 
1382  void write_parallel_data (Xdr & io,
1383  const bool write_additional_data) const;
1384 
1389  std::string get_info () const;
1390 
1394  void attach_init_function (void fptr(EquationSystems & es,
1395  const std::string & name));
1396 
1402  void attach_init_object (Initialization & init);
1403 
1409  const std::string & name));
1410 
1415  void attach_assemble_object (Assembly & assemble);
1416 
1421  const std::string & name));
1422 
1426  void attach_constraint_object (Constraint & constrain);
1427 
1437  bool has_constraint_object () const;
1438 
1442  Constraint& get_constraint_object ();
1443 
1448  void attach_QOI_function (void fptr(EquationSystems & es,
1449  const std::string & name,
1450  const QoISet & qoi_indices));
1451 
1456  void attach_QOI_object (QOI & qoi);
1457 
1463  void attach_QOI_derivative (void fptr(EquationSystems & es,
1464  const std::string & name,
1465  const QoISet & qoi_indices,
1466  bool include_liftfunc,
1467  bool apply_constraints));
1468 
1474  void attach_QOI_derivative_object (QOIDerivative & qoi_derivative);
1475 
1480  virtual void user_initialization ();
1481 
1486  virtual void user_assembly ();
1487 
1492  virtual void user_constrain ();
1493 
1498  virtual void user_QOI (const QoISet & qoi_indices);
1499 
1504  virtual void user_QOI_derivative (const QoISet & qoi_indices = QoISet(),
1505  bool include_liftfunc = true,
1506  bool apply_constraints = true);
1507 
1513  virtual void re_update ();
1514 
1518  virtual void restrict_vectors ();
1519 
1523  virtual void prolong_vectors ();
1524 
1527 
1548 
1553  virtual void disable_cache ();
1554 
1564 
1579 
1580 
1581  //--------------------------------------------------
1582  // The solution and solution access members
1583 
1588  Number current_solution (const dof_id_type global_dof_number) const;
1589 
1593  std::unique_ptr<NumericVector<Number>> solution;
1594 
1605  std::unique_ptr<NumericVector<Number>> current_local_solution;
1606 
1616 
1620  unsigned int n_qois() const;
1621 
1622 #ifndef LIBMESH_ENABLE_DEPRECATED // We use accessors for these now
1623 private:
1624 #endif
1625 
1631  std::vector<Number> qoi;
1632 
1639  std::vector<Number> qoi_error_estimates;
1640 #ifndef LIBMESH_ENABLE_DEPRECATED
1641 public:
1642 #endif
1643 
1647  void init_qois(unsigned int n_qois);
1648 
1649  void set_qoi(unsigned int qoi_index, Number qoi_value);
1650  Number get_qoi_value(unsigned int qoi_index) const;
1651 
1652  void set_qoi(std::vector<Number> new_qoi);
1653 
1657  std::vector<Number> get_qoi_values() const;
1658 
1659  void set_qoi_error_estimate(unsigned int qoi_index, Number qoi_error_estimate);
1660  Number get_qoi_error_estimate_value(unsigned int qoi_index) const;
1661 
1683  Number point_value(unsigned int var, const Point & p,
1684  const bool insist_on_success = true,
1685  const NumericVector<Number> * sol = nullptr) const;
1686 
1696  Number point_value(unsigned int var, const Point & p, const Elem & e,
1697  const NumericVector<Number> * sol = nullptr) const;
1698 
1705  Number point_value(unsigned int var, const Point & p, const Elem * e) const;
1706 
1713  Number point_value(unsigned int var, const Point & p, const NumericVector<Number> * sol) const;
1714 
1719  Gradient point_gradient(unsigned int var, const Point & p,
1720  const bool insist_on_success = true,
1721  const NumericVector<Number> * sol = nullptr) const;
1722 
1727  Gradient point_gradient(unsigned int var, const Point & p, const Elem & e,
1728  const NumericVector<Number> * sol = nullptr) const;
1729 
1736  Gradient point_gradient(unsigned int var, const Point & p, const Elem * e) const;
1737 
1744  Gradient point_gradient(unsigned int var, const Point & p, const NumericVector<Number> * sol) const;
1745 
1750  Tensor point_hessian(unsigned int var, const Point & p,
1751  const bool insist_on_success = true,
1752  const NumericVector<Number> * sol = nullptr) const;
1753 
1759  Tensor point_hessian(unsigned int var, const Point & p, const Elem & e,
1760  const NumericVector<Number> * sol = nullptr) const;
1761 
1768  Tensor point_hessian(unsigned int var, const Point & p, const Elem * e) const;
1769 
1776  Tensor point_hessian(unsigned int var, const Point & p, const NumericVector<Number> * sol) const;
1777 
1778 
1783  void local_dof_indices (const unsigned int var,
1784  std::set<dof_id_type> & var_indices) const;
1785 
1790  void zero_variable (NumericVector<Number> & v, unsigned int var_num) const;
1791 
1796  {
1797  return project_with_constraints;
1798  }
1799 
1800  void set_project_with_constraints(bool _project_with_constraints)
1801  {
1802  project_with_constraints = _project_with_constraints;
1803  }
1804 
1810  bool & hide_output() { return _hide_output; }
1811 
1812 #ifdef LIBMESH_HAVE_METAPHYSICL
1813 
1823  void projection_matrix (SparseMatrix<Number> & proj_mat) const;
1824 #endif // LIBMESH_HAVE_METAPHYSICL
1825 
1843  SparseMatrix<Number> & add_matrix (std::string_view mat_name,
1844  ParallelType type = PARALLEL,
1845  MatrixBuildType mat_build_type = MatrixBuildType::AUTOMATIC);
1846 
1862  template <template <typename> class>
1863  SparseMatrix<Number> & add_matrix (std::string_view mat_name, ParallelType = PARALLEL);
1864 
1878  SparseMatrix<Number> & add_matrix (std::string_view mat_name,
1879  std::unique_ptr<SparseMatrix<Number>> matrix,
1880  ParallelType type = PARALLEL);
1881 
1885  void remove_matrix(std::string_view mat_name);
1886 
1891  inline bool have_matrix (std::string_view mat_name) const { return _matrices.count(mat_name); }
1892 
1898  const SparseMatrix<Number> * request_matrix (std::string_view mat_name) const;
1899 
1905  SparseMatrix<Number> * request_matrix (std::string_view mat_name);
1906 
1911  const SparseMatrix<Number> & get_matrix (std::string_view mat_name) const;
1912 
1917  SparseMatrix<Number> & get_matrix (std::string_view mat_name);
1918 
1922  void prefer_hash_table_matrix_assembly(bool preference);
1923 
1928 
1932  [[nodiscard]] bool prefix_with_name() const { return _prefix_with_name; }
1933 
1938  std::string prefix() const { return this->name() + "_"; }
1939 
1943  virtual void create_static_condensation();
1944 
1948  bool has_static_condensation() const;
1949 
1950 protected:
1951 
1958  virtual void init_data ();
1959 
1964  virtual void add_matrices() {}
1965 
1969  virtual void init_matrices ();
1970 
1975  bool can_add_matrices() const { return !_matrices_initialized; }
1976 
1985  int is_adjoint = -1) const;
1986 
1995  void project_vector (const NumericVector<Number> &,
1997  int is_adjoint = -1) const;
1998 
1999  /*
2000  * If we have e.g. a element space constrained by spline values, we
2001  * can directly project only on the constrained basis; to get
2002  * consistent constraining values we have to solve for them.
2003  *
2004  * Constrain the new vector using the requested adjoint rather than
2005  * primal constraints if is_adjoint is non-negative.
2006  */
2008  int is_adjoint = -1) const;
2009 
2013  virtual bool condense_constrained_dofs() const { return false; }
2014 
2015 private:
2020  ParallelType type);
2021 
2027  unsigned int var,
2028  FEMNormType norm_type) const;
2029 
2039  template <typename iterator_type, typename InValType>
2041  const iterator_type begin,
2042  const iterator_type end,
2043  const InValType dummy,
2044  Xdr & io,
2045  const std::vector<NumericVector<Number> *> & vecs,
2046  const unsigned int var_to_read=libMesh::invalid_uint) const;
2047 
2056  unsigned int read_SCALAR_dofs (const unsigned int var,
2057  Xdr & io,
2058  NumericVector<Number> * vec) const;
2059 
2068  template <typename InValType>
2070  NumericVector<Number> * vec);
2071 
2081  NumericVector<Number> & vec)
2082  { return read_serialized_vector<Number>(io, &vec); }
2083 
2090  template <typename iterator_type>
2091  std::size_t write_serialized_blocked_dof_objects (const std::vector<const NumericVector<Number> *> & vecs,
2092  const dof_id_type n_objects,
2093  const iterator_type begin,
2094  const iterator_type end,
2095  Xdr & io,
2096  const unsigned int var_to_write=libMesh::invalid_uint) const;
2097 
2103  unsigned int write_SCALAR_dofs (const NumericVector<Number> & vec,
2104  const unsigned int var,
2105  Xdr & io) const;
2106 
2114  const NumericVector<Number> & vec) const;
2115 
2120  const std::string & name);
2121 
2126 
2131  const std::string & name);
2132 
2137 
2142  const std::string & name);
2143 
2148 
2153  const std::string & name,
2154  const QoISet & qoi_indices);
2155 
2160 
2165  const std::string & name,
2166  const QoISet & qoi_indices,
2167  bool include_liftfunc,
2168  bool apply_constraints);
2169 
2174 
2179  std::unique_ptr<DofMap> _dof_map;
2180 
2186 
2192 
2196  const std::string _sys_name;
2197 
2201  const unsigned int _sys_number;
2202 
2206  std::vector<Variable> _variables;
2207 
2211  std::vector<VariableGroup> _variable_groups;
2212 
2217  std::map<std::string, unsigned int, std::less<>> _variable_numbers;
2218 
2222  bool _active;
2223 
2230  std::map<std::string, std::unique_ptr<NumericVector<Number>>, std::less<>> _vectors;
2231 
2236  std::map<std::string, bool, std::less<>> _vector_projections;
2237 
2242  std::map<std::string, int, std::less<>> _vector_is_adjoint;
2243 
2247  std::map<std::string, std::unique_ptr<SparseMatrix<Number>>, std::less<>> _matrices;
2248 
2252  std::map<std::string, ParallelType, std::less<>> _matrix_types;
2253 
2258 
2265 
2271 
2277 
2283 
2290 
2301  std::vector<unsigned int> _written_var_indices;
2302 
2309 
2315 
2320 
2325 
2330 
2335 };
2336 
2337 
2338 
2339 // ------------------------------------------------------------
2340 // System inline methods
2341 inline
2342 const std::string & System::name() const
2343 {
2344  return _sys_name;
2345 }
2346 
2347 
2348 
2349 inline
2350 unsigned int System::number() const
2351 {
2352  return _sys_number;
2353 }
2354 
2355 
2356 
2357 inline
2359 {
2360  return _mesh;
2361 }
2362 
2363 
2364 
2365 inline
2367 {
2368  return _mesh;
2369 }
2370 
2371 
2372 
2373 inline
2375 {
2376  return *_dof_map;
2377 }
2378 
2379 
2380 
2381 inline
2383 {
2384  return *_dof_map;
2385 }
2386 
2387 
2388 
2389 inline
2390 bool System::active() const
2391 {
2392  return _active;
2393 }
2394 
2395 
2396 
2397 inline
2399 {
2400  _active = true;
2401 }
2402 
2403 
2404 
2405 inline
2407 {
2408  _active = false;
2409 }
2410 
2411 
2412 
2413 inline
2415 {
2416  return _is_initialized;
2417 }
2418 
2419 
2420 
2421 inline
2423 {
2424  _basic_system_only = true;
2425 }
2426 
2427 
2428 
2429 inline
2430 unsigned int System::n_vars() const
2431 {
2432  return cast_int<unsigned int>(_variables.size());
2433 }
2434 
2435 
2436 
2437 inline
2438 unsigned int System::n_variable_groups() const
2439 {
2440  return cast_int<unsigned int>(_variable_groups.size());
2441 }
2442 
2443 
2444 
2445 inline
2446 unsigned int System::n_components() const
2447 {
2448  if (_variables.empty())
2449  return 0;
2450 
2451  const Variable & last = _variables.back();
2452  return last.first_scalar_number() + last.n_components(this->get_mesh());
2453 }
2454 
2455 
2456 
2457 inline
2458 const Variable & System::variable (const unsigned int i) const
2459 {
2460  libmesh_assert_less (i, _variables.size());
2461 
2462  return _variables[i];
2463 }
2464 
2465 
2466 
2467 inline
2468 const VariableGroup & System::variable_group (const unsigned int vg) const
2469 {
2470  libmesh_assert_less (vg, _variable_groups.size());
2471 
2472  return _variable_groups[vg];
2473 }
2474 
2475 
2476 
2477 inline
2478 const std::string & System::variable_name (const unsigned int i) const
2479 {
2480  libmesh_assert_less (i, _variables.size());
2481 
2482  return _variables[i].name();
2483 }
2484 
2485 
2486 
2487 inline
2488 unsigned int
2489 System::variable_scalar_number (std::string_view var,
2490  unsigned int component) const
2491 {
2492  return variable_scalar_number(this->variable_number(var), component);
2493 }
2494 
2495 
2496 
2497 inline
2498 unsigned int
2499 System::variable_scalar_number (unsigned int var_num,
2500  unsigned int component) const
2501 {
2502  return _variables[var_num].first_scalar_number() + component;
2503 }
2504 
2505 
2506 
2507 inline
2508 const FEType & System::variable_type (const unsigned int i) const
2509 {
2510  libmesh_assert_less (i, _variables.size());
2511 
2512  return _variables[i].type();
2513 }
2514 
2515 
2516 
2517 inline
2518 const FEType & System::variable_type (std::string_view var) const
2519 {
2520  return _variables[this->variable_number(var)].type();
2521 }
2522 
2523 
2524 
2525 inline
2527 {
2529 }
2530 
2531 
2532 
2533 inline
2535 {
2537 }
2538 
2539 
2540 
2541 inline
2543 {
2544  return this->n_dofs() - this->n_constrained_dofs();
2545 }
2546 
2547 
2548 
2549 inline
2550 bool System::have_vector (std::string_view vec_name) const
2551 {
2552  return (_vectors.count(vec_name));
2553 }
2554 
2555 
2556 
2557 inline
2558 unsigned int System::n_vectors () const
2559 {
2560  return cast_int<unsigned int>(_vectors.size());
2561 }
2562 
2563 inline
2565 {
2566  return _vectors.begin();
2567 }
2568 
2569 inline
2571 {
2572  return _vectors.begin();
2573 }
2574 
2575 inline
2577 {
2578  return _vectors.end();
2579 }
2580 
2581 inline
2583 {
2584  return _vectors.end();
2585 }
2586 
2587 inline
2589 {
2590  return _matrices.begin();
2591 }
2592 
2593 inline
2595 {
2596  return _matrices.begin();
2597 }
2598 
2599 inline
2601 {
2602  return _matrices.end();
2603 }
2604 
2605 inline
2607 {
2608  return _matrices.end();
2609 }
2610 
2611 inline
2613 {
2614  libmesh_not_implemented();
2615 }
2616 
2617 inline
2619 
2620 inline
2621 unsigned int System::n_qois() const
2622 {
2623 #ifndef LIBMESH_ENABLE_DEPRECATED
2624  libmesh_assert_equal_to(this->qoi.size(), this->qoi_error_estimates.size());
2625 #endif
2626 
2627  return cast_int<unsigned int>(this->qoi.size());
2628 }
2629 
2630 inline
2631 std::pair<unsigned int, Real>
2633 {
2634  libmesh_not_implemented();
2635 }
2636 
2637 inline
2638 std::pair<unsigned int, Real>
2640  const ParameterVector &)
2641 {
2642  libmesh_not_implemented();
2643 }
2644 
2645 inline
2646 std::pair<unsigned int, Real>
2648 {
2649  libmesh_not_implemented();
2650 }
2651 
2652 inline
2653 std::pair<unsigned int, Real>
2655  const ParameterVector &,
2656  const QoISet &)
2657 {
2658  libmesh_not_implemented();
2659 }
2660 
2661 inline
2662 void
2664  const ParameterVector &,
2665  SensitivityData &)
2666 {
2667  libmesh_not_implemented();
2668 }
2669 
2670 inline
2671 void
2673  const ParameterVector &,
2674  SensitivityData &)
2675 {
2676  libmesh_not_implemented();
2677 }
2678 
2679 inline
2680 void
2682  const ParameterVector &,
2683  SensitivityData &)
2684 {
2685  libmesh_not_implemented();
2686 }
2687 
2688 inline
2689 void
2691  const ParameterVector &,
2692  const ParameterVector &,
2693  SensitivityData &)
2694 {
2695  libmesh_not_implemented();
2696 }
2697 
2698 inline
2699 unsigned int System::n_matrices () const
2700 {
2701  return cast_int<unsigned int>(_matrices.size());
2702 }
2703 
2704 template <template <typename> class MatrixType>
2705 inline
2707 System::add_matrix (std::string_view mat_name,
2708  const ParallelType type)
2709 {
2710  // Return the matrix if it is already there.
2711  auto it = this->_matrices.find(mat_name);
2712  if (it != this->_matrices.end())
2713  return *it->second;
2714 
2715  // Otherwise build the matrix to return.
2716  auto pr = _matrices.emplace(mat_name, std::make_unique<MatrixType<Number>>(this->comm()));
2717  _matrix_types.emplace(mat_name, type);
2718 
2719  SparseMatrix<Number> & mat = *(pr.first->second);
2720 
2721  // Initialize it first if we've already initialized the others.
2722  this->late_matrix_init(mat, type);
2723 
2724  return mat;
2725 }
2726 
2727 inline void
2729 {
2730  libmesh_error_msg_if(
2732  "System::prefer_hash_table_matrix_assembly() should be called before matrices are initialized");
2734 }
2735 
2736 } // namespace libMesh
2737 
2738 #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:1160
matrices_iterator matrices_begin()
Beginning of matrices container.
Definition: system.h:2588
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:1328
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 variable var to the list of variables for this system.
Definition: system.C:1471
std::map< std::string, std::unique_ptr< NumericVector< Number > >, std::less<> >::iterator vectors_iterator
Vector iterator typedefs.
Definition: system.h:757
vectors_iterator vectors_end()
End of vectors container.
Definition: system.h:2576
bool is_initialized() const
Definition: system.h:2414
Real time
For time-dependent problems, this is the time t at the beginning of the current timestep.
Definition: system.h:1615
bool can_add_matrices() const
Definition: system.h:1975
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:1627
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:2489
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:176
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:1350
virtual void create_static_condensation()
Request that static condensation be performed for this system.
Definition: system.C:2866
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:745
Abstract base class to be used for system initialization.
Definition: system.h:131
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.h:2458
Assembly * _assemble_system_object
Object that assembles the system.
Definition: system.h:2136
Gradient point_gradient(unsigned int var, const Point &p, const bool insist_on_success=true, const NumericVector< Number > *sol=nullptr) const
Definition: system.C:2550
bool _basic_system_only
Holds true if the components of more advanced system types (e.g.
Definition: system.h:2270
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:323
bool _is_initialized
true when additional vectors and variables do not require immediate initialization, false otherwise.
Definition: system.h:2276
void(* _constrain_system_function)(EquationSystems &es, const std::string &name)
Function to impose constraints.
Definition: system.h:2141
void set_adjoint_already_solved(bool setting)
Setter for the adjoint_already_solved boolean.
Definition: system.h:415
This class provides the ability to map between arbitrary, user-defined strings and several data types...
Definition: parameters.h:67
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:1233
virtual bool condense_constrained_dofs() const
Whether this object should condense out constrained degrees of freedom.
Definition: system.h:2013
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:2672
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:2612
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:2386
virtual void reinit()
Reinitializes degrees of freedom and other required data on the current mesh.
Definition: system.C:454
unsigned int n_qois() const
Number of currently active quantities of interest.
Definition: system.h:2621
unsigned int n_components() const
Definition: system.h:2446
virtual void disable_cache()
Avoids use of any cached data that might affect any solve result.
Definition: system.h:2618
bool active() const
Definition: system.h:2390
int extra_quadrature_order
A member int that can be employed to indicate increased or reduced quadrature order.
Definition: system.h:1578
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:253
NumericVector< Number > & get_sensitivity_solution(unsigned int i=0)
Definition: system.C:1192
void read_serialized_data(Xdr &io, const bool read_additional_data=true)
Non-templated version for backward compatibility.
Definition: system.h:1308
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:2201
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:588
NumericVector< Number > & get_sensitivity_rhs(unsigned int i=0)
Definition: system.C:1337
int vector_is_adjoint(std::string_view vec_name) const
Definition: system.C:1173
virtual void assemble()=0
Assembly function.
Constraint * _constrain_system_object
Object that constrains the system.
Definition: system.h:2147
const EquationSystems & get_equation_systems() const
Definition: system.h:721
unsigned int n_variable_groups() const
Definition: system.h:2438
virtual void assemble()
Prepares matrix and _dof_map for matrix assembly.
Definition: system.C:566
void projection_matrix(SparseMatrix< Number > &proj_mat) const
This method creates a projection matrix which corresponds to the operation of project_vector between ...
virtual void init_data()
Initializes the data for the system.
Definition: system.C:208
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:2371
std::map< std::string, std::unique_ptr< SparseMatrix< Number > >, std::less<> >::iterator matrices_iterator
Matrix iterator typedefs.
Definition: system.h:783
Number point_value(unsigned int var, const Point &p, const bool insist_on_success=true, const NumericVector< Number > *sol=nullptr) const
Definition: system.C:2421
std::unique_ptr< DofMap > _dof_map
Data structure describing the relationship between nodes, variables, etc...
Definition: system.h:2179
virtual void user_initialization()
Calls user&#39;s attached initialization function, or is overridden by the user in derived classes...
Definition: system.C:2297
std::map< std::string, std::unique_ptr< NumericVector< Number > >, std::less<> > _vectors
Some systems need an arbitrary number of vectors.
Definition: system.h:2230
bool _active
Flag stating if the system is active or not.
Definition: system.h:2222
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:768
std::vector< Variable > _variables
The Variable in this System.
Definition: system.h:2206
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:1617
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:1327
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:2871
The libMesh namespace provides an interface to certain functionality in the library.
vectors_iterator vectors_begin()
Beginning of vectors container.
Definition: system.h:2564
std::map< std::string, std::unique_ptr< SparseMatrix< Number > >, std::less<> >::const_iterator const_matrices_iterator
Definition: system.h:784
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:2283
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:2663
dof_id_type n_local_dofs() const
Definition: system.C:158
Abstract base class to be used for system assembly.
Definition: system.h:155
NumericVector< Number > & add_weighted_sensitivity_solution()
Definition: system.C:1212
void(* _qoi_evaluate_function)(EquationSystems &es, const std::string &name, const QoISet &qoi_indices)
Function to evaluate quantity of interest.
Definition: system.h:2152
const SparseMatrix< Number > * request_matrix(std::string_view mat_name) const
Definition: system.C:1100
System sys_type
The type of system.
Definition: system.h:248
Parameters parameters
Parameters for the system. If a parameter is not provided, it should be retrieved from the EquationSy...
Definition: system.h:1526
void init()
Initializes degrees of freedom on the current mesh.
Definition: system.C:197
const MeshBase & get_mesh() const
Definition: system.h:2358
NumericVector< Number > & get_weighted_sensitivity_solution()
Definition: system.C:1219
bool adjoint_already_solved
Has the adjoint problem already been solved? If the user sets adjoint_already_solved to true...
Definition: system.h:2308
dof_id_type n_dofs() const
Definition: system.C:121
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:444
Number current_solution(const dof_id_type global_dof_number) const
Definition: system.C:165
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:2339
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:80
unsigned int variable_number(std::string_view var) const
Definition: system.C:1609
std::map< std::string, std::unique_ptr< SparseMatrix< Number > >, std::less<> > _matrices
Some systems need an arbitrary number of matrices.
Definition: system.h:2247
bool have_matrix(std::string_view mat_name) const
Definition: system.h:1891
QOIDerivative * _qoi_evaluate_derivative_object
Object to compute derivatives of quantities of interest.
Definition: system.h:2173
NumericVector< Number > & add_weighted_sensitivity_adjoint_solution(unsigned int i=0)
Definition: system.C:1265
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:602
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:2681
void attach_constraint_object(Constraint &constrain)
Register a user object for imposing constraints.
Definition: system.C:2209
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:2147
void set_basic_system_only()
Sets the system to be "basic only": i.e.
Definition: system.h:2422
unsigned int first_scalar_number() const
Definition: variable.h:138
bool has_variable(std::string_view var) const
Definition: system.C:1602
unsigned int number() const
Definition: system.h:2350
void remove_vector(std::string_view vec_name)
Removes the additional vector vec_name from this system.
Definition: system.C:873
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:2242
Constraint & get_constraint_object()
Return the user object for imposing constraints.
Definition: system.C:2226
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:2690
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:1631
void deactivate()
Deactivates the system.
Definition: system.h:2406
void remove_matrix(std::string_view mat_name)
Removes the additional matrix mat_name from this system.
Definition: system.C:1089
unsigned int n_components() const
Definition: variable.C:23
std::vector< VariableGroup > _variable_groups
The VariableGroup in this System.
Definition: system.h:2211
std::string prefix() const
Definition: system.h:1938
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:1563
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:2558
Manages consistently variables, degrees of freedom, and coefficient vectors.
Definition: system.h:96
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:1668
System & operator=(const System &)=delete
bool & hide_output()
Definition: system.h:1810
bool _prefer_hash_table_matrix_assembly
Whether to use hash table matrix assembly if the matrix sub-classes support it.
Definition: system.h:2324
virtual void add_matrices()
Insertion point for adding matrices in derived classes before init_matrices() is called.
Definition: system.h:1964
bool has_constraint_object() const
Definition: system.C:2221
std::string get_info() const
Definition: system.C:2040
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:1593
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:2266
Real calculate_norm(const NumericVector< Number > &v, unsigned int var, FEMNormType norm_type, std::set< unsigned int > *skip_dimensions=nullptr) const
Definition: system.C:1724
bool project_with_constraints
Do we want to apply constraints while projecting vectors ?
Definition: system.h:2319
bool have_vector(std::string_view vec_name) const
Definition: system.h:2550
QOI * _qoi_evaluate_object
Object to compute quantities of interest.
Definition: system.h:2159
virtual std::pair< unsigned int, Real > sensitivity_solve(const ParameterVector &parameters)
Solves the sensitivity system, for the provided parameters.
Definition: system.h:2632
Initialization * _init_system_object
Object that initializes the system.
Definition: system.h:2125
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:2647
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:2234
bool _hide_output
Are we allowed to write this system to file? If _hide_output is true, then EquationSystems::write wil...
Definition: system.h:2314
unsigned int _additional_data_written
This flag is used only when reading in a system from file.
Definition: system.h:2289
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:1357
const std::string & variable_name(const unsigned int i) const
Definition: system.h:2478
void(* _init_system_function)(EquationSystems &es, const std::string &name)
Function that initializes the system.
Definition: system.h:2119
dof_id_type n_active_dofs() const
Definition: system.h:2542
std::map< std::string, ParallelType, std::less<> > _matrix_types
Holds the types of the matrices.
Definition: system.h:2252
virtual void restrict_vectors()
Restrict vectors after the mesh has coarsened.
Definition: system.C:386
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:2161
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:2699
This class implements reference counting.
void set_project_with_constraints(bool _project_with_constraints)
Definition: system.h:1800
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:1639
void activate()
Activates the system.
Definition: system.h:2398
NumericVector< Number > & add_adjoint_rhs(unsigned int i=0)
Definition: system.C:1297
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:557
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:2353
virtual void reinit_constraints()
Reinitializes the constraints for this system.
Definition: system.C:495
bool identify_variable_groups() const
Definition: system.h:2526
bool is_adjoint_already_solved() const
Accessor for the adjoint_already_solved boolean.
Definition: system.h:409
virtual void solve()
Solves the system.
Definition: system.h:347
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:301
const NumericVector< Number > * request_vector(std::string_view vec_name) const
Definition: system.C:891
EquationSystems & get_equation_systems()
Definition: system.h:726
void attach_assemble_object(Assembly &assemble)
Register a user object to use in assembling the system matrix and RHS.
Definition: system.C:2178
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:2264
EquationSystems & _equation_systems
Constant reference to the EquationSystems object used for the simulation.
Definition: system.h:2185
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:508
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:983
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:2252
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:2728
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:2311
virtual ~QOIDerivative()=default
Destructor.
virtual void update()
Update the local values to reflect the solution on neighboring processors.
Definition: system.C:510
const FEType & variable_type(const unsigned int i) const
Definition: system.h:2508
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:1138
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:537
bool _identify_variable_groups
true when VariableGroup structures should be automatically identified, false otherwise.
Definition: system.h:2282
void set_qoi_error_estimate(unsigned int qoi_index, Number qoi_error_estimate)
Definition: system.C:2406
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:2639
bool _matrices_initialized
false when additional matrices being added require initialization, true otherwise.
Definition: system.h:2257
bool _require_sparsity_pattern
Whether any of our matrices require an initial sparsity pattern computation in order to determine pre...
Definition: system.h:2329
const std::string _sys_name
A name associated with this system.
Definition: system.h:2196
Tensor point_hessian(unsigned int var, const Point &p, const bool insist_on_success=true, const NumericVector< Number > *sol=nullptr) const
Definition: system.C:2694
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:838
std::map< std::string, unsigned int, std::less<> > _variable_numbers
The variable numbers corresponding to user-specified names, useful for name-based lookups...
Definition: system.h:2217
static const bool value
Definition: xdr_io.C:54
Gradient gptr(const Point &p, const Parameters &, const std::string &libmesh_dbg_var(sys_name), const std::string &unknown_name)
Definition: projection.C:95
NumericVector< Number > & get_adjoint_solution(unsigned int i=0)
Definition: system.C:1245
virtual void re_update()
Re-update the local values when the mesh has changed.
Definition: system.C:533
Abstract base class to be used for system constraints.
Definition: system.h:179
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:1605
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:2654
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:618
void set_qoi(unsigned int qoi_index, Number qoi_value)
Definition: system.C:2378
dof_id_type n_local_constrained_dofs() const
Definition: system.C:143
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:1795
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:2342
void attach_constraint_function(void fptr(EquationSystems &es, const std::string &name))
Register a user function for imposing constraints.
Definition: system.C:2192
Gradient(* GradientFunctionPointer)(const Point &p, const Parameters &parameters, const std::string &sys_name, const std::string &unknown_name)
Definition: system.h:541
virtual void user_constrain()
Calls user&#39;s attached constraint function, or is overridden by the user in derived classes...
Definition: system.C:2325
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:1705
Number get_qoi_error_estimate_value(unsigned int qoi_index) const
Definition: system.C:2413
virtual void assemble_qoi(const QoISet &qoi_indices=QoISet())
Calls user qoi function.
Definition: system.C:577
NumericVector< Number > & add_sensitivity_solution(unsigned int i=0)
Definition: system.C:1182
FEFamily
defines an enum for finite element families.
unsigned int n_vars() const
Definition: system.h:2430
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:2130
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:1927
virtual ~System()
Definition: system.C:114
numeric_index_type read_serialized_vector(Xdr &io, NumericVector< Number > &vec)
Non-templated version for backward compatibility.
Definition: system.h:2080
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:1547
std::map< std::string, std::unique_ptr< NumericVector< Number > >, std::less<> >::const_iterator const_vectors_iterator
Definition: system.h:758
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:1148
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:1010
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:2374
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:2334
void late_matrix_init(SparseMatrix< Number > &mat, ParallelType type)
Helper function to keep DofMap forward declarable in system.h.
Definition: system.C:1076
const SparseMatrix< Number > & get_matrix(std::string_view mat_name) const
Definition: system.C:1124
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:2191
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:2600
const VariableGroup & variable_group(unsigned int vg) const
Return a constant reference to VariableGroup vg.
Definition: system.h:2468
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:2130
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:2236
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:203
const NumericVector< Number > & get_vector(std::string_view vec_name) const
Definition: system.C:943
NumericVector< Number > & get_weighted_sensitivity_adjoint_solution(unsigned int i=0)
Definition: system.C:1277
This class defines a tensor in LIBMESH_DIM dimensional Real or Complex space.
dof_id_type n_constrained_dofs() const
Definition: system.C:128
std::vector< unsigned int > _written_var_indices
This vector is used only when reading in a system from file.
Definition: system.h:2301
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:2393
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:2164
ParallelType
Defines an enum for parallel data structure types.
Abstract base class to be used for derivatives of quantities of interest.
Definition: system.h:227
NumericVector< Number > & get_adjoint_rhs(unsigned int i=0)
Definition: system.C:1307
bool prefix_with_name() const
Definition: system.h:1932
dof_id_type write_serialized_vector(Xdr &io, const NumericVector< Number > &vec) const
Writes a vector for this System.
Definition: system_io.C:2118