From 8d4e2e1413bfa77ce220f42b442eefbfc2f2776f Mon Sep 17 00:00:00 2001 From: Erik Schnetter Date: Tue, 15 Jan 2008 19:22:00 +0000 Subject: CarpetIOF5: Write a meta-file containing an inventory In addition to one data file per processor, also write out one meta-data file containing an inventory and external links to the other files. Compiles. Untested. darcs-hash:20080115192202-dae7b-e709063fdbe7d545389cdcb40846a10451e9f4c1.gz --- CarpetDev/CarpetIOF5/src/IOF5.cc | 42 ++------ CarpetDev/CarpetIOF5/src/README | 2 + CarpetDev/CarpetIOF5/src/coordinate_system.cc | 21 ++++ CarpetDev/CarpetIOF5/src/coordinate_system.hh | 7 ++ CarpetDev/CarpetIOF5/src/data_region.cc | 19 +++- CarpetDev/CarpetIOF5/src/data_region.hh | 3 + CarpetDev/CarpetIOF5/src/file.cc | 136 +++++++++++++++++++++++++- CarpetDev/CarpetIOF5/src/file.hh | 43 +++++++- CarpetDev/CarpetIOF5/src/make.code.defn | 1 + CarpetDev/CarpetIOF5/src/meta_data_region.cc | 90 +++++++++++++++++ CarpetDev/CarpetIOF5/src/meta_data_region.hh | 57 +++++++++++ CarpetDev/CarpetIOF5/src/physical_quantity.cc | 22 ++++- CarpetDev/CarpetIOF5/src/physical_quantity.hh | 6 ++ CarpetDev/CarpetIOF5/src/simulation.cc | 20 ++++ CarpetDev/CarpetIOF5/src/simulation.hh | 5 + CarpetDev/CarpetIOF5/src/tensor_component.cc | 22 ++++- CarpetDev/CarpetIOF5/src/tensor_component.hh | 7 ++ CarpetDev/CarpetIOF5/src/timestep.cc | 20 ++++ CarpetDev/CarpetIOF5/src/timestep.hh | 5 + CarpetDev/CarpetIOF5/src/topology.cc | 23 ++++- CarpetDev/CarpetIOF5/src/topology.hh | 13 +++ CarpetDev/CarpetIOF5/src/utils.cc | 20 ++-- CarpetDev/CarpetIOF5/src/utils.hh | 4 +- CarpetDev/CarpetIOF5/src/writer.cc | 76 +++++++++----- CarpetDev/CarpetIOF5/src/writer.hh | 18 ++-- 25 files changed, 597 insertions(+), 85 deletions(-) create mode 100644 CarpetDev/CarpetIOF5/src/meta_data_region.cc create mode 100644 CarpetDev/CarpetIOF5/src/meta_data_region.hh (limited to 'CarpetDev') diff --git a/CarpetDev/CarpetIOF5/src/IOF5.cc b/CarpetDev/CarpetIOF5/src/IOF5.cc index 83389906a..c21332adb 100644 --- a/CarpetDev/CarpetIOF5/src/IOF5.cc +++ b/CarpetDev/CarpetIOF5/src/IOF5.cc @@ -2,6 +2,7 @@ #include #include #include +#include #include #include #include @@ -57,9 +58,6 @@ namespace CarpetIOF5 { char const * options, void * ptr); - static int - base_10_digits (int number); - static int @@ -180,21 +178,6 @@ namespace CarpetIOF5 { - int - base_10_digits (int number) - { - number = abs (number); - int digits = 1; - while (number >= 10) - { - number /= 10; - ++ digits; - } - return digits; - } - - - int TimeToOutput (cGH const * const cctkGH, int const variable) @@ -386,23 +369,18 @@ namespace CarpetIOF5 { extending_t extending (cctkGH); - ostringstream filenamebuf; - bool const use_IO_out_dir = strcmp (out_dir, "") == 0; - int const digits = base_10_digits (CCTK_nProcs (cctkGH) - 1); - filenamebuf << (use_IO_out_dir ? IO_out_dir : out_dir) - << "/" - << alias - << "." - << setw (digits) << setfill ('0') << CCTK_MyProc (cctkGH) - << out_extension; - string const filename = filenamebuf.str(); - - bool const did_truncate = extending.get_did_truncate (filename); + bool const use_IO_out_dir = std::strcmp (out_dir, "") == 0; + string const basename + = (use_IO_out_dir ? IO_out_dir : out_dir) + string ("/") + alias; + bool const want_metafile = CCTK_MyProc (cctkGH) == 0; + + bool const did_truncate = extending.get_did_truncate (basename); bool const do_truncate = not did_truncate and IO_TruncateOutputFiles (cctkGH); - extending.set_did_truncate (filename); + extending.set_did_truncate (basename); - F5::file_t file (cctkGH, filename, do_truncate); + F5::file_t file (cctkGH, basename, string (out_extension), + want_metafile, do_truncate); writer_t writer (cctkGH, variable); writer.write (file); diff --git a/CarpetDev/CarpetIOF5/src/README b/CarpetDev/CarpetIOF5/src/README index 758b31bfa..8b51edf63 100644 --- a/CarpetDev/CarpetIOF5/src/README +++ b/CarpetDev/CarpetIOF5/src/README @@ -11,3 +11,5 @@ An F5 file contains the following hierarchy: 2006-06-05: Werner says that tensor_component and data_region should be interchanged. + +2007-04-25: Werner confirms this. diff --git a/CarpetDev/CarpetIOF5/src/coordinate_system.cc b/CarpetDev/CarpetIOF5/src/coordinate_system.cc index 49c023921..bb5b6808f 100644 --- a/CarpetDev/CarpetIOF5/src/coordinate_system.cc +++ b/CarpetDev/CarpetIOF5/src/coordinate_system.cc @@ -117,6 +117,7 @@ namespace CarpetIOF5 { namebuf << "Cartesian 3D, x0=" << m_level_origin << ", dx=" << m_level_delta; string const namestr = namebuf.str(); + m_name = namestr; char const * const name = namestr.c_str(); m_hdf5_coordinate_system @@ -131,6 +132,26 @@ namespace CarpetIOF5 { + void coordinate_system_t:: + get_link_destination (string & filename, + string & objectname) + const + { + static bool initialised = false; + static string l_filename; + static string l_objectname; + if (not initialised) + { + initialised = true; + get_topology().get_link_destination (l_filename, l_objectname); + l_objectname += string ("/") + m_name; + } + filename = l_filename; + objectname = l_objectname; + } + + + bool Cartesian_coordinate_system_t:: invariant () const diff --git a/CarpetDev/CarpetIOF5/src/coordinate_system.hh b/CarpetDev/CarpetIOF5/src/coordinate_system.hh index 06c93603e..3a36a458a 100644 --- a/CarpetDev/CarpetIOF5/src/coordinate_system.hh +++ b/CarpetDev/CarpetIOF5/src/coordinate_system.hh @@ -26,6 +26,8 @@ namespace CarpetIOF5 { topology_t & m_topology; + string m_name; + hid_t m_hdf5_coordinate_system; coordinate_system_t (topology_t & topology); @@ -43,6 +45,11 @@ namespace CarpetIOF5 { get_hdf5_coordinate_system () const; + void + get_link_destination (string & filename, + string & objectname) + const; + virtual bool invariant () const; diff --git a/CarpetDev/CarpetIOF5/src/data_region.cc b/CarpetDev/CarpetIOF5/src/data_region.cc index bee5a070c..7a68a66b9 100644 --- a/CarpetDev/CarpetIOF5/src/data_region.cc +++ b/CarpetDev/CarpetIOF5/src/data_region.cc @@ -8,7 +8,6 @@ #include "carpet.hh" #include "data_region.hh" -#include "utils.hh" @@ -54,7 +53,8 @@ namespace CarpetIOF5 { m_dataset = H5Dcreate (m_tensor_component.get_hdf5_tensor_component(), name, - hdf5_datatype, m_dataspace, m_properties); + hdf5_datatype, m_dataspace, + H5P_DEFAULT, m_properties, H5P_DEFAULT); assert (m_dataset >= 0); write_or_check_attribute @@ -82,6 +82,21 @@ namespace CarpetIOF5 { + string data_region_t:: + name_from_region (bbox const & region) + { + ostringstream namebuf; +#if 0 + namebuf << "map=" << Carpet::map << " " + << "region=" << region; +#else + namebuf << "region=" << region; +#endif + return namebuf.str(); + } + + + tensor_component_t & data_region_t:: get_tensor_component () const diff --git a/CarpetDev/CarpetIOF5/src/data_region.hh b/CarpetDev/CarpetIOF5/src/data_region.hh index 9b354166a..d40a88e7e 100644 --- a/CarpetDev/CarpetIOF5/src/data_region.hh +++ b/CarpetDev/CarpetIOF5/src/data_region.hh @@ -36,6 +36,9 @@ namespace CarpetIOF5 { virtual ~ data_region_t (); + static string + name_from_region (bbox const & region); + tensor_component_t & get_tensor_component () const; diff --git a/CarpetDev/CarpetIOF5/src/file.cc b/CarpetDev/CarpetIOF5/src/file.cc index bf6167e5a..55c00a124 100644 --- a/CarpetDev/CarpetIOF5/src/file.cc +++ b/CarpetDev/CarpetIOF5/src/file.cc @@ -1,4 +1,8 @@ +#include #include +#include +#include +#include #include #include @@ -13,16 +17,27 @@ namespace CarpetIOF5 { namespace F5 { + using namespace std; + file_t:: file_t (cGH const * const cctkGH, - string const filename, + string const basename, + string const extension, + bool const want_metafile, bool const do_truncate) : m_cctkGH (cctkGH), - m_filename (filename) + m_have_metafile (want_metafile), + m_basename (basename), + m_extension (extension) { assert (cctkGH); - char const * const filenameptr = filename.c_str(); + int const proc = CCTK_MyProc (cctkGH); + m_metafilename = make_metafilename (); + m_filename = make_filename (proc); + + char const * const metafilenameptr = m_metafilename.c_str(); + char const * const filenameptr = m_filename.c_str(); htri_t is_hdf5; H5E_BEGIN_TRY { @@ -30,16 +45,34 @@ namespace CarpetIOF5 { } H5E_END_TRY; bool const file_exists = is_hdf5 > 0; + // Ignore the metafile when determining whether the file already + // exists if (do_truncate or not file_exists) { + m_hdf5_metafile = -1; + if (m_have_metafile) + { + m_hdf5_metafile + = H5Fcreate (metafilenameptr, + H5F_ACC_TRUNC, H5P_DEFAULT, H5P_DEFAULT); + } m_hdf5_file = H5Fcreate (filenameptr, H5F_ACC_TRUNC, H5P_DEFAULT, H5P_DEFAULT); } else { + m_hdf5_metafile = -1; + if (m_have_metafile) + { + m_hdf5_metafile + = H5Fopen (metafilenameptr, H5F_ACC_RDWR, H5P_DEFAULT); + } m_hdf5_file = H5Fopen (filenameptr, H5F_ACC_RDWR, H5P_DEFAULT); } + m_filenames.resize (CCTK_nProcs (cctkGH)); + m_filenames.at(proc) = m_filename; + assert (invariant()); } @@ -48,12 +81,56 @@ namespace CarpetIOF5 { file_t:: ~ file_t() { + if (m_have_metafile) + { + herr_t const herr = H5Fclose (m_hdf5_metafile); + assert (not herr); + } herr_t const herr = H5Fclose (m_hdf5_file); assert (not herr); } + int file_t:: + base_10_digits (int number) + { + number = abs (number); + int digits = 1; + while (number >= 10) + { + number /= 10; + ++ digits; + } + return digits; + } + + + + string file_t:: + make_metafilename () + const + { + return m_basename + m_extension; + } + + + + string file_t:: + make_filename (int const proc) + const + { + int const digits = base_10_digits (CCTK_nProcs (m_cctkGH) - 1); + ostringstream filenamebuf; + filenamebuf << m_basename + << "." + << setw (digits) << setfill ('0') << proc + << m_extension; + return filenamebuf.str(); + } + + + cGH const * file_t:: get_cctkGH () const @@ -63,6 +140,38 @@ namespace CarpetIOF5 { + bool file_t:: + get_have_metafile () + const + { + return m_have_metafile; + } + + + + string file_t:: + get_filename (int const proc) + const + { + assert (proc >= 0 and proc < CCTK_nProcs (m_cctkGH)); + if (m_filenames.at(proc).empty()) + { + m_filenames.at(proc) = make_filename (proc); + } + return m_filenames.at(proc); + } + + + + hid_t file_t:: + get_hdf5_metafile() + const + { + return m_hdf5_metafile; + } + + + hid_t file_t:: get_hdf5_file() const @@ -72,11 +181,32 @@ namespace CarpetIOF5 { + void file_t:: + get_link_destination (string & filename, + string & objectname) + const + { + static bool initialised = false; + static string l_filename; + static string l_objectname; + if (not initialised) + { + initialised = true; + l_filename = m_filename; + l_objectname = string (""); + } + filename = l_filename; + objectname = l_objectname; + } + + + bool file_t:: invariant() const { return (m_cctkGH != 0 + and (not m_have_metafile or m_hdf5_metafile >= 0) and m_hdf5_file >= 0); } diff --git a/CarpetDev/CarpetIOF5/src/file.hh b/CarpetDev/CarpetIOF5/src/file.hh index b5ac2d696..66d9f0334 100644 --- a/CarpetDev/CarpetIOF5/src/file.hh +++ b/CarpetDev/CarpetIOF5/src/file.hh @@ -2,6 +2,7 @@ #define FILE_HH #include +#include #include @@ -14,6 +15,7 @@ namespace CarpetIOF5 { using std::string; + using std::vector; @@ -23,18 +25,40 @@ namespace CarpetIOF5 { cGH const * const m_cctkGH; - string const m_filename; + bool const m_have_metafile; + string const m_basename; + string const m_extension; + + string m_metafilename; + string m_filename; + + mutable vector m_filenames; + + hid_t m_hdf5_metafile; hid_t m_hdf5_file; file_t (); file_t (file_t const &); file_t operator= (file_t const &); + static int + base_10_digits (int number); + + string + make_metafilename () + const; + + string + make_filename (int proc) + const; + public: file_t (cGH const * cctkGH, string filename, + string extension, + bool want_metafile, bool do_truncate); virtual @@ -44,10 +68,27 @@ namespace CarpetIOF5 { get_cctkGH () const; + bool + get_have_metafile () + const; + + string + get_filename (int proc) + const; + + hid_t + get_hdf5_metafile () + const; + hid_t get_hdf5_file () const; + void + get_link_destination (string & filename, + string & objectname) + const; + virtual bool invariant () const; diff --git a/CarpetDev/CarpetIOF5/src/make.code.defn b/CarpetDev/CarpetIOF5/src/make.code.defn index d0a45f9d8..0641b4f9d 100644 --- a/CarpetDev/CarpetIOF5/src/make.code.defn +++ b/CarpetDev/CarpetIOF5/src/make.code.defn @@ -6,6 +6,7 @@ SRCS = IOF5.cc \ data_region.cc \ extending.cc \ file.cc \ + meta_data_region.cc \ physical_quantity.cc \ simulation.cc \ tensor_component.cc \ diff --git a/CarpetDev/CarpetIOF5/src/meta_data_region.cc b/CarpetDev/CarpetIOF5/src/meta_data_region.cc new file mode 100644 index 000000000..4f32e33a2 --- /dev/null +++ b/CarpetDev/CarpetIOF5/src/meta_data_region.cc @@ -0,0 +1,90 @@ +#include +#include +#include +#include + +#include "cctk.h" + +#include "carpet.hh" + +#include "data_region.hh" +#include "meta_data_region.hh" +#include "utils.hh" + + + +namespace CarpetIOF5 { + + namespace F5 { + + using std::ostringstream; + + + + meta_data_region_t:: + meta_data_region_t (tensor_component_t & tensor_component, + bbox const & region) + : m_tensor_component (tensor_component), + m_region (region) + { + assert (not region.empty()); + + string const namestr = data_region_t::name_from_region (region); + char const * const name = namestr.c_str(); + assert (name != 0); + + assert (invariant()); + } + + + + meta_data_region_t:: + ~ meta_data_region_t () + { + } + + + + tensor_component_t & meta_data_region_t:: + get_tensor_component () + const + { + return m_tensor_component; + } + + + + void meta_data_region_t:: + write (int const proc) + const + { + string filename; + string objectname; + get_tensor_component().get_link_destination (filename, objectname); + + string const name = data_region_t::name_from_region (m_region); + + hid_t const hdf5_tensor_component + = m_tensor_component.get_hdf5_tensor_component(); + + herr_t const herr + = H5Lcreate_external(filename.c_str(), + objectname.c_str(), + hdf5_tensor_component, + name.c_str(), + H5P_DEFAULT, H5P_DEFAULT); + assert (not herr); + } + + + + bool meta_data_region_t:: + invariant () + const + { + return not m_region.empty(); + } + + } // namespace F5 + +} // namespace CarpetIOF5 diff --git a/CarpetDev/CarpetIOF5/src/meta_data_region.hh b/CarpetDev/CarpetIOF5/src/meta_data_region.hh new file mode 100644 index 000000000..b109c5da4 --- /dev/null +++ b/CarpetDev/CarpetIOF5/src/meta_data_region.hh @@ -0,0 +1,57 @@ +#ifndef META_DATA_REGION_HH +#define META_DATA_REGION_HH + +#include + +#include "bbox.hh" +#include "defs.hh" + +#include "tensor_component.hh" + + + +namespace CarpetIOF5 { + + namespace F5 { + + class meta_data_region_t { + + tensor_component_t & m_tensor_component; + + bbox const m_region; + + hid_t m_properties; + hid_t m_dataset; + hid_t m_dataspace; + + meta_data_region_t (); + meta_data_region_t (meta_data_region_t const &); + meta_data_region_t operator= (meta_data_region_t const &); + + public: + + meta_data_region_t (tensor_component_t & tensor_component, + bbox const & region); + + virtual + ~ meta_data_region_t (); + + tensor_component_t & + get_tensor_component () + const; + + void + write (int proc) + const; + + virtual bool + invariant () + const; + + }; + + } // namespace F5 + +} // namespace CarpetIOF5 + +#endif // #ifndef META_DATA_REGION_HH diff --git a/CarpetDev/CarpetIOF5/src/physical_quantity.cc b/CarpetDev/CarpetIOF5/src/physical_quantity.cc index 2c4a24d65..0b6720ece 100644 --- a/CarpetDev/CarpetIOF5/src/physical_quantity.cc +++ b/CarpetDev/CarpetIOF5/src/physical_quantity.cc @@ -4,7 +4,6 @@ #include "cctk.h" #include "physical_quantity.hh" -#include "utils.hh" @@ -26,6 +25,7 @@ namespace CarpetIOF5 { { * p = static_cast (tolower (* p)); } + m_name = string (name); m_hdf5_physical_quantity = open_or_create_group (m_coordinate_system @@ -76,6 +76,26 @@ namespace CarpetIOF5 { + void physical_quantity_t:: + get_link_destination (string & filename, + string & objectname) + const + { + static bool initialised = false; + static string l_filename; + static string l_objectname; + if (not initialised) + { + initialised = true; + get_coordinate_system().get_link_destination (l_filename, l_objectname); + l_objectname += string ("/") + m_name; + } + filename = l_filename; + objectname = l_objectname; + } + + + bool physical_quantity_t:: invariant () const diff --git a/CarpetDev/CarpetIOF5/src/physical_quantity.hh b/CarpetDev/CarpetIOF5/src/physical_quantity.hh index 56f768799..38b670cb2 100644 --- a/CarpetDev/CarpetIOF5/src/physical_quantity.hh +++ b/CarpetDev/CarpetIOF5/src/physical_quantity.hh @@ -16,6 +16,7 @@ namespace CarpetIOF5 { coordinate_system_t & m_coordinate_system; int const m_group; + string m_name; hid_t m_hdf5_physical_quantity; @@ -43,6 +44,11 @@ namespace CarpetIOF5 { get_hdf5_physical_quantity () const; + void + get_link_destination (string & filename, + string & objectname) + const; + virtual bool invariant () const; diff --git a/CarpetDev/CarpetIOF5/src/simulation.cc b/CarpetDev/CarpetIOF5/src/simulation.cc index 10441b498..98a0a3888 100644 --- a/CarpetDev/CarpetIOF5/src/simulation.cc +++ b/CarpetDev/CarpetIOF5/src/simulation.cc @@ -60,6 +60,26 @@ namespace CarpetIOF5 { + void simulation_t:: + get_link_destination (string & filename, + string & objectname) + const + { + static bool initialised = false; + static string l_filename; + static string l_objectname; + if (not initialised) + { + initialised = true; + get_timestep().get_link_destination (l_filename, l_objectname); + l_objectname += string ("/") + m_name; + } + filename = l_filename; + objectname = l_objectname; + } + + + bool simulation_t:: invariant() const diff --git a/CarpetDev/CarpetIOF5/src/simulation.hh b/CarpetDev/CarpetIOF5/src/simulation.hh index 7aed7ca11..272b3385c 100644 --- a/CarpetDev/CarpetIOF5/src/simulation.hh +++ b/CarpetDev/CarpetIOF5/src/simulation.hh @@ -46,6 +46,11 @@ namespace CarpetIOF5 { get_hdf5_simulation () const; + void + get_link_destination (string & filename, + string & objectname) + const; + virtual bool invariant () const; diff --git a/CarpetDev/CarpetIOF5/src/tensor_component.cc b/CarpetDev/CarpetIOF5/src/tensor_component.cc index c1575f232..5d4b281fc 100644 --- a/CarpetDev/CarpetIOF5/src/tensor_component.cc +++ b/CarpetDev/CarpetIOF5/src/tensor_component.cc @@ -4,7 +4,6 @@ #include "cctk.h" #include "tensor_component.hh" -#include "utils.hh" @@ -22,6 +21,7 @@ namespace CarpetIOF5 { char const * const name = CCTK_VarName (variable); assert (name != 0); + m_name = string (name); m_hdf5_tensor_component = open_or_create_group (m_physical_quantity @@ -70,6 +70,26 @@ namespace CarpetIOF5 { + void tensor_component_t:: + get_link_destination (string & filename, + string & objectname) + const + { + static bool initialised = false; + static string l_filename; + static string l_objectname; + if (not initialised) + { + initialised = true; + get_physical_quantity().get_link_destination (l_filename, l_objectname); + l_objectname += string ("/") + m_name; + } + filename = l_filename; + objectname = l_objectname; + } + + + bool tensor_component_t:: invariant () const diff --git a/CarpetDev/CarpetIOF5/src/tensor_component.hh b/CarpetDev/CarpetIOF5/src/tensor_component.hh index 8377983a7..f659c0076 100644 --- a/CarpetDev/CarpetIOF5/src/tensor_component.hh +++ b/CarpetDev/CarpetIOF5/src/tensor_component.hh @@ -4,6 +4,7 @@ #include #include "physical_quantity.hh" +#include "utils.hh" @@ -16,6 +17,7 @@ namespace CarpetIOF5 { physical_quantity_t & m_physical_quantity; int const m_variable; + string m_name; hid_t m_hdf5_tensor_component; @@ -43,6 +45,11 @@ namespace CarpetIOF5 { get_hdf5_tensor_component () const; + void + get_link_destination (string & filename, + string & objectname) + const; + virtual bool invariant () const; diff --git a/CarpetDev/CarpetIOF5/src/timestep.cc b/CarpetDev/CarpetIOF5/src/timestep.cc index e7b75c4fe..73d106a92 100644 --- a/CarpetDev/CarpetIOF5/src/timestep.cc +++ b/CarpetDev/CarpetIOF5/src/timestep.cc @@ -99,6 +99,26 @@ namespace CarpetIOF5 { + void timestep_t:: + get_link_destination (string & filename, + string & objectname) + const + { + static bool initialised = false; + static string l_filename; + static string l_objectname; + if (not initialised) + { + initialised = true; + get_file().get_link_destination (l_filename, l_objectname); + l_objectname += string ("/") + m_name; + } + filename = l_filename; + objectname = l_objectname; + } + + + bool timestep_t:: invariant() const diff --git a/CarpetDev/CarpetIOF5/src/timestep.hh b/CarpetDev/CarpetIOF5/src/timestep.hh index 203cb6683..3a44ec29b 100644 --- a/CarpetDev/CarpetIOF5/src/timestep.hh +++ b/CarpetDev/CarpetIOF5/src/timestep.hh @@ -52,6 +52,11 @@ namespace CarpetIOF5 { get_hdf5_timestep () const; + void + get_link_destination (string & filename, + string & objectname) + const; + virtual bool invariant () const; diff --git a/CarpetDev/CarpetIOF5/src/topology.cc b/CarpetDev/CarpetIOF5/src/topology.cc index a3558448e..401f65271 100644 --- a/CarpetDev/CarpetIOF5/src/topology.cc +++ b/CarpetDev/CarpetIOF5/src/topology.cc @@ -9,7 +9,6 @@ #include "vect.hh" #include "topology.hh" -#include "utils.hh" @@ -64,6 +63,7 @@ namespace CarpetIOF5 { : topology_t (simulation) { char const * const name = "Vertices"; + m_name = string (name); m_hdf5_topology = open_or_create_group (m_simulation.get_hdf5_simulation(), name); assert (m_hdf5_topology >= 0); @@ -112,6 +112,7 @@ namespace CarpetIOF5 { ostringstream namebuf; namebuf << "Vertices map=" << map << " level=" << refinement_level; string const namestr = namebuf.str(); + m_name = namestr; char const * const name = namestr.c_str(); m_hdf5_topology @@ -155,6 +156,26 @@ namespace CarpetIOF5 { + void topology_t:: + get_link_destination (string & filename, + string & objectname) + const + { + static bool initialised = false; + static string l_filename; + static string l_objectname; + if (not initialised) + { + initialised = true; + get_simulation().get_link_destination (l_filename, l_objectname); + l_objectname += string ("/") + m_name; + } + filename = l_filename; + objectname = l_objectname; + } + + + bool mesh_refinement_topology_t:: invariant() const diff --git a/CarpetDev/CarpetIOF5/src/topology.hh b/CarpetDev/CarpetIOF5/src/topology.hh index 2e97ff255..df841107b 100644 --- a/CarpetDev/CarpetIOF5/src/topology.hh +++ b/CarpetDev/CarpetIOF5/src/topology.hh @@ -9,6 +9,7 @@ #include "vect.hh" #include "simulation.hh" +#include "utils.hh" @@ -26,6 +27,8 @@ namespace CarpetIOF5 { simulation_t & m_simulation; + string m_name; + hid_t m_hdf5_topology; topology_t (simulation_t & simulation); @@ -41,6 +44,11 @@ namespace CarpetIOF5 { get_simulation () const; + void + get_link_destination (string & filename, + string & objectname) + const; + hid_t get_hdf5_topology () const; @@ -106,6 +114,11 @@ namespace CarpetIOF5 { virtual ~ mesh_refinement_topology_t (); + void + get_link_destination (string & filename, + string & objectname) + const; + virtual bool invariant () const; diff --git a/CarpetDev/CarpetIOF5/src/utils.cc b/CarpetDev/CarpetIOF5/src/utils.cc index 6bad1510a..b1efb21ed 100644 --- a/CarpetDev/CarpetIOF5/src/utils.cc +++ b/CarpetDev/CarpetIOF5/src/utils.cc @@ -108,12 +108,10 @@ namespace CarpetIOF5 { { initialised = true; - hsize_t const cdim = 2; - int const perm = 0; + hsize_t const cdim[1] = { 2 }; hdf_complex_datatype - = H5Tarray_create (hdf5_datatype_from_dummy (real), - 1, & cdim, & perm); + = H5Tarray_create (hdf5_datatype_from_dummy (real), 1, cdim); assert (hdf_complex_datatype >= 0); } @@ -197,11 +195,11 @@ namespace CarpetIOF5 { hid_t group; if (group_exists) { - group = H5Gopen (where, name); + group = H5Gopen (where, name, H5P_DEFAULT); } else { - group = H5Gcreate (where, name, 0); + group = H5Gcreate (where, name, H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT); } return group; @@ -235,7 +233,8 @@ namespace CarpetIOF5 { hsize_t const adim = num_values; hid_t const dataspace = H5Screate_simple (1, & adim, & adim); assert (dataspace >= 0); - attribute = H5Acreate (where, name, datatype, dataspace, H5P_DEFAULT); + attribute = H5Acreate (where, name, datatype, dataspace, + H5P_DEFAULT, H5P_DEFAULT); assert (attribute >= 0); herr_t herr; herr = H5Awrite (attribute, datatype, values); @@ -257,7 +256,7 @@ namespace CarpetIOF5 { hsize_t adim; herr_t herr; herr = H5Sget_simple_extent_dims (dataspace, & adim, 0); - assert (adim == num_values); + assert (adim == hsize_t (num_values)); vector buf (adim); herr = H5Aread (attribute, datatype, & buf.front()); assert (not herr); @@ -386,7 +385,8 @@ namespace CarpetIOF5 { hsize_t const dim = 1; hid_t const dataspace = H5Screate_simple (1, & dim, & dim); assert (dataspace >= 0); - attribute = H5Acreate (where, name, datatype, dataspace, H5P_DEFAULT); + attribute = H5Acreate (where, name, datatype, dataspace, + H5P_DEFAULT, H5P_DEFAULT); assert (attribute >= 0); herr = H5Awrite (attribute, datatype, value); assert (not herr); @@ -428,7 +428,7 @@ namespace CarpetIOF5 { assert (strcmp (& buf.front(), value) == 0); } } - + } // namespace F5 } // namespace CarpetIOF5 diff --git a/CarpetDev/CarpetIOF5/src/utils.hh b/CarpetDev/CarpetIOF5/src/utils.hh index 0c7869b68..c379cc775 100644 --- a/CarpetDev/CarpetIOF5/src/utils.hh +++ b/CarpetDev/CarpetIOF5/src/utils.hh @@ -1,5 +1,5 @@ -#ifndef utils_HH -#define utils_HH +#ifndef UTILS_HH +#define UTILS_HH #include diff --git a/CarpetDev/CarpetIOF5/src/writer.cc b/CarpetDev/CarpetIOF5/src/writer.cc index f7aa3d05a..e4ef100f6 100644 --- a/CarpetDev/CarpetIOF5/src/writer.cc +++ b/CarpetDev/CarpetIOF5/src/writer.cc @@ -8,6 +8,7 @@ #include "data_region.hh" #include "file.hh" +#include "meta_data_region.hh" #include "simulation.hh" #include "tensor_component.hh" #include "timestep.hh" @@ -32,13 +33,14 @@ namespace CarpetIOF5 { write (F5::file_t & file) const { - write_meta (file); + write_meta (file, file.get_have_metafile()); } void writer_t:: - write_meta (F5::file_t & file) + write_meta (F5::file_t & file, + bool const have_metafile) const { DECLARE_CCTK_PARAMETERS; @@ -57,19 +59,20 @@ namespace CarpetIOF5 { not mglevel_iter.done(); mglevel_iter.step()) { - write_one_mglevel (timestep); + write_one_mglevel (timestep, have_metafile); } } else { - write_one_mglevel (timestep); + write_one_mglevel (timestep, have_metafile); } } void writer_t:: - write_one_mglevel (F5::timestep_t & timestep) + write_one_mglevel (F5::timestep_t & timestep, + bool const have_metafile) const { DECLARE_CCTK_PARAMETERS; @@ -96,7 +99,7 @@ namespace CarpetIOF5 { { if (Carpet::do_global_mode) { - write_global (simulation); + write_global (simulation, have_metafile); } } break; @@ -108,12 +111,12 @@ namespace CarpetIOF5 { not reflevel_iter.done(); reflevel_iter.step()) { - write_one_reflevel (simulation); + write_one_reflevel (simulation, have_metafile); } } else { - write_one_reflevel (simulation); + write_one_reflevel (simulation, have_metafile); } } break; @@ -125,7 +128,8 @@ namespace CarpetIOF5 { void writer_t:: - write_global (F5::simulation_t & simulation) + write_global (F5::simulation_t & simulation, + bool const have_metafile) const { DECLARE_CCTK_PARAMETERS; @@ -163,8 +167,15 @@ namespace CarpetIOF5 { bbox const & region = dd->boxes.at(Carpet::mglevel).at(reflevel).at(myproc).exterior; - F5::data_region_t data_region (tensor_component, region); + if (have_metafile) + { + F5::meta_data_region_t meta_data_region (tensor_component, region); + gh * const hh = Carpet::vhh.at(Carpet::map); + int const proc = hh->processor (Carpet::reflevel, Carpet::component); + meta_data_region.write (proc); + } + F5::data_region_t data_region (tensor_component, region); int const timelevel = 0; void const * const varptr = CCTK_VarDataPtrI (m_cctkGH, timelevel, m_variable); @@ -177,7 +188,8 @@ namespace CarpetIOF5 { void writer_t:: - write_one_reflevel (F5::simulation_t & simulation) + write_one_reflevel (F5::simulation_t & simulation, + bool const have_metafile) const { DECLARE_CCTK_PARAMETERS; @@ -199,19 +211,20 @@ namespace CarpetIOF5 { not map_iter.done(); map_iter.step()) { - write_one_map (simulation); + write_one_map (simulation, have_metafile); } } else { - write_one_map (simulation); + write_one_map (simulation, have_metafile); } } void writer_t:: - write_one_map (F5::simulation_t & simulation) + write_one_map (F5::simulation_t & simulation, + bool const have_metafile) const { DECLARE_CCTK_PARAMETERS; @@ -252,19 +265,20 @@ namespace CarpetIOF5 { not component_iter.done(); component_iter.step()) { - write_one_component (tensor_component); + write_one_component (tensor_component, have_metafile); } } else { - write_one_component (tensor_component); + write_one_component (tensor_component, have_metafile); } } void writer_t:: - write_one_component (F5::tensor_component_t & tensor_component) + write_one_component (F5::tensor_component_t & tensor_component, + bool const have_metafile) const { DECLARE_CCTK_PARAMETERS; @@ -277,22 +291,32 @@ namespace CarpetIOF5 { } gh * const hh = Carpet::vhh.at(Carpet::map); - if (hh->is_local (Carpet::reflevel, Carpet::component)) + bool const is_local = hh->is_local (Carpet::reflevel, Carpet::component); + if (have_metafile or is_local) { dh * const dd = Carpet::vdd.at(Carpet::map); bbox const & region = (dd->boxes.at(Carpet::mglevel).at(Carpet::reflevel) .at(Carpet::component).exterior); - F5::data_region_t data_region (tensor_component, region); + if (have_metafile) + { + F5::meta_data_region_t meta_data_region (tensor_component, region); + int const proc = hh->processor (Carpet::reflevel, Carpet::component); + meta_data_region.write (proc); + } - int const timelevel = 0; - void const * const varptr - = CCTK_VarDataPtrI (m_cctkGH, timelevel, m_variable); - assert (varptr != 0); - int const vartype = CCTK_VarTypeI (m_variable); - assert (vartype >= 0); - data_region.write (varptr, vartype); + if (is_local) + { + F5::data_region_t data_region (tensor_component, region); + int const timelevel = 0; + void const * const varptr + = CCTK_VarDataPtrI (m_cctkGH, timelevel, m_variable); + assert (varptr != 0); + int const vartype = CCTK_VarTypeI (m_variable); + assert (vartype >= 0); + data_region.write (varptr, vartype); + } } } diff --git a/CarpetDev/CarpetIOF5/src/writer.hh b/CarpetDev/CarpetIOF5/src/writer.hh index 8b8473f1e..056d39a3f 100644 --- a/CarpetDev/CarpetIOF5/src/writer.hh +++ b/CarpetDev/CarpetIOF5/src/writer.hh @@ -30,27 +30,33 @@ namespace CarpetIOF5 { private: void - write_meta (F5::file_t & file) + write_meta (F5::file_t & file, + bool have_metafile) const; void - write_one_mglevel (F5::timestep_t & timestep) + write_one_mglevel (F5::timestep_t & timestep, + bool have_metafile) const; void - write_global (F5::simulation_t & simulation) + write_global (F5::simulation_t & simulation, + bool have_metafile) const; void - write_one_reflevel (F5::simulation_t & simulation) + write_one_reflevel (F5::simulation_t & simulation, + bool have_metafile) const; void - write_one_map (F5::simulation_t & simulation) + write_one_map (F5::simulation_t & simulation, + bool have_metafile) const; void - write_one_component (F5::tensor_component_t & tensor_component) + write_one_component (F5::tensor_component_t & tensor_component, + bool have_metafile) const; }; -- cgit v1.2.3