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-2018 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),
54  zeroGradientFvPatchField<Type>::typeName
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 }
158 
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>
187 {
188  return interpolate(subsetter_, fld);
189 }
190 
191 
192 template<class GeoField>
195 {
196  return interpolate(subsetter_, tfield);
197 }
198 
199 
200 // ************************************************************************* //
Foam::IOobject::NO_WRITE
Definition: IOobject.H:130
volFields.H
Foam::tmp::clear
void clear() const noexcept
Definition: tmpI.H:291
Foam::tmp
A class for managing temporary objects.
Definition: PtrList.H:61
Foam::fvMeshSubset
Given the original mesh and the list of selected cells, it creates the mesh consisting only of the de...
Definition: fvMeshSubset.H:73
Foam::Zero
static constexpr const zero Zero
Global zero (0)
Definition: zero.H:131
Foam::fvMeshSubsetProxy::interpolateInternal
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)
Foam::fvMeshSubsetProxy::interpolate
static tmp< GeoField > interpolate(const fvMeshSubset &subsetter, const GeoField &fld)
Wrapper for field or the subsetted field.
Foam::tmp::ref
T & ref() const
Definition: tmpI.H:228
Foam::interpolate
bool interpolate(const vector &p1, const vector &p2, const vector &o, vector &n, scalar l)
Definition: curveTools.C:75
Foam::fvMeshSubsetProxy::zeroGradientField
static tmp< GeometricField< Type, fvPatchField, volMesh > > zeroGradientField(const DimensionedField< Type, volMesh > &df)
Construct volField (with zeroGradient) from an internal field.
fld
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))
Definition: gmvOutputLagrangian.H:23
fvMeshSubsetProxy.H
Foam::New
tmp< DimensionedField< TypeR, GeoMesh > > New(const tmp< DimensionedField< TypeR, GeoMesh >> &tdf1, const word &name, const dimensionSet &dimensions)
Global function forwards to reuseTmpDimensionedField::New.
Definition: DimensionedFieldReuseFunctions.H:105
Foam::fvMeshSubset::interpolate
static tmp< GeometricField< Type, fvPatchField, volMesh > > interpolate(const GeometricField< Type, fvPatchField, volMesh > &, const fvMesh &sMesh, const labelUList &patchMap, const labelUList &cellMap, const labelUList &faceMap, const bool allowUnmapped=false)
Map volume field. Optionally allow unmapped faces not to produce.
Foam::tmp::valid
bool valid() const noexcept
True for non-null pointer/reference.
Definition: tmp.H:175
Foam::GeometricField< Type, Foam::fvPatchField, Foam::volMesh >
Foam::IOobject::NO_READ
Definition: IOobject.H:123
Foam::fvMeshSubset::hasSubMesh
bool hasSubMesh() const
Have subMesh?
Definition: fvMeshSubsetI.H:42
Foam::DimensionedField
Field with dimensions and associated with geometry type GeoMesh which is used to size the field and a...
Definition: DimensionedField.H:54