Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 18 additions & 3 deletions include/base/FoamSolver.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,17 @@ class mooseDeltaT : public functionObject
{
private:
const scalar & dt_;
bool alteredDt_;
const scalar deltaTFactor_;

public:
TypeName("mooseDeltaT")

mooseDeltaT(const word & name, const Time & runTime, const scalar & dt)
: functionObject(name, runTime), dt_(dt)
: functionObject(name, runTime),
dt_(dt),
alteredDt_(false),
deltaTFactor_(Foam::solver::deltaTFactor)
{
}

Expand All @@ -35,7 +40,17 @@ class mooseDeltaT : public functionObject

bool execute() { return true; }
bool write() { return true; }
scalar maxDeltaT() const { return dt_; }
void setAltered(bool altered) { alteredDt_ = altered; }
scalar maxDeltaT() const
{
// If MOOSE altered the previous time step this prevents the time step cut back affecting future
// time steps
if (alteredDt_)
Foam::solver::deltaTFactor = Foam::rootVGreat;
else
Foam::solver::deltaTFactor = deltaTFactor_;
return dt_;
}
};
}
}
Expand Down Expand Up @@ -67,7 +82,7 @@ class FoamSolver
bool isDeltaTAdjustable() const;
// creates function object that tells OpenFOAM what MOOSE's
// time step is.
void appendDeltaTFunctionObject(const Foam::scalar & dt);
Foam::functionObjects::mooseDeltaT * appendDeltaTFunctionObject(const Foam::scalar & dt);
// get the current deltaT.
Foam::scalar getTimeDelta() const { return runTime().deltaTValue(); }

Expand Down
40 changes: 0 additions & 40 deletions include/solvers/timesteppers/FoamTimeStepper.h

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,18 @@

#include <InputParameters.h>
#include <TimeStepper.h>
#include <memory>

/*
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
to be exposed to MOOSE
*/

class FoamControlledTimeStepper : public TimeStepper
class FoamTimeStepper : public TimeStepper
{
public:
FoamControlledTimeStepper(InputParameters const & params);
FoamTimeStepper(InputParameters const & params);
static InputParameters validParams();

// Get initial time step from OpenFOAM input file
Expand All @@ -38,5 +39,7 @@ class FoamControlledTimeStepper : public TimeStepper
// Variables to determine whether an adjustable time step is used in OF and
// what it is.
bool _dt_adjustable = false;
Real _foam_initial_dt = 0.;
Real _foam_dt = 0.;
Real _desired_dt;
Foam::functionObjects::mooseDeltaT * _moose_dt;
};
7 changes: 4 additions & 3 deletions src/base/FoamSolver.C
Original file line number Diff line number Diff line change
Expand Up @@ -167,10 +167,11 @@ FoamSolver::isDeltaTAdjustable() const
return _solver->runTime.controlDict().lookupOrDefault("adjustTimeStep", false);
}

void
Foam::functionObjects::mooseDeltaT *
FoamSolver::appendDeltaTFunctionObject(const Foam::scalar & dt)
{
runTime().functionObjects().append(
new Foam::functionObjects::mooseDeltaT("Moose time step", runTime(), dt));
auto moose_dt = new Foam::functionObjects::mooseDeltaT("Moose time step", runTime(), dt);
runTime().functionObjects().append(moose_dt);
return moose_dt;
}
} // namespace Hippo
82 changes: 0 additions & 82 deletions src/timesteppers/FoamControlledTimeStepper.C

This file was deleted.

84 changes: 65 additions & 19 deletions src/timesteppers/FoamTimeStepper.C
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
#include "FoamProblem.h"
#include "FoamTimeStepper.h"
#include <pimpleSingleRegionControl.H>

#include <scalar.H>
#include <TimeStepper.h>
#include <Transient.h>
#include <solver.H>

registerMooseObject("hippoApp", FoamTimeStepper);

Expand All @@ -13,7 +16,8 @@ FoamTimeStepper::validParams()
return params;
}

FoamTimeStepper::FoamTimeStepper(InputParameters const & params) : TimeStepper(params)
FoamTimeStepper::FoamTimeStepper(InputParameters const & params)
: TimeStepper(params), _foam_dt{}, _desired_dt{}, _moose_dt(nullptr)
{
auto problem = dynamic_cast<FoamProblem *>(&_app.feProblem());
if (!problem)
Expand All @@ -22,28 +26,34 @@ FoamTimeStepper::FoamTimeStepper(InputParameters const & params) : TimeStepper(p
}
}

Real
FoamTimeStepper::computeInitialDT()
{
auto dt = _executioner.parameters().get<double>("dt");
solver().setTimeDelta(_dt);
return dt;
}

Real
FoamTimeStepper::computeDT()
{
solver().setTimeDelta(_dt);
return _dt;
}

void
FoamTimeStepper::init()
{
TimeStepper::init();
solver().setCurrentTime(_time);
solver().setEndTime(_end_time);
solver().setTimeDelta(_dt);
if (!_dt_adjustable)
return _foam_dt;

// Not ideal, but for MOOSE to get an accurate deltaT
// preSolve must be called as this updates the BCs.
solver().preSolve();

// Tells mooseDelta function object to prevent the time step being cutback at the next step if the
// previous one was cut back by MOOSE. THis again is pretty horrific but needs must.
if (solver().getTimeDelta() != _desired_dt)
_moose_dt->setAltered(true);
else
_moose_dt->setAltered(false);

// Ensure MOOSE gets OpenFOAM's time step unaffected by the mooseDeltaT
// functionObject.
Real dt_tmp = _dt;
_dt = Foam::rootVGreat;

// compute OpenFOAM's desired time step
_desired_dt = solver().computeDeltaT();
// reset MOOSE's time step and return
_dt = dt_tmp;
return _desired_dt;
}

FoamProblem *
Expand All @@ -56,3 +66,39 @@ FoamTimeStepper::problem()
}
return problem;
}

void
FoamTimeStepper::init()
{
TimeStepper::init();

// Apply start time from input file if it is present
if (_executioner.isParamSetByUser("start_time"))
solver().setCurrentTime(_time);

// Apply end time from input file if it is present
if (_executioner.isParamSetByUser("end_time"))
solver().setEndTime(_end_time);

if (_executioner.isParamSetByUser("dt"))
{
_foam_dt = _executioner.getParam<Real>("dt");
_dt_adjustable = false;
solver().setTimeDelta(_foam_dt);
return;
}
// determine if OpenFOAM's time-step is adjustable in controlDict
_dt_adjustable = solver().isDeltaTAdjustable();

// The key idea is that runTime.functionObjects().maxDeltaT() in adjustDeltaT
// loops over the function objects and chooses the minimum, so by having
// a function Object that returns what MOOSE wants, OpenFOAM will use the
// MOOSE time step if it is smaller than what OpenFOAM wants. As a result,
// if MOOSE wants to add a synchronisation step OpenFOAM will also use it too.

// create function object and append it to the solver's function object list
_moose_dt = solver().appendDeltaTFunctionObject(_dt);
_desired_dt = solver().getTimeDelta();
if (!_dt_adjustable)
_foam_dt = solver().getTimeDelta();
}
2 changes: 1 addition & 1 deletion test/tests/actions/foam_bc/main.i
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@
end_time = 1
[TimeSteppers]
[foam]
type = FoamControlledTimeStepper
type = FoamTimeStepper
[]
[]
[]
Expand Down
2 changes: 1 addition & 1 deletion test/tests/actions/foam_variable/main.i
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
end_time = 0.32
[TimeSteppers]
[foam]
type = FoamControlledTimeStepper
type = FoamTimeStepper
[]
[]
[]
Expand Down
2 changes: 1 addition & 1 deletion test/tests/bcs/fixed_value/main.i
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@
end_time = 0.32
[TimeSteppers]
[foam]
type = FoamControlledTimeStepper
type = FoamTimeStepper
[]
[]
[]
Expand Down
2 changes: 1 addition & 1 deletion test/tests/bcs/laplace_fixed_gradient/main.i
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@
end_time = 32
[TimeSteppers]
[foam]
type = FoamControlledTimeStepper
type = FoamTimeStepper
[]
[]
[]
Expand Down
2 changes: 1 addition & 1 deletion test/tests/fixed-point/flow_over_heated_plate/fluid.i
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
type = Transient
[TimeSteppers]
[foam]
type = FoamControlledTimeStepper
type = FoamTimeStepper
[]
[]
[]
Expand Down
2 changes: 1 addition & 1 deletion test/tests/fixed-point/heated_plate_converge/fluid.i
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
type = Transient
[TimeSteppers]
[foam]
type = FoamControlledTimeStepper
type = FoamTimeStepper
[]
[]
[]
Expand Down
2 changes: 1 addition & 1 deletion test/tests/fixed-point/restart_heated_plate/fluid.i
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
type = Transient
[TimeSteppers]
[foam]
type = FoamControlledTimeStepper
type = FoamTimeStepper
[]
[]
[]
Expand Down
Loading