[cig-commits] [commit] master: HDF5 based stress output (0e3e0da)

cig_noreply at geodynamics.org cig_noreply at geodynamics.org
Tue Dec 2 13:56:19 PST 2014


Repository : https://github.com/geodynamics/vq

On branch  : master
Link       : https://github.com/geodynamics/vq/compare/06902a05cf4d70bc94c85d1c195c073d4e74cdad...c935dfd33f870a081b6c01cce97a060ad1cbdbda

>---------------------------------------------------------------

commit 0e3e0dad0d866555561fb6159eb9fa98b4ee4fc4
Author: Eric Heien <emheien at ucdavis.edu>
Date:   Thu Nov 27 00:08:34 2014 -0800

    HDF5 based stress output


>---------------------------------------------------------------

0e3e0dad0d866555561fb6159eb9fa98b4ee4fc4
 quakelib/src/QuakeLibIO.cpp |  9 +++++++
 src/core/Simulation.cpp     | 57 +++++++++++++++++++++++++++++++++++++++------
 src/core/Simulation.h       |  6 +++++
 3 files changed, 65 insertions(+), 7 deletions(-)

diff --git a/quakelib/src/QuakeLibIO.cpp b/quakelib/src/QuakeLibIO.cpp
index 720fb0d..88d2b84 100644
--- a/quakelib/src/QuakeLibIO.cpp
+++ b/quakelib/src/QuakeLibIO.cpp
@@ -2884,6 +2884,9 @@ void quakelib::ModelStress::setup_stress_hdf5(const hid_t &data_file) {
         field_sizes[i] = descs[i].size;
     }
 
+    blank_data._element_id = UNDEFINED_ELEMENT_ID;
+    blank_data._shear_stress = blank_data._normal_stress = nan("");
+
     // Create the sweep table
     res = H5TBmake_table("Stress Table",
                          data_file,
@@ -3071,6 +3074,12 @@ void quakelib::ModelStressState::setup_stress_state_hdf5(const hid_t &data_file)
         field_sizes[i] = descs[i].size;
     }
 
+    blank_data._year = nan("");
+    blank_data._event_num = UNDEFINED_EVENT_ID;
+    blank_data._sweep_num = UNDEFINED_EVENT_ID;
+    blank_data._end_rec = UNDEFINED_ELEMENT_ID;
+    blank_data._start_rec = UNDEFINED_ELEMENT_ID;
+
     // Create the sweep table
     res = H5TBmake_table("Stress State Table",
                          data_file,
diff --git a/src/core/Simulation.cpp b/src/core/Simulation.cpp
index 56b07f0..02a586d 100644
--- a/src/core/Simulation.cpp
+++ b/src/core/Simulation.cpp
@@ -84,13 +84,21 @@ void Simulation::output_stress(quakelib::UIndex event_num, quakelib::UIndex swee
 
     num_stress_recs += numGlobalBlocks();
 
-    // Write the stress state details
-    stress_state.write_ascii(stress_index_outfile);
-    stress_index_outfile.flush();
+    if (getStressOutfileType() == "text") {
+        // Write the stress state details
+        stress_state.write_ascii(stress_index_outfile);
+        stress_index_outfile.flush();
+
+        // Write the stress details
+        stress.write_ascii(stress_outfile);
+        stress_outfile.flush();
+    } else if (getStressOutfileType() == "hdf5") {
+        // Write the stress state details
+        stress_state.append_stress_state_hdf5(stress_data_file);
 
-    // Write the stress details
-    stress.write_ascii(stress_outfile);
-    stress_outfile.flush();
+        // Write the stress details
+        stress.append_stress_hdf5(stress_data_file);
+    }
 }
 
 /*!
@@ -127,6 +135,7 @@ void Simulation::init(void) {
             errConsole() << "ERROR: Stress file names cannot be blank." << std::endl;
             exit(-1);
         }
+
         stress_index_outfile.open(getStressIndexOutfile());
         stress_outfile.open(getStressOutfile());
 
@@ -143,14 +152,48 @@ void Simulation::init(void) {
         quakelib::ModelStressState::write_ascii_header(stress_index_outfile);
         quakelib::ModelStress::write_ascii_header(stress_outfile);
     } else if (getStressOutfileType() == "hdf5") {
-        
+#ifdef HDF5_FOUND
+        open_stress_hdf5_file(getStressOutfile());
+#else
+        sim->errConsole() << "ERROR: HDF5 library not linked, cannot use HDF5 output files." << std::endl;
+        exit(-1);
+#endif
     } else if (!(getStressOutfileType() == "")) {
         errConsole() << "ERROR: Unknown stress output file type " << getStressOutfileType() << std::endl;
         exit(-1);
     }
+
     num_stress_recs = 0;
 }
 
+#ifdef HDF5_FOUND
+void Simulation::open_stress_hdf5_file(const std::string &hdf5_file_name) {
+    hid_t   plist_id;
+
+    plist_id = H5Pcreate(H5P_FILE_ACCESS);
+
+    if (plist_id < 0) exit(-1);
+
+#ifdef MPI_C_FOUND
+#ifdef H5_HAVE_PARALLEL
+    //H5Pset_fapl_mpio(plist_id, MPI_COMM_WORLD, MPI_INFO_NULL);
+#endif
+#endif
+    // Create the data file, overwriting any old files
+    stress_data_file = H5Fcreate(hdf5_file_name.c_str(), H5F_ACC_TRUNC, H5P_DEFAULT, plist_id);
+
+    if (stress_data_file < 0) exit(-1);
+
+    // Create the stress index table
+    quakelib::ModelStressState::setup_stress_state_hdf5(stress_data_file);
+
+    // Create the stress table
+    quakelib::ModelStress::setup_stress_hdf5(stress_data_file);
+
+    H5Pclose(plist_id);
+}
+#endif
+
 /*!
  Calculate the number of faults in the simulation based on
  the number of unique block fault IDs.
diff --git a/src/core/Simulation.h b/src/core/Simulation.h
index 43fa9e1..c454d9c 100644
--- a/src/core/Simulation.h
+++ b/src/core/Simulation.h
@@ -257,6 +257,12 @@ class Simulation : public SimFramework, public VCParams, public VCSimData, publi
         //! Files to write stress records to
         std::ofstream       stress_index_outfile, stress_outfile;
 
+#ifdef HDF5_FOUND
+        // HDF5 handle to stress data file
+        hid_t               stress_data_file;
+        void open_stress_hdf5_file(const std::string &hdf5_file_name);
+#endif
+
         //! Number of stress records written to files, used for keeping track of indices
         unsigned int        num_stress_recs;
 



More information about the CIG-COMMITS mailing list