objectivePartialVolume.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-2020 OpenCFD Ltd.
11-------------------------------------------------------------------------------
12License
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 "createZeroField.H"
32#include "IOmanip.H"
34
35// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
36
37namespace Foam
38{
39
40namespace objectives
41{
42
43// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
44
47(
51);
52
53
54// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
55
57(
58 const fvMesh& mesh,
59 const dictionary& dict,
60 const word& adjointSolverName,
61 const word& primalSolverName
62)
63:
64 objectiveIncompressible(mesh, dict, adjointSolverName, primalSolverName),
65 initVol_(Zero),
66 objectivePatches_
67 (
68 mesh_.boundaryMesh().patchSet
69 (
70 dict.get<wordRes>("patches")
71 ).sortedToc()
72 )
73{
74 // Read target volume if present. Else use the current one as a target
75 if (!dict.readIfPresent("initialVolume", initVol_))
76 {
77 const scalar oneThird(1.0/3.0);
78 for (const label patchi : objectivePatches_)
79 {
80 const fvPatch& patch = mesh_.boundary()[patchi];
81 initVol_ -= oneThird*gSum(patch.Sf() & patch.Cf());
82 }
83 }
84 // Allocate boundary field pointers
85 bdxdbDirectMultPtr_.reset(createZeroBoundaryPtr<vector>(mesh_));
86 bdSdbMultPtr_.reset(createZeroBoundaryPtr<vector>(mesh_));
87}
88
89
90// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
91
92
94{
95 J_ = Zero;
96 const scalar oneThird(1.0/3.0);
97 for (const label patchi : objectivePatches_)
98 {
99 const fvPatch& patch = mesh_.boundary()[patchi];
100 J_ -= oneThird*gSum(patch.Sf() & patch.Cf());
101 }
102 J_ -= initVol_;
103 J_ /= initVol_;
104 return J_;
105}
106
107
109{
110 const scalar oneThird(1.0/3.0);
111 for (const label patchi : objectivePatches_)
112 {
113 const fvPatch& patch = mesh_.boundary()[patchi];
114 tmp<vectorField> tnf = patch.nf();
115 const vectorField& nf = tnf();
116 bdxdbDirectMultPtr_()[patchi] = -oneThird*nf/initVol_;
117 }
118}
119
120
122{
123 const scalar oneThird(1.0/3.0);
124 for (const label patchi : objectivePatches_)
125 {
126 const fvPatch& patch = mesh_.boundary()[patchi];
127 bdSdbMultPtr_()[patchi] = -oneThird*patch.Cf()/initVol_;
128 }
129}
130
131
133{
135 << setw(width_) << "#VInit" << " "
136 << setw(width_) << initVol_ << endl;
137}
138
139
140// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
141
142} // End namespace objectives
143} // End namespace Foam
144
145// ************************************************************************* //
Istream and Ostream manipulators taking arguments.
Macros for easy insertion into run-time selection tables.
#define addToRunTimeSelectionTable(baseType, thisType, argNames)
Add to construction table with typeName as the key.
Addressing for all faces on surface of mesh. Can either be read from polyMesh or from triSurface....
Definition: boundaryMesh.H:63
A list of keyword definitions, which are a keyword followed by a number of values (eg,...
Definition: dictionary.H:126
bool readIfPresent(const word &keyword, T &val, enum keyType::option matchOpt=keyType::REGEX) const
Mesh data needed to do the Finite Volume discretisation.
Definition: fvMesh.H:91
const fvBoundaryMesh & boundary() const
Return reference to boundary mesh.
Definition: fvMesh.C:712
A finiteVolume patch using a polyPatch and a fvBoundaryMesh.
Definition: fvPatch.H:71
Abstract base class for objective functions in incompressible flows.
const fvMesh & mesh_
Definition: objective.H:67
autoPtr< boundaryVectorField > bdSdbMultPtr_
Term multiplying delta(n dS)/delta b.
Definition: objective.H:109
autoPtr< OFstream > objFunctionFilePtr_
File to keep the objective values after the end of the primal solver.
Definition: objective.H:141
autoPtr< boundaryVectorField > bdxdbDirectMultPtr_
Definition: objective.H:120
unsigned int width_
Default width of entries when writing in the objective files.
Definition: objective.H:152
scalar J_
Objective function value and weight.
Definition: objective.H:77
const dictionary & dict() const
Return objective dictionary.
Definition: objective.C:94
scalar J()
Return the objective function value.
virtual void addHeaderInfo() const
Write headers for additional columns.
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
Namespace for OpenFOAM.
Type gSum(const FieldField< Field, Type > &f)
static constexpr scalar oneThird
Definition: colourTools.C:42
Omanip< int > setw(const int i)
Definition: IOmanip.H:199
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:372
static constexpr const zero Zero
Global zero (0)
Definition: zero.H:131
dictionary dict