TissueSimulation.hpp

00001 /*
00002 
00003 Copyright (C) University of Oxford, 2005-2009
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 TISSUESIMULATION_HPP_
00029 #define TISSUESIMULATION_HPP_
00030 
00031 #include <climits> // work around boost bug
00032 #include <boost/serialization/access.hpp>
00033 #include <boost/serialization/vector.hpp>
00034 #include <boost/serialization/string.hpp>
00035 
00036 #include <vector>
00037 
00038 #include "AbstractForce.hpp"
00039 #include "AbstractCellKiller.hpp"
00040 #include "AbstractTissue.hpp"
00041 #include "RandomNumberGenerator.hpp"
00042 #include "ChastePoint.hpp"
00043 
00044 
00083 template<unsigned DIM>
00084 class TissueSimulation
00085 {
00086     // Allow tests to access private members, in order to test computation of
00087     // private functions eg. DoCellBirth
00088     friend class TestCryptSimulation2d;
00089     friend class TestTissueSimulation3d;
00090 
00091 protected:
00092 
00094     double mDt;
00095 
00097     double mEndTime;
00098 
00100     AbstractTissue<DIM>& mrTissue;
00101     
00103     bool mDeleteTissue;
00104 
00106     bool mAllocatedMemoryForForceCollection;
00107     
00109     bool mInitialiseCells;
00110 
00112     bool mNoBirth;
00113 
00115     bool mUpdateTissue;
00116 
00118     bool mOutputCellMutationStates;
00119 
00121     bool mOutputCellAncestors;
00122 
00124     bool mOutputCellTypes;
00125 
00127     bool mOutputCellVariables;
00128 
00130     bool mOutputCellCyclePhases;
00131 
00133     std::string mOutputDirectory;
00134 
00136     std::string mSimulationOutputDirectory;
00137 
00139     out_stream mpSetupFile;
00140 
00142     CancerParameters *mpParams;
00143 
00145     RandomNumberGenerator *mpRandomGenerator;
00146 
00148     unsigned mNumBirths;
00149 
00151     unsigned mNumDeaths;
00152 
00157     unsigned mSamplingTimestepMultiple;
00158 
00160     std::vector<AbstractCellKiller<DIM>*> mCellKillers;
00161 
00163     std::vector<AbstractForce<DIM>*> mForceCollection;
00164 
00166     friend class boost::serialization::access;
00178     template<class Archive>
00179     void serialize(Archive & archive, const unsigned int version)
00180     {
00181         mpParams = CancerParameters::Instance();
00182         archive & *mpParams;
00183         archive & mpParams;
00184 
00185         mpRandomGenerator = RandomNumberGenerator::Instance();
00186         archive & *mpRandomGenerator;
00187         archive & mpRandomGenerator;
00188 
00189         // If Archive is an output archive, then & resolves to <<
00190         // If Archive is an input archive, then & resolves to >>
00191         archive & mDt;
00192         archive & mEndTime;
00193         archive & mNoBirth;
00194         archive & mUpdateTissue;
00195         archive & mOutputDirectory;
00196         archive & mNumBirths;
00197         archive & mNumDeaths;
00198         archive & mCellKillers;
00199         archive & mOutputCellMutationStates;
00200         archive & mOutputCellAncestors;
00201         archive & mOutputCellTypes;
00202         archive & mOutputCellVariables;
00203         archive & mOutputCellCyclePhases;
00204         archive & mSamplingTimestepMultiple;
00205         archive & mForceCollection;
00206     }
00207 
00211     virtual void WriteVisualizerSetupFile()
00212     {
00213     }
00214 
00222     unsigned DoCellBirth();
00223 
00235     virtual c_vector<double, DIM> CalculateDividingCellCentreLocations(TissueCell* pParentCell);
00236 
00245     unsigned DoCellRemoval();
00246 
00254     virtual void UpdateNodePositions(const std::vector< c_vector<double, DIM> >& rNodeForces);
00255 
00261     virtual void ApplyTissueBoundaryConditions(const std::vector< c_vector<double, DIM> >& rOldLocations)
00262     {
00263     }
00264 
00268     virtual void PostSolve()
00269     {
00270     }
00271 
00275     virtual void SetupSolve()
00276     {
00277     }
00278 
00285     virtual void AfterSolve();
00286     
00292     virtual bool StoppingEventHasOccurred();
00293 
00294 public:
00295 
00304     TissueSimulation(AbstractTissue<DIM>& rTissue,
00305                      std::vector<AbstractForce<DIM>*> forceCollection,
00306                      bool deleteTissueAndForceCollection=false,
00307                      bool initialiseCells=true);
00308 
00314     virtual ~TissueSimulation();
00315 
00322     std::vector<double> GetNodeLocation(const unsigned& rNodeIndex);
00323     
00334     c_vector<unsigned, NUM_CELL_MUTATION_STATES> GetCellMutationStateCount();
00335     
00345     c_vector<unsigned, NUM_CELL_TYPES> GetCellTypeCount();
00346     
00357     c_vector<unsigned, 5> GetCellCyclePhaseCount();
00358 
00362     double GetDt();
00363     
00367     unsigned GetNumBirths();
00368     
00372     unsigned GetNumDeaths();
00373     
00377     std::string GetOutputDirectory();
00378 
00384     void SetDt(double dt);
00385     
00391     void SetEndTime(double endTime);
00392     
00398     void SetOutputDirectory(std::string outputDirectory);
00399 
00406     void SetSamplingTimestepMultiple(unsigned samplingTimestepMultiple);
00407     
00413     void SetNoBirth(bool noBirth);
00414 
00420     void SetOutputCellMutationStates(bool outputCellMutationStates);
00421     
00427     void SetOutputCellAncestors(bool outputCellAncestors);
00428     
00434     void SetOutputCellTypes(bool outputCellTypes);
00435     
00441     void SetOutputCellVariables(bool outputCellVariables);
00442     
00450     void SetOutputCellCyclePhases(bool outputCellCyclePhases);
00451     
00457     void SetUpdateTissueRule(bool updateTissue);
00458 
00464     void AddCellKiller(AbstractCellKiller<DIM>* pCellKiller);
00465 
00476     void Solve();
00477 
00481     AbstractTissue<DIM>& rGetTissue();
00482 
00486     const AbstractTissue<DIM>& rGetTissue() const;
00487 
00491     const std::vector<AbstractForce<DIM>*> rGetForceCollection() const;
00492     
00493 };
00494 
00495 
00496 namespace boost
00497 {
00498 namespace serialization
00499 {
00504 template<class Archive, unsigned DIM>
00505 inline void save_construct_data(
00506     Archive & ar, const TissueSimulation<DIM> * t, const BOOST_PFTO unsigned int file_version)
00507 {
00508     // Save data required to construct instance
00509     const AbstractTissue<DIM> * p_tissue = &(t->rGetTissue());
00510     ar & p_tissue;
00511     const std::vector<AbstractForce<DIM>*> force_collection = t->rGetForceCollection();
00512     ar & force_collection;
00513 }
00514 
00518 template<class Archive, unsigned DIM>
00519 inline void load_construct_data(
00520     Archive & ar, TissueSimulation<DIM> * t, const unsigned int file_version)
00521 {
00522     // Retrieve data from archive required to construct new instance
00523     AbstractTissue<DIM>* p_tissue;
00524     ar >> p_tissue;
00525     std::vector<AbstractForce<DIM>*> force_collection;
00526     ar >> force_collection;
00527 
00528     // Invoke inplace constructor to initialise instance
00529     ::new(t)TissueSimulation<DIM>(*p_tissue, force_collection, true);
00530 }
00531 }
00532 } // namespace
00533 
00534 
00535 #endif /*TISSUESIMULATION_HPP_*/

Generated on Wed Mar 18 12:51:50 2009 for Chaste by  doxygen 1.5.5