From adaac7257fc943b7551f026dd321b0cad0c06e37 Mon Sep 17 00:00:00 2001 From: Andrew Heather <> Date: Mon, 13 Nov 2023 17:59:18 +0000 Subject: [PATCH] INT: integration updates - Minor code style - virtual functions - added some noexcept --- ...ointOutletVelocityFluxFvPatchVectorField.H | 1 - .../sources/TopO/topOSource/topOSource.H | 2 +- .../objectivePartialVolume.H | 6 +-- .../objectiveTopOSolidVolume.H | 2 +- .../objectiveTopOVolume/objectiveTopOVolume.H | 4 +- .../objectiveFlowRate/objectiveFlowRate.H | 8 +-- .../objectiveFlowRatePartition.H | 6 +-- .../objectiveForce/objectiveForce.H | 14 ++--- .../objectiveIncompressible.H | 28 +++++----- .../objectiveIncompressibleI.H | 28 +++++----- .../objectiveMoment/objectiveMoment.H | 16 +++--- .../objectiveNutSqr/objectiveNutSqr.H | 10 ++-- .../objectivePowerDissipation.H | 8 +-- .../objectivePtLosses/objectivePtLosses.C | 54 ++++++++++--------- .../objectivePtLosses/objectivePtLosses.H | 19 ++++--- .../objectiveUniformityCellZone.H | 7 +-- .../objectiveUniformityPatch.C | 54 ++++++++++--------- .../objectiveUniformityPatch.H | 17 +++--- .../adjoint/objectives/objective/objective.H | 50 ++++++++--------- .../adjoint/objectives/objective/objectiveI.H | 26 ++++----- .../designVariables/designVariables.H | 2 +- .../sigmoidalHeaviside/sigmoidalHeaviside.C | 2 +- .../levelSet/levelSetDesignVariables.H | 8 +-- .../dynamicTopODesignVariables.C | 7 +-- .../regularisation/fieldRegularisation.C | 5 +- .../regularisationPDE/Helmoltz/Helmholtz.H | 1 - .../regularisationPDE/regularisationPDE.H | 1 + .../topODesignVariables/topODesignVariables.C | 7 +-- .../topODesignVariables/topODesignVariables.H | 2 +- .../topOVariablesBase/topOVariablesBase.H | 4 +- .../topODesignVariables/topOZones/topOZones.H | 2 +- .../incompressiblePrimalSolver.C | 2 +- 32 files changed, 199 insertions(+), 204 deletions(-) diff --git a/src/optimisation/adjointOptimisation/adjoint/adjointBoundaryConditions/adjointOutletVelocityFlux/adjointOutletVelocityFluxFvPatchVectorField.H b/src/optimisation/adjointOptimisation/adjoint/adjointBoundaryConditions/adjointOutletVelocityFlux/adjointOutletVelocityFluxFvPatchVectorField.H index 5dd565f9d7..160da9dd95 100644 --- a/src/optimisation/adjointOptimisation/adjoint/adjointBoundaryConditions/adjointOutletVelocityFlux/adjointOutletVelocityFluxFvPatchVectorField.H +++ b/src/optimisation/adjointOptimisation/adjoint/adjointBoundaryConditions/adjointOutletVelocityFlux/adjointOutletVelocityFluxFvPatchVectorField.H @@ -30,7 +30,6 @@ Class Foam::adjointOutletVelocityFluxFvPatchVectorField Description - An outlet boundary condition for patches in which the primal flow exhibits recirculation. Adds the contribution of the objective as an adjoint momentum flux directly to the PDEs, without the need to first compute an diff --git a/src/optimisation/adjointOptimisation/adjoint/fvOptions/sources/TopO/topOSource/topOSource.H b/src/optimisation/adjointOptimisation/adjoint/fvOptions/sources/TopO/topOSource/topOSource.H index 401788b79a..7d0ac83b8d 100644 --- a/src/optimisation/adjointOptimisation/adjoint/fvOptions/sources/TopO/topOSource/topOSource.H +++ b/src/optimisation/adjointOptimisation/adjoint/fvOptions/sources/TopO/topOSource/topOSource.H @@ -31,7 +31,7 @@ Group grpFvOptionsSources Description - Impelements Brinkman penalisation terms for topology optimisation. + Implements Brinkman penalisation terms for topology optimisation. Looks up the indicator field (beta) from the registry, through topOVariablesBase diff --git a/src/optimisation/adjointOptimisation/adjoint/objectives/geometric/objectivePartialVolume/objectivePartialVolume.H b/src/optimisation/adjointOptimisation/adjoint/objectives/geometric/objectivePartialVolume/objectivePartialVolume.H index bc9527a5d7..0c718bf64f 100644 --- a/src/optimisation/adjointOptimisation/adjoint/objectives/geometric/objectivePartialVolume/objectivePartialVolume.H +++ b/src/optimisation/adjointOptimisation/adjoint/objectives/geometric/objectivePartialVolume/objectivePartialVolume.H @@ -88,15 +88,15 @@ public: // Member Functions //- Return the objective function value - scalar J(); + virtual scalar J(); //- Update d (x) / db multiplier. Surface and volume-based sensitivity //- term - void update_dxdbDirectMultiplier(); + virtual void update_dxdbDirectMultiplier(); //- Update d (normal dS) / db multiplier. Surface and volume-based //- sensitivity term - void update_dSdbMultiplier(); + virtual void update_dSdbMultiplier(); //- Write initial volume for continuation virtual bool writeData(Ostream& os) const; diff --git a/src/optimisation/adjointOptimisation/adjoint/objectives/geometric/objectiveTopOSolidVolume/objectiveTopOSolidVolume.H b/src/optimisation/adjointOptimisation/adjoint/objectives/geometric/objectiveTopOSolidVolume/objectiveTopOSolidVolume.H index 746fad08fa..42106590da 100644 --- a/src/optimisation/adjointOptimisation/adjoint/objectives/geometric/objectiveTopOSolidVolume/objectiveTopOSolidVolume.H +++ b/src/optimisation/adjointOptimisation/adjoint/objectives/geometric/objectiveTopOSolidVolume/objectiveTopOSolidVolume.H @@ -91,7 +91,7 @@ public: // Member Functions //- Return the objective function value - scalar J(); + virtual scalar J(); //- Contribution to field sensitivities virtual void update_dJdb(); diff --git a/src/optimisation/adjointOptimisation/adjoint/objectives/geometric/objectiveTopOVolume/objectiveTopOVolume.H b/src/optimisation/adjointOptimisation/adjoint/objectives/geometric/objectiveTopOVolume/objectiveTopOVolume.H index 3c494c200a..826640c99b 100644 --- a/src/optimisation/adjointOptimisation/adjoint/objectives/geometric/objectiveTopOVolume/objectiveTopOVolume.H +++ b/src/optimisation/adjointOptimisation/adjoint/objectives/geometric/objectiveTopOVolume/objectiveTopOVolume.H @@ -75,7 +75,7 @@ public: // Constructors - //- from components + //- From components objectiveTopOVolume ( const fvMesh& mesh, @@ -92,7 +92,7 @@ public: // Member Functions //- Return the objective function value - scalar J(); + virtual scalar J(); //- Contribution to field sensitivities virtual void update_dJdb(); diff --git a/src/optimisation/adjointOptimisation/adjoint/objectives/incompressible/objectiveFlowRate/objectiveFlowRate.H b/src/optimisation/adjointOptimisation/adjoint/objectives/incompressible/objectiveFlowRate/objectiveFlowRate.H index 8b4668ca76..cc36887909 100644 --- a/src/optimisation/adjointOptimisation/adjoint/objectives/incompressible/objectiveFlowRate/objectiveFlowRate.H +++ b/src/optimisation/adjointOptimisation/adjoint/objectives/incompressible/objectiveFlowRate/objectiveFlowRate.H @@ -85,19 +85,19 @@ public: //- Destructor - ~objectiveFlowRate() = default; + virtual ~objectiveFlowRate() = default; // Member Functions //- Return the objective function value - scalar J(); + virtual scalar J(); //- Update values to be added to the adjoint outlet velocity - void update_boundarydJdv(); + virtual void update_boundarydJdv(); //- Update values to be added to the adjoint outlet pressure - void update_boundarydJdvn(); + virtual void update_boundarydJdvn(); // Helper write functions diff --git a/src/optimisation/adjointOptimisation/adjoint/objectives/incompressible/objectiveFlowRatePartition/objectiveFlowRatePartition.H b/src/optimisation/adjointOptimisation/adjoint/objectives/incompressible/objectiveFlowRatePartition/objectiveFlowRatePartition.H index 4cff6660ff..19c0619f33 100644 --- a/src/optimisation/adjointOptimisation/adjoint/objectives/incompressible/objectiveFlowRatePartition/objectiveFlowRatePartition.H +++ b/src/optimisation/adjointOptimisation/adjoint/objectives/incompressible/objectiveFlowRatePartition/objectiveFlowRatePartition.H @@ -92,13 +92,13 @@ public: // Member Functions //- Return the objective function value - scalar J(); + virtual scalar J(); //- Update values to be added to the adjoint outlet velocity - void update_boundarydJdv(); + virtual void update_boundarydJdv(); //- Update values to be added to the adjoint outlet pressure - void update_boundarydJdvn(); + virtual void update_boundarydJdvn(); // Helper write functions diff --git a/src/optimisation/adjointOptimisation/adjoint/objectives/incompressible/objectiveForce/objectiveForce.H b/src/optimisation/adjointOptimisation/adjoint/objectives/incompressible/objectiveForce/objectiveForce.H index 4092f9b92f..adff57ea70 100644 --- a/src/optimisation/adjointOptimisation/adjoint/objectives/incompressible/objectiveForce/objectiveForce.H +++ b/src/optimisation/adjointOptimisation/adjoint/objectives/incompressible/objectiveForce/objectiveForce.H @@ -96,28 +96,28 @@ public: // Member Functions //- Return the objective function value - scalar J(); + virtual scalar J(); //- Update values to be added to the adjoint wall velocity - void update_boundarydJdp(); + virtual void update_boundarydJdp(); //- Update delta(n dS)/delta b multiplier - void update_dSdbMultiplier(); + virtual void update_dSdbMultiplier(); //- Update delta(x)/delta b multiplier - void update_dxdbMultiplier(); + virtual void update_dxdbMultiplier(); //- Update dJ/dnut multiplier - void update_boundarydJdnut(); + virtual void update_boundarydJdnut(); //- Update dJ/dGradU multiplier - void update_boundarydJdGradU(); + virtual void update_boundarydJdGradU(); //- Return denominator, without density virtual scalar denom() const; //- Return force direction - const vector& forceDirection() const; + virtual const vector& forceDirection() const; }; diff --git a/src/optimisation/adjointOptimisation/adjoint/objectives/incompressible/objectiveIncompressible/objectiveIncompressible.H b/src/optimisation/adjointOptimisation/adjoint/objectives/incompressible/objectiveIncompressible/objectiveIncompressible.H index 8af411bf18..25bdda9511 100644 --- a/src/optimisation/adjointOptimisation/adjoint/objectives/incompressible/objectiveIncompressible/objectiveIncompressible.H +++ b/src/optimisation/adjointOptimisation/adjoint/objectives/incompressible/objectiveIncompressible/objectiveIncompressible.H @@ -354,20 +354,20 @@ public: virtual bool write(const bool valid = true) const; //- Inline functions for checking whether pointers are set or not - inline bool hasdJdv() const; - inline bool hasdJdp() const; - inline bool hasdJdT() const; - inline bool hasdJdTMVar1() const; - inline bool hasdJdTMVar2() const; - inline bool hasBoundarydJdv() const; - inline bool hasBoundarydJdvn() const; - inline bool hasBoundarydJdvt() const; - inline bool hasBoundarydJdp() const; - inline bool hasBoundarydJdT() const; - inline bool hasBoundarydJdTMVar1() const; - inline bool hasBoundarydJdTMVar2() const; - inline bool hasBoundarydJdnut() const; - inline bool hasBoundarydJdGradU() const; + inline bool hasdJdv() const noexcept; + inline bool hasdJdp() const noexcept; + inline bool hasdJdT() const noexcept; + inline bool hasdJdTMVar1() const noexcept; + inline bool hasdJdTMVar2() const noexcept; + inline bool hasBoundarydJdv() const noexcept; + inline bool hasBoundarydJdvn() const noexcept; + inline bool hasBoundarydJdvt() const noexcept; + inline bool hasBoundarydJdp() const noexcept; + inline bool hasBoundarydJdT() const noexcept; + inline bool hasBoundarydJdTMVar1() const noexcept; + inline bool hasBoundarydJdTMVar2() const noexcept; + inline bool hasBoundarydJdnut() const noexcept; + inline bool hasBoundarydJdGradU() const noexcept; }; diff --git a/src/optimisation/adjointOptimisation/adjoint/objectives/incompressible/objectiveIncompressible/objectiveIncompressibleI.H b/src/optimisation/adjointOptimisation/adjoint/objectives/incompressible/objectiveIncompressible/objectiveIncompressibleI.H index 3e3b05324d..3ac1a166b3 100644 --- a/src/optimisation/adjointOptimisation/adjoint/objectives/incompressible/objectiveIncompressible/objectiveIncompressibleI.H +++ b/src/optimisation/adjointOptimisation/adjoint/objectives/incompressible/objectiveIncompressible/objectiveIncompressibleI.H @@ -213,85 +213,85 @@ Foam::objectiveIncompressible::boundarydJdGradU() } -inline bool Foam::objectiveIncompressible::hasdJdv() const +inline bool Foam::objectiveIncompressible::hasdJdv() const noexcept { return bool(dJdvPtr_); } -inline bool Foam::objectiveIncompressible::hasdJdp() const +inline bool Foam::objectiveIncompressible::hasdJdp() const noexcept { return bool(dJdpPtr_); } -inline bool Foam::objectiveIncompressible::hasdJdT() const +inline bool Foam::objectiveIncompressible::hasdJdT() const noexcept { return bool(dJdTPtr_); } -inline bool Foam::objectiveIncompressible::hasdJdTMVar1() const +inline bool Foam::objectiveIncompressible::hasdJdTMVar1() const noexcept { return bool(dJdTMvar1Ptr_); } -inline bool Foam::objectiveIncompressible::hasdJdTMVar2() const +inline bool Foam::objectiveIncompressible::hasdJdTMVar2() const noexcept { return bool(dJdTMvar2Ptr_); } -inline bool Foam::objectiveIncompressible::hasBoundarydJdv() const +inline bool Foam::objectiveIncompressible::hasBoundarydJdv() const noexcept { return bool(bdJdvPtr_); } -inline bool Foam::objectiveIncompressible::hasBoundarydJdvn() const +inline bool Foam::objectiveIncompressible::hasBoundarydJdvn() const noexcept { return bool(bdJdvnPtr_); } -inline bool Foam::objectiveIncompressible::hasBoundarydJdvt() const +inline bool Foam::objectiveIncompressible::hasBoundarydJdvt() const noexcept { return bool(bdJdvtPtr_); } -inline bool Foam::objectiveIncompressible::hasBoundarydJdp() const +inline bool Foam::objectiveIncompressible::hasBoundarydJdp() const noexcept { return bool(bdJdpPtr_); } -inline bool Foam::objectiveIncompressible::hasBoundarydJdT() const +inline bool Foam::objectiveIncompressible::hasBoundarydJdT() const noexcept { return bool(bdJdTPtr_); } -inline bool Foam::objectiveIncompressible::hasBoundarydJdTMVar1() const +inline bool Foam::objectiveIncompressible::hasBoundarydJdTMVar1() const noexcept { return bool(bdJdTMvar1Ptr_); } -inline bool Foam::objectiveIncompressible::hasBoundarydJdTMVar2() const +inline bool Foam::objectiveIncompressible::hasBoundarydJdTMVar2() const noexcept { return bool(bdJdTMvar2Ptr_); } -inline bool Foam::objectiveIncompressible::hasBoundarydJdnut() const +inline bool Foam::objectiveIncompressible::hasBoundarydJdnut() const noexcept { return bool(bdJdnutPtr_); } -inline bool Foam::objectiveIncompressible::hasBoundarydJdGradU() const +inline bool Foam::objectiveIncompressible::hasBoundarydJdGradU() const noexcept { return bool(bdJdGradUPtr_); } diff --git a/src/optimisation/adjointOptimisation/adjoint/objectives/incompressible/objectiveMoment/objectiveMoment.H b/src/optimisation/adjointOptimisation/adjoint/objectives/incompressible/objectiveMoment/objectiveMoment.H index 49f0dcff6e..e13be66d74 100644 --- a/src/optimisation/adjointOptimisation/adjoint/objectives/incompressible/objectiveMoment/objectiveMoment.H +++ b/src/optimisation/adjointOptimisation/adjoint/objectives/incompressible/objectiveMoment/objectiveMoment.H @@ -97,30 +97,30 @@ public: // Member Functions //- Return the objective function value - scalar J(); + virtual scalar J(); //- Update mean drag and lift values - void update_meanValues(); + virtual void update_meanValues(); //- Update values to be added to the adjoint wall velocity - void update_boundarydJdp(); + virtual void update_boundarydJdp(); //- Update delta(n dS)/delta b multiplier - void update_dSdbMultiplier(); + virtual void update_dSdbMultiplier(); //- Update delta(x)/delta b multiplier - void update_dxdbMultiplier(); + virtual void update_dxdbMultiplier(); //- Update delta(x)/delta b multiplier coming directly from the //- objective - void update_dxdbDirectMultiplier(); + virtual void update_dxdbDirectMultiplier(); //- Update dJ/dnut multiplier - void update_boundarydJdnut(); + virtual void update_boundarydJdnut(); //- Update dJ/dGradU multiplier /* WIP - void update_boundarydJdGradU(); + virtual void update_boundarydJdGradU(); */ }; diff --git a/src/optimisation/adjointOptimisation/adjoint/objectives/incompressible/objectiveNutSqr/objectiveNutSqr.H b/src/optimisation/adjointOptimisation/adjoint/objectives/incompressible/objectiveNutSqr/objectiveNutSqr.H index 4b3b875258..c22d108ada 100644 --- a/src/optimisation/adjointOptimisation/adjoint/objectives/incompressible/objectiveNutSqr/objectiveNutSqr.H +++ b/src/optimisation/adjointOptimisation/adjoint/objectives/incompressible/objectiveNutSqr/objectiveNutSqr.H @@ -116,20 +116,20 @@ public: // Member Functions //- Return the objective function value - scalar J(); + virtual scalar J(); //- Update values to be added to the adjoint outlet velocity - void update_dJdv(); + virtual void update_dJdv(); //- Update field to be added to the first adjoint turbulence model PDE - void update_dJdTMvar1(); + virtual void update_dJdTMvar1(); //- Update field to be added to the second adjoint turbulence model PDE - void update_dJdTMvar2(); + virtual void update_dJdTMvar2(); //- Update field to be added to be added to volume-based //- sensitivity derivatives, emerging from delta ( dV ) / delta b - void update_divDxDbMultiplier(); + virtual void update_divDxDbMultiplier(); //- Add source terms to the adjoint turbulence model equations virtual void addSource(fvScalarMatrix& matrix); diff --git a/src/optimisation/adjointOptimisation/adjoint/objectives/incompressible/objectivePowerDissipation/objectivePowerDissipation.H b/src/optimisation/adjointOptimisation/adjoint/objectives/incompressible/objectivePowerDissipation/objectivePowerDissipation.H index 6f744de07b..7f2bb93a48 100644 --- a/src/optimisation/adjointOptimisation/adjoint/objectives/incompressible/objectivePowerDissipation/objectivePowerDissipation.H +++ b/src/optimisation/adjointOptimisation/adjoint/objectives/incompressible/objectivePowerDissipation/objectivePowerDissipation.H @@ -97,16 +97,16 @@ public: // Member Functions //- Return the objective function value - scalar J(); + virtual scalar J(); //- Update values to be added to the adjoint outlet velocity - void update_dJdv(); + virtual void update_dJdv(); //- Update field to be added to the first adjoint turbulence model PDE - void update_dJdTMvar1(); + virtual void update_dJdTMvar1(); //- Update field to be added to the second adjoint turbulence model PDE - void update_dJdTMvar2(); + virtual void update_dJdTMvar2(); //- Update div(dx/db multiplier). Volume-based sensitivity term virtual void update_divDxDbMultiplier(); diff --git a/src/optimisation/adjointOptimisation/adjoint/objectives/incompressible/objectivePtLosses/objectivePtLosses.C b/src/optimisation/adjointOptimisation/adjoint/objectives/incompressible/objectivePtLosses/objectivePtLosses.C index fef3492b95..f27ee4c1f2 100644 --- a/src/optimisation/adjointOptimisation/adjoint/objectives/incompressible/objectivePtLosses/objectivePtLosses.C +++ b/src/optimisation/adjointOptimisation/adjoint/objectives/incompressible/objectivePtLosses/objectivePtLosses.C @@ -52,32 +52,7 @@ addToRunTimeSelectionTable ); -// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * // - -objectivePtLosses::objectivePtLosses -( - const fvMesh& mesh, - const dictionary& dict, - const word& adjointSolverName, - const word& primalSolverName -) -: - objectiveIncompressible(mesh, dict, adjointSolverName, primalSolverName), - patches_(0), - patchPt_(0) -{ - // Find inlet/outlet patches - initialize(); - - // Allocate boundary field pointers - bdJdpPtr_.reset(createZeroBoundaryPtr(mesh_)); - bdJdvPtr_.reset(createZeroBoundaryPtr(mesh_)); - bdJdvnPtr_.reset(createZeroBoundaryPtr(mesh_)); - bdJdvtPtr_.reset(createZeroBoundaryPtr(mesh_)); -} - - -// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * // +// * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * // void objectivePtLosses::initialize() { @@ -132,6 +107,33 @@ void objectivePtLosses::initialize() } +// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * // + +objectivePtLosses::objectivePtLosses +( + const fvMesh& mesh, + const dictionary& dict, + const word& adjointSolverName, + const word& primalSolverName +) +: + objectiveIncompressible(mesh, dict, adjointSolverName, primalSolverName), + patches_(0), + patchPt_(0) +{ + // Find inlet/outlet patches + initialize(); + + // Allocate boundary field pointers + bdJdpPtr_.reset(createZeroBoundaryPtr(mesh_)); + bdJdvPtr_.reset(createZeroBoundaryPtr(mesh_)); + bdJdvnPtr_.reset(createZeroBoundaryPtr(mesh_)); + bdJdvtPtr_.reset(createZeroBoundaryPtr(mesh_)); +} + + +// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * // + scalar objectivePtLosses::J() { J_ = Zero; diff --git a/src/optimisation/adjointOptimisation/adjoint/objectives/incompressible/objectivePtLosses/objectivePtLosses.H b/src/optimisation/adjointOptimisation/adjoint/objectives/incompressible/objectivePtLosses/objectivePtLosses.H index 0cffb76ff7..65f084a6d2 100644 --- a/src/optimisation/adjointOptimisation/adjoint/objectives/incompressible/objectivePtLosses/objectivePtLosses.H +++ b/src/optimisation/adjointOptimisation/adjoint/objectives/incompressible/objectivePtLosses/objectivePtLosses.H @@ -66,6 +66,12 @@ class objectivePtLosses scalarField patchPt_; + // Private Member Functions + + //- Return the objectiveReportPatches + void initialize(); + + public: //- Runtime type information @@ -90,23 +96,20 @@ public: // Member Functions - //- Return the objectiveReportPatches - void initialize(); - //- Return the objective function value - scalar J(); + virtual scalar J(); //- Update values to be added to the adjoint inlet velocity - void update_boundarydJdp(); + virtual void update_boundarydJdp(); //- Update values to be added to the adjoint outlet velocity - void update_boundarydJdv(); + virtual void update_boundarydJdv(); //- Update values to be added to the adjoint outlet pressure - void update_boundarydJdvn(); + virtual void update_boundarydJdvn(); //- Update values to be added to the adjoint outlet tangential velocity - void update_boundarydJdvt(); + virtual void update_boundarydJdvt(); // Helper write functions diff --git a/src/optimisation/adjointOptimisation/adjoint/objectives/incompressible/objectiveUniformityCellZone/objectiveUniformityCellZone.H b/src/optimisation/adjointOptimisation/adjoint/objectives/incompressible/objectiveUniformityCellZone/objectiveUniformityCellZone.H index 697dc77ad7..c6575fb8c5 100644 --- a/src/optimisation/adjointOptimisation/adjoint/objectives/incompressible/objectiveUniformityCellZone/objectiveUniformityCellZone.H +++ b/src/optimisation/adjointOptimisation/adjoint/objectives/incompressible/objectiveUniformityCellZone/objectiveUniformityCellZone.H @@ -97,14 +97,11 @@ public: // Member Functions - //- Return the objectiveReportPatches - void initialize(); - //- Return the objective function value - scalar J(); + virtual scalar J(); //- Update values to be added to the adjoint outlet velocity - void update_dJdv(); + virtual void update_dJdv(); //- Update div( dx/db multiplier). Volume-based sensitivity term virtual void update_divDxDbMultiplier(); diff --git a/src/optimisation/adjointOptimisation/adjoint/objectives/incompressible/objectiveUniformityPatch/objectiveUniformityPatch.C b/src/optimisation/adjointOptimisation/adjoint/objectives/incompressible/objectiveUniformityPatch/objectiveUniformityPatch.C index c6f5bd91de..0d78dc3647 100644 --- a/src/optimisation/adjointOptimisation/adjoint/objectives/incompressible/objectiveUniformityPatch/objectiveUniformityPatch.C +++ b/src/optimisation/adjointOptimisation/adjoint/objectives/incompressible/objectiveUniformityPatch/objectiveUniformityPatch.C @@ -51,32 +51,7 @@ addToRunTimeSelectionTable ); -// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * // - -objectiveUniformityPatch::objectiveUniformityPatch -( - const fvMesh& mesh, - const dictionary& dict, - const word& adjointSolverName, - const word& primalSolverName -) -: - objectiveIncompressible(mesh, dict, adjointSolverName, primalSolverName), - patches_(), - UMean_(), - UVar_() -{ - // Find inlet/outlet patches - initialize(); - - // Allocate boundary field pointers - bdJdvPtr_.reset(createZeroBoundaryPtr(mesh_)); - bdJdvnPtr_.reset(createZeroBoundaryPtr(mesh_)); - bdJdvtPtr_.reset(createZeroBoundaryPtr(mesh_)); -} - - -// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * // +// * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * // void objectiveUniformityPatch::initialize() { @@ -132,6 +107,33 @@ void objectiveUniformityPatch::initialize() } +// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * // + +objectiveUniformityPatch::objectiveUniformityPatch +( + const fvMesh& mesh, + const dictionary& dict, + const word& adjointSolverName, + const word& primalSolverName +) +: + objectiveIncompressible(mesh, dict, adjointSolverName, primalSolverName), + patches_(), + UMean_(), + UVar_() +{ + // Find inlet/outlet patches + initialize(); + + // Allocate boundary field pointers + bdJdvPtr_.reset(createZeroBoundaryPtr(mesh_)); + bdJdvnPtr_.reset(createZeroBoundaryPtr(mesh_)); + bdJdvtPtr_.reset(createZeroBoundaryPtr(mesh_)); +} + + +// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * // + scalar objectiveUniformityPatch::J() { J_ = Zero; diff --git a/src/optimisation/adjointOptimisation/adjoint/objectives/incompressible/objectiveUniformityPatch/objectiveUniformityPatch.H b/src/optimisation/adjointOptimisation/adjoint/objectives/incompressible/objectiveUniformityPatch/objectiveUniformityPatch.H index 148eac5612..db39b57d95 100644 --- a/src/optimisation/adjointOptimisation/adjoint/objectives/incompressible/objectiveUniformityPatch/objectiveUniformityPatch.H +++ b/src/optimisation/adjointOptimisation/adjoint/objectives/incompressible/objectiveUniformityPatch/objectiveUniformityPatch.H @@ -70,6 +70,12 @@ class objectiveUniformityPatch scalarField UVar_; + // Private Member Functions + + //- Return the objectiveReportPatches + void initialize(); + + public: //- Runtime type information @@ -94,20 +100,17 @@ public: // Member Functions - //- Return the objectiveReportPatches - void initialize(); - //- Return the objective function value - scalar J(); + virtual scalar J(); //- Update values to be added to the adjoint outlet velocity - void update_boundarydJdv(); + virtual void update_boundarydJdv(); //- Update values to be added to the adjoint outlet pressure - void update_boundarydJdvn(); + virtual void update_boundarydJdvn(); //- Update values to be added to the adjoint outlet tangential velocity - void update_boundarydJdvt(); + virtual void update_boundarydJdvt(); // Helper write functions diff --git a/src/optimisation/adjointOptimisation/adjoint/objectives/objective/objective.H b/src/optimisation/adjointOptimisation/adjoint/objectives/objective/objective.H index b8331c1ca0..7065d518bb 100644 --- a/src/optimisation/adjointOptimisation/adjoint/objectives/objective/objective.H +++ b/src/optimisation/adjointOptimisation/adjoint/objectives/objective/objective.H @@ -266,36 +266,31 @@ public: //- Return the objective function of the optimisation cycle. // This corresponds to the mean value, if it exists, or the // instantaneous value otherwise - scalar JCycle(bool negate = false) const; + virtual scalar JCycle(bool negate = false) const; //- Accumulate contribution for the mean objective value // For steady-state runs - void accumulateJMean(solverControl& solverControl); + virtual void accumulateJMean(solverControl& solverControl); + //- Accumulate contribution for the mean objective value // For unsteady runs - void accumulateJMean(); + virtual void accumulateJMean(); //- Return the objective function weight - scalar weight() const; - - //- Return the normalization factor - const autoPtr& normFactor() const; - - //- Return the objective target value - const autoPtr& target() const; + virtual scalar weight() const; //- Is the objective normalized - bool normalize() const; + virtual bool normalize() const; //- Normalize all fields allocated by the objective virtual void doNormalization(); //- Check whether this is an objective integration time - bool isWithinIntegrationTime() const; + virtual bool isWithinIntegrationTime() const; //- Increment integration times - void incrementIntegrationTimes(const scalar timeSpan); + virtual void incrementIntegrationTimes(const scalar timeSpan); //- Contribution to field sensitivities inline const volScalarField& dJdb() const; @@ -450,22 +445,23 @@ public: inline void setWrite(const bool shouldWrite); // Inline functions for checking whether pointers are set or not - inline bool hasdJdb() const; - inline bool hasdJdbField() const; - inline bool hasBoundarydJdb() const; - inline bool hasdSdbMult() const; - inline bool hasdndbMult() const; - inline bool hasdxdbMult() const; - inline bool hasdxdbDirectMult() const; - inline bool hasBoundaryEdgeContribution() const; - inline bool hasDivDxDbMult() const; - inline bool hasGradDxDbMult() const; + inline bool hasdJdb() const noexcept; + inline bool hasdJdbField() const noexcept; + inline bool hasBoundarydJdb() const noexcept; + inline bool hasdSdbMult() const noexcept; + inline bool hasdndbMult() const noexcept; + inline bool hasdxdbMult() const noexcept; + inline bool hasdxdbDirectMult() const noexcept; + inline bool hasBoundaryEdgeContribution() const noexcept; + inline bool hasDivDxDbMult() const noexcept; + inline bool hasGradDxDbMult() const noexcept; // Inline functions for checking whether integration times are set - inline bool hasIntegrationStartTime() const; - inline bool hasIntegrationEndTime() const; - // Set the computed status of the objective - inline void setComputed(const bool isComputed); + inline bool hasIntegrationStartTime() const noexcept; + inline bool hasIntegrationEndTime() const noexcept; + + //- Set the computed status of the objective + inline void setComputed(const bool isComputed) noexcept; //- Return objective dictionary const dictionary& dict() const; diff --git a/src/optimisation/adjointOptimisation/adjoint/objectives/objective/objectiveI.H b/src/optimisation/adjointOptimisation/adjoint/objectives/objective/objectiveI.H index b134e74bf7..ad051d849d 100644 --- a/src/optimisation/adjointOptimisation/adjoint/objectives/objective/objectiveI.H +++ b/src/optimisation/adjointOptimisation/adjoint/objectives/objective/objectiveI.H @@ -167,79 +167,79 @@ inline const Foam::volTensorField& Foam::objective::gradDxDbMultiplier() const } -inline bool Foam::objective::hasdJdb() const +inline bool Foam::objective::hasdJdb() const noexcept { return bool(dJdbPtr_); } -inline bool Foam::objective::hasdJdbField() const +inline bool Foam::objective::hasdJdbField() const noexcept { return bool(dJdbFieldPtr_); } -inline bool Foam::objective::hasBoundarydJdb() const +inline bool Foam::objective::hasBoundarydJdb() const noexcept { return bool(bdJdbPtr_); } -inline bool Foam::objective::hasdSdbMult() const +inline bool Foam::objective::hasdSdbMult() const noexcept { return bool(bdSdbMultPtr_); } -inline bool Foam::objective::hasdndbMult() const +inline bool Foam::objective::hasdndbMult() const noexcept { return bool(bdndbMultPtr_); } -inline bool Foam::objective::hasdxdbMult() const +inline bool Foam::objective::hasdxdbMult() const noexcept { return bool(bdxdbMultPtr_); } -inline bool Foam::objective::hasdxdbDirectMult() const +inline bool Foam::objective::hasdxdbDirectMult() const noexcept { return bool(bdxdbDirectMultPtr_); } -inline bool Foam::objective::hasBoundaryEdgeContribution() const +inline bool Foam::objective::hasBoundaryEdgeContribution() const noexcept { return bool(bEdgeContribution_); } -inline bool Foam::objective::hasDivDxDbMult() const +inline bool Foam::objective::hasDivDxDbMult() const noexcept { return bool(divDxDbMultPtr_); } -inline bool Foam::objective::hasGradDxDbMult() const +inline bool Foam::objective::hasGradDxDbMult() const noexcept { return bool(gradDxDbMultPtr_); } -inline bool Foam::objective::hasIntegrationStartTime() const +inline bool Foam::objective::hasIntegrationStartTime() const noexcept { return bool(integrationStartTimePtr_); } -inline bool Foam::objective::hasIntegrationEndTime() const +inline bool Foam::objective::hasIntegrationEndTime() const noexcept { return bool(integrationEndTimePtr_); } -inline void Foam::objective::setComputed(const bool isComputed) +inline void Foam::objective::setComputed(const bool isComputed) noexcept { computed_ = isComputed; } diff --git a/src/optimisation/adjointOptimisation/adjoint/optimisation/designVariables/designVariables/designVariables.H b/src/optimisation/adjointOptimisation/adjoint/optimisation/designVariables/designVariables/designVariables.H index 7a684a7a14..04268c1d4b 100644 --- a/src/optimisation/adjointOptimisation/adjoint/optimisation/designVariables/designVariables/designVariables.H +++ b/src/optimisation/adjointOptimisation/adjoint/optimisation/designVariables/designVariables/designVariables.H @@ -73,7 +73,7 @@ protected: //- Which of the design variables will be updated labelList activeDesignVariables_; - //- Copy of old design variables. Usefull when performing line-search + //- Copy of old design variables. Useful when performing line-search autoPtr oldDesignVariables_; //- Maximum design variables' change in the first optimisation cycle diff --git a/src/optimisation/adjointOptimisation/adjoint/optimisation/designVariables/levelSet/interpolationFunctions/sigmoidalHeaviside/sigmoidalHeaviside.C b/src/optimisation/adjointOptimisation/adjoint/optimisation/designVariables/levelSet/interpolationFunctions/sigmoidalHeaviside/sigmoidalHeaviside.C index dfa06943f5..e7db5d749e 100644 --- a/src/optimisation/adjointOptimisation/adjoint/optimisation/designVariables/levelSet/interpolationFunctions/sigmoidalHeaviside/sigmoidalHeaviside.C +++ b/src/optimisation/adjointOptimisation/adjoint/optimisation/designVariables/levelSet/interpolationFunctions/sigmoidalHeaviside/sigmoidalHeaviside.C @@ -119,7 +119,7 @@ tmp sigmoidalHeaviside::derivative(const scalarField& arg) const const scalar pi = constant::mathematical::pi; scalarField argLimited(max(min(dNB_, arg), -dNB_)); DebugInfo - << type() << "::interpolate:: t, dNB " << t << ", " << dNB_ << endl; + << type() << "::derivative:: t, dNB " << t << ", " << dNB_ << endl; deriv = 0.5*(scalar(1) + cos(pi*argLimited/dNB_))/dNB_; diff --git a/src/optimisation/adjointOptimisation/adjoint/optimisation/designVariables/levelSet/levelSetDesignVariables.H b/src/optimisation/adjointOptimisation/adjoint/optimisation/designVariables/levelSet/levelSetDesignVariables.H index 27202a9a15..dbb18f87bd 100644 --- a/src/optimisation/adjointOptimisation/adjoint/optimisation/designVariables/levelSet/levelSetDesignVariables.H +++ b/src/optimisation/adjointOptimisation/adjoint/optimisation/designVariables/levelSet/levelSetDesignVariables.H @@ -43,14 +43,14 @@ Description \endverbatim The implemented approach borrows from the references therein, but does not - follow any of them exactly. The underlaying field of the design variables + follow any of them exactly. The underlying field of the design variables is not the level-set field but affects the latter through: a) a regularisation approach similar to that used in porosity-based topO (see the regularisation class and references therein) and b) a re-initialisation strategy. Since solving a modified Hamilton-Jacobi equation poses a number of numerical challenges, the signed distance field is obtained by identifying the zero level-set contour using the - cutFaceIso, cutCellIso infrastucture (see references therein for the + cutFaceIso, cutCellIso infrastructure (see references therein for the methodology) and using these "cut-faces" as seeds for meshWave. SourceFiles @@ -96,7 +96,7 @@ protected: //- into signed distances volScalarField aTilda_; - //- Function to transorm signed distances to the indicator field beta_ + //- Function to transform signed distances to the indicator field beta_ autoPtr interpolation_; //- The indicator field @@ -105,7 +105,7 @@ protected: //- Fix aTilda values in fixed{Zero}PorousZones and IOcells bool fixATildaValues_; - //- Write all fields related to the distance calculation (debuging) + //- Write all fields related to the distance calculation (debugging) bool writeAllDistanceFields_; diff --git a/src/optimisation/adjointOptimisation/adjoint/optimisation/designVariables/topODesignVariables/dynamicTopODesignVariables/dynamicTopODesignVariables.C b/src/optimisation/adjointOptimisation/adjoint/optimisation/designVariables/topODesignVariables/dynamicTopODesignVariables/dynamicTopODesignVariables.C index 5a75a2de86..70f35575be 100644 --- a/src/optimisation/adjointOptimisation/adjoint/optimisation/designVariables/topODesignVariables/dynamicTopODesignVariables/dynamicTopODesignVariables.C +++ b/src/optimisation/adjointOptimisation/adjoint/optimisation/designVariables/topODesignVariables/dynamicTopODesignVariables/dynamicTopODesignVariables.C @@ -86,7 +86,7 @@ Foam::dynamicTopODesignVariables::dynamicTopODesignVariables topODesignVariables(mesh, dict, size), marchCells_(mesh, dict.subDict("marchingCoeffs")) { - // Rest of the contrsuctor initialization + // Rest of the constructor initialization initialize(); } @@ -100,10 +100,7 @@ Foam::dynamicTopODesignVariables::New const dictionary& dict ) { - return autoPtr - ( - new dynamicTopODesignVariables(mesh, dict) - ); + return autoPtr::New(mesh, dict); } diff --git a/src/optimisation/adjointOptimisation/adjoint/optimisation/designVariables/topODesignVariables/regularisation/fieldRegularisation.C b/src/optimisation/adjointOptimisation/adjoint/optimisation/designVariables/topODesignVariables/regularisation/fieldRegularisation.C index 175f44b5a3..4887f48ce1 100644 --- a/src/optimisation/adjointOptimisation/adjoint/optimisation/designVariables/topODesignVariables/regularisation/fieldRegularisation.C +++ b/src/optimisation/adjointOptimisation/adjoint/optimisation/designVariables/topODesignVariables/regularisation/fieldRegularisation.C @@ -100,8 +100,7 @@ Foam::fieldRegularisation::fieldRegularisation ) { DebugInfo - << "Regularise " << Switch(regularise_) << endl; - DebugInfo + << "Regularise " << Switch(regularise_) << nl << "Project " << Switch(project_) << endl; } @@ -160,7 +159,7 @@ void Foam::fieldRegularisation::postProcessSens(scalarField& sens) { sens *= sharpenFunction_->derivative(betaArg_); } - // Add part due to regulatisation + // Add part due to regularisation if (regularise_) { // Solve the adjoint to the regularisation equation diff --git a/src/optimisation/adjointOptimisation/adjoint/optimisation/designVariables/topODesignVariables/regularisation/regularisationPDE/Helmoltz/Helmholtz.H b/src/optimisation/adjointOptimisation/adjoint/optimisation/designVariables/topODesignVariables/regularisation/regularisationPDE/Helmoltz/Helmholtz.H index 5061609ac9..36a646d617 100644 --- a/src/optimisation/adjointOptimisation/adjoint/optimisation/designVariables/topODesignVariables/regularisation/regularisationPDE/Helmoltz/Helmholtz.H +++ b/src/optimisation/adjointOptimisation/adjoint/optimisation/designVariables/topODesignVariables/regularisation/regularisationPDE/Helmoltz/Helmholtz.H @@ -69,7 +69,6 @@ private: protected: - // Protected Data //- Solve the regularisationPDE only on a subset mesh made of the diff --git a/src/optimisation/adjointOptimisation/adjoint/optimisation/designVariables/topODesignVariables/regularisation/regularisationPDE/regularisationPDE/regularisationPDE.H b/src/optimisation/adjointOptimisation/adjoint/optimisation/designVariables/topODesignVariables/regularisation/regularisationPDE/regularisationPDE/regularisationPDE.H index 4ee6727786..ea2bd7fc16 100644 --- a/src/optimisation/adjointOptimisation/adjoint/optimisation/designVariables/topODesignVariables/regularisation/regularisationPDE/regularisationPDE/regularisationPDE.H +++ b/src/optimisation/adjointOptimisation/adjoint/optimisation/designVariables/topODesignVariables/regularisation/regularisationPDE/regularisationPDE/regularisationPDE.H @@ -1,3 +1,4 @@ + /*---------------------------------------------------------------------------*\ ========= | \\ / F ield | OpenFOAM: The Open Source CFD Toolbox diff --git a/src/optimisation/adjointOptimisation/adjoint/optimisation/designVariables/topODesignVariables/topODesignVariables.C b/src/optimisation/adjointOptimisation/adjoint/optimisation/designVariables/topODesignVariables/topODesignVariables.C index 8e20805c72..766f0f8da9 100644 --- a/src/optimisation/adjointOptimisation/adjoint/optimisation/designVariables/topODesignVariables/topODesignVariables.C +++ b/src/optimisation/adjointOptimisation/adjoint/optimisation/designVariables/topODesignVariables/topODesignVariables.C @@ -174,7 +174,7 @@ void Foam::topODesignVariables::setActiveDesignVariables label varI(activeDesignVariables_.size()); activeDesignVariables_.setSize(offset + mesh_.nCells(), -1); // Set active design variables - // If specific porosity zones are perscribed, use them directly + // If specific porosity zones are prescribed, use them directly if (!zones_.adjointPorousZoneIDs().empty()) { for (label cellZoneID : zones_.adjointPorousZoneIDs()) @@ -346,10 +346,7 @@ Foam::autoPtr Foam::topODesignVariables::New const dictionary& dict ) { - return autoPtr - ( - new topODesignVariables(mesh, dict) - ); + return autoPtr::New(mesh, dict); } diff --git a/src/optimisation/adjointOptimisation/adjoint/optimisation/designVariables/topODesignVariables/topODesignVariables.H b/src/optimisation/adjointOptimisation/adjoint/optimisation/designVariables/topODesignVariables/topODesignVariables.H index 245b1fec77..4ec456a444 100644 --- a/src/optimisation/adjointOptimisation/adjoint/optimisation/designVariables/topODesignVariables/topODesignVariables.H +++ b/src/optimisation/adjointOptimisation/adjoint/optimisation/designVariables/topODesignVariables/topODesignVariables.H @@ -81,7 +81,7 @@ protected: // Protected data - //- A subfield of the design variables correponding to the porosity + //- A subfield of the design variables corresponding to the porosity //- field. // Usually the same as *this SubField alpha_; diff --git a/src/optimisation/adjointOptimisation/adjoint/optimisation/designVariables/topODesignVariables/topOVariablesBase/topOVariablesBase.H b/src/optimisation/adjointOptimisation/adjoint/optimisation/designVariables/topODesignVariables/topOVariablesBase/topOVariablesBase.H index 0a1d0af9a1..ee54d62f2d 100644 --- a/src/optimisation/adjointOptimisation/adjoint/optimisation/designVariables/topODesignVariables/topOVariablesBase/topOVariablesBase.H +++ b/src/optimisation/adjointOptimisation/adjoint/optimisation/designVariables/topODesignVariables/topOVariablesBase/topOVariablesBase.H @@ -66,7 +66,7 @@ protected: // Protected data - //- Cell zones usefull for defining the constant and changing parts + //- Cell zones useful for defining the constant and changing parts //- of the domain in topO topOZones zones_; @@ -206,7 +206,7 @@ public: // field // - 0 distance contour for levelSet or // - 0.5 beta contour for porosity-based topO. - // For levelSet topO, the process of identitying the contour sets also + // For levelSet topO, the process of identifying the contour sets also // the seeds for computing the distance field in the entire domain void writeFluidSolidInterface ( diff --git a/src/optimisation/adjointOptimisation/adjoint/optimisation/designVariables/topODesignVariables/topOZones/topOZones.H b/src/optimisation/adjointOptimisation/adjoint/optimisation/designVariables/topODesignVariables/topOZones/topOZones.H index a287a6f91b..7a80c944ad 100644 --- a/src/optimisation/adjointOptimisation/adjoint/optimisation/designVariables/topODesignVariables/topOZones/topOZones.H +++ b/src/optimisation/adjointOptimisation/adjoint/optimisation/designVariables/topODesignVariables/topOZones/topOZones.H @@ -89,7 +89,7 @@ protected: //- Get zone IDs corresponding to a wordList, read from a dict. // Avoid going through ZoneMesh.indices() since this practically sorts // the IDs from smallest to largest while we need to keep them in the - // same order as that perscribed in the wordList + // same order as that prescribed in the wordList labelList getZoneIDs(const dictionary& dict, const word& zoneGroup); //- Add a cellZone containing the cells next to IO patches diff --git a/src/optimisation/adjointOptimisation/adjoint/solvers/primalSolvers/incompressible/incompressiblePrimalSolver/incompressiblePrimalSolver.C b/src/optimisation/adjointOptimisation/adjoint/solvers/primalSolvers/incompressible/incompressiblePrimalSolver/incompressiblePrimalSolver.C index a55b75ac97..2b35d8a9d4 100644 --- a/src/optimisation/adjointOptimisation/adjoint/solvers/primalSolvers/incompressible/incompressiblePrimalSolver/incompressiblePrimalSolver.C +++ b/src/optimisation/adjointOptimisation/adjoint/solvers/primalSolvers/incompressible/incompressiblePrimalSolver/incompressiblePrimalSolver.C @@ -167,7 +167,7 @@ void Foam::incompressiblePrimalSolver::correctBoundaryConditions() // including averaged ones, if present vars.correctBoundaryConditions(); - // phi cannot be updated through correctBoundayrConditions. + // phi cannot be updated through correctBoundaryConditions. // Re-compute based on the Rhie-Chow interpolation scheme. // This is a non-linear process // (phi depends on UEqn().A() which depends on phi)