Merge branch 'master' of ssh://git.code.sf.net/p/foam-extend/foam-extend-3.2
[foam-extend-3.2.git] / src / sampling / sampledSurface / sampledPatch / sampledPatch.C
blob2194b703e92b13dfbb07f9f92e8ba8f12b6a4a47
1 /*---------------------------------------------------------------------------*\
2   =========                 |
3   \\      /  F ield         | foam-extend: Open Source CFD
4    \\    /   O peration     | Version:     3.2
5     \\  /    A nd           | Web:         http://www.foam-extend.org
6      \\/     M anipulation  | For copyright notice see file Copyright
7 -------------------------------------------------------------------------------
8 License
9     This file is part of foam-extend.
11     foam-extend is free software: you can redistribute it and/or modify it
12     under the terms of the GNU General Public License as published by the
13     Free Software Foundation, either version 3 of the License, or (at your
14     option) any later version.
16     foam-extend is distributed in the hope that it will be useful, but
17     WITHOUT ANY WARRANTY; without even the implied warranty of
18     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
19     General Public License for more details.
21     You should have received a copy of the GNU General Public License
22     along with foam-extend.  If not, see <http://www.gnu.org/licenses/>.
24 \*---------------------------------------------------------------------------*/
26 #include "sampledPatch.H"
27 #include "dictionary.H"
28 #include "polyMesh.H"
29 #include "polyPatch.H"
30 #include "volFields.H"
32 #include "addToRunTimeSelectionTable.H"
34 // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
36 namespace Foam
38     defineTypeNameAndDebug(sampledPatch, 0);
39     addNamedToRunTimeSelectionTable(sampledSurface, sampledPatch, word, patch);
43 // * * * * * * * * * * * * * * * * Constructors  * * * * * * * * * * * * * * //
45 Foam::sampledPatch::sampledPatch
47     const word& name,
48     const polyMesh& mesh,
49     const word& patchName,
50     const bool triangulate
53     sampledSurface(name, mesh),
54     patchName_(patchName),
55     triangulate_(triangulate),
56     needsUpdate_(true),
57     patchFaceLabels_(0)
61 Foam::sampledPatch::sampledPatch
63     const word& name,
64     const polyMesh& mesh,
65     const dictionary& dict
68     sampledSurface(name, mesh, dict),
69     patchName_(dict.lookup("patchName")),
70     triangulate_(dict.lookupOrDefault("triangulate", false)),
71     needsUpdate_(true),
72     patchFaceLabels_(0)
76 // * * * * * * * * * * * * * * * * Destructor  * * * * * * * * * * * * * * * //
78 Foam::sampledPatch::~sampledPatch()
82 // * * * * * * * * * * * * * * * Member Functions  * * * * * * * * * * * * * //
84 bool Foam::sampledPatch::needsUpdate() const
86     return needsUpdate_;
90 bool Foam::sampledPatch::expire()
92     // already marked as expired
93     if (needsUpdate_)
94     {
95         return false;
96     }
98     sampledSurface::clearGeom();
99     MeshStorage::clear();
100     patchFaceLabels_.clear();
102     needsUpdate_ = true;
103     return true;
107 bool Foam::sampledPatch::update()
109     if (!needsUpdate_)
110     {
111         return false;
112     }
114     label patchI = mesh().boundaryMesh().findPatchID(patchName_);
116     if (patchI != -1)
117     {
118         const polyPatch& p = mesh().boundaryMesh()[patchI];
119         this->storedPoints() = p.localPoints();
120         this->storedFaces()  = p.localFaces();
122         // an identity map
123         patchFaceLabels_.setSize(faces().size());
124         forAll(patchFaceLabels_, i)
125         {
126             patchFaceLabels_[i] = i;
127         }
129         // triangulate uses remapFaces()
130         // - this is somewhat less efficient since it recopies the faces
131         // that we just created, but we probably don't want to do this
132         // too often anyhow.
133         if (triangulate_)
134         {
135             MeshStorage::triangulate();
136         }
137     }
139     if (debug)
140     {
141         print(Pout);
142         Pout << endl;
143     }
145     needsUpdate_ = false;
146     return true;
150 // remap action on triangulation
151 void Foam::sampledPatch::remapFaces
153     const UList<label>& faceMap
156     // recalculate the cells cut
157     if (&faceMap && faceMap.size())
158     {
159         MeshStorage::remapFaces(faceMap);
160     }
165 Foam::tmp<Foam::scalarField>
166 Foam::sampledPatch::sample
168     const volScalarField& vField
169 ) const
171     return sampleField(vField);
175 Foam::tmp<Foam::vectorField>
176 Foam::sampledPatch::sample
178     const volVectorField& vField
179 ) const
181     return sampleField(vField);
184 Foam::tmp<Foam::sphericalTensorField>
185 Foam::sampledPatch::sample
187     const volSphericalTensorField& vField
188 ) const
190     return sampleField(vField);
194 Foam::tmp<Foam::symmTensorField>
195 Foam::sampledPatch::sample
197     const volSymmTensorField& vField
198 ) const
200     return sampleField(vField);
204 Foam::tmp<Foam::tensorField>
205 Foam::sampledPatch::sample
207     const volTensorField& vField
208 ) const
210     return sampleField(vField);
214 Foam::tmp<Foam::scalarField>
215 Foam::sampledPatch::interpolate
217     const interpolation<scalar>& interpolator
218 ) const
220     return interpolateField(interpolator);
224 Foam::tmp<Foam::vectorField>
225 Foam::sampledPatch::interpolate
227     const interpolation<vector>& interpolator
228 ) const
230     return interpolateField(interpolator);
233 Foam::tmp<Foam::sphericalTensorField>
234 Foam::sampledPatch::interpolate
236     const interpolation<sphericalTensor>& interpolator
237 ) const
239     return interpolateField(interpolator);
243 Foam::tmp<Foam::symmTensorField>
244 Foam::sampledPatch::interpolate
246     const interpolation<symmTensor>& interpolator
247 ) const
249     return interpolateField(interpolator);
253 Foam::tmp<Foam::tensorField>
254 Foam::sampledPatch::interpolate
256     const interpolation<tensor>& interpolator
257 ) const
259     return interpolateField(interpolator);
263 void Foam::sampledPatch::print(Ostream& os) const
265     os  << "sampledPatch: " << name() << " :"
266         << "  patch:" << patchName()
267         << "  faces:" << faces().size()
268         << "  points:" << points().size();
272 // ************************************************************************* //