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"
51#include <cxxtest/TestSuite.h>
57 bool doComputeExceptVoltage=
true,
58 bool useSamplingInterval=
false);
60void CheckCellModelResults(
const std::string& rBaseResultsFilename,
61 std::string validResultsBasename =
"",
62 double tolerance = 1e-3,
63 std::string referenceFolder =
"heart/test/data/ionicmodels");
67void CompareCellModelResults(std::string baseResultsFilename1, std::string baseResultsFilename2,
68 double tolerance,
bool vOnly=
false, std::string folderName=
"TestIonicModels");
83 bool doComputeExceptVoltage,
84 bool useSamplingInterval)
86 double start_time = 0.0;
88 if (doComputeExceptVoltage)
97 TS_ASSERT_DELTA(v_init, v_end, 1e-6);
101 TS_ASSERT_DELTA(pOdeSystem->
GetVoltage(), 1e6, 1e-6);
108 if (useSamplingInterval)
111 solution.
WriteToFile(
"TestIonicModels", filename,
"ms", 1,
false, 4);
116 solution.
WriteToFile(
"TestIonicModels", filename,
"ms", stepPerRow,
false, 4);
124 std::vector<double> voltages;
129 else if (rReader.
HasValues(
"membrane_voltage"))
131 voltages = rReader.
GetValues(
"membrane_voltage");
133 else if (rReader.
HasValues(
"membrane__V"))
135 voltages = rReader.
GetValues(
"membrane__V");
139 EXCEPTION(
"Model membrane voltage not recognised.");
148 std::vector<double> cai;
153 else if (rReader.
HasValues(
"cytosolic_calcium_concentration"))
155 cai = rReader.
GetValues(
"cytosolic_calcium_concentration");
163 EXCEPTION(
"Model intracellular calcium is not recognised.");
172 std::vector<double> h_values;
177 else if (rReader.
HasValues(
"fast_sodium_current_h_gate__h"))
179 h_values = rReader.
GetValues(
"fast_sodium_current_h_gate__h");
181 else if (rReader.
HasValues(
"membrane_fast_sodium_current_h_gate"))
183 h_values = rReader.
GetValues(
"membrane_fast_sodium_current_h_gate");
187 EXCEPTION(
"Model h gate is not recognised.");
196void CheckCellModelResults(
const std::string& rBaseResultsFilename,
197 std::string validResultsBasename,
199 std::string referenceFolder)
203 std::vector<double> times = data_reader.GetValues(
"Time");
204 std::vector<double> voltages = GetVoltages(data_reader);
206 if (validResultsBasename ==
"")
208 validResultsBasename = rBaseResultsFilename;
211 ColumnDataReader valid_reader(referenceFolder, validResultsBasename +
"ValidData",
213 std::vector<double> valid_times = valid_reader.GetValues(
"Time");
214 std::vector<double> valid_voltages = GetVoltages(valid_reader);
216 TS_ASSERT_EQUALS(times.size(), valid_times.size());
217 for (
unsigned i=0; i<valid_times.size(); i++)
219 TS_ASSERT_DELTA(times[i], valid_times[i], 1e-12);
220 TS_ASSERT_DELTA(voltages[i], valid_voltages[i], tolerance);
224void CompareCellModelResults(std::string baseResultsFilename1, std::string baseResultsFilename2,
225 double tolerance,
bool vOnly, std::string folderName)
230 std::vector<double> times1 = data_reader1.GetValues(
"Time");
231 std::vector<double> voltages1 = GetVoltages(data_reader1);
232 std::vector<double> calcium1;
233 std::vector<double> h1;
236 std::vector<double> times2 = data_reader2.GetValues(
"Time");
237 std::vector<double> voltages2 = GetVoltages(data_reader2);
238 std::vector<double> calcium2;
239 std::vector<double> h2;
243 calcium1 = GetIntracellularCalcium(data_reader1);
244 h1 = GetHGate(data_reader1);
245 calcium2 = GetIntracellularCalcium(data_reader2);
246 h2 = GetHGate(data_reader2);
249 TS_ASSERT(times1.size() >= times2.size());
250 double last_v = voltages2[0];
251 double tol = tolerance;
252 for (
unsigned i=0, j=0; i<times2.size(); i++)
255 while (j<times1.size() && times1[j] < times2[i] - 1e-12)
261 if (fabs(voltages2[i] - last_v) > 0.05)
263 tol = tolerance * 25;
269 last_v = voltages2[i];
271 TS_ASSERT_DELTA(times1[j], times2[i], 1e-12);
273 TS_ASSERT_DELTA(voltages1[j], voltages2[i], tol);
276 TS_ASSERT_DELTA(calcium1[j], calcium2[i], tol/100);
277 TS_ASSERT_DELTA(h1[j], h2[i], tol/10);
#define EXCEPTION(message)
virtual void SetStateVariables(const std::vector< double > &rVariables)=0
virtual void ComputeExceptVoltage(double tStart, double tEnd)=0
virtual double GetVoltage()=0
virtual std::vector< double > GetStdVecStateVariables()=0
virtual OdeSolution Compute(double tStart, double tEnd, double tSamp=0.0)=0
virtual void SetVoltage(double voltage)=0
bool HasValues(const std::string &rVariableName)
std::vector< double > GetValues(const std::string &rVariableName)
static HeartConfig * Instance()
void WriteToFile(std::string directoryName, std::string baseResultsFilename, std::string timeUnits, unsigned stepsPerRow=1, bool cleanDirectory=true, unsigned precision=8, bool includeDerivedQuantities=false)