Esempio n. 1
0
bool isLeapYear(long iYear)
{
    if (iMod(iYear, 4) != 0)
    {
        // Not a leap year.
        //
        return false;
    }
    unsigned long wMod = iMod(iYear, 400);
    if ((wMod == 100) || (wMod == 200) || (wMod == 300))
    {
        // Not a leap year.
        //
        return false;
    }
    return true;
}
Esempio n. 2
0
// Epoch of iFixedDay should be 1 R.D.
//
static void GregorianFromFixed(int iFixedDay, int &iYear, int &iMonth,  int &iDayOfYear, int &iDayOfMonth, int &iDayOfWeek)
{
    int d0 = iFixedDay - 1;
    int d1, n400 = iFloorDivisionMod(d0, 146097, &d1);
    int d2, n100 = iFloorDivisionMod(d1,  36524, &d2);
    int d3, n4   = iFloorDivisionMod(d2,   1461, &d3);
    int d4, n1   = iFloorDivisionMod(d3,    365, &d4);
    d4 = d4 + 1;

    iYear = 400*n400 + 100*n100 + 4*n4 + n1;

    if (n100 != 4 && n1 != 4)
    {
        iYear = iYear + 1;
    }

    static int cache_iYear = 99999;
    static int cache_iJan1st = 0;
    static int cache_iMar1st = 0;
    int iFixedDayOfJanuary1st;
    int iFixedDayOfMarch1st;
    if (iYear == cache_iYear)
    {
        iFixedDayOfJanuary1st = cache_iJan1st;
        iFixedDayOfMarch1st = cache_iMar1st;
    }
    else
    {
        cache_iYear = iYear;
        cache_iJan1st = iFixedDayOfJanuary1st = FixedFromGregorian(iYear, 1, 1);
        cache_iMar1st = iFixedDayOfMarch1st = FixedFromGregorian(iYear, 3, 1);
    }


    int iPriorDays = iFixedDay - iFixedDayOfJanuary1st;
    int iCorrection;
    if (iFixedDay < iFixedDayOfMarch1st)
    {
        iCorrection = 0;
    }
    else if (isLeapYear(iYear))
    {
        iCorrection = 1;
    }
    else
    {
        iCorrection = 2;
    }

    iMonth = (12*(iPriorDays+iCorrection)+373)/367;
    iDayOfMonth = iFixedDay - FixedFromGregorian(iYear, iMonth, 1) + 1;
    iDayOfYear = iPriorDays + 1;

    // Calculate the Day of week using the linear progression of days.
    //
    iDayOfWeek = iMod(iFixedDay, 7);
}
Esempio n. 3
0
bool FieldedTimeToLinearTime(FIELDEDTIME *ft, INT64 *plt)
{
    if (!isValidDate(ft->iYear, ft->iMonth, ft->iDayOfMonth))
    {
        *plt = 0;
        return false;
    }

    int iFixedDay = FixedFromGregorian_Adjusted(ft->iYear, ft->iMonth, ft->iDayOfMonth);
    ft->iDayOfWeek = static_cast<unsigned short>(iMod(iFixedDay+1, 7));

    INT64 lt;
    lt  = iFixedDay * FACTOR_100NS_PER_DAY;
    lt += ft->iHour * FACTOR_100NS_PER_HOUR;
    lt += ft->iMinute * FACTOR_100NS_PER_MINUTE;
    lt += ft->iSecond * FACTOR_100NS_PER_SECOND;
    lt += ft->iMicrosecond * FACTOR_100NS_PER_MICROSECOND;
    lt += ft->iMillisecond * FACTOR_100NS_PER_MILLISECOND;
    lt += ft->iNanosecond / FACTOR_NANOSECONDS_PER_100NS;

    *plt = lt;
    return true;
}
Esempio n. 4
0
// this function can be run concurrently
void StepAdvec1(int j_start, int j_end, const double& dt, const dTensor3& node, 
        const dTensorBC4& qold, dTensorBC4& qnew, dTensorBC4& aux, 
        const dTensorBC2& u1, const dTensorBC2& u2)
{

    //-local parameters -----------------------------------------------------//
    int i,j, k, me, io, jo, num_cell_shift;
    int mx   = qnew.getsize(1);
    int my   = qnew.getsize(2);
    int meqn = qnew.getsize(3);
    int kmax = qnew.getsize(4);
    int mbc  = qnew.getmbc();
    int mpoints   = int((1+4*kmax-int(sqrt(1+8*kmax)))/2);
    int mpoints1d = int(sqrt(mpoints));

    // cell widths are uniform.  need only look at cell (1,1)
    double dx = node.get(2,1,1)-node.get(1,1,1);
    double dy = node.get(1,2,2)-node.get(1,1,2);
    double x1c = node.get(1,1,1) + dx/2.0;  // center of grid cell (1,1)
    double y1c = node.get(1,1,2) + dy/2.0;
    double scutx = 0.0;
    double scuty = 0.0;
    double xcut = 0.0;
    double ycut = 0.0;
    double speedx = 0.0;
    double speedy = 0.0;

    //legendre weight for "left/bottom" half of cell
    dTensor2 qleft(mpoints1d, kmax);		

    //legendre weights for "right/top" half of cell
    dTensor2 qright(mpoints1d, kmax);

    dTensor1 qcell(kmax);		//legendre weights for current cell
    dTensor1 scut(mpoints1d);   //location of discontinuity
    discontCell* cell = new discontCell(kmax, 1);
    int method1 = int((sqrt(1+8*kmax)-1)/2);
    //-----------------------------------------------------------------------//

    // Function definitions
    int iMod(int,int);			//better mod function - returns pos numbers
    double Max(double,double);

    //loop over each equation
    for(me=1; me<= meqn; me++)
    {

        //loop over every cell
        for(j=j_start; j<=j_end; j++)
        {
            for(int n=1; n<= mpoints1d; n++)
            {

                speedx = u1.get(j,n);
                num_cell_shift = (int)( floor(speedx*dt/dx) );

                //location of where discontinuity occurs in cell indexed by (1,1)
                xcut = (x1c-dx/2.0) + (-dx*num_cell_shift + speedx*dt);

                //location of discontinuity (in [-1,1])
                scutx = 2.0/dx*(xcut-x1c);
                if( fabs(scutx -1) < 1.0e-15 )
                {
                    scutx = -1.0;
                    num_cell_shift++;
                }

                scut.set(n,scutx);
            }

            cell->setScut(scut);
            for(i=1; i<=mx; i++)
            {
                for(int n=1; n<= mpoints1d; n++)
                {

                    speedx = u1.get(j,n);
                    num_cell_shift = (int)( floor(speedx*dt/dx) );

                    //location of where discontinuity occurs in cell indexed by (1,1)
                    xcut = (x1c-dx/2.0) + (-dx*num_cell_shift + speedx*dt);

                    //location of discontinuity (in [-1,1])
                    scutx = 2.0/dx*(xcut-x1c);
                    if( fabs(scutx -1) < 1.0e-15 )
                    {
                        scutx = -1.0;
                        num_cell_shift++;
                    }

                    scut.set(n,scutx);


                    /////////////////////////////////////////////////////
                    // Set ql and qr
                    /////////////////////////////////////////////////////
                    //io = 'old' cell that provides data for current cell i
                    io = (int)(i - num_cell_shift);

                    //periodic boundary conditions enforced here
                    io = iMod((io-1),mx) + 1;	

                    for(k= 1; k<=kmax; k++)
                    {

                        qright.set(n, k, qold.get(io, j, me, k) );
                        if( io - 1 == 0)
                        {
                            qleft.set(n, k, qold.get(mx, j, me, k) );
                        }else
                        {
                            qleft.set(n, k, qold.get(io-1, j, me, k) );
                        }
                    }//end of loop over each polynomial

                }

                //create a discontinuous cell and project onto legendre basis
                cell->project(qleft, qright, qcell);

                //save legendre weights into qnew
                for(k=1; k<=kmax; k++)
                {
                    qnew.set(i,j, me, k, qcell.get(k));
                }

            }
        }

    }//end of loop over each eqn	

}// end of function StepAdvecConstCoeff.cpp