[cig-commits] r13778 - cs/cigma/trunk/src
luis at geodynamics.org
luis at geodynamics.org
Wed Dec 17 02:34:02 PST 2008
Author: luis
Date: 2008-12-17 02:34:01 -0800 (Wed, 17 Dec 2008)
New Revision: 13778
Modified:
cs/cigma/trunk/src/Residuals.cpp
cs/cigma/trunk/src/Residuals.h
cs/cigma/trunk/src/core_writers.cpp
cs/cigma/trunk/src/io_hdf5.h
Log:
When writing residuals to HDF5 file, write global values as attributes
Modified: cs/cigma/trunk/src/Residuals.cpp
===================================================================
--- cs/cigma/trunk/src/Residuals.cpp 2008-12-17 10:33:59 UTC (rev 13777)
+++ cs/cigma/trunk/src/Residuals.cpp 2008-12-17 10:34:01 UTC (rev 13778)
@@ -92,15 +92,19 @@
global_error += cell_residual * cell_residual;
}
+double Residuals::max()
+{
+ return max_residual;
+}
double Residuals::L2()
{
return sqrt(global_error); // XXX: generalizes to norm_pow(global_error)
}
-double Residuals::max()
+double Residuals::relative_squared_L2()
{
- return max_residual;
+ return global_error/total_volume;
}
// ----------------------------------------------------------------------------
Modified: cs/cigma/trunk/src/Residuals.h
===================================================================
--- cs/cigma/trunk/src/Residuals.h 2008-12-17 10:33:59 UTC (rev 13777)
+++ cs/cigma/trunk/src/Residuals.h 2008-12-17 10:34:01 UTC (rev 13778)
@@ -22,8 +22,9 @@
void resetAccumulator();
void update(int e, double cell_residual, double cell_volume);
+ double max();
double L2();
- double max();
+ double relative_squared_L2();
//void write(const char *filename); // XXX
Modified: cs/cigma/trunk/src/core_writers.cpp
===================================================================
--- cs/cigma/trunk/src/core_writers.cpp 2008-12-17 10:33:59 UTC (rev 13777)
+++ cs/cigma/trunk/src/core_writers.cpp 2008-12-17 10:34:01 UTC (rev 13778)
@@ -2,6 +2,7 @@
#include "io_text_writer.h"
#include "io_hdf5_writer.h"
#include "io_vtk_writer.h"
+#include "io_hdf5.h"
#include "Common.h"
using namespace cigma;
@@ -274,6 +275,11 @@
<< filename << "'" << std::ends;
throw cigma::Exception("WriteResiduals", stream.str());
}
+
+ status = write_scalar_attribute<double>(hdf5_writer->file, eps_loc.c_str(), "NORM_L2", residuals->L2());
+ status = write_scalar_attribute<double>(hdf5_writer->file, eps_loc.c_str(), "RELATIVE_SQUARED_L2", residuals->relative_squared_L2());
+ status = write_scalar_attribute<double>(hdf5_writer->file, eps_loc.c_str(), "NORM_MAX", residuals->max());
+ status = write_scalar_attribute<double>(hdf5_writer->file, eps_loc.c_str(), "TOTAL_VOLUME", residuals->total_volume);
}
else if (wt == FileWriter::VTK_FILE_WRITER)
{
Modified: cs/cigma/trunk/src/io_hdf5.h
===================================================================
--- cs/cigma/trunk/src/io_hdf5.h 2008-12-17 10:33:59 UTC (rev 13777)
+++ cs/cigma/trunk/src/io_hdf5.h 2008-12-17 10:34:01 UTC (rev 13778)
@@ -303,6 +303,11 @@
template <typename T>
int write_scalar_attribute(H5::H5File *file, const char *loc, const char *attr_name, const T& val)
{
+ TRI_LOG_STR("write_scalar_attribute<T>()");
+ TRI_LOG(loc);
+ TRI_LOG(attr_name);
+ TRI_LOG(val);
+
H5::H5Object* obj = 0;
H5::Attribute* attr = 0;
@@ -311,39 +316,39 @@
return -1;
}
- obj = h5_open_object(file, loc);
+ obj = h5_open_object(file, loc); // XXX: make sure this doesn't leak
if (obj == 0)
{
- return -3;
+ return -2;
}
attr = h5_open_attribute(obj, attr_name);
- if (attr == 0)
+ if (attr != 0)
{
- if (obj) { delete obj; }
- return -4;
- }
-
- const bool overwrite_mode = true;
- if (overwrite_mode)
- {
- try
+ const bool overwrite_mode = true;
+ if (overwrite_mode)
{
- delete attr;
- attr = 0;
- obj->removeAttr(attr_name);
+ try
+ {
+ delete attr;
+ attr = 0;
+ obj->removeAttr(attr_name);
+ }
+ catch (H5::AttributeIException e)
+ {
+ }
}
- catch (H5::AttributeIException e)
+ else
{
+ if (attr) { delete attr; }
+ if (obj) { delete obj; }
+ std::cerr << "Error: Overwriting existing attribute '" << attr_name
+ << "' in location '" << loc << "' is not allowed" << std::endl;
+ return -4;
}
}
- else
- {
- std::cerr << "Error: Overwriting existing attribute '" << attr_name << "' is not allowed" << std::endl;
- return -5;
- }
try
{
@@ -354,9 +359,11 @@
}
catch (H5::Exception error)
{
+ if (attr) { delete attr; }
+ if (obj) { delete obj; }
//std::cout << "Error: " << error.getDetailMsg() << " (in " << error.getFuncName() << ")" << std::endl;
std::cerr << "Error: Could not set attribute '" << attr_name << "'" << std::endl;
- return -2;
+ return -5;
}
if (attr) { delete attr; }
More information about the CIG-COMMITS
mailing list