// Increments clock
void timerCallback( TimerHandle_t myTimer )
{
    traces(TIMER_CALLBACK_ENTER);
    updateClock();
    //void sendtoServer(void); // testing 

    traces(TIMER_CALLBACK_EXIT);
}
Пример #2
0
   // ----------------------------------------------------------------------
   std::string WisemlDataKeeper::generate_xml()
   {
      std::stringstream wml;
      wml << "<?xml version=\"1.0\" encoding=\"UTF-8\"?>" << std::endl;
      wml << "<wiseml xmlns=\"http://wisebed.eu/ns/wiseml/1.0\" version=\"1.0\">" << std::endl;
      wml << setup_->generate_xml();

      std::list<WisemlScenarioCollector*> scens = scenarios();
      for(list<WisemlScenarioCollector*>::iterator sit =
         scens.begin(); sit != scens.end(); ++sit)
      {
         wml << (*sit)->generate_xml() << std::endl;
      }

      std::list<WisemlTraceCollector*> tracs = traces();
      for(list<WisemlTraceCollector*>::iterator tit =
         tracs.begin(); tit != tracs.end(); ++tit)
      {
         wml << (*tit)->generate_xml() << std::endl;
      }

      wml << "</wiseml>" << std::endl;

      return wml.str();
   }
Пример #3
0
void RECEIVE_Initialize(void) {
    traces(RECEIVE_INIT_ENTER);
    // Create queue, 80 slots, each one byte in size
    rcvData.rcvQueue = xQueueCreate(80, sizeof (char));
    // Verifies queue created
    if (rcvData.rcvQueue == 0)
        error('c');

    // Initialize parameters
    rcvData.currentIndex = 0;
    
    timer_initialize(100);
    DRV_USART0_Initialize();
    rcvData.clock = 0;
    rcvData.sequence = 0;
    rcvData.x_in = 0; 
    
    
    RGB_Initialize();
    
    traces(RECEIVE_INIT_EXIT);
}
Пример #4
0
std::vector<Trace> Engine::oscilloscope() {
  std::vector<Trace> traces(detectors_.size());

  for (auto &q : devices_)
    if ((q.second != nullptr) && (q.second->status() & DeviceStatus::can_oscil)) {
      //PL_DBG << "oscil > " << q.second->device_name();
      std::map<int, std::vector<uint16_t>> trc = q.second->oscilloscope();
      for (auto &p : trc) {
        if ((p.first >= 0) && (p.first < detectors_.size())) {
          traces[p.first].data = p.second;
          traces[p.first].index = p.first;
          traces[p.first].detector = detectors_[p.first];
        }
      }
    }
  return traces;
}
Пример #5
0
// ##################################################################
// Originally from smoothLoops.c
//
// smooth the loops and not the nodes
//
// ##################################################################
void smoothLoops(GRID *g)
{

   printf("#meshgen: Smoothing along loops ...\n");

   int     i,ii,j,k1,k2,m,kk;
   int     msweep,temp0,temp1,temp2,threeNum;
   int     i1,i2,nel,e1,e2,is,ie;
   int     edge1[2],edge2[2];
   int     *vert4ID,*vert4Index;
   double *x1,sum1,sum2,sum3;
   x1 = (double *) malloc(sizeof(double)*3*g->numNodePos);
   
   threeNum = 3*g->numNodePos;
   for (i = 0; i < threeNum; i++)
      x1[i] = g->allNodePos[i];

   g->vert1Loop = (LOOP *) malloc(sizeof(LOOP));
   g->vert2Loop = (LOOP *) malloc(sizeof(LOOP));
   g->vert3Loop = (LOOP *) malloc(sizeof(LOOP));

   // set the total length of these loops
   g->vert1Loop->totLen = 0.5*(g->quadLoop->totLen);
   g->vert2Loop->totLen = 0.5*(g->quadLoop->totLen);
   g->vert3Loop->totLen = 0.5*(g->quadLoop->totLen);

   g->vert1Loop->ID = (int *) malloc(sizeof(int)*g->vert1Loop->totLen);
   g->vert2Loop->ID = (int *) malloc(sizeof(int)*g->vert2Loop->totLen);
   g->vert3Loop->ID = (int *) malloc(sizeof(int)*g->vert3Loop->totLen);
   vert4ID          = (int *) malloc(sizeof(int)*g->vert3Loop->totLen);

   g->vert1Loop->index = (int *) malloc(sizeof(int)*(1+g->numTriNode));
   g->vert2Loop->index = (int *) malloc(sizeof(int)*(1+g->numTriNode));
   g->vert3Loop->index = (int *) malloc(sizeof(int)*(1+g->numTriNode));
   vert4Index          = (int *) malloc(sizeof(int)*(1+g->numTriNode));

   int iouter  = 1;
   int iinner  = 1;
   int imiddle = 1;
   int iinnest = 1;

   // Initialize
   for (i = 0; i <= g->numTriNode; i++)
   {
      g->vert1Loop->index[i] = g->vert2Loop->index[i] = 0;
      g->vert3Loop->index[i] = vert4Index[i] = 0;
   }

// ==================================================================
// Set up the indices for the different loops
// 4 loops per node
// ==================================================================   
   k1 = 0; k2 = 0; kk = 0;
   // Loop through the number of nodes
   for (i = 0; i < g->numTriNode; i++)
   {
      //ii = g->colourIndex[i];

      // ============================================================
      // INNERMOST LOOP
      // ============================================================
      // indices for start and end of the inner and outer loop
      // for a given triangular node
      i1  = g->iqloop3[i];
      i2  = g->iqloop3[i+1];      
      nel = i2-i1;

      // Loop through the inner
      for (j = i1; j < i2; j++)
      {
         e1 = g->q3loop[j];         

         edge1[0] = g->quadEdge[e1][0];
         edge1[1] = g->quadEdge[e1][1];

         //vert4ID[k2] = edge1[0];
         vert4ID[k2] = edge1[1];
         k2++;
      } // j loop
      vert4Index[kk+1] = vert4Index[kk] + nel;
   
      // ============================================================
      // 3 other loops
      // ============================================================
      // indices for start and end of the inner and outer loop
      // for a given triangular node
      i1  = g->quadLoop->index[2*i  ];
      i2  = g->quadLoop->index[2*i+1];            
      nel = i2-i1;      

      // Loop through the inner
      for (j = i1; j < i2; j++)
      {
         e1 = g->quadLoop->ID[j];
         e2 = g->quadLoop->ID[j+nel];

         edge1[0] = g->quadEdge[e1][0];
         edge1[1] = g->quadEdge[e1][1];

         edge2[0] = g->quadEdge[e2][0];
         edge2[1] = g->quadEdge[e2][1];

         // Note that edge1[1] and edge2[0] are always
         // the same. Therefore the other remaining
         // vertex IDs are those of the two loops
         g->vert1Loop->ID[k1] = edge1[0];
         g->vert2Loop->ID[k1] = edge2[1];
         g->vert3Loop->ID[k1] = edge1[1];
         k1++;
      } // j loop


      g->vert1Loop->index[kk+1] = g->vert1Loop->index[kk] + nel;
      g->vert2Loop->index[kk+1] = g->vert2Loop->index[kk] + nel;
      g->vert3Loop->index[kk+1] = g->vert3Loop->index[kk] + nel;

      
      kk++;


   } // i loop

// ==================================================================
// With the created vert loops - apply laplacian smoothing
// to each of the loops
// Perform the sweeps   
// ==================================================================   
   msweep = 5;
   traces('are you sure that msweep is 5?');
   exit(1);
   for (m = 0; m < msweep; m++)
   {
      for (i = 0; i < g->numTriNode; i++)
      {         
         
         // =========================================================
         // INNERMOST LOOP
         // =========================================================
         i1 = vert4Index[i];
         i2 = vert4Index[i+1];
         nel= i2-i1;
         sum1=sum2=sum3=0.0;nel=0;
         // smooth the positions (same for open or closed loop)
         for (j = i1+1; j < i2-2; j++)
         {  
            temp0 = 3*vert4ID[j];
            temp1 = 3*vert4ID[j-1];
            temp2 = 3*vert4ID[j+1];
            
            if(iinnest==1)
            {
               x1[temp0  ] = 0.5*(g->allNodePos[temp1  ] + g->allNodePos[temp2  ]);
               x1[temp0+1] = 0.5*(g->allNodePos[temp1+1] + g->allNodePos[temp2+1]);
               x1[temp0+2] = 0.5*(g->allNodePos[temp1+2] + g->allNodePos[temp2+2]);
               sum1 += g->allNodePos[temp0];
               sum2 += g->allNodePos[temp0+1];
               sum3 += g->allNodePos[temp0+2];
               nel++;
            }

         } // j loop
         
         if( vert4ID[i1] == vert4ID[i2-1])
         {
            temp0 = 3*vert4ID[i1];
            temp1 = 3*vert4ID[i1+1];
            temp2 = 3*vert4ID[i2-1];

            if(iinnest==1)
            {
               x1[temp0  ] = 0.5*(g->allNodePos[temp1  ] + g->allNodePos[temp2  ]);
               x1[temp0+1] = 0.5*(g->allNodePos[temp1+1] + g->allNodePos[temp2+1]);
               x1[temp0+2] = 0.5*(g->allNodePos[temp1+2] + g->allNodePos[temp2+2]);
               sum1 += g->allNodePos[temp0];
               sum2 += g->allNodePos[temp0+1];
               sum3 += g->allNodePos[temp0+2];
               nel++;
            }
         
         }
         ii = g->colourIndex[i];
         if(iinnest==1)
         {
            x1[3*ii  ] = sum1/nel;
            x1[3*ii+1] = sum2/nel;
            x1[3*ii+2] = sum3/nel;
         }
         
         // =========================================================
         // OUTER 3 LOOPS
         // =========================================================
         i1  = g->vert1Loop->index[i];
         i2  = g->vert1Loop->index[i+1];
         nel = i2-i1;

         // smooth the positions (same for open or closed loop)
         for (j = i1+1; j < i2-2; j++)
         {  
            
            // OUTER LOOP       
            temp0 = 3*g->vert1Loop->ID[j];
            temp1 = 3*g->vert1Loop->ID[j-1];
            temp2 = 3*g->vert1Loop->ID[j+1];
            
            if(iouter==1)
            {
               x1[temp0  ] = 0.5*(g->allNodePos[temp1  ] + g->allNodePos[temp2  ]);
               x1[temp0+1] = 0.5*(g->allNodePos[temp1+1] + g->allNodePos[temp2+1]);
               x1[temp0+2] = 0.5*(g->allNodePos[temp1+2] + g->allNodePos[temp2+2]);
            }
            // INNER LOOP         
            temp0 = 3*g->vert2Loop->ID[j];
            temp1 = 3*g->vert2Loop->ID[j-1];
            temp2 = 3*g->vert2Loop->ID[j+1];
            
            if(iinner==1)
            {
               x1[temp0  ] = 0.5*(g->allNodePos[temp1  ] + g->allNodePos[temp2  ]);
               x1[temp0+1] = 0.5*(g->allNodePos[temp1+1] + g->allNodePos[temp2+1]);
               x1[temp0+2] = 0.5*(g->allNodePos[temp1+2] + g->allNodePos[temp2+2]);
            }

            // MIDDLE LOOP
            temp0 = 3*g->vert3Loop->ID[j];
            temp1 = 3*g->vert3Loop->ID[j-1];
            temp2 = 3*g->vert3Loop->ID[j+1];
            
            if(imiddle==1)
            {
               x1[temp0  ] = 0.5*(g->allNodePos[temp1  ] + g->allNodePos[temp2  ]);
               x1[temp0+1] = 0.5*(g->allNodePos[temp1+1] + g->allNodePos[temp2+1]);
               x1[temp0+2] = 0.5*(g->allNodePos[temp1+2] + g->allNodePos[temp2+2]);
            }
         } // j loop
         
         // check if closed loop or not. Done by checking the
         // vert ID of the beginning and end of the loop. Can use
         // wither vert1Loop or vert2Loop      
         
         if( g->vert1Loop->ID[i1] == g->vert1Loop->ID[i2-1])
         {
            temp0 = 3*g->vert1Loop->ID[i1];
            temp1 = 3*g->vert1Loop->ID[i1+1];
            temp2 = 3*g->vert1Loop->ID[i2-1];

            if(iouter==1)
            {
               x1[temp0  ] = 0.5*(g->allNodePos[temp1  ] + g->allNodePos[temp2  ]);
               x1[temp0+1] = 0.5*(g->allNodePos[temp1+1] + g->allNodePos[temp2+1]);
               x1[temp0+2] = 0.5*(g->allNodePos[temp1+2] + g->allNodePos[temp2+2]);
            }

            // INNER LOOP
            temp0 = 3*g->vert2Loop->ID[i1];
            temp1 = 3*g->vert2Loop->ID[i1+1];
            temp2 = 3*g->vert2Loop->ID[i2-1];
            
            if(iinner==1)
            {
               x1[temp0  ] = 0.5*(g->allNodePos[temp1  ] + g->allNodePos[temp2  ]);
               x1[temp0+1] = 0.5*(g->allNodePos[temp1+1] + g->allNodePos[temp2+1]);
               x1[temp0+2] = 0.5*(g->allNodePos[temp1+2] + g->allNodePos[temp2+2]);
            }

            // MIDDLE LOOP
            temp0 = 3*g->vert3Loop->ID[i1];
            temp1 = 3*g->vert3Loop->ID[i1+1];
            temp2 = 3*g->vert3Loop->ID[i2-1];
            
            if(imiddle==1)
            {
               x1[temp0  ] = 0.5*(g->allNodePos[temp1  ] + g->allNodePos[temp2  ]);
               x1[temp0+1] = 0.5*(g->allNodePos[temp1+1] + g->allNodePos[temp2+1]);
               x1[temp0+2] = 0.5*(g->allNodePos[temp1+2] + g->allNodePos[temp2+2]);
            }
         }

      } // i loop

// ==================================================================         
// POSITION UPDATE
// ==================================================================            
      for (i = 0; i < g->numNodePos; i++)
      {         
         //i = g->colourIndex[ii];
         g->allNodePos[3*i  ] = g->iBoundary[i]*g->allNodePos[3*i  ]+x1[3*i  ]*(1-g->iBoundary[i]);
         g->allNodePos[3*i+1] = g->iBoundary[i]*g->allNodePos[3*i+1]+x1[3*i+1]*(1-g->iBoundary[i]);
         g->allNodePos[3*i+2] = g->iBoundary[i]*g->allNodePos[3*i+2]+x1[3*i+2]*(1-g->iBoundary[i]);
      }
      
   } // m loop

}
Пример #6
0
void updateClock() {
    traces(UPDATE_CLOCK);
    rcvData.clock++;
}
Пример #7
0
int addQRcv(char letter) {
    traces(ADD_Q_RCV_ENTER);
    if (xQueueSendFromISR(rcvData.rcvQueue, &letter, 0) != pdTRUE)
        error('b');
    traces(ADD_Q_RCV_EXIT);
}
Пример #8
0
// ##################################################################
//
// createVerticesOnEdge
//
// Function to create vertices on the triangle edges to form the 
// basis for the different quad cells
//
// ##################################################################
void recreateVerticesOnEdge(GRID *g)
{

   printf("#meshgen: Recreating vertices on triangular edges ...\n");

   int     i,i1,i2,j,k1,k2,ktemp;
   int     iSurface,nVert,nEdge;
   int    *vertID;
   double  posA[3],posB[3],posMid[3],deltaDist;
   double  normalA[3],normalB[3],normalMid[3];
   double *posVert, *normalVert;
   int     halfEdgePerSide = 0.5*g->nEdgePerSide;
   int     halfVertm1      = 0.5*(g->nVertPerSide-1);

   k1 = g->numTriNode;

   // allocate posVert   
   deltaDist  = (double) 2./g->nEdgePerSide;
   posVert    = (double *) malloc(sizeof(double)*3*g->nVertPerSide);
   normalVert = (double *) malloc(sizeof(double)*3*g->nVertPerSide);

   // Loop over total number of edges to generate 1/4, 1/2 and 3/4 
   // points along each edge and create basic connectivity info
   for (i = 0; i < g->numTriEdge; i++)
   {
      i1 = g->triEdge[i][0]; // one of the end nodes of the dge
      i2 = g->triEdge[i][1]; // other end node of the edge

      // index Id for points on edges
      ktemp = k1;

      //      0.25   0.25    0.25   0.25
      //    |------|------||------|------|
      //    A     A1      A2      A3    B
      for (j = 0; j < 3; j++ )
      {
         posA[j]   = g->allNodePos[3*i1 + j];
         posB[j]   = g->allNodePos[3*i2 + j];
         posMid[j] = g->allNodePos[3*(ktemp+halfVertm1) + j];  

         normalA[j]   = g->nodeNormal[3*i1 + j];
         normalB[j]   = g->nodeNormal[3*i2 + j];
         normalMid[j] = g->nodeNormal[3*(ktemp+halfVertm1) + j];  

         if(posMid[j] != posMid[j]) {traces(nan);exit(1);}
      }

      // Is this a domain specific condition. Must check.
      if ( strcmp(surfaceType,"naca")==0 && iHybrid != 1
            && (g->triEdge[i][3]==-1) 
            && (abs(posA[1])<0.61) && (abs(posA[0])<1.1) )
         iSurface = 1;                  
      else if ((strcmp(surfaceType,"sphere")==0 ||
               strcmp(surfaceType,"robin") ==0 ) && iHybrid != 1)
         iSurface = 1;
      else
         iSurface = 0;      

      // need to split this into A-D and then D-B
      // as D is altered based on the smoothing routines
      // add new vertices to the edge of a triangle      
      addVerticesOnEdge(posA,posMid,posVert,
                        normalA,normalMid,normalVert,
                        iSurface,halfVertm1,deltaDist);

      // append the position of the newly formed vertices onto
      // the edge array
      for (j = 0; j < halfVertm1; j++)
      {
         g->allNodePos[3*ktemp    ] = posVert[3*j    ];
         g->allNodePos[3*ktemp + 1] = posVert[3*j + 1];
         g->allNodePos[3*ktemp + 2] = posVert[3*j + 2];

         g->nodeNormal[3*ktemp    ] = normalVert[3*j    ];
         g->nodeNormal[3*ktemp + 1] = normalVert[3*j + 1];
         g->nodeNormal[3*ktemp + 2] = normalVert[3*j + 2];

         ktemp++;
      } // j loop
  
      ktemp++; // to skip mid point

      // add new vertices to the edge of a triangle
      addVerticesOnEdge(posMid,posB,posVert,
                        normalMid,normalB,normalVert,
                        iSurface,halfVertm1,deltaDist);

      for (j = 0; j < halfVertm1; j++)
      {
         g->allNodePos[3*ktemp    ] = posVert[3*j    ];
         g->allNodePos[3*ktemp + 1] = posVert[3*j + 1];
         g->allNodePos[3*ktemp + 2] = posVert[3*j + 2];

         g->nodeNormal[3*ktemp    ] = normalVert[3*j    ];
         g->nodeNormal[3*ktemp + 1] = normalVert[3*j + 1];
         g->nodeNormal[3*ktemp + 2] = normalVert[3*j + 2];

         ktemp++;
      } // j loop

      k1 += g->nVertPerSide; 

   } // i loop

   free(posVert);

}
Пример #9
0
// ##################################################################
//
// createInteriorVertices
//
// Go through the triangles and create the quad cells
//
// ##################################################################
void recreateInteriorVertices(GRID * g)
{

   printf("#meshgen: Recreating interior vertices ...\n");

   int      i,j,jj,n,nn,is1,is2,rowID,colID,counter;
   int      index,halfEdgePerSide,halfVertm1,itemp;
   int      k,kk,k1,k2,k3,k4,k5,k6,ktemp,ktemp3,ktemp4,ktemp5,ktemp6,koffset;
   int      iA,iB,iC,iD,iE,iF,iO;
   int      index1,index2,index3;
   int      edgeID[3],edge[4],dirAB,dirBC,dirCA;
   int     *vertID, iSurface;
   int      nodeMidDO,nodeMidEO,nodeMidFO;
   double   aa,bb,cc;
   double   A[3],B[3],C[3],O[3];
   double   deltaDist,deltaDistTemp;
   double  *boundaryPts, *intPts, *posVert, *normalVert;
   double   dummy1[3],dummy2[3];

   for (i = 0; i < 3; i++)
      dummy1[i] = dummy2[i] = 0.0;

   // ===============================================================
   // Initialization
   // ===============================================================
   halfEdgePerSide = 0.5*g->nEdgePerSide;
   halfVertm1      = 0.5*(g->nVertPerSide-1);
   int    edgePerQuad = 2*halfEdgePerSide*halfVertm1;
   int    halfhalfVertm1  = 0.5*(halfVertm1-1);
   int    halfVertp2 = halfVertm1 + 2;
   int    quadPtID[halfVertp2][halfVertp2];
   double quadPtPos[3*halfVertp2][3*halfVertp2];

   k1 = g->numTriNode + g->nVertPerSide*g->numTriEdge; // for center
   k2 = 0; // for edges
   k3 = g->nEdgePerSide*g->numTriEdge;
   k4 = k1 + g->numTriangle; // int edge points
   k5 = k4 + 3*halfVertm1*g->numTriangle; // quad int points
   k6 = k5; // for additional subdivision at triangular level

   aa = 0.5;
   bb = 0.5;
   cc = 0.5;

   // allocate posVert   
   deltaDist   = 1./halfEdgePerSide;
   posVert     = (double *) malloc(sizeof(double)*3*halfVertm1);
   normalVert  = (double *) malloc(sizeof(double)*3*halfVertm1);

   int     threenum = 3*g->numNodePos;
   double  weight;
   double *tempPos;

   tempPos = (double *) malloc(sizeof(double)*threenum);

   // initialization
   for (i = 0; i < threenum; i++)
      tempPos[i] = g->allNodePos[i];

   // ===============================================================
   //
   // Loop over all the triangles and build the cell connectivity
   // and edge information
   //
   // ===============================================================
   for (i = 0; i < g->numTriangle; i++)
   {
      iA = g->triConn[3*i  ];
      iB = g->triConn[3*i+1];
      iC = g->triConn[3*i+2];

      for (j = 0; j < 3; j++)
      {
         A[j] = g->allNodePos[3*iA + j]; // [x,y,z] coordinate of point A
         B[j] = g->allNodePos[3*iB + j]; // [x,y,z] coordinate of point B
         C[j] = g->allNodePos[3*iC + j]; // [x,y,z] coordinate of point C
      }
      
		// list of the edge ID for a given triangle
		edgeID[0] = g->edge2triList[3*i  ];
		edgeID[1] = g->edge2triList[3*i+1];
		edgeID[2] = g->edge2triList[3*i+2];    

		// Find the coordinate and indices of points on triangle edges
      // Loop over each of the three edges of a triangle
		for (j = 0; j < 3; j++)
		{
         // list columns 1--4 of a particular edge
         edge[0] = g->triEdge[edgeID[j]][0];
         edge[1] = g->triEdge[edgeID[j]][1];         

         // edge index in the allNodePos array
         is1     = g->numTriNode + g->nVertPerSide*(edgeID[j]);
         is2     = g->nEdgePerSide*(edgeID[j]); 

         // Obtain the node ID's of mid points and the direction of 
         // the edge (based on conventions previously defined)
         // =========================================================
         //  If the edge has the 1st node as node A
         // =========================================================
         if (edge[0] == iA)
         {
            // if the edge has the 2nd node as node (i.e, A-B)
            if (edge[1] == iB)
            {
               dirAB = 1;
               iD    = is1 + halfVertm1;
            }
            else if (edge[1] == iC)
            {
               dirCA = -1;
               iF    = is1 + halfVertm1;
            }
         } 

         // =========================================================
         //  If the edge has the 1st node as node B
         // =========================================================
         if (edge[0] == iB)
         {
            // if the edge has the 2nd node as node (i.e, A-B)
            if (edge[1] == iA)
            {
               dirAB = -1;
               iD    = is1 + halfVertm1;
            }
            else if (edge[1] == iC)
            {
               dirBC = 1;
               iE    = is1 + halfVertm1;
            }
         } 

         // =========================================================
         //  If the edge has the 1st node as node C
         // =========================================================
         if (edge[0] == iC)
         {
            // if the edge has the 2nd node as node (i.e, C-A)
            if (edge[1] == iA)
            {
               dirCA = 1;
               iF    = is1 + halfVertm1;  
            }
            else if (edge[1] == iB) // edge is C--B
            {
               dirBC = -1;
               iE    = is1 + halfVertm1;
            }
         }

      } // j loop (edgeID)

      // ============================================================
      // Add the center point
      // ============================================================
      ktemp = k1;
      iO    = ktemp;
      for (k = 0; k < 3; k++)
      {
          O[k] = ONE_THIRD*(A[k] + B[k] + C[k]);
          //g->allNodePos[3*iO + k] = O[k];                    
      }
      ktemp++; // update counter for center position

      // ============================================================
      // Loop over each of the three edges of a triangle
      // and add points along the connecting edges
      //
      // Also update the quadEdge
      // ============================================================
      ktemp3 = k3;
      ktemp4 = k4;
      ktemp5 = k5;
      ktemp6 = k6;

      for (j = 0; j < 3; j++)
      {
         // index of the middle point along any edge
         index   = g->numTriNode + g->nVertPerSide*edgeID[j]
                 + halfVertm1;

         if((strcmp(surfaceType,"sphere")==0 ||
            strcmp(surfaceType,"robin")==0 ) && iHybrid != 1)
            iSurface = 1;
         else 
            iSurface = 0;

         // add new vertices to the edge of a triangle      
         addVerticesOnEdge(&g->allNodePos[3*index],O,posVert,
                           &g->nodeNormal[3*index],&g->nodeNormal[3*iO],normalVert,
                           iSurface,halfVertm1,deltaDist);

         // append the position of the newly formed vertices on
         // the connecting edges to the allNodePos array         
         for (k = 0; k < halfVertm1; k++)
         {            
            g->allNodePos[3*ktemp4    ] = posVert[3*k    ];
            g->allNodePos[3*ktemp4 + 1] = posVert[3*k + 1];
            g->allNodePos[3*ktemp4 + 2] = posVert[3*k + 2];

            g->nodeNormal[3*ktemp4    ] = normalVert[3*k    ];
            g->nodeNormal[3*ktemp4 + 1] = normalVert[3*k + 1];
            g->nodeNormal[3*ktemp4 + 2] = normalVert[3*k + 2];

            tempPos[3*ktemp4  ] = g->allNodePos[3*ktemp4  ];
            tempPos[3*ktemp4+1] = g->allNodePos[3*ktemp4+1];
            tempPos[3*ktemp4+2] = g->allNodePos[3*ktemp4+2];

            ktemp4++;
         } // k loop


         if      (index == iD) // bordering Quad1 and Quad2
         {
            nodeMidDO         = ktemp4 - halfVertm1 + halfhalfVertm1; //
         }
         else if (index == iE) // bordering Quad2 and Quad3
         {
            nodeMidEO           = ktemp4 - halfVertm1 + halfhalfVertm1;
         }
         else if (index == iF) // bordering Quad1 and Quad3
         {
            nodeMidFO           = ktemp4 - halfVertm1 + halfhalfVertm1;
         }
         else
         {
            traces('Something is missing. Stopping.');
            exit(1);
         }

      } // j loop (loop over each edge)
      // ============================================================
      // Define and add the interior points and edges
      // Also define the quadConn for the interior cells using 
      // a temp array
      //
      // - Define interior points for each quad of a triangle
      // - Define interior edges of each quad of a triangle
      // - Define the quad loops for each quad of a triangle
      // ============================================================
      
      for (j = 0; j < 3; j++) // loop for each quad
      {
         if      (j == 0) // Quad ADOF
         {
            // corner points
            quadPtID[0           ][0           ] = iA;
            quadPtID[0           ][halfVertp2-1] = iF;
            quadPtID[halfVertp2-1][0           ] = iD;
            quadPtID[halfVertp2-1][halfVertp2-1] = iO;

            // other boundary points
            ktemp = halfVertm1;
            for (k = 0; k < halfVertm1; k++)
            {
               quadPtID[ktemp][0] = iD - dirAB*(k+1); // AD
               quadPtID[0][ktemp] = iF + dirCA*(k+1); // AF
               ktemp--; 

               quadPtID[halfVertp2-1][k+1] = nodeMidDO - halfhalfVertm1 + k; // DO
               quadPtID[k+1][halfVertp2-1] = nodeMidFO - halfhalfVertm1 + k; // FO
            }

         }
         else if (j == 1) // Quad DBEO
         {
            // corner points
            quadPtID[0           ][0           ] = iD;
            quadPtID[0           ][halfVertp2-1] = iO;
            quadPtID[halfVertp2-1][0           ] = iB;
            quadPtID[halfVertp2-1][halfVertp2-1] = iE;

            // other boundary points
            ktemp = halfVertm1;
            for (k = 0; k < halfVertm1; k++)
            {
               quadPtID[halfVertp2-1][ktemp] = iE - dirBC*(k+1); // BE
               quadPtID[ktemp][halfVertp2-1] = nodeMidEO - halfhalfVertm1 + k;// OE
               ktemp--; 

               quadPtID[k+1][0] = iD + dirAB*(k+1); // DB
               quadPtID[0][k+1] = nodeMidDO - halfhalfVertm1 + k;// DO
            
            }
         }
         else             // Quad OECF
         {
            // corner points
            quadPtID[0           ][0           ] = iO;
            quadPtID[0           ][halfVertp2-1] = iF;
            quadPtID[halfVertp2-1][0           ] = iE;
            quadPtID[halfVertp2-1][halfVertp2-1] = iC;

            // other boundary points
            ktemp = halfVertm1;
            for (k = 0; k < halfVertm1; k++)
            {
               quadPtID[ktemp][0] = nodeMidEO - halfhalfVertm1 + k;// OE
               quadPtID[0][ktemp] = nodeMidFO - halfhalfVertm1 + k;// OF
               ktemp--; 

               quadPtID[k+1][halfVertp2-1] = iF - dirCA*(k+1); // CF
               quadPtID[halfVertp2-1][k+1] = iE + dirBC*(k+1); // DO
            } // k loop
         } // if

         // =========================================================
         // At this point, the boundary IDs for the quads have been
         // obtained. Now obtain the interior points.
         //
         // Build middle points based on straight-lines (equal areas)
         // =========================================================
         for (jj = 0; jj < halfVertm1; jj++)
         {
            index1 = quadPtID[jj+1][0];
            index2 = quadPtID[jj+1][halfVertp2-1];
            for (kk = 0; kk < halfVertm1; kk++)
            {
               quadPtID[jj+1][kk+1] = ktemp5;

               // append into the allNodePos array
               for (k = 0; k < 3; k++)
               {
                  g->allNodePos[3*ktemp5+k] = 
                  g->allNodePos[3*index1+k] +
                  (kk+1)*deltaDist*(g->allNodePos[3*index2+k]
                                  - g->allNodePos[3*index1+k]);

                  g->nodeNormal[3*ktemp5+k] = 
                  g->nodeNormal[3*index1+k] +
                  (kk+1)*deltaDist*(g->nodeNormal[3*index2+k]
                                  - g->nodeNormal[3*index1+k]);

                  //tempPos[3*ktemp5+k] = g->allNodePos[3*ktemp5+k];

               } // k loop
               if((strcmp(surfaceType,"sphere")==0 ||
                  strcmp(surfaceType,"robin")==0) && iHybrid != 1)
                  moveToBoundary(dummy1,dummy2,&g->allNodePos[3*ktemp5],
                     &g->nodeNormal[3*ktemp5],surfaceType);

               ktemp5++;
            } // kk loop
         } // jj loop

         // =========================================================
         // Build interior points based on shape-preserving ideas
         // =========================================================

         if (j == 0) // Quad ADOF
         {
            for (jj = 1; jj < halfVertp2-1; jj++)
            {
               index1 = quadPtID[jj][jj];

               // equispace the diagonals
               for (k = 0; k < 3; k++)
               {
                  g->allNodePos[3*index1+k] = g->allNodePos[3*iA+k]
                     + (jj)*deltaDist
                     *(g->allNodePos[3*iO+k] - g->allNodePos[3*iA+k]);

               } // k loop
            } // jj loop

            for (rowID = 1; rowID < halfVertp2-1; rowID++)
            {
               index2    = quadPtID[rowID][rowID];
               index3    = quadPtID[rowID][halfVertp2-1];
               deltaDistTemp = 1./(halfVertp2-1-rowID);
               counter = 1;
               for (colID = rowID+1; colID < halfVertp2-1; colID++)
               {
                  index1 = quadPtID[rowID][colID];
                  for (k = 0; k < 3; k++)
                  {
                     g->allNodePos[3*index1+k] = g->allNodePos[3*index2+k]
                        + counter*deltaDistTemp
                        *(g->allNodePos[3*index3+k] - g->allNodePos[3*index2+k]);
                  }
                  counter++;
               } // colID
            } // rowID

            for (colID = 1; colID < halfVertp2-1; colID++)
            {
               index2    = quadPtID[colID][colID];
               index3    = quadPtID[halfVertp2-1][colID];
               deltaDistTemp = 1./(halfVertp2-1-colID);
               counter = 1;

               for (rowID = colID+1; rowID < halfVertp2-1; rowID++)
               {
                  index1 = quadPtID[rowID][colID];
                   // printf("rowID,colID: [%d,%d] deltaDist: %f counter: %d\n",
                   //    rowID,colID,deltaDistTemp,counter);
                  for (k = 0; k < 3; k++)
                  {
                     g->allNodePos[3*index1+k] = g->allNodePos[3*index2+k]
                        + counter*deltaDistTemp
                        *(g->allNodePos[3*index3+k] - g->allNodePos[3*index2+k]);
                  }
                  counter++;
               } // colID
            } // rowID

         }
         else if (j == 1) // quadDOBE
         {
            for (jj = 1; jj < halfVertp2-1; jj++)
            {
               index1 = quadPtID[halfVertp2-1-jj][jj];
               // equispace the diagonals
               for (k = 0; k < 3; k++)
               {
                  g->allNodePos[3*index1+k] = g->allNodePos[3*iB+k]
                     + (jj)*deltaDist
                     *(g->allNodePos[3*iO+k] - g->allNodePos[3*iB+k]);

               } // k loop
            } // jj loop

            for (rowID = 1; rowID < halfVertp2-1; rowID++)
            {
               index2    = quadPtID[rowID][0];
               index3    = quadPtID[rowID][halfVertp2-1-rowID];
               deltaDistTemp = 1./(halfVertp2-1-rowID);
               counter = 1;
               for (colID = 1; colID < halfVertp2-1-rowID; colID++)
               {
                  // printf("rowID,colID: [%d,%d] deltaDist: %f counter: %d\n",
                  //     rowID,colID,deltaDistTemp,counter);
                  index1 = quadPtID[rowID][colID];
                  for (k = 0; k < 3; k++)
                  {
                     g->allNodePos[3*index1+k] = g->allNodePos[3*index2+k]
                        + counter*deltaDistTemp
                        *(g->allNodePos[3*index3+k] - g->allNodePos[3*index2+k]);
                  }
                  counter++;
               } // colID
            } // rowID

            for (colID = 1; colID < halfVertp2-1; colID++)
            {
               index2    = quadPtID[halfVertp2-1-colID][colID];
               index3    = quadPtID[halfVertp2-1][colID];
               deltaDistTemp = 1./colID;
               counter = 1;

               for (rowID = halfVertp2-colID; rowID < halfVertp2-1; rowID++)
               {
                  index1 = quadPtID[rowID][colID];
                   // printf("rowID,colID: [%d,%d] deltaDist: %f counter: %d\n",
                   //    rowID,colID,deltaDistTemp,counter);
                  for (k = 0; k < 3; k++)
                  {
                     g->allNodePos[3*index1+k] = g->allNodePos[3*index2+k]
                        + counter*deltaDistTemp
                        *(g->allNodePos[3*index3+k] - g->allNodePos[3*index2+k]);
                  }
                  counter++;
               } // colID
            } // rowID


         }
         else if (j == 2) // Quad OFCE
         {

            for (jj = 1; jj < halfVertp2-1; jj++)
            {
               index1 = quadPtID[halfVertp2-1-jj][halfVertp2-1-jj];

               // equispace the diagonals
               for (k = 0; k < 3; k++)
               {
                  g->allNodePos[3*index1+k] = g->allNodePos[3*iC+k]
                     + (jj)*deltaDist
                     *(g->allNodePos[3*iO+k] - g->allNodePos[3*iC+k]);

               } // k loop
            } // jj loop

            for (rowID = 1; rowID < halfVertp2-1; rowID++)
            {
               index2    = quadPtID[rowID][0];
               index3    = quadPtID[rowID][rowID];
               deltaDistTemp = 1./rowID;
               counter = 1;
               for (colID = 1; colID < rowID; colID++)
               {
                  // printf("rowID,colID: [%d,%d] deltaDist: %f counter: %d\n",
                  //     rowID,colID,deltaDistTemp,counter);
                  index1 = quadPtID[rowID][colID];
                  for (k = 0; k < 3; k++)
                  {
                     g->allNodePos[3*index1+k] = g->allNodePos[3*index2+k]
                        + counter*deltaDistTemp
                        *(g->allNodePos[3*index3+k] - g->allNodePos[3*index2+k]);
                  }
                  counter++;
               } // colID
            } // rowID


            for (colID = 1; colID < halfVertp2-1; colID++)
            {
               index2    = quadPtID[0][colID];
               index3    = quadPtID[colID][colID];
               deltaDistTemp = 1./colID;
               counter = 1;

               for (rowID = 1; rowID < colID; rowID++)
               {
                  index1 = quadPtID[rowID][colID];
                   // printf("rowID,colID: [%d,%d] deltaDist: %f counter: %d\n",
                   //    rowID,colID,deltaDistTemp,counter);
                  for (k = 0; k < 3; k++)
                  {
                     g->allNodePos[3*index1+k] = g->allNodePos[3*index2+k]
                        + counter*deltaDistTemp
                        *(g->allNodePos[3*index3+k] - g->allNodePos[3*index2+k]);
                  }
                  counter++;
               } // colID
            } // rowID
         }

         // =========================================================
         // At this point, the boundary IDs for the quads have been
         // obtained. Now obtain the interior points.
         //
         // Build middle points based on straight-lines (equal areas)
         // =========================================================
         
         for (jj = 0; jj < halfVertm1; jj++)
         {
            index1 = quadPtID[jj+1][0];
            index2 = quadPtID[jj+1][halfVertp2-1];
            for (kk = 0; kk < halfVertm1; kk++)
            {
               quadPtID[jj+1][kk+1] = ktemp6;

               // append into the allNodePos array
               for (k = 0; k < 3; k++)
               {
                  tempPos[3*ktemp6+k] = 
                  g->allNodePos[3*index1+k] +
                  (kk+1)*deltaDist*(g->allNodePos[3*index2+k]
                                  - g->allNodePos[3*index1+k]);

                  g->nodeNormal[3*ktemp6+k] = 
                  g->nodeNormal[3*index1+k] +
                  (kk+1)*deltaDist*(g->nodeNormal[3*index2+k]
                                  - g->nodeNormal[3*index1+k]);

                  //tempPos[3*ktemp5+k] = g->allNodePos[3*ktemp5+k];

               } // k loop
               if((strcmp(surfaceType,"sphere")==0 ||
                  strcmp(surfaceType,"robin") == 0) && iHybrid != 1)
                  moveToBoundary(dummy1,dummy2,&g->allNodePos[3*ktemp6],
                     &g->nodeNormal[3*ktemp6],surfaceType);

               ktemp6++;
            } // kk loop
         } // jj loop


      } // j loop (loop over each quad)
      k1++;         // for center
      k2 += 3*pow4; // for number of cells in a triangle
      k3  = ktemp3; // edges inside triangle
      k4  = ktemp4; // vertices on int edges
      k5  = ktemp5; // quad int points
      k6  = ktemp6; // quad int points

	} // i loop (g->numTriangle)


   // recombine based on weights (1 = straight, 0 = shape-preserving)
   weight = 0.5;
   for (i = 0; i < threenum; i++)
      g->allNodePos[i] = weight*tempPos[i] + (1.-weight)*g->allNodePos[i];


   //
   // Re-flush the points onto the surface of the sphere
   //
   if((strcmp(surfaceType,"sphere")==0 ||
      strcmp(surfaceType,"robin") == 0) && iHybrid != 1)
   {
      for (i = 0; i < g->numNodePos; i++)
      {
         moveToBoundary(dummy1,dummy2,&g->allNodePos[3*i],
            &g->nodeNormal[3*i],surfaceType);
      }
   } // if "sphere" or "robin"

   free(tempPos);
}