1 /*---------------------------------------------------------------------------*\
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 -------------------------------------------------------------------------------
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/>.
28 Virtual base class for a level of multigrid hierarchy.
33 \*---------------------------------------------------------------------------*/
35 #ifndef mgFieldLevel_H
36 #define mgFieldLevel_H
40 #include "primitiveFields.H"
41 #include "coarseMgMeshLevel.H"
43 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
48 /*---------------------------------------------------------------------------*\
49 Class mgFieldLevel Declaration
50 \*---------------------------------------------------------------------------*/
56 //- Runtime type information
57 virtual const word& type() const = 0;
59 //- Access to child array
60 virtual const labelList& child() const = 0;
62 //- Access to fine level
63 virtual const mgFieldLevel& fineLevel() const = 0;
65 //- Is this the finest level?
66 virtual bool finest() const = 0;
71 virtual ~mgFieldLevel()
80 //- Return number of cells
81 virtual label nCells() const = 0;
83 //- Return number of internal faces
84 virtual label nInternalFaces() const = 0;
86 //- Return number of patches
87 virtual label nPatches() const = 0;
90 // Primitive variables
93 virtual const scalarField& pVar() const = 0;
96 virtual const vectorField& UVar() const = 0;
99 virtual const scalarField& TVar() const = 0;
101 //- Access to fine p field
102 virtual const volScalarField& p() const = 0;
104 //- Access to fine U field
105 virtual const volVectorField& U() const = 0;
107 //- Access to fine T field
108 virtual const volScalarField& T() const = 0;
110 //- Access to p boundary field
111 virtual const scalarField& patchP(const label patchNo) const = 0;
113 //- Access to U field
114 virtual const vectorField& patchU(const label patchNo) const = 0;
116 //- Access to T field
117 virtual const scalarField& patchT(const label patchNo) const = 0;
119 //- Access to Cv field
120 virtual const scalarField& CvVar() const = 0;
122 //- Access to fine Cv field
123 virtual const volScalarField& Cv() const = 0;
125 //- Access to Cv boundary field
126 virtual const scalarField& patchCv(const label patchNo) const = 0;
128 //- Access to R field
129 virtual const scalarField& RVar() const = 0;
131 //- Access to fine R field
132 virtual const volScalarField& R() const = 0;
134 //- Access to R boundary field
135 virtual const scalarField& patchR(const label patchNo) const = 0;
139 //- Access to fine rhoFlux field
140 virtual surfaceScalarField& rhoFlux() const = 0;
142 //- Access to fine rhoUFlux field
143 virtual surfaceVectorField& rhoUFlux() const = 0;
145 //- Access to fine rhoEFlux field
146 virtual surfaceScalarField& rhoEFlux() const = 0;
151 //- Access to rhoRes field
152 virtual const scalarField& rhoResVar() const = 0;
154 //- Access to fine rhoRes field
155 virtual const volScalarField& rhoRes() const = 0;
157 //- Access to rhoRes boundary field
158 virtual const scalarField& patchRhoRes
163 //- Access to rhoURes field
164 virtual const vectorField& rhoUResVar() const = 0;
166 //- Access to fine rhoRes field
167 virtual const volVectorField& rhoURes() const = 0;
169 //- Access to rhoRes boundary field
170 virtual const vectorField& patchRhoURes
175 //- Access to rhoERes field
176 virtual const scalarField& rhoEResVar() const = 0;
178 //- Access to fine rhoERes field
179 virtual const volScalarField& rhoERes() const = 0;
181 //- Access to rhoERes boundary field
182 virtual const scalarField& patchRhoERes
188 // Conservative variables
190 //- Access to rho field
191 virtual const scalarField& rhoVar() const = 0;
193 //- Access to fine rho field
194 virtual const volScalarField& rho() const = 0;
196 //- Access to rho boundary field
197 virtual const scalarField& patchRho
202 //- Access to rhoURes field
203 virtual const vectorField& rhoUVar() const = 0;
205 //- Access to fine rhoRes field
206 virtual const volVectorField& rhoU() const = 0;
208 //- Access to rhoRes boundary field
209 virtual const vectorField& patchRhoU
214 //- Access to rhoERes field
215 virtual const scalarField& rhoEVar() const = 0;
217 //- Access to fine rhoERes field
218 virtual const volScalarField& rhoE() const = 0;
220 //- Access to rhoERes boundary field
221 virtual const scalarField& patchRhoE
226 //- Access to rhoERes boundary field
227 virtual label const& level() const = 0;
230 // Restriction and prolongation
232 //- Restrict (from fine to coarse). Call from the level
233 // where data originates
237 UList<T>& coarseData,
238 const UList<T>& fineData
242 const labelList& c = child();
244 // Restriction = summation. Set coarse data to zero
245 coarseData = pTraits<T>::zero;
249 coarseData[c[i]] += fineData[i];
253 //- Prolong (from coarse to fine). Call from the level
254 // where data originates
258 const UList<T>& coarseData,
266 "void mgMeshLevel::prolong\n"
268 " UList<T>& coarseData,\n"
269 " const UList<T>& fineData\n"
271 ) << "Requested prolong from finest level"
272 << abort(FatalError);
277 coarseData.size() != nCells()
278 || fineData.size() != fineLevel().nCells()
283 "void mgMeshLevel::prolong\n"
285 " UList<T>& coarseData,\n"
286 " const UList<T>& fineData\n"
288 ) << "Incorrect data sizes "
289 << abort(FatalError);
293 const labelList& c = fineLevel().child();
295 // Prolongation = assignment. Initialisation not needed
298 fineData[i] = coarseData[c[i]];
302 //- Prolong to the finest level (from coarse to fine)
304 tmp<Field<T> > prolongToFinest
306 const UList<T>& coarseData
311 // Already on finest level
312 return tmp<Field<T> >(new Field<T>(coarseData));
314 else if (fineLevel().finest())
316 tmp<Field<T> > tresult
318 new Field<T>(fineLevel().nCells())
321 prolong(coarseData, tresult());
323 // Reached finest level, return
328 Field<T> intermediate(fineLevel().nCells());
330 prolong(coarseData, intermediate);
333 return fineLevel().prolongToFinest(intermediate);
339 //- Create next level from current level
340 autoPtr<mgFieldLevel> makeNextLevel
342 const mgMeshLevel& coarseMeshLevel
348 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
350 } // End namespace Foam
352 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
356 // ************************************************************************* //