From 533c2e9a08f0af366b3ff6ef6be304352b8ebaab Mon Sep 17 00:00:00 2001 From: Bruno Blais Date: Mon, 3 Jul 2023 11:20:15 -0400 Subject: [PATCH] Move the save and load function to serial tria --- include/deal.II/distributed/tria_base.h | 8 ++++---- include/deal.II/grid/tria.h | 16 ++++++++++++++++ source/grid/tria.cc | 22 ++++++++++++++++++++++ 3 files changed, 42 insertions(+), 4 deletions(-) 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 { -- 2.39.5