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

luis at geodynamics.org luis at geodynamics.org
Wed Dec 19 12:03:05 PST 2007


Author: luis
Date: 2007-12-19 12:03:05 -0800 (Wed, 19 Dec 2007)
New Revision: 8920

Added:
   cs/benchmark/cigma/trunk/src/MeshPart.cpp
   cs/benchmark/cigma/trunk/src/tests/TestMeshPart.cpp
Modified:
   cs/benchmark/cigma/trunk/src/MeshPart.h
Log:
Updates to MeshPart object


Added: cs/benchmark/cigma/trunk/src/MeshPart.cpp
===================================================================
--- cs/benchmark/cigma/trunk/src/MeshPart.cpp	2007-12-19 20:02:57 UTC (rev 8919)
+++ cs/benchmark/cigma/trunk/src/MeshPart.cpp	2007-12-19 20:03:05 UTC (rev 8920)
@@ -0,0 +1,90 @@
+#include "MeshPart.h"
+#include <cassert>
+
+// ---------------------------------------------------------------------------
+
+cigma::MeshPart::
+MeshPart()
+{
+    nno = 0;
+    nsd = 0;
+    coords = 0;
+
+    nel = 0;
+    ndofs = 0;
+    connect = 0;
+}
+
+cigma::MeshPart::
+~MeshPart()
+{
+    if (coords) delete [] coords;
+    if (connect) delete [] connect;
+}
+
+// ---------------------------------------------------------------------------
+
+
+void cigma::MeshPart::
+set_coordinates(double *coordinates, int nno, int nsd)
+{
+    assert(nno > 0);
+    assert(nsd > 0);
+
+    this->nno = nno;
+    this->nsd = nsd;
+
+    coords = new double[nno * nsd];
+
+    // XXX: memcpy?
+    for (int i = 0; i < nno; i++)
+    {
+        for (int j = 0; j < nsd; j++)
+        {
+            int n = nsd*i + j;
+            coords[n] = coordinates[n];
+        }
+    }
+}
+
+void cigma::MeshPart::
+set_connectivity(int *connectivity, int nel, int ndofs)
+{
+    assert(nel > 0);
+    assert(ndofs > 0);
+
+    this-> nel = nel;
+    this-> ndofs = ndofs;
+
+    connect = new int[nel * ndofs];
+
+    // XXX: memcpy?
+    for (int i = 0; i < nel; i++)
+    {
+        for (int j = 0; j < ndofs; j++)
+        {
+            int e = ndofs*i + j;
+            connect[e] = connectivity[e];
+        }
+    }
+}
+
+
+void cigma::MeshPart::
+cell_coords(int cellIndex, double *globalCellCoords)
+{
+    assert(nsd > 0);
+    assert(ndofs > 0);
+
+    int *conn;
+
+    conn = &connect[ndofs * cellIndex];
+    for (int i = 0; i < ndofs; i++)
+    {
+        double *coor = &coords[conn[i]];
+        for (int j = 0; j < nsd; j++)
+        {
+            globalCellCoords[nsd*i + j] = coor[j];
+        }
+    }
+}

Modified: cs/benchmark/cigma/trunk/src/MeshPart.h
===================================================================
--- cs/benchmark/cigma/trunk/src/MeshPart.h	2007-12-19 20:02:57 UTC (rev 8919)
+++ cs/benchmark/cigma/trunk/src/MeshPart.h	2007-12-19 20:03:05 UTC (rev 8920)
@@ -1,53 +1,33 @@
 #ifndef __MESH_PART_H__
 #define __MESH_PART_H__
 
-#include <vector>
-
 namespace cigma
 {
-    class Cell;
     class MeshPart;
 }
 
-
-
-/*
- * MeshPart - Container for geometric/topological information on section of mesh
- */
 class cigma::MeshPart
 {
 public:
-
-    Cell *cell;
-    
-    int nno;
-    int nsd;
-    double *coords;
-
-    int nel;
-    int ndofs;
-    int *connect;
-
-public:
     MeshPart();
-    MeshPart(Cell *cell);
-    ~MeshPart();
+    virtual ~MeshPart();
 
 public:
-    void set_cell(Cell *cell);
-    void set_coordinates(double *coords, int nno, int nsd);
-    void set_connectivity(int *connect, int nel, int ndofs);
+    void set_coordinates(double *coordinates, int nno, int nsd);
+    void set_connectivity(int *connectivity, int nel, int ndofs);
 
 public:
-    void load_cell_coords(int e, double *nodes);
+    void cell_coords(int cellIndex, double *globalCoords);
+    virtual bool find_cell(double globalPoint[3], int *cellIndex) = 0;
 
 public:
-    bool find_cell0(double *point, int& e);
-    bool find_cell(double *point, int& e);
-    void find_cells(int nodeIdx, std::vector<int> &eltIndices);
-};
 
-//----------------------------------------------------------------------------
+    int nno, nsd;
+    double *coords;
 
+    int nel, ndofs;
+    int *connect;
 
+};
+
 #endif

Added: cs/benchmark/cigma/trunk/src/tests/TestMeshPart.cpp
===================================================================
--- cs/benchmark/cigma/trunk/src/tests/TestMeshPart.cpp	2007-12-19 20:02:57 UTC (rev 8919)
+++ cs/benchmark/cigma/trunk/src/tests/TestMeshPart.cpp	2007-12-19 20:03:05 UTC (rev 8920)
@@ -0,0 +1,83 @@
+#include <iostream>
+#include <iomanip>
+#include <cstdlib>
+#include <ctime>
+#include <cassert>
+
+#include "../Numeric.h"
+#include "../TextWriter.h"
+#include "../VtkUgReader.h"
+#include "../VtkMeshPart.h"
+
+using namespace cigma;
+
+// ---------------------------------------------------------------------------
+
+inline double pick_from_interval(double a, double b)
+{
+    return a + (b-a) * rand()/(RAND_MAX + 1.0);
+}
+
+void bbox_random_point(double minpt[3], double maxpt[3], double x[3])
+{
+    const int nsd = 3;
+    for (int i = 0; i < nsd; i++)
+    {
+        assert(minpt[i] <= maxpt[i]);
+        x[i] = pick_from_interval(minpt[i], maxpt[i]);
+    }
+}
+
+// ---------------------------------------------------------------------------
+
+
+// ---------------------------------------------------------------------------
+
+
+int main(void)
+{
+    TextWriter *writer = new TextWriter();
+    writer->fp = stdout;
+
+    VtkUgReader *reader = new VtkUgReader();
+    std::string filename = "strikeslip_tet4_1000m_t0.vtk";
+    reader->open(filename);
+
+    double *coords;
+    int nno, nsd;
+    reader->get_coordinates(&coords, &nno, &nsd);
+
+    int *connect;
+    int nel, ndofs;
+    reader->get_connectivity(&connect, &nel, &ndofs);
+
+    VtkMeshPart *meshPart = new VtkMeshPart();
+
+    meshPart->set_coordinates(coords, nno, nsd);
+    meshPart->set_connectivity(connect, nel, ndofs);
+
+
+    double minpt[3], maxpt[3];
+    minmax(coords, nno, nsd, minpt, maxpt);
+    //std::cout << std::setprecision(8);
+    std::cout << "minpt = " << minpt[0] << " " << minpt[1] << " " << minpt[2] << std::endl;
+    std::cout << "maxpt = " << maxpt[0] << " " << maxpt[1] << " " << maxpt[2] << std::endl;
+    
+    int i;
+    int npts = 100;
+    double *points = new double[npts * nsd];
+    for (i = 0; i < npts; i++)
+    {
+        double *pt = &points[nsd*i];
+        bbox_random_point(minpt, maxpt, pt);
+        std::cout << pt[0] << " " << pt[1] << " " << pt[2] << std::endl;
+    }
+
+
+    delete reader;
+
+    writer->fp = NULL;
+    delete writer;
+
+    return 0;
+}



More information about the cig-commits mailing list