Zonal_DimensionedFvPatchFieldFunction.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_(dict.lookup<Type>("defaultValue", this->field_.dimensions())),
42  zonesDict_(dict.subDict("zones"))
43 {
44  evaluate();
45 }
46 
47 
48 template<class DimensionedFieldType>
50 Zonal
51 (
52  const Zonal& dff,
53  DimensionedFieldType& field
54 )
55 :
56  DimensionedFieldFunction<DimensionedFieldType>(dff, field),
57  value_(dff.value_),
58  zonesDict_(dff.zonesDict_)
59 {}
60 
61 
62 template<class DimensionedFieldType>
65 (
66  DimensionedFieldType& field
67 ) const
68 {
69  return autoPtr<DimensionedFieldFunction<DimensionedFieldType>>
70  (
71  new Zonal<DimensionedFieldType>(*this, field)
72  );
73 }
74 
75 
76 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
77 
78 template<class DimensionedFieldType>
80 {
81  DimensionedFieldType& field = this->field_;
82 
83  const fvMesh& mesh(field.mesh()());
84 
85  field.primitiveFieldRef() = value_;
86 
87  forAllConstIter(dictionary, zonesDict_, iter)
88  {
89  const dictionary& zoneDict = iter().dict();
90 
91  autoPtr<zoneGenerator> zg
92  (
94  (
95  iter().keyword(),
96  zoneType<Zone>(),
97  mesh,
98  zoneDict
99  )
100  );
101 
102  const zoneSet zs(zg->generate());
103 
104  if (zs.valid<Zone>())
105  {
106  const labelList& selected = zs.zone<Zone>();
107 
108  const Type value
109  (
110  zoneDict.lookup<Type>("value", field.dimensions())
111  );
112 
113  if (&selected == &labelList::null())
114  {
115  field.primitiveFieldRef() = value;
116  }
117  else
118  {
119  forAll(selected, i)
120  {
121  const label patchi =
122  mesh.poly().boundary().whichPatch(selected[i]);
123  if (patchi == field.mesh().index())
124  {
125  field[selected[i] - field.mesh().start()] = value;
126  }
127  }
128  }
129  }
130  }
131 }
132 
133 
134 template<class DimensionedFieldType>
136 (
137  Ostream& os
138 ) const
139 {
140  writeEntry(os, "defaultValue", this->field_.dimensions(), value_);
141  writeEntry(os, "zones", zonesDict_);
142 }
143 
144 
145 // ************************************************************************* //
#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
virtual autoPtr< DimensionedFieldFunction< DimensionedFieldType > > clone() const
Construct and return a clone for the specified field.
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.
An auto-pointer similar to the STL auto_ptr but with automatic casting to a reference to the type and...
Definition: autoPtr.H:51
const polyMesh & poly() const
Return reference to polyMesh.
Definition: fvMesh.H:456
label whichPatch(const label faceIndex) const
Return patch index for a given face label.
const polyBoundaryMesh & boundary() const
Return boundary mesh.
Definition: polyMesh.H:393
Foam::fvMesh mesh(Foam::IOobject(regionName, runTime.name(), runTime, Foam::IOobject::MUST_READ), false)
label patchi
const unitSet & lookup(const word &unitName)
Lookup and return the named unit from the table.
Definition: units.C:346
List< label > labelList
A List of labels.
Definition: labelList.H:56
intWM_LABEL_SIZE_t label
A label is an int32_t or int64_t as specified by the pre-processor macro WM_LABEL_SIZE.
Definition: label.H:59
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