Skip to content

Commit

Permalink
Some minor cleaning up.
Browse files Browse the repository at this point in the history
  • Loading branch information
agarny committed Nov 19, 2019
1 parent 9a6b83e commit 641af0e
Show file tree
Hide file tree
Showing 5 changed files with 30 additions and 32 deletions.
File renamed without changes.
2 changes: 1 addition & 1 deletion models/tests/jupyter/lorenz.ipynb
Expand Up @@ -15,7 +15,7 @@
"metadata": {},
"outputs": [],
"source": [
"s = oc.openSimulation('../sedml/lorenz/lorenz.sedml')\n",
"s = oc.openSimulation('../sedml/lorenz.sedml')\n",
"s"
]
},
Expand Down
2 changes: 1 addition & 1 deletion models/tests/python/lorenz.py
Expand Up @@ -3,7 +3,7 @@
import os
import OpenCOR as oc

s = oc.openSimulation(os.path.dirname(__file__) + '/../sedml/lorenz/lorenz.sedml')
s = oc.openSimulation(os.path.dirname(__file__) + '/../sedml/lorenz.sedml')

print('---------------------------------------')
print('Simulation:')
Expand Down
Expand Up @@ -20,7 +20,7 @@
</uniformTimeCourse>
</listOfSimulations>
<listOfModels>
<model id="model" language="urn:sedml:language:cellml.1_0" source="lorenz.cellml"/>
<model id="model" language="urn:sedml:language:cellml.1_0" source="../cellml/lorenz.cellml"/>
</listOfModels>
<listOfTasks>
<repeatedTask id="repeatedTask" range="once" resetModel="true">
Expand Down
Expand Up @@ -120,12 +120,9 @@ static PyObject * initializeSimulation(const QString &pFileName)
return PythonQt::priv()->wrapQObject(simulation);
}

// Get our runtime

CellMLSupport::CellmlFileRuntime *runtime = simulation->runtime();

// Find the solver whose name is first in alphabetical order, as this
// is the simulation's solver
// Retrieve a default ODE and NLA solver
// Note: this is useful in case our simulation is solely based on a
// CellML file...

QString odeSolverName = QString();
QString nlaSolverName = QString();
Expand All @@ -134,59 +131,60 @@ static PyObject * initializeSimulation(const QString &pFileName)
QString solverName = solverInterface->solverName();

if (solverInterface->solverType() == Solver::Type::Ode) {
if (odeSolverName.isEmpty()
|| odeSolverName.compare(solverName, Qt::CaseInsensitive) > 0) {
if ( odeSolverName.isEmpty()
|| (odeSolverName.compare(solverName, Qt::CaseInsensitive) > 0)) {
odeSolverName = solverName;
}
} else if (solverInterface->solverType() == Solver::Type::Nla) {
if (nlaSolverName.isEmpty()
|| nlaSolverName.compare(solverName, Qt::CaseInsensitive) > 0) {
if ( nlaSolverName.isEmpty()
|| (nlaSolverName.compare(solverName, Qt::CaseInsensitive) > 0)) {
nlaSolverName = solverName;
}
}
}

// Set our solver and its default properties
// Set our default ODE and NLA, if needed, solvers

setOdeSolver(simulation->data(), odeSolverName);
CellMLSupport::CellmlFileRuntime *runtime = simulation->runtime();

// Set our NLA solver if we need one
setOdeSolver(simulation->data(), odeSolverName);

if ((runtime != nullptr) && runtime->needNlaSolver()) {
setNlaSolver(simulation->data(), nlaSolverName);
}

// Complete initialisation by loading any SED-ML properties
// Further initialise our simulation, should we be dealing with either
// a SED-ML file or a COMBINE archive
// Note: this will overwrite the default ODE and NLA solvers that we set
// above...

if (simulation->fileType() == SimulationSupport::Simulation::FileType::SedmlFile
|| simulation->fileType() == SimulationSupport::Simulation::FileType::CombineArchive) {
if ( (simulation->fileType() == SimulationSupport::Simulation::FileType::SedmlFile)
|| (simulation->fileType() == SimulationSupport::Simulation::FileType::CombineArchive)) {
QString error = simulation->furtherInitialize();

QString initializationError = simulation->furtherInitialize();

if (!initializationError.isEmpty()) {
// We couldn't complete initialisation so no longer manage the simulation
if (!error.isEmpty()) {
// We couldn't complete initialisation, so no longer manage the
// simulation and raise a Python exception

simulationManager->unmanage(pFileName);

// And raise a Python exception

PyErr_SetString(PyExc_ValueError, qPrintable(initializationError));
PyErr_SetString(PyExc_ValueError, qPrintable(error));

return nullptr;
#include "pythonbegin.h"
Py_RETURN_NONE;
#include "pythonend.h"
}
}

// Do we have a valid simulation?
// Reset both the simulation's data and results (well, initialise in the
// case of its data), should we have a valid runtime

if ((runtime != nullptr) && runtime->isValid()) {
// Reset both the simulation's data and results (well, initialise in the
// case of its data)

simulation->data()->reset();
simulation->results()->reset();
}

// Return the simulation as a Python object
// Return our simulation object as a Python object

return PythonQt::priv()->wrapQObject(simulation);
}
Expand Down

0 comments on commit 641af0e

Please sign in to comment.