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

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


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

Added:
   cs/benchmark/cigma/trunk/src/FiatProxy.cpp
   cs/benchmark/cigma/trunk/src/tests/TestFiatProxy.cpp
Log:
Initial FiatProxy implementation (calls test() function)

Added: cs/benchmark/cigma/trunk/src/FiatProxy.cpp
===================================================================
--- cs/benchmark/cigma/trunk/src/FiatProxy.cpp	2007-12-19 20:05:22 UTC (rev 8936)
+++ cs/benchmark/cigma/trunk/src/FiatProxy.cpp	2007-12-19 20:05:29 UTC (rev 8937)
@@ -0,0 +1,105 @@
+#include "FiatProxy.h"
+#include <iostream>
+#include <cassert>
+
+// ---------------------------------------------------------------------------
+
+cigma::FiatProxy::FiatProxy()
+{
+}
+
+cigma::FiatProxy::~FiatProxy()
+{
+}
+
+// ---------------------------------------------------------------------------
+
+void cigma::FiatProxy::initialize()
+{
+    PyObject *module_name;
+
+    Py_Initialize();
+
+    import_array();
+
+    module_name = PyString_FromString("FiatProxy");
+    module = PyImport_Import(module_name);
+    
+    if (!module)
+    {
+        /* XXX: raise exception */ 
+        assert(false);
+    }
+
+    module_dict = PyModule_GetDict(module);
+
+    test_fn = PyDict_GetItemString(module_dict, "test");
+    if (!test_fn)
+    {
+        /* XXX: raise exception */
+        assert(false);
+    }
+    if (!PyCallable_Check(test_fn))
+    {
+        /* XXX: raise exception */
+        assert(false);
+    }
+
+    quad_fn = PyDict_GetItemString(module_dict, "quadrature");
+    if (!quad_fn)
+    {
+        /* XXX: raise exception */
+        assert(false);
+    }
+    if (!PyCallable_Check(quad_fn))
+    {
+        /* XXX: raise exception */
+        assert(false);
+    }
+
+    tab_fn = PyDict_GetItemString(module_dict, "tabulate");
+    if (!tab_fn) 
+    {
+        /* XXX: raise exception */
+        assert(false);
+    }
+    if (!PyCallable_Check(tab_fn))
+    {
+        /* XXX: raise exception */
+        assert(false);
+    }
+
+    Py_XDECREF(module_name);
+}
+
+void cigma::FiatProxy::finalize()
+{
+    if (module)
+        Py_XDECREF(module);
+}
+
+void cigma::FiatProxy::test(const char *msg, int n)
+{
+    PyObject *result;
+    long answer;
+    
+    result = PyObject_CallFunction(test_fn, "(si)", msg, n);
+
+    if (result)
+    {
+        answer = PyInt_AsLong(result);
+
+        std::cout << "Answer is " << answer << std::endl;
+
+        Py_XDECREF(result);
+    }
+}
+
+void cigma::FiatProxy::quadrature(int shape, int order, double **x, double **w, int *npts, int *dim)
+{
+}
+
+void cigma::FiatProxy::tabulate(int npts, double *pts, double *basis, double *basisDeriv)
+{
+}
+

Added: cs/benchmark/cigma/trunk/src/tests/TestFiatProxy.cpp
===================================================================
--- cs/benchmark/cigma/trunk/src/tests/TestFiatProxy.cpp	2007-12-19 20:05:22 UTC (rev 8936)
+++ cs/benchmark/cigma/trunk/src/tests/TestFiatProxy.cpp	2007-12-19 20:05:29 UTC (rev 8937)
@@ -0,0 +1,35 @@
+#include "../FiatProxy.h"
+#include <iostream>
+
+
+int main(int argc, char *argv[])
+{
+    using namespace cigma;
+
+    FiatProxy *fiat = new FiatProxy();
+    fiat->initialize();
+
+
+    //* run test function first
+    {
+        char *msg = "hello world";
+        fiat->test(msg, 3);
+    } // */
+
+
+    /* test quadrature - note copy semantics
+    {
+        int shape;
+        int order;
+        double *x, *w;
+        int npts, dim;
+
+        fiat->quadrature(shape, order, &x, &w, &npts, &dim);
+    } // */
+
+
+    fiat->finalize();
+    delete fiat;
+
+    return 0;
+}



More information about the cig-commits mailing list