Exemplo n.º 1
0
int main () {
    std::cout << "Starting VTK test" << std::endl;
    FlowField flowField ( 10, 10, 10 );

    clock_t start = clock();

    FLOAT velocity [3] = {1,1,1};

    for (int k = 0; k < flowField.getNz() + 3; k++ ){
        for (int j = 0; j < flowField.getNy() + 3; j++ ){
            for (int i = 0; i < flowField.getNx() + 3; i++ ){
                flowField.getPressure().getScalar(i,j,k) = (double) k;
                flowField.getVelocity().setVector(velocity, i,j,k);
            }
        }
    }

    std::cout << "Initialization time: " << (double) (clock() - start) / CLOCKS_PER_SEC
        << std::endl;
    start = clock();

    Parameters parameters;

    parameters.dx = 1;
    parameters.dy = 1;
    parameters.dz = 1;

    VTKStencil stencil( "/tmp/some_file", parameters );

    std::cout << "Stencil creation time: " << (double) (clock() - start) / CLOCKS_PER_SEC << std::endl;
    start = clock();

    stencil.openFile ( flowField, 5.0/3 );

    std::cout << "File-openning and grid data writing time: " << (double) (clock() - start) / CLOCKS_PER_SEC << std::endl;
    start = clock();

    FieldIterator iterator( flowField, stencil );
    iterator.iterateInnerCells();

    std::cout << "Iteration time: " << (double) (clock() - start) / CLOCKS_PER_SEC << std::endl;
    start = clock();

    stencil.write( flowField );
    std::cout << "Writing time: " << (double) (clock() - start) / CLOCKS_PER_SEC << std::endl;

    stencil.closeFile();

}
Exemplo n.º 2
0
void VelocityBufferFillStencil::applyBackWall   (FlowField & flowField, int i, int j, int k){
    const int index = 3 * (i + (flowField.getNx()+3) * j);
    _backBufferOut[ index ] = flowField.getVelocity().getVector(i, j, flowField.getNz()+1)[0];
    _backBufferOut[index+1] = flowField.getVelocity().getVector(i, j, flowField.getNz()+1)[1];
    _backBufferOut[index+2] = flowField.getVelocity().getVector(i, j, flowField.getNz()  )[2];
}
Exemplo n.º 3
0
void PressureBufferReadStencil::applyBackWall   (FlowField & flowField, int i, int j, int k){
    const int index = i + (flowField.getNx()+3) * j;
    flowField.getPressure().getScalar(i, j, flowField.getNz()+2) = _backBufferIn[index];
}
Exemplo n.º 4
0
void PressureBufferFillStencil::applyBackWall   (FlowField & flowField, int i, int j, int k){
    const int index = i + (flowField.getNx()+3) * j;
    _backBufferOut[index] = flowField.getPressure().getScalar(i, j, flowField.getNz()+1);
}
Exemplo n.º 5
0
void VelocityBufferReadStencil::applyBackWall   (FlowField & flowField, int i, int j, int k){
    const int index = 3 * (i + (flowField.getNx()+3) * j);
    flowField.getVelocity().getVector(i, j, flowField.getNz()+2)[0] = _backBufferIn[ index ];
    flowField.getVelocity().getVector(i, j, flowField.getNz()+2)[1] = _backBufferIn[index+1];
    flowField.getVelocity().getVector(i, j, flowField.getNz()+2)[2] = _backBufferIn[index+2];
}
PetscParallelManager::PetscParallelManager(FlowField & flowField, const Parameters & parameters):

    ParallelManager<FlowField> (flowField, parameters),

    _fillVelocityStencil(parameters, _leftBufferOut, _rightBufferOut, _bottomBufferOut,
                                     _topBufferOut, _frontBufferOut, _backBufferOut),
    _readVelocityStencil(parameters, _leftBufferIn, _rightBufferIn, _bottomBufferIn,
                                     _topBufferIn, _frontBufferIn, _backBufferIn),
    _fillPressureStencil(parameters, _leftBufferOut, _rightBufferOut, _bottomBufferOut,
                                     _topBufferOut, _frontBufferOut, _backBufferOut),
    _readPressureStencil(parameters, _leftBufferIn, _rightBufferIn, _bottomBufferIn,
                                     _topBufferIn, _frontBufferIn, _backBufferIn),

    _fillVelocityIterator(_flowField, parameters, _fillVelocityStencil, 1, 0),
    _readVelocityIterator(_flowField, parameters, _readVelocityStencil, 1, 0),
    _fillPressureIterator(_flowField, parameters, _fillPressureStencil, 1, 0),
    _readPressureIterator(_flowField, parameters, _readPressureStencil, 1, 0)

{

    // Allocate buffers and set number of pressure values
    if (flowField.getDim() == 2){
        _bufferSize[0] = 2 * (flowField.getNy() + 3); // Allocate space for all values
        _bufferSize[1] = 2 * (flowField.getNx() + 3);

        _pressureSize[0] = (flowField.getNy() + 3);
        _pressureSize[1] = (flowField.getNx() + 3);

        _leftBufferIn  = new FLOAT[_bufferSize[0]];
        _leftBufferOut = new FLOAT[_bufferSize[0]];

        _rightBufferIn  = new FLOAT[_bufferSize[0]];
        _rightBufferOut = new FLOAT[_bufferSize[0]];

        _bottomBufferIn  = new FLOAT[_bufferSize[1]];
        _bottomBufferOut = new FLOAT[_bufferSize[1]];

        _topBufferIn  = new FLOAT[_bufferSize[1]];
        _topBufferOut = new FLOAT[_bufferSize[1]];

    } else if (flowField.getDim() == 3) {

        _bufferSize[0] = 3 * ((flowField.getNy()+3) * (flowField.getNz()+3));
        _bufferSize[1] = 3 * ((flowField.getNx()+3) * (flowField.getNz()+3));
        _bufferSize[2] = 3 * ((flowField.getNx()+3) * (flowField.getNy()+3));

        _pressureSize[0] = (flowField.getNy()+3) * (flowField.getNz()+3);
        _pressureSize[1] = (flowField.getNx()+3) * (flowField.getNz()+3);
        _pressureSize[2] = (flowField.getNx()+3) * (flowField.getNy()+3);

        _leftBufferIn  = new FLOAT[_bufferSize[0]];
        _leftBufferOut = new FLOAT[_bufferSize[0]];

        _rightBufferIn  = new FLOAT[_bufferSize[0]];
        _rightBufferOut = new FLOAT[_bufferSize[0]];

        _bottomBufferIn  = new FLOAT[_bufferSize[1]];
        _bottomBufferOut = new FLOAT[_bufferSize[1]];

        _topBufferIn  = new FLOAT[_bufferSize[1]];
        _topBufferOut = new FLOAT[_bufferSize[1]];

        _frontBufferIn  = new FLOAT[_bufferSize[2]];
        _frontBufferOut = new FLOAT[_bufferSize[2]];

        _backBufferIn  = new FLOAT[_bufferSize[2]];
        _backBufferOut = new FLOAT[_bufferSize[2]];

    }
}
Exemplo n.º 7
0
void VTKStencil:: write ( FlowField & flowField, int timeStep ){

	FieldIterator<FlowField> _it(flowField,_parameters,*this);
	int i,j,k;
	int Nx=flowField.getNx();
	int Ny=flowField.getNy();
	int Nz;
	int dim=_parameters.geometry.dim; 
	if(dim == 2){Nz=0;}else{Nz=flowField.getNz();}

	int cellx=flowField.getCellsX();
	int celly=flowField.getCellsY();
	int cellz;
	if(dim == 2){cellz=3;}else{cellz=flowField.getCellsZ();}



	//generate the file name
	std::stringstream filename;
	filename << this->_parameters.vtk.prefix << "_" << timeStep << ".vtk";
	std::cout << filename.str() << std::endl;


	// Open the file
	std::ofstream vtkFile;
	vtkFile.open(filename.str().c_str());
	vtkFile << std::fixed << std::setprecision(6);
	(this->_outputFile) = &vtkFile;

	// Print file header
	vtkFile << "# vtk DataFile Version 2.0" << std::endl;
	vtkFile << "WS_1" <<  std::endl;
	vtkFile << "ASCII" << "\n" << std::endl;
	vtkFile << "DATASET STRUCTURED_GRID" << std::endl;
	vtkFile << "DIMENSIONS " << Nx+1 << " " << Ny+1 << " " << Nz+1  << std::endl;
	vtkFile << "POINTS " << (Nx+1)*(Ny+1)*(Nz+1) << " float" << std::endl;

	// Print grids
	for (k=2; k<cellz; k++){
		for (j=2; j<celly; j++ ){
			for(i=2; i<cellx; i++){
				vtkFile << (_parameters.meshsize)->getPosX(i,j,k) << " " \
					<< (_parameters.meshsize)->getPosY(i,j,k) << " " \
					<< (_parameters.meshsize)->getPosZ(i,j,k) << std::endl;	
			}
		}
	}
	// Output pressure field
	vtkFile <<std::endl;
	if(dim==2){
		vtkFile << "CELL_DATA " << (cellx-3)*(celly-3)*(cellz-2) << std::endl;}
	else{
		vtkFile << "CELL_DATA " << (cellx-3)*(celly-3)*(cellz-3) << std::endl;}
	vtkFile << "SCALARS pressure float 1" << std::endl;
	vtkFile << "LOOKUP_TABLE default" << std::endl;	
	output_flag=0;	
	_it.iterate();


	// Output velocity field
	vtkFile << std::endl;
	vtkFile << "VECTORS velocity float" << std::endl;
	output_flag=1;	
	_it.iterate();

	

}