Exemplo n.º 1
0
    def plot(self, fig=None, axes=None, **kwargs):
        """
        Plot the meshes comprising a 2D :class:`MeshSeq`.

        :kwarg fig: matplotlib figure
        :kwarg axes: matplotlib axes
        :kwargs: parameters to pass to Firedrake's :func:`triplot`
            function
        :return: matplotlib figure and axes for the plots
        """
        if self.dim != 2:
            raise ValueError("MeshSeq plotting only supported in 2D")
        kwargs.setdefault("interior_kw", {"edgecolor": "k"})
        kwargs.setdefault("boundary_kw", {"edgecolor": "k"})
        if (fig is None and axes is None):
            from matplotlib.pyplot import subplots

            n = len(self)
            size = (5 * n, 5)
            fig, axes = subplots(ncols=n, nrows=1, figsize=size)
        i = 0
        for axis in axes:
            if not isinstance(axis, Iterable):
                axis = [axis]
            for ax in axis:
                ax.set_title(f"MeshSeq[{i}]")
                firedrake.triplot(self.meshes[i], axes=ax, **kwargs)
                ax.axis(False)
                i += 1
        return fig, axes
Exemplo n.º 2
0
# problem parameters
verbose = True
freq_res = 50
CFL = 0.25
sim_time = 50.0  # simulation time

# %%
# Process section (simulation)
# ============================

# 2) Define mesh
print('* define mesh')
mesh = fd.RectangleMesh(nx * n, ny * n, Lx, Ly, quadrilateral=quad_mesh)

if verbose:
    fd.triplot(mesh)
    plt.legend()
    plt.savefig("plots/darcy_rt.png")

# ----
# 3) Setting problem (FunctionSpace, Init.Condition, VariationalForms)
print('* setting problem')

# 3.1) # Define function space for system
if quad_mesh:
    RT = fd.FunctionSpace(mesh, "RTCF", order)
    DG = fd.FunctionSpace(mesh, "DQ", order - 1)

    # Others function space
    V = fd.VectorFunctionSpace(mesh, "DQ", order - 1)
    T = fd.TensorFunctionSpace(mesh, "DQ", order - 1)
Exemplo n.º 3
0
d = options.turbine_diameter
deltax = 10.0 * d
deltay = 7.5 * d
centres = []
for i in range(-2, 3):
    for j in range(1, -2, -1):
        if config == "aligned":
            centres.append((i * deltax, j * deltay))
        elif config == "staggered":
            centres.append((i * deltax, (j + 0.25 * (-1)**i) * deltay))
        else:
            raise NotImplementedError  # TODO

# Plot whole mesh
fig, axes = plt.subplots(figsize=(12, 4))
triplot(options.mesh2d, axes=axes, **kwargs)
axes.legend().remove()
axes.set_xlim([-L / 2 - l, L / 2 + l])
axes.set_ylim([-W / 2 - l, W / 2 + l])
axes.set_xlabel(r"$x$-coordinate $[\mathrm m]$")
axes.set_ylabel(r"$y$-coordinate $[\mathrm m]$")
axes.set_yticks(np.linspace(-W / 2, W / 2, 5))
plt.tight_layout()
for i, loc in enumerate(centres):
    patch_kwargs["edgecolor"] = f"C{i // 3}"
    centre = (loc[0] - w / 2, loc[1] - d / 2)
    axes.add_patch(ptch.Rectangle(centre, w, d, **patch_kwargs))
plt.savefig(f"{plot_dir}/{config}_mesh.pdf")

# Zoom in on array region
axes.set_xlim([-625, 625])
                            if mesh_name not in [
                                    'circle_in_square', 'ball_in_cube',
                                    'circle_in_square_no_pml'
                            ]:
                                raise NotImplementedError(
                                    "2nd order mesh only avaiilbale" +
                                    " for circle_in_square, circle_in_square_no_pml, or ball_in_cube. "
                                    + " Not available for '%s'" % mesh_name)
                            mesh = to_2nd_order(mesh, inner_bdy_id,
                                                mesh_options['radius'])
                        logger.info("Mesh read in")

                        if visualize:
                            from firedrake import triplot
                            import matplotlib.pyplot as plt
                            triplot(mesh)
                            plt.title("h=%.2e" % cell_size)
                            plt.show()

                    # make sure to store mesh in trial
                    trial['mesh'] = mesh

                    kwargs = method_to_kwargs[method]
                    true_sol, comp_sol, snes_or_ksp = run_method.run_method(
                        trial,
                        method,
                        cl_ctx=cl_ctx,
                        queue=queue,
                        clear_memoized_objects=clear_memoized_objects,
                        comp_sol_name=method + " Computed Solution",
                        **kwargs)
Exemplo n.º 5
0
def triplot(mesh, *args, **kwargs):
    r"""Plot a mesh with a different color for each boundary segment"""
    return firedrake.triplot(mesh, *args, **kwargs)