コード例 #1
0
void MatrixTest::testMatrixMatrixOperations ()
{
  Matrix<2,3,int> lMatrix;
  Matrix<3,2,int> rMatrix;
  Matrix<2,2,int> result(0);
  assignList(lMatrix) = 1, 2, 3,
                        4, 5, 6;
  assignList(rMatrix) = 6, 5,
                        4, 3,
                        2, 1;

  // Matrix matrix multiplication
  multiply (lMatrix, rMatrix, result);
  validateEquals (result(0,0), 20);
  validateEquals (result(0,1), 14);
  validateEquals (result(1,0), 56);
  validateEquals (result(1,1), 41);

  // Bitwise comparison
  Matrix<2,3,int> matrixA(1);
  Matrix<2,3,int> matrixB(2);
  validate (matrixA == matrixA);
  validate (! (matrixA == matrixB));

  // Test equalsReturnIndex
  Matrix<2,3,double> matrix1(1);
  Matrix<2,3,double> matrix2(2);
  int i=equalsReturnIndex(matrix1,matrix2);
  validateEquals(i,0);
}
コード例 #2
0
void peanoclaw::tests::GhostLayerCompositorTest::testInterpolationFromCoarseToFinePatchLeftGhostLayer2D() {
  #if defined(Dim2)
  //Patch-array for lower-left vertex in fine patch
  peanoclaw::Patch patches[TWO_POWER_D];

  //Settings
  int coarseSubdivisionFactor = 2;
  int coarseGhostlayerWidth = 1;
  int fineSubdivisionFactor = 2;
  int fineGhostlayerWidth = 2;
  int unknownsPerSubcell = 1;

  //Setup coarse patch
  tarch::la::Vector<DIMENSIONS, double> coarsePosition;
  assignList(coarsePosition) = 2.0, 1.0;
  patches[1] = createPatch(
    unknownsPerSubcell,
    0,   //Aux fields per subcell
    0,   //Aux fields per subcell
    coarseSubdivisionFactor,
    coarseGhostlayerWidth,
    coarsePosition,
    3.0, //Coarse size
    0,   //Level
    0.0, //Time
    1.0, //Timestep size
    1.0, //Minimal neighbor time
    false   //Overlapped by coarse ghost layer
  );
  patches[3] = patches[1];

  //Setup fine patch
  tarch::la::Vector<DIMENSIONS, double> finePosition;
  assignList(finePosition) = 5.0, 2.0;
  patches[0] = createPatch(
    unknownsPerSubcell,
    0,   //Aux fields per subcell
    0,   //Aux fields per subcell
    fineSubdivisionFactor,
    fineGhostlayerWidth,
    finePosition,
    1.0, //Size
    1,   //Level
    0.0, //Time
    1.0/3.0, //Timestep size
    1.0  //Minimal neighbor time
  );

  //Fill coarse patch
  dfor(index, coarseSubdivisionFactor) {
    tarch::la::Vector<DIMENSIONS, int> subcellIndex;
    subcellIndex(0) = index(1);
    subcellIndex(1) = index(0);
    patches[1].getAccessor().setValueUNew(subcellIndex, 0, 1.0);
  }
コード例 #3
0
void DynamicColumnMatrixTest::testBasics ()
{
  DynamicColumnMatrix<int> matrix(2, 3, 5);
  validateEquals (matrix.size(), 6);
  validateEquals (matrix.rows(), 2);
  validateEquals (matrix.cols(), 3);
  validateEquals (matrix(0,0), 5);
  validateEquals (matrix(0,1), 5);
  validateEquals (matrix(1,2), 5);
  assignList(matrix) = 1, 2, 3,
                       4, 5, 6;
  validateEquals (matrix(0,0), 1);
  validateEquals (matrix(0,1), 2);
  validateEquals (matrix(0,2), 3);
  validateEquals (matrix(1,0), 4);
  validateEquals (matrix(1,1), 5);
  validateEquals (matrix(1,2), 6);
  validateEquals (matrix.column(0).size(), 2);
  validateEquals (matrix.column(1).size(), 2);
  validateEquals (matrix.column(2).size(), 2);
  validateEquals (matrix.column(0)[0], 1);
  validateEquals (matrix.column(1)[0], 2);
  validateEquals (matrix.column(2)[1], 6);

  DynamicColumnMatrix<int> matrix2(matrix);
  validateEquals (matrix2.size(), 6);
  validateEquals (matrix2.rows(), 2);
  validateEquals (matrix2.cols(), 3);
  validateEquals (matrix2(0,0), 1);
  validateEquals (matrix2(0,1), 2);
  validateEquals (matrix2(0,2), 3);
  validateEquals (matrix2(1,0), 4);
  validateEquals (matrix2(1,1), 5);
  validateEquals (matrix2(1,2), 6);
}
コード例 #4
0
void LUDecompositionTest::testLU()
{
  Matrix<4,4,double> A;
  assignList(A) =
      5.0, 2.0, 3.0, 1.0,
      6.0, 3.0, 6.0, 1.0,
      3.0, 2.0, 5.0, 4.0,
      4.0, 1.0, 2.0, 1.0;
  Matrix<4,4,double> Acopy(A);
  Vector<4,int> pivots;
  lu(A,pivots);
  Matrix<4,4,double> L(A);
  for (int i=0; i < 4; i++){
    L(i,i) = 1.0;
    for (int j=i+1; j < 4; j++){
      L(i,j) = 0.0;
    }
  }
  Matrix<4,4,double> R(A);
  for (int j=0; j < 4; j++){
    for (int i=j+1; i < 4; i++){
      R(i,j) = 0.0;
    }
  }
  assign(A) = 0.0;
  multiply (L, R, A);
  for (int i=0; i < 4; i++){
    for (int j=0; j < 4; j++){
      double temp = Acopy(i,j);
      Acopy(i,j) = Acopy(pivots(i),j);
      Acopy(pivots(i),j) = temp;
    }
  }
  //TODO validateWithParams1 (equals(A, Acopy), A);
}
コード例 #5
0
ファイル: StatisticsTest.cpp プロジェクト: unterweg/peanoclaw
void peanoclaw::tests::StatisticsTest::testGetNeighborPositionOnSameLevel() {
  tarch::la::Vector<DIMENSIONS, double> position;
  assignList(position) =
      2.0/3.0
      ,1.0/3.0
      #ifdef Dim3
      ,1.0/3.0
      #endif
      ;
  tarch::la::Vector<DIMENSIONS, double> size(1.0/3.0);
  int level = 2;
  tarch::la::Vector<DIMENSIONS, double> expectedNeighborPosition;
  assignList(expectedNeighborPosition) =
      1.0
      ,0.0
      #ifdef Dim3
      ,0.0
      #endif
      ;
  tarch::la::Vector<DIMENSIONS, int> discreteNeighborPosition;
  assignList(discreteNeighborPosition) =
      1
      ,0
      #ifdef Dim3
      ,0
      #endif
      ;

  tarch::la::Vector<DIMENSIONS, double> domainOffset(0.0);
  tarch::la::Vector<DIMENSIONS, double> domainSize(1.0);
  peanoclaw::statistics::ParallelGridValidator validator(domainOffset, domainSize, false);

  tarch::la::Vector<DIMENSIONS, double> neighborPosition
    = validator.getNeighborPositionOnLevel(
      position,
      size,
      level,
      level-1,
      discreteNeighborPosition
    );

  validateWithParams2(tarch::la::equals(neighborPosition, expectedNeighborPosition), neighborPosition, expectedNeighborPosition);
}
コード例 #6
0
void MatrixTest::testMatrixOperations ()
{
  // Test computing determinant
  Matrix<3,3,int> matrix;
  assignList(matrix) = 1, 2, 3,
                       4, 5, 6,
                       7, 8, 9;
  validateEquals (0, det3x3(matrix));
  assignList(matrix) = -1, 2, 3,
                       4, -5, 2,
                       -2, 3, 1;
  validateEquals (1, det3x3(matrix)); // computed by octave

  // Test streaming
  Matrix<2,2,int> matrix2;
  assignList(matrix2) = 1, 2, 3, 4;
  std::ostringstream stream;
  stream << matrix2;
  validateEquals (stream.str(), std::string("1, 2; 3, 4"));
  // Test matrix multiply scalar
  matrix2 =matrix2*2;
  validateEquals(matrix2(0,0),2);
  validateEquals(matrix2(0,1),4);
  validateEquals(matrix2(1,0),6);
  validateEquals(matrix2(1,1),8);
  // Test matrix add matrix
//  Matrix<2,2,int> matrix3;
//  assignList(matrix3) = 1, 2, 3, 4;
//  matrix3=matrix3+matrix2;
//  validateEquals(matrix3(0,0),3);
//  validateEquals(matrix3(0,1),6);
//  validateEquals(matrix3(1,0),9);
//  validateEquals(matrix3(1,1),12);
  // Test matrix square
  Matrix<2,2,double> matrix4;
  assignList(matrix4) = 4.0, 9.0, 16.0, 25.0;
  matrix4=sqrt(matrix4);
  validateEquals(matrix4(0,0),2.0);
  validateEquals(matrix4(0,1),3.0);
  validateEquals(matrix4(1,0),4.0);
  validateEquals(matrix4(1,1),5.0);
}
コード例 #7
0
void peano::kernel::regulargrid::parallel::tests::SetupPartitionerTest::test2D_400x400ForkMessages() {
  #ifdef Dim2
  tarch::la::Vector<DIMENSIONS,int> domain;
  assignList(domain) = 401,401;
  peano::kernel::regulargrid::parallel::SetupPartitioner partitioner(domain,2);

  partitioner._ranks.push_back(0);
  partitioner._ranks.push_back(1);

  tarch::la::Vector<DIMENSIONS,int>     partition;
  tarch::la::Vector<DIMENSIONS,double>  domainOffset;
  tarch::la::Vector<DIMENSIONS,double>  h;

  assignList(domainOffset) =  0.0,  0.0;
  assignList(h)            =  1.0/400.0,  1.0/400.0;

  assignList(partition) = 0,0;
  peano::kernel::regulargrid::parallel::messages::ForkMessage message00 =
    partitioner.getForkMessage( partition, domainOffset, h );
  validateEquals( message00.getH(), h );
  validateEquals( message00.getNumberOfGridPoints()(0), 201 );
  validateEquals( message00.getNumberOfGridPoints()(1), 401 );
  validateEquals( message00.getDomainOffset()(0), 0.0);
  validateEquals( message00.getDomainOffset()(1), 0.0);

  assignList(partition) = 1,0;
  peano::kernel::regulargrid::parallel::messages::ForkMessage message10 =
    partitioner.getForkMessage( partition, domainOffset, h );
  validateEquals( message10.getH(), h );
  validateEquals( message10.getNumberOfGridPoints()(0), 201 );
  validateEquals( message10.getNumberOfGridPoints()(1), 401 );
  validateEquals( partitioner.getOffsetOfPartition(partition)(0), 200);
  validateEquals( partitioner.getOffsetOfPartition(partition)(1), 0);
  validateEquals( message10.getDomainOffset()(1), 0.0);
  validateEquals( message10.getDomainOffset()(0), 0.5);
  validateEquals( message10.getDomainOffset()(1), 0.0);

  #endif
}
コード例 #8
0
void MatrixTest:: testAssignment ()
{
  Matrix<2,2,int> matrix(1);
  assignList(matrix) = 1, 2, 3, 4;
  validateEquals (matrix(0,0), 1);
  validateEquals (matrix(0,1), 2);
  validateEquals (matrix(1,0), 3);
  validateEquals (matrix(1,1), 4);

  DynamicMatrix<int> dynmatrix(2, 2, 2);
  validateEquals (dynmatrix(0,0), 2);
  validateEquals (dynmatrix(0,1), 2);
  validateEquals (dynmatrix(1,0), 2);
  validateEquals (dynmatrix(1,1), 2);

  assign(dynmatrix) = matrix;
  validateEquals (dynmatrix(0,0), 1);
  validateEquals (dynmatrix(0,1), 2);
  validateEquals (dynmatrix(1,0), 3);
  validateEquals (dynmatrix(1,1), 4);

  assign(dynmatrix) = 5;
  validateEquals (dynmatrix(0,0), 5);
  validateEquals (dynmatrix(0,1), 5);
  validateEquals (dynmatrix(1,0), 5);
  validateEquals (dynmatrix(1,1), 5);

  assign(matrix) = dynmatrix;
  validateEquals (matrix(0,0), 5);
  validateEquals (matrix(0,1), 5);
  validateEquals (matrix(1,0), 5);
  validateEquals (matrix(1,1), 5);

  Matrix<1,2,int> matrix2;
  assignList(matrix2) = 1, 2;
  validateEquals (matrix2(0,0), 1);
  validateEquals (matrix2(0,1), 2);
}
コード例 #9
0
void LUDecompositionTest::testLUNoPivoting()
{
  Vector<3,int> pivots3(0);
  DynamicMatrix<double> dynA (3,3);
  assignList(dynA) =
      5.0, 2.0, 3.0,
      2.0, 3.0, 6.0,
      1.0, 2.0, 4.0;
  lu (dynA, pivots3);
  Matrix<3,3,double> result3by3;
  assignList(result3by3) =
      5.0, 2.0, 3.0,
      0.4, 2.2, 4.8,
      0.2, 0.7272727272727272, -0.0909090909090909;
  //TODO validateWithParams1 (equals(dynA, result3by3), dynA);
  Vector<3,int> validPivots3(0,1,2);
  validateEqualsWithParams1 (pivots3, validPivots3, pivots3);

  Vector<4,int> pivots4(0);
  DynamicColumnMatrix<double> dyncolA (4,4);
  assignList(dyncolA) =
      5.0, 2.0, 3.0, 1.0,
      2.0, 3.0, 6.0, 1.0,
      2.0, 2.0, 5.0, 4.0,
      1.0, 1.0, 1.0, 1.0;
  lu (dyncolA, pivots4);
  Matrix<4,4,double> result4by4;
  assignList(result4by4) =
      5.0, 2.0, 3.0, 1.0,
      0.4, 2.2, 4.8, 0.6,
      0.4, 0.5454545454545454, 1.1818181818181818, 3.2727272727272727,
      0.2, 0.2727272727272727, -0.7692307692307689, 3.153846153846153;
  Vector<4,int> validPivots4(0,1,2,3);
  //TODO validateWithParams1 (equals(dyncolA, result4by4), dyncolA);
  validateEqualsWithParams1 (pivots4, validPivots4, pivots4);
}
コード例 #10
0
void MatrixTest:: testTransposedMatrix ()
{
  Matrix<3,2,int> matrix;
  assignList(matrix) = 1, 2,
                       3, 4,
                       5, 6;
  typedef Matrix<3,2,int> Matrix;
  TransposedMatrix<Matrix>& transposed = transpose(matrix);
  validateEquals (transposed(0,0), 1);
  validateEquals (transposed(0,1), 3);
  validateEquals (transposed(0,2), 5);
  validateEquals (transposed(1,0), 2);
  validateEquals (transposed(1,1), 4);
  validateEquals (transposed(1,2), 6);

  validate (transpose(transposed) == matrix);
}
コード例 #11
0
void DynamicColumnMatrixTest::testColumnManipulations ()
{
  DynamicColumnMatrix<int> matrix(2, 3);
  validateEquals (matrix.size(), 6);
  validateEquals (matrix.rows(), 2);
  validateEquals (matrix.cols(), 3);
  assignList(matrix) = 1, 2, 3,
                       4, 5, 6;

  // Remove columns
  matrix.remove(2);
  validateEquals (matrix.size(), 4);
  validateEquals (matrix.rows(), 2);
  validateEquals (matrix.cols(), 2);
  matrix.remove(1);
  validateEquals (matrix.size(), 2);
  validateEquals (matrix.rows(), 2);
  validateEquals (matrix.cols(), 1);
  matrix.remove(0);
  validateEquals (matrix.size(), 0);
  validateEquals (matrix.rows(), 0);
  validateEquals (matrix.cols(), 0);

  // Add columns
  matrix.append (DynamicVector<int>(3,1));
  validateEquals (matrix.size(), 3);
  validateEquals (matrix.rows(), 3);
  validateEquals (matrix.cols(), 1);
  validateEquals (matrix(0,0), 1);
  validateEquals (matrix(1,0), 1);
  validateEquals (matrix(2,0), 1);
  matrix.append (DynamicVector<int>(3,2));
  validateEquals (matrix.size(), 6);
  validateEquals (matrix.rows(), 3);
  validateEquals (matrix.cols(), 2);
  validateEquals (matrix(0,0), 1);
  validateEquals (matrix(1,0), 1);
  validateEquals (matrix(2,0), 1);
  validateEquals (matrix(0,1), 2);
  validateEquals (matrix(1,1), 2);
  validateEquals (matrix(2,1), 2);
  matrix.appendFront (DynamicVector<int>(3,3));
  validateEquals (matrix.size(), 9);
  validateEquals (matrix.rows(), 3);
  validateEquals (matrix.cols(), 3);
  validateEquals (matrix(0,0), 3);
  validateEquals (matrix(1,0), 3);
  validateEquals (matrix(2,0), 3);
  validateEquals (matrix(0,1), 1);
  validateEquals (matrix(1,1), 1);
  validateEquals (matrix(2,1), 1);
  validateEquals (matrix(0,2), 2);
  validateEquals (matrix(1,2), 2);
  validateEquals (matrix(2,2), 2);

  // Shift columns
  matrix.shiftSetFirst (DynamicVector<int>(3,4));
  validateEquals (matrix.size(), 9);
  validateEquals (matrix.rows(), 3);
  validateEquals (matrix.cols(), 3);
  validateEquals (matrix(0,0), 4);
  validateEquals (matrix(1,0), 4);
  validateEquals (matrix(2,0), 4);
  validateEquals (matrix(0,1), 3);
  validateEquals (matrix(1,1), 3);
  validateEquals (matrix(2,1), 3);
  validateEquals (matrix(0,2), 1);
  validateEquals (matrix(1,2), 1);
  validateEquals (matrix(2,2), 1);

  DynamicColumnMatrix<int> matrix2;
  matrix2.append (matrix);
  validateEquals (matrix2.size(), 9);
  validateEquals (matrix2.rows(), 3);
  validateEquals (matrix2.cols(), 3);
  validateEquals (matrix2(0,0), 4);
  validateEquals (matrix2(1,0), 4);
  validateEquals (matrix2(2,0), 4);
  validateEquals (matrix2(0,1), 3);
  validateEquals (matrix2(1,1), 3);
  validateEquals (matrix2(2,1), 3);
  validateEquals (matrix2(0,2), 1);
  validateEquals (matrix2(1,2), 1);
  validateEquals (matrix2(2,2), 1);

  // Remove columns from intermediate positions
  matrix2.remove (1);
  validateEquals (matrix2.size(), 6);
  validateEquals (matrix2.rows(), 3);
  validateEquals (matrix2.cols(), 2);
  validateEquals (matrix2(0,0), 4);
  validateEquals (matrix2(1,0), 4);
  validateEquals (matrix2(2,0), 4);
  validateEquals (matrix2(0,1), 1);
  validateEquals (matrix2(1,1), 1);
  validateEquals (matrix2(2,1), 1);
  matrix2.remove (0);
  validateEquals (matrix2.size(), 3);
  validateEquals (matrix2.rows(), 3);
  validateEquals (matrix2.cols(), 1);
  validateEquals (matrix2(0,0), 1);
  validateEquals (matrix2(1,0), 1);
  validateEquals (matrix2(2,0), 1);

  matrix2.clear ();
  validateEquals (matrix2.size(), 0);
  validateEquals (matrix2.rows(), 0);
  validateEquals (matrix2.cols(), 0);

}
コード例 #12
0
void peano::kernel::regulargrid::parallel::tests::SetupPartitionerTest::test2D_12x8ForkMessages() {
  #ifdef Dim2
  tarch::la::Vector<DIMENSIONS,int> domain;
  assignList(domain) = 12,9;
  peano::kernel::regulargrid::parallel::SetupPartitioner partitioner(domain,9);

  partitioner._ranks.push_back(0);
  partitioner._ranks.push_back(1);
  partitioner._ranks.push_back(2);
  partitioner._ranks.push_back(3);
  partitioner._ranks.push_back(4);
  partitioner._ranks.push_back(5);
  partitioner._ranks.push_back(6);
  partitioner._ranks.push_back(7);
  partitioner._ranks.push_back(8);

  tarch::la::Vector<DIMENSIONS,int>     partition;
  tarch::la::Vector<DIMENSIONS,double>  domainOffset;
  tarch::la::Vector<DIMENSIONS,double>  h;

  assignList(domainOffset) = -2.0, -3.0;
  assignList(h)            =  0.4,  0.5;

  assignList(partition) = 0,0;
  peano::kernel::regulargrid::parallel::messages::ForkMessage message00 =
    partitioner.getForkMessage( partition, domainOffset, h );
  assignList(partition) = 1,0;
  peano::kernel::regulargrid::parallel::messages::ForkMessage message10 =
    partitioner.getForkMessage( partition, domainOffset, h );
  assignList(partition) = 2,0;
  peano::kernel::regulargrid::parallel::messages::ForkMessage message20 =
    partitioner.getForkMessage( partition, domainOffset, h );
  assignList(partition) = 0,1;
  peano::kernel::regulargrid::parallel::messages::ForkMessage message01 =
    partitioner.getForkMessage( partition, domainOffset, h );
  assignList(partition) = 1,1;
  peano::kernel::regulargrid::parallel::messages::ForkMessage message11 =
    partitioner.getForkMessage( partition, domainOffset, h );
  assignList(partition) = 2,1;
  peano::kernel::regulargrid::parallel::messages::ForkMessage message21 =
    partitioner.getForkMessage( partition, domainOffset, h );
  assignList(partition) = 0,2;
  peano::kernel::regulargrid::parallel::messages::ForkMessage message02 =
    partitioner.getForkMessage( partition, domainOffset, h );
  assignList(partition) = 1,2;
  peano::kernel::regulargrid::parallel::messages::ForkMessage message12 =
    partitioner.getForkMessage( partition, domainOffset, h );
  assignList(partition) = 2,2;
  peano::kernel::regulargrid::parallel::messages::ForkMessage message22 =
    partitioner.getForkMessage( partition, domainOffset, h );

  //  validateEquals( message00.getNeighbourRanks(), h );

  validateEquals( message00.getH(), h );
  validateEquals( message00.getNumberOfGridPoints()(0), 5 );
  validateEquals( message00.getNumberOfGridPoints()(1), 4 );
  validateEquals( message00.getDomainOffset()(0), domainOffset(0) + 0*h(0));
  validateEquals( message00.getDomainOffset()(1), domainOffset(1) + 0*h(1));

  validateEquals( message10.getH(), h );
  validateEquals( message10.getNumberOfGridPoints()(0), 5 );
  validateEquals( message10.getNumberOfGridPoints()(1), 4 );
  validateEquals( message10.getDomainOffset()(0), domainOffset(0) + 4*h(0));
  validateEquals( message10.getDomainOffset()(1), domainOffset(1) + 0*h(1));

  validateEquals( message20.getH(), h );
  validateEquals( message20.getNumberOfGridPoints()(0), 4 );
  validateEquals( message20.getNumberOfGridPoints()(1), 4 );
  validateEquals( message20.getDomainOffset()(0), domainOffset(0) + 8*h(0));
  validateEquals( message20.getDomainOffset()(1), domainOffset(1) + 0*h(1));

  validateEquals( message01.getH(), h );
  validateEquals( message01.getNumberOfGridPoints()(0), 5 );
  validateEquals( message01.getNumberOfGridPoints()(1), 4 );
  validateEquals( message01.getDomainOffset()(0), domainOffset(0) + 0*h(0));
  validateEquals( message01.getDomainOffset()(1), domainOffset(1) + 3*h(1));
  #endif
}
コード例 #13
0
void peano::kernel::regulargrid::parallel::tests::SetupPartitionerTest::test2D_12x8() {
  #ifdef Dim2
  tarch::la::Vector<DIMENSIONS,int> domain;
  assignList(domain) = 12,9;
  peano::kernel::regulargrid::parallel::SetupPartitioner partition0(domain,8);
  peano::kernel::regulargrid::parallel::SetupPartitioner partition1(domain,9);
  peano::kernel::regulargrid::parallel::SetupPartitioner partition2(domain,10);
  peano::kernel::regulargrid::parallel::SetupPartitioner partition3(domain,11);

  validateEquals( partition0.getParallelTopology()(0), 4 );
  validateEquals( partition0.getParallelTopology()(1), 2 );
  validateEquals( partition1.getParallelTopology()(0), 3 );
  validateEquals( partition1.getParallelTopology()(1), 3 );
  validateEquals( partition2.getParallelTopology()(0), 3 );
  validateEquals( partition2.getParallelTopology()(1), 3 );
  validateEquals( partition3.getParallelTopology()(0), 3 );
  validateEquals( partition3.getParallelTopology()(1), 3 );

  tarch::la::Vector<DIMENSIONS,int> expectedSize;
  tarch::la::Vector<DIMENSIONS,int> expectedOffset;
  tarch::la::Vector<DIMENSIONS,int> subdomain;

  assignList(expectedSize) = 4,3;
  assignList(subdomain) = 0,0;
  assignList(expectedOffset) = 0,0;
  validateEquals( partition1.getSizeOfPartition(subdomain), expectedSize );
  validateEquals( partition2.getSizeOfPartition(subdomain), expectedSize );
  validateEquals( partition3.getSizeOfPartition(subdomain), expectedSize );
  validateEquals( partition1.getOffsetOfPartition(subdomain), expectedOffset );
  validateEquals( partition2.getOffsetOfPartition(subdomain), expectedOffset );
  validateEquals( partition3.getOffsetOfPartition(subdomain), expectedOffset );

  assignList(subdomain) = 1,0;
  assignList(expectedOffset) = 4,0;
  validateEquals( partition1.getSizeOfPartition(subdomain), expectedSize );
  validateEquals( partition2.getSizeOfPartition(subdomain), expectedSize );
  validateEquals( partition3.getSizeOfPartition(subdomain), expectedSize );
  validateEquals( partition1.getOffsetOfPartition(subdomain), expectedOffset );
  validateEquals( partition2.getOffsetOfPartition(subdomain), expectedOffset );
  validateEquals( partition3.getOffsetOfPartition(subdomain), expectedOffset );

  assignList(subdomain) = 2,0;
  assignList(expectedSize) = 3,3;
  assignList(expectedOffset) = 8,0;
  validateEquals( partition1.getSizeOfPartition(subdomain), expectedSize );
  validateEquals( partition2.getSizeOfPartition(subdomain), expectedSize );
  validateEquals( partition3.getSizeOfPartition(subdomain), expectedSize );
  validateEquals( partition1.getOffsetOfPartition(subdomain), expectedOffset );
  validateEquals( partition2.getOffsetOfPartition(subdomain), expectedOffset );
  validateEquals( partition3.getOffsetOfPartition(subdomain), expectedOffset );

  assignList(subdomain) = 0,1;
  assignList(expectedSize) = 4,3;
  assignList(expectedOffset) = 0,3;
  validateEquals( partition1.getSizeOfPartition(subdomain), expectedSize );
  validateEquals( partition2.getSizeOfPartition(subdomain), expectedSize );
  validateEquals( partition3.getSizeOfPartition(subdomain), expectedSize );
  validateEquals( partition1.getOffsetOfPartition(subdomain), expectedOffset );
  validateEquals( partition2.getOffsetOfPartition(subdomain), expectedOffset );
  validateEquals( partition3.getOffsetOfPartition(subdomain), expectedOffset );

  assignList(subdomain) = 1,1;
  assignList(expectedOffset) = 4,3;
  validateEquals( partition1.getSizeOfPartition(subdomain), expectedSize );
  validateEquals( partition2.getSizeOfPartition(subdomain), expectedSize );
  validateEquals( partition3.getSizeOfPartition(subdomain), expectedSize );
  validateEquals( partition1.getOffsetOfPartition(subdomain), expectedOffset );
  validateEquals( partition2.getOffsetOfPartition(subdomain), expectedOffset );
  validateEquals( partition3.getOffsetOfPartition(subdomain), expectedOffset );

  assignList(subdomain) = 2,1;
  assignList(expectedSize) = 3,3;
  assignList(expectedOffset) = 8,3;
  validateEquals( partition1.getSizeOfPartition(subdomain), expectedSize );
  validateEquals( partition2.getSizeOfPartition(subdomain), expectedSize );
  validateEquals( partition3.getSizeOfPartition(subdomain), expectedSize );
  validateEquals( partition1.getOffsetOfPartition(subdomain), expectedOffset );
  validateEquals( partition2.getOffsetOfPartition(subdomain), expectedOffset );
  validateEquals( partition3.getOffsetOfPartition(subdomain), expectedOffset );

  assignList(subdomain) = 0,2;
  assignList(expectedSize) = 4,2;
  assignList(expectedOffset) = 0,6;
  validateEquals( partition1.getSizeOfPartition(subdomain), expectedSize );
  validateEquals( partition2.getSizeOfPartition(subdomain), expectedSize );
  validateEquals( partition3.getSizeOfPartition(subdomain), expectedSize );
  validateEquals( partition1.getOffsetOfPartition(subdomain), expectedOffset );
  validateEquals( partition2.getOffsetOfPartition(subdomain), expectedOffset );
  validateEquals( partition3.getOffsetOfPartition(subdomain), expectedOffset );

  assignList(subdomain) = 1,2;
  assignList(expectedSize) = 4,2;
  assignList(expectedOffset) = 4,6;
  validateEquals( partition1.getSizeOfPartition(subdomain), expectedSize );
  validateEquals( partition2.getSizeOfPartition(subdomain), expectedSize );
  validateEquals( partition3.getSizeOfPartition(subdomain), expectedSize );
  validateEquals( partition1.getOffsetOfPartition(subdomain), expectedOffset );
  validateEquals( partition2.getOffsetOfPartition(subdomain), expectedOffset );
  validateEquals( partition3.getOffsetOfPartition(subdomain), expectedOffset );

  assignList(subdomain) = 2,2;
  assignList(expectedSize) = 3,2;
  assignList(expectedOffset) = 8,6;
  validateEquals( partition1.getSizeOfPartition(subdomain), expectedSize );
  validateEquals( partition2.getSizeOfPartition(subdomain), expectedSize );
  validateEquals( partition3.getSizeOfPartition(subdomain), expectedSize );
  validateEquals( partition1.getOffsetOfPartition(subdomain), expectedOffset );
  validateEquals( partition2.getOffsetOfPartition(subdomain), expectedOffset );
  validateEquals( partition3.getOffsetOfPartition(subdomain), expectedOffset );
  #endif
}
コード例 #14
0
ファイル: fullswof2DMain.cpp プロジェクト: unterweg/peanoclaw
void peanoclaw::native::fullswof2DMain(
  peanoclaw::native::scenarios::SWEScenario& scenario,
  tarch::la::Vector<DIMENSIONS,int> numberOfCells
) {
  tarch::logging::Log _log("peanoclaw::native::fullswof2DMain(...)");

  int ghostlayerWidth = 1;

  FullSWOF2D_Parameters parameters(
    ghostlayerWidth,
    numberOfCells[0],
    numberOfCells[1],
    scenario.getInitialMinimalMeshWidth()[0],
    scenario.getInitialMinimalMeshWidth()[1],
    scenario.getDomainSize(),
    scenario.getEndTime(),
    #ifdef PEANOCLAW_FULLSWOF2D
    scenario.enableRain(),
    scenario.getFrictionCoefficient(),
    #else
    true,
    0.0,
    #endif
    scenario.getBoundaryCondition(0, false),
    scenario.getBoundaryCondition(0, true),
    scenario.getBoundaryCondition(1, false),
    scenario.getBoundaryCondition(1, true)
  );

  Choice_scheme * schemeWrapper;
  schemeWrapper = new Choice_scheme(parameters);
  Scheme* scheme = schemeWrapper->getInternalScheme();

  tarch::la::Vector<DIMENSIONS,int> subcellIndex;

  /** Water height.*/
  TAB& h = scheme->getH();
  for (int x = -ghostlayerWidth; x < numberOfCells(0)+ghostlayerWidth; x++) {
    for (int y = -ghostlayerWidth; y < numberOfCells(1)+ghostlayerWidth; y++) {
      assignList(subcellIndex) = x, y;
      tarch::la::Vector<DIMENSIONS,double> position
        = subcellIndex.convertScalar<double>() * tarch::la::invertEntries(numberOfCells.convertScalar<double>()) * scenario.getDomainSize();
      position += scenario.getDomainOffset();
      h[x+ghostlayerWidth][y+ghostlayerWidth] = scenario.getWaterHeight(
        (float)x / numberOfCells[0] * scenario.getDomainSize()[0] + scenario.getDomainOffset()[0],
        (float)y / numberOfCells[1] * scenario.getDomainSize()[1] + scenario.getDomainOffset()[1]
      );
    }
  }

  /** X Velocity.*/
  TAB& u = scheme->getU();
  for (int x = -ghostlayerWidth; x < numberOfCells(0)+ghostlayerWidth; x++) {
    for (int y = -ghostlayerWidth; y < numberOfCells(1)+ghostlayerWidth; y++) {
        assignList(subcellIndex) = x, y;
        u[x+ghostlayerWidth][y+ghostlayerWidth] = scenario.getVeloc_u(
          (float)x / numberOfCells[0] * scenario.getDomainSize()[0] + scenario.getDomainOffset()[0],
          (float)y / numberOfCells[1] * scenario.getDomainSize()[1] + scenario.getDomainOffset()[1]
        );
    }
  }

  /** Y Velocity.*/
  TAB& v = scheme->getV();
  for (int x = -ghostlayerWidth; x < numberOfCells(0)+ghostlayerWidth; x++) {
    for (int y = -ghostlayerWidth; y < numberOfCells(1)+ghostlayerWidth; y++) {
      assignList(subcellIndex) = x, y;
      v[x+ghostlayerWidth][y+ghostlayerWidth] = scenario.getVeloc_v(
        (float)x / numberOfCells[0] * scenario.getDomainSize()[0] + scenario.getDomainOffset()[0],
        (float)y / numberOfCells[1] * scenario.getDomainSize()[1] + scenario.getDomainOffset()[1]
      );
    }
  }

  /** Topography.*/
  TAB& z = scheme->getZ();
  for (int x = -ghostlayerWidth; x < numberOfCells(0)+ghostlayerWidth; x++) {
    for (int y = -ghostlayerWidth; y < numberOfCells(1)+ghostlayerWidth; y++) {
      assignList(subcellIndex) = x, y;
      z[x+ghostlayerWidth][y+ghostlayerWidth] = scenario.getBathymetry(
        (float)x / numberOfCells[0] * scenario.getDomainSize()[0] + scenario.getDomainOffset()[0],
        (float)y / numberOfCells[1] * scenario.getDomainSize()[1] + scenario.getDomainOffset()[1]
      );
    }
  }

  tarch::timing::Watch runtimeWatch("peanoclaw::native", "fullswof2DMain", true);

  double t = 0.0;
  while(tarch::la::smaller(t, scenario.getEndTime())) {

    //TODO unterweg debug
    std::cout << "t=" << t << std::endl;

    scheme->resetN();
    schemeWrapper->calcul();
    t += scheme->getTimestep();
  }

  runtimeWatch.stopTimer();

  //Print maximum memory demand
  logInfo("fullswof2DMain", "Peak resident set size: " << peanoclaw::statistics::getPeakRSS() << "b");
  delete scheme;
}
コード例 #15
0
void peano::applications::navierstokes::prototype1::fluidnumerics::tests::CalculatePPERHSTest::testCalculatePPERHSBilinearOnOneCell() {
#ifdef Dim2

  peano::applications::navierstokes::prototype1::fluidnumerics::CalculateInverseA  myInvA(1.0, 1.0);

  Vector h;
  double eta;
  double rho = 1.0;

  // create nodal data
  const int n = NUMBER_OF_VERTICES_PER_ELEMENT;
  peano::applications::navierstokes::prototype1::RegularGridFluidVertexEnhancedDivFreeEulerExplicit nodes[n];
  for (int i=0; i<n; i++) {
    nodes[i].setFluidVertexType(peano::applications::navierstokes::prototype1::INNER);
  }
  for(int i=0; i<n; i++){
    validateNumericalEquals( nodes[i].getF()(0),  0.0 );
    validateNumericalEquals( nodes[i].getF()(1),  0.0 );
  }
  const int vertexIndexMapping[NUMBER_OF_VERTICES_PER_ELEMENT] = { 0, 1, 2, 3 }; // this test is 2d only
  Vector u;

  // create cell data
  peano::applications::navierstokes::prototype1::RegularGridFluidCellEnhancedDivFreeEulerExplicit cell;
  cell.setFluidCellType(
    peano::applications::navierstokes::prototype1::RegularGridFluidCellEnhancedDivFreeEulerExplicit::Records::INNER
  );
  cell.setRhsPPE(0.0);

  // set everything concerning the geo scenario
  assignList(u) = 0.0, 0.0;
  for(int i=0; i<n; i++){
    nodes[i].setU(u);
    nodes[i].setFluidVertexType(
      peano::applications::navierstokes::prototype1::INNER
    );
  }

  /* %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
   * First block of tests: eta==0.0, h==1.0
   * %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
   */
  eta = 0.0;
  assignList(h) = 1, 1;
  peano::applications::navierstokes::prototype1::fluidnumerics::tests::TestVertexEnumerator vertexEnumerator( vertexIndexMapping, h );
  for(int i=0; i<n; i++){
    nodes[i].resetA();
  }
  myInvA.accumulateAValues(nodes, vertexEnumerator);
  myInvA.accumulateAValues(nodes, vertexEnumerator);
  myInvA.accumulateAValues(nodes, vertexEnumerator);
  myInvA.accumulateAValues(nodes, vertexEnumerator);
  for(int i=0; i<n; i++){
    validateNumericalEquals( nodes[i].getInverseA(),  1.0/(h[0]*h[0]) );
  }
  peano::applications::navierstokes::prototype1::fluidnumerics::CalculatePPERHSDlinear myCalcPPERHS(1.0, 1.0);

  loadCalculateF(peano::applications::navierstokes::prototype1::Dlinear,
                 rho, eta);
  // --------------------------------------------------------------------
  //Test 1: u1=(0,0,0,0), u2=(0,0,0,0)
  assignList(u) = 0.0, 0.0;
  for(int i=0; i<n; i++){
    nodes[i].setU(u);
    nodes[i].resetFValues();
  }
  _myCalculateF->accumulateFValues(nodes, vertexEnumerator);

  myCalcPPERHS.calculateCellPPERightHandSide(nodes, vertexEnumerator, cell);

  validateNumericalEquals( cell.getRhsPPE(),  0.0 );

  // --------------------------------------------------------------------
  //Test 2: u1=(0,0,1,1), u2=(0,0,0,0)
  assignList(u) = 0.0, 0.0;
  for(int i=0; i<n; i++){
    nodes[i].setU(u);
    nodes[i].resetFValues();
  }
  assignList(u) = 1.0, 0.0;
  nodes[2].setU(u);
  nodes[3].setU(u);
  _myCalculateF->accumulateFValues(nodes, vertexEnumerator);

  myCalcPPERHS.calculateCellPPERightHandSide(nodes, vertexEnumerator, cell);

  validateNumericalEquals( cell.getRhsPPE(),  0.0 );

  // --------------------------------------------------------------------
  //Test 3: u1=(1,0,1,0), u2=(0,0,0,0)
  assignList(u) = 0.0, 0.0;
  for(int i=0; i<n; i++){
    nodes[i].setU(u);
    nodes[i].resetFValues();
  }
  assignList(u) = 1.0, 0.0;
  nodes[0].setU(u);
  nodes[2].setU(u);
  _myCalculateF->accumulateFValues(nodes, vertexEnumerator);
  myCalcPPERHS.calculateCellPPERightHandSide(nodes, vertexEnumerator, cell);

  validateNumericalEquals( cell.getRhsPPE(),  78.0/72.0 );

  // --------------------------------------------------------------------
  //Test 4: u1=(1,1,-1,-1), u2=(-1,1,1,-1)
  for(int i=0; i<n; i++){
    nodes[i].resetFValues();
  }
  assignList(u) = 1.0, -1.0;
  nodes[0].setU(u);
  assignList(u) = 1.0, 1.0;
  nodes[1].setU(u);
  assignList(u) = -1.0, 1.0;
  nodes[2].setU(u);
  assignList(u) = -1.0, -1.0;
  nodes[3].setU(u);

  _myCalculateF->accumulateFValues(nodes, vertexEnumerator);
  myCalcPPERHS.calculateCellPPERightHandSide(nodes, vertexEnumerator, cell);

  validateNumericalEquals( cell.getRhsPPE(),  1.0/9.0 );


  // --------------------------------------------------------------------
  //Test 5: u1=(0,0,0,0), u2=(0,0,-1,-1)
  for(int i=0; i<n; i++){
    nodes[i].resetFValues();
  }
  assignList(u) = 0.0, 0.0;
  nodes[0].setU(u);
  assignList(u) = 0.0, 0.0;
  nodes[1].setU(u);
  assignList(u) = 0.0, -1.0;
  nodes[2].setU(u);
  assignList(u) = 0.0, -1.0;
  nodes[3].setU(u);

  _myCalculateF->accumulateFValues(nodes, vertexEnumerator);
  myCalcPPERHS.calculateCellPPERightHandSide(nodes, vertexEnumerator, cell);

  validateNumericalEquals( cell.getRhsPPE(),  78.0/72.0 );

  // --------------------------------------------------------------------
  //Test 6: u1=(0,0,0,0), u2=(0,0,-3,-3)
  for(int i=0; i<n; i++){
    nodes[i].resetFValues();
  }
  assignList(u) = 0.0, 0.0;
  nodes[0].setU(u);
  assignList(u) = 0.0, 0.0;
  nodes[1].setU(u);
  assignList(u) = 0.0, -3.0;
  nodes[2].setU(u);
  assignList(u) = 0.0, -3.0;
  nodes[3].setU(u);

  _myCalculateF->accumulateFValues(nodes, vertexEnumerator);
  myCalcPPERHS.calculateCellPPERightHandSide(nodes, vertexEnumerator, cell);

  validateNumericalEquals( cell.getRhsPPE(),  15.0/4.0 );

  // %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  // Second block of tests: eta==1.0, h==1.0
  // %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  eta = 1.0;
  h[0] = 1.0;
  h[1] = 1.0;
  for(int i=0; i<n; i++){
    nodes[i].resetA();
  }
  myInvA.accumulateAValues(nodes, vertexEnumerator);
  myInvA.accumulateAValues(nodes, vertexEnumerator);
  myInvA.accumulateAValues(nodes, vertexEnumerator);
  myInvA.accumulateAValues(nodes, vertexEnumerator);
  for(int i=0; i<n; i++){
    validateNumericalEquals( nodes[i].getInverseA(),  1.0/(h[0]*h[0]) );
  }
  loadCalculateF(peano::applications::navierstokes::prototype1::Dlinear,
                 rho,eta);
  // --------------------------------------------------------------------
  //Test 7: u1=(0,0,0,0), u2=(0,0,0,0)
  assignList(u) = 0.0, 0.0;
  for(int i=0; i<n; i++){
    nodes[i].setU(u);
    nodes[i].resetFValues();
  }
  _myCalculateF->accumulateFValues(nodes, vertexEnumerator);

  myCalcPPERHS.calculateCellPPERightHandSide(nodes, vertexEnumerator, cell);

  validateNumericalEquals( cell.getRhsPPE(),  0.0 );

  // --------------------------------------------------------------------
  //Test 8: u1=(0,0,1,1), u2=(0,0,0,0)
  assignList(u) = 0.0, 0.0;
  for(int i=0; i<n; i++){
    nodes[i].setU(u);
    nodes[i].resetFValues();
  }
  assignList(u) = 1.0, 0.0;
  nodes[2].setU(u);
  nodes[3].setU(u);
  _myCalculateF->accumulateFValues(nodes, vertexEnumerator);
  myCalcPPERHS.calculateCellPPERightHandSide(nodes, vertexEnumerator, cell);

  validateNumericalEquals( cell.getRhsPPE(),  0.0 );

  // --------------------------------------------------------------------
  //Test 9: u1=(1,0,1,0), u2=(0,0,0,0)
  assignList(u) = 0.0, 0.0;
  for(int i=0; i<n; i++){
    nodes[i].setU(u);
    nodes[i].resetFValues();
  }
  assignList(u) = 1.0, 0.0;
  nodes[0].setU(u);
  nodes[2].setU(u);
  _myCalculateF->accumulateFValues(nodes, vertexEnumerator);
  myCalcPPERHS.calculateCellPPERightHandSide(nodes, vertexEnumerator, cell);

  validateNumericalEquals( cell.getRhsPPE(),  6.0/72.0 );

  // --------------------------------------------------------------------
  //Test 10: u1=(1,1,-1,-1), u2=(-1,1,1,-1)
  for(int i=0; i<n; i++){
    nodes[i].resetFValues();
  }
  assignList(u) = 1.0, -1.0;
  nodes[0].setU(u);
  assignList(u) = 1.0, 1.0;
  nodes[1].setU(u);
  assignList(u) = -1.0, 1.0;
  nodes[2].setU(u);
  assignList(u) = -1.0,-1.0;
  nodes[3].setU(u);

  _myCalculateF->accumulateFValues(nodes, vertexEnumerator);
  myCalcPPERHS.calculateCellPPERightHandSide(nodes, vertexEnumerator, cell);

  validateNumericalEquals( cell.getRhsPPE(),  1.0/9.0 );

  // --------------------------------------------------------------------
  //Test 11: u1=(0,0,0,0), u2=(0,0,-1,-1)
  for(int i=0; i<n; i++){
    nodes[i].resetFValues();
  }
  assignList(u) = 0.0, 0.0;
  nodes[0].setU(u);
  assignList(u) = 0.0, 0.0;
  nodes[1].setU(u);
  assignList(u) = 0.0, -1.0;
  nodes[2].setU(u);
  assignList(u) = 0.0, -1.0;
  nodes[3].setU(u);

  _myCalculateF->accumulateFValues(nodes, vertexEnumerator);
  myCalcPPERHS.calculateCellPPERightHandSide(nodes, vertexEnumerator, cell);

  validateNumericalEquals( cell.getRhsPPE(),  6.0/72.0 );

  // --------------------------------------------------------------------
  //Test 12: u1=(0,0,0,0), u2=(0,0,-3,-3)
  for(int i=0; i<n; i++){
    nodes[i].resetFValues();
  }
  assignList(u) = 0.0, 0.0;
  nodes[0].setU(u);
  assignList(u) = 0.0, 0.0;
  nodes[1].setU(u);
  assignList(u) = 0.0, -3.0;
  nodes[2].setU(u);
  assignList(u) = 0.0, -3.0;
  nodes[3].setU(u);

  _myCalculateF->accumulateFValues(nodes, vertexEnumerator);
  myCalcPPERHS.calculateCellPPERightHandSide(nodes, vertexEnumerator, cell);

  validateNumericalEquals( cell.getRhsPPE(),  3.0/4.0 );

  // %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  // Third block of tests: eta==3.0, h==0.25
  // %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  eta = 3.0;
  h[0] = 0.25;
  h[1] = 0.25;
  Vector cellSize(h[0],h[1]);
  vertexEnumerator.setCellSize(cellSize);
  for(int i=0; i<n; i++){
    nodes[i].resetA();
  }

  myInvA.accumulateAValues(nodes, vertexEnumerator);
  myInvA.accumulateAValues(nodes, vertexEnumerator);
  myInvA.accumulateAValues(nodes, vertexEnumerator);
  myInvA.accumulateAValues(nodes, vertexEnumerator);
  for(int i=0; i<n; i++){
    validateNumericalEquals( nodes[i].getInverseA(),  1.0/(h[0]*h[0]) );
  }

  loadCalculateF(peano::applications::navierstokes::prototype1::Dlinear,
                 rho, eta);
  // --------------------------------------------------------------------
  //Test 13: u1=(0,0,0,0), u2=(0,0,0,0)
  assignList(u) = 0.0, 0.0;
  for(int i=0; i<n; i++){
    nodes[i].setU(u);
    nodes[i].resetFValues();
  }
  _myCalculateF->accumulateFValues(nodes, vertexEnumerator);

  myCalcPPERHS.calculateCellPPERightHandSide(nodes, vertexEnumerator, cell);

  validateNumericalEquals( cell.getRhsPPE(),  0.0 );

  // --------------------------------------------------------------------
  //Test 14: u1=(0,0,1,1), u2=(0,0,0,0)
  assignList(u) = 0.0, 0.0;
  for(int i=0; i<n; i++){
    nodes[i].setU(u);
    nodes[i].resetFValues();
  }
  assignList(u) = 1.0, 0.0;
  nodes[2].setU(u);
  nodes[3].setU(u);
  _myCalculateF->accumulateFValues(nodes, vertexEnumerator);
  myCalcPPERHS.calculateCellPPERightHandSide(nodes, vertexEnumerator, cell);

  validateNumericalEquals( cell.getRhsPPE(),  0.0 );

  // --------------------------------------------------------------------
  //Test 15: u1=(1,0,1,0), u2=(0,0,0,0)
  assignList(u) = 0.0, 0.0;
  for(int i=0; i<n; i++){
    nodes[i].setU(u);
    nodes[i].resetFValues();
  }
  assignList(u) = 1.0, 0.0;
  nodes[0].setU(u);
  nodes[2].setU(u);
  _myCalculateF->accumulateFValues(nodes, vertexEnumerator);
  myCalcPPERHS.calculateCellPPERightHandSide(nodes, vertexEnumerator, cell);

  validateNumericalEquals( cell.getRhsPPE(),  -35.0/3.0 );

  // --------------------------------------------------------------------
  //Test 16: u1=(1,1,-1,-1), u2=(-1,1,1,-1)
  for(int i=0; i<n; i++){
    nodes[i].resetFValues();
  }
  assignList(u) = 1.0, -1.0;
  nodes[0].setU(u);
  assignList(u) = 1.0, 1.0;
  nodes[1].setU(u);
  assignList(u) = -1.0, 1.0;
  nodes[2].setU(u);
  assignList(u) = -1.0, -1.0;
  nodes[3].setU(u);

  _myCalculateF->accumulateFValues(nodes, vertexEnumerator);
  myCalcPPERHS.calculateCellPPERightHandSide(nodes, vertexEnumerator, cell);

  validateNumericalEquals( cell.getRhsPPE(),  1.0/9.0 );

  // --------------------------------------------------------------------
  //Test 17: u1=(0,0,0,0), u2=(0,0,-1,-1)
  for(int i=0; i<n; i++){
    nodes[i].resetFValues();
  }
  assignList(u) = 0.0, 0.0;
  nodes[0].setU(u);
  assignList(u) = 0.0, 0.0;
  nodes[1].setU(u);
  assignList(u) = 0.0, -1.0;
  nodes[2].setU(u);
  assignList(u) = 0.0, -1.0;
  nodes[3].setU(u);

  _myCalculateF->accumulateFValues(nodes, vertexEnumerator);
  myCalcPPERHS.calculateCellPPERightHandSide(nodes, vertexEnumerator, cell);

  validateNumericalEquals( cell.getRhsPPE(),  -35.0/3.0 );

  // --------------------------------------------------------------------
  //Test 18: u1=(0,0,0,0), u2=(0,0,-3,-3)
  for(int i=0; i<n; i++){
    nodes[i].resetFValues();
  }
  assignList(u) = 0.0, 0.0;
  nodes[0].setU(u);
  assignList(u) = 0.0, 0.0;
  nodes[1].setU(u);
  assignList(u) = 0.0, -3.0;
  nodes[2].setU(u);
  assignList(u) = 0.0, -3.0;
  nodes[3].setU(u);

  _myCalculateF->accumulateFValues(nodes, vertexEnumerator);
  myCalcPPERHS.calculateCellPPERightHandSide(nodes, vertexEnumerator, cell);

  validateNumericalEquals( cell.getRhsPPE(),  -69.0/2.0 );


  // %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  // Fourth block of tests: eta==3.0, h==0.25, adjFac==0
  // %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  eta = 3.0;
  h[0] = 0.25;
  h[1] = 0.25;
  for(int i=0; i<n; i++){
    nodes[i].resetA();
  }
  myInvA.accumulateAValues(nodes, vertexEnumerator);
  myInvA.accumulateAValues(nodes, vertexEnumerator);
  myInvA.accumulateAValues(nodes, vertexEnumerator);
  myInvA.accumulateAValues(nodes, vertexEnumerator);
  for(int i=0; i<n; i++){
    validateNumericalEquals( nodes[i].getInverseA(),  1.0/(h[0]*h[0]) );
  }
  peano::applications::navierstokes::prototype1::fluidnumerics::CalculatePPERHSDlinear myCalcPPERHS4(0.0, 1.0);
  loadCalculateF(peano::applications::navierstokes::prototype1::Dlinear,
                 rho, eta);
  // --------------------------------------------------------------------
  //Test 19: u1=(0,0,0,0), u2=(0,0,0,0)
  assignList(u) = 0.0, 0.0;
  for(int i=0; i<n; i++){
    nodes[i].setU(u);
    nodes[i].resetFValues();
  }
  _myCalculateF->accumulateFValues(nodes, vertexEnumerator);

  myCalcPPERHS4.calculateCellPPERightHandSide(nodes, vertexEnumerator, cell);

  validateNumericalEquals( cell.getRhsPPE(),  0.0 );

  // --------------------------------------------------------------------
  //Test 20: u1=(0,0,1,1), u2=(0,0,0,0)
  assignList(u) = 0.0, 0.0;
  for(int i=0; i<n; i++){
    nodes[i].setU(u);
    nodes[i].resetFValues();
  }
  assignList(u) = 1.0, 0.0;
  nodes[2].setU(u);
  nodes[3].setU(u);
  _myCalculateF->accumulateFValues(nodes, vertexEnumerator);
  myCalcPPERHS4.calculateCellPPERightHandSide(nodes, vertexEnumerator, cell);

  validateNumericalEquals( cell.getRhsPPE(),  0.0 );

  // --------------------------------------------------------------------
  //Test 21: u1=(1,0,1,0), u2=(0,0,0,0)
  assignList(u) = 0.0, 0.0;
  for(int i=0; i<n; i++){
    nodes[i].setU(u);
    nodes[i].resetFValues();
  }
  assignList(u) = 1.0, 0.0;
  nodes[0].setU(u);
  nodes[2].setU(u);
  _myCalculateF->accumulateFValues(nodes, vertexEnumerator);
  myCalcPPERHS4.calculateCellPPERightHandSide(nodes, vertexEnumerator, cell);

  validateNumericalEquals( cell.getRhsPPE(),  -858.0/72.0 );

  // --------------------------------------------------------------------
  //Test 22: u1=(1,1,-1,-1), u2=(-1,1,1,-1)
  for(int i=0; i<n; i++){
    nodes[i].resetFValues();
  }
  assignList(u) = 1.0, -1.0;
  nodes[0].setU(u);
  assignList(u) = 1.0, 1.0;
  nodes[1].setU(u);
  assignList(u) = -1.0, 1.0;
  nodes[2].setU(u);
  assignList(u) = -1.0,-1.0;
  nodes[3].setU(u);

  _myCalculateF->accumulateFValues(nodes, vertexEnumerator);
  myCalcPPERHS4.calculateCellPPERightHandSide(nodes, vertexEnumerator, cell);

  validateNumericalEquals( cell.getRhsPPE(),  1.0/9.0 );

  // --------------------------------------------------------------------
  //Test 23: u1=(0,0,0,0), u2=(0,0,-1,-1)
  for(int i=0; i<n; i++){
    nodes[i].resetFValues();
  }
  assignList(u) = 0.0, 0.0;
  nodes[0].setU(u);
  assignList(u) = 0.0, 0.0;
  nodes[1].setU(u);
  assignList(u) = 0.0, -1.0;
  nodes[2].setU(u);
  assignList(u) = 0.0, -1.0;
  nodes[3].setU(u);

  _myCalculateF->accumulateFValues(nodes, vertexEnumerator);
  myCalcPPERHS4.calculateCellPPERightHandSide(nodes, vertexEnumerator, cell);

  validateNumericalEquals( cell.getRhsPPE(),  -858.0/72.0 );

  // --------------------------------------------------------------------
  //Test 24: u1=(0,0,0,0), u2=(0,0,-3,-3)
  for(int i=0; i<n; i++){
    nodes[i].resetFValues();
  }
  assignList(u) = 0.0, 0.0;
  nodes[0].setU(u);
  assignList(u) = 0.0, 0.0;
  nodes[1].setU(u);
  assignList(u) = 0.0, -3.0;
  nodes[2].setU(u);
  assignList(u) = 0.0, -3.0;
  nodes[3].setU(u);

  _myCalculateF->accumulateFValues(nodes, vertexEnumerator);
  myCalcPPERHS4.calculateCellPPERightHandSide(nodes, vertexEnumerator, cell);

  validateNumericalEquals( cell.getRhsPPE(),  -141.0/4.0 );

#endif //Dim2
}
コード例 #16
0
void peano::applications::navierstokes::prototype1::fluidnumerics::tests::CalculatePPERHSTest::testCalculatePPERHSTrilinearOnOneCell3D() {
#ifdef Dim3

  peano::applications::navierstokes::prototype1::fluidnumerics::CalculateInverseA  myInvA(1.0,1.0);

  Vector h(1.0);

  // create nodal data
  const int n = NUMBER_OF_VERTICES_PER_ELEMENT;
  peano::applications::navierstokes::prototype1::RegularGridFluidVertexEnhancedDivFreeEulerExplicit nodes[n];
  for (int i=0; i<n; i++) {
    nodes[i].setFluidVertexType(peano::applications::navierstokes::prototype1::INNER);
  }
  const int vertexIndexMapping[NUMBER_OF_VERTICES_PER_ELEMENT] = { 0, 1, 2, 3, 4, 5, 6, 7 }; // this test is 3d only
  TestVertexEnumerator vertexEnumerator(vertexIndexMapping, h);

  Vector u(0.0);
  for(int i=0; i<n; i++){
    validateNumericalEquals( nodes[i].getF()(0),  0.0 );
    validateNumericalEquals( nodes[i].getF()(1),  0.0 );
    validateNumericalEquals( nodes[i].getF()(2),  0.0 );
    nodes[i].setU(u);
    nodes[i].setFluidVertexType(peano::applications::navierstokes::prototype1::INNER);
  }

  // create cell data
  peano::applications::navierstokes::prototype1::RegularGridFluidCellEnhancedDivFreeEulerExplicit cell;
  cell.setFluidCellType(peano::applications::navierstokes::prototype1::RegularGridFluidCellEnhancedDivFreeEulerExplicit::Records::INNER);
  cell.setRhsPPE(0.0);

  double hPow3;
  double hPow2;
  /* %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
   * First block of tests: h==1.0, tau==1.0, adjustmentFactor==1.0
   * %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
   */
  peano::applications::navierstokes::prototype1::fluidnumerics::CalculatePPERHSDlinear myCalcPPERHS(1.0, 1.0);
  h = Vector(1.0);
  hPow3 = h(0)*h(1)*h(2);
  hPow2 = h(0)*h(1);
  for(int i=0; i<n; i++){
    nodes[i].resetA();
  }
  for(int i=0; i<n; i++){
    myInvA.accumulateAValues(nodes, vertexEnumerator);
  }
  for(int i=0; i<n; i++){
    validateNumericalEquals( nodes[i].getInverseA(),  1.0 / hPow3 );
  }

  // --------------------------------------------------------------------
  //Test 1: u_i=Vector(0.0), F_i=Vector(0.0)
  for(int i=0; i<n; i++){
    nodes[i].setU(Vector(0.0));
    nodes[i].resetFValues();
  }
  myCalcPPERHS.calculateCellPPERightHandSide(nodes, vertexEnumerator, cell);
  validateNumericalEquals( cell.getRhsPPE(),  0.0 );

  // --------------------------------------------------------------------
  //Test 2: u_i=Vector(0.0), F_i=Vector(1.0)
  for(int i=0; i<n; i++){
    nodes[i].setU(Vector(0.0));
    nodes[i].setF(Vector(1.0));
  }
  myCalcPPERHS.calculateCellPPERightHandSide(nodes, vertexEnumerator, cell);
  validateNumericalEquals( cell.getRhsPPE(),  0.0 / hPow3 );

  // --------------------------------------------------------------------
  //Test 3: u_i=Vector(0.0), F_i=Vector(i);
  for(int i=0; i<n; i++){
    nodes[i].setU(Vector(0.0));
    nodes[i].setF( Vector(i) );
    assertion( tarch::la::equals(nodes[i].getF()(0),  (double)i) );
    assertion( tarch::la::equals(nodes[i].getF()(1),  (double)i) );
    assertion( tarch::la::equals(nodes[i].getF()(2),  (double)i) );
  }
  myCalcPPERHS.calculateCellPPERightHandSide(nodes, vertexEnumerator, cell);
  validateNumericalEquals( cell.getRhsPPE(),  7.0 / h(0) );

  // --------------------------------------------------------------------
  //Test 4: u_i=Vector(0.0), F_i=Dim*i;
  for(int i=0; i<n; i++){
    nodes[i].setU(Vector(0.0));
    Vector temp(0.0);
    assignList(temp) = 1*i, 2*i, 3*i;
    nodes[i].setF( temp );
  }
  myCalcPPERHS.calculateCellPPERightHandSide(nodes, vertexEnumerator, cell);
  validateNumericalEquals( cell.getRhsPPE(),  17.0 / h(0) );

  // --------------------------------------------------------------------
  //Test 5: u_i=Vector(1.0), F_i=Vector(0.0)
  for(int i=0; i<n; i++){
    nodes[i].setU(Vector(1.0));
    nodes[i].resetFValues();
  }
  myCalcPPERHS.calculateCellPPERightHandSide(nodes, vertexEnumerator, cell);
  validateNumericalEquals( cell.getRhsPPE(),  0.0 );

  // --------------------------------------------------------------------
  //Test 6: u_i=Vector(i), F_i=Vector(0.0)
  for(int i=0; i<n; i++){
    nodes[i].setU(Vector(i));
    nodes[i].resetFValues();
  }
  myCalcPPERHS.calculateCellPPERightHandSide(nodes, vertexEnumerator, cell);
  validateNumericalEquals( cell.getRhsPPE(),  -7.0 * hPow2 );

  // --------------------------------------------------------------------
  //Test 7: u_i=Vector(i), F_i=Vector(0.0)
  for(int i=0; i<n; i++){
    Vector temp(0.0);
    assignList(temp) = 1*i, 2*i, 3*i;
    nodes[i].setU(temp);
    nodes[i].resetFValues();
  }
  myCalcPPERHS.calculateCellPPERightHandSide(nodes, vertexEnumerator, cell);
  validateNumericalEquals( cell.getRhsPPE(),  -17.0 * hPow2 );

  /* %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
   * 2nd block of tests: h==0.5, tau==0.25, adjustmentFactor==1.0
   * %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
   */
  myCalcPPERHS.setNewTimeStepSizeTau(0.25);
  h = Vector(0.5);
  vertexEnumerator.setCellSize(h);
  hPow3 = h(0)*h(1)*h(2);
  hPow2 = h(0)*h(1);
  for(int i=0; i<n; i++){
    nodes[i].resetA();
  }
  for(int i=0; i<n; i++){
    myInvA.accumulateAValues(nodes, vertexEnumerator);
  }
  for(int i=0; i<n; i++){
    validateNumericalEquals( nodes[i].getInverseA(),  1.0 / hPow3 );
  }

  // --------------------------------------------------------------------
  //Test 8: u_i=Vector(0.0), F_i=Dim*i;
  for(int i=0; i<n; i++){
    nodes[i].setU(Vector(0.0));
    Vector temp(0.0);
    assignList(temp) = 1*i, 2*i, 3*i;
    nodes[i].setF( temp );
  }
  myCalcPPERHS.calculateCellPPERightHandSide(nodes, vertexEnumerator, cell);
  validateNumericalEquals( cell.getRhsPPE(),  17.0 / h(0) );

  // --------------------------------------------------------------------
  //Test 9: u_i=Vector(i), F_i=Vector(0.0)
  for(int i=0; i<n; i++){
    Vector temp(0.0);
    assignList(temp) = 1*i, 2*i, 3*i;
    nodes[i].setU(temp);
    nodes[i].resetFValues();
  }
  myCalcPPERHS.calculateCellPPERightHandSide(nodes, vertexEnumerator, cell);
  validateNumericalEquals( cell.getRhsPPE(),  -17.0 * hPow2 / 0.25 );

#endif //Dim3
}