fvMeshSubsetProxyTemplates.C
Go to the documentation of this file.
1 /*---------------------------------------------------------------------------*\
2  ========= |
3  \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
4  \\ / O peration |
5  \\ / A nd | www.openfoam.com
6  \\/ M anipulation |
7 -------------------------------------------------------------------------------
8  Copyright (C) 2011-2016 OpenFOAM Foundation
9  Copyright (C) 2016-2021 OpenCFD Ltd.
10 -------------------------------------------------------------------------------
11 License
12  This file is part of OpenFOAM.
13 
14  OpenFOAM is free software: you can redistribute it and/or modify it
15  under the terms of the GNU General Public License as published by
16  the Free Software Foundation, either version 3 of the License, or
17  (at your option) any later version.
18 
19  OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
20  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
21  FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
22  for more details.
23 
24  You should have received a copy of the GNU General Public License
25  along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
26 
27 \*---------------------------------------------------------------------------*/
28 
29 #include "fvMeshSubsetProxy.H"
30 #include "volFields.H"
31 
32 // * * * * * * * * * * * * * Static Member Functions * * * * * * * * * * * * //
33 
34 template<class Type>
36 <
38 >
40 (
41  const DimensionedField<Type, volMesh>& df
42 )
43 {
44  IOobject io(df);
45  io.readOpt(IOobject::NO_READ);
46  io.writeOpt(IOobject::NO_WRITE);
47  io.registerObject(false);
48 
49  auto tfield = tmp<GeometricField<Type, fvPatchField, volMesh>>::New
50  (
51  io,
52  df.mesh(),
53  dimensioned<Type>(df.dimensions(), Zero),
55  );
56  tfield.ref().primitiveFieldRef() = df;
57  tfield.ref().oriented() = df.oriented();
58  tfield.ref().correctBoundaryConditions();
59 
60  return tfield;
61 }
62 
63 
64 template<class Type>
67 (
68  const fvMeshSubset& subsetter,
70 )
71 {
72  auto tfield = zeroGradientField<Type>(df);
73 
74  if (subsetter.hasSubMesh())
75  {
76  return interpolate(subsetter, tfield());
77  }
78 
79  return tfield;
80 }
81 
82 
83 template<class Type>
86 (
87  const fvMeshSubset& subsetter,
89 )
90 {
91  // TODO - move dimensioned mesh into internal,
92  // but needs different GeometricField constructors
93 
94  if (tdf.valid())
95  {
96  if (subsetter.hasSubMesh())
97  {
98  auto tproxied = interpolate(subsetter, tdf);
99  auto tfield = zeroGradientField<Type>(tproxied());
100 
101  tdf.clear();
102  tproxied.clear();
103  return tfield;
104  }
105  else
106  {
107  auto tfield = zeroGradientField<Type>(tdf());
108 
109  tdf.clear();
110  return tfield;
111  }
112  }
113 
114  return nullptr;
115 }
116 
117 
118 template<class GeoField>
121 (
122  const fvMeshSubset& subsetter,
123  const GeoField& fld
124 )
125 {
126  if (subsetter.hasSubMesh())
127  {
128  auto tfield = subsetter.interpolate(fld);
129 
130  tfield.ref().checkOut();
131  tfield.ref().rename(fld.name());
132  return tfield;
133  }
134 
135  return fld;
136 }
137 
138 
139 template<class GeoField>
142 (
143  const fvMeshSubset& subsetter,
144  const tmp<GeoField>& tfield
145 )
146 {
147  if (tfield.valid() && subsetter.hasSubMesh())
148  {
149  auto tproxied = interpolate(subsetter, tfield());
150  tfield.clear();
151 
152  return tproxied;
153  }
154 
155  // Nothing to be done
156  return tfield;
157 }
159 
160 // * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * * //
161 
162 template<class Type>
165 (
167 ) const
168 {
169  return interpolateInternal(subsetter_, df);
170 }
171 
172 
173 template<class Type>
176 (
178 ) const
179 {
180  return interpolateInternal(subsetter_, tdf);
181 }
182 
183 
184 template<class GeoField>
186 Foam::fvMeshSubsetProxy::interpolate(const GeoField& fld) const
187 {
188  return interpolate(subsetter_, fld);
189 }
190 
191 
192 template<class GeoField>
195 {
196  return interpolate(subsetter_, tfield);
197 }
198 
199 
200 // ************************************************************************* //
static const word & zeroGradientType() noexcept
The type name for zeroGradient patch fields.
Definition: fvPatchField.H:221
static tmp< DimensionedField< Type, volMesh > > interpolate(const DimensionedField< Type, volMesh > &, const fvMesh &sMesh, const labelUList &cellMap)
Map volume internal (dimensioned) field.
bool valid() const noexcept
Identical to good(), or bool operator.
Definition: tmp.H:472
bool interpolate(const vector &p1, const vector &p2, const vector &o, vector &n, scalar l)
Definition: curveTools.C:75
T & ref() const
Return non-const reference to the contents of a non-null managed pointer.
Definition: tmpI.H:235
tmp< DimensionedField< TypeR, GeoMesh > > New(const tmp< DimensionedField< TypeR, GeoMesh >> &tf1, const word &name, const dimensionSet &dimensions, const bool initCopy=false)
Global function forwards to reuseTmpDimensionedField::New.
bool hasSubMesh() const noexcept
Have subMesh?
Definition: fvMeshSubsetI.H:35
Ignore writing from objectRegistry::writeObject()
static tmp< GeometricField< Type, fvPatchField, volMesh > > interpolateInternal(const fvMeshSubset &subsetter, const DimensionedField< Type, volMesh > &df)
Convert an internal field to a volume field (with zeroGradient)
static tmp< GeoField > interpolate(const fvMeshSubset &subsetter, const GeoField &fld)
Wrapper for field or the subsetted field.
Holds a reference to the original mesh (the baseMesh) and optionally to a subset of that mesh (the su...
Definition: fvMeshSubset.H:75
gmvFile<< "tracers "<< particles.size()<< nl;for(const passiveParticle &p :particles){ gmvFile<< p.position().x()<< ' ';}gmvFile<< nl;for(const passiveParticle &p :particles){ gmvFile<< p.position().y()<< ' ';}gmvFile<< nl;for(const passiveParticle &p :particles){ gmvFile<< p.position().z()<< ' ';}gmvFile<< nl;for(const word &name :lagrangianScalarNames){ IOField< scalar > fld(IOobject(name, runTime.timeName(), cloud::prefix, mesh, IOobject::MUST_READ, IOobject::NO_WRITE))
static tmp< GeometricField< Type, fvPatchField, volMesh > > zeroGradientField(const DimensionedField< Type, volMesh > &df)
Construct volField (with zeroGradient) from an internal field.
Field with dimensions and associated with geometry type GeoMesh which is used to size the field and a...
Nothing to be read.
void clear() const noexcept
If object pointer points to valid object: delete object and set pointer to nullptr.
Definition: tmpI.H:289
IOobject io("surfaceFilmProperties", mesh.time().constant(), mesh, IOobject::READ_IF_PRESENT, IOobject::NO_WRITE, IOobject::NO_REGISTER)
A class for managing temporary objects.
Definition: HashPtrTable.H:50
static constexpr const zero Zero
Global zero (0)
Definition: zero.H:127