CellBasedSimulationWithPdes.hpp

00001 /*
00002 
00003 Copyright (C) University of Oxford, 2005-2010
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 #ifndef CellBasedSimulationWITHPDES_HPP_
00029 #define CellBasedSimulationWITHPDES_HPP_
00030 
00031 #include <map>
00032 #include "ChasteSerialization.hpp"
00033 
00034 #include "CellBasedSimulation.hpp"
00035 
00036 #include "PdeAndBoundaryConditions.hpp"
00037 #include "TetrahedralMesh.hpp"
00038 #include "PetscTools.hpp"
00039 
00040 #include "OutputFileHandler.hpp"
00041 #include "Cell.hpp"
00042 
00047 template<unsigned DIM>
00048 class CellBasedSimulationWithPdes : public CellBasedSimulation<DIM>
00049 {
00050     // Allow tests to access private members, in order to test computation of private functions
00051     friend class TestCellBasedSimulationWithPdes;
00052 
00053 private:
00054 
00055     friend class boost::serialization::access;
00056     template<class Archive>
00057     void serialize(Archive & archive, const unsigned int version)
00058     {
00059         // If Archive is an output archive, then & resolves to <<
00060         // If Archive is an input archive, then & resolves to >>
00061         archive & boost::serialization::base_object<CellBasedSimulation<DIM> >(*this);
00062         archive & mWriteAverageRadialPdeSolution;
00063         archive & mWriteDailyAverageRadialPdeSolution;
00064         archive & mNumRadialIntervals;
00065         archive & mCellPdeElementMap;
00066     }
00067 
00072     std::vector<PdeAndBoundaryConditions<DIM>*> mPdeAndBcCollection;
00073 
00077     out_stream mpVizPdeSolutionResultsFile;
00078 
00082     out_stream mpAverageRadialPdeSolutionResultsFile;
00083 
00087     bool mWriteAverageRadialPdeSolution;
00088 
00092     bool mWriteDailyAverageRadialPdeSolution;
00093 
00098     unsigned mNumRadialIntervals;
00099 
00103     TetrahedralMesh<DIM,DIM>* mpCoarsePdeMesh;
00104 
00108     std::map<CellPtr, unsigned> mCellPdeElementMap;
00109 
00113     void SetupSolve();
00114 
00118     void SetupWritePdeSolution();
00119 
00125     void WritePdeSolution(double time);
00126 
00133     void WriteAverageRadialPdeSolution(double time, unsigned numIntervals);
00134 
00138     void SolvePde();
00139 
00143     void SolvePdeUsingCoarseMesh();
00144 
00152     unsigned FindCoarseElementContainingCell(CellPtr pCell);
00153 
00157     void PostSolve();
00158 
00162     void AfterSolve();
00163 
00171     void CreateCoarsePdeMesh(double coarseGrainScaleFactor);
00172 
00176     void InitialiseCoarsePdeMesh();
00177 
00183     void WriteVisualizerSetupFile();
00184 
00185 public:
00186 
00195      CellBasedSimulationWithPdes(AbstractCellPopulation<DIM>& rCellPopulation,
00196                               std::vector<PdeAndBoundaryConditions<DIM>*> pdeAndBcCollection=std::vector<PdeAndBoundaryConditions<DIM>*>(),
00197                               bool deleteCellPopulationAndForceCollection=false,
00198                               bool initialiseCells=true);
00199 
00206     ~CellBasedSimulationWithPdes();
00207 
00217     void SetPdeAndBcCollection(std::vector<PdeAndBoundaryConditions<DIM>*> pdeAndBcCollection);
00218 
00224     Vec GetCurrentPdeSolution(unsigned pdeIndex);
00225 
00235     void SetWriteAverageRadialPdeSolution(unsigned numRadialIntervals=10,
00236                                           bool writeDailyResults=false);
00237 
00244     void UseCoarsePdeMesh(double coarseGrainScaleFactor=10.0);
00245 
00254     void OutputSimulationParameters(out_stream& rParamsFile);
00255 };
00256 
00257 
00258 #include "SerializationExportWrapper.hpp"
00259 EXPORT_TEMPLATE_CLASS_SAME_DIMS(CellBasedSimulationWithPdes)
00260 
00261 namespace boost
00262 {
00263 namespace serialization
00264 {
00268 template<class Archive, unsigned DIM>
00269 inline void save_construct_data(
00270     Archive & ar, const CellBasedSimulationWithPdes<DIM> * t, const BOOST_PFTO unsigned int file_version)
00271 {
00272     // Save data required to construct instance
00273     const AbstractCellPopulation<DIM> * p_cell_population = &(t->rGetCellPopulation());
00274     ar & p_cell_population;
00275 }
00276 
00280 template<class Archive, unsigned DIM>
00281 inline void load_construct_data(
00282     Archive & ar, CellBasedSimulationWithPdes<DIM> * t, const unsigned int file_version)
00283 {
00284     // Retrieve data from archive required to construct new instance
00285     AbstractCellPopulation<DIM>* p_cell_population;
00286     ar >> p_cell_population;
00287 
00288     // Invoke inplace constructor to initialise instance
00289     ::new(t)CellBasedSimulationWithPdes<DIM>(*p_cell_population, std::vector<PdeAndBoundaryConditions<DIM>*>(), true, false);
00290 }
00291 }
00292 } // namespace ...
00293 
00294 
00295 #endif /*CellBasedSimulationWITHPDES_HPP_*/

Generated on Mon Nov 1 12:35:16 2010 for Chaste by  doxygen 1.5.5