Flow of a Darcy fluid through a lens of low permeability

Flow of a Darcy fluid through a lens of low permeability#

\[\begin{split} \mathbb{S}_{\textbf{u},p} \begin{cases} \Omega = [-L_x/2, L_x/2] \times [-L_y/2, L_y/2] \\ \mathsf{K}=\begin{cases} K^-(x,y)\mathsf{I} & (x/a)^2 + (y/b)^2 < 1 \\ K^+(x,y)\mathsf{I} & \text{otherwise} \end{cases} & \text{lens of low permeability} \\ \mu = 1 \\ u_{\text{E}}(x,y=\pm L_y/2) = 0 & \text{no-penetration on upper and lower boundaries} \\ p_{\text{N}}(x=-L_x/2,y) = p_{\text{in}} & \text{high-pressure left boundary} \\ p_{\text{N}}(x=L_x/2,y) = 0 & \text{low-pressure left boundary} \\ \end{cases} \end{split}\]
import numpy as np
from lucifex.mesh import rectangle_mesh, mesh_boundary
from lucifex.fem import Function, Constant
from lucifex.solver import bvp, BoundaryConditions, OptionsPETSc
from lucifex.utils import get_component_fem_functions
from lucifex.viz import plot_colormap, plot_streamlines, plot_quiver, save_figure
from lucifex.pde.darcy import darcy_incompressible

Lx = 2.0
Ly = 1.0
Nx = 200
Ny = 200
mesh = rectangle_mesh((-Lx/2 , Lx/2), (-Ly/2, Ly/2), Nx, Ny, cell='right')
boundary = mesh_boundary(
    mesh, 
    {
        "left": lambda x: x[0] + Lx/2,
        "right": lambda x: x[0] - Lx/2,
        "lower": lambda x: x[1] + Ly/2,
        "upper": lambda x: x[1] - Ly/2,
    },
)

mu = Constant(mesh, 1.0, 'mu')

u_deg = 1
u_elem = ('BDM', u_deg)
p_elem = ('DP', u_deg - 1)
u_p_elem = [u_elem, p_elem]

u_bcs = BoundaryConditions(
    ('essential', boundary['upper', 'lower'], (0.0, 0.0), 0),
)
p_in = 1.0
p_bcs = BoundaryConditions(
    ('natural', boundary['left'], p_in, 1),
    ('natural', boundary['right'], 0.0, 1),
)

petsc = OptionsPETSc(
    ksp_type='gmres', 
    pc_type='lu', 
    pc_factor_mat_solver_type='mumps',
)

k_minus, k_plus = 0.05, 1.0
a, b = (0.2 * Lx, 0.2 * Ly)
r2 = lambda x: (x[0] / a)**2 + (x[1] / b)**2
k_dcts = Function(
    (mesh, 'DP', 0), 
    lambda x: k_plus + (k_minus - k_plus) * (r2(x) < 1), 
    name='kDP',
)
eps = 0.2
k_cts = Function(
    (mesh, 'P', 1), 
    lambda x: 0.5 * (k_plus - k_minus) * np.tanh((r2(x) - 1) / eps) + 0.5 * (k_plus + k_minus), 
    name='kP',
)

solutions: dict[str, Function] = {}

for k in (k_dcts, k_cts):
    up = Function((mesh, u_p_elem), name="up")
    up_solver = bvp(darcy_incompressible, u_bcs, petsc)(up, k, mu, bcs=p_bcs)
    up_solver.solve()
    solutions[k.name] = up
for k in (k_dcts, k_cts):
    up = solutions[k.name]
    u, p = up.split(('u', 'p'), collapse=True)
    ux, uy = get_component_fem_functions(('P', 1), u, names=('ux', 'uy'))
    fig, ax = plot_colormap(p, title='$p$', x_label='$x$', y_label='$y$')
    plot_streamlines(fig, ax, (ux, uy), density=0.75, color='cyan')
    save_figure(f'{k.name}_p(x,y)', thumbnail=(k is k_dcts))(fig)
    fig, ax = plot_quiver((ux, uy), arrow_slc=7, title="$\mathbf{u}=(u_x, u_y)$")
    save_figure(f'{k.name}_u(x,y)')(fig)
    fig, ax = plot_colormap(k, title='$K$')
../../_images/75b910bed3200534d3bc45de585139e33490e62a17dd2c5825be69fefdaf6e2c.png ../../_images/781934fdd956e09bb159c25e879f71dcd3176b95595c6397db545a9be5a7605b.png ../../_images/96eb205d646736c8cb08ffba1c6ce2122d6d2d7250727b743eeecc937d6bda0d.png ../../_images/8d502f06bb143a3729b09fde70ff85f2ac9c5516e7b6ccc9d8de6eb699b58a12.png ../../_images/25e9826b1a3a0714081a5366a45f3be5528d302a9900755cfb6c3e8b2d3c8509.png ../../_images/f556281c0631cf598e90ae72bbb3b8d037a4386d05df6ddaf1fa5b3f56dde568.png
The Kernel crashed while executing code in the current cell or a previous cell. 

Please review the code in the cell(s) to identify a possible cause of the failure. 

Click <a href='https://aka.ms/vscodeJupyterKernelCrash'>here</a> for more info. 

View Jupyter <a href='command:jupyter.viewOutput'>log</a> for further details.