overland.cpp 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. #include "overland.hpp"
  2. #include "debug.hpp"
  3. namespace Kernel{
  4. void Overland::run(){
  5. #ifdef MYDEBUG
  6. cout<<" [Overland::run] start"<<endl;
  7. #endif
  8. compute_flux_soil();
  9. total_error=0;
  10. for(size_t ix=0;ix<geometry->nX;++ix){
  11. //TODO :: add rain
  12. hov[ix]=init_hov[ix]-dt*flux_soil[ix];
  13. }
  14. apply_flow();
  15. for(size_t ix=0;ix<geometry->nX;++ix){
  16. double e=abs(hov[ix]-previous_hov[ix])/n1_init_hov;
  17. error_x[ix]+=e;
  18. total_error+=e;
  19. Psoil[ix]=Physics::Psoil(geometry->hsoil[ix],hov[ix]);
  20. }
  21. #ifdef MYDEBUG
  22. cout<<" [Overland::run] error : "<<total_error<<endl;
  23. #endif
  24. #ifdef MYDEBUG
  25. cout<<" [Overland::run] end"<<endl;
  26. #endif
  27. }
  28. void Overland::compute_flux_soil(){
  29. for(size_t ix=0;ix<geometry->nX;++ix){
  30. double p1=P[ix][geometry->nZ[ix]-1];
  31. double p2=P[ix][geometry->nZ[ix]-2];
  32. double flux=Physics::k0/2*(Physics::kr(p1)+Physics::kr(p2))*((p1-p2)/(geometry->dZ[ix]*Physics::rho*Physics::g)+1);
  33. if(ix==0) flux-=Physics::k0*Physics::kr(Pl[0]+Physics::rho*Physics::g*(l[0]-geometry->hsoil[0]))*(hydr[1]-hydr[0])*geometry->dhsoil[0]/geometry->dX;
  34. else if(ix==geometry->nX-1) flux-=Physics::k0*Physics::kr(Pl[ix]+Physics::rho*Physics::g*(l[ix]-geometry->hsoil[ix]))*(hydr[ix]-hydr[ix-1])*geometry->dhsoil[ix]/geometry->dX;
  35. else flux-=Physics::k0*Physics::kr(Pl[ix]+Physics::rho*Physics::g*(l[ix]-geometry->hsoil[ix]))*(hydr[ix+1]-hydr[ix-1])/2*geometry->dhsoil[ix]/geometry->dX;
  36. flux_soil[ix]=flux;
  37. #ifdef MYDEBUG
  38. if(Debug::ix==ix){
  39. cout<<" [Overland::compute_flux_soil] p1 = "<<p1<<endl;
  40. cout<<" [Overland::compute_flux_soil] p2 = "<<p2<<endl;
  41. cout<<" [Overland::compute_flux_soil] flux = "<<flux<<endl;
  42. }
  43. #endif
  44. }
  45. }
  46. void Overland::apply_flow(){
  47. bool overflow=true;
  48. while(overflow){
  49. overflow=false;
  50. runoff_to_local_min();
  51. }
  52. }
  53. void Overland::runoff_to_local_min(){
  54. }
  55. }