incompressibleAdjointVars.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-2019 PCOpt/NTUA
9  Copyright (C) 2013-2019 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 
32 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
33 
34 namespace Foam
35 {
36 
37 // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
38 
40 
41 
42 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
43 
45 (
46  fvMesh& mesh,
47  solverControl& SolverControl,
48  objectiveManager& objManager,
49  incompressibleVars& primalVars
50 )
51 :
52  incompressibleAdjointMeanFlowVars(mesh, SolverControl, primalVars),
53  objectiveManager_(objManager),
54 
55  adjointTurbulence_
56  (
57  incompressibleAdjoint::adjointRASModel::New
58  (
59  primalVars_,
60  *this,
61  objManager
62  )
63  )
64 {}
65 
66 
67 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
68 
71 {
72  return adjointTurbulence_;
73 }
74 
75 
78 {
79  return adjointTurbulence_;
80 }
81 
82 
84 {
85  if (solverControl_.average())
86  {
87  Info<< "Resetting adjoint mean fields to zero" << endl;
88 
89  // Reset fields to zero
90  paMeanPtr_() == dimensionedScalar(paPtr_().dimensions(), Zero);
91  UaMeanPtr_() == dimensionedVector(UaPtr_().dimensions(), Zero);
92  phiaMeanPtr_() == dimensionedScalar(phiaPtr_().dimensions(), Zero);
93  adjointTurbulence_().resetMeanFields();
94 
95  // Reset averaging iteration index to 0
97  }
98 }
99 
100 
102 {
104  {
105  Info<< "Averaging adjoint fields" << endl;
106  label& iAverageIter = solverControl_.averageIter();
107  scalar avIter(iAverageIter);
108  scalar oneOverItP1 = 1./(avIter+1);
109  scalar mult = avIter*oneOverItP1;
110  paMeanPtr_() == paMeanPtr_() *mult + paPtr_() *oneOverItP1;
111  UaMeanPtr_() == UaMeanPtr_() *mult + UaPtr_() *oneOverItP1;
112  phiaMeanPtr_() == phiaMeanPtr_()*mult + phiaPtr_()*oneOverItP1;
113  adjointTurbulence_().computeMeanFields();
114  ++iAverageIter;
115  }
116 }
117 
118 
120 {
122  adjointTurbulence_->nullify();
123 }
124 
125 
126 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
127 
128 } // End namespace Foam
129 
130 // ************************************************************************* //
Foam::incompressibleAdjointMeanFlowVars
Manages the adjoint mean flow fields and their mean values.
Definition: incompressibleAdjointMeanFlowVars.H:45
Foam::objectiveManager
class for managing incompressible objective functions.
Definition: objectiveManager.H:50
Foam::solverControl::doAverageIter
bool doAverageIter() const
Definition: solverControlI.H:74
Foam::incompressibleAdjointVars::computeMeanFields
void computeMeanFields()
Definition: incompressibleAdjointVars.C:94
Foam::incompressibleAdjointMeanFlowVars::nullify
virtual void nullify()
Definition: incompressibleAdjointMeanFlowVars.C:266
Foam::incompressibleAdjointVars::incompressibleAdjointVars
incompressibleAdjointVars(const incompressibleAdjointVars &)
Foam::Zero
static constexpr const zero Zero
Definition: zero.H:131
Foam::incompressibleAdjointVars::adjointTurbulence_
autoPtr< incompressibleAdjoint::adjointRASModel > adjointTurbulence_
Definition: incompressibleAdjointVars.H:58
Foam::incompressibleAdjointMeanFlowVars::phiaMeanPtr_
autoPtr< surfaceScalarField > phiaMeanPtr_
Definition: incompressibleAdjointMeanFlowVars.H:84
Foam::solverControl
Base class for solver control classes.
Definition: solverControl.H:45
Foam::endl
Ostream & endl(Ostream &os)
Definition: Ostream.H:381
Foam::incompressibleAdjointMeanFlowVars::UaPtr_
autoPtr< volVectorField > UaPtr_
Definition: incompressibleAdjointMeanFlowVars.H:76
Foam::incompressibleAdjointMeanFlowVars::paPtr_
autoPtr< volScalarField > paPtr_
Definition: incompressibleAdjointMeanFlowVars.H:75
Foam::incompressibleAdjointVars
Class including all adjoint fields for incompressible flows.
Definition: incompressibleAdjointVars.H:46
Foam::dimensionedVector
dimensioned< vector > dimensionedVector
Dimensioned vector obtained from generic dimensioned type.
Definition: dimensionedVector.H:46
Foam::Info
messageStream Info
Foam::dimensionedScalar
dimensioned< scalar > dimensionedScalar
Dimensioned scalar obtained from generic dimensioned type.
Definition: dimensionedScalarFwd.H:36
Foam::incompressibleAdjointVars::resetMeanFields
void resetMeanFields()
Definition: incompressibleAdjointVars.C:76
Foam::incompressibleAdjointMeanFlowVars::UaMeanPtr_
autoPtr< volVectorField > UaMeanPtr_
Definition: incompressibleAdjointMeanFlowVars.H:83
Foam::incompressibleAdjointMeanFlowVars::paMeanPtr_
autoPtr< volScalarField > paMeanPtr_
Definition: incompressibleAdjointMeanFlowVars.H:82
mesh
dynamicFvMesh & mesh
Definition: createDynamicFvMesh.H:6
Foam::fvMesh
Mesh data needed to do the Finite Volume discretisation.
Definition: fvMesh.H:81
Foam
Definition: atmBoundaryLayer.C:26
Foam::New
tmp< DimensionedField< TypeR, GeoMesh > > New(const tmp< DimensionedField< TypeR, GeoMesh >> &tdf1, const word &name, const dimensionSet &dimensions)
Definition: DimensionedFieldReuseFunctions.H:100
Foam::incompressibleAdjointMeanFlowVars::solverControl_
solverControl & solverControl_
Definition: incompressibleAdjointMeanFlowVars.H:68
incompressibleAdjointVars.H
Foam::autoPtr
Pointer management similar to std::unique_ptr, with some additional methods and type checking.
Definition: HashPtrTable.H:49
Foam::incompressibleAdjointVars::nullify
virtual void nullify()
Definition: incompressibleAdjointVars.C:112
Foam::incompressibleAdjointVars::adjointTurbulence
const autoPtr< incompressibleAdjoint::adjointRASModel > & adjointTurbulence() const
Definition: incompressibleAdjointVars.C:63
Foam::incompressibleAdjointMeanFlowVars::phiaPtr_
autoPtr< surfaceScalarField > phiaPtr_
Definition: incompressibleAdjointMeanFlowVars.H:77
Foam::defineTypeNameAndDebug
defineTypeNameAndDebug(combustionModel, 0)
Foam::solverControl::average
bool average() const
Definition: solverControlI.H:100
Foam::incompressibleVars
Base class for solution control classes.
Definition: incompressibleVars.H:48
Foam::solverControl::averageIter
label & averageIter()
Definition: solverControlI.H:56
Foam::incompressibleAdjoint::adjointRASModel::New
static autoPtr< adjointRASModel > New(incompressibleVars &primalVars, incompressibleAdjointMeanFlowVars &adjointVars, objectiveManager &objManager, const word &adjointTurbulenceModelName=adjointTurbulenceModel::typeName)
Definition: adjointRASModel.C:156