Zonal_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 #include "zoneGenerator.H"
29 
30 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
31 
32 template<class DimensionedFieldType>
34 Zonal
35 (
36  const dictionary& dict,
37  DimensionedFieldType& field
38 )
39 :
40  DimensionedFieldFunction<DimensionedFieldType>(dict, field),
41  value_
42  (
43  dict.lookup<Type>
44  (
45  "defaultValue",
46  typeUnits<Type>(this->field_.dimensions())
47  )
48  ),
49  zonesDict_(dict.subDict("zones"))
50 {}
51 
52 
53 template<class DimensionedFieldType>
55 Zonal
56 (
57  const Zonal& dff,
58  DimensionedFieldType& field
59 )
60 :
61  DimensionedFieldFunction<DimensionedFieldType>(dff, field),
62  value_(dff.value_),
63  zonesDict_(dff.zonesDict_)
64 {}
65 
66 
67 template<class DimensionedFieldType>
70 (
71  DimensionedFieldType& field
72 ) const
73 {
75  (
76  new Zonal<DimensionedFieldType>(*this, field)
77  );
78 }
79 
80 
81 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
82 
83 template<class DimensionedFieldType>
85 {
86  DimensionedFieldType& field = this->field_;
87 
88  const polyMesh& mesh(field.mesh()());
89 
90  field.primitiveFieldRef() = value_;
91 
92  forAllConstIter(dictionary, zonesDict_, iter)
93  {
94  const dictionary& zoneDict = iter().dict();
95 
97 
98  if (zoneDict.found("zoneType"))
99  {
100  zg = zoneGenerator::New(iter().keyword(), mesh, zoneDict);
101  }
102  else
103  {
104  zg = zoneGenerator::New
105  (
106  iter().keyword(),
107  zoneType<Zone>(),
108  mesh,
109  zoneDict
110  );
111  }
112 
113  const zoneSet zs(zg->generate());
114 
115  if (zs.valid<Zone>())
116  {
117  const labelList& selected = zs.zone<Zone>();
118 
119  const Type value
120  (
121  zoneDict.lookup<Type>
122  (
123  "value",
124  typeUnits<Type>(field.dimensions())
125  )
126  );
127 
128  if (&selected == &labelList::null())
129  {
130  field.primitiveFieldRef() = value;
131  }
132  else
133  {
134  forAll(selected, i)
135  {
136  field[selected[i]] = value;
137  }
138  }
139  }
140  }
141 }
142 
143 
144 template<class DimensionedFieldType>
146 (
147  Ostream& os
148 ) const
149 {
150  writeEntry
151  (
152  os,
153  "defaultValue",
154  typeUnits<Type>(this->field_.dimensions()),
155  value_
156  );
157  writeEntry(os, "zones", zonesDict_);
158 }
159 
160 
161 // ************************************************************************* //
#define forAll(list, i)
Loop across all elements in list.
Definition: UList.H:449
#define forAllConstIter(Container, container, iter)
Iterate across all elements in the container object of type.
Definition: UList.H:492
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.
Zonal internal and patch field initialisation function.
Zonal(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.
static const List< label > & null()
Return a null List.
Definition: ListI.H:118
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
ITstream & lookup(const word &, bool recursive=false, bool patternMatch=true) const
Find and return an entry data stream.
Definition: dictionary.C:669
bool found(const word &, bool recursive=false, bool patternMatch=true) const
Search dictionary for given keyword.
Definition: dictionary.C:468
Mesh consisting of general polyhedral cells.
Definition: polyMesh.H:78
static autoPtr< zoneGenerator > New(const word &name, const polyMesh &mesh, const dictionary &dict)
Select constructed from name, mesh and dictionary.
Definition: zoneGenerator.C:66
Zone container returned by zoneGenerator::generate.
Definition: zoneSet.H:94
bool valid() const
Return true if any of the zone types are allocated.
Definition: zoneSetI.H:188
const ZoneType & zone() const
Return a reference to the zone type.
Foam::fvMesh mesh(Foam::IOobject(regionName, runTime.name(), runTime, Foam::IOobject::MUST_READ), false)
const unitSet & lookup(const word &unitName)
Lookup and return the named unit from the table.
Definition: units.C:346
void writeEntry(Ostream &os, const word &key, const DimensionedFieldFunction< DimensionedFieldType > &f)
const typeUnitsType< Type >::type & typeUnits(const unitSet &)
dictionary dict