Example #1
0
double scenario::diffusionequation::CornerPointField::getPorosityFromDataSet(const tarch::la::Vector<3,double>& x) const {
  logTraceInWith3Arguments( "getPorosityFromDataSet(vector)", x, _hexahedron.getBoundingBox(), _hexahedron.getOffset() );
  const double depth = x(2);

  const double pillarSizeX = getCornerPointPillarWidth()(0);
  assertion1( pillarSizeX>0.0, pillarSizeX );
  int    inArrayX    = std::floor( (x(0)-_hexahedron.getOffset()(0)) / pillarSizeX );
  if (inArrayX==_pillars(0)) inArrayX--;
  assertion3( inArrayX>=0, pillarSizeX, inArrayX, _pillars );
  assertion3( inArrayX<_pillars(0), pillarSizeX, inArrayX, _pillars );

  #if defined(Dim3)
  const double pillarSizeY = getCornerPointPillarWidth()(1);
  assertion4( pillarSizeY>0.0, pillarSizeX, pillarSizeY, inArrayX, _pillars );
  int    inArrayY    = std::floor( (x(1)-_hexahedron.getOffset()(1)) / pillarSizeY );
  if (inArrayY==_pillars(1)) inArrayY--;
  assertion5( inArrayY>=0, pillarSizeX, pillarSizeY, inArrayX, inArrayY, _pillars );
  assertion5( inArrayY<_pillars(1), pillarSizeX, pillarSizeY, inArrayX, inArrayY, _pillars );
  #elif defined(Dim2)
  const int    inArrayY    = _pillars(1) / 2;
  #endif

  const int entry = inArrayX + inArrayY * _pillars(0);
  assertion6( entry < static_cast<int>(_entries.size()), pillarSizeX, inArrayX, inArrayY, _pillars, entry, _entries.size() );

  double result = _entries[entry].getPermeability(depth);
  logTraceOutWith1Argument( "getPorosityFromDataSet(vector)", result );
  return result;
}
Example #2
0
File: test5.C Project: 8l/rose
int main()
{
	TransformationAssertion assertion3 (TransformationAssertion::StrideOneAccess);
	
	doubleArray A(10);
	A = 0;
}
void peanoclaw::parallel::MasterWorkerAndForkJoinCommunicator::receivePatch(int localCellDescriptionIndex) {
  logTraceInWith3Arguments("receivePatch", localCellDescriptionIndex, _position, _level);
  #ifdef Parallel

  std::vector<CellDescription> remoteCellDescriptionVector = CellDescriptionHeap::getInstance().receiveData(_remoteRank, _position, _level, _messageType);
  assertionEquals2(remoteCellDescriptionVector.size(), 1, _position, _level);
  CellDescription remoteCellDescription = remoteCellDescriptionVector[0];

  assertion3(localCellDescriptionIndex >= 0, localCellDescriptionIndex, _position, _level);
  CellDescription localCellDescription = CellDescriptionHeap::getInstance().getData(localCellDescriptionIndex).at(0);
  #ifdef Asserts
  assertionNumericalEquals2(remoteCellDescription.getPosition(), localCellDescription.getPosition(), localCellDescription.toString(), remoteCellDescription.toString());
  assertionNumericalEquals2(remoteCellDescription.getSize(), localCellDescription.getSize(), localCellDescription.toString(), remoteCellDescription.toString());
  assertionEquals2(remoteCellDescription.getLevel(), localCellDescription.getLevel(), localCellDescription.toString(), remoteCellDescription.toString());
  #endif

  //Load arrays and stores according indices in cell description
  if(remoteCellDescription.getUIndex() != -1) {
    remoteCellDescription.setUIndex(_subgridCommunicator.receiveDataArray());
  }

  //Reset undesired values
  remoteCellDescription.setNumberOfTransfersToBeSkipped(0);

  //Copy remote cell description to local cell description
  deleteArraysFromPatch(localCellDescriptionIndex);
  remoteCellDescription.setCellDescriptionIndex(localCellDescriptionIndex);
  CellDescriptionHeap::getInstance().getData(localCellDescriptionIndex).at(0) = remoteCellDescription;
  assertionEquals(CellDescriptionHeap::getInstance().getData(localCellDescriptionIndex).size(), 1);

  Patch subgrid(localCellDescriptionIndex);
  subgrid.initializeNonParallelFields();

  //TODO unterweg debug
//  std::cout << "Received cell description on rank " << tarch::parallel::Node::getInstance().getRank()
//      << " from rank " << _remoteRank << ": " << remoteCellDescription.toString() << std::endl << subgrid.toStringUNew() << std::endl;

  #if defined(AssertForPositiveValues) && defined(Asserts)
  if(subgrid.isLeaf() || subgrid.isVirtual()) {
    assertion4(!subgrid.containsNonPositiveNumberInUnknownInUNew(0),
                tarch::parallel::Node::getInstance().getRank(),
                _remoteRank,
                subgrid,
                subgrid.toStringUNew());
  }
  #endif

  assertionEquals(CellDescriptionHeap::getInstance().getData(localCellDescriptionIndex).at(0).getCellDescriptionIndex(), localCellDescriptionIndex);
  #endif
  logTraceOut("receivePatch");
}
void NearestNeighborMapping:: map
(
  int inputDataID,
  int outputDataID )
{
  preciceTrace2 ( "map()", inputDataID, outputDataID );
  const utils::DynVector& inputValues = input()->data(inputDataID)->values();
  utils::DynVector& outputValues = output()->data(outputDataID)->values();
  //assign(outputValues) = 0.0;
  int valueDimensions = input()->data(inputDataID)->getDimensions();
  assertion2 ( valueDimensions == output()->data(outputDataID)->getDimensions(),
              valueDimensions, output()->data(outputDataID)->getDimensions() );
  assertion3 ( inputValues.size() / valueDimensions == (int)input()->vertices().size(),
               inputValues.size(), valueDimensions, input()->vertices().size() );
  assertion3 ( outputValues.size() / valueDimensions == (int)output()->vertices().size(),
               outputValues.size(), valueDimensions, output()->vertices().size() );
  if (getConstraint() == CONSISTENT){
    preciceDebug("Map consistent");
    size_t outSize = output()->vertices().size();
    for ( size_t i=0; i < outSize; i++ ){
      int inputIndex = _vertexIndices[i] * valueDimensions;
      for ( int dim=0; dim < valueDimensions; dim++ ){
        outputValues[(i*valueDimensions)+dim] = inputValues[inputIndex+dim];
      }
    }
  }
  else {
    assertion1(getConstraint() == CONSERVATIVE, getConstraint());
    preciceDebug("Map conservative");
    size_t inSize = input()->vertices().size();
    for ( size_t i=0; i < inSize; i++ ){
      int outputIndex = _vertexIndices[i] * valueDimensions;
      for ( int dim=0; dim < valueDimensions; dim++ ){
        outputValues[outputIndex+dim] += inputValues[(i*valueDimensions)+dim];
      }
    }
  }
}
void tarch::plotter::griddata::unstructured::vtk::VTKTextFileWriter::VertexDataWriter::plotVertex( int index, double value ) {
  assertion(_lastWriteCommandVertexNumber>=-1);
  assertion(1<=_recordsPerVertex);

  float valueAsFloat = static_cast<float>(value);
  assertion3( valueAsFloat != std::numeric_limits<float>::infinity(), index, value, valueAsFloat );
  assertion3( valueAsFloat == valueAsFloat, index, value, valueAsFloat );  // test for not a number

  while (_lastWriteCommandVertexNumber<index-1) {
    plotVertex(_lastWriteCommandVertexNumber+1,0.0);
  }

  _lastWriteCommandVertexNumber = index;
  _out << valueAsFloat << " ";
  for (int i=1; i<_recordsPerVertex; i++) {
    _out << 0.0 << " ";
  }

  _out << std::endl;

  if (value<_minValue) _minValue = value;
  if (value>_maxValue) _maxValue = value;
}
Example #6
0
File: perf_test4.C Project: 8l/rose
int main()
{
	TransformationAssertion assertion3 (TransformationAssertion::StrideOneAccess);

	doubleArray A(N,N);
	doubleArray B(N,N);
	doubleArray C(N,N);
	doubleArray D(N,N);

	int TIMES = 100;

	for(int i=0 ; i < TIMES; i++)
	{
		A = B + C +D;
	}

}
Example #7
0
int main()
{
	TransformationAssertion assertion3 (TransformationAssertion::StrideOneAccess);

	doubleArray A(N,N,N);
	doubleArray B(N,N,N);
	Index I,J,K;

	int TIMES = 100;

	for(int i=0 ; i < TIMES; i++)
	{
		A(I,J,K) = B(I+1,J,K) + B(I-1,J,K)
						 + B(I,J+1,K)	+ B(I,J-1,K)
						 + B(I,J,K+1) + B(I,J,K-1)
						 + B(I,J,K); // 3D 7pt Stencil
	}

}
Example #8
0
int peanoclaw::Area::getAreasOverlappedByRemoteGhostlayers(
  const tarch::la::Vector<THREE_POWER_D_MINUS_ONE, int>& adjacentRanks,
  tarch::la::Vector<THREE_POWER_D_MINUS_ONE, int>        overlapOfRemoteGhostlayers,
  const tarch::la::Vector<DIMENSIONS, int>&              subdivisionFactor,
  int                                                    rank,
  Area                                                   areas[THREE_POWER_D_MINUS_ONE]
) {
  logTraceInWith2Arguments("getAreasOverlappedByRemoteGhostlayers(...)", adjacentRanks, overlapOfRemoteGhostlayers);
  int  numberOfAreas = 0;
  bool oneAreaCoversCompleteSubgrid = false;

  for(int dimensionality = 0; dimensionality < DIMENSIONS; dimensionality++) {
    int numberOfManifolds = getNumberOfManifolds(dimensionality);
    for(int manifoldIndex = 0; manifoldIndex < numberOfManifolds; manifoldIndex++) {
      tarch::la::Vector<DIMENSIONS, int> manifoldPosition = getManifold(dimensionality, manifoldIndex);
      int manifoldEntry = linearizeManifoldPosition(manifoldPosition);

      logDebug("getAreasOverlappedByRemoteGhostlayers(...)", "Manifold " << manifoldPosition << " of dimensions " << dimensionality
          << ": entry=" << manifoldEntry << ", rank=" << adjacentRanks[manifoldEntry] << ", overlap=" << overlapOfRemoteGhostlayers[manifoldEntry]);

      if(adjacentRanks[manifoldEntry] == rank && overlapOfRemoteGhostlayers[manifoldEntry] > 0) {
        //Reduce lower-dimensional manifolds
        bool canBeOmitted = checkHigherDimensionalManifoldForOverlap(
          adjacentRanks,
          overlapOfRemoteGhostlayers,
          manifoldPosition,
          dimensionality,
          manifoldEntry,
          rank
        );

        //Restrict size and offset by higher-dimensional manifolds
        logDebug("getAreasOverlappedByRemoteGhostlayers(...)","Testing manifold " << manifoldPosition << " of dimensions " << dimensionality
            << ": " << (canBeOmitted ? "omitting" : "consider"));

        if(!canBeOmitted) {
          tarch::la::Vector<DIMENSIONS, int> size;
          tarch::la::Vector<DIMENSIONS, int> offset;

          //Initialise size and offset
          for(int d = 0; d < DIMENSIONS; d++) {
            size(d) = (manifoldPosition(d) == 0) ? subdivisionFactor(d) : std::min(subdivisionFactor(d), overlapOfRemoteGhostlayers[manifoldEntry]);
            offset(d) = (manifoldPosition(d) == 1) ? subdivisionFactor(d) - size(d) : 0;
          }

          //TODO unterweg debug
//          std::cout << "offset: " << offset << ", size: " << size << std::endl;

          for(int adjacentDimensionality = dimensionality - 1; adjacentDimensionality >= 0; adjacentDimensionality--) {
            int numberOfAdjacentManifolds = getNumberOfAdjacentManifolds(manifoldPosition, dimensionality, adjacentDimensionality);
            for(int adjacentManifoldIndex = 0; adjacentManifoldIndex < numberOfAdjacentManifolds; adjacentManifoldIndex++) {
              tarch::la::Vector<DIMENSIONS, int> adjacentManifoldPosition = getIndexOfAdjacentManifold(
                manifoldPosition,
                dimensionality,
                adjacentDimensionality,
                adjacentManifoldIndex
              );

              //TODO unterweg debug
//              std::cout << "adj. manifold " << adjacentManifoldPosition << std::endl;

              int adjacentEntry = linearizeManifoldPosition(adjacentManifoldPosition);

              if(adjacentRanks[adjacentEntry] == rank) {
                for(int d = 0; d < DIMENSIONS; d++) {
                  if(manifoldPosition(d) == 0) {
                    if(adjacentManifoldPosition(d) < 0) {
                      int overlap = std::max(0, overlapOfRemoteGhostlayers[adjacentEntry] - offset(d));
                      offset(d) += overlap;
                      size(d) -= overlap;

                      //TODO unterweg debug
//                      std::cout << "Reducing bottom " << overlap << std::endl;
                    } else if(adjacentManifoldPosition(d) > 0) {
                      assertion2(adjacentManifoldPosition(d) > 0, adjacentManifoldPosition, d);
                      int overlap = std::max(0, offset(d) + size(d) - (subdivisionFactor(d) - overlapOfRemoteGhostlayers[adjacentEntry]));
                      size(d) -= overlap;

                      //TODO unterweg debug
//                      std::cout << "Reducing top " << overlap << std::endl;
                    }
                  }
                }
              }
            }
          }

          logDebug("getAreasOverlappedByRemoteGhostlayers(...)", "offset: " << offset << ", size: " << size << ", dimensionality=" << dimensionality << ", manifoldIndex=" << manifoldIndex << ", manifoldEntry=" << manifoldEntry);
          if(tarch::la::allGreater(size, 0)) {
            areas[numberOfAreas++] = Area(offset, size);

            oneAreaCoversCompleteSubgrid |= (tarch::la::volume(size) >= tarch::la::volume(subdivisionFactor));

            assertion1(tarch::la::allGreaterEquals(offset, 0), offset);
            assertion3(tarch::la::allGreaterEquals(subdivisionFactor, offset + size), offset, size, subdivisionFactor);
          }
        }
      }
    }
  }

  //Optimize areas
  if(oneAreaCoversCompleteSubgrid) {
    numberOfAreas = 1;
    areas[0] = Area(0, subdivisionFactor);
  }

  logTraceOutWith2Arguments("getAreasOverlappedByRemoteGhostlayers(...)", numberOfAreas, areas);
  return numberOfAreas;
}
Example #9
0
int particles::pidt::mappings::MoveParticles::moveParticlesOfOneVertexWithinCellIfTheyAreSorted(
  int                                   vertexIndex,
  const peano::grid::VertexEnumerator&  fineGridVerticesEnumerator
) {
  ParticleHeap::HeapEntries& sourceVertexParticles = ParticleHeap::getInstance().getData(vertexIndex);

  int numberOfParticlesMoved = 0;

  int biggestIndexPointingToUnmovedParticle  = static_cast<int>(sourceVertexParticles.size())-1;
  int smallestIndexPointingToUnmovedParticle = 0;

  while (
    biggestIndexPointingToUnmovedParticle>=0 &&
    sourceVertexParticles.at(biggestIndexPointingToUnmovedParticle).getMovedParticle() == particles::pidt::records::Particle::Moved
  ) {
    biggestIndexPointingToUnmovedParticle--;
  }

  #ifdef Asserts
  for (int i=0; i<biggestIndexPointingToUnmovedParticle; i++) {
    assertion3(
      sourceVertexParticles.at(i).getMovedParticle() != particles::pidt::records::Particle::Moved,
      i,
      biggestIndexPointingToUnmovedParticle,
      sourceVertexParticles.at(i).toString()
    );
  }
  #endif

  logDebug(
    "moveParticlesOfOneVertexWithinCellIfTheyAreSorted(...)",
    "moved index from " << static_cast<int>(sourceVertexParticles.size())-1 <<
    " to " << biggestIndexPointingToUnmovedParticle <<
    ": " << sourceVertexParticles.at(biggestIndexPointingToUnmovedParticle).toString() <<
    " with first element " << sourceVertexParticles.at(smallestIndexPointingToUnmovedParticle).toString()
  );

  // has to be equals as the two might just have been exchanged
  while (biggestIndexPointingToUnmovedParticle >= smallestIndexPointingToUnmovedParticle) {
    particles::pidt::records::Particle& currentParticle = sourceVertexParticles.at(smallestIndexPointingToUnmovedParticle);

    assertion( biggestIndexPointingToUnmovedParticle>=0 );
    assertion( smallestIndexPointingToUnmovedParticle>=0 );
    assertion( biggestIndexPointingToUnmovedParticle<static_cast<int>(sourceVertexParticles.size()) );
    assertion( smallestIndexPointingToUnmovedParticle<static_cast<int>(sourceVertexParticles.size()) );

    assertion4(
      currentParticle.getMovedParticle() != particles::pidt::records::Particle::Moved ||
      (smallestIndexPointingToUnmovedParticle==biggestIndexPointingToUnmovedParticle),
      smallestIndexPointingToUnmovedParticle,
      biggestIndexPointingToUnmovedParticle,
      sourceVertexParticles.at(smallestIndexPointingToUnmovedParticle).toString(),
      sourceVertexParticles.at(biggestIndexPointingToUnmovedParticle).toString()
    );

    const bool particleIsContainedInCell = fineGridVerticesEnumerator.overlaps(
      currentParticle._persistentRecords._x,
      0.0
    );

    if (particleIsContainedInCell) {
      currentParticle._persistentRecords._x             += (_state.getTimeStepSize() * currentParticle._persistentRecords._v);
      currentParticle.setMovedParticle( particles::pidt::records::Particle::Moved );
      reflectParticle(currentParticle);

      if (smallestIndexPointingToUnmovedParticle!=biggestIndexPointingToUnmovedParticle) {
        particles::pidt::records::Particle tmp                        =  currentParticle;
        currentParticle                                               =  sourceVertexParticles.at(biggestIndexPointingToUnmovedParticle);
        sourceVertexParticles[biggestIndexPointingToUnmovedParticle]  =  tmp;
      }

      numberOfParticlesMoved++;
      biggestIndexPointingToUnmovedParticle--;
    }
    else {
      smallestIndexPointingToUnmovedParticle++;
    }
  }

  return numberOfParticlesMoved;
}