[cig-commits] r14089 - cs/cigma/trunk/src

luis at geodynamics.org luis at geodynamics.org
Wed Feb 18 08:14:48 PST 2009


Author: luis
Date: 2009-02-18 08:14:47 -0800 (Wed, 18 Feb 2009)
New Revision: 14089

Modified:
   cs/cigma/trunk/src/cli_mesh_info_cmd.cpp
   cs/cigma/trunk/src/cli_mesh_info_cmd.h
Log:
Updated mesh-info command

Modified: cs/cigma/trunk/src/cli_mesh_info_cmd.cpp
===================================================================
--- cs/cigma/trunk/src/cli_mesh_info_cmd.cpp	2009-02-18 16:14:44 UTC (rev 14088)
+++ cs/cigma/trunk/src/cli_mesh_info_cmd.cpp	2009-02-18 16:14:47 UTC (rev 14089)
@@ -1,20 +1,28 @@
 #include "cli_mesh_info_cmd.h"
 #include "core_args.h"
+#include "core_info.h"
 #include "core_writers.h"
+#include <ctime>
 #include <iostream>
+#include <iomanip>
 #include <sstream>
+#include <vector>
+#include <boost/algorithm/string.hpp>
+#include <boost/lexical_cast.hpp>
 
 using namespace cigma;
 using namespace std;
-
+using namespace boost;
 namespace po = boost::program_options;
 
+const string indent = "    ";
+
 // ----------------------------------------------------------------------------
 
 MeshInfoCmd::MeshInfoCmd()
 {
     name = "mesh-info";
-    brief = "Calculate maximum cell diameter for mesh";
+    brief = "Show information about specified mesh";
     usage = "Usage: cigma mesh-info <MeshFile>";
     appendix = "";
 }
@@ -32,7 +40,13 @@
         ("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")
+        ("no-header,n", "Display only info about given cell or node IDs")
+        ("cell-id", po::value<int>(&cellid), "Show information about specific cell")
+        ("node-id", po::value<int>(&nodeid), "Show cells associated with node id")
+        ("query-point,p", po::value<string>(&pointstr), "Query mesh for arbitrary point (use commas)")
+        ("output-mesh,o", po::value<string>(&outputfile), "Output mesh in HDF5 format")
+        ("output-centroid", po::value<string>(&centroidfile), "Output file for element centroids")
+        ("output-volume", po::value<string>(&volumefile), "Output file for element volumes")
         ;
     args.add("mesh", -1);
 }
@@ -47,91 +61,213 @@
     {
         mesh_info.p_mesh = DataPath(meshfile);
         mesh_info.cell_type_name = cellname;
+        mesh = MeshPart::New(mesh_info);
     }
-    else
+    else if (vm.count("mesh-coords") && vm.count("mesh-connect") && vm.count("mesh-cell"))
     {
         mesh_info.p_nc = DataPath(ncfile);
         mesh_info.p_eb = DataPath(ebfile);
         mesh_info.cell_type_name = cellname;
+        mesh = MeshPart::New(mesh_info);
     }
+    else
+    {
+        string msg("No mesh was specified (use --mesh option)");
+        throw cigma::Exception("FunctionInfoCmd::configure", msg, 1);
+    }
 
-    TRI_LOG_STR(mesh_info);
-    mesh = MeshPart::New(mesh_info);
 }
 
-int MeshInfoCmd::run()
+static void print_node_info(shared_ptr<MeshPart> mesh, int nodeid)
 {
-    BaseCmd::run();
+    TRI_LOG_STR("print_node_info()");
+    const int ndim = mesh->n_dim();
+    const int ncells = mesh->n_cells();
+    const int nnodes = mesh->n_nodes();
+    if ((0 <= nodeid) && (nodeid < nnodes))
+    {
+        shared_ptr<Cell> cell = mesh->getCell();
+        int n_nodes_per_cell = mesh->connect->n_dofs();
 
-    if (meshfile == "")
+        cout << endl;
+        cout << "Connectivity of node " << nodeid;
+        cout << ", corresponding to point ";
+        cout << "(";
+        for (int k = 0; k < ndim; k++)
+        {
+            cout << mesh->coords->getPoint(nodeid, k);
+            if (k != ndim-1)
+            {
+                cout << ", ";
+            }
+        }
+        cout << ")";
+        cout << endl;
+
+        for (int e = 0; e < ncells; e++)
+        {
+            int cellid = -1;
+            bool hasnode = false;
+            for (int d = 0; d < n_nodes_per_cell; d++)
+            {
+                if (mesh->connect->getId(e,d) == nodeid)
+                {
+                    cellid = e;
+                    hasnode = true;
+                    break;
+                }
+            }
+            if (hasnode)
+            {
+                cout << setw(7) << cellid << " ->";
+                for (int i = 0; i < n_nodes_per_cell; i++)
+                {
+                    cout << " " << setw(7) << mesh->connect->getId(e,i);
+                }
+                cout << endl;
+            }
+        }
+    }
+    else
     {
-        printUsage();
+        cout << indent << "Node ID " << nodeid << " is out of bounds" << endl;
     }
-    else if (!mesh)
+}
+
+static void print_point_info(shared_ptr<MeshPart> mesh, string pstr)
+{
+    TRI_LOG_STR("print_point_info()");
+    valarray<double> point;
+    get_point_from_string(pstr, point);
+    int ndim = point.size();
+    int meshdim = mesh->n_dim();
+
+    cout << endl;
+    cout << "Looking for point ";
+    print_point(cout, point);
+    cout << endl;
+
+    double pt[3] = {0,0,0};
+    if (ndim == 0)
     {
-        string msg("Input mesh not specified!");
-        throw cigma::Exception("MeshInfoCmd::run", msg, 1);
+        cout << indent << "Error: Query point has zero dimensions!" << endl;
+        return;
     }
+    else if (ndim > 3)
+    {
+        cout << indent << "Error: Query point has too many dimensions (" << ndim << ")" << endl;
+        return;
+    }
+    else if (ndim != meshdim)
+    {
+        cout << indent
+             << "Error: Dimension of query point ("
+             << ndim
+             << ") does not match mesh dimension"
+             << endl;
+    }
     else
     {
-        mesh->computeCellVolumes();
+        for (int i = 0; i < ndim; i++)
+        {
+            pt[i] = point[i];
+        }
 
-        const int ndim = mesh->n_dim();
-        const int ncells = mesh->n_cells();
-        const int nnodes = mesh->coords->n_points();
+        time_t t0, t1;
+        time(&t0);
+        int cellid = -1;
+        bool found = mesh->findCell(pt, &cellid);
+        time(&t1);
 
-        double minpt[ndim], maxpt[ndim];
-        mesh->getBoundingBox(minpt, maxpt);
+        if (found)
+        {
+            cout << indent << "Point found in cell " << cellid << endl;
+        }
+        else
+        {
+            cout << indent << "Point not found in mesh!" << endl;
+        }
 
-        double h = mesh->getMaxCellDiameter();
-        double volume = mesh->getVolume();
+        int dt = t1 - t0;
+        if (dt > 1)
+        {
+            cout << indent << "Time elapsed in search was " << (t1-t0) << " seconds" << endl;
+        }
 
-        const string indent = "    ";
+        if (found)
+        {
+            print_node_coords_of_cell(cout, *mesh, cellid);
+        }
+    }
+}
 
-        cout << "Mesh Info:" << endl;
+int MeshInfoCmd::run()
+{
+    BaseCmd::run();
 
-        cout << indent << "Location  = " << meshfile << endl;
-        cout << indent << "Dimension = " << ndim << endl;
-        cout << indent << "Num cells = " << ncells << endl;
-        cout << indent << "Num nodes = " << nnodes << endl;
-        cout << indent << "Cell type = " << Cell::type2string(mesh->getCellType()) << endl;
+    if (!mesh)
+    {
+        string msg("Input mesh not specified!");
+        throw cigma::Exception("MeshInfoCmd::run", msg, 1);
+    }
+    else
+    {
+        cout << setprecision(8);
 
-        cout << indent << "Mesh bounds = ";
-        for (int i = 0; i < ndim; i++)
+        mesh->computeCellVolumes();
+
+        if (!vm.count("no-header"))
         {
-            cout << "[" << minpt[i] << ", " << maxpt[i] << "]";
-            if (i != ndim-1)
-            {
-                cout << " x ";
-            }
+            print_mesh_info(cout, *mesh, meshfile);
         }
-        cout << endl;
 
-        cout << indent << "Total mesh volume = " << volume << endl; 
-        cout << indent << "Max cell diameter = " << h << endl;
+        if (vm.count("query-point"))
+        {
+            print_point_info(mesh, pointstr);
+        }
 
-        if (volfile != "")
+        if (vm.count("cell-id"))
         {
-            TRI_LOG_STR(">> Writing volume file");
-            TRI_LOG(volfile);
-            DataPath path(volfile);
+            print_node_coords_of_cell(cout, *mesh, cellid);
+        }
+
+        if (vm.count("node-id"))
+        {
+            print_node_info(mesh, nodeid);
+        }
+
+        if (volumefile != "")
+        {
+            TRI_LOG_STR(">> Writing cell volumes to file");
+            TRI_LOG(volumefile);
+            DataPath path(volumefile);
             WriteCellVolumes(path, mesh->volume, true);
-            cout << "Saved cell volumes to '" << volfile << "'" << endl;
+            cout << indent << "Saved cell volumes to '" << volumefile << "'" << endl;
         }
 
-        if (false)
+        if (centroidfile != "")
         {
-            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);
+            TRI_LOG_STR(">> Writing cell centroids to file");
+            TRI_LOG(centroidfile);
+            DataPath path(centroidfile);
+            WriteCellCentroids(path, mesh, true);
+            cout << indent << "Saved cell centroids to '" << centroidfile << "'" << endl;
         }
 
+        if (outputfile != "")
+        {
+            //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);
+            DataPath path(outputfile);
+            WriteMeshPart(path, mesh, true);
+        }
+
     }
 
     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:44 UTC (rev 14088)
+++ cs/cigma/trunk/src/cli_mesh_info_cmd.h	2009-02-18 16:14:47 UTC (rev 14089)
@@ -22,8 +22,12 @@
 
 public:
 
-    std::string meshfile, volfile;
-    std::string ncfile, ebfile, cellname;
+    std::string meshfile, ncfile, ebfile, cellname;
+    std::string volumefile;
+    std::string centroidfile;
+    std::string outputfile;
+    int cellid, nodeid;
+    std::string pointstr;
 
     boost::shared_ptr<MeshPart> mesh;
 



More information about the CIG-COMMITS mailing list