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-2015 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  schemeData
63  ) << "Discretisation scheme not specified"
64  << endl << endl
65  << "Valid schemes are :" << endl
66  << MeshConstructorTablePtr_->sortedToc()
67  << exit(FatalIOError);
68  }
69 
70  const word schemeName(schemeData);
71 
72  typename MeshConstructorTable::iterator constructorIter =
73  MeshConstructorTablePtr_->find(schemeName);
74 
75  if (constructorIter == MeshConstructorTablePtr_->end())
76  {
78  (
79  schemeData
80  ) << "Unknown discretisation scheme "
81  << schemeName << nl << nl
82  << "Valid schemes are :" << endl
83  << MeshConstructorTablePtr_->sortedToc()
84  << exit(FatalIOError);
85  }
86 
87  return constructorIter()(mesh, schemeData);
88 }
89 
90 
91 // * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
92 
93 template<class Type>
95 {}
96 
97 
98 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
99 
100 template<class Type>
103 (
105  const tmp<surfaceScalarField>& tdeltaCoeffs,
106  const word& snGradName
107 )
108 {
109  const fvMesh& mesh = vf.mesh();
110 
111  // construct GeometricField<Type, fvsPatchField, surfaceMesh>
113  (
115  (
116  IOobject
117  (
118  snGradName + "("+vf.name()+')',
119  vf.instance(),
120  vf.mesh(),
123  ),
124  mesh,
125  vf.dimensions()*tdeltaCoeffs().dimensions()
126  )
127  );
129 
130  // set reference to difference factors array
131  const scalarField& deltaCoeffs = tdeltaCoeffs().internalField();
132 
133  // owner/neighbour addressing
134  const labelUList& owner = mesh.owner();
135  const labelUList& neighbour = mesh.neighbour();
136 
137  forAll(owner, facei)
138  {
139  ssf[facei] =
140  deltaCoeffs[facei]*(vf[neighbour[facei]] - vf[owner[facei]]);
141  }
142 
144  {
145  const fvPatchField<Type>& pvf = vf.boundaryField()[patchi];
146 
147  if (pvf.coupled())
148  {
149  ssf.boundaryField()[patchi] =
150  pvf.snGrad(tdeltaCoeffs().boundaryField()[patchi]);
151  }
152  else
153  {
154  ssf.boundaryField()[patchi] = pvf.snGrad();
155  }
156  }
157 
158  return tsf;
159 }
160 
161 
162 template<class Type>
165 (
167  const word& sndGradName
168 )
169 {
170  return snGrad(vf, vf.mesh().nonOrthDeltaCoeffs(), sndGradName);
171 }
172 
173 
174 //- Return the face-snGrad of the given cell field
175 // with explicit correction
176 template<class Type>
179 (
181 ) const
182 {
184  (
185  snGrad(vf, deltaCoeffs(vf))
186  );
187 
188  if (corrected())
189  {
190  tsf() += correction(vf);
191  }
192 
193  return tsf;
194 }
195 
196 
197 //- Return the face-snGrad of the given cell field
198 // with explicit correction
199 template<class Type>
202 (
204 ) const
205 {
207  (
208  snGrad(tvf())
209  );
210 
211  tsf.clear();
212  return tsf;
213 }
214 
215 
216 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
217 
218 } // End namespace fv
219 
220 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
221 
222 } // End namespace Foam
223 
224 // ************************************************************************* //
Foam::fvPatchField< Type >
volFields.H
Foam::fvc::snGrad
tmp< GeometricField< Type, fvsPatchField, surfaceMesh > > snGrad(const GeometricField< Type, fvPatchField, volMesh > &vf, const word &name)
Definition: fvcSnGrad.C:45
Foam::fvPatchField::snGrad
virtual tmp< Field< Type > > snGrad() const
Return patch-normal gradient.
Definition: fvPatchField.C:200
Foam::IOobject
IOobject defines the attributes of an object for which implicit objectRegistry management is supporte...
Definition: IOobject.H:91
Foam::word
A class for handling words, derived from string.
Definition: word.H:59
fv.H
HashTable.H
forAll
#define forAll(list, i)
Loop across all elements in list.
Definition: UList.H:406
Foam::tmp
A class for managing temporary objects.
Definition: PtrList.H:118
Foam::IOstream::eof
bool eof() const
Return true if end of input seen.
Definition: IOstream.H:339
Foam::GeometricField::boundaryField
GeometricBoundaryField & boundaryField()
Return reference to GeometricBoundaryField.
Definition: GeometricField.C:735
Foam::FatalIOError
IOerror FatalIOError
Foam::endl
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:251
surfaceFields.H
Foam::surfaceFields.
Foam::correction
tmp< fvMatrix< Type > > correction(const fvMatrix< Type > &)
Return the correction form of the given matrix.
Foam::IOobject::NO_WRITE
@ NO_WRITE
Definition: IOobject.H:118
Foam::fvPatchField::coupled
virtual bool coupled() const
Return true if this patch field is coupled.
Definition: fvPatchField.H:342
Foam::Field
Pre-declare SubField and related Field type.
Definition: Field.H:57
Foam::Istream
An Istream is an abstract base class for all input systems (streams, files, token lists etc)....
Definition: Istream.H:57
Foam::IOobject::NO_READ
@ NO_READ
Definition: IOobject.H:111
Foam::nl
static const char nl
Definition: Ostream.H:260
Foam::Info
messageStream Info
Foam::fv::snGradScheme::~snGradScheme
virtual ~snGradScheme()
Destructor.
Definition: snGradScheme.C:94
mesh
dynamicFvMesh & mesh
Definition: createDynamicFvMesh.H:18
boundaryField
cellIbMask *cellIbMaskExt *faceIbMask *cellIbMask boundaryField().evaluateCoupled()
Foam::fvMesh
Mesh data needed to do the Finite Volume discretisation.
Definition: fvMesh.H:78
Foam
Namespace for OpenFOAM.
Definition: combustionModel.C:30
Foam::exit
errorManipArg< error, int > exit(error &err, const int errNo=1)
Definition: errorManip.H:124
fv
labelList fv(nPoints)
Foam::UList
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
patchi
label patchi
Definition: getPatchFieldScalar.H:1
Foam::fv::snGradScheme::New
static tmp< snGradScheme< Type > > New(const fvMesh &mesh, Istream &schemeData)
Return new tmp interpolation scheme.
Definition: snGradScheme.C:46
FatalIOErrorInFunction
#define FatalIOErrorInFunction(ios)
Report an error message using Foam::FatalIOError.
Definition: error.H:330
Foam::fv::snGradScheme::snGrad
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:103
snGradScheme.H
Foam::GeometricField
Generic GeometricField class.
Definition: surfaceFieldsFwd.H:52
Foam::tmp::clear
void clear() const
If object pointer points to valid object:
Definition: tmpI.H:172
Foam::fv::snGradScheme::sndGrad
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:165