Skip to content

Commit

Permalink
Merge pull request #416 from kirichoi/start_time
Browse files Browse the repository at this point in the history
Proposed solution to Issue #411
  • Loading branch information
0u812 authored Sep 30, 2017
2 parents 1554ef3 + 300de2d commit e8b5b72
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 12 deletions.
21 changes: 14 additions & 7 deletions source/rrRoadRunner.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -989,8 +989,10 @@ bool RoadRunner::clearModel()

void RoadRunner::reset()
{
uint opt = rr::Config::getInt(rr::Config::MODEL_RESET);
reset(opt);
uint opt1 = rr::Config::getInt(rr::Config::MODEL_RESET);
reset(opt1);
uint opt2 = rr::SelectionRecord::DEPENDENT_INITIAL_GLOBAL_PARAMETER;
reset(opt2);
}

void RoadRunner::reset(int options)
Expand Down Expand Up @@ -1332,8 +1334,8 @@ const DoubleMatrix* RoadRunner::simulate(const Dictionary* dict)

applySimulateOptions();

const double timeEnd = self.simulateOpt.duration + self.simulateOpt.start;
const double timeStart = self.simulateOpt.start;
const double timeEnd = self.simulateOpt.duration;
const double timeStart = 0;

// evalute the model with its current state
self.model->getStateVectorRate(timeStart, 0, 0);
Expand Down Expand Up @@ -1563,6 +1565,12 @@ const DoubleMatrix* RoadRunner::simulate(const Dictionary* dict)

Log(Logger::LOG_DEBUG) << "Simulation done..";

for (int i = 0; i < self.simulationResult.numRows(); i++) {
self.simulationResult[i][getTimeRowIndex()] = self.simulationResult[i][getTimeRowIndex()] + self.simulateOpt.start;
}

Log(Logger::LOG_DEBUG) << "Added delta T.";

return &self.simulationResult;
}

Expand Down Expand Up @@ -4049,10 +4057,9 @@ void RoadRunner::applySimulateOptions()
{
get_self();

if (self.simulateOpt.duration < 0 || self.simulateOpt.start < 0
|| self.simulateOpt.steps < 0 )
if (self.simulateOpt.duration < 0 || self.simulateOpt.steps < 0 )
{
throw std::invalid_argument("duration, startTime and steps must be non-negative");
throw std::invalid_argument("duration and steps must be non-negative");
}

// This one creates the list of what we will look at in the result
Expand Down
9 changes: 4 additions & 5 deletions wrappers/C/Testing/Suite_TestModel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1159,9 +1159,9 @@ SUITE(TEST_MODEL)
clog << endl << " simulate with " << opt.start << ", " << opt.duration << ", " << opt.steps << "\n";
const DoubleMatrix *rk4 = rri->simulate(&opt);

for (int i = 0; i < cvode[-1].size(); i++)
for (int k = 0; k < cvode->CSize(); k++)
{
CHECK_CLOSE(*cvode[-1][i], *rk4[-1][i], 1e-6);
CHECK_CLOSE((*cvode)(cvode->RSize() - 1, k), (*rk4)(rk4->RSize() - 1, k), 1e-6);
}
}

Expand Down Expand Up @@ -1191,9 +1191,8 @@ SUITE(TEST_MODEL)
clog << endl << " simulate with " << opt.start << ", " << opt.duration << ", " << opt.steps << "\n";
const DoubleMatrix *rk45 = rri->simulate(&opt);

for (int i = 0; i < cvode[-1].size(); i++)
{
CHECK_CLOSE(*cvode[-1][i], *rk45[-1][i], 1e-6);
for (int k = 0; k < cvode->CSize(); k++){
CHECK_CLOSE((*cvode)(cvode->RSize() - 1, k), (*rk45)(rk45->RSize() - 1, k), 1e-6);
}
}

Expand Down

0 comments on commit e8b5b72

Please sign in to comment.