LBPM/tests/TestPoiseuille.cpp

132 lines
3.6 KiB
C++
Raw Permalink Normal View History

2018-01-24 15:41:40 -06:00
//*************************************************************************
// Lattice Boltzmann Simulator for Single Phase Flow in Porous Media
// James E. McCLure
//*************************************************************************
#include <stdio.h>
#include <iostream>
#include <fstream>
#include "common/ScaLBL.h"
2021-01-05 17:43:44 -06:00
#include "common/MPI.h"
2018-05-19 18:42:58 -05:00
#include "models/MRTModel.h"
2018-01-24 15:41:40 -06:00
2018-05-19 19:22:16 -05:00
void ParallelPlates(ScaLBL_MRTModel &MRT){
// initialize empty domain
2018-05-19 19:25:16 -05:00
int i,j,k,n;
2018-05-19 19:22:16 -05:00
int Nx = MRT.Nx;
int Ny = MRT.Ny;
int Nz = MRT.Nz;
2019-10-25 05:07:01 -05:00
Array<char> id_solid(Nx,Ny,Nz);
2018-05-19 19:22:16 -05:00
for (k=0;k<Nz;k++){
for (j=0;j<Ny;j++){
for (i=0;i<Nx;i++){
n = k*Nx*Ny+j*Nx+i;
if (i<2) MRT.Mask->id[n] = 0;
else if (i>Nx-3) MRT.Mask->id[n] = 0;
else MRT.Mask->id[n]=1;
2019-10-25 05:07:01 -05:00
if (MRT.Mask->id[n] == 0) id_solid(i,j,k) = 1;
else id_solid(i,j,k) = 0;
}
}
}
// Initialize the signed distance function
for (int k=0;k<Nz;k++){
for (int j=0;j<Ny;j++){
for (int i=0;i<Nx;i++){
// Initialize distance to +/- 1
MRT.Distance(i,j,k) = 2.0*double(id_solid(i,j,k))-1.0;
2018-05-19 19:22:16 -05:00
}
}
}
2019-10-25 05:10:55 -05:00
if (MRT.rank==0) printf("Initialized solid phase -- Converting to Signed Distance function \n");
2019-10-25 05:07:01 -05:00
CalcDist(MRT.Distance,id_solid,*MRT.Dm);
2019-10-25 05:10:55 -05:00
if (MRT.rank == 0) cout << "Domain set." << endl;
2018-05-19 19:22:16 -05:00
}
2018-01-24 15:41:40 -06:00
//***************************************************************************************
int main(int argc, char **argv)
{
// Initialize MPI
2021-01-05 17:43:44 -06:00
Utilities::startup( argc, argv );
2020-01-28 07:51:32 -06:00
Utilities::MPI comm( MPI_COMM_WORLD );
2021-01-05 17:43:44 -06:00
int rank = comm.getRank();
int nprocs = comm.getSize();
2018-05-15 15:29:32 -05:00
int check=0;
2018-01-24 15:41:40 -06:00
{
if (rank == 0){
printf("********************************************************\n");
printf("Running Unit Test: TestPoiseuille \n");
printf("********************************************************\n");
}
2018-05-19 18:42:58 -05:00
2018-05-19 18:54:46 -05:00
int i,j,k,n;
2018-05-19 18:42:58 -05:00
ScaLBL_MRTModel MRT(rank,nprocs,comm);
2018-05-19 18:54:46 -05:00
auto filename = argv[1];
2018-05-19 18:42:58 -05:00
MRT.ReadParams(filename);
2018-05-19 18:54:46 -05:00
MRT.SetDomain(); // this reads in the domain
2018-05-19 19:22:16 -05:00
ParallelPlates(MRT);
2018-05-19 18:42:58 -05:00
MRT.Create(); // creating the model will create data structure to match the pore structure and allocate variables
MRT.Initialize(); // initializing the model will set initial conditions for variables
MRT.Run();
2018-07-29 10:58:11 -05:00
double *Vz; Vz= new double [3*MRT.Np];
2018-05-19 18:42:58 -05:00
2018-08-27 10:40:29 -05:00
int SIZE=MRT.Np*sizeof(double);
ScaLBL_D3Q19_Momentum(MRT.fq,MRT.Velocity, MRT.Np);
2021-01-05 17:43:44 -06:00
ScaLBL_DeviceBarrier(); comm.barrier();
2018-08-27 10:40:29 -05:00
ScaLBL_CopyToHost(&Vz[0],&MRT.Velocity[0],3*SIZE);
2018-05-19 18:42:58 -05:00
if (rank == 0) printf("Force: %f,%f,%f \n",MRT.Fx,MRT.Fy,MRT.Fz);
double mu = MRT.mu;
int Nx = MRT.Nx;
int Ny = MRT.Ny;
int Nz = MRT.Nz;
double Fz = MRT.Fz;
2018-01-24 15:41:40 -06:00
double vz;
double W = 1.f*Nx-4.f;
j=Ny/2; k=Nz/2;
if (rank == 0) printf("Channel width=%f \n",W);
if (rank == 0) printf("ID flag vz analytical\n");
2021-01-05 17:43:44 -06:00
comm.barrier();
2018-05-19 18:42:58 -05:00
2018-01-24 15:41:40 -06:00
if (rank == 0) {
for (i=0;i<Nx;i++){
n = k*Nx*Ny+j*Nx+i;
2018-05-19 18:42:58 -05:00
printf("%i ",MRT.Mask->id[n]);
n = MRT.Map(i,j,k);
2018-01-24 15:41:40 -06:00
//printf("%i,%i,%i; %i :",i,j,k,n);
if (n<0) {vz =0.f; printf(" b "); }
2018-07-29 10:58:11 -05:00
else { vz=Vz[n+2*MRT.Np]; printf(" a "); }
2018-01-24 15:41:40 -06:00
printf("%f ",vz);
//Analytical solution
double x=1.f*i-1.5;
if (n<0) vz=0.f;
else vz=Fz*x*(W-x)/(2.f*mu);
printf("%f\n",vz);
}
printf("\n");
}
if (rank == 1) {
for (i=0;i<Nx;i++){
n = k*Nx*Ny+j*Nx+i;
2018-05-19 18:42:58 -05:00
printf("%i ",MRT.Mask->id[n]);
n = MRT.Map(i,j,k);
2018-01-24 15:41:40 -06:00
//printf("%i,%i,%i; %i :",i,j,k,n);
if (n<0) {vz =0.f; printf(" b "); }
2018-07-29 10:58:11 -05:00
else { vz=Vz[n+2*MRT.Np]; printf(" a "); }
2018-01-24 15:41:40 -06:00
printf("%f ",vz);
//Analytical solution
double x=1.f*i-1.5;
if (n<0) vz=0.f;
else vz=Fz*x*(W-x)/(2.f*mu);
printf("%f\n",vz);
}
printf("\n");
}
}
2021-01-05 17:43:44 -06:00
Utilities::shutdown();
2018-01-24 15:41:40 -06:00
return check;
}