本文主要是介绍An example: 2D immersed boundary lattice Boltzmann method code--By Timm Krüger.2011.,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
- // 谢谢Timm Krüger大佬的代码。 还是老样子,有啥问题Feel free to tell us~毕竟群众力量大嘛~QQ群:293267908。
- // 话不多说,上干货!
- // ISBN 978-3-319-44649-3 (Electronic)
- // 978-3-319-44647-9 (Print)
- // http://www.springer.com/978-3-319-44647-9 文章地址。
- // This is an example 2D immersed boundary lattice Boltzmann method code.
- // It uses the D2Q9 lattice with Guo's forcing term.
- // Rigid bottom and top walls are parallel to the x-axis (channel).
- // The flow is periodic along the x-axis.
- // One initially cylindrical particle is positioned in the flow.
- // This particle can be rigid/deformable and stationary/moving.
- // Last update 21-Aug-2011 by Timm Krüger.
- // This code may be changed and distributed freely.
- //
- // The lattice velocities are defined according to the following scheme:
- // index: 0 1 2 3 4 5 6 7 8
- // ----------------------------------
- // x: 0 +1 -1 0 0 +1 -1 +1 -1
- // y: 0 0 0 +1 -1 +1 -1 -1 +1
- //
- // 8 3 5 ^y
- // \|/ | x
- // 2-0-1 --->
- // /|\
- // 6 4 7
- /// *********************
- /// PREPROCESSOR COMMANDS
- /// *********************
- #include <vector> // vector containers
- #include <cmath> // mathematical library
- #include <iostream> // for the use of 'cout'
- #include <fstream> // file streams
- #include <sstream> // string streams
- #include <cstdlib> // standard library
- #define SQ(x) ((x) * (x)) // square function; replaces SQ(x) by ((x) * (x)) in the code
- using namespace std; // permanently use the standard namespace
- /// *********************
- /// SIMULATION PARAMETERS
- /// *********************
- // These are the relevant simulation parameters.
- // They can be changed by the user.
- // If a bottom or top wall shall move in negative x-direction, a negative velocity has to be specified.
- // Moving walls and gravity can be switched on simultaneously.
- /// Simulation types
- // Exactly one of the following options has to be defined.
- // RIGID_CYLINDER
- // - for simulation of, e.g., Karman vortex street
- // - the cylinder is kept in space, it does not move
- // DEFORMABLE_CYLINDER
- // - for simulation of a deformable cylinder
- // - the cylinder moves along with the flow
- // DEFORMABLE_RBC
- // - for simulation of a deformable red blood cell
- // - the cell moves along with the flow
- //这个代码一次只能算一个边界。 可以定义这几个。
- //#define RIGID_CYLINDER
- //#define DEFORMABLE_CYLINDER
- #define DEFORMABLE_RBC
- /// Fluid/lattice properties
- #ifdef RIGID_CYLINDER
- const int Nx = 300; // number of lattice nodes along the x-axis (periodic)
- const int Ny = 62; // number of lattice nodes along the y-axis (including two wall nodes)
- const double tau = 0.53; // relaxation time
- const int t_num = 100000; // number of time steps (running from 1 to t_num)
- const int t_disk = 200; // disk write time step (data will be written to the disk every t_disk step)
- const int t_info = 5000; // info time step (screen message will be printed every t_info step)
- const double gravity = 0.000005; // force density due to gravity (in positive x-direction)
- const double wall_vel_bottom = 0; // velocity of the bottom wall (in positive x-direction)
- const double wall_vel_top = 0; // velocity of the top wall (in positive x-direction)
- #else
- const int Nx = 30; // number of lattice nodes along the x-axis (periodic)
- const int Ny = 32; // number of lattice nodes along the y-axis (including two wall nodes)
- const double tau = 1; // relaxation time
- const int t_num = 50000; // number of time steps (running from 1 to t_num)
- const int t_disk = 200; // disk write time step (data will be written to the disk every t_disk step)
- const int t_info = 1000; // info time step (screen message will be printed every t_info step)
- const double gravity = 0; // force density due to gravity (in positive x-direction)
- const double wall_vel_bottom = -0.02; // velocity of the bottom wall (in positive x-direction)
- const double wall_vel_top = 0.02; // velocity of the top wall (in positive x-direction)
- #endif
- /// Particle properties
- #ifdef RIGID_CYLINDER
- const int particle_num_nodes = 36; // number of surface nodes
- const double particle_radius = 8; // radius
- const double particle_stiffness = 0.3; // stiffness modulus
- const double particle_center_x = 15; // center position (x-component)
- const double particle_center_y = 29; // center position (y-component)
- #else
- const int particle_num_nodes = 32; // number of surface nodes
- const double particle_radius = 6; // radius
- const double particle_stiffness = 0.1; // stiffness modulus
- const double particle_bending = 0.001; // stiffness modulus
- const double particle_center_x = 15; // center position (x-component)
- const double particle_center_y = 15; // center position (y-component)
- #endif
- /// *****************
- /// DECLARE VARIABLES
- /// *****************
- // The following code should not be modified when it is first used.
- const double omega = 1. / tau; // relaxation frequency (inverse of relaxation time)
- double ***pop, ***pop_old; // LBM populations (old and new)
- double **density; // fluid density
- double **velocity_x; // fluid velocity (x-component)
- double **velocity_y; // fluid velocity (y-component)
- double **force_x; // fluid force (x-component)
- double **force_y; // fluid force (y-component)
- double force_latt[9]; // lattice force term entering the lattice Boltzmann equation
- double pop_eq[9]; // equilibrium populations
- const double weight[9] = {4./9., 1./9., 1./9., 1./9., 1./9., 1./36., 1./36., 1./36., 1./36.}; // lattice weights
- /// ******************
- /// PARTICLE STRUCTURE
- /// ******************
- // The following code handles the object immersed in the flow.
- // In the present implementation, only a single object can be put into the flow.
- /// Structure for surface nodes
- // Each node has a current x- and y-position and a reference x- and y-position.
- struct node_struct {
- /// Constructor
- node_struct() {
- //x分成了x和x_ref ,是为了后面的相减,求边界上的力密度大小。
- x = 0;
- y = 0;
- x_ref = 0;
- y_ref = 0;
- vel_x = 0;
- vel_y = 0;
- force_x = 0;
- force_y = 0;
- }
- /// Elements
- double x; // current x-position
- double y; // current y-position
- double x_ref; // reference x-position
- double y_ref; // reference y-position
- double vel_x; // node velocity (x-component)
- double vel_y; // node velocity (y-component)
- double force_x; // node force (x-component)
- double force_y; // node force (y-component)
- };
- /// Structure for object (either cylinder or red blood cell)
- struct particle_struct {
- /// Constructor
- particle_struct() {
- num_nodes = particle_num_nodes;
- radius = particle_radius;
- // 设置流体刚度,用于计算边界力密度
- stiffness = particle_stiffness;
- center.x = particle_center_x;
- center.y = particle_center_y;
- center.x_ref = particle_center_x;
- center.y_ref = particle_center_y;
- node = new node_struct[num_nodes];
- // The initial shape of the object is set in the following.
- // For a cylinder (rigid or deformable), the nodes define a circle.
- // For a red blood cell, the y-position has to be changed in order to describe a red blood cell.
- // Initially, the current node positions and reference node positions are identical.
- // During the simulation, only the current positions are updated,
- // the reference node positions are fixed.
- for(int n = 0; n < num_nodes; ++n) {
- #if defined RIGID_CYLINDER || defined DEFORMABLE_CYLINDER
- node[n].x = center.x + radius * sin(2. * M_PI * (double) n / num_nodes);
- node[n].x_ref = center.x + radius * sin(2. * M_PI * (double) n / num_nodes);
- node[n].y = center.y + radius * cos(2. * M_PI * (double) n / num_nodes);
- node[n].y_ref = center.y + radius * cos(2. * M_PI * (double) n / num_nodes);
- #endif
- #ifdef DEFORMABLE_RBC
- node[n].x = center.x + radius * sin(2. * M_PI * (double) n / num_nodes);
- node[n].x_ref = center.x + radius * sin(2. * M_PI * (double) n / num_nodes);
- node[n].y = radius * cos(2. * M_PI * (double) n / num_nodes);
- // Parametrization of the red blood cell shape in 2D
这篇关于An example: 2D immersed boundary lattice Boltzmann method code--By Timm Krüger.2011.的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!