FreeFOAM The Cross-Platform CFD Toolkit
Hosted by SourceForge:
Get FreeFOAM at SourceForge.net.
            Fast, secure and Free Open Source software downloads

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