Skip to content

Commit

Permalink
Merge pull request #256 from GeoscienceAustralia/anuga_py3
Browse files Browse the repository at this point in the history
Anuga py3
  • Loading branch information
stoiver committed Feb 23, 2022
2 parents 89c5ac6 + cec3cd4 commit 861bf5b
Show file tree
Hide file tree
Showing 115 changed files with 1,734 additions and 1,832 deletions.
2 changes: 1 addition & 1 deletion anuga/abstract_2d_finite_volumes/file_function.py
Expand Up @@ -262,7 +262,7 @@ def get_netcdf_file_function(filename,

if interpolation_points is not None:

#interpolation_points = num.array(interpolation_points, num.float)
#interpolation_points = num.array(interpolation_points, float)
interpolation_points = ensure_absolute(interpolation_points)
msg = 'Points must by N x 2. I got %d' % interpolation_points.shape[1]
assert interpolation_points.shape[1] == 2, msg
Expand Down
32 changes: 16 additions & 16 deletions anuga/abstract_2d_finite_volumes/gauge.py
Expand Up @@ -179,7 +179,7 @@ def sww2csv_gauges(sww_file,
gid.close()

#convert to array for file_function
points_array = num.array(points,num.float)
points_array = num.array(points,float)

points_array = ensure_absolute(points_array)

Expand Down Expand Up @@ -669,18 +669,18 @@ def _generate_figures(plot_quantity, file_loc, report, reportname, surface,
if n[i] > n0: n0 = n[i]
n0 = int(n0)
m = len(locations)
model_time = num.zeros((n0, m, p), num.float)
stages = num.zeros((n0, m, p), num.float)
elevations = num.zeros((n0, m, p), num.float)
momenta = num.zeros((n0, m, p), num.float)
xmom = num.zeros((n0, m, p), num.float)
ymom = num.zeros((n0, m, p), num.float)
speed = num.zeros((n0, m, p), num.float)
bearings = num.zeros((n0, m, p), num.float)
due_east = 90.0*num.ones((n0, 1), num.float)
due_west = 270.0*num.ones((n0, 1), num.float)
depths = num.zeros((n0, m, p), num.float)
eastings = num.zeros((n0, m, p), num.float)
model_time = num.zeros((n0, m, p), float)
stages = num.zeros((n0, m, p), float)
elevations = num.zeros((n0, m, p), float)
momenta = num.zeros((n0, m, p), float)
xmom = num.zeros((n0, m, p), float)
ymom = num.zeros((n0, m, p), float)
speed = num.zeros((n0, m, p), float)
bearings = num.zeros((n0, m, p), float)
due_east = 90.0*num.ones((n0, 1), float)
due_west = 270.0*num.ones((n0, 1), float)
depths = num.zeros((n0, m, p), float)
eastings = num.zeros((n0, m, p), float)
min_stages = []
max_stages = []
min_momentums = []
Expand All @@ -692,9 +692,9 @@ def _generate_figures(plot_quantity, file_loc, report, reportname, surface,
max_speeds = []
min_speeds = []
max_depths = []
model_time_plot3d = num.zeros((n0, m), num.float)
stages_plot3d = num.zeros((n0, m), num.float)
eastings_plot3d = num.zeros((n0, m),num.float)
model_time_plot3d = num.zeros((n0, m), float)
stages_plot3d = num.zeros((n0, m), float)
eastings_plot3d = num.zeros((n0, m),float)
if time_unit == 'mins': scale = 60.0
if time_unit == 'hours': scale = 3600.0

Expand Down
62 changes: 31 additions & 31 deletions anuga/abstract_2d_finite_volumes/general_mesh.py
Expand Up @@ -91,12 +91,12 @@ def __init__(self,

self.use_inscribed_circle = use_inscribed_circle

self.triangles = num.array(triangles, num.int)
self.triangles = num.array(triangles, int)

if verbose:
log.timingInfo("numTriangles, " + str(self.triangles.shape[0]))

self.nodes = num.array(nodes, num.float)
self.nodes = num.array(nodes, float)

# Register number of elements and nodes
self.number_of_triangles = N = int(self.triangles.shape[0])
Expand Down Expand Up @@ -128,18 +128,18 @@ def __init__(self,
xy_extent = [min(self.nodes[:,0]), min(self.nodes[:,1]),
max(self.nodes[:,0]), max(self.nodes[:,1])]

self.xy_extent = num.array(xy_extent, num.float)
self.xy_extent = num.array(xy_extent, float)

# Allocate space for geometric quantities
self.normals = num.zeros((N, 6), num.float)
self.areas = num.zeros(N, num.float)
self.edgelengths = num.zeros((N, 3), num.float)
self.normals = num.zeros((N, 6), float)
self.areas = num.zeros(N, float)
self.edgelengths = num.zeros((N, 3), float)

# Get x,y coordinates for all triangle vertices and store
self.centroid_coordinates = num.zeros((N, 2), num.float)
self.centroid_coordinates = num.zeros((N, 2), float)

#Allocate space for geometric quantities
self.radii = num.zeros(N, num.float)
self.radii = num.zeros(N, float)

# Get x,y coordinates for all triangle vertices and store
self.vertex_coordinates = V = self.compute_vertex_coordinates()
Expand Down Expand Up @@ -315,13 +315,13 @@ def __init__(self,
# # (First normal is associated with the edge opposite
# # the first vertex, etc)
# # - Stored as six floats n0x,n0y,n1x,n1y,n2x,n2y per triangle
# n0 = num.array([x2-x1, y2-y1], num.float)
# n0 = num.array([x2-x1, y2-y1], float)
# l0 = num.sqrt(num.sum(n0**2))
#
# n1 = num.array([x0-x2, y0-y2], num.float)
# n1 = num.array([x0-x2, y0-y2], float)
# l1 = num.sqrt(num.sum(n1**2))
#
# n2 = num.array([x1-x0, y1-y0], num.float)
# n2 = num.array([x1-x0, y1-y0], float)
# l2 = num.sqrt(num.sum(n2**2))
#
# # Normalise
Expand All @@ -340,7 +340,7 @@ def __init__(self,
#
#
# #Compute centroid
## centroid = num.array([(x0 + x1 + x2)/3, (y0 + y1 + y2)/3], num.float)
## centroid = num.array([(x0 + x1 + x2)/3, (y0 + y1 + y2)/3], float)
### self.centroid_coordinates[i] = centroid
##
##
Expand All @@ -349,9 +349,9 @@ def __init__(self,
## #inscribed circle
##
## #Midpoints
## m0 = num.array([(x1 + x2)/2, (y1 + y2)/2], num.float)
## m1 = num.array([(x0 + x2)/2, (y0 + y2)/2], num.float)
## m2 = num.array([(x1 + x0)/2, (y1 + y0)/2], num.float)
## m0 = num.array([(x1 + x2)/2, (y1 + y2)/2], float)
## m1 = num.array([(x0 + x2)/2, (y0 + y2)/2], float)
## m2 = num.array([(x1 + x0)/2, (y1 + y0)/2], float)
##
## #The radius is the distance from the centroid of
## #a triangle to the midpoint of the side of the triangle
Expand Down Expand Up @@ -460,7 +460,7 @@ def get_node(self, i, absolute=False):
# get a copy so as not to modify the internal self.nodes array
V = copy.copy(V)
V += num.array([self.geo_reference.get_xllcorner(),
self.geo_reference.get_yllcorner()], num.float)
self.geo_reference.get_yllcorner()], float)
return V

def get_vertex_coordinates(self, triangle_id=None, absolute=False):
Expand Down Expand Up @@ -494,7 +494,7 @@ def get_vertex_coordinates(self, triangle_id=None, absolute=False):
i3 = 3*i
if absolute is True and not self.geo_reference.is_absolute():
offset=num.array([self.geo_reference.get_xllcorner(),
self.geo_reference.get_yllcorner()], num.float)
self.geo_reference.get_yllcorner()], float)

return V[i3:i3+3,:] + offset
else:
Expand Down Expand Up @@ -522,13 +522,13 @@ def compute_vertex_coordinates(self):
"""

M = self.number_of_triangles
vertex_coordinates = num.zeros((3*M, 2), num.float)
vertex_coordinates = num.zeros((3*M, 2), float)

k0 = self.triangles[:,0]
k1 = self.triangles[:,1]
k2 = self.triangles[:,2]

# I = num.arange(M,dtype=num.int)
# I = num.arange(M,dtype=int)
#
# V0 = V[0:3*M:3, :]
# V1 = V[1:3*M:3, :]
Expand Down Expand Up @@ -577,7 +577,7 @@ def get_edge_midpoint_coordinates(self, triangle_id=None, absolute=False):
i3 = 3*i
if absolute is True and not self.geo_reference.is_absolute():
offset=num.array([self.geo_reference.get_xllcorner(),
self.geo_reference.get_yllcorner()], num.float)
self.geo_reference.get_yllcorner()], float)

return E[i3:i3+3,:] + offset
else:
Expand Down Expand Up @@ -607,7 +607,7 @@ def compute_edge_midpoint_coordinates(self):
"""

M = self.number_of_triangles
E = num.zeros((3*M, 2), num.float)
E = num.zeros((3*M, 2), float)

V = self.vertex_coordinates

Expand Down Expand Up @@ -670,7 +670,7 @@ def get_disconnected_triangles(self):

M = len(self) # Number of triangles
K = 3*M # Total number of unique vertices
return num.reshape(num.arange(K, dtype=num.int), (M,3))
return num.reshape(num.arange(K, dtype=int), (M,3))

def get_unique_vertices(self, indices=None):
"""Return indices to vertices as a sorted list.
Expand Down Expand Up @@ -726,7 +726,7 @@ def get_triangles_and_vertices_per_node(self, node=None):

triangle_list.append( (volume_id, vertex_id) )

triangle_list = num.array(triangle_list, num.int) #array default#
triangle_list = num.array(triangle_list, int) #array default#
else:
# Get info for all nodes recursively.
# If need be, we can speed this up by
Expand Down Expand Up @@ -795,16 +795,16 @@ def build_inverted_triangle_structure(self):

# Count number of triangles per node
# number_of_triangles_per_node = num.zeros(self.number_of_nodes,
# num.int) #array default#
# int) #array default#
# for volume_id, triangle in enumerate(self.get_triangles()):
# for vertex_id in triangle:
# number_of_triangles_per_node[vertex_id] += 1

# Need to pad number_of_triangles_per_node in case lone nodes at end of list
#number_of_triangles_per_node = num.zeros(self.number_of_nodes, num.int)
#number_of_triangles_per_node = num.zeros(self.number_of_nodes, int)


number_of_triangles_per_node = num.bincount(self.triangles.flat).astype(num.int)
number_of_triangles_per_node = num.bincount(self.triangles.flat).astype(int)
number_of_lone_nodes = self.number_of_nodes - len(number_of_triangles_per_node)


Expand All @@ -817,7 +817,7 @@ def build_inverted_triangle_structure(self):

if number_of_lone_nodes > 0:
number_of_triangles_per_node = \
num.append(number_of_triangles_per_node,num.zeros(number_of_lone_nodes,num.int))
num.append(number_of_triangles_per_node,num.zeros(number_of_lone_nodes,int))

#assert num.allclose(number_of_triangles_per_node_new, number_of_triangles_per_node)

Expand All @@ -826,21 +826,21 @@ def build_inverted_triangle_structure(self):

assert number_of_entries == 3*self.number_of_triangles

#vertex_value_indices = num.zeros(number_of_entries, num.int) #array default#
#vertex_value_indices = num.zeros(number_of_entries, int) #array default#

# Array of vertex_indices (3*vol_id+vertex_id) sorted into contiguous
# order around each node. Use with number_of_triangles_per_node to
# find vertices associated with a node.
# ie There are number_of_triangles_per_node[i] vertices
vertex_value_indices = num.argsort(self.triangles.flat).astype(num.int)
vertex_value_indices = num.argsort(self.triangles.flat).astype(int)
#vertex_value_indices = num.argsort(self.triangles.flatten())

# node_index = num.zeros((self.number_of_nodes)+1, dtype = num.int)
# node_index = num.zeros((self.number_of_nodes)+1, dtype = int)
# node_index[0] = 0
# for i in xrange(self.number_of_nodes):
# node_index[i+1] = node_index[i] + number_of_triangles_per_node[i]

node_index = num.zeros((self.number_of_nodes)+1, dtype = num.int)
node_index = num.zeros((self.number_of_nodes)+1, dtype = int)
node_index[1:] = num.cumsum(number_of_triangles_per_node)

#assert num.allclose(node_index,node_index_new)
Expand Down
10 changes: 5 additions & 5 deletions anuga/abstract_2d_finite_volumes/generic_boundary_conditions.py
Expand Up @@ -208,7 +208,7 @@ def __init__(self, dirichlet_values=None):
msg = 'Must specify one value for each quantity'
raise Exception(msg)

self.dirichlet_values=num.array(dirichlet_values, num.float)
self.dirichlet_values=num.array(dirichlet_values, float)



Expand Down Expand Up @@ -338,7 +338,7 @@ def __init__(self, domain=None,


try:
q = num.array(q, num.float)
q = num.array(q, float)
except:
msg = 'Return value from time boundary function could '
msg += 'not be converted into a numeric array of floats.\n'
Expand Down Expand Up @@ -457,7 +457,7 @@ def __init__(self, domain=None,


try:
q = num.array(q, num.float)
q = num.array(q, float)
except:
msg = 'Return value from time_space_boundary function could '
msg += 'not be converted into a numeric array of floats.\n'
Expand Down Expand Up @@ -570,7 +570,7 @@ def __init__(self, filename, domain,
# any tagged boundary later on.

if verbose: log.critical('Find midpoint coordinates of entire boundary')
self.midpoint_coordinates = num.zeros((len(domain.boundary), 2), num.float)
self.midpoint_coordinates = num.zeros((len(domain.boundary), 2), float)
boundary_keys = list(domain.boundary.keys())

xllcorner = domain.geo_reference.get_xllcorner()
Expand Down Expand Up @@ -758,7 +758,7 @@ def __init__(self, filename, domain, time_thinning=1,
# any tagged boundary later on.

if verbose: log.critical('Find midpoint coordinates of entire boundary')
self.midpoint_coordinates = num.zeros((len(domain.boundary), 2), num.float)
self.midpoint_coordinates = num.zeros((len(domain.boundary), 2), float)
boundary_keys = list(domain.boundary.keys())

xllcorner = domain.geo_reference.get_xllcorner()
Expand Down
20 changes: 10 additions & 10 deletions anuga/abstract_2d_finite_volumes/generic_domain.py
Expand Up @@ -232,13 +232,13 @@ def __init__(self,
buffer_shape = self.full_send_dict[key][0].shape[0]
self.full_send_dict[key].append(num.zeros((buffer_shape,
self.nsys),
num.float))
float))

for key in self.ghost_recv_dict:
buffer_shape = self.ghost_recv_dict[key][0].shape[0]
self.ghost_recv_dict[key].append(num.zeros((buffer_shape,
self.nsys),
num.float))
float))

# Setup triangle full flag
if verbose:
Expand All @@ -249,7 +249,7 @@ def __init__(self,

# =1 for full
# =0 for ghost
self.tri_full_flag = num.ones(N, num.int)
self.tri_full_flag = num.ones(N, int)

for i in list(self.ghost_recv_dict.keys()):
id = self.ghost_recv_dict[i][0]
Expand All @@ -276,7 +276,7 @@ def __init__(self,
# print list(b)
# print num.repeat(self.tri_full_flag, 3)

self.node_full_flag = num.minimum(num.bincount(self.triangles.flat, weights=W).astype(num.int), 1)
self.node_full_flag = num.minimum(num.bincount(self.triangles.flat, weights=W).astype(int), 1)

# FIXME SR: The following line leads to a nasty segmentation fault!
# self.number_of_full_nodes = int(num.sum(self.node_full_flag))
Expand Down Expand Up @@ -346,14 +346,14 @@ def __init__(self,
# To avoid calculating the flux across each edge twice, keep an integer
# (boolean) array, to be used during the flux calculation.
N = len(self) # Number_of_triangles
self.already_computed_flux = num.zeros((N, 3), num.int)
self.already_computed_flux = num.zeros((N, 3), int)

self.work_centroid_values = num.zeros(N, num.float)
self.work_centroid_values = num.zeros(N, float)

# Storage for maximal speeds computed for each triangle by
# compute_fluxes.
# This is used for diagnostics only (reset at every yieldstep)
self.max_speed = num.zeros(N, num.float)
self.max_speed = num.zeros(N, float)

if mesh_filename is not None:
# If the mesh file passed any quantity values,
Expand Down Expand Up @@ -486,7 +486,7 @@ def get_conserved_quantities(self, vol_id,
msg += 'Only one (or none) is allowed.'
raise Exception(msg)

q = num.zeros(len(self.conserved_quantities), num.float)
q = num.zeros(len(self.conserved_quantities), float)

for i, name in enumerate(self.conserved_quantities):
Q = self.quantities[name]
Expand Down Expand Up @@ -517,7 +517,7 @@ def get_evolved_quantities(self, vol_id,
msg += 'Only one (or none) is allowed.'
raise Exception(msg)

q = num.zeros(len(self.evolved_quantities), num.float)
q = num.zeros(len(self.evolved_quantities), float)

for i, name in enumerate(self.evolved_quantities):
Q = self.quantities[name]
Expand Down Expand Up @@ -1750,7 +1750,7 @@ def _evolve_base(self, yieldstep=None,
self.recorded_max_timestep = self.evolve_min_timestep
self.number_of_steps = 0
self.number_of_first_order_steps = 0
self.max_speed = num.zeros(N, num.float)
self.max_speed = num.zeros(N, float)

def evolve_one_euler_step(self, yieldstep, finaltime):
"""One Euler Time Step
Expand Down

0 comments on commit 861bf5b

Please sign in to comment.