From: Lukas Korous Date: Sun, 1 Feb 2015 10:59:56 +0000 (+0100) Subject: Add hp::DoFHandler::save and ::load. X-Git-Tag: v8.3.0-rc1~507^2 X-Git-Url: https://gitweb.dealii.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=6753c311764e9cd347a7fe67e4e7453072cfdeb3;p=dealii.git Add hp::DoFHandler::save and ::load. --- diff --git a/include/deal.II/hp/dof_faces.h b/include/deal.II/hp/dof_faces.h index 8181aa3a96..ec542c34d5 100644 --- a/include/deal.II/hp/dof_faces.h +++ b/include/deal.II/hp/dof_faces.h @@ -198,6 +198,14 @@ namespace internal * object. */ std::size_t memory_consumption () const; + + /** + * Read or write the data of this object to or from a stream for the + * purpose of serialization + */ + template + void serialize(Archive &ar, + const unsigned int version); }; @@ -249,6 +257,14 @@ namespace internal * object. */ std::size_t memory_consumption () const; + + /** + * Read or write the data of this object to or from a stream for the + * purpose of serialization + */ + template + void serialize(Archive &ar, + const unsigned int version); }; /** @@ -272,6 +288,14 @@ namespace internal * object. */ std::size_t memory_consumption () const; + + /** + * Read or write the data of this object to or from a stream for the + * purpose of serialization + */ + template + void serialize(Archive &ar, + const unsigned int version); }; /** @@ -300,10 +324,38 @@ namespace internal * object. */ std::size_t memory_consumption () const; + + /** + * Read or write the data of this object to or from a stream for the + * purpose of serialization + */ + template + void serialize(Archive &ar, + const unsigned int version); }; // --------------------- inline and template functions ------------------ + template + void DoFIndicesOnFaces<1>::serialize(Archive &, + const unsigned int) + {} + + + template + void DoFIndicesOnFaces<2>::serialize(Archive &ar, + const unsigned int) + { + ar &lines; + } + + + template + void DoFIndicesOnFaces<3>::serialize(Archive &ar, + const unsigned int) + { + ar &lines &quads; + } template template @@ -593,6 +645,15 @@ namespace internal } } + template + template + void DoFIndicesOnFacesOrEdges::serialize(Archive &ar, + const unsigned int) + { + ar &dofs; + ar &dof_offsets; + } + } // namespace hp diff --git a/include/deal.II/hp/dof_handler.h b/include/deal.II/hp/dof_handler.h index ffd8242255..f14e49e27a 100644 --- a/include/deal.II/hp/dof_handler.h +++ b/include/deal.II/hp/dof_handler.h @@ -607,6 +607,22 @@ namespace hp */ virtual std::size_t memory_consumption () const; + /** + * Write the data of this object to a stream for the purpose of + * serialization. + */ + template + void save(Archive &ar, const unsigned int version) const; + + /** + * Read the data of this object from a stream for the purpose of + * serialization. + */ + template + void load(Archive &ar, const unsigned int version); + + BOOST_SERIALIZATION_SPLIT_MEMBER() + /** * Exception */ @@ -877,6 +893,60 @@ namespace hp /* ----------------------- Inline functions ---------------------------------- */ + template + template + void DoFHandler::save(Archive &ar, unsigned int) const + { + ar &vertex_dofs; + ar &vertex_dofs_offsets; + ar &number_cache; + ar &levels; + ar &faces; + ar &has_children; + + // write out the number of triangulation cells and later check during + // loading that this number is indeed correct; + unsigned int n_cells = tria->n_cells(); + + ar &n_cells; + } + + template + template + void DoFHandler::load(Archive &ar, unsigned int) + { + ar &vertex_dofs; + ar &vertex_dofs_offsets; + ar &number_cache; + + // boost::serialization can restore pointers just fine, but if the + // pointer object still points to something useful, that object is not + // destroyed and we end up with a memory leak. consequently, first delete + // previous content before re-loading stuff + for (unsigned int i = 0; in_cells(), + ExcMessage("The object being loaded into does not match the triangulation " + "that has been stored previously.")); + } + template inline types::global_dof_index diff --git a/include/deal.II/hp/dof_level.h b/include/deal.II/hp/dof_level.h index b89b446ade..da7513a990 100644 --- a/include/deal.II/hp/dof_level.h +++ b/include/deal.II/hp/dof_level.h @@ -242,6 +242,14 @@ namespace internal */ std::size_t memory_consumption () const; + /** + * Read or write the data of this object to or from a stream for the + * purpose of serialization + */ + template + void serialize(Archive &ar, + const unsigned int version); + private: /** * Compress the arrays that store dof indices by using a variant of run- @@ -389,6 +397,19 @@ namespace internal return &cell_dof_indices_cache[cell_cache_offsets[obj_index]]; } + + template + inline + void + DoFLevel::serialize(Archive &ar, + const unsigned int) + { + ar &this->active_fe_indices; + ar &this->cell_cache_offsets; + ar &this->cell_dof_indices_cache; + ar &this->dof_indices; + ar &this->dof_offsets; + } } // namespace hp } // namespace internal