Example #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();

}
Example #2
0
void VelocityBufferFillStencil::applyTopWall    (FlowField & flowField, int i, int j, int k){
    const int index = 3 * (i + (flowField.getNx()+3) * k);
    _topBufferOut[ index ] = flowField.getVelocity().getVector(i, flowField.getNy()+1, k)[0];
    _topBufferOut[index+1] = flowField.getVelocity().getVector(i, flowField.getNy()  , k)[1];
    _topBufferOut[index+2] = flowField.getVelocity().getVector(i, flowField.getNy()+1, k)[2];
}
Example #3
0
void VelocityBufferFillStencil::applyTopWall (FlowField & flowField, int i, int j){
    _topBufferOut[ 2*i ] = flowField.getVelocity().getVector(i, flowField.getNy()+1)[0];
    _topBufferOut[2*i+1] = flowField.getVelocity().getVector(i, flowField.getNy()  )[1];
}
Example #4
0
void VelocityBufferFillStencil::applyRightWall  (FlowField & flowField, int i, int j, int k){
    const int index = 3 * (j + (flowField.getNy()+3) * k);
    _rightBufferOut[ index ] = flowField.getVelocity().getVector(flowField.getNx(),   j, k)[0];
    _rightBufferOut[index+1] = flowField.getVelocity().getVector(flowField.getNx()+1, j, k)[1];
    _rightBufferOut[index+2] = flowField.getVelocity().getVector(flowField.getNx()+1, j, k)[2];
}
Example #5
0
void PressureBufferReadStencil::applyRightWall  (FlowField & flowField, int i, int j, int k){
    const int index = j + (flowField.getNy()+3) * k;
    flowField.getPressure().getScalar(flowField.getNx()+2, j, k) = _rightBufferIn[index];
}
Example #6
0
void PressureBufferReadStencil::applyTopWall    (FlowField & flowField, int i, int j, int k){
    const int index = i + (flowField.getNx()+3) * k;
    flowField.getPressure().getScalar(i, flowField.getNy()+2, k) = _topBufferIn[index];
}
Example #7
0
void PressureBufferFillStencil::applyTopWall    (FlowField & flowField, int i, int j, int k){
    const int index = i + (flowField.getNx()+3) * k;
    _topBufferOut[index] = flowField.getPressure().getScalar(i, flowField.getNy()+1, k);
}
Example #8
0
void PressureBufferReadStencil::applyTopWall    (FlowField & flowField, int i, int j){
    flowField.getPressure().getScalar(i, flowField.getNy()+2) = _topBufferIn[i];
}
Example #9
0
void PressureBufferFillStencil::applyTopWall    (FlowField & flowField, int i, int j){
    _topBufferOut[i] = flowField.getPressure().getScalar(i, flowField.getNy()+1);
}
Example #10
0
void PressureBufferFillStencil::applyRightWall  (FlowField & flowField, int i, int j, int k){
    const int index = j + (flowField.getNy()+3) * k;
    _rightBufferOut[index] = flowField.getPressure().getScalar(flowField.getNx()+1, j, k);
}
Example #11
0
void VelocityBufferReadStencil::applyTopWall    (FlowField & flowField, int i, int j, int k){
    const int index = 3 * (i + (flowField.getNx()+3) * k);
    flowField.getVelocity().getVector(i, flowField.getNy()+2, k)[0] = _topBufferIn[ index ];
    flowField.getVelocity().getVector(i, flowField.getNy()+2, k)[1] = _topBufferIn[index+1];
    flowField.getVelocity().getVector(i, flowField.getNy()+2, k)[2] = _topBufferIn[index+2];
}
Example #12
0
void VelocityBufferReadStencil::applyRightWall  (FlowField & flowField, int i, int j, int k){
    const int index = 3 * (j + (flowField.getNy()+3) * k);
    flowField.getVelocity().getVector(flowField.getNx()+2, j, k)[0] = _rightBufferIn[ index ];
    flowField.getVelocity().getVector(flowField.getNx()+2, j, k)[1] = _rightBufferIn[index+1];
    flowField.getVelocity().getVector(flowField.getNx()+2, j, k)[2] = _rightBufferIn[index+2];
}
Example #13
0
void VelocityBufferReadStencil::applyTopWall (FlowField & flowField, int i, int j){
    flowField.getVelocity().getVector(i, flowField.getNy()+2)[0] = _topBufferIn[ 2*i ];
    flowField.getVelocity().getVector(i, flowField.getNy()+2)[1] = _topBufferIn[2*i+1];
}
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]];

    }
}
Example #15
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();

	

}