From 37b3fa67d5170601f2b46ca5fa6dcf2b5c63f9d8 Mon Sep 17 00:00:00 2001 From: wolf Date: Wed, 17 Nov 1999 17:37:10 +0000 Subject: [PATCH] Remove large chunks of stuff: raw write of a triangulation to disk and re-reading it. Reason: the code was never finished, never tested, and no more necessary since we have the PersistentTriangulation now. git-svn-id: https://svn.dealii.org/trunk@1878 0785d39b-7218-0410-832d-ea1e28bc413d --- deal.II/deal.II/include/grid/tria.h | 30 -- deal.II/deal.II/include/grid/tria_levels.h | 174 -------- .../source/grid/tria.all_dimensions.cc | 387 +----------------- deal.II/deal.II/source/grid/tria.cc | 30 -- 4 files changed, 15 insertions(+), 606 deletions(-) diff --git a/deal.II/deal.II/include/grid/tria.h b/deal.II/deal.II/include/grid/tria.h index bed32e0259..0e489b3431 100644 --- a/deal.II/deal.II/include/grid/tria.h +++ b/deal.II/deal.II/include/grid/tria.h @@ -1743,36 +1743,6 @@ class Triangulation */ virtual void copy_triangulation (const Triangulation &old_tria); - /** - * Write out a triangulation en bloc, i.e. - * in a binary or near binary format. Since - * some of the data vectors describing a - * triangulation are written en bloc - * from memory to the stream, the file - * resulting from this operation will not - * be readable on other platforms; this - * function along with the following is - * only thought to support fast creation - * of and restoration from temporary - * files. - * - * The function is made #virtual# to - * allow derived classes to write their - * contents as well. - */ - virtual void block_write (ostream &out) const; - - /** - * Restore a triangulation written by the - * above function. The present content of - * the triangulation is obviously lost. - * - * The function is made #virtual# to - * allow derived classes to read their - * contents as well. - */ - virtual void block_read (istream &in); - /** * Create a triangulation from a list * of vertices and a list of cells, each of diff --git a/deal.II/deal.II/include/grid/tria_levels.h b/deal.II/deal.II/include/grid/tria_levels.h index c6357698e0..d7c30b0aca 100644 --- a/deal.II/deal.II/include/grid/tria_levels.h +++ b/deal.II/deal.II/include/grid/tria_levels.h @@ -146,21 +146,6 @@ class TriangulationLevel<0> { */ void monitor_memory (const unsigned int true_dimension) const; - /** - * Write out the data of this object - * in a raw format, i.e. binary or almost - * binary. - */ - void block_write (ostream &out) const; - - /** - * Read back the data written by the above - * function. By doing so, all content - * which may have been in this object will - * be lost. - */ - void block_read (istream &in); - /** * Exception */ @@ -180,102 +165,6 @@ class TriangulationLevel<0> { * Exception */ DeclException0 (ExcIO); - - protected: - - /** - * Write out a vector of anything - * in a binary format. To be exact, - * what we write is the memory content - * between #v.begin()# and #v.end()#; - * this function is therefore only - * useful if the whole information of - * the objects stored in this vector - * are contained within the objects, - * i.e. they do not have pointers, - * references, other vectors, etc. - * - * For all other vectors, specialized - * functions need to be written; the - * following one is an example for - * this. - */ - template - static void write_raw_vector (const unsigned int magic_number1, - const vector &v, - const unsigned int magic_number2, - ostream &out); - - /** - * Write a bool vector to the given stream, - * writing a pre- and a postfix magica - * number. The vector is written in an - * almost binary format, i.e. the bool - * flags are packed but the data is written - * as ASCII text. - * - * The flags are stored in a binary - * format: for each #true#, a #1# - * bit is stored, a #0# bit otherwise. - * The bits are stored as #unsigned char#, - * thus avoiding endianess. They are - * written to #out# in plain text, thus - * amounting to 3.6 bits per flag - * on the overage. Other information - * (magic numbers ans number of elements) - * is stored as plain text - * as well. The format should therefore be - * interplatform compatible. - */ - static void write_raw_vector (const unsigned int magic_number1, - const vector &v, - const unsigned int magic_number2, - ostream &out); - - /** - * Write out a vector almost raw: we - * use a run-length encoding (rle) scheme - * to reduce the size of a vector. This - * function yields better results than the - * above ones if frequently larger chunks - * of data have the same value. - */ - template - static void write_rle_vector (const unsigned int magic_number1, - const vector &v, - const unsigned int magic_number2, - ostream &out); - - /** - * Read back a vector written by - * #write_raw_vector#. - */ - template - static void read_raw_vector (const unsigned int magic_number1, - vector &v, - const unsigned int magic_number2, - istream &in); - - /** - * Read back a vector written by - * the version of #write_raw_vector# - * for #bool# vectors. - */ - static void read_raw_vector (const unsigned int magic_number1, - vector &v, - const unsigned int magic_number2, - istream &in); - - /** - * Read back a run-length encoded - * vector, as written by - * #write_rle_vector#. - */ - template - static void read_rle_vector (const unsigned int magic_number1, - vector &v, - const unsigned int magic_number2, - istream &in); }; @@ -422,27 +311,6 @@ class TriangulationLevel<1> : public TriangulationLevel<0> { * #TriangulationLevel# classes. */ void monitor_memory (const unsigned int true_dimension) const; - - /** - * Write out the data of this object - * in a raw format, i.e. binary or almost - * binary. - * - * Calls the respective function of - * #TriangulationLevel<0>#. - */ - void block_write (ostream &out) const; - - /** - * Read back the data written by the above - * function. By doing so, all content - * which may have been in this object will - * be lost. - * - * Calls the respective function of - * #TriangulationLevel<0>#. - */ - void block_read (istream &in); }; @@ -551,27 +419,6 @@ class TriangulationLevel<2> : public TriangulationLevel<1> * #TriangulationLevel# classes. */ void monitor_memory (const unsigned int true_dimension) const; - - /** - * Write out the data of this object - * in a raw format, i.e. binary or almost - * binary. - * - * Calls the respective function of - * #TriangulationLevel<1>#. - */ - void block_write (ostream &out) const; - - /** - * Read back the data written by the above - * function. By doing so, all content - * which may have been in this object will - * be lost. - * - * Calls the respective function of - * #TriangulationLevel<1>#. - */ - void block_read (istream &in); }; @@ -680,27 +527,6 @@ class TriangulationLevel<3> : public TriangulationLevel<2> * #TriangulationLevel# classes. */ void monitor_memory (const unsigned int true_dimension) const; - - /** - * Write out the data of this object - * in a raw format, i.e. binary or almost - * binary. - * - * Calls the respective function of - * #TriangulationLevel<2>#. - */ - void block_write (ostream &out) const; - - /** - * Read back the data written by the above - * function. By doing so, all content - * which may have been in this object will - * be lost. - * - * Calls the respective function of - * #TriangulationLevel<2>#. - */ - void block_read (istream &in); }; diff --git a/deal.II/deal.II/source/grid/tria.all_dimensions.cc b/deal.II/deal.II/source/grid/tria.all_dimensions.cc index 5258724bd9..b5c7ce06d1 100644 --- a/deal.II/deal.II/source/grid/tria.all_dimensions.cc +++ b/deal.II/deal.II/source/grid/tria.all_dimensions.cc @@ -23,7 +23,8 @@ -bool SubCellData::check_consistency (const unsigned int dim) const { +bool SubCellData::check_consistency (const unsigned int dim) const +{ switch (dim) { case 1: @@ -39,7 +40,8 @@ bool SubCellData::check_consistency (const unsigned int dim) const { void TriangulationLevel<0>::reserve_space (const unsigned int total_cells, - const unsigned int dimension) { + const unsigned int dimension) +{ // we need space for total_cells // cells. Maybe we have more already // with those cells which are unused, @@ -69,7 +71,8 @@ void TriangulationLevel<0>::reserve_space (const unsigned int total_cells, -void TriangulationLevel<0>::monitor_memory (const unsigned int true_dimension) const { +void TriangulationLevel<0>::monitor_memory (const unsigned int true_dimension) const +{ // Assert (refine_flags.size() == refine_flags.capacity() || // refine_flags.size()<256, // ExcMemoryWasted ("refine_flags", @@ -90,325 +93,8 @@ void TriangulationLevel<0>::monitor_memory (const unsigned int true_dimension) c -template -void TriangulationLevel<0>::write_raw_vector (const unsigned int magic_number1, - const vector &v, - const unsigned int magic_number2, - ostream &out) -{ - AssertThrow (out, ExcIO()); - - out << magic_number1 << ' ' << v.size() << '['; - out.write (reinterpret_cast(v.begin()), - reinterpret_cast(v.end()) - - reinterpret_cast(v.begin())); - out << ']' << magic_number2 << endl; - - AssertThrow (out, ExcIO()); -}; - - - -void TriangulationLevel<0>::write_raw_vector (const unsigned int magic_number1, - const vector &v, - const unsigned int magic_number2, - ostream &out) { - const unsigned int N = v.size(); - unsigned char *flags = new unsigned char[N/8+1]; - for (unsigned int i=0; i(flags[i]) << " "; - - out << ']' << magic_number2 << endl; - - delete[] flags; - - AssertThrow (out, ExcIO()); -}; - - - -template -void TriangulationLevel<0>::write_rle_vector (const unsigned int magic_number1, - const vector &v, - const unsigned int magic_number2, - ostream &out) -{ - AssertThrow (out, ExcIO()); - - // store the position of the last - // break in the data stream from - // which on nothing was yet written - // to #out# - typename vector::const_iterator last_major_break = v.begin(); - // pointer to an element against - // which we want to compare following - // elements - typename vector::const_iterator comparator; - // name says all - typename vector::const_iterator present_element; - // same here - typename vector::const_iterator end_of_vector = v.end(); - - out << magic_number1 << ' ' << v.size() << '['; - - while (last_major_break < end_of_vector) - { - // from the present position onward: - // find how many elements are equal - comparator = last_major_break; - - while (true) - { - present_element = comparator+1; - while ((present_element != end_of_vector) && - (*present_element == *comparator) && - (present_element-comparator < 255)) - ++present_element; - - // now present_element points to the - // first element which is not equal - // to #comparator# or alternatively - // to #end_of_vector# or to - // #comparator+255# - // - // if #present_element# is - // #comparator+1#, i.e. the - // sequence of equal - // elements consisted of - // only one elements then - // discard this sequence - // and find the next one - // - // otherwise leave the loop - if ((present_element != end_of_vector) && - (present_element < comparator+1)) - comparator = present_element; - else - break; - }; - - // if the loop broke because we have - // reached the end of the vector: - // maybe set comparator to - // present_element - if ((present_element == end_of_vector) && - (present_element < comparator+1)) - comparator = present_element; - - // now comparator points to the start - // of the sequence of equal elements - // and present_element points past its - // end; they may be the same if the - // length of the sequence of unequal - // elements was 255 - // - // now do the following: write out - // the elements of - // last_major_break...comparator, - // then write - // comparator...present_element - // if necessary; note that we need - // only write *one* element (that is why - // we do all this here) - out << '<' << comparator-last_major_break << '>'; - if (comparator != last_major_break) - out.write (reinterpret_cast(last_major_break), - reinterpret_cast(comparator) - - reinterpret_cast(last_major_break)); - out << '<' << present_element-comparator << '>'; - if (present_element != comparator) - out.write (reinterpret_cast(comparator), - reinterpret_cast(comparator+1) - - reinterpret_cast(comparator)); - - last_major_break = present_element; - }; - - out << ']' << magic_number2 << endl; - - AssertThrow (out, ExcIO()); -}; - - - -template -void TriangulationLevel<0>::read_raw_vector (const unsigned int magic_number1, - vector &v, - const unsigned int magic_number2, - istream &in) -{ - AssertThrow (out, ExcIO()); - - unsigned int magic_number; - in >> magic_number; - AssertThrow (magic_number==magic_number1, ExcIO()); - - unsigned int N; - in >> N; - v.resize (N); - - out.read (reinterpret_cast(v.begin()), - reinterpret_cast(v.end()) - - reinterpret_cast(v.begin())); - - in >> magic_number; - AssertThrow (magic_number==magic_number2, ExcIO()); - - AssertThrow (out, ExcIO()); -}; - - - -void -TriangulationLevel<0>::read_raw_vector (const unsigned int magic_number1, - vector &v, - const unsigned int magic_number2, - istream &in) { - AssertThrow (in, ExcIO()); - - unsigned int magic_number; - in >> magic_number; - AssertThrow (magic_number==magic_number1, ExcIO()); - - unsigned int N; - in >> N; - v.resize (N); - - vector flags (N/8+1); - for (unsigned int i=0; i> flags[i]; - }; - - for (unsigned int position=0; position!=N; ++position) - v[position] = (flags[position/8] & (1<<(position%8))); - - in >> magic_number; - AssertThrow (magic_number==magic_number2, ExcIO()); - - AssertThrow (in, ExcIO()); -}; - - - -template -void TriangulationLevel<0>::read_rle_vector (const unsigned int magic_number1, - vector &v, - const unsigned int magic_number2, - istream &in) -{ - AssertThrow (in, ExcIO()); - - unsigned int magic_number; - in >> magic_number; - AssertThrow (magic_number==magic_number1, ExcIO()); - - unsigned int N; - in >> N; - v.resize (N); - - // index of the element presently read - typename vector::iterator present_element = 0; - - // variable to store the number - // of elements to be read next - unsigned int n_elements; - - // char to hold the '<' and - // '>' chars which are used - // as delimiters, also '[]' - char delimiter; - - in >> delimiter; - AssertThrow (delimiter=='[', ExcIO()); - - // read until we reach the end - // of the vector's output - const typename vector::const_iterator v_end = v.end(); - while (present_element < v_end) - { - // each block consists of two parts: - // first some non-equal elements and - // then one element which is repeated - // several times. both lists can be - // empty - in >> delimiter; - AssertThrow (delimiter=='<', ExcIO()); - - // number of non-equal elements - in >> n_elements; - - in >> delimiter; - AssertThrow (delimiter=='>', ExcIO()); - - if (n_elements > 0) - { - in.read (reinterpret_cast (present_element), - reinterpret_cast (present_element + n_elements) - - reinterpret_cast (present_element)); - present_element += n_elements; - }; - - // now for the element which is - // to be repeated - in >> delimiter; - AssertThrow (delimiter=='<', ExcIO()); - - // number of equal elements - in >> n_elements; - - in >> delimiter; - AssertThrow (delimiter=='>', ExcIO()); - - // read this one element - if (n_elements > 0) - { - in.read (reinterpret_cast (present_element), - reinterpret_cast (present_element + 1) - - reinterpret_cast (present_element)); - // repeat it - for (unsigned int i=1; i> delimiter; - AssertThrow (delimiter==']', ExcIO()); - - in >> magic_number; - AssertThrow (magic_number==magic_number2, ExcIO()); -}; - - - - -void TriangulationLevel<0>::block_write (ostream &out) const +void TriangulationLevel<1>::reserve_space (const unsigned int new_lines) { - write_raw_vector (0, refine_flags, 0, out); - write_raw_vector (0, coarsen_flags, 0, out); - write_raw_vector (0, neighbors, 0, out); -}; - - - - - -void TriangulationLevel<1>::reserve_space (const unsigned int new_lines) { const unsigned int new_size = new_lines + count_if (lines.used.begin(), lines.used.end(), @@ -454,7 +140,8 @@ void TriangulationLevel<1>::reserve_space (const unsigned int new_lines) { -void TriangulationLevel<1>::monitor_memory (const unsigned int true_dimension) const { +void TriangulationLevel<1>::monitor_memory (const unsigned int true_dimension) const +{ // Assert (lines.lines.size() == lines.lines.capacity() || // lines.lines.size()<256, // ExcMemoryWasted ("lines", @@ -487,22 +174,8 @@ void TriangulationLevel<1>::monitor_memory (const unsigned int true_dimension) c -void TriangulationLevel<1>::block_write (ostream &out) const +void TriangulationLevel<2>::reserve_space (const unsigned int new_quads) { - TriangulationLevel<0>::block_write (out); - - write_raw_vector (0, lines.lines, 0, out); - write_rle_vector (0, lines.children, 0, out); - write_raw_vector (0, lines.used, 0, out); - write_raw_vector (0, lines.user_flags, 0, out); - write_rle_vector (0, lines.material_id, 0, out); - // note: user_pointers are not written -}; - - - - -void TriangulationLevel<2>::reserve_space (const unsigned int new_quads) { const unsigned int new_size = new_quads + count_if (quads.used.begin(), quads.used.end(), @@ -538,7 +211,8 @@ void TriangulationLevel<2>::reserve_space (const unsigned int new_quads) { -void TriangulationLevel<2>::monitor_memory (const unsigned int true_dimension) const { +void TriangulationLevel<2>::monitor_memory (const unsigned int true_dimension) const +{ // Assert (quads.quads.size() == quads.quads.capacity() || // quads.quads.size()<256, // ExcMemoryWasted ("quads", @@ -571,24 +245,8 @@ void TriangulationLevel<2>::monitor_memory (const unsigned int true_dimension) c -void TriangulationLevel<2>::block_write (ostream &out) const +void TriangulationLevel<3>::reserve_space (const unsigned int new_hexes) { - TriangulationLevel<1>::block_write (out); - - write_raw_vector (0, quads.quads, 0, out); - write_rle_vector (0, quads.children, 0, out); - write_raw_vector (0, quads.used, 0, out); - write_raw_vector (0, quads.user_flags, 0, out); - write_rle_vector (0, quads.material_id, 0, out); - // note: user_pointers are not written -}; - - - - - - -void TriangulationLevel<3>::reserve_space (const unsigned int new_hexes) { const unsigned int new_size = new_hexes + count_if (hexes.used.begin(), hexes.used.end(), @@ -624,7 +282,8 @@ void TriangulationLevel<3>::reserve_space (const unsigned int new_hexes) { -void TriangulationLevel<3>::monitor_memory (const unsigned int true_dimension) const { +void TriangulationLevel<3>::monitor_memory (const unsigned int true_dimension) const +{ // Assert (hexes.hexes.size() == hexes.hexes.capacity() || // hexes.hexes.size()<256, // ExcMemoryWasted ("hexes", @@ -657,22 +316,6 @@ void TriangulationLevel<3>::monitor_memory (const unsigned int true_dimension) c -void TriangulationLevel<3>::block_write (ostream &out) const -{ - TriangulationLevel<2>::block_write (out); - - write_raw_vector (0, hexes.hexes, 0, out); - write_rle_vector (0, hexes.children, 0, out); - write_raw_vector (0, hexes.used, 0, out); - write_raw_vector (0, hexes.user_flags, 0, out); - write_rle_vector (0, hexes.material_id, 0, out); - // note: user_pointers are not written -}; - - - - - TriaNumberCache<1>::TriaNumberCache () : n_lines (0), n_active_lines (0) diff --git a/deal.II/deal.II/source/grid/tria.cc b/deal.II/deal.II/source/grid/tria.cc index e267510f33..7816b93655 100644 --- a/deal.II/deal.II/source/grid/tria.cc +++ b/deal.II/deal.II/source/grid/tria.cc @@ -214,36 +214,6 @@ void Triangulation::copy_triangulation (const Triangulation &old_tria) -template -void Triangulation::block_write (ostream &out) const -{ - // write out the level information - out << levels.size() << endl << '['; - for (unsigned int level=0; levelblock_write (out); - out << ']'; - - // write out the vertices - out << '['; - out.write (reinterpret_cast(vertices.begin()), - reinterpret_cast(vertices.end()) - - reinterpret_cast(vertices.begin())); - out << ']'; - - write_bool_vector (0, vertices_used, 0, out); -}; - - - -template -void Triangulation::block_read (istream &) -{ - Assert (false, ExcNotImplemented()); -}; - - - - #if deal_II_dimension == 1 template <> -- 2.39.5