25 std::stringstream ss(str);
47 std::vector<std::string> &
split(
const std::string &s,
char delim, std::vector<std::string> &elems)
49 std::stringstream ss(s);
51 while (std::getline(ss, item, delim))
53 elems.push_back(item);
67 std::vector<std::string>
split(
const std::string &s,
char delim)
69 std::vector<std::string> elems;
70 split(s, delim, elems);
92 std::string folder = DB[
"inputs"][
"caseFolder"].get<std::string>();
96 fname = folder +
"/simParams.yaml";
100 fname = folder +
"/flow.yaml";
104 fname = folder +
"/domain.yaml";
108 fname = folder +
"/bodies.yaml";
130 std::string inputs =
"inputs";
131 DB[inputs][
"caseFolder"].set<std::string>(
".");
132 DB[inputs][
"deviceNumber"].set<
int>(0);
135 std::string flow =
"flow";
136 DB[flow][
"nu"].set<
real>(0.01);
137 DB[flow][
"uInitial"].set<
real>(1.0);
138 DB[flow][
"vInitial"].set<
real>(0.0);
139 DB[flow][
"numBodies"].set<
int>(0);
140 std::vector<body> *bodyVec =
new std::vector<body>;
141 DB[flow][
"bodies"].set<std::vector<body> *>(bodyVec);
145 for (
int i=0; i<4; i++)
150 std::string sim =
"simulation";
151 DB[sim][
"dt"].set<
real>(0.02);
152 DB[sim][
"nt"].set<
int>(100);
153 DB[sim][
"nsave"].set<
int>(100);
154 DB[sim][
"startStep"].set<
bool>(0);
161 std::string solver =
"velocitySolve";
162 DB[solver][
"solver"].set<std::string>(
"CG");
164 DB[solver][
"rTol"].set<
real>(1.0E-05);
165 DB[solver][
"aTol"].set<
real>(1.0E-50);
166 DB[solver][
"maxIterations"].set<
int>(10000);
169 solver =
"PoissonSolve";
170 DB[solver][
"solver"].set<std::string>(
"CG");
172 DB[solver][
"rTol"].set<
real>(1.0E-05);
173 DB[solver][
"aTol"].set<
real>(1.0E-50);
174 DB[solver][
"maxIterations"].set<
int>(20000);
188 for (
int i=1; i<argc; i++)
190 if (strcmp(argv[i],
"-directory")==0)
193 DB[
"inputs"][
"caseFolder"].set<std::string>(std::string(argv[i]));
195 else if (strcmp(argv[i],
"-deviceNumber")==0)
198 int devNum = toNumber<int>(std::string(argv[i]));
199 DB[
"inputs"][
"deviceNumber"].set<
int>(devNum);
201 cudaSetDevice(devNum);
216 for (
int i=1; i<argc; i++)
219 if ( strcmp(argv[i],
"-nu")==0 )
222 DB[
"flow"][
"nu"].set<
real>(toNumber<real>(std::string(argv[i])));
225 if ( strcmp(argv[i],
"-uPerturb")==0 )
228 DB[
"flow"][
"uPerturb"].set<
real>(toNumber<real>(std::string(argv[i])));
231 if ( strcmp(argv[i],
"-vPerturb")==0 )
234 DB[
"flow"][
"vPerturb"].set<
real>(toNumber<real>(std::string(argv[i])));
237 if ( strcmp(argv[i],
"-scaleCV")==0 )
240 DB[
"simulation"][
"scaleCV"].set<
real>(toNumber<real>(std::string(argv[i])));
243 if ( strcmp(argv[i],
"-nsave")==0 )
246 DB[
"simulation"][
"nsave"].set<
int>(toNumber<int>(std::string(argv[i])));
249 if ( strcmp(argv[i],
"-nt")==0 )
252 DB[
"simulation"][
"nt"].set<
int>(toNumber<int>(std::string(argv[i])));
255 if ( strcmp(argv[i],
"-dt")==0 )
258 DB[
"simulation"][
"dt"].set<
real>(toNumber<real>(std::string(argv[i])));
261 if ( strcmp(argv[i],
"-velocity-rtol")==0 )
264 DB[
"velocitySolve"][
"rTol"].set<
real>(toNumber<real>(std::string(argv[i])));
267 if ( strcmp(argv[i],
"-velocity-atol")==0 )
270 DB[
"velocitySolve"][
"aTol"].set<
real>(toNumber<real>(std::string(argv[i])));
273 if ( strcmp(argv[i],
"-poisson-rtol")==0 )
276 DB[
"PoissonSolve"][
"rTol"].set<
real>(toNumber<real>(std::string(argv[i])));
279 if ( strcmp(argv[i],
"-poisson-atol")==0 )
282 DB[
"PoissonSolve"][
"aTol"].set<
real>(toNumber<real>(std::string(argv[i])));
285 if ( strcmp(argv[i],
"-ibmScheme")==0 )
288 if ( strcmp(argv[i],
"NavierStokes")==0 )
291 if ( strcmp(argv[i],
"TairaColonius")==0 )
294 if ( strcmp(argv[i],
"DirectForcing")==0 )
297 if ( strcmp(argv[i],
"FadlunEtAl")==0 )
298 DB[
"simulation"][
"ibmScheme"].set<ibmScheme>(
FADLUN_ET_AL);
300 if ( strcmp(argv[i],
"Diffusion")==0 )
301 DB[
"simulation"][
"ibmScheme"].set<ibmScheme>(
DIFFUSION);
303 if ( strcmp(argv[i],
"DFModified")==0 )
304 DB[
"simulation"][
"ibmScheme"].set<ibmScheme>(
DF_MODIFIED);
306 if ( strcmp(argv[i],
"FEAModified")==0 )
307 DB[
"simulation"][
"ibmScheme"].set<ibmScheme>(
FEA_MODIFIED);
309 if ( strcmp(argv[i],
"DFImproved")==0 )
310 DB[
"simulation"][
"ibmScheme"].set<ibmScheme>(
DF_IMPROVED);
313 if ( strcmp(argv[i],
"-interpolationType")==0 )
316 if ( strcmp(argv[i],
"constant")==0 )
317 DB[
"simulation"][
"interpolationType"].set<interpolationType>(
CONSTANT);
319 if ( strcmp(argv[i],
"linear")==0 )
320 DB[
"simulation"][
"interpolationType"].set<interpolationType>(
LINEAR);
322 if ( strcmp(argv[i],
"quadratic")==0 )
323 DB[
"simulation"][
"interpolationType"].set<interpolationType>(
QUADRATIC);
343 return "Smoothed Aggregation";
345 return "Approximate Inverse";
348 printf(
"Error: Unknown preconditionerType.\n");
364 return "Explicit Euler Method";
366 return "Implicit Euler Method";
368 return "2nd Order Adams-Bashforth";
370 return "Crank-Nicolson";
373 printf(
"Error: Unknown timeScheme!\n");
387 real dt = DB[
"simulation"][
"dt"].get<
real>(),
388 scaleCV = DB[
"simulation"][
"scaleCV"].get<real>();
389 int nt = DB[
"simulation"][
"nt"].get<
int>(),
390 nsave = DB[
"simulation"][
"nsave"].get<int>(),
391 startStep = DB[
"simulation"][
"startStep"].get<
int>();
398 std::cout <<
"\nFlow parameters" <<
'\n';
399 std::cout <<
"---------------" <<
'\n';
400 std::cout <<
"nu = " << DB[
"flow"][
"nu"].get<
real>() <<
'\n';
402 std::cout <<
"\nDomain" <<
'\n';
403 std::cout <<
"------" <<
'\n';
404 std::cout << D.
nx <<
" x " << D.
ny <<
'\n';
406 std::cout <<
"\nSimulation parameters" <<
'\n';
407 std::cout <<
"---------------------" <<
'\n';
408 std::cout <<
"dt = " << dt <<
'\n';
409 std::cout <<
"scaleCV = " << scaleCV <<
'\n';
410 std::cout <<
"startStep = " << startStep <<
'\n';
411 std::cout <<
"nt = " << nt <<
'\n';
412 std::cout <<
"nsave = " << nsave <<
'\n';
413 std::cout <<
"Convection time scheme = " <<
stringFromTimeScheme(DB[
"simulation"][
"convTimeScheme"].get<timeScheme>()) <<
'\n';
414 std::cout <<
"Diffusion time scheme = " <<
stringFromTimeScheme(DB[
"simulation"][
"diffTimeScheme"].get<timeScheme>()) <<
'\n';
422 std::cout <<
"Interpolation type: ";
425 case CONSTANT : std::cout <<
"Constant\n";
break;
426 case LINEAR : std::cout <<
"Linear\n";
break;
427 case QUADRATIC: std::cout <<
"Quadratic\n";
break;
428 default : std::cout <<
"Unknown\n";
break;
432 std::cout <<
"\nVelocity Solve" <<
'\n';
433 std::cout <<
"--------------" <<
'\n';
434 std::cout <<
"Solver = " << DB[
"velocitySolve"][
"solver"].get<std::string>() <<
'\n';
435 std::cout <<
"Preconditioner = " <<
stringFromPreconditionerType(DB[
"velocitySolve"][
"preconditioner"].get<preconditionerType>()) <<
'\n';
436 std::cout <<
"Relative tolerance = " << DB[
"velocitySolve"][
"rTol"].get<
real>() <<
'\n';
437 std::cout <<
"Absolute tolerance = " << DB[
"velocitySolve"][
"aTol"].get<
real>() <<
'\n';
439 std::cout <<
"\nPoisson Solve" <<
'\n';
440 std::cout <<
"-------------" <<
'\n';
441 std::cout <<
"Solver = " << DB[
"PoissonSolve"][
"solver"].get<std::string>() <<
'\n';
442 std::cout <<
"Preconditioner = " <<
stringFromPreconditionerType(DB[
"PoissonSolve"][
"preconditioner"].get<preconditionerType>()) <<
'\n';
443 std::cout <<
"Relative tolerance = " << DB[
"PoissonSolve"][
"rTol"].get<
real>() <<
'\n';
444 std::cout <<
"Absolute tolerance = " << DB[
"PoissonSolve"][
"aTol"].get<
real>() <<
'\n';
446 std::cout <<
"\nOutput parameters" <<
'\n';
447 std::cout <<
"-----------------" <<
'\n';
448 std::cout <<
"Output folder = " << DB[
"inputs"][
"caseFolder"].get<std::string>() <<
'\n';
449 std::cout <<
"nsave = " << DB[
"simulation"][
"nsave"].get<
int>() <<
'\n';
451 cudaDeviceProp deviceProp;
452 int gpu = DB[
"inputs"][
"deviceNumber"].get<
int>();
453 cudaGetDeviceProperties(&deviceProp, gpu);
454 std::cout <<
"\nDevice Properties" <<
'\n';
455 std::cout <<
"-----------------" <<
'\n';
456 std::cout <<
"Name = " << deviceProp.name <<
'\n';
457 std::cout <<
"Number = " << gpu <<
'\n';
458 std::string ecc = deviceProp.ECCEnabled ?
"yes" :
"no";
459 std::cout <<
"Compute capability = " << deviceProp.major <<
"." << deviceProp.minor <<
'\n';
460 std::cout <<
"ECC Enabled = " << ecc << std::endl;
472 std::cout << std::endl;
484 std::stringstream out;
485 out << caseFolder <<
"/grid";
486 std::ofstream file(out.str().c_str(), std::ios::binary);
487 file.write((
char*)(&D.
nx),
sizeof(
int));
488 file.write((
char*)(&D.
x[0]), (D.
nx+1)*
sizeof(
real));
489 file.write((
char*)(&D.
ny),
sizeof(
int));
490 file.write((
char*)(&D.
y[0]), (D.
ny+1)*
sizeof(
real));
512 std::stringstream out;
515 out << caseFolder <<
'/' << std::setfill(
'0') << std::setw(7) << n;
518 mkdir(path.c_str(), S_IRWXU | S_IRWXG | S_IROTH | S_IXOTH);
522 std::ofstream file(out.str().c_str(), std::ios::binary);
524 file.write((
char*)(&N),
sizeof(
int));
525 file.write((
char*)(&q[0]), N*
sizeof(
real));
529 out << path <<
"/lambda";
530 file.open(out.str().c_str(), std::ios::binary);
532 file.write((
char*)(&N),
sizeof(
int));
533 file.write((
char*)(&lambda[0]), N*
sizeof(
real));
536 std::cout <<
"Data saved to folder " << path << std::endl;
559 writeData(caseFolder, n, qH, lambdaH, D);
571 void readData(std::string &caseFolder,
int timeStep,
real *x, std::string name)
573 std::stringstream in;
574 std::string inFilePath;
577 in << caseFolder <<
"/" << std::setfill(
'0') << std::setw(7) << timeStep <<
"/" << name;
578 inFilePath = in.str();
579 std::cout <<
"Reading fluxes from " << inFilePath <<
" ... ";
580 std::ifstream inFile(inFilePath.c_str(), std::ifstream::binary);
581 inFile.read((
char*)(&n),
sizeof(
int));
582 inFile.read((
char*)(&x[0]), n*
sizeof(
real));
584 std::cout <<
"done" << std::endl;
595 size_t _free, _total;
596 cudaMemGetInfo(&_free, &_total);
597 std::cout << label <<
": Memory Usage " << std::setprecision(3) << (_total-_free)/(1024.0*1024*1024) \
598 <<
" / " << std::setprecision(3) << _total/(1024.0*1024*1024) <<
" GB" << std::setprecision(6) <<
'\n' << std::endl;
Monitors the time spent to achieve a certain task.
vecH x
x-coordinates of the nodes
void readInputs(int argc, char **argv, parameterDB &DB, domain &D)
Reads data inputs from the command-line and the simulation files.
Definition of custom types required by the code.
void writeData< vecH >(std::string &caseFolder, int n, vecH &q, vecH &lambda, domain &D)
Writes numerical data at a given time-step (on the host).
void parseFlowFile(std::string &flowFile, parameterDB &DB)
Parses the flow file and stores the parameters in the database.
std::vector< std::string > & split(const std::string &s, char delim, std::vector< std::string > &elems)
Splits a string given a delimiter.
void printAllTime()
Prints time spent for each event as well as the total time.
Definition of the class boundaryCondition.
double real
Is a float or a double depending on the machine precision.
void readData(std::string &caseFolder, int timeStep, real *x, std::string name)
Reads numerical data at a given time-step.
fully discrete direct forcing method
std::string stringFromTimeScheme(timeScheme s)
Converts a timeScheme to a std::string.
void commandLineParse1(int argc, char **argv, parameterDB &DB)
Parses the command-line to get the case folder name and the device number.
ibmScheme
Specifies the immersed boundary method used to solve the flow.
implicit Euler method (first order)
Declaration of the functions of the namespace io.
timeScheme
Specifies the numerical scheme used for time-integration.
void parseSimulationFile(std::string &simFile, parameterDB &DB)
Parses simParams.yaml and stores the simulation parameters.
preconditionerType
Specifies the type of preconditioner.
std::map< std::string, componentParameter > parameterDB
Map from a string to a componentParameter.
T toNumber(std::string str)
Converts a string to a number.
smoothed aggregation preconditioner
void printTimingInfo(Logger &logger)
Prints the time spent to execute tasks.
cusp::array1d< real, host_memory > vecH
Cusp 1D array stored in the host.
Contains functions related to I/O tasks.
Stores information about the computational grid.
no immersed bodies - Perot (1993)
void writeData< vecD >(std::string &caseFolder, int n, vecD &q, vecD &lambda, domain &D)
Writes numerical data at a given time-step (on the device).
std::string stringFromPreconditionerType(preconditionerType s)
Converts a preconditionerType to a std::string.
interpolationType
Specifies the type of interpolation.
void writeGrid(std::string &caseFolder, domain &D)
Writes grid-points coordinates into the file grid.
int ny
number of cells in the y-direction
void initialiseDefaultDB(parameterDB &DB)
Initializes the database with default values.
int nx
number of cells in the x-direction
void parseBodiesFile(std::string &bodiesFile, parameterDB &DB)
Parses the bodies.yaml file and stores information about the immersed bodies.
approximate inverse preconditioner
void printSimulationInfo(parameterDB &DB, domain &D)
Prints the parameters of the simulation.
void printDeviceMemoryUsage(std::string label)
Prints device memory usage.
second-order Adams-Bashforth scheme
Crank-Nicolson scheme (second order)
std::map< std::string, property > componentParameter
Map from a string to a property object.
void parseDomainFile(std::string &domFile, domain &D)
Parses the domain file and generates the computational grid.
vecH y
y-coordinates of the nodes
explicit Euler method (first order)
Stores the type of boundary condition and its value.
void commandLineParse2(int argc, char **argv, parameterDB &DB)
Overwrites parameters with additional arguments of the command-line.
void writeData(std::string &caseFolder, int n, Vector &q, Vector &lambda, domain &D)
cusp::array1d< real, device_memory > vecD
Cusp 1D array stored in the device.