[cig-commits] r9195 - in cs/benchmark/cigma/trunk/src: . tests

luis at geodynamics.org luis at geodynamics.org
Wed Jan 30 05:58:06 PST 2008


Author: luis
Date: 2008-01-30 05:58:06 -0800 (Wed, 30 Jan 2008)
New Revision: 9195

Modified:
   cs/benchmark/cigma/trunk/src/CommandSet.cpp
   cs/benchmark/cigma/trunk/src/CommandSet.h
   cs/benchmark/cigma/trunk/src/CompareCmd.cpp
   cs/benchmark/cigma/trunk/src/CompareCmd.h
   cs/benchmark/cigma/trunk/src/CubeCmd.cpp
   cs/benchmark/cigma/trunk/src/DofHandler.h
   cs/benchmark/cigma/trunk/src/EvalCmd.cpp
   cs/benchmark/cigma/trunk/src/ExtractCmd.cpp
   cs/benchmark/cigma/trunk/src/FiatProxy.cpp
   cs/benchmark/cigma/trunk/src/FiatProxy.h
   cs/benchmark/cigma/trunk/src/HdfReader.cpp
   cs/benchmark/cigma/trunk/src/HdfWriter.cpp
   cs/benchmark/cigma/trunk/src/HdfWriter.h
   cs/benchmark/cigma/trunk/src/Makefile
   cs/benchmark/cigma/trunk/src/Misc.cpp
   cs/benchmark/cigma/trunk/src/Misc.h
   cs/benchmark/cigma/trunk/src/TextWriter.cpp
   cs/benchmark/cigma/trunk/src/TextWriter.h
   cs/benchmark/cigma/trunk/src/VtkReader.cpp
   cs/benchmark/cigma/trunk/src/VtkReader.h
   cs/benchmark/cigma/trunk/src/VtkWriter.cpp
   cs/benchmark/cigma/trunk/src/VtkWriter.h
   cs/benchmark/cigma/trunk/src/Writer.h
   cs/benchmark/cigma/trunk/src/tests/TestAnn.cpp
   cs/benchmark/cigma/trunk/src/tests/TestAnnLocator.cpp
   cs/benchmark/cigma/trunk/src/tests/TestFiatProxy.cpp
   cs/benchmark/cigma/trunk/src/tests/TestMeshPart.cpp
   cs/benchmark/cigma/trunk/src/tests/TestNumeric.cpp
   cs/benchmark/cigma/trunk/src/vtkls.cpp
Log:
Made various changes relating to I/O and build errors & warnings
  * Fixed build errors
  * Fixed all build warnings (except for one)
  * Still need to fix load_* functions in Misc.cpp
  * Worked on {Hdf,Vtk,Text}{Reader,Writer} classes
  * Moved functionality from VtkUgSimpleWriter to VtkWriter
  * Moved functionality from VtkUgReader to VtkReader
  * Updated tests to use Vtk{Reader,Writer}
  * Added CmdNames to Command class
  * Updated FLAGS in src/Makefile


Modified: cs/benchmark/cigma/trunk/src/CommandSet.cpp
===================================================================
--- cs/benchmark/cigma/trunk/src/CommandSet.cpp	2008-01-29 23:19:32 UTC (rev 9194)
+++ cs/benchmark/cigma/trunk/src/CommandSet.cpp	2008-01-30 13:58:06 UTC (rev 9195)
@@ -32,7 +32,7 @@
     addCommand(help);
     addCommand(new CompareCmd());
     addCommand(new ExtractCmd());
-    addCommand(new CubeCmd());
+    //addCommand(new CubeCmd());
     addCommand(new EvalCmd());
     //addCommand(new SkelCmd());
 

Modified: cs/benchmark/cigma/trunk/src/CommandSet.h
===================================================================
--- cs/benchmark/cigma/trunk/src/CommandSet.h	2008-01-29 23:19:32 UTC (rev 9194)
+++ cs/benchmark/cigma/trunk/src/CommandSet.h	2008-01-30 13:58:06 UTC (rev 9195)
@@ -2,6 +2,7 @@
 #define __COMMAND_SET_H__
 
 #include <map>
+#include <vector>
 #include <string>
 
 #include "Command.h"
@@ -19,6 +20,7 @@
 {
 public:
     typedef std::map<std::string,Command*> CmdMap;
+    typedef std::vector<std::string> CmdNames;
 
 public:
     CommandSet();
@@ -33,6 +35,7 @@
     Command *getCommand(std::string name);
 
 public:
+    CmdNames names;
     CmdMap commands;
 };
 

Modified: cs/benchmark/cigma/trunk/src/CompareCmd.cpp
===================================================================
--- cs/benchmark/cigma/trunk/src/CompareCmd.cpp	2008-01-29 23:19:32 UTC (rev 9194)
+++ cs/benchmark/cigma/trunk/src/CompareCmd.cpp	2008-01-30 13:58:06 UTC (rev 9195)
@@ -116,7 +116,7 @@
     in = opt->getValue("first");
     if (in == 0)
     {
-        in = "./tests/strikeslip_tet4_1000m_t0.vtk:displacements_t0";
+        in = (char *)"./tests/strikeslip_tet4_1000m_t0.vtk:displacements_t0"; // XXX: get rid of these defaults and the subsequent if(!debug){} construct
         if (!debug)
         {
             std::cerr << "compare: Please specify the option --fieldA" << std::endl;
@@ -132,7 +132,7 @@
     in = opt->getValue("second");
     if (in == 0)
     {
-        in = "./tests/strikeslip_hex8_1000m_t0.vtk:displacements_t0";
+        in = (char *)"./tests/strikeslip_hex8_1000m_t0.vtk:displacements_t0";
         if (!debug)
         {
             std::cerr << "compare: Please specify the option --fieldB" << std::endl;
@@ -147,7 +147,7 @@
     in = opt->getValue("output");
     if (in == 0)
     {
-        in = "foo.vtk";
+        in = (char *)"foo.vtk";
         if (!debug)
         {
             std::cerr << "compare: Please specify the option --output" << std::endl;
@@ -167,7 +167,7 @@
     in = opt->getValue("output-frequency");
     if (in == 0)
     {
-        in = "1000";
+        in = (char *)"1000";
     }
     inputstr = in;
     string_to_int(inputstr, output_frequency);
@@ -194,7 +194,7 @@
 
 
     field_a = new FE_Field();
-    load_field(inputfileA, locationA, readerA, field_a);
+    //load_field(inputfileA, locationA, readerA, field_a);
     std::cout << "first field location = " << locationA << std::endl;
     std::cout << "first field inputfile = " << inputfileA << std::endl;
     std::cout << "first field extension = " << extA << std::endl;
@@ -205,7 +205,7 @@
               << field_a->n_rank() << std::endl;
 
     field_b = new FE_Field();
-    load_field(inputfileB, locationB, readerB, field_b);
+    //load_field(inputfileB, locationB, readerB, field_b);
     std::cout << "second field location = " << locationB << std::endl;
     std::cout << "second field inputfile = " << inputfileB << std::endl;
     std::cout << "second field extension = " << extB << std::endl;
@@ -239,6 +239,7 @@
     assert(field_b != 0);
     assert(field_a->n_dim() == field_a->n_dim());
     assert(field_a->n_rank() == field_b->n_rank());
+    assert(writer != 0);
 
 
     Cell *cell_a = field_a->fe->cell;
@@ -271,8 +272,8 @@
     time(&t_0);
     t_e = t_0;
 
-    const int eltPeriod = output_frequency;
-    const int eltMax = 1000;
+    //const int eltPeriod = output_frequency;
+    //const int eltMax = 1000;
 
     if (verbose)
     {
@@ -355,15 +356,33 @@
     std::cout << std::setprecision(12);
     std::cout << "L2 = " << L2 << std::endl;
 
+
     /* write out data */
     {
+        residuals = new FE_Field();
+        residuals->fe = 0;
+        residuals->meshPart = mesh;
+        residuals->dofHandler = new DofHandler();
+        residuals->dofHandler->nno = nel;
+        residuals->dofHandler->ndim = 1;
+        residuals->dofHandler->dofs = epsilon;
+
+        writer->open(output_filename);
+        writer->write_field(residuals);
+        writer->close();
+    }
+
+
+    /* write out data
+    {
         int nno = mesh->nno;
         int nsd = mesh->nsd;
         int ndofs = mesh->ndofs;
         double *coords = mesh->coords;
         int *connect = mesh->connect;
 
-        /* XXX: create a cell-based ResidualField class */
+        // XXX: create a cell-based ResidualField class
+
         //std::cout << "Creating file " << output_filename << std::endl;
         VtkUgSimpleWriter *writer = new VtkUgSimpleWriter();
         writer->open(output_filename);
@@ -374,7 +393,7 @@
         writer->write_cell_data(output_name.c_str(), epsilon, nel, 1);
         writer->close();
         //delete writer;
-    }
+    } // */
 
     /* clean up */
     delete [] epsilon;

Modified: cs/benchmark/cigma/trunk/src/CompareCmd.h
===================================================================
--- cs/benchmark/cigma/trunk/src/CompareCmd.h	2008-01-29 23:19:32 UTC (rev 9194)
+++ cs/benchmark/cigma/trunk/src/CompareCmd.h	2008-01-30 13:58:06 UTC (rev 9195)
@@ -33,7 +33,7 @@
     MeshPart *mesh;
     FE_Field *field_a;
     FE_Field *field_b;
-    Field *residuals;
+    FE_Field *residuals;
     Reader *readerA;
     Reader *readerB;
     Reader *readerQ;
@@ -41,7 +41,10 @@
     Writer *writer;
 
 public:
-    std::string locationA, locationB;
+    std::string locationA;
+    std::string locationB;
+    std::string locationQ;
+    std::string locationM;
     std::string output_filename, output_name;
     bool verbose;
     int output_frequency;

Modified: cs/benchmark/cigma/trunk/src/CubeCmd.cpp
===================================================================
--- cs/benchmark/cigma/trunk/src/CubeCmd.cpp	2008-01-29 23:19:32 UTC (rev 9194)
+++ cs/benchmark/cigma/trunk/src/CubeCmd.cpp	2008-01-30 13:58:06 UTC (rev 9195)
@@ -152,6 +152,8 @@
     writer->write_cell_types(mesh->nsd, mesh->nel, mesh->ndofs);
     writer->close();
     //delete writer;
+
+    return 0;
 }
 
 // ---------------------------------------------------------------------------

Modified: cs/benchmark/cigma/trunk/src/DofHandler.h
===================================================================
--- cs/benchmark/cigma/trunk/src/DofHandler.h	2008-01-29 23:19:32 UTC (rev 9194)
+++ cs/benchmark/cigma/trunk/src/DofHandler.h	2008-01-30 13:58:06 UTC (rev 9195)
@@ -26,7 +26,7 @@
     void get_data(int num, int *nodes, double *d);
 
 public:
-    int nno;
+    int nno;            // XXX: rename to num (using for both PointData and CellData)
     int ndim;
     double *dofs;
     MeshPart *meshPart;

Modified: cs/benchmark/cigma/trunk/src/EvalCmd.cpp
===================================================================
--- cs/benchmark/cigma/trunk/src/EvalCmd.cpp	2008-01-29 23:19:32 UTC (rev 9194)
+++ cs/benchmark/cigma/trunk/src/EvalCmd.cpp	2008-01-30 13:58:06 UTC (rev 9195)
@@ -2,9 +2,9 @@
 #include <cassert>
 #include "EvalCmd.h"
 #include "StringUtils.h"
-#include "VtkUgReader.h"
-#include "VtkUgSimpleWriter.h"
-#include "VtkUgMeshPart.h"
+#include "VtkReader.h"
+#include "VtkWriter.h"
+#include "MeshPart.h"
 #include "Tet.h"
 #include "Hex.h"
 
@@ -90,7 +90,7 @@
     int dofs_nno, dofs_valdim;
     double *dofs;
 
-    VtkUgReader *reader = new VtkUgReader();
+    VtkReader *reader = new VtkReader();
     reader->open(inputfile);
     reader->get_coordinates(&coords, &nno, &nsd);
     reader->get_connectivity(&connect, &nel, &ndofs);
@@ -99,7 +99,7 @@
     field = new FE_Field();
     field->dim = nsd;
     field->rank = dofs_valdim;
-    field->meshPart = new cigma::VtkUgMeshPart();
+    field->meshPart = new MeshPart();
     field->meshPart->set_coordinates(coords, nno, nsd);
     field->meshPart->set_connectivity(connect, nel, ndofs);
 
@@ -127,7 +127,7 @@
     int pts_nno, pts_nsd;
     double *pts_coords;
 
-    VtkUgReader *pointsreader = new VtkUgReader();
+    VtkReader *pointsreader = new VtkReader();
     pointsreader->open(pointsfile);
     pointsreader->get_coordinates(&pts_coords, &pts_nno, &pts_nsd);
     points = new Points();
@@ -162,7 +162,7 @@
     }
 
     std::cout << "Creating file " << output_filename << std::endl;
-    VtkUgSimpleWriter *writer = new VtkUgSimpleWriter();
+    VtkWriter *writer = new VtkWriter();
     writer->open(output_filename);
     writer->write_header();
     writer->write_point_data("values", phi, npts, valdim);

Modified: cs/benchmark/cigma/trunk/src/ExtractCmd.cpp
===================================================================
--- cs/benchmark/cigma/trunk/src/ExtractCmd.cpp	2008-01-29 23:19:32 UTC (rev 9194)
+++ cs/benchmark/cigma/trunk/src/ExtractCmd.cpp	2008-01-30 13:58:06 UTC (rev 9195)
@@ -2,9 +2,9 @@
 #include <cassert>
 #include "ExtractCmd.h"
 #include "StringUtils.h"
-#include "VtkUgReader.h"
-#include "VtkUgMeshPart.h"
-#include "VtkUgSimpleWriter.h"
+#include "VtkReader.h"
+#include "VtkWriter.h"
+#include "MeshPart.h"
 #include "Tet.h"
 #include "Hex.h"
 
@@ -79,13 +79,13 @@
 
         std::cout << "Reading file " << meshfile << std::endl;
 
-        VtkUgReader reader;
+        VtkReader reader;
         reader.open(meshfile);
         reader.get_coordinates(&coordinates, &nno, &nsd);
         reader.get_connectivity(&connectivity, &nel, &ndofs);
         std::cout << "mesh ndofs = " << ndofs << std::endl;
 
-        coords->meshPart = new VtkUgMeshPart();
+        coords->meshPart = new MeshPart();
         coords->meshPart->set_coordinates(coordinates, nno, nsd);
         coords->meshPart->set_connectivity(connectivity, nel, ndofs);
 
@@ -218,7 +218,7 @@
     }
 
     std::cout << "Creating file " << output_filename << std::endl;
-    VtkUgSimpleWriter *writer = new VtkUgSimpleWriter();
+    VtkWriter *writer = new VtkWriter();
     writer->open(output_filename);
     writer->write_header();
     writer->write_points(global_points, nel*nq, nsd);

Modified: cs/benchmark/cigma/trunk/src/FiatProxy.cpp
===================================================================
--- cs/benchmark/cigma/trunk/src/FiatProxy.cpp	2008-01-29 23:19:32 UTC (rev 9194)
+++ cs/benchmark/cigma/trunk/src/FiatProxy.cpp	2008-01-30 13:58:06 UTC (rev 9195)
@@ -78,12 +78,40 @@
         Py_XDECREF(module);
 }
 
+
+
+// ---------------------------------------------------------------------------
+
+cigma::FiatProxy::FiatShape
+cigma::FiatProxy::getFiatShape(Cell::Geometry cellGeometry)
+{
+    switch (cellGeometry)
+    {
+    case Cell::TRIANGLE:
+        return FiatProxy::TRIANGLE;
+    case Cell::QUADRANGLE:
+        return FiatProxy::QUADRANGLE;
+    case Cell::TETRAHEDRON:
+        return FiatProxy::TETRAHEDRON;
+    case Cell::HEXAHEDRON:
+        return FiatProxy::HEXAHEDRON;
+    default:
+        break;
+    }
+    return FiatProxy::POINT;
+}
+
+
+
+
+// ---------------------------------------------------------------------------
+
 void cigma::FiatProxy::test(const char *msg, int n)
 {
     PyObject *result;
     long answer;
     
-    result = PyObject_CallFunction(test_fn, "(si)", msg, n);
+    result = PyObject_CallFunction(test_fn, (char *)"(si)", msg, n);
 
     if (result)
     {

Modified: cs/benchmark/cigma/trunk/src/FiatProxy.h
===================================================================
--- cs/benchmark/cigma/trunk/src/FiatProxy.h	2008-01-29 23:19:32 UTC (rev 9194)
+++ cs/benchmark/cigma/trunk/src/FiatProxy.h	2008-01-30 13:58:06 UTC (rev 9195)
@@ -3,6 +3,7 @@
 
 #include "Python.h"
 #include "numpy/arrayobject.h"
+#include "Cell.h"
 
 namespace cigma
 {
@@ -13,10 +14,11 @@
 {
 public:
     typedef enum {
+        POINT=0,
         LINE=12,
         TRIANGLE=23,
         QUADRANGLE=24,
-        TETRAHDRON=34,
+        TETRAHEDRON=34,
         HEXAHEDRON=38
     } FiatShape;
 
@@ -29,6 +31,9 @@
     void finalize();
 
 public:
+    static FiatShape getFiatShape(Cell::Geometry cellGeometry);
+
+public:
     void test(const char *msg, int n);
     void quadrature(int shape, int order, double **x, double **w, int *npts, int *dim);
     void tabulate(int npts, double *pts, double *basis, double *basisDeriv);

Modified: cs/benchmark/cigma/trunk/src/HdfReader.cpp
===================================================================
--- cs/benchmark/cigma/trunk/src/HdfReader.cpp	2008-01-29 23:19:32 UTC (rev 9194)
+++ cs/benchmark/cigma/trunk/src/HdfReader.cpp	2008-01-30 13:58:06 UTC (rev 9195)
@@ -7,6 +7,7 @@
 
 cigma::HdfReader::HdfReader()
 {
+    file_id = -1;
 }
 
 cigma::HdfReader::~HdfReader()
@@ -28,6 +29,10 @@
 close()
 {
     herr_t status = H5Fclose(file_id);
+    if (status < 0)
+    {
+        // XXX: emit warning?
+    }
 }
 
 // ---------------------------------------------------------------------------
@@ -37,10 +42,18 @@
 {
     int rank;
     hid_t type_id;
-    hid_t coords_id = h5io_dset_open(file_id, loc, &type_id, &rank, NULL, NULL);
+    hid_t coords_id;
+    herr_t status;
+
+    coords_id = h5io_dset_open(file_id, loc, &type_id, &rank, NULL, NULL);
+    assert(H5Tget_class(type_id) == H5T_FLOAT);
     assert(coords_id >= 0);
     assert(rank == 2);
-    herr_t status = H5Dclose(coords_id);
+    status = H5Dclose(coords_id);
+    if (status < 0)
+    {
+        // XXX: emit warning
+    }
 
     int ierr;
     ierr = h5io_dset_read2(file_id, loc, H5T_NATIVE_DOUBLE,
@@ -53,10 +66,18 @@
 {
     int rank;
     hid_t type_id;
-    hid_t connect_id = h5io_dset_open(file_id, loc, &type_id, &rank, NULL, NULL);
+    hid_t connect_id;
+    herr_t status;
+
+    connect_id = h5io_dset_open(file_id, loc, &type_id, &rank, NULL, NULL);
+    assert(H5Tget_class(type_id) == H5T_INTEGER);
     assert(connect_id >= 0);
     assert(rank == 2);
-    herr_t status = H5Dclose(connect_id);
+    status = H5Dclose(connect_id);
+    if (status < 0)
+    {
+        // XXX: emit warning
+    }
 
     int ierr;
     ierr = h5io_dset_read2(file_id, loc, H5T_NATIVE_INT,
@@ -68,10 +89,18 @@
 {
     int rank;
     hid_t type_id;
-    hid_t dataset_id = h5io_dset_open(file_id, loc, &type_id, &rank, NULL, NULL);
+    hid_t dataset_id;
+    herr_t status;
+
+    dataset_id = h5io_dset_open(file_id, loc, &type_id, &rank, NULL, NULL);
+    assert(H5Tget_class(type_id) == H5T_FLOAT);
     assert(dataset_id >= 0);
     assert(rank == 2);
-    herr_t status = H5Dclose(dataset_id);
+    status = H5Dclose(dataset_id);
+    if (status < 0)
+    {
+        // XXX: emit warning
+    }
 
     int ierr;
     ierr = h5io_dset_read2(file_id, loc, H5T_NATIVE_DOUBLE,

Modified: cs/benchmark/cigma/trunk/src/HdfWriter.cpp
===================================================================
--- cs/benchmark/cigma/trunk/src/HdfWriter.cpp	2008-01-29 23:19:32 UTC (rev 9194)
+++ cs/benchmark/cigma/trunk/src/HdfWriter.cpp	2008-01-30 13:58:06 UTC (rev 9195)
@@ -1,15 +1,52 @@
-#include "HdfWriter.h"
 #include <cassert>
 #include <cstdlib>
+#include "HdfWriter.h"
+#include "h5io.h"
 
+using namespace std;
+
+
 // ---------------------------------------------------------------------------
+
 cigma::HdfWriter::HdfWriter()
 {
+    file_id = -1;
 }
 
 cigma::HdfWriter::~HdfWriter()
 {
+    close();
 }
 
+
 // ---------------------------------------------------------------------------
 
+void cigma::HdfWriter::
+open(std::string filename)
+{
+    file_id = h5io_file_open(filename.c_str(), "rw");
+    if (file_id < 0)
+    {
+        // XXX: throw exception
+    }
+}
+
+void cigma::HdfWriter::
+close()
+{
+    if (file_id != -1)
+    {
+        H5Fclose(file_id);
+    }
+}
+
+
+// ---------------------------------------------------------------------------
+
+void cigma::HdfWriter::
+write_field(FE_Field *field)
+{
+    assert(field != 0);
+}
+
+// ---------------------------------------------------------------------------

Modified: cs/benchmark/cigma/trunk/src/HdfWriter.h
===================================================================
--- cs/benchmark/cigma/trunk/src/HdfWriter.h	2008-01-29 23:19:32 UTC (rev 9194)
+++ cs/benchmark/cigma/trunk/src/HdfWriter.h	2008-01-30 13:58:06 UTC (rev 9195)
@@ -2,6 +2,7 @@
 #define __HDF_WRITER_H__
 
 #include "Writer.h"
+#include "hdf5.h"
 
 
 namespace cigma
@@ -18,7 +19,15 @@
 
 public:
     WriterType getType() { return HDF_WRITER; }
+    void open(std::string filename);
+    void close();
 
+public:
+    void write_field(FE_Field *field);
+
+public:
+    hid_t file_id;
 };
 
+
 #endif

Modified: cs/benchmark/cigma/trunk/src/Makefile
===================================================================
--- cs/benchmark/cigma/trunk/src/Makefile	2008-01-29 23:19:32 UTC (rev 9194)
+++ cs/benchmark/cigma/trunk/src/Makefile	2008-01-30 13:58:06 UTC (rev 9195)
@@ -12,6 +12,8 @@
 FLAGS += $(INCLUDES)
 
 LDFLAGS += $(VTK_LDFLAGS) $(VTK_LIBS)
+LDFLAGS += $(PYTHON_LDFLAGS) $(PYTHON_LIBS)
+LDFLAGS += $(HDF5_LDFLAGS) $(HDF5_LIBS)
 
 ANNLIB = ../lib/libann.a
 H5IOLIB = ../lib/libh5io.a
@@ -40,8 +42,9 @@
 	TextReader.o \
 	VtkReader.o \
 	Writer.o \
+	HdfWriter.o \
 	TextWriter.o \
-	VtkUgSimpleWriter.o \
+	VtkWriter.o \
 	AnyOption.o \
 	StringUtils.o \
 	Command.o \

Modified: cs/benchmark/cigma/trunk/src/Misc.cpp
===================================================================
--- cs/benchmark/cigma/trunk/src/Misc.cpp	2008-01-29 23:19:32 UTC (rev 9194)
+++ cs/benchmark/cigma/trunk/src/Misc.cpp	2008-01-30 13:58:06 UTC (rev 9195)
@@ -50,13 +50,13 @@
 
     if (ext == ".txt")
     {
-        *reader == new TextReader();
+        *reader = new TextReader();
         return;
     }
 
     if (ext == ".vtk")
     {
-        *reader == new VtkReader();
+        *reader = new VtkReader();
         return;
     }
 
@@ -66,19 +66,19 @@
 {
     if (ext == ".h5")
     {
-        writer = new HdfWriter();
+        *writer = new HdfWriter();
         return;
     }
 
     if (ext == ".txt")
     {
-        writer = new TextWriter();
+        *writer = new TextWriter();
         return;
     }
 
     if (ext == ".vtk")
     {
-        writer = new VtkWriter();
+        *writer = new VtkWriter();
         return;
     }
 
@@ -155,6 +155,10 @@
     double hex_qwts[8*3] = { 1.,  1.,  1.,  1.,  1.,  1.,  1.,  1. };
 
 
+    int order;
+    string_to_int(arg_order, order);
+
+
     if (reader == 0)
     {
         assert(cell != 0);
@@ -180,6 +184,8 @@
                 quadrature->set_quadrature(hex_qpts, hex_qwts, hex_nno, hex_nsd);
                 quadrature->set_globaldim(hex_nsd);
                 break;
+            default:
+                break;
             }
         }
         else
@@ -200,13 +206,15 @@
         switch (reader->getType())
         {
         case Reader::HDF_READER:
-            assert(quadrature_path != "");
+            assert(arg_quadrature_path != "");
             break;
 
         case Reader::TXT_READER:
-            assert(points_loc != "");
-            assert(weights_loc != "");
+            assert(arg_points_loc != "");
+            assert(arg_weights_loc != "");
             break;
+        default:
+            break;
         }
     }
 
@@ -233,6 +241,9 @@
 
     case Reader::VTK_READER:
         break;
+
+    default:
+        break;
     }
 }
 
@@ -275,7 +286,7 @@
      * For detecting the filetype, one could rely only on the extension,
      * or possibly check for a magic number at the beginning of the file.
      */
-    switch (reader->getType())
+    switch (fieldReader->getType())
     {
     case Reader::HDF_READER:
         //XXX: cast to HdfReader
@@ -285,15 +296,19 @@
         break;
 
     case Reader::VTK_READER:
-        //XXX: cast to VtkReader
-        //reader.open(inputfile);
-        reader->get_coordinates(&coords, &nno, &nsd);
-        reader->get_connectivity(&connect, &nel, &ndofs);
-        //reader->get_dofs(location.c_str(), &dofs, &dofs_nno, &dofs_valdim);
-        //reader->get_vector_point_data(location.c_str(), &dofs, &dofs_nno, &dofs_valdim);
-        reader->get_scalar_point_data(location.c_str(), &dofs, &dofs_nno, &dofs_valdim);
-        //reader->get_point_data(location.c_str(), &dofs, &dofs_nno, &dofs_valdim);
+        /* XXX: cast to VtkReader
+        //fieldReader.open(inputfile);
+        fieldReader->get_coordinates(&coords, &nno, &nsd);
+        fieldReader->get_connectivity(&connect, &nel, &ndofs);
+        //fieldReader->get_dofs(location.c_str(), &dofs, &dofs_nno, &dofs_valdim);
+        //fieldReader->get_vector_point_data(location.c_str(), &dofs, &dofs_nno, &dofs_valdim);
+        fieldReader->get_scalar_point_data(location.c_str(), &dofs, &dofs_nno, &dofs_valdim);
+        //fieldReader->get_point_data(location.c_str(), &dofs, &dofs_nno, &dofs_valdim);
+        // */
         break;
+
+    default:
+        break;
     }
 
 
@@ -381,7 +396,7 @@
 
     //XXX: move to field->set_quadrature(...)
     Quadrature *Q = new cigma::Quadrature();
-    load_quadrature(field->meshPart->cell, Q);
+    //load_quadrature(field->meshPart->cell, Q); XXX
 
     field->fe = new cigma::FE();
     field->fe->set_cell_quadrature(field->meshPart->cell, Q);

Modified: cs/benchmark/cigma/trunk/src/Misc.h
===================================================================
--- cs/benchmark/cigma/trunk/src/Misc.h	2008-01-29 23:19:32 UTC (rev 9194)
+++ cs/benchmark/cigma/trunk/src/Misc.h	2008-01-30 13:58:06 UTC (rev 9195)
@@ -24,16 +24,42 @@
 
 void load_mesh();
 void load_quadrature();
+void load_quadrature(cigma::Cell *cell, cigma::Quadrature *quadrature);
 void load_field();
+void load_field(cigma::Reader *reader,
+                cigma::FE_Field *field,
+                std::string field_location);
 
+
+
 void load_reader(cigma::Reader **reader, std::string ext);
 void load_writer(cigma::Writer **writer, std::string ext);
 
-void load_quadrature(cigma::Cell *cell,
-                     cigma::Quadrature *quadrature);
 
-void load_field(cigma::Reader *reader,
-                cigma::FE_Field *field,
-                std::string field_location);
 
+
+void load_mesh(cigma::MeshPart *meshPart,
+               cigma::Reader *reader,
+               std::string mesh_path,
+               std::string coords_loc,
+               std::string connect_loc);
+
+
+void load_quadrature(cigma::Quadrature *quadrature,
+                     cigma::Cell *cell,
+                     cigma::Reader *reader,
+                     std::string arg_quadrature_path,
+                     std::string arg_points_loc,
+                     std::string arg_weights_loc,
+                     std::string arg_order);
+
+void load_field(cigma::FE_Field *field,
+                cigma::MeshPart *meshPart,
+                cigma::Reader *fieldReader,
+                cigma::Reader *meshReader,
+                std::string field_path,
+                std::string mesh_path,
+                std::string coords_path,
+                std::string connect_path);
+
 #endif

Modified: cs/benchmark/cigma/trunk/src/TextWriter.cpp
===================================================================
--- cs/benchmark/cigma/trunk/src/TextWriter.cpp	2008-01-29 23:19:32 UTC (rev 9194)
+++ cs/benchmark/cigma/trunk/src/TextWriter.cpp	2008-01-30 13:58:06 UTC (rev 9195)
@@ -14,6 +14,7 @@
 }
 
 // ---------------------------------------------------------------------------
+
 void cigma::TextWriter::open(std::string filename)
 {
     fp = fopen(filename.c_str(), "w");
@@ -31,6 +32,15 @@
 
 // ---------------------------------------------------------------------------
 
+void cigma::TextWriter::
+write_field(FE_Field *field)
+{
+    assert(field != 0);
+}
+
+
+// ---------------------------------------------------------------------------
+
 static bool write_dmat(FILE *fp, double *mat, int rows, int cols)
 {
     assert(fp != NULL);

Modified: cs/benchmark/cigma/trunk/src/TextWriter.h
===================================================================
--- cs/benchmark/cigma/trunk/src/TextWriter.h	2008-01-29 23:19:32 UTC (rev 9194)
+++ cs/benchmark/cigma/trunk/src/TextWriter.h	2008-01-30 13:58:06 UTC (rev 9195)
@@ -4,22 +4,30 @@
 #include <cstdio>
 #include <string>
 
+#include "Writer.h"
+
+
 namespace cigma
 {
     class TextWriter;
 };
 
-class cigma::TextWriter
+
+class cigma::TextWriter : public Writer
 {
 public:
     TextWriter();
     ~TextWriter();
 
 public:
+    WriterType getType() { return TXT_WRITER; }
     void open(std::string filename);
     void close();
 
 public:
+    void write_field(FE_Field *field);
+
+public:
     void write_connectivity(int *connectivity, int nel, int ndofs);
     void write_coordinates(double *coordinates, int nno, int nsd);
     void write_dofs(double *dofs, int nno, int ndim);
@@ -28,6 +36,7 @@
     FILE *fp;
 };
 
+
 // ---------------------------------------------------------------------------
 
 #endif

Modified: cs/benchmark/cigma/trunk/src/VtkReader.cpp
===================================================================
--- cs/benchmark/cigma/trunk/src/VtkReader.cpp	2008-01-29 23:19:32 UTC (rev 9194)
+++ cs/benchmark/cigma/trunk/src/VtkReader.cpp	2008-01-30 13:58:06 UTC (rev 9195)
@@ -30,7 +30,7 @@
 
 void cigma::VtkReader::open(std::string filename)
 {
-    int ierr;
+    //int ierr;
 
     /* XXX: throw exception if file doesn't exist */
     reader = vtkUnstructuredGridReader::New();

Modified: cs/benchmark/cigma/trunk/src/VtkReader.h
===================================================================
--- cs/benchmark/cigma/trunk/src/VtkReader.h	2008-01-29 23:19:32 UTC (rev 9194)
+++ cs/benchmark/cigma/trunk/src/VtkReader.h	2008-01-30 13:58:06 UTC (rev 9195)
@@ -14,7 +14,7 @@
     class VtkReader;
 }
 
-class cigma::VtkReader : cigma::Reader
+class cigma::VtkReader : public cigma::Reader
 {
 public:
     typedef enum {

Modified: cs/benchmark/cigma/trunk/src/VtkWriter.cpp
===================================================================
--- cs/benchmark/cigma/trunk/src/VtkWriter.cpp	2008-01-29 23:19:32 UTC (rev 9194)
+++ cs/benchmark/cigma/trunk/src/VtkWriter.cpp	2008-01-30 13:58:06 UTC (rev 9195)
@@ -5,11 +5,212 @@
 // ---------------------------------------------------------------------------
 cigma::VtkWriter::VtkWriter()
 {
+    fp = NULL;
 }
 
 cigma::VtkWriter::~VtkWriter()
 {
+    close();
 }
 
 // ---------------------------------------------------------------------------
 
+void cigma::VtkWriter::
+open(std::string filename)
+{
+    fp = fopen(filename.c_str(), "w");
+    assert(fp != NULL);
+}
+
+void cigma::VtkWriter::
+close()
+{
+    if (fp != NULL)
+    {
+        fclose(fp);
+    }
+}
+
+
+// ---------------------------------------------------------------------------
+
+void cigma::VtkWriter::
+write_field(FE_Field *field)
+{
+    assert(field != 0);
+}
+
+// ---------------------------------------------------------------------------
+
+void cigma::VtkWriter::
+write_header()
+{
+    assert(fp != NULL);
+    fprintf(fp, "# vtk DataFile Version 3.0\n");
+    fprintf(fp, "This line is a comment\n");
+    fprintf(fp, "ASCII\n");
+    fprintf(fp, "DATASET UNSTRUCTURED_GRID\n");
+}
+
+
+void cigma::VtkWriter::
+write_points(double *points, int npts, int ndim)
+{
+    assert(fp != NULL);
+    assert(ndim > 1);
+
+    fprintf(fp, "POINTS %d double\n", npts);
+    for (int i = 0; i < npts; i++)
+    {
+        fprintf(fp, " %g", points[ndim*i + 0]);
+        fprintf(fp, " %g", points[ndim*i + 1]);
+        if (ndim == 3)
+            fprintf(fp, " %g", points[ndim*i + 2]);
+        else
+            fprintf(fp, " 0.0");
+        fprintf(fp, "\n");
+    }
+}
+
+void cigma::VtkWriter::
+write_cells(int *cells, int nel, int ndofs)
+{
+    assert(fp != NULL);
+
+    fprintf(fp, "CELLS %d %d\n", nel, nel*(1 + ndofs));
+    for (int i = 0; i < nel; i++)
+    {
+        fprintf(fp, " %d", ndofs);
+        for (int j = 0; j < ndofs; j++)
+        {
+            fprintf(fp, " %d", cells[ndofs*i + j]);
+        }
+        fprintf(fp, "\n");
+    }
+}
+
+
+void cigma::VtkWriter::
+write_cell_types(int nsd, int nel, int ndofs)
+{
+    assert(fp != NULL);
+
+    fprintf(fp, "CELL_TYPES %d\n", nel);
+
+    int vtkType = 0;
+    if (nsd == 3)
+    {
+        switch (ndofs)
+        {
+        case  4: vtkType = 10; break; // VTK_TETRA=10
+        case  8: vtkType = 12; break; // VTK_HEXAHEDRON=12
+        case  6: vtkType = 13; break; // VTK_WEDGE=13
+        case  5: vtkType = 14; break; // VTK_PYRAMID=14
+        case 10: vtkType = 24; break; // VTK_QUADRATIC_TETRA=24
+        case 20: vtkType = 25; break; // VTK_QUADRATIC_HEXAHEDRON=25
+        }
+    }
+    else if (nsd == 2)
+    {
+        switch (ndofs)
+        {
+        case 3: vtkType =  5; break; // VTK_TRIANGLE=5
+        case 4: vtkType =  9; break; // VTK_QUAD=9
+        case 6: vtkType = 22; break; // VTK_QUADRATIC_TRIANGLE=22
+        case 8: vtkType = 23; break; // VTK_QUADRATIC_QUAD=23
+        }
+    }
+    assert(vtkType > 0);
+
+    for (int i = 0; i < nel; i++)
+    {
+        fprintf(fp, "%d\n", vtkType);
+    }
+}
+
+void cigma::VtkWriter::
+write_point_data(const char *name, double *data, int nno, int ndim)
+{
+    assert(fp != NULL);
+
+    fprintf(fp, "POINT_DATA %d\n", nno);
+
+    if (ndim == 1)
+    {
+        fprintf(fp, "SCALARS %s double 1\n", name);
+        fprintf(fp, "LOOKUP_TABLE default\n");
+        for (int i = 0; i < nno; i++)
+        {
+            fprintf(fp, "%g\n", data[i]);
+        }
+        return;
+    }
+    else if ((ndim == 2) || (ndim == 3))
+    {
+        fprintf(fp, "VECTORS %s double\n", name);
+        for (int i = 0; i < nno; i++)
+        {
+            fprintf(fp, " %g", data[ndim*i + 0]);
+            fprintf(fp, " %g", data[ndim*i + 1]);
+            if (ndim == 3)
+                fprintf(fp, " %g\n", data[ndim*i + 2]);
+            else
+                fprintf(fp, " 0.0\n");
+        }
+    }
+    else if (ndim == 9)
+    {
+        fprintf(fp, "TENSORS %s double\n", name);
+        for (int i = 0; i < nno; i++)
+        {
+            for (int j = 0; j < ndim; j++)
+            {
+                fprintf(fp, " %g", data[ndim*i + j]);
+            }
+            fprintf(fp, "\n");
+        }
+    }
+}
+
+void cigma::VtkWriter::
+write_cell_data(const char *name, double *data, int nel, int ndim)
+{
+    assert(fp != NULL);
+
+    fprintf(fp, "CELL_DATA %d\n", nel);
+
+    if (ndim == 1)
+    {
+        fprintf(fp, "SCALARS %s float 1\n", name);
+        fprintf(fp, "LOOKUP_TABLE default\n");
+        for (int i = 0; i < nel; i++)
+            fprintf(fp, "%g\n", data[i]);
+    }
+    else if ((ndim == 2) || (ndim == 3))
+    {
+        fprintf(fp, "VECTORS %s float\n", name);
+        for (int i = 0; i < nel; i++)
+        {
+            fprintf(fp, " %g", data[ndim*i + 0]);
+            fprintf(fp, " %g", data[ndim*i + 1]);
+            if (ndim == 3)
+                fprintf(fp, " %g\n", data[ndim*i + 2]);
+            else
+                fprintf(fp, " 0.0\n");
+        }
+    }
+    else if (ndim == 9)
+    {
+        fprintf(fp, "TENSORS %s float\n", name);
+        for (int i = 0; i < nel; i++)
+        {
+            for (int j = 0; j < ndim; j++)
+            {
+                fprintf(fp, " %g", data[ndim*i + j]);
+            }
+            fprintf(fp, "\n");
+        }
+    }
+}
+
+// ---------------------------------------------------------------------------

Modified: cs/benchmark/cigma/trunk/src/VtkWriter.h
===================================================================
--- cs/benchmark/cigma/trunk/src/VtkWriter.h	2008-01-29 23:19:32 UTC (rev 9194)
+++ cs/benchmark/cigma/trunk/src/VtkWriter.h	2008-01-30 13:58:06 UTC (rev 9195)
@@ -1,6 +1,8 @@
 #ifndef __VTK_WRITER_H__
 #define __VTK_WRITER_H__
 
+#include <cstdio>
+
 #include "Writer.h"
 
 
@@ -18,7 +20,22 @@
 
 public:
     WriterType getType() { return VTK_WRITER; }
+    void open(std::string filename);
+    void close();
 
+public:
+    void write_field(FE_Field *field);
+
+public:
+    void write_header();
+    void write_points(double *points, int npts, int ndim);
+    void write_cells(int *cells, int nel, int ndofs);
+    void write_cell_types(int nsd, int nel, int ndofs);
+    void write_point_data(const char *name, double *data, int nno, int ndim);
+    void write_cell_data(const char *name, double *data, int nel, int ndim);
+
+public:
+    FILE *fp;
 };
 
 #endif

Modified: cs/benchmark/cigma/trunk/src/Writer.h
===================================================================
--- cs/benchmark/cigma/trunk/src/Writer.h	2008-01-29 23:19:32 UTC (rev 9194)
+++ cs/benchmark/cigma/trunk/src/Writer.h	2008-01-30 13:58:06 UTC (rev 9195)
@@ -4,7 +4,9 @@
 #include <cstdio>
 #include <string>
 
+#include "FE_Field.h"
 
+
 namespace cigma
 {
     class Writer;
@@ -27,8 +29,14 @@
 
 public:
     virtual WriterType getType() = 0;
+    virtual void open(std::string filename) = 0;
+    virtual void close() = 0;
+
+public:
+    virtual void write_field(FE_Field *field) = 0;
 };
 
+
 // ---------------------------------------------------------------------------
 
 #endif

Modified: cs/benchmark/cigma/trunk/src/tests/TestAnn.cpp
===================================================================
--- cs/benchmark/cigma/trunk/src/tests/TestAnn.cpp	2008-01-29 23:19:32 UTC (rev 9194)
+++ cs/benchmark/cigma/trunk/src/tests/TestAnn.cpp	2008-01-30 13:58:06 UTC (rev 9195)
@@ -8,8 +8,8 @@
 #include "ANN/ANN.h"
 
 #include "MeshPart.h"
-#include "VtkUgMeshPart.h"
-#include "VtkUgReader.h"
+#include "MeshPart.h"
+#include "VtkReader.h"
 
 #include "Cell.h"
 #include "Tet.h"
@@ -178,14 +178,14 @@
     int nel, ndofs;
     int *connect;
 
-    VtkUgReader reader;
+    VtkReader reader;
     reader.open(filename);
     reader.get_coordinates(&coords, &nno, &nsd);
     reader.get_connectivity(&connect, &nel, &ndofs);
     assert(nsd == 3);
 
     MeshPart *meshPart;
-    meshPart = new VtkUgMeshPart();
+    meshPart = new MeshPart();
     meshPart->set_coordinates(coords, nno, nsd);
     meshPart->set_connectivity(connect, nel, ndofs);
     meshPart->cell = 0;
@@ -291,7 +291,6 @@
             cout << "                                 "
                  << "                                 "
                  << "                                 "
-                 << "                                 "
                  << "\r";
 
             cout << std::flush;
@@ -358,8 +357,6 @@
                         << point[2] << ") ";
         }
 
-
-        //cout << "fubar'd -> " << i << endl;
         locator->find(point, cellIndices);
 
         for (j = 0; j < num_candidates; j++)
@@ -389,7 +386,6 @@
             cout << "                                 "
                  << "                                 "
                  << "                                 "
-                 << "                                 "
                  << "\r";
 
             cout << std::flush;

Modified: cs/benchmark/cigma/trunk/src/tests/TestAnnLocator.cpp
===================================================================
--- cs/benchmark/cigma/trunk/src/tests/TestAnnLocator.cpp	2008-01-29 23:19:32 UTC (rev 9194)
+++ cs/benchmark/cigma/trunk/src/tests/TestAnnLocator.cpp	2008-01-30 13:58:06 UTC (rev 9195)
@@ -4,8 +4,7 @@
 
 #include "AnnLocator.h"
 #include "MeshPart.h"
-#include "VtkUgMeshPart.h"
-#include "VtkUgReader.h"
+#include "VtkReader.h"
 #include "Misc.h"
 #include "StringUtils.h"
 
@@ -45,14 +44,13 @@
     int *connect;
 
 
-    VtkUgReader reader;
+    VtkReader reader;
     reader.open(filename);
     reader.get_coordinates(&coords, &nno, &nsd);
     reader.get_connectivity(&connect, &nel, &ndofs);
 
 
     MeshPart *meshPart;
-    //meshPart = new VtkUgMeshPart();
     meshPart = new MeshPart();
     meshPart->set_coordinates(coords, nno, nsd);
     meshPart->set_connectivity(connect, nel, ndofs);

Modified: cs/benchmark/cigma/trunk/src/tests/TestFiatProxy.cpp
===================================================================
--- cs/benchmark/cigma/trunk/src/tests/TestFiatProxy.cpp	2008-01-29 23:19:32 UTC (rev 9194)
+++ cs/benchmark/cigma/trunk/src/tests/TestFiatProxy.cpp	2008-01-30 13:58:06 UTC (rev 9195)
@@ -12,7 +12,7 @@
 
     //* run test function first
     {
-        char *msg = "hello world";
+        const char *msg = "hello world";
         fiat->test(msg, 3);
     } // */
 

Modified: cs/benchmark/cigma/trunk/src/tests/TestMeshPart.cpp
===================================================================
--- cs/benchmark/cigma/trunk/src/tests/TestMeshPart.cpp	2008-01-29 23:19:32 UTC (rev 9194)
+++ cs/benchmark/cigma/trunk/src/tests/TestMeshPart.cpp	2008-01-30 13:58:06 UTC (rev 9195)
@@ -6,8 +6,8 @@
 
 #include "../Numeric.h"
 #include "../TextWriter.h"
-#include "../VtkUgReader.h"
-#include "../VtkUgMeshPart.h"
+#include "../VtkReader.h"
+#include "../MeshPart.h"
 #include "../Misc.h"
 
 using namespace cigma;
@@ -37,7 +37,7 @@
     TextWriter *writer = new TextWriter();
     writer->fp = stdout;
 
-    VtkUgReader *reader = new VtkUgReader();
+    VtkReader *reader = new VtkReader();
     std::string filename = "strikeslip_tet4_1000m_t0.vtk";
     reader->open(filename);
 
@@ -49,7 +49,7 @@
     int nel, ndofs;
     reader->get_connectivity(&connect, &nel, &ndofs);
 
-    VtkUgMeshPart *meshPart = new VtkUgMeshPart();
+    MeshPart *meshPart = new MeshPart();
 
     meshPart->set_coordinates(coords, nno, nsd);
     meshPart->set_connectivity(connect, nel, ndofs);

Modified: cs/benchmark/cigma/trunk/src/tests/TestNumeric.cpp
===================================================================
--- cs/benchmark/cigma/trunk/src/tests/TestNumeric.cpp	2008-01-29 23:19:32 UTC (rev 9194)
+++ cs/benchmark/cigma/trunk/src/tests/TestNumeric.cpp	2008-01-30 13:58:06 UTC (rev 9195)
@@ -2,7 +2,7 @@
 #include <cstdlib>
 #include <cassert>
 #include "../TextWriter.h"
-#include "../VtkUgReader.h"
+#include "../VtkReader.h"
 #include "../Numeric.h"
 using namespace cigma;
 
@@ -12,7 +12,7 @@
     writer->fp = stdout;
 
 
-    VtkUgReader *reader = new VtkUgReader();
+    VtkReader *reader = new VtkReader();
     std::string filename = "strikeslip_tet4_1000m_t0.vtk";
     reader->open(filename);
 

Modified: cs/benchmark/cigma/trunk/src/vtkls.cpp
===================================================================
--- cs/benchmark/cigma/trunk/src/vtkls.cpp	2008-01-29 23:19:32 UTC (rev 9194)
+++ cs/benchmark/cigma/trunk/src/vtkls.cpp	2008-01-30 13:58:06 UTC (rev 9195)
@@ -285,7 +285,6 @@
         for (i = 0; i < n; i++)
         {
             const char *name = reader->GetScalarsNameInFile(i);
-            vtkDataArray *dataArray = pointData->GetArray(i);
             cout << "Scalars[" << i << "] = " << name;
             cout << endl;
         }



More information about the cig-commits mailing list