# How to make vector field plot from NDSolveValue Solution?

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] 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?

• Your graphic doesn't correspond to the code. Jul 30 '18 at 11:36
• @andre Thanks. I fixed it now. Jul 30 '18 at 11:41

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] • That' s what I wanted. Thanks. Jul 30 '18 at 11:38

VectorPlot[Evaluate[Grad[uif[x, y], {x, y}]],
Element[{x, y}, uif["ElementMesh"]]] 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.]&)
] 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
] 