kaqRWallFunctionFvPatchScalarField.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 
33 
34 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
35 
37 (
38  const fvPatch& p,
40 )
41 :
42  parent_bctype(p, iF),
44 {}
45 
46 
48 (
49  const fvPatch& p,
51  const dictionary& dict
52 )
53 :
54  parent_bctype(p, iF, dict),
55  adjointScalarBoundaryCondition(p, iF, dict.get<word>("solverName"))
56 {}
57 
58 
60 (
61  const this_bctype& ptf,
62  const fvPatch& p,
64  const fvPatchFieldMapper& mapper
65 )
66 :
67  parent_bctype(ptf, p, iF, mapper),
68  adjointScalarBoundaryCondition(p, iF, ptf.adjointSolverName_)
69 {}
70 
71 
73 (
74  const this_bctype& tkqrwfpf,
76 )
77 :
78  parent_bctype(tkqrwfpf, iF),
80 {}
81 
82 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
83 
85 (
86  fvMatrix<scalar>& matrix
87 )
88 {
89  scalarField& source = matrix.source();
90  tmp<fvPatchScalarField> tnutWall(boundaryContrPtr_->turbulentDiffusivity());
91  fvPatchScalarField& nutWall = tnutWall.constCast();
92  if (isA<nutkWallFunctionFvPatchScalarField>(nutWall))
93  {
94  const label patchi(patch().index());
95  const scalarField& magSf = patch().magSf();
96  const turbulenceModel& turbModel = db().lookupObject<turbulenceModel>
97  (
99  (
101  internalField().group()
102  )
103  );
104  const scalarField& y = turbModel.y()[patchi];
105  const tmp<scalarField> tnuw = turbModel.nu(patchi);
106  const scalarField& nuw = tnuw();
107  const auto& nutWF = refCast<nutWallFunctionFvPatchScalarField>(nutWall);
108  const wallFunctionCoefficients& wallCoeffs = nutWF.wallCoeffs();
109  const scalar Cmu = wallCoeffs.Cmu();
110  const scalar kappa = wallCoeffs.kappa();
111  const scalar E = wallCoeffs.E();
112  const scalar yPlusLam = wallCoeffs.yPlusLam();
113 
114  const scalar Cmu25 = pow025(Cmu);
115 
116  const labelUList& faceCells = patch().faceCells();
117  const fvPatchVectorField& Uw = boundaryContrPtr_->Ub();
118  const scalarField magGradUw(mag(Uw.snGrad()));
119 
120  tmp<scalarField> tdJdnut = boundaryContrPtr_->dJdnut();
121  const scalarField& dJdnut = tdJdnut();
122 
123  const tmp<volScalarField> tk = turbModel.k();
124  const volScalarField& k = tk();
125  forAll(dJdnut, facei)
126  {
127  const label celli = faceCells[facei];
128 
129  const scalar sqrtkCell(sqrt(k[celli]));
130  const scalar yPlus = Cmu25*y[facei]*sqrtkCell/nuw[facei];
131  if (yPlusLam < yPlus)
132  {
133  const scalar logEyPlus = log(E*yPlus);
134  const scalar dnut_dyPlus =
135  nuw[facei]*kappa*(logEyPlus - 1)/sqr(logEyPlus);
136  const scalar dyPlus_dk =
137  Cmu25*y[facei]/(2*nuw[facei]*sqrtkCell);
138  const scalar dnut_dk = dnut_dyPlus*dyPlus_dk;
139  source[celli] -= dJdnut[facei]*dnut_dk*magSf[facei];
140  }
141  }
142  }
143 }
144 
145 
147 {
148  this->parent_bctype::write(os);
149  os.writeEntry("solverName", adjointSolverName_);
150 }
151 
152 
153 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
154 
155 namespace Foam
156 {
158  (
160  kaqRWallFunctionFvPatchScalarField
161  );
162 }
163 
164 
165 // ************************************************************************* //
dictionary dict
const Type & lookupObject(const word &name, const bool recursive=false) const
Lookup and return const reference to the object of the given Type. Fatal if not found or the wrong ty...
dimensionedScalar log(const dimensionedScalar &ds)
dimensioned< typename typeOfMag< Type >::type > mag(const dimensioned< Type > &dt)
const objectRegistry & db() const
The associated objectRegistry.
const scalarField & magSf() const
Return face area magnitudes, like the fvMesh::magSf() method.
Definition: fvPatch.C:131
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
dimensionedSymmTensor sqr(const dimensionedVector &dv)
virtual tmp< volScalarField > nu() const =0
Return the laminar viscosity.
dimensionedScalar sqrt(const dimensionedScalar &ds)
A finiteVolume patch using a polyPatch and a fvBoundaryMesh.
Definition: fvPatch.H:70
dimensionedScalar pow025(const dimensionedScalar &ds)
label k
Boltzmann constant.
Smooth ATC in cells next to a set of patches supplied by type.
Definition: faceCells.H:52
const dimensionedScalar kappa
Coulomb constant: default SI units: [N.m2/C2].
Abstract base class for turbulence models (RAS, LES and laminar).
Macros for easy insertion into run-time selection tables.
virtual tmp< volScalarField > k() const =0
Return the turbulence kinetic energy.
#define forAll(list, i)
Loop across all elements in list.
Definition: stdFoam.H:400
constexpr const char *const group
Group name for atomic constants.
scalar y
static word groupName(StringType base, const word &group)
Create dot-delimited name.group string.
autoPtr< boundaryAdjointContribution > boundaryContrPtr_
Engine to manage contributions of the objective functions to the adjoint boundary conditions...
kaqRWallFunctionFvPatchScalarField(const fvPatch &, const DimensionedField< scalar, volMesh > &)
Construct from patch and internal field.
fvPatchField< scalar > fvPatchScalarField
static const word propertiesName
Default name of the turbulence properties dictionary.
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
virtual const labelUList & faceCells() const
Return faceCells.
Definition: fvPatch.C:107
A FieldMapper for finite-volume patch fields.
const nearWallDist & y() const
Return the near wall distances.
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.
scalar Cmu() const noexcept
Return the object: Cmu.
Field< Type > & source() noexcept
Definition: fvMatrix.H:543
scalar yPlus
virtual void manipulateMatrix(fvMatrix< scalar > &matrix)
Add source terms to the rhs of the first cell centre.
Base class for solution control classes.
Field with dimensions and associated with geometry type GeoMesh which is used to size the field and a...
const DimensionedField< scalar, volMesh > & internalField() const noexcept
Return const-reference to the dimensioned internal field.
Definition: fvPatchField.H:734
volScalarField & p
A class for managing temporary objects.
Definition: HashPtrTable.H:50
Class to host the wall-function coefficients being used in the wall function boundary conditions...
void write(vtk::formatter &fmt, const Type &val, const label n=1)
Component-wise write of a value (N times)
makePatchTypeField(fvPatchScalarField, atmBoundaryLayerInletEpsilonFvPatchScalarField)
virtual tmp< Field< Type > > snGrad() const
Return patch-normal gradient.
Namespace for OpenFOAM.