From: Bruno Blais Date: Mon, 3 Jul 2023 15:20:15 +0000 (-0400) Subject: Move the save and load function to serial tria X-Git-Tag: relicensing~760^2~2 X-Git-Url: https://gitweb.dealii.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=533c2e9a08f0af366b3ff6ef6be304352b8ebaab;p=dealii.git Move the save and load function to serial tria --- diff --git a/include/deal.II/distributed/tria_base.h b/include/deal.II/distributed/tria_base.h index 6e9f74734f..187389c37c 100644 --- a/include/deal.II/distributed/tria_base.h +++ b/include/deal.II/distributed/tria_base.h @@ -487,16 +487,16 @@ namespace parallel * into this file. Additional cell-based data can be saved using * register_data_attach(). */ - virtual void - save(const std::string &filename) const = 0; + using Triangulation::save; + /** * Load the triangulation saved with save() back in. Cell-based data that * was saved with register_data_attach() can be read in with * notify_ready_to_unpack() after calling load(). */ - virtual void - load(const std::string &filename) = 0; + using Triangulation::load; + /** * @copydoc load() diff --git a/include/deal.II/grid/tria.h b/include/deal.II/grid/tria.h index cd10daeed1..5d26bd6ff6 100644 --- a/include/deal.II/grid/tria.h +++ b/include/deal.II/grid/tria.h @@ -3411,6 +3411,22 @@ public: load(Archive &ar, const unsigned int version); + /** + * Save the triangulation into the given file. Internally, this + * function calls the save funtion which uses BOOST archives. This + * is a placeholder implementation that, in the near future, will also + * attach the data associated with the triangulation + */ + virtual void + save(const std::string &filename) const; + + /** + * Load the triangulation saved with save() back in. + */ + virtual void + load(const std::string &filename); + + /** * Declare the (coarse) face pairs given in the argument of this function as * periodic. This way it is possible to obtain neighbors across periodic diff --git a/source/grid/tria.cc b/source/grid/tria.cc index c568252229..1a1ca15f17 100644 --- a/source/grid/tria.cc +++ b/source/grid/tria.cc @@ -28,9 +28,13 @@ #include #include +#include +#include + #include #include #include +#include #include #include #include @@ -12751,7 +12755,25 @@ void Triangulation::load_user_indices( Assert(false, ExcNotImplemented()); } +template +DEAL_II_CXX20_REQUIRES((concepts::is_valid_dim_spacedim)) +void Triangulation::save(const std::string &filename) const +{ + // Create boost archive then call alternative version of the save function + std::ofstream ofs(filename); + boost::archive::text_oarchive oa(ofs, boost::archive::no_header); + save(oa, 0); +} +template +DEAL_II_CXX20_REQUIRES((concepts::is_valid_dim_spacedim)) +void Triangulation::load(const std::string &filename) +{ + // Create boost archive then call alternative version of the load function + std::ifstream ifs(filename); + boost::archive::text_iarchive ia(ifs, boost::archive::no_header); + load(ia, 0); +} namespace {