Esempio 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();

}
Esempio n. 2
0
void PressureBufferReadStencil::applyRightWall  (FlowField & flowField, int i, int j){
    flowField.getPressure().getScalar(flowField.getNx()+2, j) = _rightBufferIn[j];
}
Esempio n. 3
0
void VelocityBufferFillStencil::applyRightWall (FlowField & flowField, int i, int j){
    _rightBufferOut[ 2*j ] = flowField.getVelocity().getVector(flowField.getNx()  , j)[0];
    _rightBufferOut[2*j+1] = flowField.getVelocity().getVector(flowField.getNx()+1, j)[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]];

    }
}
Esempio n. 5
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];
}
Esempio n. 6
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];
}
Esempio n. 7
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];
}
Esempio n. 8
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];
}
Esempio n. 9
0
void PressureBufferFillStencil::applyRightWall  (FlowField & flowField, int i, int j){
    _rightBufferOut[j] = flowField.getPressure().getScalar(flowField.getNx()+1, j);
}
Esempio n. 10
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];
}
Esempio n. 11
0
void VelocityBufferReadStencil::applyFrontWall  (FlowField & flowField, int i, int j, int k){
    const int index = 3 * (i + (flowField.getNx()+3) * j);
    flowField.getVelocity().getVector(i, j, 1)[0] = _frontBufferIn[ index ];
    flowField.getVelocity().getVector(i, j, 1)[1] = _frontBufferIn[index+1];
    flowField.getVelocity().getVector(i, j, 0)[2] = _frontBufferIn[index+2];
}
Esempio n. 12
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];
}
Esempio n. 13
0
void VelocityBufferReadStencil::applyBottomWall (FlowField & flowField, int i, int j, int k){
    const int index = 3 * (i + (flowField.getNx()+3) * k);
    flowField.getVelocity().getVector(i, 1, k)[0] = _bottomBufferIn[ index ];
    flowField.getVelocity().getVector(i, 0, k)[1] = _bottomBufferIn[index+1];
    flowField.getVelocity().getVector(i, 1, k)[2] = _bottomBufferIn[index+2];
}
Esempio n. 14
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];
}
Esempio n. 15
0
void VelocityBufferReadStencil::applyRightWall (FlowField & flowField, int i, int j){
    flowField.getVelocity().getVector(flowField.getNx()+2, j)[0] = _rightBufferIn[ 2*j ];
    flowField.getVelocity().getVector(flowField.getNx()+2, j)[1] = _rightBufferIn[2*j+1];
}
Esempio n. 16
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];
}
Esempio n. 17
0
void PressureBufferReadStencil::applyBottomWall (FlowField & flowField, int i, int j, int k){
    const int index = i + (flowField.getNx()+3) * k;
    flowField.getPressure().getScalar(i, 1, k) = _bottomBufferIn[index];
}
Esempio n. 18
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);
}
Esempio n. 19
0
void PressureBufferReadStencil::applyFrontWall  (FlowField & flowField, int i, int j, int k){
    const int index = i + (flowField.getNx()+3) * j;
    flowField.getPressure().getScalar(i, j, 1) = _frontBufferIn[index];
}
Esempio n. 20
0
void PressureBufferFillStencil::applyBottomWall (FlowField & flowField, int i, int j, int k){
    const int index = i + (flowField.getNx()+3) * k;
    _bottomBufferOut[index] = flowField.getPressure().getScalar(i, 2, k);
}
Esempio n. 21
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];
}
Esempio n. 22
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);
}
Esempio n. 23
0
void VelocityBufferFillStencil::applyFrontWall  (FlowField & flowField, int i, int j, int k){
    const int index = 3 * (i + (flowField.getNx()+3) * j);
    _frontBufferOut[ index ] = flowField.getVelocity().getVector(i, j, 2)[0];
    _frontBufferOut[index+1] = flowField.getVelocity().getVector(i, j, 2)[1];
    _frontBufferOut[index+2] = flowField.getVelocity().getVector(i, j, 2)[2];
}
Esempio n. 24
0
void PressureBufferFillStencil::applyFrontWall  (FlowField & flowField, int i, int j, int k){
    const int index = i + (flowField.getNx()+3) * j;
    _frontBufferOut[index] = flowField.getPressure().getScalar(i, j, 2);
}
Esempio n. 25
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);
}
Esempio n. 26
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();

	

}