Exemplo n.º 1
0
int main(int argc,char* argv[])
{
	const char* keys =
		"{ s   | scale  | 1      | scale of video input }"
		"{ r   | record | false  | record frames }"
		"{ v   | video  | 0      | video input }";
	
	cv::CommandLineParser cmd(argc,argv,keys);
	
	std::string videoName = cmd.get<std::string>("v");
	bool recordVideo = cmd.get<bool>("r");
	
	cv::Ptr<cv::VideoCapture> capture = new cv::VideoCapture();

	if (videoName.length() == 1) {
		capture->open(::atoi(videoName.c_str()));
	} else {
		capture->open(videoName);
	}
	
	if (!capture->isOpened())
		return -1;
	
	bool done(false);
	
	cv::Mat frame,gray;
	
	// please comment in and out -- this is causing the problem
	int someRandomNumber(0);
	
	DenseOpticalFlow dof(cmd.get<double>("s"));

	do {
		
		if (capture->read(frame))
		{
			cv::cvtColor(frame,gray,cv::COLOR_BGR2GRAY);		
			dof(gray,recordVideo);			
		} else {
			done = true;
		}
		
		int k = (int)cv::waitKey(1);
		
		if (27 == k)
			done = true;
		
	} while (!done);
	
	
	return 0;
}
Exemplo n.º 2
0
Arquivo: 1.d.c Projeto: EyciaZhou/acm
int main() {
	long T;
	int n, i, j, q, p;
	char st[55], c;
	bool f;
	scanf("%ld", &T);
	while (T--) {
		for (i = 0; i < 1005; i++) {
			for (j = 0; j <= 26; j++) {
				tire[i].n[j] = -1;
			}
			tire[i].f = 0;
			tire[i].d = -1;
			tire[i].b = false;
		}
		scanf("%d", &n);
		p = 0;
		for (i = 0; i < n; i++) {
			scanf("%s", st);
			q = 0;
			for (j = 0; j < strlen(st); j++) {
				
				if (st[j] >= 'a' && st[j] <= 'z') {
					if (tire[q].n[st[j] - 'a'] < 0) {
						tire[q].n[st[j] - 'a'] = ++p;
						tire[p].d = st[j] - 'a';
						tire[p].fa = q;
					}
					q = tire[q].n[st[j] - 'a'];
				}
			}
			tire[q].b = true;
		}
		getchar();
		dof();
		q = 0;
		f = true;
		while (true) {
			c = getchar();
			if (c == '\n' || c == EOF) {
				break;
			}

			q = getnext(q, c - 'a');
			if (tire[q].b) {
				f = false;
			}
			
		}
		if (f) {
			printf("not infected\n");
		}else{
			printf("infected\n");
		}
	}
}
bool CompliantGraspCopyTask::compliantCopy(const db_planner::Grasp *grasp, Pr2Gripper2010::ComplianceType compliance)
{
  //open slowly (2 degrees increments)
  //also, positive change means open for the pr2 gripper
  double OPEN_BY = 0.035;
  Pr2Gripper2010 *gripper = static_cast<Pr2Gripper2010 *>(mHand);
  gripper->setCompliance(compliance);

  std::vector<double> dof(mHand->getNumDOF(), 0.0);
  std::vector<double> stepSize(mHand->getNumDOF(), M_PI / 36.0);
  mHand->getDOFVals(&dof[0]);
  bool done = false;
  transf lastTran = mHand->getTran();
  while (!done)
  {
    //DBGA("Move loop");
    //open the hand a little bit
    for (int d = 0; d < mHand->getNumDOF(); d++) {
      dof[d] += OPEN_BY;
    }
    mHand->checkSetDOFVals(&dof[0]);
    mHand->moveDOFToContacts(&dof[0], &stepSize[0], true, false);

    //if we are far enough from the last saved grasp, go ahead and save a new one
    transf currentTran = mHand->getTran();
    if (!similarity(currentTran, lastTran)) {
      //save the grasp
      DBGA("Storing a compliant copy");
      //compliance messes up the pre-grasp computation
      gripper->setCompliance(Pr2Gripper2010::NONE);
      if (!checkStoreGrasp(grasp)) {
        return false;
      }
      gripper->setCompliance(compliance);
      //remember the last saved grasp
      lastTran = currentTran;
    }

    //if we have not opened as much as we wanted to, we've hit something; we are done
    for (int d = 0; d < mHand->getNumDOF(); d++) {
      if (fabs(mHand->getDOF(d)->getVal() - dof[d]) > 1.0e-5 ||
          dof[d] == mHand->getDOF(d)->getMin() ||
          dof[d] == mHand->getDOF(d)->getMax()) {
        //DBGA("Done moving");
        done = true;
        break;
      }
    }
  }
  return true;
}
Exemplo n.º 4
0
    void MatlabAdapter::initGenCoords()
    {
        engEvalString(mEngine, "coordNames = {Model.GenCoor.Name}");
        engEvalString(mEngine, "coordRanges = [ Model.lb; Model.ub]");

        mxArray *mxNames = engGetVariable(mEngine, "coordNames");
        mxArray *mxRanges = engGetVariable(mEngine, "coordRanges");

        double* values = mxGetPr(mxRanges);
        double min, max, stepSize;

        unsigned size = tree.dofs.size();
        for(unsigned i=0; i < size; i++)
        {
            mxArray *mxCell = mxGetCell(mxNames, i);
            char* name = mxArrayToString(mxCell);

            min = values[i];
            max = values[i+size];
            stepSize = (max-min) / 100.0;
            if(stepSize > 0.05) stepSize = 0.05;

            DegreeOfFreedom dof(min, max, 0, stepSize);
            dof.name = name;

            if(dof.name.size() > 6)
            {
            	if(dof.name.substr(0,6).compare("root_r") == 0)
            	{
            		TRACE("limited");
            		dof.rangeType = DegreeOfFreedom::limitedRange;
            		dof.min = -5;
            		dof.max = 5;
            	} else
            	{
            		TRACE("circular");
            		dof.rangeType = DegreeOfFreedom::circularRange;
            		dof.min = - M_PI;
            		dof.max = + M_PI;
            	}
            }

            tree.dofs.at(i)=dof;
            TRACE("generalized coordinat %s @ %i : min %f to %f", name, i, min, max);
        }


        mxDestroyArray(mxNames);
        mxDestroyArray(mxRanges);
    }
Exemplo n.º 5
0
int main()
{
    int c;
    unsigned long long a[4], y;

    fscanf(stdin, "%d", &c);

    while (c--) {
        fprintf(stdout, "%d: ", c);
        fscanf(stdin, "%lld%lld%lld%lld%lld", &y, &(a[0]), &(a[1]), &(a[2]), &(a[3]));
        fprintf(stdout, "%lld\n", dof(y, a));
    }
   
    return 0;
}
//**********************************************************************
PHX_EVALUATE_FIELDS(WeakDirichletResidual,workset)
{ 
  for (index_t cell = 0; cell < workset.num_cells; ++cell) {
    for (std::size_t ip = 0; ip < num_ip; ++ip) {
      normal_dot_flux_plus_pen(cell,ip) = ScalarT(0.0);
      for (std::size_t dim = 0; dim < num_dim; ++dim) {
	normal_dot_flux_plus_pen(cell,ip) += normal(cell,ip,dim) * flux(cell,ip,dim);
      }
      normal_dot_flux_plus_pen(cell,ip) += sigma(cell,ip) * (dof(cell,ip) - value(cell,ip)); 
    }
  }

  if(workset.num_cells>0)
    Intrepid2::FunctionSpaceTools::
      integrate<ScalarT>(residual, normal_dot_flux_plus_pen, 
			 (this->wda(workset).bases[basis_index])->weighted_basis_scalar, 
			 Intrepid2::COMP_CPP);
  
}
Exemplo n.º 7
0
void CVX_External::setFixed(bool xTranslate, bool yTranslate, bool zTranslate, bool xRotate, bool yRotate, bool zRotate)
{
	dofFixed = dof(xTranslate, yTranslate, zTranslate, xRotate, yRotate, zRotate);
	extTranslation = extRotation = Vec3D<double>(); //clear displacements
}
Exemplo n.º 8
0
void fourier_harmonic_3D(std::vector<Real> harmonics, Real lc, Real R, std::string output_name,int verbose){
    
    ////=============================================================////
    ////=======================  Mesh building  =====================////
    ////=============================================================////
    if (verbose>0){
        std::cout<<"Construction du maillage"<<std::endl;
    }
    gmsh_sphere(("sphere_"+NbrToStr(lc)).c_str(),R,lc,verbose);
    
    ////=============================================================////
    ////=======================  Mesh loading  ======================////
    ////=============================================================////
    if (verbose>0){
        std::cout<<"Chargement du maillage"<<std::endl;
    }
    Real kappa=1.;
    geometry geom;
    load_node_gmsh(geom,("sphere_"+NbrToStr(lc)).c_str());
    
    mesh_2D Omega(geom);
    load_elt_gmsh(Omega,0);
    //gmsh_clean(("sphere_"+NbrToStr(lc)).c_str());
    ////=============================================================////
    ////================== Calcul de la normale =====================////
    ////=============================================================////
    
    nrml_2D n_(Omega);
    
    ////=============================================================////
    ////================ Assemblage de la matrice ===================////
    ////=============================================================////
    if (verbose>0){
        std::cout<<"Assemblage operateurs integraux"<<std::endl;
    }
    int nbelt = nb_elt(Omega);
    P1_2D dof(Omega);
    int nbdof = nb_dof(dof);

    if (verbose>0){
        std::cout<<"Matrice de taille: ";
        std::cout<<nbdof<< std::endl;
        std::cout<<"Nel: ";
        std::cout<<nbelt<< std::endl;
    }

    gmm_dense V(nbdof,nbdof),W(nbdof,nbdof),K(nbdof,nbdof),M(nbdof,nbdof);
    bem<P1_2D,P1_2D, SLP_3D>   Vop (kappa,n_,n_);
    bem<P1_2D,P1_2D, HSP_3D>   Wop (kappa,n_,n_);
    bem<P1_2D,P1_2D, DLP_3D>   Kop (kappa,n_,n_);
    
    progress bar("assembly", nbelt*nbelt,verbose);
    for(int j=0; j<nbelt; j++){
        const elt_2D& tj = Omega[j];
        const N3&     jj = dof[j];
        
        for(int k=0; k<nbelt; k++,bar++){
            const elt_2D& tk = Omega[k];
            const N3&     kk = dof[k];
            V (jj,kk) += Vop  (tj,tk);
            W (jj,kk) += Wop  (tj,tk);
            K (jj,kk) += Kop  (tj,tk);
    
        }
        
        M(jj,jj) += MassP1(tj);
    }
    bar.end();
    

    // for (int l=0;l<harmonics.size();l++){
    //     Real p = harmonics[l];
        
    //     ////=============================================================////
    //     ////================== Harmonique de Fourier ====================////
    //     ////=============================================================////
        
    //     vect<Cplx> Ep;resize(Ep,nbdof);fill(Ep,0.);
        
    //     for (int j=0 ; j<nbelt ; j++){
    //         const elt_2D& seg = Omega[j];
    //         const N3&     I   = dof[j];
                
    //         R3 X0; X0[0] =  seg[0][0];X0[1]=seg[0][1]; X0[2]=seg[0][2];
    //         R3 X1; X1[0] =  seg[1][0];X1[1]=seg[1][1]; X1[2]=seg[1][2];
    //         R3 X2; X2[0] =  seg[2][0];X2[1]=seg[2][1]; X2[2]=seg[2][2];

    //         Real phi0 = atan2(X0[1],X0[0]);
    //         Real phi1 = atan2(X1[1],X1[0]);
    //         Real phi2 = atan2(X2[1],X2[0]);

    //         Real theta0 = acos(X0[2]);
    //         Real theta1 = acos(X1[2]);
    //         Real theta2 = acos(X2[2]);

    //         if (phi0<0){
    //             phi0 += 2 * M_PI;
    //         }
    //         if (phi1<0){
    //             phi1 += 2 * M_PI;
    //         }
    //         if (phi2<0){
    //             phi2 += 2 * M_PI;
    //         }

    //         C3 Vinc;

    //         Vinc[0] =  boost::math::spherical_harmonic(p,p,theta0,phi0);
    //         Vinc[1] =  boost::math::spherical_harmonic(p,p,theta1,phi1);
    //         Vinc[2] =  boost::math::spherical_harmonic(p,p,theta2,phi2);

    //         Ep[I] = Vinc;   
    //     }

    //     vect<Cplx> Eph;resize(Eph,nbdof);fill(Eph,0.);
    //     mv_prod(Eph,M,Ep);


	
	
	
	
    // 	////=============================================================////
    //     ////================== Calcul valeurs propres ===================////
    //     ////=============================================================////
        
        
    //     ////===================================////
    //     ////===== Test avec orthogonalité =====////
        
    //     Cplx val =0;
    //     Cplx err =0;
    //     for(int j=0; j<nbdof; j++){
    //     	val += Ep[j]*conj(Eph[j]);
    //     }
    
    //     err = abs(val)-1;
    //     std::cout<<"PS : "<<err<<std::endl;

        
    //     ////===================================////
    //     ////=========== Test avec V ===========////
        
        
    //     val =0;
    //     Real err_V =0;
        
    //     Cplx j_p = boost::math::sph_bessel(p, kappa*R);
    //     Cplx y_p = boost::math::sph_neumann(p, kappa*R);
    //     Cplx h_p = boost::math::sph_hankel_1(p, kappa*R);
        
    //     Cplx j_p_prime = boost::math::sph_bessel_prime(p, kappa*R);
    //     Cplx y_p_prime = boost::math::sph_neumann_prime(p, kappa*R);
        
    //     Cplx h_p_prime = j_p_prime + iu * y_p_prime;
        
    //     Cplx ref = iu * kappa * j_p * h_p;


    //    vect<Cplx> Temp;resize(Temp,nbdof);fill(Temp,0.);
    //    mv_prod(Temp,V,Ep);
       
    //    for(int j=0; j<nbdof; j++){
    //        val    += conj(Ep[j])*Temp[j];
    //    }
    //    //
    //    err_V = abs(val-ref) /abs(ref);
    //    if (verbose>0){
    //        std::cout<<"V : "<<err_V<<std::endl;
    //    }

        
        
    //     ////===================================////
    //     ////=========== Test avec W ===========////
        
    //     val =0;
    //     Real err_W =0;
    //     ref = - iu * pow(kappa,3) * j_p_prime * h_p_prime;
        
    //     fill(Temp,0.);
    //     mv_prod(Temp,W,Ep);
    //     for(int j=0; j<nbdof; j++){
    //         val    += conj(Ep[j])*Temp[j];
    //     }
        
    //     err_W = abs(val-ref) /abs(ref);
    //     if (verbose>0){
    //         std::cout<<"W : "<<err_W<<std::endl;
    //     }
    //     ////===================================////
    //     ////=========== Test avec K ===========////
        
    //     val =0;
    //     Real err_K =0;
    //     ref = iu /2. * kappa*kappa * (j_p_prime * h_p + j_p * h_p_prime);


        
    //     fill(Temp,0.);
    //     mv_prod(Temp,K,Ep);

    //     for(int j=0; j<nbdof; j++){
    //         val    += conj(Ep[j])*Temp[j];
    //     }
    //     err_K = abs(val-ref) /abs(ref);
    //     if (verbose>0){
    //         std::cout<<"K : "<<err_K<<std::endl;
    //     }
        
    //     ////=============================================================////
    //     ////======================== Sauvegardes ========================////
    //     ////=============================================================////
    //     std::ofstream output((output_name+"_"+NbrToStr<Real>(p)+".txt").c_str(),std::ios::app);
    //     if (!output){
    //         std::cerr<<"Output file cannot be created"<<std::endl;
    //         exit(1);
    //     }
    //     else{
    //         output<<lc<<" "<<err_V<<" "<<err_W<<" "<<err_K<<std::endl;
    //     }

    //     output.close();
        
    
    // if (l == 0)
    // {
    //     std::cout << p << "P" << std::endl;
    // }
    // }




    
}
Exemplo n.º 9
0
 void gamlr(int *famid, // 1 gaus, 2 bin, 3 pois
            int *n_in, // nobs 
            int *p_in, // nvar
            int *N_in, // length of nonzero x entries
            int *xi_in, // length-l row ids for nonzero x
            int *xp_in, // length-p+1 pointers to each column start
            double *xv_in, // nonzero x entry values
            double *y_in, // length-n y
            int *prexx, // indicator for pre-calc xx
            double *xxv_in, // dense columns of upper tri for xx
            double *eta, // length-n fixed shifts (assumed zero for gaussian)
            double *varweight, // length-p weights
            double *obsweight, // length-n weights
            int *standardize, // whether to scale penalty by sd(x_j)
            int *nlam, // length of the path
            double *delta, // path stepsize
            double *penscale,  // gamma in the GL paper
            double *thresh,  // cd convergence
            int *maxit, // cd max iterations 
            double *lambda, // output lambda
            double *deviance, // output deviance
            double *df, // output df
            double *alpha,  // output intercepts
            double *beta, // output coefficients
            int *exits, // exit status.  0 is normal
            int *verb) // talk? 
 {
  dirty = 1; // flag to say the function has been called
  // time stamp for periodic R interaction
  time_t itime = time(NULL);  

  /** Build global variables **/
  fam = *famid;
  n = *n_in;
  p = *p_in;
  nd = (double) n;
  pd = (double) p;
  N = *N_in;
  W = varweight;
  V = obsweight;

  E = eta;
  Y = y_in;
  xi = xi_in;
  xp = xp_in;
  xv = xv_in;

  doxx = *prexx;
  xxv = xxv_in;
  H = new_dvec(p);

  checkdata(*standardize);

  A=0.0;
  B = new_dzero(p);
  G = new_dzero(p);
  ag0 = new_dzero(p);
  gam = *penscale;

  npass = itertotal = 0;


  // some local variables
  double Lold, NLLHD, Lsat;
  int s;

  // family dependent settings
  switch( fam )
  {
    case 2:
      nllhd = &bin_nllhd;
      reweight = &bin_reweight;
      A = log(ybar/(1-ybar));
      Lsat = 0.0;
      break;
    case 3:
      nllhd = &po_nllhd;
      reweight = &po_reweight;
      A = log(ybar);
      // nonzero saturated deviance
      Lsat = ysum;
      for(int i=0; i<n; i++)
        if(Y[i]!=0) Lsat += -Y[i]*log(Y[i]);
      break;
    default: 
      fam = 1; // if it wasn't already
      nllhd = &lin_nllhd;
      A = (ysum - sum_dvec(eta,n))/nd;
      Lsat=0.0;
  }
  if(fam!=1){
    Z = new_dvec(n);
    vxbar = new_dvec(p);
    vxz = new_dvec(p);
  }
  else{ 
    Z = Y;
    vxz = new_dzero(p);
    if(V[0]!=0){
      vxbar = new_dvec(p);
      vstats();
    }
    else{
      vxbar = xbar; 
      vsum = nd;
      for(int j=0; j<p; j++)
        for(int i=xp[j]; i<xp[j+1]; i++)
            vxz[j] += xv[i]*Z[xi[i]]; 
    }
  }

  l1pen = INFINITY;
  Lold = INFINITY;
  NLLHD =  nllhd(n, A, E, Y);

  if(*verb)
    speak("*** n=%d observations and p=%d covariates ***\n", n,p);

  // move along the path
  for(s=0; s<*nlam; s++){

    // deflate the penalty
    if(s>0)
      lambda[s] = lambda[s-1]*(*delta);
    l1pen = lambda[s]*nd;

    // run descent
    exits[s] = cdsolve(*thresh,*maxit);

    // update parameters and objective
    itertotal += npass;
    Lold = NLLHD;
    NLLHD =  nllhd(n, A, E, Y);
    deviance[s] = 2.0*(NLLHD - Lsat);
    df[s] = dof(s, lambda, NLLHD);
    alpha[s] = A;
    copy_dvec(&beta[s*p],B,p);

    if(s==0) *thresh *= deviance[0]; // relativism
    
    // gamma lasso updating
    for(int j=0; j<p; j++) 
      if(isfinite(gam)){
        if( (W[j]>0.0) & isfinite(W[j]) )
          W[j] = 1.0/(1.0+gam*fabs(B[j]));
      } else if(B[j]!=0.0){
        W[j] = 0.0;
      }

    // verbalize
    if(*verb) 
      speak("segment %d: lambda = %.4g, dev = %.4g, npass = %d\n", 
          s+1, lambda[s], deviance[s], npass);

    // exit checks
    if(deviance[s]<0.0){
      exits[s] = 1;
      shout("Warning: negative deviance.  ");
    }
    if(df[s] >= nd){
      exits[s] = 1;
      shout("Warning: saturated model.  "); 
    }
    if(exits[s]){
      shout("Finishing path early.\n");
      *nlam = s; break; }

    itime = interact(itime); 
  }

  *maxit = itertotal;
  gamlr_cleanup();
}
//**********************************************************************
PHX_EVALUATE_FIELDS(DirichletResidual,workset)
{ 
  for (std::size_t i = 0; i < workset.num_cells; ++i)
    for (std::size_t j = 0; j < cell_data_size; ++j)
      residual(i,j)=dof(i,j)-value(i,j);
}
Exemplo n.º 11
0
/* ************************************************************************** */
void Pose2MobileVetLinArm::forwardKinematics(const Pose2Vector& p, 
    boost::optional<const gtsam::Vector&> v,
    std::vector<gtsam::Pose3>& px, boost::optional<std::vector<gtsam::Vector3>&> vx,
    boost::optional<std::vector<gtsam::Matrix>&> J_px_p,
    boost::optional<std::vector<gtsam::Matrix>&> J_vx_p,
    boost::optional<std::vector<gtsam::Matrix>&> J_vx_v) const {
    
  if (v)
    throw runtime_error("[Pose2MobileArm] TODO: velocity not implemented");

  if (!v && (vx || J_vx_p || J_vx_v))
    throw runtime_error("[Pose2MobileArm] ERROR: only ask for velocity in workspace given velocity in "
        "configuration space");

  // space for output
  px.resize(nr_links());
  if (vx) vx->resize(nr_links());
  if (J_px_p) J_px_p->assign(nr_links(), Matrix::Zero(6, dof()));
  if (J_vx_p) J_vx_p->assign(nr_links(), Matrix::Zero(3, dof()));
  if (J_vx_v) J_vx_v->assign(nr_links(), Matrix::Zero(3, dof()));

  // vehicle & arm base pose
  Pose3 veh_base, tso_base, arm_base;
  Matrix63 Hveh_base;
  Matrix64 Htso_base, Harm_base;
  if (J_px_p || J_vx_p || J_vx_v) {
    veh_base = computeBasePose3(p.pose(), Hveh_base);
    tso_base = liftBasePose3(p.pose(), p.configuration()(0), base_T_torso_, reverse_linact_, 
        Htso_base);
    Matrix6 H_tso_comp;
    arm_base = tso_base.compose(torso_T_arm_, H_tso_comp);
    Harm_base = H_tso_comp * Htso_base;

  } else {
    veh_base = computeBasePose3(p.pose());
    tso_base = liftBasePose3(p.pose(), p.configuration()(0), base_T_torso_, reverse_linact_);
    arm_base = tso_base.compose(torso_T_arm_);
  }

  // veh base link
  px[0] = veh_base;
  if (J_px_p) (*J_px_p)[0].block<6,3>(0,0) = Hveh_base;

  // torso link
  px[1] = tso_base;
  if (J_px_p) (*J_px_p)[1].block<6,4>(0,0) = Htso_base;

  // arm links
  vector<Pose3> armjpx;
  vector<Matrix> Jarm_jpx_jp;

  arm_.updateBasePose(arm_base);
  arm_.forwardKinematics(p.configuration().tail(arm_.dof()), boost::none, armjpx, boost::none,
      J_px_p ? boost::optional<vector<Matrix>&>(Jarm_jpx_jp) : boost::none);

  for (size_t i = 0; i < arm_.dof(); i++) {
    px[i+2] = armjpx[i];
    if (J_px_p) {
      // see compose's jacobian
      (*J_px_p)[i+2].block<6,4>(0,0) = (armjpx[i].inverse() * arm_base).AdjointMap() * Harm_base;
      (*J_px_p)[i+2].block(0,4,6,arm_.dof()) = Jarm_jpx_jp[i];
    }
  }
}
Exemplo n.º 12
0
/* ************************************************************************** */
void Pose2MobileArm::forwardKinematics(
    const Pose2Vector& p, boost::optional<const gtsam::Vector&> v,
    std::vector<gtsam::Pose3>& px, boost::optional<std::vector<gtsam::Vector3>&> vx,
    boost::optional<std::vector<gtsam::Matrix>&> J_px_p,
    boost::optional<std::vector<gtsam::Matrix>&> J_vx_p,
    boost::optional<std::vector<gtsam::Matrix>&> J_vx_v) const {

  if (v)
    throw runtime_error("[Pose2MobileArm] TODO: velocity not implemented");

  if (!v && (vx || J_vx_p || J_vx_v))
    throw runtime_error("[Pose2MobileArm] ERROR: only ask for velocity in workspace given velocity in "
        "configuration space");

  // space for output
  px.resize(nr_links());
  if (vx) vx->resize(nr_links());
  if (J_px_p) J_px_p->assign(nr_links(), Matrix::Zero(6, dof()));
  if (J_vx_p) J_vx_p->assign(nr_links(), Matrix::Zero(3, dof()));
  if (J_vx_v) J_vx_v->assign(nr_links(), Matrix::Zero(3, dof()));

  // vehicle & arm base pose
  Pose3 veh_base, arm_base;
  Matrix63 Hveh_base, Harm_base;
  if (J_px_p || J_vx_p || J_vx_v) {
    veh_base = computeBasePose3(p.pose(), Hveh_base);
    arm_base = computeBaseTransPose3(p.pose(), base_T_arm_, Harm_base);
  } else {
    veh_base = computeBasePose3(p.pose());
    arm_base = computeBaseTransPose3(p.pose(), base_T_arm_);
  }


  // call arm pose and velocity, for arm links
  // px[0] = base_pose3; px[i] = arm_base * px_arm[i-1]
  // vx[0] = v(0:1,0); vx[i] = vx[0] + angular x arm_base_pos + arm_base_rot * vx_arm[i-1]

  // veh base link
  px[0] = veh_base;
  if (J_px_p) (*J_px_p)[0].block<6,3>(0,0) = Hveh_base;
  if (vx) {
    (*vx)[0] = Vector3((*v)[0], (*v)[1], 0.0);
    // (*J_vx_p)[0] is zero
    if (J_vx_v)
      (*J_vx_v)[0].block<2,2>(0,0) = Matrix2::Identity();
  }

  // arm links
  vector<Pose3> armjpx;
  vector<Vector3> armjvx;
  vector<Matrix> Jarm_jpx_jp, Jarm_jvx_jp, Jarm_jvx_jv;

  arm_.updateBasePose(arm_base);
  if (v) {
    const Vector varm = v->tail(arm_.dof());
    arm_.forwardKinematics(p.configuration(), boost::optional<const Vector&>(varm),
        armjpx, vx ? boost::optional<vector<Vector3>&>(armjvx) : boost::none,
        J_px_p ? boost::optional<vector<Matrix>&>(Jarm_jpx_jp) : boost::none,
        J_vx_p ? boost::optional<vector<Matrix>&>(Jarm_jvx_jp) : boost::none,
        J_vx_v ? boost::optional<vector<Matrix>&>(Jarm_jvx_jv) : boost::none);
  } else {
    arm_.forwardKinematics(p.configuration(), boost::none,
        armjpx, vx ? boost::optional<vector<Vector3>&>(armjvx) : boost::none,
        J_px_p ? boost::optional<vector<Matrix>&>(Jarm_jpx_jp) : boost::none);
  }

  for (size_t i = 0; i < arm_.dof(); i++) {
    px[i+1] = armjpx[i];
    if (J_px_p) {
      // see compose's jacobian
      (*J_px_p)[i+1].block<6,3>(0,0) = (armjpx[i].inverse() * arm_base).AdjointMap() * Harm_base;
      (*J_px_p)[i+1].block(0,3,6,arm_.dof()) = Jarm_jpx_jp[i];
    }
    if (vx) {
      //(*vx)[i+1] = Vector3((*v)[0], (*v)[1], 0.0) +  armjvx[i];
    }
  }

}
//**********************************************************************
PHX_EVALUATE_FIELDS(DirichletResidual_EdgeBasis,workset)
{ 
  if(workset.num_cells<=0)
    return;

  residual.deep_copy(ScalarT(0.0));

  if(workset.subcell_dim==1) {
    Intrepid2::CellTools<ScalarT>::getPhysicalEdgeTangents(edgeTan,
                                            pointValues.jac,
                                            this->wda(workset).subcell_index, 
                                           *basis->getCellTopology());

    for(std::size_t c=0;c<workset.num_cells;c++) {
      for(int b=0;b<dof.dimension(1);b++) {
        for(int d=0;d<dof.dimension(2);d++)
          residual(c,b) += (dof(c,b,d)-value(c,b,d))*edgeTan(c,b,d);
      } 
    }
  }
  else if(workset.subcell_dim==2) {
    // we need to compute the tangents on each edge for each cell.
    // how do we do this????
    const shards::CellTopology & parentCell = *basis->getCellTopology();
    int cellDim = parentCell.getDimension();
    int numEdges = dof.dimension(1);

    refEdgeTan = Kokkos::createDynRankView(residual.get_kokkos_view(),"refEdgeTan",numEdges,cellDim);

    for(int i=0;i<numEdges;i++) {
      Kokkos::DynRankView<double,PHX::Device> refEdgeTan_local("refEdgeTan_local",cellDim);
      Intrepid2::CellTools<double>::getReferenceEdgeTangent(refEdgeTan_local, i, parentCell);

      for(int d=0;d<cellDim;d++) 
        refEdgeTan(i,d) = refEdgeTan_local(d);
    }

    // Loop over workset faces and edge points
    for(std::size_t c=0;c<workset.num_cells;c++) {
      for(int pt = 0; pt < numEdges; pt++) {

        // Apply parent cell Jacobian to ref. edge tangent
        for(int i = 0; i < cellDim; i++) {
          edgeTan(c, pt, i) = 0.0;
          for(int j = 0; j < cellDim; j++){
            edgeTan(c, pt, i) +=  pointValues.jac(c, pt, i, j)*refEdgeTan(pt,j);
          }// for j
        }// for i
      }// for pt
    }// for pCell

    for(std::size_t c=0;c<workset.num_cells;c++) {
      for(int b=0;b<dof.dimension(1);b++) {
        for(int d=0;d<dof.dimension(2);d++)
          residual(c,b) += (dof(c,b,d)-value(c,b,d))*edgeTan(c,b,d);
      } 
    }

  }
  else {
    // don't know what to do 
    TEUCHOS_ASSERT(false);
  }

  // loop over residuals scaling by orientation. This gurantees
  // everything is oriented in the "positive" direction, this allows
  // sums acrossed processor to be oriented in the same way (right?)
  for(std::size_t c=0;c<workset.num_cells;c++) {
    for(int b=0;b<dof.dimension(1);b++) {
      residual(c,b) *= dof_orientation(c,b);
    }
  }
}
Exemplo n.º 14
0
  //--------------------------------------------------------
  //  add_charged_surface
  //--------------------------------------------------------
  void ChargeRegulatorMethodEffectiveCharge::initialize( ) 
  {
    ChargeRegulatorMethod::initialize();
    boundary_ = atc_->is_ghost_group(atomGroupBit_);
    // set face sources to all point at unit function for use in integration
    SURFACE_SOURCE faceSources;
    map<PAIR, Array<XT_Function*> > & fs(faceSources[ELECTRIC_POTENTIAL]);
    XT_Function * f = XT_Function_Mgr::instance()->constant_function(1.);
    set< PAIR >::const_iterator fsItr;
    for (fsItr = surface_.begin(); fsItr != surface_.end(); fsItr++) {
      Array < XT_Function * > & dof  = fs[*fsItr];
      dof.reset(1);
      dof(0) = f;
    }

    // computed integrals of nodal shape functions on face
    FIELDS nodalFaceWeights;
    Array<bool> fieldMask(NUM_FIELDS); fieldMask(ELECTRIC_POTENTIAL) = true;
    (atc_->fe_engine())->compute_fluxes(fieldMask,0.,faceSources,nodalFaceWeights);
    const DENS_MAT & w = (nodalFaceWeights[ELECTRIC_POTENTIAL].quantity());

    // Get coordinates of each node in face set
    for (set<int>::const_iterator n =nodes_.begin(); n != nodes_.end(); n++) {
      DENS_VEC x = atc_->fe_engine()->fe_mesh()->nodal_coordinates(*n);
      // compute effective charge at each node I
      // multiply charge density by integral of N_I over face
      double v = w(*n,0)*chargeDensity_;
      pair<DENS_VEC,double> p(x,v);
      nodeXFMap_[*n] = p;
    }

    // set up data structure holding charged faceset information
    FIELDS sources;
    double k = lammpsInterface_->coulomb_constant();
    string fname = "radial_power";
    double xtArgs[8];
    xtArgs[0] = 0; xtArgs[1] = 0; xtArgs[2] = 0;
    xtArgs[3] = 1; xtArgs[4] = 1; xtArgs[5] = 1;
    xtArgs[6] = k*chargeDensity_;
    xtArgs[7] = -1.;
    const DENS_MAT & s(sources[ELECTRIC_POTENTIAL].quantity());
    NODE_TO_XF_MAP::iterator XFitr;
    for (XFitr = nodeXFMap_.begin(); XFitr != nodeXFMap_.end(); XFitr++) {
      // evaluate voltage at each node I
      // set up X_T function for integration: k*chargeDensity_/||x_I - x_s||
      // integral is approximated in two parts:
      // 1) near part with all faces within r < rcrit evaluated as 2 * pi * rcrit * k sigma A/A0, A is area of this region and A0 = pi * rcrit^2, so 2 k sigma A / rcrit
      // 2) far part evaluated using Gaussian quadrature on faceset
      DENS_VEC x((XFitr->second).first);
      xtArgs[0] = x(0); xtArgs[1] = x(1); xtArgs[2] = x(2);
      f = XT_Function_Mgr::instance()->function(fname,8,xtArgs);
      for (fsItr = surface_.begin(); fsItr != surface_.end(); fsItr++) {
        fs[*fsItr] = f;
      }

      // perform integration to get quantities at nodes on facesets
      // V_J' = int_S N_J k*sigma/|x_I - x_s| dS
      (atc_->fe_engine())->compute_fluxes(fieldMask,0.,faceSources,sources);

      // sum over all nodes in faceset to get total potential:
      // V_I = sum_J VJ'
      int node = XFitr->first;
      nodalChargePotential_[node] = s(node,0);
      double totalPotential = 0.;
      for (set<int>::const_iterator n =nodes_.begin(); n != nodes_.end(); n++) {
        totalPotential += s(*n,0); }

      // assign an XT function per each node and
      // then call the prescribed data manager and fix each node individually.
      f = XT_Function_Mgr::instance()->constant_function(totalPotential);
      (atc_->prescribed_data_manager())->fix_field(node,ELECTRIC_POTENTIAL,0,f);
    }
    initialized_ = true;
  }
Exemplo n.º 15
0
double SlaveBoundaryVertices::loop_over_mesh( Mesh* mesh, 
                                              MeshDomain* domain, 
                                              const Settings* settings,
                                              MsqError& err )
{
  if (settings->get_slaved_ho_node_mode() != Settings::SLAVE_CALCULATED) {
    MSQ_SETERR(err)("Request to calculate higher-order node slaved status "
                    "when Settings::get_get_slaved_ho_node_mode() "
                    "!= SLAVE_CALCUALTED", MsqError::INVALID_STATE);
    return 0.0;
  }
  
    // If user said that we should treat fixed vertices as the
    // boundary, but specified that fixed vertices are defined
    // by the dimension of their geometric domain, then just
    // do distance from the geometric domain.
  int dim = this->domainDoF;
  if (dim >= 4 && settings->get_fixed_vertex_mode() != Settings::FIXED_FLAG)
    dim = settings->get_fixed_vertex_mode();
  
    // Create a map to contain vertex depth.  Intiliaze all to 
    // elemDepth+1.
  std::vector<Mesh::VertexHandle> vertices;
  mesh->get_all_vertices( vertices, err );  MSQ_ERRZERO(err);
  if (vertices.empty())
    return 0.0;
  std::sort( vertices.begin(), vertices.end() );
  std::vector<unsigned short> depth( vertices.size(), elemDepth+1 );
  BoolArr fixed( vertices.size() );
  mesh->vertices_get_fixed_flag( &vertices[0], fixed.mArray, vertices.size(), err );
  MSQ_ERRZERO(err);
  
    // Initialize map with boundary vertices.
  if (dim >= 4) {
    for(size_t i = 0; i < vertices.size(); ++i)
      if (fixed[i])
        depth[i] = 0;
  }
  else {
    if (!domain) {
      MSQ_SETERR(err)("Request to calculate higher-order node slaved status "
                      "by distance from bounding domain without a domain.",
                      MsqError::INVALID_STATE);
      return 0.0;
    }
    
    std::vector<unsigned short> dof( vertices.size() );
    domain->domain_DoF( &vertices[0], &dof[0], vertices.size(), err ); MSQ_ERRZERO(err);
    for (size_t i = 0; i < vertices.size(); ++i)
      if (dof[i] <= dim)
        depth[i] = 0;
  }
  
    // Now iterate over elements repeatedly until we've found all of the 
    // elements near the boundary.  This could be done much more efficiently
    // using vertex-to-element adjacencies, but it is to common for 
    // applications not to implement that unless doing relaxation smoothing.
    // This is O(elemDepth * elements.size() * ln(vertices.size()));
  std::vector<Mesh::ElementHandle> elements;
  std::vector<Mesh::ElementHandle>::const_iterator j, k;
  std::vector<Mesh::VertexHandle> conn;
  std::vector<size_t> junk(2);
  mesh->get_all_elements( elements, err );  MSQ_ERRZERO(err);
  if (elements.empty())
    return 0.0;
  bool some_changed;
  do {
    some_changed = false;
    for (j = elements.begin(); j != elements.end(); ++j) {
      conn.clear(); junk.clear();
      mesh->elements_get_attached_vertices( &*j, 1, conn, junk, err ); MSQ_ERRZERO(err);
      unsigned short elem_depth = elemDepth+1;
      for (k = conn.begin(); k != conn.end(); ++k) {
        size_t i = std::lower_bound( vertices.begin(), vertices.end(), *k ) - vertices.begin();
        if (i == vertices.size()) {
          MSQ_SETERR(err)("Invalid vertex handle in element connectivity list.", 
                          MsqError::INVALID_MESH);
          return 0.0;
        }
        if (depth[i] < elem_depth)
          elem_depth = depth[i];
      }
      if (elem_depth == elemDepth+1)
        continue;
      
      ++elem_depth;
      for (k = conn.begin(); k != conn.end(); ++k) {
        size_t i = std::lower_bound( vertices.begin(), vertices.end(), *k ) - vertices.begin();
        if (depth[i] > elem_depth) {
          depth[i] = elem_depth;
          some_changed = true;
        }
      }
    } // for(elements)
  } while (some_changed);
  
    // Now remove any corner vertices from the slaved set
  std::vector<Mesh::VertexHandle>::iterator p;
  std::vector<EntityTopology> types(elements.size());
  mesh->elements_get_topologies( &elements[0], &types[0], elements.size(), err ); MSQ_ERRZERO(err);
  for (j = elements.begin(); j != elements.end(); ++j) {
    const unsigned corners = TopologyInfo::corners(types[j-elements.begin()]);
    conn.clear(); junk.clear();
    mesh->elements_get_attached_vertices( &*j, 1, conn, junk, err ); MSQ_ERRZERO(err);
    for (unsigned i = 0; i < corners; ++i) {
      p = std::lower_bound( vertices.begin(), vertices.end(), conn[i] );
      depth[p-vertices.begin()] = 0;
    }
  }
  
    // Now mark all vertices *not* within specified depth as slave vertices.
  std::vector<unsigned char> bytes( vertices.size() );
  mesh->vertices_get_byte( &vertices[0], &bytes[0], vertices.size(), err ); MSQ_ERRZERO(err);
  for (size_t i = 0; i < vertices.size(); ++i) {
    if (depth[i] <= elemDepth || fixed[i])
      bytes[i] &= ~MsqVertex::MSQ_DEPENDENT;
    else
      bytes[i] |= MsqVertex::MSQ_DEPENDENT;
  }
  
  mesh->vertices_set_byte( &vertices[0], &bytes[0], vertices.size(), err ); MSQ_ERRZERO(err);
  return 0.0;
}
Exemplo n.º 16
0
int TclExpCPCommand(ClientData clientData, Tcl_Interp *interp,
    int argc, TCL_Char **argv, Domain *theDomain)
{
    if (theExperimentalCPs == 0)
        theExperimentalCPs = new ArrayOfTaggedObjects(32);
    
    // make sure there is a minimum number of arguments
    if (argc < 4)  {
        opserr << "WARNING invalid number of arguments\n";
        printCommand(argc,argv);
        opserr << "Want: expControlPoint tag <-node nodeTag> dof rspType <-fact f> <-lim l u> <-isRel> ...\n";
        return TCL_ERROR;
    }
    
    int tag, i, argi = 1;
    int nodeTag = 0, ndf = 0, ndm = 0;
    Node *theNode = 0;
    int numSignals = 0, numLim = 0, numRefType = 0;
    double f, lim;
    ExperimentalCP *theCP = 0;
    
    if (Tcl_GetInt(interp, argv[argi], &tag) != TCL_OK)  {
        opserr << "WARNING invalid expControlPoint tag\n";
        return TCL_ERROR;
    }
    argi++;
    if (strcmp(argv[argi],"-node") == 0)  {
        argi++;
        if (Tcl_GetInt(interp, argv[argi], &nodeTag) != TCL_OK)  {
            opserr << "WARNING invalid nodeTag for control point: " << tag << endln;
            printCommand(argc,argv);
            opserr << "Want: expControlPoint tag <-node nodeTag> dof rspType <-fact f> <-lim l u> <-isRel> ...\n";
            return TCL_ERROR;
        }
        theNode = theDomain->getNode(nodeTag);
        ndf = theNode->getNumberDOF();
        ndm = OPS_GetNDM();
        argi++;
    }
    // count number of signals
    i = argi;
    while (i < argc)  {
        if (strcmp(argv[i],"-fact") == 0 || strcmp(argv[i],"-factor") == 0)
            i += 2;
        else if (strcmp(argv[i],"-isRel") == 0 || strcmp(argv[i],"-isRelative") == 0)
            i++;
        else if (strcmp(argv[i],"-lim") == 0 || strcmp(argv[i],"-limit") == 0)  {
            i += 3;
            numLim++;
        }
        else  {
            i += 2;
            numSignals++;
        }
    }
    if (numSignals == 0)  {
        opserr << "WARNING invalid number of arguments for control point: " << tag << endln;
        printCommand(argc,argv);
        opserr << "Want: expControlPoint tag <-node nodeTag> dof rspType <-fact f> <-lim l u> <-isRel> ...\n";
        return TCL_ERROR;
    }
    if (numLim > 0 && numLim != numSignals)  {
        opserr << "WARNING invalid number of limits for control point: " << tag << endln;
        printCommand(argc,argv);
        opserr << "Want: expControlPoint tag <-node nodeTag> dof rspType <-fact f> <-lim l u> <-isRel> ...\n";
        return TCL_ERROR;
    }
    ID dof(numSignals);
    ID rspType(numSignals);
    Vector factor(numSignals);
    Vector lowerLim(numSignals);
    Vector upperLim(numSignals);
    ID isRelative(numSignals);
    for (i=0; i<numSignals; i++)  {
        if (ndf == 0)  {
            int dofID = 0;
            if (sscanf(argv[argi],"%d",&dofID) != 1)  {
                if (sscanf(argv[argi],"%*[dfouDFOU]%d",&dofID) != 1)  {
                    opserr << "WARNING invalid dof for control point: " << tag << endln;
                    printCommand(argc,argv);
                    opserr << "Want: expControlPoint tag <-node nodeTag> dof rspType <-fact f> <-lim l u> <-isRel> ...\n";
                    return TCL_ERROR;
                }
            }
            dof(i) = dofID - 1;
        }
        else if (ndm == 1 && ndf == 1)  {
            if (strcmp(argv[argi],"1") == 0 || 
                strcmp(argv[argi],"dof1") == 0 || strcmp(argv[argi],"DOF1") == 0 ||
                strcmp(argv[argi],"u1") == 0 || strcmp(argv[argi],"U1") == 0 ||
                strcmp(argv[argi],"ux") == 0 || strcmp(argv[argi],"UX") == 0)
                dof(i) = 0;
            else  {
                opserr << "WARNING invalid dof for control point: " << tag << endln;
                printCommand(argc,argv);
                opserr << "Want: expControlPoint tag <-node nodeTag> dof rspType <-fact f> <-lim l u> <-isRel> ...\n";
                return TCL_ERROR;
            }
        }
        else if (ndm == 2 && ndf == 2)  {
            if (strcmp(argv[argi],"1") == 0 ||
                strcmp(argv[argi],"dof1") == 0 || strcmp(argv[argi],"DOF1") == 0 ||
                strcmp(argv[argi],"u1") == 0 || strcmp(argv[argi],"U1") == 0 ||
                strcmp(argv[argi],"ux") == 0 || strcmp(argv[argi],"UX") == 0)
                dof(i) = 0;
            else if (strcmp(argv[argi],"2") == 0 ||
                strcmp(argv[argi],"dof2") == 0 || strcmp(argv[argi],"DOF2") == 0 ||
                strcmp(argv[argi],"u2") == 0 || strcmp(argv[argi],"U2") == 0 ||
                strcmp(argv[argi],"uy") == 0 || strcmp(argv[argi],"UY") == 0)
                dof(i) = 1;
            else  {
                opserr << "WARNING invalid dof for control point: " << tag << endln;
                printCommand(argc,argv);
                opserr << "Want: expControlPoint tag <-node nodeTag> dof rspType <-fact f> <-lim l u> <-isRel> ...\n";
                return TCL_ERROR;
            }
        }
        else if (ndm == 2 && ndf == 3)  {
            if (strcmp(argv[argi],"1") == 0 ||
                strcmp(argv[argi],"dof1") == 0 || strcmp(argv[argi],"DOF1") == 0 ||
                strcmp(argv[argi],"u1") == 0 || strcmp(argv[argi],"U1") == 0 ||
                strcmp(argv[argi],"ux") == 0 || strcmp(argv[argi],"UX") == 0)
                dof(i) = 0;
            else if (strcmp(argv[argi],"2") == 0 ||
                strcmp(argv[argi],"dof2") == 0 || strcmp(argv[argi],"DOF2") == 0 ||
                strcmp(argv[argi],"u2") == 0 || strcmp(argv[argi],"U2") == 0 ||
                strcmp(argv[argi],"uy") == 0 || strcmp(argv[argi],"UY") == 0)
                dof(i) = 1;
            else if (strcmp(argv[argi],"3") == 0 ||
                strcmp(argv[argi],"dof3") == 0 || strcmp(argv[argi],"DOF3") == 0 ||
                strcmp(argv[argi],"r3") == 0 || strcmp(argv[argi],"R3") == 0 ||
                strcmp(argv[argi],"rz") == 0 || strcmp(argv[argi],"RZ") == 0)
                dof(i) = 2;
            else  {
                opserr << "WARNING invalid dof for control point: " << tag << endln;
                printCommand(argc,argv);
                opserr << "Want: expControlPoint tag <-node nodeTag> dof rspType <-fact f> <-lim l u> <-isRel> ...\n";
                return TCL_ERROR;
            }
        }
        else if (ndm == 3 && ndf == 3)  {
            if (strcmp(argv[argi],"1") == 0 ||
                strcmp(argv[argi],"dof1") == 0 || strcmp(argv[argi],"DOF1") == 0 ||
                strcmp(argv[argi],"u1") == 0 || strcmp(argv[argi],"U1") == 0 ||
                strcmp(argv[argi],"ux") == 0 || strcmp(argv[argi],"UX") == 0)
                dof(i) = 0;
            else if (strcmp(argv[argi],"2") == 0 ||
                strcmp(argv[argi],"dof2") == 0 || strcmp(argv[argi],"DOF2") == 0 ||
                strcmp(argv[argi],"u2") == 0 || strcmp(argv[argi],"U2") == 0 ||
                strcmp(argv[argi],"uy") == 0 || strcmp(argv[argi],"UY") == 0)
                dof(i) = 1;
            else if (strcmp(argv[argi],"3") == 0 ||
                strcmp(argv[argi],"dof3") == 0 || strcmp(argv[argi],"DOF3") == 0 ||
                strcmp(argv[argi],"u3") == 0 || strcmp(argv[argi],"U3") == 0 ||
                strcmp(argv[argi],"uz") == 0 || strcmp(argv[argi],"UZ") == 0)
                dof(i) = 2;
            else  {
                opserr << "WARNING invalid dof for control point: " << tag << endln;
                printCommand(argc,argv);
                opserr << "Want: expControlPoint tag <-node nodeTag> dof rspType <-fact f> <-lim l u> <-isRel> ...\n";
                return TCL_ERROR;
            }
        }
        else if (ndm == 3 && ndf == 6)  {
            if (strcmp(argv[argi],"1") == 0 ||
                strcmp(argv[argi],"dof1") == 0 || strcmp(argv[argi],"DOF1") == 0 ||
                strcmp(argv[argi],"u1") == 0 || strcmp(argv[argi],"U1") == 0 ||
                strcmp(argv[argi],"ux") == 0 || strcmp(argv[argi],"UX") == 0)
                dof(i) = 0;
            else if (strcmp(argv[argi],"2") == 0 ||
                strcmp(argv[argi],"dof2") == 0 || strcmp(argv[argi],"DOF2") == 0 ||
                strcmp(argv[argi],"u2") == 0 || strcmp(argv[argi],"U2") == 0 ||
                strcmp(argv[argi],"uy") == 0 || strcmp(argv[argi],"UY") == 0)
                dof(i) = 1;
            else if (strcmp(argv[argi],"3") == 0 ||
                strcmp(argv[argi],"dof3") == 0 || strcmp(argv[argi],"DOF3") == 0 ||
                strcmp(argv[argi],"u3") == 0 || strcmp(argv[argi],"U3") == 0 ||
                strcmp(argv[argi],"uz") == 0 || strcmp(argv[argi],"UZ") == 0)
                dof(i) = 2;
            else if (strcmp(argv[argi],"4") == 0 ||
                strcmp(argv[argi],"dof4") == 0 || strcmp(argv[argi],"DOF4") == 0 ||
                strcmp(argv[argi],"r1") == 0 || strcmp(argv[argi],"R1") == 0 ||
                strcmp(argv[argi],"rx") == 0 || strcmp(argv[argi],"RX") == 0)
                dof(i) = 3;
            else if (strcmp(argv[argi],"5") == 0 ||
                strcmp(argv[argi],"dof5") == 0 || strcmp(argv[argi],"DOF5") == 0 ||
                strcmp(argv[argi],"r2") == 0 || strcmp(argv[argi],"R2") == 0 ||
                strcmp(argv[argi],"ry") == 0 || strcmp(argv[argi],"RY") == 0)
                dof(i) = 4;
            else if (strcmp(argv[argi],"6") == 0 ||
                strcmp(argv[argi],"dof6") == 0 || strcmp(argv[argi],"DOF6") == 0 ||
                strcmp(argv[argi],"r3") == 0 || strcmp(argv[argi],"R3") == 0 ||
                strcmp(argv[argi],"rz") == 0 || strcmp(argv[argi],"RZ") == 0)
                dof(i) = 5;
            else  {
                opserr << "WARNING invalid dof for control point: " << tag << endln;
                printCommand(argc,argv);
                opserr << "Want: expControlPoint tag <-node nodeTag> dof rspType <-fact f> <-lim l u> <-isRel> ...\n";
               return TCL_ERROR;
            }
        }
        argi++;
        if (strcmp(argv[argi],"1") == 0 || strcmp(argv[argi],"dsp") == 0 ||
            strcmp(argv[argi],"disp") == 0 || strcmp(argv[argi],"displacement") == 0)
            rspType(i) = OF_Resp_Disp;
        else if (strcmp(argv[argi],"2") == 0 || strcmp(argv[argi],"vel") == 0 ||
            strcmp(argv[argi],"velocity") == 0)
            rspType(i) = OF_Resp_Vel;
        else if (strcmp(argv[argi],"3") == 0 || strcmp(argv[argi],"acc") == 0 ||
            strcmp(argv[argi],"accel") == 0 || strcmp(argv[argi],"acceleration") == 0)
            rspType(i) = OF_Resp_Accel;
        else if (strcmp(argv[argi],"4") == 0 || strcmp(argv[argi],"frc") == 0 ||
            strcmp(argv[argi],"force") == 0)
            rspType(i) = OF_Resp_Force;
        else if (strcmp(argv[argi],"5") == 0 ||  strcmp(argv[argi],"t") == 0 ||
            strcmp(argv[argi],"tme") == 0 || strcmp(argv[argi],"time") == 0)
            rspType(i) = OF_Resp_Time;
        else  {
            opserr << "WARNING invalid rspType for control point: " << tag << endln;
            printCommand(argc,argv);
            opserr << "Want: expControlPoint tag <-node nodeTag> dof rspType <-fact f> <-lim l u> <-isRel> ...\n";
            return TCL_ERROR;
        }
        argi++;
        if (argi<argc && (strcmp(argv[argi],"-fact") == 0 || strcmp(argv[argi],"-factor") == 0))  {
            argi++;
            if (Tcl_GetDouble(interp, argv[argi], &f) != TCL_OK)  {
                opserr << "WARNING invalid factor for control point: " << tag << endln;
                printCommand(argc,argv);
                opserr << "Want: expControlPoint tag <-node nodeTag> dof rspType <-fact f> <-lim l u> <-isRel> ...\n";
                return TCL_ERROR;
            }
            factor(i) = f;
            argi++;
        } else  {
            factor(i) = 1.0;
        }
        if (argi<argc && (strcmp(argv[argi],"-lim") == 0 || strcmp(argv[argi],"-limit") == 0))  {
            argi++;
            if (Tcl_GetDouble(interp, argv[argi], &lim) != TCL_OK)  {
                opserr << "WARNING invalid lower limit for control point: " << tag << endln;
                printCommand(argc,argv);
                opserr << "Want: expControlPoint tag <-node nodeTag> dof rspType <-fact f> <-lim l u> <-isRel> ...\n";
                return TCL_ERROR;
            }
            lowerLim(i) = lim;
            argi++;
            if (Tcl_GetDouble(interp, argv[argi], &lim) != TCL_OK)  {
                opserr << "WARNING invalid upper limit for control point: " << tag << endln;
                printCommand(argc,argv);
                opserr << "Want: expControlPoint tag <-node nodeTag> dof rspType <-fact f> <-lim l u> <-isRel> ...\n";
                return TCL_ERROR;
            }
            upperLim(i) = lim;
            argi++;
        }
        if (argi<argc && (strcmp(argv[argi],"-isRel") == 0 || strcmp(argv[argi],"-isRelative") == 0))  {
            isRelative(i) = 1;
            numRefType++;
            argi++;
        }
    }
    
    // parsing was successful, allocate the control point
    theCP = new ExperimentalCP(tag, dof, rspType, factor);
    
    if (theCP == 0)  {
        opserr << "WARNING could not create experimental control point " << argv[1] << endln;
        return TCL_ERROR;
    }
    
    // add limits if available
    if (numLim > 0)
        theCP->setLimits(lowerLim, upperLim);
    
    // add signal reference types if available
    if (numRefType > 0)
        theCP->setSigRefType(isRelative);
    
    // add node if available
    if (theNode != 0)
        theCP->setNode(theNode);
    
    // now add the control point to the modelBuilder
    if (addExperimentalCP(*theCP) < 0)  {
        delete theCP; // invoke the destructor, otherwise mem leak
        return TCL_ERROR;
    }
    
    return TCL_OK;
}