FreeFOAM The Cross-Platform CFD Toolkit
snGradScheme.C
Go to the documentation of this file.
1 /*---------------------------------------------------------------------------*\
2  ========= |
3  \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
4  \\ / O peration |
5  \\ / A nd | Copyright (C) 1991-2010 OpenCFD Ltd.
6  \\/ M anipulation |
7 -------------------------------------------------------------------------------
8 License
9  This file is part of OpenFOAM.
10 
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
13  the Free Software Foundation, either version 3 of the License, or
14  (at your option) any later version.
15 
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.
20 
21  You should have received a copy of the GNU General Public License
22  along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
23 
24 \*---------------------------------------------------------------------------*/
25 
26 #include <finiteVolume/fv.H>
27 #include "snGradScheme.H"
28 #include <finiteVolume/volFields.H>
30 #include <OpenFOAM/HashTable.H>
31 
32 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
33 
34 namespace Foam
35 {
36 
37 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
38 
39 namespace fv
40 {
41 
42 // * * * * * * * * * * * * * * * * * Selectors * * * * * * * * * * * * * * * //
43 
44 template<class Type>
45 tmp<snGradScheme<Type> > snGradScheme<Type>::New
46 (
47  const fvMesh& mesh,
48  Istream& schemeData
49 )
50 {
51  if (fv::debug)
52  {
53  Info<< "snGradScheme<Type>::New(const fvMesh&, Istream&)"
54  " : constructing snGradScheme<Type>"
55  << endl;
56  }
57 
58  if (schemeData.eof())
59  {
61  (
62  "snGradScheme<Type>::New(const fvMesh&, Istream&)",
63  schemeData
64  ) << "Discretisation scheme not specified"
65  << endl << endl
66  << "Valid schemes are :" << endl
67  << MeshConstructorTablePtr_->sortedToc()
68  << exit(FatalIOError);
69  }
70 
71  word schemeName(schemeData);
72 
73  typename MeshConstructorTable::iterator constructorIter =
74  MeshConstructorTablePtr_->find(schemeName);
75 
76  if (constructorIter == MeshConstructorTablePtr_->end())
77  {
79  (
80  "snGradScheme<Type>::New(const fvMesh&, Istream&)",
81  schemeData
82  ) << "Unknown discretisation scheme " << schemeName
83  << endl << endl
84  << "Valid schemes are :" << endl
85  << MeshConstructorTablePtr_->sortedToc()
86  << exit(FatalIOError);
87  }
88 
89  return constructorIter()(mesh, schemeData);
90 }
91 
92 
93 // * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
94 
95 template<class Type>
97 {}
98 
99 
100 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
101 
102 template<class Type>
105 (
107  const tmp<surfaceScalarField>& tdeltaCoeffs,
108  const word& snGradName
109 )
110 {
111  const fvMesh& mesh = vf.mesh();
112 
113  // construct GeometricField<Type, fvsPatchField, surfaceMesh>
115  (
117  (
118  IOobject
119  (
120  snGradName + "("+vf.name()+')',
121  vf.instance(),
122  vf.mesh(),
125  ),
126  mesh,
127  vf.dimensions()*tdeltaCoeffs().dimensions()
128  )
129  );
131 
132  // set reference to difference factors array
133  const scalarField& deltaCoeffs = tdeltaCoeffs().internalField();
134 
135  // owner/neighbour addressing
136  const unallocLabelList& owner = mesh.owner();
137  const unallocLabelList& neighbour = mesh.neighbour();
138 
139  forAll(owner, faceI)
140  {
141  ssf[faceI] =
142  deltaCoeffs[faceI]*(vf[neighbour[faceI]] - vf[owner[faceI]]);
143  }
144 
145  forAll(vf.boundaryField(), patchI)
146  {
147  ssf.boundaryField()[patchI] = vf.boundaryField()[patchI].snGrad();
148  }
149 
150  return tssf;
151 }
152 
153 
154 //- Return the face-snGrad of the given cell field
155 // with explicit correction
156 template<class Type>
159 (
161 ) const
162 {
164  = snGrad(vf, deltaCoeffs(vf));
165 
166  if (corrected())
167  {
168  tsf() += correction(vf);
169  }
170 
171  return tsf;
172 }
173 
174 
175 //- Return the face-snGrad of the given cell field
176 // with explicit correction
177 template<class Type>
180 (
182 ) const
183 {
185  = snGrad(tvf());
186  tvf.clear();
187  return tinterpVf;
188 }
189 
190 
191 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
192 
193 } // End namespace fv
194 
195 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
196 
197 } // End namespace Foam
198 
199 // ************************ vim: set sw=4 sts=4 et: ************************ //