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  }
65  \endverbatim
66 
67 SourceFiles
68  LagrangianFieldValue.C
69 
70 \*---------------------------------------------------------------------------*/
71 
72 #ifndef LagrangianFieldValue_H
73 #define LagrangianFieldValue_H
74 
76 #include "logFiles.H"
77 #include "scalarField.H"
78 
79 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
80 
81 namespace Foam
82 {
83 namespace functionObjects
84 {
85 
86 /*---------------------------------------------------------------------------*\
87  Class LagrangianFieldValue Declaration
88 \*---------------------------------------------------------------------------*/
89 
90 class LagrangianFieldValue
91 :
92  public LagrangianMeshFunctionObject,
93  public logFiles
94 {
95 public:
96 
97  // Public Data Types
98 
99  //- Operation type enumeration
100  enum class operationType
101  {
102  sum,
103  average,
104  min,
105  max,
106  minMag,
107  maxMag
108  };
109 
110  //- Operation type names
111  static const NamedEnum<operationType, 6> operationTypeNames_;
112 
113 
114 private:
115 
116  // Private Data
117 
118  //- List of fields
119  wordList fields_;
120 
121  //- List of weight fields
122  wordList weightFields_;
123 
124  //- Operation to apply to values
125  operationType operation_;
126 
127  //- Write the location if available for this operation
128  Switch writeLocation_;
129 
130 
131  // Private Member Functions
132 
133  //- Non-virtual read
134  void readCoeffs(const dictionary& dict);
135 
136  //- Write a name
137  template<class Type>
138  void writeName(const word& name);
139 
140  //- Write a location name
141  template<class Type, class LocationType>
142  void writeLocationName(const word& name, const word& locationName);
143 
144  //- Write a name and a location name if we are writing the location
145  template<class Type>
146  void writeNameAndLocationNames(const word& name);
147 
148  //- Write a value
149  template<class Type>
150  void writeValue(const Type& value);
151 
152  //- Write a location value
153  template<class Type, class LocationType>
154  void writeLocationValue
155  (
156  const FixedList<LocationType, pTraits<Type>::nComponents>& value
157  );
158 
159  //- Write a value and location values if we are writing the location
160  template<class Type, class Op>
161  void writeValueAndLocationValues
162  (
163  const tmp<Field<Type>>& tField,
164  const scalar emptyValue,
165  const Op& op
166  );
167 
168  //- Multiply the argument by the given weight field. Return whether or
169  // not the weight field was found.
170  template<template<class> class GeoField>
171  bool multiplyWeight
172  (
173  const word& weightFieldName,
174  scalarField& weight
175  ) const;
176 
177  //- Write the field name for the given field. Return whether or not the
178  // field was found.
179  template<template<class> class GeoField, class Type>
180  bool writeFieldName(const word& fieldName);
181 
182  //- Write the column values for the given field name. Return whether or
183  // not the field was found.
184  template<template<class> class GeoField, class Type>
185  bool writeFieldValue
186  (
187  const scalarField& weight,
188  const word& fieldName
189  );
190 
191  //- Write file header information
192  virtual void writeFileHeader(const label i = 0);
193 
194 
195 public:
196 
197  //- Runtime type information
198  TypeName("LagrangianFieldValue");
199 
200 
201  // Constructors
202 
203  //- Construct from Time and dictionary
205  (
206  const word& name,
207  const Time& runTime,
208  const dictionary& dict
209  );
210 
211  //- Disallow default bitwise copy construction
213 
214 
215  //- Destructor
216  virtual ~LagrangianFieldValue();
217 
218 
219  // Member Functions
220 
221  //- Read parameters
222  virtual bool read(const dictionary&);
223 
224  //- Return the list of fields required
225  virtual wordList fields() const;
226 
227  //- Execute. Does nothing.
228  virtual bool execute();
229 
230  //- Write the sum
231  virtual bool write();
232 
233 
234  // Member Operators
235 
236  //- Disallow default bitwise assignment
237  void operator=(const LagrangianFieldValue&) = delete;
238 };
239 
240 
241 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
242 
243 } // End namespace functionObjects
244 } // End namespace Foam
245 
246 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
247 
248 #endif
249 
250 // ************************************************************************* //
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:62
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