Chaste  Release::3.4
CellBasedPdeHandler.hpp
1 /*
2 
3 Copyright (c) 2005-2016, University of Oxford.
4 All rights reserved.
5 
6 University of Oxford means the Chancellor, Masters and Scholars of the
7 University of Oxford, having an administrative office at Wellington
8 Square, Oxford OX1 2JD, UK.
9 
10 This file is part of Chaste.
11 
12 Redistribution and use in source and binary forms, with or without
13 modification, are permitted provided that the following conditions are met:
14  * Redistributions of source code must retain the above copyright notice,
15  this list of conditions and the following disclaimer.
16  * Redistributions in binary form must reproduce the above copyright notice,
17  this list of conditions and the following disclaimer in the documentation
18  and/or other materials provided with the distribution.
19  * Neither the name of the University of Oxford nor the names of its
20  contributors may be used to endorse or promote products derived from this
21  software without specific prior written permission.
22 
23 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
24 AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
25 IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
26 ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
27 LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
28 CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
29 GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
30 HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
31 LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
32 OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
33 
34 */
35 
36 #ifndef CELLBASEDPDEHANDLER_HPP_
37 #define CELLBASEDPDEHANDLER_HPP_
38 
39 #include <map>
40 #include <memory>
41 
42 #include "ChasteSerialization.hpp"
43 #include <boost/serialization/vector.hpp>
44 
45 #include "AbstractCellPopulation.hpp"
46 #include "PdeAndBoundaryConditions.hpp"
47 #include "BoundaryConditionsContainer.hpp"
48 #include "TetrahedralMesh.hpp"
49 #include "ChasteCuboid.hpp"
50 
59 template<unsigned DIM>
61 {
62  // Allow tests to access private members, in order to test computation of private functions
63  friend class TestCellBasedPdeHandler;
64  friend class TestOffLatticeSimulationWithPdes;
65  friend class TestOnLatticeSimulationWithPdes;
66 
67 private:
68 
70  friend class boost::serialization::access;
77  template<class Archive>
78  void serialize(Archive & archive, const unsigned int version)
79  {
80  archive & mPdeAndBcCollection;
83  archive & mSetBcsOnCoarseBoundary;
84  archive & mNumRadialIntervals;
86  }
87 
88 protected:
89 
92 
94  std::vector<PdeAndBoundaryConditions<DIM>*> mPdeAndBcCollection;
95 
97  std::string mDirPath;
98 
101 
104 
107 
110 
113 
116 
119 
122 
124  std::map<CellPtr, unsigned> mCellPdeElementMap;
125 
131 
139 
152  virtual void WritePdeSolution(double time);
153 
162  void WriteAverageRadialPdeSolution(double time);
163 
169 
170 public:
171 
178  CellBasedPdeHandler(AbstractCellPopulation<DIM>* pCellPopulation, bool deleteMemberPointersInDestructor=false);
179 
183  virtual ~CellBasedPdeHandler();
184 
191 
196 
203  void OpenResultsFiles(std::string outputDirectory);
204 
209  void CloseResultsFiles();
210 
215 
220 
228 
233 
237  unsigned GetNumRadialIntervals();
238 
245  virtual void SolvePdeAndWriteResultsToFile(unsigned samplingTimestepMultiple);
246 
255  virtual std::auto_ptr<BoundaryConditionsContainer<DIM,DIM,1> > ConstructBoundaryConditionsContainer(
257  TetrahedralMesh<DIM,DIM>* pMesh);
258 
267  double GetPdeSolutionAtPoint(const c_vector<double,DIM>& rPoint, const std::string& rVariable);
268 
276  unsigned FindCoarseElementContainingCell(CellPtr pCell);
277 
284  virtual Vec GetPdeSolution(const std::string& rName = "");
285 
296  void SetWriteAverageRadialPdeSolution(const std::string& rName,
297  unsigned numRadialIntervals=10,
298  bool writeDailyResults=false);
299 
307  void SetImposeBcsOnCoarseBoundary(bool setBcsOnCoarseBoundary);
308 
316  virtual void UseCoarsePdeMesh(double stepSize, ChasteCuboid<DIM> meshCuboid, bool centreOnCellPopulation = false);
317 
324 
330  virtual void OutputParameters(out_stream& rParamsFile);
331 };
332 
335 
336 namespace boost
337 {
338 namespace serialization
339 {
344 template<class Archive, unsigned DIM>
345 inline void save_construct_data(
346  Archive & ar, const CellBasedPdeHandler<DIM> * t, const unsigned int file_version)
347 {
348  // Save data required to construct instance
349  const AbstractCellPopulation<DIM>* p_cell_population = t->GetCellPopulation();
350  ar & p_cell_population;
351 }
352 
356 template<class Archive, unsigned DIM>
357 inline void load_construct_data(
358  Archive & ar, CellBasedPdeHandler<DIM> * t, const unsigned int file_version)
359 {
360  // Retrieve data from archive required to construct new instance
361  AbstractCellPopulation<DIM>* p_cell_population;
362  ar >> p_cell_population;
363 
364  // Invoke inplace constructor to initialise instance
365  ::new(t)CellBasedPdeHandler<DIM>(p_cell_population, true);
366 }
367 }
368 }
369 
370 #endif /*CELLBASEDPDEHANDLER_HPP_*/
double GetPdeSolutionAtPoint(const c_vector< double, DIM > &rPoint, const std::string &rVariable)
std::map< CellPtr, unsigned > mCellPdeElementMap
std::string mAverageRadialSolutionVariableName
void AddPdeAndBc(PdeAndBoundaryConditions< DIM > *pPdeAndBc)
CellBasedPdeHandler(AbstractCellPopulation< DIM > *pCellPopulation, bool deleteMemberPointersInDestructor=false)
std::vector< PdeAndBoundaryConditions< DIM > * > mPdeAndBcCollection
void serialize(Archive &archive, const unsigned int version)
TetrahedralMesh< DIM, DIM > * mpCoarsePdeMesh
unsigned FindCoarseElementContainingCell(CellPtr pCell)
virtual void UseCoarsePdeMesh(double stepSize, ChasteCuboid< DIM > meshCuboid, bool centreOnCellPopulation=false)
void SetImposeBcsOnCoarseBoundary(bool setBcsOnCoarseBoundary)
out_stream mpVizPdeSolutionResultsFile
#define EXPORT_TEMPLATE_CLASS_SAME_DIMS(CLASS)
virtual void SolvePdeAndWriteResultsToFile(unsigned samplingTimestepMultiple)
void WriteAverageRadialPdeSolution(double time)
out_stream mpAverageRadialPdeSolutionResultsFile
void OpenResultsFiles(std::string outputDirectory)
TetrahedralMesh< DIM, DIM > * GetCoarsePdeMesh()
AbstractCellPopulation< DIM > * mpCellPopulation
virtual void OutputParameters(out_stream &rParamsFile)
virtual std::auto_ptr< BoundaryConditionsContainer< DIM, DIM, 1 > > ConstructBoundaryConditionsContainer(PdeAndBoundaryConditions< DIM > *pPdeAndBc, TetrahedralMesh< DIM, DIM > *pMesh)
void SetWriteAverageRadialPdeSolution(const std::string &rName, unsigned numRadialIntervals=10, bool writeDailyResults=false)
virtual void WritePdeSolution(double time)
const AbstractCellPopulation< DIM > * GetCellPopulation() const
virtual Vec GetPdeSolution(const std::string &rName="")