objectiveForceTarget.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 
30 #include "objectiveForceTarget.H"
32 #include "IOmanip.H"
33 
34 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
35 
36 namespace Foam
37 {
38 
39 namespace objectives
40 {
41 
42 // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
43 
44 defineTypeNameAndDebug(objectiveForceTarget, 0);
46 (
47  objectiveIncompressible,
48  objectiveForceTarget,
49  dictionary
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  objectiveForce(mesh, dict, adjointSolverName, primalSolverName),
63  force_(Zero),
64  target_(dict.get<scalar>("target"))
65 {}
66 
67 
68 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
69 
71 {
72  force_ = objectiveForce::J();
73  J_ = force_ - target_;
74  return J_;
75 }
76 
77 
79 {
80  if (Pstream::master())
81  {
82  // File is opened only upon invocation of the write function
83  // in order to avoid various instantiations of the same objective
84  // opening the same file
85  unsigned int width = IOstream::defaultPrecision() + 5;
86  if (objFunctionFilePtr_.empty())
87  {
90  << setw(3) << "#" << " "
91  << setw(width) << "J" << " "
92  << setw(width) << "Force" << " "
93  << setw(width) << "Target" << endl;
94  }
95 
97  << setw(3) << mesh_.time().value() << " "
98  << setw(width) << J_ << " "
99  << setw(width) << force_ << " "
100  << setw(width) << target_ << endl;
101  }
102 }
103 
104 
105 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
106 
107 } // End namespace objectives
108 } // End namespace Foam
109 
110 // ************************************************************************* //
Foam::objectives::objectiveForceTarget::write
void write() const
Write objective value.
Definition: objectiveForceTarget.C:78
Foam::word
A class for handling words, derived from Foam::string.
Definition: word.H:62
Foam::objectives::objectiveForceTarget::J
scalar J()
Return the objective function value.
Definition: objectiveForceTarget.C:70
Foam::Zero
static constexpr const zero Zero
Global zero.
Definition: zero.H:128
Foam::objectives::addToRunTimeSelectionTable
addToRunTimeSelectionTable(objectiveIncompressible, objectiveForce, dictionary)
Foam::objective::setObjectiveFilePtr
void setObjectiveFilePtr() const
Set the output file ptr.
Definition: objective.C:58
Foam::objectives::objectiveForce
Definition: objectiveForce.H:58
Foam::endl
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:337
Foam::dimensioned::value
const Type & value() const
Return const reference to value.
Definition: dimensionedType.C:404
objectiveForceTarget.H
Foam::objective::objFunctionFilePtr_
autoPtr< OFstream > objFunctionFilePtr_
File to keep the objective values after the end of the primal solver.
Definition: objective.H:129
Foam::objectives::objectiveForceTarget::objectiveForceTarget
objectiveForceTarget(const fvMesh &mesh, const dictionary &dict, const word &adjointSolverName, const word &primalSolverName)
Construct from components.
Definition: objectiveForceTarget.C:55
Foam::objectives::defineTypeNameAndDebug
defineTypeNameAndDebug(objectiveForce, 0)
Foam::objective::J_
scalar J_
Definition: objective.H:73
IOmanip.H
Istream and Ostream manipulators taking arguments.
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
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:84
Foam
Namespace for OpenFOAM.
Definition: atmBoundaryLayer.C:33
Foam::setw
Omanip< int > setw(const int i)
Definition: IOmanip.H:199
Foam::UPstream::master
static bool master(const label communicator=0)
Am I the master process.
Definition: UPstream.H:438
Foam::IOstream::defaultPrecision
static unsigned int defaultPrecision()
Return the default precision.
Definition: IOstream.H:325
Foam::objectives::objectiveForce::J
scalar J()
Return the objective function value.
Definition: objectiveForce.C:122
Foam::objective::mesh_
const fvMesh & mesh_
Definition: objective.H:64
Foam::fvMesh::time
const Time & time() const
Return the top-level database.
Definition: fvMesh.H:246