Ejemplo n.º 1
0
void
InitPolicyInterpolation< mesh_Type >::
initSimulation ( bcContainerPtr_Type /*bchandler*/,
                 vectorPtr_Type solution )
{
    ASSERT ( problem()->hasExactSolution(), "Error: You cannot use the interpolation method if the problem has not an analytical solution." );

    Real currentTime = initialTime() - timestep() * bdf()->order();
    UInt pressureOffset = uFESpace()->fieldDim() * uFESpace()->dof().numTotalDof();

    vectorPtr_Type velocity;
    velocity.reset ( new vector_Type ( uFESpace()->map(), Unique ) );

    vectorPtr_Type pressure;
    pressure.reset ( new vector_Type ( pFESpace()->map(), Unique ) );

    *solution = 0.0;
    uFESpace()->interpolate ( problem()->uexact(), *velocity, currentTime );
    pFESpace()->interpolate ( problem()->pexact(), *pressure, currentTime );
    solution->add ( *velocity );
    solution->add ( *pressure, pressureOffset );
    bdf()->setInitialCondition ( *solution );

    currentTime += timestep();
    for ( ; currentTime <=  initialTime() + timestep() / 2.0; currentTime += timestep() )
    {
        *solution = 0.0;
        *velocity = 0.0;
        *pressure = 0.0;

        uFESpace()->interpolate ( problem()->uexact(), *velocity, currentTime );
        pFESpace()->interpolate ( problem()->pexact(), *pressure, currentTime );
        solution->add ( *velocity );
        solution->add ( *pressure, pressureOffset );

        // Updating bdf
        bdf()->shiftRight ( *solution );
    }
}
Ejemplo n.º 2
0
Archivo: ns.hpp Proyecto: LANTZT/feelpp
void
NavierStokes::run()
{
    this->init();

    auto U = Xh->element( "(u,p)" );
    auto V = Xh->element( "(u,q)" );
    auto u = U.element<0>( "u" );
    auto v = V.element<0>( "u" );
    auto p = U.element<1>( "p" );
    auto q = V.element<1>( "p" );
#if defined( FEELPP_USE_LM )
    auto lambda = U.element<2>();
    auto nu = V.element<2>();
#endif
    //# endmarker4 #

    LOG(INFO) << "[dof]         number of dof: " << Xh->nDof() << "\n";
    LOG(INFO) << "[dof]    number of dof/proc: " << Xh->nLocalDof() << "\n";
    LOG(INFO) << "[dof]      number of dof(U): " << Xh->functionSpace<0>()->nDof()  << "\n";
    LOG(INFO) << "[dof] number of dof/proc(U): " << Xh->functionSpace<0>()->nLocalDof()  << "\n";
    LOG(INFO) << "[dof]      number of dof(P): " << Xh->functionSpace<1>()->nDof()  << "\n";
    LOG(INFO) << "[dof] number of dof/proc(P): " << Xh->functionSpace<1>()->nLocalDof()  << "\n";

    LOG(INFO) << "Data Summary:\n";
    LOG(INFO) << "   hsize = " << meshSize << "\n";
    LOG(INFO) << "  export = " << this->vm().count( "export" ) << "\n";
    LOG(INFO) << "      mu = " << mu << "\n";
    LOG(INFO) << " bccoeff = " << penalbc << "\n";




    //# marker5 #
    auto deft = gradt( u )+trans(gradt(u));
    auto def = grad( v )+trans(grad(v));
    //# endmarker5 #

    //# marker6 #
    // total stress tensor (trial)
    auto SigmaNt = -idt( p )*N()+mu*deft*N();

    // total stress tensor (test)
    auto SigmaN = -id( p )*N()+mu*def*N();
    //# endmarker6 #

    auto F = M_backend->newVector( Xh );
    auto D =  M_backend->newMatrix( Xh, Xh );

    // right hand side
    auto ns_rhs = form1( _test=Xh, _vector=F );


    LOG(INFO) << "[navier-stokes] vector local assembly done\n";

    // construction of the BDF
    auto bdfns=bdf(_space=Xh);

    /*
     * Construction of the left hand side
     */

    auto navierstokes = form2( _test=Xh, _trial=Xh, _matrix=D );
    mpi::timer chrono;
    navierstokes += integrate( elements( mesh ), mu*inner( deft,def )+ trans(idt( u ))*id( v )*bdfns->polyDerivCoefficient( 0 ) );
    LOG(INFO) << "mu*inner(deft,def)+(bdf(u),v): " << chrono.elapsed() << "\n";
    chrono.restart();
    navierstokes +=integrate( elements( mesh ), - div( v )*idt( p ) + divt( u )*id( q ) );
    LOG(INFO) << "(u,p): " << chrono.elapsed() << "\n";
    chrono.restart();
#if defined( FEELPP_USE_LM )
    navierstokes +=integrate( elements( mesh ), id( q )*idt( lambda ) + idt( p )*id( nu ) );
    LOG(INFO) << "(lambda,p): " << chrono.elapsed() << "\n";
    chrono.restart();
#endif

    std::for_each( inflow_conditions.begin(), inflow_conditions.end(),
                   [&]( BoundaryCondition const&  bc )
                   {
                       // right hand side
                       ns_rhs += integrate( markedfaces( mesh, bc.marker() ), inner( idf(&bc,BoundaryCondition::operator()),-SigmaN+penalbc*id( v )/hFace() ) );

                       navierstokes +=integrate( boundaryfaces( mesh ), -inner( SigmaNt,id( v ) ) );
                       navierstokes +=integrate( boundaryfaces( mesh ), -inner( SigmaN,idt( u ) ) );
                       navierstokes +=integrate( boundaryfaces( mesh ), +penalbc*inner( idt( u ),id( v ) )/hFace() );
                   });
    std::for_each( wall_conditions.begin(), wall_conditions.end(),
                   [&]( BoundaryCondition const&  bc )
                   {
                       navierstokes +=integrate( boundaryfaces( mesh ), -inner( SigmaNt,id( v ) ) );
                       navierstokes +=integrate( boundaryfaces( mesh ), -inner( SigmaN,idt( u ) ) );
                       navierstokes +=integrate( boundaryfaces( mesh ), +penalbc*inner( idt( u ),id( v ) )/hFace() );
                   });
    std::for_each( outflow_conditions.begin(), outflow_conditions.end(),
                   [&]( BoundaryCondition const&  bc )
                   {
                       ns_rhs += integrate( markedfaces( mesh, bc.marker() ), inner( idf(&bc,BoundaryCondition::operator()),N() ) );
                   });

    LOG(INFO) << "bc: " << chrono.elapsed() << "\n";
    chrono.restart();

    u = vf::project( _space=Xh->functionSpace<0>(), _expr=cst(0.) );
    p = vf::project( _space=Xh->functionSpace<1>(), _expr=cst(0.) );

    M_bdf->initialize( U );

    for( bdfns->start(); bdfns->isFinished(); bdfns->next() )
    {
        // add time dependent terms
        auto bdf_poly = bdfns->polyDeriv();
        form1( _test=Xh, _vector=Ft ) =
            integrate( _range=elements(mesh), _expr=trans(idv( bdf_poly ))*id( v ) );
        // add convective terms
        form1( _test=Xh, _vector=Ft ) +=
            integrate( _range=elements(mesh), _expr=trans(gradv(u)*idv( u ))*id(v) );
        // add contrib from time independent terms
        Ft->add( 1., F );

        // add time stepping terms from BDF to right hand side
        backend()->solve( _matrix=D, _solution=U, _rhs=Ft );

        this->exportResults( bdfns->time(), U );
    }





} // NavierNavierstokes::run
Ejemplo n.º 3
0
void main_comp(double *A1, double *B1, int N, int n, int K, int ngrid, double data[], double data1[], int delta[], int **freq, double *grid, double **F, double **Fsmooth, double **hazard, const char *appdir)
{
    int             i,j,k,**ind,iterations,n_Iterations=1000;
    int             *njumps;
    double          phi,**fdens;
    double          step,**p,**jumploc;
    double          A,B,c,h;
    SampleTime		*obs;
    
    
    delta[0]=0;
    data[0]=data1[0]=0;
        
    obs = new SampleTime[N];
    
    for (i=0; i<N; i++)
    {
        obs[i].t = data[i+1];
        obs[i].delta = delta[i+1];
    }
    
    qsort(obs,N,sizeof(SampleTime),CompareTime);
    
    for (i=0; i<N; i++)
    {
        data[i+1]= obs[i].t ;
        delta[i+1] = obs[i].delta;
    }
    
    ind = new int *[K+2];
    
    
    for (i=0;i<K+2;i++)
        ind[i]= new int[N+1];
    
    for (k=1;k<=K+1;k++)
        F[k][0]=0;
    
    njumps = new int[K+2];
    fdens= new double *[K+2];
    p= new double *[K+2];
    jumploc= new double *[K+2];
    
    
    for (i=0;i<K+2;i++)
    {
        fdens[i]= new double[ngrid+1];
        p[i]= new double[n+1];
        jumploc[i]= new double[n+1];
    }
    
    
    ICM(N,n,freq,K,ind,F,n_Iterations,&phi,&iterations);
    
    ofstream file2_("MLE.txt");
    
    if (file2_.is_open())
    {
        for (i=1;i<=n;i++)
        {
            if (F[K+1][i]>F[K+1][i-1])
            {
                file2_ << setprecision(11) << setw(20) << data1[i];
                for (k=1;k<=K+1;k++)
                    file2_ << setprecision(11) <<  setw(20) << F[k][i];
                file2_ << "\n";
            }
        }
        file2_.close();
    }

    
    for (k=1;k<=K+1;k++)
    {
        j=0;
        for (i=1;i<=n;i++)
        {
            if (F[k][i]>F[k][i-1])
            {
                p[k][j]=F[k][i]-F[k][i-1];
                jumploc[k][j]=data1[i];
                j++;
            }
        }
        njumps[k]=j;
    }
    
    A=min(N,data);
    B=max(N,data);
    *A1=A;
    *B1=B;
    step=(B-A)/ngrid;
    
    c=B;
    
    for (i=0;i<=ngrid;i++)
        grid[i]=A+i*step;
    
    h = fmin(c*pow(N,-1.0/7),9.9);
    
    
    for (i=0;i<=ngrid;i++)
    {
        for (k=1;k<K+1;k++)
            fdens[k][i]=dens_estimate(A,B,k,njumps,jumploc,p,h,grid[i]);
    }
    
    h = B*pow(N,-1.0/5);
    
    
    for (i=0;i<=ngrid;i++)
    {
        for (k=1;k<=K;k++)
            Fsmooth[k][i]=bdf(A,B,k,njumps,jumploc,p,h,grid[i]);
    }
    
    for (i=0;i<=ngrid;i++)
    {
        for (k=1;k<=K;k++)
            hazard[k][i]=fdens[k][i]/(1-Fsmooth[k][i]);
    }
    
    ofstream file_("SMLE.txt");

    if (file_.is_open())
    {
        for (i=1;i<=ngrid;i++)
        {
            file_ << setprecision(10) << setw(20) << grid[i];
            for (k=1;k<K+1;k++)
                file_ << setprecision(10) <<  setw(20) << Fsmooth[k][i];
            file_ << "\n";
        }
        file_.close();
    }
    
    ofstream file1_("data.txt");
    
    if (file1_.is_open())
    {
        for (i=1;i<=N;i++)
        {
            file1_ << setprecision(11) << setw(20) << data[i];
            file1_ <<  setw(10) << delta[i];
            file1_ << "\n";
        }
        file1_.close();
    }
    
    
    
    ofstream file3_("hazard.txt");
    
    if (file3_.is_open())
    {
        for (i=1;i<=ngrid;i++)
        {
            file3_ << setprecision(10) << setw(20) << grid[i];
            for (k=1;k<K+1;k++)
                file3_ << setprecision(10) <<  setw(20) << hazard[k][i];
            file3_ << "\n";
        }
        file3_.close();
    }
    
    // free memory
    
    for (i = 0; i < K+2; i++)
         delete[] ind[i], delete[] p[i], delete[] jumploc[i], delete[] fdens[i];
    
    delete[] ind, delete[] p, delete[] jumploc, delete[] njumps, delete[] fdens;
    
    delete[] obs;
}