예제 #1
0
파일: mic.hpp 프로젝트: ChaliZhg/feelpp
void
Microphone::init()
{
    if ( M_is_initialized  )
        return;

    M_is_initialized = true;
    LOG(INFO) << "[MIC::init] starting...\n";
    // geometry is a ]0,1[x]0,1[
    GeoTool::Node x1( 0,0 );
    GeoTool::Node x2( 1.5,0.25 );
    GeoTool::Node x3( 0.5,0.25 );
    GeoTool::Node x4( 1.5,0.65 );
    GeoTool::Rectangle R1( meshSize,"R1",x1,x2 );
    R1.setMarker( _type="line",_name="In",_marker4=true );
    R1.setMarker( _type="surface",_name="Bottom",_markerAll=true );
    GeoTool::Rectangle R2( meshSize,"R2",x3,x4 );
    R2.setMarker( _type="surface",_name="Top",_markerAll=true );
    mesh = ( R1+R2 ).createMesh<mesh_type>( "Omega" );

#if 0
    /*
     * The function space and some associate elements are then defined
     */
    Xh = space_type::New( mesh );
    // allocate an element of Xh
    pT = element_ptrtype( new element_type( Xh ) );

    //  initialisation de A1 et A2
    M_Aqm.resize( Qa() );
    for(int q=0; q<Qa(); q++)
        M_Aqm[q].resize( 1 );

    M_Aqm[0][0] = backend->newMatrix( Xh, Xh );
    M_Aqm[1][0] = backend->newMatrix( Xh, Xh );
    M_Aqm[2][0] = backend->newMatrix( Xh, Xh );


    M_Fqm.resize( Nl() );
    M_Fqm[0].resize( Ql( 0 ) );
    M_Fqm[0][0].resize(1);
    M_Fqm[0][0][0] = backend->newVector( Xh );

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

    using namespace Feel::vf;
    static const int N = 2;
    Feel::ParameterSpace<2>::Element mu_min( M_Dmu );
    mu_min << 0.8, 10;
    M_Dmu->setMin( mu_min );
    Feel::ParameterSpace<2>::Element mu_max( M_Dmu );
    mu_max << 1.2,50;
    M_Dmu->setMax( mu_max );

    element_type u( Xh, "u" );
    element_type v( Xh, "v" );

    LOG(INFO) << "Number of dof " << Xh->nLocalDof() << "\n";

    // right hand side
    form1( Xh, M_Fqm[0][0][0], _init=true ) = integrate( elements( mesh ), id( v ) );
    M_Fqm[0][0[0]->close();

    form2( Xh, Xh, M_Aqm[0][0], _init=true ) = integrate( elements( mesh ), dxt( u )*dx( v ) );
    M_Aqm[0][0]->close();

    form2( Xh, Xh, M_Aqm[1][0], _init=true ) = integrate( elements( mesh ), dyt( u )*dy( v ) );
    // Dirichlet condition apply to Bottom, only y-dir terms non zero because of normal being N()=(Nx(),Ny()) = (0,-1)
    // thus the simplification below with the signs which should -Ny() = +1
    form2( Xh, Xh, M_Aqm[1][0] ) += integrate( markedfaces( mesh,"Bottom" ), dyt( u )*id( v )+dy( u )*idt( v )+M_gammabc*idt( u )*id( v )/hFace() );
    M_Aqm[1][0]->close();

    form2( Xh, Xh, M_Aqm[2][0], _init=true ) = integrate( elements( mesh ), idt( u )*id( v ) );
    M_Aqm[2][0]->close();

    M = backend->newMatrix( Xh, Xh );

    form2( Xh, Xh, M, _init=true ) =
        integrate( elements( mesh ), id( u )*idt( v ) + grad( u )*trans( gradt( u ) ) );
    M->close();

#endif
    LOG(INFO) << "[MIC::init] done\n";

} // Microphone::run
예제 #2
0
파일: ad.hpp 프로젝트: ChaliZhg/feelpp
void
AdvectionDiffusion::initModel()
{
    // geometry is a ]0,1[x]0,1[
    GeoTool::Node x1( 0,0 );
    GeoTool::Node x2( 1,1 );
    GeoTool::Rectangle R( meshSize,"Omega",x1,x2 );
    R.setMarker( _type="line",_name="Inflow",_marker4=true );
    R.setMarker( _type="line",_name="Bottom",_marker1=true );
    R.setMarker( _type="line",_name="Top",_marker3=true );
    R.setMarker( _type="line",_name="Outflow",_marker2=true );
    R.setMarker( _type="surface",_name="Omega",_markerAll=true );
    mesh = R.createMesh( _mesh=new mesh_type, _name="Omega" );


    /*
     * The function space and some associate elements are then defined
     */
    Xh = space_type::New( mesh );
    RbXh = rbfunctionspace_type::New( this->shared_from_this() , mesh );
    // allocate an element of Xh
    pT = element_ptrtype( new element_type( Xh ) );

    //  initialisation de A1 et A2
    M_Aqm.resize( Qa() );
    for(int q=0; q<Qa(); q++)
    {
        M_Aqm[q].resize( 1 );
        M_Aqm[q][0] = backend->newMatrix( Xh, Xh );
    }

    M_Fqm.resize( this->Nl() );
    for(int l=0; l<Nl(); l++)
    {
        M_Fqm[l].resize( Ql(l) );
        for(int q=0; q<Ql(l) ; q++)
        {
            M_Fqm[l][q].resize(1);
            M_Fqm[l][q][0] = backend->newVector( Xh );
        }
    }

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

    using namespace Feel::vf;

    Feel::ParameterSpace<2>::Element mu_min( M_Dmu );
    mu_min << 1, 0.1;
    M_Dmu->setMin( mu_min );
    Feel::ParameterSpace<2>::Element mu_max( M_Dmu );
    mu_max << 10,100;
    M_Dmu->setMax( mu_max );

    element_type u( Xh, "u" );
    element_type v( Xh, "v" );

    std::cout << "Number of dof " << Xh->nLocalDof() << "\n";

    // right hand side
    form1( Xh, M_Fqm[0][0][0], _init=true ) = integrate( markedfaces( mesh, "Bottom" ), id( v ) );
    M_Fqm[0][0][0]->close();

    form2( Xh, Xh, M_Aqm[0][0], _init=true ) = integrate( elements( mesh ), Py()*dxt( u )*id( v ) );
    M_Aqm[0][0]->close();

    form2( Xh, Xh, M_Aqm[1][0], _init=true ) = integrate( elements( mesh ), dxt( u )*dx( v ) );
    M_Aqm[1][0]->close();

    form2( Xh, Xh, M_Aqm[2][0], _init=true ) = integrate( elements( mesh ), dyt( u )*dy( v ) );
    form2( Xh, Xh, M_Aqm[2][0] ) += integrate( markedfaces( mesh,"Top" ),
                                           - dyt( u )*Ny()*id( v ) - dy( u )*Ny()*idt( v ) + 20*idt( u )*id( v )/hFace() );
    M_Aqm[2][0]->close();

    form2( Xh, Xh, M_Aqm[3][0], _init=true ) = integrate( markedfaces( mesh,"Inflow" ),
                                           - dxt( u )*Nx()*id( v ) - dx( u )*Nx()*idt( v ) );
    M_Aqm[3][0]->close();
    form2( Xh, Xh, M_Aqm[4][0], _init=true ) = integrate( markedfaces( mesh,"Inflow" ),
                                           20*idt( u )*id( v )/hFace() );
    M_Aqm[4][0]->close();
    M = backend->newMatrix( Xh, Xh );

    form2( Xh, Xh, M, _init=true ) =
        integrate( elements( mesh ), id( u )*idt( v ) + grad( u )*trans( gradt( u ) ) );
    M->close();

} // AdvectionDiffusion::run
예제 #3
0
파일: ns.hpp 프로젝트: 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