Grid::Grid (int s) : size (s) { for (int i=0; i<tile_count(size); i++) tiles.push_back(Tile(i, i<12 ? 5 : 6)); for (int i=0; i<corner_count(size); i++) corners.push_back(Corner(i)); for (int i=0; i<edge_count(size); i++) edges.push_back(Edge(i)); }
std::vector<Vector2> polygon (const Tile* t, Quaternion d) { std::vector<Vector2> p; Quaternion q = reference_rotation(t, d); for (int i=0; i<edge_count(t); i++) { Vector3 c = q * vector(nth_corner(t, i)); p.push_back(Vector2(c.x, c.y)); } return p; }
void generate_season (Planet& planet, const Climate_parameters& par, float time_of_year) { Climate_generation_season season; season.tiles.resize(tile_count(planet)); season.corners.resize(corner_count(planet)); season.edges.resize(edge_count(planet)); season.var.time_of_year = time_of_year; season.var.solar_equator = axial_tilt(planet) * sin(2.0*pi*time_of_year); season.tropical_equator = 0.67*season.var.solar_equator; _set_temperature(planet, par, season); _set_wind(planet, par, season); _set_humidity(planet, par, season); // _set_river_flow(planet, par, season); Season s; s.tiles.resize(tile_count(planet)); s.corners.resize(corner_count(planet)); s.edges.resize(edge_count(planet)); copy_season(season, s); m_climate(planet).seasons.push_back(s); }
float _incoming_humidity (const Planet& planet, const Climate_generation_season& season, int i) { float humidity = 0.0; const Tile* t = nth_tile(planet, i); for (int k=0; k<edge_count(t); k++) { const Edge* e = nth_edge(t, k); if (sign(e, t) * season.edges[id(e)].wind_velocity > 0) { humidity += season.tiles[id(nth_tile(t, k))].humidity * std::abs(season.edges[id(e)].wind_velocity) * length(planet, e); } } return humidity; }
void UpdateDesiredMeshDensity::computeExistingLengths() { QSet<int> all_bcs = GuiMainWindow::pointer()->getAllBoundaryCodes(); QSet<int> fixed_bcs = all_bcs - m_BoundaryCodes; QVector<double> edge_length(m_Grid->GetNumberOfPoints(), 1e99); QVector<int> edge_count(m_Grid->GetNumberOfPoints(), 0); m_Fixed.fill(false, m_Grid->GetNumberOfPoints()); EG_VTKDCC(vtkIntArray, cell_code, m_Grid, "cell_code"); for (vtkIdType id_cell = 0; id_cell < m_Grid->GetNumberOfCells(); ++id_cell) { if (isSurface(id_cell, m_Grid)) { if (fixed_bcs.contains(cell_code->GetValue(id_cell))) { vtkIdType N_pts, *pts; m_Grid->GetCellPoints(id_cell, N_pts, pts); QVector<vec3_t> x(N_pts); for (int i = 0; i < N_pts; ++i) { m_Grid->GetPoint(pts[i], x[i].data()); m_Fixed[pts[i]] = true; } for (int i = 0; i < N_pts; ++i) { int j = i + 1; if (j >= N_pts) { j = 0; } double L = (x[i] - x[j]).abs(); edge_length[pts[i]] = min(edge_length[pts[i]], L); edge_length[pts[j]] = min(edge_length[pts[j]], L); ++edge_count[pts[i]]; ++edge_count[pts[j]]; } } } } EG_VTKDCN(vtkDoubleArray, characteristic_length_desired, m_Grid, "node_meshdensity_desired"); for (vtkIdType id_node = 0; id_node < m_Grid->GetNumberOfPoints(); ++id_node) { if (edge_count[id_node] > 0) { if (edge_length[id_node] > 1e98) { EG_BUG; } characteristic_length_desired->SetValue(id_node, edge_length[id_node]); } } }
void _set_wind (const Planet& planet, const Climate_parameters&, Climate_generation_season& season) { for (auto& t : tiles(planet)) { season.tiles[id(t)].wind = _default_wind(planet, id(t), season.tropical_equator); season.tiles[id(t)].wind.direction += north(planet, &t); } for (auto& t : tiles(planet)) { //tile shape in 2d, rotated according to wind direction std::vector<Vector2> corners = rotation_matrix(north(planet, &t) - season.tiles[id(t)].wind.direction) * polygon(&t, rotation_to_default(planet)); int e = edge_count(t); for (int k=0; k<e; k++) { int direction = sign(nth_edge(t, k), &t); if (corners[k].x + corners[(k+1)%e].x < 0) direction *= -1; season.edges[id(nth_edge(t, k))].wind_velocity -= 0.5 * direction * season.tiles[id(t)].wind.speed * std::abs(corners[k].y - corners[(k+1)%e].y) / length(corners[k] - corners[(k+1)%e]); } } }
//--------------------------------------------------------------------- bool PFile::isPolygonDefinitionListValid( void ) { Ogre::Log::Stream log( Ogre::LogManager::getSingleton().stream() ); size_t vertex_count( m_vertices.size() ) ,normal_count( m_normals.size() ) ,edge_count ( m_edges.size() ); for( size_t p( m_polygon_definitions.size() ); p--; ) { PolygonDefinition& def( m_polygon_definitions[p] ); for( int i(3); i--; ) { if( def.vertex[i] >= vertex_count ) { log << "Error: index to vertex is out of Bounds " << " m_polygon_definitions[" << p << "]" << ".vertex[" << i << "]: " << def.vertex[i]; return false; } if( def.normal[i] >= normal_count ) { log << "Error: index to normal is out of Bounds " << " m_polygon_definitions[" << p << "]" << ".normal[" << i << "]: " << def.normal[i]; return false; } if( def.edge[i] >= edge_count ) { log << "Error: index to edge is out of Bounds " << " m_polygon_definitions[" << p << "]" << ".edge[" << i << "]: " << def.edge[i]; return false; } } } return true; }
/* and final */ static void print_stat(Parrot_Interp interpreter, IMC_Unit * unit) { int sets[4] = {0,0,0,0}; int cols[4] = {-1,-1,-1,-1}; make_stat(unit, sets, cols); info(interpreter, 1, "sub %s:\n\tregisters in .imc:\t I%d, N%d, S%d, P%d\n", function, imcsets[0], imcsets[1], imcsets[2], imcsets[3]); info(interpreter, 1, "\t%d labels, %d lines deleted, %d if_branch, %d branch_branch\n", ostat.deleted_labels, ostat.deleted_ins, ostat.if_branch, ostat.branch_branch); info(interpreter, 1, "\t%d used once deleted\n", ostat.used_once); info(interpreter, 1, "\t%d invariants_moved\n", ostat.invariants_moved); info(interpreter, 1, "\tregisters needed:\t I%d, N%d, S%d, P%d\n", sets[0], sets[1], sets[2], sets[3]); info(interpreter, 1, "\tregisters in .pasm:\t I%d, N%d, S%d, P%d - %d spilled\n", cols[0]+1, cols[1]+1, cols[2]+1, cols[3]+1, unit->n_spilled); info(interpreter, 1, "\t%d basic_blocks, %d edges\n", unit->n_basic_blocks, edge_count(unit)); }
const Edge* nth_edge (const Tile& t, int n) { int k = n < 0 ? n % edge_count(t) + edge_count(t) : n % edge_count(t); return t.edges[k]; }
const Corner* nth_corner (const Tile& t, int n) { int k = n < 0 ? n % edge_count(t) + edge_count(t) : n % edge_count(t); return t.corners[k]; }
const Tile* nth_tile (const Tile& t, int n) { int k = n < 0 ? n % edge_count(t) + edge_count(t) : n % edge_count(t); return t.tiles[k]; }