47 objectiveIncompressible,
48 objectiveFlowRatePartition,
59 const word& adjointSolverName,
60 const word& primalSolverName
78 targetFlowRatePercentage_(),
79 currentFlowRatePercentage_(outletPatches_.size(),
Zero),
81 flowRateDifference_(outletPatches_.size(),
Zero)
87 const label nOutPatches = outletPatches_.
size();
88 targetFlowRatePercentage_.
setSize(nOutPatches, 1.0/scalar(nOutPatches));
91 if (targetFlowRatePercentage_.
size() != outletPatches_.
size())
94 <<
"Inconsistent sizes for targetPercentages and outletPatches" 104 for (
const label patchI : outletPatches_)
107 unsigned int wordSize =
word(
patch.name() +
"Ratio").size();
122 for (
const label patchI : inletPatches_)
126 inletFlowRate_ +=
gSum(
U.boundaryField()[patchI] & Sf);
130 forAll(outletPatches_, pI)
132 const label patchI = outletPatches_[pI];
134 const scalar outletFlowRate =
gSum(
U.boundaryField()[patchI] & Sf);
135 currentFlowRatePercentage_[pI] = -outletFlowRate/inletFlowRate_;
136 flowRateDifference_[pI] =
137 targetFlowRatePercentage_[pI] - currentFlowRatePercentage_[pI];
138 J_ += 0.5*flowRateDifference_[pI]*flowRateDifference_[pI];
147 forAll(outletPatches_, pI)
149 const label patchI = outletPatches_[pI];
151 bdJdvPtr_()[patchI] = nf*flowRateDifference_[pI]/inletFlowRate_;
158 forAll(outletPatches_, pI)
160 const label patchI = outletPatches_[pI];
161 bdJdvnPtr_()[patchI] = flowRateDifference_[pI]/inletFlowRate_;
171 forAll(outletPatches_, pI)
173 const label patchI = outletPatches_[pI];
184 for (
const label patchI : outletPatches_)
195 for (
const scalar flowRate : currentFlowRatePercentage_)
List< ReturnType > get(const UPtrList< T > &list, const AccessOp &aop)
List of values generated by applying the access operation to each list item.
void size(const label n)
Older name for setAddressableSize.
void update_boundarydJdvn()
Update values to be added to the adjoint outlet pressure.
const dictionary & dict() const
Return objective dictionary.
errorManipArg< error, int > exit(error &err, const int errNo=1)
void update_boundarydJdv()
Update values to be added to the adjoint outlet velocity.
error FatalError
Error stream (stdout output on all processes), with additional 'FOAM FATAL ERROR' header text and sta...
A list of keyword definitions, which are a keyword followed by a number of values (eg...
#define FatalErrorInFunction
Report an error message using Foam::FatalError.
autoPtr< OFstream > objFunctionFilePtr_
File to keep the objective values after the end of the primal solver.
label max(const labelHashSet &set, label maxValue=labelMin)
Find the max value in labelHashSet, optionally limited by second argument.
objectiveFlowRatePartition(const fvMesh &mesh, const dictionary &dict, const word &adjointSolverName, const word &primalSolverName)
from components
Addressing for all faces on surface of mesh. Can either be read from polyMesh or from triSurface...
Ostream & endl(Ostream &os)
Add newline and flush stream.
A finiteVolume patch using a polyPatch and a fvBoundaryMesh.
defineTypeNameAndDebug(objectiveFlowRate, 0)
virtual void addHeaderColumns() const
Write headers for additional columns.
Macros for easy insertion into run-time selection tables.
#define forAll(list, i)
Loop across all elements in list.
void setSize(const label n)
Alias for resize()
Type gSum(const FieldField< Field, Type > &f)
A class for handling words, derived from Foam::string.
A List of wordRe with additional matching capabilities.
scalar J()
Return the objective function value.
scalar J_
Objective function value and weight.
autoPtr< boundaryVectorField > bdJdvPtr_
Istream and Ostream manipulators taking arguments.
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...
const incompressibleVars & vars_
unsigned int width_
Default width of entries when writing in the objective files.
addToRunTimeSelectionTable(objectiveIncompressible, objectiveFlowRate, dictionary)
virtual void addColumnValues() const
Write information to additional columns.
Mesh data needed to do the Finite Volume discretisation.
const std::string patch
OpenFOAM patch number as a std::string.
List< label > sortedToc(const UList< bool > &bools)
Return the (sorted) values corresponding to 'true' entries.
Field< vector > vectorField
Specialisation of Field<T> for vector.
Omanip< int > setw(const int i)
A class for managing temporary objects.
const volVectorField & UInst() const
Return const reference to velocity.
autoPtr< boundaryScalarField > bdJdvnPtr_
Adjoint outlet pressure.
Abstract base class for objective functions in incompressible flows.
virtual void addHeaderInfo() const
Write any information that needs to go the header of the file.
const fvBoundaryMesh & boundary() const
Return reference to boundary mesh.
static constexpr const zero Zero
Global zero (0)