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) 2011-2013 OpenFOAM Foundation
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 "fv.H"
27 #include "snGradScheme.H"
28 #include "volFields.H"
29 #include "surfaceFields.H"
30 #include "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  const 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 "
83  << schemeName << nl << nl
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 labelUList& owner = mesh.owner();
137  const labelUList& neighbour = mesh.neighbour();
138 
139  forAll(owner, facei)
140  {
141  ssf[facei] =
142  deltaCoeffs[facei]*(vf[neighbour[facei]] - vf[owner[facei]]);
143  }
144 
146  {
147  const fvPatchField<Type>& pvf = vf.boundaryField()[patchi];
148 
149  if (pvf.coupled())
150  {
151  ssf.boundaryField()[patchi] =
152  pvf.snGrad(tdeltaCoeffs().boundaryField()[patchi]);
153  }
154  else
155  {
156  ssf.boundaryField()[patchi] = pvf.snGrad();
157  }
158  }
159 
160  return tsf;
161 }
162 
163 
164 template<class Type>
167 (
169  const word& sndGradName
170 )
171 {
172  return snGrad(vf, vf.mesh().nonOrthDeltaCoeffs(), sndGradName);
173 }
174 
175 
176 //- Return the face-snGrad of the given cell field
177 // with explicit correction
178 template<class Type>
181 (
183 ) const
184 {
186  (
187  snGrad(vf, deltaCoeffs(vf))
188  );
189 
190  if (corrected())
191  {
192  tsf() += correction(vf);
193  }
194 
195  return tsf;
196 }
197 
198 
199 //- Return the face-snGrad of the given cell field
200 // with explicit correction
201 template<class Type>
204 (
206 ) const
207 {
209  (
210  snGrad(tvf())
211  );
212 
213  tsf.clear();
214  return tsf;
215 }
216 
217 
218 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
219 
220 } // End namespace fv
221 
222 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
223 
224 } // End namespace Foam
225 
226 // ************************************************************************* //
virtual tmp< Field< Type > > snGrad() const
Return patch-normal gradient.
Definition: fvPatchField.C:207
Mesh data needed to do the Finite Volume discretisation.
Definition: fvMesh.H:78
Foam::surfaceFields.
tmp< fvMatrix< Type > > correction(const fvMatrix< Type > &)
Return the correction form of the given matrix.
GeometricBoundaryField & boundaryField()
Return reference to GeometricBoundaryField.
void clear() const
If object pointer points to valid object:
Definition: tmpI.H:174
An Istream is an abstract base class for all input systems (streams, files, token lists etc)...
Definition: Istream.H:57
A class for handling words, derived from string.
Definition: word.H:59
errorManipArg< error, int > exit(error &err, const int errNo=1)
Definition: errorManip.H:124
const fileName & instance() const
Definition: IOobject.H:337
const labelUList & owner() const
Internal face owner.
Definition: fvMesh.H:282
messageStream Info
const Mesh & mesh() const
Return mesh.
dynamicFvMesh & mesh
virtual ~snGradScheme()
Destructor.
Definition: snGradScheme.C:96
virtual bool coupled() const
Return true if this patch field is coupled.
Definition: fvPatchField.H:342
Namespace for OpenFOAM.
static tmp< snGradScheme< Type > > New(const fvMesh &mesh, Istream &schemeData)
Return new tmp interpolation scheme.
Definition: snGradScheme.C:46
bool eof() const
Return true if end of input seen.
Definition: IOstream.H:339
static tmp< GeometricField< Type, fvsPatchField, surfaceMesh > > snGrad(const GeometricField< Type, fvPatchField, volMesh > &, const tmp< surfaceScalarField > &, const word &snGradName="snGrad")
Return the snGrad of the given cell field with the given deltaCoeffs.
Definition: snGradScheme.C:105
static const char nl
Definition: Ostream.H:260
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:251
IOerror FatalIOError
IOobject defines the attributes of an object for which implicit objectRegistry management is supporte...
Definition: IOobject.H:91
#define forAll(list, i)
Definition: UList.H:421
label patchi
tmp< GeometricField< Type, fvsPatchField, surfaceMesh > > snGrad(const GeometricField< Type, fvPatchField, volMesh > &vf, const word &name)
Definition: fvcSnGrad.C:45
const dimensionSet & dimensions() const
Return dimensions.
Abstract base class with a fat-interface to all derived classes covering all possible ways in which t...
Definition: fvPatchField.H:65
const word & name() const
Return name.
Definition: IOobject.H:260
Generic GeometricField class.
labelList fv(nPoints)
static tmp< GeometricField< Type, fvsPatchField, surfaceMesh > > sndGrad(const GeometricField< Type, fvPatchField, volMesh > &, const word &snGradName="sndGrad")
Return the sndGrad of the given cell field.
Definition: snGradScheme.C:167
A 1D vector of objects of type <T>, where the size of the vector is known and can be used for subscri...
Definition: HashTable.H:60
const labelUList & neighbour() const
Internal face neighbour.
Definition: fvMesh.H:288
#define FatalIOErrorIn(functionName, ios)
Report an error message using Foam::FatalIOError.
Definition: error.H:325
A class for managing temporary objects.
Definition: PtrList.H:118