[cig-commits] r13817 - cs/cigma/trunk/src
luis at geodynamics.org
luis at geodynamics.org
Mon Jan 12 14:09:37 PST 2009
Author: luis
Date: 2009-01-12 14:09:36 -0800 (Mon, 12 Jan 2009)
New Revision: 13817
Modified:
cs/cigma/trunk/src/core_writers.cpp
cs/cigma/trunk/src/core_writers.h
Log:
Added WriteMeshPart (needed for util program?)
Modified: cs/cigma/trunk/src/core_writers.cpp
===================================================================
--- cs/cigma/trunk/src/core_writers.cpp 2009-01-12 22:09:34 UTC (rev 13816)
+++ cs/cigma/trunk/src/core_writers.cpp 2009-01-12 22:09:36 UTC (rev 13817)
@@ -3,6 +3,8 @@
#include "io_hdf5_writer.h"
#include "io_vtk_writer.h"
#include "io_hdf5.h"
+#include "nc_array.h"
+#include "eb_array.h"
#include "Common.h"
using namespace cigma;
@@ -79,10 +81,97 @@
throw cigma::Exception("WriteElementBlock", "Need implementation");
}
+void cigma::WriteMeshPart(const DataPath& path, shared_ptr<MeshPart> M)
+{
+ TRI_LOG_STR("cigma::WriteMeshPart()");
+ TRI_LOG(path);
+
+ string filename = path.filename();
+ string location = path.location();
+ shared_ptr<FileWriter> writer = FileWriter::New(filename, "a");
+ const FileWriter::WriterType wt = writer->getWriterType();
+ if (wt == FileWriter::HDF5_FILE_WRITER)
+ {
+ int status;
+
+ HDF5_Writer *h5 = static_cast<HDF5_Writer*>(&(*writer));
+ h5->setOverwriteMode(false);
+
+ string loc;
+ if (location == "") { loc = "/mesh"; }
+
+ bool has_mesh_group = h5->locationIsGroup(loc.c_str());
+ if (!has_mesh_group)
+ {
+ try
+ {
+ h5->file->createGroup(loc.c_str());
+ }
+ catch (H5::Exception e)
+ {
+ ostringstream stream;
+ stream << "Could not create group '" << loc
+ << "' in HDF5 file '" << filename << "'"
+ << std::ends;
+ throw cigma::Exception("WriteMeshPart", stream.str());
+ }
+ }
+
+ if (dynamic_cast<nc_array*>(&(*(M->coords))))
+ {
+ string nc_loc = loc + "/coordinates";
+ nc_array* nc = static_cast<nc_array*>(&(*(M->coords)));
+ status = h5->writeCoordinates(nc_loc.c_str(), nc->coords, nc->n_points(), nc->n_dim());
+ if (status < 0)
+ {
+ ostringstream stream;
+ stream << "Could not write node coordinates to location '" << nc_loc
+ << "' in HDF5 file '" << filename << "'" << std::ends;
+ throw cigma::Exception("WriteMeshPart", stream.str());
+ }
+ }
+ else
+ {
+ // XXX: copy to a temporary cigma::array<double> and write
+ throw cigma::Exception("WriteMeshPart", "Need WriteNodeCoordinates");
+ }
+
+ if (dynamic_cast<eb_array*>(&(*(M->connect))))
+ {
+ string eb_loc = loc + "/connectivity";
+ eb_array* eb = static_cast<eb_array*>(&(*(M->connect)));
+ status = h5->writeConnectivity(eb_loc.c_str(), eb->connect, eb->n_cells(), eb->n_dofs());
+ if (status < 0)
+ {
+ ostringstream stream;
+ stream << "Could not write element block to location '" << eb_loc
+ << "' in HDF5 file '" << filename << "'" << std::ends;
+ throw cigma::Exception("WriteMeshPart", stream.str());
+ }
+ }
+ else
+ {
+ // XXX: copy to a temporary cigma::array<double> and write
+ throw cigma::Exception("WriteMeshPart", "Need WriteElementBlock");
+ }
+
+ // XXX: write CellType attribute to the group loc
+
+ }
+ else if (wt == FileWriter::VTK_FILE_WRITER)
+ {
+ string msg("No vtk writer for MeshPart");
+ throw cigma::Exception("WriteMeshPart", msg);
+ }
+ else if (wt == FileWriter::TEXT_FILE_WRITER)
+ {
+ string msg("No text writer for MeshPart");
+ throw cigma::Exception("WriteMeshPart", msg);
+ }
+}
+
void cigma::WriteQuadrature(const DataPath& path, shared_ptr<Quadrature> Q, bool overwrite)
{
- //throw cigma::Exception("WriteQuadrature", "need implementation");
-
TRI_LOG_STR("cigma::WriteQuadrature()");
TRI_LOG(path);
@@ -95,17 +184,17 @@
string loc = path.location();
string pts_loc = loc + "/points";
string wts_loc = loc + "/weights";
- HDF5_Writer *hdf5_writer = static_cast<HDF5_Writer*>(&(*writer));
+ HDF5_Writer *h5 = static_cast<HDF5_Writer*>(&(*writer));
- hdf5_writer->setOverwriteMode(overwrite);
+ h5->setOverwriteMode(overwrite);
- bool is_dset = hdf5_writer->locationIsDataset(loc.c_str());
+ bool is_dset = h5->locationIsDataset(loc.c_str());
if (overwrite && is_dset)
{
try
{
// remove loc
- hdf5_writer->file->unlink(loc);
+ h5->file->unlink(loc);
}
catch (H5::Exception e)
{
@@ -115,13 +204,13 @@
}
}
- bool not_there = !(hdf5_writer->locationIsGroup(loc.c_str()));
+ bool not_there = !(h5->locationIsGroup(loc.c_str()));
if (not_there)
{
- hdf5_writer->file->createGroup(loc);
+ h5->file->createGroup(loc);
}
- status = hdf5_writer->writeDataset(wts_loc.c_str(), Q->weights, Q->npts, 1);
+ status = h5->writeDataset(wts_loc.c_str(), Q->weights, Q->npts, 1);
if (status < 0)
{
ostringstream stream;
@@ -131,7 +220,7 @@
throw cigma::Exception("WriteQuadrature", stream.str());
}
- status = hdf5_writer->writeDataset(pts_loc.c_str(), Q->points, Q->npts, Q->ndim);
+ status = h5->writeDataset(pts_loc.c_str(), Q->points, Q->npts, Q->ndim);
if (status < 0)
{
ostringstream stream;
@@ -253,19 +342,19 @@
const FileWriter::WriterType wt = writer->getWriterType();
if (wt == FileWriter::HDF5_FILE_WRITER)
{
- HDF5_Writer *hdf5_writer = static_cast<HDF5_Writer*>(&(*writer));
+ HDF5_Writer *h5 = static_cast<HDF5_Writer*>(&(*writer));
// prepare writer to overwrite exsting datasets
- hdf5_writer->setOverwriteMode(overwrite);
+ h5->setOverwriteMode(overwrite);
string eps_loc = location;
- if (hdf5_writer->locationIsGroup(eps_loc.c_str()))
+ if (h5->locationIsGroup(eps_loc.c_str()))
{
eps_loc += "/residuals";
}
TRI_LOG(eps_loc);
- int status = hdf5_writer->writeDataset(eps_loc.c_str(), residuals->epsilon, residuals->nel, 1);
+ int status = h5->writeDataset(eps_loc.c_str(), residuals->epsilon, residuals->nel, 1);
TRI_LOG(status);
if (status < 0)
{
@@ -276,10 +365,11 @@
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);
+ status = write_scalar_attribute<double>(h5->file, eps_loc.c_str(), "L2_NORM", residuals->norm_L2());
+ status = write_scalar_attribute<double>(h5->file, eps_loc.c_str(), "RELATIVE_L2", residuals->relative_squared_norm_L2());
+ status = write_scalar_attribute<double>(h5->file, eps_loc.c_str(), "VOLUME", residuals->total_volume);
+ status = write_scalar_attribute<double>(h5->file, eps_loc.c_str(), "LINF_NORM", residuals->norm_Linf());
+ status = write_scalar_attribute<double>(h5->file, eps_loc.c_str(), "MAX_CELL_DIAMETER", residuals->max_cell_diameter());
}
else if (wt == FileWriter::VTK_FILE_WRITER)
{
Modified: cs/cigma/trunk/src/core_writers.h
===================================================================
--- cs/cigma/trunk/src/core_writers.h 2009-01-12 22:09:34 UTC (rev 13816)
+++ cs/cigma/trunk/src/core_writers.h 2009-01-12 22:09:36 UTC (rev 13817)
@@ -8,7 +8,7 @@
#include "ElementBlock.h"
#include "Quadrature.h"
#include "DofHandler.h"
-//#include "MeshPart.h"
+#include "MeshPart.h"
#include "Residuals.h"
#include "io_file_writer.h"
@@ -17,6 +17,7 @@
void WriteArray(const DataPath& path, const cigma::array<double>& x, bool overwrite=false);
void WriteNodeCoordinates(const DataPath& path, boost::shared_ptr<NodeCoordinates> nc);
void WriteElementBlock(const DataPath& path, boost::shared_ptr<ElementBlock> eb);
+ void WriteMeshPart(const DataPath& path, boost::shared_ptr<MeshPart> M);
void WriteQuadrature(const DataPath& path, boost::shared_ptr<Quadrature> Q, bool overwrite=false);
void WriteQPoints(const DataPath& path, const cigma::array<double>& w, const cigma::array<double>& x, bool overwrite=false);
void WriteDofs(const DataPath& path, boost::shared_ptr<DofHandler> dofs);
More information about the CIG-COMMITS
mailing list