diff --git a/src/plugins/dataStore/DataStore/src/datastorepythonwrapper.cpp b/src/plugins/dataStore/DataStore/src/datastorepythonwrapper.cpp index 4845814c2c..96c50244d5 100644 --- a/src/plugins/dataStore/DataStore/src/datastorepythonwrapper.cpp +++ b/src/plugins/dataStore/DataStore/src/datastorepythonwrapper.cpp @@ -55,13 +55,6 @@ static bool initNumPy() //============================================================================== -typedef struct { - PyDictObject mDict; - SimulationSupport::SimulationDataUpdatedFunction *mSimulationDataUpdatedFunction; -} DataStoreValuesDictObject; - -//============================================================================== - static DataStoreValue * getDataStoreValue(PyObject *pValuesDict, PyObject *pKey) { // Get and return a DataStoreValue item from a values dictionary @@ -93,6 +86,13 @@ static PyObject * DataStoreValuesDict_subscript(PyObject *pValuesDict, //============================================================================== +typedef struct { + PyDictObject mDict; + SimulationSupport::SimulationDataUpdatedFunction *mSimulationDataUpdatedFunction; +} DataStoreValuesDictObject; + +//============================================================================== + static int DataStoreValuesDict_ass_subscript(PyObject *pValuesDict, PyObject *pKey, PyObject *pValue) { @@ -143,8 +143,8 @@ static PyMappingMethods DataStoreValuesDict_as_mapping = { static PyObject * DataStoreValuesDict_repr(DataStoreValuesDictObject *pValuesDict) { // A string representation of a values dictionary - // Note: this is a modified version of dict_repr() from dictobject.c in - // Python's C source code... + // Note: this is a modified version of dict_repr() from dictobject.c in the + // Python source code... PyDictObject *mp = reinterpret_cast(pValuesDict); Py_ssize_t i = Py_ReprEnter(reinterpret_cast(mp)); @@ -319,9 +319,9 @@ DataStorePythonWrapper::DataStorePythonWrapper(PyObject *pModule, PyType_Ready(&DataStoreValuesDict_Type); - PythonQtSupport::registerClass(&OpenCOR::DataStore::DataStore::staticMetaObject); - PythonQtSupport::registerClass(&OpenCOR::DataStore::DataStoreValue::staticMetaObject); - PythonQtSupport::registerClass(&OpenCOR::DataStore::DataStoreVariable::staticMetaObject); + PythonQtSupport::registerClass(&DataStore::staticMetaObject); + PythonQtSupport::registerClass(&DataStoreValue::staticMetaObject); + PythonQtSupport::registerClass(&DataStoreVariable::staticMetaObject); PythonQtSupport::addInstanceDecorators(this); } @@ -394,7 +394,7 @@ PyObject * DataStorePythonWrapper::dataStoreVariablesDict(const DataStoreVariabl PyObject *res = PyDict_New(); - foreach (DataStoreVariable *dataStoreVariable, pDataStoreVariables) { + for (auto dataStoreVariable : pDataStoreVariables) { PythonQtSupport::addObject(res, dataStoreVariable->uri(), dataStoreVariable); } diff --git a/src/plugins/solver/CVODESolver/src/cvodesolver.cpp b/src/plugins/solver/CVODESolver/src/cvodesolver.cpp index 378e7d306f..664f347fa9 100644 --- a/src/plugins/solver/CVODESolver/src/cvodesolver.cpp +++ b/src/plugins/solver/CVODESolver/src/cvodesolver.cpp @@ -139,16 +139,6 @@ CvodeSolver::~CvodeSolver() //============================================================================== -void CvodeSolver::initialize(double pVoi, int pRatesStatesCount, - double *pConstants, double *pRates, - double *pStates, double *pAlgebraic, - ComputeRatesFunction pComputeRates) -{ - initialize(pVoi, pRatesStatesCount, pConstants, pRates, pStates, pAlgebraic, pComputeRates, 0, 0, 0); -} - -//============================================================================== - void CvodeSolver::initialize(double pVoi, int pRatesStatesCount, double *pConstants, double *pRates, double *pStates, double *pAlgebraic, @@ -402,36 +392,38 @@ void CvodeSolver::initialize(double pVoi, int pRatesStatesCount, mSensitivityVectors = N_VCloneVectorArrayEmpty_Serial(mSensitivityVectorsSize, mStatesVector); for (int i = 0, iMax = mSensitivityVectorsSize; i < iMax; ++i) { -#ifdef Q_OS_MAC - #pragma clang diagnostic push - #pragma clang diagnostic ignored "-Wold-style-cast" -#endif - NV_DATA_S(mSensitivityVectors[i]) = pGradients; -#ifdef Q_OS_MAC - #pragma clang diagnostic pop -#endif + N_VectorContent_Serial(mSensitivityVectors[i]->content)->data = pGradients; pGradients += pRatesStatesCount; } // Initialise sensitivity code - CVodeSensInit1(mSolver, mSensitivityVectorsSize, CV_SIMULTANEOUS, NULL, mSensitivityVectors); + CVodeSensInit1(mSolver, mSensitivityVectorsSize, CV_SIMULTANEOUS, nullptr, mSensitivityVectors); CVodeSensEEtolerances(mSolver); CVodeSetSensErrCon(mSolver, SUNTRUE); - CVodeSetSensDQMethod(mSolver, CV_CENTERED, 0.0); // Specify which constants will have gradients calculated - CVodeSetSensParams(mSolver, mUserData->constants(), NULL, pGradientsIndices); + CVodeSetSensParams(mSolver, mUserData->constants(), nullptr, pGradientsIndices); } } //============================================================================== +void CvodeSolver::initialize(double pVoi, int pRatesStatesCount, + double *pConstants, double *pRates, + double *pStates, double *pAlgebraic, + ComputeRatesFunction pComputeRates) +{ + initialize(pVoi, pRatesStatesCount, pConstants, pRates, pStates, pAlgebraic, pComputeRates, 0, nullptr, nullptr); +} + +//============================================================================== + void CvodeSolver::reinitialize(double pVoi) { // Reinitialise our CVODES object diff --git a/src/plugins/solver/CVODESolver/src/cvodesolver.h b/src/plugins/solver/CVODESolver/src/cvodesolver.h index 923273b263..c950d4d764 100644 --- a/src/plugins/solver/CVODESolver/src/cvodesolver.h +++ b/src/plugins/solver/CVODESolver/src/cvodesolver.h @@ -137,14 +137,14 @@ class CvodeSolver : public OpenCOR::Solver::OdeSolver public: ~CvodeSolver() override; - void initialize(double pVoi, int pRatesStatesCount, double *pConstants, - double *pRates, double *pStates, double *pAlgebraic, - ComputeRatesFunction pComputeRates) override; void initialize(double pVoi, int pRatesStatesCount, double *pConstants, double *pRates, double *pStates, double *pAlgebraic, ComputeRatesFunction pComputeRates, int pGradientsCount, int *pGradientsIndices, double *pGradients) override; + void initialize(double pVoi, int pRatesStatesCount, double *pConstants, + double *pRates, double *pStates, double *pAlgebraic, + ComputeRatesFunction pComputeRates) override; void reinitialize(double pVoi) override; void solve(double &pVoi, double pVoiEnd) const override; diff --git a/src/plugins/support/PythonQtSupport/src/pythonqtsupportplugin.cpp b/src/plugins/support/PythonQtSupport/src/pythonqtsupportplugin.cpp index c5da405cff..6872446139 100644 --- a/src/plugins/support/PythonQtSupport/src/pythonqtsupportplugin.cpp +++ b/src/plugins/support/PythonQtSupport/src/pythonqtsupportplugin.cpp @@ -142,7 +142,7 @@ void PythonQtSupportPlugin::pluginsInitialized(const Plugins &pLoadedPlugins) // Register wrappers for every plugin that has a Python interface - foreach (Plugin *plugin, pLoadedPlugins) { + for (auto plugin : pLoadedPlugins) { PythonInterface *pythonInterface = qobject_cast(plugin->instance()); if (pythonInterface) { diff --git a/src/plugins/support/SimulationSupport/src/simulation.cpp b/src/plugins/support/SimulationSupport/src/simulation.cpp index ba92e6538e..51aa456827 100644 --- a/src/plugins/support/SimulationSupport/src/simulation.cpp +++ b/src/plugins/support/SimulationSupport/src/simulation.cpp @@ -1606,7 +1606,7 @@ QString Simulation::furtherInitialize() const QString kisaoId = QString::fromStdString(sedmlAlgorithm->getKisaoID()); - foreach (SolverInterface *solverInterface, solverInterfaces) { + for (auto solverInterface : solverInterfaces) { if (!solverInterface->id(kisaoId).compare(solverInterface->solverName())) { odeSolverInterface = solverInterface; @@ -1669,7 +1669,7 @@ QString Simulation::furtherInitialize() const mustHaveNlaSolver = true; nlaSolverName = QString::fromStdString(nlaSolverNode.getAttrValue(nlaSolverNode.getAttrIndex(SEDMLSupport::Name.toStdString()))); - foreach (SolverInterface *solverInterface, solverInterfaces) { + for (auto solverInterface : solverInterfaces) { if (!nlaSolverName.compare(solverInterface->solverName())) { mData->setNlaSolverName(nlaSolverName); diff --git a/src/plugins/support/SimulationSupport/src/simulationsupportpythonwrapper.cpp b/src/plugins/support/SimulationSupport/src/simulationsupportpythonwrapper.cpp index f20e210709..03e285e4dd 100644 --- a/src/plugins/support/SimulationSupport/src/simulationsupportpythonwrapper.cpp +++ b/src/plugins/support/SimulationSupport/src/simulationsupportpythonwrapper.cpp @@ -60,16 +60,15 @@ namespace SimulationSupport { //============================================================================== -static void setOdeSolver_(SimulationData *pSimulationData, const QString &pOdeSolverName) +static void doSetOdeSolver(SimulationData *pSimulationData, const QString &pOdeSolverName) { - foreach (SolverInterface *solverInterface, Core::solverInterfaces()) { + for (auto solverInterface : Core::solverInterfaces()) { if (!pOdeSolverName.compare(solverInterface->solverName())) { // Set the ODE solver's name pSimulationData->setOdeSolverName(pOdeSolverName); - foreach (const Solver::Property &solverInterfaceProperty, - solverInterface->solverProperties()) { + for (const auto &solverInterfaceProperty : solverInterface->solverProperties()) { // Set each ODE solver property's default value pSimulationData->addOdeSolverProperty(solverInterfaceProperty.id(), solverInterfaceProperty.defaultValue()); @@ -78,21 +77,21 @@ static void setOdeSolver_(SimulationData *pSimulationData, const QString &pOdeSo return; } } + throw std::runtime_error(QObject::tr("Unknown ODE solver.").toStdString()); } //============================================================================== -static void setNlaSolver_(SimulationData *pSimulationData, const QString &pNlaSolverName) +static void doSetNlaSolver(SimulationData *pSimulationData, const QString &pNlaSolverName) { - foreach (SolverInterface *solverInterface, Core::solverInterfaces()) { + for (auto solverInterface : Core::solverInterfaces()) { if (!pNlaSolverName.compare(solverInterface->solverName())) { // Set the NLA solver's name pSimulationData->setNlaSolverName(pNlaSolverName); - foreach (const Solver::Property &solverInterfaceProperty, - solverInterface->solverProperties()) { + for (const auto &solverInterfaceProperty : solverInterface->solverProperties()) { // Set each NLA solver property's default value pSimulationData->addNlaSolverProperty(solverInterfaceProperty.id(), solverInterfaceProperty.defaultValue()); @@ -101,6 +100,7 @@ static void setNlaSolver_(SimulationData *pSimulationData, const QString &pNlaSo return; } } + throw std::runtime_error(QObject::tr("Unknown NLA solver.").toStdString()); } @@ -136,7 +136,7 @@ static PyObject *initializeSimulation(const QString &pFileName) QString odeSolverName = QString(); QString nlaSolverName = QString(); - foreach (SolverInterface *solverInterface, Core::solverInterfaces()) { + for (auto solverInterface : Core::solverInterfaces()) { QString solverName = solverInterface->solverName(); if (solverInterface->solverType() == Solver::Type::Ode) { @@ -154,12 +154,12 @@ static PyObject *initializeSimulation(const QString &pFileName) // Set our solver and its default properties - setOdeSolver_(simulation->data(), odeSolverName); + doSetOdeSolver(simulation->data(), odeSolverName); // Set our NLA solver if we need one if ((runtime != nullptr) && runtime->needNlaSolver()) { - setNlaSolver_(simulation->data(), nlaSolverName); + doSetNlaSolver(simulation->data(), nlaSolverName); } // Complete initialisation by loading any SED-ML properties @@ -299,9 +299,9 @@ SimulationSupportPythonWrapper::SimulationSupportPythonWrapper(PyObject *pModule { Q_UNUSED(pModule) - PythonQtSupport::registerClass(&OpenCOR::SimulationSupport::Simulation::staticMetaObject); - PythonQtSupport::registerClass(&OpenCOR::SimulationSupport::SimulationData::staticMetaObject); - PythonQtSupport::registerClass(&OpenCOR::SimulationSupport::SimulationResults::staticMetaObject); + PythonQtSupport::registerClass(&Simulation::staticMetaObject); + PythonQtSupport::registerClass(&SimulationData::staticMetaObject); + PythonQtSupport::registerClass(&SimulationResults::staticMetaObject); PythonQtSupport::addInstanceDecorators(this); PyModule_AddFunctions(pModule, pythonSimulationSupportMethods); @@ -414,11 +414,11 @@ PyObject *SimulationSupportPythonWrapper::issues(Simulation *pSimulation) const bool SimulationSupportPythonWrapper::run(Simulation *pSimulation) { if (pSimulation->hasBlockingIssues()) { - throw std::runtime_error( - tr("Cannot run because simulation has blocking issues.").toStdString()); - } else if (!valid(pSimulation)) { - throw std::runtime_error( - tr("Cannot run because simulation has an invalid runtime.").toStdString()); + throw std::runtime_error(tr("Cannot run because simulation has blocking issues.").toStdString()); + } + + if (!valid(pSimulation)) { + throw std::runtime_error(tr("Cannot run because simulation has an invalid runtime.").toStdString()); } QWidget *focusWidget = nullptr; @@ -477,17 +477,18 @@ bool SimulationSupportPythonWrapper::run(Simulation *pSimulation) disconnect(pSimulation, nullptr, this, nullptr); - if (!mErrorMessage.isEmpty()) + if (!mErrorMessage.isEmpty()) { throw std::runtime_error(mErrorMessage.toStdString()); + } } else { - throw std::runtime_error( - tr("We could not allocate the memory required for the simulation.").toStdString()); + throw std::runtime_error(tr("We could not allocate the memory required for the simulation.").toStdString()); } // Restore the keyboard focus back to IPython - if (focusWidget) + if (focusWidget) { focusWidget->setFocus(); + } return mElapsedTime >= 0; } @@ -525,14 +526,14 @@ void SimulationSupportPythonWrapper::setPointInterval(SimulationData *pSimulatio void SimulationSupportPythonWrapper::setOdeSolver(SimulationData *pSimulationData, const QString &pOdeSolverName) { - setOdeSolver_(pSimulationData, pOdeSolverName); + doSetOdeSolver(pSimulationData, pOdeSolverName); } //============================================================================== void SimulationSupportPythonWrapper::setNlaSolver(SimulationData *pSimulationData, const QString &pNlaSolverName) { - setNlaSolver_(pSimulationData, pNlaSolverName); + doSetNlaSolver(pSimulationData, pNlaSolverName); } //==============================================================================