Skip to content
Closed
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
12 changes: 12 additions & 0 deletions components/omega/src/ocn/OceanDriver.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@

#include "Config.h"
#include "TimeMgr.h"
#include "TimeStepper.h"

#include "mpi.h"

Expand All @@ -25,6 +26,14 @@ bool printTimingAllRanks();
/// for each Omega module
int ocnInit(MPI_Comm Comm);

/// Initialize Omega with coupler provided parameters
int ocnInit(MPI_Comm Comm, ///< [in] ocean MPI communicator
const int OcnId, ///< [in] mct comp id for ocean
const std::string &ConfigFile, ///< [in] path to yaml config file
const std::string &LogFile, ///< [in] path to log file
const TimeInstant &StartTime ///< [in] simulation start time
);

/// Advance the model from starting from CurrTime until EndAlarm rings
int ocnRun(TimeInstant &CurrTime);

Expand All @@ -34,6 +43,9 @@ int ocnFinalize(const TimeInstant &CurrTime);
/// Initialize Omega modules needed to run ocean model
int initOmegaModules(MPI_Comm Comm);

/// Initialize Omega modules with coupler-provided time parameters
int initOmegaModules(MPI_Comm Comm, const TimeInitParams &TParams);

} // end namespace OMEGA

//===----------------------------------------------------------------------===//
Expand Down
55 changes: 49 additions & 6 deletions components/omega/src/ocn/OceanInit.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -106,15 +106,48 @@ int ocnInit(MPI_Comm Comm ///< [in] ocean MPI communicator

} // end ocnInit

int ocnInit(MPI_Comm Comm, ///< [in] ocean MPI communicator
const int OcnId, ///< [in] mct comp id for ocean
const std::string &ConfigFile, ///< [in] path to yaml config file
const std::string &LogFile, ///< [in] path to log file
const TimeInstant &StartTime ///< [in] simulation start time
) {

I4 Err = 0; // return error code

// Init the default machine environment based on input MPI communicator
MachEnv::init(Comm);
MachEnv *DefEnv = MachEnv::getDefault();

// Initialize Omega logging with coupler provided log file name
initLogging(DefEnv, LogFile);

// Read config file into Config object
Config("Omega");
Config::readAll(ConfigFile);
Config *OmegaConfig = Config::getOmegaConfig();

readTimingConfig();

// coupler decides the stop time
TimeInitParams TimeParams{StartTime, std::nullopt};

// initialize remaining Omega modules
Err = initOmegaModules(Comm, TimeParams);
if (Err != 0)
ABORT_ERROR("ocnInit: Error initializing Omega modules");

return Err;

} // end ocnInit

// Call init routines for remaining Omega modules
int initOmegaModules(MPI_Comm Comm) {
// Internal helper — all module init after TimeStepper::init1 is called.
// Called by both initOmegaModules overloads.
static int initOmegaModulesImpl(MPI_Comm Comm) {

// error and return codes
int Err = 0;

// Initialize the default time stepper (phase 1) that includes the
// calendar, model clock and start/stop times and alarms
TimeStepper::init1();
TimeStepper *DefStepper = TimeStepper::getDefault();
Clock *ModelClock = DefStepper->getClock();

Expand Down Expand Up @@ -212,7 +245,17 @@ int initOmegaModules(MPI_Comm Comm) {

return Err;

} // end initOmegaModules
} // end initOmegaModulesImpl

int initOmegaModules(MPI_Comm Comm) {
TimeStepper::init1();
return initOmegaModulesImpl(Comm);
}

int initOmegaModules(MPI_Comm Comm, const TimeInitParams &TParams) {
TimeStepper::init1(TParams);
return initOmegaModulesImpl(Comm);
}

} // end namespace OMEGA
//===----------------------------------------------------------------------===//
3 changes: 3 additions & 0 deletions components/omega/src/ocn/OceanRun.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,9 @@ int ocnRun(TimeInstant &CurrTime ///< [inout] current sim time
OceanState *DefOceanState = OceanState::getDefault();
TimeStepper *DefTimeStepper = TimeStepper::getDefault();

// EndAlarm must be set before calling ocnRun
OMEGA_REQUIRE(DefTimeStepper->hasEndAlarm(), "ocnRun: no EndAlarm");

// get simulation time and other time info
Clock *OmegaClock = DefTimeStepper->getClock();
Alarm *EndAlarm = DefTimeStepper->getEndAlarm();
Expand Down
10 changes: 5 additions & 5 deletions components/omega/src/timeStepping/ForwardBackwardStepper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,12 @@ namespace OMEGA {
// Mostly passes relevant info to the base constructor.
ForwardBackwardStepper::ForwardBackwardStepper(
const std::string &InName, ///< [in] name of time stepper
const TimeInterval &InTimeStep, ///< [in] time step
const TimeInstant &InStartTime, ///< [in] start time for time stepping
const TimeInstant &InStopTime, ///< [in] stop time for time stepping
const TimeInterval &InTimeStep ///< [in] time step
)
: TimeStepper(InName, TimeStepperType::ForwardBackward, 2, InStartTime,
InStopTime, InTimeStep) {}
///< [in] stop time for time stepping, missing in coupled mode
std::optional<TimeInstant> InStopTime)
: TimeStepper(InName, TimeStepperType::ForwardBackward, 2, InTimeStep,
InStartTime, InStopTime) {}

//------------------------------------------------------------------------------
// Advance the state by one step of the forward-backward scheme
Expand Down
6 changes: 3 additions & 3 deletions components/omega/src/timeStepping/ForwardBackwardStepper.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,10 @@ class ForwardBackwardStepper : public TimeStepper {
/// fills with some time information. Data pointers are added later.
ForwardBackwardStepper(
const std::string &InName, ///< [in] name of time stepper
const TimeInterval &InTimeStep, ///< [in] time step
const TimeInstant &InStartTime, ///< [in] start time for time stepping
const TimeInstant &InStopTime, ///< [in] stop time for time stepping
const TimeInterval &InTimeStep ///< [in] time step
);
///< [in] stop time for time stepping, missing in coupled mode
std::optional<TimeInstant> InStopTime = std::nullopt);

/// Advance the state by one step of the forward-backward scheme
void doStep(OceanState *State, ///< [inout] model state
Expand Down
10 changes: 5 additions & 5 deletions components/omega/src/timeStepping/RungeKutta2Stepper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,12 @@ namespace OMEGA {
// Mostly just passes info to the base constructor.
RungeKutta2Stepper::RungeKutta2Stepper(
const std::string &InName, ///< [in] name of time stepper
const TimeInterval &InTimeStep, ///< [in] time step
const TimeInstant &InStartTime, ///< [in] start time for time stepping
const TimeInstant &InStopTime, ///< [in] stop time for time stepping
const TimeInterval &InTimeStep ///< [in] time step
)
: TimeStepper(InName, TimeStepperType::RungeKutta2, 2, InStartTime,
InStopTime, InTimeStep) {}
///< [in] stop time for time stepping, missing in coupled mode
std::optional<TimeInstant> InStopTime)
: TimeStepper(InName, TimeStepperType::RungeKutta2, 2, InTimeStep,
InStartTime, InStopTime) {}

//------------------------------------------------------------------------------
// Advance the state by one step of the midpoint Runge Kutta scheme
Expand Down
6 changes: 3 additions & 3 deletions components/omega/src/timeStepping/RungeKutta2Stepper.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,10 @@ class RungeKutta2Stepper : public TimeStepper {
/// fills with some time information. Data pointers are added later.
RungeKutta2Stepper(
const std::string &InName, ///< [in] name of time stepper
const TimeInterval &InTimeStep, ///< [in] time step
const TimeInstant &InStartTime, ///< [in] start time for time stepping
const TimeInstant &InStopTime, ///< [in] stop time for time stepping
const TimeInterval &InTimeStep ///< [in] time step
);
///< [in] stop time for time stepping, missing in coupled mode
std::optional<TimeInstant> InStopTime = std::nullopt);

/// Advance the state by one step of the midpoint Runge Kutta scheme
void doStep(OceanState *State, ///< [inout] model state
Expand Down
10 changes: 5 additions & 5 deletions components/omega/src/timeStepping/RungeKutta4Stepper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,12 @@ namespace OMEGA {
// Uses the base constructor and adds some coefficients.
RungeKutta4Stepper::RungeKutta4Stepper(
const std::string &InName, ///< [in] name of time stepper
const TimeInterval &InTimeStep, ///< [in] time step
const TimeInstant &InStartTime, ///< [in] start time for time stepping
const TimeInstant &InStopTime, ///< [in] stop time for time stepping
const TimeInterval &InTimeStep ///< [in] time step
)
: TimeStepper(InName, TimeStepperType::RungeKutta4, 2, InStartTime,
InStopTime, InTimeStep) {
///< [in] stop time for time stepping, missing in coupled mode
std::optional<TimeInstant> InStopTime)
: TimeStepper(InName, TimeStepperType::RungeKutta4, 2, InTimeStep,
InStartTime, InStopTime) {

RKA[0] = 0;
RKA[1] = 1. / 2;
Expand Down
6 changes: 3 additions & 3 deletions components/omega/src/timeStepping/RungeKutta4Stepper.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,10 @@ class RungeKutta4Stepper : public TimeStepper {
/// fills with some time information. Data pointers are added later.
RungeKutta4Stepper(
const std::string &InName, ///< [in] name of time stepper
const TimeInterval &InTimeStep, ///< [in] time step
const TimeInstant &InStartTime, ///< [in] start time for time stepping
const TimeInstant &InStopTime, ///< [in] stop time for time stepping
const TimeInterval &InTimeStep ///< [in] time step
);
///< [in] stop time for time stepping, missing in coupled mode
std::optional<TimeInstant> InStopTime = std::nullopt);

/// Advance the state by one step of the fourth-order Runge Kutta scheme
void doStep(OceanState *State, ///< [inout] model state
Expand Down
Loading
Loading