material.c 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  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. /* material.c: The implementations of the functions that are used
  17. * to define the ez, hx and hy field update coefficients. Also a
  18. * function to initialize the parameters used by the other functions. */
  19. #include <math.h>
  20. static int sizeX=-1, sizeY=-1;
  21. static double cdtds=-1, imp0=-1;
  22. void materialInit(int width, int height, double courant, double impedance) {
  23. sizeX = width;
  24. sizeY = height;
  25. cdtds = courant;
  26. imp0 = impedance;
  27. }
  28. // Coefficients used when updating the ez-field
  29. double ezCe(int mm, int nn, int choice) {
  30. double value = 1;
  31. if((choice == 3) && (mm < sizeX/2) && (nn > sizeY/2) && (mm - nn > sizeX*0.45 - sizeY*0.55) ) {
  32. value= 0.8;//exp(-(pow(mm - sizeX*0.4 - sizeY*0.6,2) + pow(nn - sizeY/2,2)) / 50000);
  33. }
  34. return value;
  35. }
  36. double ezCh(int mm, int nn, int choice) {
  37. return ezCe(mm,nn,choice)*cdtds*imp0;
  38. }
  39. // Coefficients used when updating the hx-field
  40. double hxCe(int mm, int nn, int choice) {
  41. double value = cdtds / imp0;
  42. return value;
  43. }
  44. double hxCh(int mm, int nn, int choice) {
  45. return hxCe(mm,nn,choice)*imp0/cdtds;
  46. }
  47. // Coefficients used when updating the hy-field
  48. double hyCe(int mm, int nn, int choice) {
  49. return hxCe(mm,nn,choice);
  50. }
  51. double hyCh(int mm, int nn, int choice) {
  52. return hxCh(mm,nn,choice);
  53. }