void CSysMatrix::Initialize(int n_verts, int n_verts_global, int n_var, int n_eqns, array<array<int> > &v2e, array<int> &v2n_e, array<int> &e2v) {
	unsigned long iPoint, *row_ptr, *col_ind, *vneighs, index, nnz;
    unsigned short iNeigh, nNeigh, Max_nNeigh, iEdge;

    nPoint = n_verts;              // Assign number of points in the mesh (on processor)

	/*--- Don't delete *row_ptr, *col_ind because they are asigned to the Jacobian structure. ---*/
	row_ptr = new unsigned long [nPoint+1];
	row_ptr[0] = 0;
	for (iPoint = 0; iPoint < nPoint; iPoint++)
        row_ptr[iPoint+1] = row_ptr[iPoint]+(v2n_e(iPoint)+1); // +1 -> to include diagonal element
	nnz = row_ptr[nPoint];
  
	col_ind = new unsigned long [nnz];
  
    Max_nNeigh = 0;
    for (iPoint = 0; iPoint < nPoint; iPoint++) {
        nNeigh = v2n_e(iPoint);
        if (nNeigh > Max_nNeigh) Max_nNeigh = nNeigh;
    }
	vneighs = new unsigned long [Max_nNeigh+1]; // +1 -> to include diagonal
  
	for (iPoint = 0; iPoint < nPoint; iPoint++) {
        nNeigh = v2n_e(iPoint);
        for (iNeigh = 0; iNeigh < nNeigh; iNeigh++) {
            iEdge = v2e(iPoint)(iNeigh);
            if (e2v(iEdge,0) == iPoint) {
                vneighs[iNeigh] = e2v(iEdge,1);
            }else{
                vneighs[iNeigh] = e2v(iEdge,0);
            }
        }
		vneighs[nNeigh] = iPoint;
		sort(vneighs,vneighs+nNeigh+1);
		index = row_ptr[iPoint];
		for (iNeigh = 0; iNeigh <= nNeigh; iNeigh++) {
			col_ind[index] = vneighs[iNeigh];
			index++;
		}
	}
  
    /*--- Set the indices in the in the sparce matrix structure ---*/
    SetIndexes(n_verts, n_verts_global, n_var, n_eqns, row_ptr, col_ind, nnz);
  
    /*--- Initialization to zero ---*/
    SetValZero();
  
	delete[] vneighs;
}
Beispiel #2
0
void CSysMatrix::Initialize(unsigned long nPoint, unsigned long nPointDomain,
                            unsigned short nVar, unsigned short nEqn,
                            bool EdgeConnect, CGeometry *geometry) {
  
  unsigned long iPoint, *row_ptr, *col_ind, index, nnz, Elem;
  unsigned short iNeigh, iElem, iNode, *nNeigh;
  vector<unsigned long>::iterator it;
  vector<unsigned long> vneighs;
  
  /*--- Don't delete *row_ptr, *col_ind because they are
   asigned to the Jacobian structure. ---*/
  
  /*--- Compute the number of neighbors ---*/
  
  nNeigh = new unsigned short [nPoint];
  for (iPoint = 0; iPoint < nPoint; iPoint++) {
    
    if (EdgeConnect) {
      nNeigh[iPoint] = (geometry->node[iPoint]->GetnPoint()+1);  // +1 -> to include diagonal element
    }
    else {
      vneighs.clear();
      for(iElem = 0; iElem < geometry->node[iPoint]->GetnElem(); iElem++) {
        Elem =  geometry->node[iPoint]->GetElem(iElem);
        for (iNode = 0; iNode < geometry->elem[Elem]->GetnNodes(); iNode++)
          vneighs.push_back(geometry->elem[Elem]->GetNode(iNode));
      }
      vneighs.push_back(iPoint);
      
      sort(vneighs.begin(), vneighs.end());
      it = unique(vneighs.begin(), vneighs.end());
      vneighs.resize(it - vneighs.begin());
      nNeigh[iPoint] = vneighs.size();
    }
    
  }
  
  /*--- Create row_ptr structure, using the number of neighbors ---*/
  
  row_ptr = new unsigned long [nPoint+1];
  row_ptr[0] = 0;
  for (iPoint = 0; iPoint < nPoint; iPoint++)
    row_ptr[iPoint+1] = row_ptr[iPoint] + nNeigh[iPoint];
  nnz = row_ptr[nPoint];
  
  /*--- Create col_ind structure ---*/
  
  col_ind = new unsigned long [nnz];
  for (iPoint = 0; iPoint < nPoint; iPoint++) {
    
    vneighs.clear();
    
    if (EdgeConnect) {
      for (iNeigh = 0; iNeigh < geometry->node[iPoint]->GetnPoint(); iNeigh++)
        vneighs.push_back(geometry->node[iPoint]->GetPoint(iNeigh));
      vneighs.push_back(iPoint);
    }
    else {
      for(iElem = 0; iElem < geometry->node[iPoint]->GetnElem(); iElem++) {
        Elem =  geometry->node[iPoint]->GetElem(iElem);
        for (iNode = 0; iNode < geometry->elem[Elem]->GetnNodes(); iNode++)
          vneighs.push_back(geometry->elem[Elem]->GetNode(iNode));
      }
      vneighs.push_back(iPoint);
    }
    
    sort(vneighs.begin(), vneighs.end());
    it = unique(vneighs.begin(), vneighs.end());
    vneighs.resize( it - vneighs.begin() );
    
    index = row_ptr[iPoint];
    for (iNeigh = 0; iNeigh < vneighs.size(); iNeigh++) {
      col_ind[index] = vneighs[iNeigh];
      index++;
    }
    
  }
  
  /*--- Set the indices in the in the sparce matrix structure, and memory allocation ---*/
  
  SetIndexes(nPoint, nPointDomain, nVar, nEqn, row_ptr, col_ind, nnz);
  
  /*--- Initialization matrix to zero ---*/
  
  SetValZero();
  
  delete [] nNeigh;
  
}