Пример #1
0
int main()
{
    TestSorting test;
    QTest::qExec(&test);
    int mas1[5][5] = {{0, 1, 2, 3, 4},
                      {10,11,12,13,14},
                      {20,21,22,23,24},
                      {30,31,32,33,34},
                      {40,41,42,43,44}
                     };
    Display *mas;
    int p;

    cout << " ƒл¤ вывода на консоль нажмите 1, дл¤ вывода в файл нажмите любую другую";
    cin >> p;
    if (p == 1)
    {
        mas = new DisplayMas();
        mas->createMas(&mas1[0][0], 5);
        mas->display();
    }
    else {
        mas = new DisplayInFile();
        mas->createMas(&mas1[0][0], 5);
        mas->display();
    }
    delete mas;
    return 0;
}
Пример #2
0
int main(int argc, char **argv)
{
  Overture::start( argc, argv);
  aString nameOfOGFile="Grids/test2d-cell4.hdf";
  if( argc >1 ) {
    nameOfOGFile = argv[1];
  }
  std::cout << argv[0] << " using grid=" 
	    << nameOfOGFile << "..." << std::endl;

  Display disp; //David's display

  CompositeGrid cg;
  getFromADataBase( cg, nameOfOGFile );
  cg.update( MappedGrid::THEvertex | MappedGrid::THEcenter 
            | MappedGrid::THEvertexBoundaryNormal);

  for( int ig=0; ig< cg.numberOfComponentGrids() ; ++ig ) {
    MappedGrid &mg = cg[ig];
    for( int side=0; side<2; ++side ) {
      for( int axis=0; axis<cg.numberOfDimensions(); ++axis) {
	realArray & normal = mg.vertexBoundaryNormal(side,axis);
	printf("--grid %d, side %d, axis %d, bc %d--\n", 
	       ig, side, axis, mg.boundaryCondition()(side,axis));
	disp.display( normal );
      }
    }
  }

  Overture::finish();
}
Пример #3
0
  static void testDisplay() {
    Display d;
    std::ofstream correct;
    correct.open ("correct.txt");
		
    vector<string*> out;
		
    string* temp;
		
    for (int i = 0; i < 40; ++i) {
      temp = new string(" ");
      out.push_back(temp);
    }
		
    temp = new string("                                      .++~");
    out.push_back(temp);
    temp = new string("                                   MMMMMMMMM.");
    out.push_back(temp);
    temp = new string("              8=          .  DMMM .MMMM DMMMM");
    out.push_back(temp);
    temp = new string("            MMMM   DM    MMM  MMM  MMMM  MMM+");
    out.push_back(temp);
    temp = new string("          MMMMMM  MMMD  MMMM. MMM8 MMMM  MMM.");
    out.push_back(temp);
    temp = new string("         MMMM.    MMMM MMMM.  MMMM MMMMMMMM  MMMM ");
    out.push_back(temp);
    temp = new string("        MMMMM$.   MMMM+MMM    MMMM  MMMMM.   MM+");
    out.push_back(temp);
    temp = new string("        MMMMMMMMM.MMMMMMMM.   MMMM  MMM.");
    out.push_back(temp);
    temp = new string("         MMMMMMMMMMMMM MMMMM  MMMM  MMMI");
    out.push_back(temp);
    temp = new string("          ..MMMMMM,MMM. MMMMMM:MMM. MMM.");
    out.push_back(temp);
    temp = new string("             MMMMM MMMO  MMMI .MM=");
    out.push_back(temp);
    temp = new string("          ..MMMMM  MMMM    .");
    out.push_back(temp);
    temp = new string("         .MMMMM    MM,.         :MMD.");
    out.push_back(temp);
    temp = new string("          MMM.                MMMMMMMM         .");
    out.push_back(temp);
    temp = new string("          ..  $MMMMMMMMMM    MMMMMMMMMM       .ZZZZZZZ");
    out.push_back(temp);
    temp = new string("               MMMMNMMMMMM. MMMM8..MMMMM      ZZZZZZZ,");
    out.push_back(temp);
    temp = new string("       ...     MMMM. .MMMM +MMM     MMMM      ZZZZZZZ I.");
    out.push_back(temp);
    temp = new string("   ~MMMMMM     MMMM? MMMM. MMMM     7MMM      ZZZZZZ7IIII.");
    out.push_back(temp);
    temp = new string("   MMMMMMM     MMMMMMMMMMM.DMMM     MMMM   MMMZZZZZIIIIIIII.");
    out.push_back(temp);
    temp = new string("   MMMMMMM     MMMMMMMMMMMM:MMMM.  MMMM.   MMMZZZZIIIIIIIII");
    out.push_back(temp);
    temp = new string("   ,MMMMMMM     MMMM.  MMMM$:MMMMMMMMM,    .MMZZZIIIIIIIII ");
    out.push_back(temp);
    temp = new string("    MMMMMMM     MMMM.  MMMM.  MMMMMMM        MMMIIIIIIIII");
    out.push_back(temp);
    temp = new string("    MMMMMMMM    MMMM$MMMMM      ..           .MMMIIIIII ");
    out.push_back(temp);
    temp = new string("     MMMMMMM    MMMMMMMM                      =MMMMIII.");
    out.push_back(temp);
    temp = new string("     ....       +MMM7.                         NMM. ..");
    out.push_back(temp);
		
    for (int i = 0; i < 2; ++i) {
      temp = new string(" ");
      out.push_back(temp);
    }
		
    temp = new string("=======Build Piles======");
    out.push_back(temp);
		
    ////////////////////////////////////
    temp = new string(" -1-   -2-   -3-   -4-");
    out.push_back(temp);
		
    ////////////////////////////////////
    temp = new string("┌───┐ ┌───┐ ┌───┐ ┌───┐");
    out.push_back(temp);
		
    ////////////////////////////////////
    temp = new string("│ 11│ │ 5 │ │   │ │ 1 │");
    out.push_back(temp);
		
    ////////////////////////////////////
    temp = new string("└───┘ └───┘ └───┘ └───┘");
    out.push_back(temp);
		
    ////////////////////////////////////
    temp = new string("=======================");
    out.push_back(temp);
		
    ////////////////////////////////////
    temp = new string("Player ");
    *temp += d.convert(2);
    *temp += ": ";
    *temp += "test";
    *temp += "'s Turn	";
    out.push_back(temp);
		
    ////////////////////////////////////
    temp = new string("=======================");
    out.push_back(temp);
		
    ////////////////////////////////////
    temp = new string("Hand:");
    out.push_back(temp);
		
    ////////////////////////////////////
    temp = new string(" -1-   -2-   -3-   -4-   -5-");
    out.push_back(temp);
		
    ////////////////////////////////////
    temp = new string("┌───┐ ┌───┐ ┌───┐ ┌───┐ ┌───┐");
    out.push_back(temp);
		
    ////////////////////////////////////
    temp = new string("│ 1 │ │ 2 │ │ 3 │ │ 4 │ │ 10│");
    out.push_back(temp);
		
    ////////////////////////////////////
    temp = new string("└───┘ └───┘ └───┘ └───┘ └───┘");
    out.push_back(temp);
		
    ////////////////////////////////////
    temp = new string("Discard:");
    out.push_back(temp);
		
    ////////////////////////////////////
    temp = new string(" -1-   -2-   -3-   -4-");
    out.push_back(temp);
		
    ////////////////////////////////////
    temp = new string("┌───┐ ┌───┐ ┌───┐ ┌───┐");
    out.push_back(temp);
		
    ////////////////////////////////////
    temp = new string("│   │ │   │ │   │ │   │");
    out.push_back(temp);
		
    ////////////////////////////////////
    temp = new string("└───┘ └───┘ └───┘ └───┘");
    out.push_back(temp);
		
    ////////////////////////////////////
    temp = new string("Stockpile:");
    out.push_back(temp);
		
    ////////////////////////////////////
    temp = new string("┌───┐");
    out.push_back(temp);
		
    ////////////////////////////////////
    temp = new string("│ 1 │");
    *temp += " 1 cards left";
    out.push_back(temp);
		
    ////////////////////////////////////
    temp = new string("└───┘");
    out.push_back(temp);
		
    ////////////////////////////////////
    temp = new string("└Your Move: ");
    out.push_back(temp);
		
				
    for (unsigned long i = 0; i < out.size(); ++i) {
      if (i == out.size()) {
	correct << *(out.at(i));
      }
      else {
	correct << *(out.at(i)) << endl;
      }
    }
		
    for (int i = 0; i < (int) out.size(); ++i) {
      delete out.at(i);
    }
		
    correct.close();
	  
    std::ofstream output("test.txt");
    std::streambuf *coutbuf = std::cout.rdbuf();
    cout.rdbuf(output.rdbuf());
		
    vector<Build*> build;
    Build* buildtemp = new Build();
    build.push_back(buildtemp);
    buildtemp = new Build();
    build.push_back(buildtemp);
    buildtemp = new Build();
    build.push_back(buildtemp);
    buildtemp = new Build();
    build.push_back(buildtemp);
    buildtemp = new Build();
    build.push_back(buildtemp);
    for (int i = 1; i < 12; ++i) *(build.at(0)) += i;
    for (int i = 1; i < 6; ++i) *(build.at(1)) += i;
    for (int i = 1; i < 2; ++i) *(build.at(3)) += i;
    Stock* stock = new Stock();
    Draw* draw = new Draw();
    Player* player = new HumanPlayer("test", draw, &build, *stock);
    player->drawCards();
    player->hand.cards[0] = 1;
    player->hand.cards[1] = 2;
    player->hand.cards[2] = 3;
    player->hand.cards[3] = 4;
    player->hand.cards[4] = 10;
    player->stock.cards.push_back(1);
		
    Game game;
		
    d.display(player, build, 1, &game);
    char test[9] = {"test.txt"};
    char corr[12] = {"correct.txt"};
    assert(fileeq(test, corr));
    cout.rdbuf(coutbuf);
		
    for (int i = 0; i < (int) build.size(); ++i) delete build.at(i);
    delete stock;
    delete draw;
    delete player;
  }
Пример #4
0
void  FluxBC::
applyBoundaryCondition( realCompositeGridFunction &q,
			int ic) 
{
  assert( pCg     != NULL ); CompositeGrid &cg          = *pCg;
  assert( pInterp != NULL ); Interpolant   &interp      = *pInterp;
  assert( pOp     != NULL ); CompositeGridOperators &op = *pOp;

  Display display; //David's display class

  realArray &qTemp = q[0];
  const int nComponents         = qTemp.getLength(3); // indices ( 0, 1, 2, --3-- ), 3=component
  const int nInterpComponents   =valuesInterpolate.getLength(1);
  assert( nComponents <= nInterpComponents );
  if(debug&4)printf("***FluxBC::applyBC: nComponents %d, nInterpComponents %d, fluxCoeff %g\n",
		    nComponents, nInterpComponents,  getFluxCoefficient());

  //printf("FluxBC::applyBoundaryCondition called...\n");

  timerInterpCode = getCPU();
  interpolator.interpolatePoints(q,valuesInterpolate);

  if(debug&8) {
    printf("-------------------DISPLAY: valuesInterpolate in FluxBC::applyBoundaryCondition %d  -------\n",
	   ic);
    display.display(valuesInterpolate,"valuesInterpolate");
  }

  for ( int ig=0; ig< cg.numberOfComponentGrids(); ++ig ) {
    MappedGrid & mg = cg[ig];
    MappedGridOperators    &opmg = op[ig];
    realMappedGridFunction &q_mg = q[ig];
    Index Ib1,Ib2,Ib3;
    Index Ig1,Ig2,Ig3;

    Index I1,I2,I3;
    getIndex( mg.dimension(), I1,I2,I3);
    
    //..flux/jump bc
    const int nAxes=cg.numberOfDimensions();
    int axis, side;
    for( axis=0; axis<mg.numberOfDimensions(); axis++ ) {
      for( side=0; side<=1; side++ ) {
	
	if( mg.boundaryCondition()(side,axis) == idFluxBoundary  ) {

	  //printf("FluxBC: grid, side, axis(%i,%i,%i) is a flux boundary (bc=%i)\n",
	  //        ig,side,axis,idFluxBoundary);
	  getBoundaryIndex(mg.gridIndexRange(),side,axis,Ib1,Ib2,Ib3);
	  getGhostIndex(mg.gridIndexRange(),side,axis,Ig1,Ig2,Ig3);
	  realArray       &qArray     = q[ig];

	  int nInterpPoints= edgeEnd(ig,axis,side) - edgeStart(ig,axis,side)+1;
	  Range dims(0,nAxes-1);
	  //Range subset(edgeStart(ig,axis,side,edgeEnd(ig, axis,side)));
	  Range subset(edgeStart(ig,axis,side),edgeEnd(ig, axis,side));

	  realArray jump(nInterpPoints);
	  jump.reshape(subset);

	  jump(subset) = valuesInterpolate(subset,ic);
	  jump.reshape(Ib1,Ib2,Ib3, Range(ic,ic));

	  if(debug&8) {
	    printf("..grid %d, side %d, axis %d, component %d, flux coeff %g-- JUMP\n", 
		   ig, side, axis, ic, getFluxCoefficient() );
	    display.display(jump,"jump: values for other grids");
	  }
	  jump = getFluxCoefficient()*( jump - qArray(Ib1,Ib2,Ib3,ic));

	  //if(debug&8  || (ic==1)) {
	  if(debug&8) {
	    printf("....Flux*[ jump ]\n");
	    display.display( jump, "flux coeff*[ other - this value]" );
	  }

	  //.. ibc chosen to set a specified boundary (side,axis)
	  // ... take jumps from unext --> impose as flux in u
	  const int ibc=BCTypes::boundary1+side+2*axis;
	  opmg.applyBoundaryCondition( q_mg, Range(ic,ic), BCTypes::neumann, ibc, jump ); 

	  if(debug&8)  display.display(jump,   "jump");
	  if(debug&16) display.display(qArray(I1,I2,I3,ic), "q function");

	} // end if ibc==fluxBoundaryID


      } 
    }
  }
  timerInterpCode = getCPU()-timerInterpCode;

}