Ejemplo n.º 1
0
SEXP updateFaceNormals(SEXP vb_, SEXP it_) {
  try {
    NumericMatrix vb(vb_);
    IntegerMatrix it(it_);
    mat vbA(vb.begin(),vb.nrow(),vb.ncol());
    mat normals(it.nrow(), it.ncol()); normals.fill(0.0);
    imat itA(it.begin(),it.nrow(),it.ncol());
    int nit = it.ncol();
    colvec tmp0(3), tmp1(3), ntmp(3);
    for (int i=0; i < nit; ++i) {
      tmp0 = vbA.col(itA(1,i))-vbA.col(itA(0,i));
      tmp1 = vbA.col(itA(2,i))-vbA.col(itA(0,i));
    
      crosspArma(tmp0,tmp1,ntmp);
      double nlen = norm(ntmp,2);
      if (nlen > 0)
	ntmp /= nlen; 
      normals.col(i) = ntmp;
    
    }
    return Rcpp::wrap(normals);
  } catch (std::exception& e) {
    ::Rf_error( e.what());
  } catch (...) {
    ::Rf_error("unknown exception");
  }
}
Ejemplo n.º 2
0
SEXP updateVertexNormals(SEXP vb_, SEXP it_,SEXP angweight_) {
  try {
    typedef unsigned int uint;
    bool angweight = Rcpp::as<bool>(angweight_);
    NumericMatrix vb(vb_);
    IntegerMatrix it(it_);
    mat vbA(vb.begin(),vb.nrow(),vb.ncol());
    mat normals = vbA*0;
    imat itA(it.begin(),it.nrow(),it.ncol());
    //setup vectors to store temporary data
    colvec tmp0(3), tmp1(3), tmp2(3), angtmp(3), ntmp(3);
    int nit = it.ncol();
    for (int i=0; i < nit; ++i) {
      tmp0 = vbA.col(itA(1,i))-vbA.col(itA(0,i));
      tmp1 = vbA.col(itA(2,i))-vbA.col(itA(0,i));
      if (angweight) {
	tmp2 = vbA.col(itA(1,i))-vbA.col(itA(2,i));
	angtmp(0) = angcalcArma(tmp0,tmp1);
	angtmp(1) = angcalcArma(tmp0, tmp2);
	angtmp(2) = angcalcArma(-tmp1, tmp2);
      }
      crosspArma(tmp0,tmp1,ntmp);
      for (int j=0; j < 3; ++j) {
	double co = dot(normals.col(itA(j,i)),ntmp);
      
	if (co < 0)  {
	  if (!angweight) {
	    normals.col(itA(j,i)) -= ntmp;
	  } else {
	    normals.col(itA(j,i)) -= ntmp*angtmp(j);
	  }
	} else {
	  if (! angweight) {
	    normals.col(itA(j,i)) += ntmp;
	  } else {
	    normals.col(itA(j,i)) += ntmp*angtmp(j);
	  }
	}
      }
    }
    for (uint i=0; i < normals.n_cols; ++i) {
      double nlen = norm(normals.col(i),2);
      if (nlen > 0)
	normals.col(i) /= nlen;
    }
		       
    return Rcpp::wrap(normals);
  } catch (std::exception& e) {
    ::Rf_error( e.what());
  } catch (...) {
    ::Rf_error("unknown exception");
  }
}
Ejemplo n.º 3
0
int EEBeamColumn2d::update()
{
    int rValue = 0;

    // get current time
    Domain *theDomain = this->getDomain();
    (*t)(0) = theDomain->getCurrentTime();

    // update the coordinate transformation
    theCoordTransf->update();

    // determine dsp, vel and acc in basic system A
    const Vector &dbA = theCoordTransf->getBasicTrialDisp();
    const Vector &vbA = theCoordTransf->getBasicTrialVel();
    const Vector &abA = theCoordTransf->getBasicTrialAccel();
    const Vector &dbDeltaA = theCoordTransf->getBasicIncrDeltaDisp();

    /* transform displacements from basic sys A to basic sys B (linear)
    Vector dbDelta(3);
    (*db)[0] = dbA(0);
    (*db)[1] = -L*dbA(1);
    (*db)[2] = -dbA(1)+dbA(2);
    (*vb)[0] = vbA(0);
    (*vb)[1] = -L*vbA(1);
    (*vb)[2] = -vbA(1)+vbA(2);
    (*ab)[0] = abA(0);
    (*ab)[1] = -L*abA(1);
    (*ab)[2] = -abA(1)+abA(2);
    dbDelta(0) = dbDeltaA(0);
    dbDelta(1) = -L*dbDeltaA(1);
    dbDelta(2) = -dbDeltaA(1)+dbDeltaA(2);*/

    // transform displacements from basic sys A to basic sys B (nonlinear)
    Vector dbDelta(3);
    (*db)[0] = (L+dbA(0))*cos(dbA(1))-L;
    (*db)[1] = -(L+dbA(0))*sin(dbA(1));
    (*db)[2] = -dbA(1)+dbA(2);
    (*vb)[0] = vbA(0)*cos(dbA(1))-(L+dbA(0))*sin(dbA(1))*vbA(1);
    (*vb)[1] = -vbA(0)*sin(dbA(1))-(L+dbA(0))*cos(dbA(1))*vbA(1);
    (*vb)[2] = -vbA(1)+vbA(2);
    (*ab)[0] = abA(0)*cos(dbA(1))-2*vbA(0)*sin(dbA(1))*vbA(1)-(L+dbA(0))*cos(dbA(1))*pow(vbA(1),2)-(L+dbA(0))*sin(dbA(1))*abA(1);
    (*ab)[1] = -abA(0)*sin(dbA(1))-2*vbA(0)*cos(dbA(1))*vbA(1)+(L+dbA(0))*sin(dbA(1))*pow(vbA(1),2)-(L+dbA(0))*cos(dbA(1))*abA(1);
    (*ab)[2] = -abA(1)+abA(2);
    dbDelta(0) = (L+dbDeltaA(0))*cos(dbDeltaA(1))-L;
    dbDelta(1) = -(L+dbDeltaA(0))*sin(dbDeltaA(1));
    dbDelta(2) = -dbDeltaA(1)+dbDeltaA(2);

    // do not check time for right now because of transformation constraint
    // handler calling update at beginning of new step when applying load
    // if (dbDelta.pNorm(0) > DBL_EPSILON || (*t)(0) > tLast)  {
    if (dbDelta.pNorm(0) > DBL_EPSILON)  {
        // set the trial response at the site
        if (theSite != 0)  {
            theSite->setTrialResponse(db, vb, ab, (Vector*)0, t);
        }
        else  {
            sData[0] = OF_RemoteTest_setTrialResponse;
            rValue += theChannel->sendVector(0, 0, *sendData, 0);
        }
    }

    // save the last time
    tLast = (*t)(0);

    return rValue;
}