[cig-commits] r14087 - cs/cigma/trunk/src
luis at geodynamics.org
luis at geodynamics.org
Wed Feb 18 08:14:43 PST 2009
Author: luis
Date: 2009-02-18 08:14:43 -0800 (Wed, 18 Feb 2009)
New Revision: 14087
Added:
cs/cigma/trunk/src/core_info.cpp
cs/cigma/trunk/src/core_info.h
Log:
Created core_info.{h,cpp} files
Added: cs/cigma/trunk/src/core_info.cpp
===================================================================
--- cs/cigma/trunk/src/core_info.cpp (rev 0)
+++ cs/cigma/trunk/src/core_info.cpp 2009-02-18 16:14:43 UTC (rev 14087)
@@ -0,0 +1,182 @@
+#include "core_info.h"
+#include "tri_logger.hpp"
+#include <iomanip>
+#include <vector>
+#include <boost/algorithm/string.hpp>
+#include <boost/lexical_cast.hpp>
+#include <boost/shared_ptr.hpp>
+
+using namespace cigma;
+using namespace std;
+using namespace boost;
+
+const string indent = " ";
+
+// ----------------------------------------------------------------------------
+
+static void point_split(const string& s, vector<string>& ss)
+{
+ string val(s);
+ boost::algorithm::replace_all(val, "(", "");
+ boost::algorithm::replace_all(val, ")", "");
+ boost::algorithm::replace_all(val, "[", "");
+ boost::algorithm::replace_all(val, "]", "");
+ boost::split(ss, val, boost::is_any_of(", "), boost::token_compress_on);
+}
+
+void cigma::get_point_from_string(const string& s, valarray<double>& point)
+{
+ TRI_LOG_STR("get_point_from_string()");
+
+ vector<string> components;
+ point_split(s, components);
+
+ const int ndim = components.size();
+ point.resize(ndim);
+
+ try
+ {
+ for (int i = 0; i < ndim; i++)
+ {
+ point[i] = boost::lexical_cast<double>(components[i]);
+ }
+ }
+ catch (bad_lexical_cast& e)
+ {
+ TRI_LOG_STR(">> Caught bad_lexical_cast");
+ throw e;
+ }
+}
+
+void cigma::print_point(ostream& os, valarray<double>& point, int dim)
+{
+ int ndim;
+
+ if (dim == 0)
+ {
+ ndim = point.size();
+ }
+ else
+ {
+ ndim = dim;
+ }
+
+ if (ndim > 0)
+ {
+ if (ndim > 1)
+ {
+ os << "(";
+ }
+ for (int i = 0; i < ndim; i++)
+ {
+ os << point[i];
+ if (i != ndim-1)
+ {
+ os << ", ";
+ }
+ }
+ if (ndim > 1)
+ {
+ os << ")";
+ }
+ }
+}
+
+void cigma::print_node_coords_of_cell(ostream& os, const MeshPart& mesh, int cellid)
+{
+ TRI_LOG_STR("print_node_coords_of_cell()");
+ const int ndim = mesh.n_dim();
+ const int ncells = mesh.n_cells();
+
+ os << endl;
+
+ if ((0 <= cellid) && (cellid < ncells))
+ {
+ shared_ptr<Cell> cell = mesh.getCell();
+
+ mesh.getCell(cellid, *cell);
+
+ const int nno = cell->n_nodes();
+ const double *globverts = cell->globverts;
+
+ os << "Node coordinates for cell " << cellid << endl;
+ os << fixed;
+
+ for (int i = 0; i < nno; i++)
+ {
+ int n = (mesh.connect)->getId(cellid, i);
+
+ os << " ";
+ os << noshowpos;
+ os << setw(7) << right << n;
+ os << showpos;
+ os << " ";
+
+ for (int j = 0; j < ndim; j++)
+ {
+ os << globverts[ndim*i + j] << " ";
+ }
+
+ os << endl;
+
+ }
+
+ os << noshowpos;
+ }
+ else
+ {
+ os << "Cell ID " << cellid << " is out of bounds" << endl;
+ }
+}
+
+void cigma::print_mesh_bounds(ostream& os, const MeshPart& mesh)
+{
+ const int ndim = mesh.n_dim();
+ double minpt[ndim], maxpt[ndim];
+
+ mesh.getBoundingBox(minpt, maxpt);
+
+ os << indent << "Mesh bounds = ";
+
+ for (int i = 0; i < ndim; i++)
+ {
+ os << "[" << minpt[i] << ", " << maxpt[i] << "]";
+ if (i != ndim-1)
+ {
+ os << " x ";
+ }
+ }
+
+ os << endl;
+}
+
+void cigma::print_mesh_info(ostream& os, const MeshPart& mesh, const string& meshpath)
+{
+ const int ndim = mesh.n_dim();
+ const int ncells = mesh.n_cells();
+ const int nnodes = mesh.n_nodes();
+ const double h = mesh.getMaxCellDiameter();
+ const double volume = mesh.getVolume();
+
+ os << endl;
+ os << "Mesh Info:" << endl;
+
+ if (meshpath != "")
+ {
+ os << indent << "Location = " << meshpath << endl;
+ }
+
+ os << indent << "Dimension = " << ndim << endl;
+
+ os << indent << "Number of cells = " << ncells << endl;
+ os << indent << "Number of nodes = " << nnodes << endl;
+
+ os << indent << "Cell type = ";
+ os << Cell::type2string(mesh.getCellType()) << endl;
+
+ print_mesh_bounds(os, mesh);
+
+ os << indent << "Total mesh volume = " << volume << endl;
+ os << indent << "Max cell diameter = " << h << endl;
+}
+
Added: cs/cigma/trunk/src/core_info.h
===================================================================
--- cs/cigma/trunk/src/core_info.h (rev 0)
+++ cs/cigma/trunk/src/core_info.h 2009-02-18 16:14:43 UTC (rev 14087)
@@ -0,0 +1,20 @@
+#ifndef CIGMA_CORE_INFO_H
+#define CIGMA_CORE_INFO_H
+
+#include <valarray>
+#include <iostream>
+
+#include "Cell.h"
+#include "MeshPart.h"
+#include "Function.h"
+
+namespace cigma
+{
+ void get_point_from_string(const std::string& s, std::valarray<double>& point);
+ void print_point(std::ostream& os, std::valarray<double>& point, int dim=0);
+ void print_node_coords_of_cell(std::ostream& os, const MeshPart& mesh, int cellid);
+ void print_mesh_bounds(std::ostream& os, const MeshPart& mesh);
+ void print_mesh_info(std::ostream& os, const MeshPart& mesh, const std::string& meshpath);
+}
+
+#endif
More information about the CIG-COMMITS
mailing list