solver.hpp 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123
  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. Solution* s=solutions_stack.top();
  65. solutions_stack.pop();
  66. return s;
  67. }
  68. inline void
  69. Solver::release_solution(Solution* s){
  70. solutions_stack.push(s);
  71. }
  72. inline const Geometry&
  73. Solver::get_geometry() const{
  74. return input_data.geometry;
  75. }
  76. inline const Source&
  77. Solver::get_source() const{
  78. return input_data.source;
  79. }
  80. inline double
  81. Solver::get_vertical_factor() const{
  82. return input_data.factor;
  83. }
  84. inline size_t
  85. Solver::get_computed_solutions_number() const{
  86. return number_computed_solutions;
  87. }
  88. inline const Solution*
  89. Solver::get_solution(size_t n) const{
  90. return solutions[n];
  91. }
  92. }
  93. #endif