Skip to content
This repository has been archived by the owner on May 9, 2022. It is now read-only.

Commit

Permalink
1. Space mapping: add maxUsedIterations parameter. Closes #16
Browse files Browse the repository at this point in the history
2. Space mapping: reuse all iterations within one time step. Closes #15
  • Loading branch information
David Blom committed Mar 4, 2015
1 parent f417430 commit 1d06cb4
Show file tree
Hide file tree
Showing 36 changed files with 720 additions and 741 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ linux64GccDPOpt
darwinIntel64GccDPOpt

# Specific files
*.log
formatCode
uncrustify.cfg
runTests.sh
Expand Down
8 changes: 4 additions & 4 deletions applications/solvers/fsi/fsiFoam/fsiFoam.C
Original file line number Diff line number Diff line change
Expand Up @@ -428,16 +428,16 @@ int main(
shared_ptr<SpaceMapping> spaceMapping;

if ( algorithm == "manifold-mapping" )
spaceMapping = shared_ptr<SpaceMapping> ( new ManifoldMapping( fineModel, coarseModel, maxIter, nbReuse, reuseInformationStartingFromTimeIndex, singularityLimit, updateJacobian, initialSolutionCoarseModel ) );
spaceMapping = shared_ptr<SpaceMapping> ( new ManifoldMapping( fineModel, coarseModel, maxIter, maxUsedIterations, nbReuse, reuseInformationStartingFromTimeIndex, singularityLimit, updateJacobian, initialSolutionCoarseModel ) );

if ( algorithm == "output-space-mapping" )
spaceMapping = shared_ptr<SpaceMapping> ( new OutputSpaceMapping( fineModel, coarseModel, maxIter, nbReuse, reuseInformationStartingFromTimeIndex, singularityLimit, order ) );
spaceMapping = shared_ptr<SpaceMapping> ( new OutputSpaceMapping( fineModel, coarseModel, maxIter, maxUsedIterations, nbReuse, reuseInformationStartingFromTimeIndex, singularityLimit, order ) );

if ( algorithm == "aggressive-space-mapping" )
spaceMapping = shared_ptr<SpaceMapping> ( new AggressiveSpaceMapping( fineModel, coarseModel, maxIter, nbReuse, reuseInformationStartingFromTimeIndex, singularityLimit ) );
spaceMapping = shared_ptr<SpaceMapping> ( new AggressiveSpaceMapping( fineModel, coarseModel, maxIter, maxUsedIterations, nbReuse, reuseInformationStartingFromTimeIndex, singularityLimit ) );

if ( algorithm == "ASM-ILS" )
spaceMapping = shared_ptr<SpaceMapping> ( new ASMILS( fineModel, coarseModel, maxIter, nbReuse, reuseInformationStartingFromTimeIndex, singularityLimit ) );
spaceMapping = shared_ptr<SpaceMapping> ( new ASMILS( fineModel, coarseModel, maxIter, maxUsedIterations, nbReuse, reuseInformationStartingFromTimeIndex, singularityLimit ) );

shared_ptr<SpaceMappingSolver > spaceMappingSolver( new SpaceMappingSolver( fineModel, coarseModel, spaceMapping ) );

Expand Down
93 changes: 57 additions & 36 deletions src/fsi/ASMILS.C
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,13 @@ ASMILS::ASMILS(
shared_ptr<SurrogateModel> fineModel,
shared_ptr<SurrogateModel> coarseModel,
int maxIter,
int maxUsedIterations,
int nbReuse,
int reuseInformationStartingFromTimeIndex,
double singularityLimit
)
:
SpaceMapping( fineModel, coarseModel, maxIter, nbReuse, reuseInformationStartingFromTimeIndex, singularityLimit )
SpaceMapping( fineModel, coarseModel, maxIter, maxUsedIterations, nbReuse, reuseInformationStartingFromTimeIndex, singularityLimit )
{}

ASMILS::~ASMILS()
Expand Down Expand Up @@ -49,10 +50,8 @@ void ASMILS::performPostProcessing(
vector yk( m ), output( m ), R( m ), zstar( m ), zk( m ), xkprev( m );
xk = x0;
xkprev = x0;
coarseResiduals.resize( m, 0 );
coarseResiduals.setZero();
fineResiduals.resize( m, 0 );
fineResiduals.setZero();
coarseResiduals.clear();
fineResiduals.clear();

// Determine optimum of coarse model zstar
if ( residualCriterium )
Expand All @@ -65,7 +64,7 @@ void ASMILS::performPostProcessing(
coarseModel->optimize( y, x0, zstar );

if ( !coarseModel->allConverged() )
Warning << "Surrogate model optimization process is not converged." << endl;
Warning << "ASMILS: surrogate model optimization process is not converged." << endl;

if ( timeIndex == 0 )
xk = zstar;
Expand All @@ -81,8 +80,7 @@ void ASMILS::performPostProcessing(
return;
}

fineResiduals.conservativeResize( fineResiduals.rows(), fineResiduals.cols() + 1 );
fineResiduals.col( fineResiduals.cols() - 1 ) = xk;
fineResiduals.push_back( xk );

// Parameter extraction

Expand All @@ -91,24 +89,30 @@ void ASMILS::performPostProcessing(
if ( !coarseModel->allConverged() )
Warning << "Surrogate model optimization process is not converged." << endl;

coarseResiduals.conservativeResize( coarseResiduals.rows(), coarseResiduals.cols() + 1 );
coarseResiduals.col( coarseResiduals.cols() - 1 ) = zk;
coarseResiduals.push_back( zk );

for ( int k = 0; k < maxIter - 1; k++ )
{
xkprev = xk;

// Determine the number of columns used to calculate the mapping matrix J

int nbCols = fineResiduals.cols() - 1;
int nbCols = fineResiduals.size() - 1;
nbCols = std::max( nbCols, 0 );

// Include information from previous time steps
// Include information from previous optimization cycles

for ( unsigned i = 0; i < fineResidualsList.size(); i++ )
nbCols += fineResidualsList.at( i ).cols() - 1;
nbCols += fineResidualsList.at( i ).size() - 1;

// Include information from previous time steps

for ( unsigned i = 0; i < fineResidualsTimeList.size(); i++ )
for ( unsigned j = 0; j < fineResidualsTimeList.at( i ).size(); j++ )
nbCols += fineResidualsTimeList.at( i ).at( j ).size() - 1;

nbCols = std::min( static_cast<int>( xk.rows() ), nbCols );
nbCols = std::min( nbCols, maxUsedIterations );

assert( nbCols <= xk.rows() );

Expand All @@ -125,7 +129,7 @@ void ASMILS::performPostProcessing(
// Construct the V and W matrices
matrix V( xk.rows(), nbCols ), W( xk.rows(), nbCols );

int nbColsCurrentTimeStep = std::max( static_cast<int>(fineResiduals.cols() - 1), 0 );
int nbColsCurrentTimeStep = std::max( static_cast<int>(fineResiduals.size() - 1), 0 );
nbColsCurrentTimeStep = std::min( nbColsCurrentTimeStep, nbCols );

// Include information from previous iterations
Expand All @@ -137,29 +141,50 @@ void ASMILS::performPostProcessing(
if ( colIndex >= V.cols() )
continue;

V.col( i ) = coarseResiduals.col( coarseResiduals.cols() - 2 - i ) - coarseResiduals.col( coarseResiduals.cols() - 1 );
W.col( i ) = fineResiduals.col( fineResiduals.cols() - 2 - i ) - fineResiduals.col( fineResiduals.cols() - 1 );
V.col( i ) = coarseResiduals.at( coarseResiduals.size() - 2 - i ) - coarseResiduals.back();
W.col( i ) = fineResiduals.at( fineResiduals.size() - 2 - i ) - fineResiduals.back();
colIndex++;
}

// Include information from previous time steps
// Include information from previous optimization cycles

for ( unsigned i = 0; i < fineResidualsList.size(); i++ )
{
assert( fineResidualsList.at( i ).cols() >= 2 );
assert( coarseResidualsList.at( i ).cols() >= 2 );
assert( fineResidualsList.at( i ).size() >= 2 );
assert( coarseResidualsList.at( i ).size() >= 2 );

for ( int j = 0; j < fineResidualsList.at( i ).cols() - 1; j++ )
for ( unsigned j = 0; j < fineResidualsList.at( i ).size() - 1; j++ )
{
if ( colIndex >= V.cols() )
continue;

V.col( colIndex ) = coarseResidualsList.at( i ).col( coarseResidualsList.at( i ).cols() - 2 - j ) - coarseResidualsList.at( i ).col( coarseResidualsList.at( i ).cols() - 1 );
W.col( colIndex ) = fineResidualsList.at( i ).col( fineResidualsList.at( i ).cols() - 2 - j ) - fineResidualsList.at( i ).col( fineResidualsList.at( i ).cols() - 1 );
V.col( colIndex ) = coarseResidualsList.at( i ).at( coarseResidualsList.at( i ).size() - 2 - j ) - coarseResidualsList.at( i ).back();
W.col( colIndex ) = fineResidualsList.at( i ).at( fineResidualsList.at( i ).size() - 2 - j ) - fineResidualsList.at( i ).back();
colIndex++;
}
}

// Include information from previous time steps

for ( unsigned i = 0; i < fineResidualsTimeList.size(); i++ )
{
for ( unsigned j = 0; j < fineResidualsTimeList.at( i ).size(); j++ )
{
assert( fineResidualsTimeList.at( i ).at( j ).size() >= 2 );
assert( coarseResidualsTimeList.at( i ).at( j ).size() >= 2 );

for ( unsigned k = 0; k < fineResidualsTimeList.at( i ).at( j ).size() - 1; k++ )
{
if ( colIndex >= V.cols() )
continue;

V.col( colIndex ) = coarseResidualsTimeList.at( i ).at( j ).at( coarseResidualsTimeList.at( i ).at( j ).size() - 2 - k ) - coarseResidualsTimeList.at( i ).at( j ).back();
W.col( colIndex ) = fineResidualsTimeList.at( i ).at( j ).at( fineResidualsTimeList.at( i ).at( j ).size() - 2 - k ) - fineResidualsTimeList.at( i ).at( j ).back();
colIndex++;
}
}
}

assert( colIndex == nbCols );

// Remove dependent columns of V and W
Expand Down Expand Up @@ -210,28 +235,24 @@ void ASMILS::performPostProcessing(

fineModel->evaluate( xk, output, R );

fineResiduals.conservativeResize( fineResiduals.rows(), fineResiduals.cols() + 1 );
fineResiduals.col( fineResiduals.cols() - 1 ) = xk;
// Check convergence criteria
if ( isConvergence( xk, xkprev, residualCriterium ) )
{
iterationsConverged();
break;
}

fineResiduals.push_back( xk );

// Parameter extraction

coarseModel->optimize( R, zstar, zk );

if ( !coarseModel->allConverged() )
Warning << "Surrogate model optimization process is not converged." << endl;
Warning << "ASMILS: surrogate model optimization process is not converged." << endl;

coarseResiduals.conservativeResize( coarseResiduals.rows(), coarseResiduals.cols() + 1 );
coarseResiduals.col( coarseResiduals.cols() - 1 ) = zk;

// Check convergence criteria
if ( isConvergence( xk, xkprev, residualCriterium ) )
break;

if ( k == maxIter - 2 )
break;
coarseResiduals.push_back( zk );
}

iterationsConverged();
}

void ASMILS::removeColumnFromMatrix(
Expand Down
1 change: 1 addition & 0 deletions src/fsi/ASMILS.H
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ public:
shared_ptr<SurrogateModel> fineModel,
shared_ptr<SurrogateModel> coarseModel,
int maxIter,
int maxUsedIterations,
int nbReuse,
int reuseInformationStartingFromTimeIndex,
double singularityLimit
Expand Down
81 changes: 54 additions & 27 deletions src/fsi/AggressiveSpaceMapping.C
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,13 @@ AggressiveSpaceMapping::AggressiveSpaceMapping(
shared_ptr<SurrogateModel> fineModel,
shared_ptr<SurrogateModel> coarseModel,
int maxIter,
int maxUsedIterations,
int nbReuse,
int reuseInformationStartingFromTimeIndex,
double singularityLimit
)
:
SpaceMapping( fineModel, coarseModel, maxIter, nbReuse, reuseInformationStartingFromTimeIndex, singularityLimit )
SpaceMapping( fineModel, coarseModel, maxIter, maxUsedIterations, nbReuse, reuseInformationStartingFromTimeIndex, singularityLimit )
{}

AggressiveSpaceMapping::~AggressiveSpaceMapping()
Expand All @@ -38,10 +39,8 @@ void AggressiveSpaceMapping::performPostProcessing(
vector yk( m ), output( m ), R( m ), zstar( m ), zk( m ), xkprev( m );
xk = x0;
xkprev = x0;
coarseResiduals.resize( m, 0 );
coarseResiduals.setZero();
fineResiduals.resize( m, 0 );
fineResiduals.setZero();
coarseResiduals.clear();
fineResiduals.clear();

// Determine optimum of coarse model zstar
if ( residualCriterium )
Expand Down Expand Up @@ -77,11 +76,8 @@ void AggressiveSpaceMapping::performPostProcessing(
if ( !coarseModel->allConverged() )
Warning << "Surrogate model optimization process is not converged." << endl;

coarseResiduals.conservativeResize( coarseResiduals.rows(), coarseResiduals.cols() + 1 );
coarseResiduals.col( coarseResiduals.cols() - 1 ) = zk;

fineResiduals.conservativeResize( fineResiduals.rows(), fineResiduals.cols() + 1 );
fineResiduals.col( fineResiduals.cols() - 1 ) = xk;
coarseResiduals.push_back( zk );
fineResiduals.push_back( xk );

for ( int k = 0; k < maxIter - 1; k++ )
{
Expand All @@ -93,10 +89,16 @@ void AggressiveSpaceMapping::performPostProcessing(
int nbColsCurrentTimeStep = nbCols;
int colIndex = 0;

// Include information from previous time steps
// Include information from previous optimization cycles

for ( unsigned i = 0; i < fineResidualsList.size(); i++ )
nbCols += fineResidualsList.at( i ).cols() - 1;
nbCols += fineResidualsList.at( i ).size() - 1;

// Include information from previous time steps

for ( unsigned i = 0; i < fineResidualsTimeList.size(); i++ )
for ( unsigned j = 0; j < fineResidualsTimeList.at( i ).size(); j++ )
nbCols += fineResidualsTimeList.at( i ).at( j ).size() - 1;

if ( nbCols > 0 )
{
Expand All @@ -106,19 +108,46 @@ void AggressiveSpaceMapping::performPostProcessing(

// Include information from previous time steps

for ( unsigned i = 0; i < fineResidualsList.size(); i++ )
for ( unsigned i = fineResidualsTimeList.size(); i-- > 0; )
{
assert( fineResidualsList.at( i ).cols() >= 2 );
assert( coarseResidualsList.at( i ).cols() >= 2 );
for ( unsigned j = fineResidualsTimeList.at( i ).size(); j-- > 0; )
{
assert( fineResidualsTimeList.at( i ).at( j ).size() >= 2 );
assert( coarseResidualsTimeList.at( i ).at( j ).size() >= 2 );

for ( int j = 0; j < fineResidualsList.at( i ).cols() - 1; j++ )
for ( unsigned k = 0; k < fineResidualsTimeList.at( i ).at( j ).size() - 1; k++ )
{
colIndex++;

vector deltax, deltaz;

deltax = fineResidualsTimeList.at( i ).at( j ).at( k + 1 ) - fineResidualsTimeList.at( i ).at( j ).at( k );
deltaz = coarseResidualsTimeList.at( i ).at( j ).at( k + 1 ) - coarseResidualsTimeList.at( i ).at( j ).at( k );

if ( deltax.norm() >= singularityLimit )
{
// Sherman–Morrison formula
J += (deltax - J * deltaz) / (deltax.transpose() * J * deltaz) * (deltax.transpose() * J);
}
}
}
}

// Include information from previous optimization cycles

for ( unsigned i = fineResidualsList.size(); i-- > 0; )
{
assert( fineResidualsList.at( i ).size() >= 2 );
assert( coarseResidualsList.at( i ).size() >= 2 );

for ( unsigned j = 0; j < fineResidualsList.at( i ).size() - 1; j++ )
{
colIndex++;

vector deltax, deltaz;

deltax = fineResidualsList.at( i ).col( j + 1 ) - fineResidualsList.at( i ).col( j );
deltaz = coarseResidualsList.at( i ).col( j + 1 ) - coarseResidualsList.at( i ).col( j );
deltax = fineResidualsList.at( i ).at( j + 1 ) - fineResidualsList.at( i ).at( j );
deltaz = coarseResidualsList.at( i ).at( j + 1 ) - coarseResidualsList.at( i ).at( j );

if ( deltax.norm() >= singularityLimit )
{
Expand All @@ -136,8 +165,8 @@ void AggressiveSpaceMapping::performPostProcessing(

vector deltax, deltaz;

deltax = fineResiduals.col( i + 1 ) - fineResiduals.col( i );
deltaz = coarseResiduals.col( i + 1 ) - coarseResiduals.col( i );
deltax = fineResiduals.at( i + 1 ) - fineResiduals.at( i );
deltaz = coarseResiduals.at( i + 1 ) - coarseResiduals.at( i );

if ( deltax.norm() >= singularityLimit )
{
Expand All @@ -159,7 +188,10 @@ void AggressiveSpaceMapping::performPostProcessing(

// Check convergence criteria
if ( isConvergence( xk, xkprev, residualCriterium ) )
{
iterationsConverged();
break;
}

// Parameter extraction

Expand All @@ -168,12 +200,7 @@ void AggressiveSpaceMapping::performPostProcessing(
if ( !coarseModel->allConverged() )
Warning << "Surrogate model optimization process is not converged." << endl;

coarseResiduals.conservativeResize( coarseResiduals.rows(), coarseResiduals.cols() + 1 );
coarseResiduals.col( coarseResiduals.cols() - 1 ) = zk;

fineResiduals.conservativeResize( fineResiduals.rows(), fineResiduals.cols() + 1 );
fineResiduals.col( fineResiduals.cols() - 1 ) = xk;
coarseResiduals.push_back( zk );
fineResiduals.push_back( xk );
}

iterationsConverged();
}
1 change: 1 addition & 0 deletions src/fsi/AggressiveSpaceMapping.H
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ public:
shared_ptr<SurrogateModel> fineModel,
shared_ptr<SurrogateModel> coarseModel,
int maxIter,
int maxUsedIterations,
int nbReuse,
int reuseInformationStartingFromTimeIndex,
double singularityLimit
Expand Down
Loading

0 comments on commit 1d06cb4

Please sign in to comment.