Guest User

Untitled

a guest
Feb 21st, 2018
79
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.57 KB | None | 0 0
  1. << NDSolve`FEM`
  2.  
  3. λ = 0.53; k0 = 2 π/λ; R = λ;
  4.  
  5. mesh = ToElementMesh[FullRegion[2], {{0, R}, {0, R}},
  6. "MaxCellMeasure" -> 0.0005];
  7.  
  8. mesh["Wireframe"]
  9.  
  10. op =
  11. Most[Curl[Curl[{u[x, y], v[x, y], 0}, {x, y, z}], {x, y, z}] -
  12. k0^2 {u[x, y], v[x, y], 0}]
  13.  
  14. pde = op == {0, 0};
  15.  
  16. Subscript[Γ, D] =
  17. DirichletCondition[{u[x, y] == 0., v[x, y] == Exp[I k0 x]}, True];
  18.  
  19. {us, vs} =
  20. NDSolveValue[{pde, Subscript[Γ, D]}, {u, v}, {x, y} ∈ mesh]
  21.  
  22. DensityPlot[Re[vs[x, y]], {x, y} ∈ mesh,
  23. ColorFunction -> "Rainbow",
  24. PlotLegends -> Automatic,
  25. PlotPoints -> 50,
  26. PlotRange -> All]
  27.  
  28. λ = 53/100; k0 = 2 π/λ; R = λ;
  29.  
  30. op = Most[Curl[Curl[{u[x, y], v[x, y], 0}, {x, y, z}], {x, y, z}] -
  31. k0^2 {u[x, y], v[x, y], 0}];
  32.  
  33. pde = op == {0, 0};
  34. bc = Function[{x, y}, {u[x, y] == 0, v[x, y] == Exp[I k0 x]}] @@@ {{0, y}, {R, y}, {x,
  35. 0}, {x, R}} // Flatten;
  36.  
  37. domain = {0, R};
  38. points = 50;
  39. grid = Array[# &, points, domain];
  40. difforder = 4;
  41. (*Definition of pdetoae isn't included in this code piece,
  42. please find it in the link above. *)
  43. ptoa = pdetoae[{u, v}[x, y], {grid, grid}, difforder];
  44. del = Most@Rest@# &;
  45.  
  46. ae = del /@ del@# & /@ ptoa@pde;
  47. aebc = MapAt[del, ptoa@bc, List /@ Range@4];
  48. {b, mat} = CoefficientArrays[{ae, aebc} // Flatten,
  49. Outer[#[#2, #3] &, {u, v}, grid, grid] // Flatten];
  50. sollst = LinearSolve[-mat, N@b];
  51. solmat = ArrayReshape[sollst, {2, points, points}];
  52. {solu, solv} = ListInterpolation[#, {grid, grid}] & /@ solmat;
  53.  
  54. Outer[Plot3D[#@First[#2][x, y], {x, 0, R}, {y, 0, R}, PlotLabel -> #@Last@#2] &, {Re,
  55. Im}, {{solu, "u"}, {solv, "v"}}, 1] // Grid
Add Comment
Please, Sign In to add comment