Derive the form of a test variable-coefficient elliptic equation with periodic boundary conditions for testing the variable-coefficient multigrid solver.
We want to solve an equation of the form $\nabla \cdot (\alpha \nabla \phi) = f$
Note: it is important for solvability that the RHS, f, integrate to zero over our domain. It seems sufficient to ensure that phi integrates to zero to have this condition met.
In [1]:
    
%pylab inline
    
    
In [2]:
    
from sympy import init_session
init_session()
    
    
In [3]:
    
alpha = 2.0 + cos(2*pi*x)*cos(2*pi*y)
    
In [4]:
    
phi = sin(2*pi*x)*sin(2*pi*y)
    
we want to compute $\nabla \cdot (\alpha \nabla \phi)$
In [5]:
    
phi_x = diff(phi, x)
phi_y = diff(phi, y)
    
In [6]:
    
f = diff(alpha*phi_x, x) + diff(alpha*phi_y, y)
    
In [7]:
    
f = simplify(f)
f
    
    Out[7]:
In [8]:
    
print(f)
    
    
In [9]:
    
phi.subs(x, 0)
    
    Out[9]:
In [10]:
    
phi.subs(x, 1)
    
    Out[10]:
In [11]:
    
phi.subs(y, 0)
    
    Out[11]:
In [12]:
    
phi.subs(y, 1)
    
    Out[12]:
Derive the form of a test variable-coefficient elliptic equation with periodic boundary conditions for testing the variable-coefficient multigrid solver.
We are solving
$$\alpha \phi + \nabla \cdot (\beta \nabla \phi ) + \gamma \cdot \nabla \phi = f$$Note: it is important for solvability that the RHS, f, integrate to zero over our domain. It seems sufficient to ensure that phi integrates to zero to have this condition met.
In [13]:
    
phi = sin(2*pi*x)*sin(2*pi*y)
    
In [14]:
    
phi
    
    Out[14]:
In [15]:
    
alpha = 1.0
beta = 2.0 + cos(2*pi*x)*cos(2*pi*y)
gamma_x = sin(2*pi*x)
gamma_y = sin(2*pi*y)
    
In [16]:
    
alpha
    
    Out[16]:
In [17]:
    
beta
    
    Out[17]:
In [18]:
    
gamma_x
    
    Out[18]:
In [19]:
    
gamma_y
    
    Out[19]:
In [20]:
    
phi_x = diff(phi, x)
phi_y = diff(phi, y)
    
In [21]:
    
f = alpha*phi + diff(beta*phi_x, x) + diff(beta*phi_y, y) + gamma_x*phi_x + gamma_y*phi_y
    
In [22]:
    
f = simplify(f)
f
    
    Out[22]:
In [23]:
    
print(f)
    
    
In [24]:
    
print(alpha)
    
    
In [25]:
    
print(beta)
    
    
In [26]:
    
print(gamma_x)
    
    
In [27]:
    
print (gamma_y)
    
    
In [ ]:
    
    
In [28]:
    
phi = cos(Rational(1,2)*pi*x)*cos(Rational(1,2)*pi*y)
    
In [29]:
    
phi
    
    Out[29]:
In [30]:
    
alpha = 10
gamma_x = 1
gamma_y = 1
beta = x*y + 1
    
In [31]:
    
phi_x = diff(phi, x)
phi_y = diff(phi, y)
f = alpha*phi + diff(beta*phi_x, x) + diff(beta*phi_y, y) + gamma_x*phi_x + gamma_y*phi_y
    
In [32]:
    
f
    
    Out[32]:
In [33]:
    
simplify(f)
    
    Out[33]:
In [34]:
    
phi.subs(x,0)
    
    Out[34]:
In [35]:
    
phi.subs(x,1)
    
    Out[35]:
In [36]:
    
phi.subs(y,0)
    
    Out[36]:
In [37]:
    
phi.subs(y,1)
    
    Out[37]:
In [ ]: