double IntervalGramian<WBASIS>::norm_Ainv() const { if (normAinv == 0.0) { typedef typename WaveletBasis::Index Index; std::set<Index> Lambda; const int j0 = basis().j0(); const int jmax = 8; for (Index lambda = first_generator(&basis(), j0);; ++lambda) { Lambda.insert(lambda); if (lambda == last_wavelet(&basis(), jmax)) break; } SparseMatrix<double> A_Lambda; setup_stiffness_matrix(*this, Lambda, A_Lambda); #if 1 double help; unsigned int iterations; LanczosIteration(A_Lambda, 1e-6, help, normA, 200, iterations); normAinv = 1./help; #else Vector<double> xk(Lambda.size(), false); xk = 1; unsigned int iterations; normAinv = InversePowerIteration(A_Lambda, xk, 1e-6, 200, iterations); #endif } return normAinv; }
const Matrix* Launcher::GetBIBasisMatrix(const Matrix* matrix, int toGroebner) const { if (!CheckMatrix(matrix)) { return NULL; } switch(GetSettingsManager().GetMonomialOrder()) { case Monom::Lex: { BooleanInvolutiveBasis<MonomLex> basis(matrix, toGroebner); return basis.ToMatrix(); } case Monom::DegLex: { BooleanInvolutiveBasis<MonomDL> basis(matrix, toGroebner); return basis.ToMatrix(); } case Monom::DegRevLex: { BooleanInvolutiveBasis<MonomDRL> basis(matrix, toGroebner); return basis.ToMatrix(); } default: return 0; }; }
Object3D::Object3D () { position = zero_vector<3, float> (); basis(0) = axis_vector<3, float> (0); basis(1) = axis_vector<3, float> (1); basis(2) = axis_vector<3, float> (2); }
TEMPLATE_HEADER typename LR::Data LR::solveNormalEqn( Coordinate & c, Neighbors & nset ){ if( y.size().rows != Basis::size ){ A.resize( Basis::size, Basis::size ); y.resize( Basis::size, 1); } // find bounds for points Coordinate lb = nset[0].point, rb = nset[0].point, tmp; for( int j = 0; j < Coordinate::Dims ; j++ ){ for( int i = 1; i < nset.size(); i++ ){ lb[j] = fmin(nset[i].point[j],lb[j]); rb[j] = fmax(nset[i].point[j],rb[j]); } } // compute weights std::vector<double> weights(nset.size()); wfunc(weights,nset); // store values for A A = 0; for(int j = 0; j < Basis::size; j++ ){ for( int k = j; k < Basis::size; k++ ){ for( int i = 0; i < nset.size(); i++ ){ scale(lb,rb,nset[i].point,tmp); A(j,k) += basis(k, tmp)*basis(j, tmp)*weights[i]; } } } // store values for y y = 0; for(int j = 0; j < Basis::size; j++ ){ for( int i = 0; i < nset.size(); i++ ){ scale(lb,rb,nset[i].point,tmp); y[j] += basis(j, tmp)*weights[i]*nset[i].data; } } // solve system of equations la::solve(A,y,coef); // compute point Data output = 0; for( int i = 0; i < Basis::size; i++ ){ scale(lb,rb,c,tmp); output += coef[i]*basis(i,tmp); } return output; }
int is_ok(int i) { int basis10[11]; int basis2[21]; int j; basis(basis2, 2, i); basis(basis10, 10, i); for (j=0; j<21; j++) { if (basis2[j]==-1) break; } return is_pal(basis2) && is_pal(basis10); }
void CSCPatch::eval_Amtx(const int &size_, const Coord &pos, std::vector<SmallMatrix*> &stored_pT) { SmallMatrix *pT = new SmallMatrix(size_, 1); SmallMatrix p(1, size_); for(int i=0; i<size_; i++) { (*pT)(i,0) = basis(i, pos); p(0,i) = basis(i, pos); } Amtx += (*pT)*p; stored_pT.push_back(pT); }
const Point3 BezierPatch::operator()(const double u, const double v, Vector3 &dp_du, Vector3 &dp_dv) const { // // Copy your previous (PA07) solution here. // double bs_u[4], bs_v[4], db_dus[4], db_dvs[4]; basis(u, bs_u, ( &dp_du ? &db_dus : NULL )); basis(v, bs_v, ( &dp_dv ? &db_dvs : NULL )); Point3 point(0, 0, 0); Point3 dp_du_temp(0, 0, 0); Point3 dp_dv_temp(0, 0, 0); for (int i = 0; i < 4; i++) { for (int j = 0; j < 4; j++) { Point3 controlPoint = cvs[i][j]; double Ri = bs_u[i]; double Rj = bs_v[j]; point += controlPoint * Ri * Rj; //TODO: Check this if (&dp_du != NULL) dp_du_temp += db_dus[i] * controlPoint; if (&dp_dv != NULL) dp_dv_temp += db_dvs[j] * controlPoint; } } if (&dp_du != NULL) dp_du = Vector3(dp_du_temp.u.a); if (&dp_dv != NULL) dp_dv = Vector3(dp_dv_temp.u.a); return point; // replace (permits template to compile cleanly) }
void ObjectRenderer::renderVehicle(VehicleObject* vehicle, RenderList& outList) { const auto& clump = vehicle->getClump(); RW_CHECK(clump, "Vehicle clump is null"); if (!clump) { return; } float mindist = glm::length(vehicle->getPosition() - m_camera.position) / kVehicleDrawDistanceFactor; if (mindist < kVehicleLODDistance) { // Swich visibility to the high LOD vehicle->getHighLOD()->setFlag(Atomic::ATOMIC_RENDER, true); vehicle->getLowLOD()->setFlag(Atomic::ATOMIC_RENDER, false); } else if (mindist < kVehicleDrawDistance) { // Switch to low vehicle->getHighLOD()->setFlag(Atomic::ATOMIC_RENDER, false); vehicle->getLowLOD()->setFlag(Atomic::ATOMIC_RENDER, true); } else { culled++; return; } renderClump(clump.get(), glm::mat4(), vehicle, outList); auto modelinfo = vehicle->getVehicle(); auto woi = m_world->data->findModelInfo<SimpleModelInfo>(modelinfo->wheelmodel_); if (!woi || !woi->isLoaded() || !woi->getDistanceAtomic(mindist)) { return; } auto wheelatomic = woi->getDistanceAtomic(mindist); for (size_t w = 0; w < vehicle->info->wheels.size(); ++w) { auto& wi = vehicle->physVehicle->getWheelInfo(w); // Construct our own matrix so we can use the local transform vehicle->physVehicle->updateWheelTransform(w, false); bool isRhino = (vehicle->getVehicle()->vehiclename_ == "RHINO"); auto up = -wi.m_wheelDirectionCS; auto right = wi.m_wheelAxleCS; auto fwd = up.cross(right); btQuaternion steerQ(up, (isRhino) ? 0.f : wi.m_steering); btQuaternion rollQ(right, -wi.m_rotation); btMatrix3x3 basis(right[0], fwd[0], up[0], right[1], fwd[1], up[1], right[2], fwd[2], up[2]); btTransform t( btMatrix3x3(steerQ) * btMatrix3x3(rollQ) * basis, wi.m_chassisConnectionPointCS + wi.m_wheelDirectionCS * wi.m_raycastInfo.m_suspensionLength); glm::mat4 wheelM; t.getOpenGLMatrix(glm::value_ptr(wheelM)); wheelM = clump->getFrame()->getWorldTransform() * wheelM; wheelM = glm::scale(wheelM, glm::vec3(modelinfo->wheelscale_)); if (wi.m_chassisConnectionPointCS.x() < 0.f) { wheelM = glm::scale(wheelM, glm::vec3(-1.f, 1.f, 1.f)); } renderAtomic(wheelatomic, wheelM, nullptr, outList); } }
void MO_matrix_blas::writeorb(ostream & os, Array2 <doublevar> & rotation, Array1 <int> &moList) { int nmo_write=moList.GetDim(0); assert(rotation.GetDim(0)==nmo_write); assert(rotation.GetDim(1)==nmo_write); os.precision(15); int counter=0; for(int m=0; m < nmo_write; m++) { int mo=moList(m); for(int ion=0; ion<centers.size(); ion++) { int f=0; for(int n=0; n< centers.nbasis(ion); n++) { int fnum=centers.basis(ion,n); int imax=basis(fnum)->nfunc(); for(int i=0; i<imax; i++) { os << mo+1 << " " << f+1 << " " << ion+1 << " " << counter+1 << endl; f++; //keep a total of functions on center counter++; } //i } //n } //ion } os << "COEFFICIENTS\n"; ifstream orbin(orbfile.c_str()); rotate_orb(orbin, os, rotation, moList, totbasis); orbin.close(); }
int main(int argc, char* argv[]) { // random seed initialization std::srand(std::time(0)); // Database initialization. DataSet basis(DATA_SIZE); int i=0; for(auto& data : basis) { data.first = i++; data.second.x = 1 + gaml::random::uniform(-1,1); data.second.y = 2 + gaml::random::uniform(-1,1); data.second.z = 3 + gaml::random::uniform(-1,1); } auto kfold_evaluator = gaml::risk::cross_validation(Loss(), gaml::partition::kfold(6), true); silly::Learner scalar_learner; auto learner = gaml::multidim::learner<Y,3>(scalar_learner, array_of_output, output_of_array); double risk = kfold_evaluator(learner, basis.begin(), basis.end(), input_of_data, output_of_data); auto predictor = learner(basis.begin(), basis.end(), input_of_data, output_of_data); Y output = predictor(0); std::cout << "output : {" << output.x << ", " << output.y << ", " << output.z << "}" << std::endl << "risk = " << risk << std::endl; return 0; }
FnMap::FnMap(const QStringList & images, int rank) : QHash<QChar, FnWord>() { // rank = 0 means build an endomorphism image_rank = (rank == 0) ? images.size() : rank; if (image_rank < Fn_MinRank || image_rank > Fn_MaxRank) { // check MIN_RANK <= rank <= MAX_RANK insert(BASIS.at(0),Fail); return; } if (images.size() < Fn_MinRank || images.size() > Fn_MaxRank) { insert(BASIS.at(0),Fail); return; } Basis basis(image_rank); for (int i = 0; i < images.size(); i++) { FnWord u(images.at(i)); if (!u.checkBasis(basis)) { insert(BASIS.at(0),Fail); return; } insert(BASIS.at(2*i),u); insert(BASIS.at(2*i+1),u.inverse()); } }
/* ************************************************************************* */ Vector2 Unit3::errorVector(const Unit3& q, OptionalJacobian<2, 2> H_p, OptionalJacobian<2, 2> H_q) const { // Get the point3 of this, and the derivative. Matrix32 H_qn_q; Point3 qn = q.point3(H_q ? &H_qn_q : 0); // 2D error here is projecting q into the tangent plane of this (p). Matrix62 H_B_p; Matrix23 Bt = basis(H_p ? &H_B_p : 0).transpose(); Vector2 xi = Bt * qn.vector(); if (H_p) { // Derivatives of each basis vector. const Matrix32& H_b1_p = H_B_p.block<3, 2>(0, 0); const Matrix32& H_b2_p = H_B_p.block<3, 2>(3, 0); // Derivatives of the two entries of xi wrt the basis vectors. Matrix13 H_xi1_b1 = qn.vector().transpose(); Matrix13 H_xi2_b2 = qn.vector().transpose(); // Assemble dxi/dp = dxi/dB * dB/dp. Matrix12 H_xi1_p = H_xi1_b1 * H_b1_p; Matrix12 H_xi2_p = H_xi2_b2 * H_b2_p; *H_p << H_xi1_p, H_xi2_p; } if (H_q) { // dxi/dq is given by dxi/dqu * dqu/dq, where qu is the unit vector of q. Matrix23 H_xi_qu = Bt; *H_q = H_xi_qu * H_qn_q; } return xi; }
TEUCHOS_UNIT_TEST( Stokhos_ProductBasisUtils, TotalOrderSparse3LTO ) { success = true; ordinal_type dim = setup.d; ordinal_type order = setup.p; // ordinal_type dim = 2; // ordinal_type order = 3; // 1-D bases Teuchos::Array< Teuchos::RCP<const Stokhos::OneDOrthogPolyBasis<ordinal_type,value_type> > > bases(dim); for (ordinal_type i=0; i<dim; i++) bases[i] = Teuchos::rcp(new Stokhos::LegendreBasis<ordinal_type,value_type>(order, true)); // Product basis typedef Stokhos::MultiIndex<ordinal_type> coeff_type; typedef Stokhos::LexographicLess<coeff_type> less_type; Stokhos::TotalOrderBasis<ordinal_type,value_type,less_type> basis( bases); // Build Cijk tensor typedef Stokhos::Sparse3Tensor<ordinal_type,value_type> Cijk_type; Teuchos::RCP<Cijk_type> Cijk = Stokhos::computeTripleProductTensorLTO(basis, true); // Build Cijk tensor using original approach Teuchos::RCP<Cijk_type> Cijk2 = basis.computeTripleProductTensor(); // Check sizes TEUCHOS_TEST_EQUALITY(Cijk->num_k(), Cijk2->num_k(), out, success); TEUCHOS_TEST_EQUALITY(Cijk->num_entries(), Cijk2->num_entries(), out, success); // Check tensors match for (Cijk_type::k_iterator k_it=Cijk2->k_begin(); k_it!=Cijk2->k_end(); ++k_it) { int k = Stokhos::index(k_it); for (Cijk_type::kj_iterator j_it = Cijk2->j_begin(k_it); j_it != Cijk2->j_end(k_it); ++j_it) { int j = Stokhos::index(j_it); for (Cijk_type::kji_iterator i_it = Cijk2->i_begin(j_it); i_it != Cijk2->i_end(j_it); ++i_it) { int i = Stokhos::index(i_it); double c = Cijk->getValue(i,j,k); double c2 = Stokhos::value(i_it); double tol = setup.atol + c2*setup.rtol; double err = std::abs(c-c2); bool s = err < tol; if (!s) { out << std::endl << "Check: rel_err( C(" << i << "," << j << "," << k << ") )" << " = " << "rel_err( " << c << ", " << c2 << " ) = " << err << " <= " << tol << " : "; if (s) out << "Passed."; else out << "Failed!"; out << std::endl; } success = success && s; } } } }
Matrix<double> BspCurvBasisFuncSet::CreateMatrixIntegral(int lev) const { KnotSet kset = KnotSet(*kts,ord,num).CreateKnotSetDeriv(lev); Matrix<double> mat(kset.GetNum()-(ord-lev),kset.GetNum()-(ord-lev)); BspCurvBasisFuncSet basis(kset.GetKnots(),ord-lev,kset.GetNum()); Matrix<double> mat1(kset.GetNum()-ord+lev,kset.GetNum()-ord+lev,0.0); for (int i=0; i<kset.GetNum()-ord+lev; i++) for (int j=0; j<=i; j++) { // create the two std::sets representing the two knot std::sets Vector<double> temp1((*(basis.b))[i].GetKnots()); Vector<double> temp2((*(basis.b))[j].GetKnots()); std::set<double> s1(temp1.begin(),temp1.end()); std::set<double> s2(temp2.begin(),temp2.end()); // if there is an intersection if (*(--s2.end()) > *(s1.begin())) { // form the intersection std::set<double> s3; std::set_intersection(s1.begin(),s1.end(),s2.begin(),s2.end(),std::inserter(s3,s3.begin())); // if there is an intersection if (s3.size() > 1) { Vector<double> v(s3.size()); std::set<double>::iterator s = s3.begin(); // copy the elements into a vector for (unsigned int k=0; k<s3.size(); k++) v[k] = *s++; // create the compbezcurvs Vector<BezCurv<double> > vec1(s3.size()-1); Vector<BezCurv<double> > vec2(s3.size()-1); BspCurv<double> b1((*(basis.b))[i].GetBspCurv()), b2((*(basis.b))[j].GetBspCurv()); // find the segments of intersection for (unsigned int k=0; k<s3.size()-1; k++) { int segb1 = b1.GetKnotSet().Find_segment(v[k]); int segb2 = b2.GetKnotSet().Find_segment(v[k]); vec1[k] = b1.GetSegment(segb1); vec2[k] = b2.GetSegment(segb2); } CompBezCurv<double> cb1(vec1,s3.size()-1,v); CompBezCurv<double> cb2(vec2,s3.size()-1,v); CompBezCurv<double> prod = cb1.Product(cb2); mat1[i][j] = prod.ConvertBspCurv().Integrate((*kts)[ord-1],(*kts)[num-ord]); } } } for (int i=0; i<kset.GetNum()-ord+lev-1; i++) for (int j=i+1; j<kset.GetNum()-ord+lev; j++) mat1[i][j] = mat1[j][i]; return mat1; }
/// private : Bullet形式とDirectX形式の変換 btTransform BulletPhysics::ConvertMatrixGLToBT(const glm::mat4& m) { btMatrix3x3 basis( // 鏡像変換+転置 m[0][0], m[1][0], m[2][0], m[0][1], m[1][1], m[2][1], m[0][2], m[1][2], m[2][2] ); return btTransform(basis, btVector3(m[3][0], m[3][1], m[3][2])); }
Matrix BasisIncompleteOrdered::getBasisAsRowsInMatrix() const { Matrix basis(currentBasis_.size(), euclideanDimension_); for (Size i=0; i<basis.rows(); ++i) for (Size j=0; j<basis.columns(); ++j) basis[i][j] = currentBasis_[i][j]; return basis; }
inline std::tuple<vector,vector,vector> orthonormal_basis(const vector& v) { vector v1 = v.normalize(); auto v2_and_v3 = basis(v1); return std::make_tuple(v1, std::get<0>(v2_and_v3), std::get<1>(v2_and_v3)); }
const GCTP_TYPEINFO *Class::getBase(const GCTP_TYPEINFO &typeinfo) { #ifdef GCTP_USE_STD_RTTI return basis().get(typeinfo); #else return typeinfo.getBase(); #endif }
int CachedQuarkletProblem<PROBLEM>::number (const Index& lambda, const int jmax) const{ WaveletBasis mybasis(basis()); const int waveletsonzerolevel = (mybasis.last_wavelet(jmax)).number()+1; const int waveletsonplevel = ((mybasis.last_wavelet(jmax,lambda.p())).number()+1); const int lambda_num = (lambda.p()==0) ? lambda.number() : lambda.number() + (lambda.p()-1) * waveletsonplevel + waveletsonzerolevel; return lambda_num; }
/* ************************************************************************* */ Vector2 Unit3::error(const Unit3& q, OptionalJacobian<2,2> H_q) const { // 2D error is equal to B'*q, as B is 3x2 matrix and q is 3x1 Matrix23 Bt = basis().transpose(); Vector2 xi = Bt * q.p_; if (H_q) { *H_q = Bt * q.basis(); } return xi; }
const GCTP_TYPEINFO *Class::getBase(const char *classname) { const GCTP_TYPEINFO *derived = get(classname); #ifdef GCTP_USE_STD_RTTI if(derived) return basis().get(*derived); return 0; #else return derived->getBase(); #endif }
void draw(GameRenderer* r) { glm::vec2 basis(offset); for (size_t i = 0; i < entries.size(); ++i) { bool active = false; if (activeEntry >= 0 && i == (unsigned)activeEntry) { active = true; } entries[i].draw(font, size, active, r, basis); } }
boost::shared_ptr<tmv::Matrix<double> > LVector::basis( const tmv::ConstVectorView<double>& x, const tmv::ConstVectorView<double>& y, int order, double sigma) { assert(x.size()==y.size()); boost::shared_ptr<tmv::Matrix<double> > psi( new tmv::Matrix<double>(x.size(), PQIndex::size(order))); basis(x, y, psi->view(), order, sigma); return psi; }
const Point3 BSplineCurve::operator()(const double u, Vector3 *dp_du) const { assert(0.0 <= u && u <= 1.0); int nKnot = ( isClosed ? nCvs : nCvs - 3 ); // map `u` to [ 0, nKnot ] double t = nKnot * u; // between 0 and nKnot, inclusive // `iKnot` is the integer part of t. It will determine the first // index of `cvs` that controls the part of the curve we're // interested in. int iKnot = (int) t; // truncates (always, since t >= 0) // Note that if `u` is 1.0, `iKnot` could now equal `nKnot` which // could cause trouble if we use it (with a value of 0 to 3, // inclusive added to it) to index `cvs`. The solution for this // depends on whether the curve is closed or not, and we'll take // care of it below. t -= iKnot; // `t` retains the fractional part if (!isClosed && iKnot == nKnot) { // If we don't (need to) use the modulus in the evaluation // loop below we really want `iKnot` less than `nKnot`, so if // iKnot is nCvs, decrement it and increment `t` (which is // almost certainly 0) by 1. The evaluation should be the same // because of continuity. assert(t == 1.0); // sanity check: the only time this should happen. iKnot = nKnot - 1; t = 1.0; } // compute the bases functions and, optionally, their derivatives double bs[4], db_dts[4]; basis(t, bs, ( dp_du ? &db_dts : NULL )); Point3 p(0,0,0), dp_dt(0,0,0); for (int i = 0; i < 4; i++) { int j; if (isClosed) j = (iKnot + i) % nCvs; // the modulus "wraps" the `cvs` indices else j = iKnot + i; assert(0 <= j && j < nCvs); p += bs[i] * cvs[j]; if (dp_du) dp_dt += db_dts[i] * cvs[j]; } if (dp_du) { // effectively, `nKnot` is dt/du *dp_du = Vector3(dp_dt.u.a) * nKnot; // derivative of spline is a vector } return p; }
bool ASMs1D::evalSolution (Matrix& sField, const Vector& locSol, const RealArray* gpar, bool, int deriv) const { const int p1 = curv->order(); size_t nComp = locSol.size() / curv->numCoefs(); Vector basis(p1), ptSol; Matrix dNdu, dNdX, Xnod, Xtmp, Jac, eSol, ptDer; Matrix3D d2Ndu2, d2NdX2, Hess, ptDer2; // Fetch nodal (control point) coordinates this->getNodalCoordinates(Xnod); // Evaluate the primary solution field at each point const RealArray& upar = *gpar; size_t nPoints = upar.size(); sField.resize(nComp*int(pow(nsd,deriv)),nPoints); for (size_t i = 0; i < nPoints; i++) { IntVec ip; switch (deriv) { case 0: // Evaluate the solution this->extractBasis(upar[i],basis); scatterInd(p1,curv->basis().lastKnotInterval(),ip); utl::gather(ip,nComp,locSol,Xtmp); Xtmp.multiply(basis,ptSol); sField.fillColumn(1+i,ptSol); break; case 1: // Evaluate first derivatives of the solution this->extractBasis(upar[i],basis,dNdu); scatterInd(p1,curv->basis().lastKnotInterval(),ip); utl::gather(ip,nsd,Xnod,Xtmp); utl::Jacobian(Jac,dNdX,Xtmp,dNdu); utl::gather(ip,nComp,locSol,Xtmp); ptDer.multiply(Xtmp,dNdX); sField.fillColumn(1+i,ptDer); break; case 2: // Evaluate second derivatives of the solution this->extractBasis(upar[i],basis,dNdu,d2Ndu2); scatterInd(p1,curv->basis().lastKnotInterval(),ip); utl::gather(ip,nsd,Xnod,Xtmp); utl::Jacobian(Jac,dNdX,Xtmp,dNdu); utl::Hessian(Hess,d2NdX2,Jac,Xtmp,d2Ndu2,dNdX); utl::gather(ip,nComp,locSol,Xtmp); ptDer2.multiply(Xtmp,d2NdX2); sField.fillColumn(1+i,ptDer2); break; } } return true; }
double SturmEquation<WBASIS>::norm_A() const { if (normA == 0.0) { typedef typename WaveletBasis::Index Index; std::set<Index> Lambda; const int j0 = basis().j0(); const int jmax = j0+3; #ifdef FRAME const int pmax = std::min(basis().get_pmax_(),2); //const int pmax = 0; int p = 0; for (Index lambda = basis().first_generator(j0,0);;) { Lambda.insert(lambda); if (lambda == basis().last_wavelet(jmax,pmax)) break; //if (i==7) break; if (lambda == basis().last_wavelet(jmax,p)) { ++p; lambda = basis().first_generator(j0,p); } else ++lambda; } #else for (Index lambda = first_generator(&basis(), j0);; ++lambda) { Lambda.insert(lambda); if (lambda == last_wavelet(&basis(), jmax)) break; } #endif SparseMatrix<double> A_Lambda; setup_stiffness_matrix(*this, Lambda, A_Lambda); #if 1 double help; unsigned int iterations; LanczosIteration(A_Lambda, 1e-6, help, normA, 200, iterations); normAinv = 1./help; #else Vector<double> xk(Lambda.size(), false); xk = 1; unsigned int iterations; normA = PowerIteration(A_Lambda, xk, 1e-6, 100, iterations); #endif } return normA; }
void CustomBallAndSocketWithFriction::SubmitConstraints(dFloat timestep, int threadIndex) { CustomBallAndSocket::SubmitConstraints(timestep, threadIndex); dVector omega0(0.0f, 0.0f, 0.0f, 0.0f); dVector omega1(0.0f, 0.0f, 0.0f, 0.0f); // get the omega vector NewtonBodyGetOmega(m_body0, &omega0[0]); if (m_body1) { NewtonBodyGetOmega(m_body1, &omega1[0]); } dVector relOmega(omega0 - omega1); dFloat omegaMag = dSqrt(relOmega % relOmega); if (omegaMag > 0.1f) { // tell newton to used this the friction of the omega vector to apply the rolling friction dMatrix basis(dGrammSchmidt(relOmega)); NewtonUserJointAddAngularRow(m_joint, 0.0f, &basis[2][0]); NewtonUserJointSetRowMinimumFriction(m_joint, -m_dryFriction); NewtonUserJointSetRowMaximumFriction(m_joint, m_dryFriction); NewtonUserJointAddAngularRow(m_joint, 0.0f, &basis[1][0]); NewtonUserJointSetRowMinimumFriction(m_joint, -m_dryFriction); NewtonUserJointSetRowMaximumFriction(m_joint, m_dryFriction); // calculate the acceleration to stop the ball in one time step dFloat invTimestep = (timestep > 0.0f) ? 1.0f / timestep : 1.0f; NewtonUserJointAddAngularRow(m_joint, 0.0f, &basis[0][0]); NewtonUserJointSetRowAcceleration(m_joint, -omegaMag * invTimestep); NewtonUserJointSetRowMinimumFriction(m_joint, -m_dryFriction); NewtonUserJointSetRowMaximumFriction(m_joint, m_dryFriction); } else { // when omega is too low this is correct but the small angle approximation theorem. dMatrix basis(dGetIdentityMatrix()); for (int i = 0; i < 3; i++) { NewtonUserJointAddAngularRow(m_joint, 0.0f, &basis[i][0]); NewtonUserJointSetRowMinimumFriction(m_joint, -m_dryFriction); NewtonUserJointSetRowMaximumFriction(m_joint, m_dryFriction); } } }
int main() { //set up basisvectors std::vector<std::vector<double> > basis(2,std::vector<double>(2)); basis[0][0] = 1; basis[0][1] = 0; basis[1][0] = 0; basis[1][1] = 1; //define lattice Lattice myLattice(2,basis); //set up cones Cone Sigma0 = Cone({{1,0},{0,1}},myLattice); Cone Sigma11 = Cone({{0,1},{-1,0}},myLattice); Cone Sigma12 = Cone({{-1,0},{-1,-1}},myLattice); Cone Sigma13 = Cone({{-1,-1},{-2,-3}},myLattice); Cone Sigma21 = Cone({{-2,-3},{-1,-2}},myLattice); Cone Sigma22 = Cone({{-1,-2},{0,-1}},myLattice); Cone Sigma23 = Cone({{0,-1},{1,0}},myLattice); //Define fan std::vector<Cone> myCones = {Sigma0, Sigma11, Sigma12, Sigma13, Sigma21, Sigma22, Sigma23}; Fan myFan(myCones,myLattice); //Get dual fan Fan myDualFan = myFan.getCorrespondingDualFan(); std::vector<Cone> myDualCones = myDualFan.getCones(); std::cout << "CONES OF THE DUAL FAN" << std::endl; std::cout << "----------------------" << std::endl; for(int i = 0; i < myDualCones.size();++i) { std::cout << "Cone nr = " << i << std::endl; Cone myDualCone = myDualCones[i]; std::vector<std::vector<double> > myBVs = myDualCone.getBasisVectors(); std::cout << " " << myBVs[0][0] << std::endl; std::cout << "Ray 1 = " << myBVs[0][1] << std::endl; std::cout << " " << myBVs[0][2] << std::endl; std::cout << "" << std::endl; std::cout << " " << myBVs[1][0] << std::endl; std::cout << "Ray 2 = " << myBVs[1][1] << std::endl; std::cout << " " << myBVs[1][2] << std::endl; std::cout << "----------------------" << std::endl; } myFan.drawFan(); myDualFan.drawFan(); return 0; }
void CSCPatch::recover_this_flux(const int &size_, const Node *nd, const int &coef_index, const Flux *fluks) { // values of the recovered flux DoubleVec *fvalues = new DoubleVec(fluks->ndof(), 0.0); const Coord pos = nd->position(); SmallMatrix *bmtx = coefficients[coef_index]; for(int i=0; i<fluks->ndof(); i++) for (int j=0; j<size_; j++) (*fvalues)[i] += basis(j, pos) * (*bmtx)(j, i); subproblem->add_this_flux(material_, fluks, nd, fvalues); }
int MO_matrix_blas::showinfo(ostream & os) { os << "Blas MO " << endl; os << "Number of molecular orbitals: " << nmo << endl; string indent=" "; os << "Basis functions: \n"; for(int i=0; i< basis.GetDim(0); i++) { basis(i)->showinfo(indent, os); } return 1; }