Skip to content

Commit

Permalink
add option to use last time step of current result for new run
Browse files Browse the repository at this point in the history
  • Loading branch information
vcloarec committed Sep 4, 2023
1 parent 54bce0f commit a24b4c5
Show file tree
Hide file tree
Showing 13 changed files with 196 additions and 69 deletions.
3 changes: 2 additions & 1 deletion Tests/core/reos_hydraulic_network_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -236,8 +236,9 @@ void ReoHydraulicNetworkTest::calculationPropagation()
controller->waitForFinished();

ReosModule::Message message;
ReosSimulationData simData = structure2D->simulationData( mNetwork->currentSchemeId(), message );
std::unique_ptr<ReosSimulationPreparationProcess> preparationProcess(
structure2D->getPreparationProcessSimulation( mNetwork->currentScheme()->calculationContext(), message ) );
structure2D->getPreparationProcessSimulation( simData, mNetwork->currentScheme()->calculationContext(), message ) );
QVERIFY( preparationProcess );
controller = std::make_unique<ModuleProcessControler>( preparationProcess.get() );
controller->waitForFinished();
Expand Down
34 changes: 33 additions & 1 deletion Tests/simulationEngines/telemac/test_telemac.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -207,7 +207,7 @@ void ReosTelemacTesting::buildStructure()
int vertexCount = 86;
QCOMPARE( simData.waterLevelIni.count(), vertexCount );
QCOMPARE( simData.waterDepthIni.count(), vertexCount );
QCOMPARE( simData.velocityIni.count(), vertexCount );
QCOMPARE( simData.velocityIni.count(), vertexCount * 2 );

for ( int vi = 0; vi < vertexCount; ++vi )
{
Expand All @@ -216,6 +216,13 @@ void ReosTelemacTesting::buildStructure()
QVERIFY( simData.velocityIni.at( vi ) == 0 );
}

telemacSim->setInitialCondition( ReosTelemac2DInitialCondition::Type::LastTimeStep );
simData = hydraulicStructure->simulationData( scheme->id(), message );
QVERIFY( message.type == ReosModule::Error );
QCOMPARE( simData.waterDepthIniLocation, ReosSimulationData::None );
QCOMPARE( simData.waterLevelIniLocation, ReosSimulationData::None );
QCOMPARE( simData.velocityIniLocation, ReosSimulationData::None );

telemacSim->setInitialCondition( ReosTelemac2DInitialCondition::Type::ConstantLevelNoVelocity );

coreModule->saveProject( projectDir.filePath( "telemac_model" ) );
Expand All @@ -226,6 +233,31 @@ void ReosTelemacTesting::buildStructure()
QVERIFY( result );
QCOMPARE( result->groupCount(), 3 );
QCOMPARE( result->datasetCount( 0 ), 13 );

telemacSim->setInitialCondition( ReosTelemac2DInitialCondition::Type::LastTimeStep );
simData = hydraulicStructure->simulationData( scheme->id(), message );
QVERIFY( message.type == ReosModule::Simple );
QCOMPARE( simData.waterDepthIniLocation, ReosSimulationData::Vertex );
QCOMPARE( simData.waterLevelIniLocation, ReosSimulationData::Vertex );
QCOMPARE( simData.velocityIniLocation, ReosSimulationData::Vertex );
QCOMPARE( simData.waterLevelIni.count(), vertexCount );
QCOMPARE( simData.waterDepthIni.count(), vertexCount );
QCOMPARE( simData.velocityIni.count(), vertexCount * 2 );
for ( int vi = 0; vi < vertexCount; ++vi )
{
QVERIFY( simData.waterLevelIni.at( vi ) <= 4 && simData.waterLevelIni.at( vi ) >= 1.95 );
QVERIFY( simData.waterDepthIni.at( vi ) <= 4 && simData.waterDepthIni.at( vi ) >= 1.95 );
QVERIFY( simData.velocityIni.at( vi ) != 0 );
}

coreModule->saveProject( projectDir.filePath( "telemac_model" ) );
QVERIFY( hydraulicStructure->runSimulation( coreModule->hydraulicNetwork()->currentScheme()->calculationContext() ) );

QVERIFY( hydraulicStructure->hasResults() );
result = hydraulicStructure->results( coreModule->hydraulicNetwork()->currentScheme() );
QVERIFY( result );
QCOMPARE( result->groupCount(), 3 );
QCOMPARE( result->datasetCount( 0 ), 13 );
}

QTEST_MAIN( ReosTelemacTesting )
Expand Down
13 changes: 7 additions & 6 deletions src/core/hydraulicNetwork/reoshydraulicstructure2d.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -727,7 +727,7 @@ QString ReosHydraulicStructure2D::meshDatasetName( const QString &id ) const
return QString();
}

ReosSimulationPreparationProcess *ReosHydraulicStructure2D::getPreparationProcessSimulation( const ReosCalculationContext &context, ReosModule::Message &message )
ReosSimulationPreparationProcess *ReosHydraulicStructure2D::getPreparationProcessSimulation( const ReosSimulationData &simData, const ReosCalculationContext &context, ReosModule::Message &message )
{
if ( mMeshNeedToBeGenerated )
{
Expand All @@ -748,12 +748,12 @@ ReosSimulationPreparationProcess *ReosHydraulicStructure2D::getPreparationProces
return nullptr;
}

return new ReosSimulationPreparationProcess( this, currentSimulation(), context, message );
return new ReosSimulationPreparationProcess( this, currentSimulation(), simData, context );
}

ReosSimulationPreparationProcess *ReosHydraulicStructure2D::getPreparationProcessSimulation( const ReosCalculationContext &context, ReosModule::Message &message, const QDir &directory )
ReosSimulationPreparationProcess *ReosHydraulicStructure2D::getPreparationProcessSimulation( const ReosSimulationData &simData, const ReosCalculationContext &context, ReosModule::Message &message, const QDir &directory )
{
std::unique_ptr<ReosSimulationPreparationProcess> ret( getPreparationProcessSimulation( context, message ) );
std::unique_ptr<ReosSimulationPreparationProcess> ret( getPreparationProcessSimulation( simData, context, message ) );
ret->setDestination( directory );
return ret.release();
}
Expand Down Expand Up @@ -831,6 +831,7 @@ bool ReosHydraulicStructure2D::runSimulation( const ReosCalculationContext &cont
txtStream << QStringLiteral( "*********************************************************************************" ) << Qt::endl;

ReosModule::Message message;
const ReosSimulationData simData = simulationData( context.schemeId(), message );

removeResults( context );
updateResults( context.schemeId() );
Expand All @@ -847,7 +848,7 @@ bool ReosHydraulicStructure2D::runSimulation( const ReosCalculationContext &cont
}

txtStream << tr( "Start preparation of simulation" ) << Qt::endl;
std::unique_ptr<ReosSimulationPreparationProcess> preparationProcess( getPreparationProcessSimulation( context, message ) );
std::unique_ptr<ReosSimulationPreparationProcess> preparationProcess( getPreparationProcessSimulation( simData, context, message ) );
if ( !preparationProcess )
{
txtStream << tr( "Simulation did not start for following reason:\n\n%1" ).arg( message.text ) << Qt::endl;
Expand Down Expand Up @@ -1259,7 +1260,7 @@ ReosSimulationData ReosHydraulicStructure2D::simulationData( const QString &sche
{
ReosHydraulicSimulation *sim = simulation( scheme );
if ( sim )
message = sim->prepareSimulationData( ret );
message = sim->prepareSimulationData( ret, schemeId );
}
else
{
Expand Down
4 changes: 2 additions & 2 deletions src/core/hydraulicNetwork/reoshydraulicstructure2d.h
Original file line number Diff line number Diff line change
Expand Up @@ -193,10 +193,10 @@ class REOSCORE_EXPORT ReosHydraulicStructure2D : public ReosHydraulicNetworkElem
//**************************** Calculation process related methods

//! Returns a process that prepare the current simulation, caller take ownership
ReosSimulationPreparationProcess *getPreparationProcessSimulation( const ReosCalculationContext &context, ReosModule::Message &message );
ReosSimulationPreparationProcess *getPreparationProcessSimulation( const ReosSimulationData &simData, const ReosCalculationContext &context, ReosModule::Message &message );

//! Returns a process that prepare the current simulation files in a specific \a diectory, caller take ownership
ReosSimulationPreparationProcess *getPreparationProcessSimulation( const ReosCalculationContext &context, ReosModule::Message &message, const QDir &directory );
ReosSimulationPreparationProcess *getPreparationProcessSimulation( const ReosSimulationData &simData, const ReosCalculationContext &context, ReosModule::Message &message, const QDir &directory );

/**
* Creates a new simulation process and returns a pointer to the process, the process is not started.
Expand Down
10 changes: 6 additions & 4 deletions src/core/hydraulicNetwork/simulation/reoshydraulicsimulation.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -218,12 +218,14 @@ void ReosSimulationEngineRegistery::loadDynamicLibrary()
}
}

ReosSimulationPreparationProcess::ReosSimulationPreparationProcess( ReosHydraulicStructure2D *hydraulicStructure,
ReosHydraulicSimulation *simulation,
const ReosCalculationContext &context, ReosModule::Message &message )
ReosSimulationPreparationProcess::ReosSimulationPreparationProcess(
ReosHydraulicStructure2D *hydraulicStructure,
ReosHydraulicSimulation *simulation,
const ReosSimulationData &simData,
const ReosCalculationContext &context )
: mStructure( hydraulicStructure )
, mSimulation( simulation )
, mSimulationData( hydraulicStructure->simulationData( context.schemeId(), message ) )
, mSimulationData( simData )
, mContext( context )
, mHasMesh( mStructure->mesh()->faceCount() != 0 )
{}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,8 +77,8 @@ class REOSCORE_EXPORT ReosSimulationPreparationProcess: public ReosProcess

ReosSimulationPreparationProcess( ReosHydraulicStructure2D *hydraulicStructure,
ReosHydraulicSimulation *simulation,
const ReosCalculationContext &context,
ReosModule::Message &message );
const ReosSimulationData &simData,
const ReosCalculationContext &context );

void setDestination( const QDir &destination );
void start() override;
Expand Down Expand Up @@ -148,7 +148,7 @@ class REOSCORE_EXPORT ReosHydraulicSimulation : public ReosDataObject SIP_ABSTRA
virtual QString key() const = 0;
virtual ReosEncodedElement encode() const = 0 SIP_SKIP;

virtual ReosModule::Message prepareSimulationData( ReosSimulationData &simData ) = 0 SIP_SKIP;
virtual ReosModule::Message prepareSimulationData( ReosSimulationData &simData, const QString &schemeId ) = 0 SIP_SKIP;

virtual void prepareInput( const ReosSimulationData &simulationData, const ReosCalculationContext &calculationContext ) = 0 SIP_SKIP;

Expand Down Expand Up @@ -309,7 +309,7 @@ class REOSCORE_EXPORT ReosHydraulicSimulationDummy : public ReosHydraulicSimulat
virtual QString key() const override {return QStringLiteral( "dummy-simulation" );}
virtual ReosEncodedElement encode() const override {return ReosEncodedElement();};

ReosModule::Message prepareSimulationData( ReosSimulationData & ) override {return ReosModule::Message();}
ReosModule::Message prepareSimulationData( ReosSimulationData &, const QString & ) override {return ReosModule::Message();}

virtual void prepareInput( const ReosSimulationData &, const ReosCalculationContext & ) override {};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -422,18 +422,28 @@ void ReosHydraulicStructure2DProperties::onLaunchCalculation()
return;
}

ReosModule::Message message;
const ReosSimulationData simData = mStructure2D->simulationData( mCalculationContext.schemeId(), message );

if ( message.type == ReosModule::Error )
{
QMessageBox::warning( this, tr( "Run Simulation" ), tr( "Simulation did not start for following reason:\n\n%1" ).arg( message.text ) );
emit mStructure2D->network()->emitMessage( message, false );
return;
}

mStructure2D->removeResults( mCalculationContext );
mStructure2D->updateResults( mCalculationContext.schemeId() );

ReosHydraulicScheme *scheme = mStructure2D->network()->scheme( mCalculationContext.schemeId() );
mStructure2D->currentSimulation()->saveConfiguration( scheme );

ReosModule::Message message;
std::unique_ptr<ReosSimulationPreparationProcess> preparationProcess( mStructure2D->getPreparationProcessSimulation( mCalculationContext, message ) );

std::unique_ptr<ReosSimulationPreparationProcess> preparationProcess( mStructure2D->getPreparationProcessSimulation( simData, mCalculationContext, message ) );
if ( !preparationProcess )
{
QMessageBox::warning( this, tr( "Run Simulation" ), tr( "Simulation did not start for following reason:\n\n%1" ).arg( message.text ) );
emit mStructure2D->network()->emitMessage( message, false );
return;
}

Expand Down Expand Up @@ -471,14 +481,22 @@ void ReosHydraulicStructure2DProperties::onLaunchCalculation()
void ReosHydraulicStructure2DProperties::onExportSimulation()
{
const QString dirPath = QFileDialog::getExistingDirectory( this, "Export Simulation File", QString(), QFileDialog::ShowDirsOnly );

const QDir dir( dirPath );

ReosModule::Message message;
std::unique_ptr<ReosProcess> preparationProcess( mStructure2D->getPreparationProcessSimulation( mCalculationContext, message, dir ) );
const ReosSimulationData simData = mStructure2D->simulationData( mCalculationContext.schemeId(), message );
if ( message.type == ReosModule::Error )
{
QMessageBox::warning( this, tr( "Run Simulation" ), tr( "Simulation did not start for following reason:\n\n%1" ).arg( message.text ) );
emit mStructure2D->network()->emitMessage( message, false );
return;
}

std::unique_ptr<ReosProcess> preparationProcess( mStructure2D->getPreparationProcessSimulation( simData, mCalculationContext, message, dir ) );
if ( !preparationProcess )
{
QMessageBox::warning( this, tr( "Export Simulation" ), tr( "Simulation can't be exported for following reason:\n\n%1" ).arg( message.text ) );
emit mStructure2D->network()->emitMessage( message, false );
return;
}
ReosProcessControler *controler = new ReosProcessControler( preparationProcess.get(), this );
Expand Down
2 changes: 1 addition & 1 deletion src/simulationEngines/hecras/reoshecrassimulation.h
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ class ReosHecRasSimulation : public ReosHydraulicSimulation

QString key() const override;

ReosModule::Message prepareSimulationData( ReosSimulationData &simData ) override {return ReosModule::Message();}
ReosModule::Message prepareSimulationData( ReosSimulationData &simData, const QString &schemeId ) override {return ReosModule::Message();}

void prepareInput( const ReosSimulationData &data, const ReosCalculationContext &calculationContext ) override;
void prepareInput( const ReosSimulationData &, const ReosCalculationContext &, const QDir & ) override {}
Expand Down
28 changes: 25 additions & 3 deletions src/simulationEngines/telemac/reostelemac2dinitialcondition.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,6 @@ ReosTelemac2DInitialConstantWaterLevel::ReosTelemac2DInitialConstantWaterLevel(
: ReosTelemac2DInitialCondition( element, parent )
{
mInitialWaterLevel = new ReosParameterDouble( tr( "Initial water level" ), false, this );
ReosDataObject::decode( element );
}

ReosEncodedElement ReosTelemac2DInitialConstantWaterLevel::encode() const
Expand All @@ -80,7 +79,6 @@ ReosTelemac2DInitialConditionFromSimulation::ReosTelemac2DInitialConditionFromSi
ReosTelemac2DInitialConditionFromSimulation::ReosTelemac2DInitialConditionFromSimulation( const ReosEncodedElement &element, QObject *parent )
: ReosTelemac2DInitialCondition( parent )
{
ReosDataObject::decode( element );
}

ReosEncodedElement ReosTelemac2DInitialConditionFromSimulation::encode() const
Expand Down Expand Up @@ -152,7 +150,6 @@ ReosTelemac2DInitialConditionFromInterpolation::ReosTelemac2DInitialConditionFro
{
mFirstValue = new ReosParameterDouble( tr( "First water level value" ), false, this );
mSecondValue = new ReosParameterDouble( tr( "Second water level value" ), false, this );
ReosDataObject::decode( element );
}

ReosEncodedElement ReosTelemac2DInitialConditionFromInterpolation::encode() const
Expand Down Expand Up @@ -212,3 +209,28 @@ QString ReosTelemac2DInitialConditionFromInterpolation::crs() const
{
return mCrs;
}

ReosTelemac2DInitialConditionUseLastTimeStep::ReosTelemac2DInitialConditionUseLastTimeStep( QObject *parent )
: ReosTelemac2DInitialCondition( parent )
{
}

ReosTelemac2DInitialConditionUseLastTimeStep::ReosTelemac2DInitialConditionUseLastTimeStep( const ReosEncodedElement &element, QObject *parent )
: ReosTelemac2DInitialCondition( parent )
{
}

ReosEncodedElement ReosTelemac2DInitialConditionUseLastTimeStep::encode() const
{
ReosEncodedElement element( QStringLiteral( "telemac-2d-initial-condition-last-time-step" ) );
ReosDataObject::encode( element );
return element;
}

void ReosTelemac2DInitialConditionUseLastTimeStep::saveConfiguration( ReosHydraulicScheme * ) const
{
}

void ReosTelemac2DInitialConditionUseLastTimeStep::restoreConfiguration( ReosHydraulicScheme * )
{
}
17 changes: 16 additions & 1 deletion src/simulationEngines/telemac/reostelemac2dinitialcondition.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,8 @@ class ReosTelemac2DInitialCondition: public ReosDataObject
{
FromOtherSimulation,
ConstantLevelNoVelocity,
Interpolation
Interpolation,
LastTimeStep
};

ReosTelemac2DInitialCondition( QObject *parent = nullptr );
Expand Down Expand Up @@ -116,5 +117,19 @@ class ReosTelemac2DInitialConditionFromInterpolation: public ReosTelemac2DInitia
QString mCrs;
};

class ReosTelemac2DInitialConditionUseLastTimeStep: public ReosTelemac2DInitialCondition
{
Q_OBJECT
public:
ReosTelemac2DInitialConditionUseLastTimeStep( QObject *parent = nullptr );
ReosTelemac2DInitialConditionUseLastTimeStep( const ReosEncodedElement &element, QObject *parent = nullptr );

Type initialConditionType() const override {return Type::LastTimeStep;}
ReosEncodedElement encode() const override;

void saveConfiguration( ReosHydraulicScheme *scheme ) const override;
void restoreConfiguration( ReosHydraulicScheme *scheme ) override;
};


#endif // REOSTELEMAC2DINITIALCONDITION_H
Loading

0 comments on commit a24b4c5

Please sign in to comment.