Chaste  Release::3.4
PdeAndBoundaryConditions.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 PDEANDBOUNDARYCONDITIONS_HPP_
37 #define PDEANDBOUNDARYCONDITIONS_HPP_
38 
39 #include "ChasteSerialization.hpp"
40 #include "AbstractBoundaryCondition.hpp"
41 #include "ArchiveLocationInfo.hpp"
42 #include "AbstractLinearEllipticPde.hpp"
43 #include "AveragedSourcePde.hpp"
44 #include "PetscTools.hpp"
45 #include "FileFinder.hpp"
46 
58 template<unsigned DIM>
60 {
61  friend class TestPdeAndBoundaryConditions;
62 
63 private:
64 
73  template<class Archive>
74  void serialize(Archive & archive, const unsigned int version)
75  {
76  // Note that archiving of mSolution is handled by the methods save/load_construct_data
77  archive & mpPde;
78  archive & mpBoundaryCondition;
80  archive & mDependentVariableName;
81  }
82 
85 
88 
91 
94 
97 
102 
103 
104 public:
105 
118  AbstractBoundaryCondition<DIM>* pBoundaryCondition=NULL,
119  bool isNeumannBoundaryCondition=true,
120  Vec solution=NULL,
121  bool deleteMemberPointersInDestructor=false);
122 
127 
132 
137 
141  Vec GetSolution();
142 
146  Vec GetSolution() const;
147 
153  void SetSolution(Vec solution);
154 
159 
163  bool HasAveragedSourcePde();
164 
168  void DestroySolution();
169 
177  void SetUpSourceTermsForAveragedSourcePde(TetrahedralMesh<DIM,DIM>* pMesh, std::map< CellPtr, unsigned >* pCellPdeElementMap=NULL);
178 
184  void SetDependentVariableName(const std::string& rName);
185 
191  std::string& rGetDependentVariableName();
192 };
193 
195 // Declare identifier for the serializer
197 
198 namespace boost
199 {
200 namespace serialization
201 {
202 template<class Archive, unsigned DIM>
203 inline void save_construct_data(
204  Archive & ar, const PdeAndBoundaryConditions<DIM> * t, const unsigned int file_version)
205 {
206  if (t->GetSolution())
207  {
208  std::string archive_filename = ArchiveLocationInfo::GetArchiveDirectory() + "solution.vec";
209  PetscTools::DumpPetscObject(t->GetSolution(), archive_filename);
210  }
211 }
212 
213 template<class Archive, unsigned DIM>
214 inline void load_construct_data(
215  Archive & ar, PdeAndBoundaryConditions<DIM> * t, const unsigned int file_version)
216 {
217  Vec solution = NULL;
218 
219  std::string archive_filename = ArchiveLocationInfo::GetArchiveDirectory() + "solution.vec";
220  FileFinder file_finder(archive_filename, RelativeTo::Absolute);
221 
222  if (file_finder.Exists())
223  {
224  PetscTools::ReadPetscObject(solution, archive_filename);
225  }
226 
227  ::new(t)PdeAndBoundaryConditions<DIM>(NULL, NULL, false, solution, true);
228 }
229 }
230 } // namespace ...
231 
232 #endif /* PDEANDBOUNDARYCONDITIONS_HPP_ */
AbstractLinearEllipticPde< DIM, DIM > * mpPde
void SetDependentVariableName(const std::string &rName)
static void ReadPetscObject(Mat &rMat, const std::string &rOutputFileFullPath, Vec rParallelLayout=NULL)
Definition: PetscTools.cpp:361
static void DumpPetscObject(const Mat &rMat, const std::string &rOutputFileFullPath)
Definition: PetscTools.cpp:333
void serialize(Archive &archive, const unsigned int version)
#define EXPORT_TEMPLATE_CLASS_SAME_DIMS(CLASS)
friend class boost::serialization::access
PdeAndBoundaryConditions(AbstractLinearEllipticPde< DIM, DIM > *pPde=NULL, AbstractBoundaryCondition< DIM > *pBoundaryCondition=NULL, bool isNeumannBoundaryCondition=true, Vec solution=NULL, bool deleteMemberPointersInDestructor=false)
AbstractBoundaryCondition< DIM > * GetBoundaryCondition() const
AbstractLinearEllipticPde< DIM, DIM > * GetPde()
AbstractBoundaryCondition< DIM > * mpBoundaryCondition
static std::string GetArchiveDirectory()
void SetUpSourceTermsForAveragedSourcePde(TetrahedralMesh< DIM, DIM > *pMesh, std::map< CellPtr, unsigned > *pCellPdeElementMap=NULL)