test-context.cpp 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116
  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 <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. {
  42. ::Trace::trace().clear();
  43. ASimulator simulator(new RootModel, globalParameters);
  44. simulator.init(artis::utils::DateTime::toJulianDayNumber("2016-1-1"),
  45. modelParameters);
  46. simulator.run(context);
  47. std::cout << ::Trace::trace().elements().to_string(artis::utils::DATE_FORMAT_YMD) << std::endl;
  48. simulator.save(context);
  49. std::ofstream os("state");
  50. boost::archive::binary_oarchive oa(os);
  51. oa << context;
  52. }
  53. exit(0);
  54. std::cout << "==== PAUSE ====" << std::endl;
  55. {
  56. ::Trace::trace().clear();
  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. std::cout << ::Trace::trace().elements().filter_type(artis::utils::COMPUTE).to_string() << std::endl;
  65. }
  66. std::cout << "==== PAUSE ====" << std::endl;
  67. {
  68. ::Trace::trace().clear();
  69. AContext new_context;
  70. ASimulator simulator(new RootModel, globalParameters);
  71. std::ifstream is("state");
  72. boost::archive::binary_iarchive ia(is);
  73. ia >> new_context;
  74. new_context.begin(
  75. artis::utils::DateTime::toJulianDayNumber("2016-1-6"));
  76. new_context.end(
  77. artis::utils::DateTime::toJulianDayNumber("2016-1-10"));
  78. simulator.run(new_context);
  79. std::cout << ::Trace::trace().elements().to_string() << std::endl;
  80. }
  81. return 0;
  82. }