示例#1
0
    // This test covers the case when the hdf5 file contains 3 variables (e.g., after solving a problem with PROBLEM_DIM=3)
    void TestMeshalyzerConversion3Variables() 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_TestMeshalyzerConversion3Variables");
        CopyToTestOutputDirectory("heart/test/data/three_variables/3_vars.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),
                                                 "3_vars", &mesh, true);

        // Compare the first voltage file
        std::string test_output_directory = OutputFileHandler::GetChasteTestOutputDirectory();
        NumericFileComparison(test_output_directory + output_folder + "/output/3_vars_Vm_1.dat",
                              "heart/test/data/three_variables/extended_bidomain_Vm_1.dat").CompareFiles();

        // Compare the second voltage file
        NumericFileComparison(test_output_directory + output_folder +"/output/3_vars_Vm_2.dat",
                              "heart/test/data/three_variables/extended_bidomain_Vm_2.dat").CompareFiles();

        // Compare the Phi_e file
        NumericFileComparison(test_output_directory + output_folder + "/output/3_vars_Phi_e.dat",
                              "heart/test/data/three_variables/extended_bidomain_Phi_e.dat").CompareFiles();

        // Compare the time information file
        FileComparison(test_output_directory + output_folder + "/output/3_vars_times.info",
                       "heart/test/data/three_variables/extended_bidomain_times.info").CompareFiles();
    }
示例#2
0
    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();
    }