solver.hpp 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  1. #ifndef KERNEL_HPP
  2. #define KERNEL_HPP
  3. #include <cstdio>
  4. #include <cstring>
  5. #include <fstream>
  6. #include <stack>
  7. #include "physics.hpp"
  8. #include "geometry.hpp"
  9. #include "time.hpp"
  10. #include "input_data.hpp"
  11. #include "solution.hpp"
  12. #include "piccard.hpp"
  13. using namespace std;
  14. namespace Kernel{
  15. //! The Solver class.
  16. /*!
  17. This is the entry class to compute solutions of the problem.
  18. From an input file, it computes a Solution to each time step
  19. of the simulation.
  20. */
  21. class Solver{
  22. private:
  23. //! Piccard object used for Piccard algorithm.
  24. Piccard piccard;
  25. //! Maximal number of time subintervals allowed to compute a new Solution form a previous one.
  26. static constexpr size_t max_time_subdivisions=32;
  27. //! Datas stored in the input file will be loaded in input_data
  28. InputData input_data;
  29. //! A stack of pointers to valid Solution object.
  30. stack<Solution*> solutions_stack;
  31. //! Array of pointer to Solutions computed for each time step
  32. Solution** solutions;
  33. //! Numbers of Solutions computed so far
  34. size_t number_computed_solutions;
  35. //! Number of time subintervals used to compute a new Solution from the previous one
  36. size_t m1;
  37. //! Get a newSolution object from the stack #solutions_stacks
  38. Solution* get_new_solution();
  39. //! Returns a solution that is no longer used on the stack
  40. void release_solution(Solution*);
  41. //! Init the solution at time t=0 from the input file
  42. void init_first_solution();
  43. //! Try to compute the solution at time t+1 from the solution at time t
  44. Solution* space_solution();
  45. public:
  46. //! Construct a Solver from the input file input_filename
  47. Solver(string input_filename);
  48. //! Return the geometry of the simulation, which is given in input file
  49. const Geometry& get_geometry() const;
  50. //! Return the vertical factor (used for drawing)
  51. double get_vertical_factor() const;
  52. //! Return tjhe number of solution computed until now, relatively to the time
  53. size_t get_computed_solutions_number() const;
  54. //! Return the solution computed at time t. Return nullptr if the solution is not yet computed.
  55. const Solution* get_solution(size_t t) const;
  56. //! Compute the next Solution. Return false if the schema can't obtain such a soluition.
  57. bool compute_next_solution();
  58. };
  59. inline Solution*
  60. Solver::get_new_solution(){
  61. Solution* s=solutions_stack.top();
  62. solutions_stack.pop();
  63. return s;
  64. }
  65. inline void
  66. Solver::release_solution(Solution* s){
  67. solutions_stack.push(s);
  68. }
  69. inline const Geometry&
  70. Solver::get_geometry() const{
  71. return input_data.geometry;
  72. }
  73. inline double
  74. Solver::get_vertical_factor() const{
  75. return input_data.factor;
  76. }
  77. inline size_t
  78. Solver::get_computed_solutions_number() const{
  79. return number_computed_solutions;
  80. }
  81. inline const Solution*
  82. Solver::get_solution(size_t n) const{
  83. return solutions[n];
  84. }
  85. }
  86. #endif