Working on moving to Database

This commit is contained in:
Mark Berrill
2018-05-15 11:30:12 -04:00
parent d3e91bc829
commit 98bbdd2458
6 changed files with 83 additions and 125 deletions

View File

@@ -1,6 +1,7 @@
#ifndef included_Database
#define included_Database
#include <fstream>
#include <iostream>
#include <map>
#include <memory>
@@ -10,6 +11,13 @@
#include "common/Units.h"
inline bool exists( const std::string& filename )
{
std::ifstream domain( filename );
return domain.good();
}
//! Base class to hold data of a given type
class KeyData
{

View File

@@ -1,6 +0,0 @@
1.0
1.0e-2 0.95 0.8
0.7
0.0 0.0 0.0
0 0 1.0 1.0
200 1000 1e-5

View File

@@ -1,3 +0,0 @@
1 1 1
80 80 80
1.0 1.0 1.0

28
example/Bubble/input.in Normal file
View File

@@ -0,0 +1,28 @@
Color {
tau = 1.0;
alpha = 1e-2;
beta = 0.95;
phi_s = 0.8;
wp_saturation = 0.7
F = 0, 0, 0
Restart = false
pBC = 0
din = 1.0
dout = 1.0
timestepMax = 200
interval = 1000
tol = 1e-5;
das = 0.1
dbs = 0.9
}
Domain {
nproc = 1, 1, 1 // Number of processors (Npx,Npy,Npz)
n = 80, 80, 80 // Size of local domain (Nx,Ny,Nz)
n_spheres = 1 // Number of spheres
L = 1, 1, 1 // Length of domain (x,y,z)
}
Analysis {
}

View File

@@ -16,6 +16,17 @@
using namespace std;
std::shared_ptr<Database> readInput( const std::string& file )
{
if ( exists( file )
return std::make_shared<Database>( file );
auto db = std::make_shared<Database>();
db.putData( "Color", std::make_shared<Database>() );
db.putData( "Domain", std::make_shared<Database>() );
return db;
}
int main(int argc, char **argv)
{
// Initialize MPI
@@ -54,13 +65,6 @@ int main(int argc, char **argv)
int nspheres;
double Lx,Ly,Lz;
// Color Model parameters
int timestepMax, interval;
double tau,Fx,Fy,Fz,tol;
double alpha, beta;
double das, dbs, phi_s;
double din,dout;
double wp_saturation;
bool pBC,Restart;
int i,j,k,n;
// pmmc threshold values
@@ -72,108 +76,42 @@ int main(int argc, char **argv)
int RESTART_INTERVAL=1000;
if (rank==0){
//.............................................................
// READ SIMULATION PARMAETERS FROM INPUT FILE
//.............................................................
ifstream input("Color.in");
if (input.good()){
input >> tau; // Viscosity parameter
input >> alpha; // Surface Tension parameter
input >> beta; // Width of the interface
input >> phi_s; // value of phi at the solid surface
input >> wp_saturation;
input >> Fx;
input >> Fy;
input >> Fz;
input >> Restart;
input >> pBC;
input >> din;
input >> dout;
input >> timestepMax; // max no. of timesteps
input >> interval; // restart interval
input >> tol; // error tolerance
}
else {
printf("WARNING: No valid Color.in file, using hard-coded values \n");
tau = 1.0;
alpha = 1e-3;
beta = 0.95;
phi_s = 0.0;
wp_saturation=Fx=Fy=Fz=0;
Restart = 0;
pBC = 0;
din=dout = 1.0;
timestepMax = 3;
interval = 100;
tol = 1e-6;
das = 0.1; dbs = 0.9; // hard coded for density initialization
// should be OK to remove these parameters
// they should have no impact with the
// current boundary condition
}
//.......................................................................
// 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 {
//.......................................................................
// Set the domain for single processor test
printf("WARNING: No valid Domain.in file, using hard-coded values \n");
nprocx=nprocy=nprocz=1;
Nx=Ny=Nz=50;
nspheres=1;
Lx=Ly=Lz=1;
}
auto db = readInput( "input.in" );
}
// **************************************************************
// Broadcast simulation parameters from rank 0 to all other procs
MPI_Barrier(comm);
//.................................................
MPI_Bcast(&tau,1,MPI_DOUBLE,0,comm);
MPI_Bcast(&alpha,1,MPI_DOUBLE,0,comm);
MPI_Bcast(&beta,1,MPI_DOUBLE,0,comm);
MPI_Bcast(&das,1,MPI_DOUBLE,0,comm);
MPI_Bcast(&dbs,1,MPI_DOUBLE,0,comm);
MPI_Bcast(&phi_s,1,MPI_DOUBLE,0,comm);
MPI_Bcast(&wp_saturation,1,MPI_DOUBLE,0,comm);
MPI_Bcast(&pBC,1,MPI_LOGICAL,0,comm);
MPI_Bcast(&Restart,1,MPI_LOGICAL,0,comm);
MPI_Bcast(&din,1,MPI_DOUBLE,0,comm);
MPI_Bcast(&dout,1,MPI_DOUBLE,0,comm);
MPI_Bcast(&Fx,1,MPI_DOUBLE,0,comm);
MPI_Bcast(&Fy,1,MPI_DOUBLE,0,comm);
MPI_Bcast(&Fz,1,MPI_DOUBLE,0,comm);
MPI_Bcast(&timestepMax,1,MPI_INT,0,comm);
MPI_Bcast(&interval,1,MPI_INT,0,comm);
MPI_Bcast(&tol,1,MPI_DOUBLE,0,comm);
// Computational domain
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(&nBlocks,1,MPI_INT,0,comm);
// MPI_Bcast(&nthreads,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);
//.................................................
// Read variables from Color
auto color_db = db->getDatabase( "Color" );
auto tau = color_db->getScalarWithDefault<double>( "tau", 1.0 );
auto alpha = color_db->getScalarWithDefault<double>( "alpha", 1e-3 );
auto beta = color_db->getScalarWithDefault<double>( "beta", 0.95 );
auto phi_s = color_db->getScalarWithDefault<double>( "phi_s", 0.0 );
auto Fx = color_db->getVectorWithDefault<double>( "F", { 0, 0, 0 } )[0];
auto Fy = color_db->getScalarWithDefault<double>( "F", { 0, 0, 0 } )[1];
auto Fz = color_db->getScalarWithDefault<double>( "F", { 0, 0, 0 } )[2];
auto Restart = color_db->getScalarWithDefault<bool>( "Restart", 0 );
auto pBC = color_db->getScalarWithDefault<double>( "pBC", 0 );
auto din = color_db->getScalarWithDefault<double>( "din", 1.0 );
auto dout = color_db->getScalarWithDefault<double>( "dout", 1.0 );
auto timestepMax = color_db->getScalarWithDefault<int>( "timestepMax", 3 );
auto interval = color_db->getScalarWithDefault<int>( "interval", 100 );
auto tol = color_db->getScalarWithDefault<double>( "tol", 1e-6 );
auto das = color_db->getScalarWithDefault<double>( "das", 0.1 );
auto dbs = color_db->getScalarWithDefault<double>( "dab", 0.9 );
// Read variables from Domain
auto domain_db = db->getDatabase( "Domain" );
auto n = domain_db->getVectorWithDefault<int>( "n", { 50, 50, 50 } );
auto L = domain_db->getVectorWithDefault<double>( "L", { 1.0, 1.0, 1.0 } );
auto nproc = domain_db->getVectorWithDefault<int>( "nproc", { 1, 1, 1 } );
auto nspheres = domain_db->getScalarWithDefault<int>( "nspheres", 1 );
int Nx = n[0];
int Ny = n[1];
int Nz = n[2];
int nprocx = nproc[0];
int nprocy = nproc[1];
int nprocz = nproc[2];
double Lx = L[0];
double Ly = L[1];
double Lz = L[2];
// Get the rank info
const RankInfoStruct rank_info(rank,nprocx,nprocy,nprocz);
@@ -227,7 +165,6 @@ int main(int argc, char **argv)
MPI_Barrier(comm);
Nx+=2; Ny+=2; Nz += 2;
//Nx = Ny = Nz; // Cubic domain
int N = Nx*Ny*Nz;
int dist_mem_size = N*sizeof(double);

View File

@@ -10,12 +10,6 @@
#include "common/MPI_Helpers.h"
bool exists( const std::string& filename )
{
ifstream domain( filename );
return domain.good();
}
std::shared_ptr<Database> loadInputs( int nprocs )
{