From 99421f77f85e91262f921cf0bbdc3724d0a9cb20 Mon Sep 17 00:00:00 2001 From: David Schneider Date: Tue, 28 Nov 2023 10:34:05 +0100 Subject: [PATCH] Re arrange read time according to adjustable dt (#298) Co-authored-by: Gerasimos Chourdakis --- Adapter.C | 30 +++++++++++++++--------------- Adapter.H | 3 ++- changelog-entries/298.md | 1 + 3 files changed, 18 insertions(+), 16 deletions(-) create mode 100644 changelog-entries/298.md diff --git a/Adapter.C b/Adapter.C index f49f8f80..b92f3d00 100644 --- a/Adapter.C +++ b/Adapter.C @@ -363,9 +363,6 @@ void preciceAdapter::Adapter::configure() // Initialize preCICE and exchange the first coupling data initialize(); - // Read the received coupling data - readCouplingData(runTime_.deltaT().value()); - // If checkpointing is required, specify the checkpointed fields // and write the first checkpoint if (requiresWritingCheckpoint()) @@ -382,7 +379,7 @@ void preciceAdapter::Adapter::configure() // Adjust the timestep for the first iteration, if it is fixed if (!adjustableTimestep_) { - adjustSolverTimeStep(); + adjustSolverTimeStepAndReadData(); } // If the solver tries to end before the coupling is complete, @@ -443,12 +440,6 @@ void preciceAdapter::Adapter::execute() readCheckpoint(); } - // Adjust the timestep, if it is fixed - if (!adjustableTimestep_) - { - adjustSolverTimeStep(); - } - // Write checkpoint if required if (requiresWritingCheckpoint()) { @@ -476,9 +467,11 @@ void preciceAdapter::Adapter::execute() } ACCUMULATE_TIMER(timeInWriteResults_); - // Read the received coupling data from the buffer - // Fits to an implicit Euler - readCouplingData(runTime_.deltaT().value()); + // Adjust the timestep, if it is fixed + if (!adjustableTimestep_) + { + adjustSolverTimeStepAndReadData(); + } // If the coupling is not going to continue, tear down everything // and stop the simulation. @@ -507,9 +500,10 @@ void preciceAdapter::Adapter::execute() return; } + void preciceAdapter::Adapter::adjustTimeStep() { - adjustSolverTimeStep(); + adjustSolverTimeStepAndReadData(); return; } @@ -599,7 +593,7 @@ void preciceAdapter::Adapter::advance() return; } -void preciceAdapter::Adapter::adjustSolverTimeStep() +void preciceAdapter::Adapter::adjustSolverTimeStepAndReadData() { DEBUG(adapterInfo("Adjusting the solver's timestep...")); @@ -695,6 +689,12 @@ void preciceAdapter::Adapter::adjustSolverTimeStep() // TODO: Keep this in mind if any relevant problem appears. const_cast(runTime_).setDeltaT(timestepSolver_, false); + DEBUG(adapterInfo("Reading coupling data associated to the calculated time-step size...")); + + // Read the received coupling data from the buffer + // Fits to an implicit Euler + readCouplingData(runTime_.deltaT().value()); + return; } diff --git a/Adapter.H b/Adapter.H index 2112898b..671c947f 100644 --- a/Adapter.H +++ b/Adapter.H @@ -271,7 +271,8 @@ private: void writeCouplingData(); //- Adjust the timestep of the solver according to preCICE - void adjustSolverTimeStep(); + // and read data associated to the calculated time step length + void adjustSolverTimeStepAndReadData(); //- Determine if the coupling is still happening bool isCouplingOngoing(); diff --git a/changelog-entries/298.md b/changelog-entries/298.md new file mode 100644 index 00000000..8163f04b --- /dev/null +++ b/changelog-entries/298.md @@ -0,0 +1 @@ +- Renamed the `adjustSolverTimeStep()` method to `adjustSolverTimeStepAndReadData()`, changing the behavior to always read data at the determined time step size. [#298](https://github.com/precice/openfoam-adapter/pull/298)