norm.H
Go to the documentation of this file.
1 /*---------------------------------------------------------------------------*\
2  ========= |
3  \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
4  \\ / O peration |
5  \\ / A nd | www.openfoam.com
6  \\/ M anipulation |
7 -------------------------------------------------------------------------------
8  Copyright (C) 2022 OpenCFD Ltd.
9 -------------------------------------------------------------------------------
10 License
11  This file is part of OpenFOAM.
12 
13  OpenFOAM is free software: you can redistribute it and/or modify it
14  under the terms of the GNU General Public License as published by
15  the Free Software Foundation, either version 3 of the License, or
16  (at your option) any later version.
17 
18  OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
19  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
20  FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
21  for more details.
22 
23  You should have received a copy of the GNU General Public License
24  along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
25 
26 Class
27  Foam::functionObjects::norm
28 
29 Group
30  grpFieldFunctionObjects
31 
32 Description
33  Normalises an input field with a chosen norm,
34  and outputs a new normalised field.
35 
36  Operands:
37  \table
38  Operand | Type | Location
39  input | {vol,surface,polySurface}<Type>Field <!--
40  --> | <case>/<time>/<inpField>
41  output file | - | -
42  output field | {vol,surface,polySurface}<Type>Field <!--
43  --> | <case>/<time>/<outField>
44  \endtable
45 
46  where \c <Type>=Scalar/Vector/SphericalTensor/SymmTensor/Tensor.
47 
48 Usage
49  Minimal example by using \c system/controlDict.functions:
50  \verbatim
51  norm1
52  {
53  // Mandatory entries
54  type norm;
55  libs (fieldFunctionObjects);
56  field <word>;
57  norm <word>;
58 
59  // Conditional entries
60 
61  // when norm == Lp
62  p <scalar>;
63 
64  // when norm == composite
65  divisor <Function1<scalar>>;
66 
67  // when norm == divisorField
68  divisorField <word>;
69 
70  // Inherited entries
71  ...
72  }
73  \endverbatim
74 
75  where the entries mean:
76  \table
77  Property | Description | Type | Reqd | Deflt
78  type | Type name: norm | word | yes | -
79  libs | Library name: fieldFunctionObjects | word | yes | -
80  field | Name of the operand field | word | yes | -
81  norm | Name of normalisation operation | word | yes | -
82  p | Norm exponent for the p-norm | scalar | cndtnl | -
83  divisor | Norm divisor for the composite norm <!--
84  --> | Function1<scalar> | cndtnl | -
85  divisorField | Divisor scalar field for the field norm <!--
86  --> | word | cndtnl | -
87  \endtable
88 
89  Options for the \c norm entry:
90  \verbatim
91  L1 | L1/Taxicab norm
92  L2 | L2/Euclidean norm
93  Lp | p norm
94  max | Maximum norm
95  composite | Composite norm comprising Function1 divisor
96  divisorField | Normalise by a given field
97  \endverbatim
98 
99  The inherited entries are elaborated in:
100  - \link functionObject.H \endlink
101  - \link fieldExpression.H \endlink
102  - \link Function1.H \endlink
103 
104 
105  The normalisations are held according to the following expressions:
106 
107  - \c L1:
108 
109  \f[
110  \mathbf{y} = \frac{\mathbf{x}}{\Sigma_{i=1}^n |x_i|}
111  \f]
112 
113  - \c L2:
114 
115  \f[
116  \mathbf{y} = \frac{\mathbf{x}}{\sqrt{x_1^2 + ... + x_n^2}}
117  \f]
118 
119  - \c Lp:
120 
121  \f[
122  \mathbf{y} = \frac{\mathbf{x}}{(\Sigma_{i=1}^n |x_i|^p)^{1/p}}
123  \f]
124 
125  - \c max:
126 
127  \f[
128  \mathbf{y} = \frac{\mathbf{x}}{max|x_i|}
129  \f]
130 
131  - \c composite:
132 
133  \f[
134  \mathbf{y} = \frac{\mathbf{x}}{f(t)}
135  \f]
136 
137  - \c divisorField:
138 
139  \f[
140  \mathbf{y} = \frac{\mathbf{x}}{\mathbf{z}}
141  \f]
142 
143 Note
144  - Divisor quantity is perturbed by \c SMALL value to prevent any divisions
145  by zero irrespective of whether the quantity is close to zero or not.
146 
147 SourceFiles
148  norm.C
149  normImpl.C
150 
151 \*---------------------------------------------------------------------------*/
152 
153 #ifndef functionObjects_norm_H
154 #define functionObjects_norm_H
155 
156 #include "fieldExpression.H"
157 #include "Function1.H"
158 #include "polySurfaceFields.H"
159 
160 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
161 
162 namespace Foam
163 {
164 namespace functionObjects
165 {
166 
167 /*---------------------------------------------------------------------------*\
168  Class norm Declaration
169 \*---------------------------------------------------------------------------*/
170 
171 class norm
172 :
173  public fieldExpression
174 {
175  // Private Enumerations
176 
177  //- Options for the norm algorithm
178  enum normType : char
179  {
180  L1,
181  L2,
182  LP,
183  MAX,
184  COMPOSITE,
185  FIELD
186  };
187 
188  //- Names for normType
189  static const Enum<normType> normTypeNames;
190 
191 
192  // Private Data
193 
194  //- Norm algorithm
195  enum normType norm_;
196 
197  //- Norm divisor for the composite norm
198  autoPtr<Function1<scalar>> divisorPtr_;
199 
200  //- Divisor scalar field for the field norm
201  word divisorFieldName_;
202 
203  //- Norm exponent for the p norm
204  scalar p_;
205 
206 
207  // Private Member Functions
208 
209  //- Calculate the chosen norm of the field and register the result
210  template<class Type>
211  bool calcNorm();
212 
213  //- Return the chosen norm of the field
214  template<class GeoFieldType>
215  tmp<GeoFieldType> calcNormType();
216 
217  //- Return the divisor volScalarField
218  template<class Type>
219  tmp<volScalarField> fieldNorm
220  (
221  const GeometricField<Type, fvPatchField, volMesh>&
222  );
223 
224  //- Return the divisor surfaceScalarField
225  template<class Type>
226  tmp<surfaceScalarField> fieldNorm
227  (
228  const GeometricField<Type, fvsPatchField, surfaceMesh>&
229  );
230 
231  //- Return the divisor polySurfaceScalarField
232  template<class Type>
233  tmp<polySurfaceScalarField> fieldNorm
234  (
235  const DimensionedField<Type, polySurfaceGeoMesh>&
236  );
237 
238  //- Calculate the chosen norm of the field and return true if successful
239  virtual bool calc();
240 
241 
242 public:
243 
244  //- Runtime type information
245  TypeName("norm");
246 
247 
248  // Constructors
249 
250  //- Construct from name, Time and dictionary
251  norm
252  (
253  const word& name,
254  const Time& runTime,
255  const dictionary& dict
256  );
257 
258  //- No copy construct
259  norm(const norm&) = delete;
260 
261  //- No copy assignment
262  void operator=(const norm&) = delete;
263 
264 
265  //- Destructor
266  virtual ~norm() = default;
267 
268 
269  // Member Functions
270 
271  //- Read the dictionary data
272  virtual bool read(const dictionary&);
273 };
274 
275 
276 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
277 
278 } // End namespace functionObjects
279 } // End namespace Foam
280 
281 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
282 
283 #endif
284 
285 // ************************************************************************* //
dictionary dict
A list of keyword definitions, which are a keyword followed by a number of values (eg...
Definition: dictionary.H:129
norm(const word &name, const Time &runTime, const dictionary &dict)
Construct from name, Time and dictionary.
Definition: norm.C:75
Fields (face and point) for polySurface.
engineTime & runTime
Class to control time during OpenFOAM simulations that is also the top-level objectRegistry.
Definition: Time.H:69
const word & name() const noexcept
Return the name of this functionObject.
virtual ~norm()=default
Destructor.
A class for handling words, derived from Foam::string.
Definition: word.H:63
TypeName("norm")
Runtime type information.
Normalises an input field with a chosen norm, and outputs a new normalised field. ...
Definition: norm.H:238
void operator=(const norm &)=delete
No copy assignment.
Namespace for OpenFOAM.
virtual bool read(const dictionary &)
Read the dictionary data.
Definition: norm.C:93