Пример #1
0
    # update sol.
    c0.assign(w.sub(0))

    # # acochambramento c (c<1) and (c>0)
    # val = c0.dat.data
    # if np.any((val > cIn) + (val < np.sqrt(tol))):
    #     val[val > cIn] = 1.
    #     val[val < np.sqrt(tol)] = tol
    #     c0.dat.data[:] = val

    # %%
    # 5) print results
    if it % freq_res == 0 or t == sim_time:
        if verbose:
            contours = fd.tripcolor(c0)
            plt.xlabel(r'$x$')
            plt.ylabel(r'$y$')
            plt.colorbar(contours)
            plt.show()

        # Computed flux, scalar, and trace
        c_h, q_h, lamb = w.split()
        c_h.rename("c_h")
        q_h.rename("q_h")

        # print results
        outfile.write(c_h, q_h, time=t)
        print('-- write results @ t= {}'.format(t))

print(f'DOF = {W.dim()}')
if verbose:
    fd.triplot(mesh)
    plt.legend()
    plt.savefig("plots/sb_adr_supg_mesh.png")

# Define subdomains
x = fd.SpatialCoordinate(mesh)
logical = fd.And(fd.And(x[0] > Lx * wx, x[1] > Ly * wy),
                 fd.And(x[0] < Lx * (1 - wx), x[1] < Ly * (1 - wy)))
square = fd.conditional(logical, 1 / k_cavern, 1 / k_porous)

ikm = fd.Function(fd.FunctionSpace(mesh, "DG", 0))
ikm.interpolate(square)
if verbose:
    contours = fd.tripcolor(ikm, cmap="viridis")
    cbar = plt.colorbar(contours, aspect=10)
    cbar.set_label("Porous Domain")
    plt.savefig("plots/sb_adr_supg_doamins.png")

# 3) Setting problem (FunctionSpace, Init.Bound.Condition, VariationalForms)

# 3.1) Set Function spaces
V = fd.VectorFunctionSpace(mesh, "CG", order + 1)
P = fd.FunctionSpace(mesh, "CG", order)

# Define function space for system of concentrations (transport)
X = fd.FunctionSpace(mesh, "CG", order)

# Others function space
DG0 = fd.FunctionSpace(mesh, "DG", 0)
Пример #3
0
def tripcolor(function, *args, **kwargs):
    r"""Create a pseudo-color plot of a finite element field"""
    return firedrake.tripcolor(_project_to_2d(function), *args, **kwargs)
if verbose:
    fd.triplot(mesh)
    plt.legend()
    plt.savefig("SB_hdiv_mesh.png")

# Define subdomains
x = fd.SpatialCoordinate(mesh)
# domain = fd.And(fd.And(x[0] > Lx*wx, x[1] > Ly*wy),
#                 fd.And(x[0] < Lx*(1-wx), x[1] < Ly*(1-wy)))
domain = x[1] < Ly * wy
square = fd.conditional(domain, 1 / k_cavern, 1 / k_porous)

ikm = fd.Function(fd.FunctionSpace(mesh, "DG", 0), name='invK')
ikm.interpolate(square)
if verbose:
    contours = fd.tripcolor(ikm, shading='flat', cmap="viridis")
    cbar = plt.colorbar(contours, aspect=10)
    cbar.set_label('Porous Domain')
    plt.savefig("plots/SB_hdiv_doamins.png")

# 3) Setting problem (FunctionSpace, Init.Condition, VariationalForms)
# 3.1) Function spaces
if quad_mesh:
    RT1 = fd.FunctionSpace(mesh, "RTCF", order)
    DG0 = fd.FunctionSpace(mesh, "DQ", order - 1)
else:
    RT1 = fd.FunctionSpace(mesh, "RT", order)
    DG0 = fd.FunctionSpace(mesh, "DG", order - 1)

# Create mixed function spaces
W = RT1 * DG0
Пример #5
0
    # Setup Plot
    ukw = {'vmin': 0.0, 'vmax': +0.2}
    kw = {'vmin': -4, 'vmax': +4, 'shading': 'gouraud'}
    title_fontsize = 20
    text_fontsize = 20
    fig, axes = plt.subplots(ncols=3, nrows=1+len(methods), sharex=True, sharey=True, figsize=(20,30), dpi=200)
    plt.suptitle('Estimating Log-Conductivity $q$ \n    where $k = k_0e^q$ and $-\\nabla \\cdot k \\nabla u = f$ for known $f$', fontsize=title_fontsize)
    for ax in axes.ravel():
        ax.set_aspect('equal')

    # Plot True solution
    print('plotting true solution')
    # Column 0
    axes[0, 0].set_title('$u_{true}$', fontsize=title_fontsize)
    colors = firedrake.tripcolor(u_true, axes=axes[0, 0], shading='gouraud', **ukw)
    cax = make_axes_locatable(axes[0, 0]).append_axes("right", size="5%", pad=0.05)
    fig.colorbar(colors, cax=cax)
    # Column 1
    axes[0, 1].set_title('$q_{true}$', fontsize=title_fontsize)
    colors = firedrake.tripcolor(q_true, axes=axes[0, 1], **kw)
    cax = make_axes_locatable(axes[0, 1]).append_axes("right", size="5%", pad=0.05)
    fig.colorbar(colors, cax=cax)
    # Column 2
    axes[0, 2].set_title('$q_{true}-q_{true}$', fontsize=title_fontsize)
    zero_func = firedrake.Function(Q).assign(q_true-q_true)
    axes[0, 2].text(0.5, 0.5, f'$L^2$ Norm {firedrake.norm(zero_func, "L2"):.2f}', ha='center', fontsize=text_fontsize)
    colors = firedrake.tripcolor(zero_func, axes=axes[0, 2], **kw);
    cax = make_axes_locatable(axes[0, 2]).append_axes("right", size="5%", pad=0.05)
    fig.colorbar(colors, cax=cax)
Пример #6
0
if verbose:
    fd.triplot(mesh)
    plt.legend()
    plt.savefig("SB_hdiv_mesh.png")

# Define subdomains
x = fd.SpatialCoordinate(mesh)
domain = fd.And(fd.And(x[0] > Lx * wx, x[1] > Ly * wy),
                fd.And(x[0] < Lx * (1 - wx), x[1] < Ly * (1 - wy)))
square = fd.conditional(domain, 1 / k_cavern, 1 / k_porous)

ikm = fd.Function(fd.FunctionSpace(mesh, "DG", 0), name='invK')
ikm.interpolate(square)
if verbose:
    contours = fd.tripcolor(ikm, shading='flat', cmap="viridis")
    cbar = plt.colorbar(contours, aspect=10)
    cbar.set_label('Porous Domain')
    plt.savefig("plots/SB_hdiv_doamins.png")

# 3) Setting problem (FunctionSpace, Init.Condition, VariationalForms)
# 3.1) Function spaces
if quad_mesh:
    RT1 = fd.FunctionSpace(mesh, "RTCF", order)
    DG0 = fd.FunctionSpace(mesh, "DQ", order - 1)
else:
    RT1 = fd.FunctionSpace(mesh, "RT", order)
    DG0 = fd.FunctionSpace(mesh, "DG", order - 1)

# Create mixed function spaces
W = RT1 * DG0