예제 #1
0
void VelocityStencil::apply ( FlowField & flowField, int i, int j ){

    const FLOAT dt = _parameters.timestep.dt;
    const int obstacle = flowField.getFlags().getValue(i, j);
    VectorField & velocity = flowField.getVelocity();

    if ((obstacle & OBSTACLE_SELF) == 0){ // If this is a fluid cell
        if ((obstacle & OBSTACLE_RIGHT) == 0){  // Check whether the neighbor is also fluid
            // we require a spatial finite difference expression for the pressure gradient, evaluated
            // at the location of the u-component. We therefore compute the distance of neighbouring
            // pressure values (dx) and use this as sort-of central difference expression. This will
            // yield second-order accuracy for uniform meshsizes.
            const FLOAT dx = 0.5*(_parameters.meshsize->getDx(i,j)+_parameters.meshsize->getDx(i+1,j));
            velocity.getVector(i,j)[0] = flowField.getFGH().getVector(i,j)[0] - dt/dx *
                (flowField.getPressure().getScalar(i+1,j) - flowField.getPressure().getScalar(i,j));

        } else {    // Otherwise, set to zero
            velocity.getVector(i,j)[0] = 0;
        }   // Note that we only set one direction per cell. The neighbor at the left is
            // responsible for the other side
        if ((obstacle & OBSTACLE_TOP) == 0){
            const FLOAT dy = 0.5*(_parameters.meshsize->getDy(i,j)+_parameters.meshsize->getDy(i,j+1));
            velocity.getVector(i,j)[1] = flowField.getFGH().getVector(i,j)[1] - dt/dy *
                (flowField.getPressure().getScalar(i,j+1) - flowField.getPressure().getScalar(i,j));

        } else {
            velocity.getVector(i,j)[1] = 0;
        }
    } 
}
예제 #2
0
void PressureBufferFillStencil::applyRightWall ( FlowField & flowField, int i, int j, int k) {
  /* _lowOffset = 2; _highOffset = -1;
   * from ParallelBoundaryIterater:  i = _flowField.getCellsX()+_highOffset-1 ; j = _lowOffset ; k = _lowOffset;
   */
  rightPressureFillBuffer[0+2*((k)+((localSize[2]+3)*(j)))] = flowField.getPressure().getScalar(i-2,j,k);
  rightPressureFillBuffer[1+2*((k)+((localSize[2]+3)*(j)))] = flowField.getPressure().getScalar(i-1,j,k);
}
예제 #3
0
void PressureBufferFillStencil::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;
   */ 
  topPressureFillBuffer[0+2*((k)+((localSize[2]+3)*(i)))] = flowField.getPressure().getScalar(i,j-2,k);
  topPressureFillBuffer[1+2*((k)+((localSize[2]+3)*(i)))] = flowField.getPressure().getScalar(i,j-1,k);
}
예제 #4
0
void PressureBufferFillStencil::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 ;
   */   
  backPressureFillBuffer[0+2*((j)+((localSize[1]+3)*(i)))] = flowField.getPressure().getScalar(i,j,k-2);
  backPressureFillBuffer[1+2*((j)+((localSize[1]+3)*(i)))] = flowField.getPressure().getScalar(i,j,k-1);
}
예제 #5
0
void VelocityStencil::apply ( FlowField & flowField, int i, int j, int k ){

    const FLOAT dt = _parameters.timestep.dt;
    const int obstacle = flowField.getFlags().getValue(i, j, k);
    VectorField & velocity = flowField.getVelocity();

    if ((obstacle & OBSTACLE_SELF) == 0) {
        if ((obstacle & OBSTACLE_RIGHT) == 0) {
            const FLOAT dx = 0.5*(_parameters.meshsize->getDx(i,j,k)+_parameters.meshsize->getDx(i+1,j,k));
            velocity.getVector(i,j,k)[0] = flowField.getFGH().getVector(i,j,k)[0] - dt/dx *
                (flowField.getPressure().getScalar(i+1,j,k) - flowField.getPressure().getScalar(i,j,k));
        } else {
            velocity.getVector(i, j, k)[0] = 0.0;
        }
        if ((obstacle & OBSTACLE_TOP) == 0) {
            const FLOAT dy = 0.5*(_parameters.meshsize->getDy(i,j,k)+_parameters.meshsize->getDy(i,j+1,k));
            velocity.getVector(i,j,k)[1] = flowField.getFGH().getVector(i,j,k)[1] - dt/dy *
                (flowField.getPressure().getScalar(i,j+1,k) - flowField.getPressure().getScalar(i,j,k));
        } else {
            velocity.getVector(i, j, k)[1] = 0.0;
        }
        if ((obstacle & OBSTACLE_BACK) == 0) {
            const FLOAT dz = 0.5*(_parameters.meshsize->getDz(i,j,k)+_parameters.meshsize->getDz(i,j,k+1));
            velocity.getVector(i,j,k)[2] = flowField.getFGH().getVector(i,j,k)[2] - dt/dz *
                (flowField.getPressure().getScalar(i,j,k+1) - flowField.getPressure().getScalar(i,j,k));
        } else {
            velocity.getVector(i, j, k)[2] = 0.0;
        }
    }
}
예제 #6
0
파일: vtk_test.cpp 프로젝트: EvaBr/CFD-Lab
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();

}
예제 #7
0
void CheckpointReadStencil::apply ( FlowField & flowField, int i, int j ){


	FLOAT pressure_tmp;
	FLOAT velocity_tmp[3];

	FLOAT & pressure = flowField.getPressure().getScalar(i,j);
	FLOAT * velocity = flowField.getVelocity().getVector(i,j);

	fread(velocity_tmp, sizeof(FLOAT), 3, inputFile);
	fread(&pressure_tmp, sizeof(FLOAT), 1, inputFile);

	pressure = pressure_tmp;
	velocity[0] = velocity_tmp[0];
	velocity[1] = velocity_tmp[1];
	velocity[2] = velocity_tmp[2];

}
예제 #8
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);
}
예제 #9
0
void PressureBufferFillStencil::applyBottomWall ( FlowField & flowField, int i, int j, int k) {
  /* _lowOffset = 2; _highOffset = -1;
   * from ParallelBoundaryIterater:  i = _lowOffset ; j = _lowOffset ; k = _lowOffset;
   */
  bottomPressureFillBuffer[(k)+((localSize[2]+3)*(i))] = flowField.getPressure().getScalar(i,j+2,k);
}
예제 #10
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);
}
예제 #11
0
void PressureBufferFillStencil::applyLeftWall ( FlowField & flowField, int i, int j, int k) {
  /* _lowOffset = 0; _highOffset = 0;
   * from ParallelBoundaryIterater:  i = _lowOffset ; j = _lowOffset ; k = _lowOffset; 
   */
	leftPressureFillBuffer[(k)+((localSize[2]+3)*(j))] = flowField.getPressure().getScalar(i+2,j,k);
}
예제 #12
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);
}
예제 #13
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);
}
예제 #14
0
void PressureBufferReadStencil::applyLeftWall   (FlowField & flowField, int i, int j){
    flowField.getPressure().getScalar(1, j) = _leftBufferIn[j];
}
예제 #15
0
void PressureBufferFillStencil::applyBottomWall ( FlowField & flowField, int i, int j) {
	bottomPressureFillBuffer[i] = flowField.getPressure().getScalar(i,j+2);
}
예제 #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];
}
예제 #17
0
/*2D
 */
void PressureBufferFillStencil::applyLeftWall ( FlowField & flowField, int i, int j) {
	leftPressureFillBuffer[j] = flowField.getPressure().getScalar(i+2,j);
}
예제 #18
0
void PressureBufferReadStencil::applyTopWall    (FlowField & flowField, int i, int j){
    flowField.getPressure().getScalar(i, flowField.getNy()+2) = _topBufferIn[i];
}
예제 #19
0
void PressureBufferReadStencil::applyBottomWall (FlowField & flowField, int i, int j){
    flowField.getPressure().getScalar(i, 1) = _bottomBufferIn[i];
}
예제 #20
0
void PressureBufferReadStencil::applyRightWall  (FlowField & flowField, int i, int j){
    flowField.getPressure().getScalar(flowField.getNx()+2, j) = _rightBufferIn[j];
}
예제 #21
0
void PressureBufferFillStencil::applyFrontWall ( FlowField & flowField, int i, int j, int k) {
  /* _lowOffset = 2; _highOffset = -1;
   * from ParallelBoundaryIterater:  i = _lowOffset ; j = _lowOffset ; k = _lowOffset;
   */
  frontPressureFillBuffer[(j)+((localSize[1]+3)*(i))] = flowField.getPressure().getScalar(i,j,k+2);
}
예제 #22
0
void PressureBufferFillStencil::applyTopWall    (FlowField & flowField, int i, int j){
    _topBufferOut[i] = flowField.getPressure().getScalar(i, flowField.getNy()+1);
}
예제 #23
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];
}
예제 #24
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);
}
예제 #25
0
void PressureBufferFillStencil::applyRightWall ( FlowField & flowField, int i, int j) {
	rightPressureFillBuffer[0+2*j] = flowField.getPressure().getScalar(i-2,j);
	rightPressureFillBuffer[1+2*j] = flowField.getPressure().getScalar(i-1,j);
}
예제 #26
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];
}
예제 #27
0
void PressureBufferFillStencil::applyTopWall ( FlowField & flowField, int i, int j) {
	topPressureFillBuffer[0+2*i] = flowField.getPressure().getScalar(i,j-2);
	topPressureFillBuffer[1+2*i] = flowField.getPressure().getScalar(i,j-1);
}
예제 #28
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];
}
예제 #29
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];
}
예제 #30
0
void PressureBufferFillStencil::applyBottomWall (FlowField & flowField, int i, int j){
    _bottomBufferOut[i] = flowField.getPressure().getScalar(i, 2);
}