precice / openfoam-adapter

OpenFOAM-preCICE adapter
https://precice.org/adapter-openfoam-overview.html
GNU General Public License v3.0
134 stars 77 forks source link

Wrong time-step value read by precice.advance when using the "first-participant" method in seriel-explicit coupling for OpenFOAM #307

Closed mokerren closed 4 months ago

mokerren commented 8 months ago

I am trying to use it for a coupling between openFoam 8 and my own code of structure. I use the seriel-explicit coupling scheme and "first-participant" (Fluid part) for the time window size. My plan is to first calculate the fluid part and use the same time step for the structure part. I thought this should be done by using dt = precice.advanc() in my structure code. However, I found this commond does not give the correct time step that was used by the fluid, they are very close though. I am using adjustable time step in the openfoam. image

I am new to both preCICE and openFoam and not familar with the laguage C++. I used a not so smart way to debug by displaying the value of runTime.deltaT().value() at different code lines and turns out that its value changes. For example, if I dislay it in the follow code in Adapter.C, its value is the one used by structure code, namely 1.43988e-05. But its value is 1.43971e-05 at other places.

void preciceAdapter::Adapter::setTimeStep()
{
    std::cout <<runTime_.deltaT().value();
    adjustSolverTimeStep();

    return;
}

I appologize if the content I provided is not in a good format or it is not adequat for open an issue. But I believe preCICE is a wonderful tool and hope that my experience could make contribution to the improvement. Test1.zip Allwmake.log ldd.log wmake.log

mokerren commented 4 months ago

The problem is solved. I thought that with the method of "first-participant" the procedure is that the openfoam conducts calculation first and then pass the timestep that it used to the structure code. This assumption is wrong. The timestep is passed to the structure code before the openFoam actually making the calculation. Therefore, if the writecontrol is set as "adjustableRunTime", it will modify the timestep used by the openFoam to make sure that the output will be wrote at the excat time points. Then, the actual time step used by the openFoam is different from the one used by the structure code. So, after I change the writecontrol to "RunTime", the problem is solved.