test-context.cpp 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  1. /**
  2. * @file test/test-context.cpp
  3. * @author See the AUTHORS file
  4. */
  5. /*
  6. * Copyright (C) 2012-2017 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 "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. {
  42. ASimulator simulator(new RootModel, globalParameters);
  43. ::Trace::trace().clear();
  44. simulator.init(artis::utils::DateTime::toJulianDayNumber("2016-1-1"),
  45. modelParameters);
  46. simulator.run(context);
  47. std::cout << ::Trace::trace().elements().to_string() << std::endl;
  48. simulator.save(context);
  49. std::ofstream os("state");
  50. boost::archive::binary_oarchive oa(os);
  51. oa << context;
  52. }
  53. std::cout << "==== PAUSE ====" << std::endl;
  54. {
  55. AContext new_context(context);
  56. ASimulator simulator(new RootModel, globalParameters);
  57. ::Trace::trace().clear();
  58. new_context.begin(
  59. artis::utils::DateTime::toJulianDayNumber("2016-1-6"));
  60. new_context.end(
  61. artis::utils::DateTime::toJulianDayNumber("2016-1-10"));
  62. simulator.run(new_context);
  63. std::cout << ::Trace::trace().elements().to_string() << std::endl;
  64. }
  65. std::cout << "==== PAUSE ====" << std::endl;
  66. {
  67. AContext new_context;
  68. ASimulator simulator(new RootModel, globalParameters);
  69. std::ifstream is("state");
  70. boost::archive::binary_iarchive ia(is);
  71. ia >> new_context;
  72. ::Trace::trace().clear();
  73. new_context.begin(
  74. artis::utils::DateTime::toJulianDayNumber("2016-1-6"));
  75. new_context.end(
  76. artis::utils::DateTime::toJulianDayNumber("2016-1-10"));
  77. simulator.run(new_context);
  78. std::cout << ::Trace::trace().elements().to_string() << std::endl;
  79. }
  80. return 0;
  81. }