37 #ifndef _RUNANDCHECKIONICMODELS_HPP_ 38 #define _RUNANDCHECKIONICMODELS_HPP_ 43 #include "OdeSolution.hpp" 45 #include "ColumnDataWriter.hpp" 46 #include "ColumnDataReader.hpp" 48 #include "AbstractCardiacCell.hpp" 49 #include "HeartConfig.hpp" 55 bool doComputeExceptVoltage=
true,
56 bool useSamplingInterval=
false);
58 void CheckCellModelResults(
const std::string& rBaseResultsFilename,
59 std::string validResultsBasename =
"",
60 double tolerance = 1e-3,
61 std::string referenceFolder =
"heart/test/data/ionicmodels");
65 void CompareCellModelResults(std::string baseResultsFilename1, std::string baseResultsFilename2,
66 double tolerance,
bool vOnly=
false, std::string folderName=
"TestIonicModels");
81 bool doComputeExceptVoltage,
82 bool useSamplingInterval)
84 double start_time = 0.0;
86 if (doComputeExceptVoltage)
95 TS_ASSERT_DELTA(v_init, v_end, 1e-6);
99 TS_ASSERT_DELTA(pOdeSystem->
GetVoltage(), 1e6, 1e-6);
106 if (useSamplingInterval)
109 solution.
WriteToFile(
"TestIonicModels", filename,
"ms", 1,
false, 4);
114 solution.
WriteToFile(
"TestIonicModels", filename,
"ms", stepPerRow,
false, 4);
122 std::vector<double> voltages;
127 else if (rReader.
HasValues(
"membrane_voltage"))
129 voltages = rReader.
GetValues(
"membrane_voltage");
131 else if (rReader.
HasValues(
"membrane__V"))
133 voltages = rReader.
GetValues(
"membrane__V");
137 EXCEPTION(
"Model membrane voltage not recognised.");
146 std::vector<double> cai;
151 else if (rReader.
HasValues(
"cytosolic_calcium_concentration"))
153 cai = rReader.
GetValues(
"cytosolic_calcium_concentration");
161 EXCEPTION(
"Model intracellular calcium is not recognised.");
170 std::vector<double> h_values;
175 else if (rReader.
HasValues(
"fast_sodium_current_h_gate__h"))
177 h_values = rReader.
GetValues(
"fast_sodium_current_h_gate__h");
179 else if (rReader.
HasValues(
"membrane_fast_sodium_current_h_gate"))
181 h_values = rReader.
GetValues(
"membrane_fast_sodium_current_h_gate");
185 EXCEPTION(
"Model h gate is not recognised.");
194 void CheckCellModelResults(
const std::string& rBaseResultsFilename,
195 std::string validResultsBasename,
197 std::string referenceFolder)
201 std::vector<double> times = data_reader.GetValues(
"Time");
202 std::vector<double> voltages = GetVoltages(data_reader);
204 if (validResultsBasename ==
"")
206 validResultsBasename = rBaseResultsFilename;
209 ColumnDataReader valid_reader(referenceFolder, validResultsBasename +
"ValidData",
211 std::vector<double> valid_times = valid_reader.GetValues(
"Time");
212 std::vector<double> valid_voltages = GetVoltages(valid_reader);
214 TS_ASSERT_EQUALS(times.size(), valid_times.size());
215 for (
unsigned i=0; i<valid_times.size(); i++)
217 TS_ASSERT_DELTA(times[i], valid_times[i], 1e-12);
218 TS_ASSERT_DELTA(voltages[i], valid_voltages[i], tolerance);
222 void CompareCellModelResults(std::string baseResultsFilename1, std::string baseResultsFilename2,
223 double tolerance,
bool vOnly, std::string folderName)
228 std::vector<double> times1 = data_reader1.GetValues(
"Time");
229 std::vector<double> voltages1 = GetVoltages(data_reader1);
230 std::vector<double> calcium1;
231 std::vector<double> h1;
234 std::vector<double> times2 = data_reader2.GetValues(
"Time");
235 std::vector<double> voltages2 = GetVoltages(data_reader2);
236 std::vector<double> calcium2;
237 std::vector<double> h2;
241 calcium1 = GetIntracellularCalcium(data_reader1);
242 h1 = GetHGate(data_reader1);
243 calcium2 = GetIntracellularCalcium(data_reader2);
244 h2 = GetHGate(data_reader2);
247 TS_ASSERT(times1.size() >= times2.size());
248 double last_v = voltages2[0];
249 double tol = tolerance;
250 for (
unsigned i=0, j=0; i<times2.size(); i++)
253 while (j<times1.size() && times1[j] < times2[i] - 1e-12)
259 if (fabs(voltages2[i] - last_v) > 0.05)
261 tol = tolerance * 25;
267 last_v = voltages2[i];
269 TS_ASSERT_DELTA(times1[j], times2[i], 1e-12);
271 TS_ASSERT_DELTA(voltages1[j], voltages2[i], tol);
274 TS_ASSERT_DELTA(calcium1[j], calcium2[i], tol/100);
275 TS_ASSERT_DELTA(h1[j], h2[i], tol/10);
281 #endif //_RUNANDCHECKIONICMODELS_HPP_ bool HasValues(const std::string &rVariableName)
virtual double GetVoltage()=0
#define EXCEPTION(message)
std::vector< double > GetValues(const std::string &rVariableName)
virtual std::vector< double > GetStdVecStateVariables()=0
virtual void SetStateVariables(const std::vector< double > &rVariables)=0
virtual OdeSolution Compute(double tStart, double tEnd, double tSamp=0.0)=0
void WriteToFile(std::string directoryName, std::string baseResultsFilename, std::string timeUnits, unsigned stepsPerRow=1, bool cleanDirectory=true, unsigned precision=8, bool includeDerivedQuantities=false)
virtual void ComputeExceptVoltage(double tStart, double tEnd)=0
virtual void SetVoltage(double voltage)=0
static HeartConfig * Instance()