예제 #1
0
파일: ESDIRK.C 프로젝트: gunnups/FOAM-FSI
    void ESDIRK::getSourceTerm(
        const bool /*corrector*/,
        const int k,
        const int /*sweep*/,
        const scalar deltaT,
        fsi::vector & rhs,
        fsi::vector & qold
        )
    {
        assert( k <= nbStages - 1 );

        qold = this->qold;

        // Compute the time step from the stage deltaT
        if ( dt < 0 )
        {
            // first time step, first prediction step
            dt = deltaT / A( k, k );
        }

        assert( dt > 0 );

        rhs.setZero();

        // Calculate sum of the stage residuals
        for ( int iStage = 0; iStage < k; iStage++ )
            rhs += A( k, iStage ) * F.row( iStage ).transpose();

        rhs.array() *= dt;

        this->stageIndex = k;
    }
void TubeFlowLinearizedFluidSolver::solve(
    const fsi::vector & a,
    fsi::vector & p
    )
{
    this->a = a.array() - a0;

    std::cout << "Solve fluid domain" << std::endl;

    // Construct right hand size of linear system

    fsi::vector b( 2 * N ), x( 2 * N );
    b.setZero();

    for ( int i = 1; i < N - 1; i++ )
    {
        // Continuity equation rhs

        b( i ) = dx / dt * ( an( i ) - this->a( i ) );
        b( i ) += 0.5 * u0 * ( this->a( i - 1 ) - this->a( i + 1 ) );

        // Momentum equation rhs

        b( i + N ) = u0 * dx / dt * ( an( i ) - this->a( i ) );
        b( i + N ) += 0.5 * u0 * u0 * ( this->a( i - 1 ) - this->a( i + 1 ) );
        b( i + N ) += a0 * dx / dt * un( i );
    }

    // Boundary conditions

    // Velocity inlet condition
    b( 0 ) = u0 / 10.0 * std::pow( std::sin( M_PI * timeIndex * tau ), 2 );

    // Pressure inlet
    b( N ) = 0;

    // Velocity outlet condition
    b( N - 1 ) = 0;

    // Pressure outlet condition
    b( 2 * N - 1 ) = -cmk * rho * un( N - 1 ) + pn( N - 1 );

    // Solve for x

    x = lu.solve( b );

    // Retrieve solution

    u = x.head( N );
    this->p = x.tail( N );

    // Return pressure p
    p = this->p.array() + p0;

    data.col( 0 ) = p;
}