ricker.c 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. /*
  2. 2D FDTD simulator
  3. Copyright (C) 2019 Emilia Blåsten
  4. This program is free software: you can redistribute it and/or
  5. modify it under the terms of the GNU Affero General Public License
  6. as published by the Free Software Foundation, either version 3 of
  7. the License, or (at your option) any later version.
  8. This program is distributed in the hope that it will be useful,
  9. but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  11. Affero General Public License for more details.
  12. You should have received a copy of the GNU Affero General Public
  13. License along with this program. If not, see
  14. <http://www.gnu.org/licenses/>.
  15. */
  16. /* ricker.c: Function to implement a Ricker wavelet. This is a
  17. * travelling-wave version of the function se ezInc() takes arguments
  18. * both in time and space. */
  19. #include "ezinc.h"
  20. #include "gridtmz.h"
  21. #include <math.h>
  22. #include <stdio.h>
  23. #include <stdlib.h>
  24. static double cdtds, ppw = 0;
  25. // initialize source-function variables
  26. void ezIncInit(Grid *g) {
  27. // printf("Enter the points per wavelength for Ricker source: ");
  28. // scanf(" %lf", &ppw);
  29. ppw = 30;
  30. cdtds = g->cdtds;
  31. return;
  32. }
  33. // caculate source function at given time and location
  34. double ezInc(double time, double location) {
  35. double arg;
  36. if(ppw <= 0) {
  37. fprintf(stderr,
  38. "ezInc: ezIncInit() must be called before ezInc.\n"
  39. " Points per wavelength must be positive.\n");
  40. exit(-1);
  41. }
  42. arg = M_PI * ((cdtds * time - location) / ppw - 1.0);
  43. arg = arg * arg;
  44. return (1.0 - 2.0*arg) * exp(-arg);
  45. }