void ViscosityBufferReadStencil::applyBottomWall(FlowField & flowField, int i, int j, int k) { if( _parameters.parallel.bottomNb >= 0){ // With normal lowoffset = 1 and highoffset = -1 if ((i >= 2) & (k >= 2)) { (flowField.getViscosity().getScalar(i, j, k)) = bottomViscosityReadBuffer[(i - 2) * localSize[2] + (k - 2)]; } } }
void ViscosityBufferReadStencil::applyBackWall(FlowField & flowField, int i, int j, int k) { if( _parameters.parallel.backNb >= 0){ // lowoffset = 1 ands highoffset = -1 if ((i >= 2) & (j >= 2)) { (flowField.getViscosity().getScalar(i, j, k + 1)) = backViscosityReadBuffer[(i - 2) * localSize[1] + (j - 2)]; } } }
void ViscosityBufferReadStencil::applyFrontWall(FlowField & flowField, int i, int j, int k) { if( _parameters.parallel.frontNb >= 0){ // Remains the same with the lowoffset = 1 and highoffset = -1 if ((i >= 2) & (j >= 2)) { (flowField.getViscosity().getScalar(i, j, k)) = frontViscosityReadBuffer[(i - 2) * localSize[1] + (j - 2)]; } } }
void ViscosityBufferReadStencil::applyRightWall(FlowField & flowField, int i, int j, int k) { if( _parameters.parallel.rightNb >= 0){ // First internal layer of the sub-domain // Iterate with lowoffset = 1, and highoffset = -1 if ((j >= 2) & (k >= 2)) { (flowField.getViscosity().getScalar(i + 1, j, k)) = rightViscosityReadBuffer[(j - 2) + (k - 2) * localSize[1]]; } } }
void ViscosityBufferReadStencil::applyLeftWall(FlowField & flowField, int i, int j, int k) { if( _parameters.parallel.leftNb >= 0){ // With lowoffset = 1 and highoffset = -1 since (i-1) array if ((j >= 2) & (k >= 2)) { (flowField.getViscosity().getScalar(i, j, k)) = leftViscosityReadBuffer[(j - 2) + (k - 2) * localSize[1]]; } } }
void MaxViscosityStencil::apply (FlowField & flowField, int i, int j, int k){ if (flowField.getViscosity().getScalar(i,j,k) > _maxViscosity){ _maxViscosity = flowField.getViscosity().getScalar(i,j,k); } }
void ViscosityBufferFillStencil::applyTopWall ( FlowField & flowField, int i, int j) { topViscosityFillBuffer[i] = flowField.getViscosity().getScalar(i,j-1); }
void ViscosityBufferFillStencil::applyRightWall ( FlowField & flowField, int i, int j) { rightViscosityFillBuffer[j] = flowField.getViscosity().getScalar(i-1,j); }
void ViscosityBufferFillStencil::applyBottomWall ( FlowField & flowField, int i, int j) { bottomViscosityFillBuffer[i] = flowField.getViscosity().getScalar(i,j+2); }
void ViscosityBufferFillStencil::applyBackWall ( FlowField & flowField, int i, int j, int k) { /* _lowOffset = 2; _highOffset = -1; * from ParallelBoundaryIterater: i = _lowOffset ; j = _lowOffset ; k = Iterator<FlowField>::_flowField.getCellsZ()+_highOffset-1 ; */ backViscosityFillBuffer[(j)+(localSize[1]+3)*(i)] = flowField.getViscosity().getScalar(i,j,k-1); }
/*2D */ void ViscosityBufferFillStencil::applyLeftWall ( FlowField & flowField, int i, int j) { leftViscosityFillBuffer[j] = flowField.getViscosity().getScalar(i+2,j); }
void ViscosityBufferFillStencil::applyFrontWall ( FlowField & flowField, int i, int j, int k) { /* _lowOffset = 2; _highOffset = -1; * from ParallelBoundaryIterater: i = _lowOffset ; j = _lowOffset ; k = _lowOffset; */ frontViscosityFillBuffer[(j)+(localSize[1]+3)*(i)] = flowField.getViscosity().getScalar(i,j,k+2); }
void ViscosityBufferFillStencil::applyTopWall ( FlowField & flowField, int i, int j, int k) { /* _lowOffset = 2; _highOffset = -1; * from ParallelBoundaryIterater: i = _lowOffset ; j = Iterator<FlowField>::_flowField.getCellsY()+_highOffset-1 ; k = _lowOffset; */ topViscosityFillBuffer[(k)+(localSize[2]+3)*(i)] = flowField.getViscosity().getScalar(i,j-1,k); }
void ViscosityBufferFillStencil::applyBottomWall ( FlowField & flowField, int i, int j, int k) { /* _lowOffset = 2; _highOffset = -1; * from ParallelBoundaryIterater: i = _lowOffset ; j = _lowOffset ; k = _lowOffset; */ bottomViscosityFillBuffer[(k)+(localSize[2]+3)*(i)] = flowField.getViscosity().getScalar(i,j+2,k); }
void ViscosityBufferFillStencil::applyRightWall ( FlowField & flowField, int i, int j, int k) { /* _lowOffset = 2; _highOffset = -1; * from ParallelBoundaryIterater: i = _flowField.getCellsX()+_highOffset-1 ; j = _lowOffset ; k = _lowOffset; */ rightViscosityFillBuffer[(k)+(localSize[2]+3)*(j)] = flowField.getViscosity().getScalar(i-1,j,k); }
int main (int argc, char *argv[]) { // Parallelization related. Initialize and identify // --------------------------------------------------- int rank; // This processor's identifier int nproc; // Number of processors in the group PetscInitialize(&argc, &argv, "petsc_commandline_arg", PETSC_NULL); MPI_Comm_size(PETSC_COMM_WORLD, &nproc); MPI_Comm_rank(PETSC_COMM_WORLD, &rank); std::cout << "Rank: " << rank << ", Nproc: " << nproc << std::endl; //---------------------------------------------------- // read configuration and store information in parameters object Configuration configuration(argv[1]); Parameters parameters; configuration.loadParameters(parameters); PetscParallelConfiguration parallelConfiguration(parameters); MeshsizeFactory::getInstance().initMeshsize(parameters); FlowField *flowField = NULL; Simulation *simulation = NULL; #ifdef DEBUG std::cout << "Processor " << parameters.parallel.rank << " with index "; std::cout << parameters.parallel.indices[0] << ","; std::cout << parameters.parallel.indices[1] << ","; std::cout << parameters.parallel.indices[2]; std::cout << " is computing the size of its subdomain and obtains "; std::cout << parameters.parallel.localSize[0] << ", "; std::cout << parameters.parallel.localSize[1] << " and "; std::cout << parameters.parallel.localSize[2]; std::cout << ". Left neighbour: " << parameters.parallel.leftNb; std::cout << ", right neighbour: " << parameters.parallel.rightNb; std::cout << std::endl; std::cout << "Min. meshsizes: " << parameters.meshsize->getDxMin() << ", " << parameters.meshsize->getDyMin() << ", " << parameters.meshsize->getDzMin() << std::endl; #endif // initialise simulation if (parameters.simulation.type=="turbulence"){ // TODO WS2: initialise turbulent flow field and turbulent simulation object if(rank==0){ std::cout << "Start DNS turbulence simulation in " << parameters.geometry.dim << "D" << std::endl; } flowField = new FlowField(parameters); if(flowField == NULL){ handleError(1, "flowField==NULL!"); } simulation = new Simulation(parameters,*flowField); handleError(1,"Turbulence currently not supported yet!"); } else if (parameters.simulation.type=="dns"){ if(rank==0){ std::cout << "Start DNS simulation in " << parameters.geometry.dim << "D" << std::endl; } flowField = new FlowField(parameters); if(flowField == NULL){ handleError(1, "flowField==NULL!"); } simulation = new Simulation(parameters,*flowField); } else { handleError(1, "Unknown simulation type! Currently supported: dns, turbulence"); } // call initialization of simulation (initialize flow field) if(simulation == NULL){ handleError(1, "simulation==NULL!"); } simulation->initializeFlowField(); // flowField->getFlags().show(); // flowField->getNearWallDis().show(); // std::cout<<flowField->getNx()<<std::endl; // std::cout<<parameters.geometry.lengthX<<std::endl; // return 0; FLOAT time = 0.0; FLOAT timeStdOut=parameters.stdOut.interval; FLOAT VTKtime=0.0; int timeSteps = 0; // TODO WS1: plot initial state simulation->plotVTK(timeSteps); // time loop while (time < parameters.simulation.finalTime){ simulation->solveTimestep(); time += parameters.timestep.dt; // std-out: terminal info if ( (rank==0) && (timeStdOut <= time) ){ std::cout << "Current time: " << time << "\ttimestep: " << parameters.timestep.dt << std::endl; timeStdOut += parameters.stdOut.interval; } timeSteps++; // TODO WS1: trigger VTK output if(VTKtime <= time){ simulation->plotVTK(timeSteps); VTKtime += parameters.vtk.interval; } } // TODO WS1: plot final output simulation->plotVTK(timeSteps); flowField->getViscosity().show(); delete simulation; simulation=NULL; delete flowField; flowField= NULL; PetscFinalize(); }