DistanceFunction_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  dimLength,
46  field.dimensions(),
47  dict
48  )
49  ),
50  direction_(normalised(dict.lookup<vector>("direction")))
51 {}
52 
53 
54 template<class DimensionedFieldType>
57 (
58  const DistanceFunction& dff,
59  DimensionedFieldType& field
60 )
61 :
62  DimensionedFieldFunction<DimensionedFieldType>(dff, field),
63  funcPtr_(dff.funcPtr_, false),
64  direction_(dff.direction_)
65 {}
66 
67 
68 template<class DimensionedFieldType>
71 (
72  DimensionedFieldType& field
73 ) const
74 {
76  (
78  );
79 }
80 
81 
82 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
83 
84 template<class DimensionedFieldType>
86 evaluate()
87 {
88  this->field_.primitiveFieldRef() =
89  funcPtr_->value(direction_ & this->field_.mesh().C());
90 }
91 
92 
93 template<class DimensionedFieldType>
95 write
96 (
97  Ostream& os
98 ) const
99 {
100  writeEntry(os, dimLength, this->field_.dimensions(), funcPtr_());
101  writeEntry(os, "direction", direction_);
102 }
103 
104 
105 // ************************************************************************* //
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.
Distance function internal and patch field initialisation function.
DistanceFunction(const dictionary &dict, DimensionedFieldType &field)
Construct with dictionary to initialise given field.
virtual void evaluate()
Evaluate the function and set the field.
virtual void write(Ostream &os) const
Write data to dictionary stream.
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 unitSet & lookup(const word &unitName)
Lookup and return the named unit from the table.
Definition: units.C:346
Namespace for OpenFOAM.
const dimensionSet & dimLength
Definition: dimensions.C:141
dimensionSet normalised(const dimensionSet &)
Definition: dimensionSet.C:509
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