libMesh
Loading...
Searching...
No Matches
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
54namespace libMesh
55{
56
57// Forward Declarations
58class System;
59class EquationSystems;
60class MeshBase;
61class Xdr;
62class DofMap;
63template <typename Output> class FunctionBase;
64class ParameterVector;
65class Point;
66class SensitivityData;
67class Matrix;
68template <typename T> class NumericVector;
69template <typename T> class SparseMatrix;
70template <typename T> class VectorValue;
71typedef VectorValue<Number> NumberVectorValue;
73class SystemSubset;
74class FEType;
75class SystemNorm;
76enum FEMNormType : int;
77class Variable;
78class VariableGroup;
79
98class System : public ReferenceCountedObject<System>,
99 public ParallelObject
100{
101public:
102
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
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
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());
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,
440 SensitivityData & sensitivities);
441
447 virtual void adjoint_qoi_parameter_sensitivity (const QoISet & qoi_indices,
449 SensitivityData & sensitivities);
450
456 virtual void forward_qoi_parameter_sensitivity (const QoISet & qoi_indices,
458 SensitivityData & sensitivities);
459
470 virtual void qoi_parameter_hessian(const QoISet & qoi_indices,
472 SensitivityData & hessian);
473
486 virtual void qoi_parameter_hessian_vector_product(const QoISet & qoi_indices,
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);
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
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
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
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
1016
1022
1027 const NumericVector<Number> & get_sensitivity_solution(unsigned int i=0) const;
1028
1036
1043
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
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
1511 const std::string & name,
1512 const QoISet & qoi_indices));
1513
1518 void attach_QOI_object (QOI & qoi);
1519
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
1684public:
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
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
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,
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
2003protected:
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
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
2061private:
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
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
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
2384inline
2385const std::string & System::name() const
2386{
2387 return _sys_name;
2388}
2389
2390
2391
2392inline
2393unsigned int System::number() const
2394{
2395 return _sys_number;
2396}
2397
2398
2399
2400inline
2402{
2403 return _mesh;
2404}
2405
2406
2407
2408inline
2410{
2411 return _mesh;
2412}
2413
2414
2415
2416inline
2418{
2419 return *_dof_map;
2420}
2421
2422
2423
2424inline
2426{
2427 return *_dof_map;
2428}
2429
2430
2431
2432inline
2433bool System::active() const
2434{
2435 return _active;
2436}
2437
2438
2439
2440inline
2442{
2443 _active = true;
2444}
2445
2446
2447
2448inline
2450{
2451 _active = false;
2452}
2453
2454
2455
2456inline
2458{
2459 return _is_initialized;
2460}
2461
2462
2463
2464inline
2466{
2467 _basic_system_only = true;
2468}
2469
2470
2471
2472inline
2473unsigned int
2475 unsigned int component) const
2476{
2477 return variable_scalar_number(this->variable_number(var), component);
2478}
2479
2480
2481
2482inline
2484{
2485 return this->n_dofs() - this->n_constrained_dofs();
2486}
2487
2488
2489
2490inline
2491bool System::have_vector (std::string_view vec_name) const
2492{
2493 return (_vectors.count(vec_name));
2494}
2495
2496
2497
2498inline
2499unsigned int System::n_vectors () const
2500{
2501 return cast_int<unsigned int>(_vectors.size());
2502}
2503
2504inline
2506{
2507 return _vectors.begin();
2508}
2509
2510inline
2512{
2513 return _vectors.begin();
2514}
2515
2516inline
2521
2522inline
2524{
2525 return _vectors.end();
2526}
2527
2528inline
2533
2534inline
2536{
2537 return _matrices.begin();
2538}
2539
2540inline
2545
2546inline
2551
2552inline
2554{
2555 libmesh_not_implemented();
2556}
2557
2558inline
2560
2561inline
2562unsigned 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
2569inline
2570std::pair<unsigned int, Real>
2572{
2573 libmesh_not_implemented();
2574}
2575
2576inline
2577std::pair<unsigned int, Real>
2579 const ParameterVector &)
2580{
2581 libmesh_not_implemented();
2582}
2583
2584inline
2585std::pair<unsigned int, Real>
2587{
2588 libmesh_not_implemented();
2589}
2590
2591inline
2592std::pair<unsigned int, Real>
2594 const ParameterVector &,
2595 const QoISet &)
2596{
2597 libmesh_not_implemented();
2598}
2599
2600inline
2601void
2603 const ParameterVector &,
2605{
2606 libmesh_not_implemented();
2607}
2608
2609inline
2610void
2612 const ParameterVector &,
2614{
2615 libmesh_not_implemented();
2616}
2617
2618inline
2619void
2621 const ParameterVector &,
2623{
2624 libmesh_not_implemented();
2625}
2626
2627inline
2628void
2630 const ParameterVector &,
2631 const ParameterVector &,
2633{
2634 libmesh_not_implemented();
2635}
2636
2637inline
2638unsigned int System::n_matrices () const
2639{
2640 return cast_int<unsigned int>(_matrices.size());
2641}
2642
2643template <template <typename> class MatrixType>
2644inline
2646System::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
2666inline 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 ErrorVector unsigned int
This class handles the numbering of degrees of freedom on a mesh.
Definition dof_map.h:181
This is the base class from which all geometric element types are derived.
Definition elem.h:96
This is the EquationSystems class.
FEMFunctionBase is a base class from which users can derive in order to define "function-like" object...
class FEType hides (possibly multiple) FEFamily and approximation orders, thereby enabling specialize...
Definition fe_type.h:197
Base class for functors that can be evaluated at a point and (optionally) time.
This is the MeshBase class.
Definition mesh_base.h:81
Provides a uniform interface to vector storage schemes for different linear algebra libraries.
An object whose state is distributed along a set of processors.
const Parallel::Communicator & comm() const
Data structure for specifying which Parameters should be independent variables in a parameter sensiti...
This class provides the ability to map between arbitrary, user-defined strings and several data types...
Definition parameters.h:75
A Point defines a location in LIBMESH_DIM dimensional Real space.
Definition point.h:40
Data structure for specifying which Quantities of Interest should be calculated in an adjoint or a pa...
Definition qoi_set.h:46
This class implements reference counting.
static unsigned int n_objects()
Prints the number of outstanding (created, but not yet destroyed) objects.
Data structure for holding completed parameter sensitivity calculations.
Generic sparse matrix.
This class defines a norm/seminorm to be applied to a NumericVector which contains coefficients in a ...
Definition system_norm.h:50
This is a base class for classes which represent subsets of the dofs of a System.
Abstract base class to be used for system assembly.
Definition system.h:158
virtual void assemble()=0
Assembly function.
virtual ~Assembly()=default
Destructor.
Abstract base class to be used for system constraints.
Definition system.h:182
virtual ~Constraint()=default
Destructor.
virtual void constrain()=0
Constraint function.
Abstract base class to be used for system initialization.
Definition system.h:134
virtual ~Initialization()=default
Destructor.
virtual void initialize()=0
Initialization function.
Abstract base class to be used for derivatives of quantities of interest.
Definition system.h:230
virtual void qoi_derivative(const QoISet &qoi_indices, bool include_liftfunc, bool apply_constraints)=0
Quantity of interest derivative function.
virtual ~QOIDerivative()=default
Destructor.
Abstract base class to be used for quantities of interest.
Definition system.h:206
virtual void qoi(const QoISet &qoi_indices)=0
Quantity of interest function.
virtual ~QOI()=default
Destructor.
Manages consistently variables, degrees of freedom, and coefficient vectors.
Definition system.h:100
unsigned int n_vectors() const
Definition system.h:2499
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
virtual void user_QOI_derivative(const QoISet &qoi_indices=QoISet(), bool include_liftfunc=true, bool apply_constraints=true)
Calls user's attached quantity of interest derivative function, or is overridden by the user in deriv...
Definition system.C:2151
Constraint & get_constraint_object()
Return the user object for imposing constraints.
Definition system.C:2024
std::map< std::string, std::unique_ptr< SparseMatrix< Number > >, std::less<> >::iterator matrices_iterator
Matrix iterator typedefs.
Definition system.h:829
bool can_add_matrices() const
Definition system.h:2028
int extra_quadrature_order
A member int that can be employed to indicate increased or reduced quadrature order.
Definition system.h:1640
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,...
Definition system.h:2272
bool identify_variable_groups() const
Definition system.C:2684
bool _is_initialized
true when additional vectors and variables do not require immediate initialization,...
Definition system.h:2306
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
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
void(* _init_system_function)(EquationSystems &es, const std::string &name)
Function that initializes the system.
Definition system.h:2165
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
void(* _constrain_system_function)(EquationSystems &es, const std::string &name)
Function to impose constraints.
Definition system.h:2187
const std::string & name() const
Definition system.h:2385
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:2015
void attach_assemble_object(Assembly &assemble)
Register a user object to use in assembling the system matrix and RHS.
Definition system.C:1976
virtual bool compare(const System &other_system, const Real threshold, const bool verbose) const
Definition system.C:606
void attach_constraint_function(void fptr(EquationSystems &es, const std::string &name))
Register a user function for imposing constraints.
Definition system.C:1990
void solve_for_unconstrained_dofs(NumericVector< Number > &, int is_adjoint=-1) const
std::map< std::string, std::unique_ptr< SparseMatrix< Number > >, std::less<> >::const_iterator const_matrices_iterator
Definition system.h:830
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
NumericVector< Number > & add_weighted_sensitivity_adjoint_solution(unsigned int i=0)
Definition system.C:1252
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
void read_parallel_data(Xdr &io, const bool read_additional_data)
Non-templated version for backward compatibility.
Definition system.h:1412
virtual void reinit()
Reinitializes degrees of freedom and other required data on the current mesh.
Definition system.C:442
virtual void assemble_residual_derivatives(const ParameterVector &parameters)
Calls residual parameter derivative function.
Definition system.h:2553
const unsigned int _sys_number
The number associated with this system.
Definition system.h:2247
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.
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 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.
Number current_solution(const dof_id_type global_dof_number) const
Definition system.C:162
const SparseMatrix< Number > & get_matrix(std::string_view mat_name) const
Definition system.C:1111
virtual void qoi_parameter_hessian_vector_product(const QoISet &qoi_indices, const ParameterVector &parameters, const ParameterVector &vector, SensitivityData &product)
For each of the system's quantities of interest q in qoi[qoi_indices], and for a vector of parameters...
Definition system.h:2629
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
Assembly * _assemble_system_object
Object that assembles the system.
Definition system.h:2182
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
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...
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:1626
const Variable & variable(unsigned int var) const
Return a constant reference to Variable var.
Definition system.C:2704
vectors_iterator vectors_begin()
Beginning of vectors container.
Definition system.h:2505
std::map< std::string, std::unique_ptr< NumericVector< Number > >, std::less<> >::iterator vectors_iterator
Vector iterator typedefs.
Definition system.h:803
void set_qoi(unsigned int qoi_index, Number qoi_value)
Definition system.C:2176
void activate()
Activates the system.
Definition system.h:2441
void write_parallel_data(Xdr &io, const bool write_additional_data) const
Writes additional data, namely vectors, for this System.
Definition system_io.C:1318
dof_id_type write_serialized_vector(Xdr &io, const NumericVector< Number > &vec) const
Writes a vector for this System.
Definition system_io.C:1968
void remove_matrix(std::string_view mat_name)
Removes the additional matrix mat_name from this system.
Definition system.C:1076
Constraint * _constrain_system_object
Object that constrains the system.
Definition system.h:2193
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 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
std::map< std::string, std::unique_ptr< NumericVector< Number > >, std::less<> > _vectors
Some systems need an arbitrary number of vectors.
Definition system.h:2260
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 prefix_with_name() const
Definition system.h:1974
virtual void user_QOI(const QoISet &qoi_indices)
Calls user's attached quantity of interest function, or is overridden by the user in derived classes.
Definition system.C:2137
virtual ~System()
Definition system.C:111
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
std::string get_info() const
Definition system.C:1827
virtual void disable_cache()
Avoids use of any cached data that might affect any solve result.
Definition system.h:2559
bool is_initialized() const
Definition system.h:2457
void remove_vector(std::string_view vec_name)
Removes the additional vector vec_name from this system.
Definition system.C:861
NumericVector< Number > & get_weighted_sensitivity_adjoint_solution(unsigned int i=0)
Definition system.C:1264
virtual void create_static_condensation()
Request that static condensation be performed for this system.
Definition system.C:2664
sys_type & system()
Definition system.h:255
numeric_index_type read_serialized_vector(Xdr &io, NumericVector< Number > *vec)
Reads a vector for this System.
Definition system_io.C:986
virtual void qoi_parameter_sensitivity(const QoISet &qoi_indices, const ParameterVector &parameters, SensitivityData &sensitivities)
Solves for the derivative of each of the system's quantities of interest q in qoi[qoi_indices] with r...
Definition system.C:590
dof_id_type n_dofs() const
Definition system.C:118
std::vector< unsigned int > _written_var_indices
This vector is used only when reading in a system from file.
Definition system.h:2325
const std::string & vector_name(const unsigned int vec_num) const
Definition system.C:971
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
matrices_iterator matrices_end()
End of matrices container.
Definition system.h:2541
const FEType & variable_type(const unsigned int i) const
Definition system.C:2721
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
virtual void prolong_vectors()
Prolong vectors after the mesh has refined.
Definition system.C:432
matrices_iterator matrices_begin()
Beginning of matrices container.
Definition system.h:2529
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
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 void user_initialization()
Calls user's attached initialization function, or is overridden by the user in derived classes.
Definition system.C:2095
bool & hide_output()
Definition system.h:1852
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:939
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::map< std::string, std::unique_ptr< NumericVector< Number > >, std::less<> >::const_iterator const_vectors_iterator
Definition system.h:804
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
NumericVector< Number > & add_sensitivity_rhs(unsigned int i=0)
Definition system.C:1314
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:1117
QOI * _qoi_evaluate_object
Object to compute quantities of interest.
Definition system.h:2205
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
bool has_constraint_object() const
Definition system.C:2019
bool get_project_with_constraints()
Setter and getter functions for project_with_constraints boolean.
Definition system.h:1837
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
int vector_is_adjoint(std::string_view vec_name) const
Definition system.C:1160
bool _basic_system_only
Holds true if the components of more advanced system types (e.g.
Definition system.h:2300
MeshBase & _mesh
Constant reference to the mesh data structure used for the simulation.
Definition system.h:2237
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
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
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
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
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
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
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 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
const NumericVector< Number > * request_vector(std::string_view vec_name) const
Definition system.C:879
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
System & operator=(const System &)=delete
virtual void restrict_vectors()
Restrict vectors after the mesh has coarsened.
Definition system.C:374
virtual void user_assembly()
Calls user's attached assembly function, or is overridden by the user in derived classes.
Definition system.C:2109
unsigned int n_matrices() const
Definition system.h:2638
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)),...
Definition system.h:2593
virtual void assemble()
Prepares matrix and _dof_map for matrix assembly.
Definition system.C:554
void(* _qoi_evaluate_function)(EquationSystems &es, const std::string &name, const QoISet &qoi_indices)
Function to evaluate quantity of interest.
Definition system.h:2198
bool _prefer_hash_table_matrix_assembly
Whether to use hash table matrix assembly if the matrix sub-classes support it.
Definition system.h:2348
QOIDerivative * _qoi_evaluate_derivative_object
Object to compute derivatives of quantities of interest.
Definition system.h:2219
Initialization * _init_system_object
Object that initializes the system.
Definition system.h:2171
EquationSystems & get_equation_systems()
Definition system.h:772
dof_id_type n_active_dofs() const
Definition system.h:2483
dof_id_type n_local_dofs() const
Definition system.C:155
virtual std::string system_type() const
Definition system.h:510
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
dof_id_type n_constrained_dofs() const
Definition system.C:125
Number get_qoi_value(unsigned int qoi_index) const
Definition system.C:2184
unsigned int n_components() const
Definition system.C:2694
std::vector< Number > get_qoi_values() const
Returns a copy of qoi, not a reference.
Definition system.C:2191
System sys_type
The type of system.
Definition system.h:250
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:2111
NumericVector< Number > & add_sensitivity_solution(unsigned int i=0)
Definition system.C:1169
void init_qois(unsigned int n_qois)
Accessors for qoi and qoi_error_estimates vectors.
Definition system.C:2169
virtual void clear()
Clear all the data structures associated with the system.
Definition system.C:173
vectors_iterator vectors_end()
End of vectors container.
Definition system.h:2517
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
virtual void user_constrain()
Calls user's attached constraint function, or is overridden by the user in derived classes.
Definition system.C:2123
void set_adjoint_already_solved(bool setting)
Setter for the adjoint_already_solved boolean.
Definition system.h:417
Real time
For time-dependent problems, this is the time t at the beginning of the current timestep.
Definition system.h:1677
NumericVector< Number > & get_sensitivity_solution(unsigned int i=0)
Definition system.C:1179
virtual void add_matrices()
Insertion point for adding matrices in derived classes before init_matrices() is called.
Definition system.h:2017
virtual void qoi_parameter_hessian(const QoISet &qoi_indices, const ParameterVector &parameters, SensitivityData &hessian)
For each of the system's quantities of interest q in qoi[qoi_indices], and for a vector of parameters...
Definition system.h:2620
virtual void re_update()
Re-update the local values when the mesh has changed.
Definition system.C:521
std::unique_ptr< DofMap > _dof_map
Data structure describing the relationship between nodes, variables, etc... and degrees of freedom.
Definition system.h:2225
EquationSystems & _equation_systems
Constant reference to the EquationSystems object used for the simulation.
Definition system.h:2231
bool have_matrix(std::string_view mat_name) const
Definition system.h:1933
void deactivate()
Deactivates the system.
Definition system.h:2449
void init()
Initializes degrees of freedom on the current mesh.
Definition system.C:196
virtual std::pair< unsigned int, Real > sensitivity_solve(const ParameterVector &parameters)
Solves the sensitivity system, for the provided parameters.
Definition system.h:2571
std::unique_ptr< NumericVector< Number > > solution
Data structure to hold solution values.
Definition system.h:1655
virtual void init_matrices()
Initializes the matrices associated with this system.
Definition system.C:311
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
const VariableGroup & variable_group(unsigned int vg) const
Return a constant reference to VariableGroup vg.
Definition system.C:2709
const std::string _sys_name
A name associated with this system.
Definition system.h:2242
Gradient(* GradientFunctionPointer)(const Point &p, const Parameters &parameters, const std::string &sys_name, const std::string &unknown_name)
Definition system.h:555
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
virtual void init_data()
Initializes the data for the system.
Definition system.C:207
bool _matrices_initialized
false when additional matrices being added require initialization, true otherwise.
Definition system.h:2287
bool active() const
Definition system.h:2433
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
const std::string & variable_name(const unsigned int i) const
Definition system.C:2679
void attach_init_object(Initialization &init)
Register a user class to use to initialize the system.
Definition system.C:1945
unsigned int n_qois() const
Number of currently active quantities of interest.
Definition system.h:2562
virtual void solve()
Solves the system.
Definition system.h:349
NumericVector< Number > & get_sensitivity_rhs(unsigned int i=0)
Definition system.C:1324
virtual bool condense_constrained_dofs() const
Whether this object should condense out constrained degrees of freedom.
Definition system.h:2059
System(System &&)=default
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
NumericVector< Number > & add_adjoint_rhs(unsigned int i=0)
Definition system.C:1284
void set_basic_system_only()
Sets the system to be "basic only": i.e.
Definition system.h:2465
NumericVector< Number > & add_adjoint_solution(unsigned int i=0)
Definition system.C:1220
virtual void assemble_qoi(const QoISet &qoi_indices=QoISet())
Calls user qoi function.
Definition system.C:565
unsigned int variable_scalar_number(std::string_view var, unsigned int component) const
Definition system.h:2474
bool vector_preservation(std::string_view vec_name) const
Definition system.C:1135
void(* _assemble_system_function)(EquationSystems &es, const std::string &name)
Function that assembles the system.
Definition system.h:2176
virtual void update()
Update the local values to reflect the solution on neighboring processors.
Definition system.C:498
std::vector< Number > _qoi
Values of the quantities of interest.
Definition system.h:2367
unsigned int variable_number(std::string_view var) const
Definition system.C:1398
unsigned int n_variable_groups() const
Definition system.C:2699
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
bool has_static_condensation() const
Definition system.C:2669
System(const System &)=delete
Special functions.
void set_qoi_error_estimate(unsigned int qoi_index, Number qoi_error_estimate)
Definition system.C:2204
dof_id_type n_local_constrained_dofs() const
Definition system.C:140
void projection_matrix(SparseMatrix< Number > &proj_mat) const
This method creates a projection matrix which corresponds to the operation of project_vector between ...
Parameters parameters
Parameters for the system. If a parameter is not provided, it should be retrieved from the EquationSy...
Definition system.h:1588
bool is_adjoint_already_solved() const
Accessor for the adjoint_already_solved boolean.
Definition system.h:411
bool has_variable(std::string_view var) const
Definition system.C:1393
bool adjoint_already_solved
Has the adjoint problem already been solved? If the user sets adjoint_already_solved to true,...
Definition system.h:2332
virtual void reinit_constraints()
Reinitializes the constraints for this system.
Definition system.C:483
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
void attach_constraint_object(Constraint &constrain)
Register a user object for imposing constraints.
Definition system.C:2007
NumericVector< Number > & get_weighted_sensitivity_solution()
Definition system.C:1206
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
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
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
bool _require_sparsity_pattern
Whether any of our matrices require an initial sparsity pattern computation in order to determine pre...
Definition system.h:2353
void set_project_with_constraints(bool _project_with_constraints)
Definition system.h:1842
void read_parallel_data(Xdr &io, const bool read_additional_data)
Reads additional data, namely vectors, for this System.
Definition system_io.C:302
bool project_with_constraints
Do we want to apply constraints while projecting vectors ?
Definition system.h:2343
Number get_qoi_error_estimate_value(unsigned int qoi_index) const
Definition system.C:2211
std::string prefix() const
Definition system.h:1980
bool _prefix_with_name
Whether we are name prefixing solver options.
Definition system.h:2358
NumericVector< Number > & add_weighted_sensitivity_solution()
Definition system.C:1199
std::map< std::string, ParallelType, std::less<> > _matrix_types
Holds the types of the matrices.
Definition system.h:2282
unsigned int n_vars() const
Definition system.C:2674
const DofMap & get_dof_map() const
Definition system.h:2417
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
unsigned int _additional_data_written
This flag is used only when reading in a system from file.
Definition system.h:2313
NumericVector< Number > & get_adjoint_solution(unsigned int i=0)
Definition system.C:1232
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
bool _active
Flag stating if the system is active or not.
Definition system.h:2252
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
numeric_index_type read_serialized_vector(Xdr &io, NumericVector< Number > &vec)
Non-templated version for backward compatibility.
Definition system.h:2126
unsigned int number() const
Definition system.h:2393
const EquationSystems & get_equation_systems() const
Definition system.h:767
void late_matrix_init(SparseMatrix< Number > &mat, ParallelType type)
Helper function to keep DofMap forward declarable in system.h.
Definition system.C:1063
const NumericVector< Number > & get_vector(std::string_view vec_name) const
Definition system.C:931
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:1912
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
bool have_vector(std::string_view vec_name) const
Definition system.h:2491
const MeshBase & get_mesh() const
Definition system.h:2401
void read_serialized_data(Xdr &io, const bool read_additional_data=true)
Non-templated version for backward compatibility.
Definition system.h:1370
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:1518
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
const SparseMatrix< Number > * request_matrix(std::string_view mat_name) const
Definition system.C:1087
NumericVector< Number > & get_adjoint_rhs(unsigned int i=0)
Definition system.C:1294
This class defines a tensor in LIBMESH_DIM dimensional Real or Complex space.
This class defines a logically grouped set of variables in the system.
Definition variable.h:216
This class defines the notion of a variable in the system.
Definition variable.h:51
This class defines a vector in LIBMESH_DIM dimensional Real or Complex space.
This class implements a C++ interface to the XDR (eXternal Data Representation) format.
Definition xdr_cxx.h:68
static const Real b
The libMesh namespace provides an interface to certain functionality in the library.
ParallelType
Defines an enum for parallel data structure types.
SubsetSolveMode
defines an enum for the question what happens to the dofs outside the given subset when a system is s...
NumberVectorValue Gradient
MatrixBuildType
Defines an enum for matrix build types.
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
dof_id_type numeric_index_type
Definition id_types.h:99
uint8_t dof_id_type
Definition id_types.h:67
DIE A HORRIBLE DEATH HERE typedef LIBMESH_DEFAULT_SCALAR_TYPE Real
uint8_t processor_id_type
Definition id_types.h:104
VectorValue< Number > NumberVectorValue
Gradient gptr(const Point &p, const Parameters &, const std::string &libmesh_dbg_var(sys_name), const std::string &unknown_name)
Definition projection.C:96
Number fptr(const Point &p, const Parameters &, const std::string &libmesh_dbg_var(sys_name), const std::string &unknown_name)
Definition projection.C:81
static const bool value
Definition xdr_io.C:55