richards_evolutive_time.cpp 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  1. #include "richards_evolutive_time.hpp"
  2. namespace Kernel{
  3. void
  4. RichardsEvolutiveTime::init(size_t ix_,const Geometry* geometry,double* pumps_){
  5. ix=ix_;
  6. nZ=geometry->nZ[ix];
  7. Z=geometry->Z[ix];
  8. dX=geometry->dX;
  9. pumps=pumps_;
  10. div_w=new double[nZ];
  11. richards.init(ix,nZ,geometry->dZ[ix],pumps);
  12. }
  13. void
  14. RichardsEvolutiveTime::compute_flux_bot(){
  15. flux_bot=0;
  16. }
  17. void
  18. RichardsEvolutiveTime::compute_div_w(){
  19. double cst=Physics::rho*Physics::g;
  20. double G_left=Pl_left/cst+l_left;
  21. double G_middle=Pl_middle/cst+l_middle;
  22. double G_right=Pl_right/cst+l_right;
  23. double m_left=max(G_left,G_middle);
  24. double m_right=max(G_middle,G_right);
  25. for(size_t i=0;i<nZ;++i){
  26. div_w[i]=(Physics::kr(cst*(m_right-Z[i]))*Physics::k0*(hydr_right-hydr_middle)-Physics::kr(cst*(m_left-Z[i]))*Physics::k0*(hydr_middle-hydr_left))/(dX*dX);
  27. }
  28. }
  29. void
  30. RichardsEvolutiveTime::run(){
  31. #ifdef MYDEBUG
  32. if(ix==Debug::ix and Debug::level>0) cout<<" [RichardsEvolutiveTime ix="<<ix<<"] start"<<endl;
  33. #endif
  34. compute_flux_bot();
  35. compute_div_w();
  36. size_t m2=1;
  37. size_t n2=0;
  38. double dt_sub=dt;
  39. richards.div_w=div_w;
  40. richards.dt=dt_sub;
  41. richards.flux_bot=flux_bot;
  42. //You must specify richards.Px and also create it
  43. while(n2<m2 and m2<=max_Richards_time_subdivisions){
  44. #ifdef MYDEBUG
  45. if(ix==Debug::ix and Debug::level>1) cout<<" [RichardsEvolutiveTime ix="<<ix<<"] n2 = "<<n2<<" and m2 = "<<m2<<endl;
  46. #endif
  47. if(n2==0){
  48. richards.previous_P=init_P;
  49. richards.near_P=previous_P;
  50. }
  51. else{
  52. richards.previous_P=richards.P;
  53. richards.near_P=richards.P;
  54. }
  55. richards.P=P;
  56. richards.run();
  57. P=richards.P;
  58. if(!richards.has_converged){
  59. m2*=2;
  60. dt_sub/=2;
  61. richards.dt=dt_sub;
  62. n2=0;
  63. }
  64. else{
  65. ++n2;
  66. }
  67. }
  68. has_converged=(m2<=max_Richards_time_subdivisions);
  69. #ifdef MYDEBUG
  70. if(ix==Debug::ix){
  71. if(Debug::level>1){
  72. cout<<" [RichardsEvolutiveTime ix="<<ix<<"] out = "<<P<<endl;
  73. cout<<" [RichardsEvolutiveTime ix="<<ix<<"]";
  74. if(not has_converged) cout<<" not";
  75. cout<<" converge"<<endl;
  76. }
  77. cout<<" [RichardsEvolutiveTime ix="<<ix<<"] stop"<<endl;
  78. }
  79. #endif
  80. }
  81. }