]> https://gitweb.dealii.org/ - dealii-svn.git/commitdiff
Add functions for serialization.
authorrao <rao@0785d39b-7218-0410-832d-ea1e28bc413d>
Mon, 6 Dec 2010 18:44:56 +0000 (18:44 +0000)
committerrao <rao@0785d39b-7218-0410-832d-ea1e28bc413d>
Mon, 6 Dec 2010 18:44:56 +0000 (18:44 +0000)
git-svn-id: https://svn.dealii.org/trunk@22928 0785d39b-7218-0410-832d-ea1e28bc413d

deal.II/include/deal.II/base/index_set.h
deal.II/include/deal.II/base/parameter_handler.h
deal.II/include/deal.II/base/polynomial.h
deal.II/include/deal.II/base/quadrature.h
deal.II/include/deal.II/base/subscriptor.h
deal.II/include/deal.II/base/table.h
deal.II/include/deal.II/base/table_indices.h
deal.II/include/deal.II/lac/sparsity_pattern.h
deal.II/include/deal.II/lac/vector.h
deal.II/source/base/polynomial.cc
deal.II/source/base/quadrature.cc

index 273122d8d59309cdf09c873ec6f16d8f23306120..5570c094e3bf4db39481a2a99d50b07736d3344d 100644 (file)
@@ -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 <class Archive>
+    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 <class Archive>
+    void serialize (Archive & ar, const unsigned int version);
 
     };
 
@@ -792,6 +806,21 @@ IndexSet::print (STREAM &out) const
   out << "}" << std::endl;
 }
 
+template <class Archive>
+inline
+void
+IndexSet::Range::serialize (Archive & ar, const unsigned int)
+{
+  ar & begin & end & nth_index_in_set;
+}
+   
+template <class Archive>
+inline
+void
+IndexSet::serialize (Archive & ar, const unsigned int)
+{
+  ar & ranges & is_compressed & index_space_size;
+}
 
 DEAL_II_NAMESPACE_CLOSE
 
index d683eac337ef4dd1f04392067b8a678dd6efdaeb..eb723acb64d854fd8b1fcd989ca558ef417c5c53 100644 (file)
@@ -20,6 +20,7 @@
 #include <base/std_cxx1x/shared_ptr.h>
 
 #include <boost/property_tree/ptree_fwd.hpp>
+#include <boost/serialization/split_member.hpp>
 
 #include <map>
 #include <vector>
@@ -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 <class Archive>
+   void save (Archive & ar, const unsigned int version) const;
+
+                         /**
+                      * Read the data of this object
+                      * from a stream for the purpose of serialization.
+                      */    
+   template <class Archive>
+   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 <class Archive>
+inline
+void 
+ParameterHandler::save (Archive & ar, const unsigned int) const
+{
+                                       // Forward to serialization
+                                       // function in the base class.
+  ar &  static_cast<const Subscriptor &>(*this);
+
+  ar & *entries.get();
+
+  std::vector<std::string> descriptions;
+
+  for (unsigned int j=0; j<patterns.size(); ++j)
+    descriptions.push_back (patterns[j]->description());
+
+  ar & descriptions;
+}
+
+   
+template <class Archive>
+inline
+void 
+ParameterHandler::load (Archive & ar, const unsigned int)
+{
+                                       // Forward to serialization
+                                       // function in the base class.
+  ar &  static_cast<Subscriptor &>(*this);
+
+  ar & *entries.get();
+
+  std::vector<std::string> descriptions;
+  ar & descriptions;
+
+  patterns.clear ();
+  for (unsigned int j=0; j<descriptions.size(); ++j)
+    patterns.push_back (std_cxx1x::shared_ptr<Patterns::PatternBase>(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; j<patterns.size(); ++j)
+    if (patterns[j]->description() != prm2.patterns[j]->description())
+      return false;
+      
+  // return !(*entries != *(prm2.entries));
+  return true;
+  // TODO: Fix
+}
+
 DEAL_II_NAMESPACE_CLOSE
 
 #endif
index 4b98d27b66b4d4b7d8e5a535ebb2aea03e9f9932..d8aee0b869a6dc9526257a0c4b0300a715d7bf8c 100644 (file)
@@ -200,10 +200,22 @@ namespace Polynomials
                                         */
       Polynomial<number>& operator -= (const Polynomial<number>& p);
 
+                                                  /**
+                                                       *  Test for equality of two polynomials.
+                                                       */
+      bool operator == (const Polynomial<number> & 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 <class Archive>
+      void serialize (Archive & ar, const unsigned int version);
 
     protected:
 
@@ -629,6 +641,21 @@ namespace Polynomials
 
     return value;
   }
+  
+
+
+  template <typename number>
+  template <class Archive>
+  inline
+  void
+  Polynomial<number>::serialize (Archive & ar, const unsigned int)
+  {
+                                     // forward to serialization
+                                     // function in the base class.
+    ar &  static_cast<Subscriptor &>(*this);
+    ar & coefficients;
+  }
+
 }
 DEAL_II_NAMESPACE_CLOSE
 
index fa0fb7dc75619257d4882e2440a0f828e972879c..5907346f813d8f923c9c6725b41e82fa3339ba6f 100644 (file)
@@ -190,6 +190,11 @@ class Quadrature : public Subscriptor
                                      * size.
                                      */
     Quadrature& operator = (const Quadrature<dim>&);
+    
+                     /**
+                                     *  Test for equality of two quadratures.
+                                     */
+    bool operator == (const Quadrature<dim> & 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 <class Archive>
+    void serialize (Archive & ar, const unsigned int version);
+
   protected:
                                     /**
                                      * List of quadrature points. To
@@ -414,6 +426,20 @@ Quadrature<dim>::get_weights () const
 
 
 
+template <int dim>
+template <class Archive>
+inline
+void
+Quadrature<dim>::serialize (Archive & ar, const unsigned int)
+{
+                                     // forward to serialization
+                                     // function in the base class.
+  ar &  static_cast<Subscriptor &>(*this);
+
+  ar & quadrature_points & weights;
+}
+
+
 
 /* -------------- declaration of explicit specializations ------------- */
 
index 063dba0789ce4b0b37fa006a3becc3d082ae2aec..c2ed305d6df66e3b560009b2af992e42994db95a 100644 (file)
@@ -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 <class Archive>
+    void serialize(Archive & ar, const unsigned int version);
+
   private:
                                     /**
                                      * Register a subscriber for
@@ -230,6 +237,15 @@ class Subscriptor
 
 //---------------------------------------------------------------------------
 
+template <class Archive>
+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
index 4a13a45fee48e124e268ca79023ef7123f2712ec..bb63d483bab7d067adef88581c66c8a8c9ade078 100644 (file)
@@ -532,6 +532,11 @@ class TableBase : public Subscriptor
                                       */
     template<typename T2>
     TableBase<N,T>& operator = (const TableBase<N,T2> &src);
+    
+                                     /**
+                                         *  Test for equality of two tables.
+                                      */
+    bool operator == (const TableBase<N,T> & 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 <class Archive>
+    void serialize (Archive & ar, const unsigned int version);
+
   protected:
                                      /**
                                       * Return the position of the
@@ -1739,6 +1751,19 @@ TableBase<N,T>::TableBase (const TableBase<N,T2> &src)
 
 
 
+template <int N, typename T>
+template <class Archive>
+inline
+void
+TableBase<N,T>::serialize (Archive & ar, const unsigned int)
+{
+  ar & static_cast<Subscriptor &>(*this);
+  
+  ar & values & table_size;
+}
+
+
+
 namespace internal
 {
   namespace TableBaseAccessors
@@ -1922,6 +1947,15 @@ TableBase<N,T>::operator = (const TableBase<N,T2>& m)
 }
 
 
+template <int N, typename T>
+inline
+bool 
+TableBase<N,T>::operator == (const TableBase<N,T> & T2)  const
+{
+  return (values == T2.values);
+}
+
+
 
 template <int N, typename T>
 inline
@@ -2716,7 +2750,6 @@ Table<4,T>::operator () (const TableIndices<4> &indices)
 
 
 
-
 template <typename T>
 inline
 Table<5,T>::Table ()
index 46d7c928cd00241c7bc0205a2fc1d8cb4e77095a..6cc3635b7b7f1fe53f1de9d3f8869231f5ac16e5 100644 (file)
@@ -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 <class Archive>
+    void serialize (Archive & ar, const unsigned int version);
+
   protected:
                                      /**
                                       * Store the indices in an array.
@@ -448,6 +455,17 @@ TableIndicesBase<N>::operator != (const TableIndicesBase<N> &other) const
 
 
 
+template <int N>
+template <class Archive>
+inline
+void
+TableIndicesBase<N>::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:
  * <code>[i1,i2,...]</code>.
index 42accbd7814bcd512138abf65c5749ad7614873a..f5c5f5b19084338f7b18aa464971812752517db4 100644 (file)
@@ -17,6 +17,8 @@
 #include <base/config.h>
 #include <base/exceptions.h>
 #include <base/subscriptor.h>
+#include <boost/serialization/array.hpp>
+#include <boost/serialization/split_member.hpp>
 
 #include <vector>
 #include <iostream>
@@ -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 <class Archive>
+    void save (Archive & ar, const unsigned int version) const;
+
+                     /**
+                      * Read the data of this object 
+                      * from a stream for the purpose of serialization
+                      */    
+    template <class Archive>
+    void load (Archive & ar, const unsigned int version);
+
+    BOOST_SERIALIZATION_SPLIT_MEMBER()
 
                                     /** @addtogroup Exceptions
                                      * @{ */
@@ -2022,6 +2045,65 @@ SparsityPattern::n_nonzero_elements () const
 
 
 
+template <class Archive>
+inline
+void
+SparsityPattern::save (Archive & ar, const unsigned int) const
+{
+                                     // forward to serialization
+                                     // function in the base class.
+  ar &  static_cast<const Subscriptor &>(*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 <class Archive>
+inline
+void
+SparsityPattern::load (Archive & ar, const unsigned int)
+{
+                                     // forward to serialization
+                                     // function in the base class.
+  ar &  static_cast<Subscriptor &>(*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
index 4bf499550eacf3de54e5f88e7c98813e1f94ee49..a8b10919f4df3db9068f90d26d43c328a97548cd 100644 (file)
@@ -20,6 +20,8 @@
 #include <base/parallel.h>
 #include <base/subscriptor.h>
 #include <boost/lambda/lambda.hpp>
+#include <boost/serialization/array.hpp>
+#include <boost/serialization/split_member.hpp>
 
 #include <cstdio>
 #include <iostream>
@@ -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 <class Archive>
+    void save (Archive & ar, const unsigned int version) const;
+
+                     /**
+                      * Read the data of this object 
+                      * from a stream for the purpose of serialization.
+                      */    
+    template <class Archive>
+    void load (Archive & ar, const unsigned int version);
+
+    BOOST_SERIALIZATION_SPLIT_MEMBER()
 
   protected:
 
@@ -1440,6 +1458,40 @@ Vector<Number>::swap (Vector<Number> &v)
 }
 
 
+
+template <typename Number>
+template <class Archive>
+inline
+void
+Vector<Number>::save (Archive & ar, const unsigned int) const
+{
+                                     // forward to serialization
+                                     // function in the base class.
+  ar &  static_cast<const Subscriptor &>(*this);
+  
+  ar & vec_size & max_vec_size ;
+  ar & boost::serialization::make_array(val, max_vec_size);
+}
+
+
+
+template <typename Number>
+template <class Archive>
+inline
+void
+Vector<Number>::load (Archive & ar, const unsigned int)
+{
+                                     // forward to serialization
+                                     // function in the base class.
+  ar &  static_cast<Subscriptor &>(*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<number>& v)
   return os;  
 }
 
+
 /*@}*/
 
 DEAL_II_NAMESPACE_CLOSE
index 4dd58d8c0ea7da6229c457c4e5c97ab1f7d7c3f6..47126aa09e7c674bff66708b63bd1a6b75b5f17e 100644 (file)
@@ -210,6 +210,13 @@ namespace Polynomials
     return *this;
   }
 
+  template <typename number >
+  bool 
+  Polynomial<number>::operator == (const Polynomial<number> & p)  const
+  {
+    return (p.coefficients == coefficients);
+  }
+
 
   template <typename number>
   template <typename number2>
index 7e889c7e18fc2e683b0f28e91e6dce66a32e4656..ab855627d2bf8737563b0005165ce7bc209a8c7d 100644 (file)
@@ -272,6 +272,17 @@ Quadrature<dim>::operator= (const Quadrature<dim>& q)
 
 
 
+template <int dim>
+bool 
+Quadrature<dim>::operator == (const Quadrature<dim> & q) const
+{
+  return ((quadrature_points == q.quadrature_points)
+   &&
+   (weights == q.weights));
+}
+
+
+
 template <int dim>
 Quadrature<dim>::~Quadrature ()
 {}

In the beginning the Universe was created. This has made a lot of people very angry and has been widely regarded as a bad move.

Douglas Adams


Typeset in Trocchi and Trocchi Bold Sans Serif.