void TestCellKillersOutputParameters() { std::string output_directory = "TestSloughingCellKillersOutputParameters"; OutputFileHandler output_file_handler(output_directory, false); // Test with SloughingCellKiller SloughingCellKiller<2> sloughing_cell_killer(NULL, 20.0, true, 10.0); TS_ASSERT_EQUALS(sloughing_cell_killer.GetIdentifier(), "SloughingCellKiller-2"); out_stream sloughing_cell_killer_parameter_file = output_file_handler.OpenOutputFile("sloughing_results.parameters"); sloughing_cell_killer.OutputCellKillerParameters(sloughing_cell_killer_parameter_file); sloughing_cell_killer_parameter_file->close(); std::string sloughing_cell_killer_results_dir = output_file_handler.GetOutputDirectoryFullPath(); FileComparison( sloughing_cell_killer_results_dir + "sloughing_results.parameters", "crypt/test/data/TestSloughingCellKillers/sloughing_results.parameters").CompareFiles(); // Test with RadialSloughingCellKiller c_vector<double,2> centre(2); centre[0] = 0.1; centre[1] = 0.2; double radius = 0.4; RadialSloughingCellKiller radial_cell_killer(NULL, centre, radius); TS_ASSERT_EQUALS(radial_cell_killer.GetIdentifier(), "RadialSloughingCellKiller"); out_stream radial_cell_killer_parameter_file = output_file_handler.OpenOutputFile("radial_results.parameters"); radial_cell_killer.OutputCellKillerParameters(radial_cell_killer_parameter_file); radial_cell_killer_parameter_file->close(); std::string radial_cell_killer_results_dir = output_file_handler.GetOutputDirectoryFullPath(); FileComparison( radial_cell_killer_results_dir + "radial_results.parameters", "crypt/test/data/TestSloughingCellKillers/radial_results.parameters").CompareFiles(); }
void TestBidomainMeshalyzerConversion() throw(Exception) { /* * Firstly, copy the .h5 file to CHASTE_TEST_OUTPUT/TestHdf5ToMeshalyzerConverter, * as that is where the reader reads from. */ std::string output_folder("TestHdf5Converters_TestBidomainMeshalyzerConversion"); CopyToTestOutputDirectory("heart/test/data/Bidomain1d/bidomain.h5", output_folder); TrianglesMeshReader<1,1> mesh_reader("mesh/test/data/1D_0_to_1_100_elements"); TetrahedralMesh<1,1> mesh; mesh.ConstructFromMeshReader(mesh_reader); // Convert Hdf5ToMeshalyzerConverter<1,1> converter(FileFinder(output_folder, RelativeTo::ChasteTestOutput), "bidomain", &mesh, true); // Compare the voltage file std::string test_output_directory = OutputFileHandler::GetChasteTestOutputDirectory(); FileComparison(test_output_directory + output_folder + "/output/bidomain_V.dat", "heart/test/data/Bidomain1d/bidomain_V.dat").CompareFiles(); // Compare the Phi_e file FileComparison(test_output_directory + output_folder + "/output/bidomain_Phi_e.dat", "heart/test/data/Bidomain1d/bidomain_Phi_e.dat").CompareFiles(); // Compare the time information file FileComparison(test_output_directory + output_folder + "/output/bidomain_times.info", "heart/test/data/Bidomain1d/bidomain_times.info").CompareFiles(); }
void TestBinaryFiles() throw(Exception) { std::string base_file = "./mesh/test/data/simple_cube_binary.node"; TS_ASSERT(FileComparison(base_file, base_file, CalledCollectively, SuppressOutput).CompareFiles()); //A file which is the same for data purposes, but has the provenance line altered std::string copy_file = "./global/test/data/simple_cube_binary_copy.node"; TS_ASSERT(FileComparison(base_file, copy_file, CalledCollectively, SuppressOutput).CompareFiles()); //A file which has a single byte of data inserted std::string modified_file = "./global/test/data/simple_cube_binary_modified.node"; TS_ASSERT_EQUALS(FileComparison(base_file, modified_file, CalledCollectively, SuppressOutput).CompareFiles(0, false), expected_fail_result); }
void TestBarCleansFilesUpAfterException() { double smidge = 1e-8; { ProgressReporter progress_bar("ProgressReporterException", 1.0, 10.0); try { progress_bar.PrintInitialising(); for (unsigned i=0; i<=900; i++) { double t = 1.0 + ((i+0.0)/1000)*9.0 - smidge; progress_bar.Update(t); } EXCEPTION("Throw"); } catch(Exception&) { } } // File should now be closed since progress_bar is out of scope std::string results_dir = OutputFileHandler::GetChasteTestOutputDirectory() + "ProgressReporterException/"; FileComparison(results_dir + "progress_status.txt", "global/test/data/bad_progress_status.txt").CompareFiles(); }
void TestCellProliferativeTypesCountWriters() throw (Exception) { EXIT_IF_PARALLEL; // Create a simple 3D MeshBasedCellPopulation std::vector<Node<3>*> nodes; nodes.push_back(new Node<3>(0, true, 0.0, 0.0, 0.0)); nodes.push_back(new Node<3>(1, true, 1.0, 1.0, 0.0)); nodes.push_back(new Node<3>(2, true, 1.0, 0.0, 1.0)); nodes.push_back(new Node<3>(3, true, 0.0, 1.0, 1.0)); nodes.push_back(new Node<3>(4, false, 0.5, 0.5, 0.5)); MutableMesh<3,3> mesh(nodes); std::vector<CellPtr> cells; CellsGenerator<FixedDurationGenerationBasedCellCycleModel, 3> cells_generator; cells_generator.GenerateBasic(cells, mesh.GetNumNodes()); MeshBasedCellPopulation<3> cell_population(mesh, cells); cell_population.AddCellPopulationCountWriter<CellProliferativeTypesCountWriter>(); // An ordering must be specified for cell mutation states and cell proliferative types cell_population.SetDefaultCellMutationStateAndProliferativeTypeOrdering(); // Create an output directory for the writer std::string output_directory = "TestCellProliferativeTypesCountWriter"; OutputFileHandler output_file_handler(output_directory, false); std::string results_dir = output_file_handler.GetOutputDirectoryFullPath(); // Create a CellProliferativeTypesCountWriter and test that the correct output is generated CellProliferativeTypesCountWriter<3,3> types_count_writer; types_count_writer.OpenOutputFile(output_file_handler); types_count_writer.WriteTimeStamp(); types_count_writer.Visit(&cell_population); types_count_writer.WriteNewline(); types_count_writer.CloseFile(); FileComparison(results_dir + "celltypes.dat", "cell_based/test/data/TestCellPopulationCountWriters/celltypes.dat").CompareFiles(); // Test that we can append to files types_count_writer.OpenOutputFileForAppend(output_file_handler); types_count_writer.WriteTimeStamp(); types_count_writer.Visit(&cell_population); types_count_writer.WriteNewline(); types_count_writer.CloseFile(); FileComparison(results_dir + "celltypes.dat", "cell_based/test/data/TestCellPopulationCountWriters/celltypes_twice.dat").CompareFiles(); }
void TestCellMutationStatesCountWriter() throw (Exception) { EXIT_IF_PARALLEL; // Create a simple 2D CaBasedCellPopulation PottsMeshGenerator<2> generator(5, 0, 0, 5, 0, 0); PottsMesh<2>* p_mesh = generator.GetMesh(); std::vector<CellPtr> cells; CellsGenerator<FixedDurationGenerationBasedCellCycleModel, 2> cells_generator; cells_generator.GenerateBasic(cells, 5u); std::vector<unsigned> location_indices; location_indices.push_back(7); location_indices.push_back(11); location_indices.push_back(12); location_indices.push_back(13); location_indices.push_back(17); CaBasedCellPopulation<2> cell_population(*p_mesh, cells, location_indices); cell_population.AddCellPopulationCountWriter<CellMutationStatesCountWriter>(); // Create an output directory for the writer std::string output_directory = "TestCellMutationStatesCountWriter"; OutputFileHandler output_file_handler(output_directory, false); std::string results_dir = output_file_handler.GetOutputDirectoryFullPath(); // Create a CellMutationStatesCountWriter and test that the correct output is generated CellMutationStatesCountWriter<2,2> mutation_states_writer; mutation_states_writer.OpenOutputFile(output_file_handler); mutation_states_writer.WriteHeader(&cell_population); mutation_states_writer.WriteTimeStamp(); mutation_states_writer.Visit(&cell_population); mutation_states_writer.WriteNewline(); mutation_states_writer.CloseFile(); FileComparison(results_dir + "cellmutationstates.dat", "cell_based/test/data/TestCellPopulationCountWriters/cellmutationstates.dat").CompareFiles(); // Test that we can append to files mutation_states_writer.OpenOutputFileForAppend(output_file_handler); mutation_states_writer.WriteTimeStamp(); mutation_states_writer.Visit(&cell_population); mutation_states_writer.WriteNewline(); mutation_states_writer.CloseFile(); FileComparison(results_dir + "cellmutationstates.dat", "cell_based/test/data/TestCellPopulationCountWriters/cellmutationstates_twice.dat").CompareFiles(); }
void TestWriter() throw (Exception) { EXIT_IF_PARALLEL; // Set up a small MeshBasedCellPopulationWithGhostNodes using an appropriate cell-cycle model class CylindricalHoneycombMeshGenerator generator(5, 4, 1); Cylindrical2dMesh* p_mesh = generator.GetCylindricalMesh(); double domain_length_for_wnt = 4.0*(sqrt(3.0)/2); std::vector<unsigned> location_indices = generator.GetCellLocationIndices(); std::vector<CellPtr> cells; CryptCellsGenerator<VanLeeuwen2009WntSwatCellCycleModelHypothesisOne> cells_generator; cells_generator.Generate(cells, p_mesh, location_indices, false); MeshBasedCellPopulationWithGhostNodes<2> cell_population(*p_mesh, cells, location_indices); // Create an instance of a Wnt concentration WntConcentration<2>::Instance()->SetType(LINEAR); WntConcentration<2>::Instance()->SetCellPopulation(cell_population); WntConcentration<2>::Instance()->SetCryptLength(domain_length_for_wnt); // Initialise the cell population to set up the ODE system associated with each cell-cycle model object cell_population.InitialiseCells(); // Create an output directory for the writer std::string output_directory = "TestCellBetaCateninWriter"; OutputFileHandler output_file_handler(output_directory, false); std::string results_dir = output_file_handler.GetOutputDirectoryFullPath(); // Create a CellBetaCateninWriter and test that the correct output is generated CellBetaCateninWriter<2,2> cell_writer; cell_writer.OpenOutputFile(output_file_handler); cell_writer.WriteTimeStamp(); for (AbstractCellPopulation<2,2>::Iterator cell_iter = cell_population.Begin(); cell_iter != cell_population.End(); ++cell_iter) { cell_writer.VisitCell(*cell_iter, &cell_population); } cell_writer.CloseFile(); /* * To verify this test, we can eyeball the results file to check that the correct default * initial conditions are output (see VanLeeuwen2009WntSwatCellCycleOdeSystem.hpp). */ FileComparison(results_dir + "results.vizbetacatenin", "crypt/test/data/TestCellBetaCateninWriter/results.vizbetacatenin").CompareFiles(); // Test the correct data are returned for VTK output for the first cell double vtk_data = cell_writer.GetCellDataForVtkOutput(*(cell_population.Begin()), &cell_population); TS_ASSERT_DELTA(vtk_data, 14.6088, 1e-4); // Avoid memory leak WntConcentration<2>::Destroy(); }
void TestPdeOutput() throw(Exception) { EXIT_IF_PARALLEL; OutputFileHandler handler("TestOnLatticeSpheroidWithNutrient", false); std::string results_dir = handler.GetOutputDirectoryFullPath() + "results_from_time_0"; NumericFileComparison comp_nut(results_dir + "/results.vizcoarsepdesolution", "cell_based/test/data/TestOnLatticeSpheroidWithNutrient/results.vizcoarsepdesolution"); TS_ASSERT(comp_nut.CompareFiles()); FileComparison( results_dir + "/results.vizcoarsepdesolution", "cell_based/test/data/TestOnLatticeSpheroidWithNutrient/results.vizcoarsepdesolution").CompareFiles(); }
// This test covers the case when the hdf5 file contains more than 3 variables void TestMeshalyzerConversionLotsOfVariables() throw(Exception) { std::string output_dir = "TestHdf5Converters_TestMeshalyzerConversionLotsOfVariables"; /* * Firstly, copy the .h5 file to CHASTE_TEST_OUTPUT/TestHdf5ToMeshalyzerConverter, * as that is where the reader reads from. */ CopyToTestOutputDirectory("heart/test/data/many_variables/many_variables.h5", output_dir); TrianglesMeshReader<1,1> mesh_reader("heart/test/data/many_variables/1D_65_elements"); TetrahedralMesh<1,1> mesh; mesh.ConstructFromMeshReader(mesh_reader); // Convert Hdf5ToMeshalyzerConverter<1,1> converter(FileFinder(output_dir, RelativeTo::ChasteTestOutput), "many_variables", &mesh, true); std::vector<std::string> variable_names; variable_names.push_back("V"); variable_names.push_back("I_ks"); variable_names.push_back("I_kr"); variable_names.push_back("I_Ca_tot"); variable_names.push_back("I_tot"); variable_names.push_back("I_Na_tot"); std::string test_output_directory = OutputFileHandler::GetChasteTestOutputDirectory(); for (unsigned i=0; i<variable_names.size(); i++) { // Compare the results files FileComparison(test_output_directory + "/" + output_dir + "/output/many_variables_" + variable_names[i] + ".dat", "heart/test/data/many_variables/many_variables_" + variable_names[i] + ".dat").CompareFiles(); } // Compare the time information file FileComparison(test_output_directory + output_dir + "/output/many_variables_times.info", "heart/test/data/many_variables/many_variables_times.info").CompareFiles(); }
void TestOutputParameters2d() throw(Exception) { std::string output_directory = "TestOutputParameters2d"; OutputFileHandler output_file_handler(output_directory, false); CryptSimulationBoundaryCondition<2> boundary_condition(NULL); TS_ASSERT_EQUALS(boundary_condition.GetIdentifier(), "CryptSimulationBoundaryCondition-2"); out_stream boundary_condition_parameter_file = output_file_handler.OpenOutputFile("results2d.parameters"); boundary_condition.OutputCellPopulationBoundaryConditionParameters(boundary_condition_parameter_file); boundary_condition_parameter_file->close(); std::string boundary_condition_results_dir = output_file_handler.GetOutputDirectoryFullPath(); FileComparison( boundary_condition_results_dir + "results2d.parameters", "crypt/test/data/TestCryptSimulationBoundaryCondition/results2d.parameters").CompareFiles(); // Test OutputCellPopulationBoundaryConditionInfo() method out_stream boundary_condition_info_file = output_file_handler.OpenOutputFile("results2d.info"); boundary_condition.OutputCellPopulationBoundaryConditionInfo(boundary_condition_info_file); boundary_condition_info_file->close(); FileComparison( boundary_condition_results_dir + "results2d.info", "crypt/test/data/TestCryptSimulationBoundaryCondition/results2d.info").CompareFiles(); }
void TestMonodomainMeshalyzerConversion() throw(Exception) { // Firstly, copy ./heart/test/data/MonoDg01d/*.h5 to CHASTE_TEST_OUTPUT/TestHdf5ToMeshalyzerConverter, // as that is where the reader reads from. std::string output_folder("TestHdf5Converters_TestMonodomainMeshalyzerConversion"); CopyToTestOutputDirectory("heart/test/data/Monodomain1d/MonodomainLR91_1d.h5", output_folder); TrianglesMeshReader<1,1> mesh_reader("mesh/test/data/1D_0_to_1_100_elements"); TetrahedralMesh<1,1> mesh; mesh.ConstructFromMeshReader(mesh_reader); // Convert Hdf5ToMeshalyzerConverter<1,1> converter(FileFinder(output_folder,RelativeTo::ChasteTestOutput), "MonodomainLR91_1d", &mesh, true, 10 /* precision specified for coverage */); // Compare the voltage file with a correct version std::string test_output_directory = OutputFileHandler::GetChasteTestOutputDirectory(); FileComparison(test_output_directory + output_folder + "/output/MonodomainLR91_1d_V.dat", "heart/test/data/Monodomain1d/MonodomainLR91_1d_V.dat").CompareFiles(); FileComparison(test_output_directory + output_folder + "/output/MonodomainLR91_1d_times.info", "heart/test/data/Monodomain1d/MonodomainLR91_1d_times.info").CompareFiles(); }
void TestForceOutputParameters() { std::string output_directory = "TestForcesOutputParameters"; OutputFileHandler output_file_handler(output_directory, false); // Test with VertexCryptBoundaryForce VertexCryptBoundaryForce<2> boundary_force; TS_ASSERT_EQUALS(boundary_force.GetIdentifier(), "VertexCryptBoundaryForce-2"); out_stream boundary_force_parameter_file = output_file_handler.OpenOutputFile("boundary_results.parameters"); boundary_force.OutputForceParameters(boundary_force_parameter_file); boundary_force_parameter_file->close(); std::string boundary_force_results_dir = output_file_handler.GetOutputDirectoryFullPath(); FileComparison( boundary_force_results_dir + "boundary_results.parameters", "crypt/test/data/TestForcesForCrypt/boundary_results.parameters").CompareFiles(); }
void TestBar() { // This is in a block to make sure the file gets closed (i.e. destructor called) { ProgressReporter progress_bar("ProgressReporter", 1.0, 10.0); progress_bar.PrintInitialising(); for (unsigned i=0; i<=1000; i++) { double t = 1.0 + ((i+0.0)/1000)*9.0; progress_bar.Update(t); } progress_bar.PrintFinalising(); } std::string results_dir = OutputFileHandler::GetChasteTestOutputDirectory() + "ProgressReporter/"; FileComparison(results_dir + "progress_status.txt", "global/test/data/good_progress_status.txt").CompareFiles(); }
void TestUpdateRuleOutputUpdateRuleInfo() { EXIT_IF_PARALLEL; std::string output_directory = "TestPottsUpdateRulesOutputParameters"; OutputFileHandler output_file_handler(output_directory, false); // Test with VolumeConstraintPottsUpdateRule VolumeConstraintPottsUpdateRule<2> volume_constraint; volume_constraint.SetDeformationEnergyParameter(0.1); volume_constraint.SetMatureCellTargetVolume(20); TS_ASSERT_EQUALS(volume_constraint.GetIdentifier(), "VolumeConstraintPottsUpdateRule-2"); out_stream volume_constraint_parameter_file = output_file_handler.OpenOutputFile("volume_constraint_results.parameters"); volume_constraint.OutputUpdateRuleInfo(volume_constraint_parameter_file); volume_constraint_parameter_file->close(); std::string volume_constraint_results_dir = output_file_handler.GetOutputDirectoryFullPath(); FileComparison( volume_constraint_results_dir + "volume_constraint_results.parameters", "cell_based/test/data/TestPottsUpdateRules/volume_constraint_results.parameters").CompareFiles(); // Test with SurfaceAreaConstraintPottsUpdateRule SurfaceAreaConstraintPottsUpdateRule<2> surface_area_constraint; surface_area_constraint.SetDeformationEnergyParameter(0.1); surface_area_constraint.SetMatureCellTargetSurfaceArea(20); TS_ASSERT_EQUALS(surface_area_constraint.GetIdentifier(), "SurfaceAreaConstraintPottsUpdateRule-2"); out_stream surface_area_constraint_parameter_file = output_file_handler.OpenOutputFile("surface_area_constraint_results.parameters"); surface_area_constraint.OutputUpdateRuleInfo(surface_area_constraint_parameter_file); surface_area_constraint_parameter_file->close(); std::string surface_area_constraint_results_dir = output_file_handler.GetOutputDirectoryFullPath(); FileComparison( surface_area_constraint_results_dir + "surface_area_constraint_results.parameters", "cell_based/test/data/TestPottsUpdateRules/surface_area_constraint_results.parameters").CompareFiles(); // Test with AdhesionPottsUpdateRule AdhesionPottsUpdateRule<2> adhesion_update; adhesion_update.SetCellCellAdhesionEnergyParameter(0.3); adhesion_update.SetCellBoundaryAdhesionEnergyParameter(0.4); TS_ASSERT_EQUALS(adhesion_update.GetIdentifier(), "AdhesionPottsUpdateRule-2"); out_stream adhesion_update_parameter_file = output_file_handler.OpenOutputFile("adhesion_update_results.parameters"); adhesion_update.OutputUpdateRuleInfo(adhesion_update_parameter_file); adhesion_update_parameter_file->close(); std::string adhesion_update_results_dir = output_file_handler.GetOutputDirectoryFullPath(); FileComparison( adhesion_update_results_dir + "adhesion_update_results.parameters", "cell_based/test/data/TestPottsUpdateRules/adhesion_update_results.parameters").CompareFiles(); // Test with DifferentialAdhesionPottsUpdateRule DifferentialAdhesionPottsUpdateRule<2> differential_adhesion_update; differential_adhesion_update.SetLabelledCellLabelledCellAdhesionEnergyParameter(0.3); differential_adhesion_update.SetLabelledCellCellAdhesionEnergyParameter(0.4); differential_adhesion_update.SetCellCellAdhesionEnergyParameter(0.5); differential_adhesion_update.SetLabelledCellBoundaryAdhesionEnergyParameter(0.6); differential_adhesion_update.SetCellBoundaryAdhesionEnergyParameter(0.7); TS_ASSERT_EQUALS(differential_adhesion_update.GetIdentifier(), "DifferentialAdhesionPottsUpdateRule-2"); out_stream differential_adhesion_update_parameter_file = output_file_handler.OpenOutputFile("differential_adhesion_update_results.parameters"); differential_adhesion_update.OutputUpdateRuleInfo(differential_adhesion_update_parameter_file); differential_adhesion_update_parameter_file->close(); std::string differential_adhesion_update_results_dir = output_file_handler.GetOutputDirectoryFullPath(); FileComparison(differential_adhesion_update_results_dir + "differential_adhesion_update_results.parameters", "cell_based/test/data/TestPottsUpdateRules/differential_adhesion_update_results.parameters").CompareFiles(); // Test with DifferentialAdhesionPottsUpdateRule ChemotaxisPottsUpdateRule<2> chemotaxis_update; TS_ASSERT_EQUALS(chemotaxis_update.GetIdentifier(), "ChemotaxisPottsUpdateRule-2"); out_stream chemotaxis_update_parameter_file = output_file_handler.OpenOutputFile("chemotaxis_update_results.parameters"); chemotaxis_update.OutputUpdateRuleInfo(chemotaxis_update_parameter_file); chemotaxis_update_parameter_file->close(); std::string chemotaxis_update_results_dir = output_file_handler.GetOutputDirectoryFullPath(); FileComparison(chemotaxis_update_results_dir + "chemotaxis_update_results.parameters", "cell_based/test/data/TestPottsUpdateRules/chemotaxis_update_results.parameters").CompareFiles(); }
/** * This test runs multiple crypt simulations and records whether * or not labelled cells are in a randomly chosen crypt section. */ void TestMultipleCryptSimulations() throw (Exception) { std::string output_directory = "MakeMoreMeinekeGraphs"; double crypt_length = 22.0; // Create mesh unsigned cells_across = 13; unsigned cells_up = 25; double crypt_width = 12.1; unsigned thickness_of_ghost_layer = 3; unsigned num_simulations = 2; // Guess of maximum number of cells a crypt section may contain unsigned max_length_of_crypt_section = 5 * (unsigned)sqrt(pow(cells_across/2.0+1,2.0) + pow((double)cells_up,2.0)); std::vector<unsigned> labelled_cells_counter(max_length_of_crypt_section); for (unsigned i=0; i<max_length_of_crypt_section; i++) { labelled_cells_counter[i] = 0; } double time_of_each_run; std::vector<bool> labelled; CryptStatistics* p_crypt_statistics; // Create cell population MeshBasedCellPopulationWithGhostNodes<2>* p_crypt; CylindricalHoneycombMeshGenerator generator(cells_across, cells_up, thickness_of_ghost_layer, crypt_width/cells_across); std::vector<unsigned> location_indices; Cylindrical2dMesh* p_mesh; SimulationTime* p_simulation_time; // Loop over the number of simulations for (unsigned simulation_index=0; simulation_index<num_simulations; simulation_index++) { // Create new structures for each simulation p_mesh = generator.GetCylindricalMesh(); location_indices = generator.GetCellLocationIndices(); // Reset start time SimulationTime::Destroy(); p_simulation_time = SimulationTime::Instance(); p_simulation_time->SetStartTime(0.0); // Set up cells std::vector<CellPtr> temp_cells; CryptCellsGenerator<StochasticDurationGenerationBasedCellCycleModel> cells_generator; cells_generator.Generate(temp_cells, p_mesh, std::vector<unsigned>(), true, 0.3, 2.0, 3.0, 4.0, true); // This awkward way of setting up the cells is a result of #430 std::vector<CellPtr> cells; for (unsigned i=0; i<location_indices.size(); i++) { cells.push_back(temp_cells[location_indices[i]]); } // Set up crypt p_crypt = new MeshBasedCellPopulationWithGhostNodes<2>(*p_mesh, cells, location_indices); // Set cell population to output cell types p_crypt->AddPopulationWriter<CellMutationStatesCountWriter>(); // Set up crypt simulation CryptSimulation2d simulator(*p_crypt, false, false); simulator.SetOutputDirectory(output_directory); // Set length of simulation here time_of_each_run = 10.0*simulator.GetDt(); // for each run simulator.SetEndTime(time_of_each_run); // Create a force laws and pass it to the simulation MAKE_PTR(GeneralisedLinearSpringForce<2>, p_linear_force); p_linear_force->SetMeinekeSpringStiffness(30.0); // normally 15.0; simulator.AddForce(p_linear_force); // Set up cell killer MAKE_PTR_ARGS(SloughingCellKiller<2>, p_killer, (&simulator.rGetCellPopulation(), crypt_length)); simulator.AddCellKiller(p_killer); simulator.UseJiggledBottomCells(); // Set up crypt statistics p_crypt_statistics = new CryptStatistics(*p_crypt); // Run for a bit simulator.Solve(); p_crypt_statistics->LabelSPhaseCells(); simulator.SetEndTime(2.0*time_of_each_run); simulator.Solve(); std::vector<CellPtr> crypt_section = p_crypt_statistics->GetCryptSection(crypt_length + 2.0, 8.0, 8.0); labelled = p_crypt_statistics->AreCryptSectionCellsLabelled(crypt_section); // Store information from this simulation in a global vector for (unsigned cell_index=0; cell_index < labelled.size(); cell_index++) { TS_ASSERT(cell_index < labelled_cells_counter.size()); if (labelled[cell_index]) { labelled_cells_counter[cell_index]++; } } // Tidy up cells.clear(); labelled.clear(); WntConcentration<2>::Destroy(); delete p_crypt_statistics; delete p_crypt; } // Calculate percentage of labelled cells at each position in 'labelled_cells_counter' std::vector<double> percentage_of_labelled_cells(max_length_of_crypt_section); for (unsigned index=0; index < max_length_of_crypt_section; index ++) { percentage_of_labelled_cells[index] = (double) labelled_cells_counter[index]/num_simulations; } // Write data to file SimpleDataWriter writer1(output_directory, "percentage_of_labelled_cells.dat", percentage_of_labelled_cells, false); // Test against previous run // ... and checking visualization of labelled cells against previous run OutputFileHandler handler(output_directory, false); std::string results_file = handler.GetOutputDirectoryFullPath() + "percentage_of_labelled_cells.dat"; FileComparison( results_file, "crypt/test/data/MakeMoreMeinekeGraphs/percentage_of_labelled_cells.dat").CompareFiles(); RandomNumberGenerator::Destroy(); }
void TestCellPopulationWritersIn3dWithParticles() throw(Exception) { EXIT_IF_PARALLEL; // This test doesn't work in parallel. // Set up SimulationTime (needed if VTK is used) SimulationTime::Instance()->SetEndTimeAndNumberOfTimeSteps(1.0, 1); // Resetting the Maximum cell Id to zero (to account for previous tests) CellId::ResetMaxCellId(); // Create a simple 3D mesh with some particles std::vector<Node<3>*> nodes; nodes.push_back(new Node<3>(0, true, 0.0, 0.0, 0.0)); nodes.push_back(new Node<3>(1, true, 1.0, 1.0, 0.0)); nodes.push_back(new Node<3>(2, true, 1.0, 0.0, 1.0)); nodes.push_back(new Node<3>(3, true, 0.0, 1.0, 1.0)); nodes.push_back(new Node<3>(4, false, 0.5, 0.5, 0.5)); nodes.push_back(new Node<3>(5, false, -1.0, -1.0, -1.0)); nodes.push_back(new Node<3>(6, false, 2.0, -1.0, -1.0)); nodes.push_back(new Node<3>(7, false, 2.0, 2.0, -1.0)); nodes.push_back(new Node<3>(8, false, -1.0, 2.0, -1.0)); nodes.push_back(new Node<3>(9, false, -1.0, -1.0, 2.0)); nodes.push_back(new Node<3>(10, false, 2.0, -1.0, 2.0)); nodes.push_back(new Node<3>(11, false, 2.0, 2.0, 2.0)); nodes.push_back(new Node<3>(12, false, -1.0, 2.0, 2.0)); // Convert this to a NodesOnlyMesh MAKE_PTR(NodesOnlyMesh<3>, p_mesh); p_mesh->ConstructNodesWithoutMesh(nodes, 1.5); // Specify the node indices corresponding to cells (the others correspond to particles) std::vector<unsigned> location_indices; for (unsigned index=0; index<5; index++) { location_indices.push_back(index); } // Set up cells std::vector<CellPtr> cells; CellsGenerator<FixedDurationGenerationBasedCellCycleModel, 3> cells_generator; cells_generator.GenerateGivenLocationIndices(cells, location_indices); cells[4]->AddCellProperty(CellPropertyRegistry::Instance()->Get<ApoptoticCellProperty>()); // coverage TS_ASSERT_EQUALS(cells[4]->HasCellProperty<ApoptoticCellProperty>(), true); // Create cell population NodeBasedCellPopulationWithParticles<3> cell_population(*p_mesh, cells, location_indices); // Coverage of writing CellData to VTK for (NodeBasedCellPopulationWithParticles<3>::Iterator cell_iter = cell_population.Begin(); cell_iter != cell_population.End(); ++cell_iter) { cell_iter->GetCellData()->SetItem("var0", 1.0); cell_iter->GetCellData()->SetItem("var1", 2.0); } cell_population.Update(); // so cell neighbours are calculated when outputting volume TS_ASSERT_EQUALS(cell_population.GetIdentifier(), "NodeBasedCellPopulationWithParticles-3"); // Test writer methods cell_population.AddCellWriter<CellVolumesWriter>(); cell_population.AddCellPopulationCountWriter<CellMutationStatesCountWriter>(); cell_population.AddCellPopulationCountWriter<CellProliferativeTypesCountWriter>(); cell_population.AddCellWriter<CellAgesWriter>(); cell_population.AddCellPopulationCountWriter<CellProliferativePhasesCountWriter>(); cell_population.AddCellWriter<CellProliferativePhasesWriter>(); cell_population.SetCellAncestorsToLocationIndices(); cell_population.AddCellWriter<CellAncestorWriter>(); std::string output_directory = "TestCellPopulationWritersIn3dWithParticles"; OutputFileHandler output_file_handler(output_directory, false); cell_population.OpenWritersFiles(output_file_handler); cell_population.WriteResultsToFiles(output_directory); cell_population.CloseWritersFiles(); // Compare output with saved files of what they should look like std::string results_dir = output_file_handler.GetOutputDirectoryFullPath(); FileComparison(results_dir + "results.viznodes", "cell_based/test/data/TestCellPopulationWritersIn3dWithParticles/results.viznodes").CompareFiles(); FileComparison(results_dir + "results.vizcelltypes", "cell_based/test/data/TestCellPopulationWritersIn3dWithParticles/results.vizcelltypes").CompareFiles(); FileComparison(results_dir + "results.vizancestors", "cell_based/test/data/TestCellPopulationWritersIn3dWithParticles/results.vizancestors").CompareFiles(); // Test the GetCellMutationStateCount function: there should only be healthy cells std::vector<unsigned> cell_mutation_states = cell_population.GetCellMutationStateCount(); TS_ASSERT_EQUALS(cell_mutation_states.size(), 4u); TS_ASSERT_EQUALS(cell_mutation_states[0], 5u); TS_ASSERT_EQUALS(cell_mutation_states[1], 0u); TS_ASSERT_EQUALS(cell_mutation_states[2], 0u); TS_ASSERT_EQUALS(cell_mutation_states[3], 0u); // Test the GetCellProliferativeTypeCount function - we should have 4 stem cells and 1 dead cell (for coverage) std::vector<unsigned> cell_types = cell_population.GetCellProliferativeTypeCount(); TS_ASSERT_EQUALS(cell_types.size(), 4u); TS_ASSERT_EQUALS(cell_types[0], 5u); TS_ASSERT_EQUALS(cell_types[1], 0u); TS_ASSERT_EQUALS(cell_types[2], 0u); TS_ASSERT_EQUALS(cell_types[3], 0u); // Test that the cell population parameters are output correctly out_stream parameter_file = output_file_handler.OpenOutputFile("results.parameters"); // Write cell population parameters to file cell_population.OutputCellPopulationParameters(parameter_file); parameter_file->close(); // Compare output with saved files of what they should look like FileComparison( results_dir + "results.parameters", "cell_based/test/data/TestCellPopulationWritersIn3dWithParticles/results.parameters").CompareFiles(); for (unsigned i=0; i<nodes.size(); i++) { delete nodes[i]; } }
void TestWriteResultsToFileAndOutputCellPopulationParameters() { EXIT_IF_PARALLEL; // Copying in parallel uses parallel NodesOnlyMesh and will therefore cause unexpected errors. // Resetting the maximum cell ID to zero (to account for previous tests) CellId::ResetMaxCellId(); std::string output_directory = "TestPottsBasedCellPopulationWriters"; OutputFileHandler output_file_handler(output_directory, false); // Create a simple 2D PottsMesh PottsMeshGenerator<2> generator(6, 2, 2, 6, 2, 2); PottsMesh<2>* p_mesh = generator.GetMesh(); // Create cells std::vector<CellPtr> cells; CellsGenerator<FixedDurationGenerationBasedCellCycleModel, 2> cells_generator; cells_generator.GenerateBasic(cells, p_mesh->GetNumElements()); // Create cell population PottsBasedCellPopulation<2> cell_population(*p_mesh, cells); // For coverage, label one cell boost::shared_ptr<AbstractCellProperty> p_label(cell_population.GetCellPropertyRegistry()->Get<CellLabel>()); cell_population.GetCellUsingLocationIndex(0)->AddCellProperty(p_label); TS_ASSERT_EQUALS(cell_population.GetIdentifier(), "PottsBasedCellPopulation-2"); cell_population.SetCellAncestorsToLocationIndices(); cell_population.AddCellPopulationCountWriter<CellMutationStatesCountWriter>(); cell_population.AddCellPopulationCountWriter<CellProliferativeTypesCountWriter>(); cell_population.AddCellPopulationCountWriter<CellProliferativePhasesCountWriter>(); cell_population.AddCellWriter<CellProliferativePhasesWriter>(); cell_population.AddCellWriter<CellAncestorWriter>(); cell_population.AddCellWriter<CellAgesWriter>(); cell_population.AddCellWriter<CellVolumesWriter>(); cell_population.SetNumSweepsPerTimestep(5); TS_ASSERT_EQUALS(cell_population.GetNumSweepsPerTimestep(), 5u); // VTK writing needs a simulation time SimulationTime::Instance()->SetEndTimeAndNumberOfTimeSteps(1.0, 1); cell_population.OpenWritersFiles(output_file_handler); cell_population.WriteResultsToFiles(output_directory); cell_population.CloseWritersFiles(); // Compare output with saved files of what they should look like std::string results_dir = output_file_handler.GetOutputDirectoryFullPath(); FileComparison(results_dir + "results.viznodes", "cell_based/test/data/TestPottsBasedCellPopulationWriters/results.viznodes").CompareFiles(); FileComparison(results_dir + "results.vizcelltypes", "cell_based/test/data/TestPottsBasedCellPopulationWriters/results.vizcelltypes").CompareFiles(); FileComparison(results_dir + "results.vizancestors", "cell_based/test/data/TestPottsBasedCellPopulationWriters/results.vizancestors").CompareFiles(); FileComparison(results_dir + "cellmutationstates.dat", "cell_based/test/data/TestPottsBasedCellPopulationWriters/cellmutationstates.dat").CompareFiles(); FileComparison(results_dir + "cellages.dat", "cell_based/test/data/TestPottsBasedCellPopulationWriters/cellages.dat").CompareFiles(); FileComparison(results_dir + "cellareas.dat", "cell_based/test/data/TestPottsBasedCellPopulationWriters/cellareas.dat").CompareFiles(); // Test that the cell population parameters are output correctly out_stream parameter_file = output_file_handler.OpenOutputFile("results.parameters"); // Write cell population parameters to file cell_population.OutputCellPopulationParameters(parameter_file); parameter_file->close(); // Compare output with saved files of what they should look like FileComparison( results_dir + "results.parameters", "cell_based/test/data/TestPottsBasedCellPopulationWriters/results.parameters").CompareFiles(); }
void TestMakeMeinekeGraphs() throw (Exception) { // Specify output directory std::string output_directory = "MakeMeinekeGraphs"; // Create mesh double crypt_length = 22.0; unsigned cells_across = 13; unsigned cells_up = 25; double crypt_width = 12.1; unsigned thickness_of_ghost_layer = 3; CylindricalHoneycombMeshGenerator generator(cells_across, cells_up, thickness_of_ghost_layer, crypt_width/cells_across); Cylindrical2dMesh* p_mesh = generator.GetCylindricalMesh(); // Get location indices corresponding to real cells std::vector<unsigned> location_indices = generator.GetCellLocationIndices(); // Set up cells std::vector<CellPtr> temp_cells; CryptCellsGenerator<StochasticDurationGenerationBasedCellCycleModel> cells_generator; cells_generator.Generate(temp_cells, p_mesh, std::vector<unsigned>(), true, 0.3, 2.0, 3.0, 4.0, true); // This awkward way of setting up the cells is a result of #430 std::vector<CellPtr> cells; for (unsigned i=0; i<location_indices.size(); i++) { cells.push_back(temp_cells[location_indices[i]]); } // Create cell population MeshBasedCellPopulationWithGhostNodes<2> crypt(*p_mesh, cells, location_indices, false, 30.0); // Last parameter adjusts Ghost spring stiffness in line with the linear_force later on // Set cell population to output cell types crypt.AddPopulationWriter<CellMutationStatesCountWriter>(); // Create and configure simulation CryptSimulation2d simulator(crypt, false, false); simulator.SetOutputDirectory(output_directory); double time_of_each_run = simulator.GetDt(); // for each run simulator.SetEndTime(time_of_each_run); // Create a force law and cell killer and pass then to the simulation MAKE_PTR(GeneralisedLinearSpringForce<2>, p_linear_force); p_linear_force->SetMeinekeSpringStiffness(30.0); // normally 15.0; simulator.AddForce(p_linear_force); MAKE_PTR_ARGS(SloughingCellKiller<2>, p_killer, (&simulator.rGetCellPopulation(), crypt_length)); simulator.AddCellKiller(p_killer); // Specify unusual set up simulator.UseJiggledBottomCells(); // Test CryptStatistics::GetCryptSectionPeriodic() by labelling a column of cells... CryptStatistics crypt_statistics(crypt); std::vector<CellPtr> test_section = crypt_statistics.GetCryptSectionPeriodic(crypt_length + 2.0, 8.0, 8.0); for (unsigned i=0; i<test_section.size(); i++) { test_section[i]->AddCellProperty(crypt.GetCellPropertyRegistry()->Get<CellLabel>()); } simulator.Solve(); CellBasedSimulationArchiver<2, CryptSimulation2d>::Save(&simulator); // ... and checking visualization of labelled cells against previous run OutputFileHandler handler(output_directory, false); std::string results_file = handler.GetOutputDirectoryFullPath() + "results_from_time_0/results.viznodes"; TS_ASSERT(NumericFileComparison( results_file, "crypt/test/data/MakeMeinekeGraphs/results.viznodes").CompareFiles()); std::string results_file2 = handler.GetOutputDirectoryFullPath() + "results_from_time_0/results.vizcelltypes"; FileComparison( results_file2, "crypt/test/data/MakeMeinekeGraphs/results.vizcelltypes").CompareFiles(); // Next, test LabelSPhaseCells() for (AbstractCellPopulation<2>::Iterator cell_iter = crypt.Begin(); cell_iter != crypt.End(); ++cell_iter) { cell_iter->RemoveCellProperty<CellLabel>(); } crypt_statistics.LabelSPhaseCells(); // Iterate over cells checking for correct labels unsigned counter = 0; for (AbstractCellPopulation<2>::Iterator cell_iter = crypt.Begin(); cell_iter != crypt.End(); ++cell_iter) { bool is_labelled = cell_iter->HasCellProperty<CellLabel>(); bool in_s_phase = (cell_iter->GetCellCycleModel()->GetCurrentCellCyclePhase() == S_PHASE); TS_ASSERT_EQUALS(is_labelled, in_s_phase); if (in_s_phase) { counter++; } } TS_ASSERT_EQUALS(counter, 28u); // Test that LabelAllCellsAsHealthy sets all cells back to be UNLABELLED wild type cells crypt_statistics.LabelAllCellsAsHealthy(); // Iterate over cells checking for correct labels counter = 0; for (AbstractCellPopulation<2>::Iterator cell_iter = crypt.Begin(); cell_iter != crypt.End(); ++cell_iter) { TS_ASSERT_EQUALS(cell_iter->GetMutationState()->IsType<WildTypeCellMutationState>(), true); TS_ASSERT_EQUALS(cell_iter->HasCellProperty<CellLabel>(), false); counter++; } TS_ASSERT_EQUALS(counter, simulator.rGetCellPopulation().GetNumRealCells()); crypt_statistics.LabelSPhaseCells(); simulator.SetEndTime(2*time_of_each_run); simulator.Solve(); // TEST CryptStatistics::AreCryptSectionCellsLabelled // Set cells which are not in the crypt section to be in state APC +/-, so that we can // see the section test_section = crypt_statistics.GetCryptSectionPeriodic(crypt_length + 2.0, 8.0, 8.0); MAKE_PTR(ApcOneHitCellMutationState, p_apc1); for (AbstractCellPopulation<2>::Iterator cell_iter = crypt.Begin(); cell_iter != crypt.End(); ++cell_iter) { bool in_section = false; for (unsigned vector_index=0; vector_index<test_section.size(); vector_index++) { if (test_section[vector_index] == *cell_iter) { in_section = true; } } if (!in_section) { cell_iter->SetMutationState(p_apc1); } } simulator.SetEndTime(3*time_of_each_run); simulator.Solve(); std::vector<CellPtr> crypt_section = crypt_statistics.GetCryptSection(crypt_length + 2.0, 8.0, 8.0); std::vector<bool> labelled = crypt_statistics.AreCryptSectionCellsLabelled(crypt_section); // Test that the vector of booleans corresponds with a visualisation of the data - // only the first few cells at the base of the crypt have been labelled for (unsigned vector_index=0; vector_index<labelled.size(); vector_index++) { if (vector_index == 2u || vector_index == 3u || vector_index == 4u) { TS_ASSERT_EQUALS(labelled[vector_index], true); } else { TS_ASSERT_EQUALS(labelled[vector_index], false); } } RandomNumberGenerator::Destroy(); }