OpenFOAM logo
The Open Source CFD Toolbox
  Source Guide OpenCFD Solutions Contact OpenFOAM

surfaceInterpolationScheme.C

Go to the documentation of this file.
00001 /*---------------------------------------------------------------------------*\
00002   =========                 |
00003   \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox
00004    \\    /   O peration     |
00005     \\  /    A nd           | Copyright (C) 1991-2009 OpenCFD Ltd.
00006      \\/     M anipulation  |
00007 -------------------------------------------------------------------------------
00008 License
00009     This file is part of OpenFOAM.
00010 
00011     OpenFOAM is free software; you can redistribute it and/or modify it
00012     under the terms of the GNU General Public License as published by the
00013     Free Software Foundation; either version 2 of the License, or (at your
00014     option) any later version.
00015 
00016     OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
00017     ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
00018     FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
00019     for more details.
00020 
00021     You should have received a copy of the GNU General Public License
00022     along with OpenFOAM; if not, write to the Free Software Foundation,
00023     Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
00024 
00025 Description
00026     Abstract base class for surface interpolation schemes.
00027 
00028 \*---------------------------------------------------------------------------*/
00029 
00030 #include "surfaceInterpolationScheme.H"
00031 #include "volFields.H"
00032 #include "surfaceFields.H"
00033 #include "coupledFvPatchField.H"
00034 
00035 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
00036 
00037 namespace Foam
00038 {
00039 
00040 // * * * * * * * * * * * * * * * * * Selectors * * * * * * * * * * * * * * * //
00041 
00042 // Return weighting factors for scheme given by name in dictionary
00043 template<class Type>
00044 tmp<surfaceInterpolationScheme<Type> > surfaceInterpolationScheme<Type>::New
00045 (
00046     const fvMesh& mesh,
00047     Istream& schemeData
00048 )
00049 {
00050     if (schemeData.eof())
00051     {
00052         FatalIOErrorIn
00053         (
00054             "surfaceInterpolationScheme<Type>::New(const fvMesh&, Istream&)",
00055             schemeData
00056         )   << "Discretisation scheme not specified"
00057             << endl << endl
00058             << "Valid schemes are :" << endl
00059             << MeshConstructorTablePtr_->toc()
00060             << exit(FatalIOError);
00061     }
00062 
00063     word schemeName(schemeData);
00064 
00065     if (surfaceInterpolation::debug || surfaceInterpolationScheme<Type>::debug)
00066     {
00067         Info<< "surfaceInterpolationScheme<Type>::New"
00068                "(const fvMesh&, Istream&)"
00069                " : discretisation scheme = "
00070             << schemeName
00071             << endl;
00072     }
00073 
00074     typename MeshConstructorTable::iterator constructorIter =
00075         MeshConstructorTablePtr_->find(schemeName);
00076 
00077     if (constructorIter == MeshConstructorTablePtr_->end())
00078     {
00079         FatalIOErrorIn
00080         (
00081             "surfaceInterpolationScheme<Type>::New(const fvMesh&, Istream&)",
00082             schemeData
00083         )   << "Unknown discretisation scheme " << schemeName
00084             << endl << endl
00085             << "Valid schemes are :" << endl
00086             << MeshConstructorTablePtr_->toc()
00087             << exit(FatalIOError);
00088     }
00089 
00090     return constructorIter()(mesh, schemeData);
00091 }
00092 
00093 
00094 // Return weighting factors for scheme given by name in dictionary
00095 template<class Type>
00096 tmp<surfaceInterpolationScheme<Type> > surfaceInterpolationScheme<Type>::New
00097 (
00098     const fvMesh& mesh,
00099     const surfaceScalarField& faceFlux,
00100     Istream& schemeData
00101 )
00102 {
00103     if (schemeData.eof())
00104     {
00105         FatalIOErrorIn
00106         (
00107             "surfaceInterpolationScheme<Type>::New"
00108             "(const fvMesh&, const surfaceScalarField&, Istream&)",
00109             schemeData
00110         )   << "Discretisation scheme not specified"
00111             << endl << endl
00112             << "Valid schemes are :" << endl
00113             << MeshConstructorTablePtr_->toc()
00114             << exit(FatalIOError);
00115     }
00116 
00117     word schemeName(schemeData);
00118 
00119     if (surfaceInterpolation::debug || surfaceInterpolationScheme<Type>::debug)
00120     {
00121         Info<< "surfaceInterpolationScheme<Type>::New"
00122                "(const fvMesh&, const surfaceScalarField&, Istream&)"
00123                " : discretisation scheme = "
00124             << schemeName
00125             << endl;
00126     }
00127 
00128     typename MeshFluxConstructorTable::iterator constructorIter =
00129         MeshFluxConstructorTablePtr_->find(schemeName);
00130 
00131     if (constructorIter == MeshFluxConstructorTablePtr_->end())
00132     {
00133         FatalIOErrorIn
00134         (
00135             "surfaceInterpolationScheme<Type>::New"
00136             "(const fvMesh&, const surfaceScalarField&, Istream&)",
00137             schemeData
00138         )   << "Unknown discretisation scheme " << schemeName
00139             << endl << endl
00140             << "Valid schemes are :" << endl
00141             << MeshFluxConstructorTablePtr_->toc()
00142             << exit(FatalIOError);
00143     }
00144 
00145     return constructorIter()(mesh, faceFlux, schemeData);
00146 }
00147 
00148 
00149 // * * * * * * * * * * * * * * * * Destructor  * * * * * * * * * * * * * * * //
00150 
00151 template<class Type>
00152 surfaceInterpolationScheme<Type>::~surfaceInterpolationScheme()
00153 {}
00154 
00155 
00156 // * * * * * * * * * * * * * * * Member Functions  * * * * * * * * * * * * * //
00157 
00158 //- Return the face-interpolate of the given cell field
00159 //  with the given owner and neighbour weighting factors
00160 template<class Type>
00161 tmp<GeometricField<Type, fvsPatchField, surfaceMesh> >
00162 surfaceInterpolationScheme<Type>::interpolate
00163 (
00164     const GeometricField<Type, fvPatchField, volMesh>& vf,
00165     const tmp<surfaceScalarField>& tlambdas,
00166     const tmp<surfaceScalarField>& tys
00167 )
00168 {
00169     if (surfaceInterpolation::debug)
00170     {
00171         Info<< "surfaceInterpolationScheme<Type>::uncorrectedInterpolate"
00172                "(const GeometricField<Type, fvPatchField, volMesh>&, "
00173                "const tmp<surfaceScalarField>&, "
00174                "const tmp<surfaceScalarField>&) : "
00175                "interpolating volTypeField from cells to faces "
00176                "without explicit correction"
00177             << endl;
00178     }
00179 
00180     const surfaceScalarField& lambdas = tlambdas();
00181     const surfaceScalarField& ys = tys();
00182 
00183     const Field<Type>& vfi = vf.internalField();
00184     const scalarField& lambda = lambdas.internalField();
00185     const scalarField& y = ys.internalField();
00186 
00187     const fvMesh& mesh = vf.mesh();
00188     const unallocLabelList& P = mesh.owner();
00189     const unallocLabelList& N = mesh.neighbour();
00190 
00191     tmp<GeometricField<Type, fvsPatchField, surfaceMesh> > tsf
00192     (
00193         new GeometricField<Type, fvsPatchField, surfaceMesh>
00194         (
00195             IOobject
00196             (
00197                 "interpolate("+vf.name()+')',
00198                 vf.instance(),
00199                 vf.db()
00200             ),
00201             mesh,
00202             vf.dimensions()
00203         )
00204     );
00205     GeometricField<Type, fvsPatchField, surfaceMesh>& sf = tsf();
00206 
00207     Field<Type>& sfi = sf.internalField();
00208 
00209     for (register label fi=0; fi<P.size(); fi++)
00210     {
00211         sfi[fi] = lambda[fi]*vfi[P[fi]] + y[fi]*vfi[N[fi]];
00212     }
00213 
00214 
00215     // Interpolate across coupled patches using given lambdas and ys
00216 
00217     forAll (lambdas.boundaryField(), pi)
00218     {
00219         const fvsPatchScalarField& pLambda = lambdas.boundaryField()[pi];
00220         const fvsPatchScalarField& pY = ys.boundaryField()[pi];
00221 
00222         if (vf.boundaryField()[pi].coupled())
00223         {
00224             sf.boundaryField()[pi] =
00225                 pLambda*vf.boundaryField()[pi].patchInternalField()
00226               + pY*vf.boundaryField()[pi].patchNeighbourField();
00227         }
00228         else
00229         {
00230             sf.boundaryField()[pi] = vf.boundaryField()[pi];
00231         }
00232     }
00233 
00234     tlambdas.clear();
00235     tys.clear();
00236 
00237     return tsf;
00238 }
00239 
00240 
00241 //- Return the face-interpolate of the given cell field
00242 //  with the given weigting factors
00243 template<class Type>
00244 tmp<GeometricField<Type, fvsPatchField, surfaceMesh> >
00245 surfaceInterpolationScheme<Type>::interpolate
00246 (
00247     const GeometricField<Type, fvPatchField, volMesh>& vf,
00248     const tmp<surfaceScalarField>& tlambdas
00249 )
00250 {
00251     if (surfaceInterpolation::debug)
00252     {
00253         Info<< "surfaceInterpolationScheme<Type>::interpolate"
00254                "(const GeometricField<Type, fvPatchField, volMesh>&, "
00255                "const tmp<surfaceScalarField>&) : "
00256                "interpolating volTypeField from cells to faces "
00257                "without explicit correction"
00258             << endl;
00259     }
00260 
00261     const surfaceScalarField& lambdas = tlambdas();
00262 
00263     const Field<Type>& vfi = vf.internalField();
00264     const scalarField& lambda = lambdas.internalField();
00265 
00266     const fvMesh& mesh = vf.mesh();
00267     const unallocLabelList& P = mesh.owner();
00268     const unallocLabelList& N = mesh.neighbour();
00269 
00270     tmp<GeometricField<Type, fvsPatchField, surfaceMesh> > tsf
00271     (
00272         new GeometricField<Type, fvsPatchField, surfaceMesh>
00273         (
00274             IOobject
00275             (
00276                 "interpolate("+vf.name()+')',
00277                 vf.instance(),
00278                 vf.db()
00279             ),
00280             mesh,
00281             vf.dimensions()
00282         )
00283     );
00284     GeometricField<Type, fvsPatchField, surfaceMesh>& sf = tsf();
00285 
00286     Field<Type>& sfi = sf.internalField();
00287 
00288     for (register label fi=0; fi<P.size(); fi++)
00289     {
00290         sfi[fi] = lambda[fi]*(vfi[P[fi]] - vfi[N[fi]]) + vfi[N[fi]];
00291     }
00292 
00293     // Interpolate across coupled patches using given lambdas
00294 
00295     forAll (lambdas.boundaryField(), pi)
00296     {
00297         const fvsPatchScalarField& pLambda = lambdas.boundaryField()[pi];
00298 
00299         if (vf.boundaryField()[pi].coupled())
00300         {
00301             tsf().boundaryField()[pi] =
00302                 pLambda*vf.boundaryField()[pi].patchInternalField()
00303              + (1.0 - pLambda)*vf.boundaryField()[pi].patchNeighbourField();
00304         }
00305         else
00306         {
00307             sf.boundaryField()[pi] = vf.boundaryField()[pi];
00308         }
00309     }
00310 
00311     tlambdas.clear();
00312 
00313     return tsf;
00314 }
00315 
00316 
00317 //- Return the face-interpolate of the given cell field
00318 //  with explicit correction
00319 template<class Type>
00320 tmp<GeometricField<Type, fvsPatchField, surfaceMesh> >
00321 surfaceInterpolationScheme<Type>::interpolate
00322 (
00323     const GeometricField<Type, fvPatchField, volMesh>& vf
00324 ) const
00325 {
00326     if (surfaceInterpolation::debug)
00327     {
00328         Info<< "surfaceInterpolationScheme<Type>::interpolate"
00329                "(const GeometricField<Type, fvPatchField, volMesh>&) : "
00330             << "interpolating volTypeField from cells to faces"
00331             << endl;
00332     }
00333 
00334     tmp<GeometricField<Type, fvsPatchField, surfaceMesh> > tsf
00335         = interpolate(vf, weights(vf));
00336 
00337     if (corrected())
00338     {
00339         tsf() += correction(vf);
00340     }
00341 
00342     return tsf;
00343 }
00344 
00345 
00346 //- Return the face-interpolate of the given cell field
00347 //  with explicit correction
00348 template<class Type>
00349 tmp<GeometricField<Type, fvsPatchField, surfaceMesh> >
00350 surfaceInterpolationScheme<Type>::interpolate
00351 (
00352     const tmp<GeometricField<Type, fvPatchField, volMesh> >& tvf
00353 ) const
00354 {
00355     tmp<GeometricField<Type, fvsPatchField, surfaceMesh> > tinterpVf
00356         = interpolate(tvf());
00357     tvf.clear();
00358     return tinterpVf;
00359 }
00360 
00361 
00362 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
00363 
00364 } // End namespace Foam
00365 
00366 // ************************************************************************* //
Copyright © 2000-2009 OpenCFD Ltd