コード例 #1
0
ファイル: util.c プロジェクト: nickmunson/pong
double angle_dist(double a1, double a2) {
	a1 = amod(a1);
	a2 = amod(a2);

	if (a1 > a2) {
		return a1 - a2;
	}
	else {
		return a2 - a1;
	}
}
コード例 #2
0
void rec_lobatto( Teuchos::LAPACK<int,Real> &lapack,
                  const double xl1, 
                  const double xl2,
                  ROL::Vector<Real> &a,
                  ROL::Vector<Real> &b ) {

    Teuchos::RCP<std::vector<Real> > ap = 
        Teuchos::rcp_const_cast<std::vector<Real> >((Teuchos::dyn_cast<ROL::StdVector<Real> >(a)).getVector()); 
    Teuchos::RCP<std::vector<Real> > bp = 
        Teuchos::rcp_const_cast<std::vector<Real> >((Teuchos::dyn_cast<ROL::StdVector<Real> >(b)).getVector()); 


    const int N = ap->size()-1;

    Teuchos::RCP<std::vector<Real> > amodp = Teuchos::rcp(new std::vector<Real> (N,0.0));
    Teuchos::RCP<std::vector<Real> > bmodp = Teuchos::rcp(new std::vector<Real> (N-1,0.0));
    Teuchos::RCP<std::vector<Real> > enp   = Teuchos::rcp(new std::vector<Real> (N,0.0));
    Teuchos::RCP<std::vector<Real> > gp    = Teuchos::rcp(new std::vector<Real> (N,0.0));

    // Nth canonical vector
    (*enp)[N-1] = 1.0;

    for(int i=0;i<N-1;++i) {
        (*bmodp)[i] = sqrt((*bp)[i+1]);
    }

    for(int i=0;i<N;++i) {
        (*amodp)[i] = (*ap)[i]-xl1;
    }
    
    ROL::StdVector<Real> amod(amodp);  
    ROL::StdVector<Real> bmod(bmodp);  
    ROL::StdVector<Real> en(enp);  
    ROL::StdVector<Real> g(gp);  

    trisolve(lapack,bmod,amod,bmod,en,g);         
    Real g1 = (*gp)[N-1];

    for(int i=0;i<N;++i) {
        (*amodp)[i] = (*ap)[i]-xl2;
    }
    

    trisolve(lapack,bmod,amod,bmod,en,g);         
    Real g2 = (*gp)[N-1];

    (*ap)[N] = (g1*xl2-g2*xl1)/(g1-g2);
    (*bp)[N] = (xl2-xl1)/(g1-g2);
    
}