void particles::pit::myfunctions::RepresentationChange::leaveCell(
  particles::pit::Cell& fineGridCell
) {
  //std::cout <<"leaveCell()!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!" << MANTISSA << std::endl;

  const int cellIndex = fineGridCell.getCellIndex();
  const int NumberOfParticles = ParticleHeap::getInstance().getData(cellIndex).size();
//std::cout << "cellIndex in leaveCell():" << cellIndex << std::endl;

  if(NumberOfParticles > 0) {
    const ParticleHeap::HeapEntries& currentParticles = ParticleHeap::getInstance().getData(cellIndex);

    // Compute the mean value of the velocity for each axes
    tarch::la::Vector<DIMENSIONS, double> meanVelocity = computeMeanVelocity(currentParticles, NumberOfParticles);

    // Compute the mean value of the coordinate for each axes
    tarch::la::Vector<DIMENSIONS, double> meanCoordinate = particles::pit::myfunctions::CoordinatesRepresentationChange::computeMeanCoordinate(currentParticles, NumberOfParticles);

    // Write mean velocity and coordinate in Cell
    fineGridCell.setMeanVelocity(meanVelocity);
    fineGridCell.setMeanCoordinate(meanCoordinate);

    // Write in Heap of compressed Particles
    writeInCompressedHeap(currentParticles, cellIndex, meanVelocity, meanCoordinate);
    // Compute maxEror norm and save in cell.
    // We do it here because I don't know how to change cells in ascend in dfor(3) loop
    if(fineGridCell.isLeaf() && NumberOfParticles > 1) {
      double maxError = computeMaxError( fineGridCell );
      fineGridCell.setMyNorm(maxError);
    }
  }
}
Beispiel #2
0
bool ATOM_TerrainPatch::initialize (ATOM_TerrainQuadtree *quadtree, ATOM_TerrainPatch *parent, PatchPosition position, ATOM_VertexArray *baseVertices)
{
	ATOM_STACK_TRACE(ATOM_TerrainPatch::initialize);

	ATOM_ASSERT(quadtree);

	unsigned patchSize = quadtree->getPatchSize ();
	unsigned rootSize = quadtree->getRootSize ();
	float scaleX = quadtree->getScaleX ();
	float scaleZ = quadtree->getScaleZ ();

	_mipLevel = parent ? parent->getMipLevel() + 1 : 0;
	unsigned step = ((rootSize - 1) / (patchSize - 1)) >> _mipLevel;
	unsigned interval = (patchSize - 1) * step;
	unsigned parentOffsetX = parent ? parent->getOffsetX() : 0;
	unsigned parentOffsetZ = parent ? parent->getOffsetZ() : 0;

	switch (position)
	{
	case ATOM_TerrainPatch::LeftTop:
		_offsetX = parentOffsetX;
		_offsetZ = parentOffsetZ;
		break;
	case ATOM_TerrainPatch::RightTop:
		_offsetX = parentOffsetX + interval;
		_offsetZ = parentOffsetZ;
		break;
	case ATOM_TerrainPatch::LeftBottom:
		_offsetX = parentOffsetX;
		_offsetZ = parentOffsetZ + interval;
		break;
	case ATOM_TerrainPatch::RightBottom:
		_offsetX = parentOffsetX + interval;
		_offsetZ = parentOffsetZ + interval;
		break;
	default:
		return false;
	}

	_position = position;
	_quadtree = quadtree;
	_step = step;
	_parent = parent;
	_maxError = computeMaxError ();

	setupVertices (computeSkirtLength (), baseVertices);
	_boxRadius = computeBoundingBox (_boundingBox);

	return true;
}
void particles::pit::myfunctions::CoordinatesRepresentationChange::ascend(
  particles::pit::Cell * const    fineGridCells,
  particles::pit::Vertex * const  fineGridVertices,
  const peano::grid::VertexEnumerator&          fineGridVerticesEnumerator,
  particles::pit::Vertex * const  coarseGridVertices,
  const peano::grid::VertexEnumerator&          coarseGridVerticesEnumerator,
  particles::pit::Cell&           coarseGridCell
) {

  dfor3(k)
	particles::pit::Cell fineGridCell = fineGridCells[ fineGridVerticesEnumerator.cell(k) ];
    const tarch::la::Vector<DIMENSIONS,double> cellOffset     = fineGridVerticesEnumerator.getVertexPosition(k);
    const tarch::la::Vector<DIMENSIONS,double> MeanCoordinate = fineGridCell.getMeanCoordinate();
    bool isLeaf = fineGridCell.isLeaf();
    const int cellIndex = fineGridCell.getCellIndex();
    const int NumberOfParticles = ParticleHeap::getInstance().getData(cellIndex).size();

    if( isLeaf && NumberOfParticles>1 ) {
      // Compute Max-Norm
      double maxRelativeError = computeMaxRelativeError( fineGridCell );
      // Save maximal maxRelativeError in _globalMaxRelativeError
      if (_globalMaxRelativeError < maxRelativeError) {
        _globalMaxRelativeError = maxRelativeError;
      }
      double maxError = computeMaxError( fineGridCell );
      if(_global_max_error < maxError) {
          _global_max_error = maxError;
      }
      double maxOffset = computeMaxOffset( fineGridCell );
      // Compute RMSD
      tarch::la::Vector<DIMENSIONS,double> rmsd = computeRMSD( fineGridCell );
      // Computer L2-Norm
      tarch::la::Vector<DIMENSIONS,double> l2ErrorNorm = computeL2ErrorNorm( fineGridCell );
      tarch::la::Vector<DIMENSIONS,double> l2Norm = computeL2Norm( fineGridCell );

      // Save maximal l2ErrorNorm in _globalMaxL2ErrorNorm
      for(int d = 0; d<DIMENSIONS; d++) {
        if(_globalMaxL2ErrorNorm < l2ErrorNorm[d]) {
          _globalMaxL2ErrorNorm = l2ErrorNorm[d];
        }
      }
      // Add l2Norm to _globalL2Norm
      _globalL2ErrorNorm += l2ErrorNorm;
      // Don't forget to increment _globalNormAdditions to divide _globalL2Norm by it
      // at the end of iteration before writing it in the file!
      ++_globalNormAdditions;
      //std::cout << "_globalNormAdditions: " << _globalNormAdditions << std::endl;

      // Output for checking
      //printParticlesInfo( fineGridCell, "maxError", maxError );

      _maxRelativeErrorOut << maxRelativeError << " ";
      _maxErrorOut << maxError << " ";
      _maxOffsetOut << maxOffset << " ";

      // Histogram process
      l2_error_norm_histogram_->processHistogram(l2ErrorNorm);
      max_error_norm_histogram_->processHistogram(maxError);
      max_offset_norm_histogram_->processHistogram(maxOffset);

      for(int d=0; d<DIMENSIONS; d++) {
        _RMSDOut << rmsd[d] << " ";
        _L2ErrorNormOut << l2ErrorNorm[d] << " ";
        _L2NormOut << l2Norm[d] << " ";
        _MeanCoordinateOut << MeanCoordinate[d] << " ";
      }
      for(int d=0; d<DIMENSIONS; d++) {
        _maxRelativeErrorOut << cellOffset[d] << " ";
    	_maxErrorOut << cellOffset[d] << " ";
        _maxOffsetOut << cellOffset[d] << " ";
        _RMSDOut << cellOffset[d] << " ";
        _L2ErrorNormOut << cellOffset[d] << " ";
        _L2NormOut << cellOffset[d] << " ";
        _MeanCoordinateOut << cellOffset[d] << " ";
      }
      _maxRelativeErrorOut << std::endl;
      _maxErrorOut << std::endl;
      _maxOffsetOut << std::endl;
      _RMSDOut << std::endl;
      _L2ErrorNormOut << std::endl;
      _L2NormOut << std::endl;
      _MeanCoordinateOut << std::endl;
    }
  enddforx
}
void particles::pit::myfunctions::RepresentationChange::ascend(
  particles::pit::Cell * const    fineGridCells,
  particles::pit::Vertex * const  fineGridVertices,
  const peano::grid::VertexEnumerator&          fineGridVerticesEnumerator,
  particles::pit::Vertex * const  coarseGridVertices,
  const peano::grid::VertexEnumerator&          coarseGridVerticesEnumerator,
  particles::pit::Cell&           coarseGridCell
) {
  particles::pit::myfunctions::CoordinatesRepresentationChange::ascend(
    fineGridCells,
    fineGridVertices,
    fineGridVerticesEnumerator,
    coarseGridVertices,
    coarseGridVerticesEnumerator,
    coarseGridCell);

  dfor3(k)
    particles::pit::Cell fineGridCell = fineGridCells[ fineGridVerticesEnumerator.cell(k) ];
    const tarch::la::Vector<DIMENSIONS,double> cellOffset     = fineGridVerticesEnumerator.getVertexPosition(k);
    const tarch::la::Vector<DIMENSIONS,double> meanVelocity = fineGridCell.getMeanVelocity();
    bool isLeaf = fineGridCell.isLeaf();
    const int cellIndex = fineGridCell.getCellIndex();
    const int NumberOfParticles = ParticleHeap::getInstance().getData(cellIndex).size();

    if( isLeaf && NumberOfParticles>1 ) {
      // Compute Max-Norm
      double maxRelativeError = computeMaxRelativeError( fineGridCell );
      // Save maximal maxRelativeError in _globalMaxRelativeError
      if (_globalMaxRelativeError < maxRelativeError) {
        _globalMaxRelativeError = maxRelativeError;
      }
      double maxError = computeMaxError( fineGridCell );
      if(_global_max_error < maxError) {
          _global_max_error = maxError;
      }
      double maxOffset = computeMaxOffset( fineGridCell );
      double minOffset = computeMinOffset( fineGridCell );
      if(_globalMaxOffset < maxOffset) {
        _globalMaxOffset = maxOffset;
      }
      // Compute RMSD
      tarch::la::Vector<DIMENSIONS,double> rmsd = computeRMSD( fineGridCell );
      // Computer L2-Norm
      tarch::la::Vector<DIMENSIONS,double>
        l2ErrorNorm = computeL2ErrorNorm( fineGridCell );
      tarch::la::Vector<DIMENSIONS,double>
        l2Norm = computeL2Norm( fineGridCell );
      //std::cout << "ascend() l2ErrorNorm: " << l2ErrorNorm << std::endl;


      // Save maximal l2ErrorNorm in _globalMaxL2ErrorNorm
      for(int d = 0; d<DIMENSIONS; d++) {
        if(_globalMaxL2ErrorNorm < l2ErrorNorm[d]) {
          _globalMaxL2ErrorNorm = l2ErrorNorm[d];
        }
      }
      // Add l2ErrorNorm to _globalL2ErrorNorm
      _globalL2ErrorNorm += l2ErrorNorm;
      // Add l2Norm to _globalL2OffsetNorm
      _globalL2OffsetNorm += l2Norm;
      // Don't forget to increment _globalNormAdditions to divide _globalL2Norm
      //by it at the end of iteration before writing it in the file!
      ++_globalNormAdditions;


      // Output for checking
      if(VERBOSE) {
          printParticlesInfo( fineGridCell, "l2ErrorNorm", l2ErrorNorm );
      }

      /* All computations put in output */
      _maxRelativeErrorOut << maxRelativeError << " ";
      _maxErrorOut << maxError << " ";
      _maxOffsetOut << maxOffset << " ";
      _minOffsetOut << minOffset << " ";

      // Histogram process
      l2_error_norm_histogram_->processHistogram(l2ErrorNorm);
      max_error_norm_histogram_->processHistogram(maxError);
      max_offset_norm_histogram_->processHistogram(maxOffset);

      for(int d=0; d<DIMENSIONS; d++) {
        _RMSDOut << rmsd[d] << " ";
        _L2ErrorNormOut << l2ErrorNorm[d] << " ";
        _L2NormOut << l2Norm[d] << " ";
        _meanVelocityOut << meanVelocity[d] << " ";
      }
      /* Write coordinates of each cell near the value of the Norm(offset) */
      for(int d=0; d<DIMENSIONS; d++) {
        _maxRelativeErrorOut << cellOffset[d] << " ";
    	_maxErrorOut << cellOffset[d] << " ";
        _maxOffsetOut << cellOffset[d] << " ";
        _minOffsetOut << cellOffset[d] << " ";
        _RMSDOut << cellOffset[d] << " ";
        _L2ErrorNormOut << cellOffset[d] << " ";
        _L2NormOut << cellOffset[d] << " ";
        _meanVelocityOut << cellOffset[d] << " ";
      }
      /* Put the new line character to have one cell per line */
      _maxRelativeErrorOut << std::endl;
      _maxErrorOut << std::endl;
      _maxOffsetOut << std::endl;
      _minOffsetOut << std::endl;
      _RMSDOut << std::endl;
      _L2ErrorNormOut << std::endl;
      _L2NormOut << std::endl;
      _meanVelocityOut << std::endl;
    }
  enddforx
}
Beispiel #5
0
QPointF *fitCubic(QPolygonF &points,int first,int last,FitVector tHat1,FitVector tHat2,float error,int &width)
{
    double *u;
    double *uPrime;
    double maxError;
    int splitPoint;
    int nPts;
    double iterationError;
    int maxIterations=4;
    FitVector tHatCenter;
    QPointF *curve;
    int i;
    width=0;
    iterationError=error*error;
    nPts = last-first+1;

    if (nPts == 2) {
        double dist = distance(points[last], points[first]) / 3.0;

        curve = new QPointF[4];
        
        curve[0] = points[first];
        curve[3] = points[last];

        tHat1.scale(dist);
        tHat2.scale(dist);
        curve[1] = tHat1 + curve[0];
        curve[2] = tHat2 + curve[3];
        width=4;    

        return curve;
    }
    
    /*  Parameterize points, and attempt to fit curve */
    u = chordLengthParameterize(points, first, last);
    curve = generateBezier(points, first, last, u, tHat1, tHat2);


    /*  Find max deviation of points to fitted curve */
    maxError = computeMaxError(points, first, last, curve, u, &splitPoint);

    if (maxError < error) {
        delete[] u;
        width=4;    
        return curve;
    }

    /*  If error not too large, try some reparameterization  */
    /*  and iteration */
    if (maxError < iterationError) {
        for (i = 0; i < maxIterations; i++) {
             uPrime = reparameterize(points, first, last, u, curve);
             curve = generateBezier(points, first, last, uPrime, tHat1, tHat2);
             maxError = computeMaxError(points, first, last, curve, uPrime, &splitPoint);
             if (maxError < error) {
                 delete[] u;
                 width=4;    
                 return curve;
             }
             delete[] u;
             u = uPrime;
        }
    }

    /* Fitting failed -- split at max error point and fit recursively */
    delete[] u;
    delete[] curve;
    tHatCenter = computeCenterTangent(points, splitPoint);

    int w1,w2;
    QPointF *cu1=NULL, *cu2=NULL;
    cu1 = fitCubic(points, first, splitPoint, tHat1, tHatCenter, error,w1);

    tHatCenter.negate();
    cu2 = fitCubic(points, splitPoint, last, tHatCenter, tHat2, error,w2);

    QPointF *newcurve = new QPointF[w1+w2];
    for (int i=0;i<w1;i++)
         newcurve[i]=cu1[i];

    for (int i=0;i<w2;i++)
         newcurve[i+w1]=cu2[i];
    
    delete[] cu1;
    delete[] cu2;
    width=w1+w2;

    return newcurve;
}