From: wolf Date: Mon, 16 Aug 1999 11:07:01 +0000 (+0000) Subject: Add a class which can handle the history of a triangulation and rebuild it accordingly. X-Git-Url: https://gitweb.dealii.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=0e0a6a2441a5617513adfcbf609219db677a69d4;p=dealii-svn.git Add a class which can handle the history of a triangulation and rebuild it accordingly. git-svn-id: https://svn.dealii.org/trunk@1697 0785d39b-7218-0410-832d-ea1e28bc413d --- diff --git a/deal.II/deal.II/include/grid/persistent_tria.h b/deal.II/deal.II/include/grid/persistent_tria.h new file mode 100644 index 0000000000..4904a63d6c --- /dev/null +++ b/deal.II/deal.II/include/grid/persistent_tria.h @@ -0,0 +1,130 @@ +/*---------------------------- persistent_tria.h ---------------------------*/ +/* $Id$ */ +#ifndef __persistent_tria_H +#define __persistent_tria_H +/*---------------------------- persistent_tria.h ---------------------------*/ + + +#include +#include +#include + + +template +class PersistentTriangulation : public Triangulation +{ + public: + /** + * Build up the triangulation from the + * coarse grid in future. Copy smoothing + * flags, etc from that grid as well. + * Note that the initial state of the + * triangulation is empty, unless + * #restore_grid# is called for the + * first time. + * + * The coarse grid must persist until + * the end of this object, since it will + * be used upon reconstruction of the + * grid. + */ + PersistentTriangulation (const Triangulation &coarse_grid); + + /** + * Destructor. + */ + virtual ~PersistentTriangulation (); + + /** + * Overloaded version of the same + * function in the base class which + * stores the refinement and coarsening + * flags for later reconstruction of the + * triangulation and after that calls + * the respective function of the + * base class. + */ + virtual void execute_coarsening_and_refinement (); + + /** + * Restore the grid according to the saved + * data. For this, the coarse grid is + * copied and the grid is stepwise + * rebuilt using the saved flags. + */ + void restore_grid (); + + /** + * Overload this function to use + * #tria# as a new coarse grid. The + * present triangulation and all + * refinement and coarsening flags + * storing its history are deleted, + * and the state of the underlying + * triangulation is reset to be + * empty, until #restore_grid# is + * called the next time. + * + * The coarse grid must persist until + * the end of this object, since it will + * be used upon reconstruction of the + * grid. + */ + virtual void copy_triangulation (const Triangulation &tria); + + /** + * Throw an error, since this function + * is not useful in the context of this + * class. + */ + virtual void block_write (ostream &out) const; + + /** + * Throw an error, since this function + * is not useful in the context of this + * class. + */ + virtual void block_read (istream &in); + + /** + * Throw an error, since this function + * is not useful in the context of this + * class. + */ + virtual void create_triangulation (const vector > &vertices, + const vector > &cells, + const SubCellData &subcelldata); + + /** + * Exception. + */ + DeclException0 (ExcFunctionNotUseful); + + private: + /** + * This grid shall be used as coarse + * grid. + */ + SmartPointer > coarse_grid; + + /** + * Vectors holding the refinement and + * coarsening flags of the different + * sweeps on this time level. The + * vectors therefore hold the history + * of the grid. + */ + vector > refine_flags; + + /** + * @see refine_flags + */ + vector > coarsen_flags; +}; + + + +/*---------------------------- persistent_tria.h ---------------------------*/ +/* end of #ifndef __persistent_tria_H */ +#endif +/*---------------------------- persistent_tria.h ---------------------------*/ diff --git a/deal.II/deal.II/source/grid/persistent_tria.cc b/deal.II/deal.II/source/grid/persistent_tria.cc new file mode 100644 index 0000000000..96bc214f1c --- /dev/null +++ b/deal.II/deal.II/source/grid/persistent_tria.cc @@ -0,0 +1,103 @@ +/* $Id$ */ + +#include + + +template +PersistentTriangulation:: +PersistentTriangulation (const Triangulation &coarse_grid) : + coarse_grid (&coarse_grid) +{}; + + + +template +PersistentTriangulation::~PersistentTriangulation () +{}; + + + +template +void +PersistentTriangulation::execute_coarsening_and_refinement () +{ + // first save flags + refine_flags.push_back (vector()); + coarsen_flags.push_back (vector()); + save_refine_flags (refine_flags.back()); + save_coarsen_flags (coarsen_flags.back()); + + // then refine triangulation + Triangulation::execute_coarsening_and_refinement (); +}; + + + +template +void +PersistentTriangulation::restore_grid () { + // copy the old triangulation. + // this will yield an error if the + // underlying triangulation was not + // empty + Triangulation::copy_triangulation (*coarse_grid); + + // for each of the previous refinement + // sweeps + for (unsigned int i=0; i::execute_coarsening_and_refinement (); + }; +}; + + + +template +void +PersistentTriangulation::copy_triangulation (const Triangulation &old_grid) +{ + clear (); + coarse_grid = &old_grid; + refine_flags.clear (); + coarsen_flags.clear (); +}; + + + +template +void +PersistentTriangulation::block_write (ostream &) const +{ + Assert (false, ExcFunctionNotUseful()); +}; + + + +template +void +PersistentTriangulation::block_read (istream &) +{ + Assert (false, ExcFunctionNotUseful()); +}; + + + +template +void +PersistentTriangulation::create_triangulation (const vector > &, + const vector > &, + const SubCellData &) +{ + Assert (false, ExcFunctionNotUseful()); +}; + + + + +// explicit instantiations +template class PersistentTriangulation; +