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 
39 defineTypeNameAndDebug(incompressibleAdjointVars, 0);
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  (
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:51
Foam::objectiveManager
class for managing incompressible objective functions.
Definition: objectiveManager.H:54
Foam::solverControl::doAverageIter
bool doAverageIter() const
Definition: solverControlI.H:81
Foam::incompressibleAdjointVars::computeMeanFields
void computeMeanFields()
Compute mean fields on the fly.
Definition: incompressibleAdjointVars.C:101
Foam::incompressibleAdjointMeanFlowVars::nullify
virtual void nullify()
Nullify all adjoint fields.
Definition: incompressibleAdjointMeanFlowVars.C:273
Foam::incompressibleAdjointVars::incompressibleAdjointVars
incompressibleAdjointVars(const incompressibleAdjointVars &)
No copy construct.
Foam::Zero
static constexpr const zero Zero
Global zero (0)
Definition: zero.H:131
Foam::incompressibleAdjointVars::adjointTurbulence_
autoPtr< incompressibleAdjoint::adjointRASModel > adjointTurbulence_
Adjoint to the turbulence model.
Definition: incompressibleAdjointVars.H:64
Foam::incompressibleAdjointMeanFlowVars::phiaMeanPtr_
autoPtr< surfaceScalarField > phiaMeanPtr_
Definition: incompressibleAdjointMeanFlowVars.H:90
Foam::solverControl
Base class for solver control classes.
Definition: solverControl.H:51
Foam::endl
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:369
Foam::incompressibleAdjointMeanFlowVars::UaPtr_
autoPtr< volVectorField > UaPtr_
Definition: incompressibleAdjointMeanFlowVars.H:82
Foam::incompressibleAdjointMeanFlowVars::paPtr_
autoPtr< volScalarField > paPtr_
Definition: incompressibleAdjointMeanFlowVars.H:81
Foam::dimensionedVector
dimensioned< vector > dimensionedVector
Dimensioned vector obtained from generic dimensioned type.
Definition: dimensionedVector.H:50
Foam::Info
messageStream Info
Information stream (stdout output on master, null elsewhere)
Foam::dimensionedScalar
dimensioned< scalar > dimensionedScalar
Dimensioned scalar obtained from generic dimensioned type.
Definition: dimensionedScalarFwd.H:42
Foam::incompressibleAdjointVars::resetMeanFields
void resetMeanFields()
Reset mean fields to zero.
Definition: incompressibleAdjointVars.C:83
Foam::solverControl::averageIter
label & averageIter()
Return average iteration index reference.
Definition: solverControlI.H:63
Foam::incompressibleAdjointMeanFlowVars::UaMeanPtr_
autoPtr< volVectorField > UaMeanPtr_
Definition: incompressibleAdjointMeanFlowVars.H:89
Foam::incompressibleAdjointMeanFlowVars::paMeanPtr_
autoPtr< volScalarField > paMeanPtr_
Definition: incompressibleAdjointMeanFlowVars.H:88
mesh
dynamicFvMesh & mesh
Definition: createDynamicFvMesh.H:6
Foam::fvMesh
Mesh data needed to do the Finite Volume discretisation.
Definition: fvMesh.H:85
Foam
Namespace for OpenFOAM.
Definition: atmBoundaryLayer.C:33
Foam::incompressibleAdjointMeanFlowVars::solverControl_
solverControl & solverControl_
Reference to the solverControl of the solver allocating the fields.
Definition: incompressibleAdjointMeanFlowVars.H:74
incompressibleAdjointVars.H
Foam::autoPtr
Pointer management similar to std::unique_ptr, with some additional methods and type checking.
Definition: HashPtrTable.H:53
Foam::incompressibleAdjointVars::nullify
virtual void nullify()
Nullify all adjoint fields.
Definition: incompressibleAdjointVars.C:119
Foam::incompressibleAdjointVars::adjointTurbulence
const autoPtr< incompressibleAdjoint::adjointRASModel > & adjointTurbulence() const
Return const reference to the adjointRASModel.
Definition: incompressibleAdjointVars.C:70
Foam::incompressibleAdjointMeanFlowVars::phiaPtr_
autoPtr< surfaceScalarField > phiaPtr_
Definition: incompressibleAdjointMeanFlowVars.H:83
Foam::defineTypeNameAndDebug
defineTypeNameAndDebug(combustionModel, 0)
Foam::solverControl::average
bool average() const
Whether averaging is enabled or not.
Definition: solverControlI.H:107
Foam::incompressibleVars
Base class for solution control classes.
Definition: incompressibleVars.H:54
Foam::incompressibleAdjoint::adjointRASModel::New
static autoPtr< adjointRASModel > New(incompressibleVars &primalVars, incompressibleAdjointMeanFlowVars &adjointVars, objectiveManager &objManager, const word &adjointTurbulenceModelName=adjointTurbulenceModel::typeName)
Return a reference to the selected adjointRAS model.
Definition: adjointRASModel.C:163