system.h
Go to the documentation of this file.
1 // The libMesh Finite Element Library.
2 // Copyright (C) 2002-2018 Benjamin S. Kirk, John W. Peterson, Roy H. Stogner
3 
4 // This library is free software; you can redistribute it and/or
5 // modify it under the terms of the GNU Lesser General Public
6 // License as published by the Free Software Foundation; either
7 // version 2.1 of the License, or (at your option) any later version.
8 
9 // This library is distributed in the hope that it will be useful,
10 // but WITHOUT ANY WARRANTY; without even the implied warranty of
11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 // Lesser General Public License for more details.
13 
14 // You should have received a copy of the GNU Lesser General Public
15 // License along with this library; if not, write to the Free Software
16 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17 
18 
19 
20 #ifndef LIBMESH_SYSTEM_H
21 #define LIBMESH_SYSTEM_H
22 
23 // Local Includes
24 #include "libmesh/auto_ptr.h" // deprecated
25 #include "libmesh/elem_range.h"
26 #include "libmesh/enum_subset_solve_mode.h" // SUBSET_ZERO
27 #include "libmesh/enum_parallel_type.h" // PARALLEL
29 #include "libmesh/libmesh_common.h"
31 #include "libmesh/qoi_set.h"
33 #include "libmesh/tensor_value.h" // For point_hessian
34 #include "libmesh/variable.h"
35 
36 #ifdef LIBMESH_FORWARD_DECLARE_ENUMS
37 namespace libMesh
38 {
39 enum FEMNormType : int;
40 }
41 #else
42 #include "libmesh/enum_norm_type.h"
43 #endif
44 
45 // C++ includes
46 #include <cstddef>
47 #include <set>
48 #include <vector>
49 #include <memory>
50 
51 namespace libMesh
52 {
53 
54 // Forward Declarations
55 class System;
56 class EquationSystems;
57 class MeshBase;
58 class Xdr;
59 class DofMap;
60 template <typename Output> class FunctionBase;
61 class Parameters;
62 class ParameterVector;
63 class Point;
64 class SensitivityData;
65 template <typename T> class NumericVector;
66 template <typename T> class SparseMatrix;
67 template <typename T> class VectorValue;
68 typedef VectorValue<Number> NumberVectorValue;
70 class SystemSubset;
71 class FEType;
72 class SystemNorm;
73 
92 class System : public ReferenceCountedObject<System>,
93  public ParallelObject
94 {
95 public:
96 
101  System (EquationSystems & es,
102  const std::string & name,
103  const unsigned int number);
104 
112  {
113  public:
117  virtual ~Initialization () {}
118 
124  virtual void initialize () = 0;
125  };
126 
127 
128 
135  class Assembly
136  {
137  public:
141  virtual ~Assembly () {}
142 
148  virtual void assemble () = 0;
149  };
150 
151 
152 
160  {
161  public:
165  virtual ~Constraint () {}
166 
172  virtual void constrain () = 0;
173  };
174 
175 
176 
183  class QOI
184  {
185  public:
189  virtual ~QOI () {}
190 
196  virtual void qoi (const QoISet & qoi_indices) = 0;
197  };
198 
199 
200 
208  {
209  public:
213  virtual ~QOIDerivative () {}
214 
220  virtual void qoi_derivative (const QoISet & qoi_indices,
221  bool include_liftfunc,
222  bool apply_constraints) = 0;
223  };
224 
225 
226 
230  virtual ~System ();
231 
235  typedef System sys_type;
236 
240  sys_type & system () { return *this; }
241 
246  virtual void clear ();
247 
252  void init ();
253 
262  virtual void reinit ();
263 
267  virtual void reinit_constraints ();
268 
272  bool is_initialized();
273 
278  virtual void update ();
279 
286  virtual void assemble ();
287 
292  virtual void assemble_qoi (const QoISet & qoi_indices = QoISet());
293 
298  virtual void assemble_qoi_derivative (const QoISet & qoi_indices = QoISet(),
299  bool include_liftfunc = true,
300  bool apply_constraints = true);
301 
313  virtual void assemble_residual_derivatives (const ParameterVector & parameters);
314 
320  virtual void restrict_solve_to (const SystemSubset * subset,
321  const SubsetSolveMode subset_solve_mode=SUBSET_ZERO);
322 
326  virtual void solve () {}
327 
337  virtual std::pair<unsigned int, Real>
338  sensitivity_solve (const ParameterVector & parameters);
339 
350  virtual std::pair<unsigned int, Real>
351  weighted_sensitivity_solve (const ParameterVector & parameters,
352  const ParameterVector & weights);
353 
364  virtual std::pair<unsigned int, Real>
365  adjoint_solve (const QoISet & qoi_indices = QoISet());
366 
381  virtual std::pair<unsigned int, Real>
383  const ParameterVector & weights,
384  const QoISet & qoi_indices = QoISet());
389  { return adjoint_already_solved;}
390 
394  void set_adjoint_already_solved(bool setting)
395  { adjoint_already_solved = setting;}
396 
397 
415  virtual void qoi_parameter_sensitivity (const QoISet & qoi_indices,
416  const ParameterVector & parameters,
417  SensitivityData & sensitivities);
418 
424  virtual void adjoint_qoi_parameter_sensitivity (const QoISet & qoi_indices,
425  const ParameterVector & parameters,
426  SensitivityData & sensitivities);
427 
433  virtual void forward_qoi_parameter_sensitivity (const QoISet & qoi_indices,
434  const ParameterVector & parameters,
435  SensitivityData & sensitivities);
436 
447  virtual void qoi_parameter_hessian(const QoISet & qoi_indices,
448  const ParameterVector & parameters,
449  SensitivityData & hessian);
450 
463  virtual void qoi_parameter_hessian_vector_product(const QoISet & qoi_indices,
464  const ParameterVector & parameters,
465  const ParameterVector & vector,
466  SensitivityData & product);
467 
473  virtual bool compare (const System & other_system,
474  const Real threshold,
475  const bool verbose) const;
476 
480  const std::string & name () const;
481 
487  virtual std::string system_type () const { return "Basic"; }
488 
499  FunctionBase<Gradient> * g = nullptr) const;
500 
511  FEMFunctionBase<Gradient> * g = nullptr) const;
512 
520  typedef Number (*ValueFunctionPointer)(const Point & p,
521  const Parameters & Parameters,
522  const std::string & sys_name,
523  const std::string & unknown_name);
524  typedef Gradient (*GradientFunctionPointer)(const Point & p,
525  const Parameters & parameters,
526  const std::string & sys_name,
527  const std::string & unknown_name);
530  const Parameters & parameters) const;
531 
545  void project_vector (NumericVector<Number> & new_vector,
547  FunctionBase<Gradient> * g = nullptr,
548  int is_adjoint = -1) const;
549 
563  void project_vector (NumericVector<Number> & new_vector,
565  FEMFunctionBase<Gradient> * g = nullptr,
566  int is_adjoint = -1) const;
567 
581  const Parameters & parameters,
582  NumericVector<Number> & new_vector,
583  int is_adjoint = -1) const;
584 
599  void boundary_project_solution (const std::set<boundary_id_type> & b,
600  const std::vector<unsigned int> & variables,
602  FunctionBase<Gradient> * g = nullptr);
603 
616  void boundary_project_solution (const std::set<boundary_id_type> & b,
617  const std::vector<unsigned int> & variables,
620  const Parameters & parameters);
621 
639  void boundary_project_vector (const std::set<boundary_id_type> & b,
640  const std::vector<unsigned int> & variables,
641  NumericVector<Number> & new_vector,
643  FunctionBase<Gradient> * g = nullptr,
644  int is_adjoint = -1) const;
645 
661  void boundary_project_vector (const std::set<boundary_id_type> & b,
662  const std::vector<unsigned int> & variables,
665  const Parameters & parameters,
666  NumericVector<Number> & new_vector,
667  int is_adjoint = -1) const;
668 
672  unsigned int number () const;
673 
679  void update_global_solution (std::vector<Number> & global_soln) const;
680 
686  void update_global_solution (std::vector<Number> & global_soln,
687  const processor_id_type dest_proc) const;
688 
692  const MeshBase & get_mesh() const;
693 
697  MeshBase & get_mesh();
698 
702  const DofMap & get_dof_map() const;
703 
707  DofMap & get_dof_map();
708 
713 
718 
723  bool active () const;
724 
728  void activate ();
729 
733  void deactivate ();
734 
743  void set_basic_system_only ();
744 
748  typedef std::map<std::string, NumericVector<Number> *>::iterator vectors_iterator;
749  typedef std::map<std::string, NumericVector<Number> *>::const_iterator const_vectors_iterator;
750 
755 
760 
765 
770 
780  NumericVector<Number> & add_vector (const std::string & vec_name,
781  const bool projections=true,
782  const ParallelType type = PARALLEL);
783 
787  void remove_vector(const std::string & vec_name);
788 
795  { return _solution_projection; }
796 
801  bool have_vector (const std::string & vec_name) const;
802 
807  const NumericVector<Number> * request_vector (const std::string & vec_name) const;
808 
813  NumericVector<Number> * request_vector (const std::string & vec_name);
814 
820  const NumericVector<Number> * request_vector (const unsigned int vec_num) const;
821 
827  NumericVector<Number> * request_vector (const unsigned int vec_num);
828 
834  const NumericVector<Number> & get_vector (const std::string & vec_name) const;
835 
841  NumericVector<Number> & get_vector (const std::string & vec_name);
842 
848  const NumericVector<Number> & get_vector (const unsigned int vec_num) const;
849 
855  NumericVector<Number> & get_vector (const unsigned int vec_num);
856 
861  const std::string & vector_name (const unsigned int vec_num) const;
862 
866  const std::string & vector_name (const NumericVector<Number> & vec_reference) const;
867 
878  void set_vector_as_adjoint (const std::string & vec_name, int qoi_num);
879 
885  int vector_is_adjoint (const std::string & vec_name) const;
886 
892  void set_vector_preservation (const std::string & vec_name, bool preserve);
893 
899  bool vector_preservation (const std::string & vec_name) const;
900 
906  NumericVector<Number> & add_adjoint_solution(unsigned int i=0);
907 
912  NumericVector<Number> & get_adjoint_solution(unsigned int i=0);
913 
918  const NumericVector<Number> & get_adjoint_solution(unsigned int i=0) const;
919 
926 
932 
937  const NumericVector<Number> & get_sensitivity_solution(unsigned int i=0) const;
938 
946 
953 
960 
967 
973 
979 
985  NumericVector<Number> & add_adjoint_rhs(unsigned int i=0);
986 
993  NumericVector<Number> & get_adjoint_rhs(unsigned int i=0);
994 
999  const NumericVector<Number> & get_adjoint_rhs(unsigned int i=0) const;
1000 
1006  NumericVector<Number> & add_sensitivity_rhs(unsigned int i=0);
1007 
1017  NumericVector<Number> & get_sensitivity_rhs(unsigned int i=0);
1018 
1023  const NumericVector<Number> & get_sensitivity_rhs(unsigned int i=0) const;
1024 
1030  unsigned int n_vectors () const;
1031 
1038  virtual unsigned int n_matrices () const;
1039 
1043  unsigned int n_vars() const;
1044 
1048  unsigned int n_variable_groups() const;
1049 
1055  unsigned int n_components() const;
1056 
1060  dof_id_type n_dofs() const;
1061 
1066  dof_id_type n_active_dofs() const;
1067 
1073 
1079 
1084  dof_id_type n_local_dofs() const;
1085 
1092  unsigned int add_variable (const std::string & var,
1093  const FEType & type,
1094  const std::set<subdomain_id_type> * const active_subdomains = nullptr);
1095 
1101  unsigned int add_variable (const std::string & var,
1102  const Order order = FIRST,
1103  const FEFamily = LAGRANGE,
1104  const std::set<subdomain_id_type> * const active_subdomains = nullptr);
1105 
1112  unsigned int add_variables (const std::vector<std::string> & vars,
1113  const FEType & type,
1114  const std::set<subdomain_id_type> * const active_subdomains = nullptr);
1115 
1121  unsigned int add_variables (const std::vector<std::string> & vars,
1122  const Order order = FIRST,
1123  const FEFamily = LAGRANGE,
1124  const std::set<subdomain_id_type> * const active_subdomains = nullptr);
1125 
1129  const Variable & variable (unsigned int var) const;
1130 
1134  const VariableGroup & variable_group (unsigned int vg) const;
1135 
1139  bool has_variable(const std::string & var) const;
1140 
1144  const std::string & variable_name(const unsigned int i) const;
1145 
1150  unsigned short int variable_number (const std::string & var) const;
1151 
1156  void get_all_variable_numbers(std::vector<unsigned int> & all_variable_numbers) const;
1157 
1168  unsigned int variable_scalar_number (const std::string & var,
1169  unsigned int component) const;
1170 
1181  unsigned int variable_scalar_number (unsigned int var_num,
1182  unsigned int component) const;
1183 
1184 
1188  const FEType & variable_type (const unsigned int i) const;
1189 
1193  const FEType & variable_type (const std::string & var) const;
1194 
1199  bool identify_variable_groups () const;
1200 
1204  void identify_variable_groups (const bool);
1205 
1211  unsigned int var,
1212  FEMNormType norm_type,
1213  std::set<unsigned int> * skip_dimensions=nullptr) const;
1214 
1220  const SystemNorm & norm,
1221  std::set<unsigned int> * skip_dimensions=nullptr) const;
1222 
1226  void read_header (Xdr & io,
1227  const std::string & version,
1228  const bool read_header=true,
1229  const bool read_additional_data=true,
1230  const bool read_legacy_format=false);
1231 
1239 #ifdef LIBMESH_ENABLE_DEPRECATED
1240  void read_legacy_data (Xdr & io,
1241  const bool read_additional_data=true);
1242 #endif
1243 
1248  template <typename ValType>
1249  void read_serialized_data (Xdr & io,
1250  const bool read_additional_data=true);
1258  const bool read_additional_data=true)
1259  { read_serialized_data<Number>(io, read_additional_data); }
1260 
1266  template <typename InValType>
1267  std::size_t read_serialized_vectors (Xdr & io,
1268  const std::vector<NumericVector<Number> *> & vectors) const;
1269 
1277  std::size_t read_serialized_vectors (Xdr & io,
1278  const std::vector<NumericVector<Number> *> & vectors) const
1279  { return read_serialized_vectors<Number>(io, vectors); }
1280 
1287  template <typename InValType>
1288  void read_parallel_data (Xdr & io,
1289  const bool read_additional_data);
1290 
1300  const bool read_additional_data)
1301  { read_parallel_data<Number>(io, read_additional_data); }
1302 
1306  void write_header (Xdr & io,
1307  const std::string & version,
1308  const bool write_additional_data) const;
1309 
1314  void write_serialized_data (Xdr & io,
1315  const bool write_additional_data = true) const;
1316 
1322  std::size_t write_serialized_vectors (Xdr & io,
1323  const std::vector<const NumericVector<Number> *> & vectors) const;
1324 
1331  void write_parallel_data (Xdr & io,
1332  const bool write_additional_data) const;
1333 
1338  std::string get_info () const;
1339 
1343  void attach_init_function (void fptr(EquationSystems & es,
1344  const std::string & name));
1345 
1351  void attach_init_object (Initialization & init);
1352 
1357  void attach_assemble_function (void fptr(EquationSystems & es,
1358  const std::string & name));
1359 
1364  void attach_assemble_object (Assembly & assemble);
1365 
1369  void attach_constraint_function (void fptr(EquationSystems & es,
1370  const std::string & name));
1371 
1375  void attach_constraint_object (Constraint & constrain);
1376 
1381  void attach_QOI_function (void fptr(EquationSystems & es,
1382  const std::string & name,
1383  const QoISet & qoi_indices));
1384 
1389  void attach_QOI_object (QOI & qoi);
1390 
1396  void attach_QOI_derivative (void fptr(EquationSystems & es,
1397  const std::string & name,
1398  const QoISet & qoi_indices,
1399  bool include_liftfunc,
1400  bool apply_constraints));
1401 
1407  void attach_QOI_derivative_object (QOIDerivative & qoi_derivative);
1408 
1413  virtual void user_initialization ();
1414 
1419  virtual void user_assembly ();
1420 
1425  virtual void user_constrain ();
1426 
1431  virtual void user_QOI (const QoISet & qoi_indices);
1432 
1437  virtual void user_QOI_derivative (const QoISet & qoi_indices = QoISet(),
1438  bool include_liftfunc = true,
1439  bool apply_constraints = true);
1440 
1446  virtual void re_update ();
1447 
1451  virtual void restrict_vectors ();
1452 
1456  virtual void prolong_vectors ();
1457 
1478 
1483  virtual void disable_cache ();
1484 
1494 
1509 
1510 
1511  //--------------------------------------------------
1512  // The solution and solution access members
1513 
1518  Number current_solution (const dof_id_type global_dof_number) const;
1519 
1523  std::unique_ptr<NumericVector<Number>> solution;
1524 
1535  std::unique_ptr<NumericVector<Number>> current_local_solution;
1536 
1546 
1550  unsigned int n_qois() const;
1551 
1558  std::vector<Number> qoi;
1559 
1580  Number point_value(unsigned int var, const Point & p,
1581  const bool insist_on_success = true) const;
1582 
1590  Number point_value(unsigned int var, const Point & p, const Elem & e) const;
1591 
1598  Number point_value(unsigned int var, const Point & p, const Elem * e) const;
1599 
1604  Gradient point_gradient(unsigned int var, const Point & p,
1605  const bool insist_on_success = true) const;
1606 
1611  Gradient point_gradient(unsigned int var, const Point & p, const Elem & e) const;
1612 
1619  Gradient point_gradient(unsigned int var, const Point & p, const Elem * e) const;
1620 
1625  Tensor point_hessian(unsigned int var, const Point & p,
1626  const bool insist_on_success = true) const;
1627 
1633  Tensor point_hessian(unsigned int var, const Point & p, const Elem & e) const;
1634 
1641  Tensor point_hessian(unsigned int var, const Point & p, const Elem * e) const;
1642 
1647  void local_dof_indices (const unsigned int var,
1648  std::set<dof_id_type> & var_indices) const;
1649 
1654  void zero_variable (NumericVector<Number> & v, unsigned int var_num) const;
1655 
1656 
1662  bool & hide_output() { return _hide_output; }
1663 
1664 #ifdef LIBMESH_HAVE_METAPHYSICL
1665 
1675  void projection_matrix (SparseMatrix<Number> & proj_mat) const;
1676 #endif // LIBMESH_HAVE_METAPHYSICL
1677 
1678 protected:
1679 
1686  virtual void init_data ();
1687 
1696  int is_adjoint = -1) const;
1697 
1706  void project_vector (const NumericVector<Number> &,
1708  int is_adjoint = -1) const;
1709 
1710 private:
1717  System (const System &);
1718 
1725  System & operator=(const System &);
1726 
1732  unsigned int var,
1733  FEMNormType norm_type) const;
1734 
1744  template <typename iterator_type, typename InValType>
1746  const iterator_type begin,
1747  const iterator_type end,
1748  const InValType dummy,
1749  Xdr & io,
1750  const std::vector<NumericVector<Number> *> & vecs,
1751  const unsigned int var_to_read=libMesh::invalid_uint) const;
1752 
1761  unsigned int read_SCALAR_dofs (const unsigned int var,
1762  Xdr & io,
1763  NumericVector<Number> * vec) const;
1764 
1773  template <typename InValType>
1775  NumericVector<Number> * vec);
1776 
1786  NumericVector<Number> & vec)
1787  { return read_serialized_vector<Number>(io, &vec); }
1788 
1795  template <typename iterator_type>
1796  std::size_t write_serialized_blocked_dof_objects (const std::vector<const NumericVector<Number> *> & vecs,
1797  const dof_id_type n_objects,
1798  const iterator_type begin,
1799  const iterator_type end,
1800  Xdr & io,
1801  const unsigned int var_to_write=libMesh::invalid_uint) const;
1802 
1808  unsigned int write_SCALAR_dofs (const NumericVector<Number> & vec,
1809  const unsigned int var,
1810  Xdr & io) const;
1811 
1819  const NumericVector<Number> & vec) const;
1820 
1825  const std::string & name);
1826 
1831 
1836  const std::string & name);
1837 
1842 
1847  const std::string & name);
1848 
1853 
1858  const std::string & name,
1859  const QoISet & qoi_indices);
1860 
1865 
1870  const std::string & name,
1871  const QoISet & qoi_indices,
1872  bool include_liftfunc,
1873  bool apply_constraints);
1874 
1879 
1884  std::unique_ptr<DofMap> _dof_map;
1885 
1891 
1897 
1901  const std::string _sys_name;
1902 
1906  const unsigned int _sys_number;
1907 
1911  std::vector<Variable> _variables;
1912 
1916  std::vector<VariableGroup> _variable_groups;
1917 
1922  std::map<std::string, unsigned short int> _variable_numbers;
1923 
1927  bool _active;
1928 
1935  std::map<std::string, NumericVector<Number> * > _vectors;
1936 
1941  std::map<std::string, bool> _vector_projections;
1942 
1947  std::map<std::string, int> _vector_is_adjoint;
1948 
1952  std::map<std::string, ParallelType> _vector_types;
1953 
1960 
1966 
1972 
1978 
1985 
1996  std::vector<unsigned int> _written_var_indices;
1997 
2004 
2010 };
2011 
2012 
2013 
2014 // ------------------------------------------------------------
2015 // System inline methods
2016 inline
2017 const std::string & System::name() const
2018 {
2019  return _sys_name;
2020 }
2021 
2022 
2023 
2024 inline
2025 unsigned int System::number() const
2026 {
2027  return _sys_number;
2028 }
2029 
2030 
2031 
2032 inline
2034 {
2035  return _mesh;
2036 }
2037 
2038 
2039 
2040 inline
2042 {
2043  return _mesh;
2044 }
2045 
2046 
2047 
2048 inline
2050 {
2051  return *_dof_map;
2052 }
2053 
2054 
2055 
2056 inline
2058 {
2059  return *_dof_map;
2060 }
2061 
2062 
2063 
2064 inline
2065 bool System::active() const
2066 {
2067  return _active;
2068 }
2069 
2070 
2071 
2072 inline
2074 {
2075  _active = true;
2076 }
2077 
2078 
2079 
2080 inline
2082 {
2083  _active = false;
2084 }
2085 
2086 
2087 
2088 inline
2090 {
2091  return _is_initialized;
2092 }
2093 
2094 
2095 
2096 inline
2098 {
2099  _basic_system_only = true;
2100 }
2101 
2102 
2103 
2104 inline
2105 unsigned int System::n_vars() const
2106 {
2107  return cast_int<unsigned int>(_variables.size());
2108 }
2109 
2110 
2111 
2112 inline
2113 unsigned int System::n_variable_groups() const
2114 {
2115  return cast_int<unsigned int>(_variable_groups.size());
2116 }
2117 
2118 
2119 
2120 inline
2121 unsigned int System::n_components() const
2122 {
2123  if (_variables.empty())
2124  return 0;
2125 
2126  const Variable & last = _variables.back();
2127  return last.first_scalar_number() + last.n_components();
2128 }
2129 
2130 
2131 
2132 inline
2133 const Variable & System::variable (const unsigned int i) const
2134 {
2135  libmesh_assert_less (i, _variables.size());
2136 
2137  return _variables[i];
2138 }
2139 
2140 
2141 
2142 inline
2143 const VariableGroup & System::variable_group (const unsigned int vg) const
2144 {
2145  libmesh_assert_less (vg, _variable_groups.size());
2146 
2147  return _variable_groups[vg];
2148 }
2149 
2150 
2151 
2152 inline
2153 const std::string & System::variable_name (const unsigned int i) const
2154 {
2155  libmesh_assert_less (i, _variables.size());
2156 
2157  return _variables[i].name();
2158 }
2159 
2160 
2161 
2162 inline
2163 unsigned int
2164 System::variable_scalar_number (const std::string & var,
2165  unsigned int component) const
2166 {
2167  return variable_scalar_number(this->variable_number(var), component);
2168 }
2169 
2170 
2171 
2172 inline
2173 unsigned int
2174 System::variable_scalar_number (unsigned int var_num,
2175  unsigned int component) const
2176 {
2177  return _variables[var_num].first_scalar_number() + component;
2178 }
2179 
2180 
2181 
2182 inline
2183 const FEType & System::variable_type (const unsigned int i) const
2184 {
2185  libmesh_assert_less (i, _variables.size());
2186 
2187  return _variables[i].type();
2188 }
2189 
2190 
2191 
2192 inline
2193 const FEType & System::variable_type (const std::string & var) const
2194 {
2195  return _variables[this->variable_number(var)].type();
2196 }
2197 
2198 
2199 
2200 inline
2202 {
2204 }
2205 
2206 
2207 
2208 inline
2210 {
2212 }
2213 
2214 
2215 
2216 inline
2218 {
2219  return this->n_dofs() - this->n_constrained_dofs();
2220 }
2221 
2222 
2223 
2224 inline
2225 bool System::have_vector (const std::string & vec_name) const
2226 {
2227  return (_vectors.count(vec_name));
2228 }
2229 
2230 
2231 
2232 inline
2233 unsigned int System::n_vectors () const
2234 {
2235  return cast_int<unsigned int>(_vectors.size());
2236 }
2237 
2238 inline
2239 unsigned int System::n_matrices () const
2240 {
2241  return 0;
2242 }
2243 
2244 inline
2246 {
2247  return _vectors.begin();
2248 }
2249 
2250 inline
2252 {
2253  return _vectors.begin();
2254 }
2255 
2256 inline
2258 {
2259  return _vectors.end();
2260 }
2261 
2262 inline
2264 {
2265  return _vectors.end();
2266 }
2267 
2268 inline
2270 {
2271  libmesh_not_implemented();
2272 }
2273 
2274 inline
2276 
2277 inline
2278 unsigned int System::n_qois() const
2279 {
2280  return cast_int<unsigned int>(this->qoi.size());
2281 }
2282 
2283 inline
2284 std::pair<unsigned int, Real>
2286 {
2287  libmesh_not_implemented();
2288 }
2289 
2290 inline
2291 std::pair<unsigned int, Real>
2293  const ParameterVector &)
2294 {
2295  libmesh_not_implemented();
2296 }
2297 
2298 inline
2299 std::pair<unsigned int, Real>
2301 {
2302  libmesh_not_implemented();
2303 }
2304 
2305 inline
2306 std::pair<unsigned int, Real>
2308  const ParameterVector &,
2309  const QoISet &)
2310 {
2311  libmesh_not_implemented();
2312 }
2313 
2314 inline
2315 void
2317  const ParameterVector &,
2318  SensitivityData &)
2319 {
2320  libmesh_not_implemented();
2321 }
2322 
2323 inline
2324 void
2326  const ParameterVector &,
2327  SensitivityData &)
2328 {
2329  libmesh_not_implemented();
2330 }
2331 
2332 inline
2333 void
2335  const ParameterVector &,
2336  SensitivityData &)
2337 {
2338  libmesh_not_implemented();
2339 }
2340 
2341 inline
2342 void
2344  const ParameterVector &,
2345  const ParameterVector &,
2346  SensitivityData &)
2347 {
2348  libmesh_not_implemented();
2349 }
2350 
2351 
2352 } // namespace libMesh
2353 
2354 #endif // LIBMESH_SYSTEM_H
void set_vector_as_adjoint(const std::string &vec_name, int qoi_num)
Definition: system.C:885
Manages the family, order, etc. parameters for a given FE.
Definition: fe_type.h:179
unsigned int add_variables(const std::vector< std::string > &vars, const FEType &type, const std::set< subdomain_id_type > *const active_subdomains=nullptr)
Definition: system.C:1171
vectors_iterator vectors_end()
Definition: system.h:2257
void local_dof_indices(const unsigned int var, std::set< dof_id_type > &var_indices) const
Definition: system.C:1277
std::map< std::string, unsigned short int > _variable_numbers
Definition: system.h:1922
void write_serialized_data(Xdr &io, const bool write_additional_data=true) const
Definition: system_io.C:1704
Manages multiples systems of equations.
unsigned int variable_scalar_number(const std::string &var, unsigned int component) const
Definition: system.h:2164
static unsigned int n_objects()
virtual void clear()
Definition: system.C:205
void update_global_solution(std::vector< Number > &global_soln) const
Definition: system.C:642
void write_parallel_data(Xdr &io, const bool write_additional_data) const
Definition: system_io.C:1504
const Variable & variable(unsigned int var) const
Definition: system.h:2133
Assembly * _assemble_system_object
Definition: system.h:1841
bool _basic_system_only
Definition: system.h:1965
const unsigned int invalid_uint
Definition: libmesh.h:245
std::map< std::string, ParallelType > _vector_types
Definition: system.h:1952
bool _is_initialized
Definition: system.h:1971
void(* _constrain_system_function)(EquationSystems &es, const std::string &name)
Definition: system.h:1846
void set_adjoint_already_solved(bool setting)
Definition: system.h:394
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
NumericVector< Number > & add_adjoint_solution(unsigned int i=0)
Definition: system.C:957
virtual void forward_qoi_parameter_sensitivity(const QoISet &qoi_indices, const ParameterVector &parameters, SensitivityData &sensitivities)
Definition: system.h:2325
Specifies parameters for parameter sensitivity calculations.
virtual void assemble_residual_derivatives(const ParameterVector &parameters)
Definition: system.h:2269
Used to specify quantities of interest in a simulation.
Definition: qoi_set.h:45
void read_parallel_data(Xdr &io, const bool read_additional_data)
Definition: system.h:1299
virtual void reinit()
Definition: system.C:390
unsigned int n_qois() const
Definition: system.h:2278
unsigned int n_components() const
Definition: system.h:2121
virtual void disable_cache()
Definition: system.h:2275
bool active() const
Definition: system.h:2065
int vector_is_adjoint(const std::string &vec_name) const
Definition: system.C:896
int extra_quadrature_order
Definition: system.h:1508
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
Definition: system_io.C:811
sys_type & system()
Definition: system.h:240
NumericVector< Number > & get_sensitivity_solution(unsigned int i=0)
Definition: system.C:916
unsigned int write_SCALAR_dofs(const NumericVector< Number > &vec, const unsigned int var, Xdr &io) const
Definition: system_io.C:2101
const unsigned int _sys_number
Definition: system.h:1906
virtual void assemble_qoi_derivative(const QoISet &qoi_indices=QoISet(), bool include_liftfunc=true, bool apply_constraints=true)
Definition: system.C:484
NumericVector< Number > & get_sensitivity_rhs(unsigned int i=0)
Definition: system.C:1061
virtual void assemble()=0
Constraint * _constrain_system_object
Definition: system.h:1852
const EquationSystems & get_equation_systems() const
Definition: system.h:712
unsigned int n_variable_groups() const
Definition: system.h:2113
virtual void assemble()
Definition: system.C:462
Gradient point_gradient(unsigned int var, const Point &p, const bool insist_on_success=true) const
Definition: system.C:2100
void projection_matrix(SparseMatrix< Number > &proj_mat) const
virtual void init_data()
Definition: system.C:262
The base class for all geometric element types.
Definition: elem.h:100
uint8_t processor_id_type
Definition: id_types.h:99
std::unique_ptr< DofMap > _dof_map
Definition: system.h:1884
std::map< std::string, NumericVector< Number > * >::const_iterator const_vectors_iterator
Definition: system.h:749
virtual void user_initialization()
Definition: system.C:1918
std::vector< Variable > _variables
Definition: system.h:1911
void get_all_variable_numbers(std::vector< unsigned int > &all_variable_numbers) const
Definition: system.C:1258
NumericVector< Number > & add_sensitivity_rhs(unsigned int i=0)
Definition: system.C:1051
IterBase * end
void read_legacy_data(Xdr &io, const bool read_additional_data=true)
Definition: system_io.C:310
std::size_t read_serialized_vectors(Xdr &io, const std::vector< NumericVector< Number > *> &vectors) const
Definition: system.h:1277
vectors_iterator vectors_begin()
Definition: system.h:2245
void attach_QOI_derivative_object(QOIDerivative &qoi_derivative)
Definition: system.C:1902
virtual void adjoint_qoi_parameter_sensitivity(const QoISet &qoi_indices, const ParameterVector &parameters, SensitivityData &sensitivities)
Definition: system.h:2316
dof_id_type n_local_dofs() const
Definition: system.C:187
NumericVector< Number > & add_weighted_sensitivity_solution()
Definition: system.C:936
void(* _qoi_evaluate_function)(EquationSystems &es, const std::string &name, const QoISet &qoi_indices)
Definition: system.h:1857
System sys_type
Definition: system.h:235
void init()
Definition: system.C:237
const MeshBase & get_mesh() const
Definition: system.h:2033
bool has_variable(const std::string &var) const
Definition: system.C:1236
NumericVector< Number > & get_weighted_sensitivity_solution()
Definition: system.C:943
bool adjoint_already_solved
Definition: system.h:2003
dof_id_type n_dofs() const
Definition: system.C:150
Base class for Mesh.
Definition: mesh_base.h:77
virtual void prolong_vectors()
Definition: system.C:380
Tensor point_hessian(unsigned int var, const Point &p, const bool insist_on_success=true) const
Definition: system.C:2220
Number current_solution(const dof_id_type global_dof_number) const
Definition: system.C:194
virtual void user_QOI(const QoISet &qoi_indices)
Definition: system.C:1960
QOIDerivative * _qoi_evaluate_derivative_object
Definition: system.h:1878
void remove_vector(const std::string &vec_name)
Definition: system.C:699
NumericVector< Number > & add_weighted_sensitivity_adjoint_solution(unsigned int i=0)
Definition: system.C:989
virtual void qoi_derivative(const QoISet &qoi_indices, bool include_liftfunc, bool apply_constraints)=0
virtual void qoi_parameter_sensitivity(const QoISet &qoi_indices, const ParameterVector &parameters, SensitivityData &sensitivities)
Definition: system.C:498
virtual void qoi_parameter_hessian(const QoISet &qoi_indices, const ParameterVector &parameters, SensitivityData &hessian)
Definition: system.h:2334
void attach_constraint_object(Constraint &constrain)
Definition: system.C:1831
Manages the degrees of freedom (DOFs) in a simulation.
Definition: dof_map.h:176
void project_solution(FunctionBase< Number > *f, FunctionBase< Gradient > *g=nullptr) const
void attach_init_object(Initialization &init)
Definition: system.C:1761
void set_basic_system_only()
Definition: system.h:2097
unsigned int first_scalar_number() const
Definition: variable.h:113
unsigned int number() const
Definition: system.h:2025
NumericVector< Number > & add_vector(const std::string &vec_name, const bool projections=true, const ParallelType type=PARALLEL)
Definition: system.C:661
A variable which is solved for in a System of equations.
Definition: variable.h:49
virtual void qoi_parameter_hessian_vector_product(const QoISet &qoi_indices, const ParameterVector &parameters, const ParameterVector &vector, SensitivityData &product)
Definition: system.h:2343
Holds completed parameter sensitivity calculations.
dof_id_type numeric_index_type
Definition: id_types.h:92
void read_header(Xdr &io, const std::string &version, const bool read_header=true, const bool read_additional_data=true, const bool read_legacy_format=false)
Definition: system_io.C:115
std::vector< Number > qoi
Definition: system.h:1558
void deactivate()
Definition: system.h:2081
unsigned int n_components() const
Definition: variable.h:125
void read_serialized_data(Xdr &io, const bool read_additional_data=true)
Definition: system.h:1257
std::vector< VariableGroup > _variable_groups
Definition: system.h:1916
bool vector_preservation(const std::string &vec_name) const
Definition: system.C:875
bool is_initialized()
Definition: system.h:2089
bool use_fixed_solution
Definition: system.h:1493
unsigned int n_vectors() const
Definition: system.h:2233
Manages consistently variables, degrees of freedom, and coefficient vectors.
Definition: system.h:92
void zero_variable(NumericVector< Number > &v, unsigned int var_num) const
Definition: system.C:1322
unsigned short int variable_number(const std::string &var) const
Definition: system.C:1243
bool & hide_output()
Definition: system.h:1662
const NumericVector< Number > & get_vector(const std::string &vec_name) const
Definition: system.C:774
std::string get_info() const
Definition: system.C:1658
numeric_index_type read_serialized_vector(Xdr &io, NumericVector< Number > *vec)
Definition: system_io.C:1168
NumberVectorValue Gradient
virtual void qoi(const QoISet &qoi_indices)=0
std::unique_ptr< NumericVector< Number > > solution
Definition: system.h:1523
void attach_QOI_derivative(void fptr(EquationSystems &es, const std::string &name, const QoISet &qoi_indices, bool include_liftfunc, bool apply_constraints))
Definition: system.C:1883
Real calculate_norm(const NumericVector< Number > &v, unsigned int var, FEMNormType norm_type, std::set< unsigned int > *skip_dimensions=nullptr) const
Definition: system.C:1378
QOI * _qoi_evaluate_object
Definition: system.h:1864
virtual std::pair< unsigned int, Real > sensitivity_solve(const ParameterVector &parameters)
Definition: system.h:2285
Initialization * _init_system_object
Definition: system.h:1830
virtual std::pair< unsigned int, Real > adjoint_solve(const QoISet &qoi_indices=QoISet())
Definition: system.h:2300
System & operator=(const System &)
Definition: system.C:114
void attach_QOI_function(void fptr(EquationSystems &es, const std::string &name, const QoISet &qoi_indices))
Definition: system.C:1847
bool _hide_output
Definition: system.h:2009
unsigned int _additional_data_written
Definition: system.h:1984
const std::string & variable_name(const unsigned int i) const
Definition: system.h:2153
void(* _init_system_function)(EquationSystems &es, const std::string &name)
Definition: system.h:1824
dof_id_type n_active_dofs() const
Definition: system.h:2217
virtual void restrict_vectors()
Definition: system.C:324
void attach_assemble_function(void fptr(EquationSystems &es, const std::string &name))
Definition: system.C:1777
std::map< std::string, int > _vector_is_adjoint
Definition: system.h:1947
std::size_t read_serialized_vectors(Xdr &io, const std::vector< NumericVector< Number > *> &vectors) const
Definition: system_io.C:2203
virtual unsigned int n_matrices() const
Definition: system.h:2239
An object whose state is distributed along a set of processors.
void activate()
Definition: system.h:2073
NumericVector< Number > & add_adjoint_rhs(unsigned int i=0)
Definition: system.C:1021
virtual void restrict_solve_to(const SystemSubset *subset, const SubsetSolveMode subset_solve_mode=SUBSET_ZERO)
Definition: system.C:453
bool have_vector(const std::string &vec_name) const
Definition: system.h:2225
virtual void user_QOI_derivative(const QoISet &qoi_indices=QoISet(), bool include_liftfunc=true, bool apply_constraints=true)
Definition: system.C:1974
virtual void reinit_constraints()
Definition: system.C:397
bool identify_variable_groups() const
Definition: system.h:2201
bool is_adjoint_already_solved() const
Definition: system.h:388
virtual void solve()
Definition: system.h:326
C++ interface for the XDR (eXternal Data Representation) format.
Definition: xdr_cxx.h:66
EquationSystems & get_equation_systems()
Definition: system.h:717
void attach_assemble_object(Assembly &assemble)
Definition: system.C:1796
std::map< std::string, NumericVector< Number > * >::iterator vectors_iterator
Definition: system.h:748
bool _solution_projection
Definition: system.h:1959
EquationSystems & _equation_systems
Definition: system.h:1890
std::size_t write_serialized_vectors(Xdr &io, const std::vector< const NumericVector< Number > *> &vectors) const
Definition: system_io.C:2297
virtual std::string system_type() const
Definition: system.h:487
virtual void constrain()=0
void read_parallel_data(Xdr &io, const bool read_additional_data)
Definition: system_io.C:493
const std::string & vector_name(const unsigned int vec_num) const
Definition: system.C:832
void attach_QOI_object(QOI &qoi)
Definition: system.C:1867
virtual void user_assembly()
Definition: system.C:1932
virtual void update()
Definition: system.C:408
const FEType & variable_type(const unsigned int i) const
Definition: system.h:2183
DIE A HORRIBLE DEATH HERE typedef LIBMESH_DEFAULT_SCALAR_TYPE Real
void set_vector_preservation(const std::string &vec_name, bool preserve)
Definition: system.C:867
Number(* ValueFunctionPointer)(const Point &p, const Parameters &Parameters, const std::string &sys_name, const std::string &unknown_name)
Definition: system.h:520
bool _identify_variable_groups
Definition: system.h:1977
std::map< std::string, NumericVector< Number > *> _vectors
Definition: system.h:1935
virtual std::pair< unsigned int, Real > weighted_sensitivity_solve(const ParameterVector &parameters, const ParameterVector &weights)
Definition: system.h:2292
const std::string _sys_name
Definition: system.h:1901
const NumericVector< Number > * request_vector(const std::string &vec_name) const
Definition: system.C:716
bool & project_solution_on_reinit(void)
Definition: system.h:794
NumericVector< Number > & get_adjoint_solution(unsigned int i=0)
Definition: system.C:969
virtual void re_update()
Definition: system.C:429
std::map< std::string, bool > _vector_projections
Definition: system.h:1941
virtual ~QOI()
Definition: system.h:189
std::unique_ptr< NumericVector< Number > > current_local_solution
Definition: system.h:1535
virtual std::pair< unsigned int, Real > weighted_sensitivity_adjoint_solve(const ParameterVector &parameters, const ParameterVector &weights, const QoISet &qoi_indices=QoISet())
Definition: system.h:2307
void project_vector(NumericVector< Number > &new_vector, FunctionBase< Number > *f, FunctionBase< Gradient > *g=nullptr, int is_adjoint=-1) const
virtual bool compare(const System &other_system, const Real threshold, const bool verbose) const
Definition: system.C:514
dof_id_type n_local_constrained_dofs() const
Definition: system.C:172
void boundary_project_solution(const std::set< boundary_id_type > &b, const std::vector< unsigned int > &variables, FunctionBase< Number > *f, FunctionBase< Gradient > *g=nullptr)
unsigned int read_SCALAR_dofs(const unsigned int var, Xdr &io, NumericVector< Number > *vec) const
Definition: system_io.C:1121
Number point_value(unsigned int var, const Point &p, const bool insist_on_success=true) const
Definition: system.C:1993
const std::string & name() const
Definition: system.h:2017
void attach_constraint_function(void fptr(EquationSystems &es, const std::string &name))
Definition: system.C:1812
Gradient(* GradientFunctionPointer)(const Point &p, const Parameters &parameters, const std::string &sys_name, const std::string &unknown_name)
Definition: system.h:524
virtual void user_constrain()
Definition: system.C:1946
Real discrete_var_norm(const NumericVector< Number > &v, unsigned int var, FEMNormType norm_type) const
Definition: system.C:1359
virtual void assemble_qoi(const QoISet &qoi_indices=QoISet())
Definition: system.C:473
NumericVector< Number > & add_sensitivity_solution(unsigned int i=0)
Definition: system.C:906
unsigned int n_vars() const
Definition: system.h:2105
unsigned int add_variable(const std::string &var, const FEType &type, const std::set< subdomain_id_type > *const active_subdomains=nullptr)
Definition: system.C:1081
VectorValue< Number > NumberVectorValue
void(* _assemble_system_function)(EquationSystems &es, const std::string &name)
Definition: system.h:1835
virtual ~System()
Definition: system.C:120
numeric_index_type read_serialized_vector(Xdr &io, NumericVector< Number > &vec)
Definition: system.h:1785
bool assemble_before_solve
Definition: system.h:1477
System(EquationSystems &es, const std::string &name, const unsigned int number)
Definition: system.C:61
const DofMap & get_dof_map() const
Definition: system.h:2049
A geometric point in (x,y,z) space.
Definition: point.h:38
MeshBase & _mesh
Definition: system.h:1896
void read_serialized_data(Xdr &io, const bool read_additional_data=true)
Definition: system_io.C:725
const VariableGroup & variable_group(unsigned int vg) const
Definition: system.h:2143
void attach_init_function(void fptr(EquationSystems &es, const std::string &name))
Definition: system.C:1742
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
Definition: system_io.C:1815
NumericVector< Number > & get_weighted_sensitivity_adjoint_solution(unsigned int i=0)
Definition: system.C:1001
dof_id_type n_constrained_dofs() const
Definition: system.C:157
std::vector< unsigned int > _written_var_indices
Definition: system.h:1996
uint8_t dof_id_type
Definition: id_types.h:64
void write_header(Xdr &io, const std::string &version, const bool write_additional_data) const
Definition: system_io.C:1299
void(* _qoi_evaluate_derivative_function)(EquationSystems &es, const std::string &name, const QoISet &qoi_indices, bool include_liftfunc, bool apply_constraints)
Definition: system.h:1869
NumericVector< Number > & get_adjoint_rhs(unsigned int i=0)
Definition: system.C:1031
dof_id_type write_serialized_vector(Xdr &io, const NumericVector< Number > &vec) const
Definition: system_io.C:2156