test-context.cpp 3.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  1. /**
  2. * @file test/test-context.cpp
  3. * @author See the AUTHORS file
  4. */
  5. /*
  6. * Copyright (C) 2012-2019 ULCO http://www.univ-littoral.fr
  7. *
  8. * This program is free software: you can redistribute it and/or modify
  9. * it under the terms of the GNU General Public License as published by
  10. * the Free Software Foundation, either version 3 of the License, or
  11. * (at your option) any later version.
  12. *
  13. * This program is distributed in the hope that it will be useful,
  14. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  16. * GNU General Public License for more details.
  17. *
  18. * You should have received a copy of the GNU General Public License
  19. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  20. */
  21. #include <test/models.hpp>
  22. #include <artis/kernel/Simulator.hpp>
  23. #include <artis/utils/DateTime.hpp>
  24. #include <boost/archive/binary_oarchive.hpp>
  25. #include <boost/archive/binary_iarchive.hpp>
  26. #include <fstream>
  27. typedef artis::kernel::Simulator<RootModel, artis::utils::DoubleTime, ModelParameters, GlobalParameters> Simulator;
  28. typedef artis::context::Context<artis::utils::DoubleTime> Context;
  29. int main()
  30. {
  31. GlobalParameters globalParameters;
  32. ModelParameters modelParameters;
  33. Context context(artis::utils::DateTime::toJulianDayNumber("2016-1-1"),
  34. artis::utils::DateTime::toJulianDayNumber("2016-1-5"));
  35. Trace::trace().clear();
  36. {
  37. Simulator simulator(new RootModel, globalParameters);
  38. simulator.init(artis::utils::DateTime::toJulianDayNumber("2016-1-1"), modelParameters);
  39. simulator.run(context);
  40. simulator.save(context);
  41. std::ofstream os("state");
  42. boost::archive::binary_oarchive oa(os);
  43. oa << context;
  44. }
  45. std::cout << ::Trace::trace().elements().filter_variable("BX").to_string(artis::utils::DATE_FORMAT_YMD)
  46. << std::endl;
  47. std::cout << "==== PAUSE ====" << std::endl << std::endl;
  48. Trace::trace().clear();
  49. {
  50. Context new_context(context);
  51. Simulator simulator(new RootModel, globalParameters);
  52. new_context.begin(artis::utils::DateTime::toJulianDayNumber("2016-1-6"));
  53. new_context.end(artis::utils::DateTime::toJulianDayNumber("2016-1-10"));
  54. simulator.run(new_context);
  55. }
  56. std::cout << ::Trace::trace().elements().filter_type(artis::utils::COMPUTE).to_string() << std::endl;
  57. std::cout << "==== PAUSE ====" << std::endl << std::endl;;
  58. Trace::trace().clear();
  59. {
  60. Context new_context;
  61. Simulator simulator(new RootModel, globalParameters);
  62. std::ifstream is("state");
  63. boost::archive::binary_iarchive ia(is);
  64. ia >> new_context;
  65. new_context.begin(artis::utils::DateTime::toJulianDayNumber("2016-1-6"));
  66. new_context.end(artis::utils::DateTime::toJulianDayNumber("2016-1-10"));
  67. simulator.run(new_context);
  68. }
  69. std::cout << ::Trace::trace().elements().filter_type(artis::utils::COMPUTE).to_string() << std::endl;
  70. return 0;
  71. }