test-context.cpp 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  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. //#define CATCH_CONFIG_MAIN
  22. //#include <test/catch.hpp>
  23. #include <test/models.hpp>
  24. #include <artis/kernel/Simulator.hpp>
  25. #include <artis/utils/DateTime.hpp>
  26. #include <boost/archive/binary_oarchive.hpp>
  27. #include <boost/archive/binary_iarchive.hpp>
  28. #include <fstream>
  29. using namespace artis::kernel;
  30. typedef artis::kernel::Simulator<RootModel,
  31. artis::utils::DoubleTime,
  32. ModelParameters,
  33. GlobalParameters> ASimulator;
  34. typedef artis::context::Context<artis::utils::DoubleTime> AContext;
  35. int main()
  36. {
  37. GlobalParameters globalParameters;
  38. ModelParameters modelParameters;
  39. AContext context(artis::utils::DateTime::toJulianDayNumber("2016-1-1"),
  40. artis::utils::DateTime::toJulianDayNumber("2016-1-5"));
  41. ::Trace::trace().clear();
  42. {
  43. ASimulator simulator(new RootModel, globalParameters);
  44. simulator.init(artis::utils::DateTime::toJulianDayNumber("2016-1-1"),
  45. modelParameters);
  46. simulator.run(context);
  47. simulator.save(context);
  48. std::ofstream os("state");
  49. boost::archive::binary_oarchive oa(os);
  50. oa << context;
  51. }
  52. std::cout << ::Trace::trace().elements().filter_variable("BX").to_string(
  53. artis::utils::DATE_FORMAT_YMD) << std::endl;
  54. std::cout << "==== PAUSE ====" << std::endl;
  55. ::Trace::trace().clear();
  56. {
  57. AContext new_context(context);
  58. ASimulator simulator(new RootModel, globalParameters);
  59. new_context.begin(
  60. artis::utils::DateTime::toJulianDayNumber("2016-1-6"));
  61. new_context.end(
  62. artis::utils::DateTime::toJulianDayNumber("2016-1-10"));
  63. simulator.run(new_context);
  64. }
  65. std::cout << ::Trace::trace().elements().filter_type(
  66. artis::utils::COMPUTE).to_string() << std::endl;
  67. std::cout << "==== PAUSE ====" << std::endl;
  68. ::Trace::trace().clear();
  69. {
  70. AContext new_context;
  71. ASimulator simulator(new RootModel, globalParameters);
  72. std::ifstream is("state");
  73. boost::archive::binary_iarchive ia(is);
  74. ia >> new_context;
  75. new_context.begin(
  76. artis::utils::DateTime::toJulianDayNumber("2016-1-6"));
  77. new_context.end(
  78. artis::utils::DateTime::toJulianDayNumber("2016-1-10"));
  79. simulator.run(new_context);
  80. }
  81. std::cout << ::Trace::trace().elements().to_string() << std::endl;
  82. return 0;
  83. }