コード例 #1
0
ファイル: LIFE.C プロジェクト: k0gaMSX/legacy
/* display the current generation */
display()
{
	int i,j,k,j9;
        char c;

        if(minx && prow(minx-1)) minx--;
        if(miny && pcol(miny-1)) miny--;
	if ((maxx < (XSIZE-1)) && prow(maxx+1)) maxx++;
        if((maxy<(YSIZE-1)) && pcol(maxy+1))maxy++;
        
        while (!prow(minx)) minx++;
        while (!prow(maxx)) maxx--;
        while (!pcol(miny)) miny++;
        while (!pcol(maxy)) maxy--;

	printf("\n\ngeneration = %1d   population = %1d  ",
		gen,pop);
        ++gen;

        putchar('\n');

	j9 = maxy - miny + 1;
        for (i = minx; i<=maxx; i++) {
                if (CENTER && j9<WIDTH)
                        for (k=0; k<(WIDTH-j9)/2; k++) putchar(' ');
                for (j=miny; j<=maxy; j++) {
                        switch(cell[i][j]) {
				case 1: cell[i][j] = 2;
                                case 2: putchar('*');
                                        break;
                                case 3: cell[i][j] = 0;
                                case 0: putchar(' ');
                        }
                }
		if (i != maxx) putchar('\n');
        }
}
コード例 #2
0
ファイル: databasegraph_example.C プロジェクト: 8l/rose
//-----------------------------------------------------------------------------
int main(int argc, char *argv[]) {

	GlobalDatabaseConnection db;
	int initOk =  db.initialize();
	assert( initOk==0 );

	CREATE_TABLE(db, projects);
	CREATE_TABLE(db, files);
	CREATE_TABLE(db, graphdata);
	CREATE_TABLE(db, graphnode);
	CREATE_TABLE(db, graphedge);

	TableAccess< testtableRowdata > testtable( &db );
	testtable.initialize();

	// initialize project
	string projectName = "testProject";  // this should be given at the command line
	string fileName    = "testFile.C";   // this should be retrieved from a SgFile node

	projectsRowdata prow( UNKNOWNID ,projectName, UNKNOWNID );
	projects.retrieveCreateByColumn( &prow, "name", 
			projectName );
	long projectId 	= prow.get_id();

	// get id of this file
	filesRowdata frow( UNKNOWNID, projectId , fileName );
	files.retrieveCreateByColumn( &frow, "fileName", 
			fileName, frow.get_projectId() );
	long fileId	= frow.get_id();

	// init graph
	DatabaseGraph<testtableRowdata, EdgeTypeEmpty> *graph = 
		new DatabaseGraph<testtableRowdata, EdgeTypeEmpty>( projectId, GTYPE_TESTGRAPH, &db );
	graph->loadFromDatabase( );

	// the graph is now ready for use...
	// add some example nodes and edges

	testtableRowdata testrow1( UNKNOWNID, "dgb_exrow1", 0.1 );
	ostringstream whereClause;
	whereClause << " graphId='" << graph->getGraphId() <<"' ";
	vector<graphnodeRowdata> result = graphnode.select( whereClause.str() );
	if(result.size() > 0) {
		// select a random node from the graph
		int index = rand() % result.size();
		// the node will be identified by the id, so the other fields
		// dont have to be inited correctly
		testrow1.set_id( result[index].get_nodeId() );
	} else {
		// there are no nodes yet, create a new root node
		testtable.insert( &testrow1 );
		graph->insert( testrow1, testrow1.get_name() );
	}

	// add three other nodes...
	testtableRowdata testrow2( UNKNOWNID, "dgb_exrow2", 0.2 );
	testtable.insert( &testrow2 );
	testtableRowdata testrow3( UNKNOWNID, "dgb_exrow3", 0.3 );
	testtable.insert( &testrow3 );
	testtableRowdata testrow4( UNKNOWNID, "dgb_exrow4", 0.4 );
	testtable.insert( &testrow4 );

	graph->insert( testrow2, testrow2.get_name() );
	graph->insert( testrow3, testrow3.get_name() );
	graph->insert( testrow4, testrow4.get_name() );

	// and edges to them from the first node
	graph->insert( testrow1, testrow2 );
	graph->insert( testrow1, testrow3 );
	graph->insert( testrow1, testrow4 );

	// save graph to dot file, and to database
	graph->writeToDOTFile( "databasegraph_example.dot" );
	graph->writeToDatabase( );
	delete graph;

	db.shutdown();
	return( 0 );
}
コード例 #3
0
ファイル: Moperator.c プロジェクト: xdavidliu/saltpp
void Geometry::MoperatorGeneralBlochFill(Mat A, int b[3][2], int DimPeriod, double k[3], int ih){


	int N[3];
	for(int i=0; i<3; i++) N[i] = gN.x(i);

	double blochbc[3];
	for(int i=0; i<3; i++) blochbc[i] = k[i]*N[i]*h[i];

	int NC = 3, offset = ih*(Nxyzcr()+2);
	int ns, ne;
	double hh;

	int bc[3][2][3]; /* bc[x/y/z direction][lo/hi][Ex/Ey/Ez] */

	dcomp val, magicnum, mucp[2], mulcp[2];
	dcomp cidu_phase, cpidu_phase[2], cpidl_phase[2];



 
  /* set up b ... */
 
	for(int ic=0; ic<3; ic++) for(int j=0; j<2; j++) for(int k=0; k<3; k++)
		bc[ic][j][k] =  b[ic][j]*( k==ic ? -1 :1);

	
	MatGetOwnershipRange(A, &ns, &ne);

for (int itrue = ns; itrue < ne && itrue < 2*Nxyzc(); ++itrue) {

	Point p(itrue, Grid(N, Nc, 2)); p.project(3); int i = p.xyzcr();
	int cp[2], icp[2], cidu, cpidu[2],cpidl[2], cid, cpid[2];
	for(int j=0; j<2;j++){

		cp[j] = (p.c()+1+j) % NC;
		icp[j] = i + (cp[j]-p.c() ) *Nxyz();
		cpidu[j] = cyclic(p, 2-j, N);
		cpidl[j] = cyclic(p, 2-j, N);
		cpid[j] = cyclic(p, 2-j, N);

		cpidu_phase[j] = 1.0;
		cpidl_phase[j] = 1.0;
	}	  
	cidu = cyclic(p, 0, N);
	cid = cyclic(p, 0, N);

	cidu_phase = 1.0;
    
   for(int jr=0; jr<2; jr++) { /* column real/imag parts */
   	int jrd =  (jr-p.r())*NC*Nxyz();            
   	magicnum = (p.r()==jr)*1.0 + (p.r()<jr)*1.0*ComplexI - (p.r()>jr)*1.0* ComplexI; 

//=====================================================================
	Point prow(i, Grid(N,3,2)); prow.project(Nc);
for(int ib=0; ib<2; ib++){


	if(p.x(p.c()) == N[p.c()]-1){
		int per = periodic(p.c(), DimPeriod );
		cidu = per ? (1-N[p.c()])*cid : 0;
		cidu_phase = per? std::exp(ComplexI*blochbc[p.c()]) : bc[p.c()][1][cp[ib]];
	}

	if(p.x(cp[ib]) == 0){
		int per = periodic(cp[ib], DimPeriod );
		cpidl[ib] = per ? (1-N[cp[ib]])*cpid[ib] : 0;
		cpidl_phase[ib] = per ? std::exp(-ComplexI*blochbc[cp[ib]]) : bc[cp[ib]][0][cp[ib]];
	}

        mucp[1-ib] = pmlval(icp[1-ib], N, Npml, h, LowerPML, 1);
      	mulcp[1-ib] = pmlval(icp[1-ib]-cpidl[ib], N, Npml, h, LowerPML, 1);


	double c[4];
        hh = h[p.c()]*h[cp[ib]];
	val = mucp[1-ib] * magicnum /hh; c[1] = val.real();
	val *= cidu_phase; c[0] = -val.real();
	val = cpidl_phase[ib] * mulcp[1-ib] * magicnum/hh; c[3] = -val.real();
	val *= -cidu_phase; c[2] = -val.real();
      

	int dcol[4];
	dcol[0] = cidu; 
	dcol[1] = 0;
	dcol[2] = cidu-cpidl[ib];
	dcol[3] = -cpidl[ib];



	for(int w=0;w<4;w++){
	Point pcol(icp[ib] + jrd+dcol[w], Grid(N,3,2) );
	pcol.project(Nc);	
	if(pcol.c()!=-1) MatSetValue(A, prow.xyzcr()+offset, pcol.xyzcr()+offset, c[w], ADD_VALUES);
	}


	if(p.x(cp[ib]) == N[cp[ib]]-1){
		int per = periodic(cp[ib], DimPeriod );
		cpidu[ib] = per ? (1-N[cp[ib]])*cpid[ib] : 0;
		cpidu_phase[ib] = per? std::exp(ComplexI*blochbc[cp[ib]]) : bc[cp[ib]][1][p.c()];
	}

	if(p.x(cp[ib]) == 0){
		int per = periodic(cp[ib], DimPeriod );
		cpidl[ib] = per ? (1-N[cp[ib]])*cpid[ib] : -cpidu[ib];
		cpidl_phase[ib] = per? std::exp(-ComplexI*blochbc[cp[ib]]) : bc[cp[ib]][0][p.c()];
	}   

     
	hh =  h[cp[ib]]*h[cp[ib]];
	val = -(cpidu_phase[ib] * mucp[1-ib] * magicnum)/hh; c[0] = -val.real();
	val = +( (mucp[1-ib] + mulcp[1-ib]) * magicnum)/hh;c[1] = -val.real();
	val = -(cpidl_phase[ib] * mulcp[1-ib] * magicnum)/hh;c[2] = -val.real();
     
 
	dcol[0] = cpidu[ib]; 
	dcol[1] = 0;
	dcol[2] = -cpidl[ib];

	for(int w=0;w<3;w++){
	Point pcol(i + jrd+dcol[w], Grid(N,3,2) );
	pcol.project(Nc);
	if(pcol.c()!=-1) MatSetValue(A, prow.xyzcr()+offset, pcol.xyzcr()+offset, c[w], ADD_VALUES);
	}

}


    }
  }
}