diff --git a/Homework3/src/main.cc b/Homework3/src/main.cc index 7eb8441..b943a13 100644 --- a/Homework3/src/main.cc +++ b/Homework3/src/main.cc @@ -1,89 +1,94 @@ #include "compute_gravity.hh" #include "compute_verlet_integration.hh" #include "csv_reader.hh" #include "csv_writer.hh" #include "my_types.hh" #include "ping_pong_balls_factory.hh" #include "material_points_factory.hh" #include "planets_factory.hh" #include "system.hh" /* -------------------------------------------------------------------------- */ #include #include #include /* -------------------------------------------------------------------------- */ void help(); void argnum_error(int argc, int n); int main(int argc, char** argv) { - if (argc != 6) { + if (argc < 6) help(); - std::exit(EXIT_FAILURE); - } // the number of steps to perform Real nsteps; std::stringstream(argv[1]) >> nsteps; // freq to dump int freq; std::stringstream(argv[2]) >> freq; // init file std::string filename = argv[3]; // particle type std::string type = argv[4]; // timestep Real timestep; std::stringstream(argv[5]) >> timestep; if (type == "planet") PlanetsFactory::getInstance(); else if (type == "ping_pong") PingPongBallsFactory::getInstance(); - else if (type == "material_point") - MaterialPointsFactory::getInstance(); + else if (type == "material_point"){ + argnum_error(argc, 9); + MaterialPointsFactory::getInstance(); + } else { std::cout << "Unknown particle type: " << type << std::endl; std::exit(EXIT_FAILURE); } ParticlesFactoryInterface& factory = ParticlesFactoryInterface::getInstance(); SystemEvolution& evol = factory.createSimulation(filename, timestep); evol.setNSteps(nsteps); evol.setDumpFreq(freq); evol.evolve(); - return EXIT_SUCCESS; } void help() { std::cout<< "\n===============================================\n"<< "To use this program, the following arguments\n"<< "must be enterd in correct order:\n\n"<< "ORDER TYPE ITEM\n"<< "1 num of steps\n"<< "2 dump frequency\n"<< "3 input file name\n"<< "4 particle type\n"<< "5 time step size\n"<< "6 length of the domain\n"<< "7 density*heat_capacity\n"<< "8 heat conductivity\n\n"<< "* Particle type can be:\n"<< " planet, ping_pong, material_point\n\n"<< "* Items 6-8 are applicable\n"<< " for the case of material_point particle type."<< "\n===============================================\n\n"; + + std::exit(EXIT_FAILURE); } void argnum_error(int argc, int n) { - + if (argc != n){ + std::cout<< "\n\n>>> ERROR: number of arguments does not\n"<< + ">>> match the type of particles.\n"; + help(); + } }