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

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


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

Modified:
   cs/cigma/trunk/src/MeshPart.cpp
   cs/cigma/trunk/src/MeshPart.h
Log:
Move factory and setter methods into MeshPart class

Modified: cs/cigma/trunk/src/MeshPart.cpp
===================================================================
--- cs/cigma/trunk/src/MeshPart.cpp	2008-12-10 02:13:49 UTC (rev 13542)
+++ cs/cigma/trunk/src/MeshPart.cpp	2008-12-10 02:13:50 UTC (rev 13543)
@@ -1,8 +1,46 @@
 #include "MeshPart.h"
+#include "io_file_reader.h"
+#include "core_readers.h"
 #include <cassert>
+#include <string>
+#include <sstream>
+using namespace std;
 using namespace cigma;
 using boost::shared_ptr;
 
+
+// ----------------------------------------------------------------------------
+
+
+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->setPath(mesh_info.p_mesh);
+        if (mesh->cell_type == Cell::NONE)
+        {
+            mesh->cell_type = Cell::string2type(mesh_info.cell_type_name);
+        }
+        return mesh;
+    }
+
+    if (mesh_info.p_nc && mesh_info.p_eb)
+    {
+        mesh = shared_ptr<MeshPart>(new MeshPart);
+        mesh->setPath2(mesh_info.p_nc, mesh_info.p_eb);
+        mesh->cell_type = Cell::string2type(mesh_info.cell_type_name);
+        return mesh;
+    }
+
+    return mesh;
+}
+
+// ----------------------------------------------------------------------------
+
 MeshPart::MeshPart()
 {
     cell_type = Cell::NONE;
@@ -12,11 +50,6 @@
 {
 }
 
-void MeshPart::setCellType(Cell::type cell_type)
-{
-    this->cell_type = cell_type;
-}
-
 void MeshPart::setNodeCoordinates(const shared_ptr<NodeCoordinates>& nc)
 {
     this->coords = nc;
@@ -34,6 +67,106 @@
     this->locator = loc;
 }
 
+void MeshPart::setCellType(Cell::type cell_type)
+{
+    this->cell_type = cell_type;
+}
+
+void MeshPart::setPath(const DataPath& p_mesh)
+{
+    TRI_LOG_STR("MeshPart::setPath");
+    TRI_LOG(p_mesh);
+
+    if (p_mesh)
+    {
+        //
+        // Deduce p_nc and p_eb from p_mesh
+        //
+
+        DataPath p_nc, p_eb;
+        std::string filename = p_mesh.filename();
+        std::string location = p_mesh.location();
+
+
+        // XXX: throw exception if filename doesn't load an HDF5 reader
+        //
+        
+        // XXX: throw exception if location does not point to an HDF5 group
+        //
+
+        // XXX: read attribute CellType from group, and call this->setCell(...)
+        
+        //
+        // use default paths
+        //
+
+        if (location == "/")
+        {
+            location = "";
+        }
+
+        p_nc.set_filename(filename);
+        p_nc.set_location(location + "/coordinates");
+
+        p_eb.set_filename(filename);
+        p_eb.set_location(location + "/connectivity");
+
+        this->setPath2(p_nc, p_eb);
+    }
+    else
+    {
+        string msg("Path to mesh not specified");
+        throw cigma::Exception("MeshPart::setPath", msg);
+    }
+}
+
+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());
@@ -144,3 +277,4 @@
     return false;
 }
 
+

Modified: cs/cigma/trunk/src/MeshPart.h
===================================================================
--- cs/cigma/trunk/src/MeshPart.h	2008-12-10 02:13:49 UTC (rev 13542)
+++ cs/cigma/trunk/src/MeshPart.h	2008-12-10 02:13:50 UTC (rev 13543)
@@ -4,11 +4,12 @@
 #include <boost/noncopyable.hpp>
 #include <boost/shared_ptr.hpp>
 
-#include "Cell.h"
-//#include "CellIterator.h"
-#include "Locator.h"
 #include "NodeCoordinates.h"
 #include "ElementBlock.h"
+#include "Locator.h"
+#include "Cell.h"
+#include "DataPath.h"
+#include "core_args.h"
 
 namespace cigma
 {
@@ -24,11 +25,6 @@
     int n_cells() const;
     int n_dim() const;
 
-    void setCellType(Cell::type cell_type);
-    void setNodeCoordinates(const boost::shared_ptr<NodeCoordinates>& nc);
-    void setElementBlock(const boost::shared_ptr<ElementBlock>& eb);
-    void setLocator(const boost::shared_ptr<Locator>& loc);
-
     void getCell(int e, Cell &cell) const; // XXX
     void getBoundingBox(double *minpt, double *maxpt) const;
     void getCellCoords(int cellIndex, double *globalCoords, int dim) const;
@@ -37,6 +33,20 @@
     bool findCell(double globalPoint[3], int *cellIndex);
     bool findCell2(double globalPoint[3], double uvw[3], int *cellIndex);
 
+    /* direct setters */
+    void setNodeCoordinates(const boost::shared_ptr<NodeCoordinates>& nc);
+    void setElementBlock(const boost::shared_ptr<ElementBlock>& eb);
+    void setLocator(const boost::shared_ptr<Locator>& loc);
+    void setCellType(Cell::type cell_type);
+
+    /* incremental setters */
+    void setPath(const DataPath& p_mesh);
+    void setPath2(const DataPath& p_nc, const DataPath& p_eb);
+    void setCell(std::string cell_name);
+
+    /* static factory method */
+    static boost::shared_ptr<MeshPart> New(const MeshInfo& mesh_info);
+
 public:
     boost::shared_ptr<ElementBlock> connect;
     boost::shared_ptr<NodeCoordinates> coords;



More information about the CIG-COMMITS mailing list