void TestVertexMeshWriterWithToroidalMesh() throw(Exception) { // Create toroidal mesh (i.e. one that is periodic in both directions) ToroidalHoneycombVertexMeshGenerator generator(4, 4); Toroidal2dVertexMesh* p_mesh = generator.GetToroidalMesh(); TS_ASSERT_EQUALS(p_mesh->GetNumNodes(), 32u); // 2*4*4 TS_ASSERT_EQUALS(p_mesh->GetNumElements(), 16u); // 4*4 // Create a vertex mesh writer VertexMeshWriter<2,2> vertex_mesh_writer("TestVertexMeshWriterWithToroidalMesh", "tor_vertex_mesh_2d"); // Test files are written correctly vertex_mesh_writer.WriteFilesUsingMesh(*p_mesh); OutputFileHandler handler("TestVertexMeshWriterWithToroidalMesh", false); std::string results_file1 = handler.GetOutputDirectoryFullPath() + "tor_vertex_mesh_2d.node"; std::string results_file2 = handler.GetOutputDirectoryFullPath() + "tor_vertex_mesh_2d.cell"; FileComparison comparer1(results_file1,"mesh/test/data/TestVertexMeshWriterWithToroidalMesh/tor_vertex_mesh_2d.node"); TS_ASSERT(comparer1.CompareFiles()); FileComparison comparer2(results_file2,"mesh/test/data/TestVertexMeshWriterWithToroidalMesh/tor_vertex_mesh_2d.cell"); TS_ASSERT(comparer2.CompareFiles()); #ifdef CHASTE_VTK MutableVertexMesh<2, 2>* p_mesh_for_vtk = p_mesh->GetMeshForVtk(); std::vector<double> cell_ids; for (unsigned i=0; i<p_mesh_for_vtk->GetNumElements(); i++) { double this_cell_id = (double) i; cell_ids.push_back(this_cell_id); } vertex_mesh_writer.AddCellData("Cell IDs", cell_ids); // Add distance from origin into the node "point" data std::vector<double> distance; for (unsigned i=0; i<p_mesh_for_vtk->GetNumNodes(); i++) { distance.push_back(norm_2(p_mesh_for_vtk->GetNode(i)->rGetLocation())); } vertex_mesh_writer.AddPointData("Distance from origin", distance); vertex_mesh_writer.WriteVtkUsingMesh(*p_mesh); { ///\todo #1076. We need a way to test the contents of the VTK file std::string results_file3 = handler.GetOutputDirectoryFullPath() + "tor_vertex_mesh_2d.vtu"; FileFinder vtk_file(results_file3, RelativeTo::Absolute); TS_ASSERT(vtk_file.Exists()); } // Avoid memory leak delete p_mesh_for_vtk; #else std::cout << "This test ran, but did not test VTK-dependent functions as VTK visualization 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_VTK }
/* * Cellular birth has been tested in TestCaSingleCellWithBirth for one cell per lattice site. * This test adds to the above by further testing cellular birth considering multiple cells per lattice site. * A two-lattice mesh was created and only one lattice had free space to add one daughter cell. */ void TestMultipleCellsPerLatticeSiteWithBirth() throw (Exception) { EXIT_IF_PARALLEL; // Create a simple 2D PottsMesh PottsMeshGenerator<2> generator(2, 0, 0, 1, 0, 0); PottsMesh<2>* p_mesh = generator.GetMesh(); // Create cells std::vector<CellPtr> cells; MAKE_PTR(StemCellProliferativeType, p_stem_type); CellsGenerator<FixedDurationGenerationBasedCellCycleModel, 2> cells_generator; cells_generator.GenerateBasicRandom(cells, 3, p_stem_type); // Specify where cells lie std::vector<unsigned> location_indices; location_indices.push_back(0); location_indices.push_back(0); location_indices.push_back(1); // Create cell population CaBasedCellPopulation<2> cell_population(*p_mesh, cells, location_indices, 2); // Set up cell-based simulation OnLatticeSimulation<2> simulator(cell_population); std::string output_directory = "TestMultipleCellsPerLatticeSiteWithBirth"; simulator.SetOutputDirectory(output_directory); simulator.SetDt(0.1); simulator.SetEndTime(40); // Add update rule MAKE_PTR(DiffusionCaUpdateRule<2u>, p_diffusion_update_rule); p_diffusion_update_rule->SetDiffusionParameter(0.5); simulator.AddCaUpdateRule(p_diffusion_update_rule); // Run simulation simulator.Solve(); // Check the number of cells TS_ASSERT_EQUALS(simulator.rGetCellPopulation().GetNumRealCells(), 4u); // Test no deaths and some births TS_ASSERT_EQUALS(simulator.GetNumBirths(), 1u); TS_ASSERT_EQUALS(simulator.GetNumDeaths(), 0u); #ifdef CHASTE_VTK // Test that VTK writer has produced a file OutputFileHandler output_file_handler(output_directory, false); std::string results_dir = output_file_handler.GetOutputDirectoryFullPath(); // Initial condition file FileFinder vtk_file(results_dir + "results_from_time_0/results_0.vtu", RelativeTo::Absolute); TS_ASSERT(vtk_file.Exists()); // Final file FileFinder vtk_file2(results_dir + "results_from_time_0/results_400.vtu", RelativeTo::Absolute); TS_ASSERT(vtk_file2.Exists()); #endif //CHASTE_VTK }
void TestVertexMeshWriterIn3dWithFaces() throw(Exception) { // Create a simple 3D mesh using the Voronoi constructor 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> delaunay_mesh(nodes); VertexMesh<3,3> mesh3d(delaunay_mesh); // Create a vertex mesh writer VertexMeshWriter<3,3> vertex_mesh_writer("TestVertexMeshWriterIn3dWithFaces", "vertex_mesh_3d_with_faces", false); // Test files are written correctly vertex_mesh_writer.WriteFilesUsingMesh(mesh3d); OutputFileHandler handler("TestVertexMeshWriterIn3dWithFaces", false); std::string results_file1 = handler.GetOutputDirectoryFullPath() + "vertex_mesh_3d_with_faces.node"; std::string results_file2 = handler.GetOutputDirectoryFullPath() + "vertex_mesh_3d_with_faces.cell"; ///\todo #1468 the current saved results have no boundary nodes ///this ticket should fix that and you will need to change the saved results FileComparison comparer1(results_file1,"mesh/test/data/TestVertexMeshWriter/vertex_mesh_3d_with_faces.node"); TS_ASSERT(comparer1.CompareFiles()); FileComparison comparer2(results_file2,"mesh/test/data/TestVertexMeshWriter/vertex_mesh_3d_with_faces.cell"); TS_ASSERT(comparer2.CompareFiles()); #ifdef CHASTE_VTK std::vector<double> cell_ids; cell_ids.push_back(0.0); vertex_mesh_writer.AddCellData("Cell IDs", cell_ids); // Add distance from origin into the node "point" data std::vector<double> distance; for (unsigned i=0; i<mesh3d.GetNumNodes(); i++) { distance.push_back(norm_2(mesh3d.GetNode(i)->rGetLocation())); } vertex_mesh_writer.AddPointData("Distance from origin", distance); vertex_mesh_writer.WriteVtkUsingMesh(mesh3d, "42"); { ///\todo #1076. We need a way to test the contents of the VTK file std::string results_file3 = handler.GetOutputDirectoryFullPath() + "vertex_mesh_3d_with_faces_42.vtu"; FileFinder vtk_file(results_file3, RelativeTo::Absolute); TS_ASSERT(vtk_file.Exists()); } #else std::cout << "This test ran, but did not test VTK-dependent functions as VTK visualization 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_VTK }
bool write_c3t3_to_vtk_xml_file(const C3t3 &c3t3, const std::string &file_name) { typedef typename C3t3::Triangulation Tr; typedef typename C3t3::Cells_in_complex_iterator Cell_iterator; typedef typename Tr::Finite_vertices_iterator Vertex_iterator; // Domain typedef Exact_predicates_inexact_constructions_kernel K; typedef K::FT FT; typedef K::Point_3 Point; // check that file extension is "vtu" CGAL_assertion(file_name.substr(file_name.length()-4,4) == ".vtu"); // open file std::ofstream vtk_file(file_name.c_str()); // header vtk_file << "<VTKFile type=\"UnstructuredGrid\" "; vtk_file << "version=\"0.1\" "; vtk_file << "byte_order=\"BigEndian\">" << std::endl; int indent_size = 2; std::string indent_unit(indent_size, ' '); std::string indent = indent_unit; vtk_file << indent + "<UnstructuredGrid>" << std::endl; // write mesh Tr t = c3t3.triangulation(); int num_vertices = t.number_of_vertices(); int num_cells = c3t3.number_of_cells_in_complex(); indent += indent_unit; vtk_file << indent + "<Piece NumberOfPoints=\"" << num_vertices << "\" "; vtk_file << "NumberOfCells=\"" << num_cells << "\">" << std::endl; // Write vertices indent += indent_unit; vtk_file << indent + "<Points>" << std::endl; indent += indent_unit; vtk_file << indent; vtk_file << "<DataArray type=\"Float32\" NumberOfComponents=\"3\" Format=\"ascii\">" << std::endl; std::map<Point, int> V; int i=0; indent += indent_unit; for (Vertex_iterator it=t.finite_vertices_begin(); it != t.finite_vertices_end(); ++it) { vtk_file << indent; vtk_file << it->point().x() << " " << it->point().y() << " " << it->point().z() << std::endl; V[it->point()] = i; ++i; } indent.erase(indent.length()-indent_size, indent_size); vtk_file << indent + "</DataArray>" << std::endl; indent.erase(indent.length()-indent_size, indent_size); vtk_file << indent + "</Points>" << std::endl; // Write tetrahedra vtk_file << indent << "<Cells>" << std::endl; indent += indent_unit; vtk_file << indent; vtk_file << "<DataArray type=\"Int32\" Name=\"connectivity\" Format=\"ascii\">"; vtk_file << std::endl; indent += indent_unit; Cell_iterator it; for (it = c3t3.cells_in_complex_begin(); it != c3t3.cells_in_complex_end(); ++it) { const typename Tr::Cell c(*it); const typename Tr::Vertex_handle v0 = c.vertex(0); const typename Tr::Vertex_handle v1 = c.vertex(1); const typename Tr::Vertex_handle v2 = c.vertex(2); const typename Tr::Vertex_handle v3 = c.vertex(3); vtk_file << indent; vtk_file << V[v0->point()] << " "; vtk_file << V[v1->point()] << " "; vtk_file << V[v2->point()] << " "; vtk_file << V[v3->point()] << std::endl; } indent.erase(indent.length()-indent_size, indent_size); vtk_file << indent + "</DataArray>" << std::endl; // offsets // every element is a four node tetrahedron so all offsets are multiples of 4 vtk_file << indent; vtk_file << "<DataArray type=\"Int32\" Name=\"offsets\" Format=\"ascii\">"; vtk_file << std::endl; i = 4; indent += indent_unit; for (it = c3t3.cells_in_complex_begin(); it != c3t3.cells_in_complex_end(); ++it) { vtk_file << indent << i << std::endl; i += 4; } indent.erase(indent.length()-indent_size, indent_size); vtk_file << indent + "</DataArray>" << std::endl; // cell types (type 10 is a 4 node tetrahedron) vtk_file << indent; vtk_file << "<DataArray type=\"Int32\" Name=\"types\" Format=\"ascii\">"; vtk_file << std::endl; indent += indent_unit; for (it = c3t3.cells_in_complex_begin(); it != c3t3.cells_in_complex_end(); ++it) { vtk_file << indent << "10" << std::endl; } indent.erase(indent.length()-indent_size, indent_size); vtk_file << indent + "</DataArray>" << std::endl; indent.erase(indent.length()-indent_size, indent_size); vtk_file << indent + "</Cells>" << std::endl; // cell data // only subdomain index is written here vtk_file << indent + "<CellData Scalars=\"scalars\">" << std::endl; indent += indent_unit; vtk_file << indent + "<DataArray type=\"Int32\" Name=\"subdomain index\" Format=\"ascii\">" << std::endl; indent += indent_unit; for (it = c3t3.cells_in_complex_begin(); it != c3t3.cells_in_complex_end(); ++it) { vtk_file << indent << c3t3.subdomain_index(it) << std::endl; } indent.erase(indent.length()-indent_size, indent_size); vtk_file << indent + "</DataArray>" << std::endl; indent.erase(indent.length()-indent_size, indent_size); vtk_file << indent + "</CellData>" << std::endl; indent.erase(indent.length()-indent_size, indent_size); vtk_file << indent + "</Piece>" << std::endl; indent.erase(indent.length()-indent_size, indent_size); vtk_file << indent + "</UnstructuredGrid>" << std::endl; indent.erase(indent.length()-indent_size, indent_size); vtk_file << "</VTKFile>" << std::endl; return true; }
void TestVertexMeshWriterIn2d() throw(Exception) { std::vector<Node<2>*> basic_nodes; basic_nodes.push_back(new Node<2>(0, true, 0.0, 0.0)); basic_nodes.push_back(new Node<2>(1, true, 1.0, 0.0)); basic_nodes.push_back(new Node<2>(2, true, 1.5, 1.0)); basic_nodes.push_back(new Node<2>(3, true, 1.0, 2.0)); basic_nodes.push_back(new Node<2>(4, true, 0.0, 1.0)); basic_nodes.push_back(new Node<2>(5, true, 2.0, 0.0)); basic_nodes.push_back(new Node<2>(6, true, 2.0, 3.0)); std::vector<Node<2>*> nodes_elem_0, nodes_elem_1; // Make two elements out of these nodes nodes_elem_0.push_back(basic_nodes[0]); nodes_elem_0.push_back(basic_nodes[1]); nodes_elem_0.push_back(basic_nodes[2]); nodes_elem_0.push_back(basic_nodes[3]); nodes_elem_0.push_back(basic_nodes[4]); nodes_elem_1.push_back(basic_nodes[2]); nodes_elem_1.push_back(basic_nodes[5]); nodes_elem_1.push_back(basic_nodes[6]); std::vector<VertexElement<2,2>*> basic_vertex_elements; basic_vertex_elements.push_back(new VertexElement<2,2>(0, nodes_elem_0)); basic_vertex_elements.push_back(new VertexElement<2,2>(1, nodes_elem_1)); // Make a vertex mesh VertexMesh<2,2> basic_vertex_mesh(basic_nodes, basic_vertex_elements); // Create a vertex mesh writer VertexMeshWriter<2,2> vertex_mesh_writer("TestVertexMeshWriterIn2d", "vertex_mesh_2d"); // Test files are written correctly vertex_mesh_writer.WriteFilesUsingMesh(basic_vertex_mesh); OutputFileHandler handler("TestVertexMeshWriterIn2d", false); std::string results_file1 = handler.GetOutputDirectoryFullPath() + "vertex_mesh_2d.node"; std::string results_file2 = handler.GetOutputDirectoryFullPath() + "vertex_mesh_2d.cell"; FileComparison comparer1(results_file1,"mesh/test/data/TestVertexMeshWriter/vertex_mesh_2d.node"); TS_ASSERT(comparer1.CompareFiles()); FileComparison comparer2(results_file2,"mesh/test/data/TestVertexMeshWriter/vertex_mesh_2d.cell"); TS_ASSERT(comparer2.CompareFiles()); #ifdef CHASTE_VTK std::vector<double> cell_ids; cell_ids.push_back(0.0); cell_ids.push_back(1.0); vertex_mesh_writer.AddCellData("Cell IDs", cell_ids); // Add distance from origin into the node "point" data std::vector<double> distance; for (unsigned i=0; i<basic_vertex_mesh.GetNumNodes(); i++) { distance.push_back(norm_2(basic_vertex_mesh.GetNode(i)->rGetLocation())); } vertex_mesh_writer.AddPointData("Distance from origin", distance); vertex_mesh_writer.WriteVtkUsingMesh(basic_vertex_mesh); { ///\todo #1076. We need a way to test the contents of the VTK file std::string results_file3 = handler.GetOutputDirectoryFullPath() + "vertex_mesh_2d.vtu"; FileFinder vtk_file(results_file3, RelativeTo::Absolute); TS_ASSERT(vtk_file.Exists()); } #else std::cout << "This test ran, but did not test VTK-dependent functions as VTK visualization 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_VTK }
void TestVertexMeshWriterIn3dWithoutFaces() throw(Exception) { // Create 3D mesh 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, 0.0, 0.0)); nodes.push_back(new Node<3>(2, true, 1.0, 2.0, 0.0)); nodes.push_back(new Node<3>(3, true, 0.0, 2.0, 0.0)); nodes.push_back(new Node<3>(4, true, 0.0, 2.0, 3.0)); nodes.push_back(new Node<3>(5, true, 1.0, 0.0, 3.0)); nodes.push_back(new Node<3>(6, true, 1.0, 2.0, 3.0)); nodes.push_back(new Node<3>(7, true, 0.0, 2.0, 3.0)); std::vector<VertexElement<3,3>*> elements; elements.push_back(new VertexElement<3,3>(0, nodes)); // Make a vertex mesh VertexMesh<3,3> mesh3d(nodes, elements); TS_ASSERT_DELTA(mesh3d.GetWidth(0), 1.0, 1e-4); TS_ASSERT_DELTA(mesh3d.GetWidth(1), 2.0, 1e-4); TS_ASSERT_DELTA(mesh3d.GetWidth(2), 3.0, 1e-4); // Create a vertex mesh writer VertexMeshWriter<3,3> vertex_mesh_writer("TestVertexMeshWriterIn3dWithoutFaces", "vertex_mesh_3d", false); // Test files are written correctly vertex_mesh_writer.WriteFilesUsingMesh(mesh3d); OutputFileHandler handler("TestVertexMeshWriterIn3dWithoutFaces", false); std::string results_file1 = handler.GetOutputDirectoryFullPath() + "vertex_mesh_3d.node"; std::string results_file2 = handler.GetOutputDirectoryFullPath() + "vertex_mesh_3d.cell"; FileComparison comparer1(results_file1,"mesh/test/data/TestVertexMeshWriter/vertex_mesh_3d.node"); TS_ASSERT(comparer1.CompareFiles()); FileComparison comparer2(results_file2,"mesh/test/data/TestVertexMeshWriter/vertex_mesh_3d.cell"); TS_ASSERT(comparer2.CompareFiles()); #ifdef CHASTE_VTK std::vector<double> cell_ids; cell_ids.push_back(0.0); vertex_mesh_writer.AddCellData("Cell IDs", cell_ids); // Add distance from origin into the node "point" data std::vector<double> distance; for (unsigned i=0; i<mesh3d.GetNumNodes(); i++) { distance.push_back(norm_2(mesh3d.GetNode(i)->rGetLocation())); } vertex_mesh_writer.AddPointData("Distance from origin", distance); vertex_mesh_writer.WriteVtkUsingMesh(mesh3d, "42"); { ///\todo #1076. We need a way to test the contents of the VTK file std::string results_file3 = handler.GetOutputDirectoryFullPath() + "vertex_mesh_3d_42.vtu"; FileFinder vtk_file(results_file3, RelativeTo::Absolute); TS_ASSERT(vtk_file.Exists()); } #else std::cout << "This test ran, but did not test VTK-dependent functions as VTK visualization 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_VTK }
void TestPottsBasedWithCoarseMeshTwoEquations() throw(Exception) { EXIT_IF_PARALLEL; // 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; MAKE_PTR(DifferentiatedCellProliferativeType, p_diff_type); CellsGenerator<FixedDurationGenerationBasedCellCycleModel, 2> cells_generator; cells_generator.GenerateBasicRandom(cells, p_mesh->GetNumElements(), p_diff_type); // Create cell population PottsBasedCellPopulation<2> cell_population(*p_mesh, cells); // Set up cell-based simulation OnLatticeSimulation<2> simulator(cell_population); simulator.SetOutputDirectory("TestPottsBasedCellPopulationWithTwoPdes"); simulator.SetEndTime(0.1); // Set up PDE and pass to simulation via handler (zero uptake to check analytic solution) AveragedSourcePde<2> pde_1(cell_population, 0.0); ConstBoundaryCondition<2> bc_1(1.0); PdeAndBoundaryConditions<2> pde_and_bc_1(&pde_1, &bc_1, false); pde_and_bc_1.SetDependentVariableName("quantity 1"); AveragedSourcePde<2> pde_2(cell_population, 0.0); ConstBoundaryCondition<2> bc_2(1.0); PdeAndBoundaryConditions<2> pde_and_bc_2(&pde_2, &bc_2, false); pde_and_bc_2.SetDependentVariableName("quantity 2"); CellBasedPdeHandler<2> pde_handler(&cell_population); pde_handler.AddPdeAndBc(&pde_and_bc_1); pde_handler.AddPdeAndBc(&pde_and_bc_2); ChastePoint<2> lower(0.0, 0.0); ChastePoint<2> upper(50.0, 50.0); ChasteCuboid<2> cuboid(lower, upper); pde_handler.UseCoarsePdeMesh(10.0, cuboid, true); pde_handler.SetImposeBcsOnCoarseBoundary(true); simulator.SetCellBasedPdeHandler(&pde_handler); // Create update rules and pass to the simulation MAKE_PTR(VolumeConstraintPottsUpdateRule<2>, p_volume_constraint_update_rule); simulator.AddPottsUpdateRule(p_volume_constraint_update_rule); MAKE_PTR(AdhesionPottsUpdateRule<2>, p_adhesion_update_rule); simulator.AddPottsUpdateRule(p_adhesion_update_rule); // Solve the system simulator.Solve(); // Test solution is constant for (AbstractCellPopulation<2>::Iterator cell_iter = cell_population.Begin(); cell_iter != cell_population.End(); ++cell_iter) { double analytic_solution = 1.0; // Test that PDE solver is working correctly on both pdes TS_ASSERT_DELTA(cell_iter->GetCellData()->GetItem("quantity 1"), analytic_solution, 1e-2); TS_ASSERT_DELTA(cell_iter->GetCellData()->GetItem("quantity 2"), analytic_solution, 1e-2); } #ifdef CHASTE_VTK //First file exists FileFinder vtk_file("TestPottsBasedCellPopulationWithTwoPdes/results_from_time_0/pde_results_1.vtu", RelativeTo::ChasteTestOutput); TS_ASSERT(vtk_file.Exists()); // Check that the second VTK file for the solution has the dependent quantities OutputFileHandler handler("TestPottsBasedCellPopulationWithTwoPdes", false); VtkMeshReader<3,3> vtk_reader(handler.GetOutputDirectoryFullPath()+"results_from_time_0/pde_results_2.vtu"); std::vector<double> data1; //There is no Oxygen TS_ASSERT_THROWS_CONTAINS(vtk_reader.GetPointData("Oxygen", data1), "No point data"); TS_ASSERT(data1.empty()); vtk_reader.GetPointData("quantity 1", data1); TS_ASSERT_EQUALS(data1.size(), 6u*6u); std::vector<double> data2; vtk_reader.GetPointData("quantity 2", data2); TS_ASSERT_EQUALS(data1.size(), data2.size()); #endif //CHASTE_VTK }
int main ( int argc, char * argv [] ) { std::ifstream lyapunov_file ( "lyapunov.txt" ); std::ofstream vtk_file ( "lyapunov.vtk" ); MorseGraph cmg; cmg . load ( "cushing.cmg" ); uint64_t N = cmg . phaseSpace () -> size (); // N is also the number of values in lyapunov.txt std::cout << "There are " << N << " grid elements.\n"; boost::unordered_map < Point, uint64_t > points; std::vector< Point > point_by_index; uint64_t num_points = 0; std::cout << "Computing points\n"; for ( uint64_t i = 0; i < N; ++ i ) { int progresspercent = 0; if ( (100*i)/N > progresspercent) { progresspercent = (100*i)/N; std::cout << "\r" << progresspercent << "% "; std::cout . flush (); } RectGeo rect = * boost::dynamic_pointer_cast<RectGeo> ( cmg . phaseSpace () -> geometry ( i ) ); for ( int k = 0; k < 8; ++ k ) { double x = (k&1)?rect.upper_bounds[0]:rect.lower_bounds[0]; double y = (k&2)?rect.upper_bounds[1]:rect.lower_bounds[1]; double z = (k&4)?rect.upper_bounds[2]:rect.lower_bounds[2]; Point p ( x, y, z ); if ( points . count ( p ) ) continue; point_by_index . push_back ( p ); points [ p ] = num_points ++; } } std::cout << "\r"; uint64_t M = points . size (); std::cout << "There are " << M << " distinct points (i.e. vertices of grid elements).\n"; // OUTPUT PREAMBLE vtk_file << "# vtk DataFile Version 3.0\n"; vtk_file << "vtk output\n"; vtk_file << "ASCII\n"; vtk_file << "DATASET UNSTRUCTURED_GRID\n"; // OUTPUT POINTS std::cout << "Outputting points\n"; vtk_file << "POINTS " << M << " float\n"; for ( uint64_t i = 0; i < M; ++ i ) { int progresspercent = 0; if ( (100*i)/M > progresspercent) { progresspercent = (100*i)/M; std::cout << "\r" << progresspercent << "% "; std::cout . flush (); } const Point & p = point_by_index [ i ]; vtk_file << p.x << " " << p.y << " " << p.z << "\n"; } std::cout << "\r"; // OUTPUT CELLS std::cout << "Outputting cells\n"; vtk_file << "CELLS " << N << " " << 9*N << "\n"; for ( uint64_t i = 0; i < N; ++ i ) { int progresspercent = 0; if ( (100*i)/N > progresspercent) { progresspercent = (100*i)/N; std::cout << "\r" << progresspercent << "% "; std::cout . flush (); } RectGeo rect = * boost::dynamic_pointer_cast<RectGeo> ( cmg . phaseSpace () -> geometry ( i ) ); vtk_file << "8"; for ( int k = 0; k < 8; ++ k ) { double x = (k&1)?rect.upper_bounds[0]:rect.lower_bounds[0]; double y = (k&2)?rect.upper_bounds[1]:rect.lower_bounds[1]; double z = (k&4)?rect.upper_bounds[2]:rect.lower_bounds[2]; Point p ( x, y, z ); uint64_t pi = points [ p ]; vtk_file << " " << pi; } vtk_file << "\n"; } std::cout << "\r"; // OUTPUT CELL TYPES (all VTK_VOXEL == 11 ) //std::cout << "Outputting cell types\n"; vtk_file << "CELL_TYPES " << N << "\n"; for ( uint64_t i = 0; i < N; ++ i ) { vtk_file << "11\n"; } // OUTPUT SCALAR FIELD INFORMATION std::cout << "Outputting scalars\n"; vtk_file << "CELL_DATA " << N << "\n"; vtk_file << "SCALARS cell_scalars float 1\n"; vtk_file << "LOOKUP_TABLE default\n"; for ( uint64_t i = 0; i < N; ++ i ) { int progresspercent = 0; if ( (100*i)/N > progresspercent) { progresspercent = (100*i)/N; std::cout << "\r" << progresspercent << "% "; std::cout . flush (); } RectGeo rect = * boost::dynamic_pointer_cast<RectGeo> ( cmg . phaseSpace () -> geometry ( i ) ); double intensity; lyapunov_file >> intensity; if ( not lyapunov_file . good () ) { throw std::logic_error ( "Not enough data points in lyapunov.txt to correspond to MorseGraph.\n"); } // PUT CODE HERE TO PUT IN A VTK ENTRY CORRESPONDING TO vtk_file << intensity << "\n"; // RECTGEO AND INTENSITY } std::cout << "\r \n"; vtk_file . close (); lyapunov_file . close (); return 0; }
void TestPottsSpheroidCellSorting() throw (Exception) { EXIT_IF_PARALLEL; // Potts simulations don't work in parallel because they depend on NodesOnlyMesh for writing. // Create a simple 3D PottsMesh unsigned domain_size = 10; unsigned element_number = 4; unsigned element_size = 2; PottsMeshGenerator<3> generator(domain_size, element_number, element_size, domain_size, element_number, element_size, domain_size, element_number, element_size); PottsMesh<3>* p_mesh = generator.GetMesh(); // Create cells std::vector<CellPtr> cells; MAKE_PTR(DifferentiatedCellProliferativeType, p_diff_type); CellsGenerator<FixedDurationGenerationBasedCellCycleModel, 3> cells_generator; cells_generator.GenerateBasicRandom(cells, p_mesh->GetNumElements(), p_diff_type); // Randomly label some cells boost::shared_ptr<AbstractCellProperty> p_label(CellPropertyRegistry::Instance()->Get<CellLabel>()); RandomlyLabelCells(cells, p_label, 0.5); // Create cell population PottsBasedCellPopulation<3> cell_population(*p_mesh, cells); cell_population.AddCellPopulationCountWriter<CellMutationStatesCountWriter>(); // So outputs the labelled cells // Set up cell-based simulation OnLatticeSimulation<3> simulator(cell_population); simulator.SetOutputDirectory("TestPotts3DCellSorting"); simulator.SetDt(0.1); simulator.SetEndTime(1.0); // Create update rules and pass to the simulation MAKE_PTR(VolumeConstraintPottsUpdateRule<3>, p_volume_constraint_update_rule); p_volume_constraint_update_rule->SetMatureCellTargetVolume(element_size*element_size*element_size); p_volume_constraint_update_rule->SetDeformationEnergyParameter(0.2); simulator.AddPottsUpdateRule(p_volume_constraint_update_rule); MAKE_PTR(DifferentialAdhesionPottsUpdateRule<3>, p_differential_adhesion_update_rule); p_differential_adhesion_update_rule->SetLabelledCellLabelledCellAdhesionEnergyParameter(0.16); p_differential_adhesion_update_rule->SetLabelledCellCellAdhesionEnergyParameter(0.11); p_differential_adhesion_update_rule->SetCellCellAdhesionEnergyParameter(0.02); p_differential_adhesion_update_rule->SetLabelledCellBoundaryAdhesionEnergyParameter(0.16); p_differential_adhesion_update_rule->SetCellBoundaryAdhesionEnergyParameter(0.16); simulator.AddPottsUpdateRule(p_differential_adhesion_update_rule); // Run simulation simulator.Solve(); // Check that the same number of cells TS_ASSERT_EQUALS(simulator.rGetCellPopulation().GetNumRealCells(), 64u); // Test no births or deaths TS_ASSERT_EQUALS(simulator.GetNumBirths(), 0u); TS_ASSERT_EQUALS(simulator.GetNumDeaths(), 0u); #ifdef CHASTE_VTK // Test that VTK writer has produced some files OutputFileHandler handler("TestPotts3DCellSorting", false); std::string results_dir = handler.GetOutputDirectoryFullPath(); // Initial condition file FileFinder vtk_file(results_dir + "results_from_time_0/results_0.vtu", RelativeTo::Absolute); TS_ASSERT(vtk_file.Exists()); // Final file FileFinder vtk_file2(results_dir + "results_from_time_0/results_10.vtu", RelativeTo::Absolute); TS_ASSERT(vtk_file2.Exists()); // Check that the second VTK file for Potts specific data (element IDs) VtkMeshReader<3,3> vtk_reader(results_dir + "results_from_time_0/results_10.vtu"); std::vector<double> cell_types; vtk_reader.GetPointData("Cell types", cell_types); TS_ASSERT_EQUALS(cell_types.size(), 1000u); // The cell types are between -1 and 5. Check the maximum TS_ASSERT_DELTA(*max_element(cell_types.begin(), cell_types.end()), 5.0, 1e-12); std::vector<double> cell_ids; vtk_reader.GetPointData("Cell IDs", cell_ids); // Prior to release 3.2 this was called "Element index". // It is changed to cell_id as this is preferable for VTK output. TS_ASSERT_EQUALS(cell_ids.size(), 1000u); TS_ASSERT_DELTA(*max_element(cell_ids.begin(), cell_ids.end()), 63.0, 1e-12); #endif //CHASTE_VTK }