[cig-commits] r13075 - cs/cigma/trunk/src
luis at geodynamics.org
luis at geodynamics.org
Wed Oct 15 10:12:57 PDT 2008
Author: luis
Date: 2008-10-15 10:12:57 -0700 (Wed, 15 Oct 2008)
New Revision: 13075
Added:
cs/cigma/trunk/src/py_Quadrature.h
Modified:
cs/cigma/trunk/src/py_Quadrature.cpp
Log:
Created header file for pyQuadrature C++ struct
Modified: cs/cigma/trunk/src/py_Quadrature.cpp
===================================================================
--- cs/cigma/trunk/src/py_Quadrature.cpp 2008-10-15 17:12:55 UTC (rev 13074)
+++ cs/cigma/trunk/src/py_Quadrature.cpp 2008-10-15 17:12:57 UTC (rev 13075)
@@ -1,144 +1,137 @@
#include <iostream>
-#include "Quadrature.h"
-#include "numpy_util.h"
+#include "py_Quadrature.h"
using namespace cigma;
using namespace boost::python;
-struct pyQuadrature : Quadrature
+pyQuadrature::pyQuadrature() : na_points(0), na_weights(0)
{
- pyQuadrature() : na_points(0), na_weights(0)
- {
- PyErr_SetString(PyExc_RuntimeError, "Constructor called without arguments");
- throw_error_already_set();
- }
+ PyErr_SetString(PyExc_RuntimeError, "Constructor called without arguments");
+ throw_error_already_set();
+}
- pyQuadrature(int npts, int ndim) : Quadrature(), na_points(0), na_weights(0)
- {
- std::vector<int> point_dims;
- point_dims.push_back(npts);
- point_dims.push_back(ndim);
- na_points = numpy_util::makeArray(point_dims, PyArray_DOUBLE);
- na_weights = numpy_util::makeArray(npts, PyArray_DOUBLE);
- this->npts = npts;
- this->ndim = ndim;
- this->points = (double *)numpy_util::data(na_points);
- this->weights = (double *)numpy_util::data(na_weights);
- for (int q = 0; q < npts; q++)
+pyQuadrature::pyQuadrature(int npts, int ndim) : Quadrature(), na_points(0), na_weights(0)
+{
+ std::vector<int> point_dims;
+ point_dims.push_back(npts);
+ point_dims.push_back(ndim);
+ na_points = numpy_util::makeArray(point_dims, PyArray_DOUBLE);
+ na_weights = numpy_util::makeArray(npts, PyArray_DOUBLE);
+ this->npts = npts;
+ this->ndim = ndim;
+ this->points = (double *)numpy_util::data(na_points);
+ this->weights = (double *)numpy_util::data(na_weights);
+ for (int q = 0; q < npts; q++)
+ {
+ this->weights[q] = 0;
+ for (int j = 0; j < ndim; j++)
{
- this->weights[q] = 0;
- for (int j = 0; j < ndim; j++)
- {
- this->points[ndim*q + j] = 0;
- }
+ this->points[ndim*q + j] = 0;
}
}
+}
- ~pyQuadrature()
- {
- //std::cout << "Calling ~pyQuadrature()" << std::endl;
- npts = 0;
- ndim = 0;
- points = 0;
- weights = 0;
- }
+pyQuadrature::~pyQuadrature()
+{
+ //std::cout << "Calling ~pyQuadrature()" << std::endl;
+ npts = 0;
+ ndim = 0;
+ points = 0;
+ weights = 0;
+}
- double getPoint(int q, int j) const
+double pyQuadrature::getPoint(int q, int j) const
+{
+ if ((q >= n_points()) || (q < 0))
{
- if ((q >= n_points()) || (q < 0))
- {
- PyErr_SetString(PyExc_IndexError, "First index is out of bounds");
- throw_error_already_set();
- }
- if ((j >= n_dim()) || (j < 0))
- {
- PyErr_SetString(PyExc_IndexError, "Second index is out of bounds");
- throw_error_already_set();
- }
- return Quadrature::getPoint(q,j);
+ PyErr_SetString(PyExc_IndexError, "First index is out of bounds");
+ throw_error_already_set();
}
-
- double getWeight(int q) const
+ if ((j >= n_dim()) || (j < 0))
{
- if ((q >= n_points()) || (q < 0))
- {
- PyErr_SetString(PyExc_IndexError, "Index is out of bounds");
- throw_error_already_set();
- }
- return Quadrature::getWeight(q);
+ PyErr_SetString(PyExc_IndexError, "Second index is out of bounds");
+ throw_error_already_set();
}
+ return Quadrature::getPoint(q,j);
+}
- void setPoint(int q, int j, double val)
+double pyQuadrature::getWeight(int q) const
+{
+ if ((q >= n_points()) || (q < 0))
{
- if ((q >= n_points()) || (q < 0))
- {
- PyErr_SetString(PyExc_IndexError, "First index is out of bounds");
- throw_error_already_set();
- }
- if ((j >= n_dim()) || (j < 0))
- {
- PyErr_SetString(PyExc_IndexError, "Second index is out of bounds");
- throw_error_already_set();
- }
- Quadrature::setPoint(q, j, val);
+ PyErr_SetString(PyExc_IndexError, "Index is out of bounds");
+ throw_error_already_set();
}
+ return Quadrature::getWeight(q);
+}
- void setWeight(int q, double val)
+void pyQuadrature::setPoint(int q, int j, double val)
+{
+ if ((q >= n_points()) || (q < 0))
{
- if ((q >= n_points()) || (q < 0))
- {
- PyErr_SetString(PyExc_IndexError, "Index is out of bounds");
- throw_error_already_set();
- }
- Quadrature::setWeight(q, val);
+ PyErr_SetString(PyExc_IndexError, "First index is out of bounds");
+ throw_error_already_set();
}
-
- numeric::array getPoints()
+ if ((j >= n_dim()) || (j < 0))
{
- //return numpy_util::makeArray<double>(weights, n_points());
- return na_points;
+ PyErr_SetString(PyExc_IndexError, "Second index is out of bounds");
+ throw_error_already_set();
}
+ Quadrature::setPoint(q, j, val);
+}
- numeric::array getWeights()
+void pyQuadrature::setWeight(int q, double val)
+{
+ if ((q >= n_points()) || (q < 0))
{
- //return numpy_util::makeArray<double>(points, n_points() * n_dim());
- return na_weights;
+ PyErr_SetString(PyExc_IndexError, "Index is out of bounds");
+ throw_error_already_set();
}
+ Quadrature::setWeight(q, val);
+}
- void setPoints(numeric::array x)
+numeric::array pyQuadrature::getPoints()
+{
+ //return numpy_util::makeArray<double>(weights, n_points());
+ return na_points;
+}
+
+numeric::array pyQuadrature::getWeights()
+{
+ //return numpy_util::makeArray<double>(points, n_points() * n_dim());
+ return na_weights;
+}
+
+void pyQuadrature::setPoints(numeric::array x)
+{
+ numpy_util::check_type(x, PyArray_DOUBLE);
+ numpy_util::check_rank(x, 2);
+ numpy_util::check_size(x, npts * ndim);
+ double *data = (double *)numpy_util::data(x);
+ for (int q = 0; q < npts; q++)
{
- numpy_util::check_type(x, PyArray_DOUBLE);
- numpy_util::check_rank(x, 2);
- numpy_util::check_size(x, npts * ndim);
- double *data = (double *)numpy_util::data(x);
- for (int q = 0; q < npts; q++)
+ for (int j = 0; j < ndim; j++)
{
- for (int j = 0; j < ndim; j++)
- {
- int n = ndim*q + j;
- points[n] = data[n];
- }
+ int n = ndim*q + j;
+ points[n] = data[n];
}
}
+}
- void setWeights(numeric::array w)
+void pyQuadrature::setWeights(numeric::array w)
+{
+ numpy_util::check_type(w, PyArray_DOUBLE);
+ numpy_util::check_rank(w, 1);
+ numpy_util::check_size(w, npts);
+ double *data = (double *)numpy_util::data(w);
+ for (int q = 0; q < npts; q++)
{
- numpy_util::check_type(w, PyArray_DOUBLE);
- numpy_util::check_rank(w, 1);
- numpy_util::check_size(w, npts);
- double *data = (double *)numpy_util::data(w);
- for (int q = 0; q < npts; q++)
- {
- weights[q] = data[q];
- }
+ weights[q] = data[q];
}
+}
-private:
- numeric::array na_points;
- numeric::array na_weights;
-};
+// ----------------------------------------------------------------------------
-
void export_Quadrature()
{
using namespace boost::python;
Added: cs/cigma/trunk/src/py_Quadrature.h
===================================================================
--- cs/cigma/trunk/src/py_Quadrature.h (rev 0)
+++ cs/cigma/trunk/src/py_Quadrature.h 2008-10-15 17:12:57 UTC (rev 13075)
@@ -0,0 +1,30 @@
+#ifndef __PY_QUADRATURE_H__
+#define __PY_QUADRATURE_H__
+
+#include "Quadrature.h"
+#include "numpy_util.h"
+
+struct pyQuadrature : cigma::Quadrature
+{
+ pyQuadrature();
+ pyQuadrature(int npts, int ndim);
+ ~pyQuadrature();
+
+ double getPoint(int q, int j) const;
+ double getWeight(int q) const;
+
+ void setPoint(int q, int j, double val);
+ void setWeight(int q, double val);
+
+ boost::python::numeric::array getPoints();
+ boost::python::numeric::array getWeights();
+
+ void setPoints(boost::python::numeric::array x);
+ void setWeights(boost::python::numeric::array w);
+
+private:
+ boost::python::numeric::array na_points;
+ boost::python::numeric::array na_weights;
+};
+
+#endif
More information about the cig-commits
mailing list