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

luis at geodynamics.org luis at geodynamics.org
Tue Dec 9 18:13:08 PST 2008


Author: luis
Date: 2008-12-09 18:13:07 -0800 (Tue, 09 Dec 2008)
New Revision: 13518

Modified:
   cs/cigma/trunk/src/cli_application.cpp
   cs/cigma/trunk/src/cli_compare_cmd.cpp
   cs/cigma/trunk/src/cli_compare_cmd.h
   cs/cigma/trunk/src/cli_eval_cmd.cpp
   cs/cigma/trunk/src/cli_eval_cmd.h
   cs/cigma/trunk/src/cli_extract_cmd.cpp
   cs/cigma/trunk/src/cli_extract_cmd.h
Log:
Updates to cli

Modified: cs/cigma/trunk/src/cli_application.cpp
===================================================================
--- cs/cigma/trunk/src/cli_application.cpp	2008-12-10 02:13:06 UTC (rev 13517)
+++ cs/cigma/trunk/src/cli_application.cpp	2008-12-10 02:13:07 UTC (rev 13518)
@@ -5,31 +5,34 @@
 #include <cassert>
 #include <stdexcept>
 
+/* boost includes */
+#include <boost/algorithm/string/trim.hpp>
+
 /* cigma includes */
 #include "config.h"
 #include "cli_application.h"
+#include "Exception.h"
 
 /* basic commands */
+//#include "cli_info_cmd.h"
 #include "cli_list_cmd.h"
-//#include "cli_compare_cmd.h"
-//#include "cli_extract_cmd.h"
-//#include "cli_eval_cmd.h"
-//#include "cli_info_cmd.h"
+#include "cli_extract_cmd.h"
+#include "cli_eval_cmd.h"
+#include "cli_compare_cmd.h"
 
 using namespace std;
 using namespace cigma;
 
-
 // ----------------------------------------------------------------------------
 
 Application::Application()
 {
     /* Initialize the basic set of commands */
+    //addCommand(new InfoCmd());
     addCommand(new ListCmd());
-    //addCommand(new ExtractCmd());
-    //addCommand(new EvalCmd());
-    //addCommand(new CompareCmd());
-    //addCommand(new InfoCmd());
+    addCommand(new ExtractCmd());
+    addCommand(new EvalCmd());
+    addCommand(new CompareCmd());
 }
 
 
@@ -245,9 +248,15 @@
             return -1;
         }
     }
+    catch (cigma::Exception &e)
+    {
+        string msg = boost::algorithm::trim_copy(e.getMessage());
+        cout << "cigma: " << msg << " (in " << e.getName() << ")" << endl;
+        return -1;
+    }
     catch (bad_cast &e)
     {
-        cout << "bad cast: " << e.what() << endl;
+        cout << "cigma: bad cast " << e.what() << endl;
         return -1;
     }
     catch (exception &e)
@@ -257,7 +266,8 @@
     }
     catch (...)
     {
-        cout << "Unrecognized exception!" << endl;
+        cout << "cigma: Unrecognized exception!" << endl;
+        return -1;
     }
     return 0;
 }

Modified: cs/cigma/trunk/src/cli_compare_cmd.cpp
===================================================================
--- cs/cigma/trunk/src/cli_compare_cmd.cpp	2008-12-10 02:13:06 UTC (rev 13517)
+++ cs/cigma/trunk/src/cli_compare_cmd.cpp	2008-12-10 02:13:07 UTC (rev 13518)
@@ -1,8 +1,12 @@
-#include "CompareCmd.h"
+#include "cli_compare_cmd.h"
+#include "Common.h"
+#include "core_writers.h"
 
+#include <iostream>
+#include <iomanip>
+
 using namespace std;
 using namespace cigma;
-
 namespace po = boost::program_options;
 
 // ----------------------------------------------------------------------------
@@ -26,17 +30,56 @@
     opts_section = "Compare Options: ";
     opts.add_options()
         ("help,h", "produce help message")
-        ("first,a", po::value<string>(&firstpath), "First field path")
-        ("second,b", po::value<string>(&secondpath), "Second field path")
+        ("verbose,v", "produce verbose output")
+        ("debug,D", "print debugging information")  // XXX: make this a hidden option
+        ("mesh,m", po::value<string>(&imesh), "Integration mesh")
+        ("first,a", po::value<string>(&first), "First field path")
+        ("second,b", po::value<string>(&second), "Second field path")
         ("output,o", po::value<string>(&outputfile), "Output file (residuals)")
+        ("first-mesh", po::value<string>(&firstmesh), "Associated mesh of first field")
+        ("second-mesh", po::value<string>(&secondmesh), "Associated mesh of second field")
+        ("mesh-cell", po::value<string>(&imeshcell), "Associated cell type of integration mesh")
+        ("first-mesh-cell", po::value<string>(&firstmeshcell), "Associated cell type of first mesh")
+        ("second-mesh-cell", po::value<string>(&secondmeshcell), "Associated cell type of second mesh")
+        ("freq,f", po::value<int>(&(op.freq)), "Output frequency of timer")
         ;
     args.add("first", 1);
     args.add("second", 1);
+    //args.add("first-mesh", 1);
+    //args.add("second-mesh", 1);
 }
 
 void CompareCmd::configure()
 {
     BaseCmd::configure();
+
+    if (vm.count("help"))
+    {
+        return;
+    }
+
+    if (!vm.count("debug"))
+    {
+        TRI_LOG_OFF();
+    }
+
+    if (vm.count("verbose"))
+    {
+        op.verbose = true;
+        op.freq = 1000;
+    }
+
+    TRI_LOG_STR("CompareCmd::configure()");
+
+    op.first_name = first;
+    op.second_name = second;
+
+    DataPath im(imesh);
+    op.domain_info.mesh_info.p_mesh = DataPath(imesh);
+    op.domain_info.p_field = (op.domain_info.mesh_info).get_nc_path();
+    op.domain_info.fe_info.q_info.cell_type_name = imeshcell;
+
+    op.configure();
 }
 
 int CompareCmd::run()
@@ -47,7 +90,37 @@
         return 1;
     }
 
-    return 0;
+    TRI_LOG_STR("CompareCmd::run()");
+    TRI_LOG(imesh);
+    TRI_LOG(first);
+    TRI_LOG(second);
+    TRI_LOG(firstmesh);
+    TRI_LOG(secondmesh);
+    TRI_LOG(outputfile);
+
+    DataPath path(outputfile);
+
+    int status = op.run();
+
+    double L2 = op.residuals->L2();
+    double max_residual = op.residuals->max();
+
+    if (op.verbose)
+    {
+        // report errors
+        cout << setprecision(12) << endl;
+        cout << "Global Norms" << endl;
+        cout << "  L2 = " << L2 << endl;
+        cout << "  MaxResidual = " << max_residual << endl;
+        cout << endl;
+
+        // write out data
+        cout << "Creating file " << path.filename() << endl;
+    }
+
+    WriteResiduals(path, op.residuals);
+
+    return status;
 }
 
 // ----------------------------------------------------------------------------

Modified: cs/cigma/trunk/src/cli_compare_cmd.h
===================================================================
--- cs/cigma/trunk/src/cli_compare_cmd.h	2008-12-10 02:13:06 UTC (rev 13517)
+++ cs/cigma/trunk/src/cli_compare_cmd.h	2008-12-10 02:13:07 UTC (rev 13518)
@@ -3,6 +3,7 @@
 
 
 #include "cli_base_cmd.h"
+#include "core_compare_op.h"
 
 namespace cigma
 {
@@ -12,20 +13,26 @@
 class cigma::CompareCmd : public BaseCmd
 {
 public:
+
     CompareCmd();
     ~CompareCmd();
 
-public:
     void defineOptions();
     void configure();
     int run();
 
 public:
-    std::string qmesh;
-    std::string qrule;
-    std::string firstpath;
-    std::string secondpath;
+
+    std::string imesh, imeshcell;
+    std::string irule;
+    std::string first;
+    std::string second;
+    std::string firstmesh, secondmesh;
+    std::string firstmeshcell, secondmeshcell;
     std::string outputfile;
+
+    CompareOp op;
+
 };
 
 #endif

Modified: cs/cigma/trunk/src/cli_eval_cmd.cpp
===================================================================
--- cs/cigma/trunk/src/cli_eval_cmd.cpp	2008-12-10 02:13:06 UTC (rev 13517)
+++ cs/cigma/trunk/src/cli_eval_cmd.cpp	2008-12-10 02:13:07 UTC (rev 13518)
@@ -1,13 +1,15 @@
-#include <iostream>
+#include "cli_eval_cmd.h"
 #include "Common.h"
-#include "cli_eval_cmd.h"
+#include "DataPath.h"
+#include "core_writers.h"
+using namespace cigma;
 
-
+#include <iostream>
 using namespace std;
-using namespace cigma;
 
 namespace po = boost::program_options;
 
+
 // ----------------------------------------------------------------------------
 
 EvalCmd::EvalCmd()
@@ -24,6 +26,7 @@
 {
 }
 
+
 // ----------------------------------------------------------------------------
 
 void EvalCmd::defineOptions()
@@ -31,10 +34,11 @@
     opts_section = "Eval Options: ";
     opts.add_options()
         ("help,h", "produce help message")
+        ("verbose,v", "produce verbose output")
         ("debug,D", "print debugging information")      /* XXX: make this a hidden option */
         ("function,f", po::value<string>(&function), "Function <FUNC> to evaluate")
-        ("points,p", po::value<string>(&pointsfile), "Input quadrature points <QPTS-IN>")
-        ("output,o", po::value<string>(&valuesfile), "Output values of function <QVALS-OUT")
+        ("points,p", po::value<string>(&points), "Input quadrature points <QPTS-IN>")
+        ("output,o", po::value<string>(&values), "Output values of function <QVALS-OUT")
         ;
     args.add("function", 1);
     args.add("points", 1);
@@ -44,11 +48,27 @@
 {
     BaseCmd::configure();
 
+    if (vm.count("help"))
+    {
+        return;
+    }
+
     if (!vm.count("debug"))
     {
         TRI_LOG_OFF();
     }
 
+    if (vm.count("verbose"))
+    {
+        op.verbose = true;
+    }
+
+    TRI_LOG_STR("EvalCmd::configure()");
+
+    op.fn_name = this->function;
+    op.nc_path = DataPath(this->points);
+
+    op.configure();
 }
 
 int EvalCmd::run()
@@ -61,11 +81,21 @@
 
     TRI_LOG_STR("EvalCmd::run()");
     TRI_LOG(function);
-    TRI_LOG(pointsfile);
-    TRI_LOG(valuesfile);
+    TRI_LOG(points);
+    TRI_LOG(values);
 
+    DataPath path(values);
 
-    return 0;
+    int status = op.run();
+
+    if (op.verbose)
+    {
+        cout << "Creating file " << path.filename() << endl;
+    }
+
+    WriteArray(path, op.values);
+
+    return status;
 }
 
 // ----------------------------------------------------------------------------

Modified: cs/cigma/trunk/src/cli_eval_cmd.h
===================================================================
--- cs/cigma/trunk/src/cli_eval_cmd.h	2008-12-10 02:13:06 UTC (rev 13517)
+++ cs/cigma/trunk/src/cli_eval_cmd.h	2008-12-10 02:13:07 UTC (rev 13518)
@@ -2,6 +2,7 @@
 #define __CIGMA_EVAL_CMD_H__
 
 #include "cli_base_cmd.h"
+#include "core_eval_op.h"
 
 namespace cigma
 {
@@ -11,18 +12,22 @@
 class cigma::EvalCmd : public BaseCmd
 {
 public:
+
     EvalCmd();
     ~EvalCmd();
 
-public:
     void defineOptions();
     void configure();
     int run();
 
 public:
+
     std::string function;
-    std::string pointsfile;
-    std::string valuesfile;
+    std::string points;
+    std::string values;
+
+    EvalOp op;
+
 };
 
 #endif

Modified: cs/cigma/trunk/src/cli_extract_cmd.cpp
===================================================================
--- cs/cigma/trunk/src/cli_extract_cmd.cpp	2008-12-10 02:13:06 UTC (rev 13517)
+++ cs/cigma/trunk/src/cli_extract_cmd.cpp	2008-12-10 02:13:07 UTC (rev 13518)
@@ -1,4 +1,7 @@
 #include "cli_extract_cmd.h"
+#include "Exception.h"
+#include "DataPath.h"
+#include "core_writers.h"
 
 #include <iostream>
 #include <string>
@@ -33,10 +36,12 @@
 
     opts.add_options()
         ("help,h", "produce help message")
+        ("verbose,v", "produce verbose output")
+        ("debug,D", "print debugging information")
         ("rule,r", po::value<string>(&rule), "use a specific quadrature rule")
         ("rule-order,q", po::value<unsigned int>(&rule_order), "use a specific quadrature order")
-        ("mesh,m", po::value<string>(&meshpath), "mesh file (or path)")
-        ("output,o", po::value<string>(&pointfile), "Output HDF5 file for quadrature points")
+        ("mesh,m", po::value<string>(&mesh), "mesh file (or path)")
+        ("output,o", po::value<string>(&points), "Output HDF5 file for quadrature points")
         ;
 
     args.add("mesh", 1);
@@ -48,8 +53,20 @@
 {
     BaseCmd::configure();
 
-    if (true)
+    if (vm.count("help"))
     {
+        return;
+    }
+
+    if (!vm.count("debug"))
+    {
+        TRI_LOG_OFF();
+    }
+
+    TRI_LOG_STR("ExtractCmd::configure()");
+
+    if (vm.count("verbose"))
+    {
         if (vm.count("rule"))
         {
             cout << "Rule: " << rule << endl;
@@ -60,13 +77,19 @@
         }
         if (vm.count("mesh"))
         {
-            cout << "Input Mesh: " << meshpath << endl;
+            cout << "Input Mesh: " << mesh << endl;
         }
         if (vm.count("output"))
         {
-            cout << "Output Points: " << pointfile << endl;
+            cout << "Output Points: " << points << endl;
         }
+        op.verbose = true;
     }
+
+    op.quadrature_info.cell_type_name = rule;
+    op.mesh_info.p_mesh = DataPath(mesh);
+
+    op.configure();
 }
 
 
@@ -78,6 +101,11 @@
         return 1;
     }
 
+    TRI_LOG_STR("ExtractCmd::run()");
+    TRI_LOG(rule);
+    TRI_LOG(mesh);
+    TRI_LOG(points);
+
     // Defer work to the appropriate ExtractOp function
     //  Create QuadratureRule object
     //  Obtain specified Mesh object from disk
@@ -89,7 +117,18 @@
     //      until we exhaust the cell iterator
     //  Close the hdf5 file
 
-    return 0;
+    DataPath path(points);
+    
+    int status = op.run();
+
+    if (op.verbose)
+    {
+        cout << "Creating file " << path.filename() << endl;
+    }
+    
+    WriteQPoints(path, op.weights, op.points);
+
+    return status;
 }
 
 // ----------------------------------------------------------------------------

Modified: cs/cigma/trunk/src/cli_extract_cmd.h
===================================================================
--- cs/cigma/trunk/src/cli_extract_cmd.h	2008-12-10 02:13:06 UTC (rev 13517)
+++ cs/cigma/trunk/src/cli_extract_cmd.h	2008-12-10 02:13:07 UTC (rev 13518)
@@ -2,6 +2,7 @@
 #define __CIGMA_EXTRACT_CMD_H__
 
 #include "cli_base_cmd.h"
+#include "core_extract_op.h"
 
 namespace cigma
 {
@@ -14,20 +15,23 @@
 class cigma::ExtractCmd : public BaseCmd
 {
 public:
+
     ExtractCmd();
     ~ExtractCmd();
 
-public:
     void defineOptions();
     void configure();
     int run();
 
 public:
+
     std::string rule;
     unsigned int rule_order;
+    std::string mesh;
+    std::string points;
 
-    std::string meshpath;
-    std::string pointfile;
+    ExtractOp op;
+
 };
 
 #endif



More information about the CIG-COMMITS mailing list