LagrangianFieldValue.H
Go to the documentation of this file.
1 /*---------------------------------------------------------------------------*\
2  ========= |
3  \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
4  \\ / O peration | Website: https://openfoam.org
5  \\ / A nd | Copyright (C) 2025 OpenFOAM Foundation
6  \\/ M anipulation |
7 -------------------------------------------------------------------------------
8 License
9  This file is part of OpenFOAM.
10 
11  OpenFOAM is free software: you can redistribute it and/or modify it
12  under the terms of the GNU General Public License as published by
13  the Free Software Foundation, either version 3 of the License, or
14  (at your option) any later version.
15 
16  OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
17  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
18  FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
19  for more details.
20 
21  You should have received a copy of the GNU General Public License
22  along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
23 
24 Class
25  Foam::functionObjects::LagrangianFieldValue
26 
27 Description
28  Function to log a single reduced quantity generated from the values in a
29  Lagrangian field; e.g., sums, averages, maximums and minimums.
30 
31 Usage
32  \table
33  Property | Description | Required? | Default
34  Lagrangian | Name of the Lagrangian mesh | yes |
35  field | Field to operate on | if fields not specified |
36  fields | List of fields to operate on | if field not specified |
37  weightField | Field with which to weight the distribution | no | none
38  weightFields | List of fields with which to \
39  weight the distribution | no | none
40  operation | The operation with which to \
41  combine Lagrangian values | yes |
42  writeLocation | Whether or not to write the location | no | false
43  \endtable
44 
45  Where \c operation is one of
46  \plaintable
47  sum | Sum
48  average | Ensemble average
49  min | Minimum (component minimum if a higher rank type)
50  max | Maximum (component maximum if a higher rank type)
51  minMag | Minimum magnitude
52  maxMag | Maximum magnitude
53  \endplaintable
54 
55  Example specification to generate the total mass:
56  \verbatim
57  LagrangianFieldValue1
58  {
59  type LagrangianFieldValue;
60  libs ("libLagrangianFunctionObjects.so");
61  Lagrangian cloud;
62  field m;
63  weightField number;
64  operation sum;
65  }
66  \endverbatim
67 
68 SourceFiles
69  LagrangianFieldValue.C
70 
71 \*---------------------------------------------------------------------------*/
72 
73 #ifndef LagrangianFieldValue_H
74 #define LagrangianFieldValue_H
75 
77 #include "logFiles.H"
78 #include "scalarField.H"
79 
80 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
81 
82 namespace Foam
83 {
84 namespace functionObjects
85 {
86 
87 /*---------------------------------------------------------------------------*\
88  Class LagrangianFieldValue Declaration
89 \*---------------------------------------------------------------------------*/
90 
91 class LagrangianFieldValue
92 :
93  public LagrangianMeshFunctionObject,
94  public logFiles
95 {
96 public:
97 
98  // Public Data Types
99 
100  //- Operation type enumeration
101  enum class operationType
102  {
103  sum,
104  average,
105  min,
106  max,
107  minMag,
108  maxMag
109  };
110 
111  //- Operation type names
112  static const NamedEnum<operationType, 6> operationTypeNames_;
113 
114 
115 private:
116 
117  // Private Data
118 
119  //- List of fields
120  wordList fields_;
121 
122  //- List of weight fields
123  wordList weightFields_;
124 
125  //- Operation to apply to values
126  operationType operation_;
127 
128  //- Write the location if available for this operation
129  Switch writeLocation_;
130 
131 
132  // Private Member Functions
133 
134  //- Non-virtual read
135  void readCoeffs(const dictionary& dict);
136 
137  //- Write a name
138  template<class Type>
139  void writeName(const word& name);
140 
141  //- Write a location name
142  template<class Type, class LocationType>
143  void writeLocationName(const word& name, const word& locationName);
144 
145  //- Write a name and a location name if we are writing the location
146  template<class Type>
147  void writeNameAndLocationNames(const word& name);
148 
149  //- Write a value
150  template<class Type>
151  void writeValue(const Type& value);
152 
153  //- Write a location value
154  template<class Type, class LocationType>
155  void writeLocationValue
156  (
157  const FixedList<LocationType, pTraits<Type>::nComponents>& value
158  );
159 
160  //- Write a value and location values if we are writing the location
161  template<class Type, class Op>
162  void writeValueAndLocationValues
163  (
164  const tmp<Field<Type>>& tField,
165  const scalar emptyValue,
166  const Op& op
167  );
168 
169  //- Multiply the argument by the given weight field. Return whether or
170  // not the weight field was found.
171  template<template<class> class GeoField>
172  bool multiplyWeight
173  (
174  const word& weightFieldName,
175  scalarField& weight
176  ) const;
177 
178  //- Write the field name for the given field. Return whether or not the
179  // field was found.
180  template<template<class> class GeoField, class Type>
181  bool writeFieldName(const word& fieldName);
182 
183  //- Write the column values for the given field name. Return whether or
184  // not the field was found.
185  template<template<class> class GeoField, class Type>
186  bool writeFieldValue
187  (
188  const scalarField& weight,
189  const word& fieldName
190  );
191 
192  //- Write file header information
193  virtual void writeFileHeader(const label i = 0);
194 
195 
196 public:
197 
198  //- Runtime type information
199  TypeName("LagrangianFieldValue");
200 
201 
202  // Constructors
203 
204  //- Construct from Time and dictionary
206  (
207  const word& name,
208  const Time& runTime,
209  const dictionary& dict
210  );
211 
212  //- Disallow default bitwise copy construction
214 
215 
216  //- Destructor
217  virtual ~LagrangianFieldValue();
218 
219 
220  // Member Functions
221 
222  //- Read parameters
223  virtual bool read(const dictionary&);
224 
225  //- Return the list of fields required
226  virtual wordList fields() const;
227 
228  //- Execute. Does nothing.
229  virtual bool execute();
230 
231  //- Write the sum
232  virtual bool write();
233 
234 
235  // Member Operators
236 
237  //- Disallow default bitwise assignment
238  void operator=(const LagrangianFieldValue&) = delete;
239 };
240 
241 
242 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
243 
244 } // End namespace functionObjects
245 } // End namespace Foam
246 
247 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
248 
249 #endif
250 
251 // ************************************************************************* //
Pre-declare SubField and related Field type.
Definition: Field.H:83
Class to control time during OpenFOAM simulations that is also the top-level objectRegistry.
Definition: Time.H:76
A list of keywords followed by any number of values (e.g. words and numbers) or sub-dictionaries.
Definition: dictionary.H:162
const word & name() const
Return the name of this functionObject.
Function to log a single reduced quantity generated from the values in a Lagrangian field; e....
virtual wordList fields() const
Return the list of fields required.
TypeName("LagrangianFieldValue")
Runtime type information.
LagrangianFieldValue(const word &name, const Time &runTime, const dictionary &dict)
Construct from Time and dictionary.
static const NamedEnum< operationType, 6 > operationTypeNames_
Operation type names.
void operator=(const LagrangianFieldValue &)=delete
Disallow default bitwise assignment.
virtual bool execute()
Execute. Does nothing.
virtual bool read(const dictionary &)
Read parameters.
A class for managing temporary objects.
Definition: tmp.H:55
A class for handling words, derived from string.
Definition: word.H:63
Namespace for OpenFOAM.
List< word > wordList
A List of words.
Definition: fileName.H:54
intWM_LABEL_SIZE_t label
A label is an int32_t or int64_t as specified by the pre-processor macro WM_LABEL_SIZE.
Definition: label.H:59
#define Op(opName, op)
Definition: ops.H:100
dictionary dict