Skip to content

Commit

Permalink
Remove edges and gauges from geometry. Test grid plotting.
Browse files Browse the repository at this point in the history
  • Loading branch information
ketch committed Dec 1, 2016
1 parent 9b0daae commit c194524
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 68 deletions.
73 changes: 5 additions & 68 deletions geometry.py
Expand Up @@ -10,7 +10,6 @@
import six
from six.moves import range
from six.moves import zip
deprec_message = "'edges' has been deprecated; please use 'nodes' instead."
# ============================================================================
# Default function definitions
# ============================================================================
Expand Down Expand Up @@ -143,6 +142,8 @@ class Grid(object):
[array([ 0.1, 0.3, 0.5, 0.7, 0.9])]
>>> grid1d.c_nodes
[array([ 0. , 0.2, 0.4, 0.6, 0.8, 1. ])]
>>> grid1d.c_nodes_with_ghost(2)
[array([-0.4, -0.2, 0. , 0.2, 0.4, 0.6, 0.8, 1. , 1.2, 1.4])]
"""

Expand Down Expand Up @@ -395,62 +396,8 @@ def p_centers_with_ghost(self,num_ghost):
def p_nodes_with_ghost(self,num_ghost):
return self.mapc2p(*self.c_nodes_with_ghost(num_ghost))

# ========================================================================
# Edges: deprecated; will be removed in 6.0
@property
def c_edges(self):
warnings.warn(deprec_message)
return self.c_nodes
@property
def p_edges(self):
warnings.warn(deprec_message)
return self.p_nodes
def p_edges_with_ghost(self,num_ghost):
warnings.warn(deprec_message)
return self.p_nodes_with_ghost(num_ghost)
def c_edges_with_ghost(self, num_ghost):
warnings.warn(deprec_message)
return self.c_nodes_with_ghost(num_ghost)
# ========================================================================


# ========================================================================
# Gauges
# ========================================================================
def add_gauges(self,gauge_coords):
r"""
Determine the cell indices of each gauge and make a list of all gauges
with their cell indices.
"""
for gauge in gauge_coords:
# Check if gauge belongs to this grid:
if all(self.lower[n]<=gauge[n]<self.upper[n] for n in range(self.num_dim)):
# Set indices relative to this grid
gauge_index = [int(round((gauge[n]-self.lower[n])/self.delta[n]))
for n in range(self.num_dim)]
gauge_file_name = 'gauge'+'_'.join(str(coord) for coord in gauge)+'.txt'
self.gauge_file_names.append(gauge_file_name)
self.gauges.append(gauge_index)

def setup_gauge_files(self,outdir):
r"""
Creates and opens file objects for gauges.
"""
import os
gauge_path = os.path.join(outdir,self.gauge_dir_name)
if not os.path.exists(gauge_path):
try:
os.makedirs(gauge_path)
except OSError:
print("gauge directory already exists, ignoring")

for gauge in self.gauge_file_names:
gauge_file = os.path.join(gauge_path,gauge)
if os.path.isfile(gauge_file):
os.remove(gauge_file)
self.gauge_files.append(open(gauge_file,'a'))

def plot(self,num_ghost=0,mapped=True,mark_nodes=False,mark_centers=False):
def plot(self,num_ghost=0,mapped=True,mark_nodes=False,mark_centers=False,ax=None):
r"""Make a plot of the grid.
By default the plot uses the mapping
Expand All @@ -461,7 +408,8 @@ def plot(self,num_ghost=0,mapped=True,mark_nodes=False,mark_centers=False):
"""
import matplotlib.pyplot as plt
if self.num_dim == 2:
fig, ax = plt.subplots(1,1)
if ax is None:
fig, ax = plt.subplots(1,1)
if num_ghost>0:
if mapped:
xe, ye = self.p_nodes_with_ghost(num_ghost)
Expand Down Expand Up @@ -550,17 +498,6 @@ def delta(self):
r"""(float) - Size of an individual, computational cell"""
return (self.upper-self.lower) / float(self.num_cells)

# ========== Edges: deprecated; will be removed in 6.0 =======
@property
def edges(self):
warnings.warn(deprec_message)
return self.nodes

def edges_with_ghost(self,num_ghost):
warnings.warn(deprec_message)
return self.nodes_with_ghost(num_ghost)
# ========================================================================


# ========== Centers and nodes ========================================
@property
Expand Down
23 changes: 23 additions & 0 deletions tests/plot_tests.py
Expand Up @@ -31,10 +31,33 @@ def run_pyclaw_2d():
claw = examples.radial_dam_break.setup()
claw.run()
return claw

def set_up_mapped_grid():

def square2circle(xc,yc,r1=1.0):
d = np.maximum(np.abs(xc),np.abs(yc))
r = np.sqrt(xc**2 + yc**2)
r = np.maximum(r, 1.e-10)
xp = r1 * d * xc/r
yp = r1 * d * yc/r
return [xp, yp]

x = griddle.Dimension(-1.,1.,12, name='x')
y = griddle.Dimension(-1.,1.,10, name='y')
grid = griddle.geometry.Grid((x,y))
grid.mapc2p = square2circle
return grid
# ===================================

# ===================================
# Test functions
@image_comparison(baseline_images=['mapped_grid'],extensions=['png'])
def test_plot_mapped_grid():
fig = plt.figure()
ax = fig.add_subplot(111)
grid = set_up_mapped_grid()
grid.plot(num_ghost=1,ax=ax);

@image_comparison(baseline_images=['item'],extensions=['png'])
def test_plot_item():
fig = plt.figure(figsize=(8,6),dpi=100)
Expand Down

0 comments on commit c194524

Please sign in to comment.