initial commit for version 1.6.x patch release
[OpenFOAM-1.6.x.git] / src / finiteVolume / finiteVolume / snGradSchemes / snGradScheme / snGradScheme.C
blob54f5ff546043ede3c74d070ba0403cbae1a2afc6
1 /*---------------------------------------------------------------------------*\
2   =========                 |
3   \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox
4    \\    /   O peration     |
5     \\  /    A nd           | Copyright (C) 1991-2009 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 the
13     Free Software Foundation; either version 2 of the License, or (at your
14     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, write to the Free Software Foundation,
23     Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
25 \*---------------------------------------------------------------------------*/
27 #include "fv.H"
28 #include "snGradScheme.H"
29 #include "volFields.H"
30 #include "surfaceFields.H"
31 #include "HashTable.H"
33 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
35 namespace Foam
38 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
40 namespace fv
43 // * * * * * * * * * * * * * * * * * Selectors * * * * * * * * * * * * * * * //
45 template<class Type>
46 tmp<snGradScheme<Type> > snGradScheme<Type>::New
48     const fvMesh& mesh,
49     Istream& schemeData
52     if (fv::debug)
53     {
54         Info<< "snGradScheme<Type>::New(const fvMesh&, Istream&)"
55                " : constructing snGradScheme<Type>"
56             << endl;
57     }
59     if (schemeData.eof())
60     {
61         FatalIOErrorIn
62         (
63             "snGradScheme<Type>::New(const fvMesh&, Istream&)",
64             schemeData
65         )   << "Discretisation scheme not specified"
66             << endl << endl
67             << "Valid schemes are :" << endl
68             << MeshConstructorTablePtr_->toc()
69             << exit(FatalIOError);
70     }
72     word schemeName(schemeData);
74     typename MeshConstructorTable::iterator constructorIter =
75         MeshConstructorTablePtr_->find(schemeName);
77     if (constructorIter == MeshConstructorTablePtr_->end())
78     {
79         FatalIOErrorIn
80         (
81             "snGradScheme<Type>::New(const fvMesh&, Istream&)",
82             schemeData
83         )   << "Unknown discretisation scheme " << schemeName
84             << endl << endl
85             << "Valid schemes are :" << endl
86             << MeshConstructorTablePtr_->toc()
87             << exit(FatalIOError);
88     }
90     return constructorIter()(mesh, schemeData);
94 // * * * * * * * * * * * * * * * * Destructor  * * * * * * * * * * * * * * * //
96 template<class Type>
97 snGradScheme<Type>::~snGradScheme()
101 // * * * * * * * * * * * * * * * Member Functions  * * * * * * * * * * * * * //
103 template<class Type>
104 tmp<GeometricField<Type, fvsPatchField, surfaceMesh> >
105 snGradScheme<Type>::snGrad
107     const GeometricField<Type, fvPatchField, volMesh>& vf,
108     const tmp<surfaceScalarField>& tdeltaCoeffs,
109     const word& snGradName
112     const fvMesh& mesh = vf.mesh();
114     // construct GeometricField<Type, fvsPatchField, surfaceMesh>
115     tmp<GeometricField<Type, fvsPatchField, surfaceMesh> > tssf
116     (
117         new GeometricField<Type, fvsPatchField, surfaceMesh>
118         (
119             IOobject
120             (
121                 snGradName + "("+vf.name()+')',
122                 vf.instance(),
123                 vf.mesh(),
124                 IOobject::NO_READ,
125                 IOobject::NO_WRITE
126             ),
127             mesh,
128             vf.dimensions()*tdeltaCoeffs().dimensions()
129         )
130     );
131     GeometricField<Type, fvsPatchField, surfaceMesh>& ssf = tssf();
133     // set reference to difference factors array
134     const scalarField& deltaCoeffs = tdeltaCoeffs().internalField();
136     // owner/neighbour addressing
137     const unallocLabelList& owner = mesh.owner();
138     const unallocLabelList& neighbour = mesh.neighbour();
140     forAll(owner, faceI)
141     {
142         ssf[faceI] =
143             deltaCoeffs[faceI]*(vf[neighbour[faceI]] - vf[owner[faceI]]);
144     }
146     forAll(vf.boundaryField(), patchI)
147     {
148         ssf.boundaryField()[patchI] = vf.boundaryField()[patchI].snGrad();
149     }
151     return tssf;
155 //- Return the face-snGrad of the given cell field
156 //  with explicit correction
157 template<class Type>
158 tmp<GeometricField<Type, fvsPatchField, surfaceMesh> >
159 snGradScheme<Type>::snGrad
161     const GeometricField<Type, fvPatchField, volMesh>& vf
162 ) const
164     tmp<GeometricField<Type, fvsPatchField, surfaceMesh> > tsf
165         = snGrad(vf, deltaCoeffs(vf));
167     if (corrected())
168     {
169         tsf() += correction(vf);
170     }
172     return tsf;
176 //- Return the face-snGrad of the given cell field
177 //  with explicit correction
178 template<class Type>
179 tmp<GeometricField<Type, fvsPatchField, surfaceMesh> >
180 snGradScheme<Type>::snGrad
182     const tmp<GeometricField<Type, fvPatchField, volMesh> >& tvf
183 ) const
185     tmp<GeometricField<Type, fvsPatchField, surfaceMesh> > tinterpVf
186         = snGrad(tvf());
187     tvf.clear();
188     return tinterpVf;
192 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
194 } // End namespace fv
196 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
198 } // End namespace Foam
200 // ************************************************************************* //