Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Modernize
  • Loading branch information
inducer committed Nov 27, 2014
1 parent b2fb52f commit 186748b
Show file tree
Hide file tree
Showing 25 changed files with 119 additions and 66 deletions.
2 changes: 1 addition & 1 deletion doc/conf.py
Expand Up @@ -48,7 +48,7 @@
# The short X.Y version.
def get_version():
conf = {}
execfile("../meshpy/__init__.py", conf)
exec(compile(open("../meshpy/__init__.py").read(), "../meshpy/__init__.py", 'exec'), conf)
return conf["version"]

version = get_version()
Expand Down
5 changes: 4 additions & 1 deletion examples/airfoil3d.py
@@ -1,3 +1,6 @@
from __future__ import absolute_import
from __future__ import print_function
from six.moves import zip
def main():
import numpy
#from math import pi, cos, sin
Expand Down Expand Up @@ -59,7 +62,7 @@ def deform_wing(p):
mesh_info.set_holes([(0, 0, 0.5)])

mesh = build(mesh_info)
print "%d elements" % len(mesh.elements)
print("%d elements" % len(mesh.elements))
mesh.write_vtk("airfoil3d.vtk")


Expand Down
4 changes: 3 additions & 1 deletion examples/box-in-box.py
@@ -1,3 +1,5 @@
from __future__ import absolute_import
from __future__ import print_function
def main():
import numpy
from meshpy.tet import MeshInfo, build
Expand Down Expand Up @@ -33,7 +35,7 @@ def main():

mesh = build(mesh_info, max_volume=0.06,
volume_constraints=True, attributes=True)
print ("%d elements" % len(mesh.elements))
print(("%d elements" % len(mesh.elements)))
mesh.write_vtk("box-in-box.vtk")


Expand Down
10 changes: 6 additions & 4 deletions examples/demo.py
@@ -1,3 +1,5 @@
from __future__ import absolute_import
from __future__ import print_function
from meshpy.tet import MeshInfo, build

mesh_info = MeshInfo()
Expand All @@ -14,11 +16,11 @@
[3,7,4,0],
])
mesh = build(mesh_info)
print "Mesh Points:"
print("Mesh Points:")
for i, p in enumerate(mesh.points):
print i, p
print "Point numbers in tetrahedra:"
print(i, p)
print("Point numbers in tetrahedra:")
for i, t in enumerate(mesh.elements):
print i, t
print(i, t)
mesh.write_vtk("test.vtk")

4 changes: 3 additions & 1 deletion examples/mesh_ply.py
@@ -1,3 +1,5 @@
from __future__ import absolute_import
from __future__ import print_function
def main():
from ply import parse_ply
import sys
Expand All @@ -16,7 +18,7 @@ def main():
builder.set(mi)
mi.set_holes([builder.center()])
mesh = build(mi)
print "%d elements" % len(mesh.elements)
print("%d elements" % len(mesh.elements))
mesh.write_vtk("out.vtk")


Expand Down
2 changes: 2 additions & 0 deletions examples/nico_mesh.py
@@ -1,3 +1,5 @@
from __future__ import absolute_import
from six.moves import range
def main():
import meshpy.triangle as triangle
import math
Expand Down
2 changes: 2 additions & 0 deletions examples/test_ball.py
@@ -1,3 +1,5 @@
from __future__ import absolute_import
from six.moves import range
def main():
from math import pi, cos, sin
from meshpy.tet import MeshInfo, build
Expand Down
2 changes: 1 addition & 1 deletion examples/test_cylinder.py
Expand Up @@ -19,7 +19,7 @@ def main():

mesh = build(mesh_info, max_volume=0.01)
mesh.write_vtk("cylinder.vtk")
mesh.write_neu(file("cylinder.neu", "w"), {
mesh.write_neu(open("cylinder.neu", "w"), {
1: ("minus_z", 1),
2: ("outer", 2),
3: ("plus_z", 3),
Expand Down
4 changes: 3 additions & 1 deletion examples/test_tet_torus.py
@@ -1,3 +1,5 @@
from __future__ import absolute_import
from six.moves import range
def main():
from math import pi, cos, sin
from meshpy.tet import MeshInfo, build
Expand Down Expand Up @@ -27,7 +29,7 @@ def main():
mesh.save_elements("torus_mesh")
mesh.save_nodes("torus_mesh")

mesh.write_neu(file("torus.neu", "w"),
mesh.write_neu(open("torus.neu", "w"),
{1: ("pec", 0)})


Expand Down
2 changes: 2 additions & 0 deletions examples/test_tri_pml.py
@@ -1,3 +1,5 @@
from __future__ import absolute_import
from six.moves import range
def main():
import meshpy.triangle as triangle
import math
Expand Down
6 changes: 4 additions & 2 deletions examples/test_tri_quadratic.py
Expand Up @@ -7,11 +7,13 @@
# Utility function to create lists of the form [(1,2), (2,3), (3,4),
#(4,1)], given two numbers 1 and 4
from itertools import islice, cycle
loop = lambda a, b: zip(range(a, b), islice(cycle(range(a, b)), 1, None))
from six.moves import range
from six.moves import zip
loop = lambda a, b: list(zip(list(range(a, b)), islice(cycle(list(range(a, b))), 1, None)))

info = MeshInfo()
info.set_points([(0,0), (1,0), (1,1), (0,1), (2,0), (3,0), (3,1), (2,1)])
info.set_facets(loop(0,4) + loop(4,8), range(1,9)) # Create 8 facets and apply markers 1-8 on them
info.set_facets(loop(0,4) + loop(4,8), list(range(1,9))) # Create 8 facets and apply markers 1-8 on them
info.regions.resize(2)
info.regions[0] = [0.5, 0.5, 1, 0.1] # Fourth item specifies maximum area of triangles as a region attribute
info.regions[1] = [2.5, 0.5, 2, 0.1] # Replace 0.1 by a smaller value to produce a finer mesh
Expand Down
5 changes: 4 additions & 1 deletion examples/test_tri_simple_square.py
@@ -1,3 +1,6 @@
from __future__ import absolute_import
from __future__ import print_function
from six.moves import range
def main():
import meshpy.triangle as triangle

Expand All @@ -16,7 +19,7 @@ def round_trip_connect(start, end):

mesh = triangle.build(info, max_volume=1e-3, min_angle=25)

print "A"
print("A")
triangle.write_gnuplot_mesh("triangles.dat", mesh)

if __name__ == "__main__":
Expand Down
2 changes: 2 additions & 0 deletions examples/test_triangle.py
@@ -1,8 +1,10 @@
from __future__ import division
from __future__ import absolute_import

import meshpy.triangle as triangle
import numpy as np
import numpy.linalg as la
from six.moves import range


def round_trip_connect(start, end):
Expand Down
7 changes: 5 additions & 2 deletions examples/test_triangle_refine.py
@@ -1,3 +1,6 @@
from __future__ import absolute_import
from __future__ import print_function
from six.moves import range
def main():
import meshpy.triangle as triangle
import math
Expand Down Expand Up @@ -36,7 +39,7 @@ def needs_refinement(vertices, area ):
)

triangle.write_gnuplot_mesh("triangles-unrefined.dat", mesh)
print len(mesh.elements)
print(len(mesh.elements))

mesh.element_volumes.setup()

Expand All @@ -46,7 +49,7 @@ def needs_refinement(vertices, area ):
mesh.element_volumes[i] = 1e-8

mesh = triangle.refine(mesh)
print len(mesh.elements)
print(len(mesh.elements))

triangle.write_gnuplot_mesh("triangles.dat", mesh)

Expand Down
22 changes: 12 additions & 10 deletions examples/write_dolfin.py
@@ -1,3 +1,5 @@
from __future__ import absolute_import
from __future__ import print_function
def main():
import meshpy.triangle as triangle

Expand All @@ -7,32 +9,32 @@ def main():

mesh = triangle.build(info, max_volume=1e-3, min_angle=25)

print """
print("""
<?xml version="1.0" encoding="UTF-8"?>
<dolfin xmlns:dolfin="http://www.fenics.org/dolfin/">
<mesh celltype="triangle" dim="2">
<vertices size="%d">
""" % len(mesh.points)
""" % len(mesh.points))

for i, pt in enumerate(mesh.points):
print '<vertex index="%d" x="%g" y="%g"/>' % (
i, pt[0], pt[1])
print('<vertex index="%d" x="%g" y="%g"/>' % (
i, pt[0], pt[1]))

print """
print("""
</vertices>
<cells size="%d">
""" % len(mesh.elements)
""" % len(mesh.elements))

for i, element in enumerate(mesh.elements):
print '<triangle index="%d" v0="%d" v1="%d" v2="%d"/>' % (
i, element[0], element[1], element[2])
print('<triangle index="%d" v0="%d" v1="%d" v2="%d"/>' % (
i, element[0], element[1], element[2]))

print """
print("""
</cells>
</mesh>
</dolfin>
"""
""")

if __name__ == "__main__":
main()
Expand Down
18 changes: 11 additions & 7 deletions meshpy/common.py
@@ -1,3 +1,7 @@
from __future__ import absolute_import
from __future__ import print_function
from six.moves import range
from six.moves import zip
class _Table:
def __init__(self):
self.Rows = []
Expand Down Expand Up @@ -101,7 +105,7 @@ def write_neu(self, outfile, bc={}, periodicity=None, description="MeshPy Output
outfile.write("PROGRAM: MeshPy VERSION: %s\n" % version)
outfile.write("%s\n" % datetime.now().ctime())

bc_markers = bc.keys()
bc_markers = list(bc.keys())
if periodicity:
periodic_marker, periods = periodicity
bc_markers.append(periodic_marker)
Expand Down Expand Up @@ -149,7 +153,7 @@ def write_neu(self, outfile, bc={}, periodicity=None, description="MeshPy Output
outfile.write("ELEMENT GROUP 1.3.0\n")
# FIXME
i = 0
grp_elements = range(len(self.elements))
grp_elements = list(range(len(self.elements)))
material = 1
flags = 0
outfile.write("GROUP:%11d ELEMENTS:%11d MATERIAL:%11s NFLAGS: %11d\n"
Expand Down Expand Up @@ -190,7 +194,7 @@ def write_neu(self, outfile, bc={}, periodicity=None, description="MeshPy Output
face2el.setdefault(face, []).append((ti, fi+1))

else:
raise ValueError, "invalid number of dimensions (%d)" % dim
raise ValueError("invalid number of dimensions (%d)" % dim)

# actually output bc sections
if not self.faces.allocated:
Expand Down Expand Up @@ -257,20 +261,20 @@ def write_neu(self, outfile, bc={}, periodicity=None, description="MeshPy Output


def dump_array(name, array):
print "array %s: %d elements, %d values per element" % (name, len(array), array.unit)
print("array %s: %d elements, %d values per element" % (name, len(array), array.unit))

if len(array) == 0 or array.unit == 0:
return

try:
array[0]
except RuntimeError:
print " not allocated"
print(" not allocated")
return

for i, entry in enumerate(array):
if isinstance(entry, list):
print " %d: %s" % (i, ",".join(str(sub) for sub in entry))
print(" %d: %s" % (i, ",".join(str(sub) for sub in entry)))
else:
print " %d: %s" % (i, entry)
print(" %d: %s" % (i, entry))

7 changes: 5 additions & 2 deletions meshpy/geometry.py
@@ -1,5 +1,8 @@
from __future__ import division
from __future__ import absolute_import
import numpy as np
from six.moves import range
from six.moves import zip

__doc__ = """
Expand Down Expand Up @@ -290,7 +293,7 @@ def round_trip_connect(seq):
y = r*np.sin(phi) + cy

return ([np.array(pt) for pt in zip(x, y)],
round_trip_connect(range(subdivisions)),
round_trip_connect(list(range(subdivisions))),
None,
subdivisions*[marker])

Expand Down Expand Up @@ -414,7 +417,7 @@ def get_ring(ring_idx):
p_indices = (first_idx,)
points.append((0, 0, z))
else:
p_indices = tuple(xrange(first_idx, first_idx+len(base_shape)))
p_indices = tuple(range(first_idx, first_idx+len(base_shape)))
points.extend([(x*r, y*r, z) for (x, y) in base_shape])

rings[ring_idx] = p_indices
Expand Down
7 changes: 5 additions & 2 deletions meshpy/gmsh_reader.py
@@ -1,6 +1,9 @@
"""Reader for the GMSH file format."""

from __future__ import division
from __future__ import absolute_import
from six.moves import range
from functools import reduce

__copyright__ = "Copyright (C) 2009 Xueyu Zhu, Andreas Kloeckner"

Expand Down Expand Up @@ -98,7 +101,7 @@ def has_next_line(self):
return True

try:
self.next_line = self.line_iterable.next()
self.next_line = next(self.line_iterable)
except StopIteration:
return False
else:
Expand All @@ -111,7 +114,7 @@ def get_next_line(self):
return nl.strip()

try:
nl = self.line_iterable.next()
nl = next(self.line_iterable)
except StopIteration:
raise GmshFileFormatError("unexpected end of file")
else:
Expand Down
11 changes: 7 additions & 4 deletions meshpy/naca.py
@@ -1,6 +1,9 @@
from __future__ import division
from __future__ import absolute_import
from __future__ import print_function

import numpy
from six.moves import range


class FourDigitsSymmetric:
Expand Down Expand Up @@ -130,7 +133,7 @@ def get_naca_points(naca_digits, number_of_points=100,

if verbose:
def explain(*s):
print " ".join(str(s_i) for s_i in s)
print(" ".join(str(s_i) for s_i in s))
else:
def explain(*s):
pass
Expand All @@ -146,7 +149,7 @@ def explain(*s):

raw_abscissae = numpy.linspace(0, 1, number_of_points, endpoint=True)
abscissae = numpy.empty_like(raw_abscissae)
for i in xrange(number_of_points):
for i in range(number_of_points):
abscissae[i] = abscissa_map(raw_abscissae[i])

digits_int = int(naca_digits)
Expand Down Expand Up @@ -227,7 +230,7 @@ def explain(*s):
def write_points(points, filename):
file = open(filename, "w")
for pt in points:
print >>file, "\t".join(repr(p_comp) for p_comp in pt)
print("\t".join(repr(p_comp) for p_comp in pt), file=file)


def main():
Expand Down Expand Up @@ -263,7 +266,7 @@ def main():
if options.output is None:
options.output = "naca-%s.dat" % digits

print "Output file:", options.output
print("Output file:", options.output)
write_points(points, options.output)


Expand Down

0 comments on commit 186748b

Please sign in to comment.