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
\\/ 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-2020 OpenCFD Ltd.
-------------------------------------------------------------------------------
License
@ -28,6 +28,8 @@ License
\*---------------------------------------------------------------------------*/
#include "adjointMeshMovementSolverIncompressible.H"
#include "incompressibleAdjointSolver.H"
#include "fixedValueFvPatchFields.H"
#include "subCycleTime.H"
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
@ -70,12 +72,22 @@ adjointMeshMovementSolver::adjointMeshMovementSolver
tolerance_(-1),
ma_
(
variablesSet::autoCreateMeshMovementField
IOobject
(
word
(
adjointSensitivity.adjointVars().useSolverNameForFields() ?
"ma" + adjointSensitivity.adjointSolver().solverName() :
"ma"
),
mesh.time().timeName(),
mesh,
"ma",
dimensionSet(pow3(dimLength/dimTime))
)
IOobject::READ_IF_PRESENT,
IOobject::AUTO_WRITE
),
mesh,
dimensionedVector(pow3(dimLength/dimTime), Zero),
fixedValueFvPatchVectorField::typeName
),
source_
(
@ -142,7 +154,8 @@ void adjointMeshMovementSolver::solve()
maEqn.boundaryManipulate(ma_.boundaryFieldRef());
//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;

View File

@ -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-2021 OpenCFD Ltd.
-------------------------------------------------------------------------------
License
@ -100,6 +100,24 @@ autoPtr<adjointSensitivity> 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();

View File

@ -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
@ -155,37 +155,46 @@ public:
// Member Functions
//- Accumulate sensitivity integrands
// Corresponds to the flow and adjoint part of the sensitivities
virtual void accumulateIntegrand(const scalar dt) = 0;
//- Get primal variables
const incompressibleVars& primalVars() const;
//- Assemble sensitivities
// Adds the geometric part of the sensitivities
virtual void assembleSensitivities() = 0;
//- Get adjoint variables
const incompressibleAdjointVars& adjointVars() const;
//- Calculates and returns sensitivity fields.
// Used with optimisation libraries
virtual const scalarField& calculateSensitivities();
//- Get adjoint solver
const incompressibleAdjointSolver& adjointSolver() const;
//- Returns the sensitivity fields
// Assumes it has already been updated/computed
const scalarField& getSensitivities() const;
//- Accumulate sensitivity integrands
// Corresponds to the flow and adjoint part of the sensitivities
virtual void accumulateIntegrand(const scalar dt) = 0;
//- Zero sensitivity fields and their constituents
virtual void clearSensitivities();
//- Assemble sensitivities
// Adds the geometric part of the sensitivities
virtual void assembleSensitivities() = 0;
//- 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);
//- Calculates and returns sensitivity fields.
// Used with optimisation libraries
virtual const scalarField& calculateSensitivities();
//- Compute the volTensorField multiplying grad(dxdb) for
//- the volume-based approach to compute shape sensitivity derivatives
tmp<volTensorField> computeGradDxDbMultiplier();
//- Returns the sensitivity fields
// Assumes it has already been updated/computed
const scalarField& getSensitivities() const;
//- Compute source term for adjoint mesh movement equation
tmp<volVectorField> adjointMeshMovementSource();
//- Zero sensitivity fields and their constituents
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();
};