Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement a simulation clock type #858

Open
program-- opened this issue Jul 22, 2024 · 2 comments · May be fixed by #881
Open

Implement a simulation clock type #858

program-- opened this issue Jul 22, 2024 · 2 comments · May be fixed by #881
Labels
enhancement New feature or request

Comments

@program--
Copy link
Contributor

program-- commented Jul 22, 2024

Currently, across Data Providers and BMI instances, we're primarily using C time constructs.

Example

virtual long get_data_start_time() const = 0;
/** Return the last valid time for which data from the requested variable can be requested */
virtual long get_data_stop_time() const = 0;
/** Return the stride in the time dimension */
virtual long record_duration() const = 0;

time_t start_date_time_epoch;
time_t end_date_time_epoch;
time_t current_date_time_epoch;

However, in some recent changes, we've started using std::chrono types.

Example

clock_type::time_point time_begin_{};
//! Calendar time for simulation end
clock_type::time_point time_end_{};
//! Duration of a single simulation tick
clock_type::duration time_step_{};

One of the current issues with std::chrono clock types is that they either represent Unix time or relative time (though not clearly), and we have a use-case for representing both. A potential solution for this is to define our own clock type1, simulation_clock, as discussed here.

A benefit is that this would allow us to use std::chrono types while maintaining control of the simulation ticks however we see fit.

Footnotes

  1. https://en.cppreference.com/w/cpp/named_req/Clock

@program--
Copy link
Contributor Author

An attempt at fleshing out an interface similar to the discussed one in the above linked comment. However, unlike conventional chrono clocks, this implementation is a controlled clock, where simulation_clock::now() doesn't change unless simulation_clock::tick(...) is called.

https://github.com/program--/ngen/blob/8c21f8e3540942468b8126a01ce99da33c61e7fb/include/simulation_time/simulation_clock.hpp#L9-L123

@PhilMiller
Copy link
Contributor

The implementation you've drafted looks pretty good to me. May as well post it in a PR, and we can potentially start using it in the Forcings Engine and Coastal Formulation code that we're writing fresh.

@program-- program-- linked a pull request Sep 11, 2024 that will close this issue
10 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants