[cig-commits] r13494 - cs/cigma/trunk/src
luis at geodynamics.org
luis at geodynamics.org
Tue Dec 9 18:12:33 PST 2008
Author: luis
Date: 2008-12-09 18:12:33 -0800 (Tue, 09 Dec 2008)
New Revision: 13494
Modified:
cs/cigma/trunk/src/Field.cpp
cs/cigma/trunk/src/Field.h
Log:
Updates to cigma::Field
Modified: cs/cigma/trunk/src/Field.cpp
===================================================================
--- cs/cigma/trunk/src/Field.cpp 2008-12-10 02:12:31 UTC (rev 13493)
+++ cs/cigma/trunk/src/Field.cpp 2008-12-10 02:12:33 UTC (rev 13494)
@@ -4,6 +4,8 @@
Field::Field()
{
+ mesh = shared_ptr<MeshPart>(new MeshPart);
+ dofs = shared_ptr<DofHandler>(new DofHandler);
}
Field::~Field()
@@ -25,3 +27,53 @@
this->dofs = dofs;
}
+void Field::getCellDofs(int cellIndex, double *cellDofs)
+{
+ const int nel = mesh->n_cells();
+ const int ndofs = fe->cell->n_nodes();
+ const int valdim = this->n_rank();
+ assert((0 <= cellIndex) && (cellIndex < nel));
+
+ /*
+ for (int i = 0; i < ndofs; i++)
+ {
+ int n = mesh->connect->getId(cellIndex, i);
+ for (int j = 0; j < valdim; j++)
+ {
+ cellDofs[valdim*i + j] = dofs->dofs[valdim*n + j];
+ }
+ }*/
+
+ int nodeIds[ndofs];
+ for (int i = 0; i < ndofs; i++)
+ {
+ nodeIds[i] = mesh->connect->getId(cellIndex, i);
+ }
+ dofs->getData(ndofs, nodeIds, cellDofs);
+}
+
+bool Field::eval(double *point, double *value)
+{
+ // find the cell which contains given global point
+ int e;
+ bool found_cell = false;
+ found_cell = mesh->findCell(point, &e);
+ if (!found_cell)
+ {
+ //throw cigma::Exception("Field::eval", "Could not find cell");
+ return false; // XXX: throw exception instead of returning a boolean?
+ }
+
+ // load local cell info
+ const int ndofs = fe->cell->n_nodes();
+ const int valdim = this->n_rank();
+ double local_dofs[ndofs * valdim];
+ this->getCellDofs(e, local_dofs);
+ mesh->getCellCoords(e, fe->cell->globverts, fe->cell->n_celldim());
+
+ // interpolate on cell
+ double uvw[3];
+ fe->cell->xyz2uvw(point, uvw); // XXX: use mesh->findCell2() to get uvw directly
+ fe->cell->interpolate(local_dofs, uvw, value, valdim);
+ return true;
+}
Modified: cs/cigma/trunk/src/Field.h
===================================================================
--- cs/cigma/trunk/src/Field.h 2008-12-10 02:12:31 UTC (rev 13493)
+++ cs/cigma/trunk/src/Field.h 2008-12-10 02:12:33 UTC (rev 13494)
@@ -7,21 +7,28 @@
#include "MeshPart.h"
#include "FE.h"
#include "DofHandler.h"
+#include "Function.h"
namespace cigma
{
class Field;
}
-class cigma::Field : private boost::noncopyable
+class cigma::Field : public cigma::Function
{
public:
Field();
~Field();
+ int n_dim() const;
+ int n_rank() const;
+ bool eval(double *point, double *value);
+
void setMesh(const boost::shared_ptr<MeshPart> mesh);
void setFE(const boost::shared_ptr<FE> fe);
void setDofHandler(const boost::shared_ptr<DofHandler> dofs);
+
+ void getCellDofs(int cellIndex, double *cellDofs); // XXX: move method to DofHandler
public:
boost::shared_ptr<MeshPart> mesh;
@@ -29,5 +36,7 @@
boost::shared_ptr<DofHandler> dofs;
};
+inline int cigma::Field::n_dim() const { return mesh->coords->n_dim(); }
+inline int cigma::Field::n_rank() const { return dofs->n_rank(); }
#endif
More information about the CIG-COMMITS
mailing list