void TestArchiving() { EXIT_IF_PARALLEL; #ifdef CHASTE_CVODE OutputFileHandler handler("archive", false); std::string archive_filename = handler.GetOutputDirectoryFullPath() + "mirams_ode.arch"; { double wnt_level = 0.5; boost::shared_ptr<AbstractCellMutationState> p_state(new WildTypeCellMutationState); Mirams2010WntOdeSystem ode_system(wnt_level, p_state); TS_ASSERT_DELTA(ode_system.GetWntLevel(), 0.50, 1e-6); TS_ASSERT_EQUALS(ode_system.GetMutationState()->IsType<WildTypeCellMutationState>(), true); std::vector<double> initial_conditions = ode_system.GetInitialConditions(); TS_ASSERT_EQUALS(initial_conditions.size(), 3u); TS_ASSERT_DELTA(initial_conditions[0], 64.1863, 1e-4); TS_ASSERT_DELTA(initial_conditions[1], 64.1863, 1e-4); TS_ASSERT_DELTA(initial_conditions[2], 0.5, 1e-6); // Create an output archive std::ofstream ofs(archive_filename.c_str()); boost::archive::text_oarchive output_arch(ofs); // Archive ODE system AbstractOdeSystem* const p_const_ode_system = &ode_system; output_arch << p_const_ode_system; } { AbstractOdeSystem* p_ode_system; // Create an input archive std::ifstream ifs(archive_filename.c_str(), std::ios::binary); boost::archive::text_iarchive input_arch(ifs); // Restore from the archive input_arch >> p_ode_system; // Check that archiving worked correctly TS_ASSERT_DELTA(static_cast<Mirams2010WntOdeSystem*>(p_ode_system)->GetWntLevel(), 0.50, 1e-6); TS_ASSERT_EQUALS(static_cast<Mirams2010WntOdeSystem*>(p_ode_system)->GetMutationState()->IsType<WildTypeCellMutationState>(), true); std::vector<double> initial_conditions = p_ode_system->GetInitialConditions(); TS_ASSERT_EQUALS(initial_conditions.size(), 3u); TS_ASSERT_DELTA(initial_conditions[0], 64.1863, 1e-4); TS_ASSERT_DELTA(initial_conditions[1], 64.1863, 1e-4); TS_ASSERT_DELTA(initial_conditions[2], 0.5, 1e-6); // Tidy up delete p_ode_system; } #else std::cout << "CVODE is not enabled. " << std::endl; std::cout << "If required please install and alter your hostconfig settings to switch on chaste support." << std::endl; #endif //CHASTE_CVODE }
void TestAbstractOdeSystemForCoupledPdeSystem() { // Create ODE system OdeSystemForCoupledHeatEquation ode_system(1.0); // Test setting/getting a PDE solution vector with the correct size std::vector<double> solution(1); solution[0] = 12.3; ode_system.SetPdeSolution(solution); TS_ASSERT_EQUALS(ode_system.GetPdeSolutionSize(), 1u); std::vector<double> obtained_solution = ode_system.rGetPdeSolution(); TS_ASSERT_DELTA(obtained_solution[0], solution[0], 1e-6); // Test an exception is thrown if setting a PDE solution vector with incorrect size std::vector<double> bad_solution(2); bad_solution[0] = 2.1; bad_solution[1] = 4.9; TS_ASSERT_THROWS_THIS(ode_system.SetPdeSolution(bad_solution), "The supplied vector is not the correct size."); }
void TestArchiving() { OutputFileHandler handler("archive", false); std::string archive_filename = handler.GetOutputDirectoryFullPath() + "alarcon_ode.arch"; { double oxygen_concentration = 0.7; bool is_labelled = true; Alarcon2004OxygenBasedCellCycleOdeSystem ode_system(oxygen_concentration, is_labelled); TS_ASSERT_DELTA(ode_system.GetOxygenConcentration(), 0.70, 1e-6); TS_ASSERT_EQUALS(ode_system.IsLabelled(), true); ode_system.SetDefaultInitialCondition(2, 3.25); std::vector<double> initial_conditions = ode_system.GetInitialConditions(); TS_ASSERT_EQUALS(initial_conditions.size(), 6u); TS_ASSERT_DELTA(initial_conditions[0], 0.90, 1e-6); TS_ASSERT_DELTA(initial_conditions[1], 0.01, 1e-6); TS_ASSERT_DELTA(initial_conditions[2], 3.25, 1e-6); TS_ASSERT_DELTA(initial_conditions[3], 5.00, 1e-6); TS_ASSERT_DELTA(initial_conditions[4], 1.00, 1e-6); TS_ASSERT_DELTA(initial_conditions[5], 0.70, 1e-6); // Create an output archive std::ofstream ofs(archive_filename.c_str()); boost::archive::text_oarchive output_arch(ofs); // Archive ODE system AbstractOdeSystem* const p_const_ode_system = &ode_system; output_arch << p_const_ode_system; } { AbstractOdeSystem* p_ode_system; // Create an input archive std::ifstream ifs(archive_filename.c_str(), std::ios::binary); boost::archive::text_iarchive input_arch(ifs); // Restore from the archive input_arch >> p_ode_system; // Check that archiving worked correctly TS_ASSERT_DELTA(static_cast<Alarcon2004OxygenBasedCellCycleOdeSystem*>(p_ode_system)->GetOxygenConcentration(), 0.70, 1e-6); TS_ASSERT_EQUALS(static_cast<Alarcon2004OxygenBasedCellCycleOdeSystem*>(p_ode_system)->IsLabelled(), true); std::vector<double> initial_conditions = p_ode_system->GetInitialConditions(); TS_ASSERT_EQUALS(initial_conditions.size(), 6u); TS_ASSERT_DELTA(initial_conditions[0], 0.90, 1e-6); TS_ASSERT_DELTA(initial_conditions[1], 0.01, 1e-6); TS_ASSERT_DELTA(initial_conditions[2], 0.0, 1e-6); TS_ASSERT_DELTA(initial_conditions[3], 5.00, 1e-6); TS_ASSERT_DELTA(initial_conditions[4], 1.00, 1e-6); TS_ASSERT_DELTA(initial_conditions[5], 0.70, 1e-6); // Tidy up delete p_ode_system; } }