[cig-commits] r13068 - cs/cigma/trunk/src

luis at geodynamics.org luis at geodynamics.org
Wed Oct 15 02:08:16 PDT 2008


Author: luis
Date: 2008-10-15 02:08:16 -0700 (Wed, 15 Oct 2008)
New Revision: 13068

Added:
   cs/cigma/trunk/src/Quadrature.cpp
   cs/cigma/trunk/src/Quadrature.h
Log:
C++ container for quadrature points & weights

Added: cs/cigma/trunk/src/Quadrature.cpp
===================================================================
--- cs/cigma/trunk/src/Quadrature.cpp	                        (rev 0)
+++ cs/cigma/trunk/src/Quadrature.cpp	2008-10-15 09:08:16 UTC (rev 13068)
@@ -0,0 +1,76 @@
+#include <iostream>
+#include "Quadrature.h"
+
+using namespace cigma;
+
+// ----------------------------------------------------------------------------
+
+Quadrature::Quadrature()
+{
+    npts = 0;
+    ndim = 0;
+    points = 0;
+    weights = 0;
+}
+
+Quadrature::Quadrature(int npts, int ndim)
+{
+    this->npts = npts;
+    this->ndim = ndim;
+    this->points = new double[npts * ndim];
+    this->weights = new double[npts];
+    for (int q = 0; q < npts; q++)
+    {
+        this->weights[q] = 0;
+        for (int j = 0; j < ndim; j++)
+        {
+            this->points[ndim*q + j] = 0;
+        }
+    }
+}
+
+Quadrature::~Quadrature()
+{
+    //std::cout << "Calling ~Quadrature()" << std::endl;
+    if (points != 0)
+    {
+        delete [] points;
+        points = 0;
+        npts = 0;
+        ndim = 0;
+    }
+    if (weights != 0)
+    {
+        delete [] weights;
+        weights = 0;
+        npts = 0;
+    }
+}
+
+
+// ----------------------------------------------------------------------------
+
+void Quadrature::setData(int npts, int ndim, double *points, double *weights)
+{
+    this->npts = npts;
+    this->ndim = ndim;
+
+    if (this->points)  { delete [] this->points; }
+    if (this->weights) { delete [] this->weights; }
+
+    this->points = new double[npts * ndim];
+    this->weights = new double[npts];
+
+    for (int q = 0; q < npts; q++)
+    {
+        this->weights[q] = weights[q];
+        for (int j = 0; j < ndim; j++)
+        {
+            this->points[q*ndim + j] = points[q*ndim + j];
+        }
+    }
+}
+
+// ----------------------------------------------------------------------------
+
+

Added: cs/cigma/trunk/src/Quadrature.h
===================================================================
--- cs/cigma/trunk/src/Quadrature.h	                        (rev 0)
+++ cs/cigma/trunk/src/Quadrature.h	2008-10-15 09:08:16 UTC (rev 13068)
@@ -0,0 +1,44 @@
+#ifndef __CIGMA_QUADRATURE_H__
+#define __CIGMA_QUADRATURE_H__
+
+#include <boost/noncopyable.hpp>
+
+namespace cigma
+{
+    class Quadrature;
+}
+
+class cigma::Quadrature : private boost::noncopyable
+{
+public:
+    Quadrature();
+    Quadrature(int npts, int ndim);
+    ~Quadrature();
+
+    int n_points() const;
+    int n_dim() const;
+
+    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);
+
+    void setData(int npts, int ndim, double *points, double *weights);
+
+public:
+    int npts;
+    int ndim;
+    double *points;
+    double *weights;
+    //cigma::Cell *cell; // XXX: reference to parent cell?
+};
+
+inline int cigma::Quadrature::n_points() const { return npts; }
+inline int cigma::Quadrature::n_dim() const    { return ndim; }
+inline double cigma::Quadrature::getPoint(int q, int j) const { return points[q*ndim + j]; }
+inline double cigma::Quadrature::getWeight(int q) const { return weights[q]; }
+inline void cigma::Quadrature::setPoint(int q, int j, double val) { points[q*ndim + j] = val; }
+inline void cigma::Quadrature::setWeight(int q, double val) { weights[q] = val; }
+
+#endif



More information about the cig-commits mailing list