// // will project the velocities of all cells within the // group into the space of the groupd rigid body motion // void SandSimulator2d::rigidify( std::vector<Cell *> &group ) { // these 2 booleans indicate wether one of the cells of the current group // borders the boundary domain in x or y. // because if they do, the velocity in the respective direction has to // be zero (rigidbody collision) bool bordersLeft = false; bool bordersRight = false; bool bordersTop = false; bool bordersBottom = false; math::BoundingBox bounds; bounds.minPoint = simulationDomain.minPoint + cellSize/2.0f; bounds.maxPoint = simulationDomain.maxPoint + cellSize/2.0f; // compute the center of mass math::Vec2f center; for( size_t i=0; i<group.size(); ++i ) { center += group[i]->center; // notify if the current cell in the group is on the boundary of the simulation if( group[i]->center.x <= bounds.minPoint.x ) bordersLeft = true; if( group[i]->center.x >= bounds.maxPoint.x ) bordersRight = true; if( group[i]->center.y <= bounds.minPoint.y ) bordersBottom = true; if( group[i]->center.y >= bounds.maxPoint.y ) bordersTop = true; } center /= (float)group.size(); // compute total linear momentum and total angular momentum math::Vec2f v; // total linear momentum float w = 0.0f; // total angular momentum for( size_t i=0; i<group.size(); ++i ) { v += group[i]->velocity; math::Vec2f r = group[i]->center - center; w += math::crossProduct( r, group[i]->velocity ); } v /= (float)group.size(); w /= (float)group.size(); // set velocity for( size_t i=0; i<group.size(); ++i ) { Cell *cell =group[i]; if( (cell->neighbours[2]->type == Cell::Air)||(cell->neighbours[2]->type == Cell::Air) ) continue; math::Vec2f r = group[i]->center - center; math::Vec3f r3(r.x, r.y, 0.0f); math::Vec3f w3(0.0f, 0.0f, w); math::Vec3f rot = math::crossProduct( r3, w3 ); math::Vec2f r_cross_w(rot.x, rot.y); group[i]->velocity = v + r_cross_w; //group[i]->velocity = v; if( (group[i]->velocity.x < 0.0f)&&(bordersLeft) ) group[i]->velocity.x = 0.0f; if( (group[i]->velocity.x > 0.0f)&&(bordersRight) ) group[i]->velocity.x = 0.0f; if( (group[i]->velocity.y < 0.0f)&&(bordersBottom) ) group[i]->velocity.y = 0.0f; if( (group[i]->velocity.y > 0.0f)&&(bordersTop) ) group[i]->velocity.y = 0.0f; if( bordersLeft || bordersRight ) group[i]->velocity.x = 0.0f; if( bordersTop || bordersBottom ) group[i]->velocity.y = 0.0f; if( cell->neighbours[2]->type != Cell::Air ) group[i]->velocity.y = v.y + r_cross_w.y; if( cell->neighbours[0]->type != Cell::Air ) group[i]->velocity.x = v.x + r_cross_w.x; //group[i]->velocity = v + r_cross_w; //group[i]->velocity = v; //group[i]->velocity = math::Vec2f(); } }
void PointGroup<scalar_type>::solve(Timers& timers, bool compute_rmm, bool lda, bool compute_forces, bool compute_energy, double& energy, double* fort_forces_ptr) { HostMatrix<scalar_type> rmm_output; uint group_m = total_functions(); if (compute_rmm) { rmm_output.resize(group_m, group_m); rmm_output.zero(); } #if CPU_RECOMPUTE /** Compute functions **/ timers.functions.start(); compute_functions(compute_forces, !lda); timers.functions.pause(); #endif // prepare rmm_input for this group timers.density.start(); HostMatrix<scalar_type> rmm_input(group_m, group_m); get_rmm_input(rmm_input); timers.density.pause(); HostMatrix<vec_type3> forces(total_nucleii(), 1); forces.zero(); HostMatrix<vec_type3> dd; /******** each point *******/ uint point = 0; for (list<Point>::const_iterator point_it = points.begin(); point_it != points.end(); ++point_it, ++point) { timers.density.start(); /** density **/ scalar_type partial_density = 0; vec_type3 dxyz(0,0,0); vec_type3 dd1(0,0,0); vec_type3 dd2(0,0,0); if (lda) { for (uint i = 0; i < group_m; i++) { float w = 0.0; float Fi = function_values(i, point); for (uint j = i; j < group_m; j++) { scalar_type Fj = function_values(j, point); w += rmm_input(j, i) * Fj; } partial_density += Fi * w; } } else { for (uint i = 0; i < group_m; i++) { float w = 0.0; vec_type3 w3(0,0,0); vec_type3 ww1(0,0,0); vec_type3 ww2(0,0,0); scalar_type Fi = function_values(i, point); vec_type3 Fgi(gradient_values(i, point)); vec_type3 Fhi1(hessian_values(2 * (i + 0) + 0, point)); vec_type3 Fhi2(hessian_values(2 * (i + 0) + 1, point)); for (uint j = 0; j <= i; j++) { scalar_type rmm = rmm_input(j,i); scalar_type Fj = function_values(j, point); w += Fj * rmm; vec_type3 Fgj(gradient_values(j, point)); w3 += Fgj * rmm; vec_type3 Fhj1(hessian_values(2 * (j + 0) + 0, point)); vec_type3 Fhj2(hessian_values(2 * (j + 0) + 1, point)); ww1 += Fhj1 * rmm; ww2 += Fhj2 * rmm; } partial_density += Fi * w; dxyz += Fgi * w + w3 * Fi; dd1 += Fgi * w3 * 2 + Fhi1 * w + ww1 * Fi; vec_type3 FgXXY(Fgi.x(), Fgi.x(), Fgi.y()); vec_type3 w3YZZ(w3.y(), w3.z(), w3.z()); vec_type3 FgiYZZ(Fgi.y(), Fgi.z(), Fgi.z()); vec_type3 w3XXY(w3.x(), w3.x(), w3.y()); dd2 += FgXXY * w3YZZ + FgiYZZ * w3XXY + Fhi2 * w + ww2 * Fi; } } timers.density.pause(); timers.forces.start(); /** density derivatives **/ if (compute_forces) { dd.resize(total_nucleii(), 1); dd.zero(); for (uint i = 0, ii = 0; i < total_functions_simple(); i++) { uint nuc = func2local_nuc(ii); uint inc_i = small_function_type(i); vec_type3 this_dd = vec_type3(0,0,0); for (uint k = 0; k < inc_i; k++, ii++) { scalar_type w = 0.0; for (uint j = 0; j < group_m; j++) { scalar_type Fj = function_values(j, point); w += rmm_input(j, ii) * Fj * (ii == j ? 2 : 1); } this_dd -= gradient_values(ii, point) * w; } dd(nuc) += this_dd; } } timers.forces.pause(); timers.pot.start(); timers.density.start(); /** energy / potential **/ scalar_type exc = 0, corr = 0, y2a = 0; if (lda) cpu_pot(partial_density, exc, corr, y2a); else { cpu_potg(partial_density, dxyz, dd1, dd2, exc, corr, y2a); } timers.pot.pause(); if (compute_energy) energy += (partial_density * point_it->weight) * (exc + corr); timers.density.pause(); /** forces **/ timers.forces.start(); if (compute_forces) { scalar_type factor = point_it->weight * y2a; for (uint i = 0; i < total_nucleii(); i++) forces(i) += dd(i) * factor; } timers.forces.pause(); /** RMM **/ timers.rmm.start(); if (compute_rmm) { scalar_type factor = point_it->weight * y2a; HostMatrix<scalar_type>::blas_ssyr(LowerTriangle, factor, function_values, rmm_output, point); } timers.rmm.pause(); } timers.forces.start(); /* accumulate force results for this group */ if (compute_forces) { FortranMatrix<double> fort_forces(fort_forces_ptr, fortran_vars.atoms, 3, fortran_vars.max_atoms); // TODO: mover esto a init.cpp for (uint i = 0; i < total_nucleii(); i++) { uint global_atom = local2global_nuc[i]; vec_type3 this_force = forces(i); fort_forces(global_atom,0) += this_force.x(); fort_forces(global_atom,1) += this_force.y(); fort_forces(global_atom,2) += this_force.z(); } } timers.forces.pause(); timers.rmm.start(); /* accumulate RMM results for this group */ if (compute_rmm) { for (uint i = 0, ii = 0; i < total_functions_simple(); i++) { uint inc_i = small_function_type(i); for (uint k = 0; k < inc_i; k++, ii++) { uint big_i = local2global_func[i] + k; for (uint j = 0, jj = 0; j < total_functions_simple(); j++) { uint inc_j = small_function_type(j); for (uint l = 0; l < inc_j; l++, jj++) { uint big_j = local2global_func[j] + l; if (big_i > big_j) continue; uint big_index = (big_i * fortran_vars.m - (big_i * (big_i - 1)) / 2) + (big_j - big_i); fortran_vars.rmm_output(big_index) += rmm_output(ii, jj); } } } } } timers.rmm.pause(); #if CPU_RECOMPUTE /* clear functions */ function_values.deallocate(); gradient_values.deallocate(); hessian_values.deallocate(); #endif }
void init_mine_mesh(GLShape& base_mesh, GLShape& wheel_mesh) { float d = 0.025f; float x0 = 1.5f * d; float x1 = 2.0f * d; float y0 = 3.0f * d; float y1 = 4.0f * d; float z0 = d * 0.25f; float z1 = d; Vector3 p0(-x1, 0.0f, z1); Vector3 p1(-x0, 0.0f, z1); Vector3 p2(-x0, y0, z0); Vector3 p3(x0, y0, z0); Vector3 p4(x0, 0.0f, z1); Vector3 p5(x1, 0.0f, z1); Vector3 p6(x1, y1, 0.0f); Vector3 p7(-x1, y1, 0.0f); Vector3 q0(-x1, 0.0f, -z1); Vector3 q1(-x0, 0.0f, -z1); Vector3 q2(-x0, y0, -z0); Vector3 q3(x0, y0, -z0); Vector3 q4(x0, 0.0f, -z1); Vector3 q5(x1, 0.0f, -z1); Vector3 q6(x1, y1, 0.0f); Vector3 q7(-x1, y1, 0.0f); base_mesh = { p0, p1, p2, p0, p2, p7, p2, p3, p6, p2, p6, p7, p3, p4, p5, p3, p5, p6, q0, q1, q2, q0, q2, q7, q2, q3, q6, q2, q6, q7, q3, q4, q5, q3, q5, q6 }; std::vector<Vector2> wheel = circle(Vector2(), 3.0f * d, 16); wheel = cut(wheel, circle(Vector2(), 2.5f * d, 16)); wheel_mesh = to_xy(triangulate(wheel)); Vector3 w0(-d * 0.25f, -2.75f * d, 0.0f); Vector3 w1(d * 0.25f, -2.75f * d, 0.0f); Vector3 w2(d * 0.25f, 2.75f * d, 0.0f); Vector3 w3(-d * 0.25f, 2.75f * d, 0.0f); Vector3 w4(-d * 2.75f, -0.25f * d, 0.0f); Vector3 w5(d * 2.75f, -0.25f * d, 0.0f); Vector3 w6(d * 2.75f, 0.25f * d, 0.0f); Vector3 w7(-d * 2.75f, 0.25f * d, 0.0f); wheel_mesh.push_back(w0); wheel_mesh.push_back(w1); wheel_mesh.push_back(w2); wheel_mesh.push_back(w0); wheel_mesh.push_back(w2); wheel_mesh.push_back(w3); wheel_mesh.push_back(w4); wheel_mesh.push_back(w5); wheel_mesh.push_back(w6); wheel_mesh.push_back(w4); wheel_mesh.push_back(w6); wheel_mesh.push_back(w7); }
double SolveLong(Geometry *geometry, Longchar *lc, int k, int l, int m, double *chi, double *S, double *I) { register int ls; int local; double c1, c2, dtau_dw, dS_uw, dS_dw, w[3], chi_loc, S_loc, dtau_uw, chi_uw, S_uw, I_uw, I_uwp, chi_dw, S_dw; /* --- The first point is the intersection with the horizontal grid line -- -------------- */ chi_uw = Interpolate_3D(chi, geometry, &lc->stencil[0], l, m); S_uw = Interpolate_3D(S, geometry, &lc->stencil[0], l, m); I_uwp = Interpolate_3D(I, geometry, &lc->stencil[0], l, m); /* --- When lc->Nst == 2 we need I_uw = I_uwp -- -------------- */ I_uw = I_uwp; chi_loc = Interpolate_3D(chi, geometry, &lc->stencil[1], l, m); dtau_uw = 0.5 * (chi_uw + chi_loc) * lc->stencil[0].ds; S_loc = Interpolate_3D(S, geometry, &lc->stencil[1], l, m); /* --- Go through the long characteristic section by section -- --- */ for (ls= 2; ls < lc->Nst; ls++) { if (ls == lc->Nst-1) { /* --- The last point is the the endpoint for which the non-local contribution is needed. -- -------------- */ local = k*geometry->Nplane + m*geometry->Nx + l; chi_dw = chi[local]; S_dw = S[local]; } else { chi_dw = Interpolate_3D(chi, geometry, &lc->stencil[ls], l, m); S_dw = Interpolate_3D(S, geometry, &lc->stencil[ls], l, m); } dtau_dw = 0.5 * (chi_loc + chi_dw) * lc->stencil[ls-1].ds; dS_uw = (S_uw - S_loc) / dtau_uw; dS_dw = (S_loc - S_dw) / dtau_dw; w3(dtau_uw, w); c1 = dS_uw*dtau_dw + dS_dw*dtau_uw; c2 = dS_uw - dS_dw; I_uw = I_uwp*(1.0 - w[0]) + w[0]*S_loc + (w[1]*c1 + w[2]*c2) / (dtau_uw + dtau_dw); /* --- Try piecewise linear if quadratic gives negative monochromatic intensity -- -------------- */ if (I_uw < 0.0) { c1 = dS_uw; I_uw = (1.0 - w[0])*I_uwp + w[0]*S_loc + w[1]*c1; } /* --- Store the local quantities as upwind quantities and the downwind quantities as local ones for the next subsection of the long characteristic -- ------------ */ I_uwp = I_uw; chi_uw = chi_loc; S_uw = S_loc; chi_loc = chi_dw; S_loc = S_dw; dtau_uw = dtau_dw; } /* --- Return the upwind intensity at the nearest plane for the pertinent short characteristic -- -------------- */ return I_uw; }
static void kbic_write_block( PIA *pi, char * buf, int count ) { int k; switch (pi->mode) { case 0: case 1: case 2: w0(0x90); w2(4); w2(6); w2(4); for(k=0; k<count/2; k++) { w0(buf[2*k+1]); w2(0); w2(4); w0(buf[2*k]); w2(5); w2(4); } break; case 3: w0(0xa0); w2(4); w2(6); w2(4); w3(0); for(k=0; k<count/2; k++) { w4(buf[2*k+1]); w4(buf[2*k]); } w2(4); w2(0); w2(4); break; case 4: w0(0xa0); w2(4); w2(6); w2(4); w3(0); for(k=0; k<count/2; k++) w4w(pi_swab16(buf,k)); w2(4); w2(0); w2(4); break; case 5: w0(0xa0); w2(4); w2(6); w2(4); w3(0); for(k=0; k<count/4; k++) w4l(pi_swab32(buf,k)); w2(4); w2(0); w2(4); break; } }
static void on26_read_block( PIA *pi, char * buf, int count ) { int k, a, b; switch (pi->mode) { case 0: w0(1); P1; w0(1); P2; w0(2); P1; w0(0x18); P2; w0(0); P1; udelay(10); for (k=0;k<count;k++) { w2(6); a = r1(); w2(4); b = r1(); buf[k] = j44(a,b); } w0(2); P1; w0(8); P2; break; case 1: w0(1); P1; w0(1); P2; w0(2); P1; w0(0x19); P2; w0(0); P1; udelay(10); for (k=0;k<count/2;k++) { w2(0x26); buf[2*k] = r0(); w2(0x24); buf[2*k+1] = r0(); } w0(2); P1; w0(9); P2; break; case 2: w3(1); w3(1); w2(5); w4(1); w2(4); w3(0); w3(0); w2(0x24); udelay(10); for (k=0;k<count;k++) buf[k] = r4(); w2(4); break; case 3: w3(1); w3(1); w2(5); w4(1); w2(4); w3(0); w3(0); w2(0x24); udelay(10); for (k=0;k<count/2;k++) ((u16 *)buf)[k] = r4w(); w2(4); break; case 4: w3(1); w3(1); w2(5); w4(1); w2(4); w3(0); w3(0); w2(0x24); udelay(10); for (k=0;k<count/4;k++) ((u32 *)buf)[k] = r4l(); w2(4); break; } }
void CHLSL_Mesh::GenerateTangentSpace() { //for ( int t = 0; t < m_iNumTriangles; t++ ) //{ // CHLSL_Triangle &tri = m_Triangles[ t ]; // for ( int v = 0; v < 3; v++ ) // { // CHLSL_Vertex &vert = tri.vertices[ v ]; // } //} for (int a = 0; a < m_iNumVertices; a++) { CHLSL_Vertex &vert = m_Vertices[a]; Q_memset( vert.tangent_s, 0, sizeof( float ) * 4 ); Q_memset( vert.tangent_t, 0, sizeof( float ) * 3 ); } CHLSL_Triangle *tri = m_Triangles; for (int a = 0; a < m_iNumTriangles; a++) { CHLSL_Vertex &vert_1 = *tri->vertices[0]; CHLSL_Vertex &vert_2 = *tri->vertices[1]; CHLSL_Vertex &vert_3 = *tri->vertices[2]; Vector v1; Vector v2; Vector v3; VectorCopy( vert_1.pos, v1.Base() ); VectorCopy( vert_2.pos, v2.Base() ); VectorCopy( vert_3.pos, v3.Base() ); #if 0 Vector w1( vert_1.uv[0][0], vert_1.uv[0][1], 0 ); Vector w2( vert_2.uv[0][0], vert_2.uv[0][1], 0 ); Vector w3( vert_3.uv[0][0], vert_3.uv[0][1], 0 ); Vector tan_s_2d( 1, 0, 0 ); Vector tan_t_2d( 0, 1, 0 ); Vector delta_vert2 = v2 - v1; Vector delta_vert3 = v3 - v1; Vector delta_uv2 = w2 - w1; Vector delta_uv3 = w3 - w1; Vector n; VectorCopy( vert_1.normal, n.Base() ); delta_vert2 -= DotProduct( delta_vert2, n ) * n; delta_vert3 -= DotProduct( delta_vert3, n ) * n; //delta_vert2.NormalizeInPlace(); //delta_vert3.NormalizeInPlace(); delta_uv2.NormalizeInPlace(); delta_uv3.NormalizeInPlace(); Vector sdir( vec3_origin ); Vector tdir( vec3_origin ); sdir += DotProduct( tan_s_2d, delta_uv2 ) * delta_vert2; sdir += DotProduct( tan_s_2d, delta_uv3 ) * delta_vert3; tdir += DotProduct( tan_t_2d, delta_uv2 ) * delta_vert2; tdir += DotProduct( tan_t_2d, delta_uv3 ) * delta_vert3; #else Vector2D w1( vert_1.uv[0][0], vert_1.uv[0][1] ); Vector2D w2( vert_2.uv[0][0], vert_2.uv[0][1] ); Vector2D w3( vert_3.uv[0][0], vert_3.uv[0][1] ); float x1 = v2.x - v1.x; float x2 = v3.x - v1.x; float y1 = v2.y - v1.y; float y2 = v3.y - v1.y; float z1 = v2.z - v1.z; float z2 = v3.z - v1.z; float s1 = w2.x - w1.x; float s2 = w3.x - w1.x; float t1 = w2.y - w1.y; float t2 = w3.y - w1.y; float r = (s1 * t2 - s2 * t1); if ( r != 0 ) r = 1.0f / r; Vector sdir((t2 * x1 - t1 * x2) * r, (t2 * y1 - t1 * y2) * r, (t2 * z1 - t1 * z2) * r); Vector tdir((s1 * x2 - s2 * x1) * r, (s1 * y2 - s2 * y1) * r, (s1 * z2 - s2 * z1) * r); #endif for ( int i = 0; i < 3; i++ ) { Assert( IsFinite( vert_1.tangent_s[i] ) ); Assert( IsFinite( vert_2.tangent_s[i] ) ); Assert( IsFinite( vert_3.tangent_s[i] ) ); Assert( IsFinite( vert_1.tangent_t[i] ) ); Assert( IsFinite( vert_2.tangent_t[i] ) ); Assert( IsFinite( vert_3.tangent_t[i] ) ); vert_1.tangent_s[i] += sdir[i]; vert_2.tangent_s[i] += sdir[i]; vert_3.tangent_s[i] += sdir[i]; vert_1.tangent_t[i] += tdir[i]; vert_2.tangent_t[i] += tdir[i]; vert_3.tangent_t[i] += tdir[i]; } //tan1[i1] += sdir; //tan1[i2] += sdir; //tan1[i3] += sdir; // //tan2[i1] += tdir; //tan2[i2] += tdir; //tan2[i3] += tdir; tri++; } for (int a = 0; a < m_iNumVertices; a++) { CHLSL_Vertex &vert = m_Vertices[a]; Vector n; Vector s; Vector t; VectorCopy( vert.normal, n.Base() ); VectorCopy( vert.tangent_s, s.Base() ); VectorCopy( vert.tangent_t, t.Base() ); n.NormalizeInPlace(); s.NormalizeInPlace(); t.NormalizeInPlace(); #if 0 Vector delta = s + ( t - s ) * 0.5f; Vector bidelta; CrossProduct( delta, n, bidelta ); t = bidelta + ( delta - bidelta ) * 0.5f; t -= n * DotProduct( t, n ); t.NormalizeInPlace(); CrossProduct( n, t, s ); s.NormalizeInPlace(); #endif #if 1 //if ( !IsFinite(t.x) || !IsFinite(t.y) || !IsFinite(t.z) ) // t.Init(0,0,1); //if ( !IsFinite(s.x) || !IsFinite(s.y) || !IsFinite(s.z) ) // s.Init(0,0,1); s = (s - n * DotProduct(n, s)); t = (t - n * DotProduct(n, t)) * -1.0f; s.NormalizeInPlace(); t.NormalizeInPlace(); float w = (DotProduct(CrossProduct(n, s), t) < 0.0F) ? 1.0F : -1.0F; #endif //t *= -1.0f; VectorCopy( s.Base(), vert.tangent_s ); VectorCopy( t.Base(), vert.tangent_t ); vert.tangent_s[3] = w; } // for (long a = 0; a < m_iNumVertices; a++) // { //CHLSL_Vertex &vert = *m_Vertices[a]; // // const Vector& n = //Vector normal( vert.pos[0], vert.pos[1], vert.pos[2] ); // const Vector& t = tan1[a]; // // // Gram-Schmidt orthogonalize // tangent[a] = VectorNormalize( (t - n * DotProduct(n, t)) ); // // // Calculate handedness // tangent[a].w = (Dot(Cross(n, t), tan2[a]) < 0.0F) ? -1.0F : 1.0F; // } }
void Model3D::CalculateTangents() { Tangents.resize(Positions.size() * 4 / 3); bool generate_normals = false; if(Normals.size() != Positions.size()) { Normals.resize(Positions.size()); memset(NormBase(), 0, sizeof(GLfloat)*Normals.size()); generate_normals = true; } for(GLushort i = 0; i < VertIndices.size(); i+= 3) { GLushort a = VertIndices[i]; GLushort b = VertIndices[i+1]; GLushort c = VertIndices[i+2]; vertex3 v1(PosBase()+3*a); vertex3 v2(PosBase()+3*b); vertex3 v3(PosBase()+3*c); vertex2 w1(TCBase()+2*a); vertex2 w2(TCBase()+2*b); vertex2 w3(TCBase()+2*c); float x1 = v2[0] - v1[0]; float x2 = v3[0] - v1[0]; float y1 = v2[1] - v1[1]; float y2 = v3[1] - v1[1]; float z1 = v2[2] - v1[2]; float z2 = v3[2] - v1[2]; float s1 = w2[0] - w1[0]; float s2 = w3[0] - w1[0]; float t1 = w2[1] - w1[1]; float t2 = w3[1] - w1[1]; float r = 1.0f / (s1 * t2 - s2 * t1); vec3 T((t2 * x1 - t1 * x2) * r, (t2 * y1 - t1 * y2) * r, (t2 * z1 - t1 * z2) * r); vec3 B((s1 * x2 - s2 * x1) * r, (s1 * y2 - s2 * y1) * r, (s1 * z2 - s2 * z1) * r); if ((s1 * t2 - s2 * t1) == 0.0) { T = (v3 - v1).norm(); B = (v2 - v1).norm(); } vec3 N = (v3-v1).cross(v2-v1); if (!generate_normals) { N = vec3(NormBase()+3*a) + vec3(NormBase()+3*b) + vec3(NormBase()+3*c); } if(N.dot(N) < 0.001) { N = vec3(0.0,0.0,0.0); if (generate_normals) { VecCopy(N.p(), NormBase()+3*a); VecCopy(N.p(), NormBase()+3*b); VecCopy(N.p(), NormBase()+3*c); } vec4 t(0.0,0.0,0.0,0.0); Tangents[a] = vec4(t); Tangents[b] = vec4(t); Tangents[c] = vec4(t); } else { N = N.norm(); assert(N.dot(N) < 1.001); if (generate_normals) { VecCopy(N.p(), NormBase()+3*a); VecCopy(N.p(), NormBase()+3*b); VecCopy(N.p(), NormBase()+3*c); } float sign = (N.cross(T)).dot(B) < 0.0 ? -1.0 : 1.0; vec4 t = (T - N * N.dot(T)).norm(); t[3] = sign; Tangents[a] = vec4(t); Tangents[b] = vec4(t); Tangents[c] = vec4(t); } } }
int main(int argc, char **argv) { try { const unsigned int d = 2; const unsigned int p = 5; // Create product basis Teuchos::Array< Teuchos::RCP<const Stokhos::OneDOrthogPolyBasis<int,double> > > bases(d); for (unsigned int i=0; i<d; i++) bases[i] = Teuchos::rcp(new basis_type(p)); Teuchos::RCP<const Stokhos::CompletePolynomialBasis<int,double> > basis = Teuchos::rcp(new Stokhos::CompletePolynomialBasis<int,double>(bases)); // Create approximation Stokhos::OrthogPolyApprox<int,double> x(basis), u(basis), v(basis), w(basis), w2(basis), w3(basis); for (unsigned int i=0; i<d; i++) { x.term(i, 1) = 1.0; } // Tensor product quadrature Teuchos::RCP<const Stokhos::Quadrature<int,double> > quad = Teuchos::rcp(new Stokhos::TensorProductQuadrature<int,double>(basis)); // Triple product tensor Teuchos::RCP<Stokhos::Sparse3Tensor<int,double> > Cijk = basis->computeTripleProductTensor(); // Quadrature expansion Stokhos::QuadOrthogPolyExpansion<int,double> quad_exp(basis, Cijk, quad); // Compute PCE via quadrature expansion quad_exp.sin(u,x); quad_exp.exp(v,x); quad_exp.times(w,v,u); // Compute tensor product Stieltjes basis for u and v Teuchos::Array< Teuchos::RCP<const Stokhos::OneDOrthogPolyBasis<int,double> > > st_bases(2); st_bases[0] = Teuchos::rcp(new Stokhos::StieltjesPCEBasis<int,double>( p, Teuchos::rcp(&u,false), quad, true)); st_bases[1] = Teuchos::rcp(new Stokhos::StieltjesPCEBasis<int,double>( p, Teuchos::rcp(&v,false), quad, true)); Teuchos::RCP<const Stokhos::CompletePolynomialBasis<int,double> > st_basis = Teuchos::rcp(new Stokhos::CompletePolynomialBasis<int,double>(st_bases)); Stokhos::OrthogPolyApprox<int,double> u_st(st_basis), v_st(st_basis), w_st(st_basis); u_st.term(0, 0) = u.mean(); u_st.term(0, 1) = 1.0; v_st.term(0, 0) = v.mean(); v_st.term(1, 1) = 1.0; // Use Gram-Schmidt to orthogonalize Stieltjes basis of u and v Teuchos::Array<double> st_points_0; Teuchos::Array<double> st_weights_0; Teuchos::Array< Teuchos::Array<double> > st_values_0; st_bases[0]->getQuadPoints(p+1, st_points_0, st_weights_0, st_values_0); Teuchos::Array<double> st_points_1; Teuchos::Array<double> st_weights_1; Teuchos::Array< Teuchos::Array<double> > st_values_1; st_bases[1]->getQuadPoints(p+1, st_points_1, st_weights_1, st_values_1); Teuchos::Array< Teuchos::Array<double> > st_points(st_points_0.size()); for (int i=0; i<st_points_0.size(); i++) { st_points[i].resize(2); st_points[i][0] = st_points_0[i]; st_points[i][1] = st_points_1[i]; } Teuchos::Array<double> st_weights = st_weights_0; Teuchos::RCP< Stokhos::GramSchmidtBasis<int,double> > gs_basis = Teuchos::rcp(new Stokhos::GramSchmidtBasis<int,double>(st_basis, st_points, st_weights, 1e-15)); // Create quadrature for Gram-Schmidt basis using quad points and // and weights from original basis mapped to Stieljtes basis Teuchos::RCP< const Teuchos::Array< Teuchos::Array<double> > > points = Teuchos::rcp(&st_points,false); Teuchos::RCP< const Teuchos::Array<double> > weights = Teuchos::rcp(&st_weights,false); Teuchos::RCP<const Stokhos::Quadrature<int,double> > gs_quad = Teuchos::rcp(new Stokhos::UserDefinedQuadrature<int,double>(gs_basis, points, weights)); // Triple product tensor Teuchos::RCP<Stokhos::Sparse3Tensor<int,double> > gs_Cijk = gs_basis->computeTripleProductTensor(); // Gram-Schmidt quadrature expansion Stokhos::QuadOrthogPolyExpansion<int,double> gs_quad_exp(gs_basis, gs_Cijk, gs_quad); Stokhos::OrthogPolyApprox<int,double> u_gs(gs_basis), v_gs(gs_basis), w_gs(gs_basis); // Map expansion in Stieltjes basis to Gram-Schmidt basis gs_basis->transformCoeffs(u_st.coeff(), u_gs.coeff()); gs_basis->transformCoeffs(v_st.coeff(), v_gs.coeff()); // Compute w_gs = u_gs*v_gs in Gram-Schmidt basis gs_quad_exp.times(w_gs, u_gs, v_gs); // Project w_gs back to original basis pce_quad_func gs_func(w_gs, *gs_basis); quad_exp.binary_op(gs_func, w2, u, v); // Triple product tensor Teuchos::RCP<Stokhos::Sparse3Tensor<int,double> > st_Cijk = st_basis->computeTripleProductTensor(); // Stieltjes quadrature expansion Teuchos::RCP<const Stokhos::Quadrature<int,double> > st_quad = Teuchos::rcp(new Stokhos::UserDefinedQuadrature<int,double>(st_basis, points, weights)); Stokhos::QuadOrthogPolyExpansion<int,double> st_quad_exp(st_basis, st_Cijk, st_quad); // Compute w_st = u_st*v_st in Stieltjes basis st_quad_exp.times(w_st, u_st, v_st); // Project w_st back to original basis pce_quad_func st_func(w_st, *st_basis); quad_exp.binary_op(st_func, w3, u, v); std::cout.precision(12); std::cout << "w = " << std::endl << w; std::cout << "w2 = " << std::endl << w2; std::cout << "w3 = " << std::endl << w3; std::cout << "w_gs = " << std::endl << w_gs; std::cout << "w_st = " << std::endl << w_st; std::cout.setf(std::ios::scientific); std::cout << "w.mean() = " << w.mean() << std::endl << "w2.mean() = " << w2.mean() << std::endl << "w3.mean() = " << w3.mean() << std::endl << "w_gs.mean() = " << w_gs.mean() << std::endl << "w_st.mean() = " << w_st.mean() << std::endl << "w.std_dev() = " << w.standard_deviation() << std::endl << "w2.std_dev() = " << w2.standard_deviation() << std::endl << "w3.std_dev() = " << w3.standard_deviation() << std::endl << "w_gs.std_dev() = " << w_gs.standard_deviation() << std::endl << "w_st.std_dev() = " << w_st.standard_deviation() << std::endl; } catch (std::exception& e) { std::cout << e.what() << std::endl; } }
void C3DPlotCanvas::OnMouse( wxMouseEvent& event ) { wxPoint pt(event.GetPosition()); wxClientDC dc(this); PrepareDC(dc); wxPoint point(event.GetLogicalPosition(dc)); if (event.RightDown()) { m_bRButton = true; int where[2]; where[0] = point.x; where[1] = point.y; last[0] = point.x; last[1] = point.y; ball->mouse_down(where,3); } if (event.RightUp()) { m_bRButton = false; int where[2]; where[0] = point.x; where[1] = point.y; ball->mouse_up(where,3); } if (event.LeftDown()) { if ((event.CmdDown()) && this->m_d && this->b_select) { m_brush = true; last[0] = point.x; last[1] = point.y; } else { m_bLButton = true; int where[2]; where[0] = point.x; where[1] = point.y; last[0] = point.x; last[1] = point.y; ball->mouse_down(where,1); } } if (event.LeftUp()) { if (bSelect && this->m_d ) { bSelect = false; SelectByRect(); } else if (m_brush) { m_brush = false; } else { m_bLButton = false; int where[2]; where[0] = point.x; where[1] = point.y; ball->mouse_up(where,1); } } if (event.Dragging()) { int where[2]; where[0] = point.x; where[1] = point.y; if (m_brush) { float vp[4]; glGetFloatv(GL_VIEWPORT, vp); float W=vp[2], H=vp[3]; float diam = 2*(ball->radius); ball->apply_transform(); int pix1[2], pix2[2], pix3[2]; pix1[0] = (int)(W/2); pix1[1] = (int)(H/2); pix2[0] = (int)(W/2-1); pix2[1] = (int)(H/2); pix3[0] = (int)(W/2); pix3[1] = (int)(H/2-1); double world1[3], world2[3],world3[3]; unproject_pixel(pix1, world1, 0.0); unproject_pixel(pix2, world2, 0.0); unproject_pixel(pix3, world3, 0.0); ball->unapply_transform(); Vec3f w1(world1); Vec3f w2(world2); Vec3f w3(world3); Vec3f screen_x = w1-w2; unitize(screen_x); Vec3f screen_y = w3-w1; unitize(screen_y); Vec3f XX(1,0,0); Vec3f YY(0,1,0); Vec3f ZZ(0,0,1); xp += diam * (where[0] - last[0]) / W *(XX*screen_x); yp += diam * (where[0] - last[0]) / W *(YY*screen_x); zp += diam * (where[0] - last[0]) / W *(ZZ*screen_x); xp += diam * (last[1] - where[1]) / H *(XX*screen_y); yp += diam * (last[1] - where[1]) / H *(YY*screen_y); zp += diam * (last[1] - where[1]) / H *(ZZ*screen_y); if (xp < -1.0) xp = -1.0; if (xp > 1.0) xp = 1.0; if (yp < -1.0) yp = -1.0; if (yp > 1.0) yp = 1.0; if (zp < -1.0) zp = -1.0; if (zp > 1.0) zp = 1.0; last[0] = where[0]; last[1] = where[1]; c3d_plot_frame->control->m_xp->SetValue((int)((xp+1)*10000)); c3d_plot_frame->control->m_yp->SetValue((int)((yp+1)*10000)); c3d_plot_frame->control->m_zp->SetValue((int)((zp+1)*10000)); this->UpdateSelect(); } else { bSelect = false; if (m_bLButton & m_bRButton) { ball->mouse_drag(where,last,2); last[0] = where[0]; last[1] = where[1]; } else if (m_bLButton) { ball->mouse_drag(where,last,1); last[0] = where[0]; last[1] = where[1]; } else if (m_bRButton) { ball->mouse_drag(where,last,3); last[0] = where[0]; last[1] = where[1]; } } } Refresh(); }
int main(){ /* Example 1, String */ modifiabale_priority<string> mp_string; mp_string.push("Task Manager", 5); mp_string.push("Firefox", 7); std::cout <<"Highest Priorty : "<< mp_string.top() <<endl; mp_string.improve("Firefox", 2); std::cout <<"Highest Priorty : "<< mp_string.top() <<endl; /* OUTPUT: Highest Priorty : Task Manager Highest Priorty : Firefox */ /* Example 2, int You can always choose an integer id for your objects and work with these numbers its the fastest form. */ modifiabale_priority<int> mp_int; mp_int.push(777, 9); mp_int.push(999, 8); std::cout << "Highest Priorty : " << mp_int.top() << endl; mp_int.improve(777, 7); std::cout << "Highest Priorty : " << mp_int.top() << endl; /* OUTPUT: Highest Priorty : 999 Highest Priorty : 777 */ /* Example 3, Your defined class can be used here if < operator has been implemented on it or you may just pick up an id and work with that integer id. */ class worker { public: string name; string lname; worker() :name(""), lname("") {} worker(string name, string lname) :name(name), lname(lname){} bool operator < (const worker &e) const { if(name != e.name)return name < e.name; return lname < e.lname; } }; modifiabale_priority<worker> mp_worker; worker w1("Ali", "Hasani"); worker w2("Reza", "Hoseyni"); worker w3("Mohammad", "Rezayii"); mp_worker.push(w1, 125); mp_worker.push(w2, 111); mp_worker.push(w3, 90); std::cout << "Highest Priorty : " << mp_worker.top().lname << endl; mp_worker.improve(w1, 80); std::cout << "Highest Priorty : " << mp_worker.top().lname << endl; mp_worker.improve(w2, 70); std::cout << "Highest Priorty : " << mp_worker.top().lname << endl; /* OUTPUT: Highest Priorty : Rezayii Highest Priorty : Hasani Highest Priorty : Hoseyni */ return 0; }
void Piecewise_1D(int nspect, int mu, bool_t to_obs, double *chi, double *S, double *I, double *Psi) { register int k; int k_start, k_end, dk, Ndep = geometry.Ndep; double dtau_uw, dtau_dw, dS_uw, I_upw, dS_dw, c1, c2, w[3], zmu, Bnu[2]; zmu = 0.5 / geometry.muz[mu]; /* --- Distinguish between rays going from BOTTOM to TOP (to_obs == TRUE), and vice versa -- -------------- */ if (to_obs) { dk = -1; k_start = Ndep-1; k_end = 0; } else { dk = 1; k_start = 0; k_end = Ndep-1; } dtau_uw = zmu * (chi[k_start] + chi[k_start+dk]) * fabs(geometry.height[k_start] - geometry.height[k_start+dk]); dS_uw = (S[k_start] - S[k_start+dk]) / dtau_uw; /* --- Boundary conditions -- -------------- */ if (to_obs) { switch (geometry.vboundary[BOTTOM]) { case ZERO: I_upw = 0.0; break; case THERMALIZED: Planck(2, &atmos.T[Ndep-2], spectrum.lambda[nspect], Bnu); I_upw = Bnu[1] - (Bnu[0] - Bnu[1]) / dtau_uw; break; case IRRADIATED: I_upw = geometry.Ibottom[nspect][mu]; } } else { switch (geometry.vboundary[TOP]) { case ZERO: I_upw = 0.0; break; case THERMALIZED: Planck(2, &atmos.T[0], spectrum.lambda[nspect], Bnu); I_upw = Bnu[0] - (Bnu[1] - Bnu[0]) / dtau_uw; break; case IRRADIATED: I_upw = geometry.Itop[nspect][mu]; } } I[k_start] = I_upw; if (Psi) Psi[k_start] = 0.0; /* --- Solve transfer along ray -- -------------- */ for (k = k_start+dk; k != k_end+dk; k += dk) { w3(dtau_uw, w); if (k != k_end) { /* --- Piecewise quadratic here -- -------------- */ dtau_dw = zmu * (chi[k] + chi[k+dk]) * fabs(geometry.height[k] - geometry.height[k+dk]); dS_dw = (S[k] - S[k+dk]) / dtau_dw; /* Tiago: commenting this out to always keep linear piecewise c1 = (dS_uw*dtau_dw + dS_dw*dtau_uw); c2 = (dS_uw - dS_dw); I[k] = (1.0 - w[0])*I_upw + w[0]*S[k] + (w[1]*c1 + w[2]*c2) / (dtau_uw + dtau_dw); */ /* --- Try piecewise linear if quadratic gives negative monochromatic intensity -- -------------- */ /* if (I[k] < 0.0) { */ c1 = dS_uw; I[k] = (1.0 - w[0])*I_upw + w[0]*S[k] + w[1]*c1; if (Psi) Psi[k] = w[0] - w[1]/dtau_uw; /* } else { if (Psi) { c1 = dtau_uw - dtau_dw; Psi[k] = w[0] + (w[1]*c1 - w[2]) / (dtau_uw * dtau_dw); } } */ } else { /* --- Piecewise linear integration at end of ray -- ---------- */ I[k] = (1.0 - w[0])*I_upw + w[0]*S[k] + w[1]*dS_uw; if (Psi) Psi[k] = w[0] - w[1] / dtau_uw; } I_upw = I[k]; /* --- Re-use downwind quantities for next upwind position -- --- */ dS_uw = dS_dw; dtau_uw = dtau_dw; } }
void Piecewise_Hermite_1D(int nspect, int mu, bool_t to_obs, double *chi, double *S, double *I, double *Psi) { register int k; int k_start, k_end, dk, Ndep = geometry.Ndep,i; double dtau_uw, dtau_dw, dS_uw, I_upw, dS_dw, c1, c2, w[3], zmu, Bnu[2]; double dsup,dsdn,dt,dt2,dt3,ex,alpha,beta,alphaprim,betaprim,dsup2; double dS_up,dS_c,dchi_up,dchi_c,dchi_dn,dsdn2,dtau_up2; zmu = 0.5 / geometry.muz[mu]; /* --- Distinguish between rays going from BOTTOM to TOP (to_obs == TRUE), and vice versa -- -------------- */ if (to_obs) { dk = -1; k_start = Ndep-1; k_end = 0; } else { dk = 1; k_start = 0; k_end = Ndep-1; } dtau_uw = zmu * (chi[k_start] + chi[k_start+dk]) * fabs(geometry.height[k_start] - geometry.height[k_start+dk]); dS_uw = (S[k_start] - S[k_start+dk]) / dtau_uw; /* --- Boundary conditions -- -------------- */ if (to_obs) { switch (geometry.vboundary[BOTTOM]) { case ZERO: I_upw = 0.0; break; case THERMALIZED: Planck(2, &atmos.T[Ndep-2], spectrum.lambda[nspect], Bnu); I_upw = Bnu[1] - (Bnu[0] - Bnu[1]) / dtau_uw; break; case IRRADIATED: I_upw = geometry.Ibottom[nspect][mu]; } } else { switch (geometry.vboundary[TOP]) { case ZERO: I_upw = 0.0; break; case THERMALIZED: Planck(2, &atmos.T[0], spectrum.lambda[nspect], Bnu); I_upw = Bnu[0] - (Bnu[1] - Bnu[0]) / dtau_uw; break; case IRRADIATED: I_upw = geometry.Itop[nspect][mu]; } } I[k_start] = I_upw; if (Psi) Psi[k_start] = 0.0; /* set variables for first iteration to allow simple shift for all next iterations */ k=k_start+dk; dsup = fabs(geometry.height[k] - geometry.height[k-dk]) / geometry.muz[mu]; dsdn = fabs(geometry.height[k+dk] - geometry.height[k]) / geometry.muz[mu]; dchi_up= (chi[k] - chi[k-dk])/dsup; /* dchi/ds at central point */ har_mean_deriv(&dchi_c,dsup,dsdn,chi[k-dk],chi[k],chi[k+dk]); /* upwind path_length */ dtau_uw = 0.5 * dsup * (chi[k-dk]+chi[k]) + 1./12. * dsup*dsup * (dchi_up - dchi_c ); /* dS/dtau at upwind point */ dS_up=(S[k]-S[k-dk])/dtau_uw; /* --- Solve transfer along ray -- -------------- */ for (k = k_start+dk; k != k_end+dk; k += dk) { if (k != k_end) { /* downwind path length */ dsdn = fabs(geometry.height[k+dk] - geometry.height[k] ) / geometry.muz[mu]; /* dchi/ds at downwind point */ if (abs(k-k_end)>1) { dsdn2=fabs(geometry.height[k+2*dk] - geometry.height[k+dk])/geometry.muz[mu]; har_mean_deriv(&dchi_dn,dsdn,dsdn2,chi[k],chi[k+dk],chi[k+2*dk]); } else { dchi_dn=(chi[k+dk]-chi[k])/dsdn; } /* downwind optical path length */ dtau_dw = 0.5 * dsdn * (chi[k]+chi[k+dk]) + 1./12.* dsdn * dsdn * (dchi_c - dchi_dn) ; dt=dtau_uw; dt2=dt*dt; dt3=dt2*dt; /* compute interpolation parameters */ if (dt > 0.05) { ex=exp(-dt); alpha = ( 6.0*(dt-2.0) + (-dt3+ 6.0*(dt+2.0))*ex ) / dt3; beta = ( (dt3-6.0*(dt-2.0)) - 6.0*(dt+2.0)*ex ) / dt3; alphaprim = ( (2.0*dt-6.0) + (dt2+4.0*dt+6.0)*ex ) / dt2; betaprim = ( (-dt2+4.0*dt-6.0) + (2.0*dt+6.0)*ex ) / dt2; } else { ex=1.0 - dt + 0.5*dt2 - 0.16666667*dt3; alpha = (2.0/15.0)*dt3 - (7.0/20.0)*dt2 + dt/2.0; beta = (1.0/30.0)*dt3 - (3.0/20.0)*dt2 + dt/2.0; alphaprim = - (1.0/20.0)*dt3 + (1.0/12.0)*dt2; betaprim = (1.0/30.0)*dt3 - (1.0/12.0)*dt2; } /* dS/dt at central point */ har_mean_deriv(&dS_c,dtau_uw,dtau_dw,S[k-dk],S[k],S[k+dk]); I[k]= I_upw*ex + alpha*S[k-dk] + beta*S[k] + alphaprim*dS_up + betaprim*dS_c; if (Psi) Psi[k] = beta; } else { /* --- Piecewise linear integration at end of ray -- ---------- */ dtau_uw = zmu * (chi[k] + chi[k-dk]) * fabs(geometry.height[k] - geometry.height[k-dk]); dS_uw = (S[k] - S[k-dk]) / dtau_uw; w3(dtau_uw, w); I[k] = (1.0 - w[0])*I_upw + w[0]*S[k] + w[1]*dS_uw; if (Psi) Psi[k] = w[0] - w[1] / dtau_uw; } I_upw = I[k]; /* --- Re-use downwind quantities for next upwind position -- --- */ dsup=dsdn; dchi_up=dchi_c; dchi_c=dchi_dn; dtau_uw=dtau_dw; dS_up = dS_c; } }
static void epat_read_block( PIA *pi, char * buf, int count ) { int k, ph, a, b; switch (pi->mode) { case 0: w0(7); w2(1); w2(3); w0(0xff); ph = 0; for(k=0;k<count;k++) { if (k == count-1) w0(0xfd); w2(6+ph); a = r1(); if (a & 8) b = a; else { w2(4+ph); b = r1(); } buf[k] = j44(a,b); ph = 1 - ph; } w0(0); w2(4); break; case 1: w0(0x47); w2(1); w2(5); w0(0xff); ph = 0; for(k=0;k<count;k++) { if (k == count-1) w0(0xfd); w2(4+ph); a = r1(); b = r2(); buf[k] = j53(a,b); ph = 1 - ph; } w0(0); w2(4); break; case 2: w0(0x27); w2(1); w2(0x25); w0(0); ph = 0; for(k=0;k<count-1;k++) { w2(0x24+ph); buf[k] = r0(); ph = 1 - ph; } w2(0x26); w2(0x27); buf[count-1] = r0(); w2(0x25); w2(4); break; case 3: w3(0x80); w2(0x24); for(k=0;k<count-1;k++) buf[k] = r4(); w2(4); w3(0xa0); w2(0x24); buf[count-1] = r4(); w2(4); break; case 4: w3(0x80); w2(0x24); for(k=0;k<(count/2)-1;k++) ((u16 *)buf)[k] = r4w(); buf[count-2] = r4(); w2(4); w3(0xa0); w2(0x24); buf[count-1] = r4(); w2(4); break; case 5: w3(0x80); w2(0x24); for(k=0;k<(count/4)-1;k++) ((u32 *)buf)[k] = r4l(); for(k=count-4;k<count-1;k++) buf[k] = r4(); w2(4); w3(0xa0); w2(0x24); buf[count-1] = r4(); w2(4); break; } }
void cubic_polynomial_interpolate_motor_poses_in_tool_frame(Eigen::Matrix <double, N_POINTS, N_MOTORS> & motor_interpolations_, const double motion_time_, const Eigen::Matrix < double, N_POINTS - 1, 1> time_deltas_, mrrocpp::kinematics::common::kinematic_model* model_, const lib::JointArray desired_joints_old_, const mrrocpp::lib::Homog_matrix& current_tool_frame_, const mrrocpp::lib::Homog_matrix& desired_tool_frame_, const mrrocpp::lib::Homog_matrix& tool_transformation_) { // Manipulator has got to have some axes. assert (N_MOTORS>0); // There must be some segments (besides we cannot divide by zero). assert (N_POINTS>1); // Check model. assert (model_); // Variable containing computed transformation from current tool pose to the desired one. lib::Homog_matrix desired_relative_tool_frame; // Compute transformation from current to desired pose. desired_relative_tool_frame = !current_tool_frame_ * desired_tool_frame_; // Extract translation and rotation (second one in the form of angle, axis and gamma). Xyz_Angle_Axis_Gamma_vector relative_xyz_aa_gamma; desired_relative_tool_frame.get_xyz_angle_axis_gamma(relative_xyz_aa_gamma); #if 0 cout<<"Operational space: " << model->get_kinematic_model_label() << "\n"; cout << "Relative ee frame" << desired_relative_tool_frame << endl; cout << "Relative xyz aa gamma" << relative_xyz_aa_gamma << endl; #endif // Delta variables. Xyz_Angle_Axis_Gamma_vector delta_xyz_aa_gamma; lib::Homog_matrix delta_ee_frame; // Interpolation variables. lib::Homog_matrix int_ee_frame; lib::JointArray int_joints(N_MOTORS); lib::MotorArray int_motors(N_MOTORS); // Set last joint settings. lib::JointArray int_joints_old = desired_joints_old_; // Add current position as first one, thus there will be n+1 interpolation points. // Compute inverse kinematics for desired pose. Pass previously desired joint position as current in order to receive continuous move. model_->inverse_kinematics_transform(int_joints, desired_joints_old_, current_tool_frame_*!tool_transformation_); // Transform joints to motors (and check motors/joints values). model_->i2mp_transform(int_motors, int_joints); // Add motors to vector - first interpolation point. motor_interpolations_.row(0) = int_motors.transpose(); // Temporary variables containing motion time from start to current position (sum of time slices). double last_summed = time_deltas_(0); // Compute polynomial coefficients - the (1.16) formula. Xyz_Angle_Axis_Gamma_vector w3 = -(2.0 * relative_xyz_aa_gamma) / (motion_time_ * motion_time_ * motion_time_); Xyz_Angle_Axis_Gamma_vector w2 = (3.0 * relative_xyz_aa_gamma) / (motion_time_ * motion_time_); #if 0 cout << "w3 "<< w3 << endl; cout << "w2 "<< w2 << endl; #endif // Compute interpolation points in motor positions. for (int i = 0; i < N_POINTS - 1; ++i) { // Compute delta in the angle axis gamma representation. delta_xyz_aa_gamma // Px, Py, Pz. << w3(0) * last_summed * last_summed * last_summed + w2(0) * last_summed * last_summed, w3(1) * last_summed * last_summed * last_summed + w2(1) * last_summed * last_summed, w3(2) * last_summed * last_summed * last_summed + w2(2) * last_summed * last_summed, // vx, vy, vz (constant). relative_xyz_aa_gamma(3), relative_xyz_aa_gamma(4), relative_xyz_aa_gamma(5), // Gamma. w3(6) * last_summed * last_summed * last_summed + w2(6) * last_summed * last_summed, // Compute delta frame. delta_ee_frame.set_from_xyz_angle_axis_gamma(delta_xyz_aa_gamma); // Compute desired interpolation end effector frame. int_ee_frame = current_tool_frame_ * delta_ee_frame *!tool_transformation_; // Compute inverse kinematics for desired pose. Pass previously desired joint position as current in order to receive continuous move. model_->inverse_kinematics_transform(int_joints, int_joints_old, int_ee_frame); // Transform joints to motors (and check motors/joints values). model_->i2mp_transform(int_motors, int_joints); #if 0 cout << "delta xyz aa gamma "<< delta_xyz_aa_gamma << endl; cout << "delta ee frame "<< delta_ee_frame << endl; cout << "interpolation ee frame "<< int_ee_frame << endl; cout << int_joints << endl; cout << int_motors << endl; #endif // Add motors to vector. motor_interpolations_.row(i + 1) = int_motors.transpose(); // Set last joint settings. int_joints_old = int_joints; // Add time slice related to this segment. if (i < N_POINTS - 2) { last_summed += time_deltas_(i + 1); } } #if 0 // Display all motor interpolation poses. for (unsigned int l = 0; l < N_POINTS; ++l) { cout << "Motor interpolation point no " << l << ": " << motor_interpolations_.row(l) << endl; } #endif }
bool generalizedsymmetricdefiniteevdreduce(ap::real_2d_array& a, int n, bool isuppera, const ap::real_2d_array& b, bool isupperb, int problemtype, ap::real_2d_array& r, bool& isupperr) { bool result; ap::real_2d_array t; ap::real_1d_array w1; ap::real_1d_array w2; ap::real_1d_array w3; int i; int j; double v; ap::ap_error::make_assertion(n>0, "GeneralizedSymmetricDefiniteEVDReduce: N<=0!"); ap::ap_error::make_assertion(problemtype==1||problemtype==2||problemtype==3, "GeneralizedSymmetricDefiniteEVDReduce: incorrect ProblemType!"); result = true; // // Problem 1: A*x = lambda*B*x // // Reducing to: // C*y = lambda*y // C = L^(-1) * A * L^(-T) // x = L^(-T) * y // if( problemtype==1 ) { // // Factorize B in T: B = LL' // t.setbounds(1, n, 1, n); if( isupperb ) { for(i = 1; i <= n; i++) { ap::vmove(t.getcolumn(i, i, n), b.getrow(i, i, n)); } } else { for(i = 1; i <= n; i++) { ap::vmove(&t(i, 1), &b(i, 1), ap::vlen(1,i)); } } if( !choleskydecomposition(t, n, false) ) { result = false; return result; } // // Invert L in T // if( !invtriangular(t, n, false, false) ) { result = false; return result; } // // Build L^(-1) * A * L^(-T) in R // w1.setbounds(1, n); w2.setbounds(1, n); r.setbounds(1, n, 1, n); for(j = 1; j <= n; j++) { // // Form w2 = A * l'(j) (here l'(j) is j-th column of L^(-T)) // ap::vmove(&w1(1), &t(j, 1), ap::vlen(1,j)); symmetricmatrixvectormultiply(a, isuppera, 1, j, w1, 1.0, w2); if( isuppera ) { matrixvectormultiply(a, 1, j, j+1, n, true, w1, 1, j, 1.0, w2, j+1, n, 0.0); } else { matrixvectormultiply(a, j+1, n, 1, j, false, w1, 1, j, 1.0, w2, j+1, n, 0.0); } // // Form l(i)*w2 (here l(i) is i-th row of L^(-1)) // for(i = 1; i <= n; i++) { v = ap::vdotproduct(&t(i, 1), &w2(1), ap::vlen(1,i)); r(i,j) = v; } } // // Copy R to A // for(i = 1; i <= n; i++) { ap::vmove(&a(i, 1), &r(i, 1), ap::vlen(1,n)); } // // Copy L^(-1) from T to R and transpose // isupperr = true; for(i = 1; i <= n; i++) { for(j = 1; j <= i-1; j++) { r(i,j) = 0; } } for(i = 1; i <= n; i++) { ap::vmove(r.getrow(i, i, n), t.getcolumn(i, i, n)); } return result; } // // Problem 2: A*B*x = lambda*x // or // problem 3: B*A*x = lambda*x // // Reducing to: // C*y = lambda*y // C = U * A * U' // B = U'* U // if( problemtype==2||problemtype==3 ) { // // Factorize B in T: B = U'*U // t.setbounds(1, n, 1, n); if( isupperb ) { for(i = 1; i <= n; i++) { ap::vmove(&t(i, i), &b(i, i), ap::vlen(i,n)); } } else { for(i = 1; i <= n; i++) { ap::vmove(t.getrow(i, i, n), b.getcolumn(i, i, n)); } } if( !choleskydecomposition(t, n, true) ) { result = false; return result; } // // Build U * A * U' in R // w1.setbounds(1, n); w2.setbounds(1, n); w3.setbounds(1, n); r.setbounds(1, n, 1, n); for(j = 1; j <= n; j++) { // // Form w2 = A * u'(j) (here u'(j) is j-th column of U') // ap::vmove(&w1(1), &t(j, j), ap::vlen(1,n-j+1)); symmetricmatrixvectormultiply(a, isuppera, j, n, w1, 1.0, w3); ap::vmove(&w2(j), &w3(1), ap::vlen(j,n)); ap::vmove(&w1(j), &t(j, j), ap::vlen(j,n)); if( isuppera ) { matrixvectormultiply(a, 1, j-1, j, n, false, w1, j, n, 1.0, w2, 1, j-1, 0.0); } else { matrixvectormultiply(a, j, n, 1, j-1, true, w1, j, n, 1.0, w2, 1, j-1, 0.0); } // // Form u(i)*w2 (here u(i) is i-th row of U) // for(i = 1; i <= n; i++) { v = ap::vdotproduct(&t(i, i), &w2(i), ap::vlen(i,n)); r(i,j) = v; } } // // Copy R to A // for(i = 1; i <= n; i++) { ap::vmove(&a(i, 1), &r(i, 1), ap::vlen(1,n)); } if( problemtype==2 ) { // // Invert U in T // if( !invtriangular(t, n, true, false) ) { result = false; return result; } // // Copy U^-1 from T to R // isupperr = true; for(i = 1; i <= n; i++) { for(j = 1; j <= i-1; j++) { r(i,j) = 0; } } for(i = 1; i <= n; i++) { ap::vmove(&r(i, i), &t(i, i), ap::vlen(i,n)); } } else { // // Copy U from T to R and transpose // isupperr = false; for(i = 1; i <= n; i++) { for(j = i+1; j <= n; j++) { r(i,j) = 0; } } for(i = 1; i <= n; i++) { ap::vmove(r.getcolumn(i, i, n), t.getrow(i, i, n)); } } } return result; }
CompositeWeight<W1, W2, W3> divide(CompositeWeight<W1, W2, W3> const& x, CompositeWeight<W1, W2, W3> const& y) { W1 w1(divide(x.weight1(), y.weight1())); W2 w2(divide(x.weight2(), y.weight2())); W3 w3(divide(x.weight3(), y.weight3())); return CompositeWeight<W1, W2, W3>(w1, w2, w3); }
static void kbic_read_block( PIA *pi, char * buf, int count ) { int k, a, b; switch (pi->mode) { case 0: w0(0x98); w2(4); w2(6); w2(4); for (k=0; k<count/2; k++) { w2(1); w0(8); a = r1(); w0(0x28); b = r1(); buf[2*k] = j44(a,b); w2(5); b = r1(); w0(8); a = r1(); buf[2*k+1] = j44(a,b); w2(4); } break; case 1: w0(0xb8); w2(4); w2(6); w2(4); for (k=0; k<count/4; k++) { w0(0xb8); w2(4); w2(5); w0(8); buf[4*k] = j53(r12w()); w0(0xb8); buf[4*k+1] = j53(r12w()); w2(4); w2(5); buf[4*k+3] = j53(r12w()); w0(8); buf[4*k+2] = j53(r12w()); } w2(4); break; case 2: w0(0x88); w2(4); w2(6); w2(4); for (k=0; k<count/2; k++) { w2(0xa0); w2(0xa1); buf[2*k] = r0(); w2(0xa5); buf[2*k+1] = r0(); } w2(4); break; case 3: w0(0xa0); w2(4); w2(6); w2(4); w3(0); for (k=0; k<count; k++) buf[k] = r4(); w2(4); w2(0); w2(4); break; case 4: w0(0xa0); w2(4); w2(6); w2(4); w3(0); for (k=0; k<count/2; k++) ((u16 *)buf)[k] = r4w(); w2(4); w2(0); w2(4); break; case 5: w0(0xa0); w2(4); w2(6); w2(4); w3(0); for (k=0; k<count/4; k++) ((u32 *)buf)[k] = r4l(); w2(4); w2(0); w2(4); break; } }
CompositeWeight<W1, W2, W3> minus(CompositeWeight<W1, W2, W3> const& x, CompositeWeight<W1, W2, W3> const& y) { W1 w1(minus(x.weight1(), y.weight1())); W2 w2(minus(x.weight2(), y.weight2())); W3 w3(minus(x.weight3(), y.weight3())); return CompositeWeight<W1, W2, W3>(w1, w2, w3); }
static int kbic_read_regr( PIA *pi, int cont, int regr ) { int a, b, s; s = cont_map[cont]; switch (pi->mode) { case 0: w0(regr|0x18|s); w2(4); w2(6); w2(4); w2(1); w0(8); a = r1(); w0(0x28); b = r1(); w2(4); return j44(a,b); case 1: w0(regr|0x38|s); w2(4); w2(6); w2(4); w2(5); w0(8); a = r12w(); w2(4); return j53(a); case 2: w0(regr|0x08|s); w2(4); w2(6); w2(4); w2(0xa5); w2(0xa1); a = r0(); w2(4); return a; case 3: case 4: case 5: w0(0x20|s); w2(4); w2(6); w2(4); w3(regr); a = r4(); b = r4(); w2(4); w2(0); w2(4); return a; } return -1; }
void SolveLongStokes(Geometry *geometry, Longchar *lc, int nspect, int k, int l, int m, double *chi, double **S, double **I, double *I_uw) { register int ls, n, j; int local; double c1, c2, dtau_dw, dS_uw[4], dS_dw[4], w[3], chi_loc, S_loc[4], dtau_uw, chi_uw, S_uw[4], chi_dw, S_dw[4], P[4], Q[4][4], **R, K[4][4], K_uw[4][4]; R = matrix_double(4, 4); /* --- The first point is the intersection with the horizontal grid line -- -------------- */ chi_uw = Interpolate_3D(chi, geometry, &lc->stencil[0], l, m); StokesK_3D(nspect, geometry, &lc->stencil[0], l, m, chi_uw, K_uw); for (n = 0; n < 4; n++) { S_uw[n] = Interpolate_3D(S[n], geometry, &lc->stencil[0], l, m); I_uw[n] = Interpolate_3D(I[n], geometry, &lc->stencil[0], l, m); } chi_loc = Interpolate_3D(chi, geometry, &lc->stencil[1], l, m); dtau_uw = 0.5 * (chi_uw + chi_loc) * lc->stencil[0].ds; StokesK_3D(nspect, geometry, &lc->stencil[1], l, m, chi_loc, K); for (n = 0; n < 4; n++) S_loc[n] = Interpolate_3D(S[n], geometry, &lc->stencil[1], l, m); for (ls = 2; ls < lc->Nst; ls++) { if (ls == lc->Nst-1) { /* --- The last point is the the endpoint for which the non-local contribution is needed. -- -------------- */ local = k*geometry->Nplane + m*geometry->Nx + l; chi_dw = chi[local]; for (n = 0; n < 4; n++) S_dw[n] = S[n][local]; } else { chi_dw = Interpolate_3D(chi, geometry, &lc->stencil[ls], l, m); for (n = 0; n < 4; n++) S_dw[n] = Interpolate_3D(S[n], geometry, &lc->stencil[ls], l, m); } dtau_dw = 0.5 * (chi_loc + chi_dw) * lc->stencil[ls-1].ds; w3(dtau_uw, w); for (n = 0; n < 4; n++) { dS_uw[n] = (S_uw[n] - S_loc[n]) / dtau_uw; dS_dw[n] = (S_loc[n] - S_dw[n]) / dtau_dw; c1 = dS_uw[n]*dtau_dw + dS_dw[n]*dtau_uw; c2 = dS_uw[n] - dS_dw[n]; P[n] = w[0]*S_loc[n] + (w[1]*c1 + w[2]*c2) / (dtau_uw + dtau_dw); } for (n = 0; n < 4; n++) { for (j = 0; j < 4; j++) { Q[n][j] = -w[1]/dtau_uw * K_uw[n][j]; R[n][j] = (w[0] - w[1]/dtau_uw) * K[n][j]; } Q[n][n] = 1.0 - w[0]; R[n][n] = 1.0; } for (n = 0; n < 4; n++) { for (j = 0; j < 4; j++) P[n] += Q[n][j] * I_uw[j]; } /* --- Solve linear equations for I -- -------------- */ SolveLinearEq(4, R, P, TRUE); /* --- Store results for the upwind Stokes vector -- ------------ */ for (n = 0; n < 4; n++) I_uw[n] = P[n]; /* --- Reuse upwind quantities -- -------------- */ if (ls < lc->Nst-1) { chi_uw = chi_loc; chi_loc = chi_dw; dtau_uw = dtau_dw; for (n = 0; n < 4; n++) { S_uw[n] = S_loc[n]; S_loc[n] = S_dw[n]; for (j = 0; j < 4; j++) K_uw[n][j] = K[n][j]; } StokesK_3D(nspect, geometry, &lc->stencil[ls], l, m, chi_dw, K); } } freeMatrix((void **) R); }
static void on26_write_block( PIA *pi, char * buf, int count ) { int k; switch (pi->mode) { case 0: case 1: w0(1); P1; w0(1); P2; w0(2); P1; w0(0x18+pi->mode); P2; w0(0); P1; udelay(10); for (k=0;k<count/2;k++) { w2(5); w0(buf[2*k]); w2(7); w0(buf[2*k+1]); } w2(5); w2(4); w0(2); P1; w0(8+pi->mode); P2; break; case 2: w3(1); w3(1); w2(5); w4(1); w2(4); w3(0); w3(0); w2(0xc5); udelay(10); for (k=0;k<count;k++) w4(buf[k]); w2(0xc4); break; case 3: w3(1); w3(1); w2(5); w4(1); w2(4); w3(0); w3(0); w2(0xc5); udelay(10); for (k=0;k<count/2;k++) w4w(((u16 *)buf)[k]); w2(0xc4); break; case 4: w3(1); w3(1); w2(5); w4(1); w2(4); w3(0); w3(0); w2(0xc5); udelay(10); for (k=0;k<count/4;k++) w4l(((u32 *)buf)[k]); w2(0xc4); break; } }
void SolveShortStokes(Geometry *geometry, Stencil *st_uw, Stencil *st_dw, int nspect, int k, int kend, int l, int m, double *I_uw, double *chi, double **S, double **I, double *Psi) { /* --- Piecewise integration of the coupled Stokes transfer equations in two dimensions. Method is quasi-parabolic DELO method. See: - D. E. Rees, G. A. Murphy and C. J. Durrant 1989, ApJ 339, 1093-1106. - H. Socas Navarro, J. Trujillo Bueno and B. Ruiz Cobo 2000, "Non-LTE Inversion of Stokes Profiles", ApJ 530, 977. -- -------------- */ register int n, j; int local; double chi_uw, chi_dw, S_uw[4], S_dw[4], dS_dw[4], dS_uw[4], dtau_uw, dtau_dw, w[3], c1, c2, P[4], Q[4][4], **R, K[4][4], K_uw[4][4]; R = matrix_double(4, 4); local = k*geometry->Nplane + m*geometry->Nx + l; /* --- The upwind quantities -- -------------- */ chi_uw = Interpolate_3D(chi, geometry, st_uw, l, m); dtau_uw = 0.5 * (chi_uw + chi[local]) * st_uw->ds; StokesK_3D(nspect, geometry, st_uw, l, m, chi_uw, K_uw); for (n = 0; n < 4; n++) { S_uw[n] = Interpolate_3D(S[n], geometry, st_uw, l, m); dS_uw[n] = (S_uw[n] - S[n][local]) / dtau_uw; } StokesK(nspect, local, chi[local], K); if (k == kend) { w2(dtau_uw, w); /* --- Piecewise linear integration in last layer -- ------------ */ for (n = 0; n < 4; n++) { c1 = (S_uw[n] - S[n][local]) / dtau_uw; P[n] = w[0]*S[n][local] + w[1]*dS_uw[n]; } if (Psi) Psi[local] = w[0] - w[1]/dtau_uw; } else { w3(dtau_uw, w); /* --- The downwind quantities -- -------------- */ chi_dw = Interpolate_3D(chi, geometry, st_dw, l, m); dtau_dw = 0.5 * (chi[local] + chi_dw) * st_dw->ds; /* --- Piecewise quadratic integration -- -------------- */ for (n = 0; n < 4; n++) { S_dw[n] = Interpolate_3D(S[n], geometry, st_dw, l, m); dS_dw[n] = (S[n][local] - S_dw[n]) / dtau_dw; c1 = dS_uw[n]*dtau_dw + dS_dw[n]*dtau_uw; c2 = dS_uw[n] - dS_dw[n]; P[n] = w[0]*S[n][local] + (w[1]*c1 + w[2]*c2) / (dtau_uw + dtau_dw); } if (Psi) { c1 = dtau_uw - dtau_dw; Psi[local] = w[0] + (w[1]*c1 - w[2]) / (dtau_uw * dtau_dw); } } for (n = 0; n < 4; n++) { for (j = 0; j < 4; j++) { Q[n][j] = -w[1]/dtau_uw * K_uw[n][j]; R[n][j] = (w[0] - w[1]/dtau_uw) * K[n][j]; } Q[n][n] = 1.0 - w[0]; R[n][n] = 1.0; } for (n = 0; n < 4; n++) { for (j = 0; j < 4; j++) P[n] += Q[n][j] * I_uw[j]; } /* --- Solve linear equations for I -- -------------- */ SolveLinearEq(4, R, P, TRUE); /* --- Store results for Stokes vector -- -------------- */ for (n = 0; n < 4; n++) I[n][local] = P[n]; freeMatrix((void **) R); }