def test(irad=0.05, orad=0.6): '''Torus, rotated in space. ''' geom = pygmsh.built_in.Geometry() R = pygmsh.rotation_matrix([1., 0., 0.], np.pi / 2) geom.add_torus( irad=irad, orad=orad, lcar=0.03, x0=[0.0, 0.0, -1.0], R=R ) R = pygmsh.rotation_matrix([0., 1., 0.], np.pi / 2) geom.add_torus( irad=irad, orad=orad, lcar=0.03, x0=[0.0, 0.0, 1.0], variant='extrude_circle' ) ref = 2 * 2 * np.pi ** 2 * orad * irad ** 2 points, cells, _, _, _ = pygmsh.generate_mesh(geom) assert np.isclose(compute_volume(points, cells), ref, rtol=5e-2) return points, cells
def generate(): geom = pg.Geometry() # internal radius of torus irad = 0.15 # external radius of torus orad = 0.27 # Z_pos = (irad+orad) * np.r_[ np.ones(8), -np.ones(8), np.ones(8), -np.ones(8) ] Alpha = np.r_[ np.arange(8) * np.pi/4.0, np.arange(8) * np.pi/4.0 + np.pi/16.0, np.arange(8) * np.pi/4.0, np.arange(8) * np.pi/4.0 + np.pi/16.0 ] A1 = (irad+orad) / np.tan(np.pi/8.0) * \ np.r_[ 1.6*np.ones(8), 1.6*np.ones(8), 1.9*np.ones(8), 1.9*np.ones(8) ] for alpha, a1, z in zip(Alpha, A1, Z_pos): # Rotate torus to the y-z-plane. R1 = pg.rotation_matrix([0.0, 1.0, 0.0], 0.5*np.pi) R2 = pg.rotation_matrix([0.0, 0.0, 1.0], alpha) x0 = np.array([a1, 0.0, 0.0]) x1 = np.array([0.0, 0.0, z]) # First rotate to y-z-plane, then move out to a1, rotate by angle # alpha, move up by z. # # xnew = R2*(R1*x+x0) + x1 # geom.add_torus( irad=irad, orad=orad, lcar=0.1, R=np.dot(R2, R1), x0=np.dot(R2, x0) + x1 ) geom.add_box( -1.0, 1.0, -1.0, 1.0, -1.0, 1.0, lcar=0.3 ) return geom.get_code()
def generate(): geom = pg.Geometry() # internal radius of torus irad = 0.15 # external radius of torus orad = 0.27 # Z_pos = (irad+orad) * np.r_[ np.ones(8), -np.ones(8), np.ones(8), -np.ones(8) ] Alpha = np.r_[ np.arange(8) * np.pi/4.0, np.arange(8) * np.pi/4.0 + np.pi/16.0, np.arange(8) * np.pi/4.0, np.arange(8) * np.pi/4.0 + np.pi/16.0 ] A1 = (irad+orad) / np.tan(np.pi/8.0) * \ np.r_[ 1.6*np.ones(8), 1.6*np.ones(8), 1.9*np.ones(8), 1.9*np.ones(8) ] for alpha, a1, z in zip(Alpha, A1, Z_pos): # Rotate torus to the y-z-plane. R1 = pg.rotation_matrix([0.0, 1.0, 0.0], 0.5*np.pi) R2 = pg.rotation_matrix([0.0, 0.0, 1.0], alpha) x0 = np.array([a1, 0.0, 0.0]) x1 = np.array([0.0, 0.0, z]) # First rotate to y-z-plane, then move out to a1, rotate by angle # alpha, move up by z. # # xnew = R2*(R1*x+x0) + x1 # geom.add_torus( irad=irad, orad=orad, lcar=0.1, R=np.dot(R2, R1), x0=np.dot(R2, x0) + x1 ) geom.add_box( -1.0, 1.0, -1.0, 1.0, -1.0, 1.0, lcar=0.3 ) return geom
def test(): geom = pygmsh.built_in.Geometry() # internal radius of torus irad = 0.15 # external radius of torus orad = 0.27 Z_pos = (irad + orad) * np.concatenate( [+np.ones(8), -np.ones(8), +np.ones(8), -np.ones(8)]) Alpha = np.concatenate([ np.arange(8) * np.pi / 4.0, np.arange(8) * np.pi / 4.0 + np.pi / 16.0, np.arange(8) * np.pi / 4.0, np.arange(8) * np.pi / 4.0 + np.pi / 16.0 ]) # pylint: disable=no-member A1 = (irad+orad) / np.tan(np.pi/8.0) * \ np.concatenate([ 1.6*np.ones(8), 1.6*np.ones(8), 1.9*np.ones(8), 1.9*np.ones(8) ]) for alpha, a1, z in zip(Alpha, A1, Z_pos): # Rotate torus to the y-z-plane. R1 = pygmsh.rotation_matrix([0.0, 1.0, 0.0], 0.5 * np.pi) R2 = pygmsh.rotation_matrix([0.0, 0.0, 1.0], alpha) x0 = np.array([a1, 0.0, 0.0]) x1 = np.array([0.0, 0.0, z]) # First rotate to y-z-plane, then move out to a1, rotate by angle # alpha, move up by z. # # xnew = R2*(R1*x+x0) + x1 # geom.add_torus(irad=irad, orad=orad, lcar=0.1, R=np.dot(R2, R1), x0=np.dot(R2, x0) + x1) geom.add_box(-1.0, 1.0, -1.0, 1.0, -1.0, 1.0, lcar=0.3) ref = 15.276653079300184 points, cells, _, _, _ = pygmsh.generate_mesh(geom) assert abs(compute_volume(points, cells) - ref) < 1.0e-2 * ref return points, cells
def test(): geom = pygmsh.built_in.Geometry() # internal radius of torus irad = 0.15 # external radius of torus orad = 0.27 Z_pos = (irad + orad) * np.concatenate( [+np.ones(8), -np.ones(8), +np.ones(8), -np.ones(8)] ) Alpha = np.concatenate( [ np.arange(8) * np.pi / 4.0, np.arange(8) * np.pi / 4.0 + np.pi / 16.0, np.arange(8) * np.pi / 4.0, np.arange(8) * np.pi / 4.0 + np.pi / 16.0, ] ) A1 = ( (irad + orad) / np.tan(np.pi / 8.0) * np.concatenate( [1.6 * np.ones(8), 1.6 * np.ones(8), 1.9 * np.ones(8), 1.9 * np.ones(8)] ) ) for alpha, a1, z in zip(Alpha, A1, Z_pos): # Rotate torus to the y-z-plane. R1 = pygmsh.rotation_matrix([0.0, 1.0, 0.0], 0.5 * np.pi) R2 = pygmsh.rotation_matrix([0.0, 0.0, 1.0], alpha) x0 = np.array([a1, 0.0, 0.0]) x1 = np.array([0.0, 0.0, z]) # First rotate to y-z-plane, then move out to a1, rotate by angle # alpha, move up by z. # # xnew = R2*(R1*x+x0) + x1 # geom.add_torus( irad=irad, orad=orad, lcar=0.1, R=np.dot(R2, R1), x0=np.dot(R2, x0) + x1 ) geom.add_box(-1.0, 1.0, -1.0, 1.0, -1.0, 1.0, lcar=0.3) ref = len(A1) * 2 * np.pi ** 2 * orad * irad ** 2 + 2.0 ** 3 mesh = pygmsh.generate_mesh(geom) assert np.isclose(compute_volume(mesh), ref, rtol=2e-2) return mesh
def generate(): '''Pipe with double-ring enclosure, rotated in space. ''' geom = pg.Geometry() R = pg.rotation_matrix([1, 0, 0], np.pi/6.0) geom.add_pipe( inner_radius=0.3, outer_radius=0.4, length=1.0, R=R, lcar=0.04 ) # x0 = np.array([0, 0, 0.3]) # geom.add_torus( # irad=0.05, orad=0.6, lcar=0.1, # R=R, # x0=np.dot(R, x0) # ) # x0 = np.array([0, 0, -0.3]) # geom.add_torus( # irad=0.05, orad=0.6, lcar=0.1, # R=R, # x0=np.dot(R, x0) # ) return geom
def test(): """Pipe with double-ring enclosure, rotated in space.""" with pygmsh.geo.Geometry() as geom: sqrt2on2 = 0.5 * np.sqrt(2.0) R = pygmsh.rotation_matrix([sqrt2on2, sqrt2on2, 0], np.pi / 6.0) geom.add_pipe(inner_radius=0.3, outer_radius=0.4, length=1.0, R=R, mesh_size=0.04) R = np.array([[0.0, 0.0, 1.0], [0.0, 1.0, 0.0], [1.0, 0.0, 0.0]]) geom.add_pipe( inner_radius=0.3, outer_radius=0.4, length=1.0, mesh_size=0.04, R=R, variant="circle_extrusion", ) mesh = geom.generate_mesh() ref = 0.43988203517453256 assert abs(compute_volume(mesh) - ref) < 1.0e-2 * ref return mesh
def generate(): '''Pipe with double-ring enclosure, rotated in space. ''' geom = pg.Geometry() R = pg.rotation_matrix([1, 1, 0], np.pi/6.0) geom.add_pipe( inner_radius=0.3, outer_radius=0.4, length=1.0, R=R, lcar=0.04 ) R = np.array([ [0.0, 0.0, 1.0], [0.0, 1.0, 0.0], [1.0, 0.0, 0.0] ]) geom.add_pipe( inner_radius=0.3, outer_radius=0.4, length=1.0, lcar=0.04, R=R, variant='circle_extrusion' ) return geom
def test(): '''Pipe with double-ring enclosure, rotated in space. ''' geom = pygmsh.built_in.Geometry() sqrt2on2 = 0.5*np.sqrt(2.) R = pygmsh.rotation_matrix([sqrt2on2, sqrt2on2, 0], np.pi/6.0) geom.add_pipe( inner_radius=0.3, outer_radius=0.4, length=1.0, R=R, lcar=0.04 ) R = np.array([ [0.0, 0.0, 1.0], [0.0, 1.0, 0.0], [1.0, 0.0, 0.0] ]) geom.add_pipe( inner_radius=0.3, outer_radius=0.4, length=1.0, lcar=0.04, R=R, variant='circle_extrusion' ) ref = 0.43988203517453256 points, cells, _, _, _ = pygmsh.generate_mesh(geom) assert abs(compute_volume(points, cells) - ref) < 1.0e-2 * ref return points, cells
def generate(): '''Pipe with double-ring enclosure, rotated in space. ''' geom = pg.Geometry() R = pg.rotation_matrix([1, 0, 0], np.pi/6.0) geom.add_pipe( inner_radius=0.3, outer_radius=0.4, length=1.0, R=R, lcar=0.04 ) # x0 = np.array([0, 0, 0.3]) # geom.add_torus( # irad=0.05, orad=0.6, lcar=0.1, # R=R, # x0=np.dot(R, x0) # ) # x0 = np.array([0, 0, -0.3]) # geom.add_torus( # irad=0.05, orad=0.6, lcar=0.1, # R=R, # x0=np.dot(R, x0) # ) return geom.get_code()
def generate(): '''Pipe with double-ring enclosure, rotated in space. ''' geom = pg.Geometry() R = pg.rotation_matrix([1, 1, 0], np.pi/6.0) geom.add_pipe( inner_radius=0.3, outer_radius=0.4, length=1.0, R=R, lcar=0.04 ) R = np.array([ [0.0, 0.0, 1.0], [0.0, 1.0, 0.0], [1.0, 0.0, 0.0] ]) geom.add_pipe( inner_radius=0.3, outer_radius=0.4, length=1.0, lcar=0.04, R=R, variant='circle_extrusion' ) return geom, 0.5317080205627609
def test(irad=0.05, orad=0.6): """Torus, rotated in space. """ geom = pygmsh.built_in.Geometry() R = pygmsh.rotation_matrix([1.0, 0.0, 0.0], np.pi / 2) geom.add_torus(irad=irad, orad=orad, lcar=0.03, x0=[0.0, 0.0, -1.0], R=R) R = pygmsh.rotation_matrix([0.0, 1.0, 0.0], np.pi / 2) geom.add_torus( irad=irad, orad=orad, lcar=0.03, x0=[0.0, 0.0, 1.0], variant="extrude_circle" ) ref = 2 * 2 * np.pi ** 2 * orad * irad ** 2 mesh = pygmsh.generate_mesh(geom) assert np.isclose(compute_volume(mesh), ref, rtol=5e-2) return mesh
def test(): geom = pygmsh.built_in.Geometry() # internal radius of torus irad = 0.15 # external radius of torus orad = 0.27 Z_pos = (irad + orad) * np.concatenate( [+np.ones(8), -np.ones(8), +np.ones(8), -np.ones(8)]) Alpha = np.concatenate([ np.arange(8) * np.pi / 4.0, np.arange(8) * np.pi / 4.0 + np.pi / 16.0, np.arange(8) * np.pi / 4.0, np.arange(8) * np.pi / 4.0 + np.pi / 16.0, ]) A1 = ((irad + orad) / np.tan(np.pi / 8.0) * np.concatenate([ 1.6 * np.ones(8), 1.6 * np.ones(8), 1.9 * np.ones(8), 1.9 * np.ones(8) ])) for alpha, a1, z in zip(Alpha, A1, Z_pos): # Rotate torus to the y-z-plane. R1 = pygmsh.rotation_matrix([0.0, 1.0, 0.0], 0.5 * np.pi) R2 = pygmsh.rotation_matrix([0.0, 0.0, 1.0], alpha) x0 = np.array([a1, 0.0, 0.0]) x1 = np.array([0.0, 0.0, z]) # First rotate to y-z-plane, then move out to a1, rotate by angle # alpha, move up by z. # # xnew = R2*(R1*x+x0) + x1 # geom.add_torus(irad=irad, orad=orad, lcar=0.1, R=np.dot(R2, R1), x0=np.dot(R2, x0) + x1) geom.add_box(-1.0, 1.0, -1.0, 1.0, -1.0, 1.0, lcar=0.3) ref = len(A1) * 2 * np.pi**2 * orad * irad**2 + 2.0**3 mesh = pygmsh.generate_mesh(geom) assert np.isclose(compute_volume(mesh), ref, rtol=2e-2) return mesh
def test(radius=1.0): with pygmsh.geo.Geometry() as geom: R = [ pygmsh.rotation_matrix(np.eye(1, 3, d)[0], theta) for d, theta in enumerate(np.pi / np.array([2.0, 3.0, 5])) ] geom.add_circle([7.0, 11.0, 13.0], radius, 0.1, R[0] @ R[1] @ R[2]) ref = np.pi * radius ** 2 mesh = geom.generate_mesh() assert np.isclose(compute_volume(mesh), ref, rtol=1e-2) return mesh
def test(radius=1.0): geom = pygmsh.built_in.Geometry() R = [ pygmsh.rotation_matrix(np.eye(1, 3, d)[0], theta) for d, theta in enumerate(np.pi / np.array([2.0, 3.0, 5])) ] geom.add_circle([7.0, 11.0, 13.0], radius, 0.1, R[0] @ R[1] @ R[2]) ref = np.pi * radius**2 points, cells, _, _, _ = pygmsh.generate_mesh(geom) assert np.isclose(compute_volume(points, cells), ref, rtol=1e-2) return points, cells
def test(radius=1.0): geom = pygmsh.built_in.Geometry() R = [ pygmsh.rotation_matrix(np.eye(1, 3, d)[0], theta) for d, theta in enumerate(np.pi / np.array([2.0, 3.0, 5])) ] geom.add_circle([7.0, 11.0, 13.0], radius, 0.1, R[0] @ R[1] @ R[2]) ref = np.pi * radius ** 2 mesh = pygmsh.generate_mesh(geom) assert np.isclose(compute_volume(mesh), ref, rtol=1e-2) return mesh
def test(irad=0.05, orad=0.6): """Torus, rotated in space.""" with pygmsh.geo.Geometry() as geom: R = pygmsh.rotation_matrix([1.0, 0.0, 0.0], np.pi / 2) geom.add_torus(irad=irad, orad=orad, mesh_size=0.03, x0=[0.0, 0.0, -1.0], R=R) mesh = geom.generate_mesh() ref = 2 * np.pi**2 * orad * irad**2 assert np.isclose(compute_volume(mesh), ref, rtol=5e-2) return mesh
def generate(): '''Pipe with double-ring enclosure, rotated in space. ''' geom = pg.Geometry() sqrt2on2 = 0.5 * np.sqrt(2.) R = pg.rotation_matrix([sqrt2on2, sqrt2on2, 0], np.pi / 6.0) geom.add_pipe(inner_radius=0.3, outer_radius=0.4, length=1.0, R=R, lcar=0.04) R = np.array([[0.0, 0.0, 1.0], [0.0, 1.0, 0.0], [1.0, 0.0, 0.0]]) geom.add_pipe(inner_radius=0.3, outer_radius=0.4, length=1.0, lcar=0.04, R=R, variant='circle_extrusion') return geom, 0.43988203517453256
def test(): """Pipe with double-ring enclosure, rotated in space. """ geom = pygmsh.built_in.Geometry() sqrt2on2 = 0.5 * np.sqrt(2.0) R = pygmsh.rotation_matrix([sqrt2on2, sqrt2on2, 0], np.pi / 6.0) geom.add_pipe(inner_radius=0.3, outer_radius=0.4, length=1.0, R=R, lcar=0.04) R = np.array([[0.0, 0.0, 1.0], [0.0, 1.0, 0.0], [1.0, 0.0, 0.0]]) geom.add_pipe( inner_radius=0.3, outer_radius=0.4, length=1.0, lcar=0.04, R=R, variant="circle_extrusion", ) ref = 0.43988203517453256 mesh = pygmsh.generate_mesh(geom) assert abs(compute_volume(mesh) - ref) < 1.0e-2 * ref return mesh