all_vertical_richards.cpp 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118
  1. #include "all_vertical_richards.hpp"
  2. namespace Kernel{
  3. void
  4. AllVerticalRichards::init(const Geometry* geometry_,double** pumps_){
  5. geometry=geometry_;
  6. pumps=pumps_;
  7. indice_x_Richards=new bool[geometry->nX];
  8. richards_evolutive_time=new RichardsEvolutiveTime[geometry->nX];
  9. for(size_t ix=0;ix<geometry->nX;++ix){
  10. richards_evolutive_time[ix].init(ix,geometry,pumps[ix]);
  11. }
  12. }
  13. void
  14. AllVerticalRichards::update_indice_x_Richards(){
  15. for(size_t ix=0;ix<geometry->nX;++ix){
  16. indice_x_Richards[ix]=(error_x[ix]>max_error_x);
  17. }
  18. }
  19. void
  20. AllVerticalRichards::init_indice_x_Richards(){
  21. for(size_t ix=0;ix<geometry->nX;++ix){
  22. indice_x_Richards[ix]=true;
  23. }
  24. }
  25. void
  26. AllVerticalRichards::run(){
  27. Debug::debug_Thomas=false;
  28. size_t i_left,i_middle,i_right;
  29. #ifdef MYDEBUG
  30. cout<<" [AllVerticalRichards::run] start"<<endl;
  31. #endif
  32. for(size_t ix=0;ix<geometry->nX;++ix){
  33. P[ix][geometry->nZ[ix]-1]=Psoil[ix];
  34. if(indice_x_Richards[ix]){
  35. RichardsEvolutiveTime& r=richards_evolutive_time[ix];
  36. r.dt=dt;
  37. r.init_P=init_P[ix];
  38. r.previous_P=previous_P[ix];
  39. r.P=P[ix];
  40. //Update Psoil
  41. /* r.P[geometry->nZ[ix]-1]=Psoil[ix];
  42. r.init_P[geometry->nZ[ix]-1]=Psoil[ix];
  43. r.previous_P[geometry->nZ[ix]-1]=Psoil[ix];*/
  44. if(ix==0){
  45. i_left=0;
  46. i_middle=1;
  47. i_right=2;
  48. }
  49. else if(ix==geometry->nX-1){
  50. i_left=geometry->nX-3;
  51. i_middle=geometry->nX-2;
  52. i_right=geometry->nX-1;
  53. }
  54. else{
  55. i_left=ix-1;
  56. i_middle=ix;
  57. i_right=ix+1;
  58. }
  59. r.hydr_left=hydr[i_left];
  60. r.l_left=l[i_left];
  61. r.Pl_left=Pl[i_left];
  62. r.hydr_middle=hydr[i_middle];
  63. r.l_middle=l[i_middle];
  64. r.Pl_middle=Pl[i_middle];
  65. r.hydr_right=hydr[i_right];
  66. r.l_right=l[i_right];
  67. r.Pl_right=Pl[i_right];
  68. r.run();
  69. P[ix]=r.P;
  70. }
  71. }
  72. //[If Paraller wait for sync]
  73. has_converged=true;
  74. for(size_t ix=0;ix<geometry->nX;++ix){
  75. if(!richards_evolutive_time[ix].has_converged){
  76. has_converged=false;
  77. }
  78. }
  79. if(has_converged) compute_hsat();
  80. #ifdef MYDEBUG
  81. cout<<" [AllVerticalRichards::run] ";
  82. if(not has_converged) cout<<"not";
  83. cout<<"converge"<<endl<<" [AllVerticalRichards::run] end"<<endl;
  84. #endif
  85. }
  86. void
  87. AllVerticalRichards::compute_hsat(){
  88. for(size_t ix=0;ix<geometry->nX;++ix){
  89. double* Px=previous_P[ix];
  90. size_t iz=0;
  91. for(;iz<geometry->nZ[ix] and Px[iz]>Psat;++iz);
  92. if(iz>0 and Px[iz]<=Psat){
  93. hsat[ix]=(Psat-Px[iz-1])*geometry->dZ[ix]/(Px[iz]-Px[iz-1])+geometry->Z[ix][iz-1];
  94. }
  95. else{
  96. hsat[ix]=(iz==0)?geometry->hbot[ix]:geometry->hsoil[ix];
  97. }
  98. }
  99. }
  100. }