Configure ASAGI scenarios through command line arguments

Thanks to Dmitry N. Mikushin
parent 7222f771
......@@ -27,11 +27,13 @@
* Setting of SWE, which uses a wave propagation solver and an artificial or ASAGI scenario on multiple blocks.
*/
#include <mpi.h>
#include <algorithm>
#include <cassert>
#include <cmath>
#include <cstdlib>
#include <mpi.h>
#include <string>
#include <vector>
#ifndef CUDA
#include "blocks/SWE_WavePropagationBlock.hh"
......@@ -86,6 +88,25 @@ void exchangeBottomTopGhostLayers( const int i_bottomNeighborRank, SWE_Block1D*
const int i_topNeighborRank, SWE_Block1D* o_topNeighborInflow, SWE_Block1D* i_topNeighborOutflow,
const MPI_Datatype i_mpiRow);
// Get command line argument by the specified name.
static char* getArgByName(std::vector<std::string> vargs, std::string arg_name, char** argv)
{
std::vector<std::string>::iterator it = std::find(vargs.begin(), vargs.end(), arg_name);
if (it == vargs.end()) {
std::cerr << "Cannot find the command line argument matching the name \"" <<
arg_name << "\"" << endl;
// abort MPI execution
MPI_Abort(MPI_COMM_WORLD, -1);
exit(1);
}
return argv[it - vargs.begin()];
}
#define ARG(arg_name) getArgByName(vargs, arg_name, argv)
/**
* Main program for the simulation on a single SWE_WavePropagationBlock.
*/
......@@ -121,14 +142,28 @@ int main( int argc, char** argv ) {
// check if the necessary command line input parameters are given
#ifndef READXML
if(argc != 4) {
std::cout << "Aborting ... please provide proper input parameters." << std::endl
<< "Example: ./SWE_parallel 200 300 /work/openmp_out" << std::endl
<< "\tfor a multiple block grid of total size 200*300" << std::endl << std::flush;
// abort MPI execution
MPI_Abort(MPI_COMM_WORLD, -1);
std::vector<std::string> vargs;
vargs.push_back(argv[0]);
vargs.push_back("grid_size_x");
vargs.push_back("grid_size_y");
vargs.push_back("output_basepath");
vargs.push_back("output_steps_count");
#ifdef ASAGI
vargs.push_back("bathymetry_file");
vargs.push_back("displacement_file");
vargs.push_back("simul_area_min_x");
vargs.push_back("simul_area_max_x");
vargs.push_back("simul_area_min_y");
vargs.push_back("simul_area_max_y");
vargs.push_back("simul_duration_secs");
#endif
if (argc != vargs.size()) {
std::cout << "Usage: " << vargs[0];
for (int i = 1, e = vargs.size(); i != e; i++)
std::cout << " <" << vargs[i] << ">";
std::cout << std::endl << std::flush;
MPI_Finalize();
return 1;
}
#endif
......@@ -141,10 +176,9 @@ int main( int argc, char** argv ) {
// read command line parameters
#ifndef READXML
l_nX = atoi(argv[1]);
l_nY = atoi(argv[2]);
l_baseName = std::string(argv[3]);
l_nX = atoi(ARG("grid_size_x"));
l_nY = atoi(ARG("grid_size_y"));
l_baseName = std::string(ARG("output_basepath"));
#endif
// read xml file
......@@ -196,22 +230,22 @@ int main( int argc, char** argv ) {
//simulation area
float simulationArea[4];
simulationArea[0] = -450000;
simulationArea[1] = 6450000;
simulationArea[2] = -2450000;
simulationArea[3] = 1450000;
SWE_AsagiScenario l_scenario( ASAGI_INPUT_DIR "tohoku_gebco_ucsb3_500m_hawaii_bath.nc",
ASAGI_INPUT_DIR "tohoku_gebco_ucsb3_500m_hawaii_displ.nc",
(float) 14400., simulationArea);
simulationArea[0] = atof(ARG("simul_area_min_x"));
simulationArea[1] = atof(ARG("simul_area_max_x"));
simulationArea[2] = atof(ARG("simul_area_min_y"));
simulationArea[3] = atof(ARG("simul_area_max_y"));
float simulationDuration = atof(ARG("simul_duration_secs"));
SWE_AsagiScenario l_scenario(ARG("bathymetry_file"), ARG("displacement_file"),
simulationDuration, simulationArea);
#else
// create a simple artificial scenario
SWE_BathymetryDamBreakScenario l_scenario;
#endif
//! number of checkpoints for visualization (at each checkpoint in time, an output file is written).
int l_numberOfCheckPoints = 40;
int l_numberOfCheckPoints = atoi(ARG("output_steps_count"));
//! number of grid cells in x- and y-direction per process.
int l_nXLocal, l_nYLocal;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment