From b822430ef2c81d581652a0a854a030d54fd70081 Mon Sep 17 00:00:00 2001
From: Nicolas Marsic <nicolas.marsic@gmail.com>
Date: Thu, 2 Aug 2012 14:33:28 +0000
Subject: [PATCH] Interpolation (0form)

---
 FunctionSpace/BasisTest.cpp         |  4 +-
 FunctionSpace/CMakeLists.txt        |  1 +
 FunctionSpace/FunctionSpace.cpp     |  4 ++
 FunctionSpace/FunctionSpace.h       | 25 +++++++++---
 FunctionSpace/FunctionSpaceNode.cpp | 61 +++++++++++++++++++++++++++++
 FunctionSpace/FunctionSpaceNode.h   | 15 +++++++
 6 files changed, 103 insertions(+), 7 deletions(-)
 create mode 100644 FunctionSpace/FunctionSpaceNode.cpp
 create mode 100644 FunctionSpace/FunctionSpaceNode.h

diff --git a/FunctionSpace/BasisTest.cpp b/FunctionSpace/BasisTest.cpp
index eafa8a83e8..00f89f273b 100644
--- a/FunctionSpace/BasisTest.cpp
+++ b/FunctionSpace/BasisTest.cpp
@@ -16,7 +16,7 @@
 
 using namespace std;
 
-int test(int argc, char** argv){
+int basisTest(int argc, char** argv){
   // Init Gmsh //
   GmshInitialize(argc, argv);
 
@@ -24,7 +24,7 @@ int test(int argc, char** argv){
   Mesh msh(argv[1]);
 
   // Plot Basis //
-  HexEdgeBasis b(1);
+  TriEdgeBasis b(5);
   
   PlotBasis plot(msh.getGroup(2), b);
   plot.write("basis");
diff --git a/FunctionSpace/CMakeLists.txt b/FunctionSpace/CMakeLists.txt
index a6b8edc474..f222a3f1e6 100644
--- a/FunctionSpace/CMakeLists.txt
+++ b/FunctionSpace/CMakeLists.txt
@@ -22,6 +22,7 @@ set(SRC
   HexEdgeBasis.cpp
 
   FunctionSpace.cpp
+  FunctionSpaceNode.cpp
 )
 
 file(GLOB HDR RELATIVE ${CMAKE_CURRENT_SOURCE_DIR} *.h) 
diff --git a/FunctionSpace/FunctionSpace.cpp b/FunctionSpace/FunctionSpace.cpp
index 5fe97a8bd2..c0079b2678 100644
--- a/FunctionSpace/FunctionSpace.cpp
+++ b/FunctionSpace/FunctionSpace.cpp
@@ -4,6 +4,9 @@
 using namespace std;
 
 FunctionSpace::FunctionSpace(const GroupOfElement& goe, int basisType, int order){
+  // DofManager //
+  dofM = NULL;
+
   // Save GroupOfElement //
   this->goe = &goe;  
 
@@ -12,6 +15,7 @@ FunctionSpace::FunctionSpace(const GroupOfElement& goe, int basisType, int order
   int elementType = goe.get(0).getType();
   
   // Init Struct //
+  type   = basisType;
   basis  = BasisGenerator::generate(elementType, basisType, order);
 
   // Count Function per Entity //
diff --git a/FunctionSpace/FunctionSpace.h b/FunctionSpace/FunctionSpace.h
index bad83d9626..73bc9c3483 100644
--- a/FunctionSpace/FunctionSpace.h
+++ b/FunctionSpace/FunctionSpace.h
@@ -7,6 +7,7 @@
 #include "GroupOfElement.h"
 #include "MElement.h"
 #include "Dof.h"
+#include "DofManager.h"
 
 /** 
     @class FunctionSpace
@@ -19,26 +20,32 @@
 */
 
 class ElementComparator;
+class DofManager;
 
 class FunctionSpace{
- private:
-  const Basis* basis;
+ protected:
+  const Basis*          basis;
   const GroupOfElement* goe;
+  const DofManager*     dofM;
 
   int fPerVertex;
   int fPerEdge;
   int fPerFace;
   int fPerCell;
 
+  int type;
+
  public:
-   FunctionSpace(const GroupOfElement& goe, 
-		 int basisType, int order);
+  FunctionSpace(const GroupOfElement& goe, 
+		int basisType, int order);
 
-  ~FunctionSpace(void);
+  virtual ~FunctionSpace(void);
 
   const GroupOfElement& getSupport(void) const;
   const Basis&          getBasis(const MElement& element) const;
+  int                   getType(void) const;
 
+  void                    associate(const DofManager& dofM);
   const std::vector<Dof*> getKeys(const MElement& element) const;
 
   int getNFunctionPerVertex(const MElement& element) const;
@@ -59,6 +66,14 @@ inline const Basis& FunctionSpace::getBasis(const MElement& element) const{
   return *basis;
 }
 
+inline int FunctionSpace::getType(void) const{
+  return type;
+}
+
+inline void FunctionSpace::associate(const DofManager& dofM){
+  this->dofM = &dofM;
+}
+
 inline int FunctionSpace::getNFunctionPerVertex(const MElement& element) const{
   return fPerVertex;
 }
diff --git a/FunctionSpace/FunctionSpaceNode.cpp b/FunctionSpace/FunctionSpaceNode.cpp
new file mode 100644
index 0000000000..dce20c1b6d
--- /dev/null
+++ b/FunctionSpace/FunctionSpaceNode.cpp
@@ -0,0 +1,61 @@
+#include "FunctionSpaceNode.h"
+#include "Polynomial.h"
+#include "BasisScalar.h"
+#include "Exception.h"
+
+using namespace std;
+
+FunctionSpaceNode::FunctionSpaceNode(const GroupOfElement& goe, int order):
+FunctionSpace(goe, 0, order){
+  // Just Call Super Constructor with basisType = 0
+}
+
+
+FunctionSpaceNode::~FunctionSpaceNode(void){
+}
+
+vector<double> FunctionSpaceNode::
+interpolateAtNodes(const MElement& elem, 
+		   const vector<double>& coef) const{
+  // Check
+  unsigned int wS = coef.size();
+  unsigned int bS = basis->getSize();
+
+  if(wS < bS)
+    throw Exception
+      ("Not enough coefs for interpolation:\nBasis: %d -- coefs: %d",
+       bS, wS);
+
+  if(wS > bS)
+    throw Exception
+      ("Too much coefs for interpolation:\nBasis: %d -- coefs: %d",
+       bS, wS);
+
+  // Get Nodes
+  MElement& element = const_cast<MElement&>(elem);
+
+  vector<MVertex*> node;
+  element.getVertices(node);
+  unsigned int N = node.size();
+
+  // Get Functions
+  const vector<Polynomial>& fun = 
+    static_cast<const BasisScalar*>(basis)->getBasis();
+
+  // Init Vector
+  vector<double> value(N);
+
+  // Interpolate
+  for(unsigned int n = 0; n < N; n++){
+    const double x = node[n]->x();
+    const double y = node[n]->y();
+    const double z = node[n]->z();
+
+    value[n] = 0;
+
+    for(unsigned int i = 0; i < bS; i++)
+      value[n] += fun[i].at(x, y, z) * coef[i];
+  }
+
+  return value;
+}
diff --git a/FunctionSpace/FunctionSpaceNode.h b/FunctionSpace/FunctionSpaceNode.h
new file mode 100644
index 0000000000..d63400836d
--- /dev/null
+++ b/FunctionSpace/FunctionSpaceNode.h
@@ -0,0 +1,15 @@
+#ifndef _FUNCTIONSPACENODE_H_
+#define _FUNCTIONSPACENODE_H_
+
+#include "FunctionSpace.h"
+
+class FunctionSpaceNode: public FunctionSpace{
+  FunctionSpaceNode(const GroupOfElement& goe, int order);
+
+  virtual ~FunctionSpaceNode(void);
+
+  std::vector<double> interpolateAtNodes(const MElement& element, 
+					 const std::vector<double>& coef) const;
+};
+
+#endif
-- 
GitLab