MATH 3500 3.6 Demo: The Gravity Well

This notebook is a demonstration of the process of finding harmonic functions numerically with Mathematica.
Jason Cantarella, Fall 2022.

Exit[]

GravityWell[{x1_,y1_},{x2_,y2_},sf_]:= Block[{R,sol,gradient},
R=BooleanRegion[#1 ∧ ¬#2∧ ¬#3&,{Disk[{0,0},5],Disk[{x1,y1},0.1],Disk[{x2,y2},0.1]}];
(*The region R is a large disk (the universe) with two small disks subtracted *)

sol = NDSolve[{
Laplacian[f[x,y],{x,y}]==0, 
(*This is the differential equation  *)
DirichletCondition[f[x,y]==0,x^2 + y^2 == (5^2)],
DirichletCondition[f[x,y]==-10,(x-x1)^2 + (y-y1)^2 == 0.1^2],
DirichletCondition[f[x,y]==-15,(x-x2)^2 + (y-y2)^2 == 0.1^2]},
(*These three lines establish "boundary conditions", telling us the 
value of the function f[x,y] on the three circles bounding the 
2d region R *)

f,{x,y}∈R][[1,1,2]];

gradient = {Derivative[1,0][sol][x,y],Derivative[0,1][sol][x,y]};
(* The Derivative[n,m] operator differentiates n times with respect to the 
first variable and m times with respect to the second. If the function is 
smooth enough  the order doesn't matter. *)

If[sf,
Plot3D[sol[x,y],{x,y} ∈ R,ImageSize->Large,ViewPoint->Above,PlotRange->Full],
(* This is a 3d plot of the graph of the harmonic function *)
StreamPlot[-gradient,{x,y} ∈ R,ImageSize->Large]
(* This is a vector field plot of the gradient of the function *)
]
]

Manipulate[GravityWell[{0.3,0.4},{-1,-1.5},sf],{sf,{True,False}}]