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

snGradScheme.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 \*---------------------------------------------------------------------------*/
00026 
00027 #include "fv.H"
00028 #include "snGradScheme.H"
00029 #include "volFields.H"
00030 #include "surfaceFields.H"
00031 #include "HashTable.H"
00032 
00033 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
00034 
00035 namespace Foam
00036 {
00037 
00038 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
00039 
00040 namespace fv
00041 {
00042 
00043 // * * * * * * * * * * * * * * * * * Selectors * * * * * * * * * * * * * * * //
00044 
00045 template<class Type>
00046 tmp<snGradScheme<Type> > snGradScheme<Type>::New
00047 (
00048     const fvMesh& mesh,
00049     Istream& schemeData
00050 )
00051 {
00052     if (fv::debug)
00053     {
00054         Info<< "snGradScheme<Type>::New(const fvMesh&, Istream&)"
00055                " : constructing snGradScheme<Type>"
00056             << endl;
00057     }
00058 
00059     if (schemeData.eof())
00060     {
00061         FatalIOErrorIn
00062         (
00063             "snGradScheme<Type>::New(const fvMesh&, Istream&)",
00064             schemeData
00065         )   << "Discretisation scheme not specified"
00066             << endl << endl
00067             << "Valid schemes are :" << endl
00068             << MeshConstructorTablePtr_->toc()
00069             << exit(FatalIOError);
00070     }
00071 
00072     word schemeName(schemeData);
00073 
00074     typename MeshConstructorTable::iterator constructorIter =
00075         MeshConstructorTablePtr_->find(schemeName);
00076 
00077     if (constructorIter == MeshConstructorTablePtr_->end())
00078     {
00079         FatalIOErrorIn
00080         (
00081             "snGradScheme<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 // * * * * * * * * * * * * * * * * Destructor  * * * * * * * * * * * * * * * //
00095 
00096 template<class Type>
00097 snGradScheme<Type>::~snGradScheme()
00098 {}
00099 
00100 
00101 // * * * * * * * * * * * * * * * Member Functions  * * * * * * * * * * * * * //
00102 
00103 template<class Type>
00104 tmp<GeometricField<Type, fvsPatchField, surfaceMesh> >
00105 snGradScheme<Type>::snGrad
00106 (
00107     const GeometricField<Type, fvPatchField, volMesh>& vf,
00108     const tmp<surfaceScalarField>& tdeltaCoeffs,
00109     const word& snGradName
00110 )
00111 {
00112     const fvMesh& mesh = vf.mesh();
00113 
00114     // construct GeometricField<Type, fvsPatchField, surfaceMesh>
00115     tmp<GeometricField<Type, fvsPatchField, surfaceMesh> > tssf
00116     (
00117         new GeometricField<Type, fvsPatchField, surfaceMesh>
00118         (
00119             IOobject
00120             (
00121                 snGradName + "("+vf.name()+')',
00122                 vf.instance(),
00123                 vf.mesh(),
00124                 IOobject::NO_READ,
00125                 IOobject::NO_WRITE
00126             ),
00127             mesh,
00128             vf.dimensions()*tdeltaCoeffs().dimensions()
00129         )
00130     );
00131     GeometricField<Type, fvsPatchField, surfaceMesh>& ssf = tssf();
00132 
00133     // set reference to difference factors array
00134     const scalarField& deltaCoeffs = tdeltaCoeffs().internalField();
00135 
00136     // owner/neighbour addressing
00137     const unallocLabelList& owner = mesh.owner();
00138     const unallocLabelList& neighbour = mesh.neighbour();
00139 
00140     forAll(owner, faceI)
00141     {
00142         ssf[faceI] =
00143             deltaCoeffs[faceI]*(vf[neighbour[faceI]] - vf[owner[faceI]]);
00144     }
00145 
00146     forAll(vf.boundaryField(), patchI)
00147     {
00148         ssf.boundaryField()[patchI] = vf.boundaryField()[patchI].snGrad();
00149     }
00150 
00151     return tssf;
00152 }
00153 
00154 
00155 //- Return the face-snGrad of the given cell field
00156 //  with explicit correction
00157 template<class Type>
00158 tmp<GeometricField<Type, fvsPatchField, surfaceMesh> >
00159 snGradScheme<Type>::snGrad
00160 (
00161     const GeometricField<Type, fvPatchField, volMesh>& vf
00162 ) const
00163 {
00164     tmp<GeometricField<Type, fvsPatchField, surfaceMesh> > tsf
00165         = snGrad(vf, deltaCoeffs(vf));
00166 
00167     if (corrected())
00168     {
00169         tsf() += correction(vf);
00170     }
00171 
00172     return tsf;
00173 }
00174 
00175 
00176 //- Return the face-snGrad of the given cell field
00177 //  with explicit correction
00178 template<class Type>
00179 tmp<GeometricField<Type, fvsPatchField, surfaceMesh> >
00180 snGradScheme<Type>::snGrad
00181 (
00182     const tmp<GeometricField<Type, fvPatchField, volMesh> >& tvf
00183 ) const
00184 {
00185     tmp<GeometricField<Type, fvsPatchField, surfaceMesh> > tinterpVf
00186         = snGrad(tvf());
00187     tvf.clear();
00188     return tinterpVf;
00189 }
00190 
00191 
00192 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
00193 
00194 } // End namespace fv
00195 
00196 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
00197 
00198 } // End namespace Foam
00199 
00200 // ************************************************************************* //
Copyright © 2000-2009 OpenCFD Ltd