[cig-commits] r14071 - cs/cigma/trunk/src
luis at geodynamics.org
luis at geodynamics.org
Wed Feb 18 08:14:14 PST 2009
Author: luis
Date: 2009-02-18 08:14:14 -0800 (Wed, 18 Feb 2009)
New Revision: 14071
Modified:
cs/cigma/trunk/src/cli_mesh_info_cmd.cpp
cs/cigma/trunk/src/cli_mesh_info_cmd.h
cs/cigma/trunk/src/core_writers.cpp
cs/cigma/trunk/src/core_writers.h
Log:
Add --output-volume flag to 'cigma mesh-info'
Modified: cs/cigma/trunk/src/cli_mesh_info_cmd.cpp
===================================================================
--- cs/cigma/trunk/src/cli_mesh_info_cmd.cpp 2009-02-18 16:14:12 UTC (rev 14070)
+++ cs/cigma/trunk/src/cli_mesh_info_cmd.cpp 2009-02-18 16:14:14 UTC (rev 14071)
@@ -32,6 +32,7 @@
("mesh-cell", po::value<string>(&cellname), "...cell type for mesh")
("mesh-coords", po::value<string>(&ncfile), "...node coordinates for mesh")
("mesh-connect", po::value<string>(&ebfile), "...connectivity for mesh")
+ ("output-volume", po::value<string>(&volfile), "Output file for element volumes")
;
args.add("mesh", -1);
}
@@ -66,8 +67,13 @@
{
printUsage();
}
- else if (mesh)
+ else if (!mesh)
{
+ string msg("Input mesh not specified!");
+ throw cigma::Exception("MeshInfoCmd::run", msg, 1);
+ }
+ else
+ {
mesh->computeCellVolumes();
const int ndim = mesh->n_dim();
@@ -104,18 +110,29 @@
cout << indent << "Total mesh volume = " << volume << endl;
cout << indent << "Max cell diameter = " << h << endl;
+ if (volfile != "")
+ {
+ TRI_LOG_STR(">> Writing volume file");
+ TRI_LOG(volfile);
+ DataPath path(volfile);
+ WriteCellVolumes(path, mesh->volume, true);
+ cout << "Saved cell volumes to '" << volfile << "'" << endl;
+ }
+
if (false)
{
- DataPath output_path("debug-mesh.h5");
+ namespace fs = boost::filesystem;
+ const string dbg = "debug-mesh.h5";
+ if (fs::exists(dbg))
+ {
+ TRI_LOG_STR(">> Removing existing debug-mesh.h5");
+ fs::remove_all(dbg);
+ }
+ DataPath output_path(dbg);
WriteMeshPart(output_path, mesh, true);
}
}
- else
- {
- string msg("Input mesh not specified!");
- throw cigma::Exception("MeshInfoCmd::run", msg, 1);
- }
return 0;
}
Modified: cs/cigma/trunk/src/cli_mesh_info_cmd.h
===================================================================
--- cs/cigma/trunk/src/cli_mesh_info_cmd.h 2009-02-18 16:14:12 UTC (rev 14070)
+++ cs/cigma/trunk/src/cli_mesh_info_cmd.h 2009-02-18 16:14:14 UTC (rev 14071)
@@ -21,10 +21,10 @@
int run();
public:
- std::string meshfile;
- std::string ncfile;
- std::string ebfile;
- std::string cellname;
+
+ std::string meshfile, volfile;
+ std::string ncfile, ebfile, cellname;
+
boost::shared_ptr<MeshPart> mesh;
};
Modified: cs/cigma/trunk/src/core_writers.cpp
===================================================================
--- cs/cigma/trunk/src/core_writers.cpp 2009-02-18 16:14:12 UTC (rev 14070)
+++ cs/cigma/trunk/src/core_writers.cpp 2009-02-18 16:14:14 UTC (rev 14071)
@@ -13,6 +13,7 @@
#include <string>
#include <sstream>
+#include <valarray>
using namespace std;
#ifdef HAVE_VTK
@@ -352,6 +353,49 @@
#endif
}
+void cigma::WriteCellVolumes(const DataPath& path, const std::valarray<double>& volume, bool overwrite)
+{
+ TRI_LOG_STR("cigma::WriteCellVolumes()");
+ TRI_LOG(path);
+
+ string filename = path.filename();
+ string location = path.location();
+
+ shared_ptr<FileWriter> writer = FileWriter::New(filename, "a");
+ writer->setOverwriteMode(overwrite);
+ const FileWriter::WriterType wt = writer->getWriterType();
+ if (wt == FileWriter::HDF5_FILE_WRITER)
+ {
+ int status = writer->writeDataset(location.c_str(), &volume[0], volume.size(), 1);
+ if (status < 0)
+ {
+ std::ostringstream stream;
+ stream << "Could not write cell volumes to the HDF5 file '" << filename << "'" << std::ends;
+ throw cigma::Exception("WriteCellVolumes", stream.str());
+ }
+ }
+ else if (wt == FileWriter::VTK_FILE_WRITER)
+ {
+ throw cigma::Exception("WriteCellVolumes", "Not implemented for VTK files");
+ }
+ else if (wt == FileWriter::TEXT_FILE_WRITER)
+ {
+ int status = writer->writeDataset("", &volume[0], volume.size(), 1);
+ if (status < 0)
+ {
+ std::ostringstream stream;
+ stream << "Could not write cell volumes to the text file '" << filename << "'" << std::ends;
+ throw cigma::Exception("WriteCellVolumes", stream.str());
+ }
+ }
+ else
+ {
+ std::ostringstream stream;
+ stream << "Could not write cell volumes to path '" << path << "'" << std::ends;
+ throw cigma::Exception("WriteCellVolumes", stream.str());
+ }
+}
+
void cigma::WriteResiduals(const DataPath& path, shared_ptr<Residuals> residuals, bool overwrite)
{
TRI_LOG_STR("cigma::WriteResiduals()");
Modified: cs/cigma/trunk/src/core_writers.h
===================================================================
--- cs/cigma/trunk/src/core_writers.h 2009-02-18 16:14:12 UTC (rev 14070)
+++ cs/cigma/trunk/src/core_writers.h 2009-02-18 16:14:14 UTC (rev 14071)
@@ -1,6 +1,7 @@
#ifndef __CIGMA_WRITERS_H__
#define __CIGMA_WRITERS_H__
+#include <valarray>
#include <boost/shared_ptr.hpp>
#include "DataPath.h"
#include "core_array.h"
@@ -22,6 +23,7 @@
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);
void WriteResiduals(const DataPath& path, boost::shared_ptr<Residuals> residuals, bool overwrite=false);
+ void WriteCellVolumes(const DataPath& path, const std::valarray<double>& volume, bool overwrite=false);
}
#endif
More information about the CIG-COMMITS
mailing list