/
initializesolver.cpp.inl
123 lines (100 loc) · 4.5 KB
/
initializesolver.cpp.inl
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
#ifdef GUI_SUPPORT
bool SimulationExperimentViewSimulationWidget::initializeSolver(const libsedml::SedListOfAlgorithmParameters *pSedmlAlgorithmParameters,
const QString &pKisaoId,
SimulationExperimentViewInformationSolversWidgetData *pSolverData)
#else
QString Simulation::initializeSolver(const libsedml::SedListOfAlgorithmParameters *pSedmlAlgorithmParameters,
const QString &pKisaoId) const
#endif
{
// Initialise our solver using the given SED-ML algorithm parameters and
// KiSAO id
SolverInterface *solverInterface = nullptr;
#ifdef GUI_SUPPORT
Core::Properties solverProperties = Core::Properties();
#endif
for (auto coreSolverInterface : Core::solverInterfaces()) {
if (coreSolverInterface->id(pKisaoId) == coreSolverInterface->solverName()) {
solverInterface = coreSolverInterface;
#ifdef GUI_SUPPORT
solverProperties = pSolverData->solversProperties().value(coreSolverInterface->solverName());
pSolverData->solversListProperty()->setValue(coreSolverInterface->solverName());
#else
mData->setOdeSolverName(coreSolverInterface->solverName());
#endif
break;
}
}
if (solverInterface == nullptr) {
#ifdef GUI_SUPPORT
simulationError(QObject::tr("the requested solver (%1) could not be found").arg(pKisaoId),
Error::InvalidSimulationEnvironment);
return false;
#else
return QObject::tr("the requested solver (%1) could not be found").arg(pKisaoId);
#endif
}
for (uint i = 0, iMax = pSedmlAlgorithmParameters->getNumAlgorithmParameters(); i < iMax; ++i) {
const libsedml::SedAlgorithmParameter *sedmlAlgorithmParameter = pSedmlAlgorithmParameters->get(i);
QString parameterKisaoId = QString::fromStdString(sedmlAlgorithmParameter->getKisaoID());
#ifdef GUI_SUPPORT
QString id = solverInterface->id(parameterKisaoId);
bool propertySet = false;
for (auto solverProperty : solverProperties) {
if (solverProperty->id() == id) {
QVariant solverPropertyValue = QString::fromStdString(sedmlAlgorithmParameter->getValue());
switch (solverProperty->type()) {
case Core::Property::Type::Section:
// We should never come here...
#ifdef QT_DEBUG
qFatal("FATAL ERROR | %s:%d: a solver property cannot be of section type.", __FILE__, __LINE__);
#else
break;
#endif
case Core::Property::Type::String:
solverProperty->setValue(solverPropertyValue.toString());
break;
case Core::Property::Type::Integer:
case Core::Property::Type::IntegerGe0:
case Core::Property::Type::IntegerGt0:
solverProperty->setIntegerValue(solverPropertyValue.toInt());
break;
case Core::Property::Type::Double:
case Core::Property::Type::DoubleGe0:
case Core::Property::Type::DoubleGt0:
solverProperty->setDoubleValue(solverPropertyValue.toDouble());
break;
case Core::Property::Type::List:
solverProperty->setListValue(solverPropertyValue.toString());
break;
case Core::Property::Type::Boolean:
solverProperty->setBooleanValue(solverPropertyValue.toBool());
break;
case Core::Property::Type::Color:
// We should never come here...
#ifdef QT_DEBUG
qFatal("FATAL ERROR | %s:%d: a solver property cannot be of colour type.", __FILE__, __LINE__);
#else
break;
#endif
}
propertySet = solverProperty->type() != Core::Property::Type::Section;
break;
}
}
if (!propertySet) {
simulationError(QObject::tr("the requested solver property (%1) could not be set").arg(parameterKisaoId),
Error::InvalidSimulationEnvironment);
return false;
}
#else
mData->addOdeSolverProperty(solverInterface->id(parameterKisaoId),
QString::fromStdString(sedmlAlgorithmParameter->getValue()));
#endif
}
#ifdef GUI_SUPPORT
return true;
#else
return {};
#endif
}