Grid Generation Basics¶
This section will cover:
- Loading and visualizing boundary data
- Generating visualizing a basic grid
- Adding focus to the grid
This is sorely lacking in detail and explanation. For more help on this matter, see the pygridgen documentation.
In [1]:
%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 [2]:
domain = geopandas.read_file('basic_data/domain.geojson')
domain
Out[2]:
beta | geometry | |
---|---|---|
0 | 1 | POINT (6 1) |
1 | 0 | POINT (2 11) |
2 | 1 | POINT (2 23) |
3 | 1 | POINT (10 23) |
4 | 0 | POINT (13 17) |
5 | -1 | POINT (10 10) |
6 | 1 | POINT (18 10) |
7 | 1 | POINT (18 8) |
8 | -1 | POINT (15 8) |
9 | 1 | POINT (15 2) |
10 | 1 | POINT (13 2) |
11 | -1 | POINT (13 8) |
12 | -1 | POINT (10 8) |
13 | 1 | POINT (10 1) |
14 | 0 | POINT (6 1) |
In [3]:
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 [4]:
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])
Out[4]:
(0, 25)
Using focus to refine and coarsen portions of the grid¶
In [5]:
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])
Out[5]:
(0, 25)