ENH: Input in objectiveFlowRatePartition now reads "targetFractions"

instead of targetPercentages, with a compatibility read on the latter.
Changed corresponding tutorials too.
This commit is contained in:
Vaggelis Papoutsis
2023-12-04 15:52:35 +02:00
committed by Andrew Heather
parent eabb821926
commit c3b212e06c
19 changed files with 37 additions and 30 deletions

View File

@ -75,23 +75,30 @@ objectiveFlowRatePartition::objectiveFlowRatePartition
dict.get<wordRes>("outletPatches") dict.get<wordRes>("outletPatches")
).sortedToc() ).sortedToc()
), ),
targetFlowRatePercentage_(), targetFlowRateFraction_(),
currentFlowRatePercentage_(outletPatches_.size(), Zero), currentFlowRateFraction_(outletPatches_.size(), Zero),
inletFlowRate_(0), inletFlowRate_(0),
flowRateDifference_(outletPatches_.size(), Zero) flowRateDifference_(outletPatches_.size(), Zero)
{ {
// Read target percentages if present, otherwise treat them as equally // Read target fractions if present, otherwise treat them as equally
// distributed // distributed
if (!dict.readIfPresent("targetPercentages", targetFlowRatePercentage_)) if
(
!dict.readIfPresentCompat
(
"targetFractions", {{"targetPercentages", 2306}},
targetFlowRateFraction_
)
)
{ {
const label nOutPatches = outletPatches_.size(); const label nOutPatches = outletPatches_.size();
targetFlowRatePercentage_.setSize(nOutPatches, 1.0/scalar(nOutPatches)); targetFlowRateFraction_.setSize(nOutPatches, 1.0/scalar(nOutPatches));
} }
// Sanity checks // Sanity checks
if (targetFlowRatePercentage_.size() != outletPatches_.size()) if (targetFlowRateFraction_.size() != outletPatches_.size())
{ {
FatalErrorInFunction FatalErrorInFunction
<< "Inconsistent sizes for targetPercentages and outletPatches" << "Inconsistent sizes for targetFractions and outletPatches"
<< exit(FatalError); << exit(FatalError);
} }
@ -130,9 +137,9 @@ scalar objectiveFlowRatePartition::J()
{ {
const label patchI = outletPatches_[pI]; const label patchI = outletPatches_[pI];
const scalar outletFlowRate = gSum(phi.boundaryField()[patchI]); const scalar outletFlowRate = gSum(phi.boundaryField()[patchI]);
currentFlowRatePercentage_[pI] = -outletFlowRate/inletFlowRate_; currentFlowRateFraction_[pI] = -outletFlowRate/inletFlowRate_;
flowRateDifference_[pI] = flowRateDifference_[pI] =
targetFlowRatePercentage_[pI] - currentFlowRatePercentage_[pI]; targetFlowRateFraction_[pI] - currentFlowRateFraction_[pI];
J_ += 0.5*flowRateDifference_[pI]*flowRateDifference_[pI]; J_ += 0.5*flowRateDifference_[pI]*flowRateDifference_[pI];
} }
@ -172,7 +179,7 @@ void objectiveFlowRatePartition::addHeaderInfo() const
const fvPatch& patch = mesh_.boundary()[patchI]; const fvPatch& patch = mesh_.boundary()[patchI];
objFunctionFilePtr_() objFunctionFilePtr_()
<< setw(width_) << word("#" + patch.name() + "Tar") << " " << setw(width_) << word("#" + patch.name() + "Tar") << " "
<< setw(width_) << targetFlowRatePercentage_[pI] << endl; << setw(width_) << targetFlowRateFraction_[pI] << endl;
} }
} }
@ -190,7 +197,7 @@ void objectiveFlowRatePartition::addHeaderColumns() const
void objectiveFlowRatePartition::addColumnValues() const void objectiveFlowRatePartition::addColumnValues() const
{ {
for (const scalar flowRate : currentFlowRatePercentage_) for (const scalar flowRate : currentFlowRateFraction_)
{ {
objFunctionFilePtr_() objFunctionFilePtr_()
<< setw(width_) << flowRate << " "; << setw(width_) << flowRate << " ";

View File

@ -61,8 +61,8 @@ class objectiveFlowRatePartition
labelList inletPatches_; labelList inletPatches_;
labelList outletPatches_; labelList outletPatches_;
scalarList targetFlowRatePercentage_; scalarList targetFlowRateFraction_;
scalarList currentFlowRatePercentage_; scalarList currentFlowRateFraction_;
scalar inletFlowRate_; scalar inletFlowRate_;
scalarList flowRateDifference_; scalarList flowRateDifference_;

View File

@ -66,7 +66,7 @@ adjointManagers
outletPatches (outlet1 outlet2); outletPatches (outlet1 outlet2);
// Optional entry. If abscent, inlet flow rate will // Optional entry. If abscent, inlet flow rate will
// be partitioned equally between outlets // be partitioned equally between outlets
// targetPercentages (0.5 0.5); // targetFractions (0.5 0.5);
normalize true; normalize true;
} }
} }

View File

@ -69,7 +69,7 @@ adjointManagers
type flowRatePartition; type flowRatePartition;
inletPatches (inlet); inletPatches (inlet);
outletPatches (outlet outlet-right); outletPatches (outlet outlet-right);
targetPercentages (0.5 0.5); targetFractions (0.5 0.5);
} }
} }
} }

View File

@ -104,7 +104,7 @@ adjointManagers
type flowRatePartition; type flowRatePartition;
inletPatches (inlet); inletPatches (inlet);
outletPatches (outlet outlet-right); outletPatches (outlet outlet-right);
targetPercentages (0.5 0.5); targetFractions (0.5 0.5);
normalize true; normalize true;
target 1.e-5; target 1.e-5;
} }

View File

@ -69,7 +69,7 @@ adjointManagers
type flowRatePartition; type flowRatePartition;
inletPatches (inlet); inletPatches (inlet);
outletPatches (outlet outlet-right); outletPatches (outlet outlet-right);
targetPercentages (0.5 0.5); targetFractions (0.5 0.5);
} }
} }
} }

View File

@ -108,7 +108,7 @@ adjointManagers
type flowRatePartition; type flowRatePartition;
inletPatches (inlet); inletPatches (inlet);
outletPatches (outlet outlet-right); outletPatches (outlet outlet-right);
targetPercentages (0.3 0.7); targetFractions (0.5 0.5);
target 1.e-05; target 1.e-05;
normalize true; normalize true;
} }

View File

@ -69,7 +69,7 @@ adjointManagers
type flowRatePartition; type flowRatePartition;
inletPatches (inlet); inletPatches (inlet);
outletPatches (outlet outlet-right); outletPatches (outlet outlet-right);
targetPercentages (0.5 0.5); targetFractions (0.5 0.5);
} }
} }
} }

View File

@ -108,7 +108,7 @@ adjointManagers
type flowRatePartition; type flowRatePartition;
inletPatches (inlet); inletPatches (inlet);
outletPatches (outlet outlet-right); outletPatches (outlet outlet-right);
targetPercentages (0.5 0.5); targetFractions (0.5 0.5);
target 1.e-05; target 1.e-05;
normalize true; normalize true;
} }

View File

@ -69,7 +69,7 @@ adjointManagers
type flowRatePartition; type flowRatePartition;
inletPatches (inlet); inletPatches (inlet);
outletPatches (outlet outlet-right); outletPatches (outlet outlet-right);
targetPercentages (0.5 0.5); targetFractions (0.5 0.5);
} }
} }
} }

View File

@ -108,7 +108,7 @@ adjointManagers
type flowRatePartition; type flowRatePartition;
inletPatches (inlet); inletPatches (inlet);
outletPatches (outlet outlet-right); outletPatches (outlet outlet-right);
targetPercentages (0.7 0.3); targetFractions (0.5 0.5);
target 1.e-05; target 1.e-05;
normalize true; normalize true;
} }

View File

@ -75,7 +75,7 @@ adjointManagers
type flowRatePartition; type flowRatePartition;
inletPatches (inlet); inletPatches (inlet);
outletPatches (outlet1 outlet2); outletPatches (outlet1 outlet2);
targetPercentages (0.5 0.5); targetFractions (0.5 0.5);
} }
} }
} }

View File

@ -174,7 +174,7 @@ adjointManagers
type flowRatePartition; type flowRatePartition;
inletPatches (inlet); inletPatches (inlet);
outletPatches (outlet1 outlet2); outletPatches (outlet1 outlet2);
targetPercentages (0.5 0.5); targetFractions (0.5 0.5);
normalize true; normalize true;
target 1.e-5; target 1.e-5;
} }

View File

@ -75,7 +75,7 @@ adjointManagers
type flowRatePartition; type flowRatePartition;
inletPatches (inlet); inletPatches (inlet);
outletPatches (outlet1 outlet2); outletPatches (outlet1 outlet2);
targetPercentages (0.5 0.5); targetFractions (0.5 0.5);
} }
} }
} }

View File

@ -113,7 +113,7 @@ adjointManagers
type flowRatePartition; type flowRatePartition;
inletPatches (inlet); inletPatches (inlet);
outletPatches (outlet1 outlet2); outletPatches (outlet1 outlet2);
targetPercentages (0.5 0.5); targetFractions (0.5 0.5);
normalize true; normalize true;
target 1.e-5; target 1.e-5;
} }

View File

@ -75,7 +75,7 @@ adjointManagers
type flowRatePartition; type flowRatePartition;
inletPatches (inlet); inletPatches (inlet);
outletPatches (outlet1 outlet2); outletPatches (outlet1 outlet2);
targetPercentages (0.5 0.5); targetFractions (0.5 0.5);
} }
} }
} }

View File

@ -76,7 +76,7 @@ adjointManagers
type flowRatePartition; type flowRatePartition;
inletPatches (inlet); inletPatches (inlet);
outletPatches (outlet1 outlet2); outletPatches (outlet1 outlet2);
targetPercentages (0.5 0.5); targetFractions (0.5 0.5);
} }
} }
} }

View File

@ -69,7 +69,7 @@ adjointManagers
type flowRatePartition; type flowRatePartition;
inletPatches (inlet); inletPatches (inlet);
outletPatches (outlet outlet-right); outletPatches (outlet outlet-right);
targetPercentages (0.5 0.5); targetFractions (0.5 0.5);
} }
} }
} }

View File

@ -108,7 +108,7 @@ adjointManagers
type flowRatePartition; type flowRatePartition;
inletPatches (inlet); inletPatches (inlet);
outletPatches (outlet outlet-right); outletPatches (outlet outlet-right);
targetPercentages (0.5 0.5); targetFractions (0.5 0.5);
normalize true; normalize true;
target 1.e-5; target 1.e-5;
} }