[cig-commits] r13179 - in cs/cigma/trunk: . src tests tests/libcigma
luis at geodynamics.org
luis at geodynamics.org
Wed Oct 29 15:11:59 PDT 2008
Author: luis
Date: 2008-10-29 15:11:59 -0700 (Wed, 29 Oct 2008)
New Revision: 13179
Added:
cs/cigma/trunk/tests/libcigma/MeshPartTest.cpp
cs/cigma/trunk/tests/libcigma/MeshPartTest.h
Modified:
cs/cigma/trunk/Makefile.am
cs/cigma/trunk/src/MeshPart.cpp
cs/cigma/trunk/src/MeshPart.h
cs/cigma/trunk/tests/test_registry.cpp
Log:
Updated class cigma::MeshPart, and added CppUnit tests
This implementation of cigma::MeshPart leaves the memory management
to boost::shared_ptr.
Modified: cs/cigma/trunk/Makefile.am
===================================================================
--- cs/cigma/trunk/Makefile.am 2008-10-29 22:11:58 UTC (rev 13178)
+++ cs/cigma/trunk/Makefile.am 2008-10-29 22:11:59 UTC (rev 13179)
@@ -285,6 +285,8 @@
tests/libcigma/NodeCoordinatesTest.cpp \
tests/libcigma/ElementBlockTest.h \
tests/libcigma/ElementBlockTest.cpp \
+ tests/libcigma/MeshPartTest.h \
+ tests/libcigma/MeshPartTest.cpp \
tests/libcigma/DofHandlerTest.h \
tests/libcigma/DofHandlerTest.cpp \
tests/libcigma/FunctionTest.h \
Modified: cs/cigma/trunk/src/MeshPart.cpp
===================================================================
--- cs/cigma/trunk/src/MeshPart.cpp 2008-10-29 22:11:58 UTC (rev 13178)
+++ cs/cigma/trunk/src/MeshPart.cpp 2008-10-29 22:11:59 UTC (rev 13179)
@@ -33,9 +33,14 @@
void MeshPart::selectCell(int e)
{
assert(cell);
- this->getCellCoords(e, cell->globverts);
+ this->getCellCoords(e, cell->globverts, cell->n_celldim());
}
+void MeshPart::getCell(int e, Cell& cell)
+{
+ this->getCellCoords(e, cell.globverts, cell.n_celldim());
+}
+
void MeshPart::getBoundingBox(double *minpt, double *maxpt)
{
assert(coords);
@@ -43,25 +48,27 @@
}
-void MeshPart::getCellCoords(int cellIndex, double *globalCoords)
+void MeshPart::getCellCoords(int cellIndex, double *globalCoords, int dim)
{
assert(coords);
assert(connect);
int i,j;
+ const int ndofs = connect->n_dofs();
const int nsd = coords->n_dim();
- for (i = 0; i < connect->n_dofs(); i++)
+
+ for (i = 0; i < ndofs; i++)
{
const int n = connect->getId(cellIndex, i);
for (j = 0; j < nsd; j++)
{
- globalCoords[3*i + j] = coords->getPoint(i,j);
+ globalCoords[dim*i + j] = coords->getPoint(n,j);
}
- for (j = nsd; j < 3; j++)
+ for (j = nsd; j < dim; j++)
{
- globalCoords[3*i + j] = 0.0;
+ globalCoords[dim*i + j] = 0.0;
}
}
}
Modified: cs/cigma/trunk/src/MeshPart.h
===================================================================
--- cs/cigma/trunk/src/MeshPart.h 2008-10-29 22:11:58 UTC (rev 13178)
+++ cs/cigma/trunk/src/MeshPart.h 2008-10-29 22:11:59 UTC (rev 13179)
@@ -2,6 +2,7 @@
#define __CIGMA_MESH_PART_H__
#include "Cell.h"
+//#include "CellIterator.h"
#include "Locator.h"
#include "NodeCoordinates.h"
#include "ElementBlock.h"
@@ -13,29 +14,30 @@
class MeshPart;
}
-
class cigma::MeshPart : boost::noncopyable
{
public:
MeshPart();
~MeshPart();
- void setCell(const boost::shared_ptr<Cell>& cell); /* XXX */
+ void setCell(const boost::shared_ptr<Cell>& cell); /* XXX: setCellType(...) */
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 selectCell(int e); /* XXX */
+ void selectCell(int e); /* XXX: replace by iterator */
+
+ void getCell(int e, Cell &cell); // XXX
void getBoundingBox(double *minpt, double *maxpt);
- void getCellCoords(int cellIndex, double *globalCoords);
+ void getCellCoords(int cellIndex, double *globalCoords, int dim);
bool findCell(double globalPoint[3], double uvw[3], int *cellIndex);
public:
boost::shared_ptr<ElementBlock> connect;
boost::shared_ptr<NodeCoordinates> coords;
boost::shared_ptr<Locator> locator;
- boost::shared_ptr<Cell> cell; /* XXX: replace by iterator */
+ boost::shared_ptr<Cell> cell; // XXX: only need to save the Cell::type
};
#endif
Added: cs/cigma/trunk/tests/libcigma/MeshPartTest.cpp
===================================================================
--- cs/cigma/trunk/tests/libcigma/MeshPartTest.cpp (rev 0)
+++ cs/cigma/trunk/tests/libcigma/MeshPartTest.cpp 2008-10-29 22:11:59 UTC (rev 13179)
@@ -0,0 +1,85 @@
+#include "MeshPartTest.h"
+using namespace libcigma;
+
+#include "Cell.h"
+#include "fe_tet4.h"
+#include "nc_array.h"
+#include "eb_array.h"
+#include "MeshPart.h"
+using namespace cigma;
+
+#include <boost/shared_ptr.hpp>
+using boost::shared_ptr;
+
+const double delta = 1e-8;
+
+void MeshPartTest::test_something()
+{
+ int i,j;
+
+ float coords[8*3] = {
+ 1, 2, 3,
+ 4, 5, 6,
+ 7, 8, 9,
+ 10, 11, 12,
+ 13, 14, 15,
+ 16, 17, 18,
+ 19, 20, 21,
+ 22, 23, 24
+ };
+ int connect[5*4] = {
+ 0, 1, 2, 3,
+ 1, 2, 3, 4,
+ 2, 3, 4, 5,
+ 3, 4, 5, 6,
+ 4, 5, 6, 7
+ };
+
+
+ shared_ptr<MeshPart> mesh(new MeshPart);
+
+
+ shared_ptr<nc_array> nc(new nc_array(8,3));
+ nc->setCoordinates(coords);
+ mesh->setNodeCoordinates(nc);
+
+ shared_ptr<eb_array> eb(new eb_array(5,4));
+ eb->setConnectivity(connect);
+ mesh->setElementBlock(eb);
+
+ shared_ptr<Cell> cell(new tet4);
+ mesh->setCell(cell);
+
+
+ int cellIndex = 2;
+ double thirdcell[4*3] = {
+ 7., 8., 9., // point 2
+ 10, 11, 12, // point 3
+ 13, 14, 15, // point 4
+ 16, 17, 18, // point 5
+ };
+
+ double celldata[4*3];
+ mesh->getCellCoords(cellIndex, celldata, 3);
+ for (i = 0; i < 4; i++)
+ {
+ for (j = 0; j < 3; j++)
+ {
+ int n = 3*i + j;
+ CPPUNIT_ASSERT_DOUBLES_EQUAL(thirdcell[n], celldata[n], delta);
+ }
+ }
+
+ shared_ptr<Cell> it = Cell::New(mesh->cell->cell_type());
+ CPPUNIT_ASSERT(it->cell_type() != Cell::NONE);
+ mesh->getCell(cellIndex, *it);
+ for (i = 0; i < 4; i++)
+ {
+ for (j = 0; j < 3; j++)
+ {
+ int n = 3*i + j;
+ CPPUNIT_ASSERT_DOUBLES_EQUAL(thirdcell[n], it->globverts[n], delta);
+ }
+ }
+}
+
Added: cs/cigma/trunk/tests/libcigma/MeshPartTest.h
===================================================================
--- cs/cigma/trunk/tests/libcigma/MeshPartTest.h (rev 0)
+++ cs/cigma/trunk/tests/libcigma/MeshPartTest.h 2008-10-29 22:11:59 UTC (rev 13179)
@@ -0,0 +1,23 @@
+#ifndef __MESH_PART_TEST_H__
+#define __MESH_PART_TEST_H__
+
+#include <cppunit/TestFixture.h>
+#include <cppunit/extensions/HelperMacros.h>
+
+
+namespace libcigma
+{
+ class MeshPartTest : public CPPUNIT_NS::TestFixture
+ {
+ CPPUNIT_TEST_SUITE(MeshPartTest);
+ CPPUNIT_TEST(test_something);
+ CPPUNIT_TEST_SUITE_END();
+
+ public:
+ MeshPartTest() {}
+ ~MeshPartTest() {}
+ void test_something();
+ };
+};
+
+#endif
Modified: cs/cigma/trunk/tests/test_registry.cpp
===================================================================
--- cs/cigma/trunk/tests/test_registry.cpp 2008-10-29 22:11:58 UTC (rev 13178)
+++ cs/cigma/trunk/tests/test_registry.cpp 2008-10-29 22:11:59 UTC (rev 13179)
@@ -24,6 +24,9 @@
#include <libcigma/ElementBlockTest.h>
CPPUNIT_TEST_SUITE_REGISTRATION(libcigma::ElementBlockTest);
+#include <libcigma/MeshPartTest.h>
+CPPUNIT_TEST_SUITE_REGISTRATION(libcigma::MeshPartTest);
+
#include <libcigma/DofHandlerTest.h>
CPPUNIT_TEST_SUITE_REGISTRATION(libcigma::DofHandlerTest);
More information about the CIG-COMMITS
mailing list