void WHtreeProcesser::writeBases( const std::vector< size_t > &baseNodes, const std::string& filename ) const { std::ofstream outFile( filename.c_str() ); if( !outFile ) { std::cerr << "ERROR: unable to open out file: \"" << outFile << "\"" << std::endl; exit( -1 ); } outFile << "#bases" << std::endl; for( std::vector<size_t>::const_iterator nodeIter( baseNodes.begin() ) ; nodeIter != baseNodes.end() ; ++nodeIter ) { outFile << *nodeIter << std::endl; } outFile << "#endbases" << std::endl << std::endl; outFile << "#pruned" << std::endl; for( std::vector<WHnode>::const_iterator leafIter( m_tree.m_leaves.begin() ) ; leafIter != m_tree.m_leaves.end() ; ++leafIter ) { if( leafIter->isFlagged() ) { outFile << leafIter->getID() << std::endl; } } outFile << "#endpruned" << std::endl << std::endl; return; } // end WHtreeProcesser::writeBases() -------------------------------------------------------------------------------------
void TR::ILValidator::validate(const OMR::ILValidationStrategy *strategy) { /** * Selection Phase: * From all the available `ILValidationRule`s, only select the ones * corresponding to the given `OMR::ILValidationStrategy`. */ std::vector<TR::MethodValidationRule *> reqMethodValidationRules = getRequiredMethodValidationRules(strategy); std::vector<TR::BlockValidationRule *> reqBlockValidationRules = getRequiredBlockValidationRules(strategy); std::vector<TR::NodeValidationRule *> reqNodeValidationRules = getRequiredNodeValidationRules(strategy); /** * Validation Phase: * Validate against the required set of `ILValidationRule`s. */ /* Rules that are veriified over the entire method. */ TR::ResolvedMethodSymbol* methodSymbol = comp()->getMethodSymbol(); for (auto it = reqMethodValidationRules.begin(); it != reqMethodValidationRules.end(); ++it) { (*it)->validate(methodSymbol); } /* Checks performed across an extended blocks. */ for (auto it = reqBlockValidationRules.begin(); it != reqBlockValidationRules.end(); ++it) { TR::TreeTop *tt, *exitTreeTop; for (tt = methodSymbol->getFirstTreeTop(); tt; tt = exitTreeTop->getNextTreeTop()) { TR::TreeTop *firstTreeTop = tt; exitTreeTop = tt->getExtendedBlockExitTreeTop(); (*it)->validate(firstTreeTop, exitTreeTop); } } /* NodeValidationRules only check per node for a specific property. */ for (auto it = reqNodeValidationRules.begin(); it != reqNodeValidationRules.end(); ++it) { for (TR::PreorderNodeIterator nodeIter(methodSymbol->getFirstTreeTop(), comp(), "NODE_VALIDATOR"); nodeIter.currentTree(); ++nodeIter) { (*it)->validate(nodeIter.currentNode()); } } }
static float calculateAverageGraphEdgeLength(const TileMap::NavGraph& navGraph) { float totalLength = 0; int numEdgesCounted = 0; TileMap::NavGraph::ConstNodeIterator nodeIter(navGraph); for (const TileMap::NavGraph::Node* pNode = nodeIter.begin(); !nodeIter.end(); pNode = nodeIter.next()) { TileMap::NavGraph::ConstEdgeIterator edgeIter(navGraph, pNode->getIndex()); for (const TileMap::NavGraph::Edge* pEdge = edgeIter.begin(); !edgeIter.end(); pEdge = edgeIter.next()) { ++numEdgesCounted; totalLength += distance(navGraph.getNode(pEdge->getFrom()).getPosition(), navGraph.getNode(pEdge->getTo()).getPosition()); } } return totalLength / numEdgesCounted; }
TileMap::TileMap(Game& world, TextureManager& textureManager, const TMX& tmx) : BaseGameEntity(world, b2BodyDef()) , mWorld(world) , mTextures() , mpCollider(nullptr) , mpNavGraph(nullptr) , mDrawFlags(0) , mCellSpaceNeighborhoodRange(1) , mpCellSpacePartition(nullptr) { setDrawOrder(std::numeric_limits<int>::max()); std::vector<std::vector<sf::VertexArray>> layers; tmx.makeVertices(textureManager, mTextures, layers); for (auto it = layers.begin(); it != layers.end(); ++it) { int index = it - layers.begin(); if (it->size() != mTextures.size()) { throw std::runtime_error("Texture and layer component counts are inconsistent."); } auto pLayer = std::make_unique<Layer>(mWorld, std::move(*it), mTextures); pLayer->setDrawOrder(index); attachNode(std::move(pLayer)); } const sf::Transform& transform = getWorld().getPixelToWorldTransform(); mpCollider = std::unique_ptr<CompositeCollider>(tmx.makeCollider(transform)); mpNavGraph = std::unique_ptr<NavGraph>(tmx.makeNavGraph(transform)); mCellSpaceNeighborhoodRange = calculateAverageGraphEdgeLength(*mpNavGraph) + 1; mpCellSpacePartition = std::make_unique<NavCellSpace>((float)tmx.getTileWidth() / tmx.getWidth(), (float)tmx.getTileHeight() * tmx.getHeight(), tmx.getWidth() / 4, tmx.getHeight() / 4, mpNavGraph->numNodes()); TileMap::NavGraph::ConstNodeIterator nodeIter(*mpNavGraph); for (const TileMap::NavGraph::Node* pNode = nodeIter.begin(); !nodeIter.end(); pNode = nodeIter.next()) { mpCellSpacePartition->addEntity(pNode); } std::vector<b2Fixture*> fixtures; mpCollider->createFixtures(getBody(), fixtures); }
main( int argc, char **argv ) { int silent_mode, // Option for silent mode (no time output to stdout) optDetachLim, // Option for detachment-limited erosion only optMeander, // Option for stream meandering optFloodplainDep, // Option for floodplain (overbank) deposition optLoessDep, // Option for eolian deposition optDiffuseDepo; // Option for deposition / no deposition by diff'n tStreamMeander *meander; // -> meander object tFloodplain *floodplain; // -> floodplain object tEolian *loess; // -> eolian deposition object ofstream oefile; /****************** INITIALIZATION *************************************\ ** ALGORITHM ** Get command-line arguments (name of input file + any other opts) ** Set silent_mode flag ** Open main input file ** Create and initialize objects for... ** Mesh ** Output files ** Storm ** Stream network ** Erosion ** Uplift (or baselevel change) ** Run timer ** Write output for initial state ** Get options for erosion type, meandering, etc. \**********************************************************************/ // Check command-line arguments if( argc<2 ) { cerr << "Usage: " << argv[0] << " <input file>" << endl; ReportFatalError( "You need to give the name of an input file." ); } // Check whether we're in silent mode silent_mode = ( argc>2 && argv[2][1]=='s' ); // Say hello cout << "\nThis is CHILD, version " << VERSION << endl << "Geoarchaeology special version 1.0" << endl << endl; // Open main input file tInputFile inputFile( argv[1] ); // Create and initialize objects: cout << "Creating mesh...\n"; tMesh<tLNode> mesh( inputFile ); cout << "Creating output files...\n"; tLOutput<tLNode> output( &mesh, inputFile ); tStorm storm( inputFile ); cout << "Creating stream network...\n"; tStreamNet strmNet( mesh, storm, inputFile ); tErosion erosion( &mesh, inputFile ); tUplift uplift( inputFile ); cout << "Writing data for time zero...\n"; tRunTimer time( inputFile, !silent_mode ); output.WriteOutput( 0 ); cout << "Initialization done.\n"; // Get various options optDetachLim = inputFile.ReadItem( optDetachLim, "OPTDETACHLIM" ); optMeander = inputFile.ReadItem( optMeander, "OPTMNDR" ); optDiffuseDepo = inputFile.ReadItem( optDiffuseDepo, "OPTDIFFDEP" ); optFloodplainDep = inputFile.ReadItem( optFloodplainDep, "OPTFLOODPLAIN" ); optLoessDep = inputFile.ReadItem( optLoessDep, "OPTLOESSDEP" ); // If applicable, create stream meander object if( optMeander ) meander = new tStreamMeander( strmNet, mesh, inputFile ); // If applicable, create floodplain object if( optFloodplainDep ) floodplain = new tFloodplain( inputFile, &mesh ); // If applicable, create eolian deposition object if( optLoessDep ) loess = new tEolian( inputFile ); // For Geoarchaeology special application double kr = inputFile.ReadItem( kr, "KR" ); double drop = inputFile.ReadItem( drop, "GA_VALDROP" ); double inletElev = inputFile.ReadItem( inletElev, "GA_INLETELEV" ); double meanInletElev = inletElev; double period = inputFile.ReadItem( period, "GA_PERIOD" ); int optwave = inputFile.ReadItem( optwave, "GA_OPTWAVE" ); double amplitude = inputFile.ReadItem( amplitude, "GA_AMPLITUDE" ); double tpeak, mr, mf, ttime, oldar1, noise0, noise1; int numpts; //number of points in the floodplain curve int fpindex=0;//where are you in the floodplain data double fpslope;//slope of floodplain curve double chanslp;//slope of channel, read in if optwave==2 vector<double> fpht; vector<double> fptime; if( optwave==0 ) period = 2.0 * PI / period; else if( optwave==1 ) { tpeak = inputFile.ReadItem( tpeak, "GA_TPEAK" ); if( tpeak<=0.0 || tpeak>=1.0 ) ReportFatalError("GA_TPEAK must be between 0 and 1 (not inclusive"); tpeak = tpeak*period; mr = amplitude/tpeak; mf = amplitude/(period-tpeak); oldar1=0; noise0=0; noise1=0; oefile.open("Geoarch/outletelev"); } else if( optwave==2){ numpts=inputFile.ReadItem( numpts, "NUMFLDPLNPTS" ); fpht.assign( numpts,0 ); fptime.assign( numpts,0 ); int i=0; char add='1'; char add2='0'; char name[30]; double help; double inittime; chanslp=inputFile.ReadItem(chanslp, "CHANSLOPE" ); cout<<"channel slope is "<<chanslp<<endl; inittime=inputFile.ReadItem(inittime, "INPUTTIME" ); while (i<numpts){ if(i<9){ strcpy(name, "FLDPLNTIME" ); strcat(name, &add ); help=inputFile.ReadItem(help,name); fptime[i]=help+inittime; cout<<"index "<<i<<" fldplntime "<<fptime[i]; strcpy(name, "FLDPLNHT" ); strcat(name, &add ); help=inputFile.ReadItem(help,name); fpht[i]=help; cout<<" fldplnht "<<fpht[i]<<endl; i++; add++; } if(i>=9){ add='1'; strcpy(name, "FLDPLNTIME" ); strcat(name, &add ); strcat(name, &add2 ); help=inputFile.ReadItem(help,name); fptime[i]=help; cout<<"index "<<i<<" fldplntime "<<fptime[i]; strcpy(name, "FLDPLNHT" ); strcat(name, &add ); strcat(name, &add2 ); help=inputFile.ReadItem(help,name); fpht[i]=help; cout<<" fldplnht "<<fpht[i]<<endl; i++; add2++; } } fpslope=(fpht[fpindex+1]-fpht[fpindex])/(fptime[fpindex+1]-fptime[fpindex]); oefile.open("Terraces/outletelev"); } int numg = inputFile.ReadItem( numg, "NUMGRNSIZE" ); //if( numg<2 ) ReportFatalError("Must use at least 2 sizes with GA." ); vector<double> deparr; deparr.assign( numg,0 ); int i; for( i=0; i<numg; i++ ) deparr[i] = 0.0; assert( strmNet.getInletNodePtr() != 0 ); /**************** MAIN LOOP ******************************************\ ** ALGORITHM ** Generate storm ** Do storm... ** Update network (flow directions, drainage area, runoff) ** Water erosion/deposition (vertical) ** Meandering (if applicable) ** Floodplain deposition (if applicable) ** Do interstorm... ** Hillslope transport ** Eolian (loess) deposition (if applicable) ** Uplift (or baselevel change) **********************************************************************/ while( !time.IsFinished() ) { time.ReportTimeStatus(); // Do storm... storm.GenerateStorm( time.getCurrentTime(), strmNet.getInfilt(), strmNet.getSoilStore() ); //cout << storm.getRainrate() << " " << storm.getStormDuration() << " " // << storm.interstormDur() << endl; //cin >> dbg; strmNet.UpdateNet( time.getCurrentTime(), storm ); // Addition for Geoarchaeology model: set erodibility of main // stream to zero and set its profile elevations as a boundary // condition tMeshListIter<tLNode> nodeIter( mesh.getNodeList() ); tLNode *cn; double elev, totlen; // Start by resetting erodibility for all nodes; will be overridden // to zero for main channel nodes for( cn=nodeIter.FirstP(); nodeIter.IsActive(); cn=nodeIter.NextP() ) cn->setLayerErody( 0, kr ); // Set the new drop elevation if( optwave==0 ) { inletElev = drop + amplitude * sin( period*time.getCurrentTime() ); //cout << "Inlet " << inletElev << " at " << time.getCurrentTime() << endl; } else if( optwave==1 ) { noise1=(0.99*noise0+drand48()-0.5)*0.9; ttime = fmod( time.getCurrentTime(), period ); if( ttime<=tpeak ) inletElev = drop + mr*ttime + noise1; else inletElev = drop + amplitude - mf*(ttime-tpeak) + noise1; noise0=noise1; oefile<<noise1<<endl; } else if( optwave==2 ) { if(time.getCurrentTime()>=fptime[fpindex] && time.getCurrentTime()<fptime[fpindex+1]){ //slope and index don't need to be changed, just calculate elev inletElev = fpht[fpindex] + fpslope*(time.getCurrentTime()-fptime[fpindex]); } else{ //calculate new slope and update index fpindex++; fpslope=(fpht[fpindex+1]-fpht[fpindex])/(fptime[fpindex+1]-fptime[fpindex]); inletElev = fpht[fpindex] + fpslope*(time.getCurrentTime()-fptime[fpindex]); } cout<<"fhpt = "<<fpht[fpindex]<<" fpslope "<<fpslope<<" current time "<<time.getCurrentTime()<<" fptime "<<fptime[fpindex]<<endl; oefile<<inletElev<<endl; } // Find the total length of the main channel and compute slope if( optwave<2){ cn = strmNet.getInletNodePtr(); totlen = 0.0; do { cn->setLayerErody( 0, 0.0 ); // Main channel elev is a B.C., thus unerodible totlen += cn->getFlowEdg()->getLength(); cn = cn->getDownstrmNbr(); } while( cn->getBoundaryFlag()==kNonBoundary ); chanslp = drop/totlen; } // Now set elevations along main channel elev = inletElev; // starting at elevation at inlet cn = strmNet.getInletNodePtr(); // begin at inlet cn->setZ( inletElev ); // set inlet's elev do // work downstream along main channel, setting elevations { double delz; elev = elev - chanslp * cn->getFlowEdg()->getLength(); cn = cn->getDownstrmNbr(); delz = elev - cn->getZ(); while( delz < -0.1 ) { // Test: erode one active layer thick at a tm deparr[0] = -0.1; cn->EroDep( 0, deparr, time.getCurrentTime() ); delz += 0.1; } deparr[0] = delz; cn->EroDep( 0, deparr, time.getCurrentTime() ); } while( cn->getBoundaryFlag()==kNonBoundary ); //cout << "eroding...\n"; if( optDetachLim ) erosion.ErodeDetachLim( storm.getStormDuration() ); else erosion.DetachErode( storm.getStormDuration(), &strmNet, time.getCurrentTime() ); //cout << "meandering...\n"; if( optMeander ) meander->Migrate( time.getCurrentTime() ); //cout << "overbanking...\n"; if( optFloodplainDep ) floodplain->DepositOverbank( storm.getRainrate(), storm.getStormDuration(), time.getCurrentTime() ); // Do interstorm... //cout << "Doing diffusion\n"; erosion.Diffuse( storm.getStormDuration() + storm.interstormDur(), optDiffuseDepo ); //cout << "exposure time...\n"; erosion.UpdateExposureTime( storm.getStormDuration() + storm.interstormDur() ); if( optLoessDep ) loess->DepositLoess( &mesh, storm.getStormDuration()+storm.interstormDur(), time.getCurrentTime() ); //cout << "Uplift\n"; if( time.getCurrentTime() < uplift.getDuration() ) uplift.DoUplift( &mesh, storm.getStormDuration() + storm.interstormDur() ); time.Advance( storm.getStormDuration() + storm.interstormDur() ); //cout << "Output\n"; if( time.CheckOutputTime() ) output.WriteOutput( time.getCurrentTime() ); } }