CommonDataModelTest.h
1 // The following tests will be exported and runnable
2 #include <string>
3 #include <sstream>
4 #include <vector>
5 
6 #include <biogears/circuit_test_exports.h>
7 // #include <biogears/schema/biogears-cdm.hxx>
8 #include <biogears/cdm/CommonDataModel.h>
9 #include <biogears/cdm/circuit/SECircuitManager.h>
10 #include <biogears/cdm/circuit/fluid/SEFluidCircuit.h>
11 #include <biogears/cdm/circuit/fluid/SEFluidCircuitCalculator.h>
12 #include <biogears/cdm/compartment/fluid/SEFluidCompartment.h>
13 #include <biogears/cdm/compartment/fluid/SELiquidCompartmentGraph.h>
14 #include <biogears/cdm/compartment/substances/SEGasSubstanceQuantity.h>
15 #include <biogears/cdm/compartment/thermal/SEThermalCompartment.h>
16 #include <biogears/cdm/compartment/fluid/SELiquidCompartment.h>
17 #include <biogears/cdm/utils/testing/SETestCase.h>
18 #include <biogears/cdm/utils/testing/SETestSuite.h>
19 
20 namespace biogears {
21 class SECompartmentManager;
22 
24  SIN,
27 
28 class BIOGEARS_CIRCUIT_TEST_API CommonDataModelTest : public Loggable {
29 public:
31  CommonDataModelTest(Logger* logger);
32  virtual ~CommonDataModelTest();
33 
34  bool RunTest(const std::string& testName,
35  const std::string& sOutputDirectory);
36  void FillFunctionMap();
37 
38 protected:
39  bool myLogger;
41  std::string m_OutDirectory;
42  std::stringstream m_ss;
43 
44  typedef void (CommonDataModelTest::*testFunction)(const std::string&);
45  typedef std::map<std::string, testFunction> testMap;
46  testMap cdmMap;
47 
49  // Circuits //
51 public:
52  // Basic Circuit Tests
53  void BasicCircuitTest(const std::string& sOutputDirectory);
54 
55  void SeriesRCDCTest(const std::string& sOutputDirectory);
56  void SeriesRCSINTest(const std::string& sOutputDirectory);
57  void SeriesRCPULSETest(const std::string& sOutputDirectory);
58 
59  void SeriesRDCTest(const std::string& sOutputDirectory);
60  void SeriesRSINTest(const std::string& sOutputDirectory);
61  void SeriesRPULSETest(const std::string& sOutputDirectory);
62 
63  void SeriesRLDCTest(const std::string& sOutputDirectory);
64  void SeriesRLSINTest(const std::string& sOutputDirectory);
65  void SeriesRLPULSETest(const std::string& sOutputDirectory);
66 
67  void ParallelRDCTest(const std::string& sOutputDirectory);
68  void ParallelRSINTest(const std::string& sOutputDirectory);
69  void ParallelRPULSETest(const std::string& sOutputDirectory);
70 
71  void ParallelRCDCTest(const std::string& sOutputDirectory);
72  void ParallelRCSINTest(const std::string& sOutputDirectory);
73  void ParallelRCPULSETest(const std::string& sOutputDirectory);
74 
75  void ParallelRLDCTest(const std::string& sOutputDirectory);
76  void ParallelRLSINTest(const std::string& sOutputDirectory);
77  void ParallelRLPULSETest(const std::string& sOutputDirectory);
78  void ParallelRLSINCenteredTest(const std::string& sOutputDirectory);
79 
80  void SeriesRLCDCTest(const std::string& sOutputDirectory);
81  void SeriesRLCSINTest(const std::string& sOutputDirectory);
82  void SeriesRLCPULSETest(const std::string& sOutputDirectory);
83 
84  void ParallelRLCDCTest(const std::string& sOutputDirectory);
85  void ParallelRLCSINTest(const std::string& sOutputDirectory);
86  void ParallelRLCPULSETest(const std::string& sOutputDirectory);
87 
88  void SwitchRCDCTest(const std::string& sOutputDirectory);
89  void SwitchRCSINTest(const std::string& sOutputDirectory);
90  void SwitchRCPULSETest(const std::string& sOutputDirectory);
91 
92  void Comprehensive1DCTest(const std::string& sOutputDirectory);
93  void Comprehensive1SINTest(const std::string& sOutputDirectory);
94  void Comprehensive1PULSETest(const std::string& sOutputDirectory);
95 
96  void SimpleDiodeDCTest(const std::string& sOutputDirectory);
97  void SimpleDiodeSINTest(const std::string& sOutputDirectory);
98  void SimpleDiodePULSETest(const std::string& sOutputDirectory);
99 
100  void SeriesRCDCCurrentTest(const std::string& sOutputDirectory);
101  void SeriesRCSINCurrentTest(const std::string& sOutputDirectory);
102  void SeriesRCPULSECurrentTest(const std::string& sOutputDirectory);
103 
104  void ParallelRCDCCurrentTest(const std::string& sOutputDirectory);
105  void ParallelRCSINCurrentTest(const std::string& sOutputDirectory);
106  void ParallelRCPULSECurrentTest(const std::string& sOutputDirectory);
107 
108  void SeriesCapDCTest(const std::string& sOutputDirectory);
109  void SeriesCapSINTest(const std::string& sOutputDirectory);
110  void SeriesCapPULSETest(const std::string& sOutputDirectory);
111 
112  void ParallelRDCCurrentTest(const std::string& sOutputDirectory);
113  void ParallelRSINCurrentTest(const std::string& sOutputDirectory);
114  void ParallelRPULSECurrentTest(const std::string& sOutputDirectory);
115 
116  void CurrentCompDCTest(const std::string& sOutputDirectory);
117  void CurrentCompSINTest(const std::string& sOutputDirectory);
118  void CurrentCompPULSETest(const std::string& sOutputDirectory);
119 
120  void SeriesRLDCCurrentTest(const std::string& sOutputDirectory);
121  void SeriesRLSINCurrentTest(const std::string& sOutputDirectory);
122  void SeriesRLPULSECurrentTest(const std::string& sOutputDirectory);
123 
124  void ParallelRLDCCurrentTest(const std::string& sOutputDirectory);
125  void ParallelRLSINCurrentTest(const std::string& sOutputDirectory);
126  void ParallelRLPULSECurrentTest(const std::string& sOutputDirectory);
127 
128  void BasicDiodeDCCurrentTest(const std::string& sOutputDirectory);
129  void BasicDiodeSINCurrentTest(const std::string& sOutputDirectory);
130  void BasicDiodePULSECurrentTest(const std::string& sOutputDirectory);
131 
132  // NOTE: These next three tests seem to give errors while running, but they
133  // produce output...
134  void SwitchRCDCCurrentTest(const std::string& sOutputDirectory);
135  void SwitchRCSINCurrentTest(const std::string& sOutputDirectory);
136  void SwitchRCPULSECurrentTest(const std::string& sOutputDirectory);
137 
138  void SeriesRLCDCCurrentTest(const std::string& sOutputDirectory);
139  void SeriesRLCSINCurrentTest(const std::string& sOutputDirectory);
140  void SeriesRLCPULSECurrentTest(const std::string& sOutputDirectory);
141 
142  void ParallelRLCDCCurrentTest(const std::string& sOutputDirectory);
143  void ParallelRLCSINCurrentTest(const std::string& sOutputDirectory);
144  void ParallelRLCPULSECurrentTest(const std::string& sOutputDirectory);
145 
146  void SeriesPressureSourceAdditionDCTest(const std::string& sOutputDirectory);
147  void SeriesPressureSourceAdditionSINTest(const std::string& sOutputDirectory);
148  void
149  SeriesPressureSourceAdditionPULSETest(const std::string& sOutputDirectory);
150 
151  // NOTE: These next six tests seem to give errors while running, but it's
152  // intentional
153  void SeriesCurrentSourceAdditionDCTest(const std::string& sOutputDirectory);
154  void SeriesCurrentSourceAdditionSINTest(const std::string& sOutputDirectory);
155  void
156  SeriesCurrentSourceAdditionPULSETest(const std::string& sOutputDirectory);
157 
158  void
159  ParallelPressureSourceAdditionDCTest(const std::string& sOutputDirectory);
160  void
161  ParallelPressureSourceAdditionSINTest(const std::string& sOutputDirectory);
162  void
163  ParallelPressureSourceAdditionPULSETest(const std::string& sOutputDirectory);
164 
165  void ParallelCurrentSourceAdditionDCTest(const std::string& sOutputDirectory);
166  void
167  ParallelCurrentSourceAdditionSINTest(const std::string& sOutputDirectory);
168  void
169  ParallelCurrentSourceAdditionPULSETest(const std::string& sOutputDirectory);
170 
171  void SeriesCapDCCurrentTest(const std::string& sOutputDirectory);
172  void SeriesCapSINCurrentTest(const std::string& sOutputDirectory);
173  void SeriesCapPULSECurrentTest(const std::string& sOutputDirectory);
174 
175  void ParallelCapDCTest(const std::string& sOutputDirectory);
176  void ParallelCapSINTest(const std::string& sOutputDirectory);
177  void ParallelCapPULSETest(const std::string& sOutputDirectory);
178 
179  void ParallelCapDCCurrentTest(const std::string& sOutputDirectory);
180  void ParallelCapSINCurrentTest(const std::string& sOutputDirectory);
181  void ParallelCapPULSECurrentTest(const std::string& sOutputDirectory);
182 
183  void SeriesIndDCTest(const std::string& sOutputDirectory);
184  void SeriesIndSINTest(const std::string& sOutputDirectory);
185  void SeriesIndPULSETest(const std::string& sOutputDirectory);
186 
187  void SeriesIndDCCurrentTest(const std::string& sOutputDirectory);
188  void SeriesIndSINCurrentTest(const std::string& sOutputDirectory);
189  void SeriesIndPULSECurrentTest(const std::string& sOutputDirectory);
190 
191  void ParallelIndDCTest(const std::string& sOutputDirectory);
192  void ParallelIndSINTest(const std::string& sOutputDirectory);
193  void ParallelIndPULSETest(const std::string& sOutputDirectory);
194 
195  void ParallelIndDCCurrentTest(const std::string& sOutputDirectory);
196  void ParallelIndSINCurrentTest(const std::string& sOutputDirectory);
197  void ParallelIndPULSECurrentTest(const std::string& sOutputDirectory);
198 
199  // These next three tests intentionally fail
200  void BadDiodeDCTest(const std::string& sOutputDirectory);
201  void BadDiodeSINTest(const std::string& sOutputDirectory);
202  void BadDiodePULSETest(const std::string& sOutputDirectory);
203 
204  void ValidationComprehensive1DCTest(const std::string& sOutputDirectory);
205  void ValidationComprehensive1SINTest(const std::string& sOutputDirectory);
206  void ValidationComprehensive1PULSETest(const std::string& sOutputDirectory);
207  void
208  ValidationComprehensive1SINCenteredTest(const std::string& sOutputDirectory);
209 
210  void ValidationComprehensive2DCTest(const std::string& sOutputDirectory);
211  void ValidationComprehensive2SINTest(const std::string& sOutputDirectory);
212  void ValidationComprehensive2PULSETest(const std::string& sOutputDirectory);
213  void
214  ValidationComprehensive2SINCenteredTest(const std::string& sOutputDirectory);
215 
216  // Advanced Circuit Tests
217  void ElectricalCircuitTest(const std::string& sOutputDirectory);
218  void FluidCircuitTest(const std::string& sOutputDirectory);
219  void ThermalCircuitTest(const std::string& sOutputDirectory);
220  void CombinedCircuitTest(const std::string& sOutputDirectory);
221  void InterCircuitComparisonTest(const std::string& sOutputDirectory);
222  void InterCircuitIndividualTest(
223  const std::string& sOutputDirectory); // This one outputs two files
224  void CircuitErrorTest(
225  const std::string& sOutputDirectory); // This one doesn't output anything right now
226  void DynamicallyChangingCircuitTest(
227  const std::string& sOutputDirectory); // This one has some really strange output (-1.$)
228  void NonZeroReferencePositive(const std::string& sOutputDirectory);
229  void NonZeroReferenceNegative(const std::string& sOutputDirectory);
230  void PolarizedCapacitorTest(const std::string& sOutputDirectory);
231  void PreChargeComplianceZeroVolume(const std::string& sOutputDirectory);
232  void PreChargeComplianceNonZeroVolume(const std::string& sOutputDirectory);
233  void CircuitLockingTest(const std::string& sOutputDirectory);
234 
235 protected:
236  // Used to generalize Basic Tests
237  void RunTest(const std::string& sOutputDirectory, const std::string& testName,
238  enumCDMTestSourceType sourceType, int testIndex);
239 
240  // Setup and preprocess methods for Basic Tests
241  void TestSetup7SeriesRCDC();
242  void TestSetup7SeriesRCSIN();
243  void TestSetup7SeriesRCPULSE();
244  void TestSetup8SeriesRDC();
245  void TestSetup8SeriesRSIN();
246  void TestSetup8SeriesRPULSE();
247  void TestSetup9SeriesRLDC();
248  void TestSetup9SeriesRLSIN();
249  void TestSetup9SeriesRLPULSE();
250  void TestSetup10ParallelRDC();
251  void TestSetup10ParallelRSIN();
252  void TestSetup10ParallelRPULSE();
253  void TestSetup11ParallelRCDC();
254  void TestSetup11ParallelRCSIN();
255  void TestSetup11ParallelRCPULSE();
256  void TestSetup12ParallelRLDC();
257  void TestSetup12ParallelRLSIN();
258  void TestSetup12ParallelRLPULSE();
259  void TestSetup12ParallelRLSINCentered();
260  void TestSetup13SeriesRLCDC();
261  void TestSetup13SeriesRLCSIN();
262  void TestSetup13SeriesRLCPULSE();
263  void TestSetup14ParallelRLCDC();
264  void TestSetup14ParallelRLCSIN();
265  void TestSetup14ParallelRLCPULSE();
266  void TestSetup15SwitchRCDC();
267  void TestSetup15SwitchRCSIN();
268  void TestSetup15SwitchRCPULSE();
269  void TestSetup16Comprehensive1DC();
270  void TestSetup16Comprehensive1SIN();
271  void TestSetup16Comprehensive1PULSE();
272  void TestSetup17BasicDiodeDC();
273  void TestSetup17BasicDiodeSIN();
274  void TestSetup17BasicDiodePULSE();
275  void TestSetup18RCSeriesDCCurrent();
276  void TestSetup18RCSeriesSINCurrent();
277  void TestSetup18RCSeriesPulseCurrent();
278  void TestSetup19RCParallelDCCurrent();
279  void TestSetup19RCParallelSINCurrent();
280  void TestSetup19RCParallelPulseCurrent();
281  void TestSetup20SeriesCapDC();
282  void TestSetup20SeriesCapSIN();
283  void TestSetup20SeriesCapPulse();
284  void TestSetup21ParallelRDCCurrent();
285  void TestSetup21ParallelRSINCurrent();
286  void TestSetup21ParallelRPulseCurrent();
287  void TestSetup22CurrentCompDC();
288  void TestSetup22CurrentCompSIN();
289  void TestSetup22CurrentCompPulse();
290  void TestSetup23SeriesRLDCCurrent();
291  void TestSetup23SeriesRLSINCurrent();
292  void TestSetup23SeriesRLPULSECurrent();
293  void TestSetup24ParallelRLDCCurrent();
294  void TestSetup24ParallelRLSINCurrent();
295  void TestSetup24ParallelRLPULSECurrent();
296  void TestSetup25BasicDiodeDCCurrent();
297  void TestSetup25BasicDiodeSINCurrent();
298  void TestSetup25BasicDiodePULSECurrent();
299  void TestSetup26SwitchRCDCCurrent();
300  void TestSetup26SwitchRCSINCurrent();
301  void TestSetup26SwitchRCPULSECurrent();
302  void TestSetup27SeriesRLCDCCurrent();
303  void TestSetup27SeriesRLCSINCurrent();
304  void TestSetup27SeriesRLCPULSECurrent();
305  void TestSetup28ParallelRLCDCCurrent();
306  void TestSetup28ParallelRLCSINCurrent();
307  void TestSetup28ParallelRLCPULSECurrent();
308  void TestSetup29SeriesPressureSourceAdditionDC();
309  void TestSetup29SeriesPressureSourceAdditionSIN();
310  void TestSetup29SeriesPressureSourceAdditionPULSE();
311  void TestSetup30SeriesCurrentSourceAdditionDC();
312  void TestSetup30SeriesCurrentSourceAdditionSIN();
313  void TestSetup30SeriesCurrentSourceAdditionPULSE();
314  void TestSetup31ParallelPressureSourceAdditionDC();
315  void TestSetup31ParallelPressureSourceAdditionSIN();
316  void TestSetup31ParallelPressureSourceAdditionPULSE();
317  void TestSetup32ParallelCurrentSourceAdditionDC();
318  void TestSetup32ParallelCurrentSourceAdditionSIN();
319  void TestSetup32ParallelCurrrentSourceAdditionPULSE();
320  void TestSetup33SeriesCapDCCurrent();
321  void TestSetup33SeriesCapSINCurrent();
322  void TestSetup33SeriesCapPulseCurrent();
323  void TestSetup34ParallelCapDC();
324  void TestSetup34ParallelCapSIN();
325  void TestSetup34ParallelCapPulse();
326  void TestSetup35ParallelCapDCCurrent();
327  void TestSetup35ParallelCapSINCurrent();
328  void TestSetup35ParallelCapPulseCurrent();
329  void TestSetup36SeriesIndDC();
330  void TestSetup36SeriesIndSIN();
331  void TestSetup36SeriesIndPulse();
332  void TestSetup37SeriesIndDCCurrent();
333  void TestSetup37SeriesIndSINCurrent();
334  void TestSetup37SeriesIndPulseCurrent();
335  void TestSetup38ParallelIndDC();
336  void TestSetup38ParallelIndSIN();
337  void TestSetup38ParallelIndPulse();
338  void TestSetup39ParallelIndDCCurrent();
339  void TestSetup39ParallelIndSINCurrent();
340  void TestSetup39ParallelIndPulseCurrent();
341  void TestSetup40BadDiodeDC();
342  void TestSetup40BadDiodeSIN();
343  void TestSetup40BadDiodePulse();
344  void TestSetup41ValidationComprehensive1DC();
345  void TestSetup41ValidationComprehensive1SIN();
346  void TestSetup41ValidationComprehensive1Pulse();
347  void TestSetup41ValidationComprehensive1SINCentered();
348  void TestSetup42ValidationComprehensive2DC();
349  void TestSetup42ValidationComprehensive2SIN();
350  void TestSetup42ValidationComprehensive2Pulse();
351  void TestSetup42ValidationComprehensive2SINCentered();
352 
353  void TestPreProcess1(double dT, int i);
354  void TestPreProcess2(double dT, int i);
355  void TestPreProcess3(double dT, int i);
356  void TestPreProcess4(double dT, int i);
357  void BasicCircuitPreProcess(double dT);
358  // Advanced pre-process
359  void FluidPreProcess(SEFluidCircuit& c, double dT);
360  void TestCircuitSerialization(const std::string& fileName);
361 
363 
365  // Compartments //
367 public:
368  void GasCompartmentTest(const std::string& sOutputDirectory);
369  void LiquidCompartmentTest(const std::string& sOutputDirectory);
370  void ThermalCompartmentTest(const std::string& sOutputDirectory);
371  void TissueCompartmentTest(
372  const std::string& sOutputDirectory); // there is nothing being tested here
373 
374 protected:
375  void TestCompartmentSerialization(SECompartmentManager& mgr,
376  const std::string& fileName);
377  // Gas Compartments
378  void TestGasFlows(SETestSuite& testSuite, SESubstanceManager& subMgr);
379  void TestGasHierarchyFlows(SETestSuite& testSuite,
380  SESubstanceManager& subMgr);
381  void TestFlow(SETestCase& testCase, SEGasCompartment& cmpt,
382  double inflow_mL_Per_s, double outflow_mL_Per_s);
383  void TestGasHierarchy(SETestSuite& testSuite, SESubstanceManager& subMgr);
384  void TestGasCircuitVolumesPressuresAndFlows(SETestSuite& testSuite,
385  SESubstanceManager& subMgr);
386  void CheckGasPressureAndVolume(SETestCase& testCase, SEGasCompartment& cmpt);
387  void TestGasSubstanceQuantity(SETestCase& testCase, SEGasCompartment& cmpt,
389  double totalSubVolume_mL,
390  double totalVolume_mL);
391  void TestUpdateGasLinks(SETestSuite& testSuite, SESubstanceManager& subMgr);
392  // Liquid Compartments
393  void TestLiquidFlows(SETestSuite& testSuite, SESubstanceManager& subMgr);
394  void TestLiquidHierarchyFlows(SETestSuite& testSuite,
395  SESubstanceManager& subMgr);
396  void TestFlow(SETestCase& testCase, SELiquidCompartment& cmpt,
397  double inflow_mL_Per_s, double outflow_mL_Per_s);
398  void TestLiquidHierarchy(SETestSuite& testSuite, SESubstanceManager& subMgr);
399  void TestLiquidCircuitVolumesPressuresAndFlows(SETestSuite& testSuite,
400  SESubstanceManager& subMgr);
401  void TestLiquidHierarchySaturation(SETestSuite& testSuite,
402  SESubstanceManager& subMgr);
403  void CheckLiquidPressureAndVolume(SETestCase& testCase,
404  SELiquidCompartment& cmpt);
405  void TestLiquidSubstanceQuantity(SETestCase& testCase,
406  SELiquidCompartment& cmpt,
408  double totalMass_mg, double totalVolume_mL);
409  void TestUpdateLiquidLinks(SETestSuite& testSuite,
410  SESubstanceManager& subMgr);
411  // Thermal Compartments
412  void TestThermalFlows(SETestSuite& testSuite, SESubstanceManager& subMgr);
413  void TestThermalFlowHierarchy(SETestSuite& testSuite,
414  SESubstanceManager& subMgr);
415  void TestFlow(SETestCase& testCase, SEThermalCompartment& cmpt,
416  double inflow_kcal_Per_s, double outflow_kcal_Per_s);
417  void TestThermalHierarchy(SETestSuite& testSuite, SESubstanceManager& subMgr);
418  void TestCircuitHeatTemperatureAndFlows(SETestSuite& testSuite,
419  SESubstanceManager& subMgr);
420  void CheckTemperatureAndHeat(SETestCase& testCase,
421  SEThermalCompartment& cmpt);
422 
424  // Transport //
426 public:
427  void LargeFlowTransportTest(const std::string& sOutputDirectory);
428  void LiquidTransportTest(const std::string& sOutputDirectory);
429  void GasTransportTest(const std::string& sOutputDirectory);
430 
432  // I/O Tests //
434 public:
435  void ReadPatientDirectory(const std::string& sOutputDirectory);
436  void ReadScenarios(const std::string& sOutputDirectory);
437  void ReadSubstanceDirectory(const std::string& sOutputDirectory);
438 
440  // Properties Tests //
442 public:
443  void ScalarTest(const std::string& sOutputDirectory);
444  void UnitsTest(const std::string& sOutputDirectory);
445 
446 protected:
447  void ConvertList(std::vector<std::string> stringList);
448  // These property tests are not outputting any reports or anything, kind of
449  // just a sandbox at this point Maybe one day I will set something up, but
450  // these are generally not a problem (no jinx!)
451 };
452 }
double m_PercentTolerance
Definition: CommonDataModelTest.h:40
Definition: CommonDataModelTest.h:24
Definition: CommonDataModelTest.h:28
std::map< std::string, testFunction > testMap
Definition: CommonDataModelTest.h:45
Definition: SEThermalCompartment.h:26
Definition: SECompartmentManager.h:32
bool myLogger
Definition: CommonDataModelTest.h:39
Definition: SELiquidSubstanceQuantity.h:28
Definition: CommonDataModelTest.h:26
Definition: Logger.h:27
Definition: Logger.h:75
Definition: SELiquidCompartment.h:27
Definition: CommonDataModelTest.h:25
Definition: SEFluidCircuit.h:20
std::string m_OutDirectory
Definition: CommonDataModelTest.h:41
SECircuitManager m_Circuits
Definition: CommonDataModelTest.h:362
Definition: CommonDataModelTest.h:23
Definition: SEGasSubstanceQuantity.h:20
Definition: SETestCase.h:21
testMap cdmMap
Definition: CommonDataModelTest.h:46
Definition: SETestSuite.h:20
enumCDMTestSourceType
Definition: CommonDataModelTest.h:23
Definition: SESubstanceManager.h:23
std::stringstream m_ss
Definition: CommonDataModelTest.h:42
Definition: SEElectricalCircuit.h:18
Definition: SECircuitManager.h:53
Definition: SEGasCompartment.h:24