richards_evolutive_time.cpp 2.3 KB

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