objectiveNutSqr.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-------------------------------------------------------------------------------
11License
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
29#include "objectiveNutSqr.H"
30#include "createZeroField.H"
32
33// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
34
35namespace Foam
36{
37
38namespace objectives
39{
40
41// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
42
45(
49);
50
51
52// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
53
55(
56 const fvMesh& mesh,
57 const dictionary& dict,
58 const word& adjointSolverName,
59 const word& primalSolverName
60)
61:
62 objectiveIncompressible(mesh, dict, adjointSolverName, primalSolverName),
63 zones_
64 (
65 mesh_.cellZones().indices(this->dict().get<wordRes>("zones"))
66 )
67{
68 // Allocate source term for the adjoint turbulence model
69 dJdTMvar1Ptr_.reset
70 (
71 createZeroFieldPtr<scalar>
72 (
73 mesh_,
74 "ATMSource",
76 )
77 );
78 // Allocate term to be added to volume-based sensitivity derivatives
79 divDxDbMultPtr_.reset
80 (
81 createZeroFieldPtr<scalar>
82 (
83 mesh_,
84 ("divDxdbMult"+type()) ,
85 //variable dimensions!!
86 //Dummy zeroes. Only the internalField will be used
88 )
89 );
90 // set file pointer
91 //objFunctionFilePtr_ = new OFstream(objFunctionFolder_/type());
92}
93
94
95// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
96
98{
99 J_ = Zero;
100
102 turbVars = vars_.RASModelVariables();
103 const volScalarField& nut = turbVars->nutRefInst();
104
105 //scalar zoneVol(Zero);
106 for (const label zI : zones_)
107 {
108 const cellZone& zoneI = mesh_.cellZones()[zI];
109 for (const label cellI : zoneI)
110 {
111 J_ += sqr(nut[cellI])*(mesh_.V()[cellI]);
112 //zoneVol += mesh_.V()[cellI];
113 }
114 }
116 //reduce(zoneVol, sumOp<scalar>());
117
118 return J_;
119}
120
121
123{
125 turbVars = vars_.RASModelVariables();
127 const volScalarField& nut = turbVars->nutRef();
128
129 tmp<volScalarField> tnutJacobian = turbVars->nutJacobianVar1(lamTransp);
130 const volScalarField& nutJacobian = tnutJacobian();
131
133
134 for (const label zI : zones_)
135 {
136 const cellZone& zoneI = mesh_.cellZones()[zI];
137 for (const label cellI : zoneI)
138 {
139 dJdTMvar1[cellI] = 2.*nut[cellI]*nutJacobian[cellI];
140 }
141 }
142}
143
144
146{
148 turbVars = vars_.RASModelVariables();
149 const volScalarField& nut = turbVars->nutRef();
150
151 volScalarField& divDxDbMult = divDxDbMultPtr_();
152
153 for (const label zI : zones_)
154 {
155 const cellZone& zoneI = mesh_.cellZones()[zI];
156 for (const label cellI : zoneI)
157 {
158 divDxDbMult[cellI] = sqr(nut[cellI]);
159 }
160 }
161}
162
163
164// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
165
166} // End namespace objectives
167} // End namespace Foam
168
169// ************************************************************************* //
Macros for easy insertion into run-time selection tables.
#define addToRunTimeSelectionTable(baseType, thisType, argNames)
Add to construction table with typeName as the key.
Pointer management similar to std::unique_ptr, with some additional methods and type checking.
Definition: autoPtr.H:66
A subset of mesh cells.
Definition: cellZone.H:65
A list of keyword definitions, which are a keyword followed by a number of values (eg,...
Definition: dictionary.H:126
Mesh data needed to do the Finite Volume discretisation.
Definition: fvMesh.H:91
const DimensionedField< scalar, volMesh > & V() const
Return cell volumes.
const singlePhaseTransportModel & laminarTransport() const
Return const reference to transport model.
const autoPtr< incompressible::RASModelVariables > & RASModelVariables() const
Return const reference to the turbulence model variables.
Abstract base class for objective functions in incompressible flows.
const volScalarField & dJdTMvar1()
Contribution to field adjoint turbulence model variable 1.
autoPtr< volScalarField > dJdTMvar1Ptr_
First turbulence model variable.
const incompressibleVars & vars_
const fvMesh & mesh_
Definition: objective.H:67
autoPtr< volScalarField > divDxDbMultPtr_
Multiplier of d(Volume)/db.
Definition: objective.H:132
scalar J_
Objective function value and weight.
Definition: objective.H:77
Objective qualitatively quantifying noise through the integral of the squared turbulent viscosity ove...
scalar J()
Return the objective function value.
void update_dJdTMvar1()
Update field to be added to the adjoint turbulence model PDE.
const cellZoneMesh & cellZones() const noexcept
Return cell zone mesh.
Definition: polyMesh.H:504
A simple single-phase transport model based on viscosityModel.
A class for managing temporary objects.
Definition: tmp.H:65
A List of wordRe with additional matching capabilities.
Definition: wordRes.H:54
A class for handling words, derived from Foam::string.
Definition: word.H:68
#define defineTypeNameAndDebug(Type, DebugSwitch)
Define the typeName and debug information.
Definition: className.H:121
dynamicFvMesh & mesh
scalar nut
Namespace for OpenFOAM.
const dimensionSet dimless
Dimensionless.
dimensionedSymmTensor sqr(const dimensionedVector &dv)
const dimensionSet dimTime(0, 0, 1, 0, 0, 0, 0)
Definition: dimensionSets.H:53
fileName::Type type(const fileName &name, const bool followLink=true)
Return the file type: DIRECTORY or FILE, normally following symbolic links.
Definition: MSwindows.C:598
void reduce(const List< UPstream::commsStruct > &comms, T &value, const BinaryOp &bop, const int tag, const label comm)
static constexpr const zero Zero
Global zero (0)
Definition: zero.H:131
dictionary dict