FieldFunction_DimensionedFieldFunction.C
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) 2026 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 \*---------------------------------------------------------------------------*/
25 
27 #include "GeometricField.H"
28 
29 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
30 
31 template<class DimensionedFieldType>
34 (
35  const dictionary& dict,
36  DimensionedFieldType& field
37 )
38 :
39  DimensionedFieldFunction<DimensionedFieldType>(dict, field),
40  fieldName_(dict.lookup<word>("field")),
41  funcPtr_(nullptr),
42  dictPtr_(new dictionary(dict))
43 {}
44 
45 
46 template<class DimensionedFieldType>
49 (
50  const FieldFunction& dff,
51  DimensionedFieldType& field
52 )
53 :
54  DimensionedFieldFunction<DimensionedFieldType>(dff, field),
55  fieldName_(dff.fieldName_),
56  funcPtr_(dff.funcPtr_, false),
57  dictPtr_(nullptr)
58 {}
59 
60 
61 template<class DimensionedFieldType>
64 (
65  DimensionedFieldType& field
66 ) const
67 {
69  (
70  new FieldFunction<DimensionedFieldType>(*this, field)
71  );
72 }
73 
74 
75 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
76 
77 template<class DimensionedFieldType>
79 evaluate()
80 {
81  typedef
83  scalarFieldType;
84 
86  this->field_.mesh().template lookupField<scalar>(fieldName_);
87 
88  if (dictPtr_.valid())
89  {
90  funcPtr_.set
91  (
93  (
94  "function",
95  tx().dimensions(),
96  this->field_.dimensions(),
97  dictPtr_()
98  ).ptr()
99  );
100 
101  dictPtr_.clear();
102  }
103 
104  this->field_.primitiveFieldRef() = funcPtr_->value(tx().primitiveField());
105 }
106 
107 
108 template<class DimensionedFieldType>
110 update()
111 {
112  evaluate();
113  return true;
114 }
115 
116 
117 template<class DimensionedFieldType>
119 (
120  Ostream& os
121 ) const
122 {
123  typedef
125  scalarFieldType;
126 
127  writeEntry(os, "field", fieldName_);
128 
129  if (dictPtr_.valid())
130  {
131  writeEntry(os, "function", dictPtr_());
132  }
133  else
134  {
136  this->field_.mesh().template lookupField<scalar>(fieldName_);
137 
138  writeEntry
139  (
140  os,
141  tx().dimensions(),
142  this->field_.dimensions(),
143  funcPtr_()
144  );
145  }
146 }
147 
148 
149 // ************************************************************************* //
Base class for run-time selectable internal and patch field initialisation evaluation and update with...
virtual autoPtr< DimensionedFieldFunction< DimensionedFieldType > > clone() const
Construct and return a clone for the specified field.
Field function which looks up another field and uses it as the argument to evaluate a given Foam::Fun...
virtual void evaluate()
Evaluate the function and set the field.
virtual void write(Ostream &os) const
Write data to dictionary stream.
virtual bool update()
Update the field for the current time.
FieldFunction(const dictionary &dict, DimensionedFieldType &field)
Construct with dictionary to initialise given field.
Field with dimensions and associated with geometry type GeoMesh which is used to size the field and a...
Run-time selectable general function of one variable.
Definition: Function1.H:62
An Ostream is an abstract base class for all output systems (streams, files, token lists,...
Definition: Ostream.H:57
An auto-pointer similar to the STL auto_ptr but with automatic casting to a reference to the type and...
Definition: autoPtr.H:51
A list of keywords followed by any number of values (e.g. words and numbers) or sub-dictionaries.
Definition: dictionary.H:162
A class for managing temporary objects.
Definition: tmp.H:55
A class for handling words, derived from string.
Definition: word.H:63
const unitSet & lookup(const word &unitName)
Lookup and return the named unit from the table.
Definition: units.C:346
void evaluate(GeometricField< Type, GeoMesh > &result, const Function1< Type > &func, const GeometricField< Type, GeoMesh > &x)
void writeEntry(Ostream &os, const word &key, const DimensionedFieldFunction< DimensionedFieldType > &f)
dictionary dict