snGradScheme.C
Go to the documentation of this file.
1 /*---------------------------------------------------------------------------*\
2  ========= |
3  \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
4  \\ / O peration | Website: https://openfoam.org
5  \\ / A nd | Copyright (C) 2011-2018 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  InfoInFunction << "Constructing snGradScheme<Type>" << endl;
54  }
55 
56  if (schemeData.eof())
57  {
59  (
60  schemeData
61  ) << "Discretisation scheme not specified"
62  << endl << endl
63  << "Valid schemes are :" << endl
64  << MeshConstructorTablePtr_->sortedToc()
65  << exit(FatalIOError);
66  }
67 
68  const word schemeName(schemeData);
69 
70  typename MeshConstructorTable::iterator constructorIter =
71  MeshConstructorTablePtr_->find(schemeName);
72 
73  if (constructorIter == MeshConstructorTablePtr_->end())
74  {
76  (
77  schemeData
78  ) << "Unknown discretisation scheme "
79  << schemeName << nl << nl
80  << "Valid schemes are :" << endl
81  << MeshConstructorTablePtr_->sortedToc()
82  << exit(FatalIOError);
83  }
84 
85  return constructorIter()(mesh, schemeData);
86 }
87 
88 
89 // * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
90 
91 template<class Type>
93 {}
94 
95 
96 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
97 
98 template<class Type>
101 (
103  const tmp<surfaceScalarField>& tdeltaCoeffs,
104  const word& snGradName
105 )
106 {
107  const fvMesh& mesh = vf.mesh();
108 
109  // construct GeometricField<Type, fvsPatchField, surfaceMesh>
111  (
113  (
114  IOobject
115  (
116  snGradName + "("+vf.name()+')',
117  vf.instance(),
118  vf.mesh(),
121  ),
122  mesh,
123  vf.dimensions()*tdeltaCoeffs().dimensions()
124  )
125  );
127 
128  // set reference to difference factors array
129  const scalarField& deltaCoeffs = tdeltaCoeffs();
130 
131  // owner/neighbour addressing
132  const labelUList& owner = mesh.owner();
133  const labelUList& neighbour = mesh.neighbour();
134 
135  forAll(owner, facei)
136  {
137  ssf[facei] =
138  deltaCoeffs[facei]*(vf[neighbour[facei]] - vf[owner[facei]]);
139  }
140 
142  Boundary& ssfbf = ssf.boundaryFieldRef();
143 
145  {
146  const fvPatchField<Type>& pvf = vf.boundaryField()[patchi];
147 
148  if (pvf.coupled())
149  {
150  ssfbf[patchi] = pvf.snGrad(tdeltaCoeffs().boundaryField()[patchi]);
151  }
152  else
153  {
154  ssfbf[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 template<class Type>
177 (
179 ) const
180 {
182  (
183  snGrad(vf, deltaCoeffs(vf))
184  );
185 
186  if (corrected())
187  {
188  tsf.ref() += correction(vf);
189  }
190 
191  return tsf;
192 }
193 
194 
195 template<class Type>
198 (
200 ) const
201 {
203  (
204  snGrad(tvf())
205  );
206 
207  tsf.clear();
208  return tsf;
209 }
210 
211 
212 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
213 
214 } // End namespace fv
215 
216 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
217 
218 } // End namespace Foam
219 
220 // ************************************************************************* //
Foam::surfaceFields.
tmp< fvMatrix< Type > > correction(const fvMatrix< Type > &)
Return the correction form of the given matrix.
#define forAll(list, i)
Loop across all elements in list.
Definition: UList.H:428
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:101
const word & name() const
Return name.
Definition: IOobject.H:297
void clear() const
If object pointer points to valid object:
Definition: tmpI.H:230
virtual tmp< Field< Type > > snGrad() const
Return patch-normal gradient.
Definition: fvPatchField.C:216
errorManipArg< error, int > exit(error &err, const int errNo=1)
Definition: errorManip.H:124
const Boundary & boundaryField() const
Return const-reference to the boundary field.
T & ref() const
Return non-const reference or generate a fatal error.
Definition: tmpI.H:174
An Istream is an abstract base class for all input systems (streams, files, token lists etc)...
Definition: Istream.H:57
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
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:256
Abstract base class with a fat-interface to all derived classes covering all possible ways in which t...
Definition: fvPatchField.H:66
Generic GeometricField class.
static tmp< snGradScheme< Type > > New(const fvMesh &mesh, Istream &schemeData)
Return new tmp interpolation scheme.
Definition: snGradScheme.C:46
const labelUList & neighbour() const
Internal face neighbour.
Definition: fvMesh.H:288
const dimensionSet & dimensions() const
Return dimensions.
dynamicFvMesh & mesh
A class for handling words, derived from string.
Definition: word.H:59
labelList fv(nPoints)
virtual bool coupled() const
Return true if this patch field is coupled.
Definition: fvPatchField.H:328
bool eof() const
Return true if end of input seen.
Definition: IOstream.H:339
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:61
static const char nl
Definition: Ostream.H:265
const Mesh & mesh() const
Return mesh.
const labelUList & owner() const
Internal face owner.
Definition: fvMesh.H:282
const fileName & instance() const
Definition: IOobject.H:392
label patchi
Boundary & boundaryFieldRef()
Return a reference to the boundary field.
#define FatalIOErrorInFunction(ios)
Report an error message using Foam::FatalIOError.
Definition: error.H:331
Mesh data needed to do the Finite Volume discretisation.
Definition: fvMesh.H:78
A class for managing temporary objects.
Definition: PtrList.H:53
IOobject defines the attributes of an object for which implicit objectRegistry management is supporte...
Definition: IOobject.H:92
virtual ~snGradScheme()
Destructor.
Definition: snGradScheme.C:92
tmp< GeometricField< Type, fvsPatchField, surfaceMesh > > snGrad(const GeometricField< Type, fvPatchField, volMesh > &vf, const word &name)
Definition: fvcSnGrad.C:45
Namespace for OpenFOAM.
IOerror FatalIOError
#define InfoInFunction
Report an information message using Foam::Info.