From c10b9d56975fe703b2d5ccddab1c7d9899daeb9d Mon Sep 17 00:00:00 2001 From: Cory Date: Mon, 1 Jan 2024 15:55:59 +0100 Subject: [PATCH] Make changes --- src/main.cpp | 16 +++++--- src/wave_simulation.cpp | 88 +++++++++++++++++++++++++++++++++++++++++ 2 files changed, 98 insertions(+), 6 deletions(-) create mode 100644 src/wave_simulation.cpp diff --git a/src/main.cpp b/src/main.cpp index 137fb58..70c6536 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -5,7 +5,7 @@ * * @version 1.0 * - * @brief Implementation of the testing library + * @brief The main program * * @bug No known bugs * */ @@ -16,14 +16,18 @@ void probability_deviation() { + DEBUG("Sim no slits"); WaveSimulation sim_no_slits(.005, 2.5e-5, .008, .25, .5, .05, .05, 200., 0.); + DEBUG("Sim with slits"); WaveSimulation sim_slits(.005, 2.5e-5, .008, .25, .5, .05, .10, 200., 0., 0.02, .5, .05, .05, 2); + DEBUG("Probability deviation"); sim_no_slits.probability_deviation( "data/probability_deviation_no_slits.txt", true); + DEBUG("Probability deviation with slits"); sim_slits.probability_deviation("data/probability_deviation_slits.txt", true); } @@ -33,7 +37,7 @@ void color_map() .5, .05, .05, 2); std::vector times{0., .001, .002}; - sim.solve("data/color_map.txt", times); + sim.simulate("data/color_map.txt", times); } void detector_screen() @@ -41,19 +45,19 @@ void detector_screen() WaveSimulation *sim = new WaveSimulation( .005, 2.5e-5, .002, .25, .5, .05, .20, 200., 0., 0.02, .5, .05, .05, 1); - sim->solve("data/screen/single_slit.txt"); + sim->simulate("data/screen/single_slit.txt"); delete sim; sim = new WaveSimulation(.005, 2.5e-5, .002, .25, .5, .05, .20, 200., 0., 0.02, .5, .05, .05, 2); - sim->solve("data/screen/double_slit.txt"); + sim->simulate("data/screen/double_slit.txt"); delete sim; sim = new WaveSimulation(.005, 2.5e-5, .002, .25, .5, .05, .20, 200., 0., 0.02, .5, .05, .05, 3); - sim->solve("data/screen/triple_slit.txt"); + sim->simulate("data/screen/triple_slit.txt"); } int main() @@ -69,7 +73,7 @@ int main() // ofile.open("test.txt"); // WaveSimulation sim(.005, 2.5e-5, .008, .25, .5, .05, .10, 200., 0., // 0.02, .5, .05, .05, 2); - // sim.solve(ofile); + // sim.simulate(ofile); return 0; } diff --git a/src/wave_simulation.cpp b/src/wave_simulation.cpp new file mode 100644 index 0000000..ec9a815 --- /dev/null +++ b/src/wave_simulation.cpp @@ -0,0 +1,88 @@ +#include "WaveSimulation.hpp" +#include "utils.hpp" + +#include +#include + +void execute_simulation(std::vector &args) +{ + DEBUG("Inside execute sim"); + if (args.size() < 11) { + return; + } + + DEBUG("Declare sim"); + WaveSimulation *sim; + if (args.size() >= 11 && args.size() < 16) { + sim = new WaveSimulation( + std::stod(args[2]), std::stod(args[3]), std::stod(args[4]), + std::stod(args[5]), std::stod(args[6]), std::stod(args[7]), + std::stod(args[8]), std::stod(args[9]), std::stod(args[10])); + } + else if (args.size() >= 16) { + sim = new WaveSimulation( + std::stod(args[2]), std::stod(args[3]), std::stod(args[4]), + std::stod(args[5]), std::stod(args[6]), std::stod(args[7]), + std::stod(args[8]), std::stod(args[9]), std::stod(args[10]), + std::stod(args[11]), std::stod(args[12]), std::stod(args[13]), + std::stod(args[14]), std::stoi(args[15])); + } + + DEBUG("After instantiating sim"); + if (args[0].compare("deviation") == 0) { + DEBUG("Deviation"); + if (args.size() == 17) { + sim->probability_deviation(args[1], args[16].compare("false")); + } + else if (args.size() == 12) { + sim->probability_deviation(args[1], args[11].compare("false")); + } + else { + sim->probability_deviation(args[1]); + } + } + else if (args[0].compare("simulate") == 0) { + DEBUG("Simulate"); + if (args.size() == 17) { + sim->simulate(args[1], args[16].compare("false")); + } + else if (args.size() == 12) { + sim->simulate(args[1], args[11].compare("false")); + } + else if (args.size() > 17) { + std::vector arr; + for (size_t i = 16; i < args.size(); i++) { + arr.push_back(std::stod(args[i])); + } + sim->simulate(args[1], arr); + } + else { + sim->simulate(args[1]); + } + } + delete sim; +} + +int main(int argc, char **argv) +{ + DEBUG("Start of main"); + if (argc < 2) { + abort(); + } + + DEBUG("After arg check"); + std::string filename = argv[1]; + + DEBUG("Open file"); + std::ifstream infile; + infile.open(filename); + + DEBUG("For line in lines"); + for (std::string line; std::getline(infile, line);) { + std::vector arr = utils::split(line, ';'); + execute_simulation(arr); + } + + DEBUG("Close file"); + infile.close(); +}