Added TestMap from ScaLBL
This commit is contained in:
parent
f9efe6a47b
commit
ec9d7b146f
@ -36,6 +36,7 @@ ADD_LBPM_TEST( pmmc_cylinder )
|
||||
#ADD_LBPM_TEST( TestBubble )
|
||||
ADD_LBPM_TEST( TestTorus )
|
||||
ADD_LBPM_TEST( TestFluxBC )
|
||||
ADD_LBPM_TEST( TestMap )
|
||||
ADD_LBPM_TEST( TestInterfaceSpeed )
|
||||
ADD_LBPM_TEST( TestSphereCurvature )
|
||||
#ADD_LBPM_TEST_1_2_4( TestTwoPhase )
|
||||
|
270
tests/TestMap.cpp
Normal file
270
tests/TestMap.cpp
Normal file
@ -0,0 +1,270 @@
|
||||
|
||||
//*************************************************************************
|
||||
// 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"
|
||||
|
||||
using namespace std;
|
||||
|
||||
//***************************************************************************************
|
||||
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);
|
||||
int check;
|
||||
{
|
||||
// parallel domain size (# of sub-domains)
|
||||
int nprocx,nprocy,nprocz;
|
||||
int iproc,jproc,kproc;
|
||||
|
||||
|
||||
if (rank == 0){
|
||||
printf("********************************************************\n");
|
||||
printf("Running Color Model: TestColor \n");
|
||||
printf("********************************************************\n");
|
||||
}
|
||||
|
||||
// BGK Model parameters
|
||||
string FILENAME;
|
||||
unsigned int nBlocks, nthreads;
|
||||
int timestepMax, interval;
|
||||
double Fx,Fy,Fz,tol;
|
||||
// Domain variables
|
||||
double Lx,Ly,Lz;
|
||||
int nspheres;
|
||||
int Nx,Ny,Nz;
|
||||
int i,j,k,n;
|
||||
int dim=5;
|
||||
|
||||
static int D3Q19[18][3]={{1,0,0},{-1,0,0},{0,1,0},{0,-1,0},{0,0,1},{0,0,-1},
|
||||
{1,1,0},{-1,-1,0},{1,-1,0},{-1,1,0},
|
||||
{1,0,1},{-1,0,-1},{1,0,-1},{-1,0,1},
|
||||
{0,1,1},{0,-1,-1},{0,1,-1},{0,-1,1}};
|
||||
|
||||
if (rank==0){
|
||||
//.......................................................................
|
||||
// Reading the domain information file
|
||||
//.......................................................................
|
||||
ifstream domain("Domain.in");
|
||||
if (domain.good()){
|
||||
domain >> nprocx;
|
||||
domain >> nprocy;
|
||||
domain >> nprocz;
|
||||
domain >> Nx;
|
||||
domain >> Ny;
|
||||
domain >> Nz;
|
||||
domain >> nspheres;
|
||||
domain >> Lx;
|
||||
domain >> Ly;
|
||||
domain >> Lz;
|
||||
}
|
||||
else if (nprocs==1){
|
||||
nprocx=nprocy=nprocz=1;
|
||||
Nx=Ny=Nz=5;
|
||||
nspheres=0;
|
||||
Lx=Ly=Lz=1;
|
||||
}
|
||||
else if (nprocs==2){
|
||||
nprocx=2; nprocy=1;
|
||||
nprocz=1;
|
||||
Nx=Ny=Nz=dim;
|
||||
Nx = dim; Ny = dim; Nz = dim;
|
||||
nspheres=0;
|
||||
Lx=Ly=Lz=1;
|
||||
}
|
||||
else if (nprocs==4){
|
||||
nprocx=nprocy=2;
|
||||
nprocz=1;
|
||||
Nx=Ny=Nz=dim;
|
||||
nspheres=0;
|
||||
Lx=Ly=Lz=1;
|
||||
}
|
||||
else if (nprocs==8){
|
||||
nprocx=nprocy=nprocz=2;
|
||||
Nx=Ny=Nz=dim;
|
||||
nspheres=0;
|
||||
Lx=Ly=Lz=1;
|
||||
}
|
||||
//.......................................................................
|
||||
}
|
||||
// **************************************************************
|
||||
// Broadcast simulation parameters from rank 0 to all other procs
|
||||
MPI_Barrier(comm);
|
||||
//.................................................
|
||||
MPI_Bcast(&Nx,1,MPI_INT,0,comm);
|
||||
MPI_Bcast(&Ny,1,MPI_INT,0,comm);
|
||||
MPI_Bcast(&Nz,1,MPI_INT,0,comm);
|
||||
MPI_Bcast(&nprocx,1,MPI_INT,0,comm);
|
||||
MPI_Bcast(&nprocy,1,MPI_INT,0,comm);
|
||||
MPI_Bcast(&nprocz,1,MPI_INT,0,comm);
|
||||
MPI_Bcast(&nspheres,1,MPI_INT,0,comm);
|
||||
MPI_Bcast(&Lx,1,MPI_DOUBLE,0,comm);
|
||||
MPI_Bcast(&Ly,1,MPI_DOUBLE,0,comm);
|
||||
MPI_Bcast(&Lz,1,MPI_DOUBLE,0,comm);
|
||||
//.................................................
|
||||
MPI_Barrier(comm);
|
||||
// **************************************************************
|
||||
// **************************************************************
|
||||
|
||||
if (nprocs != nprocx*nprocy*nprocz){
|
||||
printf("nprocx = %i \n",nprocx);
|
||||
printf("nprocy = %i \n",nprocy);
|
||||
printf("nprocz = %i \n",nprocz);
|
||||
INSIST(nprocs == nprocx*nprocy*nprocz,"Fatal error in processor count!");
|
||||
}
|
||||
|
||||
if (rank==0){
|
||||
printf("********************************************************\n");
|
||||
printf("Sub-domain size = %i x %i x %i\n",Nx,Ny,Nz);
|
||||
printf("********************************************************\n");
|
||||
}
|
||||
|
||||
MPI_Barrier(comm);
|
||||
int BoundaryCondition=0;
|
||||
|
||||
Domain Dm(Nx,Ny,Nz,rank,nprocx,nprocy,nprocz,Lx,Ly,Lz,BoundaryCondition);
|
||||
|
||||
Nx += 2;
|
||||
Ny += 2;
|
||||
Nz += 2;
|
||||
int N = Nx*Ny*Nz;
|
||||
|
||||
//.......................................................................
|
||||
int Np = 0;
|
||||
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;
|
||||
Dm.id[n] = 1;
|
||||
Np++;
|
||||
}
|
||||
}
|
||||
}
|
||||
Dm.CommInit(comm);
|
||||
|
||||
// Create a communicator for the device (will use optimized layout)
|
||||
ScaLBL_Communicator ScaLBL_Comm(Dm);
|
||||
//Create a second communicator based on the regular data layout
|
||||
ScaLBL_Communicator ScaLBL_Comm_Regular(Dm);
|
||||
|
||||
|
||||
if (rank==0){
|
||||
printf("Total domain size = %i \n",N);
|
||||
printf("Reduced domain size = %i \n",Np);
|
||||
}
|
||||
|
||||
// LBM variables
|
||||
if (rank==0) printf ("Set up the neighborlist \n");
|
||||
|
||||
int neighborSize=18*Np*sizeof(int);
|
||||
int *neighborList;
|
||||
IntArray Map(Nx,Ny,Nz);
|
||||
neighborList= new int[18*Np];
|
||||
|
||||
ScaLBL_Comm.MemoryOptimizedLayoutAA(Map,neighborList,Dm.id,Np);
|
||||
MPI_Barrier(comm);
|
||||
|
||||
//......................device distributions.................................
|
||||
int dist_mem_size = Np*sizeof(double);
|
||||
if (rank==0) printf ("Allocating distributions \n");
|
||||
|
||||
int *NeighborList;
|
||||
int *dvcMap;
|
||||
|
||||
//...........................................................................
|
||||
ScaLBL_AllocateDeviceMemory((void **) &NeighborList, neighborSize);
|
||||
ScaLBL_AllocateDeviceMemory((void **) &dvcMap, sizeof(int)*Np);
|
||||
|
||||
//...........................................................................
|
||||
// Update GPU data structures
|
||||
if (rank==0) printf ("Setting up device map and neighbor list \n");
|
||||
int *TmpMap;
|
||||
TmpMap=new int[Np*sizeof(int)];
|
||||
for (k=1; k<Nz-1; k++){
|
||||
for (j=1; j<Ny-1; j++){
|
||||
for (i=1; i<Nx-1; i++){
|
||||
int idx=Map(i,j,k);
|
||||
if (!(idx < 0))
|
||||
TmpMap[idx] = k*Nx*Ny+j*Nx+i;
|
||||
}
|
||||
}
|
||||
}
|
||||
ScaLBL_CopyToDevice(dvcMap, TmpMap, sizeof(int)*Np);
|
||||
ScaLBL_DeviceBarrier();
|
||||
|
||||
// Create a dummy distribution data structure
|
||||
double *fq;
|
||||
fq = new double[19*Np];
|
||||
|
||||
for (k=1; k<Nz-1; k++){
|
||||
for (j=1; j<Ny-1; j++){
|
||||
for (i=1; i<Nx-1; i++){
|
||||
int idx=Map(i,j,k);
|
||||
if (!(idx<0)){
|
||||
for (int q=0; q<19; q++){
|
||||
fq[q*Np+idx]=k*100.f+j*10.f+i*1.f+0.01*q;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
/* for (int idx=0; idx<Np; idx++){
|
||||
n = TmpMap[idx];
|
||||
// back out the 3D indices
|
||||
k = n/(Nx*Ny);
|
||||
j = (n-Nx*Ny*k)/Nx;
|
||||
i = n-Nx*Ny*k-Nx*j;
|
||||
for (int q=0; q<19; q++){
|
||||
fq[q*Np+idx]=k*100.f+j*10.f+i*1.f+0.01*q;
|
||||
}
|
||||
}
|
||||
*/
|
||||
// Loop over the distributions for interior lattice sites
|
||||
int start=ScaLBL_Comm.next;
|
||||
for (int idx=start; idx<Np; idx++){
|
||||
n = TmpMap[idx];
|
||||
k = n/(Nx*Ny);
|
||||
j = (n-Nx*Ny*k)/Nx;
|
||||
i = n-Nx*Ny*k-Nx*j;
|
||||
for (int q=1; q<19; q++){
|
||||
int nn = neighborList[(q-1)*Np+idx];
|
||||
double value=fq[nn];
|
||||
// 3D index of neighbor
|
||||
int iq=i-D3Q19[q-1][0];
|
||||
int jq=j-D3Q19[q-1][1];
|
||||
int kq=k-D3Q19[q-1][2];
|
||||
if (iq==0) iq=1;
|
||||
if (jq==0) jq=1;
|
||||
if (kq==0) kq=1;
|
||||
if (iq==Nx-1) iq=Nx-2;
|
||||
if (jq==Ny-1) jq=Ny-2;
|
||||
if (kq==Nz-1) kq=Nz-2;
|
||||
double check = kq*100.f+jq*10.f+iq*1.f+q*0.01;
|
||||
if (value != check)
|
||||
printf("Neighbor q=%i, i=%i,j=%i,k=%i: %f \n",q,iq,jq,kq,value);
|
||||
}
|
||||
}
|
||||
|
||||
delete [] TmpMap;
|
||||
|
||||
}
|
||||
// ****************************************************
|
||||
MPI_Barrier(comm);
|
||||
MPI_Finalize();
|
||||
// ****************************************************
|
||||
|
||||
return check;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user