objective.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-2023 PCOpt/NTUA
9  Copyright (C) 2013-2023 FOSS GP
10  Copyright (C) 2019-2021 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 "objective.H"
31 #include "createZeroField.H"
32 #include "IOmanip.H"
33 
34 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
35 
36 namespace Foam
37 {
38 
39 // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
40 
41 defineTypeNameAndDebug(objective, 0);
42 defineRunTimeSelectionTable(objective, objective);
43 
44 // * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * * //
45 
46 void objective::makeFolder()
47 {
48  if (Pstream::master())
49  {
50  const Time& time = mesh_.time();
52  time.globalPath()/"optimisation"/type()/time.timeName();
54  {
56  }
57 
59  }
60 }
61 
62 
64 {
66  (
68  );
69 }
70 
71 
73 {
75  (
76  new OFstream
77  (
79  )
80  );
81 }
82 
83 
85 {
86  meanValueFilePtr_.reset
87  (
88  new OFstream
89  (
91  )
92  );
93 }
94 
95 
96 // * * * * * * * * * * * * Protected Member Functions * * * * * * * * * * * //
97 
98 const dictionary& objective::dict() const
99 {
100  return dict_;
101 }
102 
103 
104 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
105 
106 objective::objective
107 (
108  const fvMesh& mesh,
109  const dictionary& dict,
110  const word& adjointSolverName,
111  const word& primalSolverName
112 )
113 :
115  (
116  IOobject
117  (
118  adjointSolverName + "_" + dict.dictName(),
119  mesh.time().timeName(),
120  fileName("uniform")/fileName("objectives")/adjointSolverName,
121  mesh,
122  IOobject::READ_IF_PRESENT,
123  IOobject::AUTO_WRITE
124  ),
125  // avoid type checking since dictionary is read using the
126  // derived type name and type() will result in "objective"
127  // here
128  word::null
129  ),
130  mesh_(mesh),
131  dict_(dict),
132  adjointSolverName_(adjointSolverName),
133  primalSolverName_(primalSolverName),
134  objectiveName_(dict.dictName()),
135  computeMeanFields_(false), // is reset in derived classes
136  nullified_(false),
137  normalize_
138  (
139  dict.getOrDefaultCompat<bool>
140  (
141  "normalise", {{"normalize", 2406}}, false
142  )
143  ),
144  shouldWrite_(true),
145 
146  J_(Zero),
147  JMean_(this->getOrDefault<scalar>("JMean", Zero)),
148  weight_(dict.get<scalar>("weight")),
149  computed_(false),
150  normFactor_(nullptr),
151  target_
152  (
153  dict.found("target") ?
154  autoPtr<scalar>::New(dict.get<scalar>("target")) :
155  nullptr
156  ),
157  targetLeft_
158  (
159  dict.found("targetLeft") ?
160  autoPtr<scalar>::New(dict.get<scalar>("targetLeft")) :
161  nullptr
162  ),
163  integrationStartTimePtr_(nullptr),
164  integrationEndTimePtr_(nullptr),
165  fieldNames_(),
166 
167  // Initialize pointers to nullptr.
168  // Not all of them are required for each objective function.
169  // Each child should allocate whatever is needed.
170 
171  dJdbPtr_(nullptr),
172  dJdbFieldPtr_(nullptr),
173  bdJdbPtr_(nullptr),
174  bdSdbMultPtr_(nullptr),
175  bdndbMultPtr_(nullptr),
176  bdxdbMultPtr_(nullptr),
177  bdxdbDirectMultPtr_(nullptr),
178  bEdgeContribution_(nullptr),
179  divDxDbMultPtr_(nullptr),
180  gradDxDbMultPtr_(nullptr),
181 
182  objFunctionFolder_("word"),
183  objFunctionFilePtr_(nullptr),
184  instantValueFilePtr_(nullptr),
185  meanValueFilePtr_(nullptr),
186  width_(IOstream::defaultPrecision() + 5)
187 {
188  makeFolder();
189  // Read integration start and end times, if present.
190  // For unsteady runs only
191  if (dict.found("integrationStartTime"))
192  {
193  integrationStartTimePtr_.reset
194  (
195  new scalar(dict.get<scalar>("integrationStartTime"))
196  );
197  }
198  if (dict.found("integrationEndTime"))
199  {
200  integrationEndTimePtr_.reset
201  (
202  new scalar(dict.get<scalar>("integrationEndTime"))
203  );
204  }
205 
206  // Set normalization factor, if present
207  if (normalize_)
208  {
209  scalar normFactor(Zero);
210  if (dict.readIfPresent("normFactor", normFactor))
211  {
212  normFactor_.reset(new scalar(normFactor));
213  }
214  else if (this->readIfPresent("normFactor", normFactor))
215  {
216  normFactor_.reset(new scalar(normFactor));
217  }
218  }
219 
220  // Set the weight factor in case of continuation
221  this->readIfPresent("weight", weight_);
222 }
223 
224 
225 // * * * * * * * * * * * * * * * * * Selectors * * * * * * * * * * * * * * * //
226 
228 (
229  const fvMesh& mesh,
230  const dictionary& dict,
231  const word& objectiveType,
232  const word& adjointSolverName,
233  const word& primalSolverName
234 )
235 {
236  auto* ctorPtr = objectiveConstructorTable(objectiveType);
237 
238  if (!ctorPtr)
239  {
241  (
242  dict,
243  "objective",
244  objectiveType,
245  *objectiveConstructorTablePtr_
246  ) << exit(FatalIOError);
247  }
248 
249  return autoPtr<objective>
250  (
251  ctorPtr
252  (
253  mesh,
254  dict,
255  adjointSolverName,
256  primalSolverName
257  )
258  );
259 }
260 
261 
262 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
263 
265 {
266  dict_ = dict;
267  return true;
268 }
269 
270 
271 scalar objective::JCycle(bool negate) const
272 {
273  scalar J(J_);
274  if
275  (
278  )
279  {
280  J = JMean_;
281  }
282 
283  // Subtract target, in case the objective is used as a constraint
284  if (target_)
285  {
286  if (negate)
287  {
288  J = - J + targetLeft_();
289  }
290  else
291  {
292  J -= target_();
293  }
294  }
295 
296  // Normalize here, in order to get the correct value for line search
297  if (normalize_ && normFactor_)
298  {
299  J /= normFactor_();
300  }
301  J *= weight_;
302 
303  return J;
304 }
305 
306 
308 {
309  if (normalize_ && !normFactor_)
310  {
311  scalar J(JCycle()/weight_);
312  normFactor_.reset(new scalar(J));
313  DebugInfo
314  << "objective " << name() << ":: updating norm factor "
315  << "to " << normFactor_()
316  << " for time = " << mesh_.time().timeName() << endl;
317  }
318 }
319 
320 
321 void objective::accumulateJMean(solverControl& solverControl)
322 {
323  if (solverControl.doAverageIter())
324  {
325  const label iAverageIter = solverControl.averageIter();
326  if (iAverageIter == 0)
327  {
328  JMean_ = Zero;
329  }
330  scalar avIter(iAverageIter);
331  scalar oneOverItP1 = 1./(avIter + 1);
332  scalar mult = avIter*oneOverItP1;
333  JMean_ = JMean_*mult + J_*oneOverItP1;
334  }
335 }
336 
337 
339 {
341  {
342  const scalar time = mesh_.time().value();
344  {
345  const scalar dt = mesh_.time().deltaTValue();
346  const scalar elapsedTime = time - integrationStartTimePtr_();
347  const scalar denom = elapsedTime + dt;
348  JMean_ = (JMean_*elapsedTime + J_*dt)/denom;
349  }
350  }
351  else
352  {
354  << "Unallocated integration start or end time"
355  << exit(FatalError);
356  }
357 }
358 
360 scalar objective::weight() const
361 {
362  return weight_;
363 }
364 
366 bool objective::normalize() const
367 {
368  return normalize_;
369 }
370 
371 
373 {
374  if (normalize_ && normFactor_)
375  {
376  const scalar oneOverNorm(1./normFactor_());
377 
378  if (hasdJdb())
379  {
380  dJdbPtr_().primitiveFieldRef() *= oneOverNorm;
381  }
382  if (hasdJdbField())
383  {
384  dJdbFieldPtr_() *= oneOverNorm;
385  }
386  if (hasBoundarydJdb())
387  {
388  bdJdbPtr_() *= oneOverNorm;
389  }
390  if (hasdSdbMult())
391  {
392  bdSdbMultPtr_() *= oneOverNorm;
393  }
394  if (hasdndbMult())
395  {
396  bdndbMultPtr_() *= oneOverNorm;
397  }
398  if (hasdxdbMult())
399  {
400  bdxdbMultPtr_() *= oneOverNorm;
401  }
402  if (hasdxdbDirectMult())
403  {
404  bdxdbDirectMultPtr_() *= oneOverNorm;
405  }
407  {
408  bEdgeContribution_() *= oneOverNorm;
409  }
410  if (hasDivDxDbMult())
411  {
412  divDxDbMultPtr_() *= oneOverNorm;
413  }
414  if (hasGradDxDbMult())
415  {
416  gradDxDbMultPtr_() *= oneOverNorm;
417  }
418  }
419 }
420 
421 
423 {
425  {
426  const scalar time = mesh_.time().value();
427  return
428  (
431  );
432  }
433  else
434  {
436  << "Unallocated integration start or end time for objective '"
437  << objectiveName_ << "'"
438  << exit(FatalError);
439  }
440  return false;
441 }
442 
443 
444 void objective::incrementIntegrationTimes(const scalar timeSpan)
445 {
447  {
448  integrationStartTimePtr_() += timeSpan;
449  integrationEndTimePtr_() += timeSpan;
450  }
451  else
452  {
454  << "Unallocated integration start or end time"
455  << exit(FatalError);
456  }
457 }
458 
459 
460 void objective::update()
461 {
462  // Objective function value
463  J();
464 
465  // volFields
466  update_dJdb();
470 
471  // boundaryFields
478 }
479 
480 
481 void objective::nullify()
482 {
483  if (!nullified_)
484  {
485  if (hasdJdb())
486  {
487  dJdbPtr_() == dimensionedScalar(dJdbPtr_().dimensions(), Zero);
488  }
489  if (hasdJdbField())
490  {
491  dJdbFieldPtr_() = Zero;
492  }
493  if (hasBoundarydJdb())
494  {
495  bdJdbPtr_() == vector::zero;
496  }
497  if (hasdSdbMult())
498  {
499  bdSdbMultPtr_() == vector::zero;
500  }
501  if (hasdndbMult())
502  {
503  bdndbMultPtr_() == vector::zero;
504  }
505  if (hasdxdbMult())
506  {
507  bdxdbMultPtr_() == vector::zero;
508  }
509  if (hasdxdbDirectMult())
510  {
511  bdxdbDirectMultPtr_() == vector::zero;
512  }
514  {
515  for (Field<vectorField>& field : bEdgeContribution_())
516  {
517  field = vector::zero;
518  }
519  }
520  if (hasDivDxDbMult())
521  {
522  divDxDbMultPtr_() ==
523  dimensionedScalar(divDxDbMultPtr_().dimensions(), Zero);
524  }
525  if (hasGradDxDbMult())
526  {
527  gradDxDbMultPtr_() ==
528  dimensionedTensor(gradDxDbMultPtr_().dimensions(), Zero);
529  }
530 
531  nullified_ = true;
532  }
533 }
534 
535 
536 bool objective::write(const bool valid) const
537 {
538  if (Pstream::master())
539  {
540  // File is opened only upon invocation of the write function
541  // in order to avoid various instantiations of the same objective
542  // opening the same file
543  if (!objFunctionFilePtr_)
544  {
546  OFstream& file = objFunctionFilePtr_();
547  file.setf(std::ios_base::left);
548 
549  if (target_)
550  {
551  file<< setw(width_) << "#target" << " "
552  << setw(width_) << target_() << endl;
553  }
554  if (targetLeft_)
555  {
556  file<< setw(width_) << "#targetLeft" << " "
557  << setw(width_) << targetLeft_() << endl;
558  }
559  if (normalize_)
560  {
561  file<< setw(width_) << "#normFactor " << " "
562  << setw(width_) << normFactor_() << endl;
563  }
564  addHeaderInfo();
565  file<< setw(4) << "#" << " ";
566  file<< setw(width_) << "J" << " ";
567  file<< setw(width_) << "JCycle" << " ";
568  if (targetLeft_)
569  {
570  file<< setw(width_) << "JCycleLeft" << " ";
571  }
573  file<< endl;
574  }
575 
576  OFstream& file = objFunctionFilePtr_();
577  file<< setw(4) << mesh_.time().value() << " ";
578  file<< setw(width_) << J_ << " ";
579  file<< setw(width_) << JCycle() << " ";
580  if (targetLeft_)
581  {
582  file<< setw(width_) << JCycle(true) << " ";
583  }
584  addColumnValues();
585  file<< endl;
586  }
587 
588  return true;
589 }
590 
591 
593 {
594  if (Pstream::master())
595  {
596  // File is opened only upon invocation of the write function
597  // in order to avoid various instantiations of the same objective
598  // opening the same file
599  unsigned int width = IOstream::defaultPrecision() + 6;
601  {
603  }
606  << setw(width) << mesh_.time().value() << tab << J_ << endl;
607  }
608 }
609 
610 
612 {
613  if (Pstream::master())
614  {
616  {
618  }
619  }
620 }
621 
622 
623 void objective::writeMeanValue() const
624 {
625  if (Pstream::master())
626  {
627  // Write mean value if necessary
628  // Covers both steady and unsteady runs
629  if
630  (
633  )
634  {
635  // File is opened only upon invocation of the write function
636  // in order to avoid various instantiations of the same objective
637  // opening the same file
638  if (!meanValueFilePtr_)
639  {
641  }
642 
644  << mesh_.time().value() << tab << JMean_ << endl;
645  }
646  }
647 }
648 
649 
650 bool objective::writeData(Ostream& os) const
651 {
652  os.writeEntry("JMean", JMean_);
653  if (normFactor_)
654  {
655  os.writeEntry("normFactor", normFactor_());
656  }
657  os.writeEntry("weight", weight_);
658  return os.good();
659 }
660 
662 void objective::addHeaderInfo() const
663 {
664  // Does nothing in base
665 }
666 
668 void objective::addHeaderColumns() const
669 {
670  // Does nothing in base
671 }
672 
673 
674 void objective::addColumnValues() const
675 {
676  // Does nothing in base
677 }
678 
679 
680 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
681 
682 } // End namespace Foam
683 
684 // ************************************************************************* //
List< ReturnType > get(const UPtrList< T > &list, const AccessOp &aop)
List of values generated by applying the access operation to each list item.
const Type & value() const noexcept
Return const reference to value.
void setInstantValueFilePtr() const
Set the output file ptr for the instantaneous value.
Definition: objective.C:65
dictionary dict
virtual void update_dSdbMultiplier()
Update d (normal dS) / db multiplier. Surface-based sensitivity term.
Definition: objective.H:503
virtual void updateNormalizationFactor()
Update normalization factors, for objectives in which the factor is not known a priori.
Definition: objective.C:300
autoPtr< boundaryVectorField > bdxdbMultPtr_
Term multiplying delta(x)/delta b at the boundary.
Definition: objective.H:171
rDeltaTY field()
autoPtr< scalar > target_
Target value, in case the objective is used as a constraint.
Definition: objective.H:110
A class for handling file names.
Definition: fileName.H:72
virtual void incrementIntegrationTimes(const scalar timeSpan)
Increment integration times.
Definition: objective.C:437
virtual void update_dJdb()
Definition: objective.H:488
const word adjointSolverName_
Definition: objective.H:65
const dictionary & dict() const
Return objective dictionary.
Definition: objective.C:91
virtual void writeMeanValue() const
Write mean objective function history.
Definition: objective.C:616
scalar deltaTValue() const noexcept
Return time step value.
Definition: TimeStateI.H:49
dictionary dict_
Definition: objective.H:64
errorManipArg< error, int > exit(error &err, const int errNo=1)
Definition: errorManip.H:125
error FatalError
Error stream (stdout output on all processes), with additional &#39;FOAM FATAL ERROR&#39; header text and sta...
A list of keyword definitions, which are a keyword followed by a number of values (eg...
Definition: dictionary.H:129
#define FatalErrorInFunction
Report an error message using Foam::FatalError.
Definition: error.H:608
bool hasdxdbDirectMult() const noexcept
Definition: objectiveI.H:199
autoPtr< OFstream > objFunctionFilePtr_
File to keep the objective values after the end of the primal solver.
Definition: objective.H:209
bool hasBoundarydJdb() const noexcept
Definition: objectiveI.H:175
bool hasdJdbField() const noexcept
Definition: objectiveI.H:169
autoPtr< scalar > normFactor_
Normalization factor.
Definition: objective.H:101
virtual void update_dxdbMultiplier()
Update d (x) / db multiplier. Surface-based sensitivity term.
Definition: objective.H:515
Output to file stream as an OSstream, normally using std::ofstream for the actual output...
Definition: OFstream.H:71
autoPtr< scalar > targetLeft_
Target on the left hand-side of a double inequality, for double sided constraints.
Definition: objective.H:116
bool hasdndbMult() const noexcept
Definition: objectiveI.H:187
virtual void doNormalization()
Normalize all fields allocated by the objective.
Definition: objective.C:365
const word dictName("faMeshDefinition")
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:531
virtual scalar J()=0
Return the instantaneous objective function value.
tmp< DimensionedField< TypeR, GeoMesh > > New(const tmp< DimensionedField< TypeR, GeoMesh >> &tf1, const word &name, const dimensionSet &dimensions, const bool initCopy=false)
Global function forwards to reuseTmpDimensionedField::New.
static unsigned int defaultPrecision() noexcept
Return the default precision.
Definition: IOstream.H:418
constexpr char tab
The tab &#39;\t&#39; character(0x09)
Definition: Ostream.H:49
virtual void accumulateJMean()
Accumulate contribution for the mean objective value.
Definition: objective.C:331
autoPtr< vectorField3 > bEdgeContribution_
Contribution located in specific parts of a patch. Mainly intended for patch boundary edges contribut...
Definition: objective.H:185
T get(const word &keyword, enum keyType::option matchOpt=keyType::REGEX) const
Find and return a T. FatalIOError if not found, or if the number of tokens is incorrect.
autoPtr< boundaryVectorField > bdJdbPtr_
Term from material derivative.
Definition: objective.H:156
const Time & time() const
Return the top-level database.
Definition: fvMesh.H:360
bool hasBoundaryEdgeContribution() const noexcept
Definition: objectiveI.H:205
bool found(const word &keyword, enum keyType::option matchOpt=keyType::REGEX) const
Find an entry (const access) with the given keyword.
Definition: dictionaryI.H:104
const word objectiveName_
Definition: objective.H:67
virtual void update_gradDxDbMultiplier()
Update grad( dx/db multiplier). Volume-based sensitivity term.
Definition: objective.H:540
localIOdictionary is derived from IOdictionary but excludes parallel master reading.
void reset(T *p=nullptr) noexcept
Delete managed object and set to new given pointer.
Definition: autoPtrI.H:37
bool hasGradDxDbMult() const noexcept
Definition: objectiveI.H:217
virtual void update_divDxDbMultiplier()
Update div( dx/db multiplier). Volume-based sensitivity term.
Definition: objective.H:534
word timeName
Definition: getTimeIndex.H:3
fileName::Type type(const fileName &name, const bool followLink=true)
Return the file type: DIRECTORY or FILE, normally following symbolic links.
Definition: POSIX.C:799
virtual bool write(const bool valid=true) const
Write objective function history.
Definition: objective.C:529
bool hasdSdbMult() const noexcept
Definition: objectiveI.H:181
static autoPtr< objective > New(const fvMesh &mesh, const dictionary &dict, const word &objectiveType, const word &adjointSolverName, const word &primalSolverName)
Return a reference to the selected turbulence model.
Definition: objective.C:221
autoPtr< scalar > integrationEndTimePtr_
Definition: objective.H:122
dynamicFvMesh & mesh
bool mkDir(const fileName &pathName, mode_t mode=0777)
Make a directory and return an error if it could not be created.
Definition: POSIX.C:614
bool computeMeanFields_
Definition: objective.H:68
void setObjectiveFilePtr() const
Set the output file ptr.
Definition: objective.C:56
fileName globalPath() const
Return global path for the case = rootPath/globalCaseName. Same as TimePaths::globalPath() ...
Definition: Time.H:512
A class for handling words, derived from Foam::string.
Definition: word.H:63
static word defaultRegion
Return the default region name.
Definition: polyMesh.H:406
void setMeanValueFilePtr() const
Set the output file ptr for the mean value.
Definition: objective.C:77
virtual void addHeaderColumns() const
Write headers for additional columns.
Definition: objective.C:661
virtual void update_dndbMultiplier()
Update d (normal) / db multiplier. Surface-based sensitivity term.
Definition: objective.H:509
bool hasdJdb() const noexcept
Definition: objectiveI.H:163
virtual void update_boundarydJdb()
Update objective function derivative term.
Definition: objective.H:497
const fvMesh & mesh_
Definition: objective.H:63
void negate(DimensionedField< Type, GeoMesh > &result, const DimensionedField< Type, GeoMesh > &f1)
const word & name() const
Name function is needed to disambiguate those inherited from regIOobject and dictionary.
dimensioned< tensor > dimensionedTensor
Dimensioned tensor obtained from generic dimensioned type.
scalar JMean_
Average objective value.
Definition: objective.H:81
scalar J_
Objective function value and weight.
Definition: objective.H:76
#define DebugInfo
Report an information message using Foam::Info.
const Time & time() const noexcept
Return Time associated with the objectRegistry.
Definition: IOobject.C:456
virtual scalar weight() const
Return the objective function weight.
Definition: objective.C:353
virtual void update_dJdbField()
Definition: objective.H:491
virtual scalar JCycle(bool negate=false) const
Return the objective function of the optimisation cycle.
Definition: objective.C:264
Istream and Ostream manipulators taking arguments.
static word timeName(const scalar t, const int precision=precision_)
Return a time name for the given scalar time value formatted with the given precision.
Definition: Time.C:714
defineRunTimeSelectionTable(reactionRateFlameArea, dictionary)
bool readIfPresent(const word &keyword, T &val, enum keyType::option matchOpt=keyType::REGEX) const
Find an entry if present, and assign to T val. FatalIOError if it is found and the number of tokens i...
autoPtr< boundaryVectorField > bdndbMultPtr_
Term multiplying delta(n)/delta b.
Definition: objective.H:166
virtual bool writeData(Ostream &os) const
Write averaged objective for continuation.
Definition: objective.C:643
virtual void writeInstantaneousValue() const
Write objective function history at each primal solver iteration.
Definition: objective.C:585
OBJstream os(runTime.globalPath()/outputName)
defineTypeNameAndDebug(combustionModel, 0)
virtual bool isWithinIntegrationTime() const
Check whether this is an objective integration time.
Definition: objective.C:415
autoPtr< volScalarField > divDxDbMultPtr_
Multiplier of d(Volume)/db.
Definition: objective.H:194
virtual void addColumnValues() const
Write information to additional columns.
Definition: objective.C:667
autoPtr< OFstream > meanValueFilePtr_
File to keep the average objective values after the end of the primal solver.
Definition: objective.H:221
unsigned int width_
Default width of entries when writing in the objective files.
Definition: objective.H:226
virtual void update_boundaryEdgeContribution()
Update boundary edge contributions.
Definition: objective.H:528
bool hasIntegrationStartTime() const noexcept
Definition: objectiveI.H:223
virtual void nullify()
Nullify adjoint contributions.
Definition: objective.C:474
autoPtr< scalarField > dJdbFieldPtr_
Contribution to field sensitivity derivatives.
Definition: objective.H:148
virtual void writeInstantaneousSeparator() const
Append a blank line after the end of optimisation cycle to the file holding the instantaneous objecti...
Definition: objective.C:604
const word & name() const
Return reference to name.
Definition: fvMesh.H:387
dimensioned< scalar > dimensionedScalar
Dimensioned scalar obtained from generic dimensioned type.
virtual bool normalize() const
Is the objective normalized.
Definition: objective.C:359
scalar weight_
Objective weight.
Definition: objective.H:86
Mesh data needed to do the Finite Volume discretisation.
Definition: fvMesh.H:78
static bool master(const label communicator=worldComm)
True if process corresponds to the master rank in the communicator.
Definition: UPstream.H:1094
virtual void addHeaderInfo() const
Write any information that needs to go the header of the file.
Definition: objective.C:655
meshDefDict readIfPresent("polyMeshPatches", polyPatchNames)
virtual bool readDict(const dictionary &dict)
Definition: objective.C:257
bool hasDivDxDbMult() const noexcept
Definition: objectiveI.H:211
bool hasdxdbMult() const noexcept
Definition: objectiveI.H:193
autoPtr< volTensorField > gradDxDbMultPtr_
Emerging from volume objectives that include spatial derivatives.
Definition: objective.H:199
autoPtr< scalar > integrationStartTimePtr_
Objective integration start and end times (for unsteady flows)
Definition: objective.H:121
virtual void update()=0
Update objective function derivatives.
Definition: objective.C:453
Pointer management similar to std::unique_ptr, with some additional methods and type checking...
Definition: HashPtrTable.H:48
Omanip< int > setw(const int i)
Definition: IOmanip.H:199
autoPtr< OFstream > instantValueFilePtr_
File to keep the objective values at each iteration of the primal solver.
Definition: objective.H:215
autoPtr< boundaryVectorField > bdxdbDirectMultPtr_
Term multiplying delta(x)/delta b at the boundary for objectives that directly depend on x...
Definition: objective.H:178
virtual void update_dxdbDirectMultiplier()
Update d (x) / db multiplier. Surface and volume-based sensitivity term.
Definition: objective.H:522
static autoPtr< T > New(Args &&... args)
Construct autoPtr with forwarding arguments.
Definition: autoPtr.H:178
autoPtr< boundaryVectorField > bdSdbMultPtr_
Term multiplying delta(n dS)/delta b.
Definition: objective.H:161
fileName objFunctionFolder_
Output file variables.
Definition: objective.H:204
Defines the attributes of an object for which implicit objectRegistry management is supported...
Definition: IOobject.H:180
#define FatalIOErrorInLookup(ios, lookupTag, lookupName, lookupTable)
Report an error message using Foam::FatalIOError.
Definition: error.H:645
bool hasIntegrationEndTime() const noexcept
Definition: objectiveI.H:229
bool found
Namespace for OpenFOAM.
IOerror FatalIOError
Error stream (stdout output on all processes), with additional &#39;FOAM FATAL IO ERROR&#39; header text and ...
static constexpr const zero Zero
Global zero (0)
Definition: zero.H:127