Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Anuga py3 #223

Merged
merged 23 commits into from Jan 10, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
33f4914
Anuga py3 (#15)
rkwi Dec 24, 2019
da78e84
Anuga py3 (#16)
rkwi Jan 1, 2020
802ab6a
futurizing stage 1 operators, parallel
rkwi Jan 1, 2020
1886563
Merge branch 'anuga_py3' of https://github.com/rkwi/anuga_core into a…
rkwi Jan 1, 2020
ac6d9fe
Merge branch 'anuga_py3' into anuga_py3
rkwi Jan 1, 2020
d3850fd
removing duplicates
rkwi Jan 1, 2020
46c8a8d
futurizing stage 1 pmesh, rain
rkwi Jan 1, 2020
2bfa6ef
futurizing stage 1 shallow_water, simulation
rkwi Jan 1, 2020
ddade82
futurizing stage 1 structures, tsunami_source
rkwi Jan 2, 2020
a4ec473
Merge pull request #28 from rkwi/anuga_py3
stoiver Jan 7, 2020
b4f30d8
futurizing stage 1 validation_utilities, visualiser, visualiser_new
rkwi Jan 8, 2020
c1f5ec8
futurizing stage 1 utilities
rkwi Jan 8, 2020
36184f9
Merge pull request #29 from rkwi/anuga_py3
stoiver Jan 8, 2020
4e5d9ef
Merge branch 'anuga_py3' of github.com:GeoscienceAustralia/anuga_core…
stoiver Jan 8, 2020
a0c5df9
futurizing stage 1 anuga_core
rkwi Jan 9, 2020
a460eda
futurizing stage 2 anuga_core, anuga
rkwi Jan 9, 2020
cd7fade
Merge branch 'anuga_py3' of https://github.com/rkwi/anuga_core into r…
stoiver Jan 9, 2020
d83c0a3
trouble with setting up __ANUGA_SETUP__ using builtins
stoiver Jan 9, 2020
9d4ca4d
Merge branch 'rkwi-anuga_py3_1' into anuga_py3
stoiver Jan 9, 2020
a500775
trouble with setting up __ANUGA_SETUP__ using builtins (#17)
stoiver Jan 10, 2020
3ceebfe
cleaning unused python dependencies
rkwi Jan 10, 2020
5c2aea5
futurizing stage 2 geometry
rkwi Jan 10, 2020
5088481
Merge pull request #31 from rkwi/anuga_py3
stoiver Jan 10, 2020
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
19 changes: 7 additions & 12 deletions anuga/__init__.py
Expand Up @@ -21,15 +21,17 @@
# -----------------------------------------------------


from builtins import filter
__version__ = '2.0.3'

__svn_revision__ = filter(str.isdigit, "$Revision: 9737 $")
__svn_revision__ = ''.join(filter(str.isdigit, "$Revision: 9737 $"))

__svn_revision_date__ = "$Date: 2016-10-04 16:13:00 +1100 (Tue, 04 Oct 2016) $"[7:-1]


# We first need to detect if we're being called as part of the anuga setup
# procedure itself in a reliable manner.

try:
__ANUGA_SETUP__
except NameError:
Expand All @@ -41,17 +43,8 @@
_sys.stderr.write('Running from anuga source directory.\n')
del _sys
else:

try:
from anuga.__config__ import show as show_config
except ImportError:
msg = """Error importing anuga: you should not try to import anuga from
its source directory; please exit the anuga source tree, and relaunch
your python interpreter from there."""
raise ImportError(msg)

# ---------------------------------
# NetCDF changes stdout to terminal\
# ----------------------------------
# NetCDF changes stdout to terminal
# Causes trouble when using jupyter
# ---------------------------------
import sys
Expand All @@ -63,6 +56,8 @@
from numpy.testing import Tester
test = Tester().test

from anuga.__config__ import show as show_config

# --------------------------------
# Important basic classes
# --------------------------------
Expand Down
1 change: 1 addition & 0 deletions anuga/compile_all.py
@@ -1,5 +1,6 @@
""" Script to compile all C extensions in ANUGA. """

from past.builtins import execfile
import os
import subprocess
import sys
Expand Down
15 changes: 9 additions & 6 deletions anuga/error_api.py
@@ -1,3 +1,6 @@
from __future__ import division
from builtins import range
from past.utils import old_div
import matplotlib
import matplotlib.pyplot as plt
import matplotlib.tri as tri
Expand Down Expand Up @@ -29,7 +32,7 @@ def addRandomNoiseToStage(domain, samples = 50, dthr = 0.1, mag = 1E-15):

# Sample centroid values with depth greater than dthr
n_tri = int(num.sum(domain.tri_full_flag))
tri_index = num.array(range(0,n_tri))
tri_index = num.array(list(range(0,n_tri)))
submerged = tri_index[depth > dthr]
submerged = random.sample(submerged, min(samples, len(submerged)))

Expand Down Expand Up @@ -70,7 +73,7 @@ def plotCentroidError(domain, control_data, rthr = 1E-7, athr = 1E-12,
stage = domain.get_quantity(quantity)
actual_data = stage.centroid_values[:n_triangles]
adiff = num.fabs((actual_data - local_control_data))
rdiff = adiff/num.fabs(local_control_data)
rdiff = old_div(adiff,num.fabs(local_control_data))

# Compute masks for error (err_mask) and non-error (acc_mask) vertex indices based on thresholds
vertices = domain.get_vertex_coordinates()
Expand Down Expand Up @@ -102,18 +105,18 @@ def plotCentroidError(domain, control_data, rthr = 1E-7, athr = 1E-12,

# Plot non-error triangles in green
for i in range(0,size()):
n = int(len(fx[i])/3)
triang = num.array(range(0,3*n))
n = int(old_div(len(fx[i]),3))
triang = num.array(list(range(0,3*n)))
triang.shape = (n, 3)

if len(fx[i]) > 0:
plt.triplot(fx[i], fy[i], triang, 'g-')

# Plot error triangles in blue
for i in range(0,size()):
n = int(len(gx[i])/3)
n = int(old_div(len(gx[i]),3))

triang = num.array(range(0,3*n))
triang = num.array(list(range(0,3*n)))
triang.shape = (n, 3)

if len(gx[i]) > 0:
Expand Down
3 changes: 2 additions & 1 deletion anuga/geometry/aabb.py
Expand Up @@ -8,9 +8,10 @@

# Allow children to be slightly bigger than their parents to prevent
# straddling of a boundary
from builtins import object
SPLIT_BORDER_RATIO = 0.55

class AABB:
class AABB(object):
""" Axially-aligned bounding box class.
An axially aligned bounding box (or AABB) defines a box-shaped region
of the plane which contains any other arbitrary geometry.
Expand Down
26 changes: 15 additions & 11 deletions anuga/geometry/polygon.py
Expand Up @@ -3,7 +3,11 @@
"""Polygon manipulations"""
from __future__ import print_function
from __future__ import absolute_import
from __future__ import division

from builtins import str
from builtins import range
from past.utils import old_div
from future.utils import raise_
import numpy as num
import math
Expand Down Expand Up @@ -145,8 +149,8 @@ def intersection(line0, line1, rtol=1.0e-5, atol=1.0e-8):
return 4, None #FIXME (Ole): Add distance here instead of None
else:
# Lines are not parallel, check if they intersect
u0 = u0/denom
u1 = u1/denom
u0 = old_div(u0,denom)
u1 = old_div(u1,denom)

x = x0 + u0*(x1-x0)
y = y0 + u0*(y1-y0)
Expand Down Expand Up @@ -201,7 +205,7 @@ def polygon_overlap(triangles, polygon, verbose=False):
polygon = ensure_numeric(polygon)
triangles = ensure_numeric(triangles)

M = triangles.shape[0]/3 # Number of triangles
M = old_div(triangles.shape[0],3) # Number of triangles

indices = num.zeros(M, num.int)

Expand All @@ -219,7 +223,7 @@ def not_polygon_overlap(triangles, polygon, verbose=False):
polygon = ensure_numeric(polygon)
triangles = ensure_numeric(triangles)

M = triangles.shape[0]/3 # Number of triangles
M = old_div(triangles.shape[0],3) # Number of triangles

indices = num.zeros(M, num.int)

Expand All @@ -237,7 +241,7 @@ def line_intersect(triangles, line, verbose=False):
line = ensure_numeric(line)
triangles = ensure_numeric(triangles)

M = triangles.shape[0]/3 # Number of triangles
M = old_div(triangles.shape[0],3) # Number of triangles

indices = num.zeros(M, num.int)

Expand All @@ -264,7 +268,7 @@ def not_line_intersect(triangles, line, verbose=False):
line = ensure_numeric(line)
triangles = ensure_numeric(triangles)

M = triangles.shape[0]/3 # Number of triangles
M = old_div(triangles.shape[0],3) # Number of triangles

indices = num.zeros(M, num.int)

Expand Down Expand Up @@ -694,7 +698,7 @@ def polygon_area(input_polygon):
yi = pti[1]
poly_area += xi*yi1 - xi1*yi

return abs(poly_area/2)
return abs(old_div(poly_area,2))


def plot_polygons(polygons_points,
Expand Down Expand Up @@ -979,21 +983,21 @@ def number_mesh_triangles(interior_regions, bounding_poly, remainder_res):

for poly, resolution in interior_regions:
this_area = polygon_area(poly)
this_triangles = this_area/resolution
this_triangles = old_div(this_area,resolution)
no_triangles += this_triangles
area -= this_area

log.info('Interior %s%s%d'
% (('%.0f' % resolution).ljust(25),
('%.2f' % (this_area/1000000)).ljust(19),
('%.2f' % (old_div(this_area,1000000))).ljust(19),
this_triangles))

bound_triangles = area/remainder_res
bound_triangles = old_div(area,remainder_res)
no_triangles += bound_triangles

log.info('Bounding %s%s%d'
% (('%.0f' % remainder_res).ljust(25),
('%.2f' % (area/1000000)).ljust(19),
('%.2f' % (old_div(area,1000000))).ljust(19),
bound_triangles))

total_number_of_triangles = no_triangles/0.7
Expand Down
5 changes: 4 additions & 1 deletion anuga/geometry/polygon_function.py
Expand Up @@ -5,12 +5,15 @@
"""
from __future__ import absolute_import

from builtins import str
from past.builtins import basestring
from builtins import object
from future.utils import raise_
import anuga.utilities.log as log
import numpy as num
from .polygon import inside_polygon

class Polygon_function:
class Polygon_function(object):
"""Create callable object f: x,y -> z, where a,y,z are vectors and
where f will return different values depending on whether x,y belongs
to specified polygons.
Expand Down
3 changes: 2 additions & 1 deletion anuga/geometry/quad.py
Expand Up @@ -13,10 +13,11 @@
"""
from __future__ import print_function

from builtins import object
import anuga.utilities.log as log


class Cell():
class Cell:
""" One cell in the plane.
A cell is defined by an AABB, and can have smaller AABB children.
The children can be rapidly searched for intersections in log(n) time.
Expand Down
2 changes: 2 additions & 0 deletions anuga/geometry/tests/test_polygon.py
Expand Up @@ -2,6 +2,8 @@

""" Test suite to test polygon functionality. """

from builtins import str
from builtins import range
from future.utils import raise_
import unittest
import os
Expand Down
5 changes: 3 additions & 2 deletions anuga/operators/base_operator.py
@@ -1,3 +1,4 @@
from __future__ import print_function

from anuga.utilities.system_tools import log_to_file

Expand Down Expand Up @@ -83,11 +84,11 @@ def timestepping_statistics(self):

def print_statistics(self):

print self.statistics()
print(self.statistics())

def print_timestepping_statistics(self):

print self.timestepping_statistics()
print(self.timestepping_statistics())


def log_timestepping_statistics(self):
Expand Down
2 changes: 1 addition & 1 deletion anuga/operators/boundary_flux_integral_operator.py
Expand Up @@ -56,7 +56,7 @@ def __call__(self):
elif(ts_method=='rk3'):
self.boundary_flux_integral = self.boundary_flux_integral + 1.0/6.0*dt*(self.domain.boundary_flux_sum[0] + self.domain.boundary_flux_sum[1] + 4.0*self.domain.boundary_flux_sum[2])
else:
raise Exception, 'Cannot compute boundary flux integral with this timestepping method'
raise Exception('Cannot compute boundary flux integral with this timestepping method')

# Zero the boundary_flux_sum
self.domain.boundary_flux_sum[:]=0.
Expand Down
3 changes: 2 additions & 1 deletion anuga/operators/change_friction_operator.py
Expand Up @@ -3,6 +3,7 @@


"""
from __future__ import print_function

__author__="steve"
__date__ ="$09/03/2012 4:46:39 PM$"
Expand Down Expand Up @@ -112,7 +113,7 @@ def __call__(self):
self.stage_c[:] = self.elev_c + height_c
# self.domain.distribute_to_vertices_and_edges()

print 'time in erosion ',self.get_time(), dt
print('time in erosion ',self.get_time(), dt)



Expand Down
3 changes: 2 additions & 1 deletion anuga/operators/elliptic_operator.py
@@ -1,11 +1,12 @@
from __future__ import absolute_import
from anuga import Domain
from anuga import Quantity
from anuga.utilities.sparse import Sparse, Sparse_CSR
from anuga.utilities.cg_solve import conjugate_gradient
import anuga.abstract_2d_finite_volumes.neighbour_mesh as neighbour_mesh
from anuga import Dirichlet_boundary
import numpy as num
import kinematic_viscosity_operator_ext
from . import kinematic_viscosity_operator_ext
import anuga.utilities.log as log

from anuga.operators.base_operator import Operator
Expand Down