n_upwind.c 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. /*****************************************************************************
  2. *
  3. * MODULE: Grass PDE Numerical Library
  4. * AUTHOR(S): Soeren Gebbert, Berlin (GER) Dec 2006
  5. * soerengebbert <at> gmx <dot> de
  6. *
  7. * PURPOSE: upwinding stabilization algorithms
  8. * part of the gpde library
  9. *
  10. * COPYRIGHT: (C) 2000 by the GRASS Development Team
  11. *
  12. * This program is free software under the GNU General Public
  13. * License (>=v2). Read the file COPYING that comes with GRASS
  14. * for details.
  15. *
  16. *****************************************************************************/
  17. #include <math.h>
  18. #include <grass/N_pde.h>
  19. /*! \brief full upwinding stabilization algorithm
  20. *
  21. * The arguments are values to compute the local peclet number
  22. *
  23. * \param sprod double -- the scalar produkt between the velocity vector and the normal vector between two points
  24. * \param distance double -- distance between two points
  25. * \param D double -- diffusion/dispersion tensor part between two points
  26. *
  27. * \return the weighting factor
  28. * */
  29. double N_full_upwinding(double sprod, double distance, double D)
  30. {
  31. double z;
  32. if (D == 0)
  33. return 0.5;
  34. /*compute the local peclet number */
  35. z = sprod * distance / D;
  36. if (z > 0)
  37. return 1;
  38. if (z == 0)
  39. return 0.5;
  40. if (z < 0)
  41. return 0;
  42. return 0;
  43. }
  44. /*! \brief exponential upwinding stabilization algorithm
  45. *
  46. * The arguments are values to compute the local peclet number
  47. *
  48. * \param sprod double -- the scalar produkt between the velocity vector and the normal vector between two points
  49. * \param distance double -- distance between two points
  50. * \param D double -- diffusion/dispersion tensor part between two points
  51. *
  52. * \return the weighting factor
  53. * */
  54. double N_exp_upwinding(double sprod, double distance, double D)
  55. {
  56. double z;
  57. if (D == 0)
  58. return 0.5;
  59. /*compute the local peclet number */
  60. z = sprod * distance / D;
  61. if (z != 0)
  62. return (1 - (1 / z) * (1 - (z / (exp(z) - 1))));
  63. return 0.5;
  64. }