horizontal_problem.cpp 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. #include "horizontal_problem.hpp"
  2. #include "debug.hpp"
  3. namespace Kernel{
  4. void
  5. HorizontalProblem::init(const Geometry* geometry_){
  6. geometry=geometry_;
  7. sub_M=new double[geometry->nX-1];
  8. diag_M=new double[geometry->nX];
  9. sup_M=new double[geometry->nX-1];
  10. F=new double[geometry->nX];
  11. }
  12. void
  13. HorizontalProblem::compute_error(){
  14. total_error=0;
  15. for(size_t ix=0;ix<geometry->nX;++ix){
  16. double e=error_x[ix]=abs(previous_hydr[ix]-hydr[ix]);
  17. total_error+=e;
  18. }
  19. }
  20. void
  21. HorizontalProblem::run(){
  22. #ifdef MYDEBUG
  23. cout<<" [HorizontalProblem::run] start"<<endl;
  24. #endif
  25. /*for(size_t ix=0;ix<geometry->nX;++ix){
  26. hydr[ix]=previous_hydr[ix];
  27. }*/
  28. solve_system();
  29. compute_error();
  30. #ifdef MYDEBUG
  31. cout<<" [HorizontalProblem::run] end"<<endl;
  32. #endif
  33. }
  34. void
  35. HorizontalProblem::solve_system(){
  36. for(size_t ix=1;ix<geometry->nX-1;++ix){
  37. double dx=geometry->dX;
  38. double hbot=geometry->hbot[ix];
  39. double lx=l[ix];
  40. double a=-Physics::tilde_a(lx,hbot)*Physics::k0/(dx*dx);
  41. double c=Physics::tilde_c(lx,hbot)*Physics::k0/dx;
  42. double dhbot=geometry->dhbot[ix];
  43. sub_M[ix-1]=a-(dhbot*c)/2;
  44. diag_M[ix]=1-2*a;
  45. sup_M[ix]=a+(dhbot*c)/2;
  46. F[ix]=Pl[ix]/(Physics::rho*Physics::g)+lx;
  47. }
  48. diag_M[0]=1;
  49. sup_M[0]=-1;
  50. F[0]=0;
  51. diag_M[geometry->nX-1]=1;
  52. sub_M[geometry->nX-2]=-1;
  53. F[geometry->nX-1]=0;
  54. Thomas(geometry->nX,sub_M,diag_M,sup_M,F,hydr);
  55. }
  56. }