waWallFunctionFvPatchScalarField.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 | www.openfoam.com
6  \\/ M anipulation |
7 -------------------------------------------------------------------------------
8  Copyright (C) 2014-2022 PCOpt/NTUA
9  Copyright (C) 2014-2022 FOSS GP
10 -------------------------------------------------------------------------------
11 License
12  This file is part of OpenFOAM.
13 
14  OpenFOAM is free software: you can redistribute it and/or modify it
15  under the terms of the GNU General Public License as published by
16  the Free Software Foundation, either version 3 of the License, or
17  (at your option) any later version.
18 
19  OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
20  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
21  FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
22  for more details.
23 
24  You should have received a copy of the GNU General Public License
25  along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
26 
27 \*---------------------------------------------------------------------------*/
28 
30 #include "wallFvPatch.H"
32 #include "fvPatchFieldMapper.H"
33 #include "volFields.H"
35 
36 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
37 
38 namespace Foam
39 {
40 
41 // * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
42 
43 void waWallFunctionFvPatchScalarField::checkType()
44 {
45  if (!isA<wallFvPatch>(patch()))
46  {
48  << "Invalid wall function specification" << nl
49  << " Patch type for patch " << patch().name()
50  << " must be wall" << nl
51  << " Current patch type is " << patch().type() << nl << endl
52  << abort(FatalError);
53  }
54 }
55 
56 
57 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
58 
60 (
61  const fvPatch& p,
62  const DimensionedField<scalar, volMesh>& iF
63 )
64 :
65  parent_bctype(p, iF),
67 {
68  checkType();
69 }
70 
71 
73 (
74  const this_bctype& ptf,
75  const fvPatch& p,
77  const fvPatchFieldMapper& mapper
78 )
79 :
80  parent_bctype(ptf, p, iF, mapper),
81  adjointScalarBoundaryCondition(p, iF, ptf.adjointSolverName_)
82 {
83  checkType();
84 }
85 
86 
88 (
89  const fvPatch& p,
91  const dictionary& dict
92 )
93 :
94  parent_bctype(p, iF, dict),
96 {
97  checkType();
98 }
99 
100 
102 (
103  const this_bctype& ewfpsf,
105 )
106 :
107  parent_bctype(ewfpsf, iF),
109 {
110  checkType();
111 }
112 
113 
114 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
115 
117 (
118  fvMatrix<scalar>& matrix
119 )
120 {
121  scalarField& Diag = matrix.diag();
122  scalarField& lower = matrix.lower();
123  scalarField& upper = matrix.upper();
124  FieldField<Field, scalar>& internalCoeffs = matrix.internalCoeffs();
125  FieldField<Field, scalar>& boundaryCoeffs = matrix.boundaryCoeffs();
126  const fvMesh& mesh = patch().boundaryMesh().mesh();
127  const labelUList& faceCells = patch().faceCells();
128 
129  // Add diag term from the omega expression next to the wall
130  for (const label celli : faceCells)
131  {
132  Diag[celli] = 1;
133  }
134 
135  // We want something similar to setValues, but slightly modified.
136  // The solution of the boundary cell should understand contributions from
137  // the second cells off the wall but they should see the
138  // solution of the boundary cell as zero.
139  // Contributions from neighbouring cells with an omegaWallFunction boundary
140  // condition should also be zero
141 
142  const cellList& cells = mesh.cells();
143  const labelUList& own = mesh.owner();
144 
145  /*
146  const labelUList& nei = mesh.neighbour();
147  const turbulenceModel& turbModel = db().lookupObject<turbulenceModel>
148  (
149  IOobject::groupName
150  (
151  turbulenceModel::propertiesName,
152  internalField().group()
153  )
154  );
155 
156  const tmp<volScalarField> tomega = turbModel.omega();
157  const volScalarField& omega = tomega();
158  typedef omegaWallFunctionFvPatchScalarField omegaWF;
159  */
160 
161  forAll(faceCells, i)
162  {
163  const label celli = faceCells[i];
164  const cell& c = cells[celli];
165 
166  forAll(c, j)
167  {
168  const label facei = c[j];
169 
170  if (mesh.isInternalFace(facei))
171  {
172  // Neighbouring cells should get no contribution from
173  // ourselves in all cases
174  //label cellNei(-1);
175  if (celli == own[facei])
176  {
177  //cellNei = nei[facei];
178  lower[facei] = 0.0;
179  }
180  else
181  {
182  //cellNei = own[facei];
183  upper[facei] = 0.0;
184  }
185  // Additionally, if the neighbouring cell is also a boundary
186  // one with omegaWallFunction in one of its faces,
187  // contributions between the two cells should be canceled out
188  // as well.
189  // Already covered by the above
190  /*
191  bool neiHasOmegaWFface(false);
192  const cell& neiCell = cells[cellNei];
193  forAll(neiCell, fNei)
194  {
195  const label faceNei = neiCell[fNei];
196 
197  const label patchNei =
198  mesh.boundaryMesh().whichPatch(faceNei);
199  if (patchNei != -1)
200  {
201  const fvPatchField& omegaNei =
202  omega.boundaryField()[patchNei];
203  if (isA<omegaWF>(omegaNei))
204  {
205  neiHasOmegaWFface = true;
206  break;
207  }
208  }
209  }
210  if (neiHasOmegaWFface)
211  {
212  if (celli == own[facei])
213  {
214  upper[facei] = 0.0;
215  }
216  else
217  {
218  lower[facei] = 0.0;
219  }
220  }
221  */
222  }
223  // Contributions from boundaries should have already been removed
224  // using value*Coeffs and boundary*Coeffs
225  // Just to be safe
226  else
227  {
228  const label patchi = mesh.boundaryMesh().whichPatch(facei);
229  if (internalCoeffs[patchi].size())
230  {
231  label patchFacei =
232  mesh.boundaryMesh()[patchi].whichFace(facei);
233  internalCoeffs[patchi][patchFacei] = Zero;
234  boundaryCoeffs[patchi][patchFacei] = Zero;
235  }
236  }
237  }
238  }
239 
241 }
242 
243 
245 {
246  if (updated())
247  {
248  return;
249  }
253 }
254 
255 
257 (
258  const tmp<scalarField>&
259 ) const
260 {
261  return tmp<Field<scalar>>::New(this->size(), Zero);
262 }
263 
264 
266 (
267  const tmp<scalarField>&
268 ) const
269 {
270  return tmp<Field<scalar>>::New(this->size(), Zero);
271 }
272 
273 
276 {
277  return tmp<Field<scalar>>::New(this->size(), Zero);
278 }
279 
280 
283 {
284  return tmp<Field<scalar>>::New(this->size(), Zero);
285 }
286 
287 
289 {
290  this->parent_bctype::write(os);
291 }
292 
293 
294 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
295 
297 (
299  waWallFunctionFvPatchScalarField
300 );
301 
302 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
303 
304 } // End namespace Foam
305 
306 // ************************************************************************* //
const scalarField & diag() const
Definition: lduMatrix.C:195
virtual void updateCoeffs()
Update the coefficients associated with the patch field.
dictionary dict
List< cell > cellList
List of cell.
Definition: cellListFwd.H:39
error FatalError
Error stream (stdout output on all processes), with additional &#39;FOAM FATAL ERROR&#39; header text and sta...
A list of keyword definitions, which are a keyword followed by a number of values (eg...
Definition: dictionary.H:130
const fvPatch & patch() const noexcept
Return the patch.
Definition: fvPatchField.H:262
#define FatalErrorInFunction
Report an error message using Foam::FatalError.
Definition: error.H:652
static tmp< fvPatchField< scalar > > New(const word &patchFieldType, const fvPatch &, const DimensionedField< scalar, volMesh > &)
Return a pointer to a new patchField created on freestore given.
constexpr char nl
The newline &#39;\n&#39; character (0x0a)
Definition: Ostream.H:50
const fvMesh & mesh() const noexcept
Return the mesh reference.
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:518
A finiteVolume patch using a polyPatch and a fvBoundaryMesh.
Definition: fvPatch.H:70
Smooth ATC in cells next to a set of patches supplied by type.
Definition: faceCells.H:52
Macros for easy insertion into run-time selection tables.
UList< label > labelUList
A UList of labels.
Definition: UList.H:76
A field of fields is a PtrList of fields with reference counting.
Definition: FieldField.H:51
virtual void manipulateMatrix(fvMatrix< scalar > &matrix)
Manipulate waEqn at the cells next to the wall.
#define forAll(list, i)
Loop across all elements in list.
Definition: stdFoam.H:400
dynamicFvMesh & mesh
const cellShapeList & cells
bool updated() const noexcept
True if the boundary condition has already been updated.
Definition: fvPatchField.H:297
virtual void updateCoeffs()
Update the coefficients associated with the patch field.
fvPatchField< scalar > fvPatchScalarField
constexpr T & get(FixedList< T, N > &list) noexcept
Definition: FixedList.H:887
A class for handling words, derived from Foam::string.
Definition: word.H:63
Field< scalar > scalarField
Specialisation of Field<T> for scalar.
virtual const labelUList & faceCells() const
Return faceCells.
Definition: fvPatch.C:107
A FieldMapper for finite-volume patch fields.
const scalarField & lower() const
Definition: lduMatrix.C:306
A special matrix type and solver, designed for finite volume solutions of scalar equations. Face addressing is used to make all matrix assembly and solution loops vectorise.
virtual tmp< Field< scalar > > gradientBoundaryCoeffs() const
Return the matrix source coefficients corresponding to the evaluation of the gradient of this patchFi...
errorManip< error > abort(error &err)
Definition: errorManip.H:139
const fvBoundaryMesh & boundaryMesh() const noexcept
Return boundaryMesh reference.
Definition: fvPatch.H:268
An Ostream is an abstract base class for all output systems (streams, files, token lists...
Definition: Ostream.H:56
label size() const noexcept
The number of elements in the container.
Definition: UList.H:707
string upper(const std::string &s)
Return string copy transformed with std::toupper on each character.
virtual tmp< Field< scalar > > valueBoundaryCoeffs(const tmp< scalarField > &) const
Return the matrix source coefficients corresponding to the evaluation of the value of this patchField...
virtual void write(Ostream &) const
Write includes "value" entry.
waWallFunctionFvPatchScalarField(const fvPatch &, const DimensionedField< scalar, volMesh > &)
Construct from patch and internal field.
const scalarField & upper() const
Definition: lduMatrix.C:235
Base class for solution control classes.
Mesh data needed to do the Finite Volume discretisation.
Definition: fvMesh.H:78
const dimensionedScalar c
Speed of light in a vacuum.
Field with dimensions and associated with geometry type GeoMesh which is used to size the field and a...
string lower(const std::string &s)
Return string copy transformed with std::tolower on each character.
const FieldField< Field, Type > & internalCoeffs() const noexcept
fvBoundary scalar field containing pseudo-matrix coeffs for internal cells
Definition: fvMatrix.H:557
const FieldField< Field, Type > & boundaryCoeffs() const noexcept
fvBoundary scalar field containing pseudo-matrix coeffs for boundary cells
Definition: fvMatrix.H:575
virtual const word & name() const
Return name.
Definition: fvPatch.H:210
volScalarField & p
A class for managing temporary objects.
Definition: HashPtrTable.H:50
virtual tmp< Field< scalar > > valueInternalCoeffs(const tmp< scalarField > &) const
Return the matrix diagonal coefficients corresponding to the evaluation of the value of this patchFie...
makePatchTypeField(fvPatchScalarField, atmBoundaryLayerInletEpsilonFvPatchScalarField)
virtual tmp< Field< scalar > > gradientInternalCoeffs() const
Return the matrix diagonal coefficients corresponding to the evaluation of the gradient of this patch...
virtual void operator==(const fvPatchField< scalar > &)
Namespace for OpenFOAM.
virtual void manipulateMatrix(fvMatrix< Type > &matrix)
Manipulate matrix.
static constexpr const zero Zero
Global zero (0)
Definition: zero.H:127