Surfaces_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 
28 
29 // * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
30 
31 template<class DimensionedFieldType>
34 {
35  const objectRegistry& db = this->field_.mesh().db();
36 
37  surfacesPtr_.set
38  (
39  new searchableSurfaceList
40  (
41  IOobject
42  (
44  db.time().constant(),
45  searchableSurface::geometryDir(db.time()),
46  db,
47  IOobject::MUST_READ,
48  IOobject::NO_WRITE
49  ),
50  surfacesDict_,
51  false
52  )
53  );
54 
55  values_.setSize(surfacesPtr_().size());
56 
57  forAll(surfacesPtr_(), i)
58  {
59  values_.set
60  (
61  i,
62  new dimensioned<Type>
63  (
64  "value",
65  this->field_.dimensions(),
66  surfacesDict_.subDict(surfacesPtr_()[i].name())
67  )
68  );
69  }
70 }
71 
72 
73 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
74 
75 template<class DimensionedFieldType>
77 (
78  const dictionary& dict,
79  DimensionedFieldType& field
80 )
81 :
82  DimensionedFieldFunction<DimensionedFieldType>(dict, field),
83  defaultValue_("defaultValue", this->field_.dimensions(), dict),
84  surfacesDict_(dict.subDict("surfaces"))
85 {
86  readSurfacesAndValues();
87 }
88 
89 
90 template<class DimensionedFieldType>
92 (
93  const Surfaces& dff,
94  DimensionedFieldType& field
95 )
96 :
97  DimensionedFieldFunction<DimensionedFieldType>(dff, field),
98  defaultValue_(dff.defaultValue_),
99  surfacesDict_(dff.surfacesDict_)
100 {
101  readSurfacesAndValues();
102 }
103 
104 
105 template<class DimensionedFieldType>
107 <
110 (
111  DimensionedFieldType& field
112 ) const
113 {
115  (
116  new Surfaces<DimensionedFieldType>(*this, field)
117  );
118 }
119 
120 
121 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
122 
123 template<class DimensionedFieldType>
125 {
126  this->field_ = defaultValue_;
127 
128  forAll(surfacesPtr_(), i)
129  {
130  this->field_ +=
132  <
133  scalar,
134  typename DimensionedFieldType::GeoMesh_
135  >::New
136  (
137  IOobject::groupName("alpha", surfacesPtr_()[i].name()),
138  this->field_.mesh(),
139  dimless,
141  (
142  surfacesPtr_()[i],
143  this->field_.mesh().poly()
144  )
145  )
146  *(values_[i] - this->field_);
147  }
148 }
149 
150 
151 template<class DimensionedFieldType>
153 (
154  Ostream& os
155 ) const
156 {
157  writeEntry(os, defaultValue_);
158  writeEntry(os, surfacesDict_.dictName(), surfacesDict_);
159 }
160 
161 
162 // ************************************************************************* //
#define forAll(list, i)
Loop across all elements in list.
Definition: UList.H:449
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.
Dimensioned field function which sets constant values inside a set of surfaces, and a default value e...
Surfaces(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.
Field with dimensions and associated with geometry type GeoMesh which is used to size the field and a...
static word groupName(Name name, const word &group)
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
tmp< scalarField > insideFraction(const searchableSurface &surface, const polyMesh &mesh)
Return a cell-field of the volume fraction inside the given surface.
const dimensionSet & dimless
Definition: dimensions.C:138
String typeName(const std::type_info &info)
Return the un-mangled name given the standard type info.
word name(const LagrangianState state)
Return a string representation of a Lagrangian state enumeration.
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