void ShallowWater::updateVelocities() { float a = 9.81; for(int j = 1; j < m_h.getDimY(); j++) { for(int i = 2; i < m_h.getDimX(); i++) { m_vX.addValue(i, j, a * m_dt * ((m_h(i-1, j) - m_h(i, j)) / m_dx)); } } for(int j = 2; j < m_h.getDimY(); j++) { for(int i = 1; i < m_h.getDimX(); i++) { m_vY.addValue(i, j, a * m_dt * ((m_h(i, j-1) - m_h(i, j)) / m_dy)); } } }
void tree_edge(Edge e, const Graph& g) { m_decreased = relax(e, g, m_weight, m_predecessor, m_distance, m_combine, m_compare); if(m_decreased) { m_vis.edge_relaxed(e, g); put(m_cost, target(e, g), m_combine(get(m_distance, target(e, g)), m_h(target(e, g)))); } else m_vis.edge_not_relaxed(e, g); }
void ShallowWater::reflectingBoundaries() { int xMax = m_h.getDimX()-1; int yMax = m_h.getDimY()-1; for(int j = 0; j <= yMax; j++) { m_h.setValue(0, j, m_h(1, j)); m_h.setValue(xMax, j, m_h(xMax-1, j)); m_vX.setValue(1, j, 0.0); m_vX.setValue(xMax, j, 0.0); m_vY.setValue(0, j, 0.0); m_vY.setValue(xMax, j, 0.0); } for(int i = 0; i <= xMax; i++) { m_h.setValue(i, 0, m_h(i, 1)); m_h.setValue(i, yMax, m_h(i, yMax-1)); m_vX.setValue(i, 0, 0.0); m_vX.setValue(i, yMax, 0.0); m_vY.setValue(i, 1, 0.0); m_vY.setValue(i, yMax, 0.0); } }
void gray_target(Edge e, Graph& g) { m_decreased = relax(e, g, m_weight, m_predecessor, m_distance, m_combine, m_compare); if(m_decreased) { put(m_cost, target(e, g), m_combine(get(m_distance, target(e, g)), m_h(target(e, g)))); m_Q.update(target(e, g)); m_vis.edge_relaxed(e, g); } else m_vis.edge_not_relaxed(e, g); }
void ShallowWater::draw() const { Array2D<math::Vec3f> normals; normals = computeNormals(m_h); glBegin(GL_QUADS); glColor4f(0.0,0.4,0.8,0.8); for(int i = 0; i < m_h.getDimX()-1; i++) { for(int j = 0; j < m_h.getDimY()-1; j++) { glNormal3fv(normals(i, j)); glVertex3f(i*m_dx, m_h(i, j), j*m_dy); glNormal3fv(normals(i+1,j)); glVertex3f((i+1)*m_dx, m_h(i+1, j), j*m_dy); glNormal3fv(normals(i+1,j+1)); glVertex3f((i+1)*m_dx, m_h(i+1, j+1), (j+1)*m_dy); glNormal3fv(normals(i,j+1)); glVertex3f(i*m_dx, m_h(i, j+1), (j+1)*m_dy); } } glEnd(); glBegin(GL_QUADS); glColor3f(0.4,0.2,0.0); for(int i = 0; i < m_g.getDimX()-1; i++) { for(int j = 0; j < m_g.getDimY()-1; j++) { glNormal3fv(m_g_normals(i,j)); glVertex3f(i*m_dx, m_g(i, j), j*m_dy); glNormal3fv(m_g_normals(i+1,j)); glVertex3f((i+1)*m_dx, m_g(i+1, j), j*m_dy); glNormal3fv(m_g_normals(i+1,j+1)); glVertex3f((i+1)*m_dx, m_g(i+1, j+1), (j+1)*m_dy); glNormal3fv(m_g_normals(i,j+1)); glVertex3f(i*m_dx, m_g(i, j+1), (j+1)*m_dy); } } glEnd(); }
void black_target(Edge e, const Graph& g) { m_decreased = relax(e, g, m_weight, m_predecessor, m_distance, m_combine, m_compare); if(m_decreased) { m_vis.edge_relaxed(e, g); put(m_cost, target(e, g), m_combine(get(m_distance, target(e, g)), m_h(target(e, g)))); m_Q.push(target(e, g)); put(m_color, target(e, g), Color::gray()); m_vis.black_target(e, g); } else m_vis.edge_not_relaxed(e, g); }
void set_points(const TVector &x, const TVector &y) { assert(x.size() == y.size()); assert(x.size()>2); int n =static_cast<int>(x.size()); m_x.assign(x.begin(), x.end()); m_c0.assign(y.begin(), y.end()); m_c1.resize(n); m_c2.resize(n); m_c3.resize(n); Vector<T, e_host> m_h(n); Vector<T, e_host> m_l(n); Vector<T, e_host> m_mu(n); Vector<T, e_host> m_z(n); n--; for(auto i = 0; i < n; i++) { m_h[i] = m_x[i+1]-m_x[i]; } m_l[0] = 1; m_mu[0] = 0; m_z[0] = 0; for(auto i = 1; i < n; i++) { m_l[i] = 2*(m_x[i+1]-m_x[i-1])-m_h[i-1]*m_mu[i-1]; m_mu[i] = m_h[i]/m_l[i]; auto alpha = 3*(m_c0[i+1]-m_c0[i])/m_h[i]-3*(m_c0[i]-m_c0[i-1])/m_h[i-1]; m_z[i] = (alpha-m_h[i-1]*m_z[i-1])/m_l[i]; } m_l[n] = 1; m_z[n] = 0; m_c2[n] = 0; for(auto i =n-1; i >= 0; i--) { m_c2[i] = m_z[i] - m_mu[i]*m_c2[i+1]; m_c1[i] = (m_c0[i+1]-m_c0[i])/m_h[i]-m_h[i]*(m_c2[i+1]+2*m_c2[i])/3; m_c3[i] = (m_c2[i+1]-m_c2[i])/(3*m_h[i]); } }
StackValueCollection* interpretedVFrame::locals() const { int length = method()->max_locals(); if (method()->is_native()) { // If the method is native, max_locals is not telling the truth. // maxlocals then equals the size of parameters length = method()->size_of_parameters(); } StackValueCollection* result = new StackValueCollection(length); // Get oopmap describing oops and int for current bci InterpreterOopMap oop_mask; if (TraceDeoptimization && Verbose) { methodHandle m_h(thread(), method()); OopMapCache::compute_one_oop_map(m_h, bci(), &oop_mask); } else { method()->mask_for(bci(), &oop_mask); } // handle locals for(int i=0; i < length; i++) { // Find stack location intptr_t *addr = locals_addr_at(i); // Depending on oop/int put it in the right package StackValue *sv; if (oop_mask.is_oop(i)) { // oop value Handle h(*(oop *)addr); sv = new StackValue(h); } else { // integer sv = new StackValue(*addr); } assert(sv != NULL, "sanity check"); result->add(sv); } return result; }
/* * Worker routine for fetching references and/or values * for a particular bci in the interpretedVFrame. * * Returns data for either "locals" or "expressions", * using bci relative oop_map (oop_mask) information. * * @param expressions bool switch controlling what data to return (false == locals / true == expressions) * */ StackValueCollection* interpretedVFrame::stack_data(bool expressions) const { InterpreterOopMap oop_mask; // oopmap for current bci if (TraceDeoptimization && Verbose) { methodHandle m_h(Thread::current(), method()); OopMapCache::compute_one_oop_map(m_h, bci(), &oop_mask); } else { method()->mask_for(bci(), &oop_mask); } const int mask_len = oop_mask.number_of_entries(); // If the method is native, method()->max_locals() is not telling the truth. // For our purposes, max locals instead equals the size of parameters. const int max_locals = method()->is_native() ? method()->size_of_parameters() : method()->max_locals(); assert(mask_len >= max_locals, "invariant"); const int length = expressions ? mask_len - max_locals : max_locals; assert(length >= 0, "invariant"); StackValueCollection* const result = new StackValueCollection(length); if (0 == length) { return result; } if (expressions) { stack_expressions(result, length, max_locals, oop_mask, fr()); } else { stack_locals(result, length, oop_mask, fr()); } assert(length == result->size(), "invariant"); return result; }
StackValueCollection* interpretedVFrame::expressions() const { int length = fr().interpreter_frame_expression_stack_size(); if (method()->is_native()) { // If the method is native, there is no expression stack length = 0; } int nof_locals = method()->max_locals(); StackValueCollection* result = new StackValueCollection(length); InterpreterOopMap oop_mask; // Get oopmap describing oops and int for current bci if (TraceDeoptimization && Verbose) { methodHandle m_h(method()); OopMapCache::compute_one_oop_map(m_h, bci(), &oop_mask); } else { method()->mask_for(bci(), &oop_mask); } // handle expressions for(int i=0; i < length; i++) { // Find stack location intptr_t *addr = fr().interpreter_frame_expression_stack_at(i); // Depending on oop/int put it in the right package StackValue *sv; if (oop_mask.is_oop(i + nof_locals)) { // oop value Handle h(*(oop *)addr); sv = new StackValue(h); } else { // integer sv = new StackValue(*addr); } assert(sv != NULL, "sanity check"); result->add(sv); } return result; }
void interpretedVFrame::set_locals(StackValueCollection* values) const { if (values == NULL || values->size() == 0) return; int length = method()->max_locals(); if (method()->is_native()) { // If the method is native, max_locals is not telling the truth. // maxlocals then equals the size of parameters length = method()->size_of_parameters(); } assert(length == values->size(), "Mismatch between actual stack format and supplied data"); // Get oopmap describing oops and int for current bci InterpreterOopMap oop_mask; if (TraceDeoptimization && Verbose) { methodHandle m_h(thread(), method()); OopMapCache::compute_one_oop_map(m_h, bci(), &oop_mask); } else { method()->mask_for(bci(), &oop_mask); } // handle locals for (int i = 0; i < length; i++) { // Find stack location intptr_t *addr = locals_addr_at(i); // Depending on oop/int put it in the right package StackValue *sv = values->at(i); assert(sv != NULL, "sanity check"); if (oop_mask.is_oop(i)) { // oop value *(oop *) addr = (sv->get_obj())(); } else { // integer *addr = sv->get_int(); } } }