aboutsummaryrefslogtreecommitdiff
path: root/CarpetDev
diff options
context:
space:
mode:
authorErik Schnetter <schnetter@aei.mpg.de>2005-05-13 11:25:00 +0000
committerErik Schnetter <schnetter@aei.mpg.de>2005-05-13 11:25:00 +0000
commit5326f24e1a10b0832cbb0bac93f50a7de3114909 (patch)
treea09ee974ee21834b68914bea6fb988044c633bc0 /CarpetDev
parentc3697a07c1256db7185c24750a4d3ca0506436d4 (diff)
CarpetIOF5: Continue development
darcs-hash:20050513112546-891bb-5281cc61d70a2be922fd6b1899d7a06765467ee1.gz
Diffstat (limited to 'CarpetDev')
-rw-r--r--CarpetDev/CarpetIOF5/configuration.ccl2
-rw-r--r--CarpetDev/CarpetIOF5/interface.ccl3
-rw-r--r--CarpetDev/CarpetIOF5/param.ccl54
-rw-r--r--CarpetDev/CarpetIOF5/schedule.ccl5
-rw-r--r--CarpetDev/CarpetIOF5/src/IOF5.cc587
-rw-r--r--CarpetDev/CarpetIOF5/src/coordinate_system.cc11
-rw-r--r--CarpetDev/CarpetIOF5/src/coordinate_system.hh4
-rw-r--r--CarpetDev/CarpetIOF5/src/data_region.cc32
-rw-r--r--CarpetDev/CarpetIOF5/src/data_region.hh8
-rw-r--r--CarpetDev/CarpetIOF5/src/extending.cc99
-rw-r--r--CarpetDev/CarpetIOF5/src/extending.hh41
-rw-r--r--CarpetDev/CarpetIOF5/src/file.cc23
-rw-r--r--CarpetDev/CarpetIOF5/src/file.hh7
-rw-r--r--CarpetDev/CarpetIOF5/src/make.code.defn6
-rw-r--r--CarpetDev/CarpetIOF5/src/physical_quantity.cc18
-rw-r--r--CarpetDev/CarpetIOF5/src/physical_quantity.hh8
-rw-r--r--CarpetDev/CarpetIOF5/src/simulation.cc9
-rw-r--r--CarpetDev/CarpetIOF5/src/simulation.hh4
-rw-r--r--CarpetDev/CarpetIOF5/src/tensor_component.cc9
-rw-r--r--CarpetDev/CarpetIOF5/src/tensor_component.hh4
-rw-r--r--CarpetDev/CarpetIOF5/src/timestep.cc18
-rw-r--r--CarpetDev/CarpetIOF5/src/timestep.hh8
-rw-r--r--CarpetDev/CarpetIOF5/src/topology.cc24
-rw-r--r--CarpetDev/CarpetIOF5/src/topology.hh12
-rw-r--r--CarpetDev/CarpetIOF5/src/utils.cc155
-rw-r--r--CarpetDev/CarpetIOF5/src/utils.hh26
26 files changed, 1059 insertions, 118 deletions
diff --git a/CarpetDev/CarpetIOF5/configuration.ccl b/CarpetDev/CarpetIOF5/configuration.ccl
index b098a4df2..1ab5bc27d 100644
--- a/CarpetDev/CarpetIOF5/configuration.ccl
+++ b/CarpetDev/CarpetIOF5/configuration.ccl
@@ -1,3 +1,3 @@
# Configuration definitions for thorn CarpetIOF5
-REQUIRES CarpetLib HDF5 IOUtil
+REQUIRES Carpet CarpetLib HDF5 IOUtil
diff --git a/CarpetDev/CarpetIOF5/interface.ccl b/CarpetDev/CarpetIOF5/interface.ccl
index a5cfb62ea..2d8dd3139 100644
--- a/CarpetDev/CarpetIOF5/interface.ccl
+++ b/CarpetDev/CarpetIOF5/interface.ccl
@@ -2,7 +2,8 @@
IMPLEMENTS: IOF5
-USES INCLUDE: bbox.hh defs.hh vect.hh
+USES INCLUDE: bbox.hh defs.hh dh.hh vect.hh
+USES INCLUDE: carpet.hh
diff --git a/CarpetDev/CarpetIOF5/param.ccl b/CarpetDev/CarpetIOF5/param.ccl
index 726a09b0d..c05d61922 100644
--- a/CarpetDev/CarpetIOF5/param.ccl
+++ b/CarpetDev/CarpetIOF5/param.ccl
@@ -1,17 +1,61 @@
# Parameter definitions for thorn CarpetIOF5
-STRING out_dir "Output directory, overrides 'IO::out_dir'" STEERABLE = ALWAYS
+SHARES: IO
+
+USES STRING out_dir AS IO_out_dir
+USES KEYWORD out_criterion AS IO_out_criterion
+USES INT out_every AS IO_out_every
+USES REAL out_dt AS IO_out_dt
+
+PRIVATE:
+
+STRING out_dir "Output directory (overrides IO::out_dir)" STEERABLE=always
{
"^$" :: "Empty: use IO::out_dir"
".+" :: "Not empty: directory name"
} ""
-STRING out_extension "File extension for CarpetIOF5 output" STEERABLE = ALWAYS
+STRING out_filename "File name (without extension)" STEERABLE=always
{
- ".*" :: "File extension (including a leading dot, if desired)"
+ "" :: ""
+} "output"
+
+STRING out_extension "File name extension" STEERABLE=always
+{
+ "" :: "File extension (including a leading dot, if desired)"
} ".f5"
-STRING out_vars "Variables and groups which should be output in the F5 file format" STEERABLE = ALWAYS
+STRING out_vars "Variables and groups which should be output in the F5 file format" STEERABLE=always
{
- .* :: "List of group or variable names"
+ "" :: "List of group or variable names"
} ""
+
+KEYWORD out_criterion "Criterion to select CarpetIOHDF5 output intervals" STEERABLE=always
+{
+ "default" :: "Use IO::out_criterion"
+ "always" :: "Always output"
+ "never" :: "Never output"
+ "iteration" :: "Output every so many iterations"
+ "time" :: "Output every that much coordinate time"
+} "default"
+
+INT out_every "How often to do CarpetIOF5 output (overrides IO::out_every)" STEERABLE=always
+{
+ 1:* :: "Output every so many time steps"
+ 0 :: "As often as possible"
+ -1 :: "No output"
+ -2 :: "Use IO::out_every"
+} -2
+
+REAL out_dt "How often to do CarpetIOF5 output (overrides IO::out_dt)" STEERABLE=always
+{
+ (0:* :: "In intervals of that much coordinate time"
+ 0 :: "As often as possible"
+ -1 :: "No output"
+ -2 :: "Use IO::out_dt"
+} -2
+
+REAL dt_fudge "Fudge factor for time comparisons" STEERABLE=always
+{
+ 0:* :: ""
+} 1.0e-8
diff --git a/CarpetDev/CarpetIOF5/schedule.ccl b/CarpetDev/CarpetIOF5/schedule.ccl
index 0d936d041..c729ccccc 100644
--- a/CarpetDev/CarpetIOF5/schedule.ccl
+++ b/CarpetDev/CarpetIOF5/schedule.ccl
@@ -1 +1,6 @@
# Schedule definitions for thorn CarpetIOF5
+
+SCHEDULE CarpetIOF5_Startup AT startup AFTER IOUtil_Startup
+{
+ LANG: C
+} "Startup routine"
diff --git a/CarpetDev/CarpetIOF5/src/IOF5.cc b/CarpetDev/CarpetIOF5/src/IOF5.cc
new file mode 100644
index 000000000..830d986a3
--- /dev/null
+++ b/CarpetDev/CarpetIOF5/src/IOF5.cc
@@ -0,0 +1,587 @@
+#include <algorithm>
+#include <cassert>
+#include <cstdlib>
+#include <sstream>
+#include <vector>
+
+#include "cctk.h"
+#include "cctk_Arguments.h"
+#include "cctk_Parameters.h"
+
+#include "carpet.hh"
+
+#include "coordinate_system.hh"
+#include "data_region.hh"
+#include "extending.hh"
+#include "file.hh"
+#include "physical_quantity.hh"
+#include "simulation.hh"
+#include "tensor_component.hh"
+#include "timestep.hh"
+#include "topology.hh"
+#include "utils.hh"
+
+
+
+namespace CarpetIOF5 {
+
+
+
+ int const Error_none = 0; // no error
+
+ int const Error_illegal_varname = -1;
+ int const Error_group_has_no_storage = -2;
+
+ int const Error_lonely_option_string = -3;
+ int const Error_unterminated_option_string = -4;
+ int const Error_garbage_after_option_string = -5;
+ int const Error_invalid_variable_name = -6;
+
+
+
+ extern "C" int
+ CarpetIOF5_Startup ();
+
+ static void *
+ SetupGH (tFleshConfig * fleshconfig,
+ int convlevel,
+ cGH * cctkGH);
+
+
+
+ static int
+ OutputGH (cGH const * cctkGH);
+
+ static void
+ mark_variables (int variable,
+ char const * options,
+ void * ptr);
+
+
+
+ static int
+ TimeToOutput (cGH const * cctkGH,
+ int variable);
+
+
+
+ static int
+ TriggerOutput (cGH const * cctkGH,
+ int variable);
+
+
+
+ static int
+ OutputVarAs (cGH const * cctkGH,
+ char const * varname,
+ char const * alias);
+
+ static void
+ write_one_mglevel (cGH const * cctkGH,
+ F5::timestep_t & timestep,
+ int group,
+ int variable);
+
+ static void
+ write_one_reflevel (cGH const * cctkGH,
+ F5::simulation_t & simulation,
+ int group,
+ int variable);
+
+ static void
+ write_one_map (cGH const * cctkGH,
+ F5::tensor_component_t & tensor_component,
+ int group);
+
+ static void
+ write_one_component (cGH const * cctkGH,
+ F5::tensor_component_t & tensor_component);
+
+
+
+ static void
+ WriteParameters (F5::file_t & file);
+
+
+
+ extern "C" int
+ CarpetIOF5_Startup ()
+ {
+ int const ierr
+ = CCTK_RegisterBanner ("AMR HDF5 I/O provided by CarpetIOF5");
+ assert (! ierr);
+
+ extending_t::create();
+
+ return 0; // no error
+ }
+
+
+
+ void *
+ SetupGH (tFleshConfig * const fleshconfig,
+ int const convlevel,
+ cGH * const cctkGH)
+ {
+ int ierr;
+ int const io_method = CCTK_RegisterIOMethod ("IOF5");
+ ierr = CCTK_RegisterIOMethodOutputGH (io_method, OutputGH);
+ assert (! ierr);
+ ierr = CCTK_RegisterIOMethodOutputVarAs (io_method, OutputVarAs);
+ assert (! ierr);
+ ierr = CCTK_RegisterIOMethodTimeToOutput (io_method, TimeToOutput);
+ assert (! ierr);
+ ierr = CCTK_RegisterIOMethodTriggerOutput (io_method, TriggerOutput);
+ assert (! ierr);
+
+ return extending_t::setup (fleshconfig, convlevel, cctkGH);
+ }
+
+
+
+ int
+ OutputGH (cGH const * const cctkGH)
+ {
+ DECLARE_CCTK_PARAMETERS;
+
+ assert (cctkGH != 0);
+
+ int ierr;
+
+ vector<bool> want_variables (CCTK_NumVars());
+ ierr
+ = CCTK_TraverseString (out_vars,
+ mark_variables,
+ static_cast<void *> (& want_variables),
+ CCTK_GROUP_OR_VAR);
+ switch (ierr) {
+ case -2: return Error_lonely_option_string;
+ case -3: return Error_unterminated_option_string;
+ case -4: return Error_garbage_after_option_string;
+ case -5: return Error_invalid_variable_name;
+ }
+ assert (ierr >= 0);
+
+ ierr = Error_none;
+ for (int variable = 0; variable < CCTK_NumVars(); ++ variable)
+ {
+ if (want_variables.at(variable))
+ {
+ if (TimeToOutput (cctkGH, variable))
+ {
+ ierr = TriggerOutput (cctkGH, variable);
+ }
+ }
+ }
+
+ return ierr;
+ }
+
+
+
+ void
+ mark_variables (int const variable,
+ char const * const options,
+ void * const ptr)
+ {
+ vector<bool> & want_variables = * static_cast<vector<bool> *> (ptr);
+ want_variables.at (variable) = true;
+ }
+
+
+
+ int
+ TimeToOutput (cGH const * const cctkGH,
+ int const variable)
+ {
+ DECLARE_CCTK_PARAMETERS;
+
+ assert (cctkGH != 0);
+ assert (variable >= 0 and variable < CCTK_NumVars());
+
+ assert (Carpet::is_level_mode());
+ extending_t extending (cctkGH);
+
+ bool should_output;
+
+ char const * const my_out_criterion
+ = (CCTK_EQUALS (out_criterion, "default")
+ ? IO_out_criterion
+ : out_criterion);
+
+ if (CCTK_EQUALS (my_out_criterion, "always"))
+ {
+ should_output = true;
+ }
+ else if (CCTK_EQUALS (my_out_criterion, "never"))
+ {
+ should_output = false;
+ }
+ else if (CCTK_EQUALS (my_out_criterion, "iteration"))
+ {
+ int const last_output_iteration
+ = (extending.get_last_output_iteration
+ (Carpet::mglevel, Carpet::reflevel, variable));
+ int const my_out_every = out_every == -2 ? IO_out_every : out_every;
+ switch (my_out_every)
+ {
+ case 0:
+ should_output = true;
+ break;
+ case -1:
+ should_output = false;
+ break;
+ default:
+ should_output
+ = cctkGH->cctk_iteration >= last_output_iteration + my_out_every;
+ break;
+ }
+ }
+ else if (CCTK_EQUALS (my_out_criterion, "time"))
+ {
+ CCTK_REAL const last_output_time
+ = (extending.get_last_output_time
+ (Carpet::mglevel, Carpet::reflevel, variable));
+ CCTK_REAL const my_out_dt
+ = abs (out_dt - (-2)) <= dt_fudge ? IO_out_dt : out_dt;
+ if (out_dt == 0)
+ {
+ should_output = true;
+ }
+ else if (abs (out_dt - (-1)) <= dt_fudge)
+ {
+ should_output = false;
+ }
+ else
+ {
+ should_output
+ = cctkGH->cctk_time - dt_fudge >= last_output_time + my_out_dt;
+ }
+ }
+ else
+ {
+ CCTK_WARN (1, "internal error");
+ should_output = false;
+ }
+
+ return should_output;
+ }
+
+
+
+ int
+ TriggerOutput (cGH const * const cctkGH,
+ int const variable)
+ {
+ DECLARE_CCTK_PARAMETERS;
+
+ assert (cctkGH != 0);
+ assert (variable >= 0 and variable < CCTK_NumVars());
+
+ char * fullname = CCTK_FullName (variable);
+ assert (fullname);
+
+ int const ierr = OutputVarAs (cctkGH, fullname, out_filename);
+
+ free (fullname);
+
+ assert (Carpet::is_level_mode());
+ extending_t extending (cctkGH);
+ extending.set_last_output_iteration
+ (Carpet::mglevel, Carpet::reflevel, variable, cctkGH->cctk_iteration);
+ extending.set_last_output_time
+ (Carpet::mglevel, Carpet::reflevel, variable, cctkGH->cctk_time);
+
+ return ierr;
+ }
+
+
+
+ int
+ OutputVarAs (cGH const * const cctkGH,
+ char const * const varname,
+ char const * const alias)
+ {
+ DECLARE_CCTK_PARAMETERS;
+
+ assert (cctkGH != 0);
+ assert (varname != 0);
+ assert (alias != 0);
+
+ int const variable = CCTK_VarIndex (varname);
+ if (variable < 0)
+ {
+ return Error_illegal_varname;
+ }
+ assert (variable >= 0 and variable < CCTK_NumVars());
+
+ int const group = CCTK_GroupIndexFromVarI (variable);
+ assert (group >= 0 and group < CCTK_NumGroups());
+
+ if (CCTK_ActiveTimeLevelsGI (cctkGH, group) == 0)
+ {
+ return Error_group_has_no_storage;
+ }
+
+ extending_t extending (cctkGH);
+
+ std::ostringstream filenamebuf;
+ bool const use_IO_out_dir = strcmp (out_dir, "") == 0;
+ filenamebuf << (use_IO_out_dir ? IO_out_dir : out_dir)
+ << "/"
+ << alias
+ << out_extension;
+ char const * const filename = filenamebuf.str().c_str();
+
+ bool const did_truncate = extending.get_did_truncate (filename);
+ bool const do_truncate
+ = ! did_truncate and IO_TruncateOutputFiles (cctkGH);
+ extending.set_did_truncate (filename);
+
+ F5::file_t file (cctkGH, filenamebuf.str().c_str(), do_truncate);
+
+ F5::timestep_t timestep (file, cctkGH->cctk_time);
+
+ if (Carpet::is_meta_mode())
+ {
+ int const grouptype = CCTK_GroupTypeI (group);
+ assert (grouptype >= 0);
+ switch (grouptype)
+ {
+ case CCTK_GF:
+ {
+ for (Carpet::mglevel_iterator mglevel_iter (cctkGH);
+ ! mglevel_iter.done();
+ mglevel_iter.step())
+ {
+ write_one_mglevel (cctkGH, timestep, group, variable);
+ }
+ }
+ break;
+ case CCTK_ARRAY:
+ case CCTK_SCALAR:
+ {
+ Carpet::enter_global_mode (cctkGH, 0);
+ write_one_mglevel (cctkGH, timestep, group, variable);
+ Carpet::leave_global_mode (cctkGH);
+ }
+ break;
+ default:
+ assert (0);
+ }
+ }
+ else
+ {
+ write_one_mglevel (cctkGH, timestep, group, variable);
+ }
+
+ return Error_none;
+ }
+
+
+
+ void
+ write_one_mglevel (cGH const * const cctkGH,
+ F5::timestep_t & timestep,
+ int const group,
+ int const variable)
+ {
+ std::ostringstream namebuf;
+ namebuf << "convlevel " << cctkGH->cctk_convlevel;
+ F5::simulation_t simulation (timestep, namebuf.str().c_str());
+
+ if (grouptype == CCTK_GF and Carpet::is_global_mode())
+ {
+ int const grouptype = CCTK_GroupTypeI (group);
+ assert (grouptype >= 0);
+ switch (grouptype)
+ {
+ case CCTK_GF:
+ {
+ for (Carpet::reflevel_iterator reflevel_iter (cctkGH);
+ ! reflevel_iter.done();
+ reflevel_iter.step())
+ {
+ write_one_reflevel (cctkGH, simulation, group, variable);
+ }
+ }
+ break;
+ case CCTK_ARRAY:
+ case CCTK_SCALAR:
+ {
+ Carpet::enter_level_mode (cctkGH, 0);
+ write_one_reflevel (cctkGH, timestep, group, variable);
+ Carpet::leave_level_mode (cctkGH);
+ }
+ break;
+ default:
+ assert (0);
+ }
+ }
+ else
+ {
+ write_one_reflevel (cctkGH, simulation, group, variable);
+ }
+ }
+
+
+
+ void
+ write_one_reflevel (cGH const * const cctkGH,
+ F5::simulation_t & simulation,
+ int const group,
+ int const variable)
+ {
+ F5::mesh_refinement_topology_t topology
+ (simulation, Carpet::reflevel, Carpet::maxreflevels,
+ Carpet::spacereflevelfact, Carpet::maxspacereflevelfact);
+
+ vect<CCTK_REAL, dim> level_origin, level_delta;
+ for (int d=0; d<dim; ++d)
+ {
+ DECLARE_CCTK_ARGUMENTS;
+ level_origin[d] = CCTK_ORIGIN_SPACE(d);
+ level_delta[d] = CCTK_DELTA_SPACE(d);
+ }
+ F5::Cartesian_coordinate_system_t coordinate_system
+ (topology, level_origin, level_delta);
+
+ F5::physical_quantity_t physical_quantity (coordinate_system, group);
+
+ F5::tensor_component_t tensor_component (physical_quantity, variable);
+
+ if (Carpet::is_level_mode())
+ {
+ int const grouptype = CCTK_GroupTypeI (group);
+ assert (grouptype >= 0);
+
+ for (Carpet::map_iterator map_iter (cctkGH, grouptype);
+ ! map_iter.done();
+ map_iter.step())
+ {
+ write_one_map (cctkGH, tensor_component, group);
+ }
+ }
+ else
+ {
+ write_one_map (cctkGH, tensor_component, group);
+ }
+ }
+
+
+
+ void
+ write_one_map (cGH const * const cctkGH,
+ F5::tensor_component_t & tensor_component,
+ int const group)
+ {
+ if (Carpet::is_singlemap_mode())
+ {
+ int const grouptype = CCTK_GroupTypeI (group);
+ assert (grouptype >= 0);
+
+ for (Carpet::component_iterator component_iter (cctkGH, grouptype);
+ ! component_iter.done();
+ component_iter.step())
+ {
+ write_one_component (cctkGH, tensor_component);
+ }
+ }
+ else
+ {
+ write_one_component (cctkGH, tensor_component);
+ }
+ }
+
+
+
+ void
+ write_one_component (cGH const * const cctkGH,
+ F5::tensor_component_t & tensor_component)
+ {
+ int const variable = tensor_component.get_variable();
+ int const group = tensor_component.get_physical_quantity().get_group();
+
+ dh * const dd = Carpet::arrdata.at(group).at(Carpet::map).dd;
+ bbox<int, dim> const & region
+ = (dd->boxes.at(Carpet::mglevel).at(Carpet::reflevel)
+ .at(Carpet::component).exterior);
+
+ F5::data_region_t data_region (tensor_component, region);
+
+ void const * const varptr = CCTK_VarDataPtrI (cctkGH, 0, variable);
+ assert (varptr != 0);
+ int const vartype = CCTK_VarTypeI (variable);
+ assert (vartype >= 0);
+ data_region.write (varptr, vartype);
+ }
+
+
+
+ void
+ WriteParameters (F5::file_t & file)
+ {
+ hid_t const parameter_group
+ = F5::open_or_create_group (file.get_hdf5_file(), "Cactus parameters");
+
+ int first = 1;
+ for (;;)
+ {
+ cParamData const * parameter_data;
+ char * parameter_fullname;
+
+ int const ierr
+ = CCTK_ParameterWalk (first, 0,
+ & parameter_fullname, & parameter_data);
+ if (ierr > 0) break;
+ assert (ierr >= 0);
+
+ int type;
+ void const * const parameter_value
+ = CCTK_ParameterGet (parameter_data->name, parameter_data->thorn,
+ & type);
+ assert (type == parameter_data->type);
+ assert (parameter_value != 0);
+
+ switch (type)
+ {
+ case PARAMETER_BOOLEAN:
+ case PARAMETER_INT:
+ {
+ CCTK_INT const value
+ = * static_cast<CCTK_INT const *> (parameter_value);
+ F5::write_or_check_attribute
+ (parameter_group, parameter_fullname, value);
+ }
+ break;
+ case PARAMETER_REAL:
+ {
+ CCTK_REAL const value
+ = * static_cast<CCTK_REAL const *> (parameter_value);
+ F5::write_or_check_attribute
+ (parameter_group, parameter_fullname, value);
+ }
+ break;
+ case PARAMETER_KEYWORD:
+ case PARAMETER_STRING:
+ {
+ char const * const value
+ = * static_cast<char const * const *> (parameter_value);
+ F5::write_or_check_attribute
+ (parameter_group, parameter_fullname, value);
+ }
+ break;
+ default:
+ assert (0);
+ }
+
+ free (parameter_fullname);
+
+ first = 0;
+ }
+
+ herr_t const herr = H5Gclose (parameter_group);
+ assert (! herr);
+ }
+
+} // namespace CarpetIOF5
diff --git a/CarpetDev/CarpetIOF5/src/coordinate_system.cc b/CarpetDev/CarpetIOF5/src/coordinate_system.cc
index c0371f0ca..a96ebd94b 100644
--- a/CarpetDev/CarpetIOF5/src/coordinate_system.cc
+++ b/CarpetDev/CarpetIOF5/src/coordinate_system.cc
@@ -28,6 +28,15 @@ namespace CarpetIOF5 {
+ topology_t & coordinate_system_t::
+ get_topology ()
+ const
+ {
+ return m_topology;
+ }
+
+
+
hid_t coordinate_system_t::
get_hdf5_coordinate_system ()
const
@@ -103,7 +112,7 @@ namespace CarpetIOF5 {
{
assert (all (m_level_delta > 0));
- ostringstream buf;
+ std::ostringstream buf;
buf << "Cartesian 3D, x0=" << m_level_origin << ", dx=" << m_level_delta;
char const * const name = buf.str().c_str();
diff --git a/CarpetDev/CarpetIOF5/src/coordinate_system.hh b/CarpetDev/CarpetIOF5/src/coordinate_system.hh
index c0362119e..740a8a86a 100644
--- a/CarpetDev/CarpetIOF5/src/coordinate_system.hh
+++ b/CarpetDev/CarpetIOF5/src/coordinate_system.hh
@@ -31,6 +31,10 @@ namespace CarpetIOF5 {
virtual
~ coordinate_system_t ();
+ topology_t &
+ get_topology ()
+ const;
+
hid_t
get_hdf5_coordinate_system ()
const;
diff --git a/CarpetDev/CarpetIOF5/src/data_region.cc b/CarpetDev/CarpetIOF5/src/data_region.cc
index 77fe28485..6f713911e 100644
--- a/CarpetDev/CarpetIOF5/src/data_region.cc
+++ b/CarpetDev/CarpetIOF5/src/data_region.cc
@@ -32,8 +32,8 @@ namespace CarpetIOF5 {
int const vartype = CCTK_VarTypeI (m_tensor_component.get_variable());
assert (vartype >= 0);
- hid_t const datatype = hdf5_datatype_from_cactus (vartype);
- assert (datatype >= 0);
+ hid_t const hdf5_datatype = hdf5_datatype_from_cactus_datatype (vartype);
+ assert (hdf5_datatype >= 0);
m_properties = H5Pcreate (H5P_DATASET_CREATE);
assert (m_properties >= 0);
@@ -44,7 +44,8 @@ namespace CarpetIOF5 {
assert (m_dataspace >= 0);
m_dataset
- = H5Dcreate (m_dataspace, name, datatype, m_dataspace, m_properties);
+ = H5Dcreate (m_dataspace, name, hdf5_datatype,
+ m_dataspace, m_properties);
assert (m_dataset >= 0);
write_or_check_attribute
@@ -72,14 +73,23 @@ namespace CarpetIOF5 {
- template<typename T>
+ tensor_component_t & data_region_t::
+ get_tensor_component ()
+ const
+ {
+ return m_tensor_component;
+ }
+
+
+
void data_region_t::
- write (T const * const data)
+ write (void const * const data,
+ int const cactus_datatype)
const
{
- T dummy;
- hid_t const memory_datatype = hdf5_datatype (dummy);
- assert (memory_datatype >= 0);
+ hid_t const memory_hdf5_datatype
+ = hdf5_datatype_from_cactus_datatype (cactus_datatype);
+ assert (memory_hdf5_datatype >= 0);
vect<hsize_t, dim> const dims
= (m_region.shape() / m_region.stride()).reverse();
@@ -92,7 +102,7 @@ namespace CarpetIOF5 {
herr_t herr;
herr
- = H5Dwrite (m_dataset, memory_datatype, memory_dataspace,
+ = H5Dwrite (m_dataset, memory_hdf5_datatype, memory_dataspace,
m_dataspace, transfer_properties, data);
assert (! herr);
@@ -103,10 +113,6 @@ namespace CarpetIOF5 {
assert (! herr);
}
- template void data_region_t::write (CCTK_INT const * const data) const;
- template void data_region_t::write (CCTK_REAL const * const data) const;
- template void data_region_t::write (CCTK_COMPLEX const * const data) const;
-
bool data_region_t::
diff --git a/CarpetDev/CarpetIOF5/src/data_region.hh b/CarpetDev/CarpetIOF5/src/data_region.hh
index f7c1713cc..3f08e7c3a 100644
--- a/CarpetDev/CarpetIOF5/src/data_region.hh
+++ b/CarpetDev/CarpetIOF5/src/data_region.hh
@@ -32,9 +32,13 @@ namespace CarpetIOF5 {
virtual
~ data_region_t ();
- template<typename T>
+ tensor_component_t &
+ get_tensor_component ()
+ const;
+
void
- write (T const * data)
+ write (void const * data,
+ int cactus_datatype)
const;
virtual bool
diff --git a/CarpetDev/CarpetIOF5/src/extending.cc b/CarpetDev/CarpetIOF5/src/extending.cc
index 129a96847..ab07491ab 100644
--- a/CarpetDev/CarpetIOF5/src/extending.cc
+++ b/CarpetDev/CarpetIOF5/src/extending.cc
@@ -1,4 +1,5 @@
#include <cassert>
+#include <cstring>
#include "cctk.h"
@@ -8,31 +9,30 @@
namespace CarpetIOF5 {
- char const * const extending::
+ char const * const extending_t::
extension_name = "CarpetIOF5";
- void extending::
- create (cGH * cctkGH)
+ void extending_t::
+ create ()
{
- assert (cctkGH);
int const handle = CCTK_RegisterGHExtension (extension_name);
assert (handle >= 0);
int const ierr = CCTK_RegisterGHExtensionSetupGH (handle, setup);
assert (! ierr);
}
- void * extending::
- setup (tFleshConfig * const config,
+ void * extending_t::
+ setup (tFleshConfig * const fleshconfig,
int const convlevel,
cGH * const cctkGH)
{
- assert (config);
- assert (cctkGH);
+ assert (fleshconfig != 0);
+ assert (cctkGH != 0);
return new extension_t;
}
- extending::
- extending (cGH const * cctkGH)
+ extending_t::
+ extending_t (cGH const * cctkGH)
{
assert (cctkGH);
void * const ext = CCTK_GHExtension (cctkGH, extension_name);
@@ -40,11 +40,82 @@ namespace CarpetIOF5 {
m_extension = static_cast<extension_t *> (ext);
}
- set<char const *> extending::
- get_did_truncate()
+ bool extending_t::
+ get_did_truncate (char const * const name)
const
{
- return m_extension->did_truncate;
+ assert (name != 0);
+ return (m_extension->did_truncate.find (name)
+ != m_extension->did_truncate.end());
}
-
+
+ void extending_t::
+ set_did_truncate (char const * const name)
+ {
+ assert (name != 0);
+ m_extension->did_truncate.insert (strdup (name));
+ }
+
+ int extending_t::
+ get_last_output_iteration (int const ml, int const rl, int const vi)
+ const
+ {
+ resize_last_output (ml, rl, vi, m_extension->last_output_iteration);
+ return m_extension->last_output_iteration.at(ml).at(rl).at(vi);
+ }
+
+ void extending_t::
+ set_last_output_iteration (int const ml, int const rl, int const vi,
+ int const iteration)
+ {
+ resize_last_output (ml, rl, vi, m_extension->last_output_iteration);
+ m_extension->last_output_iteration.at(ml).at(rl).at(vi) = iteration;
+ }
+
+ CCTK_REAL extending_t::
+ get_last_output_time (int const ml, int const rl, int const vi)
+ const
+ {
+ resize_last_output (ml, rl, vi, m_extension->last_output_time);
+ return m_extension->last_output_time.at(ml).at(rl).at(vi);
+ }
+
+ void extending_t::
+ set_last_output_time (int const ml, int const rl, int const vi,
+ CCTK_REAL const time)
+ {
+ resize_last_output (ml, rl, vi, m_extension->last_output_time);
+ m_extension->last_output_time.at(ml).at(rl).at(vi) = time;
+ }
+
+ template<typename T>
+ void extending_t::
+ resize_last_output (int ml, int rl, int vi,
+ vector<vector<vector<T> > > & array)
+ {
+ assert (ml >= 0);
+ if (ml >= array.size())
+ {
+ array.resize (ml+1);
+ }
+ assert (rl >= 0);
+ if (rl >= array.at(ml).size())
+ {
+ array.at(ml).resize (rl+1);
+ }
+ if (vi >= array.at(ml).at(rl).size())
+ {
+ array.at(ml).at(rl).resize (vi+1, -1);
+ }
+ }
+
+ template
+ void extending_t::
+ resize_last_output (int ml, int rl, int vi,
+ vector<vector<vector<int> > > & array);
+ template
+ void extending_t::
+ resize_last_output (int ml, int rl, int vi,
+ vector<vector<vector<CCTK_REAL> > > & array);
+
} // namespace CarpetIOF5
diff --git a/CarpetDev/CarpetIOF5/src/extending.hh b/CarpetDev/CarpetIOF5/src/extending.hh
index 5d25aaabd..55d0d186e 100644
--- a/CarpetDev/CarpetIOF5/src/extending.hh
+++ b/CarpetDev/CarpetIOF5/src/extending.hh
@@ -2,6 +2,7 @@
#define EXTENDING_HH
#include <set>
+#include <vector>
#include "cctk.h"
@@ -10,15 +11,19 @@
namespace CarpetIOF5 {
using std::set;
+ using std::vector;
- class extending {
+ class extending_t {
static char const * const extension_name;
struct extension_t {
set<char const *> did_truncate;
+ // [mglevel][reflevel][variable];
+ vector<vector<vector<int> > > last_output_iteration;
+ vector<vector<vector<CCTK_REAL> > > last_output_time;
};
extension_t * m_extension;
@@ -26,23 +31,43 @@ namespace CarpetIOF5 {
public:
static void
- create (cGH * cctkGH);
-
- private:
+ create ();
static void *
setup (tFleshConfig * config,
int convlevel,
cGH * cctkGH);
- public:
+ extending_t (cGH const * cctkGH);
- extending (cGH const * cctkGH);
+ bool
+ get_did_truncate (char const * name)
+ const;
- set<char const *>
- get_did_truncate ()
+ void
+ set_did_truncate (char const * name);
+
+ int
+ get_last_output_iteration (int ml, int rl, int vi)
const;
+ void
+ set_last_output_iteration (int ml, int rl, int vi, int iteration);
+
+ CCTK_REAL
+ get_last_output_time (int ml, int rl, int vi)
+ const;
+
+ void
+ set_last_output_time (int ml, int rl, int vi, CCTK_REAL time);
+
+ private:
+
+ template<typename T>
+ static void
+ resize_last_output (int ml, int rl, int vi,
+ vector<vector<vector<T> > > & array);
+
};
} // namespace CarpetIOF5
diff --git a/CarpetDev/CarpetIOF5/src/file.cc b/CarpetDev/CarpetIOF5/src/file.cc
index 987592383..0582e2071 100644
--- a/CarpetDev/CarpetIOF5/src/file.cc
+++ b/CarpetDev/CarpetIOF5/src/file.cc
@@ -14,30 +14,22 @@ namespace CarpetIOF5 {
file_t::
file_t (cGH const * const cctkGH,
- char const * const filename)
+ char const * const filename,
+ bool const do_truncate)
: m_cctkGH (cctkGH),
m_filename (filename)
{
assert (cctkGH);
assert (filename);
- extending extension (cctkGH);
-
- bool const should_truncate = IO_TruncateOutputFiles (cctkGH);
-
- bool const did_truncate
- = (extension.get_did_truncate().find (filename)
- != extension.get_did_truncate().end());
-
htri_t is_hdf5 = H5Fis_hdf5 (filename);
assert (is_hdf5 >= 0);
bool const file_exists = is_hdf5 > 0;
- if ((should_truncate and ! did_truncate) or ! file_exists)
+ if (do_truncate or ! file_exists)
{
m_hdf5_file
= H5Fcreate (filename, H5F_ACC_TRUNC, H5P_DEFAULT, H5P_DEFAULT);
- extension.get_did_truncate().insert (filename);
}
else
{
@@ -58,6 +50,15 @@ namespace CarpetIOF5 {
+ cGH const * file_t::
+ get_cctkGH ()
+ const
+ {
+ return m_cctkGH;
+ }
+
+
+
hid_t file_t::
get_hdf5_file()
const
diff --git a/CarpetDev/CarpetIOF5/src/file.hh b/CarpetDev/CarpetIOF5/src/file.hh
index 73c3b8508..042dc9148 100644
--- a/CarpetDev/CarpetIOF5/src/file.hh
+++ b/CarpetDev/CarpetIOF5/src/file.hh
@@ -24,11 +24,16 @@ namespace CarpetIOF5 {
public:
file_t (cGH const * cctkGH,
- char const * filename);
+ char const * filename,
+ bool do_truncate);
virtual
~ file_t ();
+ cGH const *
+ get_cctkGH ()
+ const;
+
hid_t
get_hdf5_file ()
const;
diff --git a/CarpetDev/CarpetIOF5/src/make.code.defn b/CarpetDev/CarpetIOF5/src/make.code.defn
index bed641c27..05dce8360 100644
--- a/CarpetDev/CarpetIOF5/src/make.code.defn
+++ b/CarpetDev/CarpetIOF5/src/make.code.defn
@@ -1,9 +1,11 @@
# Main make.code.defn file for thorn CarpetIOF5
# Source files in this directory
-SRCS = coordinate_system.cc \
+SRCS = IOF5.cc \
+ coordinate_system.cc \
data_region.cc \
- extending.cc file.cc \
+ extending.cc \
+ file.cc \
physical_quantity.cc \
simulation.cc \
tensor_component.cc \
diff --git a/CarpetDev/CarpetIOF5/src/physical_quantity.cc b/CarpetDev/CarpetIOF5/src/physical_quantity.cc
index 0d6640442..fa5fa00d5 100644
--- a/CarpetDev/CarpetIOF5/src/physical_quantity.cc
+++ b/CarpetDev/CarpetIOF5/src/physical_quantity.cc
@@ -45,6 +45,24 @@ namespace CarpetIOF5 {
+ coordinate_system_t & physical_quantity_t::
+ get_coordinate_system ()
+ const
+ {
+ return m_coordinate_system;
+ }
+
+
+
+ int physical_quantity_t::
+ get_group ()
+ const
+ {
+ return m_group;
+ }
+
+
+
hid_t physical_quantity_t::
get_hdf5_physical_quantity ()
const
diff --git a/CarpetDev/CarpetIOF5/src/physical_quantity.hh b/CarpetDev/CarpetIOF5/src/physical_quantity.hh
index 9367c8dd0..0c3982061 100644
--- a/CarpetDev/CarpetIOF5/src/physical_quantity.hh
+++ b/CarpetDev/CarpetIOF5/src/physical_quantity.hh
@@ -27,6 +27,14 @@ namespace CarpetIOF5 {
virtual
~ physical_quantity_t ();
+ coordinate_system_t &
+ get_coordinate_system ()
+ const;
+
+ int
+ get_group ()
+ const;
+
hid_t
get_hdf5_physical_quantity ()
const;
diff --git a/CarpetDev/CarpetIOF5/src/simulation.cc b/CarpetDev/CarpetIOF5/src/simulation.cc
index 7db365ddd..22fe58d57 100644
--- a/CarpetDev/CarpetIOF5/src/simulation.cc
+++ b/CarpetDev/CarpetIOF5/src/simulation.cc
@@ -47,6 +47,15 @@ namespace CarpetIOF5 {
+ timestep_t & simulation_t::
+ get_timestep ()
+ const
+ {
+ return m_timestep;
+ }
+
+
+
hid_t simulation_t::
get_hdf5_simulation()
const
diff --git a/CarpetDev/CarpetIOF5/src/simulation.hh b/CarpetDev/CarpetIOF5/src/simulation.hh
index 33be7c2cf..baf02b725 100644
--- a/CarpetDev/CarpetIOF5/src/simulation.hh
+++ b/CarpetDev/CarpetIOF5/src/simulation.hh
@@ -34,6 +34,10 @@ namespace CarpetIOF5 {
virtual
~ simulation_t ();
+ timestep_t &
+ get_timestep ()
+ const;
+
hid_t
get_hdf5_simulation ()
const;
diff --git a/CarpetDev/CarpetIOF5/src/tensor_component.cc b/CarpetDev/CarpetIOF5/src/tensor_component.cc
index 37d013e18..0741e3265 100644
--- a/CarpetDev/CarpetIOF5/src/tensor_component.cc
+++ b/CarpetDev/CarpetIOF5/src/tensor_component.cc
@@ -44,6 +44,15 @@ namespace CarpetIOF5 {
}
+
+ physical_quantity_t & tensor_component_t::
+ get_physical_quantity ()
+ const
+ {
+ return m_physical_quantity;
+ }
+
+
hid_t tensor_component_t::
get_variable ()
diff --git a/CarpetDev/CarpetIOF5/src/tensor_component.hh b/CarpetDev/CarpetIOF5/src/tensor_component.hh
index 39a8ecf23..cbdb2383f 100644
--- a/CarpetDev/CarpetIOF5/src/tensor_component.hh
+++ b/CarpetDev/CarpetIOF5/src/tensor_component.hh
@@ -27,6 +27,10 @@ namespace CarpetIOF5 {
virtual
~ tensor_component_t ();
+ physical_quantity_t &
+ get_physical_quantity ()
+ const;
+
hid_t
get_variable ()
const;
diff --git a/CarpetDev/CarpetIOF5/src/timestep.cc b/CarpetDev/CarpetIOF5/src/timestep.cc
index ffed82efc..a5ad7b0f9 100644
--- a/CarpetDev/CarpetIOF5/src/timestep.cc
+++ b/CarpetDev/CarpetIOF5/src/timestep.cc
@@ -63,6 +63,24 @@ namespace CarpetIOF5 {
}
+
+ file_t & timestep_t::
+ get_file ()
+ const
+ {
+ return m_file;
+ }
+
+
+
+ CCTK_REAL timestep_t::
+ get_time ()
+ const
+ {
+ return m_time;
+ }
+
+
hid_t timestep_t::
get_hdf5_timestep()
diff --git a/CarpetDev/CarpetIOF5/src/timestep.hh b/CarpetDev/CarpetIOF5/src/timestep.hh
index f02db1916..715759c6d 100644
--- a/CarpetDev/CarpetIOF5/src/timestep.hh
+++ b/CarpetDev/CarpetIOF5/src/timestep.hh
@@ -36,6 +36,14 @@ namespace CarpetIOF5 {
virtual
~ timestep_t ();
+ file_t &
+ get_file ()
+ const;
+
+ CCTK_REAL
+ get_time ()
+ const;
+
hid_t
get_hdf5_timestep ()
const;
diff --git a/CarpetDev/CarpetIOF5/src/topology.cc b/CarpetDev/CarpetIOF5/src/topology.cc
index 20c8c8db7..337e1ca0b 100644
--- a/CarpetDev/CarpetIOF5/src/topology.cc
+++ b/CarpetDev/CarpetIOF5/src/topology.cc
@@ -5,6 +5,9 @@
#include "cctk.h"
+#include "defs.hh"
+#include "vect.hh"
+
#include "topology.hh"
#include "utils.hh"
@@ -29,6 +32,15 @@ namespace CarpetIOF5 {
+ simulation_t & topology_t::
+ get_simulation ()
+ const
+ {
+ return m_simulation;
+ }
+
+
+
hid_t topology_t::
get_hdf5_topology()
const
@@ -83,8 +95,8 @@ namespace CarpetIOF5 {
mesh_refinement_topology_t (simulation_t & simulation,
int const refinement_level,
int const max_refinement_levels,
- int const level_refinement_factor,
- int const max_refinement_factor)
+ vect<int, dim> const & level_refinement_factor,
+ vect<int, dim> const & max_refinement_factor)
: topology_t (simulation),
m_refinement_level (refinement_level),
m_max_refinement_levels (max_refinement_levels),
@@ -93,8 +105,8 @@ namespace CarpetIOF5 {
{
assert (refinement_level >= 0);
assert (refinement_level < max_refinement_levels);
- assert (level_refinement_factor > 0);
- assert (level_refinement_factor <= max_refinement_factor);
+ assert (all (level_refinement_factor > 0));
+ assert (all (level_refinement_factor <= max_refinement_factor));
ostringstream buf;
buf << "Vertices level " << refinement_level;
@@ -147,8 +159,8 @@ namespace CarpetIOF5 {
return (topology_t::invariant()
and m_refinement_level >= 0
and m_refinement_level < m_max_refinement_levels
- and m_level_refinement_factor > 0
- and m_level_refinement_factor <= m_max_refinement_factor);
+ and all (m_level_refinement_factor > 0)
+ and all (m_level_refinement_factor <= m_max_refinement_factor));
}
} // namespace F5
diff --git a/CarpetDev/CarpetIOF5/src/topology.hh b/CarpetDev/CarpetIOF5/src/topology.hh
index 13e879e89..8f9399f51 100644
--- a/CarpetDev/CarpetIOF5/src/topology.hh
+++ b/CarpetDev/CarpetIOF5/src/topology.hh
@@ -33,6 +33,10 @@ namespace CarpetIOF5 {
public:
+ simulation_t &
+ get_simulation ()
+ const;
+
hid_t
get_hdf5_topology ()
const;
@@ -65,16 +69,16 @@ namespace CarpetIOF5 {
int const m_refinement_level;
int const m_max_refinement_levels;
- int const m_level_refinement_factor;
- int const m_max_refinement_factor;
+ vect<int, dim> const m_level_refinement_factor;
+ vect<int, dim> const m_max_refinement_factor;
public:
mesh_refinement_topology_t (simulation_t & simulation,
int refinement_level,
int max_refinement_levels,
- int level_refinement_factor,
- int max_refinement_factor);
+ vect<int, dim> const & level_refinement_factors,
+ vect<int, dim> const & max_refinement_factors);
void
calculate_level_origin_delta (vect<CCTK_REAL, dim> const & coarse_origin,
diff --git a/CarpetDev/CarpetIOF5/src/utils.cc b/CarpetDev/CarpetIOF5/src/utils.cc
index 6bd4c4b0e..4102e36c5 100644
--- a/CarpetDev/CarpetIOF5/src/utils.cc
+++ b/CarpetDev/CarpetIOF5/src/utils.cc
@@ -1,5 +1,6 @@
#include <cassert>
#include <complex>
+#include <cstring>
#include <vector>
#include <hdf5.h>
@@ -22,80 +23,80 @@ namespace CarpetIOF5 {
hid_t
- hdf5_datatype (signed char const & dummy)
+ hdf5_datatype_from_dummy (signed char const & dummy)
{
return H5T_NATIVE_SCHAR;
}
hid_t
- hdf5_datatype (short const & dummy)
+ hdf5_datatype_from_dummy (short const & dummy)
{
return H5T_NATIVE_SHORT;
}
hid_t
- hdf5_datatype (int const & dummy)
+ hdf5_datatype_from_dummy (int const & dummy)
{
return H5T_NATIVE_INT;
}
hid_t
- hdf5_datatype (long const & dummy)
+ hdf5_datatype_from_dummy (long const & dummy)
{
return H5T_NATIVE_LONG;
}
hid_t
- hdf5_datatype (long long const & dummy)
+ hdf5_datatype_from_dummy (long long const & dummy)
{
return H5T_NATIVE_LLONG;
}
hid_t
- hdf5_datatype (float const & dummy)
+ hdf5_datatype_from_dummy (float const & dummy)
{
return H5T_NATIVE_FLOAT;
}
hid_t
- hdf5_datatype (double const & dummy)
+ hdf5_datatype_from_dummy (double const & dummy)
{
return H5T_NATIVE_DOUBLE;
}
hid_t
- hdf5_datatype (long double const & dummy)
+ hdf5_datatype_from_dummy (long double const & dummy)
{
return H5T_NATIVE_LDOUBLE;
}
hid_t
- hdf5_datatype (CCTK_COMPLEX8 const & dummy)
+ hdf5_datatype_from_dummy (CCTK_COMPLEX8 const & dummy)
{
CCTK_REAL4 real;
- return hdf5_complex_datatype (dummy, real);
+ return hdf5_complex_datatype_from_dummy (dummy, real);
}
hid_t
- hdf5_datatype (CCTK_COMPLEX16 const & dummy)
+ hdf5_datatype_from_dummy (CCTK_COMPLEX16 const & dummy)
{
CCTK_REAL8 real;
- return hdf5_complex_datatype (dummy, real);
+ return hdf5_complex_datatype_from_dummy (dummy, real);
}
hid_t
- hdf5_datatype (CCTK_COMPLEX32 const & dummy)
+ hdf5_datatype_from_dummy (CCTK_COMPLEX32 const & dummy)
{
CCTK_REAL16 real;
- return hdf5_complex_datatype (dummy, real);
+ return hdf5_complex_datatype_from_dummy (dummy, real);
}
template<typename T, typename R>
hid_t
- hdf5_complex_datatype (T const & dummy, R const & real)
+ hdf5_complex_datatype_from_dummy (T const & dummy, R const & real)
{
static bool initialised = false;
- static hid_t hdf_complex;
+ static hid_t hdf_complex_datatype;
if (! initialised)
{
@@ -104,34 +105,44 @@ namespace CarpetIOF5 {
hsize_t const dim = 2;
int const perm = 0;
- hdf_complex = H5Tarray_create (hdf5_datatype (real), 1, & dim, & perm);
- assert (hdf_complex >= 0);
+ hdf_complex_datatype
+ = H5Tarray_create (hdf5_datatype_from_dummy (real),
+ 1, & dim, & perm);
+ assert (hdf_complex_datatype >= 0);
}
- return hdf_complex;
+ return hdf_complex_datatype;
}
hid_t
- hdf5_datatype_from_cactus (int const cactus_type)
+ hdf5_datatype_from_cactus_datatype (int const cactus_datatype)
{
- switch (cactus_type) {
+ switch (cactus_datatype) {
case CCTK_VARIABLE_VOID : return H5I_INVALID_HID;
- case CCTK_VARIABLE_BYTE : { CCTK_BYTE const dummy = 0; return hdf5_datatype (dummy); }
- case CCTK_VARIABLE_INT : { CCTK_INT const dummy = 0; return hdf5_datatype (dummy); }
- case CCTK_VARIABLE_INT1 : { CCTK_INT1 const dummy = 0; return hdf5_datatype (dummy); }
- case CCTK_VARIABLE_INT2 : { CCTK_INT2 const dummy = 0; return hdf5_datatype (dummy); }
- case CCTK_VARIABLE_INT4 : { CCTK_INT4 const dummy = 0; return hdf5_datatype (dummy); }
- case CCTK_VARIABLE_INT8 : { CCTK_INT8 const dummy = 0; return hdf5_datatype (dummy); }
- case CCTK_VARIABLE_REAL : { CCTK_REAL const dummy = 0; return hdf5_datatype (dummy); }
- case CCTK_VARIABLE_REAL4 : { CCTK_REAL4 const dummy = 0; return hdf5_datatype (dummy); }
- case CCTK_VARIABLE_REAL8 : { CCTK_REAL8 const dummy = 0; return hdf5_datatype (dummy); }
- case CCTK_VARIABLE_REAL16 : { CCTK_REAL16 const dummy = 0; return hdf5_datatype (dummy); }
- case CCTK_VARIABLE_COMPLEX : { CCTK_COMPLEX dummy ; return hdf5_datatype (dummy); }
- case CCTK_VARIABLE_COMPLEX8 : { CCTK_COMPLEX8 dummy ; return hdf5_datatype (dummy); }
- case CCTK_VARIABLE_COMPLEX16: { CCTK_COMPLEX16 dummy ; return hdf5_datatype (dummy); }
- case CCTK_VARIABLE_COMPLEX32: { CCTK_COMPLEX32 dummy ; return hdf5_datatype (dummy); }
+#define CASE(TYPEID, TYPE) \
+ case TYPEID: \
+ { \
+ TYPE dummy; \
+ return hdf5_datatype_from_dummy (dummy); \
+ } \
+ break
+ CASE (CCTK_VARIABLE_BYTE , CCTK_BYTE );
+ CASE (CCTK_VARIABLE_INT , CCTK_INT );
+ CASE (CCTK_VARIABLE_INT1 , CCTK_INT1 );
+ CASE (CCTK_VARIABLE_INT2 , CCTK_INT2 );
+ CASE (CCTK_VARIABLE_INT4 , CCTK_INT4 );
+ CASE (CCTK_VARIABLE_INT8 , CCTK_INT8 );
+ CASE (CCTK_VARIABLE_REAL , CCTK_REAL );
+ CASE (CCTK_VARIABLE_REAL4 , CCTK_REAL4 );
+ CASE (CCTK_VARIABLE_REAL8 , CCTK_REAL8 );
+ CASE (CCTK_VARIABLE_REAL16 , CCTK_REAL16 );
+ CASE (CCTK_VARIABLE_COMPLEX , CCTK_COMPLEX );
+ CASE (CCTK_VARIABLE_COMPLEX8 , CCTK_COMPLEX8 );
+ CASE (CCTK_VARIABLE_COMPLEX16, CCTK_COMPLEX16);
+ CASE (CCTK_VARIABLE_COMPLEX32, CCTK_COMPLEX32);
+#undef CASE
case CCTK_VARIABLE_CHAR : return H5I_INVALID_HID;
case CCTK_VARIABLE_STRING : return H5I_INVALID_HID;
case CCTK_VARIABLE_POINTER : return H5I_INVALID_HID;
@@ -185,7 +196,7 @@ namespace CarpetIOF5 {
assert (num_values == 0 or values != 0);
T dummy;
- hid_t const datatype = hdf5_datatype (dummy);
+ hid_t const datatype = hdf5_datatype_from_dummy (dummy);
hid_t attribute;
H5E_BEGIN_TRY {
@@ -297,6 +308,78 @@ namespace CarpetIOF5 {
write_or_check_attribute (hid_t where,
char const * name,
vect<CCTK_REAL, dim> const & value);
+
+
+
+ template<>
+ void
+ write_or_check_attribute (hid_t const where,
+ char const * const name,
+ char const * const & value)
+ {
+ assert (where >= 0);
+ assert (name != 0);
+ assert (value != 0);
+
+ hid_t attribute;
+ H5E_BEGIN_TRY {
+ attribute = H5Aopen_name (where, name);
+ } H5E_END_TRY;
+
+ if (attribute < 0)
+ {
+ // The attribute does not yet exist; create it
+ hid_t const datatype = H5Tcopy (H5T_C_S1);
+ assert (datatype >= 0);
+ herr_t herr;
+ int const length = strlen (value) + 1;
+ herr = H5Tset_size (datatype, length);
+ assert (! herr);
+ 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);
+ assert (attribute >= 0);
+ herr = H5Awrite (attribute, datatype, value);
+ assert (! herr);
+ herr = H5Aclose (attribute);
+ assert (! herr);
+ herr = H5Sclose (dataspace);
+ assert (! herr);
+ herr = H5Tclose (datatype);
+ assert (! herr);
+ }
+ else
+ {
+ // The attribute already exists; read and check it
+ hid_t datatype = H5Aget_type (attribute);
+ assert (datatype >= 0);
+ hid_t typeclass = H5Tget_class (datatype);
+ assert (typeclass == H5T_STRING);
+ int const length = H5Tget_size (datatype);
+ assert (length >= 0);
+ hid_t const dataspace = H5Aget_space (attribute);
+ htri_t const is_simple = H5Sis_simple (dataspace);
+ assert (is_simple >= 0);
+ assert (is_simple > 0);
+ int const ndims = H5Sget_simple_extent_ndims (dataspace);
+ assert (ndims == 1);
+ hsize_t dim;
+ herr_t herr;
+ herr = H5Sget_simple_extent_dims (dataspace, & dim, 0);
+ assert (dim == 1);
+ vector<char> buf (length);
+ herr = H5Aread (attribute, datatype, & buf.front());
+ assert (! herr);
+ herr = H5Sclose (dataspace);
+ assert (! herr);
+ herr = H5Aclose (attribute);
+ assert (! herr);
+ herr = H5Tclose (datatype);
+ assert (! herr);
+ assert (strcmp (& buf.front(), value) == 0);
+ }
+ }
} // namespace F5
diff --git a/CarpetDev/CarpetIOF5/src/utils.hh b/CarpetDev/CarpetIOF5/src/utils.hh
index 28b6e044f..910328aae 100644
--- a/CarpetDev/CarpetIOF5/src/utils.hh
+++ b/CarpetDev/CarpetIOF5/src/utils.hh
@@ -14,34 +14,34 @@ namespace CarpetIOF5 {
namespace F5 {
hid_t
- hdf5_datatype (signed char const & dummy);
+ hdf5_datatype_from_dummy (signed char const & dummy);
hid_t
- hdf5_datatype (short const & dummy);
+ hdf5_datatype_from_dummy (short const & dummy);
hid_t
- hdf5_datatype (int const & dummy);
+ hdf5_datatype_from_dummy (int const & dummy);
hid_t
- hdf5_datatype (long const & dummy);
+ hdf5_datatype_from_dummy (long const & dummy);
hid_t
- hdf5_datatype (long long const & dummy);
+ hdf5_datatype_from_dummy (long long const & dummy);
hid_t
- hdf5_datatype (float const & dummy);
+ hdf5_datatype_from_dummy (float const & dummy);
hid_t
- hdf5_datatype (double const & dummy);
+ hdf5_datatype_from_dummy (double const & dummy);
hid_t
- hdf5_datatype (long double const & dummy);
+ hdf5_datatype_from_dummy (long double const & dummy);
hid_t
- hdf5_datatype (CCTK_COMPLEX8 const & dummy);
+ hdf5_datatype_from_dummy (CCTK_COMPLEX8 const & dummy);
hid_t
- hdf5_datatype (CCTK_COMPLEX16 const & dummy);
+ hdf5_datatype_from_dummy (CCTK_COMPLEX16 const & dummy);
hid_t
- hdf5_datatype (CCTK_COMPLEX32 const & dummy);
+ hdf5_datatype_from_dummy (CCTK_COMPLEX32 const & dummy);
template<typename T, typename R>
hid_t
- hdf5_complex_datatype (T const & dummy, R const & real);
+ hdf5_complex_datatype_from_dummy (T const & dummy, R const & real);
hid_t
- hdf5_datatype_from_cactus (int cactus_type);
+ hdf5_datatype_from_cactus_datatype (int cactus_datatype);