main.cpp 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. // This is a benchmark example to validate 2D axisymmetry with 'hcurl' fields for electromagnetic waves.
  2. #include "sparselizardbase.h"
  3. using namespace mathop;
  4. void sparselizard(void)
  5. {
  6. // The domain regions:
  7. int sur = 1, right = 2, boundary = 3;
  8. int n = 50;
  9. shape q("quadrangle", sur, {0.005,0,0, 0.055,0,0, 0.055,0.04,0, 0.005,0.04,0}, {n,n,n,n});
  10. shape lb = q.getsons()[0];
  11. lb.setphysicalregion(boundary);
  12. shape lr = q.getsons()[1];
  13. lr.setphysicalregion(right);
  14. shape lt = q.getsons()[2];
  15. lt.setphysicalregion(boundary);
  16. shape ll = q.getsons()[3];
  17. ll.setphysicalregion(boundary);
  18. mesh mymesh({q,lb,lr,lt,ll});
  19. setaxisymmetry();
  20. // Edge shape functions 'hcurl' for the electric field E.
  21. // Fields x and y are the x and y coordinate fields.
  22. field E("hcurl"), x("x"), y("y");
  23. // Use interpolation order 2 on the whole domain:
  24. E.setorder(sur, 2);
  25. double freq = 10.0e9, c = 299792458, k = 2.0*getpi()*freq/c;
  26. E.setconstraint(right, array3x1(0,y,0));
  27. // Perfect conductor boundary conditions:
  28. E.setconstraint(boundary);
  29. formulation maxwell;
  30. // This is the weak formulation for electromagnetic waves:
  31. maxwell += integral(sur, -curl(dof(E))*curl(tf(E)) + k*k*dof(E)*tf(E));
  32. solve(maxwell);
  33. E.write(sur, "E.pos", 2);
  34. compx(E).write(sur, "Ex.pos", 2);
  35. compy(E).write(sur, "Ey.pos", 2);
  36. double maxE = norm(E).max(sur, 5)[0];
  37. std::cout << "Max electric field norm is " << maxE << " V/m" << std::endl;
  38. // Code validation line. Can be removed.
  39. std::cout << (maxE < 0.138395 && maxE > 0.138393);
  40. }
  41. int main(void)
  42. {
  43. SlepcInitialize(0,{},0,0);
  44. sparselizard();
  45. SlepcFinalize();
  46. return 0;
  47. }