Skip to content

Commit

Permalink
PEP8 fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
inducer committed Mar 20, 2015
1 parent da4455c commit 16325ea
Showing 1 changed file with 58 additions and 67 deletions.
125 changes: 58 additions & 67 deletions test/test_meshpy.py
Expand Up @@ -25,8 +25,6 @@
"""




# {{{ triangle

def test_triangle_refine():
Expand All @@ -35,32 +33,32 @@ def test_triangle_refine():

segments = 50

points = [ (1,0),(1,1),(-1,1),(-1,-1),(1,-1) ]
points = [(1, 0), (1, 1), (-1, 1), (-1, -1), (1, -1)]
n_outer_points = len(points)

for i in range( 0, segments):
angle = i * 2 * math.pi / segments
points.append( ( 0.5 * math.cos( angle ), 0.5 * math.sin( angle ) ) )
for i in range(0, segments):
angle = i * 2 * math.pi / segments
points.append((0.5 * math.cos(angle), 0.5 * math.sin(angle)))

def round_trip_connect(start, end):
result = []
for i in range(start, end):
result.append((i, i+1))
result.append((end, start))
return result
result = []
for i in range(start, end):
result.append((i, i+1))
result.append((end, start))
return result

def needs_refinement(vertices, area ):
def needs_refinement(vertices, area):
vert_origin, vert_destination, vert_apex = vertices
bary_x = (vert_origin.x + vert_destination.x + vert_apex.x) / 3
bary_y = (vert_origin.y + vert_destination.y + vert_apex.y) / 3

dist_center = math.sqrt( bary_x**2 + bary_y**2 )
max_area = 100*(math.fabs( 0.002 * (dist_center-0.3) ) + 0.0001)
dist_center = math.sqrt(bary_x**2 + bary_y**2)
max_area = 100*(math.fabs(0.002 * (dist_center-0.3)) + 0.0001)
return area > max_area

info = triangle.MeshInfo()
info.set_points(points)
info.set_holes([(0,0)])
info.set_holes([(0, 0)])
info.set_facets(
round_trip_connect(0, n_outer_points-1)
+
Expand All @@ -81,41 +79,40 @@ def needs_refinement(vertices, area ):

# }}}


# {{{ tetgen

def test_tetgen():
from meshpy.tet import MeshInfo, build
mesh_info = MeshInfo()

mesh_info.set_points([
(0,0,0),
(2,0,0),
(2,2,0),
(0,2,0),
(0,0,12),
(2,0,12),
(2,2,12),
(0,2,12),
(0, 0, 0),
(2, 0, 0),
(2, 2, 0),
(0, 2, 0),
(0, 0, 12),
(2, 0, 12),
(2, 2, 12),
(0, 2, 12),
])

mesh_info.set_facets([
[0,1,2,3],
[4,5,6,7],
[0,4,5,1],
[1,5,6,2],
[2,6,7,3],
[3,7,4,0],
[0, 1, 2, 3],
[4, 5, 6, 7],
[0, 4, 5, 1],
[1, 5, 6, 2],
[2, 6, 7, 3],
[3, 7, 4, 0],
])

build(mesh_info)




def test_torus():
from math import pi, cos, sin
from meshpy.tet import MeshInfo, build
from meshpy.geometry import generate_surface_of_revolution,\
from meshpy.geometry import generate_surface_of_revolution, \
EXT_CLOSED_IN_RZ, GeometryBuilder

big_r = 3
Expand All @@ -138,6 +135,7 @@ def test_torus():

# }}}


# {{{ gmsh

def search_on_path(filenames):
Expand All @@ -155,46 +153,41 @@ def search_on_path(filenames):
if exists(join(path, filename)):
return abspath(join(path, filename))




GMSH_SPHERE = """
x = 0; y = 1; z = 2; r = 3; lc = 0.3;
p1 = newp; Point(p1) = {x, y, z, lc} ;
p2 = newp; Point(p2) = {x+r,y, z, lc} ;
p3 = newp; Point(p3) = {x, y+r,z, lc} ;
p4 = newp; Point(p4) = {x, y, z+r,lc} ;
p5 = newp; Point(p5) = {x-r,y, z, lc} ;
p6 = newp; Point(p6) = {x, y-r,z, lc} ;
p7 = newp; Point(p7) = {x, y, z-r,lc} ;
c1 = newreg; Circle(c1) = {p2,p1,p7};
c2 = newreg; Circle(c2) = {p7,p1,p5};
c3 = newreg; Circle(c3) = {p5,p1,p4};
c4 = newreg; Circle(c4) = {p4,p1,p2};
c5 = newreg; Circle(c5) = {p2,p1,p3};
c6 = newreg; Circle(c6) = {p3,p1,p5};
c7 = newreg; Circle(c7) = {p5,p1,p6};
c8 = newreg; Circle(c8) = {p6,p1,p2};
c9 = newreg; Circle(c9) = {p7,p1,p3};
c10 = newreg; Circle(c10) = {p3,p1,p4};
c11 = newreg; Circle(c11) = {p4,p1,p6};
c12 = newreg; Circle(c12) = {p6,p1,p7};
l1 = newreg; Line Loop(l1) = {c5,c10,c4}; Ruled Surface(newreg) = {l1};
l2 = newreg; Line Loop(l2) = {c9,-c5,c1}; Ruled Surface(newreg) = {l2};
l3 = newreg; Line Loop(l3) = {c12,-c8,-c1}; Ruled Surface(newreg) = {l3};
l4 = newreg; Line Loop(l4) = {c8,-c4,c11}; Ruled Surface(newreg) = {l4};
l5 = newreg; Line Loop(l5) = {-c10,c6,c3}; Ruled Surface(newreg) = {l5};
l6 = newreg; Line Loop(l6) = {-c11,-c3,c7}; Ruled Surface(newreg) = {l6};
l7 = newreg; Line Loop(l7) = {-c2,-c7,-c12};Ruled Surface(newreg) = {l7};
l8 = newreg; Line Loop(l8) = {-c6,-c9,c2}; Ruled Surface(newreg) = {l8};
p2 = newp; Point(p2) = {x+r, y, z, lc} ;
p3 = newp; Point(p3) = {x, y+r, z, lc} ;
p4 = newp; Point(p4) = {x, y, z+r, lc} ;
p5 = newp; Point(p5) = {x-r, y, z, lc} ;
p6 = newp; Point(p6) = {x, y-r, z, lc} ;
p7 = newp; Point(p7) = {x, y, z-r, lc} ;
c1 = newreg; Circle(c1) = {p2, p1, p7};
c2 = newreg; Circle(c2) = {p7, p1, p5};
c3 = newreg; Circle(c3) = {p5, p1, p4};
c4 = newreg; Circle(c4) = {p4, p1, p2};
c5 = newreg; Circle(c5) = {p2, p1, p3};
c6 = newreg; Circle(c6) = {p3, p1, p5};
c7 = newreg; Circle(c7) = {p5, p1, p6};
c8 = newreg; Circle(c8) = {p6, p1, p2};
c9 = newreg; Circle(c9) = {p7, p1, p3};
c10 = newreg; Circle(c10) = {p3, p1, p4};
c11 = newreg; Circle(c11) = {p4, p1, p6};
c12 = newreg; Circle(c12) = {p6, p1, p7};
l1 = newreg; Line Loop(l1) = {c5, c10, c4}; Ruled Surface(newreg) = {l1};
l2 = newreg; Line Loop(l2) = {c9, -c5, c1}; Ruled Surface(newreg) = {l2};
l3 = newreg; Line Loop(l3) = {c12, -c8, -c1}; Ruled Surface(newreg) = {l3};
l4 = newreg; Line Loop(l4) = {c8, -c4, c11}; Ruled Surface(newreg) = {l4};
l5 = newreg; Line Loop(l5) = {-c10, c6, c3}; Ruled Surface(newreg) = {l5};
l6 = newreg; Line Loop(l6) = {-c11, -c3, c7}; Ruled Surface(newreg) = {l6};
l7 = newreg; Line Loop(l7) = {-c2, -c7, -c12};Ruled Surface(newreg) = {l7};
l8 = newreg; Line Loop(l8) = {-c6, -c9, c2}; Ruled Surface(newreg) = {l8};
"""




def test_gmsh():
if search_on_path(["gmsh"]) is None:
from pytest import skip
Expand All @@ -207,8 +200,6 @@ def test_gmsh():
# }}}




if __name__ == "__main__":
import sys
if len(sys.argv) > 1:
Expand Down

0 comments on commit 16325ea

Please sign in to comment.