TimeFunction_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 "DimensionedField.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  funcPtr_
41  (
42  Foam::Function1<typename DimensionedFieldType::Type_>::New
43  (
44  "function",
45  field.time().userUnits(),
46  field.dimensions(),
47  dict
48  )
49  )
50 {}
51 
52 
53 template<class DimensionedFieldType>
56 (
57  const TimeFunction& dff,
58  DimensionedFieldType& field
59 )
60 :
61  DimensionedFieldFunction<DimensionedFieldType>(dff, field),
62  funcPtr_(dff.funcPtr_, false)
63 {}
64 
65 
66 template<class DimensionedFieldType>
69 (
70  DimensionedFieldType& field
71 ) const
72 {
74  (
75  new TimeFunction<DimensionedFieldType>(*this, field)
76  );
77 }
78 
79 
80 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
81 
82 template<class DimensionedFieldType>
84 evaluate()
85 {
86  this->field_.primitiveFieldRef() =
87  funcPtr_->value(this->field_.time().value());
88 }
89 
90 
91 template<class DimensionedFieldType>
93 update()
94 {
95  evaluate();
96  return true;
97 }
98 
99 
100 template<class DimensionedFieldType>
102 (
103  Ostream& os
104 ) const
105 {
106  writeEntry(os, dimLength, this->field_.dimensions(), funcPtr_());
107 }
108 
109 
110 // ************************************************************************* //
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.
Time dependent internal and patch field initialisation and update function.
virtual void evaluate()
Evaluate the function and set the field.
virtual void write(Ostream &os) const
Write data to dictionary stream.
TimeFunction(const dictionary &dict, DimensionedFieldType &field)
Construct with dictionary to initialise given field.
virtual bool update()
Update the field for the current time.
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
const dimensionSet time
Namespace for OpenFOAM.
const dimensionSet & dimLength
Definition: dimensions.C:141
void evaluate(GeometricField< Type, GeoMesh > &result, const Function1< Type > &func, const GeometricField< Type, GeoMesh > &x)
tmp< DimensionedField< TypeR, GeoMesh, Field > > New(const tmp< DimensionedField< TypeR, GeoMesh, Field >> &tdf1, const word &name, const dimensionSet &dimensions)
void writeEntry(Ostream &os, const word &key, const DimensionedFieldFunction< DimensionedFieldType > &f)
dictionary dict