Loading...
Searching...
No Matches
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-------------------------------------------------------------------------------
10License
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
26Class
27 Foam::functionObjects::norm
28
29Group
30 grpFieldFunctionObjects
31
32Description
33 Normalises an input field with a chosen norm, and outputs a new normalised
34 field.
35
36 Operands:
37 \table
38 Operand | Type | Location
39 input | {vol,surface,polySurface}TypeField | <time>/inputField
40 output file | - | -
41 output field | {vol,surface,polySurface}TypeField | <time>/outputField
42 \endtable
43
44 where \c Type can be one of:
45 \c Scalar, \c Vector, \c SphericalTensor, \c SymmTensor, or \c Tensor.
46
47Usage
48 Minimal example by using \c system/controlDict.functions:
49 \verbatim
50 normFO
51 {
52 // Mandatory entries
53 type norm;
54 libs (fieldFunctionObjects);
55 field <word>;
56 norm <word>;
57
58 // Conditional entries
59
60 // when norm == Lp
61 p <scalar>;
62
63 // when norm == composite
64 divisor <Function1<scalar>>;
65
66 // when norm == divisorField
67 divisorField <word>;
68
69 // Inherited entries
70 ...
71 }
72 \endverbatim
73
74 where the entries mean:
75 \table
76 Property | Description | Type | Reqd | Deflt
77 type | Type name: norm | word | yes | -
78 libs | Library name: fieldFunctionObjects | word | yes | -
79 field | Name of the operand field | word | yes | -
80 norm | Name of normalisation operation | word | yes | -
81 p | Norm exponent for the p-norm | scalar | cndtnl | -
82 divisor | Norm divisor for the composite norm <!--
83 --> | Function1<scalar> | cndtnl | -
84 divisorField | Divisor scalar field for the field norm <!--
85 --> | word | cndtnl | -
86 \endtable
87
88 Options for the \c norm entry:
89 \verbatim
90 L1 | L1/Taxicab norm
91 L2 | L2/Euclidean norm
92 Lp | p norm
93 max | Maximum norm
94 composite | Composite norm comprising Function1 divisor
95 divisorField | Normalise by a given field
96 \endverbatim
97
98 The inherited entries are elaborated in:
99 - \link fieldExpression.H \endlink
100 - \link Function1.H \endlink
101
102
103 The normalisations are held according to the following expressions:
104
105 - \c L1:
106
107 \f[
108 \mathbf{y} = \frac{\mathbf{x}}{\Sigma_{i=1}^n |x_i|}
109 \f]
110
111 - \c L2:
112
113 \f[
114 \mathbf{y} = \frac{\mathbf{x}}{\sqrt{x_1^2 + ... + x_n^2}}
115 \f]
116
117 - \c Lp:
118
119 \f[
120 \mathbf{y} = \frac{\mathbf{x}}{(\Sigma_{i=1}^n |x_i|^p)^{1/p}}
121 \f]
122
123 - \c max:
124
125 \f[
126 \mathbf{y} = \frac{\mathbf{x}}{max|x_i|}
127 \f]
128
129 - \c composite:
130
131 \f[
132 \mathbf{y} = \frac{\mathbf{x}}{f(t)}
133 \f]
134
135 - \c divisorField:
136
137 \f[
138 \mathbf{y} = \frac{\mathbf{x}}{\mathbf{z}}
139 \f]
140
141Note
142 - Divisor quantity is perturbed by \c SMALL value to prevent any divisions
143 by zero irrespective of whether the quantity is close to zero or not.
144
145SourceFiles
146 norm.C
147 normImpl.C
148
149\*---------------------------------------------------------------------------*/
150
151#ifndef Foam_functionObjects_norm_H
152#define Foam_functionObjects_norm_H
153
154#include "fieldExpression.H"
155#include "Function1.H"
156#include "polySurfaceFields.H"
157
158// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
159
160namespace Foam
161{
162namespace functionObjects
163{
164
165/*---------------------------------------------------------------------------*\
166 Class norm Declaration
167\*---------------------------------------------------------------------------*/
168
169class norm
170:
171 public fieldExpression
172{
173 // Private Enumerations
174
175 //- Options for the norm algorithm
176 enum normType : char
177 {
178 L1,
179 L2,
180 LP,
181 MAX,
182 COMPOSITE,
183 FIELD
184 };
185
186 //- Names for normType
187 static const Enum<normType> normTypeNames;
188
189
190 // Private Data
191
192 //- Norm algorithm
193 enum normType norm_;
194
195 //- Norm divisor for the composite norm
196 autoPtr<Function1<scalar>> divisorPtr_;
197
198 //- Divisor scalar field for the field norm
199 word divisorFieldName_;
200
201 //- Norm exponent for the p norm
202 scalar p_;
203
204
205 // Private Member Functions
206
207 //- Calculate the chosen norm of the field and register the result
208 template<class Type>
209 bool calcNorm();
210
211 //- Return the chosen norm of the field
212 template<class GeoFieldType>
213 tmp<GeoFieldType> calcNormType();
214
215 //- Return the divisor volScalarField
216 template<class Type>
217 tmp<volScalarField> fieldNorm
218 (
219 const GeometricField<Type, fvPatchField, volMesh>&
220 );
221
222 //- Return the divisor surfaceScalarField
223 template<class Type>
224 tmp<surfaceScalarField> fieldNorm
225 (
226 const GeometricField<Type, fvsPatchField, surfaceMesh>&
227 );
228
229 //- Return the divisor polySurfaceScalarField
230 template<class Type>
231 tmp<polySurfaceScalarField> fieldNorm
234 );
235
236 //- Calculate the chosen norm of the field and return true if successful
237 virtual bool calc();
238
239
240public:
241
242 //- Runtime type information
243 TypeName("norm");
244
245
246 // Constructors
247
248 //- Construct from name, Time and dictionary
249 norm
250 (
251 const word& name,
252 const Time& runTime,
253 const dictionary& dict
254 );
255
256 //- No copy construct
257 norm(const norm&) = delete;
258
259 //- No copy assignment
260 void operator=(const norm&) = delete;
261
262
263 //- Destructor
264 virtual ~norm() = default;
265
266
267 // Member Functions
268
269 //- Read the function-object dictionary
270 virtual bool read(const dictionary& dict);
271};
272
273
274// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
275
276} // End namespace functionObjects
277} // End namespace Foam
278
279// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
280
281#endif
282
283// ************************************************************************* //
Field with dimensions and associated with geometry type GeoMesh which is used to size the field and a...
Enum is a wrapper around a list of names/values that represent particular enumeration (or int) values...
Definition Enum.H:57
Generic GeometricField class.
Class to control time during OpenFOAM simulations that is also the top-level objectRegistry.
Definition Time.H:75
Pointer management similar to std::unique_ptr, with some additional methods and type checking.
Definition autoPtr.H:65
A list of keyword definitions, which are a keyword followed by a number of values (eg,...
Definition dictionary.H:133
Intermediate class for handling field expression function objects (e.g. blendingFactor etc....
fieldExpression(const word &name, const Time &runTime, const dictionary &dict, const word &fieldName=word::null, const word &resultName=word::null)
Construct from name, Time and dictionary.
virtual bool calc()=0
Calculate the components of the field and return true if successful.
Normalises an input field with a chosen norm, and outputs a new normalised field.
Definition norm.H:235
norm(const word &name, const Time &runTime, const dictionary &dict)
Construct from name, Time and dictionary.
Definition norm.C:75
virtual bool read(const dictionary &dict)
Read the function-object dictionary.
Definition norm.C:93
Foam::tmp< GeoFieldType > calcNormType()
Definition normImpl.C:63
norm(const norm &)=delete
No copy construct.
virtual ~norm()=default
Destructor.
void operator=(const norm &)=delete
No copy assignment.
TypeName("norm")
Runtime type information.
A class for managing temporary objects.
Definition tmp.H:75
A class for handling words, derived from Foam::string.
Definition word.H:66
engineTime & runTime
Function objects are OpenFOAM utilities to ease workflow configurations and enhance workflows.
Namespace for OpenFOAM.
word name(const expressions::valueTypeCode typeCode)
A word representation of a valueTypeCode. Empty for expressions::valueTypeCode::INVALID.
Definition exprTraits.C:127
Fields (face and point) for polySurface.
dictionary dict
#define TypeName(TypeNameString)
Declare a ClassName() with extra virtual type info.
Definition typeInfo.H:68