示例#1
0
void Substrate::initializeCanvas()
{
	m_image.fill(255, 255, 255);

	m_cracks.clear();

	// make random crack seeds
	m_gridData.clear();
	m_gridData.resize(m_image.width()*m_image.height(), GridData(UNCRACKED, UNCRACKED, NO_SHAPE));
	for(uint k = 0; k < m_numInitialCracks; k++) 
	{
		int c = m_image.width()/2; //randInt(0, m_image.width());
		int r = m_image.height()/2; //randInt(0, m_image.height());

		m_crackedPixels.push_back(r*m_image.width() + c);
		m_gridData[r*m_image.width() + c].angle = randInt(0, 360);
		m_gridData[r*m_image.width() + c].objectId = uniqueId();
	}

	// make initial cracks
	m_curvedPercentage = 1.0f;
	for(uint k = 0; k < m_numInitialCracks; ++k)
		makeCrack();

	// no more circles
	m_curvedPercentage = 0.0f;
}
示例#2
0
void Regioner::run(){
	
	//error initialization
	int errcount = 0;
	errout.errorid = 0;

	list<int>::iterator jj ; 
	for ( jj=runchtlist.begin() ; jj!=runchtlist.end(); jj++){
		int chtid = *jj;
		
		// clean-up and re-setup for the next cohort (Yuan: July 13, 2012)
		gd = GridData();
		cd = CohortData();
		ed = EnvData();
		bd = BgcData();
		fd = FirData();
        //rgrid.~Grid();
		//rgrid = Grid();
		//runcht.cht.~Cohort();
		runcht.cht = Cohort();

		bd.setEnvData(&ed);
		rgrid.setEnvData(&ed);
 		rgrid.setRegionData(&rd);
 		rgrid.setGridData(&gd);
 		runcht.cht.setTime(&timer);
 		runcht.cht.setProcessData(&ed, &bd, &fd);
 		runcht.cht.setModelData(&md);
 		runcht.cht.setInputData(&rd, &gd, &cd);
 		runcht.cht.setAtmData(&rgrid);
		if(!md.runeq) {
			runcht.cht.setRegnOutData(&regnod);
		}
 		runcht.cht.setRestartOutData(&resod);
  		runcht.cht.init();

  		// starting run here
		errout.chtid = chtid;
		
		//get the eqchtid, spchtid/trchtid, restart-id, and cruid
		int eqcid = 0;  //the record order in the input files, NOT the cohort ID (chtid)
		int cid = 0;    //the record order in the input files, NOT the cohort ID (chtid)
		int rescid = 0; //the record order in the input files, NOT the cohort ID (chtid)

		try {

			//for regional run, only one of the following can be true;
			if(md.runeq){
				cd.eqchtid = chtid;
				eqcid=cin.getEqRecID(cd.eqchtid);  //needed for cruid searching
				cid=eqcid;                         //
			}

			if(md.runsp){
				cd.spchtid = chtid;
				cid=cin.getSpRecID(cd.spchtid);

				cin.getEqchtid5SpFile(cd.eqchtid, cid);   
				eqcid=cin.getEqRecID(cd.eqchtid);
			
				cd.reschtid = cd.eqchtid;
				if (md.initmode==3) rescid = resin.getRecordId(cd.reschtid);
			}
		
			if(md.runtr){
				cd.trchtid = chtid;			
				cid=cin.getTrRecID(cd.trchtid);
				cin.getSpchtid5TrFile(cd.spchtid, cid); 

				int spcid=cin.getSpRecID(cd.spchtid);
				cin.getEqchtid5SpFile(cd.eqchtid, spcid);
				eqcid=cin.getEqRecID(cd.eqchtid);
			
				if (!md.runsc) {  //Yuan: when md.runsc is true, md.runtr is also true
					cd.reschtid = cd.spchtid;
				} else {
					cd.reschtid = cd.trchtid;  //restart id is of transient-run's, because sc-run is continuouity of tr-run
				}
				if (md.initmode==3) rescid = resin.getRecordId(cd.reschtid);
			}
			
			cin.getGrdID(cd.grdid, eqcid); //(eq/sp/tr)grid-id (for soil): starting from ZERO

			cin.getClmID(cd.clmid, cid);  //Yuan: from cid to get its clmid, SO no more using CRUID as its climate data id

		} catch (Exception &exception){
			errout.errorid = -1;
			errout.outputVariables(errcount);
			errcount+=1;

			if(md.consoledebug){
				cout <<"problem in setting IDs in Regioner::run\n";
				exception.mesg();
			}

		}

		if(cd.grdid>=0 && cid>=0 && eqcid>=0 && rescid>=0){
   			int error = 0;

   			//grid-level data for a cohort
			try {
				int grdrecid = gin.getGridRecID(cd.grdid);
				int clmrecid = gin.getClmRecID(cd.clmid);

				gd.gid=grdrecid;

				gin.getGridData(&gd, grdrecid, clmrecid);

    			error = rgrid.reinit(grdrecid); //reinit for a new grid
    			if (error!=0) {

    				if(md.consoledebug){
    						cout <<"problem in grid data in Regioner::run\n";
    				}

    		    	errout.errorid = -3;
    				errout.outputVariables(errcount);
    				errcount+=1;

    				continue;     //jump over to next cohort, due to grid-data error
    			}
	    	} catch (Exception &exception){
				exception.mesg();
				if(md.consoledebug){
					cout <<"problem in reinitializing grid in Regioner::run\n";
				}

	    		errout.errorid = -3;
				errout.outputVariables(errcount);
				errcount+=1;

				continue;     //jump over to next cohort, due to grid-data error

 	    	}
 
	    	//cohort-level data for a cohort
			runcht.jcalifilein=true;  // for reading Jcalinput.txt, the default is true (must be done before re-initiation)
			runcht.jcalparfile="";
			runcht.ccdriverout=false;  //don't change to true for regioner
				
			error = runcht.reinit(cid, eqcid, rescid); //reinit for a new cohort

			//run a cohort
   			try {
  				if (error!=0) {
   					cout<<"Error for reinitializing cohort: "<<chtid<<" - SKIPPED! \n";

   					errout.errorid = -5;
    				errout.outputVariables(errcount);
    				errcount+=1;

					continue;     //jump over to next cohort, due to cohort reinit error

  				} else {
    				if (md.consoledebug)
    					cout<<"cohort: "<<chtid<<" @ "<<md.runstages
							<<" - running! \n";
    				error = runcht.run();
      				if (error!=0) {
      	    			if(md.consoledebug){
      	    				cout<<"problem in running cohort in Regioner::run \n";
      	    			}

       					rout.missingValues(MAX_OREGN_YR, runcht.cohortcount);

       					errout.errorid = -4;
        				errout.outputVariables(errcount);
        				errcount+=1;

    					continue;     //jump over to next cohort, due to run cohort error
      				}
    			}

    		} catch (Exception &exception){
				exception.mesg();
    			if(md.consoledebug){
    					cout <<"problem in running cohort in Regioner::run\n";
    			}

    			rout.missingValues(MAX_OREGN_YR, runcht.cohortcount);

    			errout.errorid = -4;
    			errout.outputVariables(errcount);
    			errcount+=1;

				continue;     //jump over to next cohort, due to run cohort error

    		}

		} else { // end of cruid >=0 && other IDs>=0
			cout<<"No grid exists for cohort: "<<chtid<<" - SKIPPED! \n";

			rout.missingValues(MAX_OREGN_YR, runcht.cohortcount);

			errout.errorid = -2;
			errout.outputVariables(errcount);
			errcount+=1;
		} // end of cruid >=0 && errout.errorid ==0

		runcht.cohortcount++;
		 
	}// end of cohort loop
	
};