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 -------------------------------------------------------------------------------
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 
30 #include "objectivePartialVolume.H"
31 #include "createZeroField.H"
32 #include "IOmanip.H"
34 
35 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
36 
37 namespace Foam
38 {
39 
40 namespace objectives
41 {
42 
43 // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
44 
45 defineTypeNameAndDebug(objectivePartialVolume, 1);
47 (
48  objectiveIncompressible,
49  objectivePartialVolume,
50  dictionary
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 {
134  objFunctionFilePtr_()
135  << setw(width_) << "#VInit" << " "
136  << setw(width_) << initVol_ << endl;
137 }
138 
139 
140 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
141 
142 } // End namespace objectives
143 } // End namespace Foam
144 
145 // ************************************************************************* //
Foam::objectives::objectivePartialVolume::J
scalar J()
Return the objective function value.
Definition: objectivePartialVolume.C:93
Foam::oneThird
static constexpr scalar oneThird
Definition: colourTools.C:42
Foam::word
A class for handling words, derived from Foam::string.
Definition: word.H:62
Foam::tmp
A class for managing temporary objects.
Definition: PtrList.H:61
Foam::objectives::objectivePartialVolume::objectivePartialVolume
objectivePartialVolume(const fvMesh &mesh, const dictionary &dict, const word &adjointSolverName, const word &primalSolverName)
from components
Definition: objectivePartialVolume.C:57
Foam::Zero
static constexpr const zero Zero
Global zero (0)
Definition: zero.H:131
Foam::objectives::addToRunTimeSelectionTable
addToRunTimeSelectionTable(objectiveIncompressible, objectiveForce, dictionary)
objectivePartialVolume.H
Foam::objectives::objectivePartialVolume::addHeaderInfo
virtual void addHeaderInfo() const
Write headers for additional columns.
Definition: objectivePartialVolume.C:132
Foam::endl
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:350
Foam::gSum
Type gSum(const FieldField< Field, Type > &f)
Definition: FieldFieldFunctions.C:594
Foam::objectives::defineTypeNameAndDebug
defineTypeNameAndDebug(objectiveForce, 0)
Foam::Field< vector >
Foam::objective::J_
scalar J_
Objective function value and weight.
Definition: objective.H:77
createZeroField.H
Foam::fvPatch
A finiteVolume patch using a polyPatch and a fvBoundaryMesh.
Definition: fvPatch.H:65
IOmanip.H
Istream and Ostream manipulators taking arguments.
Foam::objectiveIncompressible
Abstract base class for objective functions in incompressible flows.
Definition: objectiveIncompressible.H:54
dict
dictionary dict
Definition: searchingEngine.H:14
Foam::dictionary
A list of keyword definitions, which are a keyword followed by a number of values (eg,...
Definition: dictionary.H:121
Foam::objectives::objectivePartialVolume::update_dSdbMultiplier
void update_dSdbMultiplier()
Definition: objectivePartialVolume.C:121
mesh
dynamicFvMesh & mesh
Definition: createDynamicFvMesh.H:6
addToRunTimeSelectionTable.H
Macros for easy insertion into run-time selection tables.
Foam::fvMesh
Mesh data needed to do the Finite Volume discretisation.
Definition: fvMesh.H:83
Foam
Namespace for OpenFOAM.
Definition: atmBoundaryLayer.C:33
Foam::setw
Omanip< int > setw(const int i)
Definition: IOmanip.H:199
Foam::fvMesh::boundary
const fvBoundaryMesh & boundary() const
Return reference to boundary mesh.
Definition: fvMesh.C:679
Foam::objectives::objectivePartialVolume::update_dxdbDirectMultiplier
void update_dxdbDirectMultiplier()
Definition: objectivePartialVolume.C:108
Foam::foamVersion::patch
const std::string patch
OpenFOAM patch number as a std::string.
Foam::objective::mesh_
const fvMesh & mesh_
Definition: objective.H:67
Foam::wordRes
A List of wordRe with additional matching capabilities.
Definition: wordRes.H:51