4
$\begingroup$

I am solving Laplace equation on circular domain from which i get solution for potential.
The code I used:

w = ImplicitRegion[x^2 + y^2 <= 4, {{x, -2, 2}, {y, -2, 2}}]
op = -Laplacian[u[x, y], {x, y}]
h = {DirichletCondition[u[x, y] == 50, x^2 + y^2 == 4 && x > 1.99], 
   DirichletCondition[u[x, y] == -50, x^2 + y^2 == 4 && x < -1.99]};
uif = NDSolveValue[{op == 
    NeumannValue[0, x^2 + y^2 == 4 && -1.9 < x < 1.9], h}, 
  u, {x, y} \[Element] w]
ContourPlot[uif[x, y], {x, y} \[Element] w, 
 ColorFunction -> "Temperature", AspectRatio -> Automatic, 
 Contours -> 30]

Solution

Now i would like to calculate current density (gradient of potential) from solution for potential and plot it as vector field on the same graph. Can this be done with some built in function or how would i go about this?

$\endgroup$
2
  • $\begingroup$ Your graphic doesn't correspond to the code. $\endgroup$ Commented Jul 30, 2018 at 11:36
  • $\begingroup$ @andre Thanks. I fixed it now. $\endgroup$ Commented Jul 30, 2018 at 11:41

3 Answers 3

5
$\begingroup$

You can use the function StreamPlot and combine plots with Show.

contour = ContourPlot[uif[x, y], {x, y} ∈ w, ColorFunction -> "Temperature", Contours -> 20];
stream = StreamPlot[ Evaluate@Grad[uif[x, y], {x, y}], {x, y} ∈ w];

Show[contour, stream]

streamPlot

$\endgroup$
1
  • $\begingroup$ That' s what I wanted. Thanks. $\endgroup$ Commented Jul 30, 2018 at 11:38
2
$\begingroup$

How about:

VectorPlot[Evaluate[Grad[uif[x, y], {x, y}]], 
 Element[{x, y}, uif["ElementMesh"]]]

enter image description here

$\endgroup$
2
$\begingroup$

StreamDensityPlot does all what you need :

field=Grad[uif[x, y],{x,y}];
StreamDensityPlot[field, {x, y} \[Element] w,
  Mesh->{{{20,Directive[Thick,Dashed]},18,16,14,12,{10,Thick}}},
  MeshStyle->Black,
  StreamStyle-> Black,
  ColorFunctionScaling->False,
  ColorFunction-> (Hue[#5/100.]&)
  ]  

enter image description here

I have interpreted the "current density" in your question as the module of the gradient of the potential (= the module of the field, that is to say a scalar, not a vector). That's the reason why I have added the iso-current-density curves (the black curves) in the graphic.

EDIT

A version with a legend :

field=Grad[uif[x, y],{x,y}];
StreamDensityPlot[field, {x, y} \[Element] w,
  Mesh->{{{20,Directive[Thick,Dashed]},18,16,14,12,{10,Thick}}},
  MeshStyle->Black,
  PlotLegends->Automatic,
  StreamStyle-> Black,
  RegionFunction->Function[{x,y,vx,vy,n},n<70],
  ColorFunction-> Hue
  ]   

enter image description here

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.