Skip to content

Commit

Permalink
Remove stepSizeDefined from cse_ssp_fixed_step_execution_create (#380)
Browse files Browse the repository at this point in the history
* Remove stepSizeDefined from cse_ssp_fixed_step_execution_create
  • Loading branch information
markaren authored Sep 25, 2019
1 parent 2167c3a commit 7e731dc
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 9 deletions.
6 changes: 1 addition & 5 deletions include/cse.h
Original file line number Diff line number Diff line change
Expand Up @@ -168,11 +168,8 @@ cse_execution* cse_ssp_execution_create(
* \param [in] startTime
* The (logical) time point at which the simulation should start.
* If startTimeDefined=false, this variable will be ignored and a default value will be used.
* \param [in] stepSizeDefined
* Defines whether or not the following stepSize variable should be ignored or not.
* Must evaluate to `true` when loaded SSP does not contain a osp:FixedStepMaster annotation providing a default step size.
* \param [in] stepSize
* If stepSizeDefined=true, this value will be used by the (fixed-step) co-simulation algorithm.
* The stepSize that will be used by the (fixed-step) co-simulation algorithm.
* \returns
* A pointer to an object which holds the execution state,
* or NULL on error.
Expand All @@ -181,7 +178,6 @@ cse_execution* cse_ssp_fixed_step_execution_create(
const char* sspDir,
bool startTimeDefined,
cse_time_point startTime,
bool stepSizeDefined,
cse_duration stepSize);

/**
Expand Down
21 changes: 18 additions & 3 deletions src/c/cse.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -162,14 +162,29 @@ cse_execution* cse_ssp_execution_create(
bool startTimeDefined,
cse_time_point startTime)
{
return cse_ssp_fixed_step_execution_create(sspDir, startTimeDefined, startTime, false, 0);
try {
auto execution = std::make_unique<cse_execution>();

auto resolver = cse::default_model_uri_resolver();
auto sim = cse::load_ssp(
*resolver,
sspDir,
startTimeDefined ? std::optional<cse::time_point>(to_time_point(startTime)) : std::nullopt);

execution->cpp_execution = std::make_unique<cse::execution>(std::move(sim.first));
execution->simulators = std::move(sim.second);

return execution.release();
} catch (...) {
handle_current_exception();
return nullptr;
}
}

cse_execution* cse_ssp_fixed_step_execution_create(
const char* sspDir,
bool startTimeDefined,
cse_time_point startTime,
bool stepSizeDefined,
cse_duration stepSize)
{
try {
Expand All @@ -179,7 +194,7 @@ cse_execution* cse_ssp_fixed_step_execution_create(
auto sim = cse::load_ssp(
*resolver,
sspDir,
stepSizeDefined ? std::make_unique<cse::fixed_step_algorithm>(to_duration(stepSize)) : nullptr,
std::make_unique<cse::fixed_step_algorithm>(to_duration(stepSize)),
startTimeDefined ? std::optional<cse::time_point>(to_time_point(startTime)) : std::nullopt);

execution->cpp_execution = std::make_unique<cse::execution>(std::move(sim.first));
Expand Down
2 changes: 1 addition & 1 deletion test/c/execution_from_ssp_custom_algo_test.c
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ int main()
}

int64_t nanoStepSize = (int64_t)(0.1 * 1.0e9);
execution = cse_ssp_fixed_step_execution_create(sspDir, true, 0, true, nanoStepSize); // override ssp startTime
execution = cse_ssp_fixed_step_execution_create(sspDir, true, 0, nanoStepSize); // override ssp startTime
if (!execution) { goto Lerror; }

cse_execution_status status;
Expand Down

0 comments on commit 7e731dc

Please sign in to comment.