From 331b2b96e5cf1681b3af2dcf8f294964b2ff99ca Mon Sep 17 00:00:00 2001
From: Nicolas Marsic <nicolas.marsic@gmail.com>
Date: Tue, 31 Jul 2012 15:07:16 +0000
Subject: [PATCH] DofManager: OK -- FunctionSpace: GetKeys part one

---
 FunctionSpace/FunctionSpace.cpp | 88 ++++++++++++++++++++++++++++++++-
 FunctionSpace/FunctionSpace.h   | 46 +++++------------
 2 files changed, 99 insertions(+), 35 deletions(-)

diff --git a/FunctionSpace/FunctionSpace.cpp b/FunctionSpace/FunctionSpace.cpp
index 7276586ba7..5fe97a8bd2 100644
--- a/FunctionSpace/FunctionSpace.cpp
+++ b/FunctionSpace/FunctionSpace.cpp
@@ -13,7 +13,6 @@ FunctionSpace::FunctionSpace(const GroupOfElement& goe, int basisType, int order
   
   // Init Struct //
   basis  = BasisGenerator::generate(elementType, basisType, order);
-  eToGoD = new map<const MElement*, const GroupOfDof*, ElementComparator>;
 
   // Count Function per Entity //
   int nVertex = goe.get(0).getNumVertices();
@@ -36,8 +35,93 @@ FunctionSpace::FunctionSpace(const GroupOfElement& goe, int basisType, int order
   fPerCell = basis->getNCellBased(); // We always got 1 cell 
 }
 
+const vector<Dof*> FunctionSpace::getKeys(const MElement& elem) const{  
+  // nTotVertex 
+  int nTotVertex = goe->getNVertex();
+
+  // Const_Cast //
+  MElement& element = const_cast<MElement&>(elem);
+
+  // Get Element Data //
+  const int nVertex = element.getNumVertices();
+  const int nEdge   = element.getNumEdges();
+  const int nFace   = element.getNumFaces(); 
+
+  vector<MVertex*> vertex(nVertex);
+  vector<MEdge> edge(nEdge);
+  vector<MFace> face(nFace);
+
+  for(int i = 0; i < nVertex; i++)
+    vertex[i] = element.getVertex(i);
+
+  for(int i = 0; i < nEdge; i++)    
+    edge[i] = element.getEdge(i);
+  
+  for(int i = 0; i < nFace; i++)
+    face[i] = element.getFace(i);
+  
+  // Get FunctionSpace Data for this Element //
+  const int nFVertex = getNFunctionPerVertex(element);
+  const int nFEdge   = getNFunctionPerEdge(element);
+  const int nFFace   = getNFunctionPerFace(element);
+  const int nFCell   = getNFunctionPerCell(element);
+
+  // Create Dof //
+  const int nDofVertex = nFVertex * nVertex; 
+  const int nDofEdge   = nFEdge   * nEdge;
+  const int nDofFace   = nFFace   * nFace;
+  const int nDofCell   = nFCell;
+
+  int nDof = 
+    nDofVertex + nDofEdge + nDofFace + nDofCell;
+
+  vector<Dof*> myDof(nDof);
+
+  int it = 0;
+
+  // Add Vertex Based Dof //
+  for(int i = 0; i < nVertex; i++){
+    // Get Id of Vertex
+    const int id = vertex[i]->getNum();
+
+    // New Dof
+    for(int j = 0; j < nFVertex; j++){
+      myDof[it] = new Dof(id, j);
+      it++;
+    }
+  }
+
+  // Add Edge Based Dof //
+  for(int i = 0; i < nEdge; i++){
+    // Get Id of Edge 
+    MVertex* vEdge0 = edge[i].getSortedVertex(0);
+    MVertex* vEdge1 = edge[i].getSortedVertex(1);
+
+    const int id = 
+      vEdge0->getNum() + 
+      vEdge1->getNum() * nTotVertex;
+
+    // Insert new Dof
+    for(int j = 0; j < nFEdge; j++){
+      myDof[it] = new Dof(id, j);
+      it++;
+    }
+  }  
+
+  // Add Cell Based Dof //
+  // Get Id of Cell 
+  const int id = element.getNum() * nTotVertex * nTotVertex;
+
+  // Insert new Dof
+  for(int j = 0; j < nFCell; j++){
+    myDof[it] = new Dof(id, j);
+    it++;
+  }
+  
+  return myDof;
+}
+
 FunctionSpace::~FunctionSpace(void){
   delete basis;
-  delete eToGoD;
 }
 
diff --git a/FunctionSpace/FunctionSpace.h b/FunctionSpace/FunctionSpace.h
index 2959221242..bad83d9626 100644
--- a/FunctionSpace/FunctionSpace.h
+++ b/FunctionSpace/FunctionSpace.h
@@ -1,14 +1,12 @@
 #ifndef _FUNCTIONSPACE_H_
 #define _FUNCTIONSPACE_H_
 
-#include <map>
-
-#include "Dof.h"
-#include "GroupOfDof.h"
+#include <vector>
 
 #include "Basis.h"
 #include "GroupOfElement.h"
 #include "MElement.h"
+#include "Dof.h"
 
 /** 
     @class FunctionSpace
@@ -24,13 +22,9 @@ class ElementComparator;
 
 class FunctionSpace{
  private:
-  friend class DofManager;
-
   const Basis* basis;
   const GroupOfElement* goe;
 
-  std::map<const MElement*, const GroupOfDof*, ElementComparator>* eToGoD;
-
   int fPerVertex;
   int fPerEdge;
   int fPerFace;
@@ -43,20 +37,14 @@ class FunctionSpace{
   ~FunctionSpace(void);
 
   const GroupOfElement& getSupport(void) const;
-  const Basis&          getBasis(MElement& element) const;
+  const Basis&          getBasis(const MElement& element) const;
 
-  int getNFunctionPerVertex(MElement& element) const;
-  int getNFunctionPerEdge(MElement& element) const;
-  int getNFunctionPerFace(MElement& element) const;
-  int getNFunctionPerCell(MElement& element) const;
+  const std::vector<Dof*> getKeys(const MElement& element) const;
 
- private:
-  void associate(const MElement& element, const GroupOfDof& god);
-};
-
-class ElementComparator{
- public:
-  bool operator()(const MElement* a, const MElement* b) const;
+  int getNFunctionPerVertex(const MElement& element) const;
+  int getNFunctionPerEdge(const MElement& element) const;
+  int getNFunctionPerFace(const MElement& element) const;
+  int getNFunctionPerCell(const MElement& element) const;
 };
 
 //////////////////////
@@ -67,32 +55,24 @@ inline const GroupOfElement& FunctionSpace::getSupport(void) const{
   return *goe;
 }
 
-inline const Basis& FunctionSpace::getBasis(MElement& element) const{
+inline const Basis& FunctionSpace::getBasis(const MElement& element) const{
   return *basis;
 }
 
-inline int FunctionSpace::getNFunctionPerVertex(MElement& element) const{
+inline int FunctionSpace::getNFunctionPerVertex(const MElement& element) const{
   return fPerVertex;
 }
 
-inline int FunctionSpace::getNFunctionPerEdge(MElement& element) const{
+inline int FunctionSpace::getNFunctionPerEdge(const MElement& element) const{
   return fPerEdge;
 }
 
-inline int FunctionSpace::getNFunctionPerFace(MElement& element) const{
+inline int FunctionSpace::getNFunctionPerFace(const MElement& element) const{
   return fPerFace;
 }
 
-inline int FunctionSpace::getNFunctionPerCell(MElement& element) const{
+inline int FunctionSpace::getNFunctionPerCell(const MElement& element) const{
   return fPerCell;
 }
 
-inline void FunctionSpace::associate(const MElement& element, const GroupOfDof& god){
-  //return fPerCell;
-}
-
-inline bool ElementComparator::operator()(const MElement* a, const MElement* b) const{
-  return a->getNum() < b->getNum();
-}
-
 #endif
-- 
GitLab