aboutsummaryrefslogtreecommitdiff
path: root/CarpetDev
diff options
context:
space:
mode:
authorErik Schnetter <schnetter@aei.mpg.de>2005-05-14 11:53:00 +0000
committerErik Schnetter <schnetter@aei.mpg.de>2005-05-14 11:53:00 +0000
commita86ebe0c9aa5a6227b49bbefca4886ba3d4a823d (patch)
tree1330bb75815cce0cc0c0d9f1671bbbfc893d92e1 /CarpetDev
parent5326f24e1a10b0832cbb0bac93f50a7de3114909 (diff)
CarpetIOF5: More development
darcs-hash:20050514115336-891bb-a65eca247e30c35b99c6d5a6c98b759489372276.gz
Diffstat (limited to 'CarpetDev')
-rw-r--r--CarpetDev/CarpetIOF5/param.ccl2
-rw-r--r--CarpetDev/CarpetIOF5/schedule.ccl2
-rw-r--r--CarpetDev/CarpetIOF5/src/IOF5.cc311
-rw-r--r--CarpetDev/CarpetIOF5/src/README10
-rw-r--r--CarpetDev/CarpetIOF5/src/coordinate_system.cc9
-rw-r--r--CarpetDev/CarpetIOF5/src/coordinate_system.hh9
-rw-r--r--CarpetDev/CarpetIOF5/src/data_region.cc12
-rw-r--r--CarpetDev/CarpetIOF5/src/data_region.hh4
-rw-r--r--CarpetDev/CarpetIOF5/src/extending.cc91
-rw-r--r--CarpetDev/CarpetIOF5/src/extending.hh41
-rw-r--r--CarpetDev/CarpetIOF5/src/file.cc17
-rw-r--r--CarpetDev/CarpetIOF5/src/file.hh14
-rw-r--r--CarpetDev/CarpetIOF5/src/physical_quantity.hh4
-rw-r--r--CarpetDev/CarpetIOF5/src/simulation.cc9
-rw-r--r--CarpetDev/CarpetIOF5/src/simulation.hh6
-rw-r--r--CarpetDev/CarpetIOF5/src/tensor_component.cc4
-rw-r--r--CarpetDev/CarpetIOF5/src/tensor_component.hh4
-rw-r--r--CarpetDev/CarpetIOF5/src/timestep.hh4
-rw-r--r--CarpetDev/CarpetIOF5/src/topology.cc9
-rw-r--r--CarpetDev/CarpetIOF5/src/topology.hh13
-rw-r--r--CarpetDev/CarpetIOF5/src/utils.cc42
-rw-r--r--CarpetDev/CarpetIOF5/src/utils.hh6
22 files changed, 403 insertions, 220 deletions
diff --git a/CarpetDev/CarpetIOF5/param.ccl b/CarpetDev/CarpetIOF5/param.ccl
index c05d61922..1fae1f165 100644
--- a/CarpetDev/CarpetIOF5/param.ccl
+++ b/CarpetDev/CarpetIOF5/param.ccl
@@ -58,4 +58,4 @@ REAL out_dt "How often to do CarpetIOF5 output (overrides IO::out_dt)" STEERABLE
REAL dt_fudge "Fudge factor for time comparisons" STEERABLE=always
{
0:* :: ""
-} 1.0e-8
+} 1.0e-12
diff --git a/CarpetDev/CarpetIOF5/schedule.ccl b/CarpetDev/CarpetIOF5/schedule.ccl
index c729ccccc..91f484a74 100644
--- a/CarpetDev/CarpetIOF5/schedule.ccl
+++ b/CarpetDev/CarpetIOF5/schedule.ccl
@@ -1,5 +1,7 @@
# Schedule definitions for thorn CarpetIOF5
+STORAGE: next_output_iteration next_output_time this_iteration
+
SCHEDULE CarpetIOF5_Startup AT startup AFTER IOUtil_Startup
{
LANG: C
diff --git a/CarpetDev/CarpetIOF5/src/IOF5.cc b/CarpetDev/CarpetIOF5/src/IOF5.cc
index 830d986a3..79cff030a 100644
--- a/CarpetDev/CarpetIOF5/src/IOF5.cc
+++ b/CarpetDev/CarpetIOF5/src/IOF5.cc
@@ -2,6 +2,7 @@
#include <cassert>
#include <cstdlib>
#include <sstream>
+#include <string>
#include <vector>
#include "cctk.h"
@@ -43,9 +44,9 @@ namespace CarpetIOF5 {
CarpetIOF5_Startup ();
static void *
- SetupGH (tFleshConfig * fleshconfig,
- int convlevel,
- cGH * cctkGH);
+ Setup (tFleshConfig * const fleshconfig,
+ int const convlevel,
+ cGH * const cctkGH);
@@ -83,6 +84,12 @@ namespace CarpetIOF5 {
int variable);
static void
+ write_global (cGH const * cctkGH,
+ F5::simulation_t & simulation,
+ int group,
+ int variable);
+
+ static void
write_one_reflevel (cGH const * cctkGH,
F5::simulation_t & simulation,
int group,
@@ -104,37 +111,24 @@ namespace CarpetIOF5 {
- extern "C" int
+ int
CarpetIOF5_Startup ()
{
- int const ierr
- = CCTK_RegisterBanner ("AMR HDF5 I/O provided by CarpetIOF5");
- assert (! ierr);
-
- extending_t::create();
-
- return 0; // no error
+ CCTK_INFO ("Startup");
+ return extending_t::create (Setup);
}
void *
- SetupGH (tFleshConfig * const fleshconfig,
- int const convlevel,
- cGH * const cctkGH)
+ Setup (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);
+ assert (fleshconfig != 0);
+ CCTK_INFO ("Setup");
+ return extending_t::setup
+ (cctkGH, OutputGH, TimeToOutput, TriggerOutput, OutputVarAs);
}
@@ -146,6 +140,8 @@ namespace CarpetIOF5 {
assert (cctkGH != 0);
+ CCTK_INFO ("OutputGH");
+
int ierr;
vector<bool> want_variables (CCTK_NumVars());
@@ -194,13 +190,19 @@ namespace CarpetIOF5 {
TimeToOutput (cGH const * const cctkGH,
int const variable)
{
+ DECLARE_CCTK_ARGUMENTS;
DECLARE_CCTK_PARAMETERS;
assert (cctkGH != 0);
assert (variable >= 0 and variable < CCTK_NumVars());
assert (Carpet::is_level_mode());
- extending_t extending (cctkGH);
+
+ {
+ char * const fullname = CCTK_FullName(variable);
+ CCTK_VInfo (CCTK_THORNSTRING, "TimeToOutput \"%s\"", fullname);
+ free (fullname);
+ }
bool should_output;
@@ -219,9 +221,6 @@ namespace CarpetIOF5 {
}
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)
{
@@ -232,30 +231,55 @@ namespace CarpetIOF5 {
should_output = false;
break;
default:
- should_output
- = cctkGH->cctk_iteration >= last_output_iteration + my_out_every;
+ if (* this_iteration == cctk_iteration)
+ {
+ // we already decided to output this iteration
+ should_output = true;
+ }
+ else if (cctk_iteration >= * next_output_iteration)
+ {
+ // it is time for the next output
+ should_output = true;
+ * this_iteration = cctk_iteration;
+ * next_output_iteration = cctk_iteration + my_out_every;
+ }
+ else
+ {
+ should_output = false;
+ }
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;
+ CCTK_REAL const my_out_dt = out_dt == -2 ? IO_out_dt : out_dt;
if (out_dt == 0)
{
should_output = true;
}
- else if (abs (out_dt - (-1)) <= dt_fudge)
+ else if (out_dt == -1)
{
should_output = false;
}
else
{
- should_output
- = cctkGH->cctk_time - dt_fudge >= last_output_time + my_out_dt;
+ if (* this_iteration == cctk_iteration)
+ {
+ // we already decided to output this iteration
+ should_output = true;
+ }
+ else if (cctk_time / cctk_delta_time
+ >= * next_output_time / cctk_delta_time - dt_fudge)
+ {
+ // it is time for the next output
+ should_output = true;
+ * this_iteration = cctk_iteration;
+ * next_output_time = cctk_time + my_out_dt;
+ }
+ else
+ {
+ should_output = false;
+ }
}
}
else
@@ -264,6 +288,27 @@ namespace CarpetIOF5 {
should_output = false;
}
+ if (should_output)
+ {
+ extending_t extending (cctkGH);
+ int const last_output_iteration
+ = (extending.get_last_output_iteration
+ (Carpet::mglevel, Carpet::reflevel, variable));
+ assert (last_output_iteration <= cctk_iteration);
+ if (last_output_iteration == cctk_iteration)
+ {
+ // Skipping output for variable, because this variable has
+ // already been output during the current iteration --
+ // probably via a trigger during the analysis stage
+ should_output = false;
+ }
+ else
+ {
+ extending.set_last_output_iteration
+ (Carpet::mglevel, Carpet::reflevel, variable, cctk_iteration);
+ }
+ }
+
return should_output;
}
@@ -278,6 +323,12 @@ namespace CarpetIOF5 {
assert (cctkGH != 0);
assert (variable >= 0 and variable < CCTK_NumVars());
+ {
+ char * const fullname = CCTK_FullName(variable);
+ CCTK_VInfo (CCTK_THORNSTRING, "TriggerOutput \"%s\"", fullname);
+ free (fullname);
+ }
+
char * fullname = CCTK_FullName (variable);
assert (fullname);
@@ -285,13 +336,6 @@ namespace CarpetIOF5 {
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;
}
@@ -308,6 +352,9 @@ namespace CarpetIOF5 {
assert (varname != 0);
assert (alias != 0);
+ CCTK_VInfo (CCTK_THORNSTRING, "OutputVarAs \"%s\" \"%s\"",
+ varname, alias);
+
int const variable = CCTK_VarIndex (varname);
if (variable < 0)
{
@@ -325,49 +372,30 @@ namespace CarpetIOF5 {
extending_t extending (cctkGH);
- std::ostringstream filenamebuf;
+ 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();
+ string const filename = filenamebuf.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::file_t file (cctkGH, filename, 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)
+ for (Carpet::mglevel_iterator mglevel_iter (cctkGH);
+ ! mglevel_iter.done();
+ mglevel_iter.step())
{
- 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);
+ write_one_mglevel (cctkGH, timestep, group, variable);
}
}
else
@@ -386,17 +414,31 @@ namespace CarpetIOF5 {
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())
+ CCTK_VInfo (CCTK_THORNSTRING,
+ "OutputVarAs/write_one_mglevel mglevel=%d", Carpet::mglevel);
+
+ ostringstream namebuf;
+ namebuf << "convlevel=" << cctkGH->cctk_convlevel;
+ string const namestr = namebuf.str();
+ char const * const name = namestr.c_str();
+ F5::simulation_t simulation (timestep, name);
+
+ int const grouptype = CCTK_GroupTypeI (group);
+ assert (grouptype >= 0);
+ switch (grouptype)
{
- int const grouptype = CCTK_GroupTypeI (group);
- assert (grouptype >= 0);
- switch (grouptype)
+ case CCTK_ARRAY:
+ case CCTK_SCALAR:
+ {
+ if (Carpet::do_global_mode)
+ {
+ write_global (cctkGH, simulation, group, variable);
+ }
+ }
+ break;
+ case CCTK_GF:
{
- case CCTK_GF:
+ if (Carpet::is_global_mode())
{
for (Carpet::reflevel_iterator reflevel_iter (cctkGH);
! reflevel_iter.done();
@@ -405,23 +447,58 @@ namespace CarpetIOF5 {
write_one_reflevel (cctkGH, simulation, group, variable);
}
}
- break;
- case CCTK_ARRAY:
- case CCTK_SCALAR:
+ else
{
- Carpet::enter_level_mode (cctkGH, 0);
- write_one_reflevel (cctkGH, timestep, group, variable);
- Carpet::leave_level_mode (cctkGH);
+ write_one_reflevel (cctkGH, simulation, group, variable);
}
- break;
- default:
- assert (0);
}
+ break;
+ default:
+ assert (0);
}
- else
+ }
+
+
+
+ void
+ write_global (cGH const * const cctkGH,
+ F5::simulation_t & simulation,
+ int const group,
+ int const variable)
+ {
+ CCTK_INFO ("OutputVarAs/write_global");
+
+ F5::unigrid_topology_t topology (simulation);
+
+ int const grouptype = CCTK_GroupTypeI (group);
+ assert (grouptype >= 0);
+ assert (grouptype == CCTK_SCALAR or grouptype == CCTK_ARRAY);
+
+ vect<CCTK_REAL, dim> level_origin, level_delta;
+ for (int d=0; d<dim; ++d)
{
- write_one_reflevel (cctkGH, simulation, group, variable);
+ level_origin[d] = 0.0;
+ level_delta[d] = 1.0;
}
+ 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);
+
+ int const myproc = CCTK_MyProc (cctkGH);
+ dh * const dd = Carpet::arrdata.at(group).at(0).dd;
+ bbox<int, dim> const & region
+ = dd->boxes.at(Carpet::mglevel).at(0).at(myproc).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);
}
@@ -432,6 +509,14 @@ namespace CarpetIOF5 {
int const group,
int const variable)
{
+ CCTK_VInfo (CCTK_THORNSTRING,
+ "OutputVarAs/write_one_reflevel reflevel=%d",
+ Carpet::reflevel);
+
+ int const grouptype = CCTK_GroupTypeI (group);
+ assert (grouptype >= 0);
+ assert (grouptype == CCTK_GF);
+
F5::mesh_refinement_topology_t topology
(simulation, Carpet::reflevel, Carpet::maxreflevels,
Carpet::spacereflevelfact, Carpet::maxspacereflevelfact);
@@ -452,9 +537,6 @@ namespace CarpetIOF5 {
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())
@@ -475,6 +557,9 @@ namespace CarpetIOF5 {
F5::tensor_component_t & tensor_component,
int const group)
{
+ CCTK_VInfo (CCTK_THORNSTRING,
+ "OutputVarAs/write_one_map map=%d", Carpet::map);
+
if (Carpet::is_singlemap_mode())
{
int const grouptype = CCTK_GroupTypeI (group);
@@ -499,21 +584,27 @@ namespace CarpetIOF5 {
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);
+ CCTK_VInfo (CCTK_THORNSTRING,
+ "OutputVarAs/write_one_component component=%d",
+ Carpet::component);
- 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);
+ gh * const hh = Carpet::vhh.at(Carpet::map);
+ if (hh->is_local (Carpet::reflevel, Carpet::component))
+ {
+ dh * const dd = Carpet::vdd.at(Carpet::map);
+ 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);
+
+ int const variable = tensor_component.get_variable();
+ 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);
+ }
}
diff --git a/CarpetDev/CarpetIOF5/src/README b/CarpetDev/CarpetIOF5/src/README
new file mode 100644
index 000000000..5795c9892
--- /dev/null
+++ b/CarpetDev/CarpetIOF5/src/README
@@ -0,0 +1,10 @@
+An F5 file contains the following hierarchy:
+
+ file
+ timestep
+ simulation
+ topology
+ coordinate_system
+ physical_quantity
+ tensor_component
+ data_region
diff --git a/CarpetDev/CarpetIOF5/src/coordinate_system.cc b/CarpetDev/CarpetIOF5/src/coordinate_system.cc
index a96ebd94b..3e0aa8fd8 100644
--- a/CarpetDev/CarpetIOF5/src/coordinate_system.cc
+++ b/CarpetDev/CarpetIOF5/src/coordinate_system.cc
@@ -1,4 +1,5 @@
#include <sstream>
+#include <string>
#include <hdf5.h>
@@ -112,9 +113,11 @@ namespace CarpetIOF5 {
{
assert (all (m_level_delta > 0));
- std::ostringstream buf;
- buf << "Cartesian 3D, x0=" << m_level_origin << ", dx=" << m_level_delta;
- char const * const name = buf.str().c_str();
+ ostringstream namebuf;
+ namebuf << "Cartesian 3D, x0=" << m_level_origin
+ << ", dx=" << m_level_delta;
+ string const namestr = namebuf.str();
+ char const * const name = namestr.c_str();
m_hdf5_coordinate_system
= open_or_create_group (m_topology.get_hdf5_topology(), name);
diff --git a/CarpetDev/CarpetIOF5/src/coordinate_system.hh b/CarpetDev/CarpetIOF5/src/coordinate_system.hh
index 740a8a86a..06c93603e 100644
--- a/CarpetDev/CarpetIOF5/src/coordinate_system.hh
+++ b/CarpetDev/CarpetIOF5/src/coordinate_system.hh
@@ -18,6 +18,10 @@ namespace CarpetIOF5 {
class coordinate_system_t {
+ coordinate_system_t ();
+ coordinate_system_t (coordinate_system_t const &);
+ coordinate_system_t operator= (coordinate_system_t const &);
+
protected:
topology_t & m_topology;
@@ -52,6 +56,11 @@ namespace CarpetIOF5 {
vect<CCTK_REAL, dim> m_level_origin;
vect<CCTK_REAL, dim> m_level_delta;
+ Cartesian_coordinate_system_t ();
+ Cartesian_coordinate_system_t (Cartesian_coordinate_system_t const &);
+ Cartesian_coordinate_system_t
+ operator= (Cartesian_coordinate_system_t const &);
+
public:
Cartesian_coordinate_system_t (topology_t & topology,
diff --git a/CarpetDev/CarpetIOF5/src/data_region.cc b/CarpetDev/CarpetIOF5/src/data_region.cc
index 6f713911e..d19700cc3 100644
--- a/CarpetDev/CarpetIOF5/src/data_region.cc
+++ b/CarpetDev/CarpetIOF5/src/data_region.cc
@@ -1,6 +1,7 @@
#include <cassert>
#include <cstdlib>
#include <sstream>
+#include <string>
#include "cctk.h"
@@ -25,9 +26,10 @@ namespace CarpetIOF5 {
{
assert (! region.empty());
- ostringstream buf;
- buf << "Region " << m_region;
- char const * const name = buf.str().c_str();
+ ostringstream namebuf;
+ namebuf << "region=" << m_region;
+ string const namestr = namebuf.str();
+ char const * const name = namestr.c_str();
assert (name != 0);
int const vartype = CCTK_VarTypeI (m_tensor_component.get_variable());
@@ -44,8 +46,8 @@ namespace CarpetIOF5 {
assert (m_dataspace >= 0);
m_dataset
- = H5Dcreate (m_dataspace, name, hdf5_datatype,
- m_dataspace, m_properties);
+ = H5Dcreate (m_tensor_component.get_hdf5_tensor_component(), name,
+ hdf5_datatype, m_dataspace, m_properties);
assert (m_dataset >= 0);
write_or_check_attribute
diff --git a/CarpetDev/CarpetIOF5/src/data_region.hh b/CarpetDev/CarpetIOF5/src/data_region.hh
index 3f08e7c3a..9b354166a 100644
--- a/CarpetDev/CarpetIOF5/src/data_region.hh
+++ b/CarpetDev/CarpetIOF5/src/data_region.hh
@@ -24,6 +24,10 @@ namespace CarpetIOF5 {
hid_t m_dataset;
hid_t m_dataspace;
+ data_region_t ();
+ data_region_t (data_region_t const &);
+ data_region_t operator= (data_region_t const &);
+
public:
data_region_t (tensor_component_t & tensor_component,
diff --git a/CarpetDev/CarpetIOF5/src/extending.cc b/CarpetDev/CarpetIOF5/src/extending.cc
index ab07491ab..4ec9a4e8b 100644
--- a/CarpetDev/CarpetIOF5/src/extending.cc
+++ b/CarpetDev/CarpetIOF5/src/extending.cc
@@ -1,5 +1,6 @@
#include <cassert>
#include <cstring>
+#include <iostream>
#include "cctk.h"
@@ -12,22 +13,42 @@ namespace CarpetIOF5 {
char const * const extending_t::
extension_name = "CarpetIOF5";
- void extending_t::
- create ()
+ int extending_t::
+ create (void * (* const Setup) (tFleshConfig * config,
+ int convlevel,
+ cGH * cctkGH))
{
int const handle = CCTK_RegisterGHExtension (extension_name);
assert (handle >= 0);
- int const ierr = CCTK_RegisterGHExtensionSetupGH (handle, setup);
- assert (! ierr);
+ int const iflag = CCTK_RegisterGHExtensionSetupGH (handle, Setup);
+ assert (iflag);
+ return 0; // no error
}
void * extending_t::
- setup (tFleshConfig * const fleshconfig,
- int const convlevel,
- cGH * const cctkGH)
+ setup (cGH * const cctkGH,
+ int (* const OutputGH) (cGH const * cctkGH),
+ int (* const TimeToOutput) (cGH const * cctkGH,
+ int variable),
+ int (* const TriggerOutput) (cGH const * cctkGH,
+ int variable),
+ int (* const OutputVarAs) (cGH const * cctkGH,
+ char const * varname,
+ char const * alias))
{
- assert (fleshconfig != 0);
assert (cctkGH != 0);
+
+ int ierr;
+ int const io_method = CCTK_RegisterIOMethod (extension_name);
+ ierr = CCTK_RegisterIOMethodOutputGH (io_method, OutputGH);
+ assert (! ierr);
+ ierr = CCTK_RegisterIOMethodTimeToOutput (io_method, TimeToOutput);
+ assert (! ierr);
+ ierr = CCTK_RegisterIOMethodTriggerOutput (io_method, TriggerOutput);
+ assert (! ierr);
+ ierr = CCTK_RegisterIOMethodOutputVarAs (io_method, OutputVarAs);
+ assert (! ierr);
+
return new extension_t;
}
@@ -41,26 +62,24 @@ namespace CarpetIOF5 {
}
bool extending_t::
- get_did_truncate (char const * const name)
+ get_did_truncate (string const name)
const
{
- 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)
+ set_did_truncate (string const name)
{
- assert (name != 0);
- m_extension->did_truncate.insert (strdup (name));
+ m_extension->did_truncate.insert (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);
+ resize_last_output_iteration (ml, rl, vi);
return m_extension->last_output_iteration.at(ml).at(rl).at(vi);
}
@@ -68,54 +87,28 @@ namespace CarpetIOF5 {
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);
+ resize_last_output_iteration (ml, rl, vi);
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)
+ resize_last_output_iteration (int ml, int rl, int vi)
+ const
{
assert (ml >= 0);
- if (ml >= array.size())
+ if (ml >= m_extension->last_output_iteration.size())
{
- array.resize (ml+1);
+ m_extension->last_output_iteration.resize (ml+1);
}
assert (rl >= 0);
- if (rl >= array.at(ml).size())
+ if (rl >= m_extension->last_output_iteration.at(ml).size())
{
- array.at(ml).resize (rl+1);
+ m_extension->last_output_iteration.at(ml).resize (rl+1);
}
- if (vi >= array.at(ml).at(rl).size())
+ if (vi >= m_extension->last_output_iteration.at(ml).at(rl).size())
{
- array.at(ml).at(rl).resize (vi+1, -1);
+ m_extension->last_output_iteration.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 55d0d186e..4f9bc9cc1 100644
--- a/CarpetDev/CarpetIOF5/src/extending.hh
+++ b/CarpetDev/CarpetIOF5/src/extending.hh
@@ -2,6 +2,7 @@
#define EXTENDING_HH
#include <set>
+#include <string>
#include <vector>
#include "cctk.h"
@@ -11,6 +12,7 @@
namespace CarpetIOF5 {
using std::set;
+ using std::string;
using std::vector;
@@ -20,32 +22,39 @@ namespace CarpetIOF5 {
static char const * const extension_name;
struct extension_t {
- set<char const *> did_truncate;
+ set<string> did_truncate;
// [mglevel][reflevel][variable];
vector<vector<vector<int> > > last_output_iteration;
- vector<vector<vector<CCTK_REAL> > > last_output_time;
};
extension_t * m_extension;
public:
- static void
- create ();
+ static int
+ create (void * (* Setup) (tFleshConfig * config,
+ int convlevel,
+ cGH * cctkGH));
static void *
- setup (tFleshConfig * config,
- int convlevel,
- cGH * cctkGH);
+ setup (cGH * cctkGH,
+ int (* OutputGH) (cGH const * cctkGH),
+ int (* TimeToOutput) (cGH const * cctkGH,
+ int variable),
+ int (* TriggerOutput) (cGH const * cctkGH,
+ int variable),
+ int (* OutputVarAs) (cGH const * cctkGH,
+ char const * varname,
+ char const * alias));
extending_t (cGH const * cctkGH);
bool
- get_did_truncate (char const * name)
+ get_did_truncate (string name)
const;
void
- set_did_truncate (char const * name);
+ set_did_truncate (string name);
int
get_last_output_iteration (int ml, int rl, int vi)
@@ -54,19 +63,11 @@ namespace CarpetIOF5 {
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);
+ void
+ resize_last_output_iteration (int ml, int rl, int vi)
+ const;
};
diff --git a/CarpetDev/CarpetIOF5/src/file.cc b/CarpetDev/CarpetIOF5/src/file.cc
index 0582e2071..07366f072 100644
--- a/CarpetDev/CarpetIOF5/src/file.cc
+++ b/CarpetDev/CarpetIOF5/src/file.cc
@@ -1,4 +1,5 @@
#include <cassert>
+#include <string>
#include <hdf5.h>
@@ -14,26 +15,29 @@ namespace CarpetIOF5 {
file_t::
file_t (cGH const * const cctkGH,
- char const * const filename,
+ string const filename,
bool const do_truncate)
: m_cctkGH (cctkGH),
m_filename (filename)
{
assert (cctkGH);
- assert (filename);
- htri_t is_hdf5 = H5Fis_hdf5 (filename);
- assert (is_hdf5 >= 0);
+ char const * const filenameptr = filename.c_str();
+
+ htri_t is_hdf5;
+ H5E_BEGIN_TRY {
+ is_hdf5 = H5Fis_hdf5 (filenameptr);
+ } H5E_END_TRY;
bool const file_exists = is_hdf5 > 0;
if (do_truncate or ! file_exists)
{
m_hdf5_file
- = H5Fcreate (filename, H5F_ACC_TRUNC, H5P_DEFAULT, H5P_DEFAULT);
+ = H5Fcreate (filenameptr, H5F_ACC_TRUNC, H5P_DEFAULT, H5P_DEFAULT);
}
else
{
- m_hdf5_file = H5Fopen (filename, H5F_ACC_RDWR, H5P_DEFAULT);
+ m_hdf5_file = H5Fopen (filenameptr, H5F_ACC_RDWR, H5P_DEFAULT);
}
assert (invariant());
@@ -73,7 +77,6 @@ namespace CarpetIOF5 {
const
{
return (m_cctkGH != 0
- and m_filename != 0
and m_hdf5_file >= 0);
}
diff --git a/CarpetDev/CarpetIOF5/src/file.hh b/CarpetDev/CarpetIOF5/src/file.hh
index 042dc9148..b5ac2d696 100644
--- a/CarpetDev/CarpetIOF5/src/file.hh
+++ b/CarpetDev/CarpetIOF5/src/file.hh
@@ -1,6 +1,8 @@
#ifndef FILE_HH
#define FILE_HH
+#include <string>
+
#include <hdf5.h>
#include "cctk.h"
@@ -11,20 +13,28 @@
namespace CarpetIOF5 {
+ using std::string;
+
+
+
namespace F5 {
class file_t {
cGH const * const m_cctkGH;
- char const * const m_filename;
+ string const m_filename;
hid_t m_hdf5_file;
+ file_t ();
+ file_t (file_t const &);
+ file_t operator= (file_t const &);
+
public:
file_t (cGH const * cctkGH,
- char const * filename,
+ string filename,
bool do_truncate);
virtual
diff --git a/CarpetDev/CarpetIOF5/src/physical_quantity.hh b/CarpetDev/CarpetIOF5/src/physical_quantity.hh
index 0c3982061..56f768799 100644
--- a/CarpetDev/CarpetIOF5/src/physical_quantity.hh
+++ b/CarpetDev/CarpetIOF5/src/physical_quantity.hh
@@ -19,6 +19,10 @@ namespace CarpetIOF5 {
hid_t m_hdf5_physical_quantity;
+ physical_quantity_t ();
+ physical_quantity_t (physical_quantity_t const &);
+ physical_quantity_t operator= (physical_quantity_t const &);
+
public:
physical_quantity_t (coordinate_system_t & coordinate_system,
diff --git a/CarpetDev/CarpetIOF5/src/simulation.cc b/CarpetDev/CarpetIOF5/src/simulation.cc
index 22fe58d57..eaf83fb1c 100644
--- a/CarpetDev/CarpetIOF5/src/simulation.cc
+++ b/CarpetDev/CarpetIOF5/src/simulation.cc
@@ -1,6 +1,4 @@
#include <cassert>
-#include <string>
-#include <sstream>
#include <hdf5.h>
@@ -22,12 +20,9 @@ namespace CarpetIOF5 {
simulation_t::
simulation_t (timestep_t & timestep,
char const * const name)
- : m_timestep (timestep)
+ : m_timestep (timestep),
+ m_name (name)
{
- ostringstream buf;
- buf << name;
- m_name = buf.str();
-
m_hdf5_simulation
= open_or_create_group (m_timestep.get_hdf5_timestep(),
m_name.c_str());
diff --git a/CarpetDev/CarpetIOF5/src/simulation.hh b/CarpetDev/CarpetIOF5/src/simulation.hh
index baf02b725..7aed7ca11 100644
--- a/CarpetDev/CarpetIOF5/src/simulation.hh
+++ b/CarpetDev/CarpetIOF5/src/simulation.hh
@@ -22,10 +22,14 @@ namespace CarpetIOF5 {
timestep_t & m_timestep;
- string m_name;
+ string const m_name;
hid_t m_hdf5_simulation;
+ simulation_t ();
+ simulation_t (simulation_t const &);
+ simulation_t operator= (simulation_t const &);
+
public:
simulation_t (timestep_t & timestep,
diff --git a/CarpetDev/CarpetIOF5/src/tensor_component.cc b/CarpetDev/CarpetIOF5/src/tensor_component.cc
index 0741e3265..a9ea0e20c 100644
--- a/CarpetDev/CarpetIOF5/src/tensor_component.cc
+++ b/CarpetDev/CarpetIOF5/src/tensor_component.cc
@@ -20,7 +20,7 @@ namespace CarpetIOF5 {
{
assert (variable >= 0 and variable < CCTK_NumVars());
- char * const name = CCTK_FullName (variable);
+ char const * const name = CCTK_VarName (variable);
assert (name != 0);
m_hdf5_tensor_component
@@ -29,8 +29,6 @@ namespace CarpetIOF5 {
name);
assert (m_hdf5_tensor_component >= 0);
- free (name);
-
assert (invariant());
}
diff --git a/CarpetDev/CarpetIOF5/src/tensor_component.hh b/CarpetDev/CarpetIOF5/src/tensor_component.hh
index cbdb2383f..8377983a7 100644
--- a/CarpetDev/CarpetIOF5/src/tensor_component.hh
+++ b/CarpetDev/CarpetIOF5/src/tensor_component.hh
@@ -19,6 +19,10 @@ namespace CarpetIOF5 {
hid_t m_hdf5_tensor_component;
+ tensor_component_t ();
+ tensor_component_t (tensor_component_t const &);
+ tensor_component_t operator= (tensor_component_t const &);
+
public:
tensor_component_t (physical_quantity_t & physical_quantity,
diff --git a/CarpetDev/CarpetIOF5/src/timestep.hh b/CarpetDev/CarpetIOF5/src/timestep.hh
index 715759c6d..203cb6683 100644
--- a/CarpetDev/CarpetIOF5/src/timestep.hh
+++ b/CarpetDev/CarpetIOF5/src/timestep.hh
@@ -27,6 +27,10 @@ namespace CarpetIOF5 {
hid_t m_hdf5_timestep;
+ timestep_t ();
+ timestep_t (timestep_t const &);
+ timestep_t operator= (timestep_t const &);
+
public:
timestep_t (file_t & file,
diff --git a/CarpetDev/CarpetIOF5/src/topology.cc b/CarpetDev/CarpetIOF5/src/topology.cc
index 337e1ca0b..b45f580d6 100644
--- a/CarpetDev/CarpetIOF5/src/topology.cc
+++ b/CarpetDev/CarpetIOF5/src/topology.cc
@@ -108,9 +108,10 @@ namespace CarpetIOF5 {
assert (all (level_refinement_factor > 0));
assert (all (level_refinement_factor <= max_refinement_factor));
- ostringstream buf;
- buf << "Vertices level " << refinement_level;
- char const * const name = buf.str().c_str();
+ ostringstream namebuf;
+ namebuf << "Vertices level=" << refinement_level;
+ string const namestr = namebuf.str();
+ char const * const name = namestr.c_str();
m_hdf5_topology
= open_or_create_group (m_simulation.get_hdf5_simulation(), name);
@@ -133,7 +134,7 @@ namespace CarpetIOF5 {
assert (all (coarse_delta > 0));
assert (all (level_offset_denominator > 0));
- CCTK_REAL const one = 1;
+ vect<CCTK_REAL, dim> const one = 1;
level_delta = coarse_delta / m_level_refinement_factor;
level_origin
= (coarse_origin
diff --git a/CarpetDev/CarpetIOF5/src/topology.hh b/CarpetDev/CarpetIOF5/src/topology.hh
index 8f9399f51..81534f945 100644
--- a/CarpetDev/CarpetIOF5/src/topology.hh
+++ b/CarpetDev/CarpetIOF5/src/topology.hh
@@ -18,6 +18,10 @@ namespace CarpetIOF5 {
class topology_t {
+ topology_t ();
+ topology_t (topology_t const &);
+ topology_t operator= (topology_t const &);
+
protected:
simulation_t & m_simulation;
@@ -50,6 +54,10 @@ namespace CarpetIOF5 {
class unigrid_topology_t : public topology_t {
+ unigrid_topology_t ();
+ unigrid_topology_t (unigrid_topology_t const &);
+ unigrid_topology_t operator= (unigrid_topology_t const &);
+
public:
// Create unigrid topology
@@ -72,6 +80,11 @@ namespace CarpetIOF5 {
vect<int, dim> const m_level_refinement_factor;
vect<int, dim> const m_max_refinement_factor;
+ mesh_refinement_topology_t ();
+ mesh_refinement_topology_t (mesh_refinement_topology_t const &);
+ mesh_refinement_topology_t
+ operator= (mesh_refinement_topology_t const &);
+
public:
mesh_refinement_topology_t (simulation_t & simulation,
diff --git a/CarpetDev/CarpetIOF5/src/utils.cc b/CarpetDev/CarpetIOF5/src/utils.cc
index 4102e36c5..ad0943ac6 100644
--- a/CarpetDev/CarpetIOF5/src/utils.cc
+++ b/CarpetDev/CarpetIOF5/src/utils.cc
@@ -70,26 +70,32 @@ namespace CarpetIOF5 {
return H5T_NATIVE_LDOUBLE;
}
+#ifdef HAVE_CCTK_COMPLEX8
hid_t
hdf5_datatype_from_dummy (CCTK_COMPLEX8 const & dummy)
{
CCTK_REAL4 real;
return hdf5_complex_datatype_from_dummy (dummy, real);
}
+#endif
+#ifdef HAVE_CCTK_COMPLEX16
hid_t
hdf5_datatype_from_dummy (CCTK_COMPLEX16 const & dummy)
{
CCTK_REAL8 real;
return hdf5_complex_datatype_from_dummy (dummy, real);
}
+#endif
+#ifdef HAVE_CCTK_COMPLEX32
hid_t
hdf5_datatype_from_dummy (CCTK_COMPLEX32 const & dummy)
{
CCTK_REAL16 real;
return hdf5_complex_datatype_from_dummy (dummy, real);
}
+#endif
template<typename T, typename R>
hid_t
@@ -102,12 +108,12 @@ namespace CarpetIOF5 {
{
initialised = true;
- hsize_t const dim = 2;
+ hsize_t const cdim = 2;
int const perm = 0;
hdf_complex_datatype
= H5Tarray_create (hdf5_datatype_from_dummy (real),
- 1, & dim, & perm);
+ 1, & cdim, & perm);
assert (hdf_complex_datatype >= 0);
}
@@ -130,18 +136,38 @@ namespace CarpetIOF5 {
break
CASE (CCTK_VARIABLE_BYTE , CCTK_BYTE );
CASE (CCTK_VARIABLE_INT , CCTK_INT );
+#ifdef HAVE_CCTK_INT1
CASE (CCTK_VARIABLE_INT1 , CCTK_INT1 );
+#endif
+#ifdef HAVE_CCTK_INT1
CASE (CCTK_VARIABLE_INT2 , CCTK_INT2 );
+#endif
+#ifdef HAVE_CCTK_INT2
CASE (CCTK_VARIABLE_INT4 , CCTK_INT4 );
+#endif
+#ifdef HAVE_CCTK_INT4
CASE (CCTK_VARIABLE_INT8 , CCTK_INT8 );
+#endif
CASE (CCTK_VARIABLE_REAL , CCTK_REAL );
+#ifdef HAVE_CCTK_REAL4
CASE (CCTK_VARIABLE_REAL4 , CCTK_REAL4 );
+#endif
+#ifdef HAVE_CCTK_REAL8
CASE (CCTK_VARIABLE_REAL8 , CCTK_REAL8 );
+#endif
+#ifdef HAVE_CCTK_REAL16
CASE (CCTK_VARIABLE_REAL16 , CCTK_REAL16 );
+#endif
CASE (CCTK_VARIABLE_COMPLEX , CCTK_COMPLEX );
+#ifdef HAVE_CCTK_COMPLEX8
CASE (CCTK_VARIABLE_COMPLEX8 , CCTK_COMPLEX8 );
+#endif
+#ifdef HAVE_CCTK_COMPLEX16
CASE (CCTK_VARIABLE_COMPLEX16, CCTK_COMPLEX16);
+#endif
+#ifdef HAVE_CCTK_COMPLEX32
CASE (CCTK_VARIABLE_COMPLEX32, CCTK_COMPLEX32);
+#endif
#undef CASE
case CCTK_VARIABLE_CHAR : return H5I_INVALID_HID;
case CCTK_VARIABLE_STRING : return H5I_INVALID_HID;
@@ -206,8 +232,8 @@ namespace CarpetIOF5 {
if (attribute < 0)
{
// The attribute does not yet exist; create it
- hsize_t const dim = num_values;
- hid_t const dataspace = H5Screate_simple (1, & dim, & dim);
+ 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);
assert (attribute >= 0);
@@ -228,11 +254,11 @@ namespace CarpetIOF5 {
assert (is_simple > 0);
int const ndims = H5Sget_simple_extent_ndims (dataspace);
assert (ndims == 1);
- hsize_t dim;
+ hsize_t adim;
herr_t herr;
- herr = H5Sget_simple_extent_dims (dataspace, & dim, 0);
- assert (dim == num_values);
- vector<T> buf (dim);
+ herr = H5Sget_simple_extent_dims (dataspace, & adim, 0);
+ assert (adim == num_values);
+ vector<T> buf (adim);
herr = H5Aread (attribute, datatype, & buf.front());
assert (! herr);
herr = H5Sclose (dataspace);
diff --git a/CarpetDev/CarpetIOF5/src/utils.hh b/CarpetDev/CarpetIOF5/src/utils.hh
index 910328aae..0c7869b68 100644
--- a/CarpetDev/CarpetIOF5/src/utils.hh
+++ b/CarpetDev/CarpetIOF5/src/utils.hh
@@ -29,12 +29,18 @@ namespace CarpetIOF5 {
hdf5_datatype_from_dummy (double const & dummy);
hid_t
hdf5_datatype_from_dummy (long double const & dummy);
+#ifdef HAVE_CCTK_COMPLEX8
hid_t
hdf5_datatype_from_dummy (CCTK_COMPLEX8 const & dummy);
+#endif
+#ifdef HAVE_CCTK_COMPLEX16
hid_t
hdf5_datatype_from_dummy (CCTK_COMPLEX16 const & dummy);
+#endif
+#ifdef HAVE_CCTK_COMPLEX32
hid_t
hdf5_datatype_from_dummy (CCTK_COMPLEX32 const & dummy);
+#endif
template<typename T, typename R>
hid_t