void TestSimpleUniformSourceParabolicPdeMethods() throw(Exception) { // Create a PDE object SimpleUniformSourceParabolicPde<2> pde(0.1); // Test that the member variables have been initialised correctly TS_ASSERT_EQUALS(pde.GetCoefficient(),0.1); // Test methods ChastePoint<2> point; TS_ASSERT_DELTA(pde.ComputeSourceTerm(point,DBL_MAX), 0.1, 1e-6); TS_ASSERT_DELTA(pde.ComputeDuDtCoefficientFunction(point), 1.0, 1e-6); c_matrix<double,2,2> diffusion_matrix = pde.ComputeDiffusionTerm(point); for (unsigned i=0; i<2; i++) { for (unsigned j=0; j<2; j++) { double value = 0.0; if (i == j) { value = 1.0; } TS_ASSERT_DELTA(diffusion_matrix(i,j), value, 1e-6); } } }
void TestSimpleUniformSourcePdeMethods() throw(Exception) { EXIT_IF_PARALLEL; // Create a PDE object SimpleUniformSourcePde<2> pde(0.05); // Test that the member variables have been initialised correctly TS_ASSERT_DELTA(pde.GetCoefficient(), 0.05, 1e-6); ChastePoint<2> point; TS_ASSERT_DELTA(pde.ComputeConstantInUSourceTerm(point, NULL), 0.0, 1e-6); TS_ASSERT_DELTA(pde.ComputeLinearInUCoeffInSourceTerm(point, NULL), 0.05, 1e-6); c_matrix<double,2,2> diffusion_matrix = pde.ComputeDiffusionTerm(point); for (unsigned i=0; i<2; i++) { for (unsigned j=0; j<2; j++) { double value = 0.0; if (i == j) { value = 1.0; } TS_ASSERT_DELTA(diffusion_matrix(i,j), value, 1e-6); } } }
DenseSymmetricMatrix compute_diffusion_matrix(RandomAccessIterator begin, RandomAccessIterator end, DistanceCallback callback, const ScalarType width) { timed_context context("Diffusion map matrix computation"); const IndexType n_vectors = end-begin; DenseSymmetricMatrix diffusion_matrix(n_vectors,n_vectors); DenseVector p = DenseVector::Zero(n_vectors); RESTRICT_ALLOC; // compute gaussian kernel matrix #pragma omp parallel shared(diffusion_matrix,begin,callback) default(none) { IndexType i_index_iter, j_index_iter; #pragma omp for nowait for (i_index_iter=0; i_index_iter<n_vectors; ++i_index_iter) { for (j_index_iter=i_index_iter; j_index_iter<n_vectors; ++j_index_iter) { ScalarType k = callback.distance(begin[i_index_iter],begin[j_index_iter]); ScalarType gk = exp(-(k*k)/width); diffusion_matrix(i_index_iter,j_index_iter) = gk; diffusion_matrix(j_index_iter,i_index_iter) = gk; } } } // compute column sum vector p = diffusion_matrix.colwise().sum(); // compute full matrix as we need to compute sum later // TODO add weighting alpha, use linear algebra to compute D^-alpha K D^-alpha for (IndexType i=0; i<n_vectors; i++) for (IndexType j=0; j<n_vectors; j++) diffusion_matrix(i,j) /= p(i)*p(j); // compute sqrt of column sum vector p = diffusion_matrix.colwise().sum().cwiseSqrt(); for (IndexType i=0; i<n_vectors; i++) for (IndexType j=0; j<n_vectors; j++) diffusion_matrix(i,j) /= p(i)*p(j); UNRESTRICT_ALLOC; return diffusion_matrix; }
void TestCellwiseSourcePdeMethods() throw(Exception) { EXIT_IF_PARALLEL; // Set up cell population HoneycombMeshGenerator generator(5, 5, 0); MutableMesh<2,2>* p_mesh = generator.GetMesh(); std::vector<CellPtr> cells; CellsGenerator<FixedDurationGenerationBasedCellCycleModel, 2> cells_generator; cells_generator.GenerateBasic(cells, p_mesh->GetNumNodes()); MeshBasedCellPopulation<2> cell_population(*p_mesh, cells); // Create a PDE object CellwiseSourcePde<2> pde(cell_population, 0.05); // Test that the member variables have been initialised correctly TS_ASSERT_EQUALS(&(pde.rGetCellPopulation()), &cell_population); TS_ASSERT_DELTA(pde.GetCoefficient(), 0.05, 1e-6); // Test methods Node<2>* p_node = cell_population.GetNodeCorrespondingToCell(*(cell_population.Begin())); TS_ASSERT_DELTA(pde.ComputeLinearInUCoeffInSourceTermAtNode(*p_node), 0.05, 1e-6); ChastePoint<2> point; c_matrix<double,2,2> diffusion_matrix = pde.ComputeDiffusionTerm(point); for (unsigned i=0; i<2; i++) { for (unsigned j=0; j<2; j++) { double value = 0.0; if (i == j) { value = 1.0; } TS_ASSERT_DELTA(diffusion_matrix(i,j), value, 1e-6); } } }
void TestAveragedSourcePdeMethods() throw(Exception) { EXIT_IF_PARALLEL; // Set up cell population HoneycombMeshGenerator generator(5, 5, 0); MutableMesh<2,2>* p_mesh = generator.GetMesh(); std::vector<CellPtr> cells; CellsGenerator<FixedDurationGenerationBasedCellCycleModel, 2> cells_generator; cells_generator.GenerateBasic(cells, p_mesh->GetNumNodes()); MeshBasedCellPopulation<2> cell_population(*p_mesh, cells); // Create a PDE object AveragedSourcePde<2> pde(cell_population, 0.05); // Test that the member variables have been initialised correctly TS_ASSERT_EQUALS(&(pde.rGetCellPopulation()), &cell_population); TS_ASSERT_DELTA(pde.GetCoefficient(), 0.05, 1e-6); // For simplicity we create a very large coarse mesh, so we know that all cells are contained in one element TrianglesMeshReader<2,2> mesh_reader("mesh/test/data/square_2_elements"); TetrahedralMesh<2,2> coarse_mesh; coarse_mesh.ConstructFromMeshReader(mesh_reader); coarse_mesh.Scale(10.0, 10.0); // Test SetupSourceTerms() when no map between cells and coarse mesh elements is supplied pde.SetupSourceTerms(coarse_mesh); TS_ASSERT_EQUALS(pde.mCellDensityOnCoarseElements.size(), 2u); // The first element has area 0.5*10*10 = 50 and there are 5*5 = 25 cells, so the cell density is 25/50 = 0.5 TS_ASSERT_DELTA(pde.mCellDensityOnCoarseElements[0], 0.5, 1e-6); // The first element doesn't contain any cells, so the cell density is zero TS_ASSERT_DELTA(pde.mCellDensityOnCoarseElements[1], 0.0, 1e-6); // Now test SetupSourceTerms() when a map between cells and coarse mesh elements is supplied std::map<CellPtr, unsigned> cell_pde_element_map; for (AbstractCellPopulation<2>::Iterator cell_iter = cell_population.Begin(); cell_iter != cell_population.End(); ++cell_iter) { cell_pde_element_map[*cell_iter] = 0; } pde.SetupSourceTerms(coarse_mesh, &cell_pde_element_map); TS_ASSERT_DELTA(pde.mCellDensityOnCoarseElements[0], 0.5, 1e-6); TS_ASSERT_DELTA(pde.mCellDensityOnCoarseElements[1], 0.0, 1e-6); // Test GetUptakeRateForElement() TS_ASSERT_DELTA(pde.GetUptakeRateForElement(0), 0.5, 1e-6); TS_ASSERT_DELTA(pde.GetUptakeRateForElement(1), 0.0, 1e-6); // Test other methods ChastePoint<2> point; TS_ASSERT_DELTA(pde.ComputeLinearInUCoeffInSourceTerm(point, coarse_mesh.GetElement(0)), 0.05*0.5, 1e-6); TS_ASSERT_DELTA(pde.ComputeConstantInUSourceTerm(point, NULL), 0.0, 1e-6); c_matrix<double,2,2> diffusion_matrix = pde.ComputeDiffusionTerm(point); for (unsigned i=0; i<2; i++) { for (unsigned j=0; j<2; j++) { double value = 0.0; if (i == j) { value = 1.0; } TS_ASSERT_DELTA(diffusion_matrix(i,j), value, 1e-6); } } }