<ol>
<li> <p>
- New:<code class="class">Vector</code> has a function <code
+ New: <code class="class">SparsityPattern</code> now has functions <code
+ class="member">block_write/block_read</code>, allowing to dump the data
+ of this object in to a file in binary format, and later to re-read it
+ without much need for much parsing.
+ <br>
+ (WB 2002/09/09)
+ </p>
+
+ <li> <p>
+ New: <code class="class">Vector</code> has a function <code
class="member">lp_norm</code>, computing the <i>l<sub>p</sub></i>-norm
of a vector for arbitrary <i>p</i>.
<br>
#include <base/subscriptor.h>
#include <vector>
+#include <iostream>
template <typename number> class FullMatrix;
*/
const unsigned int * get_column_numbers () const;
+ /**
+ * Write the data of this object
+ * en bloc to a file. This is
+ * done in a binary mode, so the
+ * output is neither readable by
+ * humans nor (probably) by other
+ * computers using a different
+ * operating system of number
+ * format.
+ *
+ * The purpose of this function
+ * is that you can swap out
+ * matrices and sparsity pattern
+ * if you are short of memory,
+ * want to communicate between
+ * different programs, or allow
+ * objects to be persistent
+ * across different runs of the
+ * program.
+ */
+ void block_write (ostream &out) const;
+
+ /**
+ * Read data that has previously
+ * been written by
+ * @p{block_write} en block from
+ * a file. This is done using the
+ * inverse operations to the
+ * above function, so it is
+ * reasonably fast because the
+ * bitstream is not interpreted
+ * except for a few numbers up
+ * front.
+ *
+ * The object is resized on this
+ * operation, and all previous
+ * contents are lost.
+ *
+ * A primitive form of error
+ * checking is performed which
+ * will recognize the bluntest
+ * attempts to interpret some
+ * data as a vector stored
+ * bitwise to a file, but not
+ * more.
+ */
+ void block_read (std::istream &in);
+
/**
* Determine an estimate for the
* memory consumption (in bytes)
+void
+SparsityPattern::block_write (ostream &out) const
+{
+ AssertThrow (out, ExcIO());
+
+ // first the simple objects,
+ // bracketed in [...]
+ out << '[' << max_dim << ' '
+ << rows << ' '
+ << max_vec_len << ' '
+ << max_row_length << ' '
+ << compressed << "][";
+ // then write out real data
+ out.write (reinterpret_cast<const char*>(&rowstart[0]),
+ reinterpret_cast<const char*>(&rowstart[max_dim])
+ - reinterpret_cast<const char*>(&rowstart[0]));
+ out << "][";
+ out.write (reinterpret_cast<const char*>(&colnums[0]),
+ reinterpret_cast<const char*>(&colnums[max_vec_len])
+ - reinterpret_cast<const char*>(&colnums[0]));
+ out << ']';
+
+ AssertThrow (out, ExcIO());
+};
+
+
+
+void
+SparsityPattern::block_read (istream &in)
+{
+ AssertThrow (in, ExcIO());
+
+ char c;
+
+ // first read in simple data
+ in >> c;
+ AssertThrow (c == '[', ExcIO());
+ in >> max_dim >> rows >> max_vec_len >> max_row_length >> compressed;
+
+ in >> c;
+ AssertThrow (c == ']', ExcIO());
+ in >> c;
+ AssertThrow (c == '[', ExcIO());
+
+ // reallocate space
+ delete[] rowstart;
+ delete[] colnums;
+
+ rowstart = new unsigned int[max_dim];
+ colnums = new unsigned int[max_vec_len];
+
+ // then read data
+ in.read (reinterpret_cast<char*>(&rowstart[0]),
+ reinterpret_cast<char*>(&rowstart[max_dim])
+ - reinterpret_cast<char*>(&rowstart[0]));
+ in >> c;
+ AssertThrow (c == ']', ExcIO());
+ in >> c;
+ AssertThrow (c == '[', ExcIO());
+ in.read (reinterpret_cast<char*>(&colnums[0]),
+ reinterpret_cast<char*>(&colnums[max_vec_len])
+ - reinterpret_cast<char*>(&colnums[0]));
+ in >> c;
+ AssertThrow (c == ']', ExcIO());
+};
+
+
+
unsigned int
SparsityPattern::memory_consumption () const
{
#include <iostream>
#include <list>
#include <set>
+#include <cstdio>
int
// now check for equivalence of sp3 and sp4
for (unsigned int row=0; row<sp3.n_rows(); ++row)
{
- const unsigned int *sp3_p=sp3.get_column_numbers()+sp3.get_rowstart_indices()[row];
- const unsigned int *sp4_p=sp4.get_column_numbers()+sp4.get_rowstart_indices()[row];
- for (; sp3_p != sp3.get_column_numbers()+sp3.get_rowstart_indices()[row+1]; ++sp3_p, ++sp4_p)
+ const unsigned int
+ *sp3_p=sp3.get_column_numbers()+sp3.get_rowstart_indices()[row];
+ const unsigned int
+ *sp4_p=sp4.get_column_numbers()+sp4.get_rowstart_indices()[row];
+ for (; sp3_p != (sp3.get_column_numbers() +
+ sp3.get_rowstart_indices()[row+1]);
+ ++sp3_p, ++sp4_p)
Assert (*sp3_p == *sp4_p, ExcInternalError());
};
std::make_pair(row,col),
ExcInternalError());
};
+
+
+ // check block_write/block_read by
+ // dumping a sparsity pattern and
+ // checking whether the
+ // read-back-in pattern is the same
+ std::ofstream tmp_write("sparsity_pattern.tmp");
+ sp3.block_write (tmp_write);
+ tmp_write.close ();
+
+ std::ifstream tmp_read("sparsity_pattern.tmp");
+ sp4.block_read (tmp_read);
+ tmp_read.close ();
+
+ // delete temporary file
+ remove ("sparsity_pattern.tmp");
+
+ // now check for equivalence of sp3 and sp4
+ for (unsigned int row=0; row<sp3.n_rows(); ++row)
+ {
+ const unsigned int
+ *sp3_p=sp3.get_column_numbers()+sp3.get_rowstart_indices()[row];
+ const unsigned int
+ *sp4_p=sp4.get_column_numbers()+sp4.get_rowstart_indices()[row];
+ for (; sp3_p != (sp3.get_column_numbers() +
+ sp3.get_rowstart_indices()[row+1]);
+ ++sp3_p, ++sp4_p)
+ Assert (*sp3_p == *sp4_p, ExcInternalError());
+ };
};