Loading include/utopia/core/model.hh +6 −0 Original line number Diff line number Diff line Loading @@ -458,10 +458,16 @@ public: ); if constexpr (_write_mode == WriteMode::basic) { if (_time_max == std::numeric_limits<hsize_t>::max()) { return std::numeric_limits<hsize_t>::max(); } return ( (_time_max - std::max(_time, _write_start)) / _write_every) + 1; } else if constexpr (_write_mode == WriteMode::manual) { if (_time_max - _time == std::numeric_limits<hsize_t>::max()) { return std::numeric_limits<hsize_t>::max(); } return _time_max - _time + 1; } else { Loading test/core/model_nested_test.cc +36 −0 Original line number Diff line number Diff line Loading @@ -13,6 +13,7 @@ // +++ Fixtures +++ namespace tt = boost::test_tools; /// A specialized infrastructure fixture, loading a configuration file /** \note If no configuration file is required or available, you can Loading Loading @@ -104,6 +105,41 @@ BOOST_AUTO_TEST_CASE (test_iteration_order) BOOST_TEST(root.sub_another.another_lazy.get_time() == 20); // Check that in all models data was written log->debug("Asserting correct data-writing ..."); auto ext_root = root._dset_state->get_current_extent(); auto ext_r_s1 = root.sub_one._dset_state->get_current_extent(); auto ext_r_s1_lazy = root.sub_one.lazy._dset_state->get_current_extent(); BOOST_TEST(ext_root == std::vector<std::size_t>({10 + 1}), tt::per_element()); BOOST_TEST(ext_r_s1 == std::vector<std::size_t>({3 + 1}), tt::per_element()); // time stop = 3 BOOST_TEST(ext_r_s1_lazy == std::vector<std::size_t>({3 + 1}), tt::per_element()); auto dset = root.sub_another.another_one._dset_state; auto ext_r_sa = dset->get_current_extent(); dset = root.sub_another.another_one._dset_state; auto ext_r_sa_a = dset->get_current_extent(); dset = root.sub_another.another_one.lazy._dset_state; auto ext_r_sa_a_l = dset->get_current_extent(); BOOST_TEST(ext_r_sa == std::vector<std::size_t>({6 + 1}), tt::per_element()); // time start = 5 BOOST_TEST(ext_r_sa_a == std::vector<std::size_t>({6 + 1}), tt::per_element()); BOOST_TEST(ext_r_sa_a_l == std::vector<std::size_t>({6 + 1}), tt::per_element()); // the sub-model run during prolog with num_steps = 20 dset = root.sub_another.another_lazy._dset_state; auto ext_r_sa_al = dset->get_current_extent(); BOOST_TEST(ext_r_sa_al == std::vector<std::size_t>({20 + 1}), tt::per_element()); // check log level propagation log->debug("Asserting correct log levels ..."); BOOST_TEST(root.get_logger()->level() == spdlog::level::debug); Loading test/core/model_nested_test.hh +36 −12 Original line number Diff line number Diff line Loading @@ -26,6 +26,9 @@ public: /// Whether the epilog was performed bool _epilog_run; /// Some data std::shared_ptr<DataSet> _dset_state; public: /// Constructor template<class ParentModel> Loading @@ -35,7 +38,8 @@ public: // Pass arguments to the base class constructor Base(name, parent_model), _prolog_run(false), _epilog_run(false) _epilog_run(false), _dset_state(this->create_dset("state", {})) { this->_log->info("DoNothingModel initialized. Level: {}", this->_level); } Loading @@ -46,8 +50,10 @@ public: /// Monitor data (does nothing) void monitor () {} /// Data write method (does nothing here) void write_data () {} /// Data write method (write zeros) void write_data () { _dset_state->write(0); } /// The prolog void prolog () { Loading Loading @@ -96,6 +102,9 @@ public: /// Whether the epilog was performed bool _epilog_run; /// Some data std::shared_ptr<DataSet> _dset_state; public: /// Constructor template<class ParentModel> Loading @@ -107,7 +116,8 @@ public: // Submodel initialization lazy("lazy", *this), _prolog_run(false), _epilog_run(false) _epilog_run(false), _dset_state(this->create_dset("state", {})) { this->_log->info("OneModel initialized. Level: {}", this->_level); } Loading @@ -121,8 +131,10 @@ public: /// Monitor data (do nothing here) void monitor () {} /// Data write method (does nothing here) void write_data () {} /// Data write method void write_data () { _dset_state->write(1); } /// Prolog void prolog () { Loading Loading @@ -182,6 +194,9 @@ public: /// Whether the epilog was performed bool _epilog_run; /// Some data std::shared_ptr<DataSet> _dset_state; public: /// Constructor template<class ParentModel> Loading @@ -194,7 +209,8 @@ public: another_one("one", *this), another_lazy("lazy", *this), _prolog_run(false), _epilog_run(false) _epilog_run(false), _dset_state(this->create_dset("state", {})) { this->_log->info("AnotherModel initialized. Level: {}", this->_level); } Loading @@ -208,8 +224,10 @@ public: /// Monitor data (do nothing here) void monitor () {} /// Data write method (does nothing here) void write_data () {} /// Data write method void write_data () { _dset_state->write(this->get_time()); } /// Prolog void prolog () { Loading Loading @@ -278,6 +296,9 @@ public: /// Start iterating model another at this time Time _start_iterate_another; /// Some data std::shared_ptr<DataSet> _dset_state; public: /// Create RootModel with initial state template<class ParentModel> Loading @@ -293,7 +314,8 @@ public: _prolog_run(false), _epilog_run(false), _stop_iterate_one(get_as<Time>("stop_iterate_one", this->_cfg)), _start_iterate_another(get_as<Time>("start_iterate_another", this->_cfg)) _start_iterate_another(get_as<Time>("start_iterate_another", this->_cfg)), _dset_state(this->create_dset("state", {})) { this->_log->info("RootModel initialized. Level: {}", this->_level); Loading Loading @@ -327,8 +349,10 @@ public: /// Monitor data (do nothing here) void monitor () {} /// Data write method (does nothing here) void write_data () {} /// Data write method void write_data () { _dset_state->write(this->get_time()); } /// Prolog void prolog () { Loading Loading
include/utopia/core/model.hh +6 −0 Original line number Diff line number Diff line Loading @@ -458,10 +458,16 @@ public: ); if constexpr (_write_mode == WriteMode::basic) { if (_time_max == std::numeric_limits<hsize_t>::max()) { return std::numeric_limits<hsize_t>::max(); } return ( (_time_max - std::max(_time, _write_start)) / _write_every) + 1; } else if constexpr (_write_mode == WriteMode::manual) { if (_time_max - _time == std::numeric_limits<hsize_t>::max()) { return std::numeric_limits<hsize_t>::max(); } return _time_max - _time + 1; } else { Loading
test/core/model_nested_test.cc +36 −0 Original line number Diff line number Diff line Loading @@ -13,6 +13,7 @@ // +++ Fixtures +++ namespace tt = boost::test_tools; /// A specialized infrastructure fixture, loading a configuration file /** \note If no configuration file is required or available, you can Loading Loading @@ -104,6 +105,41 @@ BOOST_AUTO_TEST_CASE (test_iteration_order) BOOST_TEST(root.sub_another.another_lazy.get_time() == 20); // Check that in all models data was written log->debug("Asserting correct data-writing ..."); auto ext_root = root._dset_state->get_current_extent(); auto ext_r_s1 = root.sub_one._dset_state->get_current_extent(); auto ext_r_s1_lazy = root.sub_one.lazy._dset_state->get_current_extent(); BOOST_TEST(ext_root == std::vector<std::size_t>({10 + 1}), tt::per_element()); BOOST_TEST(ext_r_s1 == std::vector<std::size_t>({3 + 1}), tt::per_element()); // time stop = 3 BOOST_TEST(ext_r_s1_lazy == std::vector<std::size_t>({3 + 1}), tt::per_element()); auto dset = root.sub_another.another_one._dset_state; auto ext_r_sa = dset->get_current_extent(); dset = root.sub_another.another_one._dset_state; auto ext_r_sa_a = dset->get_current_extent(); dset = root.sub_another.another_one.lazy._dset_state; auto ext_r_sa_a_l = dset->get_current_extent(); BOOST_TEST(ext_r_sa == std::vector<std::size_t>({6 + 1}), tt::per_element()); // time start = 5 BOOST_TEST(ext_r_sa_a == std::vector<std::size_t>({6 + 1}), tt::per_element()); BOOST_TEST(ext_r_sa_a_l == std::vector<std::size_t>({6 + 1}), tt::per_element()); // the sub-model run during prolog with num_steps = 20 dset = root.sub_another.another_lazy._dset_state; auto ext_r_sa_al = dset->get_current_extent(); BOOST_TEST(ext_r_sa_al == std::vector<std::size_t>({20 + 1}), tt::per_element()); // check log level propagation log->debug("Asserting correct log levels ..."); BOOST_TEST(root.get_logger()->level() == spdlog::level::debug); Loading
test/core/model_nested_test.hh +36 −12 Original line number Diff line number Diff line Loading @@ -26,6 +26,9 @@ public: /// Whether the epilog was performed bool _epilog_run; /// Some data std::shared_ptr<DataSet> _dset_state; public: /// Constructor template<class ParentModel> Loading @@ -35,7 +38,8 @@ public: // Pass arguments to the base class constructor Base(name, parent_model), _prolog_run(false), _epilog_run(false) _epilog_run(false), _dset_state(this->create_dset("state", {})) { this->_log->info("DoNothingModel initialized. Level: {}", this->_level); } Loading @@ -46,8 +50,10 @@ public: /// Monitor data (does nothing) void monitor () {} /// Data write method (does nothing here) void write_data () {} /// Data write method (write zeros) void write_data () { _dset_state->write(0); } /// The prolog void prolog () { Loading Loading @@ -96,6 +102,9 @@ public: /// Whether the epilog was performed bool _epilog_run; /// Some data std::shared_ptr<DataSet> _dset_state; public: /// Constructor template<class ParentModel> Loading @@ -107,7 +116,8 @@ public: // Submodel initialization lazy("lazy", *this), _prolog_run(false), _epilog_run(false) _epilog_run(false), _dset_state(this->create_dset("state", {})) { this->_log->info("OneModel initialized. Level: {}", this->_level); } Loading @@ -121,8 +131,10 @@ public: /// Monitor data (do nothing here) void monitor () {} /// Data write method (does nothing here) void write_data () {} /// Data write method void write_data () { _dset_state->write(1); } /// Prolog void prolog () { Loading Loading @@ -182,6 +194,9 @@ public: /// Whether the epilog was performed bool _epilog_run; /// Some data std::shared_ptr<DataSet> _dset_state; public: /// Constructor template<class ParentModel> Loading @@ -194,7 +209,8 @@ public: another_one("one", *this), another_lazy("lazy", *this), _prolog_run(false), _epilog_run(false) _epilog_run(false), _dset_state(this->create_dset("state", {})) { this->_log->info("AnotherModel initialized. Level: {}", this->_level); } Loading @@ -208,8 +224,10 @@ public: /// Monitor data (do nothing here) void monitor () {} /// Data write method (does nothing here) void write_data () {} /// Data write method void write_data () { _dset_state->write(this->get_time()); } /// Prolog void prolog () { Loading Loading @@ -278,6 +296,9 @@ public: /// Start iterating model another at this time Time _start_iterate_another; /// Some data std::shared_ptr<DataSet> _dset_state; public: /// Create RootModel with initial state template<class ParentModel> Loading @@ -293,7 +314,8 @@ public: _prolog_run(false), _epilog_run(false), _stop_iterate_one(get_as<Time>("stop_iterate_one", this->_cfg)), _start_iterate_another(get_as<Time>("start_iterate_another", this->_cfg)) _start_iterate_another(get_as<Time>("start_iterate_another", this->_cfg)), _dset_state(this->create_dset("state", {})) { this->_log->info("RootModel initialized. Level: {}", this->_level); Loading Loading @@ -327,8 +349,10 @@ public: /// Monitor data (do nothing here) void monitor () {} /// Data write method (does nothing here) void write_data () {} /// Data write method void write_data () { _dset_state->write(this->get_time()); } /// Prolog void prolog () { Loading