Commit 254d38d7 authored by Vaggelis Papoutsis's avatar Vaggelis Papoutsis Committed by Andrew Heather
Browse files

BUG: continuation of updateMethods with empty activeDesignVariables

When activeDesignVariables are not set explicitly, all design variables
are treated as active. These were allocated properly when starting from
0 but not when starting from an intermediate optimisation cycle
(e.g. running 5 optimisation cycles, stopping and restarting).

TUT: added a new tutorial including the restart of an optimisation run
to help identify future regression
parent 60efde8c
......@@ -51,11 +51,7 @@ void Foam::BFGS::allocateMatrices()
// Set active design variables, if necessary
if (activeDesignVars_.empty())
{
activeDesignVars_.setSize(correction_.size());
forAll(activeDesignVars_, dvI)
{
activeDesignVars_[dvI] = dvI;
}
activeDesignVars_ = identity(objectiveDerivatives_.size());
}
// Set previous HessianInv to be a diagonal matrix
......@@ -155,9 +151,14 @@ void Foam::BFGS::readFromDict()
optMethodIODict_.readEntry("counter", counter_);
optMethodIODict_.readEntry("eta", eta_);
label n = HessianInvOld_.n();
const label n(HessianInvOld_.n());
HessianInv_ = SquareMatrix<scalar>(n, Zero);
correction_ = scalarField(correctionOld_.size(), Zero);
if (activeDesignVars_.empty())
{
activeDesignVars_ = identity(n);
}
}
}
......
......@@ -51,11 +51,7 @@ void Foam::DBFGS::allocateMatrices()
// Set active design variables, if necessary
if (activeDesignVars_.empty())
{
activeDesignVars_.setSize(correction_.size());
forAll(activeDesignVars_, dvI)
{
activeDesignVars_[dvI] = dvI;
}
activeDesignVars_ = identity(objectiveDerivatives_.size());
}
// Set previous Hessian to be a diagonal matrix
......@@ -162,6 +158,11 @@ void Foam::DBFGS::readFromDict()
label n = HessianOld_.n();
Hessian_ = SquareMatrix<scalar>(n, Zero);
correction_ = scalarField(correctionOld_.size(), Zero);
if (activeDesignVars_.empty())
{
activeDesignVars_ = identity(n);
}
}
}
......
......@@ -51,11 +51,7 @@ void Foam::LBFGS::allocateMatrices()
// Set active design variables, if necessary
if (activeDesignVars_.empty())
{
activeDesignVars_.setSize(objectiveDerivatives_.size());
forAll(activeDesignVars_, dvI)
{
activeDesignVars_[dvI] = dvI;
}
activeDesignVars_ = identity(objectiveDerivatives_.size());
}
// Allocate vectors
......@@ -184,6 +180,11 @@ void Foam::LBFGS::readFromDict()
optMethodIODict_.readEntry("correctionOld", correctionOld_);
correction_ = scalarField(correctionOld_.size(), Zero);
if (activeDesignVars_.empty())
{
activeDesignVars_ = identity(derivativesOld_.size());
}
}
}
......
......@@ -58,11 +58,7 @@ void Foam::SQP::allocateMatrices()
// Set active design variables, if necessary
if (activeDesignVars_.empty())
{
activeDesignVars_.setSize(correction_.size());
forAll(activeDesignVars_, dvI)
{
activeDesignVars_[dvI] = dvI;
}
activeDesignVars_ = identity(objectiveDerivatives_.size());
}
// Set previous Hessian to be a diagonal matrix
......@@ -269,6 +265,11 @@ void Foam::SQP::readFromDict()
optMethodIODict_.readEntry("eta", eta_);
correction_ = scalarField(correctionOld_.size(), Zero);
if (activeDesignVars_.empty())
{
activeDesignVars_ = identity(correction_.size());
}
}
}
......
......@@ -51,11 +51,7 @@ void Foam::SR1::allocateMatrices()
// Set active design variables, if necessary
if (activeDesignVars_.empty())
{
activeDesignVars_.setSize(correction_.size());
forAll(activeDesignVars_, dvI)
{
activeDesignVars_[dvI] = dvI;
}
activeDesignVars_ = identity(objectiveDerivatives_.size());
}
// Set previous HessianInv to be a diagonal matrix
......@@ -146,9 +142,14 @@ void Foam::SR1::readFromDict()
optMethodIODict_.readEntry("counter", counter_);
optMethodIODict_.readEntry("eta", eta_);
label n = HessianInvOld_.n();
const label n(HessianInvOld_.n());
HessianInv_ = SquareMatrix<scalar>(n, Zero);
correction_ = scalarField(correctionOld_.size(), Zero);
if (activeDesignVars_.empty())
{
activeDesignVars_ = identity(n);
}
}
}
......
......@@ -51,11 +51,7 @@ void Foam::conjugateGradient::allocateFields()
// Set active design variables, if necessary
if (activeDesignVars_.empty())
{
activeDesignVars_.setSize(objectiveDerivatives_.size());
forAll(activeDesignVars_, dvI)
{
activeDesignVars_[dvI] = dvI;
}
activeDesignVars_ = identity(objectiveDerivatives_.size());
}
// Allocate old fields
......@@ -75,6 +71,11 @@ void Foam::conjugateGradient::readFromDict()
label nDVs = optMethodIODict_.get<label>("nDVs");
correction_ = scalarField(nDVs, Zero);
if (activeDesignVars_.empty())
{
activeDesignVars_ = identity(nDVs);
}
}
}
......
/*--------------------------------*- C++ -*----------------------------------*\
| ========= | |
| \\ / F ield | OpenFOAM: The Open Source CFD Toolbox |
| \\ / O peration | Version: v1912 |
| \\ / A nd | Website: www.openfoam.com |
| \\/ M anipulation | |
\*---------------------------------------------------------------------------*/
FoamFile
{
version 2.0;
format ascii;
class volVectorField;
location "0";
object U;
}
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
dimensions [ 0 1 -1 0 0 0 0 ];
internalField uniform ( 3.95 0 0 );
boundaryField
{
frontBack
{
type empty;
}
sideWall
{
type fixedValue;
value uniform ( 0 0 0 );
}
lower
{
type fixedValue;
value uniform ( 0 0 0 );
}
upper
{
type fixedValue;
value uniform ( 0 0 0 );
}
Inlet
{
type fixedValue;
value uniform ( 3.95 0 0 );
}
Outlet
{
type zeroGradient;
}
}
// ************************************************************************* //
/*--------------------------------*- C++ -*----------------------------------*\
| ========= | |
| \\ / F ield | OpenFOAM: The Open Source CFD Toolbox |
| \\ / O peration | Version: v1912 |
| \\ / A nd | Website: www.openfoam.com |
| \\/ M anipulation | |
\*---------------------------------------------------------------------------*/
FoamFile
{
version 2.0;
format ascii;
class volVectorField;
location "0";
object Ua;
}
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
dimensions [ 0 1 -1 0 0 0 0 ];
internalField uniform ( 0 0 0 );
boundaryField
{
frontBack
{
type empty;
}
sideWall
{
type adjointWallVelocity;
value uniform ( 0 0 0 );
}
upper
{
type adjointWallVelocity;
value uniform ( 0 0 0 );
}
Inlet
{
type adjointInletVelocity;
value uniform ( 0 0 0 );
}
Outlet
{
type adjointOutletVelocity;
value uniform ( 0 0 0 );
}
lower
{
type adjointWallVelocity;
value uniform ( 0 0 0 );
}
}
// ************************************************************************* //
/*--------------------------------*- C++ -*----------------------------------*\
| ========= | |
| \\ / F ield | OpenFOAM: The Open Source CFD Toolbox |
| \\ / O peration | Version: v1912 |
| \\ / A nd | Website: www.openfoam.com |
| \\/ M anipulation | |
\*---------------------------------------------------------------------------*/
FoamFile
{
version 2.0;
format ascii;
class volScalarField;
location "0";
object nuTilda;
}
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
dimensions [ 0 2 -1 0 0 0 0 ];
internalField uniform 4.5e-05;
boundaryField
{
frontBack
{
type empty;
}
sideWall
{
type fixedValue;
value uniform 0;
}
upper
{
type fixedValue;
value uniform 0;
}
lower
{
type fixedValue;
value uniform 0;
}
Inlet
{
type fixedValue;
value uniform 4.5e-05;
}
Outlet
{
type zeroGradient;
}
}
// ************************************************************************* //
/*--------------------------------*- C++ -*----------------------------------*\
| ========= | |
| \\ / F ield | OpenFOAM: The Open Source CFD Toolbox |
| \\ / O peration | Version: v1912 |
| \\ / A nd | Website: www.openfoam.com |
| \\/ M anipulation | |
\*---------------------------------------------------------------------------*/
FoamFile
{
version 2.0;
format ascii;
class volScalarField;
location "0";
object nuaTilda;
}
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
dimensions [ 0 0 -1 0 0 0 0 ];
internalField uniform 0;
boundaryField
{
frontBack
{
type empty;
}
sideWall
{
type fixedValue;
value uniform 0;
}
upper
{
type fixedValue;
value uniform 0;
}
lower
{
type fixedValue;
value uniform 0;
}
Inlet
{
type adjointInletNuaTilda;
value uniform 0;
}
Outlet
{
type adjointOutletNuaTilda;
value uniform 0;
}
defaultFaces
{
type empty;
}
}
// ************************************************************************* //
/*--------------------------------*- C++ -*----------------------------------*\
| ========= | |
| \\ / F ield | OpenFOAM: The Open Source CFD Toolbox |
| \\ / O peration | Version: v1912 |
| \\ / A nd | Website: www.openfoam.com |
| \\/ M anipulation | |
\*---------------------------------------------------------------------------*/
FoamFile
{
version 2.0;
format ascii;
class volScalarField;
location "0";
object nut;
}
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
dimensions [ 0 2 -1 0 0 0 0 ];
internalField uniform 3.15e-06;
boundaryField
{
frontBack
{
type empty;
}
sideWall
{
type nutLowReWallFunction;
value uniform 0;
}
upper
{
type nutLowReWallFunction;
value uniform 0;
}
lower
{
type nutLowReWallFunction;
value uniform 0;
}
Inlet
{
type fixedValue;
value uniform 3.15e-06;
}
Outlet
{
type zeroGradient;
}
}
// ************************************************************************* //
/*--------------------------------*- C++ -*----------------------------------*\
| ========= | |
| \\ / F ield | OpenFOAM: The Open Source CFD Toolbox |
| \\ / O peration | Version: v1912 |
| \\ / A nd | Website: www.openfoam.com |
| \\/ M anipulation | |
\*---------------------------------------------------------------------------*/
FoamFile
{
version 2.0;
format ascii;
class volScalarField;
location "0";
object p;
}
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
dimensions [ 0 2 -2 0 0 0 0 ];
internalField uniform 0;
boundaryField
{
frontBack
{
type empty;
}
lower
{
type zeroGradient;
}
upper
{
type zeroGradient;
}
sideWall
{
type zeroGradient;
}
Inlet
{
type zeroGradient;
}
Outlet
{
type fixedValue;
value uniform 0;
}
}
// ************************************************************************* //
/*--------------------------------*- C++ -*----------------------------------*\
| ========= | |
| \\ / F ield | OpenFOAM: The Open Source CFD Toolbox |
| \\ / O peration | Version: v1912 |
| \\ / A nd | Website: www.openfoam.com |
| \\/ M anipulation | |
\*---------------------------------------------------------------------------*/
FoamFile
{
version 2.0;
format ascii;
class volScalarField;
location "0";
object pa;
}
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
dimensions [ 0 2 -2 0 0 0 0 ];
internalField uniform 0;
boundaryField
{
frontBack
{
type empty;
}
sideWall
{
type zeroGradient;
}
upper
{
type zeroGradient;
}
Inlet
{
type zeroGradient;
}
Outlet
{
type adjointOutletPressure;
value uniform 0;
}
lower
{
type zeroGradient;
}
}
// ************************************************************************* //
#!/bin/sh
cd "${0%/*}" || exit # Run from this directory
. ${WM_PROJECT_DIR:?}/bin/tools/CleanFunctions # Tutorial clean functions
#------------------------------------------------------------------------------
cleanCase
sed -i 's/endTime 10/endTime 5/g' system/controlDict
sed -i 's/fromFile/axisAligned/g' constant/dynamicMeshDict
#------------------------------------------------------------------------------
#!/bin/sh
cd "${0%/*}" || exit # Run from this directory
. ${WM_PROJECT_DIR:?}/bin/tools/RunFunctions # Tutorial run functions
#------------------------------------------------------------------------------
resourcesDir=$FOAM_TUTORIALS/incompressible/adjointOptimisationFoam/resources
\cp -r $resourcesDir/meshes/sbend/polyMesh constant
runApplication decomposePar
runParallel $(getApplication)
mv log.adjointOptimisationFoam log.adjointOptimisationFoamFirstPhase
sed -i 's/endTime 5/endTime 10/g' system/controlDict
sed -i 's/axisAligned/fromFile/g' constant/dynamicMeshDict
runParallel $(getApplication)
runParallel cumulativeDisplacement