3

I have been trying to find the maximum value of the magnitude of an electric field in a bounded region. NDSolve gives the value of the potential inside the region once we supply the boundary conditions; the negative gradient of the potential gives the the electric field. I have this code which works well, except that it is not giving the maximum value of the electric field. Can anyone suggest the correct way of using NMaximize for this case?

Clear["Global`*"]
a = 3.6;
b = 6;
θ = 5*π/180;

Region1 = Rectangle[{0, 0}, {a, 6}];
Region2 = Triangle[{{a - b*Tan[θ], 0}, {a, 0}, {a, b}}]
reg = RegionDifference[Region1, Region2];
RegionPlot[reg]
solution = 
 NDSolveValue[{D[u[x, y], x, x] + D[u[x, y], y, y] == 0, 
   DirichletCondition[u[x, y] == 0, 
    x/Tan[θ] + b - a/Tan[θ] == y], 
   DirichletCondition[u[x, y] == -180, x == 0], 
   DirichletCondition[u[x, y] == 180*x/(a - b*Tan[θ]) - 180, 
    y == 0], DirichletCondition[u[x, y] == 50 x - 180, y == 6]}, 
  u, {x, y} ∈ reg]
EField[x_, y_] = -Grad[solution[x, y], {x, y}];
ContourPlot[solution[x, y], {x, y} ∈ reg]
VectorPlot[EField[x, y], {x, y} ∈ reg]
NMaximize[{Norm[EField[x, y]], {x, y} ∈ reg}, {x, y}]
J. M.'s missing motivation
  • 124,525
  • 11
  • 401
  • 574
Ajib Paudel
  • 109
  • 6
  • Something like this: EField2[x_?NumericQ, y_?NumericQ] := Evaluate[-Grad[solution[x, y], {x, y}]]; NMaximize[{Norm[EField2[x, y]], {x, y} \[Element] solution["ElementMesh"]}, {x, y}] perhaps? – user21 Jul 07 '16 at 18:48

1 Answers1

2

Just add:

NMaximize[{Norm[EField[x, y]], {x, y} ∈ solution["ElementMesh"]}, {x, y}]

Which gives:

{58.362, {x -> 2.95481, y -> 0.186586}}

Showing everything together:

{eMax, {xMax, yMax}} = 
 NMaximize[{Norm[EField[x, y]], {x, y} ∈ solution["ElementMesh"]}, {x, y}] /.
  sol : {__Rule} :> Values[sol]

Show[
 DensityPlot[solution[x, y], {x, y} ∈ reg, Mesh -> None, 
  ColorFunction -> "Rainbow", PlotRange -> All, 
  PlotLegends -> Automatic, AspectRatio -> b/a],
 VectorPlot[EField[x, y], {x, y} ∈ reg, VectorPoints -> 7, 
  VectorScale -> Small, VectorColorFunction -> GrayLevel],
 Graphics[{Circle[{xMax, yMax}, 0.05], Text[eMax, {xMax, yMax + 0.15}]}]
 ]

enter image description here

This answer builds on a previous answer given on calculating electric potential for a bounded 2D region: Solving 2D Laplace equation for irregular boundaries

Young
  • 7,495
  • 1
  • 20
  • 45