ENH: the adjoint grid displacement field (ma)

is now appended by the name of the adjoint solver, if more than one
exist. This was necessary for an accurate continuation since, before
these changes, only the ma field of the last solver was written. As a
result, when restarting the first adjoint solver was reading the ma
field of the last one. No changes are needed in fvSolution and fvSchemes
w.r.t. the previous code version.
This commit is contained in:
Vaggelis Papoutsis
2021-10-19 18:06:20 +03:00
committed by Andrew Heather
parent 148815265c
commit 0b0b308db2
3 changed files with 75 additions and 35 deletions

View File

@ -5,8 +5,8 @@
\\ / A nd | www.openfoam.com \\ / A nd | www.openfoam.com
\\/ M anipulation | \\/ M anipulation |
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
Copyright (C) 2007-2019 PCOpt/NTUA Copyright (C) 2007-2021 PCOpt/NTUA
Copyright (C) 2013-2019 FOSS GP Copyright (C) 2013-2021 FOSS GP
Copyright (C) 2019-2020 OpenCFD Ltd. Copyright (C) 2019-2020 OpenCFD Ltd.
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
License License
@ -28,6 +28,8 @@ License
\*---------------------------------------------------------------------------*/ \*---------------------------------------------------------------------------*/
#include "adjointMeshMovementSolverIncompressible.H" #include "adjointMeshMovementSolverIncompressible.H"
#include "incompressibleAdjointSolver.H"
#include "fixedValueFvPatchFields.H"
#include "subCycleTime.H" #include "subCycleTime.H"
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
@ -70,12 +72,22 @@ adjointMeshMovementSolver::adjointMeshMovementSolver
tolerance_(-1), tolerance_(-1),
ma_ ma_
( (
variablesSet::autoCreateMeshMovementField IOobject
( (
word
(
adjointSensitivity.adjointVars().useSolverNameForFields() ?
"ma" + adjointSensitivity.adjointSolver().solverName() :
"ma"
),
mesh.time().timeName(),
mesh, mesh,
"ma", IOobject::READ_IF_PRESENT,
dimensionSet(pow3(dimLength/dimTime)) IOobject::AUTO_WRITE
) ),
mesh,
dimensionedVector(pow3(dimLength/dimTime), Zero),
fixedValueFvPatchVectorField::typeName
), ),
source_ source_
( (
@ -142,7 +154,8 @@ void adjointMeshMovementSolver::solve()
maEqn.boundaryManipulate(ma_.boundaryFieldRef()); maEqn.boundaryManipulate(ma_.boundaryFieldRef());
//scalar residual = max(maEqn.solve().initialResidual()); //scalar residual = max(maEqn.solve().initialResidual());
scalar residual = mag(maEqn.solve().initialResidual()); scalar residual =
mag(Foam::solve(maEqn, mesh_.solverDict("ma")).initialResidual());
Info<< "Max ma " << gMax(mag(ma_)()) << endl; Info<< "Max ma " << gMax(mag(ma_)()) << endl;

View File

@ -5,8 +5,8 @@
\\ / A nd | www.openfoam.com \\ / A nd | www.openfoam.com
\\/ M anipulation | \\/ M anipulation |
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
Copyright (C) 2007-2020 PCOpt/NTUA Copyright (C) 2007-2021 PCOpt/NTUA
Copyright (C) 2013-2020 FOSS GP Copyright (C) 2013-2021 FOSS GP
Copyright (C) 2019-2021 OpenCFD Ltd. Copyright (C) 2019-2021 OpenCFD Ltd.
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
License License
@ -100,6 +100,24 @@ autoPtr<adjointSensitivity> adjointSensitivity::New
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * // // * * * * * * * * * * * * * * * 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() const scalarField& adjointSensitivity::calculateSensitivities()
{ {
assembleSensitivities(); assembleSensitivities();

View File

@ -5,8 +5,8 @@
\\ / A nd | www.openfoam.com \\ / A nd | www.openfoam.com
\\/ M anipulation | \\/ M anipulation |
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
Copyright (C) 2007-2020 PCOpt/NTUA Copyright (C) 2007-2021 PCOpt/NTUA
Copyright (C) 2013-2020 FOSS GP Copyright (C) 2013-2021 FOSS GP
Copyright (C) 2019 OpenCFD Ltd. Copyright (C) 2019 OpenCFD Ltd.
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
License License
@ -155,37 +155,46 @@ public:
// Member Functions // Member Functions
//- Accumulate sensitivity integrands //- Get primal variables
// Corresponds to the flow and adjoint part of the sensitivities const incompressibleVars& primalVars() const;
virtual void accumulateIntegrand(const scalar dt) = 0;
//- Assemble sensitivities //- Get adjoint variables
// Adds the geometric part of the sensitivities const incompressibleAdjointVars& adjointVars() const;
virtual void assembleSensitivities() = 0;
//- Calculates and returns sensitivity fields. //- Get adjoint solver
// Used with optimisation libraries const incompressibleAdjointSolver& adjointSolver() const;
virtual const scalarField& calculateSensitivities();
//- Returns the sensitivity fields //- Accumulate sensitivity integrands
// Assumes it has already been updated/computed // Corresponds to the flow and adjoint part of the sensitivities
const scalarField& getSensitivities() const; virtual void accumulateIntegrand(const scalar dt) = 0;
//- Zero sensitivity fields and their constituents //- Assemble sensitivities
virtual void clearSensitivities(); // Adds the geometric part of the sensitivities
virtual void assembleSensitivities() = 0;
//- Write sensitivity fields. //- Calculates and returns sensitivity fields.
// If valid, copies boundaryFields to volFields and writes them. // Used with optimisation libraries
// Virtual to be reimplemented by control points-based methods virtual const scalarField& calculateSensitivities();
// (Bezier, RBF) which do not need to write fields
virtual void write(const word& baseName = word::null);
//- Compute the volTensorField multiplying grad(dxdb) for //- Returns the sensitivity fields
//- the volume-based approach to compute shape sensitivity derivatives // Assumes it has already been updated/computed
tmp<volTensorField> computeGradDxDbMultiplier(); const scalarField& getSensitivities() const;
//- Compute source term for adjoint mesh movement equation //- Zero sensitivity fields and their constituents
tmp<volVectorField> adjointMeshMovementSource(); virtual void clearSensitivities();
//- Write sensitivity fields.
// If valid, copies boundaryFields to volFields and writes them.
// Virtual to be reimplemented by control points-based methods
// (Bezier, RBF) which do not need to write fields
virtual void write(const word& baseName = word::null);
//- Compute the volTensorField multiplying grad(dxdb) for
//- the volume-based approach to compute shape sensitivity derivatives
tmp<volTensorField> computeGradDxDbMultiplier();
//- Compute source term for adjoint mesh movement equation
tmp<volVectorField> adjointMeshMovementSource();
}; };