Files
LBPM/tests/TestColorBubble.cpp

100 lines
3.1 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-05-17 10:18:57 -04:00
#include "models/ColorModel.h"
2018-01-24 16:41:40 -05:00
using namespace std;
2018-05-18 11:19:17 -04:00
inline void InitializeBubble(ScaLBL_ColorModel &ColorModel, double BubbleRadius){
2018-05-18 17:24:17 -04:00
// initialize a bubble
int i,j,k,n;
int rank = ColorModel.Dm->rank();
int nprocx = ColorModel.Dm->nprocx();
int nprocy = ColorModel.Dm->nprocy();
int nprocz = ColorModel.Dm->nprocz();
int Nx = ColorModel.Dm->Nx;
int Ny = ColorModel.Dm->Ny;
int Nz = ColorModel.Dm->Nz;
2018-05-18 17:24:17 -04:00
if (rank == 0) cout << "Setting up bubble..." << endl;
for (k=0;k<Nz;k++){
for (j=0;j<Ny;j++){
for (i=0;i<Nx;i++){
n = k*Nx*Ny + j*Nz + i;
ColorModel.Averages->SDs(i,j,k) = 100.f;
}
2018-01-24 16:41:40 -05:00
}
2018-05-18 17:24:17 -04:00
}
// Initialize the bubble
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;
double iglobal= double(i+(Nx-2)*ColorModel.Dm->iproc())-double((Nx-2)*nprocx)*0.5;
double jglobal= double(j+(Ny-2)*ColorModel.Dm->jproc())-double((Ny-2)*nprocy)*0.5;
double kglobal= double(k+(Nz-2)*ColorModel.Dm->kproc())-double((Nz-2)*nprocz)*0.5;
2018-05-18 17:24:17 -04:00
// Initialize phase position field for parallel bubble test
if ((iglobal*iglobal)+(jglobal*jglobal)+(kglobal*kglobal) < BubbleRadius*BubbleRadius){
2018-05-19 17:28:39 -04:00
ColorModel.Mask->id[n] = 2;
ColorModel.Mask->id[n] = 2;
2018-05-18 17:24:17 -04:00
}
else{
2018-05-19 17:28:39 -04:00
ColorModel.Mask->id[n]=1;
ColorModel.Mask->id[n]=1;
2018-05-18 17:24:17 -04:00
}
2019-03-24 20:48:34 -04:00
ColorModel.id[n] = ColorModel.Mask->id[n];
ColorModel.Dm->id[n] = ColorModel.Mask->id[n];
2018-05-18 17:24:17 -04:00
}
2018-01-24 16:41:40 -05:00
}
2018-05-18 17:24:17 -04:00
}
FILE *OUTFILE;
char LocalRankFilename[40];
sprintf(LocalRankFilename,"Bubble.%05i.raw",rank);
OUTFILE = fopen(LocalRankFilename,"wb");
fwrite(ColorModel.id,1,Nx*Ny*Nz,OUTFILE);
fclose(OUTFILE);
2018-05-21 10:13:23 -04:00
// initialize the phase indicator field
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();
int nprocs = comm.getSize();
2018-05-18 17:24:17 -04:00
int check=0;
2018-01-24 16:41:40 -05:00
{
if (rank == 0){
printf("********************************************************\n");
printf("Running Color Model: TestColor \n");
printf("********************************************************\n");
2018-05-17 10:14:49 -04:00
if ( argc < 2 ) {
std::cerr << "Invalid number of arguments, no input file specified\n";
return -1;
2018-01-24 16:41:40 -05:00
}
}
2018-05-17 10:14:49 -04:00
auto filename = argv[1];
2018-05-18 17:24:17 -04:00
ScaLBL_ColorModel ColorModel(rank,nprocs,comm);
2018-05-17 10:14:49 -04:00
ColorModel.ReadParams(filename);
2018-05-19 17:28:39 -04:00
ColorModel.SetDomain();
//ColorModel.ReadInput();
2018-05-18 11:19:17 -04:00
double radius=15.5;
InitializeBubble(ColorModel,radius);
2018-05-19 17:28:39 -04:00
ColorModel.Create(); // creating the model will create data structure to match the pore structure and allocate variables
ColorModel.Initialize(); // initializing the model will set initial conditions for variables
ColorModel.Run();
2018-05-18 17:24:17 -04:00
ColorModel.WriteDebug();
2018-01-24 16:41:40 -05:00
}
2021-01-05 18:43:44 -05:00
Utilities::shutdown();
2018-01-24 16:41:40 -05:00
return check;
}