170 lines
5.2 KiB
C++
170 lines
5.2 KiB
C++
|
#pragma once
|
|||
|
#include <stdio.h>
|
|||
|
#include <iostream>
|
|||
|
#include <string>
|
|||
|
#include <fstream>
|
|||
|
#include <mpi.h>
|
|||
|
#include <math.h>
|
|||
|
#include "vector3.hpp"
|
|||
|
|
|||
|
void RunLBMSolverMPI();
|
|||
|
//<2F><><EFBFBD><EFBFBD>: <20>ƺ<EFBFBD><C6BA><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ż<EFBFBD>幣<EFBFBD><E5B9A3>й<EFBFBD><D0B9><EFBFBD>ѧ<EFBFBD><D1A7><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ѧ
|
|||
|
|
|||
|
//#define PARALLEL 1 //<2F><><EFBFBD><EFBFBD><EFBFBD>Ƿ<EFBFBD><C7B7><EFBFBD><EFBFBD>б<EFBFBD><D0B1><EFBFBD><EFBFBD>Ŀ<EFBFBD><C4BF><EFBFBD>
|
|||
|
|
|||
|
using namespace std;
|
|||
|
|
|||
|
struct Boundary_Condition
|
|||
|
{ //types :<3A>ٶȱ߽<C8B1><DFBD><EFBFBD><EFBFBD><EFBFBD>velocity; ѹ<><D1B9><EFBFBD>߽<EFBFBD><DFBD><EFBFBD><EFBFBD><EFBFBD>pressure<72><65> <20><><EFBFBD>ڱ߽<DAB1>periodic
|
|||
|
char xminFace[20];
|
|||
|
char xmaxFace[20];
|
|||
|
char yminFace[20];
|
|||
|
char ymaxFace[20];
|
|||
|
char zminFace[20];
|
|||
|
char zmaxFace[20];
|
|||
|
vector3<double> vel_specified[6]; //<2F><><EFBFBD><EFBFBD><EFBFBD>ٶȱ߽磺6<E7A3BA><36><EFBFBD>棨<EFBFBD>߽磩<DFBD>ϵ<EFBFBD><CFB5>ٶ<EFBFBD>ʸ<EFBFBD><CAB8>
|
|||
|
double rho_specified[6]; //<2F><><EFBFBD><EFBFBD>ѹ<EFBFBD><D1B9><EFBFBD>߽<EFBFBD>: 6<><36><EFBFBD>߽<EFBFBD><DFBD>ϵ<EFBFBD><CFB5>ܶȣ<DCB6>ѹ<EFBFBD><D1B9><EFBFBD><EFBFBD>
|
|||
|
};
|
|||
|
|
|||
|
struct Params_Pakage {
|
|||
|
char in[50];
|
|||
|
char out[50];
|
|||
|
char velocity_set[20];
|
|||
|
char bc[20];
|
|||
|
};
|
|||
|
|
|||
|
class LBM
|
|||
|
{
|
|||
|
|
|||
|
private:
|
|||
|
int FINE, iMRT, iLES, iContinue, iGEO, CONV; //<2F><><EFBFBD><EFBFBD>
|
|||
|
double conv_v;
|
|||
|
string conti_file, geo_file;
|
|||
|
int time = 0;
|
|||
|
int total_NX, total_NY, total_NZ;
|
|||
|
int NX, NY, NZ, x_np, y_np, z_np, x_id, y_id, z_id;
|
|||
|
//MRT
|
|||
|
double** M_MRT, ** M_MRTI, ** MSM;
|
|||
|
//fine
|
|||
|
int fine_NX, fine_NY, fine_NZ;
|
|||
|
int LefLowx, LefLowy, LefLowz;
|
|||
|
int Fdimx, Fdimy, Fdimz;
|
|||
|
int MeshType;
|
|||
|
int Xori, Yori, Zori;
|
|||
|
int finelocal[6];
|
|||
|
int border_node_num;
|
|||
|
//
|
|||
|
int FrameRate, ttstep;
|
|||
|
double density0;
|
|||
|
double tau;
|
|||
|
double gx, gy, gz;
|
|||
|
const double c_s = 1.0 / sqrt(3);
|
|||
|
|
|||
|
string boundary_condition;
|
|||
|
string velocity_set;
|
|||
|
Boundary_Condition BC;
|
|||
|
MPI_Comm* comm0;
|
|||
|
MPI_Comm* comm1;
|
|||
|
//
|
|||
|
double* rho;
|
|||
|
vector3<double> vel0; // ini_vel
|
|||
|
vector3<double>* vel; //, bc_specified_vel;
|
|||
|
double* pdf2;
|
|||
|
double* pdf;
|
|||
|
int* obst;
|
|||
|
double* rhoTotal{};
|
|||
|
vector3<double>* velTotal{};
|
|||
|
vector3<double>* velTotalConv{};
|
|||
|
int* obstTotal{};
|
|||
|
int* n_myid;
|
|||
|
int direction_size;
|
|||
|
int send_direction_size;
|
|||
|
vector3<int>* ei;
|
|||
|
double* weights;
|
|||
|
int* reverse_indexes;
|
|||
|
//
|
|||
|
vector3<double> *force;
|
|||
|
int* node2;
|
|||
|
double* delta;
|
|||
|
int num_node2;
|
|||
|
|
|||
|
//
|
|||
|
inline int index(int x, int y, int z) const {
|
|||
|
return ((z + 2) * (NX + 4) * (NY + 4) + (y + 2) * (NX + 4) + (x + 2));
|
|||
|
}
|
|||
|
inline int index(int x, int y, int z, int w) const {
|
|||
|
return ((x + 2) + (y + 2) * (NX + 4) + (z + 2) * (NX + 4) * (NY + 4) + w * (NX + 4) * (NY + 4) * (NZ + 4));
|
|||
|
}
|
|||
|
inline int index(int x, int y, int z, int NX, int NY) {
|
|||
|
return (z + 2) * (NX + 4) * (NY + 4) + (y + 2) * (NX + 4) + (x + 2);
|
|||
|
}
|
|||
|
inline int total_index(int x, int y, int z) const {
|
|||
|
return (z * total_NX * total_NY) + (y * total_NX) + x;
|
|||
|
}
|
|||
|
|
|||
|
public:
|
|||
|
LBM();
|
|||
|
~LBM();
|
|||
|
int initialise(Params_Pakage* p, int mpi_rank);//<2F>ܳ<EFBFBD>ʼ<EFBFBD><CABC><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|||
|
void perform_timestep(); //<2F>ܼ<EFBFBD><DCBC>㲽
|
|||
|
void output(int t, int mpi_rank); //<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|||
|
|
|||
|
int get_time();
|
|||
|
int get_NX();
|
|||
|
int get_NY();
|
|||
|
int get_NZ();
|
|||
|
int get_MeshType();
|
|||
|
int get_border_node_num();
|
|||
|
int get_total_steps();
|
|||
|
int get_FrameRate();
|
|||
|
int getdirs();
|
|||
|
int getalldirs();
|
|||
|
vector3<int>* get_ei();
|
|||
|
|
|||
|
private:
|
|||
|
//MPI
|
|||
|
void mpi_ini(int mpi_rank); //<2F><><EFBFBD>м<EFBFBD><D0BC><EFBFBD><EFBFBD><EFBFBD>ʼ<EFBFBD><CABC>
|
|||
|
void mpi_send(); //<2F><><EFBFBD>ݱ߽<DDB1>pdf2
|
|||
|
void mpi_total(int mpi_rank);//<2F><><EFBFBD>ܸ<EFBFBD>CPU<50><55><EFBFBD><EFBFBD>
|
|||
|
//<2F><>ʼ<EFBFBD><CABC><EFBFBD><EFBFBD>
|
|||
|
void ReadParameter(Params_Pakage* p, int mpi_rank);//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|||
|
void iniFlow(); //<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʼ<EFBFBD><CABC>
|
|||
|
void iniobst(); //<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʼ<EFBFBD><CABC>
|
|||
|
//output
|
|||
|
void write_binary(string filename);
|
|||
|
void read_all(std::string filename); //<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ݣ<EFBFBD><DDA3>ļ<EFBFBD>Ӧ<EFBFBD><D3A6><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ƥ<EFBFBD><C6A5>
|
|||
|
void output_all(std::string filename);//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|||
|
void output_all(std::string filename, int xmin, int xmax, int ymin, int ymax, int zmin, int zmax);
|
|||
|
//LBM iteration
|
|||
|
void compute_density_momentum(int xmin, int xmax, int ymin, int ymax, int zmin, int zmax); //<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|||
|
void stream(int xmin, int xmax, int ymin, int ymax, int zmin, int zmax);//Stream the current equilibrium distribution to the next distribution.
|
|||
|
void collision(int xmin, int xmax, int ymin, int ymax, int zmin, int zmax);//Perform the collision step. Assumes delta t / tau = 1.
|
|||
|
//BC
|
|||
|
void bouzidi();
|
|||
|
void wall_bounce_back(); //<2F><><EFBFBD><EFBFBD>ƽֱ<C6BD><D6B1><EFBFBD><EFBFBD><EFBFBD><EFBFBD><DEBB>ƣ<EFBFBD>simple bounce-back<63><6B>
|
|||
|
void velocity_boundary_condition(); //<2F><><EFBFBD><EFBFBD><EFBFBD>ٶȱ߽<C8B1><DFBD><EFBFBD><EFBFBD><EFBFBD>
|
|||
|
void pressure_boundary_condition(); //<2F><><EFBFBD><EFBFBD>ѹ<EFBFBD><D1B9><EFBFBD>߽<EFBFBD><DFBD><EFBFBD><EFBFBD><EFBFBD>
|
|||
|
void set_velocity_set();//Used to internally generate velocity_set.
|
|||
|
//
|
|||
|
void set_velocity(int x_field, int y_field, int z_field, double u_x, double u_y, double u_z);//Set velocity at position in velocity field.
|
|||
|
void set_density(int x_field, int y_field, int z_field, double density);//Set density at position in density field.
|
|||
|
double calculate_feq(int i, int j, int k, int w);
|
|||
|
double calculate_feq(int i, int j, int k, int w, double u_le_x);
|
|||
|
//<2F><><EFBFBD>غ<EFBFBD><D8BA><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ú<EFBFBD><C3BA><EFBFBD><EFBFBD><EFBFBD>Ϊ<EFBFBD>ƶ<EFBFBD><C6B6>߽<EFBFBD><DFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>f_i= f_i^eq<65><71>rho, (u+u_le_x), v, w<><77><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD>u_le_xΪ<78>廬<EFBFBD><E5BBAC><EFBFBD>ٶ<EFBFBD>
|
|||
|
double calculate_fg(int i, int j, int k, int w, double feq);//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|||
|
double calculate_fneq(int i, int j, int k, int w, double feq);//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ƽ<EFBFBD><C6BD><EFBFBD>ֲ<EFBFBD><D6B2><EFBFBD><EFBFBD><EFBFBD>
|
|||
|
double calculate_pij(double* fneq); //<2F><><EFBFBD>㶯<EFBFBD><E3B6AF>...
|
|||
|
void lookup_reverse(); //<2F><> i <20><><EFBFBD><EFBFBD><EFBFBD>ķ<EFBFBD><C4B7><EFBFBD><EFBFBD><EFBFBD>
|
|||
|
//MRT
|
|||
|
void iniMRT(); //MRT<52><54><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʼ<EFBFBD><CABC>
|
|||
|
void calculate_MSM(double tau); //MRT<52><54><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|||
|
void read_Geo(std::string filename, int mpi_rank); //<2F><><EFBFBD>븴<EFBFBD><EBB8B4><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|||
|
void getNumberFromString(string s, int* a, int n);
|
|||
|
bool IntersectTriangle(vector3<double>& orig, vector3<double>& dir, //<2F>жϹ<D0B6><CFB9><EFBFBD><EFBFBD><EFBFBD>
|
|||
|
vector3<double>& v0, vector3<double>& v1, vector3<double>& v2,
|
|||
|
double* t, double* u, double* v);
|
|||
|
void check_converge(); //<2F><>֤<EFBFBD>Ƿ<EFBFBD><C7B7><EFBFBD><EFBFBD><EFBFBD>
|
|||
|
};
|
|||
|
|
|||
|
void RUNPHLBM(int mpi_rank);
|
|||
|
void dumpstring(char* str, FILE* file);
|