PdeAndBoundaryConditions.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 PDEANDBOUNDARYCONDITIONS_HPP_
00030 #define PDEANDBOUNDARYCONDITIONS_HPP_
00031 
00032 #include "ChasteSerialization.hpp"
00033 #include "AbstractBoundaryCondition.hpp"
00034 #include "ArchiveLocationInfo.hpp"
00035 #include "AbstractLinearEllipticPde.hpp"
00036 #include "AveragedSourcePde.hpp"
00037 #include "PetscTools.hpp"
00038 #include "FileFinder.hpp"
00039 
00051 template<unsigned DIM>
00052 class PdeAndBoundaryConditions
00053 {
00054     friend class TestPdeAndBoundaryConditions;
00055 
00056 private:
00057 
00059     friend class boost::serialization::access;
00066     template<class Archive>
00067     void serialize(Archive & archive, const unsigned int version)
00068     {
00069         // Note that archiving of mSolution is handled by the methods save/load_construct_data
00070         archive & mpPde;
00071         archive & mpBoundaryCondition;
00072         archive & mIsNeumannBoundaryCondition;
00073     }
00074 
00076     AbstractLinearEllipticPde<DIM,DIM>* mpPde;
00077 
00079     AbstractBoundaryCondition<DIM>* mpBoundaryCondition;
00080 
00082     bool mIsNeumannBoundaryCondition;
00083 
00085     Vec mSolution;
00086 
00088     bool mDeleteMemberPointersInDestructor;
00089 
00090 public:
00091 
00103     PdeAndBoundaryConditions(AbstractLinearEllipticPde<DIM,DIM>* pPde=NULL,
00104                              AbstractBoundaryCondition<DIM>* pBoundaryCondition=NULL,
00105                              bool isNeumannBoundaryCondition=true,
00106                              Vec solution=NULL,
00107                              bool deleteMemberPointersInDestructor=false);
00108 
00112     ~PdeAndBoundaryConditions();
00113 
00117     AbstractLinearEllipticPde<DIM,DIM>* GetPde();
00118 
00122     AbstractBoundaryCondition<DIM>* GetBoundaryCondition() const;
00123 
00127     Vec GetSolution();
00128 
00132     Vec GetSolution() const;
00133 
00139     void SetSolution(Vec solution);
00140 
00144     bool IsNeumannBoundaryCondition();
00145 
00149     bool HasAveragedSourcePde();
00150 
00154     void DestroySolution();
00155 
00163     void SetUpSourceTermsForAveragedSourcePde(TetrahedralMesh<DIM,DIM>* pMesh, std::map< CellPtr, unsigned >* pCellPdeElementMap=NULL);
00164 };
00165 
00166 #include "SerializationExportWrapper.hpp"
00167 // Declare identifier for the serializer
00168 EXPORT_TEMPLATE_CLASS_SAME_DIMS(PdeAndBoundaryConditions)
00169 
00170 namespace boost
00171 {
00172 namespace serialization
00173 {
00174 template<class Archive, unsigned DIM>
00175 inline void save_construct_data(
00176     Archive & ar, const PdeAndBoundaryConditions<DIM> * t, const unsigned int file_version)
00177 {
00178     if (t->GetSolution())
00179     {
00180         std::string archive_filename = ArchiveLocationInfo::GetArchiveDirectory() + "solution.vec";
00181         PetscTools::DumpPetscObject(t->GetSolution(), archive_filename);
00182     }
00183 }
00184 
00185 template<class Archive, unsigned DIM>
00186 inline void load_construct_data(
00187     Archive & ar, PdeAndBoundaryConditions<DIM> * t, const unsigned int file_version)
00188 {
00189     Vec solution = NULL;
00190 
00191     std::string archive_filename = ArchiveLocationInfo::GetArchiveDirectory() + "solution.vec";
00192     FileFinder file_finder(archive_filename, RelativeTo::Absolute);
00193 
00194     if (file_finder.Exists())
00195     {
00196         PetscTools::ReadPetscObject(solution, archive_filename);
00197     }
00198 
00199     ::new(t)PdeAndBoundaryConditions<DIM>(NULL, NULL, false, solution, true);
00200 }
00201 }
00202 } // namespace ...
00203 
00204 #endif /* PDEANDBOUNDARYCONDITIONS_HPP_ */
Generated on Thu Dec 22 13:00:05 2011 for Chaste by  doxygen 1.6.3