Example #1
0
// ---------------------------------------------------------------------- 
int Dense3d::evaluate(const DblNumVec& srcDen, DblNumVec& trgVal) 
{
  //-----------------------------------
  iA(srcDen.m()==srcDOF()*(*_srcPos).n());  iA(trgVal.m()==trgDOF()*(*_trgPos).n());

  int dim  = this->dim();
  int srcDOF = this->srcDOF();
  int trgDOF = this->trgDOF();
  /* Number of sources */
  int numSrc = (*_srcPos).n();
  /* Number of targets */
  int numTrg = (*_trgPos).n();

  DblNumMat inter(trgDOF, numSrc*srcDOF);
  for(int i=0; i<numTrg; i++) {
    DblNumMat onePosMat(dim, 1, false, (*_trgPos).clmdata(i));
    DblNumVec oneValVec(trgDOF, false, trgVal.data()+trgDOF*i);
    iC( _knl.kernel((*_srcPos), (*_srcNor), onePosMat, inter) );
    iC( dgemv(1.0, inter, srcDen, 0.0, oneValVec) );
  }

  return 0;
}
int Dense3d_MPI::evaluate(Vec srcDen, Vec trgVal) 
{
  //begin
  // CHECK
  pA(_srcPos!=NULL && _srcNor!=NULL && _trgPos!=NULL && srcDen!=NULL && trgVal!=NULL);
  //-----------------------------------
  int dim  = this->dim();
  int srcDOF = this->srcDOF();
  int trgDOF = this->trgDOF();
  /* Get global number of source positions */
  PetscInt srcGlbNum = procGlbNum(_srcPos);
  /* Get local number of target positions */
  PetscInt trgLclNum = procLclNum(_trgPos);
  
  Vec srcAllPos = _srcAllPos;
  Vec srcAllNor = _srcAllNor;
  Vec srcAllDen;
  /* Create scatter context to scatter source densities to all processors */
  {
	 VecScatter ctx;
	 pC( VecScatterCreateToAll(srcDen, &ctx, &srcAllDen) );
	 pC( VecScatterBegin(ctx, srcDen, srcAllDen, INSERT_VALUES, SCATTER_FORWARD) );
	 pC( VecScatterEnd(ctx,  srcDen, srcAllDen, INSERT_VALUES, SCATTER_FORWARD) );
	 pC( VecScatterDestroy(ctx) );
  }
  
  Vec trgLclPos = _trgPos;
  Vec trgLclVal =  trgVal;

  /* Create matrices for source positions, normals, densities.  See common/nummat.hpp for
	* more information on matrices */
  double* srcAllPosArr; pC( VecGetArray(srcAllPos, &srcAllPosArr) );
  DblNumMat srcAllPosMat(dim, srcGlbNum, false, srcAllPosArr);
  double* srcAllNorArr; pC( VecGetArray(srcAllNor, &srcAllNorArr) );
  DblNumMat srcAllNorMat(dim, srcGlbNum, false, srcAllNorArr);
  double* srcAllDenArr; pC( VecGetArray(srcAllDen, &srcAllDenArr) );
  DblNumVec srcAllDenVec(srcDOF*srcGlbNum, false, srcAllDenArr);

  /* Create matrices for target positions and values */
  double* trgLclPosArr; pC( VecGetArray(trgLclPos, &trgLclPosArr) );
  DblNumMat trgLclPosMat(dim, trgLclNum, false, trgLclPosArr);
  double* trgLclValArr; pC( VecGetArray(trgLclVal, &trgLclValArr) );
  DblNumVec trgLclValVec(trgDOF*trgLclNum, false, trgLclValArr);

  /* Create an evaluation context and evaluate based on kernel type */
  DblNumMat inter(trgDOF, srcGlbNum*srcDOF);
  /* Do multiplication one line of the matrices at a time */
  for(int i=0; i<trgLclNum; i++) {
	 DblNumMat onePosMat(dim, 1, false, trgLclPosMat.clmdata(i));
	 DblNumVec oneValVec(trgDOF, false, trgLclValVec.data()+trgDOF*i);
	 /* Create kernel multiplier context based on kernel type */
	 pC( _knl.buildKnlIntCtx(srcAllPosMat, srcAllNorMat, onePosMat, inter) );
	 /* Computes 1.0*inter*srcAllDenVec + 0.0*oneValVec = oneValVec */
	 pC( dgemv(1.0, inter, srcAllDenVec, 0.0, oneValVec) );
  }
  
  pC( VecRestoreArray(srcAllPos, &srcAllPosArr) );
  pC( VecRestoreArray(srcAllNor, &srcAllNorArr) );
  pC( VecRestoreArray(srcAllDen, &srcAllDenArr) );
  
  pC( VecRestoreArray(trgLclPos, &trgLclPosArr) );
  pC( VecRestoreArray(trgLclVal, &trgLclValArr) );
  
  pC( VecDestroy(srcAllDen) );
  
  return(0);
}