CellBasedPdeHandler.hpp

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 #ifndef CELLBASEDPDEHANDLER_HPP_
00030 #define CELLBASEDPDEHANDLER_HPP_
00031 
00032 #include <map>
00033 
00034 #include "ChasteSerialization.hpp"
00035 #include <boost/serialization/vector.hpp>
00036 
00037 #include "AbstractCellPopulation.hpp"
00038 #include "PdeAndBoundaryConditions.hpp"
00039 #include "TetrahedralMesh.hpp"
00040 #include "Identifiable.hpp"
00041 
00050 template<unsigned DIM>
00051 class CellBasedPdeHandler : public Identifiable
00052 {
00053     // Allow tests to access private members, in order to test computation of private functions
00054     friend class TestCellBasedPdeHandler;
00055     friend class TestOffLatticeSimulationWithPdes;
00056 
00057 private:
00058 
00060     friend class boost::serialization::access;
00067     template<class Archive>
00068     void serialize(Archive & archive, const unsigned int version)
00069     {
00070         archive & mPdeAndBcCollection;
00071         archive & mWriteAverageRadialPdeSolution;
00072         archive & mWriteDailyAverageRadialPdeSolution;
00073         archive & mSetBcsOnCoarseBoundary;
00074         archive & mNumRadialIntervals;
00075     }
00076 
00077 protected:
00078 
00080     AbstractCellPopulation<DIM>* mpCellPopulation;
00081 
00083     std::vector<PdeAndBoundaryConditions<DIM>*> mPdeAndBcCollection;
00084 
00086     out_stream mpVizPdeSolutionResultsFile;
00087 
00089     out_stream mpAverageRadialPdeSolutionResultsFile;
00090 
00092     bool mWriteAverageRadialPdeSolution;
00093 
00095     bool mWriteDailyAverageRadialPdeSolution;
00096 
00098     bool mSetBcsOnCoarseBoundary;
00099 
00101     unsigned mNumRadialIntervals;
00102 
00104     TetrahedralMesh<DIM,DIM>* mpCoarsePdeMesh;
00105 
00107     std::map<CellPtr, unsigned> mCellPdeElementMap;
00108 
00113     bool mDeleteMemberPointersInDestructor;
00114 
00121     void InitialiseCellPdeElementMap();
00122 
00128     virtual void WritePdeSolution(double time);
00129 
00135     void WriteAverageRadialPdeSolution(double time);
00136 
00137 public:
00138 
00145     CellBasedPdeHandler(AbstractCellPopulation<DIM>* pCellPopulation, bool deleteMemberPointersInDestructor=false);
00146 
00150     virtual ~CellBasedPdeHandler();
00151 
00157     const AbstractCellPopulation<DIM>* GetCellPopulation() const;
00158 
00162     TetrahedralMesh<DIM,DIM>* GetCoarsePdeMesh();
00163 
00170     void OpenResultsFiles(std::string outputDirectory);
00171 
00176     void CloseResultsFiles();
00177 
00181     bool GetWriteAverageRadialPdeSolution();
00182 
00186     bool GetWriteDailyAverageRadialPdeSolution();
00187 
00194     void UpdateCellPdeElementMap();
00195 
00199     bool GetImposeBcsOnCoarseBoundary();
00200 
00204     unsigned GetNumRadialIntervals();
00205 
00212     virtual void SolvePdeAndWriteResultsToFile(unsigned samplingTimestepMultiple);
00213 
00221     unsigned FindCoarseElementContainingCell(CellPtr pCell);
00222 
00228     virtual Vec GetPdeSolution(unsigned pdeIndex);
00229 
00239     void SetWriteAverageRadialPdeSolution(unsigned numRadialIntervals=10,
00240                                           bool writeDailyResults=false);
00241 
00249     void SetImposeBcsOnCoarseBoundary(bool setBcsOnCoarseBoundary);
00250 
00257     virtual void UseCoarsePdeMesh(double stepSize, double meshWidth);
00258 
00264     void AddPdeAndBc(PdeAndBoundaryConditions<DIM>* pPdeAndBc);
00265 
00271     virtual void OutputParameters(out_stream& rParamsFile);
00272 };
00273 
00274 #include "SerializationExportWrapper.hpp"
00275 EXPORT_TEMPLATE_CLASS_SAME_DIMS(CellBasedPdeHandler)
00276 
00277 namespace boost
00278 {
00279 namespace serialization
00280 {
00285 template<class Archive, unsigned DIM>
00286 inline void save_construct_data(
00287     Archive & ar, const CellBasedPdeHandler<DIM> * t, const BOOST_PFTO unsigned int file_version)
00288 {
00289     // Save data required to construct instance
00290     const AbstractCellPopulation<DIM>* p_cell_population = t->GetCellPopulation();
00291     ar & p_cell_population;
00292 }
00293 
00297 template<class Archive, unsigned DIM>
00298 inline void load_construct_data(
00299     Archive & ar, CellBasedPdeHandler<DIM> * t, const unsigned int file_version)
00300 {
00301     // Retrieve data from archive required to construct new instance
00302     AbstractCellPopulation<DIM>* p_cell_population;
00303     ar >> p_cell_population;
00304 
00305     // Invoke inplace constructor to initialise instance
00306     ::new(t)CellBasedPdeHandler<DIM>(p_cell_population, true);
00307 }
00308 }
00309 }
00310 
00311 #endif /*CELLBASEDPDEHANDLER_HPP_*/
Generated on Thu Dec 22 13:00:05 2011 for Chaste by  doxygen 1.6.3