一、OpenLB的核心功能介绍
OpenLB的核心工作是通过数值模拟方法解决CFD问题。OpenLB使用基于离散介观元胞(lattice Boltzmann method, LBM)的方法对流体物理量的传输进行建模。OpenLB内置了多种模拟稳态和非稳态流动条件的模型。LBM方法基于微观的一组运动方程,建立起流体宏观物理量(如密度和速度)与微观参数(如分布函数)之间的关系,利用该关系来模拟各种复杂的流动现象。二、OpenLB的使用方法
在OpenLB中,用户可以自定义不同类型的晶体结构、晶体面边界条件和流体-结构相互作用模型。OpenLB内置了各种语言,如C++,Python 和MATLAB等,提供非常友好的API接口使得用户可以方便地使用它们进行代码的开发和测试。 下面是一个简单的OpenLB程序示例,它模拟了圆管内的定常层流:#include "openlb.h" #include "graph.h" #define N 150 #define RMIN 20 typedef double T; struct my_components { Fluid T rho; Velocityu, u_new; }; struct my_descriptor { DefaultDescriptor base; Descriptor<2,N> cylinder; }; typedef Lattice , my_descriptor> MyLattice; int main(int argc, char* argv[]) { MyLattice lattice( new my_components, DEFAULT_DESCRIPTOR ); OnLatticeBoundaryCondition boundary( lattice ); BounceBack cylinder( lattice ); lattice.initialize(); //圆柱体的绘制 for( int i = 0 ; i < lattice.getNx() ; i++) { for( int j = 0 ; j < lattice.getNy() ; j++) { if( (i-N/2)*(i-N/2)+(j-N/2)*(j-N/2) <= RMIN*RMIN ) { lattice.get(0,i,j).template get<1>() = Cylinder ::flow_velocity(); lattice.get(0,i,j).template get<1>().raw(2) = 0; cylinder.set_direction( i, j, 3, false ); cylinder.set_direction( i, j, 4, false ); } } } const int imSize[] = {600, 600}; Graph * graph = createGraph ( "flow.bmp", imSize ); auto graphFluid = graph->getGraph( 0, 0 ); while( lattice.get_time() < 5e4 ) { lattice.collide_and_stream(); cylinder.apply_bounce_back(0); boundary.apply_velocity( Cylinder ::flow_velocity(), my_descriptor::cylinder ); boundary.apply_pressure( my_components::rho, graphics, graphics, graphics, graphics ); lattice.get(0).compute_moments(); //绘制圆管流动 if( parallel.rank() == 0 ) { for( int y = 0 ; y < lattice.getNy() ; y++ ) { for( int x = 0 ; x < lattice.getNx() ; x++ ) { graphFluid[y][x] = std::min( (int)(255.0*(1-exp(-400*lattice.get(0, x, y).rho()))), 255 ); } } graph->write(); } } graph->close(); return 0; }
三、OpenLB的优点
OpenLB具有以下优点:1、高度可扩展性,用户可以方便添加自己的物理模型和特定的边界条件。
2、 实现简单, 只需要少量的代码和库函数。
3、可以在分布式内存体系结构中实现高效可扩展性。
4、速度快 ,能够节省求解时间。
5、可以提供多角度速度场计算,达到重要的精度。