solver.hpp 3.2 KB

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