libMesh
system_norm.h
Go to the documentation of this file.
1 // The libMesh Finite Element Library.
2 // Copyright (C) 2002-2025 Benjamin S. Kirk, John W. Peterson, Roy H. Stogner
3 
4 // This library is free software; you can redistribute it and/or
5 // modify it under the terms of the GNU Lesser General Public
6 // License as published by the Free Software Foundation; either
7 // version 2.1 of the License, or (at your option) any later version.
8 
9 // This library is distributed in the hope that it will be useful,
10 // but WITHOUT ANY WARRANTY; without even the implied warranty of
11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 // Lesser General Public License for more details.
13 
14 // You should have received a copy of the GNU Lesser General Public
15 // License along with this library; if not, write to the Free Software
16 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17 
18 
19 
20 #ifndef LIBMESH_SYSTEM_NORM_H
21 #define LIBMESH_SYSTEM_NORM_H
22 
23 // Local includes
24 #include "libmesh/libmesh_common.h" // for Real
25 
26 // C++ includes
27 #include <vector>
28 
29 namespace libMesh
30 {
31 
32 // Forward declarations
33 enum FEMNormType : int;
34 
50 {
51 public:
52 
56  SystemNorm();
57 
66  SystemNorm(const FEMNormType & t);
67 
75  explicit
76  SystemNorm(std::vector<FEMNormType> norms);
77 
85  SystemNorm(std::vector<FEMNormType> norms,
86  std::vector<Real> & weights);
87 
95  SystemNorm(std::vector<FEMNormType> norms,
96  std::vector<std::vector<Real>> & weights);
97 
102  SystemNorm (const SystemNorm &) = default;
103  SystemNorm (SystemNorm &&) = default;
104  SystemNorm & operator= (const SystemNorm &) = default;
105  SystemNorm & operator= (SystemNorm &&) = default;
106  virtual ~SystemNorm() = default;
107 
111  bool is_discrete() const;
112 
117  Real calculate_norm(const std::vector<Real> & v);
118 
122  Real calculate_norm(const std::vector<Real> & v1,
123  const std::vector<Real> & v2);
124 
128  bool is_identity();
129 
137  FEMNormType type(unsigned int var) const;
138 
143  void set_type(unsigned int var, const FEMNormType & t);
144 
152  Real weight(unsigned int var) const;
153 
158  void set_weight(unsigned int var, Real w);
159 
163  void set_off_diagonal_weight(unsigned int i, unsigned int j, Real w);
164 
169  Real weight_sq(unsigned int var) const;
170 
171 
172 
173 private:
174  std::vector<FEMNormType> _norms;
175 
176  std::vector<Real> _weights;
177  std::vector<Real> _weights_sq;
178 
183  std::vector<std::vector<Real>> _off_diagonal_weights;
184 };
185 
186 } // namespace libMesh
187 
188 #endif // LIBMESH_SYSTEM_NORM_H
std::vector< FEMNormType > _norms
Definition: system_norm.h:174
FEMNormType
defines an enum for norms defined on vectors of finite element coefficients
std::vector< Real > _weights_sq
Definition: system_norm.h:177
virtual ~SystemNorm()=default
This class defines a norm/seminorm to be applied to a NumericVector which contains coefficients in a ...
Definition: system_norm.h:49
bool is_discrete() const
Definition: system_norm.C:99
The libMesh namespace provides an interface to certain functionality in the library.
void set_off_diagonal_weight(unsigned int i, unsigned int j, Real w)
Sets the weight corresponding to the norm from the variable pair v1(var1) coming from v2(var2)...
Definition: system_norm.C:156
void set_weight(unsigned int var, Real w)
Sets the weight corresponding to the norm in variable var, as well as for any unset variables with in...
Definition: system_norm.C:142
FEMNormType type(unsigned int var) const
Definition: system_norm.C:112
SystemNorm & operator=(const SystemNorm &)=default
Real weight_sq(unsigned int var) const
Definition: system_norm.C:177
Real weight(unsigned int var) const
Definition: system_norm.C:134
DIE A HORRIBLE DEATH HERE typedef LIBMESH_DEFAULT_SCALAR_TYPE Real
Real calculate_norm(const std::vector< Real > &v)
Definition: system_norm.C:232
std::vector< std::vector< Real > > _off_diagonal_weights
One more data structure needed to store the off diagonal components for the generalize SystemNorm cas...
Definition: system_norm.h:183
std::vector< Real > _weights
Definition: system_norm.h:176
void set_type(unsigned int var, const FEMNormType &t)
Sets the type of the norm in variable var, as well as for any unset variables with index less than va...
Definition: system_norm.C:123
SystemNorm()
Constructor, defaults to DISCRETE_L2 with weight of 1.0.
Definition: system_norm.C:27
void ErrorVector unsigned int
Definition: adjoints_ex3.C:360