FreeFOAM The Cross-Platform CFD Toolkit
sampledIsoSurface.H
Go to the documentation of this file.
1 /*---------------------------------------------------------------------------*\
2  ========= |
3  \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
4  \\ / O peration |
5  \\ / A nd | Copyright (C) 1991-2010 OpenCFD Ltd.
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 Class
25  Foam::sampledIsoSurface
26 
27 Description
28  A sampledSurface defined by a surface of iso value. Always triangulated.
29  To be used in sampleSurfaces / functionObjects. Recalculates iso surface
30  only if time changes.
31 
32 SourceFiles
33  sampledIsoSurface.C
34 
35 \*---------------------------------------------------------------------------*/
36 
37 #ifndef sampledIsoSurface_H
38 #define sampledIsoSurface_H
39 
40 #include "isoSurface.H"
42 #include <OpenFOAM/ZoneIDs.H>
44 
45 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
46 
47 namespace Foam
48 {
49 
50 /*---------------------------------------------------------------------------*\
51  Class sampledIsoSurface Declaration
52 \*---------------------------------------------------------------------------*/
53 
55 :
56  public sampledSurface
57 {
58  // Private data
59 
60  //- Field to get isoSurface of
61  const word isoField_;
62 
63  //- iso value
64  const scalar isoVal_;
65 
66  //- Merge tolerance
67  const scalar mergeTol_;
68 
69  //- Whether to coarse
70  const Switch regularise_;
71 
72  //- Whether to recalculate cell values as average of point values
73  const Switch average_;
74 
75  //- zone name/index (if restricted to zones)
76  mutable cellZoneID zoneID_;
77 
78  //- for zones: patch to put exposed faces into
79  mutable word exposedPatchName_;
80 
81  mutable autoPtr<isoSurface> surfPtr_;
82 
83  //- triangles converted to faceList
84  mutable autoPtr<faceList> facesPtr_;
85 
86 
87  // Recreated for every isoSurface
88 
89  //- Time at last call, also track if surface needs an update
90  mutable label prevTimeIndex_;
91 
92  //- Cached volfield
93  mutable autoPtr<volScalarField> storedVolFieldPtr_;
94  mutable const volScalarField* volFieldPtr_;
95 
96  //- Cached pointfield
97  mutable autoPtr<pointScalarField> storedPointFieldPtr_;
98  mutable const pointScalarField* pointFieldPtr_;
99 
100  // And on subsetted mesh
101 
102  //- Cached submesh
103  mutable autoPtr<fvMeshSubset> subMeshPtr_;
104 
105  //- Cached volfield
106  mutable autoPtr<volScalarField> storedVolSubFieldPtr_;
107  mutable const volScalarField* volSubFieldPtr_;
108 
109  //- Cached pointfield
110  mutable autoPtr<pointScalarField> storedPointSubFieldPtr_;
111  mutable const pointScalarField* pointSubFieldPtr_;
112 
113 
114 
115  // Private Member Functions
116 
117  //- Get fields needed to recreate iso surface.
118  void getIsoFields() const;
119 
120  tmp<volScalarField> average
121  (
122  const fvMesh&,
123  const pointScalarField&
124  ) const;
125 
126  tmp<pointScalarField> average
127  (
128  const pointMesh&,
129  const volScalarField& fld
130  ) const;
131 
132  //- Create iso surface (if time has changed)
133  // Do nothing (and return false) if no update was needed
134  bool updateGeometry() const;
135 
136  //- sample field on faces
137  template <class Type>
138  tmp<Field<Type> > sampleField
139  (
141  ) const;
142 
143 
144  template <class Type>
146  interpolateField(const interpolation<Type>&) const;
147 
148 
149 public:
150 
151  //- Runtime type information
152  TypeName("sampledIsoSurface");
153 
154 
155  // Constructors
156 
157  //- Construct from dictionary
159  (
160  const word& name,
161  const polyMesh& mesh,
162  const dictionary& dict
163  );
164 
165 
166  // Destructor
167 
168  virtual ~sampledIsoSurface();
169 
170 
171  // Member Functions
172 
173  //- Does the surface need an update?
174  virtual bool needsUpdate() const;
175 
176  //- Mark the surface as needing an update.
177  // May also free up unneeded data.
178  // Return false if surface was already marked as expired.
179  virtual bool expire();
180 
181  //- Update the surface as required.
182  // Do nothing (and return false) if no update was needed
183  virtual bool update();
184 
185 
186  //- Points of surface
187  virtual const pointField& points() const
188  {
189  return surface().points();
190  }
191 
192  //- Faces of surface
193  virtual const faceList& faces() const
194  {
195  if (facesPtr_.empty())
196  {
197  const triSurface& s = surface();
198 
199  facesPtr_.reset(new faceList(s.size()));
200 
201  forAll(s, i)
202  {
203  facesPtr_()[i] = s[i].triFaceFace();
204  }
205  }
206  return facesPtr_;
207  }
208 
209 
210  const isoSurface& surface() const
211  {
212  return surfPtr_();
213  }
214 
215  //- Lookup or read isoField. Sets volFieldPtr_ and pointFieldPtr_.
216  void getIsoField();
217 
218 
219  //- sample field on surface
220  virtual tmp<scalarField> sample
221  (
222  const volScalarField&
223  ) const;
224 
225  //- sample field on surface
226  virtual tmp<vectorField> sample
227  (
228  const volVectorField&
229  ) const;
230 
231  //- sample field on surface
233  (
235  ) const;
236 
237  //- sample field on surface
239  (
240  const volSymmTensorField&
241  ) const;
242 
243  //- sample field on surface
244  virtual tmp<tensorField> sample
245  (
246  const volTensorField&
247  ) const;
248 
249 
250  //- interpolate field on surface
252  (
253  const interpolation<scalar>&
254  ) const;
255 
256  //- interpolate field on surface
258  (
259  const interpolation<vector>&
260  ) const;
261 
262  //- interpolate field on surface
264  (
266  ) const;
267 
268  //- interpolate field on surface
270  (
272  ) const;
273 
274  //- interpolate field on surface
276  (
277  const interpolation<tensor>&
278  ) const;
279 
280  //- Write
281  virtual void print(Ostream&) const;
282 };
283 
284 
285 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
286 
287 } // End namespace Foam
288 
289 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
290 
291 #ifdef NoRepository
293 #endif
294 
295 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
296 
297 #endif
298 
299 // ************************ vim: set sw=4 sts=4 et: ************************ //