Skip to content
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

Fix stop condition of IDA driver #29

Merged
merged 1 commit into from
Nov 19, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
98 changes: 44 additions & 54 deletions lib/Drivers/IDA/Driver.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,86 +2,76 @@

#include "marco/Runtime/Drivers/IDA/Driver.h"
#include "marco/Runtime/Drivers/IDA/CLI.h"
#include "marco/Runtime/Solvers/IDA/Options.h"
#include "marco/Runtime/Solvers/IDA/Profiler.h"
#include "marco/Runtime/Simulation/Options.h"
#include "marco/Runtime/Simulation/Profiler.h"
#include "marco/Runtime/Simulation/Runtime.h"
#include "marco/Runtime/Solvers/IDA/Options.h"
#include "marco/Runtime/Solvers/IDA/Profiler.h"

//===---------------------------------------------------------------------===//
// Functions defined inside the module of the compiled model
//===---------------------------------------------------------------------===//

extern "C"
{
/// @name Simulation functions.
/// {
extern "C" {
/// @name Simulation functions.
/// {

/// Compute the initial values of the variables.
void calcIC();
/// Compute the initial values of the variables.
void calcIC();

/// Compute the values of the variables managed by IDA.
void updateIDAVariables();
/// Compute the values of the variables managed by IDA.
void updateIDAVariables();

/// Compute the values of the variables not managed by IDA.
/// Notice that, from an algebraic point of view, these variables may depend
/// on the variables within IDA. For this reason, this function should be
/// called only after 'updateIDAVariables' and after having updated the time.
void updateNonIDAVariables();
/// Compute the values of the variables not managed by IDA.
/// Notice that, from an algebraic point of view, these variables may depend
/// on the variables within IDA. For this reason, this function should be
/// called only after 'updateIDAVariables' and after having updated the time.
void updateNonIDAVariables();

/// Get the time reached by IDA during the simulation.
double getIDATime();
/// Get the time reached by IDA during the simulation.
double getIDATime();

/// }
/// }
}

namespace marco::runtime
{
IDA::IDA(Simulation* simulation)
: Driver(simulation)
{
}
namespace marco::runtime {
IDA::IDA(Simulation *simulation) : Driver(simulation) {}

#ifdef CLI_ENABLE
std::unique_ptr<cli::Category> IDA::getCLIOptions()
{
return std::make_unique<sundials::ida::CommandLineOptions>();
}
std::unique_ptr<cli::Category> IDA::getCLIOptions() {
return std::make_unique<sundials::ida::CommandLineOptions>();
}
#endif // CLI_ENABLE

int IDA::run()
{
// Run the dynamic model.
calcIC();
int IDA::run() {
// Run the dynamic model.
calcIC();

do {
// Compute the next values of the variables belonging to IDA.
updateIDAVariables();
do {
// Compute the next values of the variables belonging to IDA.
updateIDAVariables();

IDA_PROFILER_ALGEBRAIC_VARS_START;
// Update the time.
setTime(getIDATime());
IDA_PROFILER_ALGEBRAIC_VARS_START;
// Update the time.
setTime(getIDATime());

// Compute the next values of the variables not belonging to IDA (which
// may depend on the IDA variables).
updateNonIDAVariables();
IDA_PROFILER_ALGEBRAIC_VARS_STOP;
// Compute the next values of the variables not belonging to IDA (which
// may depend on the IDA variables).
updateNonIDAVariables();
IDA_PROFILER_ALGEBRAIC_VARS_STOP;

// Print the values.
getSimulation()->getPrinter()->printValues();
} while (std::abs(getTime() - simulation::getOptions().endTime) >=
sundials::ida::getOptions().timeStep);
// Print the values.
getSimulation()->getPrinter()->printValues();
} while (getTime() < simulation::getOptions().endTime);

return EXIT_SUCCESS;
}
return EXIT_SUCCESS;
}
} // namespace marco::runtime

namespace marco::runtime
{
std::unique_ptr<Driver> getDriver(Simulation* simulation)
{
return std::make_unique<IDA>(simulation);
}
namespace marco::runtime {
std::unique_ptr<Driver> getDriver(Simulation *simulation) {
return std::make_unique<IDA>(simulation);
}
} // namespace marco::runtime

#endif // SUNDIALS_ENABLE