Esempio n. 1
0
void checkT(int i1, int j1)
{
    if((i1-1)>=0 && flag[i1-1][j1]=='f' && temp[i1-1][j1]=='T')
    {
        flag[i1-1][j1]='t';
        noT++;
        checkT(i1-1, j1);
    }
    if((i1+1)<m && flag[i1+1][j1]=='f' && temp[i1+1][j1]=='T')
    {
        flag[i1+1][j1]='t';
        noT++;
        checkT(i1+1, j1);
    }
    if((j1-1)>=0 && flag[i1][j1-1]=='f' && temp[i1][j1-1]=='T')
    {
        flag[i1][j1-1]='t';
        noT++;
        checkT(i1, j1-1);
    }
    if((j1+1)<n && flag[i1][j1+1]=='f' && temp[i1][j1+1]=='T')
    {
        flag[i1][j1+1]='t';
        noT++;
        checkT(i1, j1+1);
    }
}
Esempio n. 2
0
void XC::YieldSurface_BC::toElementSystem(XC::Vector &eleVector, double &x, double &y,
                                     bool dimensionalize, bool signMult)
{
    if(!T)
    {
        checkT();
        return;
    }

#ifdef _G3DEBUG
    if(T->Size() != 2)
    {
        std::cerr << "WARNING: XC::YieldSurface_BC::toElementSystem (XC::Vector &eleVector, .. \n";
        std::cerr << "T size may not be correct\n";
    }
#endif

double x1 = x, y1 = y;
	if(dimensionalize)
	{
		x1 = x*capX;
		y1 = y*capY;
	}
	if(signMult==false)
	{
		eleVector((*T)(0)) = x1;
		eleVector((*T)(1)) = y1;
	}
	else
	{
    	eleVector((*T)(0)) = x1*((*S)(0));
    	eleVector((*T)(1)) = y1*((*S)(1));
	}

}
Esempio n. 3
0
void XC::YieldSurface_BC::toLocalSystem (XC::Matrix &eleMatrix, double &x, bool nonDimensionalize, bool signMult)
{
    if(!T)
    {
        checkT();
        return;
    }

#ifdef _G3DEBUG
    if(T->Size() != 1)
    {
        std::cerr << "WARNING: XC::YieldSurface_BC::toLocalSystem (XC::Matrix &eleMatrix, double &x)\n";
        std::cerr << "T size may not be correct\n";
    }
    if(eleMatrix.noCols() !=1)
    {
        std::cerr << "WARNING: XC::YieldSurface_BC::toLocalSystem (XC::Matrix &eleMatrix, ..)\n";
        std::cerr << "XC::Matrix columns should be = 1\n";
    }
#endif

	if(signMult==false)
	{
		x = eleMatrix((*T)(0),0);
	}
	else
	{
    	x = eleMatrix((*T)(0), 0)*((*S)(0));
	}
	if (nonDimensionalize)
	{
		x = x/capX;
	}
}
Esempio n. 4
0
void XC::YieldSurface_BC::toLocalSystem (XC::Vector &eleVector, double &x, double &y,
                                    bool nonDimensionalize, bool signMult)
{
    if(!T)
    {
        checkT();
        return;
    }

#ifdef _G3DEBUG
    if(T->Size() != 2)
    {
        std::cerr << "WARNING: XC::YieldSurface_BC::toLocalSystem (XC::Vector &eleVector, double &x, double &y)\n";
        std::cerr << "T size may not be correct\n";
    }
#endif

	if(signMult==false)
	{
		x = eleVector((*T)(0));
		y = eleVector((*T)(1));
	}
	else
	{
    	x = eleVector((*T)(0))*((*S)(0));
    	y = eleVector((*T)(1))*((*S)(1));
	}

	if (nonDimensionalize)
	{
		x = x/capX;
		y = y/capY;
	}
}
Esempio n. 5
0
void initializeTrie(Tree *codeTrie) {
    for (int i = 0; i < 256; i++) {
        int *singleChar = malloc(2 * sizeof(int));
        singleChar[0] = i;
        singleChar[1] = -1;
        int foundCode[1];
        int wasPruned[1];
        checkT(codeTrie, singleChar, wasPruned, foundCode);
        free(singleChar);
    }
}
Esempio n. 6
0
int connected()
{
    int i1=0, j1=0;
    noT=noD=0;
    nflag=0;
    for(i1=0; i1<m; i1++)
    {
        for(j1=0; j1<n; j1++)
        {
            if(temp[i1][j1]=='T')
            {
                nflag=1;
                break;
            }
        }
        if(nflag)
            break;
    }
    //printf("ti1=%d j1=%d\n", i1, j1);
    nflag=0;
    if(temp[i1][j1]=='T')
    {
        reset();
        flag[i1][j1]='t';
        noT++;
        checkT(i1, j1);
    }
    for(i1=0; i1<m; i1++)
    {
        for(j1=0; j1<n; j1++)
        {
            if(temp[i1][j1]=='D')
            {
                nflag=1;
                break;
            }
        }
        if(nflag)
            break;
    }
    //printf("di1=%d j1=%d\n", i1, j1);
    if(temp[i1][j1]=='D')
    {
        reset();
        flag[i1][j1]='t';
        noD++;
        checkD(i1, j1);
    }
    if(noT==countT && noD==countD)
        return 1;
    else
        return 0;
}
const Foam::radiation::absorptionCoeffs::coeffArray&
Foam::radiation::absorptionCoeffs::coeffs
(
    const scalar T
) const
{
    checkT(T);

    if (T < Tcommon_)
    {
        return lowACoeffs_;
    }
    else
    {
        return highACoeffs_;
    }
}
Esempio n. 8
0
int getLargestSequence (int firstChar, Tree *codeTrie){
    int c = firstChar;
    int *buildSequence = malloc(sizeof(int));
    buildSequence[0] = -1;
    int foundCode[1];
    int wasPruned[1];
    *wasPruned = 0;
    int atEnd = 0;
    buildSequence = addLetterToString (buildSequence, c);
    while (checkT(codeTrie, buildSequence, wasPruned, foundCode)) {
        c = getchar();
        if (c == EOF) {
            atEnd = 1;
            break;
        }
        buildSequence = addLetterToString (buildSequence, c);
    }
    if (Escaped) {
        if (*wasPruned == 2){
            putBits(LastBitsCount, 0);
            putBits(8, buildSequence[0]);
            c = getchar();
            free(buildSequence);
            return c;
        }
    }
    free(buildSequence);
    putBits(LastBitsCount, *foundCode);
    if (*wasPruned == 1){
        if (!atEnd) {
            if (Escaped) {
                putBits(LastBitsCount, 0);
                putBits(8, c);
                c = getchar();
            }
            else {
                putBits(LastBitsCount, c);
            }
        }
    }
    LastBitsCount = getBitsCount();
    return c;
}
Esempio n. 9
0
void XC::YieldSurface_BC::toElementSystem(XC::Matrix &eleMatrix, double &x, double &y, double &z,
                                     bool dimensionalize, bool signMult)
{
    if(!T)
    {
        checkT();
        return;
    }

#ifdef _G3DEBUG
    if(T->Size() != 3)
    {
        std::cerr << "WARNING: XC::YieldSurface_BC::toElementSystem (XC::Matrix &eleMatrix, .. \n";
        std::cerr << "T size may not be correct\n";
    }
    if(eleMatrix.noCols() != 1)
    {
        std::cerr << "WARNING: XC::YieldSurface_BC::toElementSystem (XC::Matrix &eleMatrix, .. \n";
        std::cerr << "eleMatrix columns not equal to 1\n";
    }
#endif

double x1 = x, y1 = y, z1 = z;
	if(dimensionalize)
	{
		x1 = x*capX;
		y1 = y*capY;
		z1 = z*capZ;
	}
	if(signMult==false)
	{
		eleMatrix((*T)(0),0) = x1;
		eleMatrix((*T)(1),0) = y1;
		eleMatrix((*T)(2),0) = z1;
	}
	else
	{
		eleMatrix((*T)(0),0) = x1*((*S)(0));
    	eleMatrix((*T)(1),0) = y1*((*S)(1));
    	eleMatrix((*T)(2),0) = z1*((*S)(2));
	}

}
Esempio n. 10
0
int insertString (int possition, Tree *codeTrie, int *string, int *lastPos) {
    int possitionCopy = possition;
    int *buildSequence = malloc(sizeof(int));
    buildSequence[0] = -1;
    int c = string[possition];
    buildSequence = addLetterToString (buildSequence, c);
    int *foundCode = malloc(sizeof(int));
    int wasPruned[1];
    *wasPruned = 0;
    int isEnd = 0;
    while (checkT(codeTrie, buildSequence, wasPruned, foundCode)) {
        possition ++;
        c = string[possition];
        if (c == -1) {
            isEnd = 1;
            break;
        }
        buildSequence = addLetterToString (buildSequence, c);
    }
    if (*wasPruned == 2) {
        int newPossition = possition + 1;
        possition ++;
        lastPos[0] = newPossition;
    }
    else if (isEnd){
        lastPos[0] = possitionCopy;
    }
    else if (*wasPruned == 1) {
        return -1;
    }
    else {
        lastPos[0] = possition;
    }
    free(buildSequence);
    free(foundCode);
    return possition;
}
Esempio n. 11
0
 Real GsrProcess::y(Time t) const {
     checkT(t);
     return core_.y(t);
 }
Esempio n. 12
0
 Real GsrProcess::variance(Time w, Real, Time dt) const {
     checkT(w + dt);
     return core_.variance(w,dt);
 }
Esempio n. 13
0
 Real GsrProcess::expectation(Time w, Real xw, Time dt) const {
     checkT(w + dt);
     return core_.expectation_x0dep_part(w, xw, dt) +
            core_.expectation_rn_part(w, dt) +
            core_.expectation_tf_part(w, dt);
 }
Esempio n. 14
0
 Real GsrProcess::diffusion(Time t, Real) const {
     checkT(t);
     return sigma(t);
 }
Esempio n. 15
0
/// Check validity of temperature, pressure and composition input.
bool IncompressibleSolution::checkTPX(double T, double p, double x) {
	return (checkT(T,p,x) && checkP(T,p,x) && checkX(x));
}
Esempio n. 16
0
void mkTest() {

	printf(" Seller\n");
	srand(0);
	Seller *s;
	s = createSeller(HIGH, 1);
	assert(checkT(s->price==HIGH,"Seller is HIGH"));
	assert(checkT(s->que==NULL,"Seller starts with empty que"));
	assert(checkN(s->lastRow,1,"HIGH seller starts in row 1"));
	free(s);
	s = createSeller(MEDIUM, 1);
	assert(checkN(s->lastRow,5,"MEDIUM seller starts in row 5"));
	free(s);
	s = createSeller(LOW, 1);
	assert(checkN(s->lastRow,10,"LOW seller starts in row 10"));

	printf(" Person\n");
	Person *p = createPerson(s);
	assert(checkN(p->arrival,43,"p->arrival"));
	assert(checkT(s==p->seller,"checkT"));
	assert(checkT((p->next==p->prev) && (p->prev==p),"p is self referential"));

	// add person to seller
	//   we need 4 people to test que management
	//   for our testing set arrival to 0 and do not thread
	printf(" Add Person\n");
	int i;
	for(i=0; i<4;i++) {
		p=createPerson(s);
		p->arrival = 0;
		addPerson(p);
	}
	assert(checkN(s->que->id,1,"First customer id"));
	assert(checkN(s->que->next->id,2,"Second customer id"));
	assert(checkN(s->que->next->next->id,3,"Third customer id"));
	assert(checkN(s->que->next->next->next->id,4,"Fourth/Last customer id"));
	assert(checkN(s->que->next->next->next->next->id,4,"Fifth customer id (tail points to self"));

	assert(checkT(s->que->inQ==TRUE,"First customer id"));
	assert(checkT(s->que->next->inQ==TRUE,"Second customer id"));
	assert(checkT(s->que->next->next->inQ==TRUE,"Third customer id"));
	assert(checkT(s->que->next->next->next->inQ==TRUE,"Fourth/Last customer id"));

	printf(" Remove Person\n");
	// test removals
	p = removePerson(s->que);// remove person 1
	assert(checkN(p->id,1,"First person on que removed"));
	assert(checkN(s->que->id,2,"First person on que now number 2"));

	p = removePerson(s->que->next); // remove person 3
	assert(checkN(p->id,3,"Second(middle) person on que removed"));
	assert(checkN(s->que->id,2,"First person on que now number 2"));
	assert(checkN(s->que->next->id,4,"Second person should now be #4"));

	p = removePerson(s->que->next); // remove person 4
	assert(checkN(p->id,4,"Second(tail) person on que removed"));
	assert(checkN(s->que->id,2,"First person on que now number 2"));
	assert(checkN(s->que->id,s->que->next->id,"Only one person left on que #2"));
	assert(checkT((p->next==p->prev) && (p->prev==p),"p(2) is self referential"));

	p = removePerson(s->que);// remove person 2 (single person left)
	assert(checkN(p->id,2,"Last person on que removed"));
	assert(checkT(s->que==NULL,"Seller que now empty"));

	p = removePerson(s->que);// remove person from empty que
	assert(checkT(p==NULL,"NULL pointer expected"));

	//
	printf(" getSeat()\n");
	p=createPerson(s); // current low price seller
	p->id = 42;
	// check if row full algorithm even works
	assert(checkT(!isRowFull(&hall,8),"Is row 8 full NO"));

	printf("   LOW\n");
	getSeat(&hall,p,LOW);
	// first call to low assigns 10,10
	Person *cp = hall.seats[10][10];
	assert(checkT(cp!=NULL,"Seat 10,10 occupied"));
	assert(checkN(cp->id,42,"Customer 42 has the seat"));

	printf("   HIGH\n");
	p->seller->lastRow=1;
	getSeat(&hall,p,HIGH);
	// first call to low assigns 1,1
	cp = hall.seats[1][1];
	assert(checkT(cp!=NULL,"Seat 1,1 occupied"));
	assert(checkN(cp->id,42,"Customer 42 has the seat"));

	printf("   MEDIUM\n");
	p->seller->lastRow=5;
	getSeat(&hall,p,MEDIUM);
	// first call to low assigns 5,10
	cp = hall.seats[5][10];
	assert(checkT(cp!=NULL,"Seat 5,10 occupied"));
	assert(checkN(cp->id,42,"Customer 42 has the seat"));

	p->seller->lastRow=3;
	getSeat(&hall,p,MEDIUM);
	// first call to low assigns 3,10
	cp = hall.seats[3][10];
	assert(checkT(cp!=NULL,"Seat 3,10 occupied"));
	assert(checkN(cp->id,42,"Customer 42 has the seat"));

	p->seller->lastRow=6;
	getSeat(&hall,p,MEDIUM);
	// first call to low assigns 6,1
	cp = hall.seats[6][1];
	assert(checkT(cp!=NULL,"Seat 6,1 occupied"));
	assert(checkN(cp->id,42,"Customer 42 has the seat"));

	// need non-threaded test for sellTickets method


	// non-threaded test for frustratedPerson()

	printf(" frustratedPerson()\n");
	s = createSeller(HIGH,103);
	p=createPerson(s);
	p->arrival=0;
	addPerson(p);
	frustratedPerson(p);
	assert(checkT(s->que==NULL,"Person has left the building"));
}