-
Notifications
You must be signed in to change notification settings - Fork 1
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add snapshot frequency to Euler Forward driver #10
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -34,6 +34,7 @@ namespace marco::runtime | |
|
||
std::vector<int64_t> derOrders; | ||
|
||
|
||
private: | ||
Printer* printer; | ||
}; | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,77 +1,83 @@ | ||
#include "marco/Runtime/Drivers/EulerForward/Driver.h" | ||
#include "marco/Runtime/Drivers/EulerForward/CLI.h" | ||
#include "marco/Runtime/Solvers/EulerForward/Options.h" | ||
#include "marco/Runtime/Solvers/EulerForward/Profiler.h" | ||
#include "marco/Runtime/Simulation/Options.h" | ||
#include "marco/Runtime/Simulation/Profiler.h" | ||
#include "marco/Runtime/Simulation/Runtime.h" | ||
#include "marco/Runtime/Solvers/EulerForward/Options.h" | ||
#include "marco/Runtime/Solvers/EulerForward/Profiler.h" | ||
#include <iostream> | ||
|
||
namespace marco::runtime | ||
{ | ||
EulerForward::EulerForward(Simulation* simulation) | ||
: Driver(simulation) | ||
{ | ||
} | ||
namespace marco::runtime { | ||
EulerForward::EulerForward(Simulation *simulation) : Driver(simulation) {} | ||
|
||
#ifdef CLI_ENABLE | ||
std::unique_ptr<cli::Category> EulerForward::getCLIOptions() | ||
{ | ||
return std::make_unique<eulerforward::CommandLineOptions>(); | ||
} | ||
std::unique_ptr<cli::Category> EulerForward::getCLIOptions() { | ||
return std::make_unique<eulerforward::CommandLineOptions>(); | ||
} | ||
#endif // CLI_ENABLE | ||
|
||
int EulerForward::run() | ||
{ | ||
if (marco::runtime::simulation::getOptions().debug) { | ||
std::cerr << "[Euler Forward] Starting simulation" << std::endl; | ||
} | ||
int EulerForward::run() { | ||
if (marco::runtime::simulation::getOptions().debug) { | ||
std::cerr << "[Euler Forward] Starting simulation" << std::endl; | ||
} | ||
|
||
double time; | ||
std::size_t iterationStep = 0; | ||
|
||
double time; | ||
do { | ||
iterationStep++; | ||
bool snapshotCondition = | ||
iterationStep % eulerforward::getOptions().snapshotSteps == 0; | ||
|
||
do { | ||
// Compute the next values of the state variables. | ||
if (marco::runtime::simulation::getOptions().debug) { | ||
std::cerr << "[Euler Forward] Updating state variables" << std::endl; | ||
} | ||
// Compute the next values of the state variables. | ||
if (marco::runtime::simulation::getOptions().debug) { | ||
std::cerr << "[Euler Forward] Updating state variables" << std::endl; | ||
} | ||
|
||
EULER_FORWARD_PROFILER_STATEVAR_START; | ||
updateStateVariables(eulerforward::getOptions().timeStep); | ||
EULER_FORWARD_PROFILER_STATEVAR_STOP; | ||
EULER_FORWARD_PROFILER_STATEVAR_START; | ||
updateStateVariables(eulerforward::getOptions().timeStep); | ||
EULER_FORWARD_PROFILER_STATEVAR_STOP; | ||
|
||
// Move to the next step. | ||
if (marco::runtime::simulation::getOptions().debug) { | ||
std::cerr << "[Euler Forward] Updating time and non-state variables" << std::endl; | ||
} | ||
// Move to the next step. | ||
if (marco::runtime::simulation::getOptions().debug) { | ||
std::cerr << "[Euler Forward] Updating time and non-state variables" | ||
<< std::endl; | ||
} | ||
|
||
if (snapshotCondition) { | ||
EULER_FORWARD_PROFILER_NONSTATEVAR_START; | ||
time = getTime() + eulerforward::getOptions().timeStep; | ||
setTime(time); | ||
|
||
updateNonStateVariables(); | ||
EULER_FORWARD_PROFILER_NONSTATEVAR_STOP; | ||
} | ||
|
||
if (marco::runtime::simulation::getOptions().debug) { | ||
std::cerr << "[Euler Forward] Printing values" << std::endl; | ||
} | ||
if (marco::runtime::simulation::getOptions().debug) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This should be done only if the snapshot steps condition holds. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Pushing soon There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The macros / assertions -- introduced as sequence points? |
||
std::cerr << "[Euler Forward] Printing values" << std::endl; | ||
} | ||
|
||
// Print the values. | ||
// Print the values at a specified frequency. | ||
if (snapshotCondition) { | ||
getSimulation()->getPrinter()->printValues(); | ||
} while (std::abs(simulation::getOptions().endTime - time) >= | ||
eulerforward::getOptions().timeStep); | ||
|
||
if (marco::runtime::simulation::getOptions().debug) { | ||
std::cerr << "[Euler Forward] Simulation finished" << std::endl; | ||
} | ||
|
||
return EXIT_SUCCESS; | ||
} while (std::abs(simulation::getOptions().endTime - time) >= | ||
eulerforward::getOptions().timeStep); | ||
|
||
iterationStep++; | ||
getSimulation()->getPrinter()->printValues(); | ||
|
||
if (marco::runtime::simulation::getOptions().debug) { | ||
std::cerr << "[Euler Forward] Simulation finished" << std::endl; | ||
} | ||
|
||
return EXIT_SUCCESS; | ||
} | ||
} // namespace marco::runtime | ||
|
||
namespace marco::runtime | ||
{ | ||
std::unique_ptr<Driver> getDriver(Simulation* simulation) | ||
{ | ||
return std::make_unique<EulerForward>(simulation); | ||
} | ||
namespace marco::runtime { | ||
std::unique_ptr<Driver> getDriver(Simulation *simulation) { | ||
return std::make_unique<EulerForward>(simulation); | ||
} | ||
} // namespace marco::runtime |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this whiteline inserted by clang-format? :D
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No :D