Add time stepper that allows OpenFOAM to control the time step so that CFL adaptive stepping can be used#48
Conversation
hsaunders1904
left a comment
There was a problem hiding this comment.
Looks good and getting OpenFOAM to do an extra synchronisation step seems reasonable to me. I haven't had a chance to do any manual testing yet, but I've left a few comments.
|
|
||
| /* | ||
| Time stepper that allows OpenFOAM to control the time step enabling features such as CFL | ||
| daptive time steps. the intention is to allows the current time step in OpenFOAM |
There was a problem hiding this comment.
| daptive time steps. the intention is to allows the current time step in OpenFOAM | |
| adaptive time steps. The intention is to allows the current time step in OpenFOAM |
| if (deltaT >= Foam::rootVGreat) | ||
| mooseError("Computed OpenFOAM time step must be less that rootVGreat"); |
There was a problem hiding this comment.
In what scenario would deltaT be greater than rootVGreat? Could we consider clipping the value to rootVGreat? A comment here explaining what's gone on and why an error is the best way to deal with this case, would be helpful.
Might also be nice for the user if the values of deltaT and rootVGreat were included in this error message.
There was a problem hiding this comment.
I should probs add some more comments, but this is taken from OpenFOAM (need to remember where). But in some cases (like the buoyancy case), the deltaT becomes huge with adaptive time stepping on the first time step. I think rootVGreat is like 1e158, so I think if it suggests that we probs want the user to reconsider. I can add those numbers to the error.
| for t in 0.4 0.8 1 1.4 1.8 2 2.4 2.8 3; do | ||
| if ! [ -d "${CASE_DIR}/$t" ]; then | ||
| echo "Error for t=$t" | ||
| exit 1 | ||
| fi | ||
| done |
There was a problem hiding this comment.
This checks we have the directories we want. Should we also check that time directories we don't want, do not exist?
Maybe we can count the number of time directories and make sure that's correct as well? Something like find buoyantCavity -maxdepth 1 -type d | grep -E '/[0-9]+(\.[0-9]+)?$' | wc -l will count the number of time directories.
There was a problem hiding this comment.
Makes sense
| #include "InputParameters.h" | ||
|
|
There was a problem hiding this comment.
This is a MOOSE include so should go in the include block below and use <> brackets.
I should have documented the include conventions for the repo (my bad). But Hippo includes are first (using ""). Then third party includes (so MOOSE/OpenFOAM, using <>), then standard library includes (using <>). Not massively important, but it keeps things organised and easy to parse by eye.
| #include "InputParameters.h" | |
| #include <InputParameters.h> |
| #include "scalar.H" | ||
|
|
There was a problem hiding this comment.
| #include "scalar.H" | |
| #include <scalar.H> |
|
@hsaunders1904 An additional concern atm is that an addition time is inserted by MOOSE on the OpenFOAM solve based on FoamSolver::synchronizeAdaptiveTimes(double dt)
{
double foam_dt = runTime().deltaTValue();
if (std::abs(dt - foam_dt) > 1e-6)
{
runTime().setDeltaTNoAdjust(dt);
}
}Here |
Where are you calling |
|
@hsaunders1904 It's called in the |
|
Remind me where |
That should be doable |
|
|
The is issue is that it must be called after |
|
@hsaunders1904 I have just shown another way of doing this using OpenFOAM's function objects. It means that information about the timestep doesn't need to be passed through |
hsaunders1904
left a comment
There was a problem hiding this comment.
From what I can work out, this looks good. I haven't quite got my head around how the functionObject is solving the problem we had, yet. But I probably just need to spend a bit more time looking at it.
|
|
||
| /* | ||
| Time stepper that allows OpenFOAM to control the time step enabling features such as CFL | ||
| daptive time steps. The intention is to allows the current time step in OpenFOAM |
There was a problem hiding this comment.
| daptive time steps. The intention is to allows the current time step in OpenFOAM | |
| adaptive time steps. The intention is to allow the current time step in OpenFOAM |
There was a problem hiding this comment.
This comment/docstring should probably be just above FoamControlledTimeStepper's definition
| // Not ideal, but for MOOSE to get an accurate deltaT | ||
| // preSolve must be called as this updates the BCs. | ||
| Foam::solver & foam_solver{solver().solver()}; | ||
| Foam::pimpleSingleRegionControl pimple(foam_solver.pimple); | ||
|
|
||
| pimple.read(); | ||
| foam_solver.preSolve(); |
There was a problem hiding this comment.
I reckon this should probably be moved into a function in FoamSolver, then it's just solver()->preSolve() and we keep all the OpenFOAM stuff wrapped up behind an interface. I feel like that interface could become very useful when we start looking at getting Hippo working with OpenFOAM.com.
Also, doesn't the solver already have an associated pimple object (foam_solver.pimple)? Does foam_solver.pimple.readIfModified() work?
There was a problem hiding this comment.
I will do this, I think I will also create a FoamSolver::computeDeltaT function to hide the actual calculation of the OpenFOAM time step behind the interface
| _dt_adjustable = foam_solver.runTime.controlDict().lookupOrDefault("adjustTimeStep", false); | ||
|
|
||
| // Add functionObject that tells OpenFOAM what MOOSE's time step is. | ||
| // If MOOSE inserts a timestep the functionObjects.maxTime() with return |
There was a problem hiding this comment.
| // If MOOSE inserts a timestep the functionObjects.maxTime() with return | |
| // If MOOSE inserts a timestep then functionObjects.maxTime() will return |
There was a problem hiding this comment.
maxTime() or maxDeltaT()?
It is a little obscure, but the key idea is that |
Would be great to have this in a comment. Then I think we're good to go! |
|
@hsaunders1904 The comment has been added. I have also further attempted to improve the hiding of the gory OpenFOAM bits within |
hsaunders1904
left a comment
There was a problem hiding this comment.
Great to see this working! 🚀
This isn't for this PR, but would the old FoamTimestepper also benefit from using your new functionObject? The problem that #42 aimed to solve is still around
Summary
Implements
FoamControlledTimeStepperwhich allows OpenFOAM to control the time step with MOOSE inserting time steps for sub-cycling synchronisation. Currently,synchronizeAdaptiveTimesis added toFoamSolverand called during run to ensure the MOOSE time and OF time is synchronised. However, it is not clear if this is the best design choice.Related Issue
This should at least partially resolves #28
Checklist
maxDeltaTfunction object be modified).dtare passed to the executioner.