solver.hpp 3.2 KB

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