Commit 2d60d6f1 authored by Jonathan Lambrechts's avatar Jonathan Lambrechts
Browse files

fix examples data download + pycodestyle

parent dbf527c0
Pipeline #9870 failed with stages
in 2 minutes and 33 seconds
......@@ -40,7 +40,7 @@ domain.add_boundary_curve(x, "wall1", domain_srs, CurveType.POLYLINE)
# A SPLINE uses a cubic spline interpolation through the control points
x = [[0, 0], [0.25, -0.2], [0.75, -0.2], [1, 0]]
domain.add_boundary_curve(x, "wall2", domain_srs, CurveType.SPLINE)
domain.add_boundary_curve(x, "wall2", domain_srs, CurveType.BSPLINE)
# %%
# A BSPLINE is smoother than a SPLINE but the control points are not on the
......
......@@ -24,7 +24,7 @@ import os
import urllib.request
import tarfile
if not os.path.isdir("data"):
url = "ftp://braque.mema.ucl.ac.be/seamsh/data-test-1.tar.gz"
url = "https://nextcloud.cism.ucl.ac.be/s/L2tTqQi5MMk9dqT/download/data-test-1.tar.gz"
urllib.request.urlretrieve(url, "data-test-1.tar.gz")
f = tarfile.open("data-test-1.tar.gz", "r:*")
f.extractall()
......
......@@ -12,7 +12,7 @@ import os
import urllib.request
import tarfile
if not os.path.isdir("data"):
url = "ftp://braque.mema.ucl.ac.be/seamsh/data-test-1.tar.gz"
url = "https://nextcloud.cism.ucl.ac.be/s/L2tTqQi5MMk9dqT/download/data-test-1.tar.gz"
urllib.request.urlretrieve(url, "data-test-1.tar.gz")
f = tarfile.open("data-test-1.tar.gz", "r:*")
f.extractall()
......
......@@ -92,6 +92,7 @@ def np2c(a, dtype=np.float64):
r.tmp = tmp
return r
class PolyMesh:
def __init__(self, bbmin, bbmax):
lib.polymesh_new.restype = c.c_void_p
......@@ -101,13 +102,14 @@ class PolyMesh:
def add_points(self, v):
tags = np.arange(self._n, self._n+v.shape[0], dtype=np.int32)
self._n += v.shape[0]
lib.polymesh_add_points(self._ptr,
c.c_int(v.shape[0]),
np2c(v), np2c(tags,np.int32))
lib.polymesh_add_points(
self._ptr,
c.c_int(v.shape[0]),
np2c(v), np2c(tags, np.int32))
def get_triangles(self):
lib.polymesh_n_faces.restype = c.c_int
n = lib.polymesh_n_faces(self._ptr)
tri = np.empty((n,3),np.int32)
tri = np.empty((n, 3), np.int32)
lib.polymesh_faces(self._ptr, np2c(tri, np.int32))
return tri
......@@ -136,7 +136,8 @@ class Domain:
nc = []
for i, j in zip(breaks[:-1], breaks[1:]):
ncurve = _Curve(
curve.points[i:j+1], curve.tag, curve.curve_type, curve.projection)
curve.points[i:j+1], curve.tag, curve.curve_type,
curve.projection)
ncurve.pointsid = curve.pointsid[i:j+1]
newcurves.append(ncurve)
nc.append(len(newcurves)-1)
......@@ -330,10 +331,8 @@ class Domain:
self._add_shapefile(filename, physical_name_field, False, False,
curve_type)
from .gmsh import _curve_sample
def coarsen_boundaries(domain: Domain, x0: _tools.Tuple[float, float],
x0_projection: _tools.osr.SpatialReference,
mesh_size: MeshSizeCallback) -> Domain:
......@@ -409,9 +408,10 @@ def coarsen_boundaries(domain: Domain, x0: _tools.Tuple[float, float],
_tools.c.c_int(first), _tools.np2c(ms),
_tools.c.byref(p_xo), _tools.c.byref(n_xo),
_tools.c.byref(p_l), _tools.c.byref(n_l))
#xptr = _tools.c.POINTER(n_xo.value*2*_tools.c.c_double)
#xbuf = _tools.c.cast(p_xo, xptr).contents
xbuf = _tools.c.cast(p_xo, _tools.c.POINTER(n_xo.value*2*_tools.c.c_double)).contents
# xptr = _tools.c.POINTER(n_xo.value*2*_tools.c.c_double)
# xbuf = _tools.c.cast(p_xo, xptr).contents
xtype = _tools.c.POINTER(n_xo.value*2*_tools.c.c_double)
xbuf = _tools.c.cast(p_xo, xtype).contents
xo = _tools.np.ctypeslib.frombuffer(xbuf, dtype=_tools.np.float64)
xo = xo.reshape([-1, 2]).copy()
_tools.lib.libcfree(p_xo)
......
......@@ -65,25 +65,29 @@ def _curve_sample_gmsh_tag(tag, lc, projection):
size = _tools.np.hstack([size, esize])[s]
return x[:, :2], xi, size
class _lcproj():
def __init__(self, lc, proj):
self.lc = lc
self.projection = proj
def __call__(self, x, projection):
xlc = _tools.project_points(x, self.projection, projection)
x2 = _tools.np.copy(x)
eps = 1e-8
x2[:,0] += eps
x2[:,1] += eps
x2[:, 0] += eps
x2[:, 1] += eps
xlc = _tools.project_points(x, self.projection, projection)
xlc2 = _tools.project_points(x2, self.projection, projection)
slc = self.lc(xlc, projection)
h = _tools.np.hypot(xlc2[:,0]-xlc[:,0], xlc2[:,1]-xlc[:,1])/_tools.np.hypot(eps,eps)
enorm = _tools.np.hypot(eps, eps)
h = _tools.np.hypot(xlc2[:, 0]-xlc[:, 0], xlc2[:, 1]-xlc[:, 1])/enorm
return slc/h
def _curve_sample(curve, lc, projection):
gmsh.model.add(str(_tools.uuid.uuid4()))
#points = _tools.project_points(curve.points, curve.projection, projection)
tags = list([gmsh.model.geo.addPoint(*x, 0) - 1
for x in curve.points[:-1, :]])
if _tools.np.linalg.norm(curve.points[0, :]-curve.points[-1, :]) < 1e-8:
......
......@@ -58,4 +58,4 @@ seamsh.gmsh.gmsh.open("test.msh")
tag,nodes = seamsh.gmsh.gmsh.model.mesh.getElementsByType(2)
ntri = len(tag)
print("ntri",ntri)
assert(ntri>40000 and ntri<41000)
assert(ntri>43000 and ntri<44000)
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment