Grid Generation Basics

This section will cover:

  1. Loading and visualizing boundary data
  2. Generating visualizing a basic grid
  3. Adding focus to the grid

This is sorely lacking in detail and explanation. For more help on this matter, see the pygridgen documentation.


In [ ]:
%matplotlib inline
import warnings
warnings.simplefilter('ignore')

import numpy as np
import matplotlib.pyplot as plt
import pandas
import geopandas

import pygridgen as pgg
import pygridtools as pgt

Loading and plotting the boundary data


In [ ]:
domain = geopandas.read_file('basic_data/domain.geojson')
domain

In [ ]:
fig, ax = plt.subplots(figsize=(5, 5), subplot_kw={'aspect':'equal'})
fig = pgt.viz.plot_domain(domain, betacol='beta', ax=ax)

Generating a grid with pygridgen, plotting with pygridtools


In [ ]:
grid = pgg.Gridgen(domain.geometry.x, domain.geometry.y,
                   domain.beta, shape=(50, 50), ul_idx=2)

fig, ax = plt.subplots(figsize=(7, 7), subplot_kw={'aspect':'equal'})
fig = pgt.viz.plot_cells(grid.x, grid.y, ax=ax)
fig = pgt.viz.plot_domain(domain, betacol='beta', ax=ax)
ax.set_xlim([0, 25])
ax.set_ylim([0, 25])

Using focus to refine and coarsen portions of the grid


In [ ]:
focus = pgg.Focus()

focus.add_focus(0.90, 'y', factor=0.5, extent=0.05)
focus.add_focus(0.50, 'y', factor=5, extent=0.1)
focus.add_focus(0.65, 'x', factor=4, extent=0.2)
grid.focus = focus
grid.generate_grid()

fig, ax = plt.subplots(figsize=(7, 7), subplot_kw={'aspect':'equal'})
fig, cell_artist = pgt.viz.plot_cells(grid.x, grid.y, ax=ax)
fig, domain_artist = pgt.viz.plot_domain(domain, betacol='beta', ax=ax)
ax.set_xlim([0, 25])
ax.set_ylim([0, 25])