Exemple #1
0
void splineInter2D(double *Tc, double *dT, const double *T,
        const double *omega, const double *m, int N, const double *X,
        double *h, bool doDerivative, bool boundary) {
    // Increments in X and Y direction
    int xf, yf, i, j, k, m0 = m[0], m1 = m[1];
    double x, y, p;
    
    //for each value X compute the value in  the spline
    #pragma omp parallel for default(shared) private(x, y, xf, yf, p, i, j, k)
    for (i=0;i<N;i++) {
        Tc[i]   = 0;
        
        x = (X[i]   - omega[0]) / h[0] + .5 - 1;
        y = (X[i+N] - omega[2]) / h[1] + .5 - 1;

        //check if it is a valid x
        if (!boundary && (x<=-2 || y<=-2 || x>=m0+1 || y>=m1+1))
            continue;
        
        xf = floor(x);
        yf = floor(y);
        x  = x - xf;
        y  = y - yf;
        
        if (doDerivative) {
            dT[i]   = 0;
            dT[i+N] = 0;
        }

        for (j=-1;j<3;j++) {
            for (k=-1;k<3;k++) {
                if (boundary) {
                    p = T[min(m0-1,max(0,xf+j))+m0*(min(m1-1,max(0,yf+k)))];
                } else {
                    p = (xf+j<0 || xf+j>m0-1 ||
                         yf+k<0 || yf+k>m1-1)? 0: T[xf+j+m0*(yf+k)];
                }
                Tc[i] += p*b0(3-j,x-j)*b0(3-k,y-k);
                if (doDerivative) {
                    dT[i]   += p*db0(3-j,x-j)* b0(3-k,y-k);
                    dT[i+N] += p* b0(3-j,x-j)*db0(3-k,y-k);
                }
            }
        }
        
        if (mxIsNaN(Tc[i]))
            mexPrintf("Is NAN. ");
        
        if (doDerivative) {
            dT[i]   = dT[i]/h[0];
            dT[i+N] = dT[i+N]/h[1];
        }
    }    
}
Exemple #2
0
void splineInter1D(double *Tc, double *dT, const double *T,
        const double *omega, const double *m, int N, const double *X,
        double *h, bool doDerivative, bool boundary) {
    int xf, i, j, m0 = m[0];
    double x, p;
    
    #pragma omp parallel for default(shared) private(x, xf, p, i, j)
    for (i=0;i<N;i++) {
        Tc[i] = 0;
        
        x = (X[i] - omega[0]) / h[0] + .5 - 1; //subtract 1 for indexing purposes in C
        
        //check if it is a valid x
        if (!boundary && (x<=-2 || x>=m0+1))
            continue;
        
        xf = floor(x);
        x  = x - xf;
        
        if (doDerivative) {
            dT[i] = 0;
        }
        
        for (j=-1;j<3;j++) {
            if (boundary) {
                p = T[min(m0-1,max(0,xf+j))];
            } else {
                p = (xf+j<0 || xf+j>m0-1)? 0: T[xf+j];
            }
            Tc[i] += p*b0(3-j,x-j);
            if (doDerivative) {
                dT[i] += p*db0(3-j,x-j);
            }
        }
        
        if (mxIsNaN(Tc[i]))
            mexPrintf("Is NAN. ");
        
        if (doDerivative) {
            dT[i] = dT[i]/h[0];
        }
    }
}
static PyObject *test(PyObject *self,PyObject *args)
{
    double r;

    fprintf(stderr,"overflow");
    r = overflow(1.e160);
    printerr(r);

    fprintf(stderr,"\ndiv by 0");
    r = db0(0.0);
    printerr(r);

    fprintf(stderr,"\nnested outer");
    r = nest1(0, 0.0);
    printerr(r);

    fprintf(stderr,"\nnested inner");
    r = nest1(1, 1.0);
    printerr(r);

    fprintf(stderr,"\ntrailing outer");
    r = nest1(2, 2.0);
    printerr(r);

    fprintf(stderr,"\nnested prior");
    r = nest2(0, 0.0);
    printerr(r);

    fprintf(stderr,"\nnested interior");
    r = nest2(1, 1.0);
    printerr(r);

    fprintf(stderr,"\nnested trailing");
    r = nest2(2, 2.0);
    printerr(r);

    Py_INCREF (Py_None);
    return Py_None;
}
Exemple #4
0
void splineInter3D(double *Tc, double *dT, const double *T,
        const double *omega, const double *m, int N, const double *X,
        double *h, bool doDerivative, bool boundary) {
    int xf, yf, zf, i, j, k, l;
    int i1 = 1, m0 = m[0], m1 = m[1], m2 = m[2], m01 = m0*m1;
    double x, y, z, p;
    
    // Increments in X,Y and Z direction
    #pragma omp parallel for default(shared) private(x, y, z, xf, yf, zf, p, i, j, k, l)
    for (i=0;i<N;i++) {
        Tc[i] = 0;
        
        x = (X[i]     - omega[0]) / h[0] + .5 - 1;
        y = (X[i+N]   - omega[2]) / h[1] + .5 - 1;
        z = (X[i+2*N] - omega[4]) / h[2] + .5 - 1;
        
        xf = floor(x);
        yf = floor(y);
        zf = floor(z);
        
        //check if it is a valid x
        if (!boundary && (x<=-2 || y<=-2 || z<=-2 || x>=m[0]+1 || y>=m1+1|| z>=m2+1))
            continue;
        
        // Extract remainder
        x = x - xf;
        y = y - yf;
        z = z - zf;
        
        if (doDerivative) {
            dT[i]     = 0;
            dT[i+N]   = 0;
            dT[i+2*N] = 0;
        }
        
        for (j=-1;j<3;j++) {
            for (k=-1;k<3;k++) {
                for (l=-1;l<3;l++) {
                    if (boundary) {
                        p = T[min(m0-1,max(0,xf+j))+m0*(min(m1-1,max(0,yf+k)))+m01*(min(m2-1,max(0,zf+l)))];
                    } else {
                        p = (xf+j<0 || xf+j>m0-1 ||
                             yf+k<0 || yf+k>m1-1 ||
                             zf+l<0 || zf+l>m2-1)? 0: T[xf+j+m0*(yf+k)+m01*(zf+l)];
                    }
                    Tc[i] += p*b0(3-j,x-j)*b0(3-k,y-k)*b0(3-l,z-l);
                    if (doDerivative) {
                        dT[i]     += p*db0(3-j,x-j)* b0(3-k,y-k)* b0(3-l,z-l);
                        dT[i+N]   += p* b0(3-j,x-j)*db0(3-k,y-k)* b0(3-l,z-l);
                        dT[i+2*N] += p* b0(3-j,x-j)* b0(3-k,y-k)*db0(3-l,z-l);
                    }
                }
            }
        }
        
        if (mxIsNaN(Tc[i]))
            mexPrintf("Is NAN. ");
        
        if (doDerivative) {
            dT[i] = dT[i]/h[0]; dT[i+N] = dT[i+N]/h[1]; dT[i+2*N] = dT[i+2*N]/h[2];
        }
    }
}
Exemple #5
0
// Compute the normal at a specific point in the patch.
// The s and t values vary between 0 and 1.
QVector3D QGLBezierPatch::normal(qreal s, qreal t) const
{
    qreal a[4];
    qreal b[4];
    qreal tx, ty, tz;
    qreal sx, sy, sz;

    // Compute the derivative of the surface in t.
    a[0] = b0(s);
    a[1] = b1(s);
    a[2] = b2(s);
    a[3] = b3(s);
    b[0] = db0(t);
    b[1] = db1(t);
    b[2] = db2(t);
    b[3] = db3(t);
    tx = 0.0f;
    ty = 0.0f;
    tz = 0.0f;
    for (int i = 0; i < 4; ++i) {
        for (int j = 0; j < 4; ++j) {
            tx += a[i] * points[j * 4 + i].x() * b[j];
            ty += a[i] * points[j * 4 + i].y() * b[j];
            tz += a[i] * points[j * 4 + i].z() * b[j];
        }
    }

    // Compute the derivative of the surface in s.
    a[0] = db0(s);
    a[1] = db1(s);
    a[2] = db2(s);
    a[3] = db3(s);
    b[0] = b0(t);
    b[1] = b1(t);
    b[2] = b2(t);
    b[3] = b3(t);
    sx = 0.0f;
    sy = 0.0f;
    sz = 0.0f;
    for (int i = 0; i < 4; ++i) {
        for (int j = 0; j < 4; ++j) {
            sx += a[i] * points[j * 4 + i].x() * b[j];
            sy += a[i] * points[j * 4 + i].y() * b[j];
            sz += a[i] * points[j * 4 + i].z() * b[j];
        }
    }

    // The normal is the cross-product of the two derivatives,
    // normalized to a unit vector.
    QVector3D n = QVector3D::normal(QVector3D(sx, sy, sz), QVector3D(tx, ty, tz));
    if (n.isNull()) {
        // A zero normal may occur if one of the patch edges is zero-length.
        // We correct for this by substituting an overall patch normal that
        // we compute from two of the sides that are not zero in length.
        QVector3D sides[4];
        QVector3D vectors[2];
        sides[0] = points[3] - points[0];
        sides[1] = points[15] - points[3];
        sides[2] = points[12] - points[15];
        sides[3] = points[0] - points[12];
        int i = 0;
        int j = 0;
        vectors[0] = QVector3D(1.0f, 0.0f, 0.0f);
        vectors[1] = QVector3D(0.0f, 1.0f, 0.0f);
        while (i < 2 && j < 4) {
            if (sides[j].isNull())
                ++j;
            else
                vectors[i++] = sides[j++];
        }
        n = QVector3D::normal(vectors[0], vectors[1]);
    }
    return n;
}