From: rao Date: Mon, 6 Dec 2010 18:44:56 +0000 (+0000) Subject: Add functions for serialization. X-Git-Url: https://gitweb.dealii.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=dc30956a4351e169fec898281474135dc801e957;p=dealii-svn.git Add functions for serialization. git-svn-id: https://svn.dealii.org/trunk@22928 0785d39b-7218-0410-832d-ea1e28bc413d --- diff --git a/deal.II/include/deal.II/base/index_set.h b/deal.II/include/deal.II/base/index_set.h index 273122d8d5..5570c094e3 100644 --- a/deal.II/include/deal.II/base/index_set.h +++ b/deal.II/include/deal.II/base/index_set.h @@ -363,6 +363,13 @@ class IndexSet DeclException1 (ExcIndexNotPresent, int, << "The global index " << arg1 << " is not an element of this set."); + + /** + * Write or read 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: /** @@ -426,6 +433,13 @@ class IndexSet { return sizeof(Range); } + + /** + * Write or read the data of this object to or + * from a stream for the purpose of serialization + */ + template + void serialize (Archive & ar, const unsigned int version); }; @@ -792,6 +806,21 @@ IndexSet::print (STREAM &out) const out << "}" << std::endl; } +template +inline +void +IndexSet::Range::serialize (Archive & ar, const unsigned int) +{ + ar & begin & end & nth_index_in_set; +} + +template +inline +void +IndexSet::serialize (Archive & ar, const unsigned int) +{ + ar & ranges & is_compressed & index_space_size; +} DEAL_II_NAMESPACE_CLOSE diff --git a/deal.II/include/deal.II/base/parameter_handler.h b/deal.II/include/deal.II/base/parameter_handler.h index d683eac337..eb723acb64 100644 --- a/deal.II/include/deal.II/base/parameter_handler.h +++ b/deal.II/include/deal.II/base/parameter_handler.h @@ -20,6 +20,7 @@ #include #include +#include #include #include @@ -2028,6 +2029,27 @@ class ParameterHandler : public Subscriptor */ unsigned int 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() + + /** + * Test for equality. + */ + bool operator == (const ParameterHandler & prm2) const; + /** @addtogroup Exceptions * @{ */ @@ -2578,6 +2600,61 @@ class MultipleParameterLoop : public ParameterHandler }; +template +inline +void +ParameterHandler::save (Archive & ar, const unsigned int) const +{ + // Forward to serialization + // function in the base class. + ar & static_cast(*this); + + ar & *entries.get(); + + std::vector descriptions; + + for (unsigned int j=0; jdescription()); + + ar & descriptions; +} + + +template +inline +void +ParameterHandler::load (Archive & ar, const unsigned int) +{ + // Forward to serialization + // function in the base class. + ar & static_cast(*this); + + ar & *entries.get(); + + std::vector descriptions; + ar & descriptions; + + patterns.clear (); + for (unsigned int j=0; j(Patterns::pattern_factory(descriptions[j]))); +} + +inline +bool +ParameterHandler::operator == (const ParameterHandler & prm2) const +{ + if(patterns.size() != prm2.patterns.size()) + return false; + + for(unsigned int j=0; jdescription() != prm2.patterns[j]->description()) + return false; + + // return !(*entries != *(prm2.entries)); + return true; + // TODO: Fix +} + DEAL_II_NAMESPACE_CLOSE #endif diff --git a/deal.II/include/deal.II/base/polynomial.h b/deal.II/include/deal.II/base/polynomial.h index 4b98d27b66..d8aee0b869 100644 --- a/deal.II/include/deal.II/base/polynomial.h +++ b/deal.II/include/deal.II/base/polynomial.h @@ -200,10 +200,22 @@ namespace Polynomials */ Polynomial& operator -= (const Polynomial& p); + /** + * Test for equality of two polynomials. + */ + bool operator == (const Polynomial & p) const; + /** * Print coefficients. */ void print(std::ostream& out) const; + + /** + * Write or read the data of this object to or + * from a stream for the purpose of serialization. + */ + template + void serialize (Archive & ar, const unsigned int version); protected: @@ -629,6 +641,21 @@ namespace Polynomials return value; } + + + + template + template + inline + void + Polynomial::serialize (Archive & ar, const unsigned int) + { + // forward to serialization + // function in the base class. + ar & static_cast(*this); + ar & coefficients; + } + } DEAL_II_NAMESPACE_CLOSE diff --git a/deal.II/include/deal.II/base/quadrature.h b/deal.II/include/deal.II/base/quadrature.h index fa0fb7dc75..5907346f81 100644 --- a/deal.II/include/deal.II/base/quadrature.h +++ b/deal.II/include/deal.II/base/quadrature.h @@ -190,6 +190,11 @@ class Quadrature : public Subscriptor * size. */ Quadrature& operator = (const Quadrature&); + + /** + * Test for equality of two quadratures. + */ + bool operator == (const Quadrature & p) const; /** * Set the quadrature points and @@ -242,6 +247,13 @@ class Quadrature : public Subscriptor */ unsigned int memory_consumption () const; + /** + * Write or read the data of this object to or + * from a stream for the purpose of serialization. + */ + template + void serialize (Archive & ar, const unsigned int version); + protected: /** * List of quadrature points. To @@ -414,6 +426,20 @@ Quadrature::get_weights () const +template +template +inline +void +Quadrature::serialize (Archive & ar, const unsigned int) +{ + // forward to serialization + // function in the base class. + ar & static_cast(*this); + + ar & quadrature_points & weights; +} + + /* -------------- declaration of explicit specializations ------------- */ diff --git a/deal.II/include/deal.II/base/subscriptor.h b/deal.II/include/deal.II/base/subscriptor.h index 063dba0789..c2ed305d6d 100644 --- a/deal.II/include/deal.II/base/subscriptor.h +++ b/deal.II/include/deal.II/base/subscriptor.h @@ -145,6 +145,13 @@ class Subscriptor << "\" did subscribe to this object of class " << arg1); //@} + /** + * 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: /** * Register a subscriber for @@ -230,6 +237,15 @@ class Subscriptor //--------------------------------------------------------------------------- +template +inline +void +Subscriptor::serialize(Archive & ar, const unsigned int) +{ + ar & (unsigned int&)counter ;//& counter_map; + // TODO: Serialize counter_map +} + // If we are in optimized mode, the subscription checking is turned // off. Therefore, we provide inline definitions of subscribe and // unsubscribe here. The definitions for debug mode are in diff --git a/deal.II/include/deal.II/base/table.h b/deal.II/include/deal.II/base/table.h index 4a13a45fee..bb63d483ba 100644 --- a/deal.II/include/deal.II/base/table.h +++ b/deal.II/include/deal.II/base/table.h @@ -532,6 +532,11 @@ class TableBase : public Subscriptor */ template TableBase& operator = (const TableBase &src); + + /** + * Test for equality of two tables. + */ + bool operator == (const TableBase & T2) const; /** * Set all entries to their @@ -646,6 +651,13 @@ class TableBase : public Subscriptor */ unsigned int memory_consumption () const; + /** + * Write or read the data of this object to or + * from a stream for the purpose of serialization. + */ + template + void serialize (Archive & ar, const unsigned int version); + protected: /** * Return the position of the @@ -1739,6 +1751,19 @@ TableBase::TableBase (const TableBase &src) +template +template +inline +void +TableBase::serialize (Archive & ar, const unsigned int) +{ + ar & static_cast(*this); + + ar & values & table_size; +} + + + namespace internal { namespace TableBaseAccessors @@ -1922,6 +1947,15 @@ TableBase::operator = (const TableBase& m) } +template +inline +bool +TableBase::operator == (const TableBase & T2) const +{ + return (values == T2.values); +} + + template inline @@ -2716,7 +2750,6 @@ Table<4,T>::operator () (const TableIndices<4> &indices) - template inline Table<5,T>::Table () diff --git a/deal.II/include/deal.II/base/table_indices.h b/deal.II/include/deal.II/base/table_indices.h index 46d7c928cd..6cc3635b7b 100644 --- a/deal.II/include/deal.II/base/table_indices.h +++ b/deal.II/include/deal.II/base/table_indices.h @@ -69,6 +69,13 @@ class TableIndicesBase */ void sort (); + /** + * Write or read the data of this object to or + * from a stream for the purpose of serialization. + */ + template + void serialize (Archive & ar, const unsigned int version); + protected: /** * Store the indices in an array. @@ -448,6 +455,17 @@ TableIndicesBase::operator != (const TableIndicesBase &other) const +template +template +inline +void +TableIndicesBase::serialize (Archive & ar, const unsigned int) +{ + ar & indices; +} + + + template <> inline void @@ -537,6 +555,7 @@ TableIndices<3>::TableIndices (const unsigned int index1, } + inline TableIndices<4>::TableIndices () { @@ -643,6 +662,7 @@ TableIndices<7>::TableIndices (const unsigned int index1, } + /** * Output operator for indices; reports them in a list like this: * [i1,i2,...]. diff --git a/deal.II/include/deal.II/lac/sparsity_pattern.h b/deal.II/include/deal.II/lac/sparsity_pattern.h index 42accbd781..f5c5f5b190 100644 --- a/deal.II/include/deal.II/lac/sparsity_pattern.h +++ b/deal.II/include/deal.II/lac/sparsity_pattern.h @@ -17,6 +17,8 @@ #include #include #include +#include +#include #include #include @@ -660,6 +662,11 @@ class SparsityPattern : public Subscriptor * objects. */ SparsityPattern & operator = (const SparsityPattern &); + + /** + * Test for equality of two SparsityPatterns. + */ + bool operator == (const SparsityPattern &) const; /** * Reallocate memory and set up data @@ -1437,6 +1444,22 @@ class SparsityPattern : public Subscriptor * information! */ inline const unsigned int * get_column_numbers () 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() /** @addtogroup Exceptions * @{ */ @@ -2022,6 +2045,65 @@ SparsityPattern::n_nonzero_elements () const +template +inline +void +SparsityPattern::save (Archive & ar, const unsigned int) const +{ + // forward to serialization + // function in the base class. + ar & static_cast(*this); + + ar & max_dim & rows & cols & max_vec_len & max_row_length & compressed & diagonal_optimized; + + ar & boost::serialization::make_array(rowstart, max_dim + 1); + ar & boost::serialization::make_array(colnums, max_vec_len); +} + + + +template +inline +void +SparsityPattern::load (Archive & ar, const unsigned int) +{ + // forward to serialization + // function in the base class. + ar & static_cast(*this); + + ar & max_dim & rows & cols & max_vec_len & max_row_length & compressed & diagonal_optimized; + + rowstart = new std::size_t [max_dim + 1]; + colnums = new unsigned int [max_vec_len]; + + ar & boost::serialization::make_array(rowstart, max_dim + 1); + ar & boost::serialization::make_array(colnums, max_vec_len); +} + + + +inline +bool +SparsityPattern::operator == (const SparsityPattern& sp2) const +{ + if (max_dim != sp2.max_dim || rows != sp2.rows || cols != sp2.cols || + max_vec_len != sp2.max_vec_len || max_row_length != sp2.max_row_length || + compressed != sp2.compressed || diagonal_optimized != sp2.diagonal_optimized) + return false; + + for (unsigned int i = 0; i < max_dim+1; ++i) + if (rowstart[i] != sp2.rowstart[i]) + return false; + + for (unsigned int i = 0; i < max_vec_len; ++i) + if (colnums[i] != sp2.colnums[i]) + return false; + + return true; +} + + + namespace internal { namespace SparsityPatternTools diff --git a/deal.II/include/deal.II/lac/vector.h b/deal.II/include/deal.II/lac/vector.h index 4bf499550e..a8b10919f4 100644 --- a/deal.II/include/deal.II/lac/vector.h +++ b/deal.II/include/deal.II/lac/vector.h @@ -20,6 +20,8 @@ #include #include #include +#include +#include #include #include @@ -939,6 +941,22 @@ class Vector : public Subscriptor */ unsigned int 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() protected: @@ -1440,6 +1458,40 @@ Vector::swap (Vector &v) } + +template +template +inline +void +Vector::save (Archive & ar, const unsigned int) const +{ + // forward to serialization + // function in the base class. + ar & static_cast(*this); + + ar & vec_size & max_vec_size ; + ar & boost::serialization::make_array(val, max_vec_size); +} + + + +template +template +inline +void +Vector::load (Archive & ar, const unsigned int) +{ + // forward to serialization + // function in the base class. + ar & static_cast(*this); + + ar & vec_size & max_vec_size ; + + val = new Number[max_vec_size]; + ar & boost::serialization::make_array(val, max_vec_size); +} + + #endif @@ -1488,6 +1540,7 @@ operator << (LogStream& os, const Vector& v) return os; } + /*@}*/ DEAL_II_NAMESPACE_CLOSE diff --git a/deal.II/source/base/polynomial.cc b/deal.II/source/base/polynomial.cc index 4dd58d8c0e..47126aa09e 100644 --- a/deal.II/source/base/polynomial.cc +++ b/deal.II/source/base/polynomial.cc @@ -210,6 +210,13 @@ namespace Polynomials return *this; } + template + bool + Polynomial::operator == (const Polynomial & p) const + { + return (p.coefficients == coefficients); + } + template template diff --git a/deal.II/source/base/quadrature.cc b/deal.II/source/base/quadrature.cc index 7e889c7e18..ab855627d2 100644 --- a/deal.II/source/base/quadrature.cc +++ b/deal.II/source/base/quadrature.cc @@ -272,6 +272,17 @@ Quadrature::operator= (const Quadrature& q) +template +bool +Quadrature::operator == (const Quadrature & q) const +{ + return ((quadrature_points == q.quadrature_points) + && + (weights == q.weights)); +} + + + template Quadrature::~Quadrature () {}