VolumeTrackedOffLatticeSimulation.cpp

00001 /*
00002 
00003 Copyright (C) University of Oxford, 2005-2011
00004 
00005 University of Oxford means the Chancellor, Masters and Scholars of the
00006 University of Oxford, having an administrative office at Wellington
00007 Square, Oxford OX1 2JD, UK.
00008 
00009 This file is part of Chaste.
00010 
00011 Chaste is free software: you can redistribute it and/or modify it
00012 under the terms of the GNU Lesser General Public License as published
00013 by the Free Software Foundation, either version 2.1 of the License, or
00014 (at your option) any later version.
00015 
00016 Chaste is distributed in the hope that it will be useful, but WITHOUT
00017 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
00018 FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Lesser General Public
00019 License for more details. The offer of Chaste under the terms of the
00020 License is subject to the License being interpreted in accordance with
00021 English Law and subject to any action against the University of Oxford
00022 being under the jurisdiction of the English Courts.
00023 
00024 You should have received a copy of the GNU Lesser General Public License
00025 along with Chaste. If not, see <http://www.gnu.org/licenses/>.
00026 
00027 */
00028 
00029 #include "VolumeTrackedOffLatticeSimulation.hpp"
00030 #include "MeshBasedCellPopulation.hpp"
00031 #include "VertexBasedCellPopulation.hpp"
00032 #include "CellwiseData.hpp"
00033 
00034 template<unsigned DIM>
00035 VolumeTrackedOffLatticeSimulation<DIM>::VolumeTrackedOffLatticeSimulation(AbstractCellPopulation<DIM>& rCellPopulation,
00036                                                       bool deleteCellPopulationInDestructor,
00037                                                       bool initialiseCells)
00038     : OffLatticeSimulation<DIM>(rCellPopulation, deleteCellPopulationInDestructor, initialiseCells)
00039 {
00040     if (!dynamic_cast<MeshBasedCellPopulation<DIM>*>(&rCellPopulation) && !dynamic_cast<VertexBasedCellPopulation<DIM>*>(&rCellPopulation) )
00041     {
00042         EXCEPTION("VolumeTrackedOffLatticeSimulation require a subclass of MeshBasedCellPopulation or VertexBasedSimulation.");
00043     }
00044 }
00045 
00046 template<unsigned DIM>
00047 VolumeTrackedOffLatticeSimulation<DIM>::~VolumeTrackedOffLatticeSimulation()
00048 {
00049 }
00050 
00051 template<unsigned DIM>
00052 void VolumeTrackedOffLatticeSimulation<DIM>::PostSolve()
00053 {
00054     // Make sure the cell population is updated
00055     this->mrCellPopulation.Update();
00056     CellwiseData<DIM>::Instance()->ReallocateMemory();
00057 
00058     if (dynamic_cast<MeshBasedCellPopulation<DIM>*>(&(this->mrCellPopulation)))
00059     {
00060         // Static cast on the cell population
00061         MeshBasedCellPopulation<DIM>* p_static_cast_cell_population = static_cast<MeshBasedCellPopulation<DIM>*>(&(this->mrCellPopulation));
00062 
00063         // Create Voronoi tessellation for volumes
00064         p_static_cast_cell_population->CreateVoronoiTessellation();
00065 
00066         // Loop over cells and set volume value in CellWiseData
00067         for (typename AbstractCellPopulation<DIM>::Iterator cell_iter = this->mrCellPopulation.Begin();
00068              cell_iter != this->mrCellPopulation.End();
00069              ++cell_iter)
00070         {
00071             // Get the index of the node corresponding to this cell
00072             unsigned node_index = this->mrCellPopulation.GetLocationIndexUsingCell(*cell_iter);
00073 
00074             // Store in CellwiseData
00075             CellwiseData<DIM>::Instance()->SetValue(p_static_cast_cell_population->GetVolumeOfVoronoiElement(node_index), node_index, 0);
00076         }
00077     }
00078     else if (dynamic_cast<VertexBasedCellPopulation<DIM>*>(&(this->mrCellPopulation)))
00079     {
00080         // Static cast on the cell population
00081         VertexBasedCellPopulation<DIM>* p_static_cast_cell_population = static_cast<VertexBasedCellPopulation<DIM>*>(&(this->mrCellPopulation));
00082 
00083         for (typename AbstractCellPopulation<DIM>::Iterator cell_iter = this->mrCellPopulation.Begin();
00084              cell_iter != this->mrCellPopulation.End();
00085              ++cell_iter)
00086         {
00087 
00088             // Get the index of vertex element corresponding to this cell
00089             unsigned element_index = this->mrCellPopulation.GetLocationIndexUsingCell(*cell_iter);
00090 
00091             // Store in CellwiseData
00092             CellwiseData<DIM>::Instance()->SetValue(p_static_cast_cell_population->rGetMesh().GetVolumeOfElement(element_index), element_index, 0);
00093         }
00094     }
00095 }
00096 
00098 // Explicit instantiation
00100 
00101 template class VolumeTrackedOffLatticeSimulation<1>;
00102 template class VolumeTrackedOffLatticeSimulation<2>;
00103 template class VolumeTrackedOffLatticeSimulation<3>;
00104 
00105 // Serialization for Boost >= 1.36
00106 #include "SerializationExportWrapperForCpp.hpp"
00107 EXPORT_TEMPLATE_CLASS_SAME_DIMS(VolumeTrackedOffLatticeSimulation)
Generated on Thu Dec 22 13:00:05 2011 for Chaste by  doxygen 1.6.3