Loading...
Searching...
No Matches
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-------------------------------------------------------------------------------
11License
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
34template<class Type>
36<
38>
40(
42)
43{
44 IOobject io(df);
45 io.readOpt(IOobject::NO_READ);
46 io.writeOpt(IOobject::NO_WRITE);
47 io.registerObject(false);
48
50 (
51 io,
52 df.mesh(),
55 );
56 tfield.ref().primitiveFieldRef() = df;
57 tfield.ref().oriented() = df.oriented();
58 tfield.ref().correctBoundaryConditions();
60 return tfield;
61}
62
63
64template<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 }
79 return tfield;
80}
81
82
83template<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.good())
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 }
114 return nullptr;
115}
116
117
118template<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 }
135 return fld;
136}
137
138
139template<class GeoField>
142(
143 const fvMeshSubset& subsetter,
144 const tmp<GeoField>& tfield
145)
146{
147 if (tfield.good() && 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;
158
159
160// * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * * //
161
162template<class Type>
165(
167) const
169 return interpolateInternal(subsetter_, df);
170}
171
172
173template<class Type>
176(
178) const
180 return interpolateInternal(subsetter_, tdf);
181}
182
183
184template<class GeoField>
186Foam::fvMeshSubsetProxy::interpolate(const GeoField& fld) const
188 return interpolate(subsetter_, fld);
189}
190
191
192template<class GeoField>
195{
196 return interpolate(subsetter_, tfield);
197}
198
199
200// ************************************************************************* //
Info<< nl;Info<< "Write faMesh in vtk format:"<< nl;{ vtk::uindirectPatchWriter writer(aMesh.patch(), fileName(aMesh.time().globalPath()/vtkBaseFileName));writer.writeGeometry();globalIndex procAddr(aMesh.nFaces());labelList cellIDs;if(UPstream::master()) { cellIDs.resize(procAddr.totalSize());for(const labelRange &range :procAddr.ranges()) { auto slice=cellIDs.slice(range);slice=identity(range);} } writer.beginCellData(4);writer.writeProcIDs();writer.write("cellID", cellIDs);writer.write("area", aMesh.S().field());writer.write("normal", aMesh.faceAreaNormals());writer.beginPointData(1);writer.write("normal", aMesh.pointAreaNormals());Info<< " "<< writer.output().name()<< nl;}{ vtk::lineWriter writer(aMesh.points(), aMesh.edges(), fileName(aMesh.time().globalPath()/(vtkBaseFileName+"-edges")));writer.writeGeometry();writer.beginCellData(4);writer.writeProcIDs();{ Field< scalar > fld(faMeshTools::flattenEdgeField(aMesh.magLe(), true))
Field with dimensions and associated with geometry type GeoMesh which is used to size the field and a...
const Mesh & mesh() const noexcept
Return const reference to mesh.
const dimensionSet & dimensions() const noexcept
Return dimensions.
orientedType oriented() const noexcept
Return oriented type.
Generic GeometricField class.
@ NO_READ
Nothing to be read.
@ NO_WRITE
Ignore writing from objectRegistry::writeObject().
Defines the attributes of an object for which implicit objectRegistry management is supported,...
Definition IOobject.H:191
Generic dimensioned Type class.
static tmp< GeoField > interpolate(const fvMeshSubset &subsetter, const GeoField &fld)
Wrapper for field or the subsetted field.
static tmp< GeometricField< Type, fvPatchField, volMesh > > zeroGradientField(const DimensionedField< Type, volMesh > &df)
Construct volField (with zeroGradient) from an internal field.
const fvMeshSubset & subsetter() const noexcept
The mesh subsetter.
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).
Holds a reference to the original mesh (the baseMesh) and optionally to a subset of that mesh (the su...
static tmp< DimensionedField< Type, volMesh > > interpolate(const DimensionedField< Type, volMesh > &, const fvMesh &sMesh, const labelUList &cellMap)
Map volume internal (dimensioned) field.
bool hasSubMesh() const noexcept
Have subMesh?
static const word & zeroGradientType() noexcept
The type name for zeroGradient patch fields.
A class for managing temporary objects.
Definition tmp.H:75
bool good() const noexcept
True if pointer/reference is non-null.
Definition tmp.H:249
void clear() const noexcept
If object pointer points to valid object: delete object and set pointer to nullptr.
Definition tmpI.H:289
const auto & io
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.
static constexpr const zero Zero
Global zero (0).
Definition zero.H:127
bool interpolate(const vector &p1, const vector &p2, const vector &o, vector &n, scalar l)
Definition curveTools.C:75