diff --git a/src/plugins/solverinterface.cpp b/src/plugins/solverinterface.cpp index 5923ffd13a..5a7b57dfe1 100644 --- a/src/plugins/solverinterface.cpp +++ b/src/plugins/solverinterface.cpp @@ -25,10 +25,6 @@ along with this program. If not, see . //============================================================================== -#include - -//============================================================================== - void doNonLinearSolve(char *pRuntime, void (*pFunction)(double *, double *, void *), double *pParameters, int pSize, void *pUserData) @@ -135,32 +131,33 @@ NlaSolver::~NlaSolver() = default; //============================================================================== -NlaSolver * nlaSolver(const QString &pRuntimeAddress) +QString objectAddress(QObject *pObject) { - // Return the runtime's NLA solver - - QVariant res = qApp->property(pRuntimeAddress.toUtf8().constData()); + // Return the given object's address as a string - return res.isValid()?reinterpret_cast(res.toULongLong()):nullptr; + return QString::number(quint64(pObject)); } //============================================================================== -void setNlaSolver(const QString &pRuntimeAddress, NlaSolver *pGlobalNlaSolver) +NlaSolver * nlaSolver(const QString &pObjectAddress) { - // Keep track of the runtime's NLA solver + // Return the runtime's NLA solver + + QObject *object = reinterpret_cast(QVariant(pObjectAddress).toULongLong()); + QVariant res = object->property(pObjectAddress.toUtf8().constData()); - qApp->setProperty(pRuntimeAddress.toUtf8().constData(), - quint64(pGlobalNlaSolver)); + return res.isValid()?reinterpret_cast(res.toULongLong()):nullptr; } //============================================================================== -void unsetNlaSolver(const QString &pRuntimeAddress) +void setNlaSolver(QObject *pObject, NlaSolver *pGlobalNlaSolver) { - // Stop tracking the runtime's NLA solver + // Keep track of the runtime's NLA solver - qApp->setProperty(pRuntimeAddress.toUtf8().constData(), QVariant::Invalid); + pObject->setProperty(objectAddress(pObject).toUtf8().constData(), + quint64(pGlobalNlaSolver)); } //============================================================================== diff --git a/src/plugins/solverinterface.h b/src/plugins/solverinterface.h index 38eef5661d..43d1cfbe58 100644 --- a/src/plugins/solverinterface.h +++ b/src/plugins/solverinterface.h @@ -111,10 +111,11 @@ class NlaSolver : public Solver //============================================================================== -NlaSolver * nlaSolver(const QString &pRuntimeAddress); +QString objectAddress(QObject *pObject); -void setNlaSolver(const QString &pRuntimeAddress, NlaSolver *pGlobalNlaSolver); -void unsetNlaSolver(const QString &pRuntimeAddress); +NlaSolver * nlaSolver(const QString &pObjectAddress); + +void setNlaSolver(QObject *pObject, NlaSolver *pGlobalNlaSolver); //============================================================================== diff --git a/src/plugins/support/CellMLSupport/src/cellmlfileruntime.cpp b/src/plugins/support/CellMLSupport/src/cellmlfileruntime.cpp index a3419b05e3..45d88872c2 100644 --- a/src/plugins/support/CellMLSupport/src/cellmlfileruntime.cpp +++ b/src/plugins/support/CellMLSupport/src/cellmlfileruntime.cpp @@ -585,15 +585,6 @@ void CellmlFileRuntime::update(CellmlFile *pCellmlFile, bool pAll) //============================================================================== -QString CellmlFileRuntime::address() const -{ - // Return our address as a string - - return QString::number(quint64(this)); -} - -//============================================================================== - bool CellmlFileRuntime::isValid() const { // The runtime is valid if no issues were found @@ -969,7 +960,7 @@ QString CellmlFileRuntime::cleanCode(const std::wstring &pCode) // new parameter to all our calls to doNonLinearSolve() so that // doNonLinearSolve() can retrieve the correct instance of our NLA solver - res.replace("do_nonlinearsolve(", QString(R"(doNonLinearSolve("%1", )").arg(address())); + res.replace("do_nonlinearsolve(", QString(R"(doNonLinearSolve("%1", )").arg(Solver::objectAddress(this))); return res; } diff --git a/src/plugins/support/CellMLSupport/src/cellmlfileruntime.h b/src/plugins/support/CellMLSupport/src/cellmlfileruntime.h index 0f6d8931b8..2bb37a2b83 100644 --- a/src/plugins/support/CellMLSupport/src/cellmlfileruntime.h +++ b/src/plugins/support/CellMLSupport/src/cellmlfileruntime.h @@ -140,8 +140,6 @@ class CELLMLSUPPORT_EXPORT CellmlFileRuntime : public QObject void update(CellmlFile *pCellmlFile, bool pAll = true); - QString address() const; - bool isValid() const; bool needNlaSolver() const; diff --git a/src/plugins/support/SimulationSupport/src/simulation.cpp b/src/plugins/support/SimulationSupport/src/simulation.cpp index 17fe5dd197..17d6794cb3 100644 --- a/src/plugins/support/SimulationSupport/src/simulation.cpp +++ b/src/plugins/support/SimulationSupport/src/simulation.cpp @@ -531,11 +531,10 @@ void SimulationData::reset(bool pInitialize, bool pAll) if (runtime->needNlaSolver()) { // Set our NLA solver - // Note: we unset it at the end of this method... nlaSolver = static_cast(nlaSolverInterface()->solverInstance()); - Solver::setNlaSolver(runtime->address(), nlaSolver); + Solver::setNlaSolver(runtime, nlaSolver); // Keep track of any error that might be reported by our NLA solver @@ -595,8 +594,6 @@ void SimulationData::reset(bool pInitialize, bool pAll) if (nlaSolver != nullptr) { delete nlaSolver; - - Solver::unsetNlaSolver(runtime->address()); } // Let people know whether our data is clean, i.e. not modified, and ask our diff --git a/src/plugins/support/SimulationSupport/src/simulationworker.cpp b/src/plugins/support/SimulationSupport/src/simulationworker.cpp index 5da0dd3b68..328d82f70e 100644 --- a/src/plugins/support/SimulationSupport/src/simulationworker.cpp +++ b/src/plugins/support/SimulationSupport/src/simulationworker.cpp @@ -90,14 +90,13 @@ void SimulationWorker::run() auto odeSolver = static_cast(mSimulation->data()->odeSolverInterface()->solverInstance()); // Set up our NLA solver, if needed - // Note: we unset it at the end of this method... Solver::NlaSolver *nlaSolver = nullptr; if (mRuntime->needNlaSolver()) { nlaSolver = static_cast(mSimulation->data()->nlaSolverInterface()->solverInstance()); - Solver::setNlaSolver(mRuntime->address(), nlaSolver); + Solver::setNlaSolver(mRuntime, nlaSolver); } // Keep track of any error that might be reported by any of our solvers @@ -254,8 +253,6 @@ void SimulationWorker::run() if (nlaSolver != nullptr) { delete nlaSolver; - - Solver::unsetNlaSolver(mRuntime->address()); } // Reset our simulation owner's knowledge of us