Merge branch 'master' of github.com:OpenCFD/OpenFOAM-1.7.x
[OpenFOAM-1.7.x.git] / src / finiteVolume / fvMesh / fvMesh.H
blobc29f4f5cad6d3f0f4795c4ff317944e93886236d
1 /*---------------------------------------------------------------------------*\
2   =========                 |
3   \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox
4    \\    /   O peration     |
5     \\  /    A nd           | Copyright (C) 1991-2011 OpenCFD Ltd.
6      \\/     M anipulation  |
7 -------------------------------------------------------------------------------
8 License
9     This file is part of OpenFOAM.
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.
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.
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/>.
24 Class
25     Foam::fvMesh
27 Description
28     Mesh data needed to do the Finite Volume discretisation.
30     NOTE ON USAGE:
31     fvMesh contains all the topological and geometric information
32     related to the mesh.  It is also responsible for keeping the data
33     up-to-date.  This is done by deleting the cell volume, face area,
34     cell/face centre, addressing and other derived information as
35     required and recalculating it as necessary.  The fvMesh therefore
36     reserves the right to delete the derived information upon every
37     topological (mesh refinement/morphing) or geometric change (mesh
38     motion).  It is therefore unsafe to keep local references to the
39     derived data outside of the time loop.
41 SourceFiles
42     fvMesh.C
43     fvMeshGeometry.C
45 \*---------------------------------------------------------------------------*/
47 #ifndef fvMesh_H
48 #define fvMesh_H
50 #include "polyMesh.H"
51 #include "lduMesh.H"
52 #include "primitiveMesh.H"
53 #include "fvBoundaryMesh.H"
54 #include "surfaceInterpolation.H"
55 #include "DimensionedField.H"
56 #include "volFieldsFwd.H"
57 #include "surfaceFieldsFwd.H"
58 #include "pointFieldsFwd.H"
59 #include "slicedVolFieldsFwd.H"
60 #include "slicedSurfaceFieldsFwd.H"
61 #include "className.H"
63 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
65 namespace Foam
68 class fvMeshLduAddressing;
69 class volMesh;
72 /*---------------------------------------------------------------------------*\
73                            Class fvMesh Declaration
74 \*---------------------------------------------------------------------------*/
76 class fvMesh
78     public polyMesh,
79     public lduMesh,
80     public surfaceInterpolation
82     // Private data
84         //- Boundary mesh
85         fvBoundaryMesh boundary_;
88     // Demand-driven data
90         mutable fvMeshLduAddressing* lduPtr_;
92         //- Current time index for cell volumes
93         //  Note.  The whole mechanism will be replaced once the
94         //  dimensionedField is created and the dimensionedField
95         //  will take care of the old-time levels.
96         mutable label curTimeIndex_;
98         //- Cell volumes old time level
99         mutable void* VPtr_;
101         //- Cell volumes old time level
102         mutable DimensionedField<scalar, volMesh>* V0Ptr_;
104         //- Cell volumes old-old time level
105         mutable DimensionedField<scalar, volMesh>* V00Ptr_;
107         //- Face area vectors
108         mutable slicedSurfaceVectorField* SfPtr_;
110         //- Mag face area vectors
111         mutable surfaceScalarField* magSfPtr_;
113         //- Cell centres
114         mutable slicedVolVectorField* CPtr_;
116         //- Face centres
117         mutable slicedSurfaceVectorField* CfPtr_;
119         //- Face motion fluxes
120         mutable surfaceScalarField* phiPtr_;
123     // Private Member Functions
125         // Storage management
127             //- Clear geometry but not the old-time cell volumes
128             void clearGeomNotOldVol();
130             //- Clear geometry
131             void clearGeom();
133             //- Clear addressing
134             void clearAddressing();
137        // Make geometric data
139             void makeSf() const;
140             void makeMagSf() const;
142             void makeC() const;
143             void makeCf() const;
146         //- Disallow construct as copy
147         fvMesh(const fvMesh&);
149         //- Disallow assignment
150         void operator=(const fvMesh&);
153 public:
155     // Public typedefs
157         typedef fvMesh Mesh;
158         typedef fvBoundaryMesh BoundaryMesh;
161     // Declare name of the class and its debug switch
162     ClassName("fvMesh");
165     // Constructors
167         //- Construct from IOobject
168         explicit fvMesh(const IOobject& io);
170         //- Construct from components without boundary.
171         //  Boundary is added using addFvPatches() member function
172         fvMesh
173         (
174             const IOobject& io,
175             const Xfer<pointField>& points,
176             const Xfer<faceList>& faces,
177             const Xfer<labelList>& allOwner,
178             const Xfer<labelList>& allNeighbour,
179             const bool syncPar = true
180         );
182         //- Construct without boundary from cells rather than owner/neighbour.
183         //  Boundary is added using addPatches() member function
184         fvMesh
185         (
186             const IOobject& io,
187             const Xfer<pointField>& points,
188             const Xfer<faceList>& faces,
189             const Xfer<cellList>& cells,
190             const bool syncPar = true
191         );
194     // Destructor
196         virtual ~fvMesh();
199     // Member Functions
201         // Helpers
203             //- Add boundary patches. Constructor helper
204             void addFvPatches
205             (
206                 const List<polyPatch*>&,
207                 const bool validBoundary = true
208             );
210             //- Update the mesh based on the mesh files saved in time
211             //  directories
212             virtual readUpdateState readUpdate();
215         // Access
217             //- Return the top-level database
218             const Time& time() const
219             {
220                 return polyMesh::time();
221             }
223             //- Return the object registry - resolve conflict polyMesh/lduMesh
224             virtual const objectRegistry& thisDb() const
225             {
226                 return polyMesh::thisDb();
227             }
229             //- Return reference to name
230             //  Note: name() is currently ambiguous due to derivation from
231             //  surfaceInterpolation
232             const word& name() const
233             {
234                 return polyMesh::name();
235             }
237             //- Return reference to boundary mesh
238             const fvBoundaryMesh& boundary() const;
240             //- Return ldu addressing
241             virtual const lduAddressing& lduAddr() const;
243             //- Return a list of pointers for each patch
244             //  with only those pointing to interfaces being set
245             virtual lduInterfacePtrsList interfaces() const
246             {
247                 return boundary().interfaces();
248             }
250             //- Internal face owner
251             const unallocLabelList& owner() const
252             {
253                 return lduAddr().lowerAddr();
254             }
256             //- Internal face neighbour
257             const unallocLabelList& neighbour() const
258             {
259                 return lduAddr().upperAddr();
260             }
262             //- Return cell volumes
263             const DimensionedField<scalar, volMesh>& V() const;
265             //- Return old-time cell volumes
266             const DimensionedField<scalar, volMesh>& V0() const;
268             //- Return old-old-time cell volumes
269             const DimensionedField<scalar, volMesh>& V00() const;
271             //- Return sub-cycle cell volumes
272             tmp<DimensionedField<scalar, volMesh> > Vsc() const;
274             //- Return sub-cycl old-time cell volumes
275             tmp<DimensionedField<scalar, volMesh> > Vsc0() const;
277             //- Return cell face area vectors
278             const surfaceVectorField& Sf() const;
280             //- Return cell face area magnitudes
281             const surfaceScalarField& magSf() const;
283             //- Return cell face motion fluxes
284             const surfaceScalarField& phi() const;
286             //- Return cell centres as volVectorField
287             const volVectorField& C() const;
289             //- Return face centres as surfaceVectorField
290             const surfaceVectorField& Cf() const;
293         // Edit
295             //- Clear all geometry and addressing
296             void clearOut();
298             //- Update mesh corresponding to the given map
299             virtual void updateMesh(const mapPolyMesh& mpm);
301             //- Move points, returns volumes swept by faces in motion
302             virtual tmp<scalarField> movePoints(const pointField&);
304             //- Map all fields in time using given map.
305             virtual void mapFields(const mapPolyMesh& mpm);
307             //- Remove boundary patches. Warning: fvPatchFields hold ref to
308             //  these fvPatches.
309             void removeFvBoundary();
311             //- Return cell face motion fluxes
312             surfaceScalarField& setPhi();
314             //- Return old-time cell volumes
315             DimensionedField<scalar, volMesh>& setV0();
318         // Write
320             //- Write the underlying polyMesh and other data
321             virtual bool writeObjects
322             (
323                 IOstream::streamFormat fmt,
324                 IOstream::versionNumber ver,
325                 IOstream::compressionType cmp
326             ) const;
328             //- Write mesh using IO settings from time
329             virtual bool write() const;
332     // Member Operators
334         bool operator!=(const fvMesh&) const;
335         bool operator==(const fvMesh&) const;
339 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
341 } // End namespace Foam
343 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
345 #ifdef NoRepository
346 #   include "fvPatchFvMeshTemplates.C"
347 #endif
349 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
351 #endif
353 // ************************************************************************* //