<jupyter_start><jupyter_text>Green's function============== Fundamental solution-------------------------------$E$ here is the fundamental solution for the Laplacian<jupyter_code>from sympy import *
from sympy.physics.vector.functions import dot
init_printing()
x1, x2, xi1, xi2 = symbols('x_1 x_2 xi_1 xi_2')
E = -1/(2*pi) * log(sqrt((x1-xi1)**2 + (x2-xi2)**2))
E<jupyter_output><empty_output><jupyter_text>**Task**: Check that $\nabla^2_\xi E = 0$ for $x \neq \xi$.*Hint*: https://docs.sympy.org/latest/tutorial/calculus.htmlderivatives<jupyter_code>A = diff(E,x1,2)+diff(E,x2,2)
A
simplify(A)<jupyter_output><empty_output><jupyter_text>Directional derivative------------------------------<jupyter_code>n1, n2 = symbols('n_1 n_2')
n = Matrix([n1,n2])
gradE = Matrix([diff(E,x1),diff(E,x2)])<jupyter_output><empty_output><jupyter_text>**Task**: Compute the directional derivative $\frac{\partial E}{\partial n}$.<jupyter_code>DirDerE = (n1/sqrt(n1**2+n2**2))*diff(E,x1) + (n2/sqrt(n1**2+n2**2))*diff(E,x2)
DirDerE<jupyter_output><empty_output><jupyter_text>**Task** (optional): Write a function which returns the directional derivative of an expression.<jupyter_code>def ddn(expr):
    NewExpr = (n1/sqrt(n1**2+n2**2))*diff(expr,x1) + (n2/sqrt(n1**2+n2**2))*diff(expr,x2)
    #NewExpr = diff(expr,x1) + diff(expr,x2)
    
    return NewExpr
    #pass
ddn(E)<jupyter_output><empty_output><jupyter_text>Reflection principle---------------------------- For simple geometries Green's function can sometimes be found by reflecting the fundamental solution at the boundary and linearly combining the fundamental solution with its reflection.  ![reflection principle](reflection_principle.png) **Task**: Based on $E$, find the solution for the half-space problem\begin{align*}    \nabla^2G(x,\xi) &= -\delta(x-\xi), & \xi\in\Omega \\    G(x,\xi) &= 0, & \xi\in\partial\Omega \\    \Omega &= \{\xi\in\mathbb{R}^2 : \xi_2 > 0\}\end{align*}*Hint*: https://docs.sympy.org/latest/tutorial/basic_operations.htmlsubstitution<jupyter_code>G = ddn(E)

Reflection = G.subs(x2, -x2)
TotalGreen = Reflection + G

SubsGreen = TotalGreen.subs(n1,0).subs(n2,-1)

SubsGreen<jupyter_output><empty_output><jupyter_text>**Check condition**<jupyter_code>SubsGreen.subs(xi2,0)<jupyter_output><empty_output><jupyter_text>**Task**: Based on $E$, find the solution for the half-space problem\begin{align*}    \nabla^2G(x,\xi) &= -\delta(x-\xi), & \xi\in\Omega \\    \frac{\partial G(x,\xi)}{\partial n} &= 0, & \xi\in\partial\Omega \\    \Omega &= \{\xi\in\mathbb{R}^2 : \xi_2 > 0\}\end{align*}<jupyter_code>Reflection = E.subs(x2, -x2)
TotalGreen = Reflection + E
TotalGreen<jupyter_output><empty_output><jupyter_text>**Check condition**\begin{align*}    \frac{\partial G(x,\xi)}{\partial n} &= 0, & \xi\in\partial\Omega\end{align*}<jupyter_code>ddn(TotalGreen).subs(n1,0).subs(n2,-1).subs(x2,0)<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.2154696132596685, 'fraction_numerical': 0.028660220994475138, 'mean_word_length': 5.022869022869023, 'pattern_counts': {'":': 0, '<': 37, '<?xml version=': 0, '>': 39, 'https://': 2, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '9', 'dir': 'jupyter-structured-clean-dedup', 'id': '452808', 'license': 'MIT', 'n_tokens_mistral': 1145, 'n_tokens_neox': 1103, 'n_words': 182, 'path': 'PythonCodes/Exercises/Class-SEAS/green/green.ipynb', 'repo_name': 'Nicolucas/TEAR', 'size': '2896'}