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

luis at geodynamics.org luis at geodynamics.org
Wed Dec 17 02:33:37 PST 2008


Author: luis
Date: 2008-12-17 02:33:36 -0800 (Wed, 17 Dec 2008)
New Revision: 13767

Modified:
   cs/cigma/trunk/src/FE.cpp
   cs/cigma/trunk/src/FE.h
   cs/cigma/trunk/src/Field.cpp
   cs/cigma/trunk/src/Field.h
   cs/cigma/trunk/src/MeshPart.cpp
   cs/cigma/trunk/src/Quadrature.cpp
   cs/cigma/trunk/src/Quadrature.h
   cs/cigma/trunk/src/core_readers.cpp
   cs/cigma/trunk/src/core_readers.h
   cs/cigma/trunk/src/io_file_reader.cpp
   cs/cigma/trunk/src/io_file_reader.h
   cs/cigma/trunk/src/io_hdf5.cpp
   cs/cigma/trunk/src/io_hdf5_reader.cpp
   cs/cigma/trunk/src/io_text_reader.cpp
   cs/cigma/trunk/src/io_vtk_reader.cpp
Log:
Using improved version of core_readers.{h,cpp}

Modified: cs/cigma/trunk/src/FE.cpp
===================================================================
--- cs/cigma/trunk/src/FE.cpp	2008-12-17 10:33:32 UTC (rev 13766)
+++ cs/cigma/trunk/src/FE.cpp	2008-12-17 10:33:36 UTC (rev 13767)
@@ -13,17 +13,7 @@
 {
     TRI_LOG_STR("FE::New()");
     TRI_LOG(fe_info);
-
-    shared_ptr<FE> fe;
-
-    if (fe_info)
-    {
-        fe             = shared_ptr<FE>(new FE);
-        fe->quadrature = Quadrature::New(fe_info.q_info);
-        fe->cell       = Cell::New(fe_info.q_info.cell_type_name.c_str());
-        fe->setBasisAtQuad(fe_info.p_fe_basis);
-    }
-
+    shared_ptr<FE> fe = ReadFE(fe_info);
     return fe;
 }
 
@@ -137,55 +127,17 @@
 }
 
 
-void FE::setCell(string cell_name)
+void FE::setBasisAtQuad(const DataPath& p_basis)
 {
-    TRI_LOG_STR("FE::setCell()");
+    TRI_LOG_STR("FE::setBasisAtQuad()");
 
-    if (!quadrature)
+    if (quadrature && !cell)
     {
-        quadrature = shared_ptr<Quadrature>(new Quadrature());
-        quadrature->setCell(cell_name);
+        cell = Cell::New(quadrature->getCellType());
     }
 
-    this->cell = Cell::New(quadrature->getCellType());
-
-    return;
-}
-
-
-void FE::setQuadPath(const DataPath& p_quad)
-{
-    TRI_LOG_STR("FE::setQuadPath()");
-
-    if (!quadrature)
+    if (quadrature && cell)
     {
-        quadrature = shared_ptr<Quadrature>(new Quadrature);
-    }
-
-    quadrature->setPath(p_quad);
-}
-
-
-void FE::setQuadPath2(const DataPath& p_weights, const DataPath& p_points)
-{
-    TRI_LOG_STR("FE::setQuadPath2()");
-
-    if (!quadrature)
-    {
-        quadrature = shared_ptr<Quadrature>(new Quadrature);
-    }
-
-    quadrature->setPath2(p_weights, p_points);
-
-}
-
-
-void FE::setBasisAtQuad(const DataPath& p_basis)
-{
-    TRI_LOG_STR("FE::setBasisAtQuad()");
-
-    if (cell && quadrature)
-    {
         if (p_basis.empty())
         {
             this->init_basis();

Modified: cs/cigma/trunk/src/FE.h
===================================================================
--- cs/cigma/trunk/src/FE.h	2008-12-17 10:33:32 UTC (rev 13766)
+++ cs/cigma/trunk/src/FE.h	2008-12-17 10:33:36 UTC (rev 13767)
@@ -29,13 +29,8 @@
 
     //void apply_refmap(Cell& cell);
 
-    /* direct setters */
     void set_basis_tab(double *tab);
 
-    /* incremental setters */
-    void setCell(std::string cell_name);
-    void setQuadPath(const DataPath& p_quad);
-    void setQuadPath2(const DataPath& p_weights, const DataPath& p_points);
     void setBasisAtQuad(const DataPath& p_basis);
 
     /* static factory method */

Modified: cs/cigma/trunk/src/Field.cpp
===================================================================
--- cs/cigma/trunk/src/Field.cpp	2008-12-17 10:33:32 UTC (rev 13766)
+++ cs/cigma/trunk/src/Field.cpp	2008-12-17 10:33:36 UTC (rev 13767)
@@ -134,103 +134,4 @@
     return true;
 }
 
-
 // ----------------------------------------------------------------------------
-
-
-void Field::setDofsPath(const DataPath& p_dofs)
-{
-    TRI_LOG_STR("Field::setDofsPath()");
-    TRI_LOG(p_dofs);
-
-    if (!dofs)
-    {
-        dofs = shared_ptr<DofHandler>(new DofHandler);
-    }
-
-    dofs->setPath(p_dofs);
-}
-
-void Field::setMeshPath(const DataPath& p_mesh)
-{
-    TRI_LOG_STR("Field::setMeshPath()");
-    TRI_LOG(p_mesh);
-
-    if (!mesh)
-    {
-        mesh = shared_ptr<MeshPart>(new MeshPart);
-    }
-
-    mesh->setPath(p_mesh);
-}
-
-void Field::setMeshPath2(const DataPath& p_nc, const DataPath& p_eb)
-{
-    TRI_LOG_STR("Field::setMeshPart2()");
-    TRI_LOG(p_nc);
-    TRI_LOG(p_eb);
-
-    if (!mesh)
-    {
-        mesh = shared_ptr<MeshPart>(new MeshPart);
-    }
-
-    mesh->setPath2(p_nc, p_eb);
-}
-
-void Field::setCell(string cell_name)
-{
-    TRI_LOG_STR("Field::setCell()");
-    TRI_LOG(cell_name);
-
-    if (!fe)
-    {
-        fe = shared_ptr<FE>(new FE);
-    }
-
-    fe->setCell(cell_name);
-
-    // XXX: make sure that fe->cell->cell_type() is equal to mesh->cell_type (throw exception otherwise)
-}
-
-void Field::setQuadPath(const DataPath& p_quad)
-{
-    TRI_LOG_STR("Field::setQuadPath()");
-    TRI_LOG(p_quad);
-
-    if (!fe)
-    {
-        fe = shared_ptr<FE>(new FE);
-    }
-
-    fe->setQuadPath(p_quad);
-}
-
-void Field::setQuadPath2(const DataPath& p_weights, const DataPath& p_points)
-{
-    TRI_LOG_STR("Field::setQuadPath2()");
-    TRI_LOG(p_weights);
-    TRI_LOG(p_points);
-
-    if (!fe)
-    {
-        fe = shared_ptr<FE>(new FE);
-    }
-
-    fe->setQuadPath2(p_weights, p_points);
-}
-
-void Field::setBasisAtQuad(const DataPath& p_basis)
-{
-    TRI_LOG_STR("Field::setBasisAtQuad()");
-    TRI_LOG(p_basis);
-
-    if (!fe)
-    {
-        string msg("Failed to initialize quadrature before setting basis tabulation");
-        throw cigma::Exception("Field::setBasisAtQuad", msg);
-    }
-
-    fe->setBasisAtQuad(p_basis);
-}
-

Modified: cs/cigma/trunk/src/Field.h
===================================================================
--- cs/cigma/trunk/src/Field.h	2008-12-17 10:33:32 UTC (rev 13766)
+++ cs/cigma/trunk/src/Field.h	2008-12-17 10:33:36 UTC (rev 13767)
@@ -36,15 +36,6 @@
     void setFE(const boost::shared_ptr<FE> fe);
     void setDofHandler(const boost::shared_ptr<DofHandler> dofs);
     
-    /* incremental setters */
-    void setDofsPath(const DataPath& p_dofs);
-    void setMeshPath(const DataPath& p_mesh);
-    void setMeshPath2(const DataPath& p_nc, const DataPath& p_eb);
-    void setCell(std::string cell_name);
-    void setQuadPath(const DataPath& p_quad);
-    void setQuadPath2(const DataPath& p_weights, const DataPath& p_points);
-    void setBasisAtQuad(const DataPath& p_basis);
-
     /* static factory method */
     static boost::shared_ptr<Field> NewField(const FieldInfo& field_info);
 

Modified: cs/cigma/trunk/src/MeshPart.cpp
===================================================================
--- cs/cigma/trunk/src/MeshPart.cpp	2008-12-17 10:33:32 UTC (rev 13766)
+++ cs/cigma/trunk/src/MeshPart.cpp	2008-12-17 10:33:36 UTC (rev 13767)
@@ -13,29 +13,10 @@
 
 // ----------------------------------------------------------------------------
 
-
 shared_ptr<MeshPart> MeshPart::New(const MeshInfo& mesh_info)
 {
     TRI_LOG_STR("MeshPart::New()");
-
-    shared_ptr<MeshPart> mesh;
-
-    if (mesh_info.p_mesh)
-    {
-        mesh = shared_ptr<MeshPart>(new MeshPart);
-        mesh->cell_type = Cell::string2type(mesh_info.cell_type_name);
-        mesh->setPath(mesh_info.p_mesh);
-        return mesh;
-    }
-
-    if (mesh_info.p_nc && mesh_info.p_eb)
-    {
-        mesh = shared_ptr<MeshPart>(new MeshPart);
-        mesh->cell_type = Cell::string2type(mesh_info.cell_type_name);
-        mesh->setPath2(mesh_info.p_nc, mesh_info.p_eb);
-        return mesh;
-    }
-
+    shared_ptr<MeshPart> mesh = ReadMeshPart(mesh_info);
     return mesh;
 }
 
@@ -72,146 +53,6 @@
     this->cell_type = cell_type;
 }
 
-void MeshPart::setPath(const DataPath& p_mesh)
-{
-    TRI_LOG_STR("MeshPart::setPath()");
-    TRI_LOG(p_mesh);
-
-    string filename = p_mesh.filename();
-    string location = p_mesh.location();
-
-    shared_ptr<FileReader> reader = FileReader::New(filename, "r");
-    const FileReader::ReaderType rt = reader->getReaderType();
-
-    if (rt == FileReader::HDF5_FILE_READER)
-    {
-        HDF5_Reader *h5 = static_cast<HDF5_Reader*>(&(*reader));
-
-        // 
-        // XXX: Move these methods to HDF5_Reader (cf. VtkReader)
-        //
-        string loc = location;
-        if (location == "") { loc = "/"; }
-        bool locIsGroup = h5->locationIsGroup(loc.c_str());
-        TRI_LOG(locIsGroup);
-
-        if (locIsGroup)
-        {
-            DataPath p_nc, p_eb;
-
-            p_nc.set_filename(filename);
-            p_nc.set_location(location + "/coordinates");
-
-            p_eb.set_filename(filename);
-            p_eb.set_location(location + "/connectivity");
-
-            if (cell_type == Cell::NONE)
-            {
-                string cell_name;
-                int status = h5->getStringAttr(loc.c_str(), "CellType", cell_name);
-                TRI_LOG(status);
-                if (status == 0)
-                {
-                    TRI_LOG(cell_name);
-                    this->cell_type = Cell::string2type(cell_name);
-                }
-            }
-
-            this->setPath2(p_nc, p_eb);
-        }
-        else
-        {
-            std::ostringstream stream;
-            stream << "Could not read mesh path '" << p_mesh << "' as an HDF5 group" << std::ends;
-            throw cigma::Exception("MeshPart::setPath", stream.str());
-        }
-    }
-    else if (rt == FileReader::VTK_FILE_READER)
-    {
-        VtkReader *vtk = static_cast<VtkReader*>(&(*reader));
-
-        this->coords    = vtk->getNodeCoordinates(0);
-        this->connect   = vtk->getElementBlock(0);
-        this->cell_type = vtk->getCellType(0);
-
-        string cellname = Cell::type2string(cell_type);
-        TRI_LOG(cellname);
-
-
-        /*
-        DataPath p_nc, p_eb;
-        p_nc.set_filename(filename);
-        p_eb.set_filename(filename);
-
-        if (cell_type == Cell::NONE)
-        {
-            this->cell_type = vtk->getCellType(0);
-        }
-        TRI_LOG(cell_type);
-
-        this->setPath2(p_nc, p_eb);
-        */
-    }
-    else if (rt == FileReader::TEXT_FILE_READER)
-    {
-        string msg("Cannot specify mesh coordinates & connectivity with a single text file");
-        throw cigma::Exception("MeshPart::setPath", msg);
-    }
-    else
-    {
-        std::ostringstream stream;
-        stream << "Invalid mesh path '" << p_mesh << "'" << std::ends;
-        throw cigma::Exception("MeshPart::setPath", stream.str());
-    }
-}
-
-void MeshPart::setPath2(const DataPath& p_nc, const DataPath& p_eb)
-{
-    TRI_LOG_STR("MeshPart::setPath2()");
-    TRI_LOG(p_nc);
-    TRI_LOG(p_eb);
-
-    if (p_nc)
-    {
-        try
-        {
-            coords = ReadNodeCoordinates(p_nc);
-        }
-        catch (cigma::Exception& e)
-        {
-            throw cigma::Exception("MeshPart::setPath2", e.getMessage());
-        }
-    }
-    else
-    {
-        string msg("Path to mesh node coordinates not specified");
-        throw cigma::Exception("MeshPart::setPath2", msg);
-    }
-
-    if (p_eb)
-    {
-        try
-        {
-            connect = ReadElementBlock(p_eb);
-        }
-        catch (cigma::Exception& e)
-        {
-            throw cigma::Exception("MeshPart::setPath2", e.getMessage());
-        }
-    }
-    else
-    {
-        string msg("Path to mesh element block not specified");
-        throw cigma::Exception("MeshPart::setPath2", msg);
-    }
-}
-
-void MeshPart::setCell(string cell_name)
-{
-    this->cell_type = Cell::string2type(cell_name);
-}
-
-
 void MeshPart::getCell(int e, Cell& cell) const
 {
     this->getCellCoords(e, cell.globverts, cell.n_celldim());

Modified: cs/cigma/trunk/src/Quadrature.cpp
===================================================================
--- cs/cigma/trunk/src/Quadrature.cpp	2008-12-17 10:33:32 UTC (rev 13766)
+++ cs/cigma/trunk/src/Quadrature.cpp	2008-12-17 10:33:36 UTC (rev 13767)
@@ -14,6 +14,16 @@
 
 // ----------------------------------------------------------------------------
 
+shared_ptr<Quadrature> Quadrature::New(const QuadratureInfo& q_info)
+{
+    TRI_LOG_STR("Quadrature::New()");
+    TRI_LOG(q_info);
+    shared_ptr<Quadrature> Q = ReadQuadrature(q_info);
+    return Q;
+}
+
+// ----------------------------------------------------------------------------
+
 shared_ptr<Quadrature> Quadrature::default_rule(Cell::type cell_type)
 {
     TRI_LOG_STR("Quadrature::default_rule()");
@@ -147,39 +157,6 @@
     return Q;
 }
 
-shared_ptr<Quadrature> Quadrature::New(const QuadratureInfo& q_info)
-{
-    TRI_LOG_STR("Quadrature::New()");
-    TRI_LOG(q_info);
-
-    shared_ptr<Quadrature> Q;
-
-    if (q_info.p_quadrature)
-    {
-        Q = shared_ptr<Quadrature>(new Quadrature);
-        Q->cell_type = Cell::string2type(q_info.cell_type_name);
-        Q->setPath(q_info.p_quadrature);
-        return Q;
-    }
-
-    if (q_info.p_weights && q_info.p_points)
-    {
-        Q = shared_ptr<Quadrature>(new Quadrature);
-        Q->cell_type = Cell::string2type(q_info.cell_type_name);
-        Q->setPath2(q_info.p_weights, q_info.p_points);
-        return Q;
-    }
-
-    if (q_info.cell_type_name != "")
-    {
-        Cell::type cell_type = Cell::string2type(q_info.cell_type_name);
-        Q = Quadrature::default_rule(cell_type);
-        return Q;
-    }
-
-    return Q;
-}
-
 // ----------------------------------------------------------------------------
 
 Quadrature::Quadrature()
@@ -227,7 +204,6 @@
 
 Quadrature::~Quadrature()
 {
-    //std::cout << "Calling ~Quadrature()" << std::endl;
     if (points != 0)
     {
         delete [] points;
@@ -243,7 +219,6 @@
     }
 }
 
-
 // ----------------------------------------------------------------------------
 
 void Quadrature::reinit(int npts, int ndim)
@@ -293,198 +268,68 @@
 
 // ----------------------------------------------------------------------------
 
-
-void Quadrature::setPath(const DataPath& p_quad)
+void Quadrature::readPaths(const DataPath& p_weights, const DataPath& p_points)
 {
-    TRI_LOG_STR("Quadrature::setPath()");
-    TRI_LOG(p_quad);
-
-    // XXX: check that location points to HDF5 group
-    // XXX: check for cell type attribute
-
-    string filename = p_quad.filename();
-    string location = p_quad.location();
-    shared_ptr<FileReader> reader = FileReader::New(filename, "r");
-    const FileReader::ReaderType rt = reader->getReaderType();
-
-    bool combined_weights_and_points = false;
-
-    if (rt == FileReader::HDF5_FILE_READER)
-    {
-        HDF5_Reader* h5 = static_cast<HDF5_Reader*>(&(*reader));
-
-        string loc = location;
-        if (location == "") { loc = "/"; }
-        bool locIsGroup = h5->locationIsGroup(loc.c_str());
-        TRI_LOG(locIsGroup);
-        if (locIsGroup)
-        {
-            DataPath p_wts, p_pts;
-
-            p_wts.set_filename(filename);
-            p_wts.set_location(location + "/weights");
-
-            p_pts.set_filename(filename);
-            p_pts.set_location(location + "/points");
-
-            // read CellType attribute, if necessary
-            if (cell_type == Cell::NONE)
-            {
-                string cell_name;
-                int status = h5->getStringAttr(loc.c_str(), "CellType", cell_name);
-                TRI_LOG(status);
-                if (status == 0)
-                {
-                    TRI_LOG(cell_name);
-                    this->cell_type = Cell::string2type(cell_name);
-                }
-            }
-
-            // load weights & points from separate arrays
-            this->setPath2(p_wts, p_pts);
-        }
-        else
-        {
-            bool locIsDataset = h5->locationIsDataset(location.c_str());
-            TRI_LOG(locIsDataset);
-            if (locIsDataset)
-            {
-                // load weights & points simultaneously
-                combined_weights_and_points = true;
-            }
-            else
-            {
-                std::ostringstream stream;
-                stream << "Could not read quadrature points from data path '"
-                       << p_quad << "'" << std::ends;
-                throw cigma::Exception("Quadrature::setPath", stream.str());
-            }
-        }
-    }
-    else if ((rt == FileReader::TEXT_FILE_READER) || (rt == FileReader::VTK_FILE_READER))
-    {
-        // load weights & points simultaneously
-        combined_weights_and_points = true;
-    }
-    else
-    {
-        std::ostringstream stream;
-        stream << "Could not read file '" << filename << "'" << std::ends;
-        throw cigma::Exception("Quadrature::setPath", stream.str());
-    }
-
-    if (combined_weights_and_points)
-    {
-        cigma::array<double> *wx = ReadArray(p_quad);
-
-        if (wx == 0)
-        {
-            std::ostringstream stream;
-            stream << "Failed to read quadrature from path '"
-                   << p_quad << "'" << std::ends;
-            throw cigma::Exception("Quadrature::setPath", stream.str());
-        }
-        else
-        {
-            this->setFromCombinedData(*wx);
-            delete wx;
-        }
-
-        bool all_points_in_cell = points_in_cell();
-        TRI_LOG(all_points_in_cell);
-        if (!all_points_in_cell)
-        {
-            std::ostringstream stream;
-            stream << "Quadrature points not compatible with cell '";
-            stream << Cell::type2string(cell_type);
-            stream << "'" << std::ends;
-            throw cigma::Exception("Quadrature::setPath", stream.str());
-        }
-    }
-
-}
-
-
-void Quadrature::setPath2(const DataPath& p_weights, const DataPath& p_points)
-{
     TRI_LOG_STR("Quadrature::setPath2");
     TRI_LOG(p_weights);
     TRI_LOG(p_points);
 
-    int q_nwts, q_npts, q_ndim;
+    // clear out existing data
+    if (weights) { delete [] weights; }
+    if (points)  { delete [] points; }
 
-    // load weights array from p_weights
+    // load weights array from path
     cigma::array<double> *wts = ReadArray(p_weights);
     if (wts == 0)
     {
         std::ostringstream stream;
         stream << "Failed to read quadrature weights from path '"
                << p_weights << "'" << std::ends;
-        throw cigma::Exception("Quadrature::setPath2", stream.str());
+        throw cigma::Exception("ReadQuadrature", stream.str());
     }
-    q_nwts = wts->n_points();
     this->weights = wts->_data;
+    int nw = wts->n_points();
+    int nwd = wts->n_dim();
     wts->_data = 0;
     delete wts;
 
-    // load points array from p_points
+    // load points array from path
     cigma::array<double> *pts = ReadArray(p_points);
     if (pts == 0)
     {
         std::ostringstream stream;
         stream << "Failed to read quadrature points from path '"
                << p_points << "'" << std::ends;
-        throw cigma::Exception("Quadrature::setPath2", stream.str());
+        throw cigma::Exception("ReadQuadrature", stream.str());
     }
-    this->npts = pts->n_points();
-    this->ndim = pts->n_dim();
     this->points = pts->_data;
+    int nx = pts->n_points();
+    int nxd = pts->n_dim();
     pts->_data = 0;
     delete pts;
 
-    if (q_nwts != this->npts)
+    if (nwd != 1)
     {
         std::ostringstream stream;
-        stream << "Number of weights (" << q_nwts << ") "
-               << "does not match the number of quadrature "
-               << "points (" << npts << ")" << std::ends;
-        throw cigma::Exception("Quadrature::setPath2", stream.str());
+        stream << "Quadrature weights array must be one dimensional "
+               << "(found dimensions " << nw << " x " << nwd << ")"
+               << std::ends;
+        throw cigma::Exception("ReadQuadrature", stream.str());
     }
 
-    // check points
-    bool all_points_in_cell = points_in_cell();
-    TRI_LOG(all_points_in_cell);
-    if (!all_points_in_cell)
+    if (nw != nx)
     {
         std::ostringstream stream;
-        stream << "Quadrature points not compatible with cell '";
-        stream << Cell::type2string(cell_type);
-        stream << "'" << std::ends;
-        throw cigma::Exception("Quadrature::setPath2", stream.str());
+        stream << "Number of weights (" << nw << ") "
+               << "does not match the number of quadrature "
+               << "points (" << nx << ")"
+               << std::ends;
+        throw cigma::Exception("ReadQuadrature", stream.str());
     }
-}
 
-void Quadrature::setCell(string cell_name)
-{
-    TRI_LOG_STR("Quadrature::setCell");
-    TRI_LOG(cell_name);
-
-    this->cell_type = Cell::string2type(cell_name);
-
-    if (cell_type != Cell::NONE)
-    {
-        shared_ptr<Quadrature> Q = Quadrature::default_rule(cell_type);
-        this->reinit(Q->npts, Q->ndim);
-        this->setData(Q->points, Q->weights);
-        this->check_points();
-    }
-    else
-    {
-        std::ostringstream stream;
-        stream << "Could not instantiate cell '" << cell_name;
-        stream << "'" << std::ends;
-        throw cigma::Exception("Quadrature::setCell", stream.str());
-    }
+    this->npts = nx;
+    this->ndim = nxd;
+    this->check_points();
 }
 
 // ----------------------------------------------------------------------------

Modified: cs/cigma/trunk/src/Quadrature.h
===================================================================
--- cs/cigma/trunk/src/Quadrature.h	2008-12-17 10:33:32 UTC (rev 13766)
+++ cs/cigma/trunk/src/Quadrature.h	2008-12-17 10:33:36 UTC (rev 13767)
@@ -43,10 +43,7 @@
     void setWeight(int q, double val);
     void setCellType(Cell::type cell_type);
 
-    /* incremental setters */
-    void setPath(const DataPath& p_quad);
-    void setPath2(const DataPath& p_weights, const DataPath& p_points);
-    void setCell(std::string cell_name);
+    void readPaths(const DataPath& p_weights, const DataPath& p_points);
 
     /* static factory methods */
     static boost::shared_ptr<Quadrature> New(const QuadratureInfo& q_info);

Modified: cs/cigma/trunk/src/core_readers.cpp
===================================================================
--- cs/cigma/trunk/src/core_readers.cpp	2008-12-17 10:33:32 UTC (rev 13766)
+++ cs/cigma/trunk/src/core_readers.cpp	2008-12-17 10:33:36 UTC (rev 13767)
@@ -1,6 +1,8 @@
 #include "core_readers.h"
-#include "Common.h"
 
+#include "Common.h"
+#include "Filesystem.h"
+#include "Cell.h"
 #include "nc_array.h"
 #include "eb_array.h"
 #include "AnnLocator.h"
@@ -16,6 +18,7 @@
 using namespace std;
 using namespace cigma;
 using boost::shared_ptr;
+namespace fs = boost::filesystem;
 
 
 // ----------------------------------------------------------------------------
@@ -25,47 +28,32 @@
     TRI_LOG_STR("cigma::ReadArray()");
     TRI_LOG(array_path);
 
-    cigma::array<double>* a = 0;
+    const string filename = array_path.filename();
+    const string location = array_path.location();
 
-    string filename = array_path.filename();
-    string location = array_path.location();
+    cigma::array<double>* a = 0;
     shared_ptr<FileReader> reader = FileReader::New(filename, "r");
-    const FileReader::ReaderType rt = reader->getReaderType();
-    if (rt == FileReader::HDF5_FILE_READER)
+
+    if (reader)
     {
-        a = new cigma::array<double>();
-        int status = reader->getDataset(location.c_str(), &(a->_data), &(a->npts), &(a->ndim));
-        if (status < 0)
+        try
         {
-            delete a;
-            throw cigma::Exception("ReadArray", "Error in HDF5 reader");
+            a = new cigma::array<double>();
+            reader->getDoubleArray(location.c_str(), *a);
         }
-        return a;
-    }
-    else if (rt == FileReader::VTK_FILE_READER)
-    {
-        a = new cigma::array<double>();
-        int status = reader->getDataset(location.c_str(), &(a->_data), &(a->npts), &(a->ndim));
-        if (status < 0)
+        catch (cigma::Exception& e)
         {
             delete a;
-            throw cigma::Exception("ReadArray", "Error in VTK reader");
+            throw cigma::Exception("ReadArray", e.getMessage());
         }
     }
-    else if (rt == FileReader::TEXT_FILE_READER)
-    {
-        a = new cigma::array<double>();
-        int status = reader->getDataset("", &(a->_data), &(a->npts), &(a->ndim));
-        if (status < 0)
-        {
-            delete a;
-            throw cigma::Exception("ReadArray", "Error in text reader");
-        }
-        return a;
-    }
     else
     {
-        throw cigma::Exception("ReadArray", "Could not load data path");
+        std::ostringstream stream;
+        stream << "Could not load data path '"
+               << array_path << "'"
+               << std::ends;
+        throw cigma::Exception("ReadArray", stream.str());
     }
 
     return a;
@@ -78,53 +66,16 @@
     TRI_LOG_STR("cigma::ReadNodeCoordinates()");
     TRI_LOG(nc_path);
 
-    shared_ptr<NodeCoordinates> nc_ptr;
-    string filename = nc_path.filename();
-    string location = nc_path.location();
+    const string filename = nc_path.filename();
+    const string location = nc_path.location();
 
-    /* dispatch on reader type */
+    shared_ptr<NodeCoordinates> nc;
     shared_ptr<FileReader> reader = FileReader::New(filename, "r");
-    const FileReader::ReaderType rt = reader->getReaderType();
-    if (rt == FileReader::HDF5_FILE_READER)
+
+    if (reader)
     {
-        shared_ptr<nc_array> nc(new nc_array);
-        int status = reader->getCoordinates(location.c_str(), &(nc->coords), &(nc->nno), &(nc->nsd));
-        if (status < 0)
-        {
-            std::ostringstream stream;
-            stream << "Could not read node coordinates from location '"
-                   << location << "' in HDF5 file '" << filename << "'"
-                   << std::ends;
-            throw cigma::Exception("ReadNodeCoordinates", stream.str());
-        }
-        nc_ptr = nc;
+        nc = reader->getNodeCoordinates(location.c_str());
     }
-    else if (rt == FileReader::VTK_FILE_READER)
-    {
-        shared_ptr<nc_array> nc(new nc_array);
-        int status = reader->getCoordinates(location.c_str(), &(nc->coords), &(nc->nno), &(nc->nsd));
-        if (status < 0)
-        {
-            std::ostringstream stream;
-            stream << "Could not read node coordinates from VTK file '"
-                   << filename << "'" << std::ends;
-            throw cigma::Exception("ReadNodeCoordinates", stream.str());
-        }
-        nc_ptr = nc;
-    }
-    else if (rt == FileReader::TEXT_FILE_READER)
-    {
-        shared_ptr<nc_array> nc(new nc_array);
-        int status = reader->getCoordinates("", &(nc->coords), &(nc->nno), &(nc->nsd));
-        if (status < 0)
-        {
-            std::ostringstream stream;
-            stream << "Could not read node coordinates from text file '"
-                   << filename << "'" << std::ends;
-            throw cigma::Exception("ReadNodeCoordinates", stream.str());
-        }
-        nc_ptr = nc;
-    }
     else
     {
         std::ostringstream stream;
@@ -133,7 +84,7 @@
         throw cigma::Exception("ReadNodeCoordinates", stream.str());
     }
 
-    return nc_ptr;
+    return nc;
 }
 
 
@@ -144,263 +95,235 @@
     TRI_LOG_STR("cigma::ReadElementBlock()");
     TRI_LOG(eb_path);
 
-    shared_ptr<ElementBlock> eb_ptr;
-    string filename = eb_path.filename();
-    string location = eb_path.location();
+    const string filename = eb_path.filename();
+    const string location = eb_path.location();
 
-    /* dispatch on reader type */
+    shared_ptr<ElementBlock> eb;
     shared_ptr<FileReader> reader = FileReader::New(filename, "r");
-    const FileReader::ReaderType rt = reader->getReaderType();
-    if (rt == FileReader::HDF5_FILE_READER)
+
+    if (reader)
     {
-        shared_ptr<eb_array> eb(new eb_array);
-        int status = reader->getConnectivity(location.c_str(), &(eb->connect), &(eb->nel), &(eb->ndofs));
-        if (status < 0)
-        {
-            std::ostringstream stream;
-            stream << "Could not open element block from location '"
-                   << location << "' in HDF5 file '" << filename << "'"
-                   << std::ends;
-            throw cigma::Exception("ReadElementBlock", stream.str());
-        }
-        eb_ptr = eb;
+        eb = reader->getElementBlock(location.c_str());
     }
-    else if (rt == FileReader::VTK_FILE_READER)
-    {
-        shared_ptr<eb_array> eb(new eb_array);
-        int status = reader->getConnectivity(location.c_str(), &(eb->connect), &(eb->nel), &(eb->ndofs));
-        if (status < 0)
-        {
-            std::ostringstream stream;
-            stream << "Could not open element block from VTK file '"
-                   << filename << "'" << std::ends;
-            throw cigma::Exception("ReadElementBlock", stream.str());
-        }
-        eb_ptr = eb;
-    }
-    else if (rt == FileReader::TEXT_FILE_READER)
-    {
-        shared_ptr<eb_array> eb(new eb_array);
-        int status = reader->getConnectivity("", &(eb->connect), &(eb->nel), &(eb->ndofs));
-        if (status < 0)
-        {
-            std::ostringstream stream;
-            stream << "Could not open element block from text file '"
-                   << filename << "'" << std::ends;
-            throw cigma::Exception("ReadElementBlock", stream.str());
-        }
-        eb_ptr = eb;
-    }
     else
     {
-        throw cigma::Exception("ReadElementBlock", "Could not load data path");
+        std::ostringstream stream;
+        stream << "Could not read element block from path '"
+               << eb_path << "'" << std::ends;
+        throw cigma::Exception("ReadElementBlock", stream.str());
     }
 
-    return eb_ptr;
+    return eb;
 }
 
 // ----------------------------------------------------------------------------
 
-/*
 shared_ptr<MeshPart> cigma::ReadMeshPart(const MeshInfo& mesh_info)
 {
     TRI_LOG_STR("cigma::ReadMeshPart()");
 
-    shared_ptr<MeshPart> mesh_ptr;
-    shared_ptr<NodeCoordinates> nc_ptr;
-    shared_ptr<ElementBlock> eb_ptr;
-    shared_ptr<AnnLocator> loc_ptr;
-    Cell::type cell_type = Cell::NONE;
+    shared_ptr<MeshPart> mesh;
+    shared_ptr<AnnLocator> locator;
 
-    // load coordinates
-    DataPath nc_path = mesh_info.get_nc_path();
-    try
+    Cell::type celltype = Cell::NONE;
+    if (mesh_info.cell_type_name != "")
     {
-        nc_ptr = ReadNodeCoordinates(nc_path);
+        celltype = Cell::string2type(mesh_info.cell_type_name);
     }
-    catch (cigma::Exception& e)
+
+    if (mesh_info.p_mesh)
     {
-        throw cigma::Exception("ReadMeshPart", e.getMessage());
+        const string filename = mesh_info.p_mesh.filename();
+        const string location = mesh_info.p_mesh.location();
+
+        shared_ptr<FileReader> reader = FileReader::New(filename, "r");
+
+        mesh = reader->getMeshPart(location.c_str());
     }
+    else
+    {
+        mesh = shared_ptr<MeshPart>(new MeshPart);
+        mesh->coords = ReadNodeCoordinates(mesh_info.p_nc);
+        mesh->connect = ReadElementBlock(mesh_info.p_eb);
+    }
 
-    // load elements
-    DataPath eb_path = mesh_info.get_eb_path();
-    try
+    if (celltype != Cell::NONE)
     {
-        eb_ptr = ReadElementBlock(eb_path);
+        if (mesh->getCellType() == Cell::NONE)
+        {
+            mesh->setCellType(celltype);
+        }
+        else if (mesh->getCellType() != celltype)
+        {
+            string cellname = Cell::type2string(mesh->getCellType());
+            if (cellname == "") { cellname = "none"; }
+            std::ostringstream stream;
+            stream << "Mesh cell type already determined to be '"
+                   << cellname << "', but was given '"
+                   << mesh_info.cell_type_name << "'"
+                   << std::ends;
+            throw cigma::Exception("ReadMeshPart", stream.str());
+        }
     }
-    catch (cigma::Exception& e)
+
+    if (mesh->getCellType() == Cell::NONE)
     {
-        throw cigma::Exception("ReadMeshPart", e.getMessage());
+        string msg("No cell type was specified for mesh");
+        throw cigma::Exception("ReadMeshPart", msg);
     }
 
-    // load cell type from name
-    cell_type = Cell::string2type(mesh_info.cell_type_name);
-
-    // initialize mesh
-    mesh_ptr = shared_ptr<MeshPart>(new MeshPart);
-    mesh_ptr->setCellType(cell_type);
-    mesh_ptr->setNodeCoordinates(nc_ptr);
-    mesh_ptr->setElementBlock(eb_ptr);
-    if (mesh_info.use_locator)
+    if (mesh && mesh_info.use_locator)
     {
         // XXX: is there a better way to initialize? inheritance on MeshPart perhaps?
-        loc_ptr = shared_ptr<AnnLocator>(new AnnLocator);
-        loc_ptr->init(*mesh_ptr);
-        mesh_ptr->setLocator(loc_ptr);
+        locator = shared_ptr<AnnLocator>(new AnnLocator);
+        locator->init(*mesh);
+        mesh->setLocator(locator);
     }
 
-    return mesh_ptr;
-} // */
+    return mesh;
+}
 
 // ----------------------------------------------------------------------------
 
-/*
-shared_ptr<Quadrature> cigma::ReadQuadrature(const QuadratureInfo& quadrature_info)
+shared_ptr<Quadrature> cigma::ReadQuadrature(const QuadratureInfo& q_info)
 {
     TRI_LOG_STR("cigma::ReadQuadrature()");
+    TRI_LOG(q_info);
 
-    shared_ptr<Quadrature> q_ptr(new Quadrature);
+    shared_ptr<Quadrature> Q;
 
-    Cell::type cell_type = Cell::NONE;
-    if (quadrature_info.cell_type_name != "")
+    Cell::type celltype = Cell::NONE;
+    if (q_info.cell_type_name != "")
     {
-        cell_type = Cell::string2type(quadrature_info.cell_type_name);
+        celltype = Cell::string2type(q_info.cell_type_name);
     }
-    q_ptr->setCellType(cell_type);
 
-    if (quadrature_info.p_quadrature.empty() &&
-        quadrature_info.p_weights.empty() &&
-        quadrature_info.p_points.empty())
+    if (q_info.p_quadrature.empty() &&
+        q_info.p_weights.empty() &&
+        q_info.p_points.empty())
     {
         // 
         // No paths were specified, so we should create a
         // new Quadrature object based on the given cell type
         //
-        if (cell_type != Cell::NONE)
+        if (celltype != Cell::NONE)
         {
-            q_ptr = Quadrature::default_rule(cell_type);
+            Q = Quadrature::default_rule(celltype);
         }
         else
         {
-            throw cigma::Exception("ReadQuadrature", "No rule or cell type specified");
+            string msg("No rule or cell type specified");
+            throw cigma::Exception("ReadQuadrature", msg);
         }
     }
-    else if (quadrature_info.p_quadrature.empty())
+    else if (q_info.p_quadrature.empty())
     {
         //
         // Since the p_quadrature path is empty, we use the other
         // two paths p_weights and p_points to create the new Quadrature
         //
-        if (quadrature_info.p_weights.empty())
+        if (q_info.p_weights.empty())
         {
-            throw cigma::Exception("ReadQuadrature", "No path to quadrature weights was given");
+            string msg("No path to quadrature weights was given");
+            throw cigma::Exception("ReadQuadrature", msg);
         }
 
-        if (quadrature_info.p_points.empty())
+        if (q_info.p_points.empty())
         {
-            throw cigma::Exception("ReadQuadrature", "No path to quadrature points was given");
+            string msg("No path to quadrature points was given");
+            throw cigma::Exception("ReadQuadrature", msg);
         }
 
-        // load weights array from path
-        cigma::array<double> *wts = ReadArray(quadrature_info.p_weights);
-        if (wts == 0)
-        {
-            std::ostringstream stream;
-            stream << "Failed to read quadrature weights from path '"
-                   << quadrature_info.p_weights << "'" << std::ends;
-            throw cigma::Exception("ReadQuadrature", stream.str());
-        }
-        q_ptr->weights = wts->_data;
-        wts->_data = 0;
-        delete wts;
-
-        // load points array from path
-        cigma::array<double> *pts = ReadArray(quadrature_info.p_points);
-        if (pts == 0)
-        {
-            std::ostringstream stream;
-            stream << "Failed to read quadrature points from path '"
-                   << quadrature_info.p_points << "'" << std::ends;
-            throw cigma::Exception("ReadQuadrature", stream.str());
-        }
-        q_ptr->points = pts->_data;
-        pts->_data = 0;
-        delete pts;
+        Q = shared_ptr<Quadrature>(new Quadrature);
+        Q->readPaths(q_info.p_weights, q_info.p_points);
     }
     else
     {
         //
         // Now, we know p_quadrature is not empty so we use it exclusively
         //
-        if (!quadrature_info.p_weights.empty())
+        if (q_info.p_weights)
         {
             std::ostringstream stream;
             stream << "Don't need to overspecify weights if path '"
-                   << quadrature_info.p_quadrature
-                   << "' has already been given"
+                   << q_info.p_quadrature << "' has already been given"
                    << std::ends;
             throw cigma::Exception("ReadQuadrature", stream.str());
         }
 
-        if (!quadrature_info.p_points.empty())
+        if (q_info.p_points)
         {
             std::ostringstream stream;
             stream << "Don't need to overspecify points if path '"
-                   << quadrature_info.p_quadrature
-                   << "' has already been given"
+                   << q_info.p_quadrature << "' has already been given"
                    << std::ends;
             throw cigma::Exception("ReadQuadrature", stream.str());
         }
 
-        // load weights & points simultaneously
-        cigma::array<double> *wx = ReadArray(quadrature_info.p_quadrature);
-        const int npts = wx->n_points();
-        const int ndim = -1 + wx->n_dim();
-        q_ptr->reinit(npts, ndim);
-        for (int q = 0; q < npts; q++)
+        const string filename = q_info.p_quadrature.filename();
+        const string location = q_info.p_quadrature.location();
+
+        shared_ptr<FileReader> reader = FileReader::New(filename, "r");
+
+        if (reader)
         {
-            q_ptr->setWeight(q, wx->data(q, 0));
-            for (int j = 0; j < ndim; j++)
+            if (reader->getReaderType() == FileReader::VTK_FILE_READER)
             {
-                q_ptr->setPoint(q, j, wx->data(q, 1+j));
+                Q = reader->getQuadrature(0);
             }
+            else
+            {
+                Q = reader->getQuadrature(location.c_str());
+            }
         }
-        delete wx;
     }
 
-    return q_ptr;
-} // */
+    if (Q)
+    {
+        if (celltype != Cell::NONE)
+        {
+            if (Q->getCellType() == Cell::NONE)
+            {
+                Q->setCellType(celltype);
+            }
+            else if (Q->getCellType() != celltype)
+            {
+                string cellname = Cell::type2string(Q->getCellType());
+                if (cellname == "") { cellname = "none"; }
+                std::ostringstream stream;
+                stream << "Quadrature cell type already determined to be '"
+                       << cellname << "', but was given '"
+                       << q_info.cell_type_name << "'"
+                       << std::ends;
+                throw cigma::Exception("ReadQuadrature", stream.str());
+            }
+        }
 
+        Q->check_points();
+    }
+
+    return Q;
+}
+
 // ----------------------------------------------------------------------------
 
-/*
 shared_ptr<FE> cigma::ReadFE(const FE_Info& fe_info)
 {
     TRI_LOG_STR("cigma::ReadFE()");
-    assert(fe_info.q_info.cell_type_name != "");
+    TRI_LOG(fe_info);
 
-    shared_ptr<FE> fe_ptr;
-    shared_ptr<Quadrature> q_ptr;
-   
-    // load quadrature
-    q_ptr = ReadQuadrature(fe_info.q_info);
+    shared_ptr<FE> fe;
 
-    // initialize fe
-    fe_ptr = shared_ptr<FE>(new FE);
-    fe_ptr->init(q_ptr);
-    if (fe_info.p_fe_basis.empty())
+    if (fe_info)
     {
-        fe_ptr->init_basis();
+        fe = shared_ptr<FE>(new FE);
+        fe->quadrature = Quadrature::New(fe_info.q_info);
+        fe->cell       = Cell::New(fe_info.q_info.cell_type_name.c_str());
+        fe->setBasisAtQuad(fe_info.p_fe_basis);
     }
-    else
-    {
-        // XXX: copy basis tabulation from fe_info.p_fe_basis (needed for FIAT)
-        fe_ptr->init_basis();
-    }
 
-    return fe_ptr;
-} // */
+    return fe;
+}
 
 // ----------------------------------------------------------------------------
 
@@ -409,80 +332,80 @@
     TRI_LOG_STR("cigma::ReadDofHandler()");
     TRI_LOG(dofs_path);
 
-    shared_ptr<DofHandler> dofs_ptr;
-    string filename = dofs_path.filename();
-    string location = dofs_path.location();
+    const string filename = dofs_path.filename();
+    const string location = dofs_path.location();
 
-    /* dispatch on reader type */
+    shared_ptr<DofHandler> dofs;
     shared_ptr<FileReader> reader = FileReader::New(filename, "r");
-    const FileReader::ReaderType rt = reader->getReaderType();
-    if (rt == FileReader::HDF5_FILE_READER)
+
+    if (reader)
     {
-        dofs_ptr = shared_ptr<DofHandler>(new DofHandler);
-        int status = reader->getDataset(location.c_str(), &(dofs_ptr->dofs), &(dofs_ptr->nno), &(dofs_ptr->rank));
-        if (status < 0)
-        {
-            std::ostringstream stream;
-            stream << "Could not read dofs from location '"
-                   << location << "' in HDF5 file '" << filename << "'"
-                   << std::ends;
-            throw cigma::Exception("ReadDofHandler", stream.str());
-        }
+        dofs= reader->getDofHandler(location.c_str());
     }
-    else if (rt == FileReader::VTK_FILE_READER)
-    {
-        int status;
-        throw cigma::Exception("ReadDofHandler", "Error in VTK reader");
-    }
-    else if (rt == FileReader::TEXT_FILE_READER)
-    {
-        dofs_ptr = shared_ptr<DofHandler>(new DofHandler);
-        int status = reader->getDataset("", &(dofs_ptr->dofs), &(dofs_ptr->nno), &(dofs_ptr->rank));
-        if (status < 0)
-        {
-            std::ostringstream stream;
-            stream << "Could not read dofs from text file '" << filename << "'" << std::ends;
-            throw cigma::Exception("ReadDofHandler", stream.str());
-        }
-    }
     else
     {
         std::ostringstream stream;
-        stream << "Could not read dofs from path '" << dofs_path << "'" << std::ends;
+        stream << "Could not read dofs from path '"
+               << dofs_path << "'" << std::ends;
         throw cigma::Exception("ReadDofHandler", stream.str());
     }
 
-    return dofs_ptr;
+    return dofs;
 }
 
 // ----------------------------------------------------------------------------
 
-/*
+
 shared_ptr<Field> cigma::ReadField(const FieldInfo& field_info)
 {
     TRI_LOG_STR("cigma::ReadField()");
+    TRI_LOG(field_info);
 
-    shared_ptr<Field> field_ptr;
-    shared_ptr<MeshPart> mesh_ptr;
-    shared_ptr<FE> fe_ptr;
-    shared_ptr<DofHandler> dofs_ptr;
+    shared_ptr<Field> field;
 
-    // load MeshPart from mesh_info
-    mesh_ptr = ReadMeshPart(field_info.mesh_info);
+    if (field_info.p_field.is_vtk_file())
+    {
+        const string filename = field_info.p_field.filename();
+        const string location = field_info.p_field.location();
+        shared_ptr<FileReader> reader = FileReader::New(filename, "r");
+        field = shared_ptr<Field>(new Field);
+        field->mesh = reader->getMeshPart(0);
+        field->fe   = reader->getFE(0);
+        field->dofs = reader->getDofHandler(location.c_str());
+    }
+    else if (field_info.p_field.is_hdf5_file() && field_info.mesh_info.p_mesh.is_hdf5_file())
+    {
+        const string filename = field_info.p_field.filename();
+        const string location = field_info.p_field.location();
+        const string meshfile = field_info.mesh_info.p_mesh.filename();
+        const string meshloc  = field_info.mesh_info.p_mesh.location();
+        if (fs::equivalent(fs::path(meshfile), fs::path(filename)))
+        {
+            shared_ptr<FileReader> reader = FileReader::New(filename, "r");
+            field = shared_ptr<Field>(new Field);
+            field->mesh = reader->getMeshPart(meshloc.c_str());
+            field->fe   = reader->getFE(meshloc.c_str());
+            field->dofs = reader->getDofHandler(location.c_str());
+        }
+    }
+    
+    if (!field)
+    {
+        field = shared_ptr<Field>(new Field);
+        field->mesh = ReadMeshPart(field_info.mesh_info);
+        field->dofs = ReadDofHandler(field_info.p_field);
 
-    // load FE from fe_info
-    fe_ptr = ReadFE(field_info.fe_info);
+        if (field_info.fe_info)
+        {
+            field->fe = ReadFE(field_info.fe_info);
+        }
+        else if (field->mesh)
+        {
+            field->fe = shared_ptr<FE>(new FE(field->mesh->getCellType()));
+        }
+    }
 
-    // load DofHandler from path p_field
-    dofs_ptr = ReadDofHandler(field_info.p_field);
+    return field;
+}
 
-    // initialize Field
-    field_ptr = shared_ptr<Field>(new Field);
-    field_ptr->setMesh(mesh_ptr);
-    field_ptr->setFE(fe_ptr);
-    field_ptr->setDofHandler(dofs_ptr);
-
-    return field_ptr;
-} // */
-
 // ----------------------------------------------------------------------------

Modified: cs/cigma/trunk/src/core_readers.h
===================================================================
--- cs/cigma/trunk/src/core_readers.h	2008-12-17 10:33:32 UTC (rev 13766)
+++ cs/cigma/trunk/src/core_readers.h	2008-12-17 10:33:36 UTC (rev 13767)
@@ -2,38 +2,29 @@
 #define __CIGMA_READERS_H__
 
 #include <boost/shared_ptr.hpp>
-#include "core_array.h"
 
 #include "DataPath.h"
+#include "core_args.h"
+#include "core_array.h"
+
 #include "NodeCoordinates.h"
 #include "ElementBlock.h"
 #include "MeshPart.h"
-#include "DofHandler.h"
 #include "Quadrature.h"
 #include "FE.h"
+#include "DofHandler.h"
 #include "Field.h"
-#include "Cell.h"
-//#include "core_args.h"
 
 namespace cigma
 {
-
     cigma::array<double>* ReadArray(const DataPath& array_path);
-
     boost::shared_ptr<NodeCoordinates> ReadNodeCoordinates(const DataPath& nc_path);
-
     boost::shared_ptr<ElementBlock> ReadElementBlock(const DataPath& eb_path);
-
-    //boost::shared_ptr<MeshPart> ReadMeshPart(const MeshInfo& mesh_info);
-
-    //boost::shared_ptr<Quadrature> ReadQuadrature(const QuadratureInfo& quadrature_info);
-
-    //boost::shared_ptr<FE> ReadFE(const FE_Info& fe_info);
-
+    boost::shared_ptr<MeshPart> ReadMeshPart(const MeshInfo& mesh_info);
+    boost::shared_ptr<Quadrature> ReadQuadrature(const QuadratureInfo& quadrature_info);
+    boost::shared_ptr<FE> ReadFE(const FE_Info& fe_info);
     boost::shared_ptr<DofHandler> ReadDofHandler(const DataPath& dofs_path);
-
-    //boost::shared_ptr<Field> ReadField(const FieldInfo& field_info);
-
+    boost::shared_ptr<Field> ReadField(const FieldInfo& field_info);
 }
 
 #endif

Modified: cs/cigma/trunk/src/io_file_reader.cpp
===================================================================
--- cs/cigma/trunk/src/io_file_reader.cpp	2008-12-17 10:33:32 UTC (rev 13766)
+++ cs/cigma/trunk/src/io_file_reader.cpp	2008-12-17 10:33:36 UTC (rev 13767)
@@ -18,10 +18,9 @@
 using namespace cigma;
 
 
-shared_ptr<FileReader> FileReader::New(std::string filename, std::string mode)
+shared_ptr<FileReader> FileReader::New(const std::string& filename, const std::string& mode)
 {
-    shared_ptr<FileReader> tmp(new NullReader());
-    int status = -1;
+    shared_ptr<FileReader> reader;
 
     fs::path p(filename);
     string ext = fs::extension(p);
@@ -30,8 +29,8 @@
     {
         if (is_hdf5_extension(ext.c_str()))
         {
-            tmp.reset(new HDF5_Reader());
-            status = tmp->open(filename.c_str(), mode.c_str());
+            reader.reset(new HDF5_Reader());
+            int status = reader->open(filename.c_str(), mode.c_str());
             if (status < 0)
             {
                 std::ostringstream stream;
@@ -41,8 +40,8 @@
         }
         else if (is_vtk_extension(ext.c_str()))
         {
-            tmp.reset(new VtkReader());
-            status = tmp->open(filename.c_str(), mode.c_str());
+            reader.reset(new VtkReader());
+            int status = reader->open(filename.c_str(), mode.c_str());
             if (status < 0)
             {
                 std::ostringstream stream;
@@ -52,8 +51,8 @@
         }
         else if (is_text_extension(ext.c_str()))
         {
-            tmp.reset(new TextReader());
-            status = tmp->open(filename.c_str(), mode.c_str());
+            reader.reset(new TextReader());
+            int status = reader->open(filename.c_str(), mode.c_str());
             if (status < 0)
             {
                 std::ostringstream stream;
@@ -69,7 +68,7 @@
         throw cigma::Exception("FileReader::New", stream.str());
     }
 
-    return tmp;
+    return reader;
 }
 
 FileReader::FileReader()

Modified: cs/cigma/trunk/src/io_file_reader.h
===================================================================
--- cs/cigma/trunk/src/io_file_reader.h	2008-12-17 10:33:32 UTC (rev 13766)
+++ cs/cigma/trunk/src/io_file_reader.h	2008-12-17 10:33:36 UTC (rev 13767)
@@ -50,7 +50,7 @@
     virtual boost::shared_ptr<FE> getFE(const char *loc) = 0;
     virtual boost::shared_ptr<DofHandler> getDofHandler(const char *loc) = 0;
 
-    static boost::shared_ptr<FileReader> New(std::string filename, std::string mode);
+    static boost::shared_ptr<FileReader> New(const std::string& filename, const std::string& mode);
 
 public:
 

Modified: cs/cigma/trunk/src/io_hdf5.cpp
===================================================================
--- cs/cigma/trunk/src/io_hdf5.cpp	2008-12-17 10:33:32 UTC (rev 13766)
+++ cs/cigma/trunk/src/io_hdf5.cpp	2008-12-17 10:33:36 UTC (rev 13767)
@@ -60,9 +60,9 @@
         if (attr->getTypeClass() == H5T_STRING)
         {
             H5::DataType datatype = attr->getDataType();
-            TRI_LOG(datatype.getClass());
-            TRI_LOG(datatype.getSize());
-            TRI_LOG(datatype.isVariableStr());
+            //TRI_LOG(datatype.getClass());
+            //TRI_LOG(datatype.getSize());
+            //TRI_LOG(datatype.isVariableStr());
 
             if (datatype.isVariableStr())
             {

Modified: cs/cigma/trunk/src/io_hdf5_reader.cpp
===================================================================
--- cs/cigma/trunk/src/io_hdf5_reader.cpp	2008-12-17 10:33:32 UTC (rev 13766)
+++ cs/cigma/trunk/src/io_hdf5_reader.cpp	2008-12-17 10:33:36 UTC (rev 13767)
@@ -60,6 +60,7 @@
 
 int HDF5_Reader::close()
 {
+    TRI_LOG_STR("HDF5_Reader::close()"); 
     if (file)
     {
         delete file;
@@ -236,7 +237,7 @@
 
 shared_ptr<Quadrature> HDF5_Reader::getQuadrature(const char *loc)
 {
-    TRI_LOG_STR("HDF5_Reader::getQuadrature");
+    TRI_LOG_STR("HDF5_Reader::getQuadrature()");
 
     shared_ptr<Quadrature> Q;
 
@@ -272,6 +273,15 @@
             throw cigma::Exception("HDF5_Reader::getQuadrature", stream.str());
         }
 
+        if (nwd != 1)
+        {
+            std::ostringstream stream;
+            stream << "Quadrature weights array must be one dimensional "
+                   << "(found dimensions " << nw << " x " << nwd << ")"
+                   << std::ends;
+            throw cigma::Exception("ReadQuadrature", stream.str());
+        }
+
         if (nw != nx)
         {
             std::ostringstream stream;
@@ -302,13 +312,20 @@
 
 shared_ptr<FE> HDF5_Reader::getFE(const char *loc)
 {
+    TRI_LOG_STR("HDF5_Reader::getFE()");
     shared_ptr<FE> fe;
+    Cell::type celltype = this->getCellType(loc);
+    if (celltype != Cell::NONE)
+    {
+        fe = shared_ptr<FE>(new FE(celltype));
+    }
     return fe;
 }
 
 
 shared_ptr<DofHandler> HDF5_Reader::getDofHandler(const char *loc)
 {
+    TRI_LOG_STR("HDF5_Reader::getDofHandler");
     shared_ptr<DofHandler> dh(new DofHandler);
     int status = this->getDataset(loc, &(dh->dofs), &(dh->nno), &(dh->rank));
     if (status < 0)
@@ -349,7 +366,6 @@
 
 int HDF5_Reader::getStringAttr(const char *loc, const char *attr_name, string& val)
 {
-    TRI_LOG_STR("HDF5_Reader::getString()");
     return read_scalar_attribute<string>(file, loc, attr_name, val);
 }
 

Modified: cs/cigma/trunk/src/io_text_reader.cpp
===================================================================
--- cs/cigma/trunk/src/io_text_reader.cpp	2008-12-17 10:33:32 UTC (rev 13766)
+++ cs/cigma/trunk/src/io_text_reader.cpp	2008-12-17 10:33:36 UTC (rev 13767)
@@ -90,6 +90,9 @@
     assert(ret == 1);
     assert(cols > 0);
 
+    TRI_LOG(rows);
+    TRI_LOG(cols);
+
     T* m = new T[rows * cols];
     const char *fmt = get_format<T>();
     for (int i = 0; i < rows; i++)

Modified: cs/cigma/trunk/src/io_vtk_reader.cpp
===================================================================
--- cs/cigma/trunk/src/io_vtk_reader.cpp	2008-12-17 10:33:32 UTC (rev 13766)
+++ cs/cigma/trunk/src/io_vtk_reader.cpp	2008-12-17 10:33:36 UTC (rev 13767)
@@ -113,6 +113,7 @@
 
 int VtkReader::close()
 {
+    TRI_LOG_STR("VtkReader::close()");
     gridType = GRID_NULL;
 
     if (dataset != 0)



More information about the CIG-COMMITS mailing list