예제 #1
0
void Margolus::Calculation(cuint& dx, cuint& dy, cuint& dz) {
//#pragma omp parallel for
    for (uint ix = dx; ix < GetSizeX() - 1; ix += 2) {
        for (uint iy = dy; iy < GetSizeY() - 1; iy += 2) {
            for (uint iz = dz; iz < GetSizeZ() - 1; iz += 2) {
                if (CheckEmpty(ix, iy, iz)) {
                    continue;
                }
                blockSize3D = 1;
                CreateRotateNotBlock3D(blocks3D[0], ix, iy, iz);
                if (modifierMove && CheckMod(ix, iy, iz)) {
                    if (CheckActive (ix, iy)) {
                        if (CheckCanRotate3D(ClockWiceX, ix, iy, iz)) {
                            CreateRotateBlock3D(blocks3D[blockSize3D], ClockWiceX, ix, iy, iz, false, true);
                            ++blockSize3D;
                            CreateRotateBlock3D(blocks3D[blockSize3D], ClockWiceX, ix, iy, iz, true, true);
                            ++blockSize3D;
                            CreateRotateBlock3D(blocks3D[blockSize3D], ClockWiceX, ix, iy, iz);
                            ++blockSize3D;
                        }
                        if (CheckCanRotate3D(CounterClockWiceX, ix, iy, iz)) {
                            CreateRotateBlock3D(blocks3D[blockSize3D], CounterClockWiceX, ix, iy, iz, false, true);
                            ++blockSize3D;
                            CreateRotateBlock3D(blocks3D[blockSize3D], CounterClockWiceX, ix, iy, iz, true, true);
                            ++blockSize3D;
                            CreateRotateBlock3D(blocks3D[blockSize3D], CounterClockWiceX, ix, iy, iz);
                            ++blockSize3D;
                        }
                        if (CheckCanRotate3D(ClockWiceY, ix, iy, iz)) {
                            CreateRotateBlock3D(blocks3D[blockSize3D], ClockWiceY, ix, iy, iz, false, true);
                            ++blockSize3D;
                            CreateRotateBlock3D(blocks3D[blockSize3D], ClockWiceY, ix, iy, iz, true, true);
                            ++blockSize3D;
                            CreateRotateBlock3D(blocks3D[blockSize3D], ClockWiceY, ix, iy, iz);
                            ++blockSize3D;
                        }
                        if (CheckCanRotate3D(CounterClockWiceY, ix, iy, iz)) {
                            CreateRotateBlock3D(blocks3D[blockSize3D], CounterClockWiceY, ix, iy, iz, false, true);
                            ++blockSize3D;
                            CreateRotateBlock3D(blocks3D[blockSize3D], CounterClockWiceY, ix, iy, iz, true, true);
                            ++blockSize3D;
                            CreateRotateBlock3D(blocks3D[blockSize3D], CounterClockWiceY, ix, iy, iz);
                            ++blockSize3D;
                        }
                        if (CheckCanRotate3D(ClockWiceZ, ix, iy, iz)) {
                            CreateRotateBlock3D(blocks3D[blockSize3D], ClockWiceZ, ix, iy, iz, false, true);
                            ++blockSize3D;
                            CreateRotateBlock3D(blocks3D[blockSize3D], ClockWiceZ, ix, iy, iz, true, true);
                            ++blockSize3D;
                            CreateRotateBlock3D(blocks3D[blockSize3D], ClockWiceZ, ix, iy, iz);
                            ++blockSize3D;
                        }
                        if (CheckCanRotate3D(CounterClockWiceZ, ix, iy, iz)) {
                            CreateRotateBlock3D(blocks3D[blockSize3D], CounterClockWiceZ, ix, iy, iz, false, true);
                            ++blockSize3D;
                            CreateRotateBlock3D(blocks3D[blockSize3D], CounterClockWiceZ, ix, iy, iz, true, true);
                            ++blockSize3D;
                            CreateRotateBlock3D(blocks3D[blockSize3D], CounterClockWiceZ, ix, iy, iz);
                            ++blockSize3D;
                        }
                    } else {
                        CreateRotateBlock3D(blocks3D[blockSize3D], ClockWiceX, ix, iy, iz, false, true);
                        ++blockSize3D;
                        CreateRotateBlock3D(blocks3D[blockSize3D], CounterClockWiceX, ix, iy, iz, false, true);
                        ++blockSize3D;
                        CreateRotateBlock3D(blocks3D[blockSize3D], ClockWiceY, ix, iy, iz, false, true);
                        ++blockSize3D;
                        CreateRotateBlock3D(blocks3D[blockSize3D], CounterClockWiceY, ix, iy, iz, false, true);
                        ++blockSize3D;
                        CreateRotateBlock3D(blocks3D[blockSize3D], ClockWiceZ, ix, iy, iz, false, true);
                        ++blockSize3D;
                        CreateRotateBlock3D(blocks3D[blockSize3D], CounterClockWiceZ, ix, iy, iz, false, true);
                        ++blockSize3D;
                    }
                } else {
                    if (CheckCanRotate3D(ClockWiceX, ix, iy, iz)) {
                        CreateRotateBlock3D(blocks3D[blockSize3D], ClockWiceX, ix, iy, iz);
                        ++blockSize3D;
                    }
                    if (CheckCanRotate3D(CounterClockWiceX, ix, iy, iz)) {
                        CreateRotateBlock3D(blocks3D[blockSize3D], CounterClockWiceX, ix, iy, iz);
                        ++blockSize3D;
                    }
                    if (CheckCanRotate3D(ClockWiceY, ix, iy, iz)) {
                        CreateRotateBlock3D(blocks3D[blockSize3D], ClockWiceY, ix, iy, iz);
                        ++blockSize3D;
                    }
                    if (CheckCanRotate3D(CounterClockWiceY, ix, iy, iz)) {
                        CreateRotateBlock3D(blocks3D[blockSize3D], CounterClockWiceY, ix, iy, iz);
                        ++blockSize3D;
                    }
                    if (CheckCanRotate3D(ClockWiceZ, ix, iy, iz)) {
                        CreateRotateBlock3D(blocks3D[blockSize3D], ClockWiceZ, ix, iy, iz);
                        ++blockSize3D;
                    }
                    if (CheckCanRotate3D(CounterClockWiceZ, ix, iy, iz)) {
                        CreateRotateBlock3D(blocks3D[blockSize3D], CounterClockWiceZ, ix, iy, iz);
                        ++blockSize3D;
                    }
                }
                double Z = 0.0;
                // + Energy
                for (uint i = 0; i < blockSize3D; ++i) {
                    double energy = CalculationBlockEnergy(blocks3D[i], ix, iy, iz); //кДж/моль
                    blocks3D[i].energy = exp(-energy / (R * *T));
                    Z += blocks3D[i].energy;
                }
                //normalization
                double sumProbability = 0.0;
                double rnd = (double)(rand()) / RAND_MAX;
                for (uint i = 0; i < blockSize3D; ++i) {
                    sumProbability += blocks3D[i].energy / Z;
                    if (rnd <= sumProbability) {
                        ChangeBlock(blocks3D[i], ix, iy, iz);
                        break;
                    }
                }
            }
        }
    }
}
int WindowLister( int x,
                  int y,
                  int xx,
                  int yy,
                  int CharToExitOn,
                  int *NumItems,
                  int NumToStartWith,
				  int (*CharHandler)(int ch, int Index),
                  void (*ScreenClearer)( void ),
                  void (*DisplayLineFunction)(int Index) )
{
    register int i;
    register int CurrLine = 0;
    int PrevLine;
    int NumLines = yy - y;
    int Top = NumToStartWith;
    int OldTop;
    int RefreshScreen = 1;
    int ch;
    union REGS regs, regs2;
    int Index;

    regs.x.cx = ( (y-1) << 8 ) + x-1;
    regs.x.dx = ( (yy-1) << 8 ) + xx-1;
    regs.x.ax = 0;
    regs.h.bh = A_NORMAL;
    regs.h.ah = 0x06;
    regs.x.ax = 1;

    for (;;) {

        if ( RefreshScreen ) {
            ScreenClearer();
            ChangeBlock( x, y, xx, yy, A_NORMAL );
            RefreshScreen = 0;
            PrevLine = 500;
            OldTop = -500;
            for (i=0; i<=NumLines; ++i) {
                gotoxy( x, i+y );
                if ( i+Top <= *NumItems )
                    DisplayLineFunction( i+Top );
            }
        }

        Index = CurrLine + Top;

        if ( PrevLine != CurrLine || OldTop != Top ) {
			SetAttrib( A_REVERSE );
            gotoxy( x, y + CurrLine );
            DisplayLineFunction( Index );
			SetAttrib( A_NORMAL );
        }
        HideCursor();

        PrevLine = CurrLine;
        OldTop = Top;

        ch = GComm();
        if ( ch == CharToExitOn ) return( Index );

        switch( ch ) {

			case ESC:
				return( -1 );

			case DOWN:
                CurrLine++;
                if (CurrLine > NumLines) {
                    CurrLine = NumLines;
                    if ( Top < *NumItems - NumLines ) {
                        Top++;
                           ChangeBlock( x, y, xx, yy, A_NORMAL );
                        regs.h.ah = 0x06;
                        int86( 0x10, &regs, &regs2 );
                        gotoxy( x, yy );
                    }
                }
                break;

            case UP:
                CurrLine--;
                if (CurrLine < 0) {
                    CurrLine=0;
                    if ( Top > 0 ) {
                        Top--;
                           ChangeBlock( x, yy, xx, yy, A_NORMAL );
                        regs.h.ah = 7;
                        int86( 0x10, &regs, &regs2 );
                        gotoxy( x, y );
                    }
                }
                break;

            case END:
                Top = *NumItems - NumLines;
                if ( Top < 0 ) {
                    Top = 0;
                }
                CurrLine = NumLines;
                if ( CurrLine > *NumItems ) {
                    CurrLine = *NumItems;
                }
                RefreshScreen++;
                break;

            case PGDN:
                Top += NumLines;
                if (Top > *NumItems - NumLines) {
                    Top = *NumItems - NumLines;
                    if ( Top < 0 )
                        Top = 0;
                    CurrLine = NumLines;
                    if ( CurrLine > *NumItems ) {
                        CurrLine = *NumItems;
                    }
                }
                RefreshScreen++;
                break;

            case PGUP:
                Top -= NumLines;
                if (Top < 0) {
                    Top = 0;
                    CurrLine = 0;
                }
                RefreshScreen++;
                break;

            case HOME:
                Top = CurrLine = 0;
                RefreshScreen++;
                break;

            default:
                gotoxy( x, CurrLine + y );
                ReverseText();
                DisplayLineFunction( Index );
                NormalText();
				/*HideCursor();*/
                RefreshScreen++;
				CurrLine = CharHandler( ch, Index );
				RefreshScreen = 1;
				if ( CurrLine - Top <= NumLines && CurrLine - Top >= 0 )
					CurrLine -= Top;
				else {
					Top = CurrLine - 1;
					CurrLine = 1;
					if ( Top < 0 ) {
						Top = CurrLine = 0;
					}
                }
                break;

        }
        if ( Top < 0 ) {
            Top = 0;
            CurrLine = 0;
        }
        if ( Top + CurrLine > *NumItems ) {
            CurrLine = *NumItems - Top;
        }
        if ( PrevLine != CurrLine || Top != OldTop ) {
            ChangeBlock( x, y, xx, yy, A_NORMAL );
        }
        if ( RefreshScreen > 1 ) {
            Top = CurrLine = 0;
        }
    }
}