コード例 #1
0
ファイル: Instance.cpp プロジェクト: lexarvn/RayTracer
void Instance::transformBoundingBox()
{
    auto b = i->getBoundingBox();
    
    BoundingBox bb;
    
    for(int i = 0; i <= RayTracer::getInstance()->maxTime; ++i)
    {
        std::set<double> x,y,z;
        
        auto m = makeMatrices(i);
        
        auto p = Vector(b.xmin(i),0,0);
        p = transformLoc(m.first, p);
        x.insert(p.x);
        y.insert(p.y);
        z.insert(p.z);
        
        p = Vector(b.xmax(i),0,0);
        p = transformLoc(m.first, p);
        x.insert(p.x);
        y.insert(p.y);
        z.insert(p.z);
        
        p = Vector(0,b.ymin(i),0);
        p = transformLoc(m.first, p);
        x.insert(p.x);
        y.insert(p.y);
        z.insert(p.z);
        
        p = Vector(0,b.ymax(i),0);
        p = transformLoc(m.first, p);
        x.insert(p.x);
        y.insert(p.y);
        z.insert(p.z);
        
        p = Vector(0,0,b.zmin(i));
        p = transformLoc(m.first, p);
        x.insert(p.x);
        y.insert(p.y);
        z.insert(p.z);
        
        p = Vector(0,0,b.zmax(i));
        p = transformLoc(m.first, p);
        x.insert(p.x);
        y.insert(p.y);
        z.insert(p.z);
               
        bb.xmin.addFrame(i, *x.begin());
        bb.xmax.addFrame(i, *x.rbegin());
        bb.ymin.addFrame(i, *y.begin());
        bb.ymax.addFrame(i, *y.rbegin());
        bb.zmin.addFrame(i, *z.begin());
        bb.zmax.addFrame(i, *z.rbegin());
    }
    bbox = bb;
}
コード例 #2
0
int QDeclarativeDrag::qt_metacall(QMetaObject::Call _c, int _id, void **_a)
{
    _id = QObject::qt_metacall(_c, _id, _a);
    if (_id < 0)
        return _id;
    if (_c == QMetaObject::InvokeMetaMethod) {
        if (_id < 8)
            qt_static_metacall(this, _c, _id, _a);
        _id -= 8;
    }
#ifndef QT_NO_PROPERTIES
      else if (_c == QMetaObject::ReadProperty) {
        void *_v = _a[0];
        switch (_id) {
        case 0: *reinterpret_cast< QGraphicsObject**>(_v) = target(); break;
        case 1: *reinterpret_cast< Axis*>(_v) = axis(); break;
        case 2: *reinterpret_cast< qreal*>(_v) = xmin(); break;
        case 3: *reinterpret_cast< qreal*>(_v) = xmax(); break;
        case 4: *reinterpret_cast< qreal*>(_v) = ymin(); break;
        case 5: *reinterpret_cast< qreal*>(_v) = ymax(); break;
        case 6: *reinterpret_cast< bool*>(_v) = active(); break;
        case 7: *reinterpret_cast< bool*>(_v) = filterChildren(); break;
        }
        _id -= 8;
    } else if (_c == QMetaObject::WriteProperty) {
        void *_v = _a[0];
        switch (_id) {
        case 0: setTarget(*reinterpret_cast< QGraphicsObject**>(_v)); break;
        case 1: setAxis(*reinterpret_cast< Axis*>(_v)); break;
        case 2: setXmin(*reinterpret_cast< qreal*>(_v)); break;
        case 3: setXmax(*reinterpret_cast< qreal*>(_v)); break;
        case 4: setYmin(*reinterpret_cast< qreal*>(_v)); break;
        case 5: setYmax(*reinterpret_cast< qreal*>(_v)); break;
        case 7: setFilterChildren(*reinterpret_cast< bool*>(_v)); break;
        }
        _id -= 8;
    } else if (_c == QMetaObject::ResetProperty) {
        switch (_id) {
        case 0: resetTarget(); break;
        }
        _id -= 8;
    } else if (_c == QMetaObject::QueryPropertyDesignable) {
        _id -= 8;
    } else if (_c == QMetaObject::QueryPropertyScriptable) {
        _id -= 8;
    } else if (_c == QMetaObject::QueryPropertyStored) {
        _id -= 8;
    } else if (_c == QMetaObject::QueryPropertyEditable) {
        _id -= 8;
    } else if (_c == QMetaObject::QueryPropertyUser) {
        _id -= 8;
    }
#endif // QT_NO_PROPERTIES
    return _id;
}
コード例 #3
0
ファイル: box.hpp プロジェクト: NervanaSystems/aeon
 float size() const
 {
     if (xmax() < xmin() || ymax() < ymin())
     {
         // If box is invalid (e.g. xmax < xmin or ymax < ymin), return 0.
         return 0.0f;
     }
     else
     {
         return width() * height();
     }
 }
コード例 #4
0
ファイル: update.c プロジェクト: adamdempsey90/fargo3d
void update_flux(double *qs,double *q) {
    int i,j,k;
    i=j=k=0;
    double res,fac,facd,res2;
#ifdef _OPENMP
    #pragma omp parallel for private(i,j,k,res,fac,facd,res2)
#endif
    for(j=0;j<size_y-1;j++) {
        res = 0;
        res2 = 0;
        fac  = 0;
        facd = 0;
        for(i=0;i<size_x;i++) {    
            facd += dens[l];
            //fac += (SurfY(j+1,k)*vy_temp[lyp]*(qs[lyp]-q[l]) - SurfY(j,k)*vy_temp[l]*(qs[l]-q[l]))*InvVol(j,k);
            fac = ((vy_temp[l]*qs[l]*denstar[l]*SurfY(j,k)-vy_temp[lyp]*qs[lyp]*denstar[lyp]*SurfY(j+1,k))*InvVol(j,k));
            res += fac;

            //res2 += (( vy_temp[lyp]*(qs[lyp]-q[l]) - vy_temp[l]*(qs[l]-q[l]))/(ymin(j+1)-ymin(j)));
            
            res2 += .5*(vy_temp[l]+vy_temp[lyp])*(qs[lyp]-qs[l])/(ymin(j+1)-ymin(j));


            //res2 += ((vy_temp[l]*qs[l]*SurfY(j,k)-vy_temp[lyp]*qs[lyp]*SurfY(j+1,k))*InvVol(j,k));
            //res2 -= q[l]*((vy_temp[l]*SurfY(j,k) - vy_temp[lyp]*SurfY(j+1,k)))*InvVol(j,k);
        }
        res /=(double)nx;
        res2 /= (double)nx;
        fac /=(double)nx;
        facd /=(double)nx;
        drFt[j] -= dt*res*.5;
        LamdepS[j + size_y] -= .5*res2*dt*facd; 
        dtLd_rhs[j] -= fac*dt*.5;
    }
    return;
}
コード例 #5
0
int findTopmostVertex(coord *verts, const int numVerts)
{
	real ymin(32767);
	int vmin;
	coord *vertPtr = verts;

	for (int i = 0; i < numVerts; i++){
		if (vertPtr[1] < ymin)
		{
			ymin = vertPtr[1];
			vmin = i;
		}
		vertPtr += 2;
	}

	return vmin;
}
コード例 #6
0
ファイル: update.c プロジェクト: adamdempsey90/fargo3d
void update_density_Y(double dt) {
    int i,j,k;
    i=j=k=0;
    double res;
#ifdef _OPENMP
    #pragma omp parallel for collapse(2) private(i,j,k,res)
#endif
    for(k=0;k<size_z;k++) {
        for(j=0;j<size_y-1;j++) {
            res = 0;
            for(i=0;i<size_x;i++) {
                res += vy_temp[l]*denstar[l];
                dens[l] += dt*((vy_temp[l]*denstar[l]*SurfY(j,k)-vy_temp[lyp]*denstar[lyp]*SurfY(j+1,k))*InvVol(j,k));

            }
            res /= (double)nx;
            mdotavg[j] += res * -2*M_PI*ymin(j)*dt;
        }
    }
    return;
}
コード例 #7
0
// ---------------------------------------------------------------------------
//
// ---------------------------------------------------------------------------
TInt CSvgStyleElementImpl::GetAttributeFloat( const TInt aNameId,
                                              TFloatFixPt& aValue )
    {
    switch ( aNameId )
        {
        case KAtrRefX:
            {
            TFloatFixPt          xmin( KMAXFLOATFIX ), x; // 0x7fff is the maximum integer in TFixPt
            CSvgElementImpl*lNewElement = ( CSvgElementImpl* ) FirstChild();
            while ( lNewElement != NULL )
                {
                lNewElement->GetAttributeFloat( KAtrRefX, x );
                if ( x < xmin )
                    xmin = x;
                lNewElement = ( CSvgElementImpl * )
                              lNewElement->NextSibling();
                }
            aValue = xmin;
            }
        break;
        case KAtrRefY:
            {
            TFloatFixPt          ymin( KMAXFLOATFIX ), y; // 0x7fff is the maximum integer in TFixPt
            CSvgElementImpl*lNewElement = ( CSvgElementImpl* ) FirstChild();
            while ( lNewElement != NULL )
                {
                lNewElement->GetAttributeFloat( KAtrRefY, y );
                if ( y < ymin )
                    ymin = y;
                lNewElement = ( CSvgElementImpl * )
                              lNewElement->NextSibling();
                }
            aValue = ymin;
            }
        break;
        default:
        return CSvgElementImpl::GetAttributeFloat( aNameId, aValue );
        }
    return KErrNone;
    }
コード例 #8
0
ファイル: glyph_info.hpp プロジェクト: Vanuan/mapnik
 double height() const { return ymax() - ymin(); };
コード例 #9
0
 nervana::boundingbox::box unnormalize(float width, float height)
 {
     return nervana::boundingbox::box(
         xmin() * width, ymin() * height, xmax() * width - 1, ymax() * height - 1);
 }
コード例 #10
0
ファイル: qtessellator.cpp プロジェクト: KDE/android-qt
QRectF QTessellatorPrivate::collectAndSortVertices(const QPointF *points, int *maxActiveEdges)
{
    *maxActiveEdges = 0;
    Vertex *v = vertices.storage;
    Vertex **vv = vertices.sorted;

    qreal xmin(points[0].x());
    qreal xmax(points[0].x());
    qreal ymin(points[0].y());
    qreal ymax(points[0].y());

    // collect vertex data
    Q27Dot5 y_prev = FloatToQ27Dot5(points[vertices.nPoints-1].y());
    Q27Dot5 x_next = FloatToQ27Dot5(points[0].x());
    Q27Dot5 y_next = FloatToQ27Dot5(points[0].y());
    int j = 0;
    int i = 0;
    while (i < vertices.nPoints) {
        Q27Dot5 y_curr = y_next;

        *vv = v;

        v->x = x_next;
        v->y = y_next;
        v->flags = 0;

    next_point:

        xmin = qMin(xmin, points[i+1].x());
        xmax = qMax(xmax, points[i+1].x());
        ymin = qMin(ymin, points[i+1].y());
        ymax = qMax(ymax, points[i+1].y());

        y_next = FloatToQ27Dot5(points[i+1].y());
        x_next = FloatToQ27Dot5(points[i+1].x());

        // skip vertices on top of each other
        if (v->x == x_next && v->y == y_next) {
            ++i;
            if (i < vertices.nPoints)
                goto next_point;
            Vertex *v0 = vertices.storage;
            v0->flags &= ~(LineBeforeStarts|LineBeforeEnds|LineBeforeHorizontal);
            if (y_prev < y_curr)
                v0->flags |= LineBeforeEnds;
            else if (y_prev > y_curr)
                v0->flags |= LineBeforeStarts;
            else
                v0->flags |= LineBeforeHorizontal;
            if ((v0->flags & (LineBeforeStarts|LineAfterStarts))
                && !(v0->flags & (LineAfterEnds|LineBeforeEnds)))
                *maxActiveEdges += 2;
            break;
        }

        if (y_prev < y_curr)
            v->flags |= LineBeforeEnds;
        else if (y_prev > y_curr)
            v->flags |= LineBeforeStarts;
        else
            v->flags |= LineBeforeHorizontal;


        if (y_curr < y_next)
            v->flags |= LineAfterStarts;
        else if (y_curr > y_next)
            v->flags |= LineAfterEnds;
        else
            v->flags |= LineAfterHorizontal;
        // ### could probably get better limit by looping over sorted list and counting down on ending edges
        if ((v->flags & (LineBeforeStarts|LineAfterStarts))
            && !(v->flags & (LineAfterEnds|LineBeforeEnds)))
            *maxActiveEdges += 2;
        y_prev = y_curr;
        ++v;
        ++vv;
        ++j;
        ++i;
    }
    vertices.nPoints = j;

    QDEBUG() << "maxActiveEdges=" << *maxActiveEdges;
    vv = vertices.sorted;
    qSort(vv, vv + vertices.nPoints, compareVertex);

    return QRectF(xmin, ymin, xmax-xmin, ymax-ymin);
}
コード例 #11
0
ファイル: oldtessellator.cpp プロジェクト: maxxant/qt
void old_tesselate_polygon(QVector<XTrapezoid> *traps, const QPointF *pg, int pgSize,
                           bool winding)
{
    QVector<QEdge> edges;
    edges.reserve(128);
    qreal ymin(INT_MAX/256);
    qreal ymax(INT_MIN/256);

    //painter.begin(pg, pgSize);
    if (pg[0] != pg[pgSize-1])
        qWarning() << Q_FUNC_INFO << "Malformed polygon (first and last points must be identical)";
    // generate edge table
//     qDebug() << "POINTS:";
    for (int x = 0; x < pgSize-1; ++x) {
	QEdge edge;
        QPointF p1(Q27Dot5ToDouble(FloatToQ27Dot5(pg[x].x())),
                   Q27Dot5ToDouble(FloatToQ27Dot5(pg[x].y())));
        QPointF p2(Q27Dot5ToDouble(FloatToQ27Dot5(pg[x+1].x())),
                   Q27Dot5ToDouble(FloatToQ27Dot5(pg[x+1].y())));

//         qDebug() << "    "
//                  << p1;
	edge.winding = p1.y() > p2.y() ? 1 : -1;
	if (edge.winding > 0)
            qSwap(p1, p2);
        edge.p1.x = XDoubleToFixed(p1.x());
        edge.p1.y = XDoubleToFixed(p1.y());
        edge.p2.x = XDoubleToFixed(p2.x());
        edge.p2.y = XDoubleToFixed(p2.y());

	edge.m = (p1.y() - p2.y()) / (p1.x() - p2.x()); // line derivative
	edge.b = p1.y() - edge.m * p1.x(); // intersection with y axis
	edge.m = edge.m != 0.0 ? 1.0 / edge.m : 0.0; // inverted derivative
	edges.append(edge);
        ymin = qMin(ymin, qreal(XFixedToDouble(edge.p1.y)));
        ymax = qMax(ymax, qreal(XFixedToDouble(edge.p2.y)));
    }

    QList<const QEdge *> et; 	    // edge list
    for (int i = 0; i < edges.size(); ++i)
        et.append(&edges.at(i));

    // sort edge table by min y value
    qSort(et.begin(), et.end(), compareEdges);

    // eliminate shared edges
    for (int i = 0; i < et.size(); ++i) {
	for (int k = i+1; k < et.size(); ++k) {
            const QEdge *edgeI = et.at(i);
            const QEdge *edgeK = et.at(k);
            if (edgeK->p1.y > edgeI->p1.y)
                break;
   	    if (edgeI->winding != edgeK->winding &&
                isEqual(edgeI->p1, edgeK->p1) && isEqual(edgeI->p2, edgeK->p2)
		) {
 		et.removeAt(k);
		et.removeAt(i);
		--i;
		break;
	    }
	}
    }

    if (ymax <= ymin)
	return;
    QList<const QEdge *> aet; 	    // edges that intersects the current scanline

//     if (ymin < 0)
// 	ymin = 0;
//     if (paintEventClipRegion) // don't scan more lines than we have to
// 	ymax = paintEventClipRegion->boundingRect().height();

#ifdef QT_DEBUG_TESSELATOR
    qDebug("==> ymin = %f, ymax = %f", ymin, ymax);
#endif // QT_DEBUG_TESSELATOR

    currentY = ymin; // used by the less than op
    for (qreal y = ymin; y < ymax;) {
	// fill active edge table with edges that intersect the current line
	for (int i = 0; i < et.size(); ++i) {
            const QEdge *edge = et.at(i);
            if (edge->p1.y > XDoubleToFixed(y))
                break;
            aet.append(edge);
            et.removeAt(i);
            --i;
	}

	// remove processed edges from active edge table
	for (int i = 0; i < aet.size(); ++i) {
	    if (aet.at(i)->p2.y <= XDoubleToFixed(y)) {
		aet.removeAt(i);
 		--i;
	    }
	}
        if (aet.size()%2 != 0) {
#ifndef QT_NO_DEBUG
            qWarning("QX11PaintEngine: aet out of sync - this should not happen.");
#endif
            return;
        }

	// done?
	if (!aet.size()) {
            if (!et.size()) {
                break;
	    } else {
 		y = currentY = XFixedToDouble(et.at(0)->p1.y);
                continue;
	    }
        }

        // calculate the next y where we have to start a new set of trapezoids
	qreal next_y(INT_MAX/256);
 	for (int i = 0; i < aet.size(); ++i) {
            const QEdge *edge = aet.at(i);
 	    if (XFixedToDouble(edge->p2.y) < next_y)
 		next_y = XFixedToDouble(edge->p2.y);
        }

	if (et.size() && next_y > XFixedToDouble(et.at(0)->p1.y))
	    next_y = XFixedToDouble(et.at(0)->p1.y);

        int aetSize = aet.size();
	for (int i = 0; i < aetSize; ++i) {
	    for (int k = i+1; k < aetSize; ++k) {
                const QEdge *edgeI = aet.at(i);
                const QEdge *edgeK = aet.at(k);
		qreal m1 = edgeI->m;
		qreal b1 = edgeI->b;
		qreal m2 = edgeK->m;
		qreal b2 = edgeK->b;

		if (qAbs(m1 - m2) < 0.001)
                    continue;

                // ### intersect is not calculated correctly when optimized with -O2 (gcc)
                volatile qreal intersect = 0;
                if (!qIsFinite(b1))
                    intersect = (1.f / m2) * XFixedToDouble(edgeI->p1.x) + b2;
                else if (!qIsFinite(b2))
                    intersect = (1.f / m1) * XFixedToDouble(edgeK->p1.x) + b1;
                else
                    intersect = (b1*m1 - b2*m2) / (m1 - m2);

 		if (intersect > y && intersect < next_y)
		    next_y = intersect;
	    }
	}

        XFixed yf, next_yf;
        yf = qrealToXFixed(y);
        next_yf = qrealToXFixed(next_y);

        if (yf == next_yf) {
            y = currentY = next_y;
            continue;
        }

#ifdef QT_DEBUG_TESSELATOR
        qDebug("###> y = %f, next_y = %f, %d active edges", y, next_y, aet.size());
        qDebug("===> edges");
        dump_edges(et);
        qDebug("===> active edges");
        dump_edges(aet);
#endif
	// calc intersection points
 	QVarLengthArray<QIntersectionPoint> isects(aet.size()+1);
 	for (int i = 0; i < isects.size()-1; ++i) {
            const QEdge *edge = aet.at(i);
 	    isects[i].x = (edge->p1.x != edge->p2.x) ?
			  ((y - edge->b)*edge->m) : XFixedToDouble(edge->p1.x);
	    isects[i].edge = edge;
	}

	if (isects.size()%2 != 1)
	    qFatal("%s: number of intersection points must be odd", Q_FUNC_INFO);

	// sort intersection points
 	qSort(&isects[0], &isects[isects.size()-1], compareIntersections);
//         qDebug() << "INTERSECTION_POINTS:";
//  	for (int i = 0; i < isects.size(); ++i)
//             qDebug() << isects[i].edge << isects[i].x;

        if (winding) {
            // winding fill rule
            for (int i = 0; i < isects.size()-1;) {
                int winding = 0;
                const QEdge *left = isects[i].edge;
                const QEdge *right = 0;
                winding += isects[i].edge->winding;
                for (++i; i < isects.size()-1 && winding != 0; ++i) {
                    winding += isects[i].edge->winding;
                    right = isects[i].edge;
                }
                if (!left || !right)
                    break;
                //painter.addTrapezoid(&toXTrapezoid(yf, next_yf, *left, *right));
                traps->append(toXTrapezoid(yf, next_yf, *left, *right));
            }
        } else {
            // odd-even fill rule
            for (int i = 0; i < isects.size()-2; i += 2) {
                //painter.addTrapezoid(&toXTrapezoid(yf, next_yf, *isects[i].edge, *isects[i+1].edge));
                traps->append(toXTrapezoid(yf, next_yf, *isects[i].edge, *isects[i+1].edge));
            }
        }
	y = currentY = next_y;
    }

#ifdef QT_DEBUG_TESSELATOR
    qDebug("==> number of trapezoids: %d - edge table size: %d\n", traps->size(), et.size());

    for (int i = 0; i < traps->size(); ++i)
        dump_trap(traps->at(i));
#endif

    // optimize by unifying trapezoids that share left/right lines
    // and have a common top/bottom edge
//     for (int i = 0; i < tps.size(); ++i) {
// 	for (int k = i+1; k < tps.size(); ++k) {
// 	    if (i != k && tps.at(i).right == tps.at(k).right
// 		&& tps.at(i).left == tps.at(k).left
// 		&& (tps.at(i).top == tps.at(k).bottom
// 		    || tps.at(i).bottom == tps.at(k).top))
// 	    {
// 		tps[i].bottom = tps.at(k).bottom;
// 		tps.removeAt(k);
//                 i = 0;
// 		break;
// 	    }
// 	}
//     }
    //static int i = 0;
    //QImage img = painter.end();
    //img.save(QString("res%1.png").arg(i++), "PNG");
}
コード例 #12
0
ファイル: resist.c プロジェクト: adamdempsey90/ssdisk
void _Resist_cpu (int idx, int idy, int idz, int idx1, int idy1, int idz1, int idx2, int idy2, int idz2, Field *B1, Field *B2, Field *Emf, Field2D *Eta) {

//<USER_DEFINED>
  INPUT(B1);
  INPUT(B2);
  INPUT(Emf);
  INPUT2D(Eta);
  OUTPUT(Emf);
//<\USER_DEFINED>

//<EXTERNAL>
  real* b1 = B1->field_cpu;
  real* b2 = B2->field_cpu;
  real* emf = Emf->field_cpu;
  real* eta = Eta->field_cpu;
  real dx = Dx;
  int pitch  = Pitch_cpu;
  int pitch2d = Pitch2D;
  int stride = Stride_cpu;
  int size_x = XIP; 
  int size_y = Ny+2*NGHY-1;
  int size_z = Nz+2*NGHZ-1;
//<\EXTERNAL>

//<INTERNAL>
  int i;
  int j;
  int k;
  int l1m;
  int l2m;
  int ll;
  real diff1;
  real diff2;
//<\INTERNAL>

//<CONSTANT>
// real ymin(Ny+2*NGHY+1);
// real zmin(Nz+2*NGHZ+1);
//<\CONSTANT>

//<MAIN_LOOP>
  for (k=1; k<size_z; k++) {
    for (j=1; j<size_y; j++) {
      for (i=XIM; i<size_x; i++) {
//<#>
	ll = l;
	l1m = lxm*idx1+lym*idy1+lzm*idz1;
	l2m = lxm*idx2+lym*idy2+lzm*idz2;
	/* Ideally it should not be the zone size but the distance
	   between zone centers. The different is very minute here and
	   does not matter */
	diff1 = zone_size_x(j,k)*idx1+zone_size_y(j,k)*idy1+zone_size_z(j,k)*idz1;
	diff2 = zone_size_x(j,k)*idx2+zone_size_y(j,k)*idy2+zone_size_z(j,k)*idz2;
	emf[ll] += eta[l2D]*((b2[ll]-b2[l1m])/diff1-(b1[ll]-b1[l2m])/diff2);
#ifdef CYLINDRICAL
	if (idz1+idz2 == 0) // Considering vertical component of Emf
	  emf[ll] -= eta[l2D]*(b1[ll]+b1[l2m])*.5/ymin(j); 
//Note that (phi,r,z) has a left-handed orientation.
#endif
#ifdef SPHERICAL
	if (idy1+idy2 == 0) // Considering radial component of Emf
	  emf[ll] += eta[l2D]*(b2[ll]+b2[l1m])*.5/ymed(j)*cos(zmin(k))/sin(zmin(k));
	if (idz1+idz2 == 0) // Considering colatitude component of Emf
	  emf[ll] -= eta[l2D]*(b1[ll]+b1[l2m])*.5/ymin(j);
	if (idx1+idx2 == 0) // Considering azimuthal component of Emf
	  emf[ll] += eta[l2D]*(b2[ll]+b2[l1m])*.5/ymin(j);
#endif
//<\#>
      }
    }
  }
//<\MAIN_LOOP>
}
コード例 #13
0
ファイル: substep1_y.c プロジェクト: adamdempsey90/fargo3d
void SubStep1_y_cpu (real dt) {
  
//<USER_DEFINED>
  INPUT(Pressure);
  INPUT(Density);
  INPUT(Pot);
#ifdef X
  INPUT(Vx);
#endif
#ifdef Y
  INPUT(Vy);
  OUTPUT(Vy_temp);
#endif
#ifdef Z
  INPUT(Vz);
#endif
#ifdef MHD
  INPUT(Bx);
  INPUT(Bz);
#endif
//<\USER_DEFINED>

//<EXTERNAL>
  real* p   = Pressure->field_cpu;
  real* pot = Pot->field_cpu;
  real* rho = Density->field_cpu;
#ifdef X
  real* vx      = Vx->field_cpu;
  real* vx_temp = Vx_temp->field_cpu;
#endif
#ifdef Y
  real* vy      = Vy->field_cpu;
  real* vy_temp = Vy_temp->field_cpu;
#endif
#ifdef Z
  real* vz      = Vz->field_cpu;
  real* vz_temp = Vz_temp->field_cpu;
#endif
#ifdef MHD
  real* bx = Bx->field_cpu;
  real* bz = Bz->field_cpu;
#endif
  int pitch  = Pitch_cpu;
  int stride = Stride_cpu;
  int size_x = XIP; 
  int size_y = Ny+2*NGHY-1;
  int size_z = Nz+2*NGHZ-1;
//<\EXTERNAL>

//<INTERNAL>
  int i; //Variables reserved
  int j; //for the topology
  int k; //of the kernels
  int ll;
  real dtOVERrhom;
#ifdef X
  int llxp;
#endif
#ifdef Y
  int llym;
#endif
#ifdef Z
  int llzp;
#endif
#ifdef MHD
  real db1;
  real db2;
  real bmeanm;
  real bmean;
#endif
#ifndef CARTESIAN
  real vphi;
#endif
#ifdef SHEARINGBOX
  real vm1, vm2;
#endif
#ifdef SPHERICAL
  real vzz;
#endif
//<\INTERNAL>


//<CONSTANT>
// real xmin(Nx+2*NGHX+1);
// real ymin(Ny+2*NGHY+1);
// real zmin(Nz+2*NGHZ+1);
// real OMEGAFRAME(1);
// real OORTA(1);
// real VERTICALDAMPING(1);
//<\CONSTANT>

//<MAIN_LOOP>

  i = j = k = 0;

#ifdef Z
  for(k=1; k<size_z; k++) {
#endif
#ifdef Y
    for(j=1; j<size_y; j++) {
#endif
#ifdef X
      for(i=XIM; i<size_x; i++) {
#endif
//<#>
#ifdef Y
	ll = l;
#ifdef X
	llxp = lxp;
#endif //ENDIF X
	llym = lym;
#ifdef Z
	llzp = lzp;
#endif //ENDIF Z
	dtOVERrhom = 2.0*dt/(rho[ll]+rho[llym]);

#ifdef CARTESIAN
	vy_temp[ll] = vy[ll] - 
	  dtOVERrhom*(p[ll]-p[llym])/(ymed(j)-ymed(j-1));

#ifdef SHEARINGBOX 
	vm1 = vx[ll]+vx[llxp]; 
	vm2 = vx[llym]+vx[llxp-pitch]; 
	vy_temp[l] += dt*(.5*OMEGAFRAME*(vm1+vm2) -
			  4.0*OORTA*OMEGAFRAME*ymin(j)); 
#endif //ENDIF SHEARINGBOX
#ifdef MHD
#ifndef PASSIVEMHD
	bmean  = 0.5*(bx[ll] + bx[llxp]);
	bmeanm = 0.5*(bx[llym] + bx[llxp-pitch]);

	db1 = (bmean*bmean-bmeanm*bmeanm);

	bmean  = 0.5*(bz[ll] + bz[llzp]);
	bmeanm = 0.5*(bz[llym] + bz[llym+stride]);

	db2 = (bmean*bmean-bmeanm*bmeanm); //grad(b^2/2)

	vy_temp[ll] -= .5*dtOVERrhom*(db1 + db2)/((ymed(j)-ymed(j-1))*MU0);
#endif //ENDIF !PASSIVEMHD
#endif //ENDIF MHD
#endif //ENDIF CARTESIAN

#ifdef CYLINDRICAL
	vphi = .25*(vx[ll] + vx[llxp] + vx[llym] + vx[llxp-pitch]);
	vphi += ymin(j)*OMEGAFRAME;
 	vy_temp[ll] = vy[ll] -
	  dtOVERrhom*(p[ll]-p[llym])/(ymed(j)-ymed(j-1));
	vy_temp[ll] += vphi*vphi/ymin(j)*dt;
	vy_temp[ll] /= (1.+VERTICALDAMPING*dt);

#ifdef MHD	
#ifndef PASSIVEMHD
	bmean  = 0.5*(bx[ll] + bx[llxp]);
	bmeanm = 0.5*(bx[llym] + bx[llxp-pitch]);

	vy_temp[ll] -= dtOVERrhom*.25*(bmean+bmeanm)*(bmean+bmeanm)/(MU0*ymin(j));

	db1 = (bmean*bmean-bmeanm*bmeanm);

	bmean  = 0.5*(bz[ll] + bz[llzp]);
	bmeanm = 0.5*(bz[llym] + bz[llym+stride]);

	db2 = (bmean*bmean-bmeanm*bmeanm); //-grad((bphi^2+bz^2)/2)

	vy_temp[ll] -= .5*dtOVERrhom*(db1 + db2)/((ymed(j)-ymed(j-1))*MU0);
	
#endif //END !PASSIVEMHD
#endif //END MHD
#endif //END CYLINDRICAL

#ifdef SPHERICAL
	vphi =  .25*(vx[ll] + vx[llxp] + vx[llym] + vx[llxp-pitch]);
	vphi += ymin(j)*sin(zmed(k))*OMEGAFRAME;
 	vy_temp[ll] = vy[ll] - 
	  dtOVERrhom*(p[ll]-p[llym])/(ymed(j)-ymed(j-1));
	vzz = .25*(vz[ll] + vz[llzp]  + vz[llym] + vz[llzp-pitch]);
	vy_temp[ll] += (vphi*vphi + vzz*vzz)/ymin(j)*dt;
#ifdef MHD	
#ifndef PASSIVEMHD
	bmean  = 0.5*(bx[ll] + bx[llxp]);
	bmeanm = 0.5*(bx[llym] + bx[llxp-pitch]);

	vy_temp[ll] -= dtOVERrhom*.25*(bmean+bmeanm)*(bmean+bmeanm)/(MU0*ymin(j));//Source term -B_phi^2/(mu_0\rho r)

	db1 = (bmean*bmean-bmeanm*bmeanm);

	bmean  = 0.5*(bz[ll] + bz[llzp]);
	bmeanm = 0.5*(bz[llym] + bz[llym+stride]);

	vy_temp[ll] -= dtOVERrhom*.25*(bmean+bmeanm)*(bmean+bmeanm)/(MU0*ymin(j));//Source term -B_\theta^2/(mu_0\rho r)

	db2 = (bmean*bmean-bmeanm*bmeanm); //-grad((bphi^2+btheta^2)/2)

	vy_temp[ll] -= .5*dtOVERrhom*(db1 + db2)/((ymed(j)-ymed(j-1))*MU0);
	
#endif //END !PASSIVEMHD
#endif //END MHD
#endif //END SPHERICAL


#ifdef POTENTIAL
	vy_temp[ll] -= (pot[ll]-pot[llym])*dt/(ymed(j)-ymed(j-1));
#endif //ENDIF POTENTIAL
#endif //ENDIF Y


//<\#>
#ifdef X
      }
#endif
#ifdef Y
    }
#endif
#ifdef Z
  }
#endif
//<\MAIN_LOOP>

}
コード例 #14
0
ファイル: update.c プロジェクト: adamdempsey90/fargo3d
void update_flux_avg(double *qs, double *q) {
    int i,j,k;
    i=j=k=0;
    double res, res1,res2,fac;
    double vravg, vravgp;
    double davg, davgp;
#ifdef _FFTW
    for(j=0;j<size_y-1;j++) {
        conv_prefac[j] = -dt*qs[j]*SurfY(j,k)*InvVol(j,k);
    }
    convolution_2d(vy_temp,denstar,drFd,conv_prefac,0,size_y,size_y-1);

    for(j=0;j<size_y-1;j++) {
        conv_prefac[j] = dt*qs[j+1]*SurfY(j+1,k)*InvVol(j,k);
    }
    convolution_2d(&vy_temp[size_x],&denstar[size_x],drFd,conv_prefac,0,size_y,size_y-1);
#endif
#ifdef _OPENMP
    //#pragma omp parallel for private(i,j,k,res,fac,res2,res1,vravg,vravgp,davg,davgp)
#endif
    for(j=0;j<size_y-1;j++) {
        i = 0;
     //   convolution(&vy_temp[l],&denstar[l],drFd,-dt*qs[j]*SurfY(j,k)*InvVol(j,k),j,size_y);
    //    convolution(&vy_temp[lyp],&denstar[lyp],drFd,dt*qs[j+1]*SurfY(j+1,k)*InvVol(j,k),j,size_y);
    
        
        res = 0;
        res1 = 0;
        res2 = 0;
        fac = 0;
        vravg = 0;
        vravgp = 0;
        davg = 0;
        davgp = 0;
        for(i=0;i<size_x;i++) {    
//            fac += (denstar[lyp]*vy_temp[lyp]*SurfY(j+1,k)*(qs[j+1] - q[j]) - denstar[l]*vy_temp[l]*SurfY(j,k)*(qs[j] - q[j]))*InvVol(j,k);
            vravg += vy_temp[l];
            vravgp += vy_temp[lyp];
            davg += denstar[l];
            davgp += denstar[lyp];

            fac = ((vy_temp[l]*qs[j]*denstar[l]*SurfY(j,k)-vy_temp[lyp]*qs[j+1]*denstar[lyp]*SurfY(j+1,k))*InvVol(j,k));
            res += fac;
            //res2 += fac - .5*(qs[j] + qs[j+1])*((vy_temp[l]*denstar[l]*SurfY(j,k)-vy_temp[lyp]*denstar[lyp]*SurfY(j+1,k))*InvVol(j,k));
            
            res2 += dens[l]*.5*(vy_temp[l]+vy_temp[lyp])*(qs[j+1]-qs[j])/(ymin(j+1)-ymin(j));

            //res2 += (vy_temp[lyp]*denstar[lyp]*(qs[j+1]-q[j]) - vy_temp[l]*denstar[l]*(qs[j]-q[j]))/(ymin(j+1)-ymin(j));
        //    res2 += fac - q[j]*((vy_temp[l]*denstar[l]*SurfY(j,k)-vy_temp[lyp]*denstar[lyp]*SurfY(j+1,k))*InvVol(j,k));
            //res += ((vy_temp[l]*qs[j]*denstar[l]*ymin(j)-vy_temp[lyp]*qs[j+1]*denstar[lyp]*ymin(j+1)))/(ymin(j+1)-ymin(j));
        }
        res /=(double)nx;
        res2 /= (double)nx;
        fac /=(double)nx;
        vravg /= (double)nx;
        vravgp /= (double)nx;
        davg /= (double)nx;
        davgp /= (double)nx;
        
        res1 = ((vravg*qs[j]*davg*SurfY(j,k)-vravgp*qs[j+1]*davgp*SurfY(j+1,k))*InvVol(j,k));

        drFd[j] -= dt*res;
        mdotl[j] -= dt*res;
        drFdB[j] -= dt*res1;
        LamdepS[j] += dt*res2;
    }
    return;
}
コード例 #15
0
void visctensor_cart_cpu(){

//<USER_DEFINED>
  INPUT(Density);
#ifdef X
  INPUT(Vx);
  OUTPUT(Mmx);
  OUTPUT(Mpx);
#endif
#ifdef Y
  INPUT(Vy);
  OUTPUT(Mmy);
  OUTPUT(Mpy);
#endif
#ifdef Z
  INPUT(Vz);
  OUTPUT(Mmz);
  OUTPUT(Mpz);
#endif
//<\USER_DEFINED>

//<EXTERNAL>
  real* rho = Density->field_cpu;
#ifdef X
  real* vx = Vx->field_cpu;
#endif
#ifdef Y
  real* vy = Vy->field_cpu;
#endif
#ifdef Z
  real* vz = Vz->field_cpu;
#endif
#ifdef X
  real* tauxx = Mmx->field_cpu;
#endif
#ifdef Y
  real* tauyy = Mmy->field_cpu;
#endif
#ifdef Z
  real* tauzz = Mmz->field_cpu;
#endif
#if defined(X) && defined(Z)
  real* tauxz = Mpx->field_cpu;
#endif
#if defined(Y) && defined(X)
  real* tauyx = Mpy->field_cpu;
#endif
#if defined(Z) && defined(Y)
  real* tauzy = Mpz->field_cpu;
#endif
  int pitch  = Pitch_cpu;
  int stride = Stride_cpu;
  int size_x = XIP; 
  int size_y = Ny+2*NGHY-1;
  int size_z = Nz+2*NGHZ-1;
  real dx = Dx;
//<\EXTERNAL>

//<INTERNAL>
  int i;
  int j;
  int k;
  real div_v;
//<\INTERNAL>

//<CONSTANT>
// real NU(1);
// real Sxj(Ny+2*NGHY);
// real Syj(Ny+2*NGHY);
// real Szj(Ny+2*NGHY);
// real Sxk(Nz+2*NGHZ);
// real Syk(Nz+2*NGHZ);
// real Szk(Nz+2*NGHZ);
// real ymin(Ny+2*NGHY+1);
// real zmin(Nz+2*NGHZ+1);
// real InvVj(Ny+2*NGHY);
//<\CONSTANT>

//<MAIN_LOOP>

  i = j = k = 0;

#ifdef Z
  for(k=1; k<size_z; k++) {
#endif
#ifdef Y
    for(j=1; j<size_y; j++) {
#endif
#ifdef X
      for(i=XIM; i<size_x; i++) {
#endif
//<#>
//Evaluate centered divergence.
	div_v = 0.0;
#ifdef X
	div_v += (vx[lxp]-vx[l])*SurfX(j,k);
#endif
#ifdef Y
	div_v += (vy[lyp]*SurfY(j+1,k)-vy[l]*SurfY(j,k));
#endif
#ifdef Z
	div_v += (vz[lzp]*SurfZ(j,k+1)-vz[l]*SurfZ(j,k));
#endif
	div_v *= 2.0/3.0*InvVol(j,k);

#ifdef X
	tauxx[l] = NU*rho[l]*(2.0*(vx[lxp]-vx[l])/dx - div_v);
#endif
#ifdef Y
	tauyy[l] = NU*rho[l]*(2.0*(vy[lyp]-vy[l])/(ymin(j+1)-ymin(j)) - div_v);
#endif
#ifdef Z
	tauzz[l] = NU*rho[l]*(2.0*(vz[lzp]-vz[l])/(zmin(k+1)-zmin(k)) - div_v);
#endif

#if defined(X) && defined(Z)
	tauxz[l] = NU*.25*(rho[l]+rho[lzm]+rho[lxm]+rho[lxm-stride])*((vx[l]-vx[lzm])/(zmed(k)-zmed(k-1)) + (vz[l]-vz[lxm])/dx); //centered on lower, left "radial" edge in y
#endif

#if defined(Y) && defined(X)
	tauyx[l] = NU*.25*(rho[l]+rho[lxm]+rho[lym]+rho[lxm-pitch])*((vy[l]-vy[lxm])/dx + (vx[l]-vx[lym])/(ymed(j)-ymed(j-1))); //centered on left, inner vertical edge in z
#endif

#if defined(Z) && defined(Y)
	tauzy[l] = NU*.25*(rho[l]+rho[lym]+rho[lzm]+rho[lym-stride])*((vz[l]-vz[lym])/(ymed(j)-ymed(j-1)) + (vy[l]-vy[lzm])/(zmed(k)-zmed(k-1))); //centered on lower, inner edge in x ("azimuthal")
#endif
//<\#>
#ifdef X
      }
#endif
#ifdef Y
    }
#endif
#ifdef Z
  }
#endif
//<\MAIN_LOOP>
}
コード例 #16
0
ファイル: viscosity.c プロジェクト: adamdempsey90/fargo3d
void viscosity(void) {
    int i,j,k;
    i=j=k=0;
    double visc, viscm,div_v;
    double res,fac,facp;
    double res2,fac2;
    double res3,fac3;
    double resd,facd;
    double res4;
    visc = 0;
    viscm = 0;
    compute_energy();
#ifdef _OPENMP
    #pragma omp parallel 
    {
    #pragma omp for collapse(3) private(i,j,k,visc,viscm,div_v)
#endif
    for(k=0;k<size_z;k++) {
        for(j=1;j<size_y-1;j++) {
            for(i=0;i<size_x;i++) {

                visc = params.alpha*energy[l]*energy[l]*sqrt(ymed(j)*ymed(j)*ymed(j));
                viscm = params.alpha*.5*(energy[l]*energy[l]+energy[lym]*energy[lym])*sqrt(ymin(j)*ymin(j)*ymin(j));
                div_v = 0.0;
                div_v += (vx[lxp]-vx[l])*SurfX(j,k);
                div_v += (vy[lyp]*SurfY(j+1,k)-vy[l]*SurfY(j,k));
                div_v *= 2.0/3.0*InvVol(j,k);

                tauxx[l] = visc*dens[l]*(2.0*(vx[lxp]-vx[l])/zone_size_x(j,k) - div_v);
                tauxx[l] += visc*dens[l]*(vy[lyp]+vy[l])/ymed(j);
                tauyy[l] = visc*dens[l]*(2.0*(vy[lyp]-vy[l])/(ymin(j+1)-ymin(j)) - div_v);
                tauxy[l] = viscm*.25*(dens[l]+dens[lxm]+dens[lym]+dens[lxm-pitch])*((vy[l]-vy[lxm])/(dx*ymin(j)) + (vx[l]-vx[lym])/(ymed(j)-ymed(j-1))-.5*(vx[l]+vx[lym])/ymin(j)); //centered on left, inner vertical edge in z


            }
        }
    }



    i = j = k = 0;
#ifdef _OPENMP
#pragma omp for private(j,viscm)
#endif
    for(j=1;j<size_y-1;j++) {
        viscm = params.alpha*.5*(energy[l]*energy[l]+energy[lym]*energy[lym])*sqrt(ymin(j)*ymin(j)*ymin(j));
        tauxyavg[j] = viscm*.5*(dbar[j]+dbar[j-1])*( (vxbar[j]-vxbar[j-1])/(ymed(j)-ymed(j-1))-.5*(vxbar[j]+vxbar[j-1])/ymin(j)); 
    }
#ifdef _OPENMP
#pragma omp barrier
#pragma omp for collapse(2) private(i,j,k,res,fac,facp,resd,res2,res3,fac2,fac3,facd,res4)
#endif
    for(k=0;k<size_z;k++) {
        for(j=1;j<size_y-2;j++) {
            res = 0;
            resd = 0;
            res3 = 0;
            res2 = 0;
            res4 = 0;
            for(i=0;i<size_x;i++) {
                // X
                resd += dens[l];
                
                fac3 = 2.0*(tauxx[l]-tauxx[lxm])/(zone_size_x(j,k)*(dens[l]+dens[lxm]));
                res3 += fac3;
                
                vx_temp[l] += fac3*dt;
                
                fac =  (ymin(j+1)*ymin(j+1)*tauxy[lyp]-ymin(j)*ymin(j)*tauxy[l])/((ymin(j+1)-ymin(j))*ymed(j));

                
                //facp =  (ymin(j+1)*ymin(j+1)*tauxy[lxp+pitch]-ymin(j)*ymin(j)*tauxy[lxp])/((ymin(j+1)-ymin(j))*ymed(j));

                fac2 = fac*2.0/(ymed(j)*(dens[l]+dens[lxm]));

                //res2 += .5*fac2 + .5*facp*2.0/(ymed(j)*(dens[lxp]+dens[l]));

                res2 += fac2;

                vx_temp[l] += fac2*dt; 

                res += fac;

                //res4 += fac;
                // Y
                vy_temp[l] += 2.0*(ymed(j)*tauyy[l]-ymed(j-1)*tauyy[lym])/((ymed(j)-ymed(j-1))*(dens[l]+dens[lym])*ymin(j))*dt;
                vy_temp[l] += 2.0*(tauxy[lxp]-tauxy[l])/(dx*ymin(j)*(dens[l]+dens[lym]))*dt;
                vy_temp[l] -= (tauxx[l]+tauxx[lym])/(ymin(j)*(dens[l]+dens[lym]))*dt;
                //res += .5*(fac+facp);
            }
            res2 /= (double)nx;
            res3 /= (double)nx;
            resd /= (double)nx;
            res /= (double)nx;
            res4 /= (double)nx;

            LamdepS[j + size_y*3] += dt*res3*ymed(j)*resd;
            LamdepS[j + size_y*2] += dt*res2*ymed(j)*resd;
             drFt[j] += -dt*res;
             dtLd_rhs[j] += res*ymed(j);
            //drFd[j] = -(ymin(j+1)*ymin(j+1)*tauxyavg[j+1]*SurfY(j+1,k) - ymin(j)*ymin(j)*tauxyavg[j]*SurfY(j,k))*InvVol(j,k);
            
            facd  =  -dt*(ymin(j+1)*ymin(j+1)*tauxyavg[j+1]-ymin(j)*ymin(j)*tauxyavg[j])/((ymin(j+1)-ymin(j))*ymed(j));

            LamdepS[j + size_y*5] += facd; //-dt*res;
            drFd[j]  +=  facd; //-dt*res;             
            drFnu[j] += facd;
            drFdB[j]  +=  facd; //-dt*res;             

        }
    }
#ifdef _OPENMP
    }
#endif
    return;
}