Files
LBPM/tests/TestPoiseuille.cpp

123 lines
3.3 KiB
C++
Raw Normal View History

2018-01-24 16:41:40 -05: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"
#include "common/MPI_Helpers.h"
2018-05-19 19:42:58 -04:00
#include "models/MRTModel.h"
2018-01-24 16:41:40 -05:00
2018-05-19 20:22:16 -04:00
void ParallelPlates(ScaLBL_MRTModel &MRT){
// initialize empty domain
2018-05-19 20:25:16 -04:00
int i,j,k,n;
2018-05-19 20:22:16 -04:00
int Nx = MRT.Nx;
int Ny = MRT.Ny;
int Nz = MRT.Nz;
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;
}
}
}
}
2018-01-24 16:41:40 -05:00
//***************************************************************************************
int main(int argc, char **argv)
{
//*****************************************
// ***** MPI STUFF ****************
//*****************************************
// Initialize MPI
int rank,nprocs;
MPI_Init(&argc,&argv);
MPI_Comm comm = MPI_COMM_WORLD;
MPI_Comm_rank(comm,&rank);
MPI_Comm_size(comm,&nprocs);
2018-05-15 16:29:32 -04:00
int check=0;
2018-01-24 16:41:40 -05:00
{
if (rank == 0){
printf("********************************************************\n");
printf("Running Unit Test: TestPoiseuille \n");
printf("********************************************************\n");
}
2018-05-19 19:42:58 -04:00
2018-05-19 19:54:46 -04:00
int i,j,k,n;
2018-05-19 19:42:58 -04:00
ScaLBL_MRTModel MRT(rank,nprocs,comm);
2018-05-19 19:54:46 -04:00
auto filename = argv[1];
2018-05-19 19:42:58 -04:00
MRT.ReadParams(filename);
2018-05-19 19:54:46 -04:00
MRT.SetDomain(); // this reads in the domain
2018-05-19 20:22:16 -04:00
ParallelPlates(MRT);
2018-05-19 19:42:58 -04: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 11:58:11 -04:00
double *Vz; Vz= new double [3*MRT.Np];
2018-05-19 19:42:58 -04:00
2018-08-27 11:40:29 -04:00
int SIZE=MRT.Np*sizeof(double);
ScaLBL_D3Q19_Momentum(MRT.fq,MRT.Velocity, MRT.Np);
ScaLBL_DeviceBarrier(); MPI_Barrier(comm);
ScaLBL_CopyToHost(&Vz[0],&MRT.Velocity[0],3*SIZE);
2018-05-19 19:42:58 -04: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 16:41:40 -05: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");
MPI_Barrier(comm);
2018-05-19 19:42:58 -04:00
2018-01-24 16:41:40 -05:00
if (rank == 0) {
for (i=0;i<Nx;i++){
n = k*Nx*Ny+j*Nx+i;
2018-05-19 19:42:58 -04:00
printf("%i ",MRT.Mask->id[n]);
n = MRT.Map(i,j,k);
2018-01-24 16:41:40 -05:00
//printf("%i,%i,%i; %i :",i,j,k,n);
if (n<0) {vz =0.f; printf(" b "); }
2018-07-29 11:58:11 -04:00
else { vz=Vz[n+2*MRT.Np]; printf(" a "); }
2018-01-24 16:41:40 -05: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 19:42:58 -04:00
printf("%i ",MRT.Mask->id[n]);
n = MRT.Map(i,j,k);
2018-01-24 16:41:40 -05:00
//printf("%i,%i,%i; %i :",i,j,k,n);
if (n<0) {vz =0.f; printf(" b "); }
2018-07-29 11:58:11 -04:00
else { vz=Vz[n+2*MRT.Np]; printf(" a "); }
2018-01-24 16:41:40 -05: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");
}
}
// ****************************************************
MPI_Barrier(comm);
MPI_Finalize();
// ****************************************************
return check;
}