[cig-commits] r13083 - in cs/cigma/trunk: src tests tests/libcigma tests/pytests
luis at geodynamics.org
luis at geodynamics.org
Wed Oct 15 10:13:10 PDT 2008
Author: luis
Date: 2008-10-15 10:13:10 -0700 (Wed, 15 Oct 2008)
New Revision: 13083
Added:
cs/cigma/trunk/src/py_Function.cpp
cs/cigma/trunk/src/py_Function.h
cs/cigma/trunk/tests/libcigma/FunctionTest.cpp
cs/cigma/trunk/tests/libcigma/FunctionTest.h
cs/cigma/trunk/tests/pytests/test_function.py
Modified:
cs/cigma/trunk/src/Function.cpp
cs/cigma/trunk/src/Function.h
cs/cigma/trunk/tests/test_registry.cpp
Log:
Python bindings for abstract class cigma::Function
Modified: cs/cigma/trunk/src/Function.cpp
===================================================================
--- cs/cigma/trunk/src/Function.cpp 2008-10-15 17:13:08 UTC (rev 13082)
+++ cs/cigma/trunk/src/Function.cpp 2008-10-15 17:13:10 UTC (rev 13083)
@@ -5,6 +5,7 @@
// ----------------------------------------------------------------------------
+Function::Function() {}
Function::~Function() {}
// ----------------------------------------------------------------------------
Modified: cs/cigma/trunk/src/Function.h
===================================================================
--- cs/cigma/trunk/src/Function.h 2008-10-15 17:13:08 UTC (rev 13082)
+++ cs/cigma/trunk/src/Function.h 2008-10-15 17:13:10 UTC (rev 13083)
@@ -11,11 +11,11 @@
class cigma::Function
{
public:
-
+ Function();
virtual ~Function();
- virtual int n_dim() = 0;
- virtual int n_rank() = 0;
+ virtual int n_dim() const = 0;
+ virtual int n_rank() const = 0;
virtual bool eval(double *point, double *value) = 0;
static boost::shared_ptr<Function> New(const char *source);
Added: cs/cigma/trunk/src/py_Function.cpp
===================================================================
--- cs/cigma/trunk/src/py_Function.cpp (rev 0)
+++ cs/cigma/trunk/src/py_Function.cpp 2008-10-15 17:13:10 UTC (rev 13083)
@@ -0,0 +1,36 @@
+#include "py_Function.h"
+
+using namespace cigma;
+using namespace boost::python;
+
+// ----------------------------------------------------------------------------
+
+int pyFunction::n_dim() const
+{
+ return this->get_override("n_dim")();
+}
+
+int pyFunction::n_rank() const
+{
+ return this->get_override("n_rank")();
+}
+
+bool pyFunction::eval(double *point, double *value)
+{
+ return this->get_override("eval")(point,value);
+}
+
+// ----------------------------------------------------------------------------
+
+void export_Function()
+{
+ using namespace cigma;
+ using namespace boost::python;
+
+ class_<pyFunction, boost::noncopyable>("Function")
+ .def("n_dim", pure_virtual(&Function::n_dim))
+ .def("n_rank", pure_virtual(&Function::n_rank))
+ .def("eval", pure_virtual(&Function::eval))
+ ;
+
+}
Added: cs/cigma/trunk/src/py_Function.h
===================================================================
--- cs/cigma/trunk/src/py_Function.h (rev 0)
+++ cs/cigma/trunk/src/py_Function.h 2008-10-15 17:13:10 UTC (rev 13083)
@@ -0,0 +1,42 @@
+#ifndef __PY_FUNCTION_H__
+#define __PY_FUNCTION_H__
+
+#include <boost/python.hpp>
+#include "Function.h"
+#include "Point.h"
+
+struct pyFunction : cigma::Function, boost::python::wrapper<cigma::Function>
+{
+ int n_dim() const;
+ int n_rank() const;
+ bool eval(double *point, double *value);
+
+ template <int dim, int rank>
+ bool eval(cigma::Point<dim>& x, cigma::Point<rank>& y)
+ {
+ if (boost::python::override py_eval = this->get_override("eval"))
+ {
+ return py_eval(x, y);
+ }
+ return cigma::Function::eval(x.coord, y.coord);
+ }
+
+ bool eval_33(cigma::Point<3>& x, cigma::Point<3>& y)
+ {
+ return eval<3,3>(x,y);
+ }
+
+ /*
+ bool eval_39();
+ bool eval_36();
+ bool eval_33();
+ bool eval_31();
+ bool eval_24();
+ bool eval_22();
+ bool eval_21();
+ bool eval_11();
+ // */
+
+};
+
+#endif
Added: cs/cigma/trunk/tests/libcigma/FunctionTest.cpp
===================================================================
--- cs/cigma/trunk/tests/libcigma/FunctionTest.cpp (rev 0)
+++ cs/cigma/trunk/tests/libcigma/FunctionTest.cpp 2008-10-15 17:13:10 UTC (rev 13083)
@@ -0,0 +1,10 @@
+#include "FunctionTest.h"
+using namespace libcigma;
+
+#include "Function.h"
+using namespace cigma;
+
+void FunctionTest::test_something()
+{
+}
+
Added: cs/cigma/trunk/tests/libcigma/FunctionTest.h
===================================================================
--- cs/cigma/trunk/tests/libcigma/FunctionTest.h (rev 0)
+++ cs/cigma/trunk/tests/libcigma/FunctionTest.h 2008-10-15 17:13:10 UTC (rev 13083)
@@ -0,0 +1,23 @@
+#ifndef __FUNCTION_TEST_H__
+#define __FUNCTION_TEST_H__
+
+#include <cppunit/TestFixture.h>
+#include <cppunit/extensions/HelperMacros.h>
+
+
+namespace libcigma
+{
+ class FunctionTest : public CPPUNIT_NS::TestFixture
+ {
+ CPPUNIT_TEST_SUITE(FunctionTest);
+ CPPUNIT_TEST(test_something);
+ CPPUNIT_TEST_SUITE_END();
+
+ public:
+ FunctionTest() {}
+ ~FunctionTest() {}
+ void test_something();
+ };
+};
+
+#endif
Added: cs/cigma/trunk/tests/pytests/test_function.py
===================================================================
--- cs/cigma/trunk/tests/pytests/test_function.py (rev 0)
+++ cs/cigma/trunk/tests/pytests/test_function.py 2008-10-15 17:13:10 UTC (rev 13083)
@@ -0,0 +1,29 @@
+#!/usr/bin/env python
+
+from _cigma import Function
+
+class MyScalarFunction(Function):
+ def __init__(self):
+ Function.__init__(self) # Very Important!
+ def n_dim(self):
+ return 3
+ def n_rank(self):
+ return 1
+ def eval(self, point, value):
+ return False
+
+import unittest
+class FunctionTest(unittest.TestCase):
+ def __init__(self, *args):
+ unittest.TestCase.__init__(self, *args)
+ def test_function_zero(self):
+ pass
+ def test_function_scalar(self):
+ f = MyScalarFunction()
+ self.assertEqual(f.n_dim(), 3)
+ self.assertEqual(f.n_rank(), 1)
+
+def create_suite():
+ suite = unittest.TestSuite()
+ suite.addTest(unittest.makeSuite(FunctionTest))
+ return suite
Modified: cs/cigma/trunk/tests/test_registry.cpp
===================================================================
--- cs/cigma/trunk/tests/test_registry.cpp 2008-10-15 17:13:08 UTC (rev 13082)
+++ cs/cigma/trunk/tests/test_registry.cpp 2008-10-15 17:13:10 UTC (rev 13083)
@@ -21,6 +21,9 @@
#include <libcigma/ElementBlockTest.h>
CPPUNIT_TEST_SUITE_REGISTRATION(libcigma::ElementBlockTest);
+#include <libcigma/FunctionTest.h>
+CPPUNIT_TEST_SUITE_REGISTRATION(libcigma::FunctionTest);
+
#include <libcigma/ReaderTest.h>
CPPUNIT_TEST_SUITE_REGISTRATION(libcigma::ReaderTest);
More information about the cig-commits
mailing list