Example #1
0
int cFileData::getPointColorData(std::vector<float> *vertex, std::vector<GLubyte> *color) {
    cDataFieldT<vtkPoint>* df_p =
        static_cast<cDataFieldT<vtkPoint>*>(getDatafield("POINTS"));
    if (!df_p)
        return 0;
    cDataFieldT<float>* df_a =
        static_cast<cDataFieldT<float>*>(getDatafield("altitude"));
    if (!df_a)
        return 0;
    cDataFieldT<unsigned char>* df_d =
        static_cast<cDataFieldT<unsigned char>*>(getDatafield("detection"));
    if (!df_d)
        return 0;

    int pos = 0;
    vertex->reserve(df_p->numEntries()*3);
    float scaleFac = 5.0*(float)WORLD_SPHERE_RADIUS/EARTH_RADIUS;
    for (int i=0; i < df_p->numEntries(); ++i) {
        switch(df_d->getValueAt(i)) {
        case 0:
            color->push_back(GLubyte(255));
            color->push_back(GLubyte(255));
            color->push_back(GLubyte(178));
            break;
        case 1:
            color->push_back(GLubyte(254));
            color->push_back(GLubyte(204));
            color->push_back(GLubyte(92));
            break;
        case 2:
            color->push_back(GLubyte(253));
            color->push_back(GLubyte(141));
            color->push_back(GLubyte(60));
            break;
        case 4:
            color->push_back(GLubyte(227));
            color->push_back(GLubyte(26));
            color->push_back(GLubyte(28));
            break;
        }
        vtkPoint p = df_p->getValueAt(i);
        float a = df_a->getValueAt(i)*scaleFac;
        vertex->push_back((WORLD_SPHERE_RADIUS+a)*sin(THETA(p.y))*sin(PHI(p.x)));
        vertex->push_back((WORLD_SPHERE_RADIUS+a)*cos(THETA(p.y)));
        vertex->push_back((WORLD_SPHERE_RADIUS+a)*sin(THETA(p.y))*cos(PHI(p.x)));
        pos+=3;
    }
    return pos;
}
Example #2
0
double nfst_phi( nfst_plan *ths, double x, int d)
{
  NFST_PRE_WINFUN( d);
  double phi_tmp = PHI( x, d);
  NFST_POST_WINFUN( d);

  return phi_tmp;
}
Example #3
0
GLuint cFileData::getDisplayList() {
    cDataFieldT<vtkPoint>* df_p =
        static_cast<cDataFieldT<vtkPoint>*>(getDatafield("POINTS"));
    if (!df_p)
        return 0;
    cDataFieldT<float>* df_a =
        static_cast<cDataFieldT<float>*>(getDatafield("altitude"));
    if (!df_a)
        return 0;
    cDataFieldT<unsigned char>* df_d =
        static_cast<cDataFieldT<unsigned char>*>(getDatafield("detection"));
    if (!df_d)
        return 0;
    GLuint n;
    glNewList(n, GL_COMPILE);
    GLUquadricObj *gSphere = gluNewQuadric();
    gluQuadricNormals(gSphere, GLU_SMOOTH);
    float mat_emission_detection4[4] = {0.8f, 0.2f, 0.2f, 0.0f};
    float mat_emission[4] = {0.2f, 0.2f, 0.8f, 0.0f};
    float scaleFac = WORLD_SPHERE_RADIUS/EARTH_RADIUS;
    glEnable(GL_LIGHTING);
    for (int i=0; i < df_p->numEntries(); ++i) {
        vtkPoint p = df_p->getValueAt(i);
        float a = df_a->getValueAt(i)*scaleFac;
        if (df_d->getValueAt(i) == 4)
            glMaterialfv(GL_FRONT, GL_DIFFUSE, mat_emission_detection4);
        else
            glMaterialfv(GL_FRONT, GL_DIFFUSE, mat_emission);
        glPushMatrix();
        glTranslatef((WORLD_SPHERE_RADIUS+a)*sin(THETA(p.y))*sin(PHI(p.x)),
                     (WORLD_SPHERE_RADIUS+a)*cos(THETA(p.y)),
                     (WORLD_SPHERE_RADIUS+a)*sin(THETA(p.y))*cos(PHI(p.x)));
        gluSphere(gSphere, 0.1f, 6, 6);
        glPopMatrix();
    }
    glEnable(GL_LIGHTING);
    gluDeleteQuadric(gSphere);
    glEndList();

    return n;
}
  /// Add an Argument to the basic block.
  static SILValue CreateEmptyPHI(SILBasicBlock *BB, unsigned NumPreds,
                                 SILSSAUpdater *Updater) {
    // Add the argument to the block.
    SILValue PHI(new (BB->getModule()) SILArgument(BB, Updater->ValType), 0);

    // Mark all predecessor blocks with the sentinel undef value.
    SmallVector<SILBasicBlock*, 4> Preds(BB->pred_begin(), BB->pred_end());
    for (auto *PredBB: Preds) {
      TermInst *TI = PredBB->getTerminator();
      addNewEdgeValueToBranch(TI, BB, SILValue(Updater->PHISentinel.get(), 0));
    }
    return PHI;
  }
Example #5
0
int cFileData::getPointData(std::vector<float> *vertex) {
    cDataFieldT<vtkPoint>* df_p =
        static_cast<cDataFieldT<vtkPoint>*>(getDatafield("POINTS"));
    if (!df_p)
        return 0;
    cDataFieldT<float>* df_a =
        static_cast<cDataFieldT<float>*>(getDatafield("altitude"));
    if (!df_a)
        return 0;
    int pos = 0;
    vertex->reserve(df_p->numEntries()*3);
    float scaleFac = 5.0*(float)WORLD_SPHERE_RADIUS/EARTH_RADIUS;
    for (int i=0; i < df_p->numEntries(); ++i) {
        vtkPoint p = df_p->getValueAt(i);
        float a = df_a->getValueAt(i)*scaleFac;
        vertex->push_back((WORLD_SPHERE_RADIUS+a)*sin(THETA(p.y))*sin(PHI(p.x)));
        vertex->push_back((WORLD_SPHERE_RADIUS+a)*cos(THETA(p.y)));
        vertex->push_back((WORLD_SPHERE_RADIUS+a)*sin(THETA(p.y))*cos(PHI(p.x)));
        pos+=3;
    }
    return pos;
}
Example #6
0
void BackboneAngles(CHAIN **Chain, int NChain)
{

  register int Res, Cn;

  for( Cn=0; Cn<NChain; Cn++ ) {

    for( Res=0; Res<Chain[Cn]->NRes; Res++ ) {
      PHI(Chain[Cn],Res);
      PSI(Chain[Cn],Res);
    }
  }
}
Example #7
0
  void Identity::update(Eigen::VectorXdRefConst x, const int t)
  {
    if (!isRegistered(t))
    {
      throw_named("Not fully initialized!");
    }
//        std::cout<<"Updating ";
//        for(int i=0;i<jointMap.size();i++)
//        	std::cout<<(*posesJointNames)[jointMap[i]]<<" ";
//        std::cout<<std::endl;
    if (x.rows() >= PHI.rows())
    {
      if (useRef)
      {
        if (updateJacobian_)
        JAC.setZero();
        for (int i = 0; i < jointMap.size(); i++)
        {
          PHI(i) = x(jointMap[i]) - jointRef(i);
          if (updateJacobian_)
          {
            JAC(i, jointMap[i]) = 1.0;
          }
        }
      }
      else
      {
        PHI = x;
        if (updateJacobian_)
        {
          JAC = Eigen::MatrixXd::Identity(x.rows(), x.rows());
        }
      }
    }
    else
    {
      throw_named("Size mismatch "<<x.rows()<<"!="<<PHI.rows());
    }
  }
Example #8
0
void two_phase_3d_op_explicit(double phi[M][N][P],
			      const double u0[M][N][P],
			      double curvature_motion_part[M][N][P],
			      double dt, double c1, double c2)
{
	double mu = TP_MU;
	double nu = TP_NU;
	double lambda1 = TP_LAMBDA1;
	double lambda2 = TP_LAMBDA2;

	double dx = 1.0;
	double dy = 1.0;
	double dz = 1.0;

	double dx2 = dx * 2.0;
	double dy2 = dy * 2.0;
	double dz2 = dz * 2.0;

	double Dx_p, Dx_m;
	double Dy_p, Dy_m;
	double Dz_p, Dz_m;
	double Dx_0, Dy_0, Dz_0;

	double Dxx, Dyy, Dzz;
	double Dxy, Dxz, Dyz;

	double Grad, K;

	double stencil[3][3][3];
#pragma AP array_partition variable=stencil complete dim=0

	double numer, denom;

	uint32_t i, j, k, l;

	for (i = 1; i < M - 1; i++) {
		for (j = 1; j < N - 1; j++) {
			for (k = 1; k < P - 1; k++) {
#pragma AP pipeline
				/* stencil code */
				stencil[0][0][0] = stencil[0][0][1];
				stencil[0][1][0] = stencil[0][1][1];
				stencil[0][2][0] = stencil[0][2][1];

				stencil[0][0][1] = stencil[0][0][2];
				stencil[0][1][1] = stencil[0][1][2];
				stencil[0][2][1] = stencil[0][2][2];

				stencil[0][0][2] = PHI(i - 1, j - 1, k + 1);
				stencil[0][1][2] = PHI(i - 1, j, k + 1);
				stencil[0][2][2] = PHI(i - 1, j + 1, k + 1);

				stencil[1][0][0] = stencil[1][0][1];
				stencil[1][1][0] = stencil[1][2][1];
				stencil[1][2][0] = stencil[1][2][1];

				stencil[1][0][1] = stencil[1][0][2];
				stencil[1][1][1] = stencil[1][1][2];
				stencil[1][2][1] = stencil[1][2][2];

				stencil[1][0][2] = PHI(i, j - 1, k + 1);
				stencil[1][1][2] = PHI(i, j, k + 1);
				stencil[1][2][2] = PHI(i, j + 1, k + 1);

				stencil[2][0][0] = stencil[2][0][1];
				stencil[2][1][0] = stencil[2][1][1];
				stencil[2][2][0] = stencil[2][2][1];

				stencil[2][0][1] = stencil[2][0][2];
				stencil[2][1][1] = stencil[2][1][2];
				stencil[2][2][1] = stencil[2][2][2];

				stencil[2][0][2] = PHI(i + 1, j - 1, k + 1);
				stencil[2][1][2] = PHI(i + 1, j, k + 1);
				stencil[2][2][2] = PHI(i + 1, j + 1, k + 1);

				/* regular calculation here */
				Dx_p =
				    (stencil[2][1][1] - stencil[1][1][1]) / dx;
				Dx_m =
				    (stencil[1][1][1] - stencil[0][1][1]) / dx;
				Dy_p =
				    (stencil[1][2][1] - stencil[1][1][1]) / dy;
				Dy_m =
				    (stencil[1][1][1] - stencil[1][0][1]) / dy;
				Dz_p =
				    (stencil[1][1][2] - stencil[1][1][1]) / dz;
				Dz_m =
				    (stencil[1][1][1] - stencil[1][1][0]) / dz;

				Dx_0 =
				    (stencil[2][1][1] - stencil[0][1][1]) / dx2;
				Dy_0 =
				    (stencil[1][2][1] - stencil[1][0][1]) / dy2;
				Dz_0 =
				    (stencil[1][1][2] - stencil[1][1][0]) / dz2;

				Dxx = (Dx_p - Dx_m) / dx;
				Dyy = (Dy_p - Dy_m) / dy;
				Dzz = (Dz_p - Dz_m) / dz;

				Dxy =
				    (stencil[2][2][1] - stencil[2][0][1] -
				     stencil[0][2][1] -
				     stencil[0][0][1]) / (4 * dx * dy);
				Dxz =
				    (stencil[2][1][2] - stencil[2][1][0] -
				     stencil[0][1][2] +
				     stencil[0][1][0]) / (4 * dx * dz);
				Dyz =
				    (stencil[1][2][2] - stencil[1][2][0] -
				     stencil[1][0][2] +
				     stencil[1][0][0]) / (4 * dy * dz);

				Grad = (SQR(Dx_0) + SQR(Dy_0) + SQR(Dz_0));
				denom = Grad;

				/* denom = denom^1.5 */
				for (l = 0; l < 3; l++) {
#pragma AP unroll
					denom *= denom;
				}
				q3_sqrt(denom);

				numer = (Dx_0 * Dx_0 * Dyy -
					 2.0 * Dx_0 * Dy_0 * Dxy +
					 Dy_0 * Dy_0 * Dxx + Dx_0 * Dx_0 * Dzz -
					 2.0 * Dx_0 * Dz_0 * Dxz +
					 Dz_0 * Dz_0 * Dxx + Dy_0 * Dy_0 * Dzz -
					 2.0 * Dy_0 * Dz_0 * Dyz +
					 Dz_0 * Dz_0 * Dyy);

				K = numer / denom;

				CMP(i, j, k) =
				    Grad * (mu * K +
					    lambda1 * (U0(i, j, k) -
						       c1) * (U0(i, j,
								 k) - c1) -
					    lambda2 * (U0(i, j, k) -
						       c2) * (U0(i, j,
								 k) - c2));
			}
		}
	}

	neumann_bc(curvature_motion_part);

	for (k = 0; k < P; k++) {
		for (j = 0; j < N; j++) {
			for (i = 0; i < M; i++) {
#pragma AP pipeline
				PHI(i, j, k) += CMP(i, j, k) * dt;
			}
		}
	}
}
Example #9
0
/** more memory usage, a bit faster */
void nfst_full_psi(nfst_plan *ths, double eps)
{
  int t, i;                             /**< index over all dimensions        */
  int j;                                /**< index over all nodes             */
  int l_L;                              /**< plain index 0<=l_L<lprod         */
  int lc[ths->d];                       /**< multi index 0<=lj<u+o+1          */
  int lg_plain[ths->d+1];               /**< postfix plain index              */
  int count_lg[ths->d];
  int lg_offset[ths->d];
  int lg[ths->d];
  int lprod;                            /**< 'bandwidth' of matrix B          */
  int lb[ths->d];                       /**< depends on x_j                   */

  double phi_tilde[ths->d+1];

  int *index_g, *index_f;
  double *new_psi;
  int ix, ix_old, size_psi;

  phi_tilde[0] = 1.0;
  lg_plain[0]  =   0;

  if(ths->nfst_flags & PRE_PSI)
  {
    size_psi = ths->M_total;
    index_f  =    (int*)nfft_malloc( ths->M_total  * sizeof( int));
    index_g  =    (int*)nfft_malloc( size_psi * sizeof( int));
    new_psi  = (double*)nfft_malloc( size_psi * sizeof( double));

    for( t = 0,lprod = 1; t < ths->d; t++)
    {
      lprod *= NFST_SUMMANDS;
      eps *= PHI( 0, t);
    }

    for( ix = 0, ix_old = 0, j = 0; j < ths->M_total; j++)
    {
      MACRO_init_lb_lg_lc_phi_tilde_lg_plain( with_PRE_PSI);

      for( l_L = 0; l_L < lprod; l_L++)
      {
        MACRO_update__phi_tilde__lg_plain( with_PRE_PSI);

        if( fabs(phi_tilde[ths->d]) > eps)
        {
          index_g[ix] =  lg_plain[ths->d];
          new_psi[ix] = phi_tilde[ths->d];

          ix++;
          if( ix == size_psi)
          {
            size_psi += ths->M_total;
            index_g   =    (int*)realloc( index_g, size_psi * sizeof( int));
            new_psi   = (double*)realloc( new_psi, size_psi * sizeof( double));
          }
        }
        MACRO_count__lg_lc;

      } /* for(l_L) */

      index_f[j] = ix - ix_old;
      ix_old     = ix;

    } /* for(j) */

    nfft_free( ths->psi);

    size_psi      = ix;
    ths->size_psi = size_psi;
    index_g       = (int*)realloc( index_g, size_psi * sizeof( int));
    new_psi       = (double*)realloc( new_psi, size_psi * sizeof( double));

    ths->psi         = new_psi;
    ths->psi_index_g = index_g;
    ths->psi_index_f = index_f;

  } /* if(PRE_PSI) */
} /* nfst_full_psi */
int CFEAT::k1DC0LElement (int nE, CVector<int>& nVNList,
                          CMatrix<double>& dMk,CMatrix<double> & dTF)
// ==================================================================
// Function: Generates k for the 1D-C0 linear element
//    Input: Element number
//   Output: Element stiffness matrix in dMk
//           a return value of 0 means no error
// ==================================================================
{

    CVector<float> fVMatP(NUMEP);     // young's modulus
    CVector<float> fVCoords1(PDIM);     // nodal coordinates (node 1)
    CVector<float> fVCoords2(PDIM);     // nodal coordinates (node 2)
    CVector<float> fVCoords3(PDIM);    // nodal coordinates (node 3)
    CVector<float> fVCoords4(PDIM);    // nodal coordinates (node 4)
    CVector<int> nVN(NUMENODES);
    CElement::type VC;
    // get element data
    m_ElementData(nE).GetMaterialProperty(fVMatP);
    m_ElementData(nE).GetNodes(nVN);
    m_ElementData(nE).Getstressstrain(VC);
    m_NodalData(nVN(1)).GetCoords (fVCoords1);
    m_NodalData(nVN(2)).GetCoords (fVCoords2);
    m_NodalData(nVN(3)).GetCoords (fVCoords3);
    m_NodalData(nVN(4)).GetCoords (fVCoords4);
    float x = 0.0f;
    CGaussQuad GQ;          // for numerical integration via G-Q
    const int NORDER = 2;   // numerical integration order
    const int NGP    = 2;   // # of G-Q points
    CVector<double> PHI(NUMENODES);    // shape functions
    CVector<double> DPHDXI(NUMENODES); // derivatives of shape functions
    CVector<double> DPHDX(NUMENODES);  // derivatives of shape functions (wrt x)
    CMatrix<double> DJAC(NORDER,NORDER);
    CMatrix<double> DJACIN(NORDER,NORDER);
    CMatrix<double> DO(3,4),DN(4,8),DBT(8,3),DT(8,3),DK(8,8),DTE(8,1),DTI(3,3),DTT(8,3);
    double delta=0.0,DETJAC;
    float T;
    DB.Set(0.0);
    DN.Set(0.0);
    DO.Set(0.0);
    DBT.Set(0.0);
    DT.Set(0.0);
    DEO.Set(0.0);
    DTE.Set(0.0);
    DD.Set(0.0);
    DK.Set(0.0);
    DTI.Set(0.0);
    DTT.Set(0.0);
    int i, j;

    for (int NG=1; NG <= NGP; NG++)
    {
        for (int NN=1; NN<=NGP; NN++)
        {
            // gauss-point and weight
            double PXI = GQ.GetLocation (NORDER, NG);
            double PNI = GQ.GetLocation (NORDER, NN);
            double WG1  = GQ.GetWeight (NORDER, NG);
            double WG2  = GQ.GetWeight (NORDER, NN);
            // shape functions
            PHI(1)=0.25*(1.0-PXI)*(1.0-PNI);
            PHI(2)=0.25*(1.0+PXI)*(1.0-PNI);
            PHI(3)=0.25*(1.0+PXI)*(1.0+PNI);
            PHI(4)=0.25*(1.0-PXI)*(1.0+PNI);

            double a=fVCoords1(1)-fVCoords2(1)+fVCoords3(1)-fVCoords4(1);
            double a1=-fVCoords1(1)+fVCoords2(1)+fVCoords3(1)-fVCoords4(1);
            double a2=-fVCoords1(1)-fVCoords2(1)+fVCoords3(1)+fVCoords4(1);
            double b=fVCoords1(2)-fVCoords2(2)+fVCoords3(2)-fVCoords4(2);
            double b1=-fVCoords1(2)+fVCoords2(2)+fVCoords3(2)-fVCoords4(2);
            double b2=-fVCoords1(2)-fVCoords2(2)+fVCoords3(2)+fVCoords4(2);

            // compute jacobian
            DJAC(1,1)=(PNI*a+a1)*0.25;
            DJAC(1,2)=(PNI*b+b1)*0.25;
            DJAC(2,1)=(PXI*a+a2)*0.25;
            DJAC(2,2)=(PXI*b+b2)*0.25;

            DETJAC=DJAC(1,1)*DJAC(2,2)-DJAC(1,2)*DJAC(2,1);

            /*if(DETJAC==0)
            	ErrorHandler(INVERSEERROR);*/
            // compute inverse of jacobian
            DJACIN(1,1)=DJAC(2,2)/DETJAC;
            DJACIN(2,2)=DJAC(1,1)/DETJAC;
            if(DJAC(1,2)!=0)
                DJACIN(1,2)=-DJAC(1,2)/DETJAC;
            else
                DJACIN(1,2)=DJAC(1,2)/DETJAC;
            if(DJAC(2,1)!=0)
                DJACIN(2,1)=-DJAC(2,1)/DETJAC;
            else
                DJACIN(2,1)=DJAC(2,1)/DETJAC;
            DO(1,1)=DJACIN(1,1);
            DO(1,2)=DJACIN(1,2);
            DO(2,3)=DJACIN(2,1);
            DO(2,4)=DJACIN(2,2);
            DO(3,1)=DJACIN(2,1);
            DO(3,2)=DJACIN(2,2);
            DO(3,3)=DJACIN(1,1);
            DO(3,4)=DJACIN(1,2);

            DN(1,1)=DN(3,2)= -(1-PNI);
            DN(1,3)=DN(3,4)= -DN(1,1);
            DN(1,5)=DN(3,6)=  (1+PNI);
            DN(1,7)=DN(3,8)= -DN(1,5);
            DN(2,1)=DN(4,2)= -(1-PXI);
            DN(2,3)=DN(4,4)= -(1+PXI);
            DN(2,5)=DN(4,6)= -DN(2,3);
            DN(2,7)=DN(4,8)= -DN(2,1);
            if (VC==0)
            {
                DD(1,1)=DD(2,2)=fVMatP(2)/(1-fVMatP(3)*fVMatP(3));
                DD(1,2)=DD(2,1)=fVMatP(3)*fVMatP(2)/(1-fVMatP(3)*fVMatP(3));
                DD(3,3)=0.5*(1-fVMatP(3))*fVMatP(2)/(1-fVMatP(3)*fVMatP(3));
            }
            else
            {
                DD(1,1)=DD(2,2)=(1-fVMatP(3))*fVMatP(2)/((1+fVMatP(3))*(1-2*fVMatP(3)));
                DD(1,2)=DD(2,1)=fVMatP(3)*fVMatP(2)/((1+fVMatP(3))*(1-2*fVMatP(3)));
                DD(3,3)=(0.5-fVMatP(3))*fVMatP(2)/((1+fVMatP(3))*(1-2*fVMatP(3)));
            }
            Multiply(DO,DN,DB);
            for(int h=1; h<=4; h++)
            {
                m_NodalData(nVN(h)).GetTemp(T);
                delta+=PHI(h)*T;
            }
            if(VC==0)
                DEO(1,1)=DEO(2,1)=fVMatP(4)*delta;
            else
                DEO(1,1)=DEO(2,1)=(1+fVMatP(3))*fVMatP(4)*delta;

            // compute stiffness at gauss point
            for (i=1; i <= 3; i++)
                for (j=1; j <= 3; j++)
                    DTI(i,j) += WG1*WG2*DD(i,j)*fVMatP(1)*DETJAC;
            Transpose(DB,DBT);
            Multiply(DBT,DTI,DT);
            Multiply(DBT,DD,DTT);
            Multiply(DTT,DEO,DTE);
            Multiply(DT,DB,DK);
            for(int k=1; k<=2*NUMENODES; k++)
            {
                dTF(k,1) += WG1*WG2*DTE(i,1)*fVMatP(1);
                for(int l=1; l<=2*NUMENODES; l++)
                    dMk(k,l)+=DK(k,l);
            }
        }
    }



    // debug?
    return 0;
}