adjointOutletVelocityFluxFvPatchVectorField.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) 2007-2020 PCOpt/NTUA
9  Copyright (C) 2013-2020 FOSS GP
10  Copyright (C) 2019 OpenCFD Ltd.
11 -------------------------------------------------------------------------------
12 License
13  This file is part of OpenFOAM.
14 
15  OpenFOAM is free software: you can redistribute it and/or modify it
16  under the terms of the GNU General Public License as published by
17  the Free Software Foundation, either version 3 of the License, or
18  (at your option) any later version.
19 
20  OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
21  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
22  FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
23  for more details.
24 
25  You should have received a copy of the GNU General Public License
26  along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
27 
28 \*---------------------------------------------------------------------------*/
29 
31 #include "emptyFvPatch.H"
32 #include "fvMatrix.H"
34 
35 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
36 
39 (
40  const fvPatch& p,
42 )
43 :
44  fixedValueFvPatchVectorField(p, iF),
45  adjointVectorBoundaryCondition(p, iF, word::null)
46 {}
47 
48 
51 (
53  const fvPatch& p,
55  const fvPatchFieldMapper& mapper
56 )
57 :
58  fixedValueFvPatchVectorField(ptf, p, iF, mapper),
60 {}
61 
62 
65 (
66  const fvPatch& p,
68  const dictionary& dict
69 )
70 :
71  fixedValueFvPatchVectorField(p, iF),
72  adjointVectorBoundaryCondition(p, iF, dict.get<word>("solverName"))
73 {
75  (
76  vectorField("value", dict, p.size())
77  );
78 }
79 
80 
83 (
86 )
87 :
88  fixedValueFvPatchVectorField(pivpvf, iF),
90 {}
91 
92 
93 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
94 
96 (
97  fvMatrix<vector>& matrix
98 )
99 {
100  vectorField& source = matrix.source();
101  const vectorField& Sf = patch().Sf();
102  const labelList& faceCells = patch().faceCells();
103  const scalarField& magSf = patch().magSf();
104  tmp<vectorField> tvelocitySource(boundaryContrPtr_->velocitySource());
105  const vectorField& velocitySource = tvelocitySource();
106  const fvPatchScalarField& pab = boundaryContrPtr_->pab();
107  const word& fieldName = internalField().name();
108  tmp<tensorField> tgradUab(computePatchGrad<vector>(fieldName));
109  const tensorField& gradUab = tgradUab();
110 
111  // Momentum diffusion coefficient
112  tmp<scalarField> tmomentumDiffusion(boundaryContrPtr_->momentumDiffusion());
113  const scalarField& momentumDiffusion = tmomentumDiffusion();
114 
115  vectorField explDiffusiveFlux
116  (
117  -momentumDiffusion*(gradUab - sphericalTensor::oneThirdI*tr(gradUab))
118  & Sf
119  );
120 
121 // const fvPatchVectorField& Ub = boundaryContrPtr_->Ub();
122 // const fvPatchVectorField& Uab = boundaryContrPtr_->Uab();
123 // vectorField cmFormTerm = (Ub & Uab)*Sf;
124 
125  forAll(faceCells, fI)
126  {
127  const label cI = faceCells[fI];
128  // Contributions from the convection and diffusion term (except from
129  // the transpose part) will be canceled out through the value and
130  // gradient coeffs. The pressure flux will be inserted later through
131  // grad(pa), so it must be canceled out here. Once the typical fluxes
132  // have been canceled out, add the objective flux. velocitySource
133  // includes also fluxes from the adjoint turbulence-dependent terms
134  // found in the adjoint momentum equations.
135  source[cI] +=
136  pab[fI]*Sf[fI]
137 // - cmFormTerm[fI]
138  + explDiffusiveFlux[fI]
139  - velocitySource[fI]*magSf[fI];
140  }
141 }
142 
143 
145 {
146  if (updated())
147  {
148  return;
149  }
150 
151  tmp<vectorField> tnf = patch().nf();
152  const vectorField& nf = tnf();
153 
154  // vectorField Ua = (patchInternalField() & nf) * nf;
155  const fvsPatchScalarField& phia = boundaryContrPtr_->phiab();
156  vectorField Ua((phia/patch().magSf())*nf);
157 
158  operator==(Ua);
159 
160  fixedValueFvPatchVectorField::updateCoeffs();
161 }
162 
163 
166 (
167  const tmp<scalarField>&
168 ) const
169 {
170  return tmp<Field<vector>>::New(this->size(), Zero);
171 }
172 
173 
176 (
177  const tmp<scalarField>&
178 ) const
179 {
180  return tmp<Field<vector>>::New(this->size(), Zero);
181 }
182 
183 
187 {
188  return tmp<Field<vector>>::New(this->size(), Zero);
189 }
190 
191 
195 {
196  return tmp<Field<vector>>::New(this->size(), Zero);
197 }
198 
199 
201 (
202  Ostream& os
203 ) const
204 {
206  writeEntry("value", os);
207  os.writeEntry("solverName", adjointSolverName_);
208 }
209 
210 
211 // * * * * * * * * * * * * * * * Member Operators * * * * * * * * * * * * * //
212 
213 void Foam::adjointOutletVelocityFluxFvPatchVectorField::operator=
214 (
215  const fvPatchField<vector>& pvf
216 )
217 {
218  fvPatchField<vector>::operator=(patch().nf()*(patch().nf() & pvf));
219 }
220 
221 
222 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
223 
224 namespace Foam
225 {
227  (
230  );
231 }
232 
233 // ************************************************************************* //
Foam::fvPatchField
Abstract base class with a fat-interface to all derived classes covering all possible ways in which t...
Definition: volSurfaceMapping.H:51
Foam::fvPatchField< vector >::write
virtual void write(Ostream &) const
Write.
Definition: fvPatchField.C:384
p
volScalarField & p
Definition: createFieldRefs.H:8
Foam::word
A class for handling words, derived from Foam::string.
Definition: word.H:65
Foam::adjointOutletVelocityFluxFvPatchVectorField::valueInternalCoeffs
virtual tmp< Field< vector > > valueInternalCoeffs(const tmp< scalarField > &) const
Definition: adjointOutletVelocityFluxFvPatchVectorField.C:166
Foam::adjointOutletVelocityFluxFvPatchVectorField::adjointOutletVelocityFluxFvPatchVectorField
adjointOutletVelocityFluxFvPatchVectorField(const fvPatch &, const DimensionedField< vector, volMesh > &)
Construct from patch and internal field.
Definition: adjointOutletVelocityFluxFvPatchVectorField.C:39
Foam::tmp
A class for managing temporary objects.
Definition: PtrList.H:61
Foam::Zero
static constexpr const zero Zero
Global zero (0)
Definition: zero.H:131
Foam::adjointOutletVelocityFluxFvPatchVectorField::write
virtual void write(Ostream &) const
Write.
Definition: adjointOutletVelocityFluxFvPatchVectorField.C:201
Foam::fvsPatchField
An abstract base class with a fat-interface to all derived classes covering all possible ways in whic...
Definition: fvsPatchField.H:68
fvMatrix.H
Foam::adjointBoundaryCondition::boundaryContrPtr_
autoPtr< boundaryAdjointContribution > boundaryContrPtr_
Definition: adjointBoundaryCondition.H:73
Foam::adjointOutletVelocityFluxFvPatchVectorField::updateCoeffs
virtual void updateCoeffs()
Update the coefficients associated with the patch field.
Definition: adjointOutletVelocityFluxFvPatchVectorField.C:144
forAll
#define forAll(list, i)
Loop across all elements in list.
Definition: stdFoam.H:296
Foam::vectorField
Field< vector > vectorField
Specialisation of Field<T> for vector.
Definition: primitiveFieldsFwd.H:54
Foam::oneThirdI
static const sphericalTensor oneThirdI(1.0/3.0)
Foam::adjointOutletVelocityFluxFvPatchVectorField::valueBoundaryCoeffs
virtual tmp< Field< vector > > valueBoundaryCoeffs(const tmp< scalarField > &) const
Definition: adjointOutletVelocityFluxFvPatchVectorField.C:176
Foam::Field< vector >
Foam::operator==
tmp< faMatrix< Type > > operator==(const faMatrix< Type > &, const faMatrix< Type > &)
Foam::adjointBoundaryCondition::adjointSolverName_
word adjointSolverName_
adjointSolver name corresponding to field
Definition: adjointBoundaryCondition.H:65
Foam::fvPatch
A finiteVolume patch using a polyPatch and a fvBoundaryMesh.
Definition: fvPatch.H:65
Foam::adjointOutletVelocityFluxFvPatchVectorField::gradientBoundaryCoeffs
virtual tmp< Field< vector > > gradientBoundaryCoeffs() const
Definition: adjointOutletVelocityFluxFvPatchVectorField.C:186
adjointOutletVelocityFluxFvPatchVectorField.H
Foam::adjointOutletVelocityFluxFvPatchVectorField
An outlet boundary condition for patches in which the primal flow exhibits recirculation....
Definition: adjointOutletVelocityFluxFvPatchVectorField.H:60
dict
dictionary dict
Definition: searchingEngine.H:14
Foam::adjointOutletVelocityFluxFvPatchVectorField::manipulateMatrix
virtual void manipulateMatrix(fvMatrix< vector > &matrix)
add source term in the first cells off the wall due to adjoint WF
Definition: adjointOutletVelocityFluxFvPatchVectorField.C:96
Foam::dictionary
A list of keyword definitions, which are a keyword followed by a number of values (eg,...
Definition: dictionary.H:123
os
OBJstream os(runTime.globalPath()/outputName)
addToRunTimeSelectionTable.H
Macros for easy insertion into run-time selection tables.
Foam::adjointVectorBoundaryCondition
adjointBoundaryCondition< vector > adjointVectorBoundaryCondition
Definition: adjointBoundaryConditionsFwd.H:44
Foam
Namespace for OpenFOAM.
Definition: atmBoundaryLayer.C:33
emptyFvPatch.H
Foam::New
tmp< DimensionedField< TypeR, GeoMesh > > New(const tmp< DimensionedField< TypeR, GeoMesh >> &tdf1, const word &name, const dimensionSet &dimensions)
Global function forwards to reuseTmpDimensionedField::New.
Definition: DimensionedFieldReuseFunctions.H:105
Foam::foamVersion::patch
const std::string patch
OpenFOAM patch number as a std::string.
Foam::List< label >
Foam::adjointOutletVelocityFluxFvPatchVectorField::gradientInternalCoeffs
virtual tmp< Field< vector > > gradientInternalCoeffs() const
Definition: adjointOutletVelocityFluxFvPatchVectorField.C:194
Foam::fvMatrix::source
Field< Type > & source()
Definition: fvMatrix.H:445
Foam::fvMatrix
A special matrix type and solver, designed for finite volume solutions of scalar equations....
Definition: fvPatchField.H:68
Foam::Ostream::writeEntry
Ostream & writeEntry(const keyType &key, const T &value)
Write a keyword/value entry.
Definition: Ostream.H:236
Foam::fvPatchFieldMapper
Foam::fvPatchFieldMapper.
Definition: fvPatchFieldMapper.H:47
Foam::tr
dimensionedScalar tr(const dimensionedSphericalTensor &dt)
Definition: dimensionedSphericalTensor.C:51
Foam::Ostream
An Ostream is an abstract base class for all output systems (streams, files, token lists,...
Definition: Ostream.H:56
Foam::makePatchTypeField
makePatchTypeField(fvPatchScalarField, atmBoundaryLayerInletEpsilonFvPatchScalarField)
Foam::fvPatchField::operator=
virtual void operator=(const UList< Type > &)
Definition: fvPatchField.C:404
Foam::faceCells
Smooth ATC in cells next to a set of patches supplied by type.
Definition: faceCells.H:56
Foam::DimensionedField
Field with dimensions and associated with geometry type GeoMesh which is used to size the field and a...
Definition: DimensionedField.H:54