当前位置: 首页>>代码示例>>C++>>正文


C++ Iter::get_iter方法代码示例

本文整理汇总了C++中Iter::get_iter方法的典型用法代码示例。如果您正苦于以下问题:C++ Iter::get_iter方法的具体用法?C++ Iter::get_iter怎么用?C++ Iter::get_iter使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Iter的用法示例。


在下文中一共展示了Iter::get_iter方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: test

int test(int argc, char* argv[])
{
    if ( argc != 3 ) {
        std::cout << "error."    << std::endl;
        std::cout << "./run <n> <endtimestep>" << std::endl;
        return 1;
    }

    const int n = std::atoi(argv[1]); 
    
    //----------------------------------------------
    // define space domain
    //----------------------------------------------
    const int  D = 2;
    const real l = 1.0;
    const int hn = 3;
    //const int hn = 2;

    //----------------------------------------------
    // define mesh
    //----------------------------------------------
    const Mesh mesh( hn, l, n, l, n );
    //mesh.print_mesh_data();

    //----------------------------------------------
    // define time domain
    //----------------------------------------------
    const real      dt = 0.1 * mesh.delta(0) / 1.0; 
    //const real dt = 1.0e-5;
    const real endtime = 200 * 1.0 / 1.0;
    const int  endstep = static_cast<int>(endtime / dt);
    //const int  endstep = std::atoi(argv[2]);

    real * u = new real[mesh.size()];
    real * v = new real[mesh.size()];
    real * p = new real[mesh.size()];

    real * nu = new real[mesh.size()];
    real * nv = new real[mesh.size()];

    uniform_value(  u, 0.0, mesh );
    uniform_value(  v, 0.0, mesh );
    uniform_value( nu, 0.0, mesh );
    uniform_value( nv, 0.0, mesh );
    uniform_value(  p, 0.0, mesh );

    boundary_update_u_v( u, v, mesh );

    for ( int timestep = 0 ; timestep < endstep ; timestep++ ) {

        const Iter iter = time_marching_RK1_cavity( nu, nv, p, u, v, dt, mesh );

        swap( &nu, &u );
        swap( &nv, &v );
        //const Iter iter = time_marching_RK2_cavity( &u, &v, &p, dt, mesh );

        if ( timestep % 100 == 0 ) {

            real * const div = new real[mesh.size()];
            uniform_value( div, 0.0, mesh );

            calc_div( div, u, v, mesh );

            const std::string div_filename( "div.dat" );
            const std::string div_position( "cell_center" );
            //save_array( D, div, div_filename, div_position, mesh );

            abs_array( div, mesh );
            const real max_abs_div_value = max_from_array( div, mesh );
            delete[] div;
            
            std::cout << timestep / static_cast<real>(endstep) * 100 << " %";
            std::cout << "\t timestep = " << timestep;
            std::cout << "\titer = " << iter.get_iter() << "\terr = " << iter.get_error();
            std::cout << "\tdiv = " << std::scientific << std::showpos << max_abs_div_value << std::endl;
        }
    }

    const std::string u_filename( "u.dat" );
    const std::string u_position( "staggered_x" );
    save_array( D, u, u_filename, u_position, mesh );

    const std::string v_filename( "v.dat" );
    const std::string v_position( "staggered_y" );
    save_array( D, v, v_filename, v_position, mesh );

    const std::string p_filename( "p.dat" );
    const std::string p_position( "cell_center" );
    save_array( D, p, p_filename, p_position, mesh );

    output_result( "result_u.dat", "result_v.dat", u, v, mesh );

    delete[] u;
    delete[] v;
    delete[] p;
    delete[] nu;
    delete[] nv;

    return 0;
}
开发者ID:mariotan7,项目名称:NS_solver,代码行数:100,代码来源:main.cpp


注:本文中的Iter::get_iter方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。