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

luis at geodynamics.org luis at geodynamics.org
Tue Dec 9 18:13:47 PST 2008


Author: luis
Date: 2008-12-09 18:13:46 -0800 (Tue, 09 Dec 2008)
New Revision: 13541

Modified:
   cs/cigma/trunk/src/FE.cpp
   cs/cigma/trunk/src/FE.h
Log:
Move factory and setter methods into FE class

Modified: cs/cigma/trunk/src/FE.cpp
===================================================================
--- cs/cigma/trunk/src/FE.cpp	2008-12-10 02:13:45 UTC (rev 13540)
+++ cs/cigma/trunk/src/FE.cpp	2008-12-10 02:13:46 UTC (rev 13541)
@@ -1,7 +1,27 @@
 #include "FE.h"
+#include "core_array.h"
+#include "core_readers.h"
+#include <string>
+#include <sstream>
+using namespace std;
 using namespace cigma;
 using boost::shared_ptr;
 
+// ----------------------------------------------------------------------------
+
+shared_ptr<FE> FE::New(const FE_Info& fe_info)
+{
+    shared_ptr<FE> fe(new FE);
+
+    fe->quadrature = Quadrature::New(fe_info.q_info);
+    fe->cell = Cell::New(fe_info.q_info.cell_type_name.c_str());
+    fe->setBasisAtQuad(fe_info.p_fe_basis);
+
+    return fe;
+}
+
+// ----------------------------------------------------------------------------
+
 FE::FE()
 {
     jxw = 0;
@@ -68,3 +88,127 @@
 }
 
 
+void FE::set_basis_tab(double *tab)
+{
+    assert(cell);
+    assert(quadrature);
+    assert(jxw != 0);
+    assert(basis_tab != 0);
+
+    const int nq = quadrature->n_points();
+    const int ndofs = cell->n_nodes();
+
+    for (int q = 0; q < nq; q++)
+    {
+        for (int j = 0; j < ndofs; j++)
+        {
+            int k = ndofs*q + j;
+            this->basis_tab[k] = tab[k];
+        }
+    }
+
+    //this->update_jxw();
+}
+
+
+void FE::setCell(string cell_name)
+{
+    TRI_LOG_STR("FE::setCell");
+
+    if (!quadrature)
+    {
+        quadrature = shared_ptr<Quadrature>(new Quadrature());
+        quadrature->setCell(cell_name);
+    }
+
+    this->cell = Cell::New(quadrature->getCellType());
+
+    return;
+}
+
+
+void FE::setQuadPath(const DataPath& p_quad)
+{
+    TRI_LOG_STR("FE::setQuadPath");
+
+    if (!quadrature)
+    {
+        quadrature = shared_ptr<Quadrature>(new Quadrature);
+    }
+
+    quadrature->setPath(p_quad);
+}
+
+
+void FE::setQuadPath2(const DataPath& p_weights, const DataPath& p_points)
+{
+    TRI_LOG_STR("FE::setQuadPath2");
+
+    if (!quadrature)
+    {
+        quadrature = shared_ptr<Quadrature>(new Quadrature);
+    }
+
+    quadrature->setPath2(p_weights, p_points);
+}
+
+
+void FE::setBasisAtQuad(const DataPath& p_basis)
+{
+    if (cell && quadrature)
+    {
+        if (p_basis.empty())
+        {
+            this->init_basis();
+        }
+        else
+        {
+            cigma::array<double> *b = ReadArray(p_basis);
+            if (b == 0)
+            {
+                std::ostringstream stream;
+                stream << "Failed to read basis function values from path '" << p_basis << "'" << std::ends;
+                throw cigma::Exception("FE::setBasisAtQuad", stream.str());
+            }
+
+            const int nq = quadrature->n_points();
+            const int ndofs = cell->n_nodes();
+
+            if ((b->n_points() != nq) || (b->n_dim() != ndofs))
+            {
+                std::ostringstream stream;
+                stream << "Basis tabulation array "
+                       << "[" << b->n_points() << "x" << b->n_dim() << "]"
+                       << " did not match expected dimensions "
+                       << "[" << nq << "x" << ndofs << "]"
+                       << std::ends;
+                delete b;
+                throw cigma::Exception("FE::setBasisAtQuad", stream.str());
+            }
+
+            if (jxw != 0) { delete [] jxw; }
+            if (basis_tab != 0) { delete [] basis_tab; }
+
+            jxw = new double[nq];
+            basis_tab = new double[nq * ndofs];
+
+            this->set_basis_tab(b->_data);
+        }
+    }
+    else
+    {
+        string msg("Cannot set basis function values: uninitialized");
+        if (!cell)
+        {
+            msg += " cell";
+            if (!quadrature)
+                msg += " and ";
+        }
+        if (!quadrature)
+        {
+            msg += "quadrature";
+        }
+        throw cigma::Exception("FE::setBasisAtQuad", msg);
+    }
+}
+

Modified: cs/cigma/trunk/src/FE.h
===================================================================
--- cs/cigma/trunk/src/FE.h	2008-12-10 02:13:45 UTC (rev 13540)
+++ cs/cigma/trunk/src/FE.h	2008-12-10 02:13:46 UTC (rev 13541)
@@ -6,6 +6,8 @@
 
 #include "Cell.h"
 #include "Quadrature.h"
+#include "DataPath.h"
+#include "core_args.h"
 
 namespace cigma
 {
@@ -26,6 +28,18 @@
 
     //void apply_refmap(Cell& cell);
 
+    /* direct setters */
+    void set_basis_tab(double *tab);
+
+    /* incremental setters */
+    void setCell(std::string cell_name);
+    void setQuadPath(const DataPath& p_quad);
+    void setQuadPath2(const DataPath& p_weights, const DataPath& p_points);
+    void setBasisAtQuad(const DataPath& p_basis);
+
+    /* static factory method */
+    static boost::shared_ptr<FE> New(const FE_Info& fe_info);
+
 public:
     boost::shared_ptr<Cell> cell;
     boost::shared_ptr<Quadrature> quadrature;



More information about the CIG-COMMITS mailing list