#!/usr/bin/env python
# coding: utf-8
# # Elliptic PDE: Radially Symmetric Singular Solution
# Copyright (C) 2010-2020 Luke Olson
# Copyright (C) 2020 Andreas Kloeckner
#
#
# MIT License
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
# in the Software without restriction, including without limitation the rights
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
# copies of the Software, and to permit persons to whom the Software is
# furnished to do so, subject to the following conditions:
#
# The above copyright notice and this permission notice shall be included in
# all copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
# THE SOFTWARE.
#
#
# -----
#
# 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.
# In[18]:
import numpy as np
import matplotlib.pyplot as plt
from mpl_toolkits.mplot3d import Axes3D
from matplotlib import cm
import math
import sympy as sym
sym.init_printing()
# ## Set up Grid
# In[19]:
X = np.arange(-10, 10, 0.2)
Y = np.arange(-10, 10, 0.2)
X, Y = np.meshgrid(X, Y)
# ## Solution
# In[20]:
r = np.sqrt(X**2 + Y**2)
Z = -np.log(r)/(2*math.pi)
# ## Check Symbolically
# In[21]:
sx = sym.Symbol("x")
sy = sym.Symbol("y")
sr = sym.sqrt(sx**2 + sy**2)
ssol = sym.log(sr)
sym.simplify(sym.diff(ssol, sx, 2) + sym.diff(ssol, sy, 2))
# ## Plot
# In[23]:
fig = plt.figure(figsize=(8, 6))
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()
# Given $C\log(r)$ as the *free-space Green's function*, can we construct the solution to the PDE with a more general $f$?