richards_evolutive_time.cpp 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  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. if(ix==Debug::ix and Debug::level>0) cout<<" [RichardsEvolutiveTime ix="<<ix<<"] start"<<endl;
  31. compute_flux_bot();
  32. compute_div_w();
  33. size_t m2=1;
  34. size_t n2=0;
  35. double dt_sub=dt;
  36. richards.div_w=div_w;
  37. richards.dt=dt_sub;
  38. richards.flux_bot=flux_bot;
  39. //You must specify richards.Px and also create it
  40. while(n2<m2 and m2<=max_Richards_time_subdivisions){
  41. if(ix==Debug::ix and Debug::level>1) cout<<" [RichardsEvolutiveTime ix="<<ix<<"] n2 = "<<n2<<" and m2 = "<<m2<<endl;
  42. if(n2==0){
  43. richards.previous_P=init_P;
  44. richards.near_P=previous_P;
  45. }
  46. else{
  47. richards.previous_P=richards.P;
  48. richards.near_P=richards.P;
  49. }
  50. richards.P=P;
  51. richards.run();
  52. P=richards.P;
  53. if(!richards.has_converged){
  54. m2*=2;
  55. dt_sub/=2;
  56. richards.dt=dt_sub;
  57. n2=0;
  58. }
  59. else{
  60. ++n2;
  61. }
  62. }
  63. has_converged=(m2<=max_Richards_time_subdivisions);
  64. if(ix==Debug::ix and Debug::level>0){
  65. if(Debug::level>1){
  66. cout<<" [RichardsEvolutiveTime ix="<<ix<<"] out = "<<P<<endl;
  67. cout<<" [RichardsEvolutiveTime ix="<<ix<<"]";
  68. if(not has_converged) cout<<" not";
  69. cout<<" converge"<<endl;
  70. }
  71. cout<<" [RichardsEvolutiveTime ix="<<ix<<"] stop"<<endl;
  72. }
  73. }
  74. }