virtual void grid(GridType *grid) { CoordBox<2> box = grid->boundingBox(); grid->setEdge(ContainerCellType()); for (CoordBox<2>::Iterator i = box.begin(); i != box.end(); ++i) { // IDs are derived from a counter. Resetting it ensures // that the initializer will use the same ID for a // particle on each node for any given container cell: counter = 1 + i->toIndex(box.dimensions) * numCells; ContainerCellType cell = grid->get(*i); cell.clear(); grid->set(*i, cell); if (*i == Coord<2>(0, 0)) { // add a single cell with an influx of 1. this will // make the whole system heat up over time. addHeater(grid, Coord<2>(0, 0), FloatCoord<2>(0, 0), 0, 1); } addRandomCells(grid, *i, numCells); } fillGeometryData(grid); }
virtual void grid(GridBase<CELL, 3> *ret) { CoordBox<3> box = ret->boundingBox(); for (CoordBox<3>::Iterator i = box.begin(); i != box.end(); ++i) { ret->at(*i) = CELL(*i); } }
void Initializer::grid(LibGeoDecomp::GridBase<Cell, 2> *ret) { using LibGeoDecomp::CoordBox; using LibGeoDecomp::FloatCoord; boost::gil::rgb8_image_t img; boost::gil::png_read_image(VANDOUKEN_DATA_DIR VANDOUKEN_INITIALIZER_IMG, img); boost::gil::rgb8_image_t scaledImg(gridDimensions().x(), gridDimensions().y()); boost::gil::resize_view( boost::gil::const_view(img) , boost::gil::view(scaledImg) , boost::gil::bilinear_sampler() ); boost::gil::rgb8_image_t::const_view_t imgView = boost::gil::const_view(scaledImg); CoordBox<2> box = ret->boundingBox(); for (CoordBox<2>::Iterator i = box.begin(); i != box.end(); ++i) { bool setForce = false; FloatCoord<2> force; for (std::size_t j = 0; j < shapes.size(); ++j) { shapes[j]->initCell(&force, &setForce, *i); } // force alpha channel to 0xff to ensure all particles are opaque boost::gil::rgb8_image_t::value_type pixel = imgView(i->x(), i->y()); unsigned color = 0xff000000 + (pixel[0] << 16) + (pixel[1] << 8) + (pixel[2] << 0); ret->set(*i, Cell(color, *i, setForce, force, rand() % Cell::MAX_SPAWN_COUNTDOWN)); } std::cout << "done ...\n"; }
virtual void grid(GridBase<CELL_TYPE, 1> *ret) { CoordBox<1> boundingBox = ret->boundingBox(); for (CoordBox<1>::Iterator i = boundingBox.begin(); i != boundingBox.end(); ++i) { CELL_TYPE cell(i->x() % width(), i->x() / width()); ret->set(*i, cell); } }
void stepFinished(const GridType& grid, unsigned step, WriterEvent event) { avrgTemperature = 0; CoordBox<2> box = grid.boundingBox(); for (CoordBox<2>::Iterator i = box.begin(); i != box.end(); ++i) { avrgTemperature += grid.get(*i).temperature; } avrgTemperature /= box.dimensions.prod(); std::cout << "averageTemperature(" << step << ") = " << avrgTemperature << "\n"; }
virtual void grid(GridBase<BushFireCell, 2> *ret) { Random::seed(4711); CoordBox<2> box = ret->boundingBox(); Grid<double> humidityGrid = createUnwarpedPlasmaField(gridDimensions(), 0.5); Grid<double> fuelGrid = createUnwarpedPlasmaField(gridDimensions(), 0.01); for (CoordBox<2>::Iterator i = box.begin(); i != box.end(); ++i) { ret->set(*i, BushFireCell(humidityGrid[*i], 1.0 + fuelGrid[*i])); } CoordBox<2> seatOfFire(Coord<2>(100, 100), Coord<2>(10, 10)); for (CoordBox<2>::Iterator i = seatOfFire.begin(); i != seatOfFire.end(); ++i) { if (box.inBounds(*i)) { ret->set(*i, BushFireCell(0, 10.0, 200.0, BushFireCell::BURNING)); } } }