Exemplo n.º 1
1
StandardPVFieldPtr StandardPVField::getStandardPVField()
{
    static StandardPVFieldPtr standardPVField;
    static Mutex mutex;
    Lock xx(mutex);

    if(standardPVField.get()==NULL) {
        standardPVField= StandardPVFieldPtr(new StandardPVField());
    }
    return standardPVField;
}
Exemplo n.º 2
0
// 布の形状の更新
void updateCloth(void) {
    // ★ 次の手順で質点の位置を決定する
    //clothのみがグローバル変数
    // 1. 質点に働く力を求める
    // 質点のfの定義
    for(int y = 0; y < POINT_NUM; y++) {
        for(int x = 0; x < POINT_NUM; x++) {
            cloth->points[x][y].f.set(0,0,0);
        }
    }
    //バネによる力を考える
    for(int i = 0; i < cloth->springs.size(); i++) {
        Vector3d nowlength(cloth->springs[i]->p0->p - cloth->springs[i]->p1->p);
        double gap = nowlength.length() - cloth->springs[i]->restLength;
        double strpower = Ks * gap; 
        //p1-p0
        Vector3d attraction(cloth->springs[i]->p1->p.x - cloth->springs[i]->p0->p.x,
                            cloth->springs[i]->p1->p.y - cloth->springs[i]->p0->p.y,
                            cloth->springs[i]->p1->p.z - cloth->springs[i]->p0->p.z);  
        attraction.normalize();
        attraction.scale(strpower);
        cloth->springs[i]->p0->f += attraction; 
        //向きを反転
        attraction.scale(-1);
        cloth->springs[i]->p1->f += attraction;
    }
    //重力M*gを加える
    //ついでに空気抵抗を考える
    for(int y = 0; y < POINT_NUM; y++) { 
        for(int x = 0; x < POINT_NUM; x++) {
           Vector3d grav(Mass*gravity.x,Mass*gravity.y,Mass*gravity.z);
           cloth->points[x][y].f +=  grav;
           Vector3d airresister(Dk*cloth->points[x][y].v.x,Dk*cloth->points[x][y].v.y,Dk*cloth->points[x][y].v.z);
           cloth->points[x][y].f -= airresister;
        }
    }

            // 2. 質点の加速度を求める
            // 3. 質点の速度を更新する
            // 4. 質点の位置を更新する
    for(int y = 0; y < POINT_NUM; y++){
        for(int x = 0; x < POINT_NUM; x++) {
            //加速度accelを求めてdTを掛けた
            if(!(cloth->points[x][y].bFixed)){
                Vector3d accel(cloth->points[x][y].f.x/Mass*dT,cloth->points[x][y].f.y/Mass*dT,cloth->points[x][y].f.z/Mass*dT);
                //質点の速度
                cloth->points[x][y].v += accel;
                //質点の位置
                Vector3d xx(cloth->points[x][y].v.x*dT,cloth->points[x][y].v.y*dT,cloth->points[x][y].v.z*dT);
                cloth->points[x][y].p += xx;
            }
        }
    }
}
Exemplo n.º 3
0
void PvaClientMonitor::destroy()
{
    {
        Lock xx(mutex);
        if(isDestroyed) return;
        isDestroyed = true;
    }
    if(monitor) monitor->destroy();
    monitor.reset();
    monitorElement.reset();
}
Exemplo n.º 4
0
Executor::~Executor()
{
    execute(shutdown);
    stopped.wait();
    // The thread signals 'stopped' while still holding
    // the lock.  By taking it we wait for the run() function
    // to actually return
    Lock xx(mutex);
    head.reset();
    tail.reset();
}
Exemplo n.º 5
0
/* >>> start tutorial code >>> */
int main( ){


    USING_NAMESPACE_ACADO

    // DEFINE VALRIABLES:
    // ---------------------------
    DVector                 b(3)  ;
    DifferentialState      x("", 2, 2);
    Function               f     ;


    // DEFINE THE VECTOR AND MATRIX ENTRIES:
    // -------------------------------------
    b(0)   = 1.0;  b(1)   = 1.0;  b(2)   = 1.0;


    // DEFINE A TEST FUNCTION:
    // -----------------------
    f << x.getInverse();


    // TEST THE FUNCTION f:
    // --------------------
    EvaluationPoint zz(f);

    DVector xx(4);

    xx(0) = 2.0;
    xx(1) = 0.1;
    xx(2) = 0.0;
    xx(3) = 2.0;

    zz.setX( xx );

    // EVALUATE f AT THE POINT  (tt,xx):
    // ---------------------------------
    std::cout << "f: " << std::endl << f.evaluate( zz ) << std::endl;

    return 0;
}
Exemplo n.º 6
0
Tmatrix<Interval> EllipsoidalIntegrator::integrate( double t0, double tf, int M,
													const Tmatrix<Interval> &x,
													const Tmatrix<Interval> &p,
													const Tmatrix<Interval> &w ){

  
	typedef TaylorVariable<Interval> T;
	
	Tmatrix< TaylorVariable<Interval> > xx(x.getDim());
	
	Tmatrix<T> *pp = 0;
	Tmatrix<T> *ww = 0;
	
	if( p.getDim() > 0 ) pp = new Tmatrix<T>(p.getDim());
	if( w.getDim() > 0 ) ww = new Tmatrix<T>(w.getDim());
	
	int nn = 0;
	for( int i=0; i<(int) x.getDim(); i++ ) if( diam(x(i)) > EQUALITY_EPS ) nn++;
	for( int i=0; i<(int) p.getDim(); i++ ) if( diam(p(i)) > EQUALITY_EPS ) nn++;
	for( int i=0; i<(int) w.getDim(); i++ ) if( diam(w(i)) > EQUALITY_EPS ) nn++;
	
	TaylorModel<Interval> Mod( nn, M );
	
	nn = 0;
	for( int i=0; i<(int) x.getDim(); i++ ){
		if( diam(x(i)) > EQUALITY_EPS ){ xx(i) = T( &Mod, nn, x(i) ); nn++; }
		else xx(i) = x(i);
	}
	for( int i=0; i<(int) p.getDim(); i++ ){
		if( diam(p(i)) > EQUALITY_EPS ){ pp->operator()(i) = T( &Mod, nn, p(i) ); nn++; }
		else pp->operator()(i) = p(i);
	}
	for( int i=0; i<(int) w.getDim(); i++ ){
		if( diam(w(i)) > EQUALITY_EPS ){ ww->operator()(i) = T( &Mod, nn, w(i) ); nn++; }
		else ww->operator()(i) = w(i);
	}
	
	integrate( t0, tf, &xx, pp, ww );
	
	return getStateBound( xx );
}
Exemplo n.º 7
0
 //! method to overload to compute grad_f, the first derivative of
 //  the cost function with respect to x
 virtual void gradient(Array& grad, const Array& x) const {
     Real eps = finiteDifferenceEpsilon(), fp, fm;
     Array xx(x);
     for (Size i=0; i<x.size(); i++) {
         xx[i] += eps;
         fp = value(xx);
         xx[i] -= 2.0*eps;
         fm = value(xx);
         grad[i] = 0.5*(fp - fm)/eps;
         xx[i] = x[i];
     }
 }
Exemplo n.º 8
0
void SVD::solve(MatDoub_I &b, MatDoub_O &x, Doub thresh = -1.)
{
	int i,j,m=b.ncols();
	if (b.nrows() != n || x.nrows() != n || b.ncols() != x.ncols())
		throw("SVD::solve bad sizes");
	VecDoub xx(n);
	for (j=0;j<m;j++) {
		for (i=0;i<n;i++) xx[i] = b[i][j];
		solve(xx,xx,thresh);
		for (i=0;i<n;i++) x[i][j] = xx[i];
	}
}
Exemplo n.º 9
0
void Executor::execute(CommandPtr const & command)
{
    Lock xx(mutex);
    command->next.reset();
    if(head.get()==NULL) {
        head = command;
        moreWork.signal();
        return;
    }
    if(tail.get()==NULL) return;
    tail->next = command;   
}
Exemplo n.º 10
0
 static void PvaClientBeingDestroyed() {
     size_t numLeft = 0;
     {
          Lock xx(mutex);
          --numberPvaClient;
           numLeft = numberPvaClient;
     }
     if(numLeft<=0) {
         ClientFactory::stop();
         CAClientFactory::stop();
     }
 }
Exemplo n.º 11
0
  static void apply( const matrix_type & A ,
                     const multi_vector_type & x ,
                     const multi_vector_type & y ,
                     const std::vector<Ordinal> & col_indices )
  {
    CudaSparseSingleton & s = CudaSparseSingleton::singleton();
    const double alpha = 1 , beta = 0 ;
    const int n = A.graph.row_map.dimension_0() - 1 ;
    const int nz = A.graph.entries.dimension_0();
    const size_t ncol = col_indices.size();

    // Copy columns of x into a contiguous vector
    vector_type xx( Kokkos::allocate_without_initializing, "xx" , n * ncol );
    vector_type yy( Kokkos::allocate_without_initializing, "yy" , n * ncol );

    for (size_t col=0; col<ncol; col++) {
      const std::pair< size_t , size_t > span( n * col , n * ( col + 1 ) );
      vector_type xx_view = Kokkos::subview<vector_type>( xx , span );
      vector_type x_col =
        Kokkos::subview<vector_type>( x, Kokkos::ALL(), col_indices[col] );
      Kokkos::deep_copy(xx_view, x_col);
    }

    // Sparse matrix-times-multivector
    cusparseStatus_t status =
      cusparseDcsrmm( s.handle ,
                      CUSPARSE_OPERATION_NON_TRANSPOSE ,
                      n , ncol , n , nz ,
                      &alpha ,
                      s.descra ,
                      A.values.ptr_on_device() ,
                      A.graph.row_map.ptr_on_device() ,
                      A.graph.entries.ptr_on_device() ,
                      xx.ptr_on_device() ,
                      n ,
                      &beta ,
                      yy.ptr_on_device() ,
                      n );

    if ( CUSPARSE_STATUS_SUCCESS != status ) {
      throw std::runtime_error( std::string("ERROR - cusparseDcsrmv " ) );
    }

    // Copy columns out of continguous multivector
    for (size_t col=0; col<ncol; col++) {
      const std::pair< size_t , size_t > span( n * col , n * ( col + 1 ) );
      vector_type yy_view = Kokkos::subview<vector_type>( yy , span );
      vector_type y_col =
        Kokkos::subview<vector_type>( y, Kokkos::ALL(), col_indices[col] );
      Kokkos::deep_copy(y_col, yy_view );
    }
  }
Exemplo n.º 12
0
void Executor::execute(CommandPtr const & command)
{
    Lock xx(mutex);
    command->next.reset();
    if(!head.get()) {
        head = command;
        moreWork.signal();
        return;
    }
    CommandPtr tail = head;
    while(tail->next) tail = tail->next;
    tail->next = command;   
}
Exemplo n.º 13
0
StandardFieldPtr StandardField::getStandardField()
{
    static StandardFieldPtr standardFieldCreate;
    static Mutex mutex;
    Lock xx(mutex);

    if(standardFieldCreate.get()==0)
    {
        standardFieldCreate = StandardFieldPtr(new StandardField());
        standardFieldCreate->init();
    }
    return standardFieldCreate;
}
Exemplo n.º 14
0
    bool NoxSolver<Scalar>::computeF(const Epetra_Vector &x, Epetra_Vector &f, FillType flag)
    {
      EpetraVector<Scalar> xx(x);  // wrap our structures around core Epetra objects
      EpetraVector<Scalar> rhs(f);

      rhs.zero();

      Scalar* coeff_vec = new Scalar[xx.length()];
      xx.extract(coeff_vec);
      this->dp->assemble(coeff_vec, NULL, &rhs); // NULL is for the global matrix.
      delete [] coeff_vec;

      return true;
    }
Exemplo n.º 15
0
bool NoxProblemInterface::computeF(const Epetra_Vector &x, Epetra_Vector &f, FillType flag)
{
  EpetraVector xx(x);  // wrap our structures around core Epetra objects
  EpetraVector rhs(f);

  rhs.zero();
  
  scalar* coeff_vec = new scalar[xx.length()];
  xx.extract(coeff_vec);
  fep->assemble(coeff_vec, NULL, &rhs); // NULL is for the global matrix.
  delete [] coeff_vec;
  
  return true;
}
Exemplo n.º 16
0
 connection::connection(boost::asio::io_service& ios, const std::string& request_id_header) :
     _io_service(ios),
     _request_id_header_tag(request_id_header),
     _waiting_for_async_reply(false),
     _request_complete(false),
     _keep_alive(false)
 {
     {
         csi::spinlock::scoped_lock xx(s_spinlock);
         s_context_count++;
     }
     _parser.data = this; // this is the wrong "this" since this is a baseclass... dont call any virtuals from this
     http_parser_init(&_parser, HTTP_REQUEST);
 }
Exemplo n.º 17
0
 static void PvaClientBeingConstructed()
 {
     bool saveFirst = false;
     { 
          Lock xx(mutex);
          ++numberPvaClient;
          saveFirst = firstTime;
          firstTime = false;
     }
     if(saveFirst) {
         ClientFactory::start();
         CAClientFactory::start();
     }
 }
Exemplo n.º 18
0
 //! method to overload to compute J_f, the jacobian of
 // the cost function with respect to x
 virtual void jacobian(Matrix &jac, const Array &x) const {
     Real eps = finiteDifferenceEpsilon();
     Array xx(x), fp, fm;
     for(Size i=0; i<x.size(); ++i) {
         xx[i] += eps;
         fp = values(xx);
         xx[i] -= 2.0*eps;
         fm = values(xx);
         for(Size j=0; j<fp.size(); ++j) {
             jac[j][i] = 0.5*(fp[j]-fm[j])/eps;
         }
         xx[i] = x[i];
     }
 }
/* >>> start tutorial code >>> */
int main( ){

    USING_NAMESPACE_ACADO

    // DEFINE VALRIABLES:
    // ---------------------------
       DifferentialState x, y;
       Function f;

       f << x*x + pow(y,2);

    // TEST THE FUNCTION f:
    // --------------------
       EvaluationPoint  z(f);
       EvaluationPoint dz(f);

       Vector xx(2);  Vector dx(2);

       xx(0) =  1.0;  dx(0) =  0.5;
       xx(1) =  1.0;  dx(1) =  0.1;

       z.setX( xx );  dz.setX( dx );


    // FORWARD DIFFERENTIATION:
    // ------------------------
       Vector ff = f.evaluate  ( z  );
       Vector df = f.AD_forward( dz );


    // PRINT THE RESULTS:
    // ------------------
       ff.print("result of evaluation      \n");
       df.print("result for the derivative \n");

    return 0;
}
Exemplo n.º 20
0
int main( ){

    USING_NAMESPACE_ACADO

    // DEFINE VARIABLES:
    // -----------------------
       DifferentialState x, y;
       IntermediateState z   ;
       Function f;

       z = 1.0;

       int run1;

       for( run1 = 0; run1 < 5; run1++ )
            z += sin( z + x*y );

       f << z;


    // TEST THE FUNCTION f:
    // --------------------
       EvaluationPoint zz(f);

       Vector xx(2);
       xx.setZero();
       xx(0) = 2.0;
       xx(1) = 0.0;

       zz.setX(xx);

       Vector result = f.evaluate( zz );
       result.print("result");

    return 0;
}
Exemplo n.º 21
0
int main()
{
	int key = 0;
	lex LL("Test");
	std::vector<std::string> xx(128);
	Create_ID_Map(xx);
	key = LL.gettok();
	while (key)
	{
		std::cout << xx[key];
		key = LL.gettok();
	}
	
	return 0;
}
Exemplo n.º 22
0
DbPvProviderPtr getDbPvProvider()
{
    static DbPvProviderPtr dbPvProvider;
    static Mutex mutex;
    Lock xx(mutex);

    if(dbPvProvider.get()==0) {
        CAServerSecurityPlugin::shared_pointer cssp(new CAServerSecurityPlugin());
        SecurityPluginRegistry::instance().installServerSecurityPlugin(cssp);
        dbPvProvider = DbPvProviderPtr(new DbPvProvider());
        ChannelProvider::shared_pointer xxx = dynamic_pointer_cast<ChannelProvider>(dbPvProvider);
        dbPvProvider->channelFinder = SyncChannelFind::shared_pointer(new SyncChannelFind(xxx));
        DbPvProviderFactory::create(dbPvProvider);
    }
    return dbPvProvider;
}
Exemplo n.º 23
0
void Timer::dump(std::ostream& o)
{
    Lock xx(mutex);
    if(!alive) return;
    TimeStamp currentTime;
    TimerCallbackPtr nodeToCall(head);
    currentTime.getCurrent();
    while(true) {
        if(nodeToCall.get()==NULL) return;
        TimeStamp timeToRun = nodeToCall->timeToRun;
        double period = nodeToCall->period;
        double diff = TimeStamp::diff(timeToRun,currentTime);
        o << "timeToRun " << diff << " period " << period << std::endl;
        nodeToCall = nodeToCall->next;
    }
}
ChannelProviderLocalPtr getChannelProviderLocal()
{
    static ChannelProviderLocalPtr channelProviderLocal;
    static Mutex mutex;
    Lock xx(mutex);
    if(channelProviderLocal.get()==NULL) {
        channelProviderLocal = ChannelProviderLocalPtr(
            new ChannelProviderLocal());
        ChannelProvider::shared_pointer xxx =
            dynamic_pointer_cast<ChannelProvider>(channelProviderLocal);
        channelProviderLocal->channelFinder =
            SyncChannelFind::shared_pointer(new SyncChannelFind(xxx));
        LocalChannelProviderFactory::create(channelProviderLocal);
    }
    return channelProviderLocal;
}
Exemplo n.º 25
0
  static void apply( const matrix_type & A ,
                     const std::vector<vector_type> & x ,
                     const std::vector<vector_type> & y )
  {
    CudaSparseSingleton & s = CudaSparseSingleton::singleton();
    const double alpha = 1 , beta = 0 ;
    const int n = A.graph.row_map.dimension(0) - 1 ;
    // const int nz = A.graph.entry_count();
    const size_t ncol = x.size();

    // Copy columns of x into a contiguous vector
    vector_type xx( "xx" , n * ncol );
    vector_type yy( "yy" , n * ncol );

    for (size_t col=0; col<ncol; col++) {
      const std::pair< size_t , size_t > span( n * col , n * ( col + 1 ) );
      const vector_type xx_view( xx , span );
      KokkosArray::deep_copy(xx_view, x[col]);
    }

    // Sparse matrix-times-multivector
    cusparseStatus_t status =
      cusparseDcsrmm( s.handle ,
		      CUSPARSE_OPERATION_NON_TRANSPOSE ,
		      n , ncol , n , 
		      alpha ,
		      s.descra ,
		      A.values.ptr_on_device() ,
		      A.graph.row_map.ptr_on_device() ,
		      A.graph.entries.ptr_on_device() ,
		      xx.ptr_on_device() , 
		      n , 
		      beta ,
		      yy.ptr_on_device() ,
		      n );
    
    if ( CUSPARSE_STATUS_SUCCESS != status ) {
      throw std::runtime_error( std::string("ERROR - cusparseDcsrmv " ) );
    }
    
    // Copy columns out of continguous multivector
    for (size_t col=0; col<ncol; col++) {
      const std::pair< size_t , size_t > span( n * col , n * ( col + 1 ) );
      const vector_type yy_view( yy , span );
      KokkosArray::deep_copy(y[col], yy_view );
    }
  }
Exemplo n.º 26
0
bool NoxProblemInterface::computeF(const Epetra_Vector &x, Epetra_Vector &f, FillType flag)
{
  _F_
  EpetraVector xx(x);			// wrap our structures around core Epetra objects
  EpetraVector rhs(f);

  Timer tmr;
  tmr.start();

  // The first NULL is for the global matrix, the other for the Dir vector.
  fep.assemble(&xx, NULL, &rhs, NULL);

  tmr.stop();
  assembly_time += tmr.get_seconds();

  return true;
}
Exemplo n.º 27
0
Timer::~Timer() {
    {
        Lock xx(mutex);
        alive = false;
    }
    waitForWork.signal();
    waitForDone.wait();
    TimerCallbackPtr timerCallback;
    while(true) {
        timerCallback = head;
        if(head.get()==NULL) break;
        head->timerStopped();
        head = timerCallback->next;
        timerCallback->next.reset();
        timerCallback->onList = false;
    }
}
Exemplo n.º 28
0
bool NoxProblemInterface::computeF(const Epetra_Vector &x, Epetra_Vector &f, FillType flag)
{
	_F_
	EpetraVector xx(x);			// wrap our structures around core Epetra objects
	EpetraVector rhs(f);

	Timer tmr;
	tmr.start();

	rhs.zero();
	fep.assemble(&xx, &rhs, NULL);

	tmr.stop();
	assembly_time += tmr.get_seconds();

	return true;
}
Exemplo n.º 29
0
StringArrayPtr AlarmSeverityFunc::getSeverityNames()
{
    static size_t severityCount = 5;
    static StringArrayPtr severityNames;
    static Mutex mutex;
    Lock xx(mutex);
    if(severityNames.get()==NULL) {
        severityNames = StringArrayPtr(new StringArray());
        severityNames->reserve(severityCount);
        severityNames->push_back("NONE");
        severityNames->push_back("MINOR");
        severityNames->push_back("MAJOR");
        severityNames->push_back("INVALID");
        severityNames->push_back("UNDEFINED");
    }
    return severityNames;
}
Exemplo n.º 30
0
    bool NoxSolver<Scalar>::computeJacobian(const Epetra_Vector &x, Epetra_Operator &op)
    {
      Epetra_RowMatrix *jac = dynamic_cast<Epetra_RowMatrix *>(&op);
      assert(jac != NULL);

      EpetraVector<Scalar> xx(x);			// wrap our structures around core Epetra objects
      EpetraMatrix<Scalar> jacobian(*jac);

      jacobian.zero();

      Scalar* coeff_vec = new Scalar[xx.length()];
      xx.extract(coeff_vec);
      this->dp->assemble(coeff_vec, &jacobian, NULL); // NULL is for the right-hand side.
      delete [] coeff_vec;
      //jacobian.finish();

      return true;
    }