void TestSolveCellSystemsInclUpdateVoltage() throw(Exception) { HeartConfig::Instance()->Reset(); TetrahedralMesh<1,1> mesh; mesh.ConstructRegularSlabMesh(1.0, 1.0); // [0,1] with h=1.0, ie 2 node mesh MyCardiacCellFactory cell_factory; cell_factory.SetMesh(&mesh); MonodomainTissue<1> monodomain_tissue( &cell_factory ); Vec voltage = PetscTools::CreateAndSetVec(2, -81.4354); // something that isn't resting potential monodomain_tissue.SolveCellSystems(voltage, 0, 1, false); // solve for 1ms without updating the voltage if (mesh.GetDistributedVectorFactory()->IsGlobalIndexLocal(0)) { TS_ASSERT_DELTA(monodomain_tissue.GetCardiacCell(0)->GetVoltage(), -81.4354, 1e-3); } if (mesh.GetDistributedVectorFactory()->IsGlobalIndexLocal(1)) { TS_ASSERT_DELTA(monodomain_tissue.GetCardiacCell(1)->GetVoltage(), -81.4354, 1e-3); } Vec voltage2 = PetscTools::CreateAndSetVec(2, -75); monodomain_tissue.SolveCellSystems(voltage2, 1, 2, true); // solve another ms, using this new voltage, but now updating the voltage too ReplicatableVector voltage2_repl(voltage2); // should have changed following solve // check the new voltage in the cell is NEAR -75 (otherwise the passed in voltage wasn't used, but // NOT EXACTLY -75, ie that the voltage was solved for. if (mesh.GetDistributedVectorFactory()->IsGlobalIndexLocal(0)) { // check has been updated TS_ASSERT_DIFFERS(monodomain_tissue.GetCardiacCell(0)->GetVoltage(), -75); // check near -75 TS_ASSERT_DELTA(monodomain_tissue.GetCardiacCell(0)->GetVoltage(), -75, 2.0); // within 2mV // check the passed in voltage was updated TS_ASSERT_DELTA(voltage2_repl[0], monodomain_tissue.GetCardiacCell(0)->GetVoltage(), 1e-10); } if (mesh.GetDistributedVectorFactory()->IsGlobalIndexLocal(1)) { TS_ASSERT_DIFFERS(monodomain_tissue.GetCardiacCell(1)->GetVoltage(), -75); TS_ASSERT_DELTA(monodomain_tissue.GetCardiacCell(1)->GetVoltage(), -75, 2.0); // within 2mV TS_ASSERT_DELTA(voltage2_repl[1], monodomain_tissue.GetCardiacCell(1)->GetVoltage(), 1e-10); } PetscTools::Destroy(voltage); PetscTools::Destroy(voltage2); }
void TestMonodomainTissueGetCardiacCell() throw(Exception) { HeartConfig::Instance()->Reset(); TetrahedralMesh<1,1> mesh; mesh.ConstructRegularSlabMesh(1.0, 1.0); // [0,1] with h=1.0, ie 2 node mesh MyCardiacCellFactory cell_factory; cell_factory.SetMesh(&mesh); MonodomainTissue<1> monodomain_tissue( &cell_factory ); if (mesh.GetDistributedVectorFactory()->IsGlobalIndexLocal(0)) { AbstractCardiacCellInterface* cell = monodomain_tissue.GetCardiacCell(0); TS_ASSERT_DELTA(cell->GetStimulus(0.001),-80,1e-10); } if (mesh.GetDistributedVectorFactory()->IsGlobalIndexLocal(1)) { AbstractCardiacCellInterface* cell = monodomain_tissue.GetCardiacCell(1); TS_ASSERT_DELTA(cell->GetStimulus(0.001),0,1e-10); } }
void TestExtendedTissueHeterogeneousGgap3D() throw (Exception) { HeartConfig::Instance()->Reset(); TrianglesMeshReader<3,3> mesh_reader("mesh/test/data/cube_2mm_12_elements"); TetrahedralMesh<3,3> mesh; mesh.ConstructFromMeshReader(mesh_reader); std::vector<boost::shared_ptr<AbstractChasteRegion<3> > > heterogeneity_areas; std::vector<double> Ggap_values; //first cuboid include node 0 ChastePoint<3> cornerA(-1, -1, 0); ChastePoint<3> cornerB(0.001, 0.001, 0.001); boost::shared_ptr<ChasteCuboid<3> > p_cuboid_1(new ChasteCuboid<3>(cornerA, cornerB)); heterogeneity_areas.push_back(p_cuboid_1); //second cuboid include node 6 ChastePoint<3> cornerC(0.199, 0.199, 0.199); ChastePoint<3> cornerD(0.25, 0.25, 0.25); boost::shared_ptr<ChasteCuboid<3> > p_cuboid_2(new ChasteCuboid<3>(cornerC, cornerD)); ChasteCuboid<3> cuboid_2(cornerC, cornerD); heterogeneity_areas.push_back(p_cuboid_2); //within the first area Ggap_values.push_back(143.0); //within the second area Ggap_values.push_back(9143.0); //elsewhere double isotropic_ggap=586.0; StimulatedCellFactory stimulated_cell_factory; UnStimulatedCellFactory unstimulated_cell_factory; ExtracellularStimulusFactory extracellular_stimulus_factory; stimulated_cell_factory.SetMesh(&mesh); unstimulated_cell_factory.SetMesh(&mesh); extracellular_stimulus_factory.SetMesh(&mesh); ExtendedBidomainTissue<3> extended_bidomain_tissue( &stimulated_cell_factory, &unstimulated_cell_factory, &extracellular_stimulus_factory); extended_bidomain_tissue.SetGGap(isotropic_ggap);//this is what the problem class does first extended_bidomain_tissue.SetGgapHeterogeneities(heterogeneity_areas, Ggap_values); extended_bidomain_tissue.CreateGGapConductivities(); unsigned probe_node_1 = 0u; unsigned probe_node_2 = 6u; unsigned probe_node_3 = 5u; const std::vector<unsigned>& r_permutation = mesh.rGetNodePermutation(); if (!r_permutation.empty()) { probe_node_1 = r_permutation[0u];//within first cuboid probe_node_2 = r_permutation[6u];//within second cuboid probe_node_3 = r_permutation[5u];//elsewhere } Vec vector = mesh.GetDistributedVectorFactory()->CreateVec(); DistributedVector dist_solution = mesh.GetDistributedVectorFactory()->CreateDistributedVector(vector); for (DistributedVector::Iterator index = dist_solution.Begin(); index != dist_solution.End(); ++index) { extended_bidomain_tissue.UpdateAdditionalCaches(index.Global, index.Local, 2.0); } extended_bidomain_tissue.ReplicateAdditionalCaches(); //Ggap TS_ASSERT_EQUALS(extended_bidomain_tissue.rGetGgapCacheReplicated()[probe_node_1],143.0);//within first cuboid TS_ASSERT_EQUALS(extended_bidomain_tissue.rGetGgapCacheReplicated()[probe_node_2],9143.0);//within second cuboid TS_ASSERT_EQUALS(extended_bidomain_tissue.rGetGgapCacheReplicated()[probe_node_3],586.0);//elsewhere PetscTools::Destroy(vector); }