# coding: utf-8
# Elliptic PDE
# ===
# Poisson Problem:
#
Given open domain $\Omega \subset \mathbb{R}^2$
# $$ -\nabla \cdot \nabla u = f(x)\quad \text{in}\, \Omega $$
# $$ u = g(x)\quad \text{on}\, \partial\Omega $$
# Let:
# $$ f(x) = \delta(x) $$
# $\delta(x)$ is the Dirac delta function. This problem describes a unit charge at the origin.
# Solution
# ===
# Potential due to point charge:
# $$ u(x,y) = -\frac{1}{2\pi}\ln(r) $$
#
# $r = \sqrt{x^2+y^2}$, the distance to the origin.
# Step 1: Import packages
# ===
# - `numpy` is used for vectors and linear algebra
# - `matpllotlib.pyplot` is used for plotting
# In[1]:
get_ipython().magic('matplotlib inline')
import numpy as np
import matplotlib.pyplot as plt
from mpl_toolkits.mplot3d import Axes3D
from matplotlib import cm
import math
# Step 2: Set up grid
# ===
# In[2]:
X = np.arange(-10, 10, 0.2)
Y = np.arange(-10, 10, 0.2)
X, Y = np.meshgrid(X, Y)
# Step 3: Set solution values
# ===
# In[3]:
r = np.sqrt(X**2 + Y**2)
Z = -np.log(r)/(2*math.pi)
# Step 4: Plot solution
# ===
# In[4]:
fig = plt.figure()
ax = fig.add_subplot(111, projection='3d')
#ax.plot_surface(X, Y, Z, rstride=1, cstride=1, cmap=cm.coolwarm,
# linewidth=0, antialiased=False)
ax.plot_wireframe(X, Y, Z, linewidth=0.2)
#ax.set_zlim(-1.0, 1.0)
#plt.show()