Files
LBPM/tests/TestPressVel.cpp

195 lines
5.9 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"
2021-01-05 18:43:44 -05:00
#include "common/MPI.h"
2018-01-24 16:41:40 -05:00
2018-05-15 10:01:14 -04:00
2018-01-24 16:41:40 -05:00
//***************************************************************************************
int main(int argc, char **argv)
{
// Initialize MPI
2021-01-05 18:43:44 -05:00
Utilities::startup( argc, argv );
2020-01-28 08:51:32 -05:00
Utilities::MPI comm( MPI_COMM_WORLD );
2021-01-05 18:43:44 -05:00
int rank = comm.getRank();
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: TestPressVel \n");
printf("********************************************************\n");
}
2018-05-15 15:00:26 -04:00
2018-01-24 16:41:40 -05:00
// Domain variables
int i,j,k,n;
2018-05-15 10:01:14 -04:00
// Load inputs
2018-05-15 15:00:26 -04:00
string FILENAME = argv[1];
2018-05-15 16:03:29 -04:00
// Load inputs
2018-05-15 14:40:38 -04:00
if (rank==0) printf("Loading input database \n");
2018-05-15 16:21:38 -04:00
auto db = std::make_shared<Database>( FILENAME );
auto domain_db = db->getDatabase( "Domain" );
int Nx = domain_db->getVector<int>( "n" )[0];
2018-05-15 14:40:38 -04:00
int Ny = domain_db->getVector<int>( "n" )[1];
int Nz = domain_db->getVector<int>( "n" )[2];
int nprocx = domain_db->getVector<int>( "nproc" )[0];
int nprocy = domain_db->getVector<int>( "nproc" )[1];
int nprocz = domain_db->getVector<int>( "nproc" )[2];
2018-01-24 16:41:40 -05:00
if (rank==0){
printf("********************************************************\n");
printf("Sub-domain size = %i x %i x %i\n",Nx,Ny,Nz);
printf("********************************************************\n");
}
2021-01-05 18:43:44 -05:00
comm.barrier();
2018-05-15 10:01:14 -04:00
int kproc = rank/(nprocx*nprocy);
int jproc = (rank-nprocx*nprocy*kproc)/nprocx;
int iproc = rank-nprocx*nprocy*kproc-nprocz*jproc;
2018-01-24 16:41:40 -05:00
if (rank == 0) {
printf("i,j,k proc=%d %d %d \n",iproc,jproc,kproc);
}
2021-01-05 18:43:44 -05:00
comm.barrier();
2018-01-24 16:41:40 -05:00
if (rank == 1){
printf("i,j,k proc=%d %d %d \n",iproc,jproc,kproc);
printf("\n\n");
}
double iVol_global = 1.0/Nx/Ny/Nz/nprocx/nprocy/nprocz;
2018-05-19 07:49:32 -04:00
std::shared_ptr<Domain> Dm (new Domain(domain_db,comm));
Dm->CommInit();
2018-01-24 16:41:40 -05:00
Nx += 2;
Ny += 2;
Nz += 2;
int N = Nx*Ny*Nz;
//.......................................................................
// Assign the phase ID field
//.......................................................................
char LocalRankString[8];
sprintf(LocalRankString,"%05d",rank);
char LocalRankFilename[40];
sprintf(LocalRankFilename,"ID.%05i",rank);
2018-05-19 07:49:32 -04:00
Dm->CommInit();
2018-01-24 16:41:40 -05:00
//.......................................................................
// Compute the media porosity
//.......................................................................
double sum;
double sum_local=0.0, porosity;
int Np=0; // number of local pore nodes
for (k=1;k<Nz-1;k++){
for (j=1;j<Ny-1;j++){
for (i=1;i<Nx-1;i++){
n = k*Nx*Ny+j*Nx+i;
2018-05-17 21:03:11 -04:00
Dm->id[n] = 1;
if (Dm->id[n] > 0){
2018-01-24 16:41:40 -05:00
sum_local+=1.0;
Np++;
}
}
}
}
2021-01-05 18:43:44 -05:00
sum = comm.sumReduce( sum_local );
2018-01-24 16:41:40 -05:00
porosity = sum*iVol_global;
if (rank==0) printf("Media porosity = %f \n",porosity);
2021-01-05 18:43:44 -05:00
comm.barrier();
2018-01-24 16:41:40 -05:00
if (rank == 0) cout << "Domain set." << endl;
if (rank==0) printf ("Create ScaLBL_Communicator \n");
// Create a communicator for the device
auto ScaLBL_Comm = std::make_shared<ScaLBL_Communicator>( Dm );
2018-01-24 16:41:40 -05:00
//...........device phase ID.................................................
if (rank==0) printf ("Copying phase ID to device \n");
char *ID;
ScaLBL_AllocateDeviceMemory((void **) &ID, N); // Allocate device memory
// Copy to the device
ScaLBL_CopyToDevice(ID, Dm->id.data(), N);
2018-01-24 16:41:40 -05:00
//...........................................................................
if (rank==0){
printf("Total domain size = %i \n",N);
printf("Reduced domain size = %i \n",Np);
}
// LBM variables
2018-05-15 14:34:32 -04:00
if (rank==0) printf ("Set up the neighborlist \n");
int Npad=Np+32;
int neighborSize=18*Npad*sizeof(int);
2018-01-24 16:41:40 -05:00
int *neighborList;
IntArray Map(Nx,Ny,Nz);
2018-05-15 14:34:32 -04:00
neighborList= new int[18*Npad];
Np = ScaLBL_Comm->MemoryOptimizedLayoutAA(Map,neighborList,Dm->id.data(),Np);
2020-01-28 08:51:32 -05:00
comm.barrier();
2018-01-24 16:41:40 -05:00
//......................device distributions.................................
2018-05-15 14:34:32 -04:00
if (rank==0) printf ("Allocating distributions \n");
2018-01-24 16:41:40 -05:00
int dist_mem_size = Np*sizeof(double);
int *NeighborList;
double * dist;
double * Velocity;
//...........................................................................
ScaLBL_AllocateDeviceMemory((void **) &dist, 19*dist_mem_size);
ScaLBL_AllocateDeviceMemory((void **) &NeighborList, neighborSize);
ScaLBL_AllocateDeviceMemory((void **) &Velocity, 3*sizeof(double)*Np);
ScaLBL_CopyToDevice(NeighborList, neighborList, neighborSize);
//...........................................................................
/*
* AA Algorithm begins here
*
*/
double *DIST;
DIST = new double [19*Np];
double VALUE=0.1;
for (int n=0; n<Np; n++){
//DIST[n]=1.0;
// even distributions
DIST[Np + n] = 1.0 - VALUE;
DIST[2*Np + n] = 1.0 - VALUE;
DIST[3*Np + n] = 1.0 - VALUE;
DIST[4*Np + n] = 1.0;
DIST[5*Np + n] = 1.0;
DIST[6*Np + n] = 1.0;
DIST[7*Np + n] = 1.0;
DIST[8*Np + n] = 1.0;
DIST[9*Np + n] = 1.0;
// odd distributions
DIST[10*Np + n] = 1.0;
DIST[11*Np + n] = 1.0;
DIST[12*Np + n] = 1.0;
DIST[13*Np + n] = 1.0;
DIST[14*Np + n] = 1.0;
DIST[15*Np + n] = 1.0;
DIST[16*Np + n] = 1.0;
DIST[17*Np + n] = 1.0;
DIST[18*Np + n] = 1.0;
}
ScaLBL_CopyToDevice(dist, DIST, 19*Np*sizeof(double));
double *Vz;
Vz= new double [Np];
size_t SIZE=Np*sizeof(double);
ScaLBL_D3Q19_Momentum(dist, Velocity, Np);
ScaLBL_CopyToHost(&Vz[0],&Velocity[2],SIZE);
//
for (int n=0; n<Np; n++){
if (Vz[n] - VALUE > 1e-8){
printf("ERROR: site %i, value=%f \n",n,Vz[n]); check = 15;
}
}
}
2021-01-05 18:43:44 -05:00
Utilities::shutdown();
2018-05-15 16:29:32 -04:00
return check;
2021-01-05 18:43:44 -05:00
2018-01-24 16:41:40 -05:00
}