From 5d584be42f4e2d6e2aad22733d32abe030e8c654 Mon Sep 17 00:00:00 2001 From: Vaggelis Papoutsis Date: Thu, 7 Oct 2021 18:00:44 +0300 Subject: [PATCH] ENH: adjustments to the efficiency of the adjoint code - ATCstandard, ATCUaGradU: the ATC is now added as a dimensioned field and not as an fvMatrix to UaEqn. This get rid of many unnecessary allocations. - ATCstandard: gradU is cached within the class to avoid its re-computation in every adjoint iteration of the steady state solver. - Inlined a number of functions within the primal and adjoint solvers. This probably has a negligible effect since they likely were inlined by the compiler either way. - The momentum diffusivity at the boundary, used by the adjoint boundary conditions, was computed for the entire field and, then, only the boundary field of each adjoint boundary condition was used. If many outlet boundaries exist, the entire nuEff field would be computed as many times as the number of boundaries, leading to an unnecessary computational overhead. - Outlet boundary conditions (both pressure and velocity) use the local patch gradient to compute their fluxes. This patch gradient requires the computation of the adjacent cell gradient, which is done on the fly, on a per patch basis. To compute this patch adjacent gradient however, the field under the grad sign is interpolated on the entire mesh. If many outlets exist, this leads to a huge computational overhead. Solved by caching the interpolated field to the database and re-using it, in a way similar to the caching of gradient fields (see fvc::grad). WIP: functions returning references to primal and adjoint boundary fields within boundaryAdjointContributions seem to have a non-negligible overhead for cases with many patches. No easy work-around here since these are virtual and cannot be inlined. WIP: introduced the code structure for caching the contributions to the adjoint boundary conditions that depend only on the primal fields and reusing. The process needs to be completed and evaluated, to make sure that the extra code complexity is justified by gains in performance. --- .../adjoint/ATCModel/ATCModel/ATCModel.C | 10 +- .../adjoint/ATCModel/ATCModel/ATCModel.H | 7 +- .../adjoint/ATCModel/ATCUaGradU/ATCUaGradU.C | 6 +- .../ATCModel/ATCstandard/ATCstandard.C | 95 ++++++------ .../ATCModel/ATCstandard/ATCstandard.H | 15 +- .../adjointBoundaryCondition.C | 64 +++++++-- .../adjointBoundaryCondition.H | 8 +- ...ointOutletVelocityFluxFvPatchVectorField.C | 9 +- ...ointOutletVelocityFluxFvPatchVectorField.H | 8 +- .../adjointWallVelocityFvPatchVectorField.C | 9 +- ...oundaryAdjointContributionIncompressible.C | 97 ++++--------- .../objectiveForce/objectiveForce.C | 134 +++++++---------- .../objectiveForce/objectiveForce.H | 8 +- .../objectiveMoment/objectiveMoment.C | 136 ++++++++---------- .../objectiveMoment/objectiveMoment.H | 8 +- .../adjointMeshMovementSolverIncompressible.C | 10 +- .../adjointSensitivityIncompressible.C | 22 +-- .../adjointSensitivityIncompressible.H | 19 ++- .../adjoint/parameterization/Bezier/Bezier.C | 8 +- .../NURBS3DVolume/NURBS3DVolume.C | 42 +++--- .../controlPointsDefinition.C | 4 +- .../adjointSolver/adjointSolver.C | 5 +- .../adjointSimple/adjointSimple.C | 6 +- .../incompressibleAdjointSolver.C | 6 +- .../incompressible/incompressibleVars.C | 79 +--------- .../incompressible/incompressibleVars.H | 34 +++-- .../incompressible/incompressibleVarsI.H | 110 ++++++++++++++ .../incompressibleAdjointVars.C | 46 +++--- .../incompressibleAdjointVars.H | 16 ++- .../incompressibleAdjointVarsI.H | 45 ++++++ .../incompressibleAdjointMeanFlowVars.C | 40 +----- .../incompressibleAdjointMeanFlowVars.H | 20 +-- .../incompressibleAdjointMeanFlowVarsI.H | 72 ++++++++++ .../adjointSpalartAllmaras.C | 127 ++++++++-------- .../adjointTurbulenceModel.H | 21 ++- 35 files changed, 732 insertions(+), 614 deletions(-) create mode 100644 src/optimisation/adjointOptimisation/adjoint/solvers/variablesSet/incompressible/incompressibleVarsI.H create mode 100644 src/optimisation/adjointOptimisation/adjoint/solvers/variablesSet/incompressibleAdjoint/incompressibleAdjointVarsI.H create mode 100644 src/optimisation/adjointOptimisation/adjoint/solvers/variablesSet/incompressibleAdjointMeanFlow/incompressibleAdjointMeanFlowVarsI.H diff --git a/src/optimisation/adjointOptimisation/adjoint/ATCModel/ATCModel/ATCModel.C b/src/optimisation/adjointOptimisation/adjoint/ATCModel/ATCModel/ATCModel.C index 2be1febb35..057996e18a 100644 --- a/src/optimisation/adjointOptimisation/adjoint/ATCModel/ATCModel/ATCModel.C +++ b/src/optimisation/adjointOptimisation/adjoint/ATCModel/ATCModel/ATCModel.C @@ -5,8 +5,8 @@ \\ / A nd | www.openfoam.com \\/ M anipulation | ------------------------------------------------------------------------------- - Copyright (C) 2007-2019 PCOpt/NTUA - Copyright (C) 2013-2019 FOSS GP + Copyright (C) 2007-2021 PCOpt/NTUA + Copyright (C) 2013-2021 FOSS GP Copyright (C) 2019-2021 OpenCFD Ltd. ------------------------------------------------------------------------------- License @@ -259,6 +259,12 @@ bool ATCModel::writeData(Ostream&) const } +void ATCModel::updatePrimalBasedQuantities() +{ + // Does nothing in base +} + + // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // } // End namespace Foam diff --git a/src/optimisation/adjointOptimisation/adjoint/ATCModel/ATCModel/ATCModel.H b/src/optimisation/adjointOptimisation/adjoint/ATCModel/ATCModel/ATCModel.H index d80c75b12e..7738ef491c 100644 --- a/src/optimisation/adjointOptimisation/adjoint/ATCModel/ATCModel/ATCModel.H +++ b/src/optimisation/adjointOptimisation/adjoint/ATCModel/ATCModel/ATCModel.H @@ -5,8 +5,8 @@ \\ / A nd | www.openfoam.com \\/ M anipulation | ------------------------------------------------------------------------------- - Copyright (C) 2007-2019 PCOpt/NTUA - Copyright (C) 2013-2019 FOSS GP + Copyright (C) 2007-2021 PCOpt/NTUA + Copyright (C) 2013-2021 FOSS GP Copyright (C) 2019 OpenCFD Ltd. ------------------------------------------------------------------------------- License @@ -201,6 +201,9 @@ public: //- Dummy writeData function required from regIOobject virtual bool writeData(Ostream&) const; + + //- Update quantities related with the primal fields + virtual void updatePrimalBasedQuantities(); }; diff --git a/src/optimisation/adjointOptimisation/adjoint/ATCModel/ATCUaGradU/ATCUaGradU.C b/src/optimisation/adjointOptimisation/adjoint/ATCModel/ATCUaGradU/ATCUaGradU.C index 99d73932ff..660a697ee2 100644 --- a/src/optimisation/adjointOptimisation/adjoint/ATCModel/ATCUaGradU/ATCUaGradU.C +++ b/src/optimisation/adjointOptimisation/adjoint/ATCModel/ATCUaGradU/ATCUaGradU.C @@ -5,8 +5,8 @@ \\ / A nd | www.openfoam.com \\/ M anipulation | ------------------------------------------------------------------------------- - Copyright (C) 2007-2019 PCOpt/NTUA - Copyright (C) 2013-2019 FOSS GP + Copyright (C) 2007-2021 PCOpt/NTUA + Copyright (C) 2013-2021 FOSS GP Copyright (C) 2019 OpenCFD Ltd. ------------------------------------------------------------------------------- License @@ -97,7 +97,7 @@ void ATCUaGradU::addATC(fvVectorMatrix& UaEqn) smoothATC(); // Actual ATC term - UaEqn += fvm::Su(ATC_, Ua); + UaEqn += ATC_.internalField(); } diff --git a/src/optimisation/adjointOptimisation/adjoint/ATCModel/ATCstandard/ATCstandard.C b/src/optimisation/adjointOptimisation/adjoint/ATCModel/ATCstandard/ATCstandard.C index 214c3aefbc..9ad646fe88 100644 --- a/src/optimisation/adjointOptimisation/adjoint/ATCModel/ATCstandard/ATCstandard.C +++ b/src/optimisation/adjointOptimisation/adjoint/ATCModel/ATCstandard/ATCstandard.C @@ -5,8 +5,8 @@ \\ / A nd | www.openfoam.com \\/ M anipulation | ------------------------------------------------------------------------------- - Copyright (C) 2007-2019 PCOpt/NTUA - Copyright (C) 2013-2019 FOSS GP + Copyright (C) 2007-2021 PCOpt/NTUA + Copyright (C) 2013-2021 FOSS GP Copyright (C) 2019 OpenCFD Ltd. ------------------------------------------------------------------------------- License @@ -57,7 +57,20 @@ ATCstandard::ATCstandard const dictionary& dict ) : - ATCModel(mesh, primalVars, adjointVars, dict) + ATCModel(mesh, primalVars, adjointVars, dict), + gradU_ + ( + IOobject + ( + "gradUATC", + mesh_.time().timeName(), + mesh_, + IOobject::NO_READ, + IOobject::NO_WRITE + ), + mesh_, + dimensionedTensor(dimless/dimTime, Zero) + ) {} @@ -65,23 +78,14 @@ ATCstandard::ATCstandard void ATCstandard::addATC(fvVectorMatrix& UaEqn) { + addProfiling(ATCstandard, "ATCstandard::addATC"); const volVectorField& U = primalVars_.U(); const volVectorField& Ua = adjointVars_.UaInst(); const surfaceScalarField& phi = primalVars_.phi(); - // Build U to go into the ATC term, based on whether to smooth field or not - autoPtr UForATC(nullptr); - if (reconstructGradients_) - { - UForATC.reset(new volVectorField(fvc::reconstruct(phi))); - } - else - { - UForATC.reset(new volVectorField(U)); - } // Main ATC term - ATC_ = (fvc::grad(UForATC(), "gradUATC") & Ua); + ATC_ = gradU_ & Ua; if (extraConvection_ > 0) { @@ -97,55 +101,62 @@ void ATCstandard::addATC(fvVectorMatrix& UaEqn) smoothATC(); // actual ATC term - UaEqn += fvm::Su(ATC_, Ua); + UaEqn += ATC_.internalField(); } tmp ATCstandard::getFISensitivityTerm() const { - tmp tvolSDTerm - ( - new volTensorField - ( - IOobject - ( - "ATCFISensitivityTerm" + type(), - mesh_.time().timeName(), - mesh_, - IOobject::NO_READ, - IOobject::NO_WRITE - ), - mesh_, - dimensionedTensor(sqr(dimLength)/pow(dimTime, 3), Zero) - ) - ); - - volTensorField& volSDTerm = tvolSDTerm.ref(); - const volVectorField& U = primalVars_.U(); const volVectorField& Ua = adjointVars_.Ua(); - volTensorField gradU(fvc::grad(U)); + // We only need to modify the boundaryField of gradU locally. + // If grad(U) is cached then + // a. The .ref() call fails since the tmp is initialised from a + // const ref + // b. we would be changing grad(U) for all other places in the code + // that need it + // So, always allocate new memory and avoid registering the new field + tmp tgradU(volTensorField::New("gradULocal", fvc::grad(U))); + volTensorField::Boundary& gradUbf = tgradU.ref().boundaryFieldRef(); - // Explicitly correct the boundary gradient to get rid of the - // tangential component + // Explicitly correct the boundary gradient to get rid of + // the tangential component forAll(mesh_.boundary(), patchI) { const fvPatch& patch = mesh_.boundary()[patchI]; if (isA(patch)) { tmp tnf = mesh_.boundary()[patchI].nf(); - const vectorField& nf = tnf(); - gradU.boundaryFieldRef()[patchI] = - nf*U.boundaryField()[patchI].snGrad(); + gradUbf[patchI] = tnf*U.boundaryField()[patchI].snGrad(); } } const volScalarField& mask = getLimiter(); - volSDTerm = -(gradU & Ua)*U*mask; + return + tmp::New + ( + "ATCFISensitivityTerm" + type(), + - (tgradU & Ua)*U*mask + ); +} - return tvolSDTerm; + +void ATCstandard::updatePrimalBasedQuantities() +{ + const volVectorField& U = primalVars_.U(); + const surfaceScalarField& phi = primalVars_.phi(); + // Build U to go into the ATC term, based on whether to smooth field or not + autoPtr UForATC(nullptr); + if (reconstructGradients_) + { + gradU_ = fvc::grad(fvc::reconstruct(phi), "gradUATC"); + } + else + { + gradU_ = fvc::grad(U, "gradUATC"); + } } diff --git a/src/optimisation/adjointOptimisation/adjoint/ATCModel/ATCstandard/ATCstandard.H b/src/optimisation/adjointOptimisation/adjoint/ATCModel/ATCstandard/ATCstandard.H index 4c65a9c280..0d7f4eb99f 100644 --- a/src/optimisation/adjointOptimisation/adjoint/ATCModel/ATCstandard/ATCstandard.H +++ b/src/optimisation/adjointOptimisation/adjoint/ATCModel/ATCstandard/ATCstandard.H @@ -5,8 +5,8 @@ \\ / A nd | www.openfoam.com \\/ M anipulation | ------------------------------------------------------------------------------- - Copyright (C) 2007-2019 PCOpt/NTUA - Copyright (C) 2013-2019 FOSS GP + Copyright (C) 2007-2021 PCOpt/NTUA + Copyright (C) 2013-2021 FOSS GP Copyright (C) 2019 OpenCFD Ltd. ------------------------------------------------------------------------------- License @@ -49,7 +49,7 @@ namespace Foam { /*---------------------------------------------------------------------------*\ - Class ATCstandard Declaration + Class ATCstandard Declaration \*---------------------------------------------------------------------------*/ class ATCstandard @@ -58,6 +58,12 @@ class ATCstandard { private: + // Private data + + //- The gradU used in the computation of the standard ATC + // Cached to avoid costly recomputation in each adjoint iteration + volTensorField gradU_; + // Private Member Functions //- No copy construct @@ -96,6 +102,9 @@ public: //- Get the FI sensitivity derivatives term coming from the ATC virtual tmp getFISensitivityTerm() const; + + //- Update quantities related with the primal fields + virtual void updatePrimalBasedQuantities(); }; diff --git a/src/optimisation/adjointOptimisation/adjoint/adjointBoundaryConditions/adjointBoundaryCondition/adjointBoundaryCondition.C b/src/optimisation/adjointOptimisation/adjoint/adjointBoundaryConditions/adjointBoundaryCondition/adjointBoundaryCondition.C index 1d87524b23..0e49b2815e 100644 --- a/src/optimisation/adjointOptimisation/adjoint/adjointBoundaryConditions/adjointBoundaryCondition/adjointBoundaryCondition.C +++ b/src/optimisation/adjointOptimisation/adjoint/adjointBoundaryConditions/adjointBoundaryCondition/adjointBoundaryCondition.C @@ -5,8 +5,8 @@ \\ / A nd | www.openfoam.com \\/ M anipulation | ------------------------------------------------------------------------------- - Copyright (C) 2007-2020 PCOpt/NTUA - Copyright (C) 2013-2020 FOSS GP + Copyright (C) 2007-2021 PCOpt/NTUA + Copyright (C) 2013-2021 FOSS GP Copyright (C) 2019-2020 OpenCFD Ltd. ------------------------------------------------------------------------------- License @@ -73,19 +73,48 @@ adjointBoundaryCondition::computePatchGrad(word name) word schemeData(is); */ - tmp> tinterpScheme - ( - surfaceInterpolationScheme::New - ( - mesh, - mesh.interpolationScheme("interpolate(" + name + ")") - ) - ); + // If there are many patches calling this function, the computation of + // the surface field might be a significant computational + // burden. Cache the interpolated field and fetch from the registry when + // possible. + const word surfFieldName("interpolated" + name + "ForBoundaryGrad"); + typedef GeometricField surfFieldType; + surfFieldType* surfFieldPtr = + mesh.objectRegistry::template getObjectPtr(surfFieldName); - GeometricField surfField - ( - tinterpScheme().interpolate(field) - ); + if (!surfFieldPtr) + { + solution::cachePrintMessage("Calculating and caching", name, field); + + surfFieldPtr = + surfaceInterpolationScheme::New + ( + mesh, mesh.interpolationScheme("interpolate(" + name + ")") + )().interpolate(field).ptr(); + surfFieldPtr->rename(surfFieldName); + regIOobject::store(surfFieldPtr); + } + else + { + if (surfFieldPtr->upToDate(field)) + { + solution::cachePrintMessage("Reusing", name, field); + } + else + { + solution::cachePrintMessage("Updating", name, field); + delete surfFieldPtr; + + surfFieldPtr = + surfaceInterpolationScheme::New + ( + mesh, mesh.interpolationScheme("interpolate(" + name + ")") + )().interpolate(field).ptr(); + surfFieldPtr->rename(surfFieldName); + regIOobject::store(surfFieldPtr); + } + } + surfFieldType& surfField = *surfFieldPtr; // Auxiliary fields const surfaceVectorField& Sf = mesh.Sf(); @@ -271,6 +300,13 @@ const ATCModel& adjointBoundaryCondition::getATC() const } +template +void adjointBoundaryCondition::updatePrimalBasedQuantities() +{ + // Does nothing in base +} + + template tmp < diff --git a/src/optimisation/adjointOptimisation/adjoint/adjointBoundaryConditions/adjointBoundaryCondition/adjointBoundaryCondition.H b/src/optimisation/adjointOptimisation/adjoint/adjointBoundaryConditions/adjointBoundaryCondition/adjointBoundaryCondition.H index 4ec46c64c9..dd2f92c98d 100644 --- a/src/optimisation/adjointOptimisation/adjoint/adjointBoundaryConditions/adjointBoundaryCondition/adjointBoundaryCondition.H +++ b/src/optimisation/adjointOptimisation/adjoint/adjointBoundaryConditions/adjointBoundaryCondition/adjointBoundaryCondition.H @@ -5,8 +5,8 @@ \\ / A nd | www.openfoam.com \\/ M anipulation | ------------------------------------------------------------------------------- - Copyright (C) 2007-2020 PCOpt/NTUA - Copyright (C) 2013-2020 FOSS GP + Copyright (C) 2007-2021 PCOpt/NTUA + Copyright (C) 2013-2021 FOSS GP Copyright (C) 2019 OpenCFD Ltd. ------------------------------------------------------------------------------- License @@ -152,6 +152,10 @@ public: < Field::type> > dxdbMult() const; + + //- Update the primal based quantities related to the adjoint boundary + //- conditions + virtual void updatePrimalBasedQuantities(); }; diff --git a/src/optimisation/adjointOptimisation/adjoint/adjointBoundaryConditions/adjointOutletVelocityFlux/adjointOutletVelocityFluxFvPatchVectorField.C b/src/optimisation/adjointOptimisation/adjoint/adjointBoundaryConditions/adjointOutletVelocityFlux/adjointOutletVelocityFluxFvPatchVectorField.C index 8abaf44d00..8b70903941 100644 --- a/src/optimisation/adjointOptimisation/adjoint/adjointBoundaryConditions/adjointOutletVelocityFlux/adjointOutletVelocityFluxFvPatchVectorField.C +++ b/src/optimisation/adjointOptimisation/adjoint/adjointBoundaryConditions/adjointOutletVelocityFlux/adjointOutletVelocityFluxFvPatchVectorField.C @@ -5,8 +5,8 @@ \\ / A nd | www.openfoam.com \\/ M anipulation | ------------------------------------------------------------------------------- - Copyright (C) 2007-2020 PCOpt/NTUA - Copyright (C) 2013-2020 FOSS GP + Copyright (C) 2007-2021 PCOpt/NTUA + Copyright (C) 2013-2021 FOSS GP Copyright (C) 2019 OpenCFD Ltd. ------------------------------------------------------------------------------- License @@ -97,6 +97,11 @@ void Foam::adjointOutletVelocityFluxFvPatchVectorField::manipulateMatrix fvMatrix& matrix ) { + addProfiling + ( + adjointOutletVelocityFluxFvPatchVectorField, + "adjointOutletVelocityFluxFvPatchVectorField::manipulateMatrix" + ); vectorField& source = matrix.source(); const vectorField& Sf = patch().Sf(); const labelList& faceCells = patch().faceCells(); diff --git a/src/optimisation/adjointOptimisation/adjoint/adjointBoundaryConditions/adjointOutletVelocityFlux/adjointOutletVelocityFluxFvPatchVectorField.H b/src/optimisation/adjointOptimisation/adjoint/adjointBoundaryConditions/adjointOutletVelocityFlux/adjointOutletVelocityFluxFvPatchVectorField.H index 3201b245ab..5dd565f9d7 100644 --- a/src/optimisation/adjointOptimisation/adjoint/adjointBoundaryConditions/adjointOutletVelocityFlux/adjointOutletVelocityFluxFvPatchVectorField.H +++ b/src/optimisation/adjointOptimisation/adjoint/adjointBoundaryConditions/adjointOutletVelocityFlux/adjointOutletVelocityFluxFvPatchVectorField.H @@ -5,8 +5,8 @@ \\ / A nd | www.openfoam.com \\/ M anipulation | ------------------------------------------------------------------------------- - Copyright (C) 2007-2020 PCOpt/NTUA - Copyright (C) 2013-2020 FOSS GP + Copyright (C) 2007-2021 PCOpt/NTUA + Copyright (C) 2013-2021 FOSS GP Copyright (C) 2019 OpenCFD Ltd. ------------------------------------------------------------------------------- License @@ -63,10 +63,6 @@ class adjointOutletVelocityFluxFvPatchVectorField public fixedValueFvPatchVectorField, public adjointVectorBoundaryCondition { - // Private Member Functions - - tmp computeLocalGrad(); - public: diff --git a/src/optimisation/adjointOptimisation/adjoint/adjointBoundaryConditions/adjointWallVelocity/adjointWallVelocityFvPatchVectorField.C b/src/optimisation/adjointOptimisation/adjoint/adjointBoundaryConditions/adjointWallVelocity/adjointWallVelocityFvPatchVectorField.C index 32372f99af..c26a7b863a 100644 --- a/src/optimisation/adjointOptimisation/adjoint/adjointBoundaryConditions/adjointWallVelocity/adjointWallVelocityFvPatchVectorField.C +++ b/src/optimisation/adjointOptimisation/adjoint/adjointBoundaryConditions/adjointWallVelocity/adjointWallVelocityFvPatchVectorField.C @@ -5,8 +5,8 @@ \\ / A nd | www.openfoam.com \\/ M anipulation | ------------------------------------------------------------------------------- - Copyright (C) 2007-2020 PCOpt/NTUA - Copyright (C) 2013-2020 FOSS GP + Copyright (C) 2007-2021 PCOpt/NTUA + Copyright (C) 2013-2021 FOSS GP Copyright (C) 2019-2020 OpenCFD Ltd. ------------------------------------------------------------------------------- License @@ -105,6 +105,11 @@ void Foam::adjointWallVelocityFvPatchVectorField::manipulateMatrix fvMatrix& matrix ) { + addProfiling + ( + adjointWallVelocityFvPatchVectorField, + "adjointWallVelocityFvPatchVectorField::manipulateMatrix" + ); // Grab ref to the diagonal matrix vectorField& source = matrix.source(); diff --git a/src/optimisation/adjointOptimisation/adjoint/boundaryAdjointContributions/boundaryAdjointContributionIncompressible/boundaryAdjointContributionIncompressible.C b/src/optimisation/adjointOptimisation/adjoint/boundaryAdjointContributions/boundaryAdjointContributionIncompressible/boundaryAdjointContributionIncompressible.C index 3b01bb971e..3d1d19f474 100644 --- a/src/optimisation/adjointOptimisation/adjoint/boundaryAdjointContributions/boundaryAdjointContributionIncompressible/boundaryAdjointContributionIncompressible.C +++ b/src/optimisation/adjointOptimisation/adjoint/boundaryAdjointContributions/boundaryAdjointContributionIncompressible/boundaryAdjointContributionIncompressible.C @@ -5,8 +5,8 @@ \\ / A nd | www.openfoam.com \\/ M anipulation | ------------------------------------------------------------------------------- - Copyright (C) 2007-2019 PCOpt/NTUA - Copyright (C) 2013-2019 FOSS GP + Copyright (C) 2007-2021 PCOpt/NTUA + Copyright (C) 2013-2021 FOSS GP Copyright (C) 2019 OpenCFD Ltd. ------------------------------------------------------------------------------- License @@ -89,11 +89,10 @@ boundaryAdjointContributionIncompressible tmp boundaryAdjointContributionIncompressible::velocitySource() { // Objective function contribution - PtrList& objectives = objectiveManager_.getObjectiveFunctions(); tmp tsource = sumContributions ( - objectives, + objectiveManager_.getObjectiveFunctions(), &objectiveIncompressible::boundarydJdv ); vectorField& source = tsource.ref(); @@ -110,11 +109,10 @@ tmp boundaryAdjointContributionIncompressible::velocitySource() tmp boundaryAdjointContributionIncompressible::pressureSource() { // Objective function contribution - PtrList& objectives = objectiveManager_.getObjectiveFunctions(); tmp tsource = sumContributions ( - objectives, + objectiveManager_.getObjectiveFunctions(), &objectiveIncompressible::boundarydJdvn ); @@ -126,10 +124,7 @@ tmp boundaryAdjointContributionIncompressible::pressureSource() const vectorField& adjointTurbulenceContr = adjointRAS().adjointMomentumBCSource()[patch_.index()]; - tmp tnf = patch_.nf(); - const vectorField& nf = tnf(); - - source += adjointTurbulenceContr & nf; + source += adjointTurbulenceContr & patch_.nf(); return (tsource); } @@ -139,11 +134,10 @@ tmp boundaryAdjointContributionIncompressible::tangentVelocitySource() { // Objective function contribution - PtrList& objectives = objectiveManager_.getObjectiveFunctions(); tmp tsource = sumContributions ( - objectives, + objectiveManager_.getObjectiveFunctions(), &objectiveIncompressible::boundarydJdvt ); @@ -167,59 +161,51 @@ boundaryAdjointContributionIncompressible::tangentVelocitySource() tmp boundaryAdjointContributionIncompressible::normalVelocitySource() { - PtrList& objectives = objectiveManager_.getObjectiveFunctions(); - tmp tsource = + return sumContributions ( - objectives, + objectiveManager_.getObjectiveFunctions(), &objectiveIncompressible::boundarydJdp ); - return (tsource); } tmp boundaryAdjointContributionIncompressible::energySource() { - PtrList& objectives = objectiveManager_.getObjectiveFunctions(); - tmp tsource = + return sumContributions ( - objectives, + objectiveManager_.getObjectiveFunctions(), &objectiveIncompressible::boundarydJdT ); - return (tsource); } tmp boundaryAdjointContributionIncompressible::adjointTMVariable1Source() { - PtrList& objectives = objectiveManager_.getObjectiveFunctions(); - tmp tsource = + return sumContributions ( - objectives, + objectiveManager_.getObjectiveFunctions(), &objectiveIncompressible::boundarydJdTMvar1 ); - return (tsource); } tmp boundaryAdjointContributionIncompressible::adjointTMVariable2Source() { - PtrList& objectives = objectiveManager_.getObjectiveFunctions(); - tmp tsource = + return sumContributions ( - objectives, + objectiveManager_.getObjectiveFunctions(), &objectiveIncompressible::boundarydJdTMvar2 ); - return (tsource); } @@ -249,15 +235,8 @@ boundaryAdjointContributionIncompressible::dJdGradU() tmp boundaryAdjointContributionIncompressible::momentumDiffusion() { - tmp tnuEff(new scalarField(patch_.size(), Zero)); - scalarField& nuEff = tnuEff.ref(); - const autoPtr& - adjointTurbulenceModel = adjointVars().adjointTurbulence(); - - nuEff = adjointTurbulenceModel().nuEff()().boundaryField()[patch_.index()]; - - return tnuEff; + return adjointVars().adjointTurbulence()().nuEff(patch_.index()); } @@ -296,64 +275,40 @@ tmp boundaryAdjointContributionIncompressible::thermalDiffusion() tmp boundaryAdjointContributionIncompressible::wallDistance() { - tmp twallDist(new scalarField(patch_.size(), Zero)); - scalarField& wallDist = twallDist.ref(); - - wallDist = primalVars_.turbulence()->y()[patch_.index()]; - - return twallDist; + return primalVars_.turbulence()->y()[patch_.index()]; } tmp boundaryAdjointContributionIncompressible::TMVariable1Diffusion() { - const autoPtr& adjointRAS = - adjointVars().adjointTurbulence(); + return + adjointVars().adjointTurbulence()->diffusionCoeffVar1(patch_.index()); - tmp tdiffCoeff = - adjointRAS().diffusionCoeffVar1(patch_.index()); - - return tdiffCoeff; } tmp boundaryAdjointContributionIncompressible::TMVariable2Diffusion() { - const autoPtr& adjointRAS = - adjointVars().adjointTurbulence(); - - tmp tdiffCoeff = - adjointRAS().diffusionCoeffVar2(patch_.index()); - - return tdiffCoeff; + return + adjointVars().adjointTurbulence()->diffusionCoeffVar2(patch_.index()); } tmp boundaryAdjointContributionIncompressible::TMVariable1() { - const autoPtr& RASVariables = - primalVars_.RASModelVariables(); - tmp tboundField(new scalarField(patch_.size(), Zero)); - scalarField& boundField = tboundField.ref(); - - boundField = RASVariables().TMVar1().boundaryField()[patch_.index()]; - - return tboundField; + return + primalVars_.RASModelVariables()->TMVar1(). + boundaryField()[patch_.index()]; } tmp boundaryAdjointContributionIncompressible::TMVariable2() { - const autoPtr& RASVariables = - primalVars_.RASModelVariables(); - tmp tboundField(new scalarField(patch_.size(), Zero)); - scalarField& boundField = tboundField.ref(); - - boundField = RASVariables().TMVar2().boundaryField()[patch_.index()]; - - return tboundField; + return + primalVars_.RASModelVariables()->TMVar2(). + boundaryField()[patch_.index()]; } diff --git a/src/optimisation/adjointOptimisation/adjoint/objectives/incompressible/objectiveForce/objectiveForce.C b/src/optimisation/adjointOptimisation/adjoint/objectives/incompressible/objectiveForce/objectiveForce.C index 18e694f1d8..74cdec6b1f 100644 --- a/src/optimisation/adjointOptimisation/adjoint/objectives/incompressible/objectiveForce/objectiveForce.C +++ b/src/optimisation/adjointOptimisation/adjoint/objectives/incompressible/objectiveForce/objectiveForce.C @@ -5,8 +5,8 @@ \\ / A nd | www.openfoam.com \\/ M anipulation | ------------------------------------------------------------------------------- - Copyright (C) 2007-2019 PCOpt/NTUA - Copyright (C) 2013-2019 FOSS GP + Copyright (C) 2007-2019, 2022 PCOpt/NTUA + Copyright (C) 2013-2019, 2022 FOSS GP Copyright (C) 2019-2020 OpenCFD Ltd. ------------------------------------------------------------------------------- License @@ -70,28 +70,7 @@ objectiveForce::objectiveForce forceDirection_(dict.get("direction")), Aref_(dict.get("Aref")), rhoInf_(dict.get("rhoInf")), - UInf_(dict.get("UInf")), - stressXPtr_ - ( - Foam::createZeroFieldPtr - ( - mesh_, "stressX", dimLength/sqr(dimTime) - ) - ), - stressYPtr_ - ( - Foam::createZeroFieldPtr - ( - mesh_, "stressY", dimLength/sqr(dimTime) - ) - ), - stressZPtr_ - ( - Foam::createZeroFieldPtr - ( - mesh_, "stressZ", dimLength/sqr(dimTime) - ) - ) + UInf_(dict.get("UInf")) { // Sanity check and print info if (forcePatches_.empty()) @@ -135,16 +114,9 @@ scalar objectiveForce::J() for (const label patchI : forcePatches_) { - pressureForce += gSum - ( - mesh_.Sf().boundaryField()[patchI] * p.boundaryField()[patchI] - ); - // Viscous term calculated using the full tensor derivative - viscousForce += gSum - ( - devReff.boundaryField()[patchI] - & mesh_.Sf().boundaryField()[patchI] - ); + const vectorField& Sf = mesh_.Sf().boundaryField()[patchI]; + pressureForce += gSum(Sf*p.boundaryField()[patchI]); + viscousForce += gSum(devReff.boundaryField()[patchI] & Sf); } cumulativeForce = pressureForce + viscousForce; @@ -178,8 +150,8 @@ void objectiveForce::update_dSdbMultiplier() // Compute contributions with mean fields, if present const volScalarField& p = vars_.p(); const volVectorField& U = vars_.U(); - const autoPtr& - turbVars = vars_.RASModelVariables(); + const autoPtr& turbVars = + vars_.RASModelVariables(); const singlePhaseTransportModel& lamTransp = vars_.laminarTransport(); tmp tdevReff = turbVars->devReff(lamTransp, U); @@ -208,11 +180,16 @@ void objectiveForce::update_dxdbMultiplier() turbVars = vars_.RASModelVariables(); const singlePhaseTransportModel& lamTransp = vars_.laminarTransport(); - //tmp tdevReff = turbVars->devReff(lamTransp, U); - //const volSymmTensorField& devReff = tdevReff(); - - volScalarField nuEff(lamTransp.nu() + turbVars->nutRef()); - volTensorField gradU(fvc::grad(U)); + // We only need to modify the boundaryField of gradU locally. + // If grad(U) is cached then + // a. The .ref() call fails since the tmp is initialised from a + // const ref + // b. we would be changing grad(U) for all other places in the code + // that need it + // So, always allocate new memory and avoid registering the new field + tmp tgradU = + volTensorField::New("gradULocal", fvc::grad(U)); + volTensorField& gradU = tgradU.ref(); volTensorField::Boundary& gradUbf = gradU.boundaryFieldRef(); // Explicitly correct the boundary gradient to get rid of @@ -222,49 +199,42 @@ void objectiveForce::update_dxdbMultiplier() const fvPatch& patch = mesh_.boundary()[patchI]; if (isA(patch)) { - tmp nf = patch.nf(); - gradUbf[patchI] = nf*U.boundaryField()[patchI].snGrad(); + tmp tnf = patch.nf(); + gradUbf[patchI] = tnf*U.boundaryField()[patchI].snGrad(); } } - volTensorField stress(nuEff*(gradU + T(gradU))); - - stressXPtr_().replace(0, stress.component(0)); - stressXPtr_().replace(1, stress.component(1)); - stressXPtr_().replace(2, stress.component(2)); - - stressYPtr_().replace(0, stress.component(3)); - stressYPtr_().replace(1, stress.component(4)); - stressYPtr_().replace(2, stress.component(5)); - - stressZPtr_().replace(0, stress.component(6)); - stressZPtr_().replace(1, stress.component(7)); - stressZPtr_().replace(2, stress.component(8)); - - volTensorField gradStressX(fvc::grad(stressXPtr_())); - volTensorField gradStressY(fvc::grad(stressYPtr_())); - volTensorField gradStressZ(fvc::grad(stressZPtr_())); - - // the notorious second-order derivative at the wall. Use with caution! - volVectorField gradp(fvc::grad(p)); - + // Term coming from gradp + tmp tgradp(fvc::grad(p)); + const volVectorField& gradp = tgradp.cref(); for (const label patchI : forcePatches_) { - const fvPatch& patch = mesh_.boundary()[patchI]; - tmp tnf = patch.nf(); - const vectorField& nf = tnf(); bdxdbMultPtr_()[patchI] = - ( - ( - ( - -(forceDirection_.x() * gradStressX.boundaryField()[patchI]) - -(forceDirection_.y() * gradStressY.boundaryField()[patchI]) - -(forceDirection_.z() * gradStressZ.boundaryField()[patchI]) - ) & nf - ) - + (forceDirection_ & nf)*gradp.boundaryField()[patchI] - ) - /denom(); + (forceDirection_ & mesh_.boundary()[patchI].nf()) + *gradp.boundaryField()[patchI]/denom(); + } + tgradp.clear(); + + // Term coming from stresses + tmp tnuEff = lamTransp.nu() + turbVars->nutRef(); + tmp tstress = tnuEff*twoSymm(tgradU); + const volSymmTensorField& stress = tstress.cref(); + autoPtr ptemp + (Foam::createZeroFieldPtr( mesh_, "temp", sqr(dimVelocity))); + volVectorField& temp = ptemp.ref(); + + for (label idir = 0; idir < pTraits::nComponents; ++idir) + { + unzipRow(stress, idir, temp); + volTensorField gradStressDir(fvc::grad(temp)); + for (const label patchI : forcePatches_) + { + const fvPatch& patch = mesh_.boundary()[patchI]; + tmp tnf = patch.nf(); + bdxdbMultPtr_()[patchI] -= + forceDirection_.component(idir) + *(gradStressDir.boundaryField()[patchI] & tnf)/denom(); + } } } @@ -278,17 +248,17 @@ void objectiveForce::update_boundarydJdnut() { const fvPatch& patch = mesh_.boundary()[patchI]; tmp tnf = patch.nf(); - const vectorField& nf = tnf(); bdJdnutPtr_()[patchI] = - -((devGradU.boundaryField()[patchI] & forceDirection_) & nf)/denom(); + - ((devGradU.boundaryField()[patchI] & forceDirection_) & tnf) + /denom(); } } void objectiveForce::update_boundarydJdGradU() { - const autoPtr& - turbVars = vars_.RASModelVariables(); + const autoPtr& turbVars = + vars_.RASModelVariables(); const singlePhaseTransportModel& lamTransp = vars_.laminarTransport(); volScalarField nuEff(lamTransp.nu() + turbVars->nutRef()); for (const label patchI : forcePatches_) diff --git a/src/optimisation/adjointOptimisation/adjoint/objectives/incompressible/objectiveForce/objectiveForce.H b/src/optimisation/adjointOptimisation/adjoint/objectives/incompressible/objectiveForce/objectiveForce.H index 01bf362ae2..4092f9b92f 100644 --- a/src/optimisation/adjointOptimisation/adjoint/objectives/incompressible/objectiveForce/objectiveForce.H +++ b/src/optimisation/adjointOptimisation/adjoint/objectives/incompressible/objectiveForce/objectiveForce.H @@ -5,8 +5,8 @@ \\ / A nd | www.openfoam.com \\/ M anipulation | ------------------------------------------------------------------------------- - Copyright (C) 2007-2020 PCOpt/NTUA - Copyright (C) 2013-2020 FOSS GP + Copyright (C) 2007-2020, 2022 PCOpt/NTUA + Copyright (C) 2013-2020, 2022 FOSS GP Copyright (C) 2019 OpenCFD Ltd. ------------------------------------------------------------------------------- License @@ -70,10 +70,6 @@ protected: scalar rhoInf_; scalar UInf_; - autoPtr stressXPtr_; - autoPtr stressYPtr_; - autoPtr stressZPtr_; - public: diff --git a/src/optimisation/adjointOptimisation/adjoint/objectives/incompressible/objectiveMoment/objectiveMoment.C b/src/optimisation/adjointOptimisation/adjoint/objectives/incompressible/objectiveMoment/objectiveMoment.C index b6c3378193..f89e72203c 100644 --- a/src/optimisation/adjointOptimisation/adjoint/objectives/incompressible/objectiveMoment/objectiveMoment.C +++ b/src/optimisation/adjointOptimisation/adjoint/objectives/incompressible/objectiveMoment/objectiveMoment.C @@ -5,8 +5,8 @@ \\ / A nd | www.openfoam.com \\/ M anipulation | ------------------------------------------------------------------------------- - Copyright (C) 2007-2019 PCOpt/NTUA - Copyright (C) 2013-2019 FOSS GP + Copyright (C) 2007-2019, 2022 PCOpt/NTUA + Copyright (C) 2013-2019, 2022 FOSS GP Copyright (C) 2019-2020 OpenCFD Ltd. ------------------------------------------------------------------------------- License @@ -76,27 +76,6 @@ objectiveMoment::objectiveMoment rhoInf_(dict.get("rhoInf")), UInf_(dict.get("UInf")), invDenom_(2./(rhoInf_*UInf_*UInf_*Aref_*lRef_)), - stressXPtr_ - ( - Foam::createZeroFieldPtr - ( - mesh_, "stressX", dimLength/sqr(dimTime) - ) - ), - stressYPtr_ - ( - Foam::createZeroFieldPtr - ( - mesh_, "stressY", dimLength/sqr(dimTime) - ) - ), - stressZPtr_ - ( - Foam::createZeroFieldPtr - ( - mesh_, "stressZ", dimLength/sqr(dimTime) - ) - ), devReff_(vars_.turbulence()->devReff()()) { // Sanity check and print info @@ -170,8 +149,8 @@ void objectiveMoment::update_meanValues() if (computeMeanFields_) { const volVectorField& U = vars_.U(); - const autoPtr& - turbVars = vars_.RASModelVariables(); + const autoPtr& turbVars = + vars_.RASModelVariables(); const singlePhaseTransportModel& lamTransp = vars_.laminarTransport(); devReff_ = turbVars->devReff(lamTransp, U)(); @@ -184,8 +163,8 @@ void objectiveMoment::update_boundarydJdp() for (const label patchI : momentPatches_) { const fvPatch& patch = mesh_.boundary()[patchI]; - vectorField dx(patch.Cf() - rotationCentre_); - bdJdpPtr_()[patchI] = (momentDirection_ ^ dx)*invDenom_*rhoInf_; + tmp tdx = patch.Cf() - rotationCentre_; + bdJdpPtr_()[patchI] = (momentDirection_ ^ tdx)*invDenom_*rhoInf_; } } @@ -197,19 +176,19 @@ void objectiveMoment::update_dSdbMultiplier() for (const label patchI : momentPatches_) { const fvPatch& patch = mesh_.boundary()[patchI]; - const vectorField dx(patch.Cf() - rotationCentre_); + tmp tdx = patch.Cf() - rotationCentre_; bdSdbMultPtr_()[patchI] = ( ( rhoInf_* ( - (momentDirection_^dx) & + (momentDirection_ ^ tdx()) & ( devReff_.boundaryField()[patchI] ) ) ) - + rhoInf_ * (momentDirection_^dx) * p.boundaryField()[patchI] + + rhoInf_*(momentDirection_ ^ tdx())*p.boundaryField()[patchI] ) *invDenom_; } @@ -221,11 +200,20 @@ void objectiveMoment::update_dxdbMultiplier() const volScalarField& p = vars_.p(); const volVectorField& U = vars_.U(); - const autoPtr& - turbVars = vars_.RASModelVariables(); + const autoPtr& turbVars = + vars_.RASModelVariables(); const singlePhaseTransportModel& lamTransp = vars_.laminarTransport(); - volScalarField nuEff(lamTransp.nu() + turbVars->nutRef()); - volTensorField gradU(fvc::grad(U)); + + // We only need to modify the boundaryField of gradU locally. + // If grad(U) is cached then + // a. The .ref() call fails since the tmp is initialised from a + // const ref + // b. we would be changing grad(U) for all other places in the code + // that need it + // So, always allocate new memory and avoid registering the new field + tmp tgradU = + volTensorField::New("gradULocal", fvc::grad(U)); + volTensorField::Boundary& gradUbf = tgradU.ref().boundaryFieldRef(); // Explicitly correct the boundary gradient to get rid of the // tangential component @@ -235,51 +223,46 @@ void objectiveMoment::update_dxdbMultiplier() if (isA(patch)) { tmp tnf = mesh_.boundary()[patchI].nf(); - const vectorField& nf = tnf(); - gradU.boundaryFieldRef()[patchI] = - nf * U.boundaryField()[patchI].snGrad(); + gradUbf[patchI] = tnf*U.boundaryField()[patchI].snGrad(); } } - volTensorField stress(nuEff*(gradU + T(gradU))); - - stressXPtr_().replace(0, stress.component(0)); - stressXPtr_().replace(1, stress.component(1)); - stressXPtr_().replace(2, stress.component(2)); - - stressYPtr_().replace(0, stress.component(3)); - stressYPtr_().replace(1, stress.component(4)); - stressYPtr_().replace(2, stress.component(5)); - - stressZPtr_().replace(0, stress.component(6)); - stressZPtr_().replace(1, stress.component(7)); - stressZPtr_().replace(2, stress.component(8)); - - volTensorField gradStressX(fvc::grad(stressXPtr_())); - volTensorField gradStressY(fvc::grad(stressYPtr_())); - volTensorField gradStressZ(fvc::grad(stressZPtr_())); - - volVectorField gradp(fvc::grad(p)); - + // Term coming from gradp + tmp tgradp = fvc::grad(p); + const volVectorField& gradp = tgradp.cref(); for (const label patchI : momentPatches_) { const fvPatch& patch = mesh_.boundary()[patchI]; tmp tnf = patch.nf(); - const vectorField& nf = tnf(); - vectorField dx(patch.Cf() - rotationCentre_); - vectorField aux(momentDirection_^dx); + tmp tdx = patch.Cf() - rotationCentre_; bdxdbMultPtr_()[patchI] = - ( - ( - ( - -(aux.component(0) * gradStressX.boundaryField()[patchI]) - -(aux.component(1) * gradStressY.boundaryField()[patchI]) - -(aux.component(2) * gradStressZ.boundaryField()[patchI]) - ) & nf - ) - + (momentDirection_ & (dx^nf))*gradp.boundaryField()[patchI] - ) - *invDenom_*rhoInf_; + (momentDirection_ & (tdx ^ tnf))*gradp.boundaryField()[patchI] + *invDenom_*rhoInf_; + } + tgradp.clear(); + + // Term coming from stresses + tmp tnuEff = lamTransp.nu() + turbVars->nutRef(); + tmp tstress = tnuEff*twoSymm(tgradU); + const volSymmTensorField& stress = tstress.cref(); + autoPtr ptemp + (Foam::createZeroFieldPtr( mesh_, "temp", sqr(dimVelocity))); + volVectorField& temp = ptemp.ref(); + + for (label idir = 0; idir < pTraits::nComponents; ++idir) + { + unzipRow(stress, idir, temp); + volTensorField gradStressDir(fvc::grad(temp)); + for (const label patchI : momentPatches_) + { + const fvPatch& patch = mesh_.boundary()[patchI]; + tmp tnf = patch.nf(); + tmp tdx = patch.Cf() - rotationCentre_; + tmp taux = (momentDirection_ ^ tdx)().component(idir); + bdxdbMultPtr_()[patchI] -= + taux*(gradStressDir.boundaryField()[patchI] & tnf) + *invDenom_*rhoInf_; + } } } @@ -316,13 +299,12 @@ void objectiveMoment::update_boundarydJdnut() for (const label patchI : momentPatches_) { const fvPatch& patch = mesh_.boundary()[patchI]; - tmp nf(patch.nf()); - const vectorField dx(patch.Cf() - rotationCentre_); + tmp tnf = patch.nf(); + tmp tdx = patch.Cf() - rotationCentre_; + const fvPatchSymmTensorField& bdevGradU = + devGradU.boundaryField()[patchI]; bdJdnutPtr_()[patchI] = - -rhoInf_ - *( - (dx^(devGradU.boundaryField()[patchI] & nf)) & momentDirection_ - )*invDenom_; + - rhoInf_*((tdx ^ (bdevGradU & tnf)) & momentDirection_)*invDenom_; } } diff --git a/src/optimisation/adjointOptimisation/adjoint/objectives/incompressible/objectiveMoment/objectiveMoment.H b/src/optimisation/adjointOptimisation/adjoint/objectives/incompressible/objectiveMoment/objectiveMoment.H index c5a54afb9b..49f0dcff6e 100644 --- a/src/optimisation/adjointOptimisation/adjoint/objectives/incompressible/objectiveMoment/objectiveMoment.H +++ b/src/optimisation/adjointOptimisation/adjoint/objectives/incompressible/objectiveMoment/objectiveMoment.H @@ -5,8 +5,8 @@ \\ / A nd | www.openfoam.com \\/ M anipulation | ------------------------------------------------------------------------------- - Copyright (C) 2007-2019 PCOpt/NTUA - Copyright (C) 2013-2019 FOSS GP + Copyright (C) 2007-2019, 2022 PCOpt/NTUA + Copyright (C) 2013-2019, 2022 FOSS GP Copyright (C) 2019 OpenCFD Ltd. ------------------------------------------------------------------------------- License @@ -68,10 +68,6 @@ class objectiveMoment scalar UInf_; scalar invDenom_; - autoPtr stressXPtr_; - autoPtr stressYPtr_; - autoPtr stressZPtr_; - // Store this in order to computed only once per objective call volSymmTensorField devReff_; diff --git a/src/optimisation/adjointOptimisation/adjoint/optimisation/adjointSensitivity/incompressible/adjointMeshMovementSolver/adjointMeshMovementSolverIncompressible.C b/src/optimisation/adjointOptimisation/adjoint/optimisation/adjointSensitivity/incompressible/adjointMeshMovementSolver/adjointMeshMovementSolverIncompressible.C index 5b8c87476a..663db50998 100644 --- a/src/optimisation/adjointOptimisation/adjoint/optimisation/adjointSensitivity/incompressible/adjointMeshMovementSolver/adjointMeshMovementSolverIncompressible.C +++ b/src/optimisation/adjointOptimisation/adjoint/optimisation/adjointSensitivity/incompressible/adjointMeshMovementSolver/adjointMeshMovementSolverIncompressible.C @@ -5,8 +5,8 @@ \\ / A nd | www.openfoam.com \\/ M anipulation | ------------------------------------------------------------------------------- - Copyright (C) 2007-2021 PCOpt/NTUA - Copyright (C) 2013-2021 FOSS GP + Copyright (C) 2007-2022 PCOpt/NTUA + Copyright (C) 2013-2022 FOSS GP Copyright (C) 2019-2020 OpenCFD Ltd. ------------------------------------------------------------------------------- License @@ -76,9 +76,9 @@ adjointMeshMovementSolver::adjointMeshMovementSolver ( word ( - adjointSensitivity.adjointVars().useSolverNameForFields() ? - "ma" + adjointSensitivity.adjointSolver().solverName() : - "ma" + adjointSensitivity.adjointVars().useSolverNameForFields() + ? "ma" + adjointSensitivity.adjointSolver().solverName() + : "ma" ), mesh.time().timeName(), mesh, diff --git a/src/optimisation/adjointOptimisation/adjoint/optimisation/adjointSensitivity/incompressible/adjointSensitivity/adjointSensitivityIncompressible.C b/src/optimisation/adjointOptimisation/adjoint/optimisation/adjointSensitivity/incompressible/adjointSensitivity/adjointSensitivityIncompressible.C index d680f8b571..0cd4e7565f 100644 --- a/src/optimisation/adjointOptimisation/adjoint/optimisation/adjointSensitivity/incompressible/adjointSensitivity/adjointSensitivityIncompressible.C +++ b/src/optimisation/adjointOptimisation/adjoint/optimisation/adjointSensitivity/incompressible/adjointSensitivity/adjointSensitivityIncompressible.C @@ -5,8 +5,8 @@ \\ / A nd | www.openfoam.com \\/ M anipulation | ------------------------------------------------------------------------------- - Copyright (C) 2007-2021 PCOpt/NTUA - Copyright (C) 2013-2021 FOSS GP + Copyright (C) 2007-2022 PCOpt/NTUA + Copyright (C) 2013-2022 FOSS GP Copyright (C) 2019-2021 OpenCFD Ltd. ------------------------------------------------------------------------------- License @@ -100,24 +100,6 @@ autoPtr adjointSensitivity::New // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * // -const incompressibleVars& adjointSensitivity::primalVars() const -{ - return primalVars_; -} - - -const incompressibleAdjointVars& adjointSensitivity::adjointVars() const -{ - return adjointVars_; -} - - -const incompressibleAdjointSolver& adjointSensitivity::adjointSolver() const -{ - return adjointSolver_; -} - - const scalarField& adjointSensitivity::calculateSensitivities() { assembleSensitivities(); diff --git a/src/optimisation/adjointOptimisation/adjoint/optimisation/adjointSensitivity/incompressible/adjointSensitivity/adjointSensitivityIncompressible.H b/src/optimisation/adjointOptimisation/adjoint/optimisation/adjointSensitivity/incompressible/adjointSensitivity/adjointSensitivityIncompressible.H index 76bc8ded03..eebb436e9c 100644 --- a/src/optimisation/adjointOptimisation/adjoint/optimisation/adjointSensitivity/incompressible/adjointSensitivity/adjointSensitivityIncompressible.H +++ b/src/optimisation/adjointOptimisation/adjoint/optimisation/adjointSensitivity/incompressible/adjointSensitivity/adjointSensitivityIncompressible.H @@ -5,8 +5,8 @@ \\ / A nd | www.openfoam.com \\/ M anipulation | ------------------------------------------------------------------------------- - Copyright (C) 2007-2021 PCOpt/NTUA - Copyright (C) 2013-2021 FOSS GP + Copyright (C) 2007-2022 PCOpt/NTUA + Copyright (C) 2013-2022 FOSS GP Copyright (C) 2019 OpenCFD Ltd. ------------------------------------------------------------------------------- License @@ -156,13 +156,22 @@ public: // Member Functions //- Get primal variables - const incompressibleVars& primalVars() const; + inline const incompressibleVars& primalVars() const + { + return primalVars_; + } //- Get adjoint variables - const incompressibleAdjointVars& adjointVars() const; + inline const incompressibleAdjointVars& adjointVars() const + { + return adjointVars_; + } //- Get adjoint solver - const incompressibleAdjointSolver& adjointSolver() const; + inline const incompressibleAdjointSolver& adjointSolver() const + { + return adjointSolver_; + } //- Accumulate sensitivity integrands // Corresponds to the flow and adjoint part of the sensitivities diff --git a/src/optimisation/adjointOptimisation/adjoint/parameterization/Bezier/Bezier.C b/src/optimisation/adjointOptimisation/adjoint/parameterization/Bezier/Bezier.C index 19eb3db58e..6653c2ed48 100644 --- a/src/optimisation/adjointOptimisation/adjoint/parameterization/Bezier/Bezier.C +++ b/src/optimisation/adjointOptimisation/adjoint/parameterization/Bezier/Bezier.C @@ -5,8 +5,8 @@ \\ / A nd | www.openfoam.com \\/ M anipulation | ------------------------------------------------------------------------------- - Copyright (C) 2007-2019 PCOpt/NTUA - Copyright (C) 2013-2019 FOSS GP + Copyright (C) 2007-2019, 2022 PCOpt/NTUA + Copyright (C) 2013-2019, 2022 FOSS GP Copyright (C) 2019 OpenCFD Ltd. ------------------------------------------------------------------------------- License @@ -236,9 +236,7 @@ tmp Bezier::dndbBasedSensitivities const label patchStart = ppatch.start(); const tensorField& dxdbInt = dxidXj_[cpI].primitiveField(); vectorField dxdbDir(dxdbInt.size(), Zero); - dxdbDir.replace(0, dxdbInt.component(3*idir)); - dxdbDir.replace(1, dxdbInt.component(3*idir + 1)); - dxdbDir.replace(2, dxdbInt.component(3*idir + 2)); + unzipRow(dxdbInt, vector::components(idir), dxdbDir); // Loop over patch faces forAll(patch, fI) diff --git a/src/optimisation/adjointOptimisation/adjoint/parameterization/NURBS/NURBS3DVolume/NURBS3DVolume/NURBS3DVolume.C b/src/optimisation/adjointOptimisation/adjoint/parameterization/NURBS/NURBS3DVolume/NURBS3DVolume/NURBS3DVolume.C index b1a699bb50..3d35a13e5a 100644 --- a/src/optimisation/adjointOptimisation/adjoint/parameterization/NURBS/NURBS3DVolume/NURBS3DVolume/NURBS3DVolume.C +++ b/src/optimisation/adjointOptimisation/adjoint/parameterization/NURBS/NURBS3DVolume/NURBS3DVolume/NURBS3DVolume.C @@ -5,8 +5,8 @@ \\ / A nd | www.openfoam.com \\/ M anipulation | ------------------------------------------------------------------------------- - Copyright (C) 2007-2021 PCOpt/NTUA - Copyright (C) 2013-2021 FOSS GP + Copyright (C) 2007-2022 PCOpt/NTUA + Copyright (C) 2013-2022 FOSS GP Copyright (C) 2019-2021 OpenCFD Ltd. ------------------------------------------------------------------------------- License @@ -653,17 +653,7 @@ Foam::NURBS3DVolume::NURBS3DVolume maxIter_(dict.getOrDefault