Пример #1
0
def run_project_test(surface, handler, test_name):
    # Run a bunch of point projections: Only try to match to 1e-8
    eps = 1e-8

    # print('------------- These points should be fully inside of domain')
    pts= [[0,0,0],[2,3,-1],[3,2.5,-.1]]
    for pt in pts:
        # print('Projecting point (%f %f %f)'%(pt[0],pt[1],pt[2]))
        u,v,D = surface.projectPoint(pt,eps=1e-12)
        handler.root_add_val('{} point {} projection u'.format(test_name, pt), u, tol=eps)
        handler.root_add_val('{} point {} projection v'.format(test_name, pt), v, tol=eps)
        handler.root_add_val('{} point {} projection D'.format(test_name, pt), D, tol=eps*10)

    # ----------- This should be (0,0) corner
    u,v,D = surface.projectPoint([-1,-1,0],eps=1e-12)
    handler.root_add_val('{} projected u for (0,0) corner'.format(test_name), u, tol=eps)
    handler.root_add_val('{} projected v for (0,0) corner'.format(test_name), v, tol=eps)

    # ---------- This should be (0,1) corner
    u,v,D = surface.projectPoint([-1,5,0],eps=1e-12)
    handler.root_add_val('{} projected u for (0,1) corner'.format(test_name), u, tol=eps)
    handler.root_add_val('{} projected v for (0,1) corner'.format(test_name), v, tol=eps)

    # ---------- This should be (1,0) corner
    u,v,D = surface.projectPoint([6,-1,0],eps=1e-12)
    handler.root_add_val('{} projected u for (1,0) corner'.format(test_name), u, tol=eps)
    handler.root_add_val('{} projected v for (1,0) corner'.format(test_name), v, tol=eps)

    # ---------- This should be (1,1) corner
    u,v,D = surface.projectPoint([6,6,0],eps=1e-12)
    handler.root_add_val('{} projected u for (1,1) corner'.format(test_name), u, tol=eps)
    handler.root_add_val('{} projected v for (1,1) corner'.format(test_name), v, tol=eps)

    # ---------- This should be edge zero (*,0)
    u,v,D = surface.projectPoint([2.54,-1,0],eps=1e-12)
    handler.root_add_val('{} projected u for (*,0) edge'.format(test_name), u, tol=eps)
    handler.root_add_val('{} projected v for (*,0) edge'.format(test_name), v, tol=eps)


    # Curve projection
    for kc in [2,3,4]:
        x = [0,1,2,0]
        y = [4,3,2,1]
        z = [-3,1,3,5]

        curve = pySpline.Curve(k=kc,x=x,y=y,z=z)
        u,v,s,D = surface.projectCurve(curve)
        # ---------- surface-curve projection with kc = kc
        handler.root_add_val('{} projected curve u with kc={}'.format(test_name, kc), u, tol=eps)
        handler.root_add_val('{} projected curve v with kc={}'.format(test_name, kc), v, tol=eps)
        handler.root_add_val('{} projected curve s with kc={}'.format(test_name, kc), s, tol=eps)
        handler.root_add_val('{} projected curve D with kc={}'.format(test_name, kc), D, tol=eps*10)
Пример #2
0
# This is a test script to test the functionality of the 
# pySpline surface
import numpy
from pyspline import pySpline

# Create a generic surface
nu = 20
nv = 20
u = numpy.linspace(0,4,nu)
v = numpy.linspace(0,4,nv)
[V,U] = numpy.meshgrid(v,u)
Z = numpy.cos(U)*numpy.sin(V)
surf = pySpline.Surface(x=U,y=V,z=Z,ku=4,kv=4,Nctlu=5,Nctlv=5)
surf.writeTecplot('surface.dat')

n = 100
theta = numpy.linspace(.0000,2*numpy.pi,n)
x = (numpy.cos(theta)-1)
y = (numpy.sin(theta)+1)
z = (numpy.linspace(0,1,n) + 2)
curve = pySpline.Curve(x=x,y=y,z=z,k=4,Nctl=16,niter=100)
curve.writeTecplot('helix.dat')

u,v,s,D = surf.projectCurve(curve,Niter=100,eps1=1e-10,eps2=1e-10,
                            u=1,v=1,s=1)

print(u,v,s,D)
print(curve(s))
print(surf(u,v))

Пример #3
0
def run_project_test(surface, handler):
    # Run a bunch of point projections: Only try to match to 1e-8
    eps = 1e-8

    # print('------------- These points should be fully inside of domain')
    pts = [[0, 0, 0], [2, 3, -1], [3, 2.5, -.1]]
    for pt in pts:
        # print('Projecting point (%f %f %f)'%(pt[0],pt[1],pt[2]))
        u, v, D = surface.projectPoint(pt, eps=1e-12)
        # print('u:')
        handler.root_add_val(u, eps, eps)
        # print('v:')
        handler.root_add_val(v, eps, eps)
        # print('D:')
        handler.root_add_val(D, eps * 10, eps * 10)

    # print(' ----------- This should be (0,0) corner')
    u, v, D = surface.projectPoint([-1, -1, 0], eps=1e-12)
    # print('u:')
    handler.root_add_val(u, eps, eps)
    # print('v:')
    handler.root_add_val(v, eps, eps)

    # print(' ---------- This should be (0,1) corner')
    u, v, D = surface.projectPoint([-1, 5, 0], eps=1e-12)
    # print('u:')
    handler.root_add_val(u, eps, eps)
    # print('v:')
    handler.root_add_val(v, eps, eps)

    # print(' ---------- This should be (1,0) corner')
    u, v, D = surface.projectPoint([6, -1, 0], eps=1e-12)
    # print('u:')
    handler.root_add_val(u, eps, eps)
    # print('v:')
    handler.root_add_val(v, eps, eps)

    # print(' ---------- This should be (1,1) corner')
    u, v, D = surface.projectPoint([6, 6, 0], eps=1e-12)
    # print('u:')
    handler.root_add_val(u, eps, eps)
    # print('v:')
    handler.root_add_val(v, eps, eps)

    # print(' ---------- This should be  edge zero (*,0)')
    u, v, D = surface.projectPoint([2.54, -1, 0], eps=1e-12)
    # print('u:')
    handler.root_add_val(u, eps, eps)
    # print('v:')
    handler.root_add_val(v, eps, eps)

    # Curve projection
    for kc in [2, 3, 4]:
        x = [0, 1, 2, 0]
        y = [4, 3, 2, 1]
        z = [-3, 1, 3, 5]

        curve = pySpline.Curve(k=kc, x=x, y=y, z=z)
        u, v, s, D = surface.projectCurve(curve)
        # print(' ---------- surface-curve projection with kc=%d'%(kc))
        # print('u:')
        handler.root_add_val(u, eps, eps)
        # print('v:')
        handler.root_add_val(v, eps, eps)
        # print('s:')
        handler.root_add_val(s, eps, eps)
        # print('D:')
        handler.root_add_val(D, eps * 10, eps * 10)
Пример #4
0
    def regression_test(self, handler):

        # print('+--------------------------------------+')
        # print('           Create Tests   ')
        # print('+--------------------------------------+')
        # print('-----------  2D k=2 test ----------')
        k = 2
        t = [0, 0, 0.5, 1, 1]
        coef = numpy.zeros((3, 2))
        coef[0] = [0, 0.6]
        coef[1] = [1.1, 1.4]
        coef[2] = [2.6, 5.1]
        curve = pySpline.Curve(t=t, k=k, coef=coef)
        run_curve_test(curve, handler, '2D k={}'.format(k))
        io_test(curve)

        # print('-----------  2D k=3 test ----------')
        k = 3
        t = [0, 0, 0, 0.5, 1, 1, 1]
        coef = numpy.zeros((4, 2))
        coef[0] = [0, 0.45]
        coef[1] = [.71, 1.5]
        coef[2] = [2.5, 5.9]
        coef[3] = [4, -2]
        curve = pySpline.Curve(t=t, k=k, coef=coef)
        run_curve_test(curve, handler, '2D k={}'.format(k))
        io_test(curve)

        # print('-----------  2D k=4 test ----------')
        k = 4
        t = [0, 0, 0, 0, 0.5, 1, 1, 1, 1]
        coef = numpy.zeros((5, 2))
        coef[0] = [0, -.60]
        coef[1] = [.9, 1.6]
        coef[2] = [1.6, 5.2]
        coef[3] = [4.2, -2.24]
        coef[4] = [2.9, 6.2]
        curve = pySpline.Curve(t=t, k=k, coef=coef)
        run_curve_test(curve, handler, '2D k={}'.format(k))
        io_test(curve)

        # Get helix data
        n = 100
        theta = numpy.linspace(0.0, numpy.pi * 2, n)
        x = numpy.cos(theta)
        y = numpy.sin(theta)
        z = numpy.linspace(0, 1, n)

        # print('+--------------------------------------+')
        # print('              LMS Tests   ')
        # print('+--------------------------------------+')
        for k in [2, 3, 4]:
            test_name = 'LMS test k={}'.format(k)
            # print('--------- Test helix data with k=%d-------'%(k))
            curve = pySpline.Curve(x=x, y=y, z=z, k=k, nCtl=16, niter=50)
            run_curve_test(curve, handler, test_name)
            run_project_test(curve, handler, test_name)

        # print('+--------------------------------------+')
        # print('           Interp Tests   ')
        # print('+--------------------------------------+')
        for k in [2, 3, 4]:
            test_name = 'interpolation test k={}'.format(k)
            # print('--------- Test helix data with k=%d-------'%(k))
            curve = pySpline.Curve(x=x, y=y, z=z, k=k)
            run_curve_test(curve, handler, test_name)
            run_project_test(curve, handler, test_name)
Пример #5
0
        # Set the chord as well
        geo.scale['wing'].coef[-1] = val[3]

    coords = hyp.getSurfaceCoordinates()
    DVGeo = DVGeometry(ffd_file)
    coef = DVGeo.FFD.vols[0].coef.copy()

    # First determine the reference chord lengths:
    nSpan = coef.shape[2]
    ref = numpy.zeros((nSpan, 3))

    for k in range(nSpan):
        max_x = numpy.max(coef[:, :, k, 0])
        min_x = numpy.min(coef[:, :, k, 0])

        ref[k, 0] = min_x + 0.25 * (max_x - min_x)
        ref[k, 1] = numpy.average(coef[:, :, k, 1])
        ref[k, 2] = numpy.average(coef[:, :, k, 2])

    c0 = pySpline.Curve(X=ref, k=2)
    DVGeo.addRefAxis('wing', c0)
    DVGeo.addGeoDVGlobal('winglet', [0, 0, 0, 1], winglet, lower=-5, upper=5)
    DVGeo.addPointSet(coords, 'coords')
    DVGeo.setDesignVars({'winglet': [1.5, 2.5, -2.0, .60]})
    hyp.setSurfaceCoordinates(DVGeo.update('coords'))

# Run and write grid
hyp.run()
hyp.writeCGNS('717.cgns')
Пример #6
0
    '''Test the writing functions'''
    crv.writeTecplot('tmp.dat')
    crv.writeTecplot('tmp.dat',coef=False, orig=False)
    os.remove('tmp.dat')

print('+--------------------------------------+')
print('           Create Tests   ')
print('+--------------------------------------+')
print('-----------  2D k=2 test ----------')
k = 2
t = [0,0,0.5,1,1]
coef = numpy.zeros((3,2))
coef[0] = [0,0.6]
coef[1] = [1.1,1.4]
coef[2] = [2.6,5.1]
curve = pySpline.Curve(t=t,k=k,coef=coef)
run_curve_test(curve)
io_test(curve)

print('-----------  2D k=3 test ----------')
k = 3
t = [0,0,0,0.5,1,1,1]
coef = numpy.zeros((4,2))
coef[0] = [0,0.45]
coef[1] = [.71,1.5]
coef[2] = [2.5,5.9]
coef[3] = [4,-2]
curve = pySpline.Curve(t=t,k=k,coef=coef)
run_curve_test(curve)
io_test(curve)
Пример #7
0
# This is a test script to test the functionality of the 
# pySpline curve class

import sys,time
import numpy
from pyspline import pySpline

# Get some Helix-like data

n = 100
theta = numpy.linspace(.0000,2*numpy.pi,n)
x = numpy.cos(theta)
y = numpy.sin(theta)
z = numpy.linspace(0,1,n)
print('Helix Data')
curve = pySpline.Curve(x=x,y=y,z=z,k=4,Nctl=16,niter=100)
curve.writeTecplot('helix.dat')

# Load naca0012 data
print('Naca 0012 data')
x,y = numpy.loadtxt('naca0012',unpack=True)
curve = pySpline.Curve(x=x,y=y,k=4,Nctl=11,niter=500)
curve.writeTecplot('naca_data.dat')

# Projection Tests
print('Projection Tests')
x = [0,2,3,5]
y = [-2,5,3,0]
z = [0,0,0,0]
curve1 = pySpline.Curve(x=x,y=y,z=z,k=4)