From f51437ec175e0984a95da8ec937d17e263dc3268 Mon Sep 17 00:00:00 2001
From: Nicolas Marsic <nicolas.marsic@gmail.com>
Date: Tue, 18 Mar 2014 09:53:59 +0000
Subject: [PATCH] Clever (but not super awesome) way to handle mutliple FS (dof
 type offset)

---
 FunctionSpace/FunctionSpace.cpp | 25 +++++++++++++++++++++++--
 FunctionSpace/FunctionSpace.h   |  7 ++++---
 2 files changed, 27 insertions(+), 5 deletions(-)

diff --git a/FunctionSpace/FunctionSpace.cpp b/FunctionSpace/FunctionSpace.cpp
index de6c25173c..4089a3eac8 100644
--- a/FunctionSpace/FunctionSpace.cpp
+++ b/FunctionSpace/FunctionSpace.cpp
@@ -13,8 +13,6 @@ const size_t FunctionSpace::nGeoType = 9;
 size_t FunctionSpace::nxtOffset = 0;
 
 FunctionSpace::FunctionSpace(void){
-  offset     = nxtOffset;
-  nxtOffset += 21;
 }
 
 FunctionSpace::~FunctionSpace(void){
@@ -24,6 +22,9 @@ FunctionSpace::~FunctionSpace(void){
 }
 
 void FunctionSpace::build(const GroupOfElement& goe, string family){
+  // Save Dof type offset //
+  offset = nxtOffset;
+
   // Save GroupOfElement & Mesh //
   this->goe  = &goe;
   this->mesh = &(goe.getMesh());
@@ -79,6 +80,10 @@ void FunctionSpace::build(const GroupOfElement& goe, string family){
 
   // Build Dof //
   buildDof();
+
+  // Find next next offset //
+  size_t maxType = findMaxType();
+  nxtOffset += maxType + 1;
 }
 
 void FunctionSpace::buildDof(void){
@@ -98,6 +103,22 @@ void FunctionSpace::buildDof(void){
   }
 }
 
+size_t FunctionSpace::findMaxType(void){
+  // Maximum type //
+  size_t maxType = 0;
+
+  // Iterate for dof //
+  const set<Dof>::iterator end = dof.end();
+        set<Dof>::iterator it  = dof.begin();
+
+  for(; it != end; it++)
+    // If this type is bigger, it becomes the new 'maxType'
+    if(it->getType() > maxType)
+      maxType = it->getType();
+
+  return maxType;
+}
+
 vector<Dof> FunctionSpace::getUnorderedKeys(const MElement& elem) const{
   // Const_Cast //
   MElement& element = const_cast<MElement&>(elem);
diff --git a/FunctionSpace/FunctionSpace.h b/FunctionSpace/FunctionSpace.h
index 470f0f6c92..8053238ba4 100644
--- a/FunctionSpace/FunctionSpace.h
+++ b/FunctionSpace/FunctionSpace.h
@@ -30,7 +30,7 @@ class GroupOfElement;
 
 class FunctionSpace{
  protected:
-  // Number of possible geomtrical topologies //
+  // Number of possible geomtrical topologies & Dof Type offset //
   static const size_t nGeoType;
   static size_t nxtOffset;
 
@@ -79,8 +79,9 @@ class FunctionSpace{
  protected:
   FunctionSpace(void);
 
-  void build(const GroupOfElement& goe, std::string family);
-  void buildDof(void);
+  void   build(const GroupOfElement& goe, std::string family);
+  void   buildDof(void);
+  size_t findMaxType(void);
 
   std::vector<Dof> getUnorderedKeys(const MElement& element) const;
 };
-- 
GitLab