diff --git a/Mesh/ThinLayer.cpp b/Mesh/ThinLayer.cpp
index 8b6749a692db01cb684f23ff064ec53c4339c395..c6f7939b03977d335ce45777b3cb1282384169c7 100644
--- a/Mesh/ThinLayer.cpp
+++ b/Mesh/ThinLayer.cpp
@@ -1,529 +1,608 @@
-/*
- * ThinLayer.cpp
- *
- *  Created on: Oct 13, 2014
- *      Author: nicolas
- */
+// Gmsh - Copyright (C) 1997-2015 C. Geuzaine, J.-F. Remacle
+//
+// See the LICENSE.txt file for license information. Please report all
+// bugs and problems to the public mailing list <gmsh@geuz.org>.
+//
+// Author: Nicolas Kowalski
 
 #include "ThinLayer.h"
 #include "GModel.h"
 #include "robustPredicates.h"
 #include "GRegion.h"
 
+std::map<MVertex*,std::vector<MTetrahedron*> > ThinLayer::VertexToTets;
+std::map<MTetrahedron*,MTet4*> ThinLayer::TetToTet4;
+std::map<MVertex*,std::vector<CorrespVertices*> > ThinLayer::VertexToCorresp;
+std::vector<std::vector<CorrespVertices*> > ThinLayer::vecOfThinSheets;
+const double ThinLayer::epsilon = 0.00001;
+const double ThinLayer::angleMax = 0.9;
+const double ThinLayer::distP2PMax = 0.3;
 
 CorrespVertices::CorrespVertices(){}
 CorrespVertices::~CorrespVertices(){}
 void CorrespVertices::setStartPoint(MVertex* v){
-	this->StartPoint = v;
+  this->StartPoint = v;
 }
 void CorrespVertices::setEndPoint(SPoint3 p){
-	this->EndPoint = p;
+  this->EndPoint = p;
 }
 void CorrespVertices::setStartNormal(SVector3 v){
-	this->StartNormal = v;
+  this->StartNormal = v;
 }
 void CorrespVertices::setEndNormal(SVector3 v){
-	this->EndNormal = v;
+  this->EndNormal = v;
 }
 void CorrespVertices::setEndTriangle(faceXtet f){
-	this->EndTriangle = f;
+  this->EndTriangle = f;
 }
 void CorrespVertices::setdistP2P(double d){
-	this->distP2P = d;
+  this->distP2P = d;
 }
 void CorrespVertices::setangleProd(double a){
-	this->angleProd = a;
+  this->angleProd = a;
 }
 void CorrespVertices::setActive(bool b){
-	this->Active = b;
+  this->Active = b;
 }
 void CorrespVertices::setEndTriangleActive(bool b){
-	this->EndTriangleActive = b;
+  this->EndTriangleActive = b;
 }
 void CorrespVertices::setIsMaster(bool b){
-	this->IsMaster = b;
+  this->IsMaster = b;
 }
 void CorrespVertices::setTagMaster(int i){
-	this->tagMaster = i;
+  this->tagMaster = i;
 }
 MVertex* CorrespVertices::getStartPoint(){
-	return StartPoint;
+  return StartPoint;
 }
 SPoint3 CorrespVertices::getEndPoint(){
-	return EndPoint;
+  return EndPoint;
 }
 SVector3 CorrespVertices::getStartNormal(){
-	return StartNormal;
+  return StartNormal;
 }
 SVector3 CorrespVertices::getEndNormal(){
-	return EndNormal;
+  return EndNormal;
 }
 faceXtet CorrespVertices::getEndTriangle(){
-	return EndTriangle;
+  return EndTriangle;
 }
 double CorrespVertices::getdistP2P(){
-	return distP2P;
+  return distP2P;
 }
 double CorrespVertices::getangleProd(){
-	return angleProd;
+  return angleProd;
 }
 bool CorrespVertices::getActive(){
-	return Active;
+  return Active;
 }
 bool CorrespVertices::getEndTriangleActive(){
-	return EndTriangleActive;
+  return EndTriangleActive;
 }
 bool CorrespVertices::getIsMaster(){
-	return IsMaster;
+  return IsMaster;
 }
 int CorrespVertices::getTagMaster(){
-	return tagMaster;
+  return tagMaster;
 }
 
-
-
 ThinLayer::ThinLayer(){}
 
 ThinLayer::~ThinLayer(){}
 
-void ThinLayer::perform(){
-	ThinLayer::fillVertexToTets();
-	ThinLayer::fillTetToTet4();
-	std::map<MVertex*,double> AllDist = ThinLayer::computeAllDistToOppSide();
-	ThinLayer::checkOppositeTriangles();
-	ThinLayer::fillvecOfThinSheets();
-	std::set<MVertex*> constr_vertices;
+void ThinLayer::perform()
+{
+  ThinLayer::fillVertexToTets();
+  ThinLayer::fillTetToTet4();
+  std::map<MVertex*,double> AllDist = ThinLayer::computeAllDistToOppSide();
+  ThinLayer::checkOppositeTriangles();
+  ThinLayer::fillvecOfThinSheets();
+  std::set<MVertex*> constr_vertices;
 }
 
-void ThinLayer::checkOppositeTriangles(){
-	//all endTriangle will be set to active or not
-	for (std::map<MVertex*,std::vector<CorrespVertices*> >::iterator it1 = VertexToCorresp.begin();it1 != VertexToCorresp.end();it1++){
-		MVertex* vertTmp = (*it1).first;
-		std::vector<CorrespVertices*> vecCorr = (*it1).second;
-		for (unsigned int i = 0;i < vecCorr.size();i++){
-			CorrespVertices* currentCorr = vecCorr[i];
-			faceXtet currentEndTri = currentCorr->getEndTriangle();
-			MVertex* endP0 = currentEndTri.v[0];
-			MVertex* endP1 = currentEndTri.v[1];
-			MVertex* endP2 = currentEndTri.v[2];
-			std::map<MVertex*,std::vector<CorrespVertices*> >::iterator it2 = VertexToCorresp.find(endP0);
-			std::map<MVertex*,std::vector<CorrespVertices*> >::iterator it3 = VertexToCorresp.find(endP1);
-			std::map<MVertex*,std::vector<CorrespVertices*> >::iterator it4 = VertexToCorresp.find(endP2);
-			(*it1).second[i]->setEndTriangleActive(false);
-			if (it2 != VertexToCorresp.end()){
-				if (it3 != VertexToCorresp.end()){
-					if (it4 != VertexToCorresp.end()){
-						if ((*it2).second[0]->getActive()){
-							if ((*it3).second[0]->getActive()){
-								if ((*it4).second[0]->getActive()){
-									(*it1).second[i]->setEndTriangleActive(true);
-								}
-							}
-						}
-					}
-				}
-			}
-		}
-	}
+void ThinLayer::checkOppositeTriangles()
+{
+  //all endTriangle will be set to active or not
+  for (std::map<MVertex*,std::vector<CorrespVertices*> >::iterator it1 =
+         VertexToCorresp.begin();it1 != VertexToCorresp.end();it1++){
+    std::vector<CorrespVertices*> vecCorr = (*it1).second;
+    for (unsigned int i = 0;i < vecCorr.size();i++){
+      CorrespVertices* currentCorr = vecCorr[i];
+      faceXtet currentEndTri = currentCorr->getEndTriangle();
+      MVertex* endP0 = currentEndTri.v[0];
+      MVertex* endP1 = currentEndTri.v[1];
+      MVertex* endP2 = currentEndTri.v[2];
+      std::map<MVertex*,std::vector<CorrespVertices*> >::iterator it2 =
+        VertexToCorresp.find(endP0);
+      std::map<MVertex*,std::vector<CorrespVertices*> >::iterator it3 =
+        VertexToCorresp.find(endP1);
+      std::map<MVertex*,std::vector<CorrespVertices*> >::iterator it4 =
+        VertexToCorresp.find(endP2);
+      (*it1).second[i]->setEndTriangleActive(false);
+      if (it2 != VertexToCorresp.end()){
+        if (it3 != VertexToCorresp.end()){
+          if (it4 != VertexToCorresp.end()){
+            if ((*it2).second[0]->getActive()){
+              if ((*it3).second[0]->getActive()){
+                if ((*it4).second[0]->getActive()){
+                  (*it1).second[i]->setEndTriangleActive(true);
+                }
+              }
+            }
+          }
+        }
+      }
+    }
+  }
 }
 
 void ThinLayer::fillvecOfThinSheets(){
-	for (std::map<MVertex*,std::vector<CorrespVertices*> >::iterator it1 = VertexToCorresp.begin();it1 != VertexToCorresp.end();it1++){
-		MVertex* vertTmp = (*it1).first;
-		std::vector<CorrespVertices*> vecCorr = (*it1).second;
-		for (unsigned int i = 0;i < vecCorr.size();i++){
-			CorrespVertices* currentCorr = vecCorr[i];
-			if ((currentCorr->getStartPoint()->onWhat()->dim() == 2) && (currentCorr->getActive()) && (currentCorr->getEndTriangleActive()) && (currentCorr->getTagMaster() == (-2))){
-				//Found the first node of a new master sheet
-				std::vector<CorrespVertices*> MasterSheet;
-				MasterSheet.clear();
-				(*it1).second[i]->setTagMaster(-1);
-				faceXtet faceEndSlave = (*it1).second[i]->getEndTriangle();
-				for (unsigned int j = 0;j < 3;j++){
-					std::map<MVertex*,std::vector<CorrespVertices*> >::iterator it2 = VertexToCorresp.find(faceEndSlave.v[j]);
-					if (it2 != VertexToCorresp.end()){
-						if (faceEndSlave.v[j]->onWhat()->dim() == 2){
-							(*it2).second[0]->setTagMaster((*it1).second[i]->getStartPoint()->onWhat()->tag());
-						}
-					}
-				}
-				MasterSheet.push_back((*it1).second[i]);
-				std::set<MVertex*> CurrentSheet;
-				CurrentSheet.clear();
-				CurrentSheet.insert((*it1).second[i]->getStartPoint());
-				while (CurrentSheet.size() != 0){
-					MVertex* VToDo = (*CurrentSheet.begin());
-					std::vector<MTetrahedron*> surroundingTet = VertexToTets[VToDo];
-					for (unsigned int j = 0;j < surroundingTet.size();j++){
-						for (unsigned int k = 0;k < surroundingTet[j]->getNumVertices();k++){
-							MVertex* ToInsertTmp = surroundingTet[j]->getVertex(k);
-							std::map<MVertex*,std::vector<CorrespVertices*> >::iterator it2 = VertexToCorresp.find(ToInsertTmp);
-							if (ToInsertTmp->onWhat()->tag() == VToDo->onWhat()->tag()){//TODO: OR that onwhat -> dim <, for edges
-								if (it2 != VertexToCorresp.end()){
-									CorrespVertices* correspToInsert = ((*it2).second)[0];
-									if ((correspToInsert->getStartPoint()->onWhat()->dim() == 2) && (correspToInsert->getActive()) && (correspToInsert->getEndTriangleActive()) && (correspToInsert->getTagMaster() == (-2))){
-										MasterSheet.push_back((*it2).second[0]);
-										(*it2).second[0]->setTagMaster(-1);
-										faceXtet faceEndSlave2 = (*it2).second[0]->getEndTriangle();
-										for (unsigned int j = 0;j < 3;j++){
-											std::map<MVertex*,std::vector<CorrespVertices*> >::iterator it3 = VertexToCorresp.find(faceEndSlave2.v[j]);
-											if (it3 != VertexToCorresp.end()){
-												if (faceEndSlave2.v[j]->onWhat()->dim() == 2){
-													(*it3).second[0]->setTagMaster((*it2).second[i]->getStartPoint()->onWhat()->tag());
-												}
-											}
-										}
-										CurrentSheet.insert(ToInsertTmp);
-									}
-								}
-							}
-						}
-					}
-					CurrentSheet.erase(VToDo);
-				}
-				vecOfThinSheets.push_back(MasterSheet);
-			}
-		}
-	}
-}
-std::map<MVertex*,double> ThinLayer::computeAllDistToOppSide(){
-	std::map<MVertex*,double> AllDistToOppSide;
-	GModel *m = GModel::current();
-//	std::vector<MElement*> crackElements;
-	std::set<MVertex*> BoundaryVertices;
-
-
+  for (std::map<MVertex*,std::vector<CorrespVertices*> >::iterator it1 =
+         VertexToCorresp.begin();it1 != VertexToCorresp.end();it1++){
+    std::vector<CorrespVertices*> vecCorr = (*it1).second;
+    for (unsigned int i = 0;i < vecCorr.size();i++){
+      CorrespVertices* currentCorr = vecCorr[i];
+      if ((currentCorr->getStartPoint()->onWhat()->dim() == 2) &&
+          (currentCorr->getActive()) && (currentCorr->getEndTriangleActive()) &&
+          (currentCorr->getTagMaster() == (-2))){
+        //Found the first node of a new master sheet
+        std::vector<CorrespVertices*> MasterSheet;
+        MasterSheet.clear();
+        (*it1).second[i]->setTagMaster(-1);
+        faceXtet faceEndSlave = (*it1).second[i]->getEndTriangle();
+        for (unsigned int j = 0;j < 3;j++){
+          std::map<MVertex*,std::vector<CorrespVertices*> >::iterator it2 =
+            VertexToCorresp.find(faceEndSlave.v[j]);
+          if (it2 != VertexToCorresp.end()){
+            if (faceEndSlave.v[j]->onWhat()->dim() == 2){
+              (*it2).second[0]->setTagMaster
+                ((*it1).second[i]->getStartPoint()->onWhat()->tag());
+            }
+          }
+        }
+        MasterSheet.push_back((*it1).second[i]);
+        std::set<MVertex*> CurrentSheet;
+        CurrentSheet.clear();
+        CurrentSheet.insert((*it1).second[i]->getStartPoint());
+        while (CurrentSheet.size() != 0){
+          MVertex* VToDo = (*CurrentSheet.begin());
+          std::vector<MTetrahedron*> surroundingTet = VertexToTets[VToDo];
+          for (unsigned int j = 0;j < surroundingTet.size();j++){
+            for (unsigned int k = 0;k < surroundingTet[j]->getNumVertices();k++){
+              MVertex* ToInsertTmp = surroundingTet[j]->getVertex(k);
+              std::map<MVertex*,std::vector<CorrespVertices*> >::iterator it2 =
+                VertexToCorresp.find(ToInsertTmp);
+              if (ToInsertTmp->onWhat()->tag() == VToDo->onWhat()->tag()){
+                //TODO: OR that onwhat -> dim <, for edges
+                if (it2 != VertexToCorresp.end()){
+                  CorrespVertices* correspToInsert = ((*it2).second)[0];
+                  if ((correspToInsert->getStartPoint()->onWhat()->dim() == 2) &&
+                      (correspToInsert->getActive()) &&
+                      (correspToInsert->getEndTriangleActive()) &&
+                      (correspToInsert->getTagMaster() == (-2))){
+                    MasterSheet.push_back((*it2).second[0]);
+                    (*it2).second[0]->setTagMaster(-1);
+                    faceXtet faceEndSlave2 = (*it2).second[0]->getEndTriangle();
+                    for (unsigned int j = 0;j < 3;j++){
+                      std::map<MVertex*,std::vector<CorrespVertices*> >::iterator it3 =
+                        VertexToCorresp.find(faceEndSlave2.v[j]);
+                      if (it3 != VertexToCorresp.end()){
+                        if (faceEndSlave2.v[j]->onWhat()->dim() == 2){
+                          (*it3).second[0]->setTagMaster
+                            ((*it2).second[i]->getStartPoint()->onWhat()->tag());
+                        }
+                      }
+                    }
+                    CurrentSheet.insert(ToInsertTmp);
+                  }
+                }
+              }
+            }
+          }
+          CurrentSheet.erase(VToDo);
+        }
+        vecOfThinSheets.push_back(MasterSheet);
+      }
+    }
+  }
+}
 
-	for (GModel::riter itr= m->firstRegion();itr != m->lastRegion();itr++){
-		GRegion* rTmp = (*itr);
-		for(unsigned int i = 0; i < rTmp->tetrahedra.size(); i++){
-			MTet4* tet4Tmp = TetToTet4[rTmp->tetrahedra[i]];
-			for (unsigned int j = 0;j < 4;j++){
-				if (tet4Tmp->getNeigh(j) == 0){
-					//find the 4th point,and fill the two vector of the boundary triangle
-					faceXtet fxtTmp(tet4Tmp,j);
-					for (int k = 0;k < 3;k++){
-						MVertex* toTest = fxtTmp.v[k];
-						if (toTest->onWhat()->dim() == 2){
-							if(BoundaryVertices.find(toTest) == BoundaryVertices.end()){
-								BoundaryVertices.insert(toTest);
-							}
-						}
-					}
-					//			crackElements.push_back(rTmp->getMeshElement(j));
-				}
-			}
-		}
-	}
-	for(std::set<MVertex*>::iterator it = BoundaryVertices.begin(); it != BoundaryVertices.end(); it++){
-		MVertex* toCompute = (*it);
-		double resultTmp = computeDistToOppSide(toCompute);
-		AllDistToOppSide[toCompute] = resultTmp;
-	}
+std::map<MVertex*,double> ThinLayer::computeAllDistToOppSide()
+{
+  std::map<MVertex*,double> AllDistToOppSide;
+  GModel *m = GModel::current();
+  // std::vector<MElement*> crackElements;
+  std::set<MVertex*> BoundaryVertices;
 
+  for (GModel::riter itr= m->firstRegion();itr != m->lastRegion();itr++){
+    GRegion* rTmp = (*itr);
+    for(unsigned int i = 0; i < rTmp->tetrahedra.size(); i++){
+      MTet4* tet4Tmp = TetToTet4[rTmp->tetrahedra[i]];
+      for (unsigned int j = 0;j < 4;j++){
+        if (tet4Tmp->getNeigh(j) == 0){
+          //find the 4th point,and fill the two vector of the boundary triangle
+          faceXtet fxtTmp(tet4Tmp,j);
+          for (int k = 0;k < 3;k++){
+            MVertex* toTest = fxtTmp.v[k];
+            if (toTest->onWhat()->dim() == 2){
+              if(BoundaryVertices.find(toTest) == BoundaryVertices.end()){
+                BoundaryVertices.insert(toTest);
+              }
+            }
+          }
+          // crackElements.push_back(rTmp->getMeshElement(j));
+        }
+      }
+    }
+  }
+  for(std::set<MVertex*>::iterator it = BoundaryVertices.begin();
+      it != BoundaryVertices.end(); it++){
+    MVertex* toCompute = (*it);
+    double resultTmp = computeDistToOppSide(toCompute);
+    AllDistToOppSide[toCompute] = resultTmp;
+  }
 
-	return AllDistToOppSide;
+  return AllDistToOppSide;
 }
 
-double ThinLayer::computeDistToOppSide(MVertex* v){
-	double DistToOppSide;
-	//We assume v is on the boundary
-	//First we need to get the internal normal
-	SVector3 InteriorNormal = ThinLayer::computeInteriorNormal(v);
-	//Then we find the first triangle
-	MTet4* FirstTet = ThinLayer::getTetFromPoint(v,InteriorNormal);
-	MTet4* CurrentTet = FirstTet;
-	MTet4* PastTet = FirstTet;
-	SPoint3 CurrentPos = SPoint3(v->x(),v->y(),v->z());
-	SPoint3 LastPos = CurrentPos;
-	int* CurrentTri = 0;
-	CorrespVertices CVTemp;
-	CVTemp.setStartPoint(v);
-	CVTemp.setStartNormal(InteriorNormal);
-	FindNewPoint((&CurrentPos),CurrentTri,CurrentTet,InteriorNormal);
-	faceXtet fxtCV(CurrentTet,(*CurrentTri));
-//	while(CurrentTet->getNeigh((*CurrentTri)) != 0){
-	while(CurrentTet != 0){
-		PastTet = CurrentTet;
-		faceXtet fxtCVtmp(PastTet,(*CurrentTri));
-		FindNewPoint((&CurrentPos),CurrentTri,CurrentTet,InteriorNormal);
-		CurrentTet = CurrentTet->getNeigh((*CurrentTri));
-		DistToOppSide += CurrentPos.distance(LastPos);
-		LastPos = CurrentPos;
-	}
-	CVTemp.setEndPoint(LastPos);
-	CVTemp.setEndTriangle(fxtCV);
-	SVector3 EndDir1(fxtCV.v[1]->x() - fxtCV.v[0]->x(),fxtCV.v[1]->y() - fxtCV.v[0]->y(),fxtCV.v[1]->z() - fxtCV.v[0]->z());
-	SVector3 EndDir2(fxtCV.v[2]->x() - fxtCV.v[0]->x(),fxtCV.v[2]->y() - fxtCV.v[0]->y(),fxtCV.v[2]->z() - fxtCV.v[0]->z());
-	SVector3 EndNormal(EndDir1.y() * EndDir2.z() - EndDir1.z() * EndDir2.y(),EndDir1.z() * EndDir2.x() - EndDir1.x() * EndDir2.z(),EndDir1.x() * EndDir2.y() - EndDir1.y() * EndDir2.x());
-	EndNormal.normalize();
-	CVTemp.setEndNormal(EndNormal);
-	CVTemp.setangleProd(fabs(CVTemp.getStartNormal().x() * CVTemp.getEndNormal().x() + CVTemp.getStartNormal().y() * CVTemp.getEndNormal().y() + CVTemp.getStartNormal().z() * CVTemp.getEndNormal().z()));
-	CVTemp.setdistP2P(DistToOppSide);
-	if ((CVTemp.getangleProd() > angleMax) &&(CVTemp.getdistP2P() < distP2PMax)){
-		CVTemp.setActive(true);
-	}
-	else{
-		CVTemp.setActive(false);
-	}
-	CVTemp.setTagMaster(-2);
-	VertexToCorresp[v].push_back(&CVTemp);
-	return DistToOppSide;
+double ThinLayer::computeDistToOppSide(MVertex* v)
+{
+  double DistToOppSide = 0.;
+  //We assume v is on the boundary
+  //First we need to get the internal normal
+  SVector3 InteriorNormal = ThinLayer::computeInteriorNormal(v);
+  //Then we find the first triangle
+  MTet4* FirstTet = ThinLayer::getTetFromPoint(v,InteriorNormal);
+  MTet4* CurrentTet = FirstTet;
+  MTet4* PastTet = FirstTet;
+  SPoint3 CurrentPos = SPoint3(v->x(),v->y(),v->z());
+  SPoint3 LastPos = CurrentPos;
+  int* CurrentTri = 0;
+  CorrespVertices CVTemp;
+  CVTemp.setStartPoint(v);
+  CVTemp.setStartNormal(InteriorNormal);
+  FindNewPoint((&CurrentPos),CurrentTri,CurrentTet,InteriorNormal);
+  faceXtet fxtCV(CurrentTet,(*CurrentTri));
+  //	while(CurrentTet->getNeigh((*CurrentTri)) != 0){
+  while(CurrentTet != 0){
+    PastTet = CurrentTet;
+    faceXtet fxtCVtmp(PastTet,(*CurrentTri));
+    FindNewPoint((&CurrentPos),CurrentTri,CurrentTet,InteriorNormal);
+    CurrentTet = CurrentTet->getNeigh((*CurrentTri));
+    DistToOppSide += CurrentPos.distance(LastPos);
+    LastPos = CurrentPos;
+  }
+  CVTemp.setEndPoint(LastPos);
+  CVTemp.setEndTriangle(fxtCV);
+  SVector3 EndDir1(fxtCV.v[1]->x() - fxtCV.v[0]->x(),fxtCV.v[1]->y() -
+                   fxtCV.v[0]->y(),fxtCV.v[1]->z() - fxtCV.v[0]->z());
+  SVector3 EndDir2(fxtCV.v[2]->x() - fxtCV.v[0]->x(),fxtCV.v[2]->y() -
+                   fxtCV.v[0]->y(),fxtCV.v[2]->z() - fxtCV.v[0]->z());
+  SVector3 EndNormal(EndDir1.y() * EndDir2.z() - EndDir1.z() * EndDir2.y(),
+                     EndDir1.z() * EndDir2.x() - EndDir1.x() * EndDir2.z(),
+                     EndDir1.x() * EndDir2.y() - EndDir1.y() * EndDir2.x());
+  EndNormal.normalize();
+  CVTemp.setEndNormal(EndNormal);
+  CVTemp.setangleProd(fabs(CVTemp.getStartNormal().x() * CVTemp.getEndNormal().x() +
+                           CVTemp.getStartNormal().y() * CVTemp.getEndNormal().y() +
+                           CVTemp.getStartNormal().z() * CVTemp.getEndNormal().z()));
+  CVTemp.setdistP2P(DistToOppSide);
+  if ((CVTemp.getangleProd() > angleMax) &&(CVTemp.getdistP2P() < distP2PMax)){
+    CVTemp.setActive(true);
+  }
+  else{
+    CVTemp.setActive(false);
+  }
+  CVTemp.setTagMaster(-2);
+  VertexToCorresp[v].push_back(&CVTemp);
+  return DistToOppSide;
 }
 
-SVector3 ThinLayer::computeInteriorNormal(MVertex* v){
-	SPoint3 InteriorNormal(0.0,0.0,0.0);
-	std::vector<MTetrahedron*> currentVecTet = VertexToTets[v];
-	std::vector<SPoint3> vecInteriorNodes;
-	std::vector<SPoint3> vecFirstDir;
-	std::vector<SPoint3> vecSecondDir;
-	for (unsigned int i = 0;i < currentVecTet.size();i++){
-		MTet4* tet4Tmp = TetToTet4[currentVecTet[i]];
-		for (int j = 0;j < 4 ; j++){
-			if (tet4Tmp->getNeigh(j) == 0){
-				//find the 4th point,and fill the two vector of the boundary triangle
-				faceXtet fxtTmp(tet4Tmp,j);
-				for (int k = 0;k < 4;k++){
-					bool foundInteriorPoint = true;
-					for (int l = 0;l < 3;l++){
-						if (tet4Tmp->tet()->getVertex(k) == fxtTmp.v[l]){
-							foundInteriorPoint = false;
-						}
-					}
-					if (foundInteriorPoint){
-						SPoint3 pointTmp(tet4Tmp->tet()->getVertex(k)->x(),tet4Tmp->tet()->getVertex(k)->y(),tet4Tmp->tet()->getVertex(k)->z());
-						vecInteriorNodes.push_back(pointTmp);
-					}
-				}
-				SPoint3 pointTmp1(fxtTmp.v[1]->x() - fxtTmp.v[0]->x(),fxtTmp.v[1]->y() - fxtTmp.v[0]->y(),fxtTmp.v[1]->z() - fxtTmp.v[0]->z());
-				SPoint3 pointTmp2(fxtTmp.v[2]->x() - fxtTmp.v[0]->x(),fxtTmp.v[2]->y() - fxtTmp.v[0]->y(),fxtTmp.v[2]->z() - fxtTmp.v[0]->z());
-				vecFirstDir.push_back(pointTmp1);
-				vecSecondDir.push_back(pointTmp2);
-			}
-		}
-	}
-	//at this point we have all the info necessary.
-	SPoint3 pointInteriorAverage(0.0,0.0,0.0);
-	for (unsigned int i = 0;i < vecInteriorNodes.size();i++){
-		pointInteriorAverage += SPoint3(vecInteriorNodes[i].x(),vecInteriorNodes[i].y(),vecInteriorNodes[i].z());
-//		pointInteriorAverage.x() += vecInteriorNodes[i].x();
-//		pointInteriorAverage.y() += vecInteriorNodes[i].y();
-//		pointInteriorAverage.z() += vecInteriorNodes[i].z();
-	}
-	pointInteriorAverage = SPoint3(pointInteriorAverage.x() / (double(vecInteriorNodes.size())),pointInteriorAverage.y() / (double(vecInteriorNodes.size())),pointInteriorAverage.z() / (double(vecInteriorNodes.size())));
-//	pointInteriorAverage.x() = pointInteriorAverage.x() / (double(vecInteriorNodes.size()));
-//	pointInteriorAverage.y() = pointInteriorAverage.y() / (double(vecInteriorNodes.size()));
-//	pointInteriorAverage.z() = pointInteriorAverage.z() / (double(vecInteriorNodes.size()));
-	SPoint3 dirInteriorAverage(pointInteriorAverage.x() - v->x(),pointInteriorAverage.y() - v->y(),pointInteriorAverage.z() - v->z());
-	double norme = sqrt(dirInteriorAverage.x() * dirInteriorAverage.x() + dirInteriorAverage.y() * dirInteriorAverage.y() + dirInteriorAverage.z() * dirInteriorAverage.z());
-	dirInteriorAverage = SPoint3(dirInteriorAverage.x() / norme,dirInteriorAverage.y() / norme,dirInteriorAverage.z() / norme);
-//	dirInteriorAverage.x() = dirInteriorAverage.x() / norme;
-//	dirInteriorAverage.y() = dirInteriorAverage.y() / norme;
-//	dirInteriorAverage.z() = dirInteriorAverage.z() / norme;
-	std::vector<SPoint3> vecOrthogDir;
-	for(unsigned int i = 0;i < vecFirstDir.size();i++){
-		SPoint3 pointTmp(vecFirstDir[i].y() * vecSecondDir[i].z() - vecFirstDir[i].z() * vecSecondDir[i].y(),vecFirstDir[i].z() * vecSecondDir[i].x() - vecFirstDir[i].x() * vecSecondDir[i].z(),vecFirstDir[i].x() * vecSecondDir[i].y() - vecFirstDir[i].y() * vecSecondDir[i].x());
-		vecOrthogDir.push_back(pointTmp);
-	}
-	for(unsigned int i = 0;i < vecOrthogDir.size();i++){
-		double prodScalTmp = vecOrthogDir[i].x() * dirInteriorAverage.x() + vecOrthogDir[i].y() * dirInteriorAverage.y() + vecOrthogDir[i].z() * dirInteriorAverage.z();
-		if (prodScalTmp < 0.0){
-			vecOrthogDir[i] = SPoint3(- vecOrthogDir[i].x(),- vecOrthogDir[i].y(),- vecOrthogDir[i].z());
-//			vecOrthogDir[i].x() = - vecOrthogDir[i].x();
-//			vecOrthogDir[i].y() = - vecOrthogDir[i].y();
-//			vecOrthogDir[i].z() = - vecOrthogDir[i].z();
-		}
-		double normeTmp = sqrt(vecOrthogDir[i].x() * vecOrthogDir[i].x() + vecOrthogDir[i].y() * vecOrthogDir[i].y() + vecOrthogDir[i].z() * vecOrthogDir[i].z());
-		vecOrthogDir[i] = SPoint3(vecOrthogDir[i].x() / normeTmp,vecOrthogDir[i].y() / normeTmp,vecOrthogDir[i].z() / normeTmp);
-//		vecOrthogDir[i].x() = vecOrthogDir[i].x() / normeTmp;
-//		vecOrthogDir[i].y() = vecOrthogDir[i].y() / normeTmp;
-//		vecOrthogDir[i].z() = vecOrthogDir[i].z() / normeTmp;
-		InteriorNormal += SPoint3(vecOrthogDir[i].x(),vecOrthogDir[i].y(),vecOrthogDir[i].z());
-//		InteriorNormal.x() += vecOrthogDir[i].x();
-//		InteriorNormal.y() += vecOrthogDir[i].y();
-//		InteriorNormal.z() += vecOrthogDir[i].z();
-	}
-	norme = sqrt(InteriorNormal.x() * InteriorNormal.x() + InteriorNormal.y() * InteriorNormal.y() + InteriorNormal.z() * InteriorNormal.z());
-	InteriorNormal = SPoint3(InteriorNormal.x() / norme,InteriorNormal.y() / norme,InteriorNormal.z() / norme);
-//	InteriorNormal.x() = InteriorNormal.x() / norme;
-//	InteriorNormal.y() = InteriorNormal.y() / norme;
-//	InteriorNormal.z() = InteriorNormal.z() / norme;
-	return InteriorNormal;
+SVector3 ThinLayer::computeInteriorNormal(MVertex* v)
+{
+  SPoint3 InteriorNormal(0.0,0.0,0.0);
+  std::vector<MTetrahedron*> currentVecTet = VertexToTets[v];
+  std::vector<SPoint3> vecInteriorNodes;
+  std::vector<SPoint3> vecFirstDir;
+  std::vector<SPoint3> vecSecondDir;
+  for (unsigned int i = 0;i < currentVecTet.size();i++){
+    MTet4* tet4Tmp = TetToTet4[currentVecTet[i]];
+    for (int j = 0;j < 4 ; j++){
+      if (tet4Tmp->getNeigh(j) == 0){
+        //find the 4th point,and fill the two vector of the boundary triangle
+        faceXtet fxtTmp(tet4Tmp,j);
+        for (int k = 0;k < 4;k++){
+          bool foundInteriorPoint = true;
+          for (int l = 0;l < 3;l++){
+            if (tet4Tmp->tet()->getVertex(k) == fxtTmp.v[l]){
+              foundInteriorPoint = false;
+            }
+          }
+          if (foundInteriorPoint){
+            SPoint3 pointTmp(tet4Tmp->tet()->getVertex(k)->x(),
+                             tet4Tmp->tet()->getVertex(k)->y(),
+                             tet4Tmp->tet()->getVertex(k)->z());
+            vecInteriorNodes.push_back(pointTmp);
+          }
+        }
+        SPoint3 pointTmp1(fxtTmp.v[1]->x() - fxtTmp.v[0]->x(),fxtTmp.v[1]->y() -
+                          fxtTmp.v[0]->y(),fxtTmp.v[1]->z() - fxtTmp.v[0]->z());
+        SPoint3 pointTmp2(fxtTmp.v[2]->x() - fxtTmp.v[0]->x(),fxtTmp.v[2]->y() -
+                          fxtTmp.v[0]->y(),fxtTmp.v[2]->z() - fxtTmp.v[0]->z());
+        vecFirstDir.push_back(pointTmp1);
+        vecSecondDir.push_back(pointTmp2);
+      }
+    }
+  }
+  //at this point we have all the info necessary.
+  SPoint3 pointInteriorAverage(0.0,0.0,0.0);
+  for (unsigned int i = 0;i < vecInteriorNodes.size();i++){
+    pointInteriorAverage += SPoint3(vecInteriorNodes[i].x(),
+                                    vecInteriorNodes[i].y(),
+                                    vecInteriorNodes[i].z());
+    // pointInteriorAverage.x() += vecInteriorNodes[i].x();
+    // pointInteriorAverage.y() += vecInteriorNodes[i].y();
+    // pointInteriorAverage.z() += vecInteriorNodes[i].z();
+  }
+  pointInteriorAverage = SPoint3(pointInteriorAverage.x() /
+                                 (double(vecInteriorNodes.size())),
+                                 pointInteriorAverage.y() /
+                                 (double(vecInteriorNodes.size())),
+                                 pointInteriorAverage.z() /
+                                 (double(vecInteriorNodes.size())));
+  // pointInteriorAverage.x() = pointInteriorAverage.x() / (double(vecInteriorNodes.size()));
+  // pointInteriorAverage.y() = pointInteriorAverage.y() / (double(vecInteriorNodes.size()));
+  // pointInteriorAverage.z() = pointInteriorAverage.z() / (double(vecInteriorNodes.size()));
+  SPoint3 dirInteriorAverage(pointInteriorAverage.x() - v->x(),
+                             pointInteriorAverage.y() - v->y(),
+                             pointInteriorAverage.z() - v->z());
+  double norme = sqrt(dirInteriorAverage.x() * dirInteriorAverage.x() +
+                      dirInteriorAverage.y() * dirInteriorAverage.y() +
+                      dirInteriorAverage.z() * dirInteriorAverage.z());
+  dirInteriorAverage = SPoint3(dirInteriorAverage.x() / norme,
+                               dirInteriorAverage.y() / norme,
+                               dirInteriorAverage.z() / norme);
+  // dirInteriorAverage.x() = dirInteriorAverage.x() / norme;
+  // dirInteriorAverage.y() = dirInteriorAverage.y() / norme;
+  // dirInteriorAverage.z() = dirInteriorAverage.z() / norme;
+  std::vector<SPoint3> vecOrthogDir;
+  for(unsigned int i = 0;i < vecFirstDir.size();i++){
+    SPoint3 pointTmp(vecFirstDir[i].y() * vecSecondDir[i].z() -
+                     vecFirstDir[i].z() * vecSecondDir[i].y(),
+                     vecFirstDir[i].z() * vecSecondDir[i].x() -
+                     vecFirstDir[i].x() * vecSecondDir[i].z(),
+                     vecFirstDir[i].x() * vecSecondDir[i].y() -
+                     vecFirstDir[i].y() * vecSecondDir[i].x());
+    vecOrthogDir.push_back(pointTmp);
+  }
+  for(unsigned int i = 0;i < vecOrthogDir.size();i++){
+    double prodScalTmp = vecOrthogDir[i].x() * dirInteriorAverage.x() +
+      vecOrthogDir[i].y() * dirInteriorAverage.y() +
+      vecOrthogDir[i].z() * dirInteriorAverage.z();
+    if (prodScalTmp < 0.0){
+      vecOrthogDir[i] = SPoint3(- vecOrthogDir[i].x(),- vecOrthogDir[i].y(),
+                                - vecOrthogDir[i].z());
+      // vecOrthogDir[i].x() = - vecOrthogDir[i].x();
+      // vecOrthogDir[i].y() = - vecOrthogDir[i].y();
+      // vecOrthogDir[i].z() = - vecOrthogDir[i].z();
+    }
+    double normeTmp = sqrt(vecOrthogDir[i].x() * vecOrthogDir[i].x() +
+                           vecOrthogDir[i].y() * vecOrthogDir[i].y() +
+                           vecOrthogDir[i].z() * vecOrthogDir[i].z());
+    vecOrthogDir[i] = SPoint3(vecOrthogDir[i].x() / normeTmp,
+                              vecOrthogDir[i].y() / normeTmp,
+                              vecOrthogDir[i].z() / normeTmp);
+    // vecOrthogDir[i].x() = vecOrthogDir[i].x() / normeTmp;
+    // vecOrthogDir[i].y() = vecOrthogDir[i].y() / normeTmp;
+    // vecOrthogDir[i].z() = vecOrthogDir[i].z() / normeTmp;
+    InteriorNormal += SPoint3(vecOrthogDir[i].x(),vecOrthogDir[i].y(),vecOrthogDir[i].z());
+    // InteriorNormal.x() += vecOrthogDir[i].x();
+    // InteriorNormal.y() += vecOrthogDir[i].y();
+    // InteriorNormal.z() += vecOrthogDir[i].z();
+  }
+  norme = sqrt(InteriorNormal.x() * InteriorNormal.x() +
+               InteriorNormal.y() * InteriorNormal.y() +
+               InteriorNormal.z() * InteriorNormal.z());
+  InteriorNormal = SPoint3(InteriorNormal.x() / norme,
+                           InteriorNormal.y() / norme,
+                           InteriorNormal.z() / norme);
+  // InteriorNormal.x() = InteriorNormal.x() / norme;
+  // InteriorNormal.y() = InteriorNormal.y() / norme;
+  // InteriorNormal.z() = InteriorNormal.z() / norme;
+  return InteriorNormal;
 }
 
-MTet4* ThinLayer::getTetFromPoint(MVertex* v, SVector3 InteriorNormal){
-	MTet4* TetToGet = 0;
-	std::vector<MTetrahedron*> currentVecTet = VertexToTets[v];
-	for (unsigned int i = 0;i < currentVecTet.size();i++){
-		std::vector<SVector3> vecDir;
-		for (int j = 0;j < 4 ; j++){
-			if (currentVecTet[i]->getVertex(j) != v){
-				SVector3 DirTmp(currentVecTet[i]->getVertex(j)->x() - v->x(),currentVecTet[i]->getVertex(j)->y() - v->y(),currentVecTet[i]->getVertex(j)->z() - v->z());
-				vecDir.push_back(DirTmp);
-			}
-		}
-		bool IsPositiv = ThinLayer::IsPositivOrientation(vecDir[0],vecDir[1],vecDir[2]);
-		if (!IsPositiv){
-			SVector3 DirTmp1 = vecDir[1];
-			SVector3 DirTmp2 = vecDir[0];
-			SVector3 DirTmp3 = vecDir[2];
-			vecDir.clear();
-			vecDir.push_back(DirTmp1);
-			vecDir.push_back(DirTmp2);
-			vecDir.push_back(DirTmp3);
-		}
-		bool isPositiv1 = ThinLayer::IsPositivOrientation(vecDir[0],vecDir[1],InteriorNormal);
-		bool isPositiv2 = ThinLayer::IsPositivOrientation(vecDir[1],vecDir[2],InteriorNormal);
-		bool isPositiv3 = ThinLayer::IsPositivOrientation(vecDir[2],vecDir[0],InteriorNormal);
-		if (isPositiv1){
-			if (isPositiv2){
-				if (isPositiv3){
-					TetToGet = TetToTet4[currentVecTet[i]];
-				}
-			}
-		}
-	}
-	return TetToGet;
+MTet4* ThinLayer::getTetFromPoint(MVertex* v, SVector3 InteriorNormal)
+{
+  MTet4* TetToGet = 0;
+  std::vector<MTetrahedron*> currentVecTet = VertexToTets[v];
+  for (unsigned int i = 0;i < currentVecTet.size();i++){
+    std::vector<SVector3> vecDir;
+    for (int j = 0;j < 4 ; j++){
+      if (currentVecTet[i]->getVertex(j) != v){
+        SVector3 DirTmp(currentVecTet[i]->getVertex(j)->x() - v->x(),
+                        currentVecTet[i]->getVertex(j)->y() - v->y(),
+                        currentVecTet[i]->getVertex(j)->z() - v->z());
+        vecDir.push_back(DirTmp);
+      }
+    }
+    bool IsPositiv = ThinLayer::IsPositivOrientation(vecDir[0],vecDir[1],vecDir[2]);
+    if (!IsPositiv){
+      SVector3 DirTmp1 = vecDir[1];
+      SVector3 DirTmp2 = vecDir[0];
+      SVector3 DirTmp3 = vecDir[2];
+      vecDir.clear();
+      vecDir.push_back(DirTmp1);
+      vecDir.push_back(DirTmp2);
+      vecDir.push_back(DirTmp3);
+    }
+    bool isPositiv1 = ThinLayer::IsPositivOrientation(vecDir[0],vecDir[1],InteriorNormal);
+    bool isPositiv2 = ThinLayer::IsPositivOrientation(vecDir[1],vecDir[2],InteriorNormal);
+    bool isPositiv3 = ThinLayer::IsPositivOrientation(vecDir[2],vecDir[0],InteriorNormal);
+    if (isPositiv1){
+      if (isPositiv2){
+        if (isPositiv3){
+          TetToGet = TetToTet4[currentVecTet[i]];
+        }
+      }
+    }
+  }
+  return TetToGet;
 }
 
-bool ThinLayer::IsPositivOrientation(SVector3 a, SVector3 b, SVector3 c){
-	bool result = false;
-	SPoint3 ProdVec(a.y() * b.z() - a.z() * b.y(),a.z() * b.x() - a.x() * b.z(),a.x() * b.y() - a.y() * b.x());
-	double ProdScal = ProdVec.x() * c.x() + ProdVec.y() * c.y() + ProdVec.z() * c.z();
-	if (ProdScal >= 0.0){
-		result = true;
-	}
-	return result;
+bool ThinLayer::IsPositivOrientation(SVector3 a, SVector3 b, SVector3 c)
+{
+  bool result = false;
+  SPoint3 ProdVec(a.y() * b.z() - a.z() * b.y(),a.z() * b.x() -
+                  a.x() * b.z(),a.x() * b.y() - a.y() * b.x());
+  double ProdScal = ProdVec.x() * c.x() + ProdVec.y() * c.y() + ProdVec.z() * c.z();
+  if (ProdScal >= 0.0){
+    result = true;
+  }
+  return result;
 }
 
-
-void ThinLayer::FindNewPoint(SPoint3* CurrentPoint, int* CurrentTri, MTet4* CurrentTet, SVector3 InteriorNormal){
-	double distanceP2P = 0.0;
-	double alphaMax;
-	double betaMax;
-	SPoint3 ResultPoint;
-	int triToGet = 0;
-	for (unsigned int n = 0;n < 4 ; n++){
-		//calculer matrice a inverser
-		faceXtet fxt(CurrentTet,n);
-		double a = fxt.v[1]->x() - fxt.v[0]->x();
-		double b = fxt.v[2]->x() - fxt.v[0]->x();
-		double c = InteriorNormal.x();
-		double d = fxt.v[1]->y() - fxt.v[0]->y();
-		double e = fxt.v[2]->y() - fxt.v[0]->y();
-		double f = InteriorNormal.y();
-		double g = fxt.v[1]->z() - fxt.v[0]->z();
-		double h = fxt.v[2]->z() - fxt.v[0]->z();
-		double i = InteriorNormal.z();
-		//produit matrice inverse par vecteur donne poids
-		double detMat = a * e * i  + b * f * g + c * d * h - c * e * g - f * h * a - i * b * d;
-		double ai = e * i - f * h;
-		double bi = c * h - b * i;
-		double ci = b * f - c * e;
-		double di = f * g - d * i;
-		double ei = a * i - c * g;
-		double fi = c * d - a * f;
-//		double gi = d * h - e * g;
-//		double hi = b * g - a * h;
-//		double ii = a * e - b * d;
-		double oppx = (*CurrentPoint).x() - fxt.v[0]->x();
-		double oppy = (*CurrentPoint).y() - fxt.v[0]->y();
-		double oppz = (*CurrentPoint).z() - fxt.v[0]->z();
-		double alpha = ai / detMat * oppx + bi / detMat * oppy + ci / detMat * oppz;
-		double beta = di / detMat * oppx + ei / detMat * oppy + fi / detMat * oppz;
-//		double gamma = gi / detMat * oppx + hi / detMat * oppy + ii / detMat * oppz;
-		//Test si poids entre 0 et 1 et si length maximale
-		if ((alpha >= (0.0-epsilon)) && (alpha <= (1.0 + epsilon))){
-			if ((beta >= (0.0-epsilon)) && (beta <= (1.0 + epsilon))){
-				if (((1.0 - alpha - beta) >= (0.0-epsilon)) && ((1.0 - alpha - beta) <= (1.0 + epsilon))){
-					SPoint3 PointTmp(fxt.v[0]->x() + alpha * (fxt.v[1]->x() - fxt.v[0]->x()) + beta * (fxt.v[2]->x() - fxt.v[0]->x()),fxt.v[0]->y() + alpha * (fxt.v[1]->y() - fxt.v[0]->y()) + beta * (fxt.v[2]->y() - fxt.v[0]->y()),fxt.v[0]->z() + alpha * (fxt.v[1]->z() - fxt.v[0]->z()) + beta * (fxt.v[2]->z() - fxt.v[0]->z()));
-					double distanceTmp = PointTmp.distance((*CurrentPoint));
-					if (distanceTmp > distanceP2P){
-						distanceP2P = distanceTmp;
-						ResultPoint = PointTmp;
-						triToGet = n;
-						alphaMax = alpha;
-						betaMax = beta;
-					}
-				}
-			}
-		}
-	}
-	//test si trop proche d'un point / une arete
-	if (((alphaMax < epsilon) && (betaMax < epsilon)) || ((alphaMax < epsilon) && ((1.0 - alphaMax - betaMax) < epsilon)) || (((1.0 - alphaMax - betaMax) < epsilon) && (betaMax < epsilon))){
-		//proche d'un point
-		double DistMinTmp = 10000000.0;
-		int indexMinTmp;
-		for (unsigned int i = 0;i < 4;i++){
-			double distanceTmp = sqrt((CurrentTet->tet()->getVertex(i)->x() - ResultPoint.x()) * (CurrentTet->tet()->getVertex(i)->x() - ResultPoint.x()) + (CurrentTet->tet()->getVertex(i)->y() - ResultPoint.y()) * (CurrentTet->tet()->getVertex(i)->y() - ResultPoint.y()) + (CurrentTet->tet()->getVertex(i)->z() - ResultPoint.z()) * (CurrentTet->tet()->getVertex(i)->z() - ResultPoint.z()));
-			if (distanceTmp < DistMinTmp){
-				DistMinTmp = distanceTmp;
-				indexMinTmp = i;
-			}
-		}
-		MTet4* NewTet = ThinLayer::getTetFromPoint(CurrentTet->tet()->getVertex(indexMinTmp),InteriorNormal);
-		SPoint3 PointTmp(CurrentTet->tet()->getVertex(indexMinTmp)->x(),CurrentTet->tet()->getVertex(indexMinTmp)->y(),CurrentTet->tet()->getVertex(indexMinTmp)->z());
-		(*CurrentPoint) = PointTmp;
-		CurrentTet = NewTet;
-	}
-	else if ((alphaMax < epsilon) || (betaMax < epsilon) || ((1.0 - alphaMax - betaMax) < epsilon)){
-		//trop proche d'une arete
-	}
-	else{
-		(*CurrentPoint) = ResultPoint;
-		(*CurrentTri) = triToGet;
-		CurrentTet = CurrentTet->getNeigh(triToGet);
-	}
+void ThinLayer::FindNewPoint(SPoint3* CurrentPoint, int* CurrentTri,
+                             MTet4* CurrentTet, SVector3 InteriorNormal)
+{
+  double distanceP2P = 0.0;
+  double alphaMax = 0.0;
+  double betaMax = 0.0;
+  SPoint3 ResultPoint;
+  int triToGet = 0;
+  for (unsigned int n = 0;n < 4 ; n++){
+    //calculer matrice a inverser
+    faceXtet fxt(CurrentTet,n);
+    double a = fxt.v[1]->x() - fxt.v[0]->x();
+    double b = fxt.v[2]->x() - fxt.v[0]->x();
+    double c = InteriorNormal.x();
+    double d = fxt.v[1]->y() - fxt.v[0]->y();
+    double e = fxt.v[2]->y() - fxt.v[0]->y();
+    double f = InteriorNormal.y();
+    double g = fxt.v[1]->z() - fxt.v[0]->z();
+    double h = fxt.v[2]->z() - fxt.v[0]->z();
+    double i = InteriorNormal.z();
+    //produit matrice inverse par vecteur donne poids
+    double detMat = a * e * i  + b * f * g + c * d * h - c * e * g - f * h * a - i * b * d;
+    double ai = e * i - f * h;
+    double bi = c * h - b * i;
+    double ci = b * f - c * e;
+    double di = f * g - d * i;
+    double ei = a * i - c * g;
+    double fi = c * d - a * f;
+    // double gi = d * h - e * g;
+    // double hi = b * g - a * h;
+    // double ii = a * e - b * d;
+    double oppx = (*CurrentPoint).x() - fxt.v[0]->x();
+    double oppy = (*CurrentPoint).y() - fxt.v[0]->y();
+    double oppz = (*CurrentPoint).z() - fxt.v[0]->z();
+    double alpha = ai / detMat * oppx + bi / detMat * oppy + ci / detMat * oppz;
+    double beta = di / detMat * oppx + ei / detMat * oppy + fi / detMat * oppz;
+    // double gamma = gi / detMat * oppx + hi / detMat * oppy + ii / detMat * oppz;
+    //Test si poids entre 0 et 1 et si length maximale
+    if ((alpha >= (0.0-epsilon)) && (alpha <= (1.0 + epsilon))){
+      if ((beta >= (0.0-epsilon)) && (beta <= (1.0 + epsilon))){
+        if (((1.0 - alpha - beta) >= (0.0-epsilon)) &&
+            ((1.0 - alpha - beta) <= (1.0 + epsilon))){
+          SPoint3 PointTmp(fxt.v[0]->x() + alpha * (fxt.v[1]->x() - fxt.v[0]->x()) +
+                           beta * (fxt.v[2]->x() - fxt.v[0]->x()),fxt.v[0]->y() +
+                           alpha * (fxt.v[1]->y() - fxt.v[0]->y()) +
+                           beta * (fxt.v[2]->y() - fxt.v[0]->y()),fxt.v[0]->z() +
+                           alpha * (fxt.v[1]->z() - fxt.v[0]->z()) +
+                           beta * (fxt.v[2]->z() - fxt.v[0]->z()));
+          double distanceTmp = PointTmp.distance((*CurrentPoint));
+          if (distanceTmp > distanceP2P){
+            distanceP2P = distanceTmp;
+            ResultPoint = PointTmp;
+            triToGet = n;
+            alphaMax = alpha;
+            betaMax = beta;
+          }
+        }
+      }
+    }
+  }
+  //test si trop proche d'un point / une arete
+  if (((alphaMax < epsilon) && (betaMax < epsilon)) ||
+      ((alphaMax < epsilon) && ((1.0 - alphaMax - betaMax) < epsilon)) ||
+      (((1.0 - alphaMax - betaMax) < epsilon) && (betaMax < epsilon))){
+    //proche d'un point
+    double DistMinTmp = 10000000.0;
+    int indexMinTmp = 0;
+    for (unsigned int i = 0;i < 4;i++){
+      double distanceTmp =
+        sqrt((CurrentTet->tet()->getVertex(i)->x() - ResultPoint.x()) *
+             (CurrentTet->tet()->getVertex(i)->x() - ResultPoint.x()) +
+             (CurrentTet->tet()->getVertex(i)->y() - ResultPoint.y()) *
+             (CurrentTet->tet()->getVertex(i)->y() - ResultPoint.y()) +
+             (CurrentTet->tet()->getVertex(i)->z() - ResultPoint.z()) *
+             (CurrentTet->tet()->getVertex(i)->z() - ResultPoint.z()));
+      if (distanceTmp < DistMinTmp){
+        DistMinTmp = distanceTmp;
+        indexMinTmp = i;
+      }
+    }
+    MTet4* NewTet = ThinLayer::getTetFromPoint
+      (CurrentTet->tet()->getVertex(indexMinTmp),InteriorNormal);
+    SPoint3 PointTmp(CurrentTet->tet()->getVertex(indexMinTmp)->x(),
+                     CurrentTet->tet()->getVertex(indexMinTmp)->y(),
+                     CurrentTet->tet()->getVertex(indexMinTmp)->z());
+    (*CurrentPoint) = PointTmp;
+    CurrentTet = NewTet;
+  }
+  else if ((alphaMax < epsilon) || (betaMax < epsilon) ||
+           ((1.0 - alphaMax - betaMax) < epsilon)){
+    //trop proche d'une arete
+  }
+  else{
+    (*CurrentPoint) = ResultPoint;
+    (*CurrentTri) = triToGet;
+    CurrentTet = CurrentTet->getNeigh(triToGet);
+  }
 }
 
-void ThinLayer::fillVertexToTets(){
-	GModel *m = GModel::current();
-	for (GModel::riter itr= m->firstRegion();itr != m->lastRegion();itr++){
-		GRegion* rTmp = (*itr);
-		for (unsigned int i = 0; i < rTmp->tetrahedra.size();i++){
-			MTetrahedron* elem = rTmp->tetrahedra[i];
-			for (unsigned int j = 0; j < 4;j++){
-				std::vector<MTetrahedron*> emptyTetVec;
-				emptyTetVec.clear();
-				VertexToTets[elem->getVertex(j)] = emptyTetVec;
-				std::vector<CorrespVertices*> emptyCVVec;
-				emptyCVVec.clear();
-				VertexToCorresp[elem->getVertex(j)] = emptyCVVec;
-			}
-		}
-	}
-	for (GModel::riter itr= m->firstRegion();itr != m->lastRegion();itr++){
-		GRegion* rTmp = (*itr);
-		for (unsigned int i = 0; i < rTmp->tetrahedra.size();i++){
-			MTetrahedron* elem = rTmp->tetrahedra[i];
-			for (unsigned int j = 0; j < 4;j++){
-				VertexToTets[elem->getVertex(j)].push_back(elem);
-			}
-		}
-	}
+void ThinLayer::fillVertexToTets()
+{
+  GModel *m = GModel::current();
+  for (GModel::riter itr= m->firstRegion();itr != m->lastRegion();itr++){
+    GRegion* rTmp = (*itr);
+    for (unsigned int i = 0; i < rTmp->tetrahedra.size();i++){
+      MTetrahedron* elem = rTmp->tetrahedra[i];
+      for (unsigned int j = 0; j < 4;j++){
+        std::vector<MTetrahedron*> emptyTetVec;
+        emptyTetVec.clear();
+        VertexToTets[elem->getVertex(j)] = emptyTetVec;
+        std::vector<CorrespVertices*> emptyCVVec;
+        emptyCVVec.clear();
+        VertexToCorresp[elem->getVertex(j)] = emptyCVVec;
+      }
+    }
+  }
+  for (GModel::riter itr= m->firstRegion();itr != m->lastRegion();itr++){
+    GRegion* rTmp = (*itr);
+    for (unsigned int i = 0; i < rTmp->tetrahedra.size();i++){
+      MTetrahedron* elem = rTmp->tetrahedra[i];
+      for (unsigned int j = 0; j < 4;j++){
+        VertexToTets[elem->getVertex(j)].push_back(elem);
+      }
+    }
+  }
 }
 
 void ThinLayer::fillTetToTet4(){
-	GModel *m = GModel::current();
-	std::vector<MTet4*> vecAllTet4;
-	vecAllTet4.clear();
-	for (GModel::riter itr= m->firstRegion();itr != m->lastRegion();itr++){
-		GRegion* rTmp = (*itr);
-		for (unsigned int i = 0; i < rTmp->tetrahedra.size();i++){
-			MTetrahedron* elem = rTmp->tetrahedra[i];
-			MTet4 tet4tmp = MTet4(elem,0.0);
-			MTet4* currentTet4 = &tet4tmp;
-			TetToTet4[elem] = currentTet4;
-			vecAllTet4.clear();
-		}
-	}
-	connectTets(vecAllTet4);
+  GModel *m = GModel::current();
+  std::vector<MTet4*> vecAllTet4;
+  vecAllTet4.clear();
+  for (GModel::riter itr= m->firstRegion();itr != m->lastRegion();itr++){
+    GRegion* rTmp = (*itr);
+    for (unsigned int i = 0; i < rTmp->tetrahedra.size();i++){
+      MTetrahedron* elem = rTmp->tetrahedra[i];
+      MTet4 tet4tmp = MTet4(elem,0.0);
+      MTet4* currentTet4 = &tet4tmp;
+      TetToTet4[elem] = currentTet4;
+      vecAllTet4.clear();
+    }
+  }
+  connectTets(vecAllTet4);
 }
-
-/****************static declarations****************/
-
-std::map<MVertex*,std::vector<MTetrahedron*> > ThinLayer::VertexToTets;
-std::map<MTetrahedron*,MTet4*> ThinLayer::TetToTet4;
-std::map<MVertex*,std::vector<CorrespVertices*> > ThinLayer::VertexToCorresp;
-std::vector<std::vector<CorrespVertices*> > ThinLayer::vecOfThinSheets;
-
diff --git a/Mesh/ThinLayer.h b/Mesh/ThinLayer.h
index de9e37c819f6429bc122b36ac262ee3ce127e30c..45f39ad8488eb593cb49996ef3af8a9ecf2b1c8e 100644
--- a/Mesh/ThinLayer.h
+++ b/Mesh/ThinLayer.h
@@ -1,9 +1,9 @@
-/*
- * ThinLayer.h
- *
- *  Created on: Oct 13, 2014
- *      Author: nicolas
- */
+// Gmsh - Copyright (C) 1997-2015 C. Geuzaine, J.-F. Remacle
+//
+// See the LICENSE.txt file for license information. Please report all
+// bugs and problems to the public mailing list <gmsh@geuz.org>.
+//
+// Author: Nicolas Kowalski
 
 #ifndef THINLAYER_H_
 #define THINLAYER_H_
@@ -12,7 +12,6 @@
 #include "MTriangle.h"
 #include "meshGRegionDelaunayInsertion.h"
 
-
 static int faces[4][3] = {{0,1,2}, {0,2,3}, {0,3,1}, {1,3,2}};
 
 struct faceXtet{
@@ -38,7 +37,7 @@ struct faceXtet{
 
   inline MVertex * getVertex (int i) const { return unsorted[i];}
 
- inline bool operator < (const faceXtet & other) const
+  inline bool operator < (const faceXtet & other) const
   {
     if (v[0] < other.v[0]) return true;
     if (v[0] > other.v[0]) return false;
@@ -68,70 +67,68 @@ struct faceXtet{
 
 class CorrespVertices{
 private:
-	MVertex* StartPoint;
-	SPoint3 EndPoint;
-	SVector3 StartNormal;
-	SVector3 EndNormal;
-	faceXtet EndTriangle;
-	double distP2P;
-	double angleProd;
-	bool Active;
-	bool EndTriangleActive;
-	bool IsMaster;
-	int tagMaster;
+  MVertex* StartPoint;
+  SPoint3 EndPoint;
+  SVector3 StartNormal;
+  SVector3 EndNormal;
+  faceXtet EndTriangle;
+  double distP2P;
+  double angleProd;
+  bool Active;
+  bool EndTriangleActive;
+  bool IsMaster;
+  int tagMaster;
 public:
-	CorrespVertices();
-	~CorrespVertices();
-	void setStartPoint(MVertex* v);
-	void setEndPoint(SPoint3 p);
-	void setStartNormal(SVector3 v);
-	void setEndNormal(SVector3 v);
-	void setEndTriangle(faceXtet f);
-	void setdistP2P(double d);
-	void setangleProd(double a);
-	void setActive(bool b);
-	void setEndTriangleActive(bool b);
-	void setIsMaster(bool b);
-	void setTagMaster(int i);
-	MVertex* getStartPoint();
-	SPoint3 getEndPoint();
-	SVector3 getStartNormal();
-	SVector3 getEndNormal();
-	faceXtet getEndTriangle();
-	double getdistP2P();
-	double getangleProd();
-	bool getActive();
-	bool getEndTriangleActive();
-	bool getIsMaster();
-	int getTagMaster();
+  CorrespVertices();
+  ~CorrespVertices();
+  void setStartPoint(MVertex* v);
+  void setEndPoint(SPoint3 p);
+  void setStartNormal(SVector3 v);
+  void setEndNormal(SVector3 v);
+  void setEndTriangle(faceXtet f);
+  void setdistP2P(double d);
+  void setangleProd(double a);
+  void setActive(bool b);
+  void setEndTriangleActive(bool b);
+  void setIsMaster(bool b);
+  void setTagMaster(int i);
+  MVertex* getStartPoint();
+  SPoint3 getEndPoint();
+  SVector3 getStartNormal();
+  SVector3 getEndNormal();
+  faceXtet getEndTriangle();
+  double getdistP2P();
+  double getangleProd();
+  bool getActive();
+  bool getEndTriangleActive();
+  bool getIsMaster();
+  int getTagMaster();
 };
 
 class ThinLayer{
 private:
 public:
-	ThinLayer();
-	~ThinLayer();
-	static void perform();
-	static void checkOppositeTriangles();
-	static void fillvecOfThinSheets();
-	static std::map<MVertex*,double> computeAllDistToOppSide();
-	static double computeDistToOppSide(MVertex* v);
-	static SVector3 computeInteriorNormal(MVertex* v);
-	static MTet4* getTetFromPoint(MVertex* v, SVector3 InteriorNormal);
-	static bool IsPositivOrientation(SVector3 a, SVector3 b, SVector3 c);
-	static void FindNewPoint(SPoint3* CurrentPoint, int* CurrentTri, MTet4* CurrentTet, SVector3 InteriorNormal);
-	static std::map<MVertex*,std::vector<MTetrahedron*> > VertexToTets;
-	static std::map<MTetrahedron*,MTet4*> TetToTet4;
-	static std::map<MVertex*,std::vector<CorrespVertices*> > VertexToCorresp;
-	static std::vector<std::vector<CorrespVertices*> > vecOfThinSheets;
-	static const double epsilon = 0.00001;
-	static const double angleMax = 0.9;
-	static const double distP2PMax = 0.3;
-	static void fillVertexToTets();
-	static void fillTetToTet4();
+  ThinLayer();
+  ~ThinLayer();
+  static void perform();
+  static void checkOppositeTriangles();
+  static void fillvecOfThinSheets();
+  static std::map<MVertex*,double> computeAllDistToOppSide();
+  static double computeDistToOppSide(MVertex* v);
+  static SVector3 computeInteriorNormal(MVertex* v);
+  static MTet4* getTetFromPoint(MVertex* v, SVector3 InteriorNormal);
+  static bool IsPositivOrientation(SVector3 a, SVector3 b, SVector3 c);
+  static void FindNewPoint(SPoint3* CurrentPoint, int* CurrentTri,
+                           MTet4* CurrentTet, SVector3 InteriorNormal);
+  static std::map<MVertex*,std::vector<MTetrahedron*> > VertexToTets;
+  static std::map<MTetrahedron*,MTet4*> TetToTet4;
+  static std::map<MVertex*,std::vector<CorrespVertices*> > VertexToCorresp;
+  static std::vector<std::vector<CorrespVertices*> > vecOfThinSheets;
+  static const double epsilon;
+  static const double angleMax;
+  static const double distP2PMax;
+  static void fillVertexToTets();
+  static void fillTetToTet4();
 };
 
-
-
-
-#endif /* THINLAYER_H_ */
+#endif
diff --git a/Mesh/meshGEdge.cpp b/Mesh/meshGEdge.cpp
index 9feda8d55183159acc70c1308552e79a27b73a66..7f2765f2fdc461ede1d458dfbf7320f4c1cc83a3 100644
--- a/Mesh/meshGEdge.cpp
+++ b/Mesh/meshGEdge.cpp
@@ -268,14 +268,13 @@ static double Integration(GEdge *ge, double t1, double t2,
 }
 
 void copyMesh(GEdge *from, GEdge *to, int direction)
-{  
+{
   Range<double> u_bounds = from->parBounds(0);
   double u_min = u_bounds.low();
   double u_max = u_bounds.high();
 
   Range<double> to_u_bounds = to->parBounds(0);
   double to_u_min = to_u_bounds.low();
-  double to_u_max = to_u_bounds.high();
 
   for(unsigned int i = 0; i < from->mesh_vertices.size(); i++){
     int index = (direction < 0) ? (from->mesh_vertices.size() - 1 - i) : i;
diff --git a/Plugin/DuplicateBoundaries.cpp b/Plugin/DuplicateBoundaries.cpp
index 33e31b7f3e1dff4f0ecba697a31620515fb0e37f..db6b15c2aa3a6c7e7a70dbc53f1668429e201b3d 100644
--- a/Plugin/DuplicateBoundaries.cpp
+++ b/Plugin/DuplicateBoundaries.cpp
@@ -140,1343 +140,1335 @@ struct Less_EdgeData : public std::binary_function<EdgeData, EdgeData, bool> {
 //}
 
 double GMSH_DuplicateBoundariesPlugin::abs(double x){
-	if (x < 0.0){
-		return (-x);
-	}
-	else{
-		return x;
-	}
+  if (x < 0.0){
+    return (-x);
+  }
+  else{
+    return x;
+  }
 }
 
 PView *GMSH_DuplicateBoundariesPlugin::executeBis(PView *view)
 {
-	std::cout<<"starting DuplicateBoundaries"<<std::endl;
-	GModel *m = GModel::current();
-	m->setFactory("geo");
-	std::set<GFace*> ToDuplicateList;
-	ToDuplicateList.clear();
-	std::set<GFace*> ToDuplicateListBoundary;
-	ToDuplicateListBoundary.clear();
-	std::vector<GFace*> facesBound;
-	facesBound.clear();
-	std::map<GFace*,SPoint3> centers;
-	std::vector<std::pair<GFace*,GFace*> > pairs;
-//	int PhysicalSeeds = m->setPhysicalName("Seeds",3);
-//
-//	//std::cout<<"number for seeds: "<<PhysicalSeeds<<" and for interface: "<<PhysicalInterface<<std::endl;
-//
-//	for (GModel::riter itf= m->firstRegion();itf != m->lastRegion();itf++){
-//		GRegion* fTmp = (*itf);
-//		fTmp->addPhysicalEntity(PhysicalSeeds);
-//	}
-	int PhysicalInterface = m->setPhysicalName("Interface",3);
-	std::cout<<"DEBUT INIT"<<std::endl;
-	for (GModel::fiter itf= m->firstFace();itf != m->lastFace();itf++){
-		GFace* fTmp = (*itf);
-
-
-		for (unsigned int i = 0; i < fTmp->getNumMeshElements();i++){
-			MElement* elem = fTmp->getMeshElement(i);
-
-	
-		}
-
-
-		if (fTmp->numRegions() == 2){
-			ToDuplicateList.insert(fTmp);
-		}
-		else{
-			facesBound.push_back(fTmp);
-		}
-	}
-
-	for(unsigned int i=0;i<facesBound.size();i++){
-		double x = 0.0;
-		double y = 0.0;
-		double z = 0.0;
-
-		std::list<GVertex*> vertices;
-
-		vertices = facesBound[i]->vertices();
-
-		for(std::list<GVertex*>::iterator it2=vertices.begin();it2!=vertices.end();it2++){
-			x = x + (*it2)->x();
-			y = y + (*it2)->y();
-			z = z + (*it2)->z();
-		}
-
-		x = x/vertices.size();
-		y = y/vertices.size();
-		z = z/vertices.size();
-
-		centers.insert(std::pair<GFace*,SPoint3>(facesBound[i],SPoint3(x,y,z)));
-	}
-
-	for(unsigned int i=0;i<facesBound.size();i++){
-		for(unsigned int j=0;j<facesBound.size();j++){
-			std::map<GFace*,SPoint3>::iterator it3 = centers.find(facesBound[i]);
-			std::map<GFace*,SPoint3>::iterator it4 = centers.find(facesBound[j]);
-
-			SPoint3 p1 = it3->second;
-			SPoint3 p2 = it4->second;
-
-
-			//				categories.push_back(val);
-
-			//				print_segment(p1,p2,file);
-
-			if (abs((p2.x()-p1.x()-1.0))<0.0001){
-				if (abs((p2.y()-p1.y()))<0.0001){
-					if (abs((p2.z()-p1.z()))<0.0001){
-						pairs.push_back(std::pair<GFace*,GFace*>(facesBound[i],facesBound[j]));
-						ToDuplicateListBoundary.insert(facesBound[i]);
-					}else if(abs((p2.z()-p1.z()-1.0))<0.0001){
-						pairs.push_back(std::pair<GFace*,GFace*>(facesBound[i],facesBound[j]));
-						ToDuplicateListBoundary.insert(facesBound[i]);
-					}else if (abs((p1.z()-p2.z()-1.0))<0.0001){
-						pairs.push_back(std::pair<GFace*,GFace*>(facesBound[i],facesBound[j]));
-						ToDuplicateListBoundary.insert(facesBound[i]);
-					}
-				}else if (abs((p2.y()-p1.y()-1.0))<0.0001){
-					if (abs((p2.z()-p1.z()))<0.0001){
-						pairs.push_back(std::pair<GFace*,GFace*>(facesBound[i],facesBound[j]));
-						ToDuplicateListBoundary.insert(facesBound[i]);
-					}else if (abs((p2.z()-p1.z()-1.0))<0.0001){
-						pairs.push_back(std::pair<GFace*,GFace*>(facesBound[i],facesBound[j]));
-						ToDuplicateListBoundary.insert(facesBound[i]);
-					}else if (abs((p1.z()-p2.z()-1.0))<0.0001){
-						pairs.push_back(std::pair<GFace*,GFace*>(facesBound[i],facesBound[j]));
-						ToDuplicateListBoundary.insert(facesBound[i]);
-					}
-				}else if (abs((p1.y()-p2.y()-1.0))<0.0001){
-					if (abs((p2.z()-p1.z()))<0.0001){
-						pairs.push_back(std::pair<GFace*,GFace*>(facesBound[i],facesBound[j]));
-						ToDuplicateListBoundary.insert(facesBound[i]);
-					}else if (abs((p2.z()-p1.z()-1.0))<0.0001){
-						pairs.push_back(std::pair<GFace*,GFace*>(facesBound[i],facesBound[j]));
-						ToDuplicateListBoundary.insert(facesBound[i]);
-					}else if (abs((p1.z()-p2.z()-1.0))<0.0001){
-						pairs.push_back(std::pair<GFace*,GFace*>(facesBound[i],facesBound[j]));
-						ToDuplicateListBoundary.insert(facesBound[i]);
-					}
-				}
-			}else if (abs((p1.x()-p2.x()-1.0))<0.0001){
-				if (abs((p2.y()-p1.y()))<0.0001){
-					if (abs((p2.z()-p1.z()))<0.0001){
-						//NOTHING
-					}else if(abs((p2.z()-p1.z()-1.0))<0.0001){
-						//NOTHING
-					}else if (abs((p1.z()-p2.z()-1.0))<0.0001){
-						//NOTHING
-					}
-				}else if (abs((p2.y()-p1.y()-1.0))<0.0001){
-					if (abs((p2.z()-p1.z()))<0.0001){
-						//NOTHING
-					}else if (abs((p2.z()-p1.z()-1.0))<0.0001){
-						//NOTHING
-					}else if (abs((p1.z()-p2.z()-1.0))<0.0001){
-						//NOTHING
-					}
-				}else if (abs((p1.y()-p2.y()-1.0))<0.0001){
-					if (abs((p2.z()-p1.z()))<0.0001){
-						//NOTHING
-					}else if (abs((p2.z()-p1.z()-1.0))<0.0001){
-						//NOTHING
-					}else if (abs((p1.z()-p2.z()-1.0))<0.0001){
-						//NOTHING
-					}
-				}
-			}else if (abs((p1.x()-p2.x()))<0.0001){
-				if (abs((p2.y()-p1.y()-1.0))<0.0001){
-					if (abs((p2.z()-p1.z()))<0.0001){
-						pairs.push_back(std::pair<GFace*,GFace*>(facesBound[i],facesBound[j]));
-						ToDuplicateListBoundary.insert(facesBound[i]);
-					}else if (abs((p2.z()-p1.z()-1.0))<0.0001){
-						pairs.push_back(std::pair<GFace*,GFace*>(facesBound[i],facesBound[j]));
-						ToDuplicateListBoundary.insert(facesBound[i]);
-					}else if (abs((p1.z()-p2.z()-1.0))<0.0001){
-						pairs.push_back(std::pair<GFace*,GFace*>(facesBound[i],facesBound[j]));
-						ToDuplicateListBoundary.insert(facesBound[i]);
-					}
-				}else if (abs((p1.y()-p2.y()-1.0))<0.0001){
-					if (abs((p2.z()-p1.z()))<0.0001){
-						//NOTHING
-					}else if (abs((p2.z()-p1.z()-1.0))<0.0001){
-						//NOTHING
-					}else if (abs((p1.z()-p2.z()-1.0))<0.0001){
-						//NOTHING
-					}
-				}else if (abs((p1.y()-p2.y()))<0.0001){
-					if (abs((p2.z()-p1.z()-1.0))<0.0001){
-						pairs.push_back(std::pair<GFace*,GFace*>(facesBound[i],facesBound[j]));
-						ToDuplicateListBoundary.insert(facesBound[i]);
-					}else if (abs((p1.z()-p2.z()-1.0))<0.0001){
-						//NOTHING
-					}
-				}
-			}
-		}
-	}
-
-	int counterNbDone = 10000;
-	//int tagEdges = 10000;
-	for (std::set<GFace*>::iterator itr = ToDuplicateList.begin();itr != ToDuplicateList.end();itr++){
-		counterNbDone++;
-		GFace* fTmp = (*itr);
-		//on doit dupliquer la face, les noeuds, les aretes, puis creer une region entre les deux
-		std::map<MVertex*,MVertex* > VertexAssociation;
-		std::map<GVertex*,GVertex* > GVertexAssociation;
-		std::map<GEdge*,GEdge* > GEdgeAssociation;
-		std::list<GVertex*> vlist = fTmp->vertices();
-		std::map<GVertex*,GEdge* > SurroudingEdges;
-		GRegion *rTmp = fTmp->getRegion(1);
-		std::list<GFace*> facesReg;
-		facesReg = rTmp->faces();
-		for (std::list<GFace*>::iterator it2=facesReg.begin();it2!=facesReg.end();it2++){
-			GFace* fTemp = (*it2);
-		}
-		double xCenterReg = 0.0;
-		double yCenterReg = 0.0;
-		double zCenterReg = 0.0;
-
-
-
-
-
-		int counterPts = 0;
-		for(std::list<GFace*>::iterator it2=facesReg.begin();it2!=facesReg.end();it2++){
-			GFace* fTemp = (*it2);
-			std::list<GVertex*> verticesFace = fTemp->vertices();
-			for (std::list<GVertex*>::iterator it3=verticesFace.begin();it3!=verticesFace.end();it3++){
-				xCenterReg = xCenterReg + (*it3)->x();
-				yCenterReg = yCenterReg + (*it3)->y();
-				zCenterReg = zCenterReg + (*it3)->z();
-				counterPts++;
-			}
-		}
-
-		xCenterReg = xCenterReg/counterPts;
-		yCenterReg = yCenterReg/counterPts;
-		zCenterReg = zCenterReg/counterPts;
-
-		for (std::list<GVertex*>::iterator itv = vlist.begin();itv != vlist.end();itv++){
-			//duplication Gvertex
-			GVertex* vTmp = (*itv);
-			double ponderatedX = 0.99999999999 * vTmp->x() + 0.00000000001 * xCenterReg;
-			double ponderatedY = 0.99999999999 * vTmp->y() + 0.00000000001 * yCenterReg;
-			double ponderatedZ = 0.99999999999 * vTmp->z() + 0.00000000001 * zCenterReg;
-//			double ponderatedX = 1.0 * vTmp->x() + 0.0 * xCenterReg;
-//			double ponderatedY = 1.0 * vTmp->y() + 0.0 * yCenterReg;
-//			double ponderatedZ = 1.0 * vTmp->z() + 0.0 * zCenterReg;
-			//GVertex* newv = new gmshVertex(m,vTmp->prescribedMeshSizeAtVertex());
-			GVertex* newv = m->addVertex(ponderatedX,ponderatedY,ponderatedZ,vTmp->prescribedMeshSizeAtVertex());
-			GVertexAssociation[vTmp] = newv;
-			//creation des Gedge correspondantes
-			//GEdge* newE = new GEdge(m,tagEdges,vTmp,newv);
-			//tagEdges++;
-			//m->add(newE);
-			GEdge* newE = m->addLine(vTmp,newv);
-			SurroudingEdges[vTmp] = newE;
-			//maintenant traitement mesh
-			MVertex *vMesh = vTmp->mesh_vertices[0];
-			MVertex *newMv = new MVertex(vMesh->x(), vMesh->y(), vMesh->z(), (GEntity*)newv);
-			VertexAssociation[vMesh] = newMv;
-			newv->addMeshVertex(newMv);
-		}
-		std::list<GEdge*> elist = fTmp->edges();
-		std::vector<GEdge*> newEdgesVector;
-		std::vector<GFace*> SurroundingsFaces;
-		for (std::list<GEdge*>::iterator ite = elist.begin();ite != elist.end();ite++){
-			//duplication Gedge
-			GEdge* eTmp = (*ite);
-			GEdge* newE = m->addLine(GVertexAssociation[eTmp->getEndVertex()],GVertexAssociation[eTmp->getBeginVertex()]);
-			GEdgeAssociation[eTmp] = newE;
-			newEdgesVector.push_back(newE);
-			//creation des GFace correspondantes
-			GEdge* firstE = SurroudingEdges.find(eTmp->getEndVertex())->second;
-			GEdge* lastE = SurroudingEdges.find(eTmp->getBeginVertex())->second;
-			std::vector<GEdge*> VecEdgesTmp;
-			VecEdgesTmp.push_back(eTmp);
-			VecEdgesTmp.push_back(firstE);
-			VecEdgesTmp.push_back(newE);
-			VecEdgesTmp.push_back(lastE);
-			std::vector<std::vector<GEdge*> > VecOfVecTmp;
-			VecOfVecTmp.push_back(VecEdgesTmp);
-			GFace* newFaceTmp = m->addPlanarFace(VecOfVecTmp);
-			SurroundingsFaces.push_back(newFaceTmp);
-			//maintenant traitement mesh
-			for (unsigned int i = 0; i < eTmp->mesh_vertices.size();i++){
-				MVertex *vMesh = eTmp->mesh_vertices[i];
-				MVertex *newMv = new MVertex(vMesh->x(), vMesh->y(), vMesh->z(), (GEntity*)newE);
-				VertexAssociation[vMesh] = newMv;
-				newE->addMeshVertex(newMv);
-			}
-			for (unsigned int i = 0; i < eTmp->getNumMeshElements();i++){
-				MElement* elem = eTmp->getMeshElement(i);
-				MVertex *firstETmp = VertexAssociation.find(elem->getVertex(0))->second;
-				MVertex *lastETmp = VertexAssociation.find(elem->getVertex(1))->second;
-				MLine *newLine = new MLine(firstETmp,lastETmp);
-				newE->addLine(newLine);
-			}
-		}
-		std::vector<std::vector<GEdge*> > VecOfVec;
-		VecOfVec.push_back(newEdgesVector);
-		//creation de la nouvelle face
-		GFace* GFaceAssociation = m->addPlanarFace(VecOfVec);
-		//maintenant traitement mesh
-		for (unsigned int i = 0; i < fTmp->mesh_vertices.size();i++){
-			MVertex *vMesh = fTmp->mesh_vertices[i];
-			MVertex *newMv = new MVertex(vMesh->x(), vMesh->y(), vMesh->z(), (GEntity*)GFaceAssociation);
-			VertexAssociation[vMesh] = newMv;
-			GFaceAssociation->addMeshVertex(newMv);
-		}
-		for (unsigned int i = 0; i < fTmp->getNumMeshElements();i++){
-			MElement* elem = fTmp->getMeshElement(i);
-			MVertex *firstE = VertexAssociation.find(elem->getVertex(0))->second;
-			MVertex *secondE = VertexAssociation.find(elem->getVertex(1))->second;
-			MVertex *thirdE = VertexAssociation.find(elem->getVertex(2))->second;
-			MTriangle *newTri = new MTriangle(firstE,secondE,thirdE);
-			GFaceAssociation->addTriangle(newTri);
-
-
-
-		}
-		std::vector<GFace*> VectorFaces;
-		std::list<GFace*> listFaces;
-		VectorFaces.push_back(fTmp);
-		listFaces.push_back(fTmp);
-		for (unsigned int i = 0;i < SurroundingsFaces.size();i++){
-			VectorFaces.push_back(SurroundingsFaces[i]);
-			listFaces.push_back(SurroundingsFaces[i]);
-		}
-		VectorFaces.push_back(GFaceAssociation);
-		listFaces.push_back(GFaceAssociation);
-		std::vector<std::vector<GFace*> > VecOfVecGFace;
-		VecOfVecGFace.push_back(VectorFaces);
-		//creation de la nouvelle region
-
-		GRegion* createdRegion = new GRegion(m,counterNbDone);
-		createdRegion->addPhysicalEntity(PhysicalInterface);
-		createdRegion->set(listFaces);
-		m->add(createdRegion);
-		std::list<GFace*> RegFaces = rTmp->faces();
-		std::list<GFace*>::iterator it = std::find(RegFaces.begin(), RegFaces.end(), fTmp);
-		std::cout<<(*it)->tag()<<std::endl;
-		if(it != RegFaces.end()) RegFaces.erase(it);
-		RegFaces.push_back(GFaceAssociation);
-		rTmp->set(RegFaces);
-		std::list<GFace*> NewFacesReg;
-		NewFacesReg = rTmp->faces();
-		for (std::list<GFace*>::iterator it2=NewFacesReg.begin();it2!=NewFacesReg.end();it2++){
-			GFace* fTemp = (*it2);
-			for (std::list<GEdge*>::iterator ite = elist.begin();ite != elist.end();ite++){
-				GEdge* eTmp = (*ite);
-				GEdge* newE = GEdgeAssociation[eTmp];
-				fTemp->replaceEdge(eTmp,newE);
-			}
-		}
-		for (unsigned int i = 0; i < fTmp->getNumMeshElements();i++){
-			MElement* elem = fTmp->getMeshElement(i);
-
-	
-
-			MVertex *firstE = VertexAssociation.find(elem->getVertex(0))->second;
-			MVertex *secondE = VertexAssociation.find(elem->getVertex(1))->second;
-			MVertex *thirdE = VertexAssociation.find(elem->getVertex(2))->second;
-
-	
-
-			MPrism *newPri = new MPrism(elem->getVertex(0),elem->getVertex(1),elem->getVertex(2),firstE,secondE,thirdE);
-
-			createdRegion->addPrism(newPri);
-		}
-		for (unsigned int i = 0; i < rTmp->getNumMeshElements();i++){
-			MElement* elem = rTmp->getMeshElement(i);
-			for (int j = 0;j < elem->getNumVertices();j++){
-				MVertex* vert = elem->getVertex(j);
-				std::map<MVertex*,MVertex* >::iterator itMap = VertexAssociation.find(vert);
-				if (itMap != VertexAssociation.end()){
-					elem->setVertex(j,itMap->second);
-				}
-			}
-		}
-		int countTmp = 0;
-		//maitenant refonte points dans faces
-		for (std::list<GFace*>::iterator itTmp = NewFacesReg.begin();itTmp != NewFacesReg.end();itTmp++){
-			GFace* GFaceTmp = (*itTmp);
-			countTmp++;
-			for (unsigned int i = 0; i < GFaceTmp->getNumMeshElements();i++){
-				MElement* elem = GFaceTmp->getMeshElement(i);
-				for (int j = 0;j < elem->getNumVertices();j++){
-					MVertex* vert = elem->getVertex(j);
-					std::map<MVertex*,MVertex* >::iterator itMap = VertexAssociation.find(vert);
-					if (itMap != VertexAssociation.end()){
-						elem->setVertex(j,itMap->second);
-	
-
-
-						std::vector<MVertex*> FaceVerti = GFaceTmp->mesh_vertices;
-						std::vector<MVertex*>::iterator itHere = std::find(FaceVerti.begin(), FaceVerti.end(), vert);
-						if(itHere != FaceVerti.end()) {
-							FaceVerti.erase(itHere);
-							FaceVerti.push_back(itMap->second);
-							GFaceTmp->mesh_vertices = FaceVerti;
-						}
-
-
-					}
-				}
-			}
-		}
-	}
-
-	//maintenant on attaque les faces au bord
-	for (std::set<GFace*>::iterator itr = ToDuplicateListBoundary.begin();itr != ToDuplicateListBoundary.end();itr++){
-		counterNbDone++;
-		GFace* fTmp = (*itr);
-		//on doit dupliquer la face, les noeuds, les aretes, puis creer une region entre les deux
-		std::map<MVertex*,MVertex* > VertexAssociation;
-		std::map<GVertex*,GVertex* > GVertexAssociation;
-		std::map<GEdge*,GEdge* > GEdgeAssociation;
-		std::list<GVertex*> vlist = fTmp->vertices();
-		std::map<GVertex*,GEdge* > SurroudingEdges;
-		GRegion *rTmp = fTmp->getRegion(0);
-		double xCenterReg = 0.0;
-		double yCenterReg = 0.0;
-		double zCenterReg = 0.0;
-
-		std::list<GFace*> facesReg;
-
-		facesReg = rTmp->faces();
-
-		int counterPts = 0;
-		for(std::list<GFace*>::iterator it2=facesReg.begin();it2!=facesReg.end();it2++){
-			GFace* fTemp = (*it2);
-			std::list<GVertex*> verticesFace = fTemp->vertices();
-			for (std::list<GVertex*>::iterator it3=verticesFace.begin();it3!=verticesFace.end();it3++){
-				xCenterReg = xCenterReg + (*it3)->x();
-				yCenterReg = yCenterReg + (*it3)->y();
-				zCenterReg = zCenterReg + (*it3)->z();
-				counterPts++;
-			}
-		}
-
-		xCenterReg = xCenterReg/counterPts;
-		yCenterReg = yCenterReg/counterPts;
-		zCenterReg = zCenterReg/counterPts;
-
-		for (std::list<GVertex*>::iterator itv = vlist.begin();itv != vlist.end();itv++){
-			//duplication Gvertex
-			GVertex* vTmp = (*itv);
-			double ponderatedX = 0.99999999999 * vTmp->x() + 0.00000000001 * xCenterReg;
-			double ponderatedY = 0.99999999999 * vTmp->y() + 0.00000000001 * yCenterReg;
-			double ponderatedZ = 0.99999999999 * vTmp->z() + 0.00000000001 * zCenterReg;
-			GVertex* newv = m->addVertex(ponderatedX,ponderatedY,ponderatedZ,vTmp->prescribedMeshSizeAtVertex());
-			GVertexAssociation[vTmp] = newv;
-			//creation des Gedge correspondantes
-			GEdge* newE = m->addLine(vTmp,newv);
-			SurroudingEdges[vTmp] = newE;
-			//maintenant traitement mesh
-			MVertex *vMesh = vTmp->mesh_vertices[0];
-			MVertex *newMv = new MVertex(vMesh->x(), vMesh->y(), vMesh->z(), (GEntity*)newv);
-			VertexAssociation[vMesh] = newMv;
-			newv->addMeshVertex(newMv);
-		}
-		std::list<GEdge*> elist = fTmp->edges();
-		std::vector<GEdge*> newEdgesVector;
-		std::vector<GFace*> SurroundingsFaces;
-		for (std::list<GEdge*>::iterator ite = elist.begin();ite != elist.end();ite++){
-			//duplication Gedge
-			GEdge* eTmp = (*ite);
-			GEdge* newE = m->addLine(GVertexAssociation[eTmp->getEndVertex()],GVertexAssociation[eTmp->getBeginVertex()]);
-			GEdgeAssociation[eTmp] = newE;
-			newEdgesVector.push_back(newE);
-			//creation des GFace correspondantes
-			GEdge* firstE = SurroudingEdges.find(eTmp->getEndVertex())->second;
-			GEdge* lastE = SurroudingEdges.find(eTmp->getBeginVertex())->second;
-			std::vector<GEdge*> VecEdgesTmp;
-			VecEdgesTmp.push_back(eTmp);
-			VecEdgesTmp.push_back(firstE);
-			VecEdgesTmp.push_back(newE);
-			VecEdgesTmp.push_back(lastE);
-			std::vector<std::vector<GEdge*> > VecOfVecTmp;
-			VecOfVecTmp.push_back(VecEdgesTmp);
-			GFace* newFaceTmp = m->addPlanarFace(VecOfVecTmp);
-			SurroundingsFaces.push_back(newFaceTmp);
-			//maintenant traitement mesh
-			for (unsigned int i = 0; i < eTmp->mesh_vertices.size();i++){
-				MVertex *vMesh = eTmp->mesh_vertices[i];
-				MVertex *newMv = new MVertex(vMesh->x(), vMesh->y(), vMesh->z(), (GEntity*)newE);
-				VertexAssociation[vMesh] = newMv;
-				newE->addMeshVertex(newMv);
-			}
-			for (unsigned int i = 0; i < eTmp->getNumMeshElements();i++){
-				MElement* elem = eTmp->getMeshElement(i);
-				MVertex *firstETmp = VertexAssociation.find(elem->getVertex(0))->second;
-				MVertex *lastETmp = VertexAssociation.find(elem->getVertex(1))->second;
-				MLine *newLine = new MLine(firstETmp,lastETmp);
-				newE->addLine(newLine);
-			}
-		}
-		std::vector<std::vector<GEdge*> > VecOfVec;
-		VecOfVec.push_back(newEdgesVector);
-		//creation de la nouvelle face
-		GFace* GFaceAssociation = m->addPlanarFace(VecOfVec);
-		//maintenant traitement mesh
-		for (unsigned int i = 0; i < fTmp->mesh_vertices.size();i++){
-			MVertex *vMesh = fTmp->mesh_vertices[i];
-			MVertex *newMv = new MVertex(vMesh->x(), vMesh->y(), vMesh->z(), (GEntity*)GFaceAssociation);
-			VertexAssociation[vMesh] = newMv;
-			GFaceAssociation->addMeshVertex(newMv);
-		}
-		for (unsigned int i = 0; i < fTmp->getNumMeshElements();i++){
-			MElement* elem = fTmp->getMeshElement(i);
-			MVertex *firstE = VertexAssociation.find(elem->getVertex(0))->second;
-			MVertex *secondE = VertexAssociation.find(elem->getVertex(1))->second;
-			MVertex *thirdE = VertexAssociation.find(elem->getVertex(2))->second;
-			MTriangle *newTri = new MTriangle(firstE,secondE,thirdE);
-			GFaceAssociation->addTriangle(newTri);
-		}
-		std::vector<GFace*> VectorFaces;
-		std::list<GFace*> listFaces;
-		VectorFaces.push_back(fTmp);
-		listFaces.push_back(fTmp);
-		for (unsigned int i = 0;i < SurroundingsFaces.size();i++){
-			VectorFaces.push_back(SurroundingsFaces[i]);
-			listFaces.push_back(SurroundingsFaces[i]);
-		}
-		VectorFaces.push_back(GFaceAssociation);
-		listFaces.push_back(GFaceAssociation);
-		std::vector<std::vector<GFace*> > VecOfVecGFace;
-		VecOfVecGFace.push_back(VectorFaces);
-		//creation de la nouvelle region
-
-		GRegion* createdRegion = new GRegion(m,counterNbDone);
-		createdRegion->set(listFaces);
-		createdRegion->addPhysicalEntity(PhysicalInterface);
-		m->add(createdRegion);
-
-
-		std::list<GFace*> RegFaces = rTmp->faces();
-		std::list<GFace*>::iterator it = std::find(RegFaces.begin(), RegFaces.end(), fTmp);
-		std::cout<<(*it)->tag()<<std::endl;
-		if(it != RegFaces.end()) RegFaces.erase(it);
-		RegFaces.push_back(GFaceAssociation);
-		rTmp->set(RegFaces);
-		std::list<GFace*> NewFacesReg;
-		NewFacesReg = rTmp->faces();
-		for (std::list<GFace*>::iterator it2=NewFacesReg.begin();it2!=NewFacesReg.end();it2++){
-			GFace* fTemp = (*it2);
-			for (std::list<GEdge*>::iterator ite = elist.begin();ite != elist.end();ite++){
-				GEdge* eTmp = (*ite);
-				GEdge* newE = GEdgeAssociation[eTmp];
-				fTemp->replaceEdge(eTmp,newE);
-			}
-		}
-
-
-		for (unsigned int i = 0; i < fTmp->getNumMeshElements();i++){
-			MElement* elem = fTmp->getMeshElement(i);
-			MVertex *firstE = VertexAssociation.find(elem->getVertex(0))->second;
-			MVertex *secondE = VertexAssociation.find(elem->getVertex(1))->second;
-			MVertex *thirdE = VertexAssociation.find(elem->getVertex(2))->second;
-			MPrism *newPri = new MPrism(elem->getVertex(0),elem->getVertex(1),elem->getVertex(2),firstE,secondE,thirdE);
-
-			createdRegion->addPrism(newPri);
-		}
-		for (unsigned int i = 0; i < rTmp->getNumMeshElements();i++){
-			MElement* elem = rTmp->getMeshElement(i);
-			for (int j = 0;j < elem->getNumVertices();j++){
-				MVertex* vert = elem->getVertex(j);
-				std::map<MVertex*,MVertex* >::iterator itMap = VertexAssociation.find(vert);
-				if (itMap != VertexAssociation.end()){
-					elem->setVertex(j,itMap->second);
-				}
-			}
-		}
-
-
-		int countTmp = 0;
-		//maitenant refonte points dans faces
-		for (std::list<GFace*>::iterator itTmp = NewFacesReg.begin();itTmp != NewFacesReg.end();itTmp++){
-			GFace* GFaceTmp = (*itTmp);
-			countTmp++;
-			for (unsigned int i = 0; i < GFaceTmp->getNumMeshElements();i++){
-				MElement* elem = GFaceTmp->getMeshElement(i);
-				for (int j = 0;j < elem->getNumVertices();j++){
-					MVertex* vert = elem->getVertex(j);
-					std::map<MVertex*,MVertex* >::iterator itMap = VertexAssociation.find(vert);
-					if (itMap != VertexAssociation.end()){
-						elem->setVertex(j,itMap->second);
-						std::vector<MVertex*> FaceVerti = GFaceTmp->mesh_vertices;
-						std::vector<MVertex*>::iterator itHere = std::find(FaceVerti.begin(), FaceVerti.end(), vert);
-						if(itHere != FaceVerti.end()) {
-							FaceVerti.erase(itHere);
-							FaceVerti.push_back(itMap->second);
-							GFaceTmp->mesh_vertices = FaceVerti;
-						}
-					}
-				}
-			}
-		}
-
-
-	}
-
-/*
-	//now we put all info into a file
-	//to being with we put all boundary vertices into a unique set
-	std::vector<MEdge*> ListBoundaryVectors;
-	for (GModel::fiter itf= m->firstFace();itf != m->lastFace();itf++){
-		GFace* fTmp = (*itf);
-		if (fTmp->regions().size() == 1){
-			//for each node we are going to test the displacement
-			std::list<GEdge*> elist = fTmp->edges();
-			for (std::list<GEdge*>::iterator ite = elist.begin();ite != elist.end();ite++){
-
-			}
-		}
-	}
-	std::ofstream file2("PeriodicMatches.txt");
-	file2 << "PeriodicalNodes\n\n";
-	file2 << "Displacement 1.0 0.0 0.0\n\n";
-	file2 << "Displacement 0.0 1.0 0.0\n\n";
-	file2 << "Displacement 0.0 0.0 1.0\n\n";
-*/
-
-
-
-
-
-
-
-	return view;
+  std::cout<<"starting DuplicateBoundaries"<<std::endl;
+  GModel *m = GModel::current();
+  m->setFactory("geo");
+  std::set<GFace*> ToDuplicateList;
+  ToDuplicateList.clear();
+  std::set<GFace*> ToDuplicateListBoundary;
+  ToDuplicateListBoundary.clear();
+  std::vector<GFace*> facesBound;
+  facesBound.clear();
+  std::map<GFace*,SPoint3> centers;
+  std::vector<std::pair<GFace*,GFace*> > pairs;
+  //	int PhysicalSeeds = m->setPhysicalName("Seeds",3);
+  //
+  //	//std::cout<<"number for seeds: "<<PhysicalSeeds<<" and for interface: "<<PhysicalInterface<<std::endl;
+  //
+  //	for (GModel::riter itf= m->firstRegion();itf != m->lastRegion();itf++){
+  //		GRegion* fTmp = (*itf);
+  //		fTmp->addPhysicalEntity(PhysicalSeeds);
+  //	}
+  int PhysicalInterface = m->setPhysicalName("Interface",3);
+  std::cout<<"DEBUT INIT"<<std::endl;
+  for (GModel::fiter itf= m->firstFace();itf != m->lastFace();itf++){
+    GFace* fTmp = (*itf);
+
+    //for (unsigned int i = 0; i < fTmp->getNumMeshElements();i++){
+    //  MElement* elem = fTmp->getMeshElement(i);
+    //}
+
+    if (fTmp->numRegions() == 2){
+      ToDuplicateList.insert(fTmp);
+    }
+    else{
+      facesBound.push_back(fTmp);
+    }
+  }
+
+  for(unsigned int i=0;i<facesBound.size();i++){
+    double x = 0.0;
+    double y = 0.0;
+    double z = 0.0;
+
+    std::list<GVertex*> vertices;
+
+    vertices = facesBound[i]->vertices();
+
+    for(std::list<GVertex*>::iterator it2=vertices.begin();it2!=vertices.end();it2++){
+      x = x + (*it2)->x();
+      y = y + (*it2)->y();
+      z = z + (*it2)->z();
+    }
+
+    x = x/vertices.size();
+    y = y/vertices.size();
+    z = z/vertices.size();
+
+    centers.insert(std::pair<GFace*,SPoint3>(facesBound[i],SPoint3(x,y,z)));
+  }
+
+  for(unsigned int i=0;i<facesBound.size();i++){
+    for(unsigned int j=0;j<facesBound.size();j++){
+      std::map<GFace*,SPoint3>::iterator it3 = centers.find(facesBound[i]);
+      std::map<GFace*,SPoint3>::iterator it4 = centers.find(facesBound[j]);
+
+      SPoint3 p1 = it3->second;
+      SPoint3 p2 = it4->second;
+
+
+      //				categories.push_back(val);
+
+      //				print_segment(p1,p2,file);
+
+      if (abs((p2.x()-p1.x()-1.0))<0.0001){
+        if (abs((p2.y()-p1.y()))<0.0001){
+          if (abs((p2.z()-p1.z()))<0.0001){
+            pairs.push_back(std::pair<GFace*,GFace*>(facesBound[i],facesBound[j]));
+            ToDuplicateListBoundary.insert(facesBound[i]);
+          }else if(abs((p2.z()-p1.z()-1.0))<0.0001){
+            pairs.push_back(std::pair<GFace*,GFace*>(facesBound[i],facesBound[j]));
+            ToDuplicateListBoundary.insert(facesBound[i]);
+          }else if (abs((p1.z()-p2.z()-1.0))<0.0001){
+            pairs.push_back(std::pair<GFace*,GFace*>(facesBound[i],facesBound[j]));
+            ToDuplicateListBoundary.insert(facesBound[i]);
+          }
+        }else if (abs((p2.y()-p1.y()-1.0))<0.0001){
+          if (abs((p2.z()-p1.z()))<0.0001){
+            pairs.push_back(std::pair<GFace*,GFace*>(facesBound[i],facesBound[j]));
+            ToDuplicateListBoundary.insert(facesBound[i]);
+          }else if (abs((p2.z()-p1.z()-1.0))<0.0001){
+            pairs.push_back(std::pair<GFace*,GFace*>(facesBound[i],facesBound[j]));
+            ToDuplicateListBoundary.insert(facesBound[i]);
+          }else if (abs((p1.z()-p2.z()-1.0))<0.0001){
+            pairs.push_back(std::pair<GFace*,GFace*>(facesBound[i],facesBound[j]));
+            ToDuplicateListBoundary.insert(facesBound[i]);
+          }
+        }else if (abs((p1.y()-p2.y()-1.0))<0.0001){
+          if (abs((p2.z()-p1.z()))<0.0001){
+            pairs.push_back(std::pair<GFace*,GFace*>(facesBound[i],facesBound[j]));
+            ToDuplicateListBoundary.insert(facesBound[i]);
+          }else if (abs((p2.z()-p1.z()-1.0))<0.0001){
+            pairs.push_back(std::pair<GFace*,GFace*>(facesBound[i],facesBound[j]));
+            ToDuplicateListBoundary.insert(facesBound[i]);
+          }else if (abs((p1.z()-p2.z()-1.0))<0.0001){
+            pairs.push_back(std::pair<GFace*,GFace*>(facesBound[i],facesBound[j]));
+            ToDuplicateListBoundary.insert(facesBound[i]);
+          }
+        }
+      }else if (abs((p1.x()-p2.x()-1.0))<0.0001){
+        if (abs((p2.y()-p1.y()))<0.0001){
+          if (abs((p2.z()-p1.z()))<0.0001){
+            //NOTHING
+          }else if(abs((p2.z()-p1.z()-1.0))<0.0001){
+            //NOTHING
+          }else if (abs((p1.z()-p2.z()-1.0))<0.0001){
+            //NOTHING
+          }
+        }else if (abs((p2.y()-p1.y()-1.0))<0.0001){
+          if (abs((p2.z()-p1.z()))<0.0001){
+            //NOTHING
+          }else if (abs((p2.z()-p1.z()-1.0))<0.0001){
+            //NOTHING
+          }else if (abs((p1.z()-p2.z()-1.0))<0.0001){
+            //NOTHING
+          }
+        }else if (abs((p1.y()-p2.y()-1.0))<0.0001){
+          if (abs((p2.z()-p1.z()))<0.0001){
+            //NOTHING
+          }else if (abs((p2.z()-p1.z()-1.0))<0.0001){
+            //NOTHING
+          }else if (abs((p1.z()-p2.z()-1.0))<0.0001){
+            //NOTHING
+          }
+        }
+      }else if (abs((p1.x()-p2.x()))<0.0001){
+        if (abs((p2.y()-p1.y()-1.0))<0.0001){
+          if (abs((p2.z()-p1.z()))<0.0001){
+            pairs.push_back(std::pair<GFace*,GFace*>(facesBound[i],facesBound[j]));
+            ToDuplicateListBoundary.insert(facesBound[i]);
+          }else if (abs((p2.z()-p1.z()-1.0))<0.0001){
+            pairs.push_back(std::pair<GFace*,GFace*>(facesBound[i],facesBound[j]));
+            ToDuplicateListBoundary.insert(facesBound[i]);
+          }else if (abs((p1.z()-p2.z()-1.0))<0.0001){
+            pairs.push_back(std::pair<GFace*,GFace*>(facesBound[i],facesBound[j]));
+            ToDuplicateListBoundary.insert(facesBound[i]);
+          }
+        }else if (abs((p1.y()-p2.y()-1.0))<0.0001){
+          if (abs((p2.z()-p1.z()))<0.0001){
+            //NOTHING
+          }else if (abs((p2.z()-p1.z()-1.0))<0.0001){
+            //NOTHING
+          }else if (abs((p1.z()-p2.z()-1.0))<0.0001){
+            //NOTHING
+          }
+        }else if (abs((p1.y()-p2.y()))<0.0001){
+          if (abs((p2.z()-p1.z()-1.0))<0.0001){
+            pairs.push_back(std::pair<GFace*,GFace*>(facesBound[i],facesBound[j]));
+            ToDuplicateListBoundary.insert(facesBound[i]);
+          }else if (abs((p1.z()-p2.z()-1.0))<0.0001){
+            //NOTHING
+          }
+        }
+      }
+    }
+  }
+
+  int counterNbDone = 10000;
+  //int tagEdges = 10000;
+  for (std::set<GFace*>::iterator itr = ToDuplicateList.begin();itr != ToDuplicateList.end();itr++){
+    counterNbDone++;
+    GFace* fTmp = (*itr);
+    //on doit dupliquer la face, les noeuds, les aretes, puis creer une region entre les deux
+    std::map<MVertex*,MVertex* > VertexAssociation;
+    std::map<GVertex*,GVertex* > GVertexAssociation;
+    std::map<GEdge*,GEdge* > GEdgeAssociation;
+    std::list<GVertex*> vlist = fTmp->vertices();
+    std::map<GVertex*,GEdge* > SurroudingEdges;
+    GRegion *rTmp = fTmp->getRegion(1);
+    std::list<GFace*> facesReg;
+    facesReg = rTmp->faces();
+    //for (std::list<GFace*>::iterator it2=facesReg.begin();it2!=facesReg.end();it2++){
+    //  GFace* fTemp = (*it2);
+    //}
+    double xCenterReg = 0.0;
+    double yCenterReg = 0.0;
+    double zCenterReg = 0.0;
+
+    int counterPts = 0;
+    for(std::list<GFace*>::iterator it2=facesReg.begin();it2!=facesReg.end();it2++){
+      GFace* fTemp = (*it2);
+      std::list<GVertex*> verticesFace = fTemp->vertices();
+      for (std::list<GVertex*>::iterator it3=verticesFace.begin();it3!=verticesFace.end();it3++){
+        xCenterReg = xCenterReg + (*it3)->x();
+        yCenterReg = yCenterReg + (*it3)->y();
+        zCenterReg = zCenterReg + (*it3)->z();
+        counterPts++;
+      }
+    }
+
+    xCenterReg = xCenterReg/counterPts;
+    yCenterReg = yCenterReg/counterPts;
+    zCenterReg = zCenterReg/counterPts;
+
+    for (std::list<GVertex*>::iterator itv = vlist.begin();itv != vlist.end();itv++){
+      //duplication Gvertex
+      GVertex* vTmp = (*itv);
+      double ponderatedX = 0.99999999999 * vTmp->x() + 0.00000000001 * xCenterReg;
+      double ponderatedY = 0.99999999999 * vTmp->y() + 0.00000000001 * yCenterReg;
+      double ponderatedZ = 0.99999999999 * vTmp->z() + 0.00000000001 * zCenterReg;
+      //			double ponderatedX = 1.0 * vTmp->x() + 0.0 * xCenterReg;
+      //			double ponderatedY = 1.0 * vTmp->y() + 0.0 * yCenterReg;
+      //			double ponderatedZ = 1.0 * vTmp->z() + 0.0 * zCenterReg;
+      //GVertex* newv = new gmshVertex(m,vTmp->prescribedMeshSizeAtVertex());
+      GVertex* newv = m->addVertex(ponderatedX,ponderatedY,ponderatedZ,vTmp->prescribedMeshSizeAtVertex());
+      GVertexAssociation[vTmp] = newv;
+      //creation des Gedge correspondantes
+      //GEdge* newE = new GEdge(m,tagEdges,vTmp,newv);
+      //tagEdges++;
+      //m->add(newE);
+      GEdge* newE = m->addLine(vTmp,newv);
+      SurroudingEdges[vTmp] = newE;
+      //maintenant traitement mesh
+      MVertex *vMesh = vTmp->mesh_vertices[0];
+      MVertex *newMv = new MVertex(vMesh->x(), vMesh->y(), vMesh->z(), (GEntity*)newv);
+      VertexAssociation[vMesh] = newMv;
+      newv->addMeshVertex(newMv);
+    }
+    std::list<GEdge*> elist = fTmp->edges();
+    std::vector<GEdge*> newEdgesVector;
+    std::vector<GFace*> SurroundingsFaces;
+    for (std::list<GEdge*>::iterator ite = elist.begin();ite != elist.end();ite++){
+      //duplication Gedge
+      GEdge* eTmp = (*ite);
+      GEdge* newE = m->addLine(GVertexAssociation[eTmp->getEndVertex()],GVertexAssociation[eTmp->getBeginVertex()]);
+      GEdgeAssociation[eTmp] = newE;
+      newEdgesVector.push_back(newE);
+      //creation des GFace correspondantes
+      GEdge* firstE = SurroudingEdges.find(eTmp->getEndVertex())->second;
+      GEdge* lastE = SurroudingEdges.find(eTmp->getBeginVertex())->second;
+      std::vector<GEdge*> VecEdgesTmp;
+      VecEdgesTmp.push_back(eTmp);
+      VecEdgesTmp.push_back(firstE);
+      VecEdgesTmp.push_back(newE);
+      VecEdgesTmp.push_back(lastE);
+      std::vector<std::vector<GEdge*> > VecOfVecTmp;
+      VecOfVecTmp.push_back(VecEdgesTmp);
+      GFace* newFaceTmp = m->addPlanarFace(VecOfVecTmp);
+      SurroundingsFaces.push_back(newFaceTmp);
+      //maintenant traitement mesh
+      for (unsigned int i = 0; i < eTmp->mesh_vertices.size();i++){
+        MVertex *vMesh = eTmp->mesh_vertices[i];
+        MVertex *newMv = new MVertex(vMesh->x(), vMesh->y(), vMesh->z(), (GEntity*)newE);
+        VertexAssociation[vMesh] = newMv;
+        newE->addMeshVertex(newMv);
+      }
+      for (unsigned int i = 0; i < eTmp->getNumMeshElements();i++){
+        MElement* elem = eTmp->getMeshElement(i);
+        MVertex *firstETmp = VertexAssociation.find(elem->getVertex(0))->second;
+        MVertex *lastETmp = VertexAssociation.find(elem->getVertex(1))->second;
+        MLine *newLine = new MLine(firstETmp,lastETmp);
+        newE->addLine(newLine);
+      }
+    }
+    std::vector<std::vector<GEdge*> > VecOfVec;
+    VecOfVec.push_back(newEdgesVector);
+    //creation de la nouvelle face
+    GFace* GFaceAssociation = m->addPlanarFace(VecOfVec);
+    //maintenant traitement mesh
+    for (unsigned int i = 0; i < fTmp->mesh_vertices.size();i++){
+      MVertex *vMesh = fTmp->mesh_vertices[i];
+      MVertex *newMv = new MVertex(vMesh->x(), vMesh->y(), vMesh->z(), (GEntity*)GFaceAssociation);
+      VertexAssociation[vMesh] = newMv;
+      GFaceAssociation->addMeshVertex(newMv);
+    }
+    for (unsigned int i = 0; i < fTmp->getNumMeshElements();i++){
+      MElement* elem = fTmp->getMeshElement(i);
+      MVertex *firstE = VertexAssociation.find(elem->getVertex(0))->second;
+      MVertex *secondE = VertexAssociation.find(elem->getVertex(1))->second;
+      MVertex *thirdE = VertexAssociation.find(elem->getVertex(2))->second;
+      MTriangle *newTri = new MTriangle(firstE,secondE,thirdE);
+      GFaceAssociation->addTriangle(newTri);
+
+
+
+    }
+    std::vector<GFace*> VectorFaces;
+    std::list<GFace*> listFaces;
+    VectorFaces.push_back(fTmp);
+    listFaces.push_back(fTmp);
+    for (unsigned int i = 0;i < SurroundingsFaces.size();i++){
+      VectorFaces.push_back(SurroundingsFaces[i]);
+      listFaces.push_back(SurroundingsFaces[i]);
+    }
+    VectorFaces.push_back(GFaceAssociation);
+    listFaces.push_back(GFaceAssociation);
+    std::vector<std::vector<GFace*> > VecOfVecGFace;
+    VecOfVecGFace.push_back(VectorFaces);
+    //creation de la nouvelle region
+
+    GRegion* createdRegion = new GRegion(m,counterNbDone);
+    createdRegion->addPhysicalEntity(PhysicalInterface);
+    createdRegion->set(listFaces);
+    m->add(createdRegion);
+    std::list<GFace*> RegFaces = rTmp->faces();
+    std::list<GFace*>::iterator it = std::find(RegFaces.begin(), RegFaces.end(), fTmp);
+    std::cout<<(*it)->tag()<<std::endl;
+    if(it != RegFaces.end()) RegFaces.erase(it);
+    RegFaces.push_back(GFaceAssociation);
+    rTmp->set(RegFaces);
+    std::list<GFace*> NewFacesReg;
+    NewFacesReg = rTmp->faces();
+    for (std::list<GFace*>::iterator it2=NewFacesReg.begin();it2!=NewFacesReg.end();it2++){
+      GFace* fTemp = (*it2);
+      for (std::list<GEdge*>::iterator ite = elist.begin();ite != elist.end();ite++){
+        GEdge* eTmp = (*ite);
+        GEdge* newE = GEdgeAssociation[eTmp];
+        fTemp->replaceEdge(eTmp,newE);
+      }
+    }
+    for (unsigned int i = 0; i < fTmp->getNumMeshElements();i++){
+      MElement* elem = fTmp->getMeshElement(i);
+
+
+
+      MVertex *firstE = VertexAssociation.find(elem->getVertex(0))->second;
+      MVertex *secondE = VertexAssociation.find(elem->getVertex(1))->second;
+      MVertex *thirdE = VertexAssociation.find(elem->getVertex(2))->second;
+
+
+
+      MPrism *newPri = new MPrism(elem->getVertex(0),elem->getVertex(1),elem->getVertex(2),firstE,secondE,thirdE);
+
+      createdRegion->addPrism(newPri);
+    }
+    for (unsigned int i = 0; i < rTmp->getNumMeshElements();i++){
+      MElement* elem = rTmp->getMeshElement(i);
+      for (int j = 0;j < elem->getNumVertices();j++){
+        MVertex* vert = elem->getVertex(j);
+        std::map<MVertex*,MVertex* >::iterator itMap = VertexAssociation.find(vert);
+        if (itMap != VertexAssociation.end()){
+          elem->setVertex(j,itMap->second);
+        }
+      }
+    }
+    int countTmp = 0;
+    //maitenant refonte points dans faces
+    for (std::list<GFace*>::iterator itTmp = NewFacesReg.begin();itTmp != NewFacesReg.end();itTmp++){
+      GFace* GFaceTmp = (*itTmp);
+      countTmp++;
+      for (unsigned int i = 0; i < GFaceTmp->getNumMeshElements();i++){
+        MElement* elem = GFaceTmp->getMeshElement(i);
+        for (int j = 0;j < elem->getNumVertices();j++){
+          MVertex* vert = elem->getVertex(j);
+          std::map<MVertex*,MVertex* >::iterator itMap = VertexAssociation.find(vert);
+          if (itMap != VertexAssociation.end()){
+            elem->setVertex(j,itMap->second);
+
+
+
+            std::vector<MVertex*> FaceVerti = GFaceTmp->mesh_vertices;
+            std::vector<MVertex*>::iterator itHere = std::find(FaceVerti.begin(), FaceVerti.end(), vert);
+            if(itHere != FaceVerti.end()) {
+              FaceVerti.erase(itHere);
+              FaceVerti.push_back(itMap->second);
+              GFaceTmp->mesh_vertices = FaceVerti;
+            }
+
+
+          }
+        }
+      }
+    }
+  }
+
+  //maintenant on attaque les faces au bord
+  for (std::set<GFace*>::iterator itr = ToDuplicateListBoundary.begin();itr != ToDuplicateListBoundary.end();itr++){
+    counterNbDone++;
+    GFace* fTmp = (*itr);
+    //on doit dupliquer la face, les noeuds, les aretes, puis creer une region entre les deux
+    std::map<MVertex*,MVertex* > VertexAssociation;
+    std::map<GVertex*,GVertex* > GVertexAssociation;
+    std::map<GEdge*,GEdge* > GEdgeAssociation;
+    std::list<GVertex*> vlist = fTmp->vertices();
+    std::map<GVertex*,GEdge* > SurroudingEdges;
+    GRegion *rTmp = fTmp->getRegion(0);
+    double xCenterReg = 0.0;
+    double yCenterReg = 0.0;
+    double zCenterReg = 0.0;
+
+    std::list<GFace*> facesReg;
+
+    facesReg = rTmp->faces();
+
+    int counterPts = 0;
+    for(std::list<GFace*>::iterator it2=facesReg.begin();it2!=facesReg.end();it2++){
+      GFace* fTemp = (*it2);
+      std::list<GVertex*> verticesFace = fTemp->vertices();
+      for (std::list<GVertex*>::iterator it3=verticesFace.begin();it3!=verticesFace.end();it3++){
+        xCenterReg = xCenterReg + (*it3)->x();
+        yCenterReg = yCenterReg + (*it3)->y();
+        zCenterReg = zCenterReg + (*it3)->z();
+        counterPts++;
+      }
+    }
+
+    xCenterReg = xCenterReg/counterPts;
+    yCenterReg = yCenterReg/counterPts;
+    zCenterReg = zCenterReg/counterPts;
+
+    for (std::list<GVertex*>::iterator itv = vlist.begin();itv != vlist.end();itv++){
+      //duplication Gvertex
+      GVertex* vTmp = (*itv);
+      double ponderatedX = 0.99999999999 * vTmp->x() + 0.00000000001 * xCenterReg;
+      double ponderatedY = 0.99999999999 * vTmp->y() + 0.00000000001 * yCenterReg;
+      double ponderatedZ = 0.99999999999 * vTmp->z() + 0.00000000001 * zCenterReg;
+      GVertex* newv = m->addVertex(ponderatedX,ponderatedY,ponderatedZ,vTmp->prescribedMeshSizeAtVertex());
+      GVertexAssociation[vTmp] = newv;
+      //creation des Gedge correspondantes
+      GEdge* newE = m->addLine(vTmp,newv);
+      SurroudingEdges[vTmp] = newE;
+      //maintenant traitement mesh
+      MVertex *vMesh = vTmp->mesh_vertices[0];
+      MVertex *newMv = new MVertex(vMesh->x(), vMesh->y(), vMesh->z(), (GEntity*)newv);
+      VertexAssociation[vMesh] = newMv;
+      newv->addMeshVertex(newMv);
+    }
+    std::list<GEdge*> elist = fTmp->edges();
+    std::vector<GEdge*> newEdgesVector;
+    std::vector<GFace*> SurroundingsFaces;
+    for (std::list<GEdge*>::iterator ite = elist.begin();ite != elist.end();ite++){
+      //duplication Gedge
+      GEdge* eTmp = (*ite);
+      GEdge* newE = m->addLine(GVertexAssociation[eTmp->getEndVertex()],GVertexAssociation[eTmp->getBeginVertex()]);
+      GEdgeAssociation[eTmp] = newE;
+      newEdgesVector.push_back(newE);
+      //creation des GFace correspondantes
+      GEdge* firstE = SurroudingEdges.find(eTmp->getEndVertex())->second;
+      GEdge* lastE = SurroudingEdges.find(eTmp->getBeginVertex())->second;
+      std::vector<GEdge*> VecEdgesTmp;
+      VecEdgesTmp.push_back(eTmp);
+      VecEdgesTmp.push_back(firstE);
+      VecEdgesTmp.push_back(newE);
+      VecEdgesTmp.push_back(lastE);
+      std::vector<std::vector<GEdge*> > VecOfVecTmp;
+      VecOfVecTmp.push_back(VecEdgesTmp);
+      GFace* newFaceTmp = m->addPlanarFace(VecOfVecTmp);
+      SurroundingsFaces.push_back(newFaceTmp);
+      //maintenant traitement mesh
+      for (unsigned int i = 0; i < eTmp->mesh_vertices.size();i++){
+        MVertex *vMesh = eTmp->mesh_vertices[i];
+        MVertex *newMv = new MVertex(vMesh->x(), vMesh->y(), vMesh->z(), (GEntity*)newE);
+        VertexAssociation[vMesh] = newMv;
+        newE->addMeshVertex(newMv);
+      }
+      for (unsigned int i = 0; i < eTmp->getNumMeshElements();i++){
+        MElement* elem = eTmp->getMeshElement(i);
+        MVertex *firstETmp = VertexAssociation.find(elem->getVertex(0))->second;
+        MVertex *lastETmp = VertexAssociation.find(elem->getVertex(1))->second;
+        MLine *newLine = new MLine(firstETmp,lastETmp);
+        newE->addLine(newLine);
+      }
+    }
+    std::vector<std::vector<GEdge*> > VecOfVec;
+    VecOfVec.push_back(newEdgesVector);
+    //creation de la nouvelle face
+    GFace* GFaceAssociation = m->addPlanarFace(VecOfVec);
+    //maintenant traitement mesh
+    for (unsigned int i = 0; i < fTmp->mesh_vertices.size();i++){
+      MVertex *vMesh = fTmp->mesh_vertices[i];
+      MVertex *newMv = new MVertex(vMesh->x(), vMesh->y(), vMesh->z(), (GEntity*)GFaceAssociation);
+      VertexAssociation[vMesh] = newMv;
+      GFaceAssociation->addMeshVertex(newMv);
+    }
+    for (unsigned int i = 0; i < fTmp->getNumMeshElements();i++){
+      MElement* elem = fTmp->getMeshElement(i);
+      MVertex *firstE = VertexAssociation.find(elem->getVertex(0))->second;
+      MVertex *secondE = VertexAssociation.find(elem->getVertex(1))->second;
+      MVertex *thirdE = VertexAssociation.find(elem->getVertex(2))->second;
+      MTriangle *newTri = new MTriangle(firstE,secondE,thirdE);
+      GFaceAssociation->addTriangle(newTri);
+    }
+    std::vector<GFace*> VectorFaces;
+    std::list<GFace*> listFaces;
+    VectorFaces.push_back(fTmp);
+    listFaces.push_back(fTmp);
+    for (unsigned int i = 0;i < SurroundingsFaces.size();i++){
+      VectorFaces.push_back(SurroundingsFaces[i]);
+      listFaces.push_back(SurroundingsFaces[i]);
+    }
+    VectorFaces.push_back(GFaceAssociation);
+    listFaces.push_back(GFaceAssociation);
+    std::vector<std::vector<GFace*> > VecOfVecGFace;
+    VecOfVecGFace.push_back(VectorFaces);
+    //creation de la nouvelle region
+
+    GRegion* createdRegion = new GRegion(m,counterNbDone);
+    createdRegion->set(listFaces);
+    createdRegion->addPhysicalEntity(PhysicalInterface);
+    m->add(createdRegion);
+
+
+    std::list<GFace*> RegFaces = rTmp->faces();
+    std::list<GFace*>::iterator it = std::find(RegFaces.begin(), RegFaces.end(), fTmp);
+    std::cout<<(*it)->tag()<<std::endl;
+    if(it != RegFaces.end()) RegFaces.erase(it);
+    RegFaces.push_back(GFaceAssociation);
+    rTmp->set(RegFaces);
+    std::list<GFace*> NewFacesReg;
+    NewFacesReg = rTmp->faces();
+    for (std::list<GFace*>::iterator it2=NewFacesReg.begin();it2!=NewFacesReg.end();it2++){
+      GFace* fTemp = (*it2);
+      for (std::list<GEdge*>::iterator ite = elist.begin();ite != elist.end();ite++){
+        GEdge* eTmp = (*ite);
+        GEdge* newE = GEdgeAssociation[eTmp];
+        fTemp->replaceEdge(eTmp,newE);
+      }
+    }
+
+
+    for (unsigned int i = 0; i < fTmp->getNumMeshElements();i++){
+      MElement* elem = fTmp->getMeshElement(i);
+      MVertex *firstE = VertexAssociation.find(elem->getVertex(0))->second;
+      MVertex *secondE = VertexAssociation.find(elem->getVertex(1))->second;
+      MVertex *thirdE = VertexAssociation.find(elem->getVertex(2))->second;
+      MPrism *newPri = new MPrism(elem->getVertex(0),elem->getVertex(1),elem->getVertex(2),firstE,secondE,thirdE);
+
+      createdRegion->addPrism(newPri);
+    }
+    for (unsigned int i = 0; i < rTmp->getNumMeshElements();i++){
+      MElement* elem = rTmp->getMeshElement(i);
+      for (int j = 0;j < elem->getNumVertices();j++){
+        MVertex* vert = elem->getVertex(j);
+        std::map<MVertex*,MVertex* >::iterator itMap = VertexAssociation.find(vert);
+        if (itMap != VertexAssociation.end()){
+          elem->setVertex(j,itMap->second);
+        }
+      }
+    }
+
+
+    int countTmp = 0;
+    //maitenant refonte points dans faces
+    for (std::list<GFace*>::iterator itTmp = NewFacesReg.begin();itTmp != NewFacesReg.end();itTmp++){
+      GFace* GFaceTmp = (*itTmp);
+      countTmp++;
+      for (unsigned int i = 0; i < GFaceTmp->getNumMeshElements();i++){
+        MElement* elem = GFaceTmp->getMeshElement(i);
+        for (int j = 0;j < elem->getNumVertices();j++){
+          MVertex* vert = elem->getVertex(j);
+          std::map<MVertex*,MVertex* >::iterator itMap = VertexAssociation.find(vert);
+          if (itMap != VertexAssociation.end()){
+            elem->setVertex(j,itMap->second);
+            std::vector<MVertex*> FaceVerti = GFaceTmp->mesh_vertices;
+            std::vector<MVertex*>::iterator itHere = std::find(FaceVerti.begin(), FaceVerti.end(), vert);
+            if(itHere != FaceVerti.end()) {
+              FaceVerti.erase(itHere);
+              FaceVerti.push_back(itMap->second);
+              GFaceTmp->mesh_vertices = FaceVerti;
+            }
+          }
+        }
+      }
+    }
+
+
+  }
+
+  /*
+  //now we put all info into a file
+  //to being with we put all boundary vertices into a unique set
+  std::vector<MEdge*> ListBoundaryVectors;
+  for (GModel::fiter itf= m->firstFace();itf != m->lastFace();itf++){
+  GFace* fTmp = (*itf);
+  if (fTmp->regions().size() == 1){
+  //for each node we are going to test the displacement
+  std::list<GEdge*> elist = fTmp->edges();
+  for (std::list<GEdge*>::iterator ite = elist.begin();ite != elist.end();ite++){
+
+  }
+  }
+  }
+  std::ofstream file2("PeriodicMatches.txt");
+  file2 << "PeriodicalNodes\n\n";
+  file2 << "Displacement 1.0 0.0 0.0\n\n";
+  file2 << "Displacement 0.0 1.0 0.0\n\n";
+  file2 << "Displacement 0.0 0.0 1.0\n\n";
+  */
+
+
+
+
+
+
+
+  return view;
 }
 
 PView *GMSH_DuplicateBoundariesPlugin::executeFourth(PView *view)
 {
-	GModel *m = GModel::current();
-	m->setFactory("geo");
-	std::set<GFace*> ToDuplicateList;
-	ToDuplicateList.clear();
-	std::set<GFace*> ToDuplicateListBoundary;
-	ToDuplicateListBoundary.clear();
-	std::vector<GFace*> facesBound;
-	facesBound.clear();
-	std::map<GFace*,SPoint3> centers;
-	std::vector<std::pair<GFace*,GFace*> > pairs;
-	std::vector<std::pair<GFace*,GFace*> > newPairs;
-	int PhysicalInterface = m->setPhysicalName("Interface",3);
-	for (GModel::fiter itf= m->firstFace();itf != m->lastFace();itf++){
-		GFace* fTmp = (*itf);
-		if (fTmp->numRegions() == 2){
-			ToDuplicateList.insert(fTmp);
-		}
-		else{
-			ToDuplicateListBoundary.insert(fTmp);
-			facesBound.push_back(fTmp);
-		}
-	}
-
-
-
-
-
-
-
-
-	for(unsigned int i=0;i<facesBound.size();i++){
-		double x = 0.0;
-		double y = 0.0;
-		double z = 0.0;
-
-		std::list<GVertex*> vertices;
-
-		vertices = facesBound[i]->vertices();
-
-		for(std::list<GVertex*>::iterator it2=vertices.begin();it2!=vertices.end();it2++){
-			x = x + (*it2)->x();
-			y = y + (*it2)->y();
-			z = z + (*it2)->z();
-		}
-
-		x = x/vertices.size();
-		y = y/vertices.size();
-		z = z/vertices.size();
-
-		centers.insert(std::pair<GFace*,SPoint3>(facesBound[i],SPoint3(x,y,z)));
-	}
-
-	for(unsigned int i=0;i<facesBound.size();i++){
-		for(unsigned int j=0;j<facesBound.size();j++){
-			std::map<GFace*,SPoint3>::iterator it3 = centers.find(facesBound[i]);
-			std::map<GFace*,SPoint3>::iterator it4 = centers.find(facesBound[j]);
-
-			SPoint3 p1 = it3->second;
-			SPoint3 p2 = it4->second;
-
-
-			//				categories.push_back(val);
-
-			//				print_segment(p1,p2,file);
-
-			if (abs((p2.x()-p1.x()-1.0))<0.0001){
-				if (abs((p2.y()-p1.y()))<0.0001){
-					if (abs((p2.z()-p1.z()))<0.0001){
-						pairs.push_back(std::pair<GFace*,GFace*>(facesBound[i],facesBound[j]));
-						ToDuplicateListBoundary.insert(facesBound[i]);
-					}else if(abs((p2.z()-p1.z()-1.0))<0.0001){
-						pairs.push_back(std::pair<GFace*,GFace*>(facesBound[i],facesBound[j]));
-						ToDuplicateListBoundary.insert(facesBound[i]);
-					}else if (abs((p1.z()-p2.z()-1.0))<0.0001){
-						pairs.push_back(std::pair<GFace*,GFace*>(facesBound[i],facesBound[j]));
-						ToDuplicateListBoundary.insert(facesBound[i]);
-					}
-				}else if (abs((p2.y()-p1.y()-1.0))<0.0001){
-					if (abs((p2.z()-p1.z()))<0.0001){
-						pairs.push_back(std::pair<GFace*,GFace*>(facesBound[i],facesBound[j]));
-						ToDuplicateListBoundary.insert(facesBound[i]);
-					}else if (abs((p2.z()-p1.z()-1.0))<0.0001){
-						pairs.push_back(std::pair<GFace*,GFace*>(facesBound[i],facesBound[j]));
-						ToDuplicateListBoundary.insert(facesBound[i]);
-					}else if (abs((p1.z()-p2.z()-1.0))<0.0001){
-						pairs.push_back(std::pair<GFace*,GFace*>(facesBound[i],facesBound[j]));
-						ToDuplicateListBoundary.insert(facesBound[i]);
-					}
-				}else if (abs((p1.y()-p2.y()-1.0))<0.0001){
-					if (abs((p2.z()-p1.z()))<0.0001){
-						pairs.push_back(std::pair<GFace*,GFace*>(facesBound[i],facesBound[j]));
-						ToDuplicateListBoundary.insert(facesBound[i]);
-					}else if (abs((p2.z()-p1.z()-1.0))<0.0001){
-						pairs.push_back(std::pair<GFace*,GFace*>(facesBound[i],facesBound[j]));
-						ToDuplicateListBoundary.insert(facesBound[i]);
-					}else if (abs((p1.z()-p2.z()-1.0))<0.0001){
-						pairs.push_back(std::pair<GFace*,GFace*>(facesBound[i],facesBound[j]));
-						ToDuplicateListBoundary.insert(facesBound[i]);
-					}
-				}
-			}else if (abs((p1.x()-p2.x()-1.0))<0.0001){
-				if (abs((p2.y()-p1.y()))<0.0001){
-					if (abs((p2.z()-p1.z()))<0.0001){
-						//NOTHING
-					}else if(abs((p2.z()-p1.z()-1.0))<0.0001){
-						//NOTHING
-					}else if (abs((p1.z()-p2.z()-1.0))<0.0001){
-						//NOTHING
-					}
-				}else if (abs((p2.y()-p1.y()-1.0))<0.0001){
-					if (abs((p2.z()-p1.z()))<0.0001){
-						//NOTHING
-					}else if (abs((p2.z()-p1.z()-1.0))<0.0001){
-						//NOTHING
-					}else if (abs((p1.z()-p2.z()-1.0))<0.0001){
-						//NOTHING
-					}
-				}else if (abs((p1.y()-p2.y()-1.0))<0.0001){
-					if (abs((p2.z()-p1.z()))<0.0001){
-						//NOTHING
-					}else if (abs((p2.z()-p1.z()-1.0))<0.0001){
-						//NOTHING
-					}else if (abs((p1.z()-p2.z()-1.0))<0.0001){
-						//NOTHING
-					}
-				}
-			}else if (abs((p1.x()-p2.x()))<0.0001){
-				if (abs((p2.y()-p1.y()-1.0))<0.0001){
-					if (abs((p2.z()-p1.z()))<0.0001){
-						pairs.push_back(std::pair<GFace*,GFace*>(facesBound[i],facesBound[j]));
-						ToDuplicateListBoundary.insert(facesBound[i]);
-					}else if (abs((p2.z()-p1.z()-1.0))<0.0001){
-						pairs.push_back(std::pair<GFace*,GFace*>(facesBound[i],facesBound[j]));
-						ToDuplicateListBoundary.insert(facesBound[i]);
-					}else if (abs((p1.z()-p2.z()-1.0))<0.0001){
-						pairs.push_back(std::pair<GFace*,GFace*>(facesBound[i],facesBound[j]));
-						ToDuplicateListBoundary.insert(facesBound[i]);
-					}
-				}else if (abs((p1.y()-p2.y()-1.0))<0.0001){
-					if (abs((p2.z()-p1.z()))<0.0001){
-						//NOTHING
-					}else if (abs((p2.z()-p1.z()-1.0))<0.0001){
-						//NOTHING
-					}else if (abs((p1.z()-p2.z()-1.0))<0.0001){
-						//NOTHING
-					}
-				}else if (abs((p1.y()-p2.y()))<0.0001){
-					if (abs((p2.z()-p1.z()-1.0))<0.0001){
-						pairs.push_back(std::pair<GFace*,GFace*>(facesBound[i],facesBound[j]));
-						ToDuplicateListBoundary.insert(facesBound[i]);
-					}else if (abs((p1.z()-p2.z()-1.0))<0.0001){
-						//NOTHING
-					}
-				}
-			}
-		}
-	}
-
-
-
-
-
-
-
-
-
-
-	std::map<std::pair<MVertex*,GRegion*>,MVertex* > VertexGlobalAssociation;
-	std::map<std::pair<GVertex*,GRegion*>,GVertex* > GVertexGlobalAssociation;
-	std::map<std::pair<GEdge*,GRegion*>,GEdge* > GEdgeGlobalAssociation;
-	std::map<std::pair<GFace*,GRegion*>,GFace* > GFaceGlobalAssociation;
-
-	for (GModel::riter itr= m->firstRegion();itr != m->lastRegion();itr++){
-		GRegion* rTmp = (*itr);
-		std::list<GFace*> RegFaces = rTmp->faces();
-		std::map<MVertex*,MVertex* > VertexAssociation;
-		std::map<GVertex*,GVertex* > GVertexAssociation;
-		std::map<GEdge*,GEdge* > GEdgeAssociation;
-		//int counterNbDone = 10000;
-		double xCenterReg = 0.0;
-		double yCenterReg = 0.0;
-		double zCenterReg = 0.0;
-		int counterPts = 0;
-		for(std::list<GFace*>::iterator it2=RegFaces.begin();it2!=RegFaces.end();it2++){
-			GFace* fTemp = (*it2);
-			std::list<GVertex*> verticesFace = fTemp->vertices();
-			for (std::list<GVertex*>::iterator it3=verticesFace.begin();it3!=verticesFace.end();it3++){
-				xCenterReg = xCenterReg + (*it3)->x();
-				yCenterReg = yCenterReg + (*it3)->y();
-				zCenterReg = zCenterReg + (*it3)->z();
-				counterPts++;
-			}
-		}
-		xCenterReg = xCenterReg/counterPts;
-		yCenterReg = yCenterReg/counterPts;
-		zCenterReg = zCenterReg/counterPts;
-		//duplication noeud et aretes au niveau de la region directement
-		std::list<GVertex*> vlist;
-
-
-		std::list<GFace*> listFacesTmp = rTmp->faces();
-		for (std::list<GFace*>::iterator itTp = listFacesTmp.begin();itTp != listFacesTmp.end();itTp++){
-			std::list<GVertex*> vlist2;
-			vlist2 = (*itTp)->vertices();
-			for (std::list<GVertex*>::iterator itTp2 = vlist2.begin();itTp2 != vlist2.end();itTp2++){
-				if(std::find(vlist.begin(), vlist.end(), *itTp2) == vlist.end())
-					vlist.push_back(*itTp2);
-			}
-		}
-
-
-		for (std::list<GVertex*>::iterator itv = vlist.begin();itv != vlist.end();itv++){
-			//duplication Gvertex
-			GVertex* vTmp = (*itv);
-			double ponderatedX = 0.99999999999 * vTmp->x() + 0.00000000001 * xCenterReg;
-			double ponderatedY = 0.99999999999 * vTmp->y() + 0.00000000001 * yCenterReg;
-			double ponderatedZ = 0.99999999999 * vTmp->z() + 0.00000000001 * zCenterReg;
-			GVertex* newv = m->addVertex(ponderatedX,ponderatedY,ponderatedZ,vTmp->prescribedMeshSizeAtVertex());
-			GVertexAssociation[vTmp] = newv;
-			GVertexGlobalAssociation[std::make_pair(vTmp,rTmp)] = newv;
-			//creation des Gedge correspondantes
-//			GEdge* newE = m->addLine(vTmp,newv);
-//			SurroudingEdges[vTmp] = newE;
-			//maintenant traitement mesh
-			MVertex *vMesh = vTmp->mesh_vertices[0];
-			MVertex *newMv = new MVertex(vMesh->x(), vMesh->y(), vMesh->z(), (GEntity*)newv);
-			VertexAssociation[vMesh] = newMv;
-			VertexGlobalAssociation[std::make_pair(vMesh,rTmp)] = newMv;
-			newv->addMeshVertex(newMv);
-		}
-		//maintenant on soccupe de duppliquer les edges de la region
-		std::list<GEdge*> elist = rTmp->edges();
-
-		std::vector<GFace*> SurroundingsFaces;
-		for (std::list<GEdge*>::iterator ite = elist.begin();ite != elist.end();ite++){
-			//duplication Gedge
-			GEdge* eTmp = (*ite);
-			GEdge* newE = m->addLine(GVertexAssociation[eTmp->getEndVertex()],GVertexAssociation[eTmp->getBeginVertex()]);
-			GEdgeAssociation[eTmp] = newE;
-			GEdgeGlobalAssociation[std::make_pair(eTmp,rTmp)] = newE;
-			//creation des GFace correspondantes
-//			GEdge* firstE = SurroudingEdges.find(eTmp->getEndVertex())->second;
-//			GEdge* lastE = SurroudingEdges.find(eTmp->getBeginVertex())->second;
-//			std::vector<GEdge*> VecEdgesTmp;
-//			VecEdgesTmp.push_back(eTmp);
-//			VecEdgesTmp.push_back(firstE);
-//			VecEdgesTmp.push_back(newE);
-//			VecEdgesTmp.push_back(lastE);
-//			std::vector<std::vector<GEdge*> > VecOfVecTmp;
-//			VecOfVecTmp.push_back(VecEdgesTmp);
-//			GFace* newFaceTmp = m->addPlanarFace(VecOfVecTmp);
-//			SurroundingsFaces.push_back(newFaceTmp);
-			//maintenant traitement mesh
-			for (unsigned int i = 0; i < eTmp->mesh_vertices.size();i++){
-				MVertex *vMesh = eTmp->mesh_vertices[i];
-				MVertex *newMv = new MVertex(vMesh->x(), vMesh->y(), vMesh->z(), (GEntity*)newE);
-				VertexAssociation[vMesh] = newMv;
-				VertexGlobalAssociation[std::make_pair(vMesh,rTmp)] = newMv;
-				newE->addMeshVertex(newMv);
-			}
-			for (unsigned int i = 0; i < eTmp->getNumMeshElements();i++){
-				MElement* elem = eTmp->getMeshElement(i);
-				MVertex *firstETmp = VertexAssociation.find(elem->getVertex(0))->second;
-				MVertex *lastETmp = VertexAssociation.find(elem->getVertex(1))->second;
-				MLine *newLine = new MLine(firstETmp,lastETmp);
-				newE->addLine(newLine);
-			}
-		}
-		for (std::list<GFace*>::iterator itf = RegFaces.begin();itf != RegFaces.end();itf++){
-			GFace* fTmp = (*itf);
-			std::vector<GEdge*> newEdgesVector;
-			std::list<GEdge*> elistFace = fTmp->edges();
-			for (std::list<GEdge*>::iterator ite = elistFace.begin();ite != elistFace.end();ite++){
-				GEdge* eTmp = (*ite);
-				GEdge* eToFind = GEdgeAssociation[eTmp];
-				newEdgesVector.push_back(eToFind);
-			}
-			std::vector<std::vector<GEdge*> > VecOfVec;
-			VecOfVec.push_back(newEdgesVector);
-			//creation de la nouvelle face
-			GFace* GFaceAssociation = m->addPlanarFace(VecOfVec);
-			//maintenant traitement mesh
-			for (unsigned int i = 0; i < fTmp->mesh_vertices.size();i++){
-				MVertex *vMesh = fTmp->mesh_vertices[i];
-				MVertex *newMv = new MVertex(vMesh->x(), vMesh->y(), vMesh->z(), (GEntity*)GFaceAssociation);
-				VertexAssociation[vMesh] = newMv;
-				VertexGlobalAssociation[std::make_pair(vMesh,rTmp)] = newMv;
-				GFaceAssociation->addMeshVertex(newMv);
-			}
-			for (unsigned int i = 0; i < fTmp->getNumMeshElements();i++){
-				MElement* elem = fTmp->getMeshElement(i);
-				MVertex *firstE = VertexAssociation.find(elem->getVertex(0))->second;
-				MVertex *secondE = VertexAssociation.find(elem->getVertex(1))->second;
-				MVertex *thirdE = VertexAssociation.find(elem->getVertex(2))->second;
-				MTriangle *newTri = new MTriangle(firstE,secondE,thirdE);
-				GFaceAssociation->addTriangle(newTri);
-			}
-			GFaceGlobalAssociation[std::make_pair(fTmp,rTmp)] = GFaceAssociation;
-		}
-	}
-	int counterNbDone = 10000;
-	//maintenant on va traiter les faces initiales
-	for (std::set<GFace*>::iterator itf = ToDuplicateList.begin();itf != ToDuplicateList.end();itf++){
-		counterNbDone++;
-		GFace* fTmp = (*itf);
-		GRegion* reg1 = fTmp->getRegion(0);
-		GRegion* reg2 = fTmp->getRegion(1);
-		//pour commencer on cree des aretes entre les vertex
-		std::list<GVertex*> vlist = fTmp->vertices();
-		std::map<GVertex*,GEdge* > SurroudingEdges;
-		for (std::list<GVertex*>::iterator itv = vlist.begin();itv != vlist.end();itv++){
-			GVertex* vTmp = (*itv);
-			GVertex* v1=0;
-			GVertex* v2=0;
-			std::map<std::pair<GVertex*,GRegion*>,GVertex* >::iterator itMap = GVertexGlobalAssociation.find(std::make_pair(vTmp,reg1));
-			if (itMap != GVertexGlobalAssociation.end()){
-				v1 = itMap->second;
-			}
-			itMap = GVertexGlobalAssociation.find(std::make_pair(vTmp,reg2));
-			if (itMap != GVertexGlobalAssociation.end()){
-				v2 = itMap->second;
-			}
-			GEdge* newE = m->addLine(v1,v2);
-			SurroudingEdges[vTmp] = newE;
-		}
-		//ici tous les vertex sont traites
-		//on va traiter les edges
-		std::list<GEdge*> elist = fTmp->edges();
-		std::vector<GEdge*> newEdgesVector;
-		std::vector<GFace*> SurroundingsFaces;
-		for (std::list<GEdge*>::iterator ite = elist.begin();ite != elist.end();ite++){
-			//duplication Gedge
-			GEdge* eTmp = (*ite);
-			GEdge* e1=0;
-			GEdge* e2=0;
-			std::map<std::pair<GEdge*,GRegion*>,GEdge* >::iterator itMap = GEdgeGlobalAssociation.find(std::make_pair(eTmp,reg1));
-			if (itMap != GEdgeGlobalAssociation.end()){
-				e1 = itMap->second;
-			}
-			itMap = GEdgeGlobalAssociation.find(std::make_pair(eTmp,reg2));
-			if (itMap != GEdgeGlobalAssociation.end()){
-				e2 = itMap->second;
-			}
-			//creation des GFace correspondantes
-			GEdge* firstE = SurroudingEdges.find(eTmp->getBeginVertex())->second;
-			GEdge* lastE = SurroudingEdges.find(eTmp->getEndVertex())->second;
-			if (firstE->getBeginVertex() != e1->getEndVertex()){
-				firstE->reverse();
-			}
-			if (firstE->getBeginVertex() != e1->getEndVertex()){
-				e1->reverse();
-			}
-			if (firstE->getBeginVertex() != e1->getEndVertex()){
-				firstE->reverse();
-			}
-			if (e2->getBeginVertex() != firstE->getEndVertex()){
-				e2->reverse();
-			}
-			if (lastE->getBeginVertex() != e2->getEndVertex()){
-				lastE->reverse();
-			}
-			std::vector<GEdge*> VecEdgesTmp;
-			VecEdgesTmp.push_back(e1);
-			VecEdgesTmp.push_back(firstE);
-			VecEdgesTmp.push_back(e2);
-			VecEdgesTmp.push_back(lastE);
-			std::vector<std::vector<GEdge*> > VecOfVecTmp;
-			VecOfVecTmp.push_back(VecEdgesTmp);
-			GFace* newFaceTmp = m->addPlanarFace(VecOfVecTmp);
-			SurroundingsFaces.push_back(newFaceTmp);
-		}
-		std::vector<GFace*> VectorFaces;
-		std::list<GFace*> listFaces;
-		GFace* f1;
-		GFace* f2;
-		std::map<std::pair<GFace*,GRegion*>,GFace* >::iterator itMap = GFaceGlobalAssociation.find(std::make_pair(fTmp,reg1));
-		if (itMap != GFaceGlobalAssociation.end()){
-			f1 = itMap->second;
-		}
-		itMap = GFaceGlobalAssociation.find(std::make_pair(fTmp,reg2));
-		if (itMap != GFaceGlobalAssociation.end()){
-			f2 = itMap->second;
-		}
-		VectorFaces.push_back(f1);
-		listFaces.push_back(f1);
-		for (unsigned int i = 0;i < SurroundingsFaces.size();i++){
-			VectorFaces.push_back(SurroundingsFaces[i]);
-			listFaces.push_back(SurroundingsFaces[i]);
-		}
-		VectorFaces.push_back(f2);
-		listFaces.push_back(f2);
-		std::vector<std::vector<GFace*> > VecOfVecGFace;
-		VecOfVecGFace.push_back(VectorFaces);
-		//creation de la nouvelle region
-		GRegion* createdRegion = new GRegion(m,counterNbDone);
-		createdRegion->addPhysicalEntity(PhysicalInterface);
-		createdRegion->set(listFaces);
-		m->add(createdRegion);
-		for (unsigned int i = 0; i < fTmp->getNumMeshElements();i++){
-			MElement* elem = fTmp->getMeshElement(i);
-			MVertex* v1=0;
-			MVertex* v2=0;
-			MVertex* v3=0;
-			MVertex* v4=0;
-			MVertex* v5=0;
-			MVertex* v6=0;
-			std::map<std::pair<MVertex*,GRegion*>,MVertex* >::iterator itMap = VertexGlobalAssociation.find(std::make_pair(elem->getVertex(0),reg1));
-			if (itMap != VertexGlobalAssociation.end()){
-				v1 = itMap->second;
-			}
-			itMap = VertexGlobalAssociation.find(std::make_pair(elem->getVertex(1),reg1));
-			if (itMap != VertexGlobalAssociation.end()){
-				v2 = itMap->second;
-			}
-			itMap = VertexGlobalAssociation.find(std::make_pair(elem->getVertex(2),reg1));
-			if (itMap != VertexGlobalAssociation.end()){
-				v3 = itMap->second;
-			}
-			itMap = VertexGlobalAssociation.find(std::make_pair(elem->getVertex(0),reg2));
-			if (itMap != VertexGlobalAssociation.end()){
-				v4 = itMap->second;
-			}
-			itMap = VertexGlobalAssociation.find(std::make_pair(elem->getVertex(1),reg2));
-			if (itMap != VertexGlobalAssociation.end()){
-				v5 = itMap->second;
-			}
-			itMap = VertexGlobalAssociation.find(std::make_pair(elem->getVertex(2),reg2));
-			if (itMap != VertexGlobalAssociation.end()){
-				v6 = itMap->second;
-			}
-			MPrism *newPri = new MPrism(v1,v2,v3,v4,v5,v6);
-
-			createdRegion->addPrism(newPri);
-		}
-		for (unsigned int i = 0; i < reg1->getNumMeshElements();i++){
-			MElement* elem = reg1->getMeshElement(i);
-			for (int j = 0;j < elem->getNumVertices();j++){
-				MVertex* vert = elem->getVertex(j);
-				std::map<std::pair<MVertex*,GRegion*>,MVertex* >::iterator itMap = VertexGlobalAssociation.find(std::make_pair(vert,reg1));
-				if (itMap != VertexGlobalAssociation.end()){
-					elem->setVertex(j,itMap->second);
-				}
-			}
-		}
-		for (unsigned int i = 0; i < reg2->getNumMeshElements();i++){
-			MElement* elem = reg2->getMeshElement(i);
-			for (int j = 0;j < elem->getNumVertices();j++){
-				MVertex* vert = elem->getVertex(j);
-				std::map<std::pair<MVertex*,GRegion*>,MVertex* >::iterator itMap = VertexGlobalAssociation.find(std::make_pair(vert,reg2));
-				if (itMap != VertexGlobalAssociation.end()){
-					elem->setVertex(j,itMap->second);
-				}
-			}
-		}
-	}
-	//maintenant on va traiter les faces du bord
-	for (std::set<GFace*>::iterator itf = ToDuplicateListBoundary.begin();itf != ToDuplicateListBoundary.end();itf++){
-		counterNbDone++;
-		GFace* fTmp = (*itf);
-		GRegion* reg1 = fTmp->getRegion(0);
-		//pour commencer on cree des aretes entre les vertex
-		std::list<GVertex*> vlist = fTmp->vertices();
-		std::map<GVertex*,GEdge* > SurroudingEdges;
-		for (std::list<GVertex*>::iterator itv = vlist.begin();itv != vlist.end();itv++){
-			GVertex* vTmp = (*itv);
-			GVertex* v1=0;
-			std::map<std::pair<GVertex*,GRegion*>,GVertex* >::iterator itMap = GVertexGlobalAssociation.find(std::make_pair(vTmp,reg1));
-			if (itMap != GVertexGlobalAssociation.end()){
-				v1 = itMap->second;
-			}
-			GEdge* newE = m->addLine(v1,vTmp);
-			SurroudingEdges[vTmp] = newE;
-		}
-		//ici tous les vertex sont traites
-		//on va traiter les edges
-		std::list<GEdge*> elist = fTmp->edges();
-		std::vector<GEdge*> newEdgesVector;
-		std::vector<GFace*> SurroundingsFaces;
-		for (std::list<GEdge*>::iterator ite = elist.begin();ite != elist.end();ite++){
-			//duplication Gedge
-			GEdge* eTmp = (*ite);
-			GEdge* e1=0;
-			std::map<std::pair<GEdge*,GRegion*>,GEdge* >::iterator itMap = GEdgeGlobalAssociation.find(std::make_pair(eTmp,reg1));
-			if (itMap != GEdgeGlobalAssociation.end()){
-				e1 = itMap->second;
-			}
-			//creation des GFace correspondantes
-			GEdge* firstE = SurroudingEdges.find(eTmp->getBeginVertex())->second;
-			GEdge* lastE = SurroudingEdges.find(eTmp->getEndVertex())->second;
-			if (firstE->getBeginVertex() != e1->getEndVertex()){
-				firstE->reverse();
-			}
-			if (firstE->getBeginVertex() != e1->getEndVertex()){
-				e1->reverse();
-			}
-			if (firstE->getBeginVertex() != e1->getEndVertex()){
-				firstE->reverse();
-			}
-			if (eTmp->getBeginVertex() != firstE->getEndVertex()){
-				eTmp->reverse();
-			}
-			if (lastE->getBeginVertex() != eTmp->getEndVertex()){
-				lastE->reverse();
-			}
-			std::vector<GEdge*> VecEdgesTmp;
-			VecEdgesTmp.push_back(e1);
-			VecEdgesTmp.push_back(firstE);
-			VecEdgesTmp.push_back(eTmp);
-			VecEdgesTmp.push_back(lastE);
-			std::vector<std::vector<GEdge*> > VecOfVecTmp;
-			VecOfVecTmp.push_back(VecEdgesTmp);
-			GFace* newFaceTmp = m->addPlanarFace(VecOfVecTmp);
-			SurroundingsFaces.push_back(newFaceTmp);
-		}
-		std::vector<GFace*> VectorFaces;
-		std::list<GFace*> listFaces;
-		GFace* f1;
-		std::map<std::pair<GFace*,GRegion*>,GFace* >::iterator itMap = GFaceGlobalAssociation.find(std::make_pair(fTmp,reg1));
-		if (itMap != GFaceGlobalAssociation.end()){
-			f1 = itMap->second;
-		}
-		VectorFaces.push_back(f1);
-		listFaces.push_back(f1);
-		for (unsigned int i = 0;i < SurroundingsFaces.size();i++){
-			VectorFaces.push_back(SurroundingsFaces[i]);
-			listFaces.push_back(SurroundingsFaces[i]);
-		}
-		VectorFaces.push_back(fTmp);
-		listFaces.push_back(fTmp);
-		std::vector<std::vector<GFace*> > VecOfVecGFace;
-		VecOfVecGFace.push_back(VectorFaces);
-		//creation de la nouvelle region
-		GRegion* createdRegion = new GRegion(m,counterNbDone);
-		createdRegion->addPhysicalEntity(PhysicalInterface);
-		createdRegion->set(listFaces);
-		m->add(createdRegion);
-		for (unsigned int i = 0; i < fTmp->getNumMeshElements();i++){
-			MElement* elem = fTmp->getMeshElement(i);
-			MVertex* v1=0;
-			MVertex* v2=0;
-			MVertex* v3=0;
-			std::map<std::pair<MVertex*,GRegion*>,MVertex* >::iterator itMap = VertexGlobalAssociation.find(std::make_pair(elem->getVertex(0),reg1));
-			if (itMap != VertexGlobalAssociation.end()){
-				v1 = itMap->second;
-			}
-			itMap = VertexGlobalAssociation.find(std::make_pair(elem->getVertex(1),reg1));
-			if (itMap != VertexGlobalAssociation.end()){
-				v2 = itMap->second;
-			}
-			itMap = VertexGlobalAssociation.find(std::make_pair(elem->getVertex(2),reg1));
-			if (itMap != VertexGlobalAssociation.end()){
-				v3 = itMap->second;
-			}
-			MPrism *newPri = new MPrism(v1,v2,v3,elem->getVertex(0),elem->getVertex(1),elem->getVertex(2));
-
-			createdRegion->addPrism(newPri);
-		}
-		for (unsigned int i = 0; i < reg1->getNumMeshElements();i++){
-			MElement* elem = reg1->getMeshElement(i);
-			for (int j = 0;j < elem->getNumVertices();j++){
-				MVertex* vert = elem->getVertex(j);
-				std::map<std::pair<MVertex*,GRegion*>,MVertex* >::iterator itMap = VertexGlobalAssociation.find(std::make_pair(vert,reg1));
-				if (itMap != VertexGlobalAssociation.end()){
-					elem->setVertex(j,itMap->second);
-				}
-			}
-		}
-	}
-	std::ofstream file("MicrostructurePolycrystal3D.pos");
-	file << "View \"test\" {\n";
-
-	std::ofstream file2("PERIODIC.map");
-	for (std::vector<std::pair<GFace*,GFace*> >::iterator itP = pairs.begin();itP != pairs.end();itP++){
-		std::pair<GFace*,GFace*> pairTmp = (*itP);
-		GFace* ToReplaceFace = pairTmp.second;
-		GRegion* rTmp = ToReplaceFace->getRegion(0);
-		std::map<std::pair<GFace*,GRegion*>,GFace* >::iterator itMap = GFaceGlobalAssociation.find(std::make_pair(ToReplaceFace,rTmp));
-		if (itMap != GFaceGlobalAssociation.end()){
-			GFace* associatedFace = (*itMap).second;
-
-
-
-
-
-
-			std::map<GFace*,SPoint3>::iterator it3 = centers.find(pairTmp.first);
-			std::map<GFace*,SPoint3>::iterator it4 = centers.find(ToReplaceFace);
-
-			SPoint3 p1 = it3->second;
-			SPoint3  p2 = it4->second;
-
-			//double delta_x = fabs(p2.x()-p1.x());
-			//double delta_y = fabs(p2.y()-p1.y());
-			//double delta_z = fabs(p2.z()-p1.z());
-
-
-			file << "SL ("
-					<< p1.x() << ", " << p1.y() << ", " << p1.z() << ", "
-					<< p2.x() << ", " << p2.y() << ", " << p2.z()
-					<< "){10, 20};\n";
-
-			//file2 << "PERIODIC\tSURFACE"<<faces[i]->tag() << "\tSURFACE" << faces[j]->tag() << "\t" << p2.x()-p1.x() << "\t" << p2.y()-p1.y() << "\t" << p2.z()-p1.z() << "\n";
-			if (abs((p2.x()-p1.x()-1.0))<0.0001){
-				if (abs((p2.y()-p1.y()))<0.0001){
-					if (abs((p2.z()-p1.z()))<0.0001){
-						file2 << "NSET\tFRONT = FRONT + SURFACE"<<ToReplaceFace->tag()<<"\n";
-						file2 << "NSET\tBACK = BACK + SURFACE"<<pairTmp.first->tag()<<"\n";
-					}else if(abs((p2.z()-p1.z()-1.0))<0.0001){
-						file2 << "NSET\tFRONTTOP = FRONTTOP + SURFACE"<<ToReplaceFace->tag()<<"\n";
-						file2 << "NSET\tBACKBOTTOM = BACKBOTTOM + SURFACE"<<pairTmp.first->tag()<<"\n";
-					}else if (abs((p1.z()-p2.z()-1.0))<0.0001){
-						file2 << "NSET\tFRONTBOTTOM = FRONTBOTTOM + SURFACE"<<ToReplaceFace->tag()<<"\n";
-						file2 << "NSET\tBACKTOP = BACKTOP + SURFACE"<<pairTmp.first->tag()<<"\n";
-					}
-				}else if (abs((p2.y()-p1.y()-1.0))<0.0001){
-					if (abs((p2.z()-p1.z()))<0.0001){
-						file2 << "NSET\tFRONTRIGHT = FRONTRIGHT + SURFACE"<<ToReplaceFace->tag()<<"\n";
-						file2 << "NSET\tBACKLEFT = BACKLEFT + SURFACE"<<pairTmp.first->tag()<<"\n";
-					}else if (abs((p2.z()-p1.z()-1.0))<0.0001){
-						file2 << "NSET\tFRONTRIGHTTOP = FRONTRIGHTTOP + SURFACE"<<ToReplaceFace->tag()<<"\n";
-						file2 << "NSET\tBACKLEFTBOTTOM = BACKLEFTBOTTOM + SURFACE"<<pairTmp.first->tag()<<"\n";
-					}else if (abs((p1.z()-p2.z()-1.0))<0.0001){
-						file2 << "NSET\tFRONTRIGHTBOTTOM = FRONTRIGHTBOTTOM + SURFACE"<<ToReplaceFace->tag()<<"\n";
-						file2 << "NSET\tBACKLEFTTOP = BACKLEFTTOP + SURFACE"<<pairTmp.first->tag()<<"\n";
-					}
-				}else if (abs((p1.y()-p2.y()-1.0))<0.0001){
-					if (abs((p2.z()-p1.z()))<0.0001){
-						file2 << "NSET\tFRONTLEFT = FRONTLEFT + SURFACE"<<ToReplaceFace->tag()<<"\n";
-						file2 << "NSET\tBACKRIGHT = BACKRIGHT + SURFACE"<<pairTmp.first->tag()<<"\n";
-					}else if (abs((p2.z()-p1.z()-1.0))<0.0001){
-						file2 << "NSET\tFRONTLEFTTOP = FRONTLEFTTOP + SURFACE"<<ToReplaceFace->tag()<<"\n";
-						file2 << "NSET\tBACKRIGHTBOTTOM = BACKRIGHTBOTTOM + SURFACE"<<pairTmp.first->tag()<<"\n";
-					}else if (abs((p1.z()-p2.z()-1.0))<0.0001){
-						file2 << "NSET\tFRONTLEFTBOTTOM = FRONTLEFTBOTTOM + SURFACE"<<ToReplaceFace->tag()<<"\n";
-						file2 << "NSET\tBACKRIGHTTOP = BACKRIGHTTOP + SURFACE"<<pairTmp.first->tag()<<"\n";
-					}
-				}
-			}else if (abs((p1.x()-p2.x()-1.0))<0.0001){
-				if (abs((p2.y()-p1.y()))<0.0001){
-					if (abs((p2.z()-p1.z()))<0.0001){
-						file2 << "NSET\tFRONT = FRONT + SURFACE"<<pairTmp.first->tag()<<"\n";
-						file2 << "NSET\tBACK = BACK + SURFACE"<<ToReplaceFace->tag()<<"\n";
-					}else if(abs((p2.z()-p1.z()-1.0))<0.0001){
-						file2 << "NSET\tFRONTBOTTOM = FRONTBOTTOM + SURFACE"<<pairTmp.first->tag()<<"\n";
-						file2 << "NSET\tBACKTOP = BACKTOP + SURFACE"<<ToReplaceFace->tag()<<"\n";
-					}else if (abs((p1.z()-p2.z()-1.0))<0.0001){
-						file2 << "NSET\tFRONTTOP = FRONTTOP + SURFACE"<<pairTmp.first->tag()<<"\n";
-						file2 << "NSET\tBACKBOTTOM = BACKBOTTOM + SURFACE"<<ToReplaceFace->tag()<<"\n";
-					}
-				}else if (abs((p2.y()-p1.y()-1.0))<0.0001){
-					if (abs((p2.z()-p1.z()))<0.0001){
-						file2 << "NSET\tFRONTLEFT = FRONTLEFT + SURFACE"<<pairTmp.first->tag()<<"\n";
-						file2 << "NSET\tBACKRIGHT = BACKRIGHT + SURFACE"<<ToReplaceFace->tag()<<"\n";
-					}else if (abs((p2.z()-p1.z()-1.0))<0.0001){
-						file2 << "NSET\tFRONTLEFTBOTTOM = FRONTLEFTBOTTOM + SURFACE"<<pairTmp.first->tag()<<"\n";
-						file2 << "NSET\tBACKRIGHTTOP = BACKRIGHTTOP + SURFACE"<<ToReplaceFace->tag()<<"\n";
-					}else if (abs((p1.z()-p2.z()-1.0))<0.0001){
-						file2 << "NSET\tFRONTLEFTTOP = FRONTLEFTTOP + SURFACE"<<pairTmp.first->tag()<<"\n";
-						file2 << "NSET\tBACKRIGHTBOTTOM = BACKRIGHTBOTTOM + SURFACE"<<ToReplaceFace->tag()<<"\n";
-					}
-				}else if (abs((p1.y()-p2.y()-1.0))<0.0001){
-					if (abs((p2.z()-p1.z()))<0.0001){
-						file2 << "NSET\tFRONTRIGHT = FRONTRIGHT + SURFACE"<<pairTmp.first->tag()<<"\n";
-						file2 << "NSET\tBACKLEFT = BACKLEFT + SURFACE"<<ToReplaceFace->tag()<<"\n";
-					}else if (abs((p2.z()-p1.z()-1.0))<0.0001){
-						file2 << "NSET\tFRONTRIGHTBOTTOM = FRONTRIGHTBOTTOM + SURFACE"<<pairTmp.first->tag()<<"\n";
-						file2 << "NSET\tBACKLEFTTOP = BACKLEFTTOP + SURFACE"<<ToReplaceFace->tag()<<"\n";
-					}else if (abs((p1.z()-p2.z()-1.0))<0.0001){
-						file2 << "NSET\tFRONTRIGHTTOP = FRONTRIGHTTOP + SURFACE"<<pairTmp.first->tag()<<"\n";
-						file2 << "NSET\tBACKLEFTBOTTOM = BACKLEFTBOTTOM + SURFACE"<<ToReplaceFace->tag()<<"\n";
-					}
-				}
-			}else if (abs((p1.x()-p2.x()))<0.0001){
-				if (abs((p2.y()-p1.y()-1.0))<0.0001){
-					if (abs((p2.z()-p1.z()))<0.0001){
-						file2 << "NSET\tRIGHT = RIGHT + SURFACE"<<ToReplaceFace->tag()<<"\n";
-						file2 << "NSET\tLEFT = LEFT + SURFACE"<<pairTmp.first->tag()<<"\n";
-					}else if (abs((p2.z()-p1.z()-1.0))<0.0001){
-						file2 << "NSET\tRIGHTTOP = RIGHTTOP + SURFACE"<<ToReplaceFace->tag()<<"\n";
-						file2 << "NSET\tLEFTBOTTOM = LEFTBOTTOM + SURFACE"<<pairTmp.first->tag()<<"\n";
-					}else if (abs((p1.z()-p2.z()-1.0))<0.0001){
-						file2 << "NSET\tRIGHTBOTTOM = RIGHTBOTTOM + SURFACE"<<ToReplaceFace->tag()<<"\n";
-						file2 << "NSET\tLEFTTOP = LEFTTOP + SURFACE"<<pairTmp.first->tag()<<"\n";
-					}
-				}else if (abs((p1.y()-p2.y()-1.0))<0.0001){
-					if (abs((p2.z()-p1.z()))<0.0001){
-						file2 << "NSET\tRIGHT = RIGHT + SURFACE"<<pairTmp.first->tag()<<"\n";
-						file2 << "NSET\tLEFT = LEFT + SURFACE"<<ToReplaceFace->tag()<<"\n";
-					}else if (abs((p2.z()-p1.z()-1.0))<0.0001){
-						file2 << "NSET\tRIGHTBOTTOM = RIGHTBOTTOM + SURFACE"<<pairTmp.first->tag()<<"\n";
-						file2 << "NSET\tLEFTTOP = LEFTTOP + SURFACE"<<ToReplaceFace->tag()<<"\n";
-					}else if (abs((p1.z()-p2.z()-1.0))<0.0001){
-						file2 << "NSET\tRIGHTTOP = RIGHTTOP + SURFACE"<<pairTmp.first->tag()<<"\n";
-						file2 << "NSET\tLEFTBOTTOM = LEFTBOTTOM + SURFACE"<<ToReplaceFace->tag()<<"\n";
-					}
-				}else if (abs((p1.y()-p2.y()))<0.0001){
-					if (abs((p2.z()-p1.z()-1.0))<0.0001){
-						file2 << "NSET\tTOP = TOP + SURFACE"<<ToReplaceFace->tag()<<"\n";
-						file2 << "NSET\tBOTTOM = BOTTOM + SURFACE"<<pairTmp.first->tag()<<"\n";
-					}else if (abs((p1.z()-p2.z()-1.0))<0.0001){
-						file2 << "NSET\tTOP = TOP + SURFACE"<<pairTmp.first->tag()<<"\n";
-						file2 << "NSET\tBOTTOM = BOTTOM + SURFACE"<<ToReplaceFace->tag()<<"\n";
-					}
-				}
-			}
-//			count++;
-
-
-
-
-
-
-
-			newPairs.push_back(std::make_pair(pairTmp.first,associatedFace));
-		}
-	}
-//	for (std::vector<std::pair<GFace*,GFace*> >::iterator itP = newPairs.begin();itP != newPairs.end();itP++){
-//		std::pair<GFace*,GFace*> pairTmp = (*itP);
-//	}
+  GModel *m = GModel::current();
+  m->setFactory("geo");
+  std::set<GFace*> ToDuplicateList;
+  ToDuplicateList.clear();
+  std::set<GFace*> ToDuplicateListBoundary;
+  ToDuplicateListBoundary.clear();
+  std::vector<GFace*> facesBound;
+  facesBound.clear();
+  std::map<GFace*,SPoint3> centers;
+  std::vector<std::pair<GFace*,GFace*> > pairs;
+  std::vector<std::pair<GFace*,GFace*> > newPairs;
+  int PhysicalInterface = m->setPhysicalName("Interface",3);
+  for (GModel::fiter itf= m->firstFace();itf != m->lastFace();itf++){
+    GFace* fTmp = (*itf);
+    if (fTmp->numRegions() == 2){
+      ToDuplicateList.insert(fTmp);
+    }
+    else{
+      ToDuplicateListBoundary.insert(fTmp);
+      facesBound.push_back(fTmp);
+    }
+  }
+
+
+
+
+
+
+
+
+  for(unsigned int i=0;i<facesBound.size();i++){
+    double x = 0.0;
+    double y = 0.0;
+    double z = 0.0;
+
+    std::list<GVertex*> vertices;
+
+    vertices = facesBound[i]->vertices();
+
+    for(std::list<GVertex*>::iterator it2=vertices.begin();it2!=vertices.end();it2++){
+      x = x + (*it2)->x();
+      y = y + (*it2)->y();
+      z = z + (*it2)->z();
+    }
+
+    x = x/vertices.size();
+    y = y/vertices.size();
+    z = z/vertices.size();
+
+    centers.insert(std::pair<GFace*,SPoint3>(facesBound[i],SPoint3(x,y,z)));
+  }
+
+  for(unsigned int i=0;i<facesBound.size();i++){
+    for(unsigned int j=0;j<facesBound.size();j++){
+      std::map<GFace*,SPoint3>::iterator it3 = centers.find(facesBound[i]);
+      std::map<GFace*,SPoint3>::iterator it4 = centers.find(facesBound[j]);
+
+      SPoint3 p1 = it3->second;
+      SPoint3 p2 = it4->second;
+
+
+      //				categories.push_back(val);
+
+      //				print_segment(p1,p2,file);
+
+      if (abs((p2.x()-p1.x()-1.0))<0.0001){
+        if (abs((p2.y()-p1.y()))<0.0001){
+          if (abs((p2.z()-p1.z()))<0.0001){
+            pairs.push_back(std::pair<GFace*,GFace*>(facesBound[i],facesBound[j]));
+            ToDuplicateListBoundary.insert(facesBound[i]);
+          }else if(abs((p2.z()-p1.z()-1.0))<0.0001){
+            pairs.push_back(std::pair<GFace*,GFace*>(facesBound[i],facesBound[j]));
+            ToDuplicateListBoundary.insert(facesBound[i]);
+          }else if (abs((p1.z()-p2.z()-1.0))<0.0001){
+            pairs.push_back(std::pair<GFace*,GFace*>(facesBound[i],facesBound[j]));
+            ToDuplicateListBoundary.insert(facesBound[i]);
+          }
+        }else if (abs((p2.y()-p1.y()-1.0))<0.0001){
+          if (abs((p2.z()-p1.z()))<0.0001){
+            pairs.push_back(std::pair<GFace*,GFace*>(facesBound[i],facesBound[j]));
+            ToDuplicateListBoundary.insert(facesBound[i]);
+          }else if (abs((p2.z()-p1.z()-1.0))<0.0001){
+            pairs.push_back(std::pair<GFace*,GFace*>(facesBound[i],facesBound[j]));
+            ToDuplicateListBoundary.insert(facesBound[i]);
+          }else if (abs((p1.z()-p2.z()-1.0))<0.0001){
+            pairs.push_back(std::pair<GFace*,GFace*>(facesBound[i],facesBound[j]));
+            ToDuplicateListBoundary.insert(facesBound[i]);
+          }
+        }else if (abs((p1.y()-p2.y()-1.0))<0.0001){
+          if (abs((p2.z()-p1.z()))<0.0001){
+            pairs.push_back(std::pair<GFace*,GFace*>(facesBound[i],facesBound[j]));
+            ToDuplicateListBoundary.insert(facesBound[i]);
+          }else if (abs((p2.z()-p1.z()-1.0))<0.0001){
+            pairs.push_back(std::pair<GFace*,GFace*>(facesBound[i],facesBound[j]));
+            ToDuplicateListBoundary.insert(facesBound[i]);
+          }else if (abs((p1.z()-p2.z()-1.0))<0.0001){
+            pairs.push_back(std::pair<GFace*,GFace*>(facesBound[i],facesBound[j]));
+            ToDuplicateListBoundary.insert(facesBound[i]);
+          }
+        }
+      }else if (abs((p1.x()-p2.x()-1.0))<0.0001){
+        if (abs((p2.y()-p1.y()))<0.0001){
+          if (abs((p2.z()-p1.z()))<0.0001){
+            //NOTHING
+          }else if(abs((p2.z()-p1.z()-1.0))<0.0001){
+            //NOTHING
+          }else if (abs((p1.z()-p2.z()-1.0))<0.0001){
+            //NOTHING
+          }
+        }else if (abs((p2.y()-p1.y()-1.0))<0.0001){
+          if (abs((p2.z()-p1.z()))<0.0001){
+            //NOTHING
+          }else if (abs((p2.z()-p1.z()-1.0))<0.0001){
+            //NOTHING
+          }else if (abs((p1.z()-p2.z()-1.0))<0.0001){
+            //NOTHING
+          }
+        }else if (abs((p1.y()-p2.y()-1.0))<0.0001){
+          if (abs((p2.z()-p1.z()))<0.0001){
+            //NOTHING
+          }else if (abs((p2.z()-p1.z()-1.0))<0.0001){
+            //NOTHING
+          }else if (abs((p1.z()-p2.z()-1.0))<0.0001){
+            //NOTHING
+          }
+        }
+      }else if (abs((p1.x()-p2.x()))<0.0001){
+        if (abs((p2.y()-p1.y()-1.0))<0.0001){
+          if (abs((p2.z()-p1.z()))<0.0001){
+            pairs.push_back(std::pair<GFace*,GFace*>(facesBound[i],facesBound[j]));
+            ToDuplicateListBoundary.insert(facesBound[i]);
+          }else if (abs((p2.z()-p1.z()-1.0))<0.0001){
+            pairs.push_back(std::pair<GFace*,GFace*>(facesBound[i],facesBound[j]));
+            ToDuplicateListBoundary.insert(facesBound[i]);
+          }else if (abs((p1.z()-p2.z()-1.0))<0.0001){
+            pairs.push_back(std::pair<GFace*,GFace*>(facesBound[i],facesBound[j]));
+            ToDuplicateListBoundary.insert(facesBound[i]);
+          }
+        }else if (abs((p1.y()-p2.y()-1.0))<0.0001){
+          if (abs((p2.z()-p1.z()))<0.0001){
+            //NOTHING
+          }else if (abs((p2.z()-p1.z()-1.0))<0.0001){
+            //NOTHING
+          }else if (abs((p1.z()-p2.z()-1.0))<0.0001){
+            //NOTHING
+          }
+        }else if (abs((p1.y()-p2.y()))<0.0001){
+          if (abs((p2.z()-p1.z()-1.0))<0.0001){
+            pairs.push_back(std::pair<GFace*,GFace*>(facesBound[i],facesBound[j]));
+            ToDuplicateListBoundary.insert(facesBound[i]);
+          }else if (abs((p1.z()-p2.z()-1.0))<0.0001){
+            //NOTHING
+          }
+        }
+      }
+    }
+  }
+
+
+
+
+
 
-	std::cout<<"End of DuplicateBoundaries"<<std::endl;
-	return view;
+
+
+
+
+  std::map<std::pair<MVertex*,GRegion*>,MVertex* > VertexGlobalAssociation;
+  std::map<std::pair<GVertex*,GRegion*>,GVertex* > GVertexGlobalAssociation;
+  std::map<std::pair<GEdge*,GRegion*>,GEdge* > GEdgeGlobalAssociation;
+  std::map<std::pair<GFace*,GRegion*>,GFace* > GFaceGlobalAssociation;
+
+  for (GModel::riter itr= m->firstRegion();itr != m->lastRegion();itr++){
+    GRegion* rTmp = (*itr);
+    std::list<GFace*> RegFaces = rTmp->faces();
+    std::map<MVertex*,MVertex* > VertexAssociation;
+    std::map<GVertex*,GVertex* > GVertexAssociation;
+    std::map<GEdge*,GEdge* > GEdgeAssociation;
+    //int counterNbDone = 10000;
+    double xCenterReg = 0.0;
+    double yCenterReg = 0.0;
+    double zCenterReg = 0.0;
+    int counterPts = 0;
+    for(std::list<GFace*>::iterator it2=RegFaces.begin();it2!=RegFaces.end();it2++){
+      GFace* fTemp = (*it2);
+      std::list<GVertex*> verticesFace = fTemp->vertices();
+      for (std::list<GVertex*>::iterator it3=verticesFace.begin();it3!=verticesFace.end();it3++){
+        xCenterReg = xCenterReg + (*it3)->x();
+        yCenterReg = yCenterReg + (*it3)->y();
+        zCenterReg = zCenterReg + (*it3)->z();
+        counterPts++;
+      }
+    }
+    xCenterReg = xCenterReg/counterPts;
+    yCenterReg = yCenterReg/counterPts;
+    zCenterReg = zCenterReg/counterPts;
+    //duplication noeud et aretes au niveau de la region directement
+    std::list<GVertex*> vlist;
+
+
+    std::list<GFace*> listFacesTmp = rTmp->faces();
+    for (std::list<GFace*>::iterator itTp = listFacesTmp.begin();itTp != listFacesTmp.end();itTp++){
+      std::list<GVertex*> vlist2;
+      vlist2 = (*itTp)->vertices();
+      for (std::list<GVertex*>::iterator itTp2 = vlist2.begin();itTp2 != vlist2.end();itTp2++){
+        if(std::find(vlist.begin(), vlist.end(), *itTp2) == vlist.end())
+          vlist.push_back(*itTp2);
+      }
+    }
+
+
+    for (std::list<GVertex*>::iterator itv = vlist.begin();itv != vlist.end();itv++){
+      //duplication Gvertex
+      GVertex* vTmp = (*itv);
+      double ponderatedX = 0.99999999999 * vTmp->x() + 0.00000000001 * xCenterReg;
+      double ponderatedY = 0.99999999999 * vTmp->y() + 0.00000000001 * yCenterReg;
+      double ponderatedZ = 0.99999999999 * vTmp->z() + 0.00000000001 * zCenterReg;
+      GVertex* newv = m->addVertex(ponderatedX,ponderatedY,ponderatedZ,vTmp->prescribedMeshSizeAtVertex());
+      GVertexAssociation[vTmp] = newv;
+      GVertexGlobalAssociation[std::make_pair(vTmp,rTmp)] = newv;
+      //creation des Gedge correspondantes
+      //			GEdge* newE = m->addLine(vTmp,newv);
+      //			SurroudingEdges[vTmp] = newE;
+      //maintenant traitement mesh
+      MVertex *vMesh = vTmp->mesh_vertices[0];
+      MVertex *newMv = new MVertex(vMesh->x(), vMesh->y(), vMesh->z(), (GEntity*)newv);
+      VertexAssociation[vMesh] = newMv;
+      VertexGlobalAssociation[std::make_pair(vMesh,rTmp)] = newMv;
+      newv->addMeshVertex(newMv);
+    }
+    //maintenant on soccupe de duppliquer les edges de la region
+    std::list<GEdge*> elist = rTmp->edges();
+
+    std::vector<GFace*> SurroundingsFaces;
+    for (std::list<GEdge*>::iterator ite = elist.begin();ite != elist.end();ite++){
+      //duplication Gedge
+      GEdge* eTmp = (*ite);
+      GEdge* newE = m->addLine(GVertexAssociation[eTmp->getEndVertex()],GVertexAssociation[eTmp->getBeginVertex()]);
+      GEdgeAssociation[eTmp] = newE;
+      GEdgeGlobalAssociation[std::make_pair(eTmp,rTmp)] = newE;
+      //creation des GFace correspondantes
+      //			GEdge* firstE = SurroudingEdges.find(eTmp->getEndVertex())->second;
+      //			GEdge* lastE = SurroudingEdges.find(eTmp->getBeginVertex())->second;
+      //			std::vector<GEdge*> VecEdgesTmp;
+      //			VecEdgesTmp.push_back(eTmp);
+      //			VecEdgesTmp.push_back(firstE);
+      //			VecEdgesTmp.push_back(newE);
+      //			VecEdgesTmp.push_back(lastE);
+      //			std::vector<std::vector<GEdge*> > VecOfVecTmp;
+      //			VecOfVecTmp.push_back(VecEdgesTmp);
+      //			GFace* newFaceTmp = m->addPlanarFace(VecOfVecTmp);
+      //			SurroundingsFaces.push_back(newFaceTmp);
+      //maintenant traitement mesh
+      for (unsigned int i = 0; i < eTmp->mesh_vertices.size();i++){
+        MVertex *vMesh = eTmp->mesh_vertices[i];
+        MVertex *newMv = new MVertex(vMesh->x(), vMesh->y(), vMesh->z(), (GEntity*)newE);
+        VertexAssociation[vMesh] = newMv;
+        VertexGlobalAssociation[std::make_pair(vMesh,rTmp)] = newMv;
+        newE->addMeshVertex(newMv);
+      }
+      for (unsigned int i = 0; i < eTmp->getNumMeshElements();i++){
+        MElement* elem = eTmp->getMeshElement(i);
+        MVertex *firstETmp = VertexAssociation.find(elem->getVertex(0))->second;
+        MVertex *lastETmp = VertexAssociation.find(elem->getVertex(1))->second;
+        MLine *newLine = new MLine(firstETmp,lastETmp);
+        newE->addLine(newLine);
+      }
+    }
+    for (std::list<GFace*>::iterator itf = RegFaces.begin();itf != RegFaces.end();itf++){
+      GFace* fTmp = (*itf);
+      std::vector<GEdge*> newEdgesVector;
+      std::list<GEdge*> elistFace = fTmp->edges();
+      for (std::list<GEdge*>::iterator ite = elistFace.begin();ite != elistFace.end();ite++){
+        GEdge* eTmp = (*ite);
+        GEdge* eToFind = GEdgeAssociation[eTmp];
+        newEdgesVector.push_back(eToFind);
+      }
+      std::vector<std::vector<GEdge*> > VecOfVec;
+      VecOfVec.push_back(newEdgesVector);
+      //creation de la nouvelle face
+      GFace* GFaceAssociation = m->addPlanarFace(VecOfVec);
+      //maintenant traitement mesh
+      for (unsigned int i = 0; i < fTmp->mesh_vertices.size();i++){
+        MVertex *vMesh = fTmp->mesh_vertices[i];
+        MVertex *newMv = new MVertex(vMesh->x(), vMesh->y(), vMesh->z(), (GEntity*)GFaceAssociation);
+        VertexAssociation[vMesh] = newMv;
+        VertexGlobalAssociation[std::make_pair(vMesh,rTmp)] = newMv;
+        GFaceAssociation->addMeshVertex(newMv);
+      }
+      for (unsigned int i = 0; i < fTmp->getNumMeshElements();i++){
+        MElement* elem = fTmp->getMeshElement(i);
+        MVertex *firstE = VertexAssociation.find(elem->getVertex(0))->second;
+        MVertex *secondE = VertexAssociation.find(elem->getVertex(1))->second;
+        MVertex *thirdE = VertexAssociation.find(elem->getVertex(2))->second;
+        MTriangle *newTri = new MTriangle(firstE,secondE,thirdE);
+        GFaceAssociation->addTriangle(newTri);
+      }
+      GFaceGlobalAssociation[std::make_pair(fTmp,rTmp)] = GFaceAssociation;
+    }
+  }
+  int counterNbDone = 10000;
+  //maintenant on va traiter les faces initiales
+  for (std::set<GFace*>::iterator itf = ToDuplicateList.begin();itf != ToDuplicateList.end();itf++){
+    counterNbDone++;
+    GFace* fTmp = (*itf);
+    GRegion* reg1 = fTmp->getRegion(0);
+    GRegion* reg2 = fTmp->getRegion(1);
+    //pour commencer on cree des aretes entre les vertex
+    std::list<GVertex*> vlist = fTmp->vertices();
+    std::map<GVertex*,GEdge* > SurroudingEdges;
+    for (std::list<GVertex*>::iterator itv = vlist.begin();itv != vlist.end();itv++){
+      GVertex* vTmp = (*itv);
+      GVertex* v1=0;
+      GVertex* v2=0;
+      std::map<std::pair<GVertex*,GRegion*>,GVertex* >::iterator itMap = GVertexGlobalAssociation.find(std::make_pair(vTmp,reg1));
+      if (itMap != GVertexGlobalAssociation.end()){
+        v1 = itMap->second;
+      }
+      itMap = GVertexGlobalAssociation.find(std::make_pair(vTmp,reg2));
+      if (itMap != GVertexGlobalAssociation.end()){
+        v2 = itMap->second;
+      }
+      GEdge* newE = m->addLine(v1,v2);
+      SurroudingEdges[vTmp] = newE;
+    }
+    //ici tous les vertex sont traites
+    //on va traiter les edges
+    std::list<GEdge*> elist = fTmp->edges();
+    std::vector<GEdge*> newEdgesVector;
+    std::vector<GFace*> SurroundingsFaces;
+    for (std::list<GEdge*>::iterator ite = elist.begin();ite != elist.end();ite++){
+      //duplication Gedge
+      GEdge* eTmp = (*ite);
+      GEdge* e1=0;
+      GEdge* e2=0;
+      std::map<std::pair<GEdge*,GRegion*>,GEdge* >::iterator itMap = GEdgeGlobalAssociation.find(std::make_pair(eTmp,reg1));
+      if (itMap != GEdgeGlobalAssociation.end()){
+        e1 = itMap->second;
+      }
+      itMap = GEdgeGlobalAssociation.find(std::make_pair(eTmp,reg2));
+      if (itMap != GEdgeGlobalAssociation.end()){
+        e2 = itMap->second;
+      }
+      //creation des GFace correspondantes
+      GEdge* firstE = SurroudingEdges.find(eTmp->getBeginVertex())->second;
+      GEdge* lastE = SurroudingEdges.find(eTmp->getEndVertex())->second;
+      if (firstE->getBeginVertex() != e1->getEndVertex()){
+        firstE->reverse();
+      }
+      if (firstE->getBeginVertex() != e1->getEndVertex()){
+        e1->reverse();
+      }
+      if (firstE->getBeginVertex() != e1->getEndVertex()){
+        firstE->reverse();
+      }
+      if (e2->getBeginVertex() != firstE->getEndVertex()){
+        e2->reverse();
+      }
+      if (lastE->getBeginVertex() != e2->getEndVertex()){
+        lastE->reverse();
+      }
+      std::vector<GEdge*> VecEdgesTmp;
+      VecEdgesTmp.push_back(e1);
+      VecEdgesTmp.push_back(firstE);
+      VecEdgesTmp.push_back(e2);
+      VecEdgesTmp.push_back(lastE);
+      std::vector<std::vector<GEdge*> > VecOfVecTmp;
+      VecOfVecTmp.push_back(VecEdgesTmp);
+      GFace* newFaceTmp = m->addPlanarFace(VecOfVecTmp);
+      SurroundingsFaces.push_back(newFaceTmp);
+    }
+    std::vector<GFace*> VectorFaces;
+    std::list<GFace*> listFaces;
+    GFace* f1;
+    GFace* f2;
+    std::map<std::pair<GFace*,GRegion*>,GFace* >::iterator itMap = GFaceGlobalAssociation.find(std::make_pair(fTmp,reg1));
+    if (itMap != GFaceGlobalAssociation.end()){
+      f1 = itMap->second;
+    }
+    itMap = GFaceGlobalAssociation.find(std::make_pair(fTmp,reg2));
+    if (itMap != GFaceGlobalAssociation.end()){
+      f2 = itMap->second;
+    }
+    VectorFaces.push_back(f1);
+    listFaces.push_back(f1);
+    for (unsigned int i = 0;i < SurroundingsFaces.size();i++){
+      VectorFaces.push_back(SurroundingsFaces[i]);
+      listFaces.push_back(SurroundingsFaces[i]);
+    }
+    VectorFaces.push_back(f2);
+    listFaces.push_back(f2);
+    std::vector<std::vector<GFace*> > VecOfVecGFace;
+    VecOfVecGFace.push_back(VectorFaces);
+    //creation de la nouvelle region
+    GRegion* createdRegion = new GRegion(m,counterNbDone);
+    createdRegion->addPhysicalEntity(PhysicalInterface);
+    createdRegion->set(listFaces);
+    m->add(createdRegion);
+    for (unsigned int i = 0; i < fTmp->getNumMeshElements();i++){
+      MElement* elem = fTmp->getMeshElement(i);
+      MVertex* v1=0;
+      MVertex* v2=0;
+      MVertex* v3=0;
+      MVertex* v4=0;
+      MVertex* v5=0;
+      MVertex* v6=0;
+      std::map<std::pair<MVertex*,GRegion*>,MVertex* >::iterator itMap = VertexGlobalAssociation.find(std::make_pair(elem->getVertex(0),reg1));
+      if (itMap != VertexGlobalAssociation.end()){
+        v1 = itMap->second;
+      }
+      itMap = VertexGlobalAssociation.find(std::make_pair(elem->getVertex(1),reg1));
+      if (itMap != VertexGlobalAssociation.end()){
+        v2 = itMap->second;
+      }
+      itMap = VertexGlobalAssociation.find(std::make_pair(elem->getVertex(2),reg1));
+      if (itMap != VertexGlobalAssociation.end()){
+        v3 = itMap->second;
+      }
+      itMap = VertexGlobalAssociation.find(std::make_pair(elem->getVertex(0),reg2));
+      if (itMap != VertexGlobalAssociation.end()){
+        v4 = itMap->second;
+      }
+      itMap = VertexGlobalAssociation.find(std::make_pair(elem->getVertex(1),reg2));
+      if (itMap != VertexGlobalAssociation.end()){
+        v5 = itMap->second;
+      }
+      itMap = VertexGlobalAssociation.find(std::make_pair(elem->getVertex(2),reg2));
+      if (itMap != VertexGlobalAssociation.end()){
+        v6 = itMap->second;
+      }
+      MPrism *newPri = new MPrism(v1,v2,v3,v4,v5,v6);
+
+      createdRegion->addPrism(newPri);
+    }
+    for (unsigned int i = 0; i < reg1->getNumMeshElements();i++){
+      MElement* elem = reg1->getMeshElement(i);
+      for (int j = 0;j < elem->getNumVertices();j++){
+        MVertex* vert = elem->getVertex(j);
+        std::map<std::pair<MVertex*,GRegion*>,MVertex* >::iterator itMap = VertexGlobalAssociation.find(std::make_pair(vert,reg1));
+        if (itMap != VertexGlobalAssociation.end()){
+          elem->setVertex(j,itMap->second);
+        }
+      }
+    }
+    for (unsigned int i = 0; i < reg2->getNumMeshElements();i++){
+      MElement* elem = reg2->getMeshElement(i);
+      for (int j = 0;j < elem->getNumVertices();j++){
+        MVertex* vert = elem->getVertex(j);
+        std::map<std::pair<MVertex*,GRegion*>,MVertex* >::iterator itMap = VertexGlobalAssociation.find(std::make_pair(vert,reg2));
+        if (itMap != VertexGlobalAssociation.end()){
+          elem->setVertex(j,itMap->second);
+        }
+      }
+    }
+  }
+  //maintenant on va traiter les faces du bord
+  for (std::set<GFace*>::iterator itf = ToDuplicateListBoundary.begin();itf != ToDuplicateListBoundary.end();itf++){
+    counterNbDone++;
+    GFace* fTmp = (*itf);
+    GRegion* reg1 = fTmp->getRegion(0);
+    //pour commencer on cree des aretes entre les vertex
+    std::list<GVertex*> vlist = fTmp->vertices();
+    std::map<GVertex*,GEdge* > SurroudingEdges;
+    for (std::list<GVertex*>::iterator itv = vlist.begin();itv != vlist.end();itv++){
+      GVertex* vTmp = (*itv);
+      GVertex* v1=0;
+      std::map<std::pair<GVertex*,GRegion*>,GVertex* >::iterator itMap = GVertexGlobalAssociation.find(std::make_pair(vTmp,reg1));
+      if (itMap != GVertexGlobalAssociation.end()){
+        v1 = itMap->second;
+      }
+      GEdge* newE = m->addLine(v1,vTmp);
+      SurroudingEdges[vTmp] = newE;
+    }
+    //ici tous les vertex sont traites
+    //on va traiter les edges
+    std::list<GEdge*> elist = fTmp->edges();
+    std::vector<GEdge*> newEdgesVector;
+    std::vector<GFace*> SurroundingsFaces;
+    for (std::list<GEdge*>::iterator ite = elist.begin();ite != elist.end();ite++){
+      //duplication Gedge
+      GEdge* eTmp = (*ite);
+      GEdge* e1=0;
+      std::map<std::pair<GEdge*,GRegion*>,GEdge* >::iterator itMap = GEdgeGlobalAssociation.find(std::make_pair(eTmp,reg1));
+      if (itMap != GEdgeGlobalAssociation.end()){
+        e1 = itMap->second;
+      }
+      //creation des GFace correspondantes
+      GEdge* firstE = SurroudingEdges.find(eTmp->getBeginVertex())->second;
+      GEdge* lastE = SurroudingEdges.find(eTmp->getEndVertex())->second;
+      if (firstE->getBeginVertex() != e1->getEndVertex()){
+        firstE->reverse();
+      }
+      if (firstE->getBeginVertex() != e1->getEndVertex()){
+        e1->reverse();
+      }
+      if (firstE->getBeginVertex() != e1->getEndVertex()){
+        firstE->reverse();
+      }
+      if (eTmp->getBeginVertex() != firstE->getEndVertex()){
+        eTmp->reverse();
+      }
+      if (lastE->getBeginVertex() != eTmp->getEndVertex()){
+        lastE->reverse();
+      }
+      std::vector<GEdge*> VecEdgesTmp;
+      VecEdgesTmp.push_back(e1);
+      VecEdgesTmp.push_back(firstE);
+      VecEdgesTmp.push_back(eTmp);
+      VecEdgesTmp.push_back(lastE);
+      std::vector<std::vector<GEdge*> > VecOfVecTmp;
+      VecOfVecTmp.push_back(VecEdgesTmp);
+      GFace* newFaceTmp = m->addPlanarFace(VecOfVecTmp);
+      SurroundingsFaces.push_back(newFaceTmp);
+    }
+    std::vector<GFace*> VectorFaces;
+    std::list<GFace*> listFaces;
+    GFace* f1;
+    std::map<std::pair<GFace*,GRegion*>,GFace* >::iterator itMap = GFaceGlobalAssociation.find(std::make_pair(fTmp,reg1));
+    if (itMap != GFaceGlobalAssociation.end()){
+      f1 = itMap->second;
+    }
+    VectorFaces.push_back(f1);
+    listFaces.push_back(f1);
+    for (unsigned int i = 0;i < SurroundingsFaces.size();i++){
+      VectorFaces.push_back(SurroundingsFaces[i]);
+      listFaces.push_back(SurroundingsFaces[i]);
+    }
+    VectorFaces.push_back(fTmp);
+    listFaces.push_back(fTmp);
+    std::vector<std::vector<GFace*> > VecOfVecGFace;
+    VecOfVecGFace.push_back(VectorFaces);
+    //creation de la nouvelle region
+    GRegion* createdRegion = new GRegion(m,counterNbDone);
+    createdRegion->addPhysicalEntity(PhysicalInterface);
+    createdRegion->set(listFaces);
+    m->add(createdRegion);
+    for (unsigned int i = 0; i < fTmp->getNumMeshElements();i++){
+      MElement* elem = fTmp->getMeshElement(i);
+      MVertex* v1=0;
+      MVertex* v2=0;
+      MVertex* v3=0;
+      std::map<std::pair<MVertex*,GRegion*>,MVertex* >::iterator itMap = VertexGlobalAssociation.find(std::make_pair(elem->getVertex(0),reg1));
+      if (itMap != VertexGlobalAssociation.end()){
+        v1 = itMap->second;
+      }
+      itMap = VertexGlobalAssociation.find(std::make_pair(elem->getVertex(1),reg1));
+      if (itMap != VertexGlobalAssociation.end()){
+        v2 = itMap->second;
+      }
+      itMap = VertexGlobalAssociation.find(std::make_pair(elem->getVertex(2),reg1));
+      if (itMap != VertexGlobalAssociation.end()){
+        v3 = itMap->second;
+      }
+      MPrism *newPri = new MPrism(v1,v2,v3,elem->getVertex(0),elem->getVertex(1),elem->getVertex(2));
+
+      createdRegion->addPrism(newPri);
+    }
+    for (unsigned int i = 0; i < reg1->getNumMeshElements();i++){
+      MElement* elem = reg1->getMeshElement(i);
+      for (int j = 0;j < elem->getNumVertices();j++){
+        MVertex* vert = elem->getVertex(j);
+        std::map<std::pair<MVertex*,GRegion*>,MVertex* >::iterator itMap = VertexGlobalAssociation.find(std::make_pair(vert,reg1));
+        if (itMap != VertexGlobalAssociation.end()){
+          elem->setVertex(j,itMap->second);
+        }
+      }
+    }
+  }
+  std::ofstream file("MicrostructurePolycrystal3D.pos");
+  file << "View \"test\" {\n";
+
+  std::ofstream file2("PERIODIC.map");
+  for (std::vector<std::pair<GFace*,GFace*> >::iterator itP = pairs.begin();itP != pairs.end();itP++){
+    std::pair<GFace*,GFace*> pairTmp = (*itP);
+    GFace* ToReplaceFace = pairTmp.second;
+    GRegion* rTmp = ToReplaceFace->getRegion(0);
+    std::map<std::pair<GFace*,GRegion*>,GFace* >::iterator itMap = GFaceGlobalAssociation.find(std::make_pair(ToReplaceFace,rTmp));
+    if (itMap != GFaceGlobalAssociation.end()){
+      GFace* associatedFace = (*itMap).second;
+
+
+
+
+
+
+      std::map<GFace*,SPoint3>::iterator it3 = centers.find(pairTmp.first);
+      std::map<GFace*,SPoint3>::iterator it4 = centers.find(ToReplaceFace);
+
+      SPoint3 p1 = it3->second;
+      SPoint3  p2 = it4->second;
+
+      //double delta_x = fabs(p2.x()-p1.x());
+      //double delta_y = fabs(p2.y()-p1.y());
+      //double delta_z = fabs(p2.z()-p1.z());
+
+
+      file << "SL ("
+           << p1.x() << ", " << p1.y() << ", " << p1.z() << ", "
+           << p2.x() << ", " << p2.y() << ", " << p2.z()
+           << "){10, 20};\n";
+
+      //file2 << "PERIODIC\tSURFACE"<<faces[i]->tag() << "\tSURFACE" << faces[j]->tag() << "\t" << p2.x()-p1.x() << "\t" << p2.y()-p1.y() << "\t" << p2.z()-p1.z() << "\n";
+      if (abs((p2.x()-p1.x()-1.0))<0.0001){
+        if (abs((p2.y()-p1.y()))<0.0001){
+          if (abs((p2.z()-p1.z()))<0.0001){
+            file2 << "NSET\tFRONT = FRONT + SURFACE"<<ToReplaceFace->tag()<<"\n";
+            file2 << "NSET\tBACK = BACK + SURFACE"<<pairTmp.first->tag()<<"\n";
+          }else if(abs((p2.z()-p1.z()-1.0))<0.0001){
+            file2 << "NSET\tFRONTTOP = FRONTTOP + SURFACE"<<ToReplaceFace->tag()<<"\n";
+            file2 << "NSET\tBACKBOTTOM = BACKBOTTOM + SURFACE"<<pairTmp.first->tag()<<"\n";
+          }else if (abs((p1.z()-p2.z()-1.0))<0.0001){
+            file2 << "NSET\tFRONTBOTTOM = FRONTBOTTOM + SURFACE"<<ToReplaceFace->tag()<<"\n";
+            file2 << "NSET\tBACKTOP = BACKTOP + SURFACE"<<pairTmp.first->tag()<<"\n";
+          }
+        }else if (abs((p2.y()-p1.y()-1.0))<0.0001){
+          if (abs((p2.z()-p1.z()))<0.0001){
+            file2 << "NSET\tFRONTRIGHT = FRONTRIGHT + SURFACE"<<ToReplaceFace->tag()<<"\n";
+            file2 << "NSET\tBACKLEFT = BACKLEFT + SURFACE"<<pairTmp.first->tag()<<"\n";
+          }else if (abs((p2.z()-p1.z()-1.0))<0.0001){
+            file2 << "NSET\tFRONTRIGHTTOP = FRONTRIGHTTOP + SURFACE"<<ToReplaceFace->tag()<<"\n";
+            file2 << "NSET\tBACKLEFTBOTTOM = BACKLEFTBOTTOM + SURFACE"<<pairTmp.first->tag()<<"\n";
+          }else if (abs((p1.z()-p2.z()-1.0))<0.0001){
+            file2 << "NSET\tFRONTRIGHTBOTTOM = FRONTRIGHTBOTTOM + SURFACE"<<ToReplaceFace->tag()<<"\n";
+            file2 << "NSET\tBACKLEFTTOP = BACKLEFTTOP + SURFACE"<<pairTmp.first->tag()<<"\n";
+          }
+        }else if (abs((p1.y()-p2.y()-1.0))<0.0001){
+          if (abs((p2.z()-p1.z()))<0.0001){
+            file2 << "NSET\tFRONTLEFT = FRONTLEFT + SURFACE"<<ToReplaceFace->tag()<<"\n";
+            file2 << "NSET\tBACKRIGHT = BACKRIGHT + SURFACE"<<pairTmp.first->tag()<<"\n";
+          }else if (abs((p2.z()-p1.z()-1.0))<0.0001){
+            file2 << "NSET\tFRONTLEFTTOP = FRONTLEFTTOP + SURFACE"<<ToReplaceFace->tag()<<"\n";
+            file2 << "NSET\tBACKRIGHTBOTTOM = BACKRIGHTBOTTOM + SURFACE"<<pairTmp.first->tag()<<"\n";
+          }else if (abs((p1.z()-p2.z()-1.0))<0.0001){
+            file2 << "NSET\tFRONTLEFTBOTTOM = FRONTLEFTBOTTOM + SURFACE"<<ToReplaceFace->tag()<<"\n";
+            file2 << "NSET\tBACKRIGHTTOP = BACKRIGHTTOP + SURFACE"<<pairTmp.first->tag()<<"\n";
+          }
+        }
+      }else if (abs((p1.x()-p2.x()-1.0))<0.0001){
+        if (abs((p2.y()-p1.y()))<0.0001){
+          if (abs((p2.z()-p1.z()))<0.0001){
+            file2 << "NSET\tFRONT = FRONT + SURFACE"<<pairTmp.first->tag()<<"\n";
+            file2 << "NSET\tBACK = BACK + SURFACE"<<ToReplaceFace->tag()<<"\n";
+          }else if(abs((p2.z()-p1.z()-1.0))<0.0001){
+            file2 << "NSET\tFRONTBOTTOM = FRONTBOTTOM + SURFACE"<<pairTmp.first->tag()<<"\n";
+            file2 << "NSET\tBACKTOP = BACKTOP + SURFACE"<<ToReplaceFace->tag()<<"\n";
+          }else if (abs((p1.z()-p2.z()-1.0))<0.0001){
+            file2 << "NSET\tFRONTTOP = FRONTTOP + SURFACE"<<pairTmp.first->tag()<<"\n";
+            file2 << "NSET\tBACKBOTTOM = BACKBOTTOM + SURFACE"<<ToReplaceFace->tag()<<"\n";
+          }
+        }else if (abs((p2.y()-p1.y()-1.0))<0.0001){
+          if (abs((p2.z()-p1.z()))<0.0001){
+            file2 << "NSET\tFRONTLEFT = FRONTLEFT + SURFACE"<<pairTmp.first->tag()<<"\n";
+            file2 << "NSET\tBACKRIGHT = BACKRIGHT + SURFACE"<<ToReplaceFace->tag()<<"\n";
+          }else if (abs((p2.z()-p1.z()-1.0))<0.0001){
+            file2 << "NSET\tFRONTLEFTBOTTOM = FRONTLEFTBOTTOM + SURFACE"<<pairTmp.first->tag()<<"\n";
+            file2 << "NSET\tBACKRIGHTTOP = BACKRIGHTTOP + SURFACE"<<ToReplaceFace->tag()<<"\n";
+          }else if (abs((p1.z()-p2.z()-1.0))<0.0001){
+            file2 << "NSET\tFRONTLEFTTOP = FRONTLEFTTOP + SURFACE"<<pairTmp.first->tag()<<"\n";
+            file2 << "NSET\tBACKRIGHTBOTTOM = BACKRIGHTBOTTOM + SURFACE"<<ToReplaceFace->tag()<<"\n";
+          }
+        }else if (abs((p1.y()-p2.y()-1.0))<0.0001){
+          if (abs((p2.z()-p1.z()))<0.0001){
+            file2 << "NSET\tFRONTRIGHT = FRONTRIGHT + SURFACE"<<pairTmp.first->tag()<<"\n";
+            file2 << "NSET\tBACKLEFT = BACKLEFT + SURFACE"<<ToReplaceFace->tag()<<"\n";
+          }else if (abs((p2.z()-p1.z()-1.0))<0.0001){
+            file2 << "NSET\tFRONTRIGHTBOTTOM = FRONTRIGHTBOTTOM + SURFACE"<<pairTmp.first->tag()<<"\n";
+            file2 << "NSET\tBACKLEFTTOP = BACKLEFTTOP + SURFACE"<<ToReplaceFace->tag()<<"\n";
+          }else if (abs((p1.z()-p2.z()-1.0))<0.0001){
+            file2 << "NSET\tFRONTRIGHTTOP = FRONTRIGHTTOP + SURFACE"<<pairTmp.first->tag()<<"\n";
+            file2 << "NSET\tBACKLEFTBOTTOM = BACKLEFTBOTTOM + SURFACE"<<ToReplaceFace->tag()<<"\n";
+          }
+        }
+      }else if (abs((p1.x()-p2.x()))<0.0001){
+        if (abs((p2.y()-p1.y()-1.0))<0.0001){
+          if (abs((p2.z()-p1.z()))<0.0001){
+            file2 << "NSET\tRIGHT = RIGHT + SURFACE"<<ToReplaceFace->tag()<<"\n";
+            file2 << "NSET\tLEFT = LEFT + SURFACE"<<pairTmp.first->tag()<<"\n";
+          }else if (abs((p2.z()-p1.z()-1.0))<0.0001){
+            file2 << "NSET\tRIGHTTOP = RIGHTTOP + SURFACE"<<ToReplaceFace->tag()<<"\n";
+            file2 << "NSET\tLEFTBOTTOM = LEFTBOTTOM + SURFACE"<<pairTmp.first->tag()<<"\n";
+          }else if (abs((p1.z()-p2.z()-1.0))<0.0001){
+            file2 << "NSET\tRIGHTBOTTOM = RIGHTBOTTOM + SURFACE"<<ToReplaceFace->tag()<<"\n";
+            file2 << "NSET\tLEFTTOP = LEFTTOP + SURFACE"<<pairTmp.first->tag()<<"\n";
+          }
+        }else if (abs((p1.y()-p2.y()-1.0))<0.0001){
+          if (abs((p2.z()-p1.z()))<0.0001){
+            file2 << "NSET\tRIGHT = RIGHT + SURFACE"<<pairTmp.first->tag()<<"\n";
+            file2 << "NSET\tLEFT = LEFT + SURFACE"<<ToReplaceFace->tag()<<"\n";
+          }else if (abs((p2.z()-p1.z()-1.0))<0.0001){
+            file2 << "NSET\tRIGHTBOTTOM = RIGHTBOTTOM + SURFACE"<<pairTmp.first->tag()<<"\n";
+            file2 << "NSET\tLEFTTOP = LEFTTOP + SURFACE"<<ToReplaceFace->tag()<<"\n";
+          }else if (abs((p1.z()-p2.z()-1.0))<0.0001){
+            file2 << "NSET\tRIGHTTOP = RIGHTTOP + SURFACE"<<pairTmp.first->tag()<<"\n";
+            file2 << "NSET\tLEFTBOTTOM = LEFTBOTTOM + SURFACE"<<ToReplaceFace->tag()<<"\n";
+          }
+        }else if (abs((p1.y()-p2.y()))<0.0001){
+          if (abs((p2.z()-p1.z()-1.0))<0.0001){
+            file2 << "NSET\tTOP = TOP + SURFACE"<<ToReplaceFace->tag()<<"\n";
+            file2 << "NSET\tBOTTOM = BOTTOM + SURFACE"<<pairTmp.first->tag()<<"\n";
+          }else if (abs((p1.z()-p2.z()-1.0))<0.0001){
+            file2 << "NSET\tTOP = TOP + SURFACE"<<pairTmp.first->tag()<<"\n";
+            file2 << "NSET\tBOTTOM = BOTTOM + SURFACE"<<ToReplaceFace->tag()<<"\n";
+          }
+        }
+      }
+      //			count++;
+
+
+
+
+
+
+
+      newPairs.push_back(std::make_pair(pairTmp.first,associatedFace));
+    }
+  }
+  //	for (std::vector<std::pair<GFace*,GFace*> >::iterator itP = newPairs.begin();itP != newPairs.end();itP++){
+  //		std::pair<GFace*,GFace*> pairTmp = (*itP);
+  //	}
+
+  std::cout<<"End of DuplicateBoundaries"<<std::endl;
+  return view;
 }
 
 
@@ -1485,945 +1477,945 @@ PView *GMSH_DuplicateBoundariesPlugin::executeFourth(PView *view)
 
 PView *GMSH_DuplicateBoundariesPlugin::execute(PView *view)
 {
-	GModel *m = GModel::current();
-	if (m->getDim() == 3){
-		view = GMSH_DuplicateBoundariesPlugin::executeDuplicate(view);
-	}
-	else if (m->getDim() == 2){
-		view = GMSH_DuplicateBoundariesPlugin::execute2DWithBound(view);
-	}
-	//view = GMSH_DuplicateBoundariesPlugin::ComputeBestSeeds(view);
-	//view = GMSH_DuplicateBoundariesPlugin::execute2D(view);
-	//view = GMSH_DuplicateBoundariesPlugin::execute2DWithBound(view);
-	return view;
+  GModel *m = GModel::current();
+  if (m->getDim() == 3){
+    view = GMSH_DuplicateBoundariesPlugin::executeDuplicate(view);
+  }
+  else if (m->getDim() == 2){
+    view = GMSH_DuplicateBoundariesPlugin::execute2DWithBound(view);
+  }
+  //view = GMSH_DuplicateBoundariesPlugin::ComputeBestSeeds(view);
+  //view = GMSH_DuplicateBoundariesPlugin::execute2D(view);
+  //view = GMSH_DuplicateBoundariesPlugin::execute2DWithBound(view);
+  return view;
 }
 
 
 
 PView *GMSH_DuplicateBoundariesPlugin::executeDuplicate(PView *view)
 {
-	std::cout<<"starting DuplicateBoundaries"<<std::endl;
-	GModel *m = GModel::current();
-	m->setFactory("geo");
-	std::set<GFace*> ToDuplicateList;
-	ToDuplicateList.clear();
-	std::set<GFace*> ToDuplicateListBoundary;
-	ToDuplicateListBoundary.clear();
-	std::vector<GFace*> facesBound;
-	facesBound.clear();
-	std::map<GFace*,SPoint3> centers;
-	std::vector<std::pair<GFace*,GFace*> > pairs;
-	std::vector<std::pair<GFace*,GFace*> > newPairs;
-	int PhysicalInterface = m->setPhysicalName("Interface",3);
-	for (GModel::fiter itf= m->firstFace();itf != m->lastFace();itf++){
-		GFace* fTmp = (*itf);
-		if (fTmp->numRegions() == 2){
-			ToDuplicateList.insert(fTmp);
-		}
-		else{
-//			ToDuplicateListBoundary.insert(fTmp);
-			facesBound.push_back(fTmp);
-		}
-	}
-
-
-
-
-
-
-
-
-	for(unsigned int i=0;i<facesBound.size();i++){
-		double x = 0.0;
-		double y = 0.0;
-		double z = 0.0;
-
-		std::list<GVertex*> vertices;
-
-		vertices = facesBound[i]->vertices();
-
-		for(std::list<GVertex*>::iterator it2=vertices.begin();it2!=vertices.end();it2++){
-			x = x + (*it2)->x();
-			y = y + (*it2)->y();
-			z = z + (*it2)->z();
-		}
-
-		x = x/vertices.size();
-		y = y/vertices.size();
-		z = z/vertices.size();
-
-		centers.insert(std::pair<GFace*,SPoint3>(facesBound[i],SPoint3(x,y,z)));
-	}
-
-	for(unsigned int i=0;i<facesBound.size();i++){
-		for(unsigned int j=0;j<facesBound.size();j++){
-			std::map<GFace*,SPoint3>::iterator it3 = centers.find(facesBound[i]);
-			std::map<GFace*,SPoint3>::iterator it4 = centers.find(facesBound[j]);
-
-			SPoint3 p1 = it3->second;
-			SPoint3 p2 = it4->second;
-
-
-			//				categories.push_back(val);
-
-			//				print_segment(p1,p2,file);
-
-			if (abs((p2.x()-p1.x()-1.0))<0.0001){
-				if (abs((p2.y()-p1.y()))<0.0001){
-					if (abs((p2.z()-p1.z()))<0.0001){
-						pairs.push_back(std::pair<GFace*,GFace*>(facesBound[i],facesBound[j]));
-						ToDuplicateListBoundary.insert(facesBound[i]);
-					}else if(abs((p2.z()-p1.z()-1.0))<0.0001){
-						pairs.push_back(std::pair<GFace*,GFace*>(facesBound[i],facesBound[j]));
-						ToDuplicateListBoundary.insert(facesBound[i]);
-					}else if (abs((p1.z()-p2.z()-1.0))<0.0001){
-						pairs.push_back(std::pair<GFace*,GFace*>(facesBound[i],facesBound[j]));
-						ToDuplicateListBoundary.insert(facesBound[i]);
-					}
-				}else if (abs((p2.y()-p1.y()-1.0))<0.0001){
-					if (abs((p2.z()-p1.z()))<0.0001){
-						pairs.push_back(std::pair<GFace*,GFace*>(facesBound[i],facesBound[j]));
-						ToDuplicateListBoundary.insert(facesBound[i]);
-					}else if (abs((p2.z()-p1.z()-1.0))<0.0001){
-						pairs.push_back(std::pair<GFace*,GFace*>(facesBound[i],facesBound[j]));
-						ToDuplicateListBoundary.insert(facesBound[i]);
-					}else if (abs((p1.z()-p2.z()-1.0))<0.0001){
-						pairs.push_back(std::pair<GFace*,GFace*>(facesBound[i],facesBound[j]));
-						ToDuplicateListBoundary.insert(facesBound[i]);
-					}
-				}else if (abs((p1.y()-p2.y()-1.0))<0.0001){
-					if (abs((p2.z()-p1.z()))<0.0001){
-						pairs.push_back(std::pair<GFace*,GFace*>(facesBound[i],facesBound[j]));
-						ToDuplicateListBoundary.insert(facesBound[i]);
-					}else if (abs((p2.z()-p1.z()-1.0))<0.0001){
-						pairs.push_back(std::pair<GFace*,GFace*>(facesBound[i],facesBound[j]));
-						ToDuplicateListBoundary.insert(facesBound[i]);
-					}else if (abs((p1.z()-p2.z()-1.0))<0.0001){
-						pairs.push_back(std::pair<GFace*,GFace*>(facesBound[i],facesBound[j]));
-						ToDuplicateListBoundary.insert(facesBound[i]);
-					}
-				}
-			}else if (abs((p1.x()-p2.x()-1.0))<0.0001){
-				if (abs((p2.y()-p1.y()))<0.0001){
-					if (abs((p2.z()-p1.z()))<0.0001){
-						//NOTHING
-					}else if(abs((p2.z()-p1.z()-1.0))<0.0001){
-						//NOTHING
-					}else if (abs((p1.z()-p2.z()-1.0))<0.0001){
-						//NOTHING
-					}
-				}else if (abs((p2.y()-p1.y()-1.0))<0.0001){
-					if (abs((p2.z()-p1.z()))<0.0001){
-						//NOTHING
-					}else if (abs((p2.z()-p1.z()-1.0))<0.0001){
-						//NOTHING
-					}else if (abs((p1.z()-p2.z()-1.0))<0.0001){
-						//NOTHING
-					}
-				}else if (abs((p1.y()-p2.y()-1.0))<0.0001){
-					if (abs((p2.z()-p1.z()))<0.0001){
-						//NOTHING
-					}else if (abs((p2.z()-p1.z()-1.0))<0.0001){
-						//NOTHING
-					}else if (abs((p1.z()-p2.z()-1.0))<0.0001){
-						//NOTHING
-					}
-				}
-			}else if (abs((p1.x()-p2.x()))<0.0001){
-				if (abs((p2.y()-p1.y()-1.0))<0.0001){
-					if (abs((p2.z()-p1.z()))<0.0001){
-						pairs.push_back(std::pair<GFace*,GFace*>(facesBound[i],facesBound[j]));
-						ToDuplicateListBoundary.insert(facesBound[i]);
-					}else if (abs((p2.z()-p1.z()-1.0))<0.0001){
-						pairs.push_back(std::pair<GFace*,GFace*>(facesBound[i],facesBound[j]));
-						ToDuplicateListBoundary.insert(facesBound[i]);
-					}else if (abs((p1.z()-p2.z()-1.0))<0.0001){
-						pairs.push_back(std::pair<GFace*,GFace*>(facesBound[i],facesBound[j]));
-						ToDuplicateListBoundary.insert(facesBound[i]);
-					}
-				}else if (abs((p1.y()-p2.y()-1.0))<0.0001){
-					if (abs((p2.z()-p1.z()))<0.0001){
-						//NOTHING
-					}else if (abs((p2.z()-p1.z()-1.0))<0.0001){
-						//NOTHING
-					}else if (abs((p1.z()-p2.z()-1.0))<0.0001){
-						//NOTHING
-					}
-				}else if (abs((p1.y()-p2.y()))<0.0001){
-					if (abs((p2.z()-p1.z()-1.0))<0.0001){
-						pairs.push_back(std::pair<GFace*,GFace*>(facesBound[i],facesBound[j]));
-						ToDuplicateListBoundary.insert(facesBound[i]);
-					}else if (abs((p1.z()-p2.z()-1.0))<0.0001){
-						//NOTHING
-					}
-				}
-			}
-		}
-	}
-
-
-
-
-
-
-
-
-
-
-	std::map<std::pair<MVertex*,GRegion*>,MVertex* > VertexGlobalAssociation;
-	std::map<std::pair<GVertex*,GRegion*>,GVertex* > GVertexGlobalAssociation;
-	std::map<std::pair<GEdge*,GRegion*>,GEdge* > GEdgeGlobalAssociation;
-	std::map<std::pair<GFace*,GRegion*>,GFace* > GFaceGlobalAssociation;
-//	for (GModel::viter itv= m->firstVertex();itv != m->lastVertex();itv++){
-//		GVertex* vTmp = (*itv);
-//		std::vector<GVertex* > vecTmp;
-//		vecTmp.clear();
-//		GVertexGlobalAssociation[vTmp] = vecTmp;
-//		for (int i = 0; i < vTmp->mesh_vertices.size();i++){
-//			MVertex *vMesh = vTmp->mesh_vertices[i];
-//			std::vector<MVertex* > vecTmpBis;
-//			vecTmpBis.clear();
-//			VertexGlobalAssociation[vMesh] = vecTmpBis;
-//		}
-//	}
-//	for (GModel::eiter ite= m->firstEdge();ite != m->lastEdge();ite++){
-//		GEdge* eTmp = (*ite);
-//		std::vector<GEdge* > vecTmp;
-//		vecTmp.clear();
-//		GEdgeGlobalAssociation[eTmp] = vecTmp;
-//		for (int i = 0; i < eTmp->mesh_vertices.size();i++){
-//			MVertex *vMesh = eTmp->mesh_vertices[i];
-//			std::vector<MVertex* > vecTmpBis;
-//			vecTmpBis.clear();
-//			VertexGlobalAssociation[vMesh] = vecTmpBis;
-//		}
-//	}
-//	for (GModel::fiter itf= m->firstFace();itf != m->lastFace();itf++){
-//		GFace* fTmp = (*itf);
-//		for (int i = 0; i < fTmp->mesh_vertices.size();i++){
-//			MVertex *vMesh = fTmp->mesh_vertices[i];
-//			std::vector<MVertex* > vecTmpBis;
-//			vecTmpBis.clear();
-//			VertexGlobalAssociation[vMesh] = vecTmpBis;
-//		}
-//	}
-//	for (GModel::riter itr= m->firstRegion();itr != m->lastRegion();itr++){
-//		GRegion* rTmp = (*itr);
-//		for (int i = 0; i < rTmp->mesh_vertices.size();i++){
-//			MVertex *vMesh = rTmp->mesh_vertices[i];
-//			std::vector<MVertex* > vecTmpBis;
-//			vecTmpBis.clear();
-//			VertexGlobalAssociation[vMesh] = vecTmpBis;
-//		}
-//	}
-	for (GModel::riter itr= m->firstRegion();itr != m->lastRegion();itr++){
-		GRegion* rTmp = (*itr);
-		std::list<GFace*> RegFaces = rTmp->faces();
-		std::map<MVertex*,MVertex* > VertexAssociation;
-		std::map<GVertex*,GVertex* > GVertexAssociation;
-		std::map<GEdge*,GEdge* > GEdgeAssociation;
-		//int counterNbDone = 10000;
-		double xCenterReg = 0.0;
-		double yCenterReg = 0.0;
-		double zCenterReg = 0.0;
-		int counterPts = 0;
-		for(std::list<GFace*>::iterator it2=RegFaces.begin();it2!=RegFaces.end();it2++){
-			GFace* fTemp = (*it2);
-			std::list<GVertex*> verticesFace = fTemp->vertices();
-			for (std::list<GVertex*>::iterator it3=verticesFace.begin();it3!=verticesFace.end();it3++){
-				xCenterReg = xCenterReg + (*it3)->x();
-				yCenterReg = yCenterReg + (*it3)->y();
-				zCenterReg = zCenterReg + (*it3)->z();
-				counterPts++;
-			}
-		}
-		xCenterReg = xCenterReg/counterPts;
-		yCenterReg = yCenterReg/counterPts;
-		zCenterReg = zCenterReg/counterPts;
-		//duplication noeud et aretes au niveau de la region directement
-		std::list<GVertex*> vlist;
-
-
-		std::list<GFace*> listFacesTmp = rTmp->faces();
-		for (std::list<GFace*>::iterator itTp = listFacesTmp.begin();itTp != listFacesTmp.end();itTp++){
-			std::list<GVertex*> vlist2;
-			vlist2 = (*itTp)->vertices();
-			for (std::list<GVertex*>::iterator itTp2 = vlist2.begin();itTp2 != vlist2.end();itTp2++){
-				if(std::find(vlist.begin(), vlist.end(), *itTp2) == vlist.end())
-					vlist.push_back(*itTp2);
-			}
-		}
-
-
-		for (std::list<GVertex*>::iterator itv = vlist.begin();itv != vlist.end();itv++){
-			//duplication Gvertex
-			GVertex* vTmp = (*itv);
-			double ponderatedX = 0.99999999999 * vTmp->x() + 0.00000000001 * xCenterReg;
-			double ponderatedY = 0.99999999999 * vTmp->y() + 0.00000000001 * yCenterReg;
-			double ponderatedZ = 0.99999999999 * vTmp->z() + 0.00000000001 * zCenterReg;
-			GVertex* newv = m->addVertex(ponderatedX,ponderatedY,ponderatedZ,vTmp->prescribedMeshSizeAtVertex());
-			GVertexAssociation[vTmp] = newv;
-			GVertexGlobalAssociation[std::make_pair(vTmp,rTmp)] = newv;
-			//creation des Gedge correspondantes
-//			GEdge* newE = m->addLine(vTmp,newv);
-//			SurroudingEdges[vTmp] = newE;
-			//maintenant traitement mesh
-			MVertex *vMesh = vTmp->mesh_vertices[0];
-			MVertex *newMv = new MVertex(vMesh->x(), vMesh->y(), vMesh->z(), (GEntity*)newv);
-			VertexAssociation[vMesh] = newMv;
-			VertexGlobalAssociation[std::make_pair(vMesh,rTmp)] = newMv;
-			newv->addMeshVertex(newMv);
-		}
-		//maintenant on soccupe de duppliquer les edges de la region
-		std::list<GEdge*> elist = rTmp->edges();
-
-		std::vector<GFace*> SurroundingsFaces;
-		for (std::list<GEdge*>::iterator ite = elist.begin();ite != elist.end();ite++){
-			//duplication Gedge
-			GEdge* eTmp = (*ite);
-			GEdge* newE = m->addLine(GVertexAssociation[eTmp->getEndVertex()],GVertexAssociation[eTmp->getBeginVertex()]);
-			GEdgeAssociation[eTmp] = newE;
-			GEdgeGlobalAssociation[std::make_pair(eTmp,rTmp)] = newE;
-			//creation des GFace correspondantes
-//			GEdge* firstE = SurroudingEdges.find(eTmp->getEndVertex())->second;
-//			GEdge* lastE = SurroudingEdges.find(eTmp->getBeginVertex())->second;
-//			std::vector<GEdge*> VecEdgesTmp;
-//			VecEdgesTmp.push_back(eTmp);
-//			VecEdgesTmp.push_back(firstE);
-//			VecEdgesTmp.push_back(newE);
-//			VecEdgesTmp.push_back(lastE);
-//			std::vector<std::vector<GEdge*> > VecOfVecTmp;
-//			VecOfVecTmp.push_back(VecEdgesTmp);
-//			GFace* newFaceTmp = m->addPlanarFace(VecOfVecTmp);
-//			SurroundingsFaces.push_back(newFaceTmp);
-			//maintenant traitement mesh
-			for (unsigned int i = 0; i < eTmp->mesh_vertices.size();i++){
-				MVertex *vMesh = eTmp->mesh_vertices[i];
-				MVertex *newMv = new MVertex(vMesh->x(), vMesh->y(), vMesh->z(), (GEntity*)newE);
-				VertexAssociation[vMesh] = newMv;
-				VertexGlobalAssociation[std::make_pair(vMesh,rTmp)] = newMv;
-				newE->addMeshVertex(newMv);
-			}
-			for (unsigned int i = 0; i < eTmp->getNumMeshElements();i++){
-				MElement* elem = eTmp->getMeshElement(i);
-				MVertex *firstETmp = VertexAssociation.find(elem->getVertex(0))->second;
-				MVertex *lastETmp = VertexAssociation.find(elem->getVertex(1))->second;
-				MVertex *midETmp = VertexAssociation.find(elem->getVertex(2))->second;
-				MLine3 *newLine = new MLine3(firstETmp,lastETmp,midETmp);
-				newE->addLine(newLine);
-			}
-		}
-		for (std::list<GFace*>::iterator itf = RegFaces.begin();itf != RegFaces.end();itf++){
-			GFace* fTmp = (*itf);
-			std::vector<GEdge*> newEdgesVector;
-			std::list<GEdge*> elistFace = fTmp->edges();
-			for (std::list<GEdge*>::iterator ite = elistFace.begin();ite != elistFace.end();ite++){
-				GEdge* eTmp = (*ite);
-				GEdge* eToFind = GEdgeAssociation[eTmp];
-				newEdgesVector.push_back(eToFind);
-			}
-			std::vector<std::vector<GEdge*> > VecOfVec;
-			VecOfVec.push_back(newEdgesVector);
-			//creation de la nouvelle face
-			GFace* GFaceAssociation = m->addPlanarFace(VecOfVec);
-//			int tagTmp = GFaceAssociation->tag();
-//			std::ostringstream ss;
-//			ss << tagTmp;
-////			char *intStr = itoa(tagTmp);
-//			std::string nameSurf = "SURFACE";
-////			nameSurf += std::string(intStr);
-//			nameSurf += ss.str();
-//			int PhysicalSurfaceTmp = m->setPhysicalName(nameSurf,2);
-//			GFaceAssociation->addPhysicalEntity(PhysicalSurfaceTmp);
-			//maintenant traitement mesh
-			for (unsigned int i = 0; i < fTmp->mesh_vertices.size();i++){
-				MVertex *vMesh = fTmp->mesh_vertices[i];
-				MVertex *newMv = new MVertex(vMesh->x(), vMesh->y(), vMesh->z(), (GEntity*)GFaceAssociation);
-				VertexAssociation[vMesh] = newMv;
-				VertexGlobalAssociation[std::make_pair(vMesh,rTmp)] = newMv;
-				GFaceAssociation->addMeshVertex(newMv);
-			}
-			for (unsigned int i = 0; i < fTmp->getNumMeshElements();i++){
-				MElement* elem = fTmp->getMeshElement(i);
-				MVertex *firstE = VertexAssociation.find(elem->getVertex(0))->second;
-				MVertex *secondE = VertexAssociation.find(elem->getVertex(1))->second;
-				MVertex *thirdE = VertexAssociation.find(elem->getVertex(2))->second;
-				MVertex *fourthE = VertexAssociation.find(elem->getVertex(3))->second;
-				MVertex *fifthE = VertexAssociation.find(elem->getVertex(4))->second;
-				MVertex *sisthE = VertexAssociation.find(elem->getVertex(5))->second;
-				MTriangle6 *newTri = new MTriangle6(firstE,secondE,thirdE,fourthE,fifthE,sisthE);
-				GFaceAssociation->addTriangle(newTri);
-			}
-			GFaceGlobalAssociation[std::make_pair(fTmp,rTmp)] = GFaceAssociation;
-		}
-	}
-	int counterNbDone = 10000;
-	//maintenant on va traiter les faces initiales
-	for (std::set<GFace*>::iterator itf = ToDuplicateList.begin();itf != ToDuplicateList.end();itf++){
-		counterNbDone++;
-		GFace* fTmp = (*itf);
-		GRegion* reg1 = fTmp->getRegion(0);
-		GRegion* reg2 = fTmp->getRegion(1);
-		//pour commencer on cree des aretes entre les vertex
-		std::list<GVertex*> vlist = fTmp->vertices();
-		std::map<GVertex*,GEdge* > SurroudingEdges;
-		for (std::list<GVertex*>::iterator itv = vlist.begin();itv != vlist.end();itv++){
-			GVertex* vTmp = (*itv);
-			GVertex* v1=0;
-			GVertex* v2=0;
-			std::map<std::pair<GVertex*,GRegion*>,GVertex* >::iterator itMap = GVertexGlobalAssociation.find(std::make_pair(vTmp,reg1));
-			if (itMap != GVertexGlobalAssociation.end()){
-				v1 = itMap->second;
-			}
-			itMap = GVertexGlobalAssociation.find(std::make_pair(vTmp,reg2));
-			if (itMap != GVertexGlobalAssociation.end()){
-				v2 = itMap->second;
-			}
-			GEdge* newE = m->addLine(v1,v2);
-			SurroudingEdges[vTmp] = newE;
-		}
-		//ici tous les vertex sont traites
-		//on va traiter les edges
-		std::list<GEdge*> elist = fTmp->edges();
-		std::vector<GEdge*> newEdgesVector;
-		std::vector<GFace*> SurroundingsFaces;
-		for (std::list<GEdge*>::iterator ite = elist.begin();ite != elist.end();ite++){
-			//duplication Gedge
-			GEdge* eTmp = (*ite);
-			GEdge* e1=0;
-			GEdge* e2=0;
-			std::map<std::pair<GEdge*,GRegion*>,GEdge* >::iterator itMap = GEdgeGlobalAssociation.find(std::make_pair(eTmp,reg1));
-			if (itMap != GEdgeGlobalAssociation.end()){
-				e1 = itMap->second;
-			}
-			itMap = GEdgeGlobalAssociation.find(std::make_pair(eTmp,reg2));
-			if (itMap != GEdgeGlobalAssociation.end()){
-				e2 = itMap->second;
-			}
-			//creation des GFace correspondantes
-			GEdge* firstE = SurroudingEdges.find(eTmp->getBeginVertex())->second;
-			GEdge* lastE = SurroudingEdges.find(eTmp->getEndVertex())->second;
-			if (firstE->getBeginVertex() != e1->getEndVertex()){
-				firstE->reverse();
-			}
-			if (firstE->getBeginVertex() != e1->getEndVertex()){
-				e1->reverse();
-			}
-			if (firstE->getBeginVertex() != e1->getEndVertex()){
-				firstE->reverse();
-			}
-			if (e2->getBeginVertex() != firstE->getEndVertex()){
-				e2->reverse();
-			}
-			if (lastE->getBeginVertex() != e2->getEndVertex()){
-				lastE->reverse();
-			}
-			std::vector<GEdge*> VecEdgesTmp;
-			VecEdgesTmp.push_back(e1);
-			VecEdgesTmp.push_back(firstE);
-			VecEdgesTmp.push_back(e2);
-			VecEdgesTmp.push_back(lastE);
-			std::vector<std::vector<GEdge*> > VecOfVecTmp;
-			VecOfVecTmp.push_back(VecEdgesTmp);
-			GFace* newFaceTmp = m->addPlanarFace(VecOfVecTmp);
-			SurroundingsFaces.push_back(newFaceTmp);
-		}
-		std::vector<GFace*> VectorFaces;
-		std::list<GFace*> listFaces;
-		GFace* f1;
-		GFace* f2;
-		std::map<std::pair<GFace*,GRegion*>,GFace* >::iterator itMap = GFaceGlobalAssociation.find(std::make_pair(fTmp,reg1));
-		if (itMap != GFaceGlobalAssociation.end()){
-			f1 = itMap->second;
-		}
-		itMap = GFaceGlobalAssociation.find(std::make_pair(fTmp,reg2));
-		if (itMap != GFaceGlobalAssociation.end()){
-			f2 = itMap->second;
-		}
-		VectorFaces.push_back(f1);
-		listFaces.push_back(f1);
-		for (unsigned int i = 0;i < SurroundingsFaces.size();i++){
-			VectorFaces.push_back(SurroundingsFaces[i]);
-			listFaces.push_back(SurroundingsFaces[i]);
-		}
-		VectorFaces.push_back(f2);
-		listFaces.push_back(f2);
-		std::vector<std::vector<GFace*> > VecOfVecGFace;
-		VecOfVecGFace.push_back(VectorFaces);
-		//creation de la nouvelle region
-		GRegion* createdRegion = new GRegion(m,counterNbDone);
-		createdRegion->addPhysicalEntity(PhysicalInterface);
-		createdRegion->set(listFaces);
-		m->add(createdRegion);
-		for (unsigned int i = 0; i < fTmp->getNumMeshElements();i++){
-			MElement* elem = fTmp->getMeshElement(i);
-			MVertex* v1=0;
-			MVertex* v2=0;
-			MVertex* v3=0;
-			MVertex* v4=0;
-			MVertex* v5=0;
-			MVertex* v6=0;
-			std::map<std::pair<MVertex*,GRegion*>,MVertex* >::iterator itMap = VertexGlobalAssociation.find(std::make_pair(elem->getVertex(0),reg1));
-			if (itMap != VertexGlobalAssociation.end()){
-				v1 = itMap->second;
-			}
-			itMap = VertexGlobalAssociation.find(std::make_pair(elem->getVertex(3),reg1));
-			if (itMap != VertexGlobalAssociation.end()){
-				v2 = itMap->second;
-			}
-			itMap = VertexGlobalAssociation.find(std::make_pair(elem->getVertex(5),reg1));
-			if (itMap != VertexGlobalAssociation.end()){
-				v3 = itMap->second;
-			}
-			itMap = VertexGlobalAssociation.find(std::make_pair(elem->getVertex(0),reg2));
-			if (itMap != VertexGlobalAssociation.end()){
-				v4 = itMap->second;
-			}
-			itMap = VertexGlobalAssociation.find(std::make_pair(elem->getVertex(3),reg2));
-			if (itMap != VertexGlobalAssociation.end()){
-				v5 = itMap->second;
-			}
-			itMap = VertexGlobalAssociation.find(std::make_pair(elem->getVertex(5),reg2));
-			if (itMap != VertexGlobalAssociation.end()){
-				v6 = itMap->second;
-			}
-			MPrism *newPri = new MPrism(v1,v3,v2,v4,v6,v5);
-
-			createdRegion->addPrism(newPri);
-
-			//second
-			itMap = VertexGlobalAssociation.find(std::make_pair(elem->getVertex(1),reg1));
-			if (itMap != VertexGlobalAssociation.end()){
-				v1 = itMap->second;
-			}
-			itMap = VertexGlobalAssociation.find(std::make_pair(elem->getVertex(4),reg1));
-			if (itMap != VertexGlobalAssociation.end()){
-				v2 = itMap->second;
-			}
-			itMap = VertexGlobalAssociation.find(std::make_pair(elem->getVertex(3),reg1));
-			if (itMap != VertexGlobalAssociation.end()){
-				v3 = itMap->second;
-			}
-			itMap = VertexGlobalAssociation.find(std::make_pair(elem->getVertex(1),reg2));
-			if (itMap != VertexGlobalAssociation.end()){
-				v4 = itMap->second;
-			}
-			itMap = VertexGlobalAssociation.find(std::make_pair(elem->getVertex(4),reg2));
-			if (itMap != VertexGlobalAssociation.end()){
-				v5 = itMap->second;
-			}
-			itMap = VertexGlobalAssociation.find(std::make_pair(elem->getVertex(3),reg2));
-			if (itMap != VertexGlobalAssociation.end()){
-				v6 = itMap->second;
-			}
-			MPrism *newPri2 = new MPrism(v1,v3,v2,v4,v6,v5);
-
-			createdRegion->addPrism(newPri2);
-			//third
-			itMap = VertexGlobalAssociation.find(std::make_pair(elem->getVertex(2),reg1));
-			if (itMap != VertexGlobalAssociation.end()){
-				v1 = itMap->second;
-			}
-			itMap = VertexGlobalAssociation.find(std::make_pair(elem->getVertex(5),reg1));
-			if (itMap != VertexGlobalAssociation.end()){
-				v2 = itMap->second;
-			}
-			itMap = VertexGlobalAssociation.find(std::make_pair(elem->getVertex(4),reg1));
-			if (itMap != VertexGlobalAssociation.end()){
-				v3 = itMap->second;
-			}
-			itMap = VertexGlobalAssociation.find(std::make_pair(elem->getVertex(2),reg2));
-			if (itMap != VertexGlobalAssociation.end()){
-				v4 = itMap->second;
-			}
-			itMap = VertexGlobalAssociation.find(std::make_pair(elem->getVertex(5),reg2));
-			if (itMap != VertexGlobalAssociation.end()){
-				v5 = itMap->second;
-			}
-			itMap = VertexGlobalAssociation.find(std::make_pair(elem->getVertex(4),reg2));
-			if (itMap != VertexGlobalAssociation.end()){
-				v6 = itMap->second;
-			}
-			MPrism *newPri3 = new MPrism(v1,v3,v2,v4,v6,v5);
-
-			createdRegion->addPrism(newPri3);
-			//fourth
-			itMap = VertexGlobalAssociation.find(std::make_pair(elem->getVertex(3),reg1));
-			if (itMap != VertexGlobalAssociation.end()){
-				v1 = itMap->second;
-			}
-			itMap = VertexGlobalAssociation.find(std::make_pair(elem->getVertex(4),reg1));
-			if (itMap != VertexGlobalAssociation.end()){
-				v2 = itMap->second;
-			}
-			itMap = VertexGlobalAssociation.find(std::make_pair(elem->getVertex(5),reg1));
-			if (itMap != VertexGlobalAssociation.end()){
-				v3 = itMap->second;
-			}
-			itMap = VertexGlobalAssociation.find(std::make_pair(elem->getVertex(3),reg2));
-			if (itMap != VertexGlobalAssociation.end()){
-				v4 = itMap->second;
-			}
-			itMap = VertexGlobalAssociation.find(std::make_pair(elem->getVertex(4),reg2));
-			if (itMap != VertexGlobalAssociation.end()){
-				v5 = itMap->second;
-			}
-			itMap = VertexGlobalAssociation.find(std::make_pair(elem->getVertex(5),reg2));
-			if (itMap != VertexGlobalAssociation.end()){
-				v6 = itMap->second;
-			}
-			MPrism *newPri4 = new MPrism(v1,v3,v2,v4,v6,v5);
-
-			createdRegion->addPrism(newPri4);
-		}
-		for (unsigned int i = 0; i < reg1->getNumMeshElements();i++){
-			MElement* elem = reg1->getMeshElement(i);
-			for (int j = 0;j < elem->getNumVertices();j++){
-				MVertex* vert = elem->getVertex(j);
-				std::map<std::pair<MVertex*,GRegion*>,MVertex* >::iterator itMap = VertexGlobalAssociation.find(std::make_pair(vert,reg1));
-				if (itMap != VertexGlobalAssociation.end()){
-					elem->setVertex(j,itMap->second);
-				}
-			}
-		}
-		for (unsigned int i = 0; i < reg2->getNumMeshElements();i++){
-			MElement* elem = reg2->getMeshElement(i);
-			for (int j = 0;j < elem->getNumVertices();j++){
-				MVertex* vert = elem->getVertex(j);
-				std::map<std::pair<MVertex*,GRegion*>,MVertex* >::iterator itMap = VertexGlobalAssociation.find(std::make_pair(vert,reg2));
-				if (itMap != VertexGlobalAssociation.end()){
-					elem->setVertex(j,itMap->second);
-				}
-			}
-		}
-	}
-	//maintenant on va traiter les faces du bord
-	for (std::set<GFace*>::iterator itf = ToDuplicateListBoundary.begin();itf != ToDuplicateListBoundary.end();itf++){
-		counterNbDone++;
-		GFace* fTmp = (*itf);
-		GRegion* reg1 = fTmp->getRegion(0);
-		//pour commencer on cree des aretes entre les vertex
-		std::list<GVertex*> vlist = fTmp->vertices();
-		std::map<GVertex*,GEdge* > SurroudingEdges;
-		for (std::list<GVertex*>::iterator itv = vlist.begin();itv != vlist.end();itv++){
-			GVertex* vTmp = (*itv);
-			GVertex* v1=0;
-			std::map<std::pair<GVertex*,GRegion*>,GVertex* >::iterator itMap = GVertexGlobalAssociation.find(std::make_pair(vTmp,reg1));
-			if (itMap != GVertexGlobalAssociation.end()){
-				v1 = itMap->second;
-			}
-			GEdge* newE = m->addLine(v1,vTmp);
-			SurroudingEdges[vTmp] = newE;
-		}
-		//ici tous les vertex sont traites
-		//on va traiter les edges
-		std::list<GEdge*> elist = fTmp->edges();
-		std::vector<GEdge*> newEdgesVector;
-		std::vector<GFace*> SurroundingsFaces;
-		for (std::list<GEdge*>::iterator ite = elist.begin();ite != elist.end();ite++){
-			//duplication Gedge
-			GEdge* eTmp = (*ite);
-			GEdge* e1=0;
-			std::map<std::pair<GEdge*,GRegion*>,GEdge* >::iterator itMap = GEdgeGlobalAssociation.find(std::make_pair(eTmp,reg1));
-			if (itMap != GEdgeGlobalAssociation.end()){
-				e1 = itMap->second;
-			}
-			//creation des GFace correspondantes
-			GEdge* firstE = SurroudingEdges.find(eTmp->getBeginVertex())->second;
-			GEdge* lastE = SurroudingEdges.find(eTmp->getEndVertex())->second;
-			if (firstE->getBeginVertex() != e1->getEndVertex()){
-				firstE->reverse();
-			}
-			if (firstE->getBeginVertex() != e1->getEndVertex()){
-				e1->reverse();
-			}
-			if (firstE->getBeginVertex() != e1->getEndVertex()){
-				firstE->reverse();
-			}
-			if (eTmp->getBeginVertex() != firstE->getEndVertex()){
-				eTmp->reverse();
-			}
-			if (lastE->getBeginVertex() != eTmp->getEndVertex()){
-				lastE->reverse();
-			}
-			std::vector<GEdge*> VecEdgesTmp;
-			VecEdgesTmp.push_back(e1);
-			VecEdgesTmp.push_back(firstE);
-			VecEdgesTmp.push_back(eTmp);
-			VecEdgesTmp.push_back(lastE);
-			std::vector<std::vector<GEdge*> > VecOfVecTmp;
-			VecOfVecTmp.push_back(VecEdgesTmp);
-			GFace* newFaceTmp = m->addPlanarFace(VecOfVecTmp);
-			SurroundingsFaces.push_back(newFaceTmp);
-		}
-		std::vector<GFace*> VectorFaces;
-		std::list<GFace*> listFaces;
-		GFace* f1;
-		std::map<std::pair<GFace*,GRegion*>,GFace* >::iterator itMap = GFaceGlobalAssociation.find(std::make_pair(fTmp,reg1));
-		if (itMap != GFaceGlobalAssociation.end()){
-			f1 = itMap->second;
-		}
-		VectorFaces.push_back(f1);
-		listFaces.push_back(f1);
-		for (unsigned int i = 0;i < SurroundingsFaces.size();i++){
-			VectorFaces.push_back(SurroundingsFaces[i]);
-			listFaces.push_back(SurroundingsFaces[i]);
-		}
-		VectorFaces.push_back(fTmp);
-		listFaces.push_back(fTmp);
-		std::vector<std::vector<GFace*> > VecOfVecGFace;
-		VecOfVecGFace.push_back(VectorFaces);
-		//creation de la nouvelle region
-		GRegion* createdRegion = new GRegion(m,counterNbDone);
-		createdRegion->addPhysicalEntity(PhysicalInterface);
-		createdRegion->set(listFaces);
-		m->add(createdRegion);
-		for (unsigned int i = 0; i < fTmp->getNumMeshElements();i++){
-			MElement* elem = fTmp->getMeshElement(i);
-			MVertex* v1=0;
-			MVertex* v2=0;
-			MVertex* v3=0;
-			std::map<std::pair<MVertex*,GRegion*>,MVertex* >::iterator itMap = VertexGlobalAssociation.find(std::make_pair(elem->getVertex(0),reg1));
-			if (itMap != VertexGlobalAssociation.end()){
-				v1 = itMap->second;
-			}
-			itMap = VertexGlobalAssociation.find(std::make_pair(elem->getVertex(3),reg1));
-			if (itMap != VertexGlobalAssociation.end()){
-				v2 = itMap->second;
-			}
-			itMap = VertexGlobalAssociation.find(std::make_pair(elem->getVertex(5),reg1));
-			if (itMap != VertexGlobalAssociation.end()){
-				v3 = itMap->second;
-			}
-			MPrism *newPri = new MPrism(v1,v3,v2,elem->getVertex(0),elem->getVertex(5),elem->getVertex(3));
-
-			createdRegion->addPrism(newPri);
-			//second
-			itMap = VertexGlobalAssociation.find(std::make_pair(elem->getVertex(1),reg1));
-			if (itMap != VertexGlobalAssociation.end()){
-				v1 = itMap->second;
-			}
-			itMap = VertexGlobalAssociation.find(std::make_pair(elem->getVertex(4),reg1));
-			if (itMap != VertexGlobalAssociation.end()){
-				v2 = itMap->second;
-			}
-			itMap = VertexGlobalAssociation.find(std::make_pair(elem->getVertex(3),reg1));
-			if (itMap != VertexGlobalAssociation.end()){
-				v3 = itMap->second;
-			}
-			MPrism *newPri2 = new MPrism(v1,v3,v2,elem->getVertex(1),elem->getVertex(3),elem->getVertex(4));
-
-			createdRegion->addPrism(newPri2);
-			//third
-			itMap = VertexGlobalAssociation.find(std::make_pair(elem->getVertex(2),reg1));
-			if (itMap != VertexGlobalAssociation.end()){
-				v1 = itMap->second;
-			}
-			itMap = VertexGlobalAssociation.find(std::make_pair(elem->getVertex(5),reg1));
-			if (itMap != VertexGlobalAssociation.end()){
-				v2 = itMap->second;
-			}
-			itMap = VertexGlobalAssociation.find(std::make_pair(elem->getVertex(4),reg1));
-			if (itMap != VertexGlobalAssociation.end()){
-				v3 = itMap->second;
-			}
-			MPrism *newPri3 = new MPrism(v1,v3,v2,elem->getVertex(2),elem->getVertex(4),elem->getVertex(5));
-
-			createdRegion->addPrism(newPri3);
-			//fourth
-			itMap = VertexGlobalAssociation.find(std::make_pair(elem->getVertex(3),reg1));
-			if (itMap != VertexGlobalAssociation.end()){
-				v1 = itMap->second;
-			}
-			itMap = VertexGlobalAssociation.find(std::make_pair(elem->getVertex(4),reg1));
-			if (itMap != VertexGlobalAssociation.end()){
-				v2 = itMap->second;
-			}
-			itMap = VertexGlobalAssociation.find(std::make_pair(elem->getVertex(5),reg1));
-			if (itMap != VertexGlobalAssociation.end()){
-				v3 = itMap->second;
-			}
-			MPrism *newPri4 = new MPrism(v1,v3,v2,elem->getVertex(3),elem->getVertex(5),elem->getVertex(4));
-
-			createdRegion->addPrism(newPri4);
-		}
-		for (unsigned int i = 0; i < reg1->getNumMeshElements();i++){
-			MElement* elem = reg1->getMeshElement(i);
-			for (int j = 0;j < elem->getNumVertices();j++){
-				MVertex* vert = elem->getVertex(j);
-				std::map<std::pair<MVertex*,GRegion*>,MVertex* >::iterator itMap = VertexGlobalAssociation.find(std::make_pair(vert,reg1));
-				if (itMap != VertexGlobalAssociation.end()){
-					elem->setVertex(j,itMap->second);
-				}
-			}
-		}
-	}
-	std::ofstream file("MicrostructurePolycrystal3D.pos");
-	file << "View \"test\" {\n";
-
-	std::ofstream file2("PERIODIC.map");
-	std::ofstream file3("SetAdd.map");
-	for (std::vector<std::pair<GFace*,GFace*> >::iterator itP = pairs.begin();itP != pairs.end();itP++){
-		std::pair<GFace*,GFace*> pairTmp = (*itP);
-		GFace* ToReplaceFace = pairTmp.second;
-		GRegion* rTmp = ToReplaceFace->getRegion(0);
-		std::map<std::pair<GFace*,GRegion*>,GFace* >::iterator itMap = GFaceGlobalAssociation.find(std::make_pair(ToReplaceFace,rTmp));
-		if (itMap != GFaceGlobalAssociation.end()){
-			GFace* associatedFace = (*itMap).second;
-
-
-
-
-
-			file3 <<associatedFace->tag()<<"\tSURFACE"<<associatedFace->tag()<<"\tNSET "<<"\n";
-
-			int tagTmp = associatedFace->tag();
-			std::ostringstream ss;
-			ss << tagTmp;
-//			char *intStr = itoa(tagTmp);
-			std::string nameSurf = "SURFACE";
-//			nameSurf += std::string(intStr);
-			nameSurf += ss.str();
-			int PhysicalSurfaceTmp = m->setPhysicalName(nameSurf,2);
-			associatedFace->addPhysicalEntity(PhysicalSurfaceTmp);
-
-			std::map<GFace*,SPoint3>::iterator it3 = centers.find(pairTmp.first);
-			std::map<GFace*,SPoint3>::iterator it4 = centers.find(ToReplaceFace);
-
-			SPoint3 p1 = it3->second;
-			SPoint3  p2 = it4->second;
-
-			//double delta_x = fabs(p2.x()-p1.x());
-			//double delta_y = fabs(p2.y()-p1.y());
-			//double delta_z = fabs(p2.z()-p1.z());
-
-
-			file << "SL ("
-					<< p1.x() << ", " << p1.y() << ", " << p1.z() << ", "
-					<< p2.x() << ", " << p2.y() << ", " << p2.z()
-					<< "){10, 20};\n";
-
-			//file2 << "PERIODIC\tSURFACE"<<faces[i]->tag() << "\tSURFACE" << faces[j]->tag() << "\t" << p2.x()-p1.x() << "\t" << p2.y()-p1.y() << "\t" << p2.z()-p1.z() << "\n";
-			if (abs((p2.x()-p1.x()-1.0))<0.0001){
-				if (abs((p2.y()-p1.y()))<0.0001){
-					if (abs((p2.z()-p1.z()))<0.0001){
-						file2 << "NSET\tFRONT = FRONT + SURFACE"<<associatedFace->tag()<<"\n";
-						file2 << "NSET\tBACK = BACK + SURFACE"<<pairTmp.first->tag()<<"\n";
-					}else if(abs((p2.z()-p1.z()-1.0))<0.0001){
-						file2 << "NSET\tFRONTTOP = FRONTTOP + SURFACE"<<associatedFace->tag()<<"\n";
-						file2 << "NSET\tBACKBOTTOM = BACKBOTTOM + SURFACE"<<pairTmp.first->tag()<<"\n";
-					}else if (abs((p1.z()-p2.z()-1.0))<0.0001){
-						file2 << "NSET\tFRONTBOTTOM = FRONTBOTTOM + SURFACE"<<associatedFace->tag()<<"\n";
-						file2 << "NSET\tBACKTOP = BACKTOP + SURFACE"<<pairTmp.first->tag()<<"\n";
-					}
-				}else if (abs((p2.y()-p1.y()-1.0))<0.0001){
-					if (abs((p2.z()-p1.z()))<0.0001){
-						file2 << "NSET\tFRONTRIGHT = FRONTRIGHT + SURFACE"<<associatedFace->tag()<<"\n";
-						file2 << "NSET\tBACKLEFT = BACKLEFT + SURFACE"<<pairTmp.first->tag()<<"\n";
-					}else if (abs((p2.z()-p1.z()-1.0))<0.0001){
-						file2 << "NSET\tFRONTRIGHTTOP = FRONTRIGHTTOP + SURFACE"<<associatedFace->tag()<<"\n";
-						file2 << "NSET\tBACKLEFTBOTTOM = BACKLEFTBOTTOM + SURFACE"<<pairTmp.first->tag()<<"\n";
-					}else if (abs((p1.z()-p2.z()-1.0))<0.0001){
-						file2 << "NSET\tFRONTRIGHTBOTTOM = FRONTRIGHTBOTTOM + SURFACE"<<associatedFace->tag()<<"\n";
-						file2 << "NSET\tBACKLEFTTOP = BACKLEFTTOP + SURFACE"<<pairTmp.first->tag()<<"\n";
-					}
-				}else if (abs((p1.y()-p2.y()-1.0))<0.0001){
-					if (abs((p2.z()-p1.z()))<0.0001){
-						file2 << "NSET\tFRONTLEFT = FRONTLEFT + SURFACE"<<associatedFace->tag()<<"\n";
-						file2 << "NSET\tBACKRIGHT = BACKRIGHT + SURFACE"<<pairTmp.first->tag()<<"\n";
-					}else if (abs((p2.z()-p1.z()-1.0))<0.0001){
-						file2 << "NSET\tFRONTLEFTTOP = FRONTLEFTTOP + SURFACE"<<associatedFace->tag()<<"\n";
-						file2 << "NSET\tBACKRIGHTBOTTOM = BACKRIGHTBOTTOM + SURFACE"<<pairTmp.first->tag()<<"\n";
-					}else if (abs((p1.z()-p2.z()-1.0))<0.0001){
-						file2 << "NSET\tFRONTLEFTBOTTOM = FRONTLEFTBOTTOM + SURFACE"<<associatedFace->tag()<<"\n";
-						file2 << "NSET\tBACKRIGHTTOP = BACKRIGHTTOP + SURFACE"<<pairTmp.first->tag()<<"\n";
-					}
-				}
-			}else if (abs((p1.x()-p2.x()-1.0))<0.0001){
-				if (abs((p2.y()-p1.y()))<0.0001){
-					if (abs((p2.z()-p1.z()))<0.0001){
-						file2 << "NSET\tFRONT = FRONT + SURFACE"<<pairTmp.first->tag()<<"\n";
-						file2 << "NSET\tBACK = BACK + SURFACE"<<associatedFace->tag()<<"\n";
-					}else if(abs((p2.z()-p1.z()-1.0))<0.0001){
-						file2 << "NSET\tFRONTBOTTOM = FRONTBOTTOM + SURFACE"<<pairTmp.first->tag()<<"\n";
-						file2 << "NSET\tBACKTOP = BACKTOP + SURFACE"<<associatedFace->tag()<<"\n";
-					}else if (abs((p1.z()-p2.z()-1.0))<0.0001){
-						file2 << "NSET\tFRONTTOP = FRONTTOP + SURFACE"<<pairTmp.first->tag()<<"\n";
-						file2 << "NSET\tBACKBOTTOM = BACKBOTTOM + SURFACE"<<associatedFace->tag()<<"\n";
-					}
-				}else if (abs((p2.y()-p1.y()-1.0))<0.0001){
-					if (abs((p2.z()-p1.z()))<0.0001){
-						file2 << "NSET\tFRONTLEFT = FRONTLEFT + SURFACE"<<pairTmp.first->tag()<<"\n";
-						file2 << "NSET\tBACKRIGHT = BACKRIGHT + SURFACE"<<associatedFace->tag()<<"\n";
-					}else if (abs((p2.z()-p1.z()-1.0))<0.0001){
-						file2 << "NSET\tFRONTLEFTBOTTOM = FRONTLEFTBOTTOM + SURFACE"<<pairTmp.first->tag()<<"\n";
-						file2 << "NSET\tBACKRIGHTTOP = BACKRIGHTTOP + SURFACE"<<associatedFace->tag()<<"\n";
-					}else if (abs((p1.z()-p2.z()-1.0))<0.0001){
-						file2 << "NSET\tFRONTLEFTTOP = FRONTLEFTTOP + SURFACE"<<pairTmp.first->tag()<<"\n";
-						file2 << "NSET\tBACKRIGHTBOTTOM = BACKRIGHTBOTTOM + SURFACE"<<associatedFace->tag()<<"\n";
-					}
-				}else if (abs((p1.y()-p2.y()-1.0))<0.0001){
-					if (abs((p2.z()-p1.z()))<0.0001){
-						file2 << "NSET\tFRONTRIGHT = FRONTRIGHT + SURFACE"<<pairTmp.first->tag()<<"\n";
-						file2 << "NSET\tBACKLEFT = BACKLEFT + SURFACE"<<associatedFace->tag()<<"\n";
-					}else if (abs((p2.z()-p1.z()-1.0))<0.0001){
-						file2 << "NSET\tFRONTRIGHTBOTTOM = FRONTRIGHTBOTTOM + SURFACE"<<pairTmp.first->tag()<<"\n";
-						file2 << "NSET\tBACKLEFTTOP = BACKLEFTTOP + SURFACE"<<associatedFace->tag()<<"\n";
-					}else if (abs((p1.z()-p2.z()-1.0))<0.0001){
-						file2 << "NSET\tFRONTRIGHTTOP = FRONTRIGHTTOP + SURFACE"<<pairTmp.first->tag()<<"\n";
-						file2 << "NSET\tBACKLEFTBOTTOM = BACKLEFTBOTTOM + SURFACE"<<associatedFace->tag()<<"\n";
-					}
-				}
-			}else if (abs((p1.x()-p2.x()))<0.0001){
-				if (abs((p2.y()-p1.y()-1.0))<0.0001){
-					if (abs((p2.z()-p1.z()))<0.0001){
-						file2 << "NSET\tRIGHT = RIGHT + SURFACE"<<associatedFace->tag()<<"\n";
-						file2 << "NSET\tLEFT = LEFT + SURFACE"<<pairTmp.first->tag()<<"\n";
-					}else if (abs((p2.z()-p1.z()-1.0))<0.0001){
-						file2 << "NSET\tRIGHTTOP = RIGHTTOP + SURFACE"<<associatedFace->tag()<<"\n";
-						file2 << "NSET\tLEFTBOTTOM = LEFTBOTTOM + SURFACE"<<pairTmp.first->tag()<<"\n";
-					}else if (abs((p1.z()-p2.z()-1.0))<0.0001){
-						file2 << "NSET\tRIGHTBOTTOM = RIGHTBOTTOM + SURFACE"<<associatedFace->tag()<<"\n";
-						file2 << "NSET\tLEFTTOP = LEFTTOP + SURFACE"<<pairTmp.first->tag()<<"\n";
-					}
-				}else if (abs((p1.y()-p2.y()-1.0))<0.0001){
-					if (abs((p2.z()-p1.z()))<0.0001){
-						file2 << "NSET\tRIGHT = RIGHT + SURFACE"<<pairTmp.first->tag()<<"\n";
-						file2 << "NSET\tLEFT = LEFT + SURFACE"<<associatedFace->tag()<<"\n";
-					}else if (abs((p2.z()-p1.z()-1.0))<0.0001){
-						file2 << "NSET\tRIGHTBOTTOM = RIGHTBOTTOM + SURFACE"<<pairTmp.first->tag()<<"\n";
-						file2 << "NSET\tLEFTTOP = LEFTTOP + SURFACE"<<associatedFace->tag()<<"\n";
-					}else if (abs((p1.z()-p2.z()-1.0))<0.0001){
-						file2 << "NSET\tRIGHTTOP = RIGHTTOP + SURFACE"<<pairTmp.first->tag()<<"\n";
-						file2 << "NSET\tLEFTBOTTOM = LEFTBOTTOM + SURFACE"<<associatedFace->tag()<<"\n";
-					}
-				}else if (abs((p1.y()-p2.y()))<0.0001){
-					if (abs((p2.z()-p1.z()-1.0))<0.0001){
-						file2 << "NSET\tTOP = TOP + SURFACE"<<associatedFace->tag()<<"\n";
-						file2 << "NSET\tBOTTOM = BOTTOM + SURFACE"<<pairTmp.first->tag()<<"\n";
-					}else if (abs((p1.z()-p2.z()-1.0))<0.0001){
-						file2 << "NSET\tTOP = TOP + SURFACE"<<pairTmp.first->tag()<<"\n";
-						file2 << "NSET\tBOTTOM = BOTTOM + SURFACE"<<associatedFace->tag()<<"\n";
-					}
-				}
-			}
-//			count++;
-
-
-
-
-
-
-
-			newPairs.push_back(std::make_pair(pairTmp.first,associatedFace));
-		}
-	}
-//	for (std::vector<std::pair<GFace*,GFace*> >::iterator itP = newPairs.begin();itP != newPairs.end();itP++){
-//		std::pair<GFace*,GFace*> pairTmp = (*itP);
-//	}
+  std::cout<<"starting DuplicateBoundaries"<<std::endl;
+  GModel *m = GModel::current();
+  m->setFactory("geo");
+  std::set<GFace*> ToDuplicateList;
+  ToDuplicateList.clear();
+  std::set<GFace*> ToDuplicateListBoundary;
+  ToDuplicateListBoundary.clear();
+  std::vector<GFace*> facesBound;
+  facesBound.clear();
+  std::map<GFace*,SPoint3> centers;
+  std::vector<std::pair<GFace*,GFace*> > pairs;
+  std::vector<std::pair<GFace*,GFace*> > newPairs;
+  int PhysicalInterface = m->setPhysicalName("Interface",3);
+  for (GModel::fiter itf= m->firstFace();itf != m->lastFace();itf++){
+    GFace* fTmp = (*itf);
+    if (fTmp->numRegions() == 2){
+      ToDuplicateList.insert(fTmp);
+    }
+    else{
+      //			ToDuplicateListBoundary.insert(fTmp);
+      facesBound.push_back(fTmp);
+    }
+  }
+
+
+
+
+
+
+
+
+  for(unsigned int i=0;i<facesBound.size();i++){
+    double x = 0.0;
+    double y = 0.0;
+    double z = 0.0;
+
+    std::list<GVertex*> vertices;
+
+    vertices = facesBound[i]->vertices();
+
+    for(std::list<GVertex*>::iterator it2=vertices.begin();it2!=vertices.end();it2++){
+      x = x + (*it2)->x();
+      y = y + (*it2)->y();
+      z = z + (*it2)->z();
+    }
+
+    x = x/vertices.size();
+    y = y/vertices.size();
+    z = z/vertices.size();
+
+    centers.insert(std::pair<GFace*,SPoint3>(facesBound[i],SPoint3(x,y,z)));
+  }
+
+  for(unsigned int i=0;i<facesBound.size();i++){
+    for(unsigned int j=0;j<facesBound.size();j++){
+      std::map<GFace*,SPoint3>::iterator it3 = centers.find(facesBound[i]);
+      std::map<GFace*,SPoint3>::iterator it4 = centers.find(facesBound[j]);
+
+      SPoint3 p1 = it3->second;
+      SPoint3 p2 = it4->second;
+
+
+      //				categories.push_back(val);
+
+      //				print_segment(p1,p2,file);
+
+      if (abs((p2.x()-p1.x()-1.0))<0.0001){
+        if (abs((p2.y()-p1.y()))<0.0001){
+          if (abs((p2.z()-p1.z()))<0.0001){
+            pairs.push_back(std::pair<GFace*,GFace*>(facesBound[i],facesBound[j]));
+            ToDuplicateListBoundary.insert(facesBound[i]);
+          }else if(abs((p2.z()-p1.z()-1.0))<0.0001){
+            pairs.push_back(std::pair<GFace*,GFace*>(facesBound[i],facesBound[j]));
+            ToDuplicateListBoundary.insert(facesBound[i]);
+          }else if (abs((p1.z()-p2.z()-1.0))<0.0001){
+            pairs.push_back(std::pair<GFace*,GFace*>(facesBound[i],facesBound[j]));
+            ToDuplicateListBoundary.insert(facesBound[i]);
+          }
+        }else if (abs((p2.y()-p1.y()-1.0))<0.0001){
+          if (abs((p2.z()-p1.z()))<0.0001){
+            pairs.push_back(std::pair<GFace*,GFace*>(facesBound[i],facesBound[j]));
+            ToDuplicateListBoundary.insert(facesBound[i]);
+          }else if (abs((p2.z()-p1.z()-1.0))<0.0001){
+            pairs.push_back(std::pair<GFace*,GFace*>(facesBound[i],facesBound[j]));
+            ToDuplicateListBoundary.insert(facesBound[i]);
+          }else if (abs((p1.z()-p2.z()-1.0))<0.0001){
+            pairs.push_back(std::pair<GFace*,GFace*>(facesBound[i],facesBound[j]));
+            ToDuplicateListBoundary.insert(facesBound[i]);
+          }
+        }else if (abs((p1.y()-p2.y()-1.0))<0.0001){
+          if (abs((p2.z()-p1.z()))<0.0001){
+            pairs.push_back(std::pair<GFace*,GFace*>(facesBound[i],facesBound[j]));
+            ToDuplicateListBoundary.insert(facesBound[i]);
+          }else if (abs((p2.z()-p1.z()-1.0))<0.0001){
+            pairs.push_back(std::pair<GFace*,GFace*>(facesBound[i],facesBound[j]));
+            ToDuplicateListBoundary.insert(facesBound[i]);
+          }else if (abs((p1.z()-p2.z()-1.0))<0.0001){
+            pairs.push_back(std::pair<GFace*,GFace*>(facesBound[i],facesBound[j]));
+            ToDuplicateListBoundary.insert(facesBound[i]);
+          }
+        }
+      }else if (abs((p1.x()-p2.x()-1.0))<0.0001){
+        if (abs((p2.y()-p1.y()))<0.0001){
+          if (abs((p2.z()-p1.z()))<0.0001){
+            //NOTHING
+          }else if(abs((p2.z()-p1.z()-1.0))<0.0001){
+            //NOTHING
+          }else if (abs((p1.z()-p2.z()-1.0))<0.0001){
+            //NOTHING
+          }
+        }else if (abs((p2.y()-p1.y()-1.0))<0.0001){
+          if (abs((p2.z()-p1.z()))<0.0001){
+            //NOTHING
+          }else if (abs((p2.z()-p1.z()-1.0))<0.0001){
+            //NOTHING
+          }else if (abs((p1.z()-p2.z()-1.0))<0.0001){
+            //NOTHING
+          }
+        }else if (abs((p1.y()-p2.y()-1.0))<0.0001){
+          if (abs((p2.z()-p1.z()))<0.0001){
+            //NOTHING
+          }else if (abs((p2.z()-p1.z()-1.0))<0.0001){
+            //NOTHING
+          }else if (abs((p1.z()-p2.z()-1.0))<0.0001){
+            //NOTHING
+          }
+        }
+      }else if (abs((p1.x()-p2.x()))<0.0001){
+        if (abs((p2.y()-p1.y()-1.0))<0.0001){
+          if (abs((p2.z()-p1.z()))<0.0001){
+            pairs.push_back(std::pair<GFace*,GFace*>(facesBound[i],facesBound[j]));
+            ToDuplicateListBoundary.insert(facesBound[i]);
+          }else if (abs((p2.z()-p1.z()-1.0))<0.0001){
+            pairs.push_back(std::pair<GFace*,GFace*>(facesBound[i],facesBound[j]));
+            ToDuplicateListBoundary.insert(facesBound[i]);
+          }else if (abs((p1.z()-p2.z()-1.0))<0.0001){
+            pairs.push_back(std::pair<GFace*,GFace*>(facesBound[i],facesBound[j]));
+            ToDuplicateListBoundary.insert(facesBound[i]);
+          }
+        }else if (abs((p1.y()-p2.y()-1.0))<0.0001){
+          if (abs((p2.z()-p1.z()))<0.0001){
+            //NOTHING
+          }else if (abs((p2.z()-p1.z()-1.0))<0.0001){
+            //NOTHING
+          }else if (abs((p1.z()-p2.z()-1.0))<0.0001){
+            //NOTHING
+          }
+        }else if (abs((p1.y()-p2.y()))<0.0001){
+          if (abs((p2.z()-p1.z()-1.0))<0.0001){
+            pairs.push_back(std::pair<GFace*,GFace*>(facesBound[i],facesBound[j]));
+            ToDuplicateListBoundary.insert(facesBound[i]);
+          }else if (abs((p1.z()-p2.z()-1.0))<0.0001){
+            //NOTHING
+          }
+        }
+      }
+    }
+  }
+
+
+
+
+
+
+
+
+
+
+  std::map<std::pair<MVertex*,GRegion*>,MVertex* > VertexGlobalAssociation;
+  std::map<std::pair<GVertex*,GRegion*>,GVertex* > GVertexGlobalAssociation;
+  std::map<std::pair<GEdge*,GRegion*>,GEdge* > GEdgeGlobalAssociation;
+  std::map<std::pair<GFace*,GRegion*>,GFace* > GFaceGlobalAssociation;
+  //	for (GModel::viter itv= m->firstVertex();itv != m->lastVertex();itv++){
+  //		GVertex* vTmp = (*itv);
+  //		std::vector<GVertex* > vecTmp;
+  //		vecTmp.clear();
+  //		GVertexGlobalAssociation[vTmp] = vecTmp;
+  //		for (int i = 0; i < vTmp->mesh_vertices.size();i++){
+  //			MVertex *vMesh = vTmp->mesh_vertices[i];
+  //			std::vector<MVertex* > vecTmpBis;
+  //			vecTmpBis.clear();
+  //			VertexGlobalAssociation[vMesh] = vecTmpBis;
+  //		}
+  //	}
+  //	for (GModel::eiter ite= m->firstEdge();ite != m->lastEdge();ite++){
+  //		GEdge* eTmp = (*ite);
+  //		std::vector<GEdge* > vecTmp;
+  //		vecTmp.clear();
+  //		GEdgeGlobalAssociation[eTmp] = vecTmp;
+  //		for (int i = 0; i < eTmp->mesh_vertices.size();i++){
+  //			MVertex *vMesh = eTmp->mesh_vertices[i];
+  //			std::vector<MVertex* > vecTmpBis;
+  //			vecTmpBis.clear();
+  //			VertexGlobalAssociation[vMesh] = vecTmpBis;
+  //		}
+  //	}
+  //	for (GModel::fiter itf= m->firstFace();itf != m->lastFace();itf++){
+  //		GFace* fTmp = (*itf);
+  //		for (int i = 0; i < fTmp->mesh_vertices.size();i++){
+  //			MVertex *vMesh = fTmp->mesh_vertices[i];
+  //			std::vector<MVertex* > vecTmpBis;
+  //			vecTmpBis.clear();
+  //			VertexGlobalAssociation[vMesh] = vecTmpBis;
+  //		}
+  //	}
+  //	for (GModel::riter itr= m->firstRegion();itr != m->lastRegion();itr++){
+  //		GRegion* rTmp = (*itr);
+  //		for (int i = 0; i < rTmp->mesh_vertices.size();i++){
+  //			MVertex *vMesh = rTmp->mesh_vertices[i];
+  //			std::vector<MVertex* > vecTmpBis;
+  //			vecTmpBis.clear();
+  //			VertexGlobalAssociation[vMesh] = vecTmpBis;
+  //		}
+  //	}
+  for (GModel::riter itr= m->firstRegion();itr != m->lastRegion();itr++){
+    GRegion* rTmp = (*itr);
+    std::list<GFace*> RegFaces = rTmp->faces();
+    std::map<MVertex*,MVertex* > VertexAssociation;
+    std::map<GVertex*,GVertex* > GVertexAssociation;
+    std::map<GEdge*,GEdge* > GEdgeAssociation;
+    //int counterNbDone = 10000;
+    double xCenterReg = 0.0;
+    double yCenterReg = 0.0;
+    double zCenterReg = 0.0;
+    int counterPts = 0;
+    for(std::list<GFace*>::iterator it2=RegFaces.begin();it2!=RegFaces.end();it2++){
+      GFace* fTemp = (*it2);
+      std::list<GVertex*> verticesFace = fTemp->vertices();
+      for (std::list<GVertex*>::iterator it3=verticesFace.begin();it3!=verticesFace.end();it3++){
+        xCenterReg = xCenterReg + (*it3)->x();
+        yCenterReg = yCenterReg + (*it3)->y();
+        zCenterReg = zCenterReg + (*it3)->z();
+        counterPts++;
+      }
+    }
+    xCenterReg = xCenterReg/counterPts;
+    yCenterReg = yCenterReg/counterPts;
+    zCenterReg = zCenterReg/counterPts;
+    //duplication noeud et aretes au niveau de la region directement
+    std::list<GVertex*> vlist;
+
+
+    std::list<GFace*> listFacesTmp = rTmp->faces();
+    for (std::list<GFace*>::iterator itTp = listFacesTmp.begin();itTp != listFacesTmp.end();itTp++){
+      std::list<GVertex*> vlist2;
+      vlist2 = (*itTp)->vertices();
+      for (std::list<GVertex*>::iterator itTp2 = vlist2.begin();itTp2 != vlist2.end();itTp2++){
+        if(std::find(vlist.begin(), vlist.end(), *itTp2) == vlist.end())
+          vlist.push_back(*itTp2);
+      }
+    }
+
+
+    for (std::list<GVertex*>::iterator itv = vlist.begin();itv != vlist.end();itv++){
+      //duplication Gvertex
+      GVertex* vTmp = (*itv);
+      double ponderatedX = 0.99999999999 * vTmp->x() + 0.00000000001 * xCenterReg;
+      double ponderatedY = 0.99999999999 * vTmp->y() + 0.00000000001 * yCenterReg;
+      double ponderatedZ = 0.99999999999 * vTmp->z() + 0.00000000001 * zCenterReg;
+      GVertex* newv = m->addVertex(ponderatedX,ponderatedY,ponderatedZ,vTmp->prescribedMeshSizeAtVertex());
+      GVertexAssociation[vTmp] = newv;
+      GVertexGlobalAssociation[std::make_pair(vTmp,rTmp)] = newv;
+      //creation des Gedge correspondantes
+      //			GEdge* newE = m->addLine(vTmp,newv);
+      //			SurroudingEdges[vTmp] = newE;
+      //maintenant traitement mesh
+      MVertex *vMesh = vTmp->mesh_vertices[0];
+      MVertex *newMv = new MVertex(vMesh->x(), vMesh->y(), vMesh->z(), (GEntity*)newv);
+      VertexAssociation[vMesh] = newMv;
+      VertexGlobalAssociation[std::make_pair(vMesh,rTmp)] = newMv;
+      newv->addMeshVertex(newMv);
+    }
+    //maintenant on soccupe de duppliquer les edges de la region
+    std::list<GEdge*> elist = rTmp->edges();
+
+    std::vector<GFace*> SurroundingsFaces;
+    for (std::list<GEdge*>::iterator ite = elist.begin();ite != elist.end();ite++){
+      //duplication Gedge
+      GEdge* eTmp = (*ite);
+      GEdge* newE = m->addLine(GVertexAssociation[eTmp->getEndVertex()],GVertexAssociation[eTmp->getBeginVertex()]);
+      GEdgeAssociation[eTmp] = newE;
+      GEdgeGlobalAssociation[std::make_pair(eTmp,rTmp)] = newE;
+      //creation des GFace correspondantes
+      //			GEdge* firstE = SurroudingEdges.find(eTmp->getEndVertex())->second;
+      //			GEdge* lastE = SurroudingEdges.find(eTmp->getBeginVertex())->second;
+      //			std::vector<GEdge*> VecEdgesTmp;
+      //			VecEdgesTmp.push_back(eTmp);
+      //			VecEdgesTmp.push_back(firstE);
+      //			VecEdgesTmp.push_back(newE);
+      //			VecEdgesTmp.push_back(lastE);
+      //			std::vector<std::vector<GEdge*> > VecOfVecTmp;
+      //			VecOfVecTmp.push_back(VecEdgesTmp);
+      //			GFace* newFaceTmp = m->addPlanarFace(VecOfVecTmp);
+      //			SurroundingsFaces.push_back(newFaceTmp);
+      //maintenant traitement mesh
+      for (unsigned int i = 0; i < eTmp->mesh_vertices.size();i++){
+        MVertex *vMesh = eTmp->mesh_vertices[i];
+        MVertex *newMv = new MVertex(vMesh->x(), vMesh->y(), vMesh->z(), (GEntity*)newE);
+        VertexAssociation[vMesh] = newMv;
+        VertexGlobalAssociation[std::make_pair(vMesh,rTmp)] = newMv;
+        newE->addMeshVertex(newMv);
+      }
+      for (unsigned int i = 0; i < eTmp->getNumMeshElements();i++){
+        MElement* elem = eTmp->getMeshElement(i);
+        MVertex *firstETmp = VertexAssociation.find(elem->getVertex(0))->second;
+        MVertex *lastETmp = VertexAssociation.find(elem->getVertex(1))->second;
+        MVertex *midETmp = VertexAssociation.find(elem->getVertex(2))->second;
+        MLine3 *newLine = new MLine3(firstETmp,lastETmp,midETmp);
+        newE->addLine(newLine);
+      }
+    }
+    for (std::list<GFace*>::iterator itf = RegFaces.begin();itf != RegFaces.end();itf++){
+      GFace* fTmp = (*itf);
+      std::vector<GEdge*> newEdgesVector;
+      std::list<GEdge*> elistFace = fTmp->edges();
+      for (std::list<GEdge*>::iterator ite = elistFace.begin();ite != elistFace.end();ite++){
+        GEdge* eTmp = (*ite);
+        GEdge* eToFind = GEdgeAssociation[eTmp];
+        newEdgesVector.push_back(eToFind);
+      }
+      std::vector<std::vector<GEdge*> > VecOfVec;
+      VecOfVec.push_back(newEdgesVector);
+      //creation de la nouvelle face
+      GFace* GFaceAssociation = m->addPlanarFace(VecOfVec);
+      //			int tagTmp = GFaceAssociation->tag();
+      //			std::ostringstream ss;
+      //			ss << tagTmp;
+      ////			char *intStr = itoa(tagTmp);
+      //			std::string nameSurf = "SURFACE";
+      ////			nameSurf += std::string(intStr);
+      //			nameSurf += ss.str();
+      //			int PhysicalSurfaceTmp = m->setPhysicalName(nameSurf,2);
+      //			GFaceAssociation->addPhysicalEntity(PhysicalSurfaceTmp);
+      //maintenant traitement mesh
+      for (unsigned int i = 0; i < fTmp->mesh_vertices.size();i++){
+        MVertex *vMesh = fTmp->mesh_vertices[i];
+        MVertex *newMv = new MVertex(vMesh->x(), vMesh->y(), vMesh->z(), (GEntity*)GFaceAssociation);
+        VertexAssociation[vMesh] = newMv;
+        VertexGlobalAssociation[std::make_pair(vMesh,rTmp)] = newMv;
+        GFaceAssociation->addMeshVertex(newMv);
+      }
+      for (unsigned int i = 0; i < fTmp->getNumMeshElements();i++){
+        MElement* elem = fTmp->getMeshElement(i);
+        MVertex *firstE = VertexAssociation.find(elem->getVertex(0))->second;
+        MVertex *secondE = VertexAssociation.find(elem->getVertex(1))->second;
+        MVertex *thirdE = VertexAssociation.find(elem->getVertex(2))->second;
+        MVertex *fourthE = VertexAssociation.find(elem->getVertex(3))->second;
+        MVertex *fifthE = VertexAssociation.find(elem->getVertex(4))->second;
+        MVertex *sisthE = VertexAssociation.find(elem->getVertex(5))->second;
+        MTriangle6 *newTri = new MTriangle6(firstE,secondE,thirdE,fourthE,fifthE,sisthE);
+        GFaceAssociation->addTriangle(newTri);
+      }
+      GFaceGlobalAssociation[std::make_pair(fTmp,rTmp)] = GFaceAssociation;
+    }
+  }
+  int counterNbDone = 10000;
+  //maintenant on va traiter les faces initiales
+  for (std::set<GFace*>::iterator itf = ToDuplicateList.begin();itf != ToDuplicateList.end();itf++){
+    counterNbDone++;
+    GFace* fTmp = (*itf);
+    GRegion* reg1 = fTmp->getRegion(0);
+    GRegion* reg2 = fTmp->getRegion(1);
+    //pour commencer on cree des aretes entre les vertex
+    std::list<GVertex*> vlist = fTmp->vertices();
+    std::map<GVertex*,GEdge* > SurroudingEdges;
+    for (std::list<GVertex*>::iterator itv = vlist.begin();itv != vlist.end();itv++){
+      GVertex* vTmp = (*itv);
+      GVertex* v1=0;
+      GVertex* v2=0;
+      std::map<std::pair<GVertex*,GRegion*>,GVertex* >::iterator itMap = GVertexGlobalAssociation.find(std::make_pair(vTmp,reg1));
+      if (itMap != GVertexGlobalAssociation.end()){
+        v1 = itMap->second;
+      }
+      itMap = GVertexGlobalAssociation.find(std::make_pair(vTmp,reg2));
+      if (itMap != GVertexGlobalAssociation.end()){
+        v2 = itMap->second;
+      }
+      GEdge* newE = m->addLine(v1,v2);
+      SurroudingEdges[vTmp] = newE;
+    }
+    //ici tous les vertex sont traites
+    //on va traiter les edges
+    std::list<GEdge*> elist = fTmp->edges();
+    std::vector<GEdge*> newEdgesVector;
+    std::vector<GFace*> SurroundingsFaces;
+    for (std::list<GEdge*>::iterator ite = elist.begin();ite != elist.end();ite++){
+      //duplication Gedge
+      GEdge* eTmp = (*ite);
+      GEdge* e1=0;
+      GEdge* e2=0;
+      std::map<std::pair<GEdge*,GRegion*>,GEdge* >::iterator itMap = GEdgeGlobalAssociation.find(std::make_pair(eTmp,reg1));
+      if (itMap != GEdgeGlobalAssociation.end()){
+        e1 = itMap->second;
+      }
+      itMap = GEdgeGlobalAssociation.find(std::make_pair(eTmp,reg2));
+      if (itMap != GEdgeGlobalAssociation.end()){
+        e2 = itMap->second;
+      }
+      //creation des GFace correspondantes
+      GEdge* firstE = SurroudingEdges.find(eTmp->getBeginVertex())->second;
+      GEdge* lastE = SurroudingEdges.find(eTmp->getEndVertex())->second;
+      if (firstE->getBeginVertex() != e1->getEndVertex()){
+        firstE->reverse();
+      }
+      if (firstE->getBeginVertex() != e1->getEndVertex()){
+        e1->reverse();
+      }
+      if (firstE->getBeginVertex() != e1->getEndVertex()){
+        firstE->reverse();
+      }
+      if (e2->getBeginVertex() != firstE->getEndVertex()){
+        e2->reverse();
+      }
+      if (lastE->getBeginVertex() != e2->getEndVertex()){
+        lastE->reverse();
+      }
+      std::vector<GEdge*> VecEdgesTmp;
+      VecEdgesTmp.push_back(e1);
+      VecEdgesTmp.push_back(firstE);
+      VecEdgesTmp.push_back(e2);
+      VecEdgesTmp.push_back(lastE);
+      std::vector<std::vector<GEdge*> > VecOfVecTmp;
+      VecOfVecTmp.push_back(VecEdgesTmp);
+      GFace* newFaceTmp = m->addPlanarFace(VecOfVecTmp);
+      SurroundingsFaces.push_back(newFaceTmp);
+    }
+    std::vector<GFace*> VectorFaces;
+    std::list<GFace*> listFaces;
+    GFace* f1;
+    GFace* f2;
+    std::map<std::pair<GFace*,GRegion*>,GFace* >::iterator itMap = GFaceGlobalAssociation.find(std::make_pair(fTmp,reg1));
+    if (itMap != GFaceGlobalAssociation.end()){
+      f1 = itMap->second;
+    }
+    itMap = GFaceGlobalAssociation.find(std::make_pair(fTmp,reg2));
+    if (itMap != GFaceGlobalAssociation.end()){
+      f2 = itMap->second;
+    }
+    VectorFaces.push_back(f1);
+    listFaces.push_back(f1);
+    for (unsigned int i = 0;i < SurroundingsFaces.size();i++){
+      VectorFaces.push_back(SurroundingsFaces[i]);
+      listFaces.push_back(SurroundingsFaces[i]);
+    }
+    VectorFaces.push_back(f2);
+    listFaces.push_back(f2);
+    std::vector<std::vector<GFace*> > VecOfVecGFace;
+    VecOfVecGFace.push_back(VectorFaces);
+    //creation de la nouvelle region
+    GRegion* createdRegion = new GRegion(m,counterNbDone);
+    createdRegion->addPhysicalEntity(PhysicalInterface);
+    createdRegion->set(listFaces);
+    m->add(createdRegion);
+    for (unsigned int i = 0; i < fTmp->getNumMeshElements();i++){
+      MElement* elem = fTmp->getMeshElement(i);
+      MVertex* v1=0;
+      MVertex* v2=0;
+      MVertex* v3=0;
+      MVertex* v4=0;
+      MVertex* v5=0;
+      MVertex* v6=0;
+      std::map<std::pair<MVertex*,GRegion*>,MVertex* >::iterator itMap = VertexGlobalAssociation.find(std::make_pair(elem->getVertex(0),reg1));
+      if (itMap != VertexGlobalAssociation.end()){
+        v1 = itMap->second;
+      }
+      itMap = VertexGlobalAssociation.find(std::make_pair(elem->getVertex(3),reg1));
+      if (itMap != VertexGlobalAssociation.end()){
+        v2 = itMap->second;
+      }
+      itMap = VertexGlobalAssociation.find(std::make_pair(elem->getVertex(5),reg1));
+      if (itMap != VertexGlobalAssociation.end()){
+        v3 = itMap->second;
+      }
+      itMap = VertexGlobalAssociation.find(std::make_pair(elem->getVertex(0),reg2));
+      if (itMap != VertexGlobalAssociation.end()){
+        v4 = itMap->second;
+      }
+      itMap = VertexGlobalAssociation.find(std::make_pair(elem->getVertex(3),reg2));
+      if (itMap != VertexGlobalAssociation.end()){
+        v5 = itMap->second;
+      }
+      itMap = VertexGlobalAssociation.find(std::make_pair(elem->getVertex(5),reg2));
+      if (itMap != VertexGlobalAssociation.end()){
+        v6 = itMap->second;
+      }
+      MPrism *newPri = new MPrism(v1,v3,v2,v4,v6,v5);
+
+      createdRegion->addPrism(newPri);
+
+      //second
+      itMap = VertexGlobalAssociation.find(std::make_pair(elem->getVertex(1),reg1));
+      if (itMap != VertexGlobalAssociation.end()){
+        v1 = itMap->second;
+      }
+      itMap = VertexGlobalAssociation.find(std::make_pair(elem->getVertex(4),reg1));
+      if (itMap != VertexGlobalAssociation.end()){
+        v2 = itMap->second;
+      }
+      itMap = VertexGlobalAssociation.find(std::make_pair(elem->getVertex(3),reg1));
+      if (itMap != VertexGlobalAssociation.end()){
+        v3 = itMap->second;
+      }
+      itMap = VertexGlobalAssociation.find(std::make_pair(elem->getVertex(1),reg2));
+      if (itMap != VertexGlobalAssociation.end()){
+        v4 = itMap->second;
+      }
+      itMap = VertexGlobalAssociation.find(std::make_pair(elem->getVertex(4),reg2));
+      if (itMap != VertexGlobalAssociation.end()){
+        v5 = itMap->second;
+      }
+      itMap = VertexGlobalAssociation.find(std::make_pair(elem->getVertex(3),reg2));
+      if (itMap != VertexGlobalAssociation.end()){
+        v6 = itMap->second;
+      }
+      MPrism *newPri2 = new MPrism(v1,v3,v2,v4,v6,v5);
+
+      createdRegion->addPrism(newPri2);
+      //third
+      itMap = VertexGlobalAssociation.find(std::make_pair(elem->getVertex(2),reg1));
+      if (itMap != VertexGlobalAssociation.end()){
+        v1 = itMap->second;
+      }
+      itMap = VertexGlobalAssociation.find(std::make_pair(elem->getVertex(5),reg1));
+      if (itMap != VertexGlobalAssociation.end()){
+        v2 = itMap->second;
+      }
+      itMap = VertexGlobalAssociation.find(std::make_pair(elem->getVertex(4),reg1));
+      if (itMap != VertexGlobalAssociation.end()){
+        v3 = itMap->second;
+      }
+      itMap = VertexGlobalAssociation.find(std::make_pair(elem->getVertex(2),reg2));
+      if (itMap != VertexGlobalAssociation.end()){
+        v4 = itMap->second;
+      }
+      itMap = VertexGlobalAssociation.find(std::make_pair(elem->getVertex(5),reg2));
+      if (itMap != VertexGlobalAssociation.end()){
+        v5 = itMap->second;
+      }
+      itMap = VertexGlobalAssociation.find(std::make_pair(elem->getVertex(4),reg2));
+      if (itMap != VertexGlobalAssociation.end()){
+        v6 = itMap->second;
+      }
+      MPrism *newPri3 = new MPrism(v1,v3,v2,v4,v6,v5);
+
+      createdRegion->addPrism(newPri3);
+      //fourth
+      itMap = VertexGlobalAssociation.find(std::make_pair(elem->getVertex(3),reg1));
+      if (itMap != VertexGlobalAssociation.end()){
+        v1 = itMap->second;
+      }
+      itMap = VertexGlobalAssociation.find(std::make_pair(elem->getVertex(4),reg1));
+      if (itMap != VertexGlobalAssociation.end()){
+        v2 = itMap->second;
+      }
+      itMap = VertexGlobalAssociation.find(std::make_pair(elem->getVertex(5),reg1));
+      if (itMap != VertexGlobalAssociation.end()){
+        v3 = itMap->second;
+      }
+      itMap = VertexGlobalAssociation.find(std::make_pair(elem->getVertex(3),reg2));
+      if (itMap != VertexGlobalAssociation.end()){
+        v4 = itMap->second;
+      }
+      itMap = VertexGlobalAssociation.find(std::make_pair(elem->getVertex(4),reg2));
+      if (itMap != VertexGlobalAssociation.end()){
+        v5 = itMap->second;
+      }
+      itMap = VertexGlobalAssociation.find(std::make_pair(elem->getVertex(5),reg2));
+      if (itMap != VertexGlobalAssociation.end()){
+        v6 = itMap->second;
+      }
+      MPrism *newPri4 = new MPrism(v1,v3,v2,v4,v6,v5);
+
+      createdRegion->addPrism(newPri4);
+    }
+    for (unsigned int i = 0; i < reg1->getNumMeshElements();i++){
+      MElement* elem = reg1->getMeshElement(i);
+      for (int j = 0;j < elem->getNumVertices();j++){
+        MVertex* vert = elem->getVertex(j);
+        std::map<std::pair<MVertex*,GRegion*>,MVertex* >::iterator itMap = VertexGlobalAssociation.find(std::make_pair(vert,reg1));
+        if (itMap != VertexGlobalAssociation.end()){
+          elem->setVertex(j,itMap->second);
+        }
+      }
+    }
+    for (unsigned int i = 0; i < reg2->getNumMeshElements();i++){
+      MElement* elem = reg2->getMeshElement(i);
+      for (int j = 0;j < elem->getNumVertices();j++){
+        MVertex* vert = elem->getVertex(j);
+        std::map<std::pair<MVertex*,GRegion*>,MVertex* >::iterator itMap = VertexGlobalAssociation.find(std::make_pair(vert,reg2));
+        if (itMap != VertexGlobalAssociation.end()){
+          elem->setVertex(j,itMap->second);
+        }
+      }
+    }
+  }
+  //maintenant on va traiter les faces du bord
+  for (std::set<GFace*>::iterator itf = ToDuplicateListBoundary.begin();itf != ToDuplicateListBoundary.end();itf++){
+    counterNbDone++;
+    GFace* fTmp = (*itf);
+    GRegion* reg1 = fTmp->getRegion(0);
+    //pour commencer on cree des aretes entre les vertex
+    std::list<GVertex*> vlist = fTmp->vertices();
+    std::map<GVertex*,GEdge* > SurroudingEdges;
+    for (std::list<GVertex*>::iterator itv = vlist.begin();itv != vlist.end();itv++){
+      GVertex* vTmp = (*itv);
+      GVertex* v1=0;
+      std::map<std::pair<GVertex*,GRegion*>,GVertex* >::iterator itMap = GVertexGlobalAssociation.find(std::make_pair(vTmp,reg1));
+      if (itMap != GVertexGlobalAssociation.end()){
+        v1 = itMap->second;
+      }
+      GEdge* newE = m->addLine(v1,vTmp);
+      SurroudingEdges[vTmp] = newE;
+    }
+    //ici tous les vertex sont traites
+    //on va traiter les edges
+    std::list<GEdge*> elist = fTmp->edges();
+    std::vector<GEdge*> newEdgesVector;
+    std::vector<GFace*> SurroundingsFaces;
+    for (std::list<GEdge*>::iterator ite = elist.begin();ite != elist.end();ite++){
+      //duplication Gedge
+      GEdge* eTmp = (*ite);
+      GEdge* e1=0;
+      std::map<std::pair<GEdge*,GRegion*>,GEdge* >::iterator itMap = GEdgeGlobalAssociation.find(std::make_pair(eTmp,reg1));
+      if (itMap != GEdgeGlobalAssociation.end()){
+        e1 = itMap->second;
+      }
+      //creation des GFace correspondantes
+      GEdge* firstE = SurroudingEdges.find(eTmp->getBeginVertex())->second;
+      GEdge* lastE = SurroudingEdges.find(eTmp->getEndVertex())->second;
+      if (firstE->getBeginVertex() != e1->getEndVertex()){
+        firstE->reverse();
+      }
+      if (firstE->getBeginVertex() != e1->getEndVertex()){
+        e1->reverse();
+      }
+      if (firstE->getBeginVertex() != e1->getEndVertex()){
+        firstE->reverse();
+      }
+      if (eTmp->getBeginVertex() != firstE->getEndVertex()){
+        eTmp->reverse();
+      }
+      if (lastE->getBeginVertex() != eTmp->getEndVertex()){
+        lastE->reverse();
+      }
+      std::vector<GEdge*> VecEdgesTmp;
+      VecEdgesTmp.push_back(e1);
+      VecEdgesTmp.push_back(firstE);
+      VecEdgesTmp.push_back(eTmp);
+      VecEdgesTmp.push_back(lastE);
+      std::vector<std::vector<GEdge*> > VecOfVecTmp;
+      VecOfVecTmp.push_back(VecEdgesTmp);
+      GFace* newFaceTmp = m->addPlanarFace(VecOfVecTmp);
+      SurroundingsFaces.push_back(newFaceTmp);
+    }
+    std::vector<GFace*> VectorFaces;
+    std::list<GFace*> listFaces;
+    GFace* f1;
+    std::map<std::pair<GFace*,GRegion*>,GFace* >::iterator itMap = GFaceGlobalAssociation.find(std::make_pair(fTmp,reg1));
+    if (itMap != GFaceGlobalAssociation.end()){
+      f1 = itMap->second;
+    }
+    VectorFaces.push_back(f1);
+    listFaces.push_back(f1);
+    for (unsigned int i = 0;i < SurroundingsFaces.size();i++){
+      VectorFaces.push_back(SurroundingsFaces[i]);
+      listFaces.push_back(SurroundingsFaces[i]);
+    }
+    VectorFaces.push_back(fTmp);
+    listFaces.push_back(fTmp);
+    std::vector<std::vector<GFace*> > VecOfVecGFace;
+    VecOfVecGFace.push_back(VectorFaces);
+    //creation de la nouvelle region
+    GRegion* createdRegion = new GRegion(m,counterNbDone);
+    createdRegion->addPhysicalEntity(PhysicalInterface);
+    createdRegion->set(listFaces);
+    m->add(createdRegion);
+    for (unsigned int i = 0; i < fTmp->getNumMeshElements();i++){
+      MElement* elem = fTmp->getMeshElement(i);
+      MVertex* v1=0;
+      MVertex* v2=0;
+      MVertex* v3=0;
+      std::map<std::pair<MVertex*,GRegion*>,MVertex* >::iterator itMap = VertexGlobalAssociation.find(std::make_pair(elem->getVertex(0),reg1));
+      if (itMap != VertexGlobalAssociation.end()){
+        v1 = itMap->second;
+      }
+      itMap = VertexGlobalAssociation.find(std::make_pair(elem->getVertex(3),reg1));
+      if (itMap != VertexGlobalAssociation.end()){
+        v2 = itMap->second;
+      }
+      itMap = VertexGlobalAssociation.find(std::make_pair(elem->getVertex(5),reg1));
+      if (itMap != VertexGlobalAssociation.end()){
+        v3 = itMap->second;
+      }
+      MPrism *newPri = new MPrism(v1,v3,v2,elem->getVertex(0),elem->getVertex(5),elem->getVertex(3));
+
+      createdRegion->addPrism(newPri);
+      //second
+      itMap = VertexGlobalAssociation.find(std::make_pair(elem->getVertex(1),reg1));
+      if (itMap != VertexGlobalAssociation.end()){
+        v1 = itMap->second;
+      }
+      itMap = VertexGlobalAssociation.find(std::make_pair(elem->getVertex(4),reg1));
+      if (itMap != VertexGlobalAssociation.end()){
+        v2 = itMap->second;
+      }
+      itMap = VertexGlobalAssociation.find(std::make_pair(elem->getVertex(3),reg1));
+      if (itMap != VertexGlobalAssociation.end()){
+        v3 = itMap->second;
+      }
+      MPrism *newPri2 = new MPrism(v1,v3,v2,elem->getVertex(1),elem->getVertex(3),elem->getVertex(4));
+
+      createdRegion->addPrism(newPri2);
+      //third
+      itMap = VertexGlobalAssociation.find(std::make_pair(elem->getVertex(2),reg1));
+      if (itMap != VertexGlobalAssociation.end()){
+        v1 = itMap->second;
+      }
+      itMap = VertexGlobalAssociation.find(std::make_pair(elem->getVertex(5),reg1));
+      if (itMap != VertexGlobalAssociation.end()){
+        v2 = itMap->second;
+      }
+      itMap = VertexGlobalAssociation.find(std::make_pair(elem->getVertex(4),reg1));
+      if (itMap != VertexGlobalAssociation.end()){
+        v3 = itMap->second;
+      }
+      MPrism *newPri3 = new MPrism(v1,v3,v2,elem->getVertex(2),elem->getVertex(4),elem->getVertex(5));
+
+      createdRegion->addPrism(newPri3);
+      //fourth
+      itMap = VertexGlobalAssociation.find(std::make_pair(elem->getVertex(3),reg1));
+      if (itMap != VertexGlobalAssociation.end()){
+        v1 = itMap->second;
+      }
+      itMap = VertexGlobalAssociation.find(std::make_pair(elem->getVertex(4),reg1));
+      if (itMap != VertexGlobalAssociation.end()){
+        v2 = itMap->second;
+      }
+      itMap = VertexGlobalAssociation.find(std::make_pair(elem->getVertex(5),reg1));
+      if (itMap != VertexGlobalAssociation.end()){
+        v3 = itMap->second;
+      }
+      MPrism *newPri4 = new MPrism(v1,v3,v2,elem->getVertex(3),elem->getVertex(5),elem->getVertex(4));
+
+      createdRegion->addPrism(newPri4);
+    }
+    for (unsigned int i = 0; i < reg1->getNumMeshElements();i++){
+      MElement* elem = reg1->getMeshElement(i);
+      for (int j = 0;j < elem->getNumVertices();j++){
+        MVertex* vert = elem->getVertex(j);
+        std::map<std::pair<MVertex*,GRegion*>,MVertex* >::iterator itMap = VertexGlobalAssociation.find(std::make_pair(vert,reg1));
+        if (itMap != VertexGlobalAssociation.end()){
+          elem->setVertex(j,itMap->second);
+        }
+      }
+    }
+  }
+  std::ofstream file("MicrostructurePolycrystal3D.pos");
+  file << "View \"test\" {\n";
+
+  std::ofstream file2("PERIODIC.map");
+  std::ofstream file3("SetAdd.map");
+  for (std::vector<std::pair<GFace*,GFace*> >::iterator itP = pairs.begin();itP != pairs.end();itP++){
+    std::pair<GFace*,GFace*> pairTmp = (*itP);
+    GFace* ToReplaceFace = pairTmp.second;
+    GRegion* rTmp = ToReplaceFace->getRegion(0);
+    std::map<std::pair<GFace*,GRegion*>,GFace* >::iterator itMap = GFaceGlobalAssociation.find(std::make_pair(ToReplaceFace,rTmp));
+    if (itMap != GFaceGlobalAssociation.end()){
+      GFace* associatedFace = (*itMap).second;
+
+
+
+
+
+      file3 <<associatedFace->tag()<<"\tSURFACE"<<associatedFace->tag()<<"\tNSET "<<"\n";
+
+      int tagTmp = associatedFace->tag();
+      std::ostringstream ss;
+      ss << tagTmp;
+      //			char *intStr = itoa(tagTmp);
+      std::string nameSurf = "SURFACE";
+      //			nameSurf += std::string(intStr);
+      nameSurf += ss.str();
+      int PhysicalSurfaceTmp = m->setPhysicalName(nameSurf,2);
+      associatedFace->addPhysicalEntity(PhysicalSurfaceTmp);
+
+      std::map<GFace*,SPoint3>::iterator it3 = centers.find(pairTmp.first);
+      std::map<GFace*,SPoint3>::iterator it4 = centers.find(ToReplaceFace);
+
+      SPoint3 p1 = it3->second;
+      SPoint3  p2 = it4->second;
+
+      //double delta_x = fabs(p2.x()-p1.x());
+      //double delta_y = fabs(p2.y()-p1.y());
+      //double delta_z = fabs(p2.z()-p1.z());
+
+
+      file << "SL ("
+           << p1.x() << ", " << p1.y() << ", " << p1.z() << ", "
+           << p2.x() << ", " << p2.y() << ", " << p2.z()
+           << "){10, 20};\n";
+
+      //file2 << "PERIODIC\tSURFACE"<<faces[i]->tag() << "\tSURFACE" << faces[j]->tag() << "\t" << p2.x()-p1.x() << "\t" << p2.y()-p1.y() << "\t" << p2.z()-p1.z() << "\n";
+      if (abs((p2.x()-p1.x()-1.0))<0.0001){
+        if (abs((p2.y()-p1.y()))<0.0001){
+          if (abs((p2.z()-p1.z()))<0.0001){
+            file2 << "NSET\tFRONT = FRONT + SURFACE"<<associatedFace->tag()<<"\n";
+            file2 << "NSET\tBACK = BACK + SURFACE"<<pairTmp.first->tag()<<"\n";
+          }else if(abs((p2.z()-p1.z()-1.0))<0.0001){
+            file2 << "NSET\tFRONTTOP = FRONTTOP + SURFACE"<<associatedFace->tag()<<"\n";
+            file2 << "NSET\tBACKBOTTOM = BACKBOTTOM + SURFACE"<<pairTmp.first->tag()<<"\n";
+          }else if (abs((p1.z()-p2.z()-1.0))<0.0001){
+            file2 << "NSET\tFRONTBOTTOM = FRONTBOTTOM + SURFACE"<<associatedFace->tag()<<"\n";
+            file2 << "NSET\tBACKTOP = BACKTOP + SURFACE"<<pairTmp.first->tag()<<"\n";
+          }
+        }else if (abs((p2.y()-p1.y()-1.0))<0.0001){
+          if (abs((p2.z()-p1.z()))<0.0001){
+            file2 << "NSET\tFRONTRIGHT = FRONTRIGHT + SURFACE"<<associatedFace->tag()<<"\n";
+            file2 << "NSET\tBACKLEFT = BACKLEFT + SURFACE"<<pairTmp.first->tag()<<"\n";
+          }else if (abs((p2.z()-p1.z()-1.0))<0.0001){
+            file2 << "NSET\tFRONTRIGHTTOP = FRONTRIGHTTOP + SURFACE"<<associatedFace->tag()<<"\n";
+            file2 << "NSET\tBACKLEFTBOTTOM = BACKLEFTBOTTOM + SURFACE"<<pairTmp.first->tag()<<"\n";
+          }else if (abs((p1.z()-p2.z()-1.0))<0.0001){
+            file2 << "NSET\tFRONTRIGHTBOTTOM = FRONTRIGHTBOTTOM + SURFACE"<<associatedFace->tag()<<"\n";
+            file2 << "NSET\tBACKLEFTTOP = BACKLEFTTOP + SURFACE"<<pairTmp.first->tag()<<"\n";
+          }
+        }else if (abs((p1.y()-p2.y()-1.0))<0.0001){
+          if (abs((p2.z()-p1.z()))<0.0001){
+            file2 << "NSET\tFRONTLEFT = FRONTLEFT + SURFACE"<<associatedFace->tag()<<"\n";
+            file2 << "NSET\tBACKRIGHT = BACKRIGHT + SURFACE"<<pairTmp.first->tag()<<"\n";
+          }else if (abs((p2.z()-p1.z()-1.0))<0.0001){
+            file2 << "NSET\tFRONTLEFTTOP = FRONTLEFTTOP + SURFACE"<<associatedFace->tag()<<"\n";
+            file2 << "NSET\tBACKRIGHTBOTTOM = BACKRIGHTBOTTOM + SURFACE"<<pairTmp.first->tag()<<"\n";
+          }else if (abs((p1.z()-p2.z()-1.0))<0.0001){
+            file2 << "NSET\tFRONTLEFTBOTTOM = FRONTLEFTBOTTOM + SURFACE"<<associatedFace->tag()<<"\n";
+            file2 << "NSET\tBACKRIGHTTOP = BACKRIGHTTOP + SURFACE"<<pairTmp.first->tag()<<"\n";
+          }
+        }
+      }else if (abs((p1.x()-p2.x()-1.0))<0.0001){
+        if (abs((p2.y()-p1.y()))<0.0001){
+          if (abs((p2.z()-p1.z()))<0.0001){
+            file2 << "NSET\tFRONT = FRONT + SURFACE"<<pairTmp.first->tag()<<"\n";
+            file2 << "NSET\tBACK = BACK + SURFACE"<<associatedFace->tag()<<"\n";
+          }else if(abs((p2.z()-p1.z()-1.0))<0.0001){
+            file2 << "NSET\tFRONTBOTTOM = FRONTBOTTOM + SURFACE"<<pairTmp.first->tag()<<"\n";
+            file2 << "NSET\tBACKTOP = BACKTOP + SURFACE"<<associatedFace->tag()<<"\n";
+          }else if (abs((p1.z()-p2.z()-1.0))<0.0001){
+            file2 << "NSET\tFRONTTOP = FRONTTOP + SURFACE"<<pairTmp.first->tag()<<"\n";
+            file2 << "NSET\tBACKBOTTOM = BACKBOTTOM + SURFACE"<<associatedFace->tag()<<"\n";
+          }
+        }else if (abs((p2.y()-p1.y()-1.0))<0.0001){
+          if (abs((p2.z()-p1.z()))<0.0001){
+            file2 << "NSET\tFRONTLEFT = FRONTLEFT + SURFACE"<<pairTmp.first->tag()<<"\n";
+            file2 << "NSET\tBACKRIGHT = BACKRIGHT + SURFACE"<<associatedFace->tag()<<"\n";
+          }else if (abs((p2.z()-p1.z()-1.0))<0.0001){
+            file2 << "NSET\tFRONTLEFTBOTTOM = FRONTLEFTBOTTOM + SURFACE"<<pairTmp.first->tag()<<"\n";
+            file2 << "NSET\tBACKRIGHTTOP = BACKRIGHTTOP + SURFACE"<<associatedFace->tag()<<"\n";
+          }else if (abs((p1.z()-p2.z()-1.0))<0.0001){
+            file2 << "NSET\tFRONTLEFTTOP = FRONTLEFTTOP + SURFACE"<<pairTmp.first->tag()<<"\n";
+            file2 << "NSET\tBACKRIGHTBOTTOM = BACKRIGHTBOTTOM + SURFACE"<<associatedFace->tag()<<"\n";
+          }
+        }else if (abs((p1.y()-p2.y()-1.0))<0.0001){
+          if (abs((p2.z()-p1.z()))<0.0001){
+            file2 << "NSET\tFRONTRIGHT = FRONTRIGHT + SURFACE"<<pairTmp.first->tag()<<"\n";
+            file2 << "NSET\tBACKLEFT = BACKLEFT + SURFACE"<<associatedFace->tag()<<"\n";
+          }else if (abs((p2.z()-p1.z()-1.0))<0.0001){
+            file2 << "NSET\tFRONTRIGHTBOTTOM = FRONTRIGHTBOTTOM + SURFACE"<<pairTmp.first->tag()<<"\n";
+            file2 << "NSET\tBACKLEFTTOP = BACKLEFTTOP + SURFACE"<<associatedFace->tag()<<"\n";
+          }else if (abs((p1.z()-p2.z()-1.0))<0.0001){
+            file2 << "NSET\tFRONTRIGHTTOP = FRONTRIGHTTOP + SURFACE"<<pairTmp.first->tag()<<"\n";
+            file2 << "NSET\tBACKLEFTBOTTOM = BACKLEFTBOTTOM + SURFACE"<<associatedFace->tag()<<"\n";
+          }
+        }
+      }else if (abs((p1.x()-p2.x()))<0.0001){
+        if (abs((p2.y()-p1.y()-1.0))<0.0001){
+          if (abs((p2.z()-p1.z()))<0.0001){
+            file2 << "NSET\tRIGHT = RIGHT + SURFACE"<<associatedFace->tag()<<"\n";
+            file2 << "NSET\tLEFT = LEFT + SURFACE"<<pairTmp.first->tag()<<"\n";
+          }else if (abs((p2.z()-p1.z()-1.0))<0.0001){
+            file2 << "NSET\tRIGHTTOP = RIGHTTOP + SURFACE"<<associatedFace->tag()<<"\n";
+            file2 << "NSET\tLEFTBOTTOM = LEFTBOTTOM + SURFACE"<<pairTmp.first->tag()<<"\n";
+          }else if (abs((p1.z()-p2.z()-1.0))<0.0001){
+            file2 << "NSET\tRIGHTBOTTOM = RIGHTBOTTOM + SURFACE"<<associatedFace->tag()<<"\n";
+            file2 << "NSET\tLEFTTOP = LEFTTOP + SURFACE"<<pairTmp.first->tag()<<"\n";
+          }
+        }else if (abs((p1.y()-p2.y()-1.0))<0.0001){
+          if (abs((p2.z()-p1.z()))<0.0001){
+            file2 << "NSET\tRIGHT = RIGHT + SURFACE"<<pairTmp.first->tag()<<"\n";
+            file2 << "NSET\tLEFT = LEFT + SURFACE"<<associatedFace->tag()<<"\n";
+          }else if (abs((p2.z()-p1.z()-1.0))<0.0001){
+            file2 << "NSET\tRIGHTBOTTOM = RIGHTBOTTOM + SURFACE"<<pairTmp.first->tag()<<"\n";
+            file2 << "NSET\tLEFTTOP = LEFTTOP + SURFACE"<<associatedFace->tag()<<"\n";
+          }else if (abs((p1.z()-p2.z()-1.0))<0.0001){
+            file2 << "NSET\tRIGHTTOP = RIGHTTOP + SURFACE"<<pairTmp.first->tag()<<"\n";
+            file2 << "NSET\tLEFTBOTTOM = LEFTBOTTOM + SURFACE"<<associatedFace->tag()<<"\n";
+          }
+        }else if (abs((p1.y()-p2.y()))<0.0001){
+          if (abs((p2.z()-p1.z()-1.0))<0.0001){
+            file2 << "NSET\tTOP = TOP + SURFACE"<<associatedFace->tag()<<"\n";
+            file2 << "NSET\tBOTTOM = BOTTOM + SURFACE"<<pairTmp.first->tag()<<"\n";
+          }else if (abs((p1.z()-p2.z()-1.0))<0.0001){
+            file2 << "NSET\tTOP = TOP + SURFACE"<<pairTmp.first->tag()<<"\n";
+            file2 << "NSET\tBOTTOM = BOTTOM + SURFACE"<<associatedFace->tag()<<"\n";
+          }
+        }
+      }
+      //			count++;
+
+
+
+
+
+
+
+      newPairs.push_back(std::make_pair(pairTmp.first,associatedFace));
+    }
+  }
+  //	for (std::vector<std::pair<GFace*,GFace*> >::iterator itP = newPairs.begin();itP != newPairs.end();itP++){
+  //		std::pair<GFace*,GFace*> pairTmp = (*itP);
+  //	}
 
-	std::cout<<"End of DuplicateBoundaries"<<std::endl;
-	return view;
+  std::cout<<"End of DuplicateBoundaries"<<std::endl;
+  return view;
 }
 
 
@@ -2438,461 +2430,461 @@ PView *GMSH_DuplicateBoundariesPlugin::executeDuplicate(PView *view)
 
 PView *GMSH_DuplicateBoundariesPlugin::execute2D(PView *view)
 {
-	std::cout<<"starting DuplicateBoundaries"<<std::endl;
-	GModel *m = GModel::current();
-	m->setFactory("geo");
-	std::set<GEdge*> ToDuplicateList;
-	ToDuplicateList.clear();
-	std::set<GFace*> ToDuplicateListBoundary;
-	ToDuplicateListBoundary.clear();
-	std::vector<GFace*> facesBound;
-	facesBound.clear();
-	std::map<GFace*,SPoint3> centers;
-	std::vector<std::pair<GFace*,GFace*> > pairs;
-	std::vector<std::pair<GFace*,GFace*> > newPairs;
-	int PhysicalInterface = m->setPhysicalName("Interface",2);
-	for (GModel::eiter ite= m->firstEdge();ite != m->lastEdge();ite++){
-		GEdge* eTmp = (*ite);
-		if (eTmp->faces().size() == 2){
-			ToDuplicateList.insert(eTmp);
-		}
-	}
-
-
-
-
-
-
-
-
-
-
-	std::map<std::pair<MVertex*,GFace*>,MVertex* > VertexGlobalAssociation;
-	std::map<std::pair<GVertex*,GFace*>,GVertex* > GVertexGlobalAssociation;
-	std::map<std::pair<GEdge*,GFace*>,GEdge* > GEdgeGlobalAssociation;
-	std::map<std::pair<GFace*,GRegion*>,GFace* > GFaceGlobalAssociation;
-	for (GModel::fiter itr= m->firstFace();itr != m->lastFace();itr++){
-		GFace* rTmp = (*itr);
-		std::list<GEdge*> RegEdges = rTmp->edges();
-		std::map<MVertex*,MVertex* > VertexAssociation;
-		std::map<GVertex*,GVertex* > GVertexAssociation;
-		std::map<GEdge*,GEdge* > GEdgeAssociation;
-		//int counterNbDone = 10000;
-		double xCenterReg = 0.0;
-		double yCenterReg = 0.0;
-		double zCenterReg = 0.0;
-		int counterPts = 0;
-		for(std::list<GEdge*>::iterator it2=RegEdges.begin();it2!=RegEdges.end();it2++){
-			GEdge* fTemp = (*it2);
-			std::list<GVertex*> verticesFace = fTemp->vertices();
-			for (std::list<GVertex*>::iterator it3=verticesFace.begin();it3!=verticesFace.end();it3++){
-				xCenterReg = xCenterReg + (*it3)->x();
-				yCenterReg = yCenterReg + (*it3)->y();
-				zCenterReg = zCenterReg + (*it3)->z();
-				counterPts++;
-			}
-		}
-		xCenterReg = xCenterReg/counterPts;
-		yCenterReg = yCenterReg/counterPts;
-		zCenterReg = zCenterReg/counterPts;
-		//duplication noeud et aretes au niveau de la region directement
-		std::list<GVertex*> vlist;
-
-
-		std::list<GEdge*> listedgesTmp = rTmp->edges();
-		std::cout<<"listeEdge size "<<listedgesTmp.size()<<std::endl;
-		for (std::list<GEdge*>::iterator itTp = listedgesTmp.begin();itTp != listedgesTmp.end();itTp++){
-			std::list<GVertex*> vlist2;
-			if(std::find(vlist.begin(), vlist.end(),(*itTp)->getBeginVertex()) == vlist.end())
-				vlist.push_back((*itTp)->getBeginVertex());
-			if(std::find(vlist.begin(), vlist.end(),(*itTp)->getEndVertex()) == vlist.end())
-				vlist.push_back((*itTp)->getEndVertex());
-		}
-
-
-		for (std::list<GVertex*>::iterator itv = vlist.begin();itv != vlist.end();itv++){
-			//duplication Gvertex
-			GVertex* vTmp = (*itv);
-			double ponderatedX = 0.99999999999 * vTmp->x() + 0.00000000001 * xCenterReg;
-			double ponderatedY = 0.99999999999 * vTmp->y() + 0.00000000001 * yCenterReg;
-			double ponderatedZ = 0.99999999999 * vTmp->z() + 0.00000000001 * zCenterReg;
-			GVertex* newv = m->addVertex(ponderatedX,ponderatedY,ponderatedZ,vTmp->prescribedMeshSizeAtVertex());
-			GVertexAssociation[vTmp] = newv;
-			GVertexGlobalAssociation[std::make_pair(vTmp,rTmp)] = newv;
-			//creation des Gedge correspondantes
-//			GEdge* newE = m->addLine(vTmp,newv);
-//			SurroudingEdges[vTmp] = newE;
-			//maintenant traitement mesh
-			MVertex *vMesh = vTmp->mesh_vertices[0];
-			MVertex *newMv = new MVertex(vMesh->x(), vMesh->y(), vMesh->z(), (GEntity*)newv);
-			VertexAssociation[vMesh] = newMv;
-			VertexGlobalAssociation[std::make_pair(vMesh,rTmp)] = newMv;
-			newv->addMeshVertex(newMv);
-		}
-		//maintenant on soccupe de duppliquer les edges de la region
-		std::list<GEdge*> elist = rTmp->edges();
-
-		std::vector<GFace*> SurroundingsFaces;
-		for (std::list<GEdge*>::iterator itf = RegEdges.begin();itf != RegEdges.end();itf++){
-			GEdge* eTmp = (*itf);
-			//creation de la nouvelle face
-			GEdge* newE = m->addLine(GVertexAssociation[eTmp->getBeginVertex()],GVertexAssociation[eTmp->getEndVertex()]);
-			for (unsigned int i = 0; i < eTmp->mesh_vertices.size();i++){
-				MVertex *vMesh = eTmp->mesh_vertices[i];
-				MVertex *newMv = new MVertex(vMesh->x(), vMesh->y(), vMesh->z(), (GEntity*)newE);
-				VertexAssociation[vMesh] = newMv;
-				VertexGlobalAssociation[std::make_pair(vMesh,rTmp)] = newMv;
-				newE->addMeshVertex(newMv);
-			}
-			for (unsigned int i = 0; i < eTmp->getNumMeshElements();i++){
-				MElement* elem = eTmp->getMeshElement(i);
-				MVertex *firstETmp = VertexAssociation.find(elem->getVertex(0))->second;
-				MVertex *lastETmp = VertexAssociation.find(elem->getVertex(1))->second;
-				MVertex *midETmp = VertexAssociation.find(elem->getVertex(2))->second;
-				MLine3 *newLine = new MLine3(firstETmp,lastETmp,midETmp);
-				newE->addLine(newLine);
-			}
-			GEdgeGlobalAssociation[std::make_pair(eTmp,rTmp)] = newE;
-		}
-	}
-	int counterNbDone = 10000;
-	//maintenant on va traiter les faces initiales
-	for (std::set<GEdge*>::iterator itf = ToDuplicateList.begin();itf != ToDuplicateList.end();itf++){
-		counterNbDone++;
-		GEdge* eTmp = (*itf);
-		std::list<GFace*> listFacesTmpT = eTmp->faces();
-		std::list<GFace*>::iterator itTmpFace = listFacesTmpT.begin();
-		GFace* fac1 = (*itTmpFace);
-		itTmpFace++;
-		GFace* fac2 = (*itTmpFace);
-		//pour commencer on cree des aretes entre les vertex
-//		std::list<GVertex*> vlist = eTmp->vertices();
-		std::list<GVertex*> vlist;
-		vlist.push_back(eTmp->getBeginVertex());
-		vlist.push_back(eTmp->getEndVertex());
-		std::map<GVertex*,GEdge* > SurroudingEdges;
-		for (std::list<GVertex*>::iterator itv = vlist.begin();itv != vlist.end();itv++){
-			GVertex* vTmp = (*itv);
-			GVertex* v1=0;
-			GVertex* v2=0;
-			std::map<std::pair<GVertex*,GFace*>,GVertex* >::iterator itMap = GVertexGlobalAssociation.find(std::make_pair(vTmp,fac1));
-			if (itMap != GVertexGlobalAssociation.end()){
-				v1 = itMap->second;
-			}
-			itMap = GVertexGlobalAssociation.find(std::make_pair(vTmp,fac2));
-			if (itMap != GVertexGlobalAssociation.end()){
-				v2 = itMap->second;
-			}
-			GEdge* newE = m->addLine(v1,v2);
-			SurroudingEdges[vTmp] = newE;
-		}
-		//ici tous les vertex sont traites
-		//on va traiter les edges
-//		std::list<GEdge*> elist = fTmp->edges();
-		std::vector<GEdge*> newEdgesVector;
-		std::vector<GFace*> SurroundingsFaces;
-		//duplication Gedge
-		//			GEdge* eTmp = (*ite);
-		GEdge* e1=0;
-		GEdge* e2=0;
-		std::map<std::pair<GEdge*,GFace*>,GEdge* >::iterator itMap = GEdgeGlobalAssociation.find(std::make_pair(eTmp,fac1));
-		if (itMap != GEdgeGlobalAssociation.end()){
-			e1 = itMap->second;
-		}
-		itMap = GEdgeGlobalAssociation.find(std::make_pair(eTmp,fac2));
-		if (itMap != GEdgeGlobalAssociation.end()){
-			e2 = itMap->second;
-		}
-		//creation des GFace correspondantes
-		GEdge* firstE = SurroudingEdges.find(eTmp->getBeginVertex())->second;
-		GEdge* lastE = SurroudingEdges.find(eTmp->getEndVertex())->second;
-		if (firstE->getBeginVertex() != e1->getEndVertex()){
-			firstE->reverse();
-		}
-		if (firstE->getBeginVertex() != e1->getEndVertex()){
-			e1->reverse();
-		}
-		if (firstE->getBeginVertex() != e1->getEndVertex()){
-			firstE->reverse();
-		}
-		if (e2->getBeginVertex() != firstE->getEndVertex()){
-			e2->reverse();
-		}
-		if (lastE->getBeginVertex() != e2->getEndVertex()){
-			lastE->reverse();
-		}
-		std::vector<GEdge*> VecEdgesTmp;
-		VecEdgesTmp.push_back(e1);
-		VecEdgesTmp.push_back(firstE);
-		VecEdgesTmp.push_back(e2);
-		VecEdgesTmp.push_back(lastE);
-		std::vector<std::vector<GEdge*> > VecOfVecTmp;
-		VecOfVecTmp.push_back(VecEdgesTmp);
-		GFace* newFaceTmp = m->addPlanarFace(VecOfVecTmp);
-		//			SurroundingsFaces.push_back(newFaceTmp);
-
-		//creation de la nouvelle region
-//		GRegion* createdRegion = new GRegion(m,counterNbDone);
-		newFaceTmp->addPhysicalEntity(PhysicalInterface);
-//		createdRegion->set(listFaces);
-//		m->add(createdRegion);
-		for (unsigned int i = 0; i < eTmp->getNumMeshElements();i++){
-			MElement* elem = eTmp->getMeshElement(i);
-			MVertex* v1=0;
-			MVertex* v2=0;
-			MVertex* v3=0;
-			MVertex* v4=0;
-			//MVertex* v5;
-			//MVertex* v6;
-			std::map<std::pair<MVertex*,GFace*>,MVertex* >::iterator itMap = VertexGlobalAssociation.find(std::make_pair(elem->getVertex(0),fac1));
-			if (itMap != VertexGlobalAssociation.end()){
-				v1 = itMap->second;
-			}
-			itMap = VertexGlobalAssociation.find(std::make_pair(elem->getVertex(2),fac1));
-			if (itMap != VertexGlobalAssociation.end()){
-				v2 = itMap->second;
-			}
-			itMap = VertexGlobalAssociation.find(std::make_pair(elem->getVertex(2),fac2));
-			if (itMap != VertexGlobalAssociation.end()){
-				v3 = itMap->second;
-			}
-			itMap = VertexGlobalAssociation.find(std::make_pair(elem->getVertex(0),fac2));
-			if (itMap != VertexGlobalAssociation.end()){
-				v4 = itMap->second;
-			}
-//			itMap = VertexGlobalAssociation.find(std::make_pair(elem->getVertex(3),fac2));
-//			if (itMap != VertexGlobalAssociation.end()){
-//				v5 = itMap->second;
-//			}
-//			itMap = VertexGlobalAssociation.find(std::make_pair(elem->getVertex(5),fac2));
-//			if (itMap != VertexGlobalAssociation.end()){
-//				v6 = itMap->second;
-//			}
-			MQuadrangle *newQua = new MQuadrangle(v1,v2,v3,v4);
-
-			newFaceTmp->addQuadrangle(newQua);
-
-			//second
-			itMap = VertexGlobalAssociation.find(std::make_pair(elem->getVertex(2),fac1));
-			if (itMap != VertexGlobalAssociation.end()){
-				v1 = itMap->second;
-			}
-			itMap = VertexGlobalAssociation.find(std::make_pair(elem->getVertex(1),fac1));
-			if (itMap != VertexGlobalAssociation.end()){
-				v2 = itMap->second;
-			}
-			itMap = VertexGlobalAssociation.find(std::make_pair(elem->getVertex(1),fac2));
-			if (itMap != VertexGlobalAssociation.end()){
-				v3 = itMap->second;
-			}
-			itMap = VertexGlobalAssociation.find(std::make_pair(elem->getVertex(2),fac2));
-			if (itMap != VertexGlobalAssociation.end()){
-				v4 = itMap->second;
-			}
-			//			itMap = VertexGlobalAssociation.find(std::make_pair(elem->getVertex(3),fac2));
-			//			if (itMap != VertexGlobalAssociation.end()){
-			//				v5 = itMap->second;
-			//			}
-			//			itMap = VertexGlobalAssociation.find(std::make_pair(elem->getVertex(5),fac2));
-			//			if (itMap != VertexGlobalAssociation.end()){
-			//				v6 = itMap->second;
-			//			}
-			MQuadrangle *newQua2 = new MQuadrangle(v1,v2,v3,v4);
-
-			newFaceTmp->addQuadrangle(newQua2);
-
-
-
-
-		}
-		for (unsigned int i = 0; i < fac1->getNumMeshElements();i++){
-			MElement* elem = fac1->getMeshElement(i);
-			for (int j = 0;j < elem->getNumVertices();j++){
-				MVertex* vert = elem->getVertex(j);
-				std::map<std::pair<MVertex*,GFace*>,MVertex* >::iterator itMap = VertexGlobalAssociation.find(std::make_pair(vert,fac1));
-				if (itMap != VertexGlobalAssociation.end()){
-					elem->setVertex(j,itMap->second);
-				}
-			}
-		}
-		for (unsigned int i = 0; i < fac2->getNumMeshElements();i++){
-			MElement* elem = fac2->getMeshElement(i);
-			for (int j = 0;j < elem->getNumVertices();j++){
-				MVertex* vert = elem->getVertex(j);
-				std::map<std::pair<MVertex*,GFace*>,MVertex* >::iterator itMap = VertexGlobalAssociation.find(std::make_pair(vert,fac2));
-				if (itMap != VertexGlobalAssociation.end()){
-					elem->setVertex(j,itMap->second);
-				}
-			}
-		}
-	}
-	//maintenant on va traiter les faces du bord
-//	std::ofstream file("MicrostructurePolycrystal3D.pos");
-//	file << "View \"test\" {\n";
-//
-//	std::ofstream file2("PERIODIC.map");
-//	std::ofstream file3("SetAdd.map");
-//	for (std::vector<std::pair<GFace*,GFace*> >::iterator itP = pairs.begin();itP != pairs.end();itP++){
-//		std::pair<GFace*,GFace*> pairTmp = (*itP);
-//		GFace* ToReplaceFace = pairTmp.second;
-//		GRegion* rTmp = ToReplaceFace->getRegion(0);
-//		std::map<std::pair<GFace*,GRegion*>,GFace* >::iterator itMap = GFaceGlobalAssociation.find(std::make_pair(ToReplaceFace,rTmp));
-//		if (itMap != GFaceGlobalAssociation.end()){
-//			GFace* associatedFace = (*itMap).second;
-//
-//
-//
-//
-//
-//			file3 <<associatedFace->tag()<<"\tSURFACE"<<associatedFace->tag()<<"\tNSET "<<"\n";
-//
-//			int tagTmp = associatedFace->tag();
-//			std::ostringstream ss;
-//			ss << tagTmp;
-////			char *intStr = itoa(tagTmp);
-//			std::string nameSurf = "SURFACE";
-////			nameSurf += std::string(intStr);
-//			nameSurf += ss.str();
-//			int PhysicalSurfaceTmp = m->setPhysicalName(nameSurf,2);
-//			associatedFace->addPhysicalEntity(PhysicalSurfaceTmp);
-//
-//			std::map<GFace*,SPoint3>::iterator it3 = centers.find(pairTmp.first);
-//			std::map<GFace*,SPoint3>::iterator it4 = centers.find(ToReplaceFace);
-//
-//			SPoint3 p1 = it3->second;
-//			SPoint3  p2 = it4->second;
-//
-//			double delta_x = fabs(p2.x()-p1.x());
-//			double delta_y = fabs(p2.y()-p1.y());
-//			double delta_z = fabs(p2.z()-p1.z());
-//
-//
-//			file << "SL ("
-//					<< p1.x() << ", " << p1.y() << ", " << p1.z() << ", "
-//					<< p2.x() << ", " << p2.y() << ", " << p2.z()
-//					<< "){10, 20};\n";
-//
-//			//file2 << "PERIODIC\tSURFACE"<<faces[i]->tag() << "\tSURFACE" << faces[j]->tag() << "\t" << p2.x()-p1.x() << "\t" << p2.y()-p1.y() << "\t" << p2.z()-p1.z() << "\n";
-//			if (abs((p2.x()-p1.x()-1.0))<0.0001){
-//				if (abs((p2.y()-p1.y()))<0.0001){
-//					if (abs((p2.z()-p1.z()))<0.0001){
-//						file2 << "NSET\tFRONT = FRONT + SURFACE"<<associatedFace->tag()<<"\n";
-//						file2 << "NSET\tBACK = BACK + SURFACE"<<pairTmp.first->tag()<<"\n";
-//					}else if(abs((p2.z()-p1.z()-1.0))<0.0001){
-//						file2 << "NSET\tFRONTTOP = FRONTTOP + SURFACE"<<associatedFace->tag()<<"\n";
-//						file2 << "NSET\tBACKBOTTOM = BACKBOTTOM + SURFACE"<<pairTmp.first->tag()<<"\n";
-//					}else if (abs((p1.z()-p2.z()-1.0))<0.0001){
-//						file2 << "NSET\tFRONTBOTTOM = FRONTBOTTOM + SURFACE"<<associatedFace->tag()<<"\n";
-//						file2 << "NSET\tBACKTOP = BACKTOP + SURFACE"<<pairTmp.first->tag()<<"\n";
-//					}
-//				}else if (abs((p2.y()-p1.y()-1.0))<0.0001){
-//					if (abs((p2.z()-p1.z()))<0.0001){
-//						file2 << "NSET\tFRONTRIGHT = FRONTRIGHT + SURFACE"<<associatedFace->tag()<<"\n";
-//						file2 << "NSET\tBACKLEFT = BACKLEFT + SURFACE"<<pairTmp.first->tag()<<"\n";
-//					}else if (abs((p2.z()-p1.z()-1.0))<0.0001){
-//						file2 << "NSET\tFRONTRIGHTTOP = FRONTRIGHTTOP + SURFACE"<<associatedFace->tag()<<"\n";
-//						file2 << "NSET\tBACKLEFTBOTTOM = BACKLEFTBOTTOM + SURFACE"<<pairTmp.first->tag()<<"\n";
-//					}else if (abs((p1.z()-p2.z()-1.0))<0.0001){
-//						file2 << "NSET\tFRONTRIGHTBOTTOM = FRONTRIGHTBOTTOM + SURFACE"<<associatedFace->tag()<<"\n";
-//						file2 << "NSET\tBACKLEFTTOP = BACKLEFTTOP + SURFACE"<<pairTmp.first->tag()<<"\n";
-//					}
-//				}else if (abs((p1.y()-p2.y()-1.0))<0.0001){
-//					if (abs((p2.z()-p1.z()))<0.0001){
-//						file2 << "NSET\tFRONTLEFT = FRONTLEFT + SURFACE"<<associatedFace->tag()<<"\n";
-//						file2 << "NSET\tBACKRIGHT = BACKRIGHT + SURFACE"<<pairTmp.first->tag()<<"\n";
-//					}else if (abs((p2.z()-p1.z()-1.0))<0.0001){
-//						file2 << "NSET\tFRONTLEFTTOP = FRONTLEFTTOP + SURFACE"<<associatedFace->tag()<<"\n";
-//						file2 << "NSET\tBACKRIGHTBOTTOM = BACKRIGHTBOTTOM + SURFACE"<<pairTmp.first->tag()<<"\n";
-//					}else if (abs((p1.z()-p2.z()-1.0))<0.0001){
-//						file2 << "NSET\tFRONTLEFTBOTTOM = FRONTLEFTBOTTOM + SURFACE"<<associatedFace->tag()<<"\n";
-//						file2 << "NSET\tBACKRIGHTTOP = BACKRIGHTTOP + SURFACE"<<pairTmp.first->tag()<<"\n";
-//					}
-//				}
-//			}else if (abs((p1.x()-p2.x()-1.0))<0.0001){
-//				if (abs((p2.y()-p1.y()))<0.0001){
-//					if (abs((p2.z()-p1.z()))<0.0001){
-//						file2 << "NSET\tFRONT = FRONT + SURFACE"<<pairTmp.first->tag()<<"\n";
-//						file2 << "NSET\tBACK = BACK + SURFACE"<<associatedFace->tag()<<"\n";
-//					}else if(abs((p2.z()-p1.z()-1.0))<0.0001){
-//						file2 << "NSET\tFRONTBOTTOM = FRONTBOTTOM + SURFACE"<<pairTmp.first->tag()<<"\n";
-//						file2 << "NSET\tBACKTOP = BACKTOP + SURFACE"<<associatedFace->tag()<<"\n";
-//					}else if (abs((p1.z()-p2.z()-1.0))<0.0001){
-//						file2 << "NSET\tFRONTTOP = FRONTTOP + SURFACE"<<pairTmp.first->tag()<<"\n";
-//						file2 << "NSET\tBACKBOTTOM = BACKBOTTOM + SURFACE"<<associatedFace->tag()<<"\n";
-//					}
-//				}else if (abs((p2.y()-p1.y()-1.0))<0.0001){
-//					if (abs((p2.z()-p1.z()))<0.0001){
-//						file2 << "NSET\tFRONTLEFT = FRONTLEFT + SURFACE"<<pairTmp.first->tag()<<"\n";
-//						file2 << "NSET\tBACKRIGHT = BACKRIGHT + SURFACE"<<associatedFace->tag()<<"\n";
-//					}else if (abs((p2.z()-p1.z()-1.0))<0.0001){
-//						file2 << "NSET\tFRONTLEFTBOTTOM = FRONTLEFTBOTTOM + SURFACE"<<pairTmp.first->tag()<<"\n";
-//						file2 << "NSET\tBACKRIGHTTOP = BACKRIGHTTOP + SURFACE"<<associatedFace->tag()<<"\n";
-//					}else if (abs((p1.z()-p2.z()-1.0))<0.0001){
-//						file2 << "NSET\tFRONTLEFTTOP = FRONTLEFTTOP + SURFACE"<<pairTmp.first->tag()<<"\n";
-//						file2 << "NSET\tBACKRIGHTBOTTOM = BACKRIGHTBOTTOM + SURFACE"<<associatedFace->tag()<<"\n";
-//					}
-//				}else if (abs((p1.y()-p2.y()-1.0))<0.0001){
-//					if (abs((p2.z()-p1.z()))<0.0001){
-//						file2 << "NSET\tFRONTRIGHT = FRONTRIGHT + SURFACE"<<pairTmp.first->tag()<<"\n";
-//						file2 << "NSET\tBACKLEFT = BACKLEFT + SURFACE"<<associatedFace->tag()<<"\n";
-//					}else if (abs((p2.z()-p1.z()-1.0))<0.0001){
-//						file2 << "NSET\tFRONTRIGHTBOTTOM = FRONTRIGHTBOTTOM + SURFACE"<<pairTmp.first->tag()<<"\n";
-//						file2 << "NSET\tBACKLEFTTOP = BACKLEFTTOP + SURFACE"<<associatedFace->tag()<<"\n";
-//					}else if (abs((p1.z()-p2.z()-1.0))<0.0001){
-//						file2 << "NSET\tFRONTRIGHTTOP = FRONTRIGHTTOP + SURFACE"<<pairTmp.first->tag()<<"\n";
-//						file2 << "NSET\tBACKLEFTBOTTOM = BACKLEFTBOTTOM + SURFACE"<<associatedFace->tag()<<"\n";
-//					}
-//				}
-//			}else if (abs((p1.x()-p2.x()))<0.0001){
-//				if (abs((p2.y()-p1.y()-1.0))<0.0001){
-//					if (abs((p2.z()-p1.z()))<0.0001){
-//						file2 << "NSET\tRIGHT = RIGHT + SURFACE"<<associatedFace->tag()<<"\n";
-//						file2 << "NSET\tLEFT = LEFT + SURFACE"<<pairTmp.first->tag()<<"\n";
-//					}else if (abs((p2.z()-p1.z()-1.0))<0.0001){
-//						file2 << "NSET\tRIGHTTOP = RIGHTTOP + SURFACE"<<associatedFace->tag()<<"\n";
-//						file2 << "NSET\tLEFTBOTTOM = LEFTBOTTOM + SURFACE"<<pairTmp.first->tag()<<"\n";
-//					}else if (abs((p1.z()-p2.z()-1.0))<0.0001){
-//						file2 << "NSET\tRIGHTBOTTOM = RIGHTBOTTOM + SURFACE"<<associatedFace->tag()<<"\n";
-//						file2 << "NSET\tLEFTTOP = LEFTTOP + SURFACE"<<pairTmp.first->tag()<<"\n";
-//					}
-//				}else if (abs((p1.y()-p2.y()-1.0))<0.0001){
-//					if (abs((p2.z()-p1.z()))<0.0001){
-//						file2 << "NSET\tRIGHT = RIGHT + SURFACE"<<pairTmp.first->tag()<<"\n";
-//						file2 << "NSET\tLEFT = LEFT + SURFACE"<<associatedFace->tag()<<"\n";
-//					}else if (abs((p2.z()-p1.z()-1.0))<0.0001){
-//						file2 << "NSET\tRIGHTBOTTOM = RIGHTBOTTOM + SURFACE"<<pairTmp.first->tag()<<"\n";
-//						file2 << "NSET\tLEFTTOP = LEFTTOP + SURFACE"<<associatedFace->tag()<<"\n";
-//					}else if (abs((p1.z()-p2.z()-1.0))<0.0001){
-//						file2 << "NSET\tRIGHTTOP = RIGHTTOP + SURFACE"<<pairTmp.first->tag()<<"\n";
-//						file2 << "NSET\tLEFTBOTTOM = LEFTBOTTOM + SURFACE"<<associatedFace->tag()<<"\n";
-//					}
-//				}else if (abs((p1.y()-p2.y()))<0.0001){
-//					if (abs((p2.z()-p1.z()-1.0))<0.0001){
-//						file2 << "NSET\tTOP = TOP + SURFACE"<<associatedFace->tag()<<"\n";
-//						file2 << "NSET\tBOTTOM = BOTTOM + SURFACE"<<pairTmp.first->tag()<<"\n";
-//					}else if (abs((p1.z()-p2.z()-1.0))<0.0001){
-//						file2 << "NSET\tTOP = TOP + SURFACE"<<pairTmp.first->tag()<<"\n";
-//						file2 << "NSET\tBOTTOM = BOTTOM + SURFACE"<<associatedFace->tag()<<"\n";
-//					}
-//				}
-//			}
-////			count++;
-//
-//
-//
-//
-//
-//
-//
-//			newPairs.push_back(std::make_pair(pairTmp.first,associatedFace));
-//		}
-//	}
-//	for (std::vector<std::pair<GFace*,GFace*> >::iterator itP = newPairs.begin();itP != newPairs.end();itP++){
-//		std::pair<GFace*,GFace*> pairTmp = (*itP);
-//	}
+  std::cout<<"starting DuplicateBoundaries"<<std::endl;
+  GModel *m = GModel::current();
+  m->setFactory("geo");
+  std::set<GEdge*> ToDuplicateList;
+  ToDuplicateList.clear();
+  std::set<GFace*> ToDuplicateListBoundary;
+  ToDuplicateListBoundary.clear();
+  std::vector<GFace*> facesBound;
+  facesBound.clear();
+  std::map<GFace*,SPoint3> centers;
+  std::vector<std::pair<GFace*,GFace*> > pairs;
+  std::vector<std::pair<GFace*,GFace*> > newPairs;
+  int PhysicalInterface = m->setPhysicalName("Interface",2);
+  for (GModel::eiter ite= m->firstEdge();ite != m->lastEdge();ite++){
+    GEdge* eTmp = (*ite);
+    if (eTmp->faces().size() == 2){
+      ToDuplicateList.insert(eTmp);
+    }
+  }
+
+
+
 
-	std::cout<<"End of DuplicateBoundaries"<<std::endl;
-	return view;
+
+
+
+
+
+
+  std::map<std::pair<MVertex*,GFace*>,MVertex* > VertexGlobalAssociation;
+  std::map<std::pair<GVertex*,GFace*>,GVertex* > GVertexGlobalAssociation;
+  std::map<std::pair<GEdge*,GFace*>,GEdge* > GEdgeGlobalAssociation;
+  std::map<std::pair<GFace*,GRegion*>,GFace* > GFaceGlobalAssociation;
+  for (GModel::fiter itr= m->firstFace();itr != m->lastFace();itr++){
+    GFace* rTmp = (*itr);
+    std::list<GEdge*> RegEdges = rTmp->edges();
+    std::map<MVertex*,MVertex* > VertexAssociation;
+    std::map<GVertex*,GVertex* > GVertexAssociation;
+    std::map<GEdge*,GEdge* > GEdgeAssociation;
+    //int counterNbDone = 10000;
+    double xCenterReg = 0.0;
+    double yCenterReg = 0.0;
+    double zCenterReg = 0.0;
+    int counterPts = 0;
+    for(std::list<GEdge*>::iterator it2=RegEdges.begin();it2!=RegEdges.end();it2++){
+      GEdge* fTemp = (*it2);
+      std::list<GVertex*> verticesFace = fTemp->vertices();
+      for (std::list<GVertex*>::iterator it3=verticesFace.begin();it3!=verticesFace.end();it3++){
+        xCenterReg = xCenterReg + (*it3)->x();
+        yCenterReg = yCenterReg + (*it3)->y();
+        zCenterReg = zCenterReg + (*it3)->z();
+        counterPts++;
+      }
+    }
+    xCenterReg = xCenterReg/counterPts;
+    yCenterReg = yCenterReg/counterPts;
+    zCenterReg = zCenterReg/counterPts;
+    //duplication noeud et aretes au niveau de la region directement
+    std::list<GVertex*> vlist;
+
+
+    std::list<GEdge*> listedgesTmp = rTmp->edges();
+    std::cout<<"listeEdge size "<<listedgesTmp.size()<<std::endl;
+    for (std::list<GEdge*>::iterator itTp = listedgesTmp.begin();itTp != listedgesTmp.end();itTp++){
+      std::list<GVertex*> vlist2;
+      if(std::find(vlist.begin(), vlist.end(),(*itTp)->getBeginVertex()) == vlist.end())
+        vlist.push_back((*itTp)->getBeginVertex());
+      if(std::find(vlist.begin(), vlist.end(),(*itTp)->getEndVertex()) == vlist.end())
+        vlist.push_back((*itTp)->getEndVertex());
+    }
+
+
+    for (std::list<GVertex*>::iterator itv = vlist.begin();itv != vlist.end();itv++){
+      //duplication Gvertex
+      GVertex* vTmp = (*itv);
+      double ponderatedX = 0.99999999999 * vTmp->x() + 0.00000000001 * xCenterReg;
+      double ponderatedY = 0.99999999999 * vTmp->y() + 0.00000000001 * yCenterReg;
+      double ponderatedZ = 0.99999999999 * vTmp->z() + 0.00000000001 * zCenterReg;
+      GVertex* newv = m->addVertex(ponderatedX,ponderatedY,ponderatedZ,vTmp->prescribedMeshSizeAtVertex());
+      GVertexAssociation[vTmp] = newv;
+      GVertexGlobalAssociation[std::make_pair(vTmp,rTmp)] = newv;
+      //creation des Gedge correspondantes
+      //			GEdge* newE = m->addLine(vTmp,newv);
+      //			SurroudingEdges[vTmp] = newE;
+      //maintenant traitement mesh
+      MVertex *vMesh = vTmp->mesh_vertices[0];
+      MVertex *newMv = new MVertex(vMesh->x(), vMesh->y(), vMesh->z(), (GEntity*)newv);
+      VertexAssociation[vMesh] = newMv;
+      VertexGlobalAssociation[std::make_pair(vMesh,rTmp)] = newMv;
+      newv->addMeshVertex(newMv);
+    }
+    //maintenant on soccupe de duppliquer les edges de la region
+    std::list<GEdge*> elist = rTmp->edges();
+
+    std::vector<GFace*> SurroundingsFaces;
+    for (std::list<GEdge*>::iterator itf = RegEdges.begin();itf != RegEdges.end();itf++){
+      GEdge* eTmp = (*itf);
+      //creation de la nouvelle face
+      GEdge* newE = m->addLine(GVertexAssociation[eTmp->getBeginVertex()],GVertexAssociation[eTmp->getEndVertex()]);
+      for (unsigned int i = 0; i < eTmp->mesh_vertices.size();i++){
+        MVertex *vMesh = eTmp->mesh_vertices[i];
+        MVertex *newMv = new MVertex(vMesh->x(), vMesh->y(), vMesh->z(), (GEntity*)newE);
+        VertexAssociation[vMesh] = newMv;
+        VertexGlobalAssociation[std::make_pair(vMesh,rTmp)] = newMv;
+        newE->addMeshVertex(newMv);
+      }
+      for (unsigned int i = 0; i < eTmp->getNumMeshElements();i++){
+        MElement* elem = eTmp->getMeshElement(i);
+        MVertex *firstETmp = VertexAssociation.find(elem->getVertex(0))->second;
+        MVertex *lastETmp = VertexAssociation.find(elem->getVertex(1))->second;
+        MVertex *midETmp = VertexAssociation.find(elem->getVertex(2))->second;
+        MLine3 *newLine = new MLine3(firstETmp,lastETmp,midETmp);
+        newE->addLine(newLine);
+      }
+      GEdgeGlobalAssociation[std::make_pair(eTmp,rTmp)] = newE;
+    }
+  }
+  int counterNbDone = 10000;
+  //maintenant on va traiter les faces initiales
+  for (std::set<GEdge*>::iterator itf = ToDuplicateList.begin();itf != ToDuplicateList.end();itf++){
+    counterNbDone++;
+    GEdge* eTmp = (*itf);
+    std::list<GFace*> listFacesTmpT = eTmp->faces();
+    std::list<GFace*>::iterator itTmpFace = listFacesTmpT.begin();
+    GFace* fac1 = (*itTmpFace);
+    itTmpFace++;
+    GFace* fac2 = (*itTmpFace);
+    //pour commencer on cree des aretes entre les vertex
+    //		std::list<GVertex*> vlist = eTmp->vertices();
+    std::list<GVertex*> vlist;
+    vlist.push_back(eTmp->getBeginVertex());
+    vlist.push_back(eTmp->getEndVertex());
+    std::map<GVertex*,GEdge* > SurroudingEdges;
+    for (std::list<GVertex*>::iterator itv = vlist.begin();itv != vlist.end();itv++){
+      GVertex* vTmp = (*itv);
+      GVertex* v1=0;
+      GVertex* v2=0;
+      std::map<std::pair<GVertex*,GFace*>,GVertex* >::iterator itMap = GVertexGlobalAssociation.find(std::make_pair(vTmp,fac1));
+      if (itMap != GVertexGlobalAssociation.end()){
+        v1 = itMap->second;
+      }
+      itMap = GVertexGlobalAssociation.find(std::make_pair(vTmp,fac2));
+      if (itMap != GVertexGlobalAssociation.end()){
+        v2 = itMap->second;
+      }
+      GEdge* newE = m->addLine(v1,v2);
+      SurroudingEdges[vTmp] = newE;
+    }
+    //ici tous les vertex sont traites
+    //on va traiter les edges
+    //		std::list<GEdge*> elist = fTmp->edges();
+    std::vector<GEdge*> newEdgesVector;
+    std::vector<GFace*> SurroundingsFaces;
+    //duplication Gedge
+    //			GEdge* eTmp = (*ite);
+    GEdge* e1=0;
+    GEdge* e2=0;
+    std::map<std::pair<GEdge*,GFace*>,GEdge* >::iterator itMap = GEdgeGlobalAssociation.find(std::make_pair(eTmp,fac1));
+    if (itMap != GEdgeGlobalAssociation.end()){
+      e1 = itMap->second;
+    }
+    itMap = GEdgeGlobalAssociation.find(std::make_pair(eTmp,fac2));
+    if (itMap != GEdgeGlobalAssociation.end()){
+      e2 = itMap->second;
+    }
+    //creation des GFace correspondantes
+    GEdge* firstE = SurroudingEdges.find(eTmp->getBeginVertex())->second;
+    GEdge* lastE = SurroudingEdges.find(eTmp->getEndVertex())->second;
+    if (firstE->getBeginVertex() != e1->getEndVertex()){
+      firstE->reverse();
+    }
+    if (firstE->getBeginVertex() != e1->getEndVertex()){
+      e1->reverse();
+    }
+    if (firstE->getBeginVertex() != e1->getEndVertex()){
+      firstE->reverse();
+    }
+    if (e2->getBeginVertex() != firstE->getEndVertex()){
+      e2->reverse();
+    }
+    if (lastE->getBeginVertex() != e2->getEndVertex()){
+      lastE->reverse();
+    }
+    std::vector<GEdge*> VecEdgesTmp;
+    VecEdgesTmp.push_back(e1);
+    VecEdgesTmp.push_back(firstE);
+    VecEdgesTmp.push_back(e2);
+    VecEdgesTmp.push_back(lastE);
+    std::vector<std::vector<GEdge*> > VecOfVecTmp;
+    VecOfVecTmp.push_back(VecEdgesTmp);
+    GFace* newFaceTmp = m->addPlanarFace(VecOfVecTmp);
+    //			SurroundingsFaces.push_back(newFaceTmp);
+
+    //creation de la nouvelle region
+    //		GRegion* createdRegion = new GRegion(m,counterNbDone);
+    newFaceTmp->addPhysicalEntity(PhysicalInterface);
+    //		createdRegion->set(listFaces);
+    //		m->add(createdRegion);
+    for (unsigned int i = 0; i < eTmp->getNumMeshElements();i++){
+      MElement* elem = eTmp->getMeshElement(i);
+      MVertex* v1=0;
+      MVertex* v2=0;
+      MVertex* v3=0;
+      MVertex* v4=0;
+      //MVertex* v5;
+      //MVertex* v6;
+      std::map<std::pair<MVertex*,GFace*>,MVertex* >::iterator itMap = VertexGlobalAssociation.find(std::make_pair(elem->getVertex(0),fac1));
+      if (itMap != VertexGlobalAssociation.end()){
+        v1 = itMap->second;
+      }
+      itMap = VertexGlobalAssociation.find(std::make_pair(elem->getVertex(2),fac1));
+      if (itMap != VertexGlobalAssociation.end()){
+        v2 = itMap->second;
+      }
+      itMap = VertexGlobalAssociation.find(std::make_pair(elem->getVertex(2),fac2));
+      if (itMap != VertexGlobalAssociation.end()){
+        v3 = itMap->second;
+      }
+      itMap = VertexGlobalAssociation.find(std::make_pair(elem->getVertex(0),fac2));
+      if (itMap != VertexGlobalAssociation.end()){
+        v4 = itMap->second;
+      }
+      //			itMap = VertexGlobalAssociation.find(std::make_pair(elem->getVertex(3),fac2));
+      //			if (itMap != VertexGlobalAssociation.end()){
+      //				v5 = itMap->second;
+      //			}
+      //			itMap = VertexGlobalAssociation.find(std::make_pair(elem->getVertex(5),fac2));
+      //			if (itMap != VertexGlobalAssociation.end()){
+      //				v6 = itMap->second;
+      //			}
+      MQuadrangle *newQua = new MQuadrangle(v1,v2,v3,v4);
+
+      newFaceTmp->addQuadrangle(newQua);
+
+      //second
+      itMap = VertexGlobalAssociation.find(std::make_pair(elem->getVertex(2),fac1));
+      if (itMap != VertexGlobalAssociation.end()){
+        v1 = itMap->second;
+      }
+      itMap = VertexGlobalAssociation.find(std::make_pair(elem->getVertex(1),fac1));
+      if (itMap != VertexGlobalAssociation.end()){
+        v2 = itMap->second;
+      }
+      itMap = VertexGlobalAssociation.find(std::make_pair(elem->getVertex(1),fac2));
+      if (itMap != VertexGlobalAssociation.end()){
+        v3 = itMap->second;
+      }
+      itMap = VertexGlobalAssociation.find(std::make_pair(elem->getVertex(2),fac2));
+      if (itMap != VertexGlobalAssociation.end()){
+        v4 = itMap->second;
+      }
+      //			itMap = VertexGlobalAssociation.find(std::make_pair(elem->getVertex(3),fac2));
+      //			if (itMap != VertexGlobalAssociation.end()){
+      //				v5 = itMap->second;
+      //			}
+      //			itMap = VertexGlobalAssociation.find(std::make_pair(elem->getVertex(5),fac2));
+      //			if (itMap != VertexGlobalAssociation.end()){
+      //				v6 = itMap->second;
+      //			}
+      MQuadrangle *newQua2 = new MQuadrangle(v1,v2,v3,v4);
+
+      newFaceTmp->addQuadrangle(newQua2);
+
+
+
+
+    }
+    for (unsigned int i = 0; i < fac1->getNumMeshElements();i++){
+      MElement* elem = fac1->getMeshElement(i);
+      for (int j = 0;j < elem->getNumVertices();j++){
+        MVertex* vert = elem->getVertex(j);
+        std::map<std::pair<MVertex*,GFace*>,MVertex* >::iterator itMap = VertexGlobalAssociation.find(std::make_pair(vert,fac1));
+        if (itMap != VertexGlobalAssociation.end()){
+          elem->setVertex(j,itMap->second);
+        }
+      }
+    }
+    for (unsigned int i = 0; i < fac2->getNumMeshElements();i++){
+      MElement* elem = fac2->getMeshElement(i);
+      for (int j = 0;j < elem->getNumVertices();j++){
+        MVertex* vert = elem->getVertex(j);
+        std::map<std::pair<MVertex*,GFace*>,MVertex* >::iterator itMap = VertexGlobalAssociation.find(std::make_pair(vert,fac2));
+        if (itMap != VertexGlobalAssociation.end()){
+          elem->setVertex(j,itMap->second);
+        }
+      }
+    }
+  }
+  //maintenant on va traiter les faces du bord
+  //	std::ofstream file("MicrostructurePolycrystal3D.pos");
+  //	file << "View \"test\" {\n";
+  //
+  //	std::ofstream file2("PERIODIC.map");
+  //	std::ofstream file3("SetAdd.map");
+  //	for (std::vector<std::pair<GFace*,GFace*> >::iterator itP = pairs.begin();itP != pairs.end();itP++){
+  //		std::pair<GFace*,GFace*> pairTmp = (*itP);
+  //		GFace* ToReplaceFace = pairTmp.second;
+  //		GRegion* rTmp = ToReplaceFace->getRegion(0);
+  //		std::map<std::pair<GFace*,GRegion*>,GFace* >::iterator itMap = GFaceGlobalAssociation.find(std::make_pair(ToReplaceFace,rTmp));
+  //		if (itMap != GFaceGlobalAssociation.end()){
+  //			GFace* associatedFace = (*itMap).second;
+  //
+  //
+  //
+  //
+  //
+  //			file3 <<associatedFace->tag()<<"\tSURFACE"<<associatedFace->tag()<<"\tNSET "<<"\n";
+  //
+  //			int tagTmp = associatedFace->tag();
+  //			std::ostringstream ss;
+  //			ss << tagTmp;
+  ////			char *intStr = itoa(tagTmp);
+  //			std::string nameSurf = "SURFACE";
+  ////			nameSurf += std::string(intStr);
+  //			nameSurf += ss.str();
+  //			int PhysicalSurfaceTmp = m->setPhysicalName(nameSurf,2);
+  //			associatedFace->addPhysicalEntity(PhysicalSurfaceTmp);
+  //
+  //			std::map<GFace*,SPoint3>::iterator it3 = centers.find(pairTmp.first);
+  //			std::map<GFace*,SPoint3>::iterator it4 = centers.find(ToReplaceFace);
+  //
+  //			SPoint3 p1 = it3->second;
+  //			SPoint3  p2 = it4->second;
+  //
+  //			double delta_x = fabs(p2.x()-p1.x());
+  //			double delta_y = fabs(p2.y()-p1.y());
+  //			double delta_z = fabs(p2.z()-p1.z());
+  //
+  //
+  //			file << "SL ("
+  //					<< p1.x() << ", " << p1.y() << ", " << p1.z() << ", "
+  //					<< p2.x() << ", " << p2.y() << ", " << p2.z()
+  //					<< "){10, 20};\n";
+  //
+  //			//file2 << "PERIODIC\tSURFACE"<<faces[i]->tag() << "\tSURFACE" << faces[j]->tag() << "\t" << p2.x()-p1.x() << "\t" << p2.y()-p1.y() << "\t" << p2.z()-p1.z() << "\n";
+  //			if (abs((p2.x()-p1.x()-1.0))<0.0001){
+  //				if (abs((p2.y()-p1.y()))<0.0001){
+  //					if (abs((p2.z()-p1.z()))<0.0001){
+  //						file2 << "NSET\tFRONT = FRONT + SURFACE"<<associatedFace->tag()<<"\n";
+  //						file2 << "NSET\tBACK = BACK + SURFACE"<<pairTmp.first->tag()<<"\n";
+  //					}else if(abs((p2.z()-p1.z()-1.0))<0.0001){
+  //						file2 << "NSET\tFRONTTOP = FRONTTOP + SURFACE"<<associatedFace->tag()<<"\n";
+  //						file2 << "NSET\tBACKBOTTOM = BACKBOTTOM + SURFACE"<<pairTmp.first->tag()<<"\n";
+  //					}else if (abs((p1.z()-p2.z()-1.0))<0.0001){
+  //						file2 << "NSET\tFRONTBOTTOM = FRONTBOTTOM + SURFACE"<<associatedFace->tag()<<"\n";
+  //						file2 << "NSET\tBACKTOP = BACKTOP + SURFACE"<<pairTmp.first->tag()<<"\n";
+  //					}
+  //				}else if (abs((p2.y()-p1.y()-1.0))<0.0001){
+  //					if (abs((p2.z()-p1.z()))<0.0001){
+  //						file2 << "NSET\tFRONTRIGHT = FRONTRIGHT + SURFACE"<<associatedFace->tag()<<"\n";
+  //						file2 << "NSET\tBACKLEFT = BACKLEFT + SURFACE"<<pairTmp.first->tag()<<"\n";
+  //					}else if (abs((p2.z()-p1.z()-1.0))<0.0001){
+  //						file2 << "NSET\tFRONTRIGHTTOP = FRONTRIGHTTOP + SURFACE"<<associatedFace->tag()<<"\n";
+  //						file2 << "NSET\tBACKLEFTBOTTOM = BACKLEFTBOTTOM + SURFACE"<<pairTmp.first->tag()<<"\n";
+  //					}else if (abs((p1.z()-p2.z()-1.0))<0.0001){
+  //						file2 << "NSET\tFRONTRIGHTBOTTOM = FRONTRIGHTBOTTOM + SURFACE"<<associatedFace->tag()<<"\n";
+  //						file2 << "NSET\tBACKLEFTTOP = BACKLEFTTOP + SURFACE"<<pairTmp.first->tag()<<"\n";
+  //					}
+  //				}else if (abs((p1.y()-p2.y()-1.0))<0.0001){
+  //					if (abs((p2.z()-p1.z()))<0.0001){
+  //						file2 << "NSET\tFRONTLEFT = FRONTLEFT + SURFACE"<<associatedFace->tag()<<"\n";
+  //						file2 << "NSET\tBACKRIGHT = BACKRIGHT + SURFACE"<<pairTmp.first->tag()<<"\n";
+  //					}else if (abs((p2.z()-p1.z()-1.0))<0.0001){
+  //						file2 << "NSET\tFRONTLEFTTOP = FRONTLEFTTOP + SURFACE"<<associatedFace->tag()<<"\n";
+  //						file2 << "NSET\tBACKRIGHTBOTTOM = BACKRIGHTBOTTOM + SURFACE"<<pairTmp.first->tag()<<"\n";
+  //					}else if (abs((p1.z()-p2.z()-1.0))<0.0001){
+  //						file2 << "NSET\tFRONTLEFTBOTTOM = FRONTLEFTBOTTOM + SURFACE"<<associatedFace->tag()<<"\n";
+  //						file2 << "NSET\tBACKRIGHTTOP = BACKRIGHTTOP + SURFACE"<<pairTmp.first->tag()<<"\n";
+  //					}
+  //				}
+  //			}else if (abs((p1.x()-p2.x()-1.0))<0.0001){
+  //				if (abs((p2.y()-p1.y()))<0.0001){
+  //					if (abs((p2.z()-p1.z()))<0.0001){
+  //						file2 << "NSET\tFRONT = FRONT + SURFACE"<<pairTmp.first->tag()<<"\n";
+  //						file2 << "NSET\tBACK = BACK + SURFACE"<<associatedFace->tag()<<"\n";
+  //					}else if(abs((p2.z()-p1.z()-1.0))<0.0001){
+  //						file2 << "NSET\tFRONTBOTTOM = FRONTBOTTOM + SURFACE"<<pairTmp.first->tag()<<"\n";
+  //						file2 << "NSET\tBACKTOP = BACKTOP + SURFACE"<<associatedFace->tag()<<"\n";
+  //					}else if (abs((p1.z()-p2.z()-1.0))<0.0001){
+  //						file2 << "NSET\tFRONTTOP = FRONTTOP + SURFACE"<<pairTmp.first->tag()<<"\n";
+  //						file2 << "NSET\tBACKBOTTOM = BACKBOTTOM + SURFACE"<<associatedFace->tag()<<"\n";
+  //					}
+  //				}else if (abs((p2.y()-p1.y()-1.0))<0.0001){
+  //					if (abs((p2.z()-p1.z()))<0.0001){
+  //						file2 << "NSET\tFRONTLEFT = FRONTLEFT + SURFACE"<<pairTmp.first->tag()<<"\n";
+  //						file2 << "NSET\tBACKRIGHT = BACKRIGHT + SURFACE"<<associatedFace->tag()<<"\n";
+  //					}else if (abs((p2.z()-p1.z()-1.0))<0.0001){
+  //						file2 << "NSET\tFRONTLEFTBOTTOM = FRONTLEFTBOTTOM + SURFACE"<<pairTmp.first->tag()<<"\n";
+  //						file2 << "NSET\tBACKRIGHTTOP = BACKRIGHTTOP + SURFACE"<<associatedFace->tag()<<"\n";
+  //					}else if (abs((p1.z()-p2.z()-1.0))<0.0001){
+  //						file2 << "NSET\tFRONTLEFTTOP = FRONTLEFTTOP + SURFACE"<<pairTmp.first->tag()<<"\n";
+  //						file2 << "NSET\tBACKRIGHTBOTTOM = BACKRIGHTBOTTOM + SURFACE"<<associatedFace->tag()<<"\n";
+  //					}
+  //				}else if (abs((p1.y()-p2.y()-1.0))<0.0001){
+  //					if (abs((p2.z()-p1.z()))<0.0001){
+  //						file2 << "NSET\tFRONTRIGHT = FRONTRIGHT + SURFACE"<<pairTmp.first->tag()<<"\n";
+  //						file2 << "NSET\tBACKLEFT = BACKLEFT + SURFACE"<<associatedFace->tag()<<"\n";
+  //					}else if (abs((p2.z()-p1.z()-1.0))<0.0001){
+  //						file2 << "NSET\tFRONTRIGHTBOTTOM = FRONTRIGHTBOTTOM + SURFACE"<<pairTmp.first->tag()<<"\n";
+  //						file2 << "NSET\tBACKLEFTTOP = BACKLEFTTOP + SURFACE"<<associatedFace->tag()<<"\n";
+  //					}else if (abs((p1.z()-p2.z()-1.0))<0.0001){
+  //						file2 << "NSET\tFRONTRIGHTTOP = FRONTRIGHTTOP + SURFACE"<<pairTmp.first->tag()<<"\n";
+  //						file2 << "NSET\tBACKLEFTBOTTOM = BACKLEFTBOTTOM + SURFACE"<<associatedFace->tag()<<"\n";
+  //					}
+  //				}
+  //			}else if (abs((p1.x()-p2.x()))<0.0001){
+  //				if (abs((p2.y()-p1.y()-1.0))<0.0001){
+  //					if (abs((p2.z()-p1.z()))<0.0001){
+  //						file2 << "NSET\tRIGHT = RIGHT + SURFACE"<<associatedFace->tag()<<"\n";
+  //						file2 << "NSET\tLEFT = LEFT + SURFACE"<<pairTmp.first->tag()<<"\n";
+  //					}else if (abs((p2.z()-p1.z()-1.0))<0.0001){
+  //						file2 << "NSET\tRIGHTTOP = RIGHTTOP + SURFACE"<<associatedFace->tag()<<"\n";
+  //						file2 << "NSET\tLEFTBOTTOM = LEFTBOTTOM + SURFACE"<<pairTmp.first->tag()<<"\n";
+  //					}else if (abs((p1.z()-p2.z()-1.0))<0.0001){
+  //						file2 << "NSET\tRIGHTBOTTOM = RIGHTBOTTOM + SURFACE"<<associatedFace->tag()<<"\n";
+  //						file2 << "NSET\tLEFTTOP = LEFTTOP + SURFACE"<<pairTmp.first->tag()<<"\n";
+  //					}
+  //				}else if (abs((p1.y()-p2.y()-1.0))<0.0001){
+  //					if (abs((p2.z()-p1.z()))<0.0001){
+  //						file2 << "NSET\tRIGHT = RIGHT + SURFACE"<<pairTmp.first->tag()<<"\n";
+  //						file2 << "NSET\tLEFT = LEFT + SURFACE"<<associatedFace->tag()<<"\n";
+  //					}else if (abs((p2.z()-p1.z()-1.0))<0.0001){
+  //						file2 << "NSET\tRIGHTBOTTOM = RIGHTBOTTOM + SURFACE"<<pairTmp.first->tag()<<"\n";
+  //						file2 << "NSET\tLEFTTOP = LEFTTOP + SURFACE"<<associatedFace->tag()<<"\n";
+  //					}else if (abs((p1.z()-p2.z()-1.0))<0.0001){
+  //						file2 << "NSET\tRIGHTTOP = RIGHTTOP + SURFACE"<<pairTmp.first->tag()<<"\n";
+  //						file2 << "NSET\tLEFTBOTTOM = LEFTBOTTOM + SURFACE"<<associatedFace->tag()<<"\n";
+  //					}
+  //				}else if (abs((p1.y()-p2.y()))<0.0001){
+  //					if (abs((p2.z()-p1.z()-1.0))<0.0001){
+  //						file2 << "NSET\tTOP = TOP + SURFACE"<<associatedFace->tag()<<"\n";
+  //						file2 << "NSET\tBOTTOM = BOTTOM + SURFACE"<<pairTmp.first->tag()<<"\n";
+  //					}else if (abs((p1.z()-p2.z()-1.0))<0.0001){
+  //						file2 << "NSET\tTOP = TOP + SURFACE"<<pairTmp.first->tag()<<"\n";
+  //						file2 << "NSET\tBOTTOM = BOTTOM + SURFACE"<<associatedFace->tag()<<"\n";
+  //					}
+  //				}
+  //			}
+  ////			count++;
+  //
+  //
+  //
+  //
+  //
+  //
+  //
+  //			newPairs.push_back(std::make_pair(pairTmp.first,associatedFace));
+  //		}
+  //	}
+  //	for (std::vector<std::pair<GFace*,GFace*> >::iterator itP = newPairs.begin();itP != newPairs.end();itP++){
+  //		std::pair<GFace*,GFace*> pairTmp = (*itP);
+  //	}
+
+  std::cout<<"End of DuplicateBoundaries"<<std::endl;
+  return view;
 }
 
 
@@ -2921,427 +2913,29 @@ PView *GMSH_DuplicateBoundariesPlugin::execute2D(PView *view)
 
 PView *GMSH_DuplicateBoundariesPlugin::execute2DWithBound(PView *view)
 {
-	std::cout<<"starting DuplicateBoundaries"<<std::endl;
-	GModel *m = GModel::current();
-	m->setFactory("geo");
-	std::set<GEdge*> ToDuplicateList;
-	ToDuplicateList.clear();
-	std::set<GEdge*> ToDuplicateListBoundary;
-	ToDuplicateListBoundary.clear();
-	std::vector<GFace*> facesBound;
-	facesBound.clear();
-	std::map<GFace*,SPoint3> centers;
-	std::vector<std::pair<GFace*,GFace*> > pairs;
-	std::vector<std::pair<GFace*,GFace*> > newPairs;
-	int PhysicalInterface = m->setPhysicalName("Interface",2);
-
-	for (GModel::eiter ite= m->firstEdge();ite != m->lastEdge();ite++){
-		GEdge* eTmp = (*ite);
-		if (eTmp->faces().size() == 2){
-			ToDuplicateList.insert(eTmp);
-		}
-		else{
-			ToDuplicateListBoundary.insert(eTmp);
-		}
-	}
-
-
-
-
-
-
-
-
-
-
-	std::map<std::pair<MVertex*,GFace*>,MVertex* > VertexGlobalAssociation;
-	std::map<std::pair<GVertex*,GFace*>,GVertex* > GVertexGlobalAssociation;
-	std::map<std::pair<GEdge*,GFace*>,GEdge* > GEdgeGlobalAssociation;
-	std::map<std::pair<GFace*,GRegion*>,GFace* > GFaceGlobalAssociation;
-	for (GModel::fiter itr= m->firstFace();itr != m->lastFace();itr++){
-		GFace* rTmp = (*itr);
-		std::list<GEdge*> RegEdges = rTmp->edges();
-		std::map<MVertex*,MVertex* > VertexAssociation;
-		std::map<GVertex*,GVertex* > GVertexAssociation;
-		std::map<GEdge*,GEdge* > GEdgeAssociation;
-		//int counterNbDone = 10000;
-		double xCenterReg = 0.0;
-		double yCenterReg = 0.0;
-		double zCenterReg = 0.0;
-		int counterPts = 0;
-		for(std::list<GEdge*>::iterator it2=RegEdges.begin();it2!=RegEdges.end();it2++){
-			GEdge* fTemp = (*it2);
-			std::list<GVertex*> verticesFace = fTemp->vertices();
-			for (std::list<GVertex*>::iterator it3=verticesFace.begin();it3!=verticesFace.end();it3++){
-				xCenterReg = xCenterReg + (*it3)->x();
-				yCenterReg = yCenterReg + (*it3)->y();
-				zCenterReg = zCenterReg + (*it3)->z();
-				counterPts++;
-			}
-		}
-		xCenterReg = xCenterReg/counterPts;
-		yCenterReg = yCenterReg/counterPts;
-		zCenterReg = zCenterReg/counterPts;
-		//duplication noeud et aretes au niveau de la region directement
-		std::list<GVertex*> vlist;
-
-
-		std::list<GEdge*> listedgesTmp = rTmp->edges();
-		for (std::list<GEdge*>::iterator itTp = listedgesTmp.begin();itTp != listedgesTmp.end();itTp++){
-			std::list<GVertex*> vlist2;
-			if(std::find(vlist.begin(), vlist.end(),(*itTp)->getBeginVertex()) == vlist.end())
-				vlist.push_back((*itTp)->getBeginVertex());
-			if(std::find(vlist.begin(), vlist.end(),(*itTp)->getEndVertex()) == vlist.end())
-				vlist.push_back((*itTp)->getEndVertex());
-		}
-
-
-		for (std::list<GVertex*>::iterator itv = vlist.begin();itv != vlist.end();itv++){
-			//duplication Gvertex
-			GVertex* vTmp = (*itv);
-			double ponderatedX = 0.99999999999 * vTmp->x() + 0.00000000001 * xCenterReg;
-			double ponderatedY = 0.99999999999 * vTmp->y() + 0.00000000001 * yCenterReg;
-			double ponderatedZ = 0.99999999999 * vTmp->z() + 0.00000000001 * zCenterReg;
-			GVertex* newv = m->addVertex(ponderatedX,ponderatedY,ponderatedZ,vTmp->prescribedMeshSizeAtVertex());
-			GVertexAssociation[vTmp] = newv;
-			GVertexGlobalAssociation[std::make_pair(vTmp,rTmp)] = newv;
-			//creation des Gedge correspondantes
-//			GEdge* newE = m->addLine(vTmp,newv);
-//			SurroudingEdges[vTmp] = newE;
-			//maintenant traitement mesh
-			MVertex *vMesh = vTmp->mesh_vertices[0];
-			MVertex *newMv = new MVertex(vMesh->x(), vMesh->y(), vMesh->z(), (GEntity*)newv);
-			VertexAssociation[vMesh] = newMv;
-			VertexGlobalAssociation[std::make_pair(vMesh,rTmp)] = newMv;
-			newv->addMeshVertex(newMv);
-		}
-		//maintenant on soccupe de duppliquer les edges de la region
-		std::list<GEdge*> elist = rTmp->edges();
-
-		std::vector<GFace*> SurroundingsFaces;
-		for (std::list<GEdge*>::iterator itf = RegEdges.begin();itf != RegEdges.end();itf++){
-			GEdge* eTmp = (*itf);
-			GEdge* newE = m->addLine(GVertexAssociation[eTmp->getBeginVertex()],GVertexAssociation[eTmp->getEndVertex()]);
-			for (unsigned int i = 0; i < eTmp->mesh_vertices.size();i++){
-				MVertex *vMesh = eTmp->mesh_vertices[i];
-				MVertex *newMv = new MVertex(vMesh->x(), vMesh->y(), vMesh->z(), (GEntity*)newE);
-				VertexAssociation[vMesh] = newMv;
-				VertexGlobalAssociation[std::make_pair(vMesh,rTmp)] = newMv;
-				newE->addMeshVertex(newMv);
-			}
-			for (unsigned int i = 0; i < eTmp->getNumMeshElements();i++){
-				MElement* elem = eTmp->getMeshElement(i);
-				MVertex *firstETmp = VertexAssociation.find(elem->getVertex(0))->second;
-				MVertex *lastETmp = VertexAssociation.find(elem->getVertex(1))->second;
-				MVertex *midETmp = VertexAssociation.find(elem->getVertex(2))->second;
-				MLine3 *newLine = new MLine3(firstETmp,lastETmp,midETmp);
-				newE->addLine(newLine);
-			}
-			GEdgeGlobalAssociation[std::make_pair(eTmp,rTmp)] = newE;
-		}
-	}
-	int counterNbDone = 10000;
-	//maintenant on va traiter les faces initiales
-	for (std::set<GEdge*>::iterator itf = ToDuplicateList.begin();itf != ToDuplicateList.end();itf++){
-		counterNbDone++;
-		GEdge* eTmp = (*itf);
-		std::list<GFace*> listFacesTmpT = eTmp->faces();
-		std::list<GFace*>::iterator itTmpFace = listFacesTmpT.begin();
-		GFace* fac1 = (*itTmpFace);
-		itTmpFace++;
-		GFace* fac2 = (*itTmpFace);
-		//pour commencer on cree des aretes entre les vertex
-//		std::list<GVertex*> vlist = eTmp->vertices();
-		std::list<GVertex*> vlist;
-		vlist.push_back(eTmp->getBeginVertex());
-		vlist.push_back(eTmp->getEndVertex());
-		std::map<GVertex*,GEdge* > SurroudingEdges;
-		for (std::list<GVertex*>::iterator itv = vlist.begin();itv != vlist.end();itv++){
-			GVertex* vTmp = (*itv);
-			GVertex* v1=0;
-			GVertex* v2=0;
-			std::map<std::pair<GVertex*,GFace*>,GVertex* >::iterator itMap = GVertexGlobalAssociation.find(std::make_pair(vTmp,fac1));
-			if (itMap != GVertexGlobalAssociation.end()){
-				v1 = itMap->second;
-			}
-			itMap = GVertexGlobalAssociation.find(std::make_pair(vTmp,fac2));
-			if (itMap != GVertexGlobalAssociation.end()){
-				v2 = itMap->second;
-			}
-			GEdge* newE = m->addLine(v1,v2);
-			SurroudingEdges[vTmp] = newE;
-		}
-		//ici tous les vertex sont traites
-		//on va traiter les edges
-		std::vector<GEdge*> newEdgesVector;
-		std::vector<GFace*> SurroundingsFaces;
-		//duplication Gedge
-		//			GEdge* eTmp = (*ite);
-		GEdge* e1=0;
-		GEdge* e2=0;
-		std::map<std::pair<GEdge*,GFace*>,GEdge* >::iterator itMap = GEdgeGlobalAssociation.find(std::make_pair(eTmp,fac1));
-		if (itMap != GEdgeGlobalAssociation.end()){
-			e1 = itMap->second;
-		}
-		itMap = GEdgeGlobalAssociation.find(std::make_pair(eTmp,fac2));
-		if (itMap != GEdgeGlobalAssociation.end()){
-			e2 = itMap->second;
-		}
-		//creation des GFace correspondantes
-		GEdge* firstE = SurroudingEdges.find(eTmp->getBeginVertex())->second;
-		GEdge* lastE = SurroudingEdges.find(eTmp->getEndVertex())->second;
-		if (firstE->getBeginVertex() != e1->getEndVertex()){
-			firstE->reverse();
-		}
-		if (firstE->getBeginVertex() != e1->getEndVertex()){
-			e1->reverse();
-		}
-		if (firstE->getBeginVertex() != e1->getEndVertex()){
-			firstE->reverse();
-		}
-		if (e2->getBeginVertex() != firstE->getEndVertex()){
-			e2->reverse();
-		}
-		if (lastE->getBeginVertex() != e2->getEndVertex()){
-			lastE->reverse();
-		}
-		std::vector<GEdge*> VecEdgesTmp;
-		VecEdgesTmp.push_back(e1);
-		VecEdgesTmp.push_back(firstE);
-		VecEdgesTmp.push_back(e2);
-		VecEdgesTmp.push_back(lastE);
-		std::vector<std::vector<GEdge*> > VecOfVecTmp;
-		VecOfVecTmp.push_back(VecEdgesTmp);
-		GFace* newFaceTmp = m->addPlanarFace(VecOfVecTmp);
-		//			SurroundingsFaces.push_back(newFaceTmp);
-
-		//creation de la nouvelle region
-//		GRegion* createdRegion = new GRegion(m,counterNbDone);
-		newFaceTmp->addPhysicalEntity(PhysicalInterface);
-//		createdRegion->set(listFaces);
-//		m->add(createdRegion);
-		for (unsigned int i = 0; i < eTmp->getNumMeshElements();i++){
-			MElement* elem = eTmp->getMeshElement(i);
-			MVertex* v1=0;
-			MVertex* v2=0;
-			MVertex* v3=0;
-			MVertex* v4=0;
-			//MVertex* v5;
-			//MVertex* v6;
-			std::map<std::pair<MVertex*,GFace*>,MVertex* >::iterator itMap = VertexGlobalAssociation.find(std::make_pair(elem->getVertex(0),fac1));
-			if (itMap != VertexGlobalAssociation.end()){
-				v1 = itMap->second;
-			}
-			itMap = VertexGlobalAssociation.find(std::make_pair(elem->getVertex(2),fac1));
-			if (itMap != VertexGlobalAssociation.end()){
-				v2 = itMap->second;
-			}
-			itMap = VertexGlobalAssociation.find(std::make_pair(elem->getVertex(2),fac2));
-			if (itMap != VertexGlobalAssociation.end()){
-				v3 = itMap->second;
-			}
-			itMap = VertexGlobalAssociation.find(std::make_pair(elem->getVertex(0),fac2));
-			if (itMap != VertexGlobalAssociation.end()){
-				v4 = itMap->second;
-			}
-//			itMap = VertexGlobalAssociation.find(std::make_pair(elem->getVertex(3),fac2));
-//			if (itMap != VertexGlobalAssociation.end()){
-//				v5 = itMap->second;
-//			}
-//			itMap = VertexGlobalAssociation.find(std::make_pair(elem->getVertex(5),fac2));
-//			if (itMap != VertexGlobalAssociation.end()){
-//				v6 = itMap->second;
-//			}
-			MQuadrangle *newQua = new MQuadrangle(v1,v2,v3,v4);
-
-			newFaceTmp->addQuadrangle(newQua);
-
-			//second
-			itMap = VertexGlobalAssociation.find(std::make_pair(elem->getVertex(2),fac1));
-			if (itMap != VertexGlobalAssociation.end()){
-				v1 = itMap->second;
-			}
-			itMap = VertexGlobalAssociation.find(std::make_pair(elem->getVertex(1),fac1));
-			if (itMap != VertexGlobalAssociation.end()){
-				v2 = itMap->second;
-			}
-			itMap = VertexGlobalAssociation.find(std::make_pair(elem->getVertex(1),fac2));
-			if (itMap != VertexGlobalAssociation.end()){
-				v3 = itMap->second;
-			}
-			itMap = VertexGlobalAssociation.find(std::make_pair(elem->getVertex(2),fac2));
-			if (itMap != VertexGlobalAssociation.end()){
-				v4 = itMap->second;
-			}
-			//			itMap = VertexGlobalAssociation.find(std::make_pair(elem->getVertex(3),fac2));
-			//			if (itMap != VertexGlobalAssociation.end()){
-			//				v5 = itMap->second;
-			//			}
-			//			itMap = VertexGlobalAssociation.find(std::make_pair(elem->getVertex(5),fac2));
-			//			if (itMap != VertexGlobalAssociation.end()){
-			//				v6 = itMap->second;
-			//			}
-			MQuadrangle *newQua2 = new MQuadrangle(v1,v2,v3,v4);
-
-			newFaceTmp->addQuadrangle(newQua2);
-
-
-
-
-		}
-		for (unsigned int i = 0; i < fac1->getNumMeshElements();i++){
-			MElement* elem = fac1->getMeshElement(i);
-			for (int j = 0;j < elem->getNumVertices();j++){
-				MVertex* vert = elem->getVertex(j);
-				std::map<std::pair<MVertex*,GFace*>,MVertex* >::iterator itMap = VertexGlobalAssociation.find(std::make_pair(vert,fac1));
-				if (itMap != VertexGlobalAssociation.end()){
-					elem->setVertex(j,itMap->second);
-				}
-			}
-		}
-		for (unsigned int i = 0; i < fac2->getNumMeshElements();i++){
-			MElement* elem = fac2->getMeshElement(i);
-			for (int j = 0;j < elem->getNumVertices();j++){
-				MVertex* vert = elem->getVertex(j);
-				std::map<std::pair<MVertex*,GFace*>,MVertex* >::iterator itMap = VertexGlobalAssociation.find(std::make_pair(vert,fac2));
-				if (itMap != VertexGlobalAssociation.end()){
-					elem->setVertex(j,itMap->second);
-				}
-			}
-		}
-	}
-
-
-
-
-
-
-
-
-	//maintenant on va traiter les faces du bord
-	for (std::set<GEdge*>::iterator itf = ToDuplicateListBoundary.begin();itf != ToDuplicateListBoundary.end();itf++){
-		counterNbDone++;
-		GEdge* eTmp = (*itf);
-		std::list<GFace*> listFacesTmpT = eTmp->faces();
-		std::list<GFace*>::iterator itTmpFace = listFacesTmpT.begin();
-		GFace* fac1 = (*itTmpFace);
-//		GFace* reg1 = fTmp->getRegion(0);
-		//pour commencer on cree des aretes entre les vertex
-		std::list<GVertex*> vlist;
-		vlist.push_back(eTmp->getBeginVertex());
-		vlist.push_back(eTmp->getEndVertex());
-		std::map<GVertex*,GEdge* > SurroudingEdges;
-		for (std::list<GVertex*>::iterator itv = vlist.begin();itv != vlist.end();itv++){
-			GVertex* vTmp = (*itv);
-			GVertex* v1=0;
-			std::map<std::pair<GVertex*,GFace*>,GVertex* >::iterator itMap = GVertexGlobalAssociation.find(std::make_pair(vTmp,fac1));
-			if (itMap != GVertexGlobalAssociation.end()){
-				v1 = itMap->second;
-			}
-			GEdge* newE = m->addLine(v1,vTmp);
-			SurroudingEdges[vTmp] = newE;
-		}
-		//ici tous les vertex sont traites
-		//on va traiter les edges
-//		std::list<GEdge*> elist = fTmp->edges();
-		std::vector<GEdge*> newEdgesVector;
-		std::vector<GFace*> SurroundingsFaces;
-//		for (std::list<GEdge*>::iterator ite = elist.begin();ite != elist.end();ite++){
-		//duplication Gedge
-		//			GEdge* eTmp = (*ite);
-		GEdge* e1=0;
-		std::map<std::pair<GEdge*,GFace*>,GEdge* >::iterator itMap = GEdgeGlobalAssociation.find(std::make_pair(eTmp,fac1));
-		if (itMap != GEdgeGlobalAssociation.end()){
-			e1 = itMap->second;
-		}
-		//creation des GFace correspondantes
-		GEdge* firstE = SurroudingEdges.find(eTmp->getBeginVertex())->second;
-		GEdge* lastE = SurroudingEdges.find(eTmp->getEndVertex())->second;
-		if (firstE->getBeginVertex() != e1->getEndVertex()){
-			firstE->reverse();
-		}
-		if (firstE->getBeginVertex() != e1->getEndVertex()){
-			e1->reverse();
-		}
-		if (firstE->getBeginVertex() != e1->getEndVertex()){
-			firstE->reverse();
-		}
-		if (eTmp->getBeginVertex() != firstE->getEndVertex()){
-			eTmp->reverse();
-		}
-		if (lastE->getBeginVertex() != eTmp->getEndVertex()){
-			lastE->reverse();
-		}
-		std::vector<GEdge*> VecEdgesTmp;
-		VecEdgesTmp.push_back(e1);
-		VecEdgesTmp.push_back(firstE);
-		VecEdgesTmp.push_back(eTmp);
-		VecEdgesTmp.push_back(lastE);
-		std::vector<std::vector<GEdge*> > VecOfVecTmp;
-		VecOfVecTmp.push_back(VecEdgesTmp);
-		GFace* newFaceTmp = m->addPlanarFace(VecOfVecTmp);
-//		SurroundingsFaces.push_back(newFaceTmp);
-//		}
-		std::vector<GFace*> VectorFaces;
-		std::list<GFace*> listFaces;
-//		GFace* f1;
-//		std::map<std::pair<GFace*,GRegion*>,GFace* >::iterator itMap = GFaceGlobalAssociation.find(std::make_pair(fTmp,reg1));
-//		if (itMap != GFaceGlobalAssociation.end()){
-//			f1 = itMap->second;
-//		}
-//		VectorFaces.push_back(f1);
-//		listFaces.push_back(f1);
-//		for (unsigned int i = 0;i < SurroundingsFaces.size();i++){
-//			VectorFaces.push_back(SurroundingsFaces[i]);
-//			listFaces.push_back(SurroundingsFaces[i]);
-//		}
-//		VectorFaces.push_back(fTmp);
-//		listFaces.push_back(fTmp);
-//		std::vector<std::vector<GFace*> > VecOfVecGFace;
-//		VecOfVecGFace.push_back(VectorFaces);
-//		//creation de la nouvelle region
-//		GRegion* createdRegion = new GRegion(m,counterNbDone);
-		newFaceTmp->addPhysicalEntity(PhysicalInterface);
-//		createdRegion->set(listFaces);
-//		m->add(createdRegion);
-		for (unsigned int i = 0; i < eTmp->getNumMeshElements();i++){
-			MElement* elem = eTmp->getMeshElement(i);
-			MVertex* v1=0;
-			MVertex* v2=0;
-			//MVertex* v3;
-			std::map<std::pair<MVertex*,GFace*>,MVertex* >::iterator itMap = VertexGlobalAssociation.find(std::make_pair(elem->getVertex(0),fac1));
-			if (itMap != VertexGlobalAssociation.end()){
-				v1 = itMap->second;
-			}
-			itMap = VertexGlobalAssociation.find(std::make_pair(elem->getVertex(2),fac1));
-			if (itMap != VertexGlobalAssociation.end()){
-				v2 = itMap->second;
-			}
-			MQuadrangle *newQua = new MQuadrangle(v1,v2,elem->getVertex(2),elem->getVertex(0));
-			newFaceTmp->addQuadrangle(newQua);
-			//second
-			itMap = VertexGlobalAssociation.find(std::make_pair(elem->getVertex(2),fac1));
-			if (itMap != VertexGlobalAssociation.end()){
-				v1 = itMap->second;
-			}
-			itMap = VertexGlobalAssociation.find(std::make_pair(elem->getVertex(1),fac1));
-			if (itMap != VertexGlobalAssociation.end()){
-				v2 = itMap->second;
-			}
-			MQuadrangle *newQua2 = new MQuadrangle(v1,v2,elem->getVertex(1),elem->getVertex(2));
-			newFaceTmp->addQuadrangle(newQua2);
-		}
-		for (unsigned int i = 0; i < fac1->getNumMeshElements();i++){
-			MElement* elem = fac1->getMeshElement(i);
-			for (int j = 0;j < elem->getNumVertices();j++){
-				MVertex* vert = elem->getVertex(j);
-				std::map<std::pair<MVertex*,GFace*>,MVertex* >::iterator itMap = VertexGlobalAssociation.find(std::make_pair(vert,fac1));
-				if (itMap != VertexGlobalAssociation.end()){
-					elem->setVertex(j,itMap->second);
-				}
-			}
-		}
-	}
+  std::cout<<"starting DuplicateBoundaries"<<std::endl;
+  GModel *m = GModel::current();
+  m->setFactory("geo");
+  std::set<GEdge*> ToDuplicateList;
+  ToDuplicateList.clear();
+  std::set<GEdge*> ToDuplicateListBoundary;
+  ToDuplicateListBoundary.clear();
+  std::vector<GFace*> facesBound;
+  facesBound.clear();
+  std::map<GFace*,SPoint3> centers;
+  std::vector<std::pair<GFace*,GFace*> > pairs;
+  std::vector<std::pair<GFace*,GFace*> > newPairs;
+  int PhysicalInterface = m->setPhysicalName("Interface",2);
+
+  for (GModel::eiter ite= m->firstEdge();ite != m->lastEdge();ite++){
+    GEdge* eTmp = (*ite);
+    if (eTmp->faces().size() == 2){
+      ToDuplicateList.insert(eTmp);
+    }
+    else{
+      ToDuplicateListBoundary.insert(eTmp);
+    }
+  }
 
 
 
@@ -3352,6 +2946,262 @@ PView *GMSH_DuplicateBoundariesPlugin::execute2DWithBound(PView *view)
 
 
 
+  std::map<std::pair<MVertex*,GFace*>,MVertex* > VertexGlobalAssociation;
+  std::map<std::pair<GVertex*,GFace*>,GVertex* > GVertexGlobalAssociation;
+  std::map<std::pair<GEdge*,GFace*>,GEdge* > GEdgeGlobalAssociation;
+  std::map<std::pair<GFace*,GRegion*>,GFace* > GFaceGlobalAssociation;
+  for (GModel::fiter itr= m->firstFace();itr != m->lastFace();itr++){
+    GFace* rTmp = (*itr);
+    std::list<GEdge*> RegEdges = rTmp->edges();
+    std::map<MVertex*,MVertex* > VertexAssociation;
+    std::map<GVertex*,GVertex* > GVertexAssociation;
+    std::map<GEdge*,GEdge* > GEdgeAssociation;
+    //int counterNbDone = 10000;
+    double xCenterReg = 0.0;
+    double yCenterReg = 0.0;
+    double zCenterReg = 0.0;
+    int counterPts = 0;
+    for(std::list<GEdge*>::iterator it2=RegEdges.begin();it2!=RegEdges.end();it2++){
+      GEdge* fTemp = (*it2);
+      std::list<GVertex*> verticesFace = fTemp->vertices();
+      for (std::list<GVertex*>::iterator it3=verticesFace.begin();it3!=verticesFace.end();it3++){
+        xCenterReg = xCenterReg + (*it3)->x();
+        yCenterReg = yCenterReg + (*it3)->y();
+        zCenterReg = zCenterReg + (*it3)->z();
+        counterPts++;
+      }
+    }
+    xCenterReg = xCenterReg/counterPts;
+    yCenterReg = yCenterReg/counterPts;
+    zCenterReg = zCenterReg/counterPts;
+    //duplication noeud et aretes au niveau de la region directement
+    std::list<GVertex*> vlist;
+
+
+    std::list<GEdge*> listedgesTmp = rTmp->edges();
+    for (std::list<GEdge*>::iterator itTp = listedgesTmp.begin();itTp != listedgesTmp.end();itTp++){
+      std::list<GVertex*> vlist2;
+      if(std::find(vlist.begin(), vlist.end(),(*itTp)->getBeginVertex()) == vlist.end())
+        vlist.push_back((*itTp)->getBeginVertex());
+      if(std::find(vlist.begin(), vlist.end(),(*itTp)->getEndVertex()) == vlist.end())
+        vlist.push_back((*itTp)->getEndVertex());
+    }
+
+
+    for (std::list<GVertex*>::iterator itv = vlist.begin();itv != vlist.end();itv++){
+      //duplication Gvertex
+      GVertex* vTmp = (*itv);
+      double ponderatedX = 0.99999999999 * vTmp->x() + 0.00000000001 * xCenterReg;
+      double ponderatedY = 0.99999999999 * vTmp->y() + 0.00000000001 * yCenterReg;
+      double ponderatedZ = 0.99999999999 * vTmp->z() + 0.00000000001 * zCenterReg;
+      GVertex* newv = m->addVertex(ponderatedX,ponderatedY,ponderatedZ,vTmp->prescribedMeshSizeAtVertex());
+      GVertexAssociation[vTmp] = newv;
+      GVertexGlobalAssociation[std::make_pair(vTmp,rTmp)] = newv;
+      //creation des Gedge correspondantes
+      //			GEdge* newE = m->addLine(vTmp,newv);
+      //			SurroudingEdges[vTmp] = newE;
+      //maintenant traitement mesh
+      MVertex *vMesh = vTmp->mesh_vertices[0];
+      MVertex *newMv = new MVertex(vMesh->x(), vMesh->y(), vMesh->z(), (GEntity*)newv);
+      VertexAssociation[vMesh] = newMv;
+      VertexGlobalAssociation[std::make_pair(vMesh,rTmp)] = newMv;
+      newv->addMeshVertex(newMv);
+    }
+    //maintenant on soccupe de duppliquer les edges de la region
+    std::list<GEdge*> elist = rTmp->edges();
+
+    std::vector<GFace*> SurroundingsFaces;
+    for (std::list<GEdge*>::iterator itf = RegEdges.begin();itf != RegEdges.end();itf++){
+      GEdge* eTmp = (*itf);
+      GEdge* newE = m->addLine(GVertexAssociation[eTmp->getBeginVertex()],GVertexAssociation[eTmp->getEndVertex()]);
+      for (unsigned int i = 0; i < eTmp->mesh_vertices.size();i++){
+        MVertex *vMesh = eTmp->mesh_vertices[i];
+        MVertex *newMv = new MVertex(vMesh->x(), vMesh->y(), vMesh->z(), (GEntity*)newE);
+        VertexAssociation[vMesh] = newMv;
+        VertexGlobalAssociation[std::make_pair(vMesh,rTmp)] = newMv;
+        newE->addMeshVertex(newMv);
+      }
+      for (unsigned int i = 0; i < eTmp->getNumMeshElements();i++){
+        MElement* elem = eTmp->getMeshElement(i);
+        MVertex *firstETmp = VertexAssociation.find(elem->getVertex(0))->second;
+        MVertex *lastETmp = VertexAssociation.find(elem->getVertex(1))->second;
+        MVertex *midETmp = VertexAssociation.find(elem->getVertex(2))->second;
+        MLine3 *newLine = new MLine3(firstETmp,lastETmp,midETmp);
+        newE->addLine(newLine);
+      }
+      GEdgeGlobalAssociation[std::make_pair(eTmp,rTmp)] = newE;
+    }
+  }
+  int counterNbDone = 10000;
+  //maintenant on va traiter les faces initiales
+  for (std::set<GEdge*>::iterator itf = ToDuplicateList.begin();itf != ToDuplicateList.end();itf++){
+    counterNbDone++;
+    GEdge* eTmp = (*itf);
+    std::list<GFace*> listFacesTmpT = eTmp->faces();
+    std::list<GFace*>::iterator itTmpFace = listFacesTmpT.begin();
+    GFace* fac1 = (*itTmpFace);
+    itTmpFace++;
+    GFace* fac2 = (*itTmpFace);
+    //pour commencer on cree des aretes entre les vertex
+    //		std::list<GVertex*> vlist = eTmp->vertices();
+    std::list<GVertex*> vlist;
+    vlist.push_back(eTmp->getBeginVertex());
+    vlist.push_back(eTmp->getEndVertex());
+    std::map<GVertex*,GEdge* > SurroudingEdges;
+    for (std::list<GVertex*>::iterator itv = vlist.begin();itv != vlist.end();itv++){
+      GVertex* vTmp = (*itv);
+      GVertex* v1=0;
+      GVertex* v2=0;
+      std::map<std::pair<GVertex*,GFace*>,GVertex* >::iterator itMap = GVertexGlobalAssociation.find(std::make_pair(vTmp,fac1));
+      if (itMap != GVertexGlobalAssociation.end()){
+        v1 = itMap->second;
+      }
+      itMap = GVertexGlobalAssociation.find(std::make_pair(vTmp,fac2));
+      if (itMap != GVertexGlobalAssociation.end()){
+        v2 = itMap->second;
+      }
+      GEdge* newE = m->addLine(v1,v2);
+      SurroudingEdges[vTmp] = newE;
+    }
+    //ici tous les vertex sont traites
+    //on va traiter les edges
+    std::vector<GEdge*> newEdgesVector;
+    std::vector<GFace*> SurroundingsFaces;
+    //duplication Gedge
+    //			GEdge* eTmp = (*ite);
+    GEdge* e1=0;
+    GEdge* e2=0;
+    std::map<std::pair<GEdge*,GFace*>,GEdge* >::iterator itMap = GEdgeGlobalAssociation.find(std::make_pair(eTmp,fac1));
+    if (itMap != GEdgeGlobalAssociation.end()){
+      e1 = itMap->second;
+    }
+    itMap = GEdgeGlobalAssociation.find(std::make_pair(eTmp,fac2));
+    if (itMap != GEdgeGlobalAssociation.end()){
+      e2 = itMap->second;
+    }
+    //creation des GFace correspondantes
+    GEdge* firstE = SurroudingEdges.find(eTmp->getBeginVertex())->second;
+    GEdge* lastE = SurroudingEdges.find(eTmp->getEndVertex())->second;
+    if (firstE->getBeginVertex() != e1->getEndVertex()){
+      firstE->reverse();
+    }
+    if (firstE->getBeginVertex() != e1->getEndVertex()){
+      e1->reverse();
+    }
+    if (firstE->getBeginVertex() != e1->getEndVertex()){
+      firstE->reverse();
+    }
+    if (e2->getBeginVertex() != firstE->getEndVertex()){
+      e2->reverse();
+    }
+    if (lastE->getBeginVertex() != e2->getEndVertex()){
+      lastE->reverse();
+    }
+    std::vector<GEdge*> VecEdgesTmp;
+    VecEdgesTmp.push_back(e1);
+    VecEdgesTmp.push_back(firstE);
+    VecEdgesTmp.push_back(e2);
+    VecEdgesTmp.push_back(lastE);
+    std::vector<std::vector<GEdge*> > VecOfVecTmp;
+    VecOfVecTmp.push_back(VecEdgesTmp);
+    GFace* newFaceTmp = m->addPlanarFace(VecOfVecTmp);
+    //			SurroundingsFaces.push_back(newFaceTmp);
+
+    //creation de la nouvelle region
+    //		GRegion* createdRegion = new GRegion(m,counterNbDone);
+    newFaceTmp->addPhysicalEntity(PhysicalInterface);
+    //		createdRegion->set(listFaces);
+    //		m->add(createdRegion);
+    for (unsigned int i = 0; i < eTmp->getNumMeshElements();i++){
+      MElement* elem = eTmp->getMeshElement(i);
+      MVertex* v1=0;
+      MVertex* v2=0;
+      MVertex* v3=0;
+      MVertex* v4=0;
+      //MVertex* v5;
+      //MVertex* v6;
+      std::map<std::pair<MVertex*,GFace*>,MVertex* >::iterator itMap = VertexGlobalAssociation.find(std::make_pair(elem->getVertex(0),fac1));
+      if (itMap != VertexGlobalAssociation.end()){
+        v1 = itMap->second;
+      }
+      itMap = VertexGlobalAssociation.find(std::make_pair(elem->getVertex(2),fac1));
+      if (itMap != VertexGlobalAssociation.end()){
+        v2 = itMap->second;
+      }
+      itMap = VertexGlobalAssociation.find(std::make_pair(elem->getVertex(2),fac2));
+      if (itMap != VertexGlobalAssociation.end()){
+        v3 = itMap->second;
+      }
+      itMap = VertexGlobalAssociation.find(std::make_pair(elem->getVertex(0),fac2));
+      if (itMap != VertexGlobalAssociation.end()){
+        v4 = itMap->second;
+      }
+      //			itMap = VertexGlobalAssociation.find(std::make_pair(elem->getVertex(3),fac2));
+      //			if (itMap != VertexGlobalAssociation.end()){
+      //				v5 = itMap->second;
+      //			}
+      //			itMap = VertexGlobalAssociation.find(std::make_pair(elem->getVertex(5),fac2));
+      //			if (itMap != VertexGlobalAssociation.end()){
+      //				v6 = itMap->second;
+      //			}
+      MQuadrangle *newQua = new MQuadrangle(v1,v2,v3,v4);
+
+      newFaceTmp->addQuadrangle(newQua);
+
+      //second
+      itMap = VertexGlobalAssociation.find(std::make_pair(elem->getVertex(2),fac1));
+      if (itMap != VertexGlobalAssociation.end()){
+        v1 = itMap->second;
+      }
+      itMap = VertexGlobalAssociation.find(std::make_pair(elem->getVertex(1),fac1));
+      if (itMap != VertexGlobalAssociation.end()){
+        v2 = itMap->second;
+      }
+      itMap = VertexGlobalAssociation.find(std::make_pair(elem->getVertex(1),fac2));
+      if (itMap != VertexGlobalAssociation.end()){
+        v3 = itMap->second;
+      }
+      itMap = VertexGlobalAssociation.find(std::make_pair(elem->getVertex(2),fac2));
+      if (itMap != VertexGlobalAssociation.end()){
+        v4 = itMap->second;
+      }
+      //			itMap = VertexGlobalAssociation.find(std::make_pair(elem->getVertex(3),fac2));
+      //			if (itMap != VertexGlobalAssociation.end()){
+      //				v5 = itMap->second;
+      //			}
+      //			itMap = VertexGlobalAssociation.find(std::make_pair(elem->getVertex(5),fac2));
+      //			if (itMap != VertexGlobalAssociation.end()){
+      //				v6 = itMap->second;
+      //			}
+      MQuadrangle *newQua2 = new MQuadrangle(v1,v2,v3,v4);
+
+      newFaceTmp->addQuadrangle(newQua2);
+
+
+
+
+    }
+    for (unsigned int i = 0; i < fac1->getNumMeshElements();i++){
+      MElement* elem = fac1->getMeshElement(i);
+      for (int j = 0;j < elem->getNumVertices();j++){
+        MVertex* vert = elem->getVertex(j);
+        std::map<std::pair<MVertex*,GFace*>,MVertex* >::iterator itMap = VertexGlobalAssociation.find(std::make_pair(vert,fac1));
+        if (itMap != VertexGlobalAssociation.end()){
+          elem->setVertex(j,itMap->second);
+        }
+      }
+    }
+    for (unsigned int i = 0; i < fac2->getNumMeshElements();i++){
+      MElement* elem = fac2->getMeshElement(i);
+      for (int j = 0;j < elem->getNumVertices();j++){
+        MVertex* vert = elem->getVertex(j);
+        std::map<std::pair<MVertex*,GFace*>,MVertex* >::iterator itMap = VertexGlobalAssociation.find(std::make_pair(vert,fac2));
+        if (itMap != VertexGlobalAssociation.end()){
+          elem->setVertex(j,itMap->second);
+        }
+      }
+    }
+  }
 
 
 
@@ -3360,172 +3210,314 @@ PView *GMSH_DuplicateBoundariesPlugin::execute2DWithBound(PView *view)
 
 
 
-//	std::ofstream file("MicrostructurePolycrystal3D.pos");
-//	file << "View \"test\" {\n";
-//
-//	std::ofstream file2("PERIODIC.map");
-//	std::ofstream file3("SetAdd.map");
-//	for (std::vector<std::pair<GFace*,GFace*> >::iterator itP = pairs.begin();itP != pairs.end();itP++){
-//		std::pair<GFace*,GFace*> pairTmp = (*itP);
-//		GFace* ToReplaceFace = pairTmp.second;
-//		GRegion* rTmp = ToReplaceFace->getRegion(0);
-//		std::map<std::pair<GFace*,GRegion*>,GFace* >::iterator itMap = GFaceGlobalAssociation.find(std::make_pair(ToReplaceFace,rTmp));
-//		if (itMap != GFaceGlobalAssociation.end()){
-//			GFace* associatedFace = (*itMap).second;
-//
-//
-//
-//
-//
-//			file3 <<associatedFace->tag()<<"\tSURFACE"<<associatedFace->tag()<<"\tNSET "<<"\n";
-//
-//			int tagTmp = associatedFace->tag();
-//			std::ostringstream ss;
-//			ss << tagTmp;
-////			char *intStr = itoa(tagTmp);
-//			std::string nameSurf = "SURFACE";
-////			nameSurf += std::string(intStr);
-//			nameSurf += ss.str();
-//			int PhysicalSurfaceTmp = m->setPhysicalName(nameSurf,2);
-//			associatedFace->addPhysicalEntity(PhysicalSurfaceTmp);
-//
-//			std::map<GFace*,SPoint3>::iterator it3 = centers.find(pairTmp.first);
-//			std::map<GFace*,SPoint3>::iterator it4 = centers.find(ToReplaceFace);
-//
-//			SPoint3 p1 = it3->second;
-//			SPoint3  p2 = it4->second;
-//
-//			double delta_x = fabs(p2.x()-p1.x());
-//			double delta_y = fabs(p2.y()-p1.y());
-//			double delta_z = fabs(p2.z()-p1.z());
-//
-//
-//			file << "SL ("
-//					<< p1.x() << ", " << p1.y() << ", " << p1.z() << ", "
-//					<< p2.x() << ", " << p2.y() << ", " << p2.z()
-//					<< "){10, 20};\n";
-//
-//			//file2 << "PERIODIC\tSURFACE"<<faces[i]->tag() << "\tSURFACE" << faces[j]->tag() << "\t" << p2.x()-p1.x() << "\t" << p2.y()-p1.y() << "\t" << p2.z()-p1.z() << "\n";
-//			if (abs((p2.x()-p1.x()-1.0))<0.0001){
-//				if (abs((p2.y()-p1.y()))<0.0001){
-//					if (abs((p2.z()-p1.z()))<0.0001){
-//						file2 << "NSET\tFRONT = FRONT + SURFACE"<<associatedFace->tag()<<"\n";
-//						file2 << "NSET\tBACK = BACK + SURFACE"<<pairTmp.first->tag()<<"\n";
-//					}else if(abs((p2.z()-p1.z()-1.0))<0.0001){
-//						file2 << "NSET\tFRONTTOP = FRONTTOP + SURFACE"<<associatedFace->tag()<<"\n";
-//						file2 << "NSET\tBACKBOTTOM = BACKBOTTOM + SURFACE"<<pairTmp.first->tag()<<"\n";
-//					}else if (abs((p1.z()-p2.z()-1.0))<0.0001){
-//						file2 << "NSET\tFRONTBOTTOM = FRONTBOTTOM + SURFACE"<<associatedFace->tag()<<"\n";
-//						file2 << "NSET\tBACKTOP = BACKTOP + SURFACE"<<pairTmp.first->tag()<<"\n";
-//					}
-//				}else if (abs((p2.y()-p1.y()-1.0))<0.0001){
-//					if (abs((p2.z()-p1.z()))<0.0001){
-//						file2 << "NSET\tFRONTRIGHT = FRONTRIGHT + SURFACE"<<associatedFace->tag()<<"\n";
-//						file2 << "NSET\tBACKLEFT = BACKLEFT + SURFACE"<<pairTmp.first->tag()<<"\n";
-//					}else if (abs((p2.z()-p1.z()-1.0))<0.0001){
-//						file2 << "NSET\tFRONTRIGHTTOP = FRONTRIGHTTOP + SURFACE"<<associatedFace->tag()<<"\n";
-//						file2 << "NSET\tBACKLEFTBOTTOM = BACKLEFTBOTTOM + SURFACE"<<pairTmp.first->tag()<<"\n";
-//					}else if (abs((p1.z()-p2.z()-1.0))<0.0001){
-//						file2 << "NSET\tFRONTRIGHTBOTTOM = FRONTRIGHTBOTTOM + SURFACE"<<associatedFace->tag()<<"\n";
-//						file2 << "NSET\tBACKLEFTTOP = BACKLEFTTOP + SURFACE"<<pairTmp.first->tag()<<"\n";
-//					}
-//				}else if (abs((p1.y()-p2.y()-1.0))<0.0001){
-//					if (abs((p2.z()-p1.z()))<0.0001){
-//						file2 << "NSET\tFRONTLEFT = FRONTLEFT + SURFACE"<<associatedFace->tag()<<"\n";
-//						file2 << "NSET\tBACKRIGHT = BACKRIGHT + SURFACE"<<pairTmp.first->tag()<<"\n";
-//					}else if (abs((p2.z()-p1.z()-1.0))<0.0001){
-//						file2 << "NSET\tFRONTLEFTTOP = FRONTLEFTTOP + SURFACE"<<associatedFace->tag()<<"\n";
-//						file2 << "NSET\tBACKRIGHTBOTTOM = BACKRIGHTBOTTOM + SURFACE"<<pairTmp.first->tag()<<"\n";
-//					}else if (abs((p1.z()-p2.z()-1.0))<0.0001){
-//						file2 << "NSET\tFRONTLEFTBOTTOM = FRONTLEFTBOTTOM + SURFACE"<<associatedFace->tag()<<"\n";
-//						file2 << "NSET\tBACKRIGHTTOP = BACKRIGHTTOP + SURFACE"<<pairTmp.first->tag()<<"\n";
-//					}
-//				}
-//			}else if (abs((p1.x()-p2.x()-1.0))<0.0001){
-//				if (abs((p2.y()-p1.y()))<0.0001){
-//					if (abs((p2.z()-p1.z()))<0.0001){
-//						file2 << "NSET\tFRONT = FRONT + SURFACE"<<pairTmp.first->tag()<<"\n";
-//						file2 << "NSET\tBACK = BACK + SURFACE"<<associatedFace->tag()<<"\n";
-//					}else if(abs((p2.z()-p1.z()-1.0))<0.0001){
-//						file2 << "NSET\tFRONTBOTTOM = FRONTBOTTOM + SURFACE"<<pairTmp.first->tag()<<"\n";
-//						file2 << "NSET\tBACKTOP = BACKTOP + SURFACE"<<associatedFace->tag()<<"\n";
-//					}else if (abs((p1.z()-p2.z()-1.0))<0.0001){
-//						file2 << "NSET\tFRONTTOP = FRONTTOP + SURFACE"<<pairTmp.first->tag()<<"\n";
-//						file2 << "NSET\tBACKBOTTOM = BACKBOTTOM + SURFACE"<<associatedFace->tag()<<"\n";
-//					}
-//				}else if (abs((p2.y()-p1.y()-1.0))<0.0001){
-//					if (abs((p2.z()-p1.z()))<0.0001){
-//						file2 << "NSET\tFRONTLEFT = FRONTLEFT + SURFACE"<<pairTmp.first->tag()<<"\n";
-//						file2 << "NSET\tBACKRIGHT = BACKRIGHT + SURFACE"<<associatedFace->tag()<<"\n";
-//					}else if (abs((p2.z()-p1.z()-1.0))<0.0001){
-//						file2 << "NSET\tFRONTLEFTBOTTOM = FRONTLEFTBOTTOM + SURFACE"<<pairTmp.first->tag()<<"\n";
-//						file2 << "NSET\tBACKRIGHTTOP = BACKRIGHTTOP + SURFACE"<<associatedFace->tag()<<"\n";
-//					}else if (abs((p1.z()-p2.z()-1.0))<0.0001){
-//						file2 << "NSET\tFRONTLEFTTOP = FRONTLEFTTOP + SURFACE"<<pairTmp.first->tag()<<"\n";
-//						file2 << "NSET\tBACKRIGHTBOTTOM = BACKRIGHTBOTTOM + SURFACE"<<associatedFace->tag()<<"\n";
-//					}
-//				}else if (abs((p1.y()-p2.y()-1.0))<0.0001){
-//					if (abs((p2.z()-p1.z()))<0.0001){
-//						file2 << "NSET\tFRONTRIGHT = FRONTRIGHT + SURFACE"<<pairTmp.first->tag()<<"\n";
-//						file2 << "NSET\tBACKLEFT = BACKLEFT + SURFACE"<<associatedFace->tag()<<"\n";
-//					}else if (abs((p2.z()-p1.z()-1.0))<0.0001){
-//						file2 << "NSET\tFRONTRIGHTBOTTOM = FRONTRIGHTBOTTOM + SURFACE"<<pairTmp.first->tag()<<"\n";
-//						file2 << "NSET\tBACKLEFTTOP = BACKLEFTTOP + SURFACE"<<associatedFace->tag()<<"\n";
-//					}else if (abs((p1.z()-p2.z()-1.0))<0.0001){
-//						file2 << "NSET\tFRONTRIGHTTOP = FRONTRIGHTTOP + SURFACE"<<pairTmp.first->tag()<<"\n";
-//						file2 << "NSET\tBACKLEFTBOTTOM = BACKLEFTBOTTOM + SURFACE"<<associatedFace->tag()<<"\n";
-//					}
-//				}
-//			}else if (abs((p1.x()-p2.x()))<0.0001){
-//				if (abs((p2.y()-p1.y()-1.0))<0.0001){
-//					if (abs((p2.z()-p1.z()))<0.0001){
-//						file2 << "NSET\tRIGHT = RIGHT + SURFACE"<<associatedFace->tag()<<"\n";
-//						file2 << "NSET\tLEFT = LEFT + SURFACE"<<pairTmp.first->tag()<<"\n";
-//					}else if (abs((p2.z()-p1.z()-1.0))<0.0001){
-//						file2 << "NSET\tRIGHTTOP = RIGHTTOP + SURFACE"<<associatedFace->tag()<<"\n";
-//						file2 << "NSET\tLEFTBOTTOM = LEFTBOTTOM + SURFACE"<<pairTmp.first->tag()<<"\n";
-//					}else if (abs((p1.z()-p2.z()-1.0))<0.0001){
-//						file2 << "NSET\tRIGHTBOTTOM = RIGHTBOTTOM + SURFACE"<<associatedFace->tag()<<"\n";
-//						file2 << "NSET\tLEFTTOP = LEFTTOP + SURFACE"<<pairTmp.first->tag()<<"\n";
-//					}
-//				}else if (abs((p1.y()-p2.y()-1.0))<0.0001){
-//					if (abs((p2.z()-p1.z()))<0.0001){
-//						file2 << "NSET\tRIGHT = RIGHT + SURFACE"<<pairTmp.first->tag()<<"\n";
-//						file2 << "NSET\tLEFT = LEFT + SURFACE"<<associatedFace->tag()<<"\n";
-//					}else if (abs((p2.z()-p1.z()-1.0))<0.0001){
-//						file2 << "NSET\tRIGHTBOTTOM = RIGHTBOTTOM + SURFACE"<<pairTmp.first->tag()<<"\n";
-//						file2 << "NSET\tLEFTTOP = LEFTTOP + SURFACE"<<associatedFace->tag()<<"\n";
-//					}else if (abs((p1.z()-p2.z()-1.0))<0.0001){
-//						file2 << "NSET\tRIGHTTOP = RIGHTTOP + SURFACE"<<pairTmp.first->tag()<<"\n";
-//						file2 << "NSET\tLEFTBOTTOM = LEFTBOTTOM + SURFACE"<<associatedFace->tag()<<"\n";
-//					}
-//				}else if (abs((p1.y()-p2.y()))<0.0001){
-//					if (abs((p2.z()-p1.z()-1.0))<0.0001){
-//						file2 << "NSET\tTOP = TOP + SURFACE"<<associatedFace->tag()<<"\n";
-//						file2 << "NSET\tBOTTOM = BOTTOM + SURFACE"<<pairTmp.first->tag()<<"\n";
-//					}else if (abs((p1.z()-p2.z()-1.0))<0.0001){
-//						file2 << "NSET\tTOP = TOP + SURFACE"<<pairTmp.first->tag()<<"\n";
-//						file2 << "NSET\tBOTTOM = BOTTOM + SURFACE"<<associatedFace->tag()<<"\n";
-//					}
-//				}
-//			}
-////			count++;
-//
-//
-//
-//
-//
-//
-//
-//			newPairs.push_back(std::make_pair(pairTmp.first,associatedFace));
-//		}
-//	}
-//	for (std::vector<std::pair<GFace*,GFace*> >::iterator itP = newPairs.begin();itP != newPairs.end();itP++){
-//		std::pair<GFace*,GFace*> pairTmp = (*itP);
-//	}
+  //maintenant on va traiter les faces du bord
+  for (std::set<GEdge*>::iterator itf = ToDuplicateListBoundary.begin();itf != ToDuplicateListBoundary.end();itf++){
+    counterNbDone++;
+    GEdge* eTmp = (*itf);
+    std::list<GFace*> listFacesTmpT = eTmp->faces();
+    std::list<GFace*>::iterator itTmpFace = listFacesTmpT.begin();
+    GFace* fac1 = (*itTmpFace);
+    //		GFace* reg1 = fTmp->getRegion(0);
+    //pour commencer on cree des aretes entre les vertex
+    std::list<GVertex*> vlist;
+    vlist.push_back(eTmp->getBeginVertex());
+    vlist.push_back(eTmp->getEndVertex());
+    std::map<GVertex*,GEdge* > SurroudingEdges;
+    for (std::list<GVertex*>::iterator itv = vlist.begin();itv != vlist.end();itv++){
+      GVertex* vTmp = (*itv);
+      GVertex* v1=0;
+      std::map<std::pair<GVertex*,GFace*>,GVertex* >::iterator itMap = GVertexGlobalAssociation.find(std::make_pair(vTmp,fac1));
+      if (itMap != GVertexGlobalAssociation.end()){
+        v1 = itMap->second;
+      }
+      GEdge* newE = m->addLine(v1,vTmp);
+      SurroudingEdges[vTmp] = newE;
+    }
+    //ici tous les vertex sont traites
+    //on va traiter les edges
+    //		std::list<GEdge*> elist = fTmp->edges();
+    std::vector<GEdge*> newEdgesVector;
+    std::vector<GFace*> SurroundingsFaces;
+    //		for (std::list<GEdge*>::iterator ite = elist.begin();ite != elist.end();ite++){
+    //duplication Gedge
+    //			GEdge* eTmp = (*ite);
+    GEdge* e1=0;
+    std::map<std::pair<GEdge*,GFace*>,GEdge* >::iterator itMap = GEdgeGlobalAssociation.find(std::make_pair(eTmp,fac1));
+    if (itMap != GEdgeGlobalAssociation.end()){
+      e1 = itMap->second;
+    }
+    //creation des GFace correspondantes
+    GEdge* firstE = SurroudingEdges.find(eTmp->getBeginVertex())->second;
+    GEdge* lastE = SurroudingEdges.find(eTmp->getEndVertex())->second;
+    if (firstE->getBeginVertex() != e1->getEndVertex()){
+      firstE->reverse();
+    }
+    if (firstE->getBeginVertex() != e1->getEndVertex()){
+      e1->reverse();
+    }
+    if (firstE->getBeginVertex() != e1->getEndVertex()){
+      firstE->reverse();
+    }
+    if (eTmp->getBeginVertex() != firstE->getEndVertex()){
+      eTmp->reverse();
+    }
+    if (lastE->getBeginVertex() != eTmp->getEndVertex()){
+      lastE->reverse();
+    }
+    std::vector<GEdge*> VecEdgesTmp;
+    VecEdgesTmp.push_back(e1);
+    VecEdgesTmp.push_back(firstE);
+    VecEdgesTmp.push_back(eTmp);
+    VecEdgesTmp.push_back(lastE);
+    std::vector<std::vector<GEdge*> > VecOfVecTmp;
+    VecOfVecTmp.push_back(VecEdgesTmp);
+    GFace* newFaceTmp = m->addPlanarFace(VecOfVecTmp);
+    //		SurroundingsFaces.push_back(newFaceTmp);
+    //		}
+    std::vector<GFace*> VectorFaces;
+    std::list<GFace*> listFaces;
+    //		GFace* f1;
+    //		std::map<std::pair<GFace*,GRegion*>,GFace* >::iterator itMap = GFaceGlobalAssociation.find(std::make_pair(fTmp,reg1));
+    //		if (itMap != GFaceGlobalAssociation.end()){
+    //			f1 = itMap->second;
+    //		}
+    //		VectorFaces.push_back(f1);
+    //		listFaces.push_back(f1);
+    //		for (unsigned int i = 0;i < SurroundingsFaces.size();i++){
+    //			VectorFaces.push_back(SurroundingsFaces[i]);
+    //			listFaces.push_back(SurroundingsFaces[i]);
+    //		}
+    //		VectorFaces.push_back(fTmp);
+    //		listFaces.push_back(fTmp);
+    //		std::vector<std::vector<GFace*> > VecOfVecGFace;
+    //		VecOfVecGFace.push_back(VectorFaces);
+    //		//creation de la nouvelle region
+    //		GRegion* createdRegion = new GRegion(m,counterNbDone);
+    newFaceTmp->addPhysicalEntity(PhysicalInterface);
+    //		createdRegion->set(listFaces);
+    //		m->add(createdRegion);
+    for (unsigned int i = 0; i < eTmp->getNumMeshElements();i++){
+      MElement* elem = eTmp->getMeshElement(i);
+      MVertex* v1=0;
+      MVertex* v2=0;
+      //MVertex* v3;
+      std::map<std::pair<MVertex*,GFace*>,MVertex* >::iterator itMap = VertexGlobalAssociation.find(std::make_pair(elem->getVertex(0),fac1));
+      if (itMap != VertexGlobalAssociation.end()){
+        v1 = itMap->second;
+      }
+      itMap = VertexGlobalAssociation.find(std::make_pair(elem->getVertex(2),fac1));
+      if (itMap != VertexGlobalAssociation.end()){
+        v2 = itMap->second;
+      }
+      MQuadrangle *newQua = new MQuadrangle(v1,v2,elem->getVertex(2),elem->getVertex(0));
+      newFaceTmp->addQuadrangle(newQua);
+      //second
+      itMap = VertexGlobalAssociation.find(std::make_pair(elem->getVertex(2),fac1));
+      if (itMap != VertexGlobalAssociation.end()){
+        v1 = itMap->second;
+      }
+      itMap = VertexGlobalAssociation.find(std::make_pair(elem->getVertex(1),fac1));
+      if (itMap != VertexGlobalAssociation.end()){
+        v2 = itMap->second;
+      }
+      MQuadrangle *newQua2 = new MQuadrangle(v1,v2,elem->getVertex(1),elem->getVertex(2));
+      newFaceTmp->addQuadrangle(newQua2);
+    }
+    for (unsigned int i = 0; i < fac1->getNumMeshElements();i++){
+      MElement* elem = fac1->getMeshElement(i);
+      for (int j = 0;j < elem->getNumVertices();j++){
+        MVertex* vert = elem->getVertex(j);
+        std::map<std::pair<MVertex*,GFace*>,MVertex* >::iterator itMap = VertexGlobalAssociation.find(std::make_pair(vert,fac1));
+        if (itMap != VertexGlobalAssociation.end()){
+          elem->setVertex(j,itMap->second);
+        }
+      }
+    }
+  }
+
+
+
+
+
 
-	std::cout<<"End of DuplicateBoundaries"<<std::endl;
-	return view;
+
+
+
+
+
+
+
+
+
+
+
+
+  //	std::ofstream file("MicrostructurePolycrystal3D.pos");
+  //	file << "View \"test\" {\n";
+  //
+  //	std::ofstream file2("PERIODIC.map");
+  //	std::ofstream file3("SetAdd.map");
+  //	for (std::vector<std::pair<GFace*,GFace*> >::iterator itP = pairs.begin();itP != pairs.end();itP++){
+  //		std::pair<GFace*,GFace*> pairTmp = (*itP);
+  //		GFace* ToReplaceFace = pairTmp.second;
+  //		GRegion* rTmp = ToReplaceFace->getRegion(0);
+  //		std::map<std::pair<GFace*,GRegion*>,GFace* >::iterator itMap = GFaceGlobalAssociation.find(std::make_pair(ToReplaceFace,rTmp));
+  //		if (itMap != GFaceGlobalAssociation.end()){
+  //			GFace* associatedFace = (*itMap).second;
+  //
+  //
+  //
+  //
+  //
+  //			file3 <<associatedFace->tag()<<"\tSURFACE"<<associatedFace->tag()<<"\tNSET "<<"\n";
+  //
+  //			int tagTmp = associatedFace->tag();
+  //			std::ostringstream ss;
+  //			ss << tagTmp;
+  ////			char *intStr = itoa(tagTmp);
+  //			std::string nameSurf = "SURFACE";
+  ////			nameSurf += std::string(intStr);
+  //			nameSurf += ss.str();
+  //			int PhysicalSurfaceTmp = m->setPhysicalName(nameSurf,2);
+  //			associatedFace->addPhysicalEntity(PhysicalSurfaceTmp);
+  //
+  //			std::map<GFace*,SPoint3>::iterator it3 = centers.find(pairTmp.first);
+  //			std::map<GFace*,SPoint3>::iterator it4 = centers.find(ToReplaceFace);
+  //
+  //			SPoint3 p1 = it3->second;
+  //			SPoint3  p2 = it4->second;
+  //
+  //			double delta_x = fabs(p2.x()-p1.x());
+  //			double delta_y = fabs(p2.y()-p1.y());
+  //			double delta_z = fabs(p2.z()-p1.z());
+  //
+  //
+  //			file << "SL ("
+  //					<< p1.x() << ", " << p1.y() << ", " << p1.z() << ", "
+  //					<< p2.x() << ", " << p2.y() << ", " << p2.z()
+  //					<< "){10, 20};\n";
+  //
+  //			//file2 << "PERIODIC\tSURFACE"<<faces[i]->tag() << "\tSURFACE" << faces[j]->tag() << "\t" << p2.x()-p1.x() << "\t" << p2.y()-p1.y() << "\t" << p2.z()-p1.z() << "\n";
+  //			if (abs((p2.x()-p1.x()-1.0))<0.0001){
+  //				if (abs((p2.y()-p1.y()))<0.0001){
+  //					if (abs((p2.z()-p1.z()))<0.0001){
+  //						file2 << "NSET\tFRONT = FRONT + SURFACE"<<associatedFace->tag()<<"\n";
+  //						file2 << "NSET\tBACK = BACK + SURFACE"<<pairTmp.first->tag()<<"\n";
+  //					}else if(abs((p2.z()-p1.z()-1.0))<0.0001){
+  //						file2 << "NSET\tFRONTTOP = FRONTTOP + SURFACE"<<associatedFace->tag()<<"\n";
+  //						file2 << "NSET\tBACKBOTTOM = BACKBOTTOM + SURFACE"<<pairTmp.first->tag()<<"\n";
+  //					}else if (abs((p1.z()-p2.z()-1.0))<0.0001){
+  //						file2 << "NSET\tFRONTBOTTOM = FRONTBOTTOM + SURFACE"<<associatedFace->tag()<<"\n";
+  //						file2 << "NSET\tBACKTOP = BACKTOP + SURFACE"<<pairTmp.first->tag()<<"\n";
+  //					}
+  //				}else if (abs((p2.y()-p1.y()-1.0))<0.0001){
+  //					if (abs((p2.z()-p1.z()))<0.0001){
+  //						file2 << "NSET\tFRONTRIGHT = FRONTRIGHT + SURFACE"<<associatedFace->tag()<<"\n";
+  //						file2 << "NSET\tBACKLEFT = BACKLEFT + SURFACE"<<pairTmp.first->tag()<<"\n";
+  //					}else if (abs((p2.z()-p1.z()-1.0))<0.0001){
+  //						file2 << "NSET\tFRONTRIGHTTOP = FRONTRIGHTTOP + SURFACE"<<associatedFace->tag()<<"\n";
+  //						file2 << "NSET\tBACKLEFTBOTTOM = BACKLEFTBOTTOM + SURFACE"<<pairTmp.first->tag()<<"\n";
+  //					}else if (abs((p1.z()-p2.z()-1.0))<0.0001){
+  //						file2 << "NSET\tFRONTRIGHTBOTTOM = FRONTRIGHTBOTTOM + SURFACE"<<associatedFace->tag()<<"\n";
+  //						file2 << "NSET\tBACKLEFTTOP = BACKLEFTTOP + SURFACE"<<pairTmp.first->tag()<<"\n";
+  //					}
+  //				}else if (abs((p1.y()-p2.y()-1.0))<0.0001){
+  //					if (abs((p2.z()-p1.z()))<0.0001){
+  //						file2 << "NSET\tFRONTLEFT = FRONTLEFT + SURFACE"<<associatedFace->tag()<<"\n";
+  //						file2 << "NSET\tBACKRIGHT = BACKRIGHT + SURFACE"<<pairTmp.first->tag()<<"\n";
+  //					}else if (abs((p2.z()-p1.z()-1.0))<0.0001){
+  //						file2 << "NSET\tFRONTLEFTTOP = FRONTLEFTTOP + SURFACE"<<associatedFace->tag()<<"\n";
+  //						file2 << "NSET\tBACKRIGHTBOTTOM = BACKRIGHTBOTTOM + SURFACE"<<pairTmp.first->tag()<<"\n";
+  //					}else if (abs((p1.z()-p2.z()-1.0))<0.0001){
+  //						file2 << "NSET\tFRONTLEFTBOTTOM = FRONTLEFTBOTTOM + SURFACE"<<associatedFace->tag()<<"\n";
+  //						file2 << "NSET\tBACKRIGHTTOP = BACKRIGHTTOP + SURFACE"<<pairTmp.first->tag()<<"\n";
+  //					}
+  //				}
+  //			}else if (abs((p1.x()-p2.x()-1.0))<0.0001){
+  //				if (abs((p2.y()-p1.y()))<0.0001){
+  //					if (abs((p2.z()-p1.z()))<0.0001){
+  //						file2 << "NSET\tFRONT = FRONT + SURFACE"<<pairTmp.first->tag()<<"\n";
+  //						file2 << "NSET\tBACK = BACK + SURFACE"<<associatedFace->tag()<<"\n";
+  //					}else if(abs((p2.z()-p1.z()-1.0))<0.0001){
+  //						file2 << "NSET\tFRONTBOTTOM = FRONTBOTTOM + SURFACE"<<pairTmp.first->tag()<<"\n";
+  //						file2 << "NSET\tBACKTOP = BACKTOP + SURFACE"<<associatedFace->tag()<<"\n";
+  //					}else if (abs((p1.z()-p2.z()-1.0))<0.0001){
+  //						file2 << "NSET\tFRONTTOP = FRONTTOP + SURFACE"<<pairTmp.first->tag()<<"\n";
+  //						file2 << "NSET\tBACKBOTTOM = BACKBOTTOM + SURFACE"<<associatedFace->tag()<<"\n";
+  //					}
+  //				}else if (abs((p2.y()-p1.y()-1.0))<0.0001){
+  //					if (abs((p2.z()-p1.z()))<0.0001){
+  //						file2 << "NSET\tFRONTLEFT = FRONTLEFT + SURFACE"<<pairTmp.first->tag()<<"\n";
+  //						file2 << "NSET\tBACKRIGHT = BACKRIGHT + SURFACE"<<associatedFace->tag()<<"\n";
+  //					}else if (abs((p2.z()-p1.z()-1.0))<0.0001){
+  //						file2 << "NSET\tFRONTLEFTBOTTOM = FRONTLEFTBOTTOM + SURFACE"<<pairTmp.first->tag()<<"\n";
+  //						file2 << "NSET\tBACKRIGHTTOP = BACKRIGHTTOP + SURFACE"<<associatedFace->tag()<<"\n";
+  //					}else if (abs((p1.z()-p2.z()-1.0))<0.0001){
+  //						file2 << "NSET\tFRONTLEFTTOP = FRONTLEFTTOP + SURFACE"<<pairTmp.first->tag()<<"\n";
+  //						file2 << "NSET\tBACKRIGHTBOTTOM = BACKRIGHTBOTTOM + SURFACE"<<associatedFace->tag()<<"\n";
+  //					}
+  //				}else if (abs((p1.y()-p2.y()-1.0))<0.0001){
+  //					if (abs((p2.z()-p1.z()))<0.0001){
+  //						file2 << "NSET\tFRONTRIGHT = FRONTRIGHT + SURFACE"<<pairTmp.first->tag()<<"\n";
+  //						file2 << "NSET\tBACKLEFT = BACKLEFT + SURFACE"<<associatedFace->tag()<<"\n";
+  //					}else if (abs((p2.z()-p1.z()-1.0))<0.0001){
+  //						file2 << "NSET\tFRONTRIGHTBOTTOM = FRONTRIGHTBOTTOM + SURFACE"<<pairTmp.first->tag()<<"\n";
+  //						file2 << "NSET\tBACKLEFTTOP = BACKLEFTTOP + SURFACE"<<associatedFace->tag()<<"\n";
+  //					}else if (abs((p1.z()-p2.z()-1.0))<0.0001){
+  //						file2 << "NSET\tFRONTRIGHTTOP = FRONTRIGHTTOP + SURFACE"<<pairTmp.first->tag()<<"\n";
+  //						file2 << "NSET\tBACKLEFTBOTTOM = BACKLEFTBOTTOM + SURFACE"<<associatedFace->tag()<<"\n";
+  //					}
+  //				}
+  //			}else if (abs((p1.x()-p2.x()))<0.0001){
+  //				if (abs((p2.y()-p1.y()-1.0))<0.0001){
+  //					if (abs((p2.z()-p1.z()))<0.0001){
+  //						file2 << "NSET\tRIGHT = RIGHT + SURFACE"<<associatedFace->tag()<<"\n";
+  //						file2 << "NSET\tLEFT = LEFT + SURFACE"<<pairTmp.first->tag()<<"\n";
+  //					}else if (abs((p2.z()-p1.z()-1.0))<0.0001){
+  //						file2 << "NSET\tRIGHTTOP = RIGHTTOP + SURFACE"<<associatedFace->tag()<<"\n";
+  //						file2 << "NSET\tLEFTBOTTOM = LEFTBOTTOM + SURFACE"<<pairTmp.first->tag()<<"\n";
+  //					}else if (abs((p1.z()-p2.z()-1.0))<0.0001){
+  //						file2 << "NSET\tRIGHTBOTTOM = RIGHTBOTTOM + SURFACE"<<associatedFace->tag()<<"\n";
+  //						file2 << "NSET\tLEFTTOP = LEFTTOP + SURFACE"<<pairTmp.first->tag()<<"\n";
+  //					}
+  //				}else if (abs((p1.y()-p2.y()-1.0))<0.0001){
+  //					if (abs((p2.z()-p1.z()))<0.0001){
+  //						file2 << "NSET\tRIGHT = RIGHT + SURFACE"<<pairTmp.first->tag()<<"\n";
+  //						file2 << "NSET\tLEFT = LEFT + SURFACE"<<associatedFace->tag()<<"\n";
+  //					}else if (abs((p2.z()-p1.z()-1.0))<0.0001){
+  //						file2 << "NSET\tRIGHTBOTTOM = RIGHTBOTTOM + SURFACE"<<pairTmp.first->tag()<<"\n";
+  //						file2 << "NSET\tLEFTTOP = LEFTTOP + SURFACE"<<associatedFace->tag()<<"\n";
+  //					}else if (abs((p1.z()-p2.z()-1.0))<0.0001){
+  //						file2 << "NSET\tRIGHTTOP = RIGHTTOP + SURFACE"<<pairTmp.first->tag()<<"\n";
+  //						file2 << "NSET\tLEFTBOTTOM = LEFTBOTTOM + SURFACE"<<associatedFace->tag()<<"\n";
+  //					}
+  //				}else if (abs((p1.y()-p2.y()))<0.0001){
+  //					if (abs((p2.z()-p1.z()-1.0))<0.0001){
+  //						file2 << "NSET\tTOP = TOP + SURFACE"<<associatedFace->tag()<<"\n";
+  //						file2 << "NSET\tBOTTOM = BOTTOM + SURFACE"<<pairTmp.first->tag()<<"\n";
+  //					}else if (abs((p1.z()-p2.z()-1.0))<0.0001){
+  //						file2 << "NSET\tTOP = TOP + SURFACE"<<pairTmp.first->tag()<<"\n";
+  //						file2 << "NSET\tBOTTOM = BOTTOM + SURFACE"<<associatedFace->tag()<<"\n";
+  //					}
+  //				}
+  //			}
+  ////			count++;
+  //
+  //
+  //
+  //
+  //
+  //
+  //
+  //			newPairs.push_back(std::make_pair(pairTmp.first,associatedFace));
+  //		}
+  //	}
+  //	for (std::vector<std::pair<GFace*,GFace*> >::iterator itP = newPairs.begin();itP != newPairs.end();itP++){
+  //		std::pair<GFace*,GFace*> pairTmp = (*itP);
+  //	}
+
+  std::cout<<"End of DuplicateBoundaries"<<std::endl;
+  return view;
 }
 
 
@@ -3571,344 +3563,343 @@ PView *GMSH_DuplicateBoundariesPlugin::execute2DWithBound(PView *view)
 
 PView *GMSH_DuplicateBoundariesPlugin::executeTer(PView *view)
 {
-	std::cout<<"starting DuplicateBoundaries"<<std::endl;
-	GModel *m = GModel::current();
-	m->setFactory("geo");
-	std::set<GFace*> ToDuplicateList;
-	ToDuplicateList.clear();
-	std::set<GFace*> ToDuplicateListBoundary;
-	ToDuplicateListBoundary.clear();
-	std::vector<GFace*> facesBound;
-	facesBound.clear();
-	std::map<GFace*,SPoint3> centers;
-	std::vector<std::pair<GFace*,GFace*> > pairs;
-	std::vector<std::pair<GFace*,GFace*> > newPairs;
-	int PhysicalInterface = m->setPhysicalName("Interface",3);
-	int PhysicalBoundary = m->setPhysicalName("Boundary",2);
-	for (GModel::fiter itf= m->firstFace();itf != m->lastFace();itf++){
-		GFace* fTmp = (*itf);
-		if (fTmp->numRegions() == 2){
-			ToDuplicateList.insert(fTmp);
-		}
-		else{
-			ToDuplicateListBoundary.insert(fTmp);
-			facesBound.push_back(fTmp);
-		}
-	}
-
-
-
-
-
-
-
-	std::map<std::pair<MVertex*,GRegion*>,MVertex* > VertexGlobalAssociation;
-	std::map<std::pair<GVertex*,GRegion*>,GVertex* > GVertexGlobalAssociation;
-	std::map<std::pair<GEdge*,GRegion*>,GEdge* > GEdgeGlobalAssociation;
-	std::map<std::pair<GFace*,GRegion*>,GFace* > GFaceGlobalAssociation;
-
-	for (GModel::riter itr= m->firstRegion();itr != m->lastRegion();itr++){
-		GRegion* rTmp = (*itr);
-		std::list<GFace*> RegFaces = rTmp->faces();
-		std::map<MVertex*,MVertex* > VertexAssociation;
-		std::map<GVertex*,GVertex* > GVertexAssociation;
-		std::map<GEdge*,GEdge* > GEdgeAssociation;
-		//int counterNbDone = 10000;
-		double xCenterReg = 0.0;
-		double yCenterReg = 0.0;
-		double zCenterReg = 0.0;
-		int counterPts = 0;
-		for(std::list<GFace*>::iterator it2=RegFaces.begin();it2!=RegFaces.end();it2++){
-			GFace* fTemp = (*it2);
-			std::list<GVertex*> verticesFace = fTemp->vertices();
-			for (std::list<GVertex*>::iterator it3=verticesFace.begin();it3!=verticesFace.end();it3++){
-				xCenterReg = xCenterReg + (*it3)->x();
-				yCenterReg = yCenterReg + (*it3)->y();
-				zCenterReg = zCenterReg + (*it3)->z();
-				counterPts++;
-			}
-		}
-		xCenterReg = xCenterReg/counterPts;
-		yCenterReg = yCenterReg/counterPts;
-		zCenterReg = zCenterReg/counterPts;
-		//duplication noeud et aretes au niveau de la region directement
-		std::list<GVertex*> vlist;
-
-
-		std::list<GFace*> listFacesTmp = rTmp->faces();
-		for (std::list<GFace*>::iterator itTp = listFacesTmp.begin();itTp != listFacesTmp.end();itTp++){
-			std::list<GVertex*> vlist2;
-			vlist2 = (*itTp)->vertices();
-			for (std::list<GVertex*>::iterator itTp2 = vlist2.begin();itTp2 != vlist2.end();itTp2++){
-				if(std::find(vlist.begin(), vlist.end(), *itTp2) == vlist.end())
-					vlist.push_back(*itTp2);
-			}
-		}
-
-
-		for (std::list<GVertex*>::iterator itv = vlist.begin();itv != vlist.end();itv++){
-			//duplication Gvertex
-			GVertex* vTmp = (*itv);
-			double ponderatedX = 0.99999999999 * vTmp->x() + 0.00000000001 * xCenterReg;
-			double ponderatedY = 0.99999999999 * vTmp->y() + 0.00000000001 * yCenterReg;
-			double ponderatedZ = 0.99999999999 * vTmp->z() + 0.00000000001 * zCenterReg;
-			GVertex* newv = m->addVertex(ponderatedX,ponderatedY,ponderatedZ,vTmp->prescribedMeshSizeAtVertex());
-			GVertexAssociation[vTmp] = newv;
-			GVertexGlobalAssociation[std::make_pair(vTmp,rTmp)] = newv;
-			//creation des Gedge correspondantes
-//			GEdge* newE = m->addLine(vTmp,newv);
-//			SurroudingEdges[vTmp] = newE;
-			//maintenant traitement mesh
-			MVertex *vMesh = vTmp->mesh_vertices[0];
-			MVertex *newMv = new MVertex(vMesh->x(), vMesh->y(), vMesh->z(), (GEntity*)newv);
-			VertexAssociation[vMesh] = newMv;
-			VertexGlobalAssociation[std::make_pair(vMesh,rTmp)] = newMv;
-			newv->addMeshVertex(newMv);
-		}
-		//maintenant on soccupe de duppliquer les edges de la region
-		std::list<GEdge*> elist = rTmp->edges();
-
-		std::vector<GFace*> SurroundingsFaces;
-		for (std::list<GEdge*>::iterator ite = elist.begin();ite != elist.end();ite++){
-			//duplication Gedge
-			GEdge* eTmp = (*ite);
-			GEdge* newE = m->addLine(GVertexAssociation[eTmp->getEndVertex()],GVertexAssociation[eTmp->getBeginVertex()]);
-			GEdgeAssociation[eTmp] = newE;
-			GEdgeGlobalAssociation[std::make_pair(eTmp,rTmp)] = newE;
-			//creation des GFace correspondantes
-//			GEdge* firstE = SurroudingEdges.find(eTmp->getEndVertex())->second;
-//			GEdge* lastE = SurroudingEdges.find(eTmp->getBeginVertex())->second;
-//			std::vector<GEdge*> VecEdgesTmp;
-//			VecEdgesTmp.push_back(eTmp);
-//			VecEdgesTmp.push_back(firstE);
-//			VecEdgesTmp.push_back(newE);
-//			VecEdgesTmp.push_back(lastE);
-//			std::vector<std::vector<GEdge*> > VecOfVecTmp;
-//			VecOfVecTmp.push_back(VecEdgesTmp);
-//			GFace* newFaceTmp = m->addPlanarFace(VecOfVecTmp);
-//			SurroundingsFaces.push_back(newFaceTmp);
-			//maintenant traitement mesh
-			for (unsigned int i = 0; i < eTmp->mesh_vertices.size();i++){
-				MVertex *vMesh = eTmp->mesh_vertices[i];
-				MVertex *newMv = new MVertex(vMesh->x(), vMesh->y(), vMesh->z(), (GEntity*)newE);
-				VertexAssociation[vMesh] = newMv;
-				VertexGlobalAssociation[std::make_pair(vMesh,rTmp)] = newMv;
-				newE->addMeshVertex(newMv);
-			}
-			for (unsigned int i = 0; i < eTmp->getNumMeshElements();i++){
-				MElement* elem = eTmp->getMeshElement(i);
-				MVertex *firstETmp = VertexAssociation.find(elem->getVertex(0))->second;
-				MVertex *lastETmp = VertexAssociation.find(elem->getVertex(1))->second;
-				MLine *newLine = new MLine(firstETmp,lastETmp);
-				newE->addLine(newLine);
-			}
-		}
-		for (std::list<GFace*>::iterator itf = RegFaces.begin();itf != RegFaces.end();itf++){
-			GFace* fTmp = (*itf);
-			std::vector<GEdge*> newEdgesVector;
-			std::list<GEdge*> elistFace = fTmp->edges();
-			for (std::list<GEdge*>::iterator ite = elistFace.begin();ite != elistFace.end();ite++){
-				GEdge* eTmp = (*ite);
-				GEdge* eToFind = GEdgeAssociation[eTmp];
-				newEdgesVector.push_back(eToFind);
-			}
-			std::vector<std::vector<GEdge*> > VecOfVec;
-			VecOfVec.push_back(newEdgesVector);
-			//creation de la nouvelle face
-			GFace* GFaceAssociation = m->addPlanarFace(VecOfVec);
-			//maintenant traitement mesh
-			for (unsigned int i = 0; i < fTmp->mesh_vertices.size();i++){
-				MVertex *vMesh = fTmp->mesh_vertices[i];
-				MVertex *newMv = new MVertex(vMesh->x(), vMesh->y(), vMesh->z(), (GEntity*)GFaceAssociation);
-				VertexAssociation[vMesh] = newMv;
-				VertexGlobalAssociation[std::make_pair(vMesh,rTmp)] = newMv;
-				GFaceAssociation->addMeshVertex(newMv);
-			}
-			for (unsigned int i = 0; i < fTmp->getNumMeshElements();i++){
-				MElement* elem = fTmp->getMeshElement(i);
-				MVertex *firstE = VertexAssociation.find(elem->getVertex(0))->second;
-				MVertex *secondE = VertexAssociation.find(elem->getVertex(1))->second;
-				MVertex *thirdE = VertexAssociation.find(elem->getVertex(2))->second;
-				MTriangle *newTri = new MTriangle(firstE,secondE,thirdE);
-				GFaceAssociation->addTriangle(newTri);
-			}
-			GFaceGlobalAssociation[std::make_pair(fTmp,rTmp)] = GFaceAssociation;
-		}
-	}
-	int counterNbDone = 10000;
-	//maintenant on va traiter les faces initiales
-	for (std::set<GFace*>::iterator itf = ToDuplicateList.begin();itf != ToDuplicateList.end();itf++){
-		counterNbDone++;
-		GFace* fTmp = (*itf);
-		GRegion* reg1 = fTmp->getRegion(0);
-		GRegion* reg2 = fTmp->getRegion(1);
-		//pour commencer on cree des aretes entre les vertex
-		std::list<GVertex*> vlist = fTmp->vertices();
-		std::map<GVertex*,GEdge* > SurroudingEdges;
-		for (std::list<GVertex*>::iterator itv = vlist.begin();itv != vlist.end();itv++){
-			GVertex* vTmp = (*itv);
-			GVertex* v1=0;
-			GVertex* v2=0;
-			std::map<std::pair<GVertex*,GRegion*>,GVertex* >::iterator itMap = GVertexGlobalAssociation.find(std::make_pair(vTmp,reg1));
-			if (itMap != GVertexGlobalAssociation.end()){
-				v1 = itMap->second;
-			}
-			itMap = GVertexGlobalAssociation.find(std::make_pair(vTmp,reg2));
-			if (itMap != GVertexGlobalAssociation.end()){
-				v2 = itMap->second;
-			}
-			GEdge* newE = m->addLine(v1,v2);
-			SurroudingEdges[vTmp] = newE;
-		}
-		//ici tous les vertex sont traites
-		//on va traiter les edges
-		std::list<GEdge*> elist = fTmp->edges();
-		std::vector<GEdge*> newEdgesVector;
-		std::vector<GFace*> SurroundingsFaces;
-		for (std::list<GEdge*>::iterator ite = elist.begin();ite != elist.end();ite++){
-			//duplication Gedge
-			GEdge* eTmp = (*ite);
-			GEdge* e1=0;
-			GEdge* e2=0;
-			std::map<std::pair<GEdge*,GRegion*>,GEdge* >::iterator itMap = GEdgeGlobalAssociation.find(std::make_pair(eTmp,reg1));
-			if (itMap != GEdgeGlobalAssociation.end()){
-				e1 = itMap->second;
-			}
-			itMap = GEdgeGlobalAssociation.find(std::make_pair(eTmp,reg2));
-			if (itMap != GEdgeGlobalAssociation.end()){
-				e2 = itMap->second;
-			}
-			//creation des GFace correspondantes
-			GEdge* firstE = SurroudingEdges.find(eTmp->getBeginVertex())->second;
-			GEdge* lastE = SurroudingEdges.find(eTmp->getEndVertex())->second;
-			if (firstE->getBeginVertex() != e1->getEndVertex()){
-				firstE->reverse();
-			}
-			if (firstE->getBeginVertex() != e1->getEndVertex()){
-				e1->reverse();
-			}
-			if (firstE->getBeginVertex() != e1->getEndVertex()){
-				firstE->reverse();
-			}
-			if (e2->getBeginVertex() != firstE->getEndVertex()){
-				e2->reverse();
-			}
-			if (lastE->getBeginVertex() != e2->getEndVertex()){
-				lastE->reverse();
-			}
-			std::vector<GEdge*> VecEdgesTmp;
-			VecEdgesTmp.push_back(e1);
-			VecEdgesTmp.push_back(firstE);
-			VecEdgesTmp.push_back(e2);
-			VecEdgesTmp.push_back(lastE);
-			std::vector<std::vector<GEdge*> > VecOfVecTmp;
-			VecOfVecTmp.push_back(VecEdgesTmp);
-			GFace* newFaceTmp = m->addPlanarFace(VecOfVecTmp);
-			SurroundingsFaces.push_back(newFaceTmp);
-		}
-		std::vector<GFace*> VectorFaces;
-		std::list<GFace*> listFaces;
-		GFace* f1;
-		GFace* f2;
-		std::map<std::pair<GFace*,GRegion*>,GFace* >::iterator itMap = GFaceGlobalAssociation.find(std::make_pair(fTmp,reg1));
-		if (itMap != GFaceGlobalAssociation.end()){
-			f1 = itMap->second;
-		}
-		itMap = GFaceGlobalAssociation.find(std::make_pair(fTmp,reg2));
-		if (itMap != GFaceGlobalAssociation.end()){
-			f2 = itMap->second;
-		}
-		VectorFaces.push_back(f1);
-		listFaces.push_back(f1);
-		for (unsigned int i = 0;i < SurroundingsFaces.size();i++){
-			VectorFaces.push_back(SurroundingsFaces[i]);
-			listFaces.push_back(SurroundingsFaces[i]);
-		}
-		VectorFaces.push_back(f2);
-		listFaces.push_back(f2);
-		std::vector<std::vector<GFace*> > VecOfVecGFace;
-		VecOfVecGFace.push_back(VectorFaces);
-		//creation de la nouvelle region
-		GRegion* createdRegion = new GRegion(m,counterNbDone);
-		createdRegion->addPhysicalEntity(PhysicalInterface);
-		createdRegion->set(listFaces);
-		m->add(createdRegion);
-		for (unsigned int i = 0; i < fTmp->getNumMeshElements();i++){
-			MElement* elem = fTmp->getMeshElement(i);
-			MVertex* v1=0;
-			MVertex* v2=0;
-			MVertex* v3=0;
-			MVertex* v4=0;
-			MVertex* v5=0;
-			MVertex* v6=0;
-			std::map<std::pair<MVertex*,GRegion*>,MVertex* >::iterator itMap = VertexGlobalAssociation.find(std::make_pair(elem->getVertex(0),reg1));
-			if (itMap != VertexGlobalAssociation.end()){
-				v1 = itMap->second;
-			}
-			itMap = VertexGlobalAssociation.find(std::make_pair(elem->getVertex(1),reg1));
-			if (itMap != VertexGlobalAssociation.end()){
-				v2 = itMap->second;
-			}
-			itMap = VertexGlobalAssociation.find(std::make_pair(elem->getVertex(2),reg1));
-			if (itMap != VertexGlobalAssociation.end()){
-				v3 = itMap->second;
-			}
-			itMap = VertexGlobalAssociation.find(std::make_pair(elem->getVertex(0),reg2));
-			if (itMap != VertexGlobalAssociation.end()){
-				v4 = itMap->second;
-			}
-			itMap = VertexGlobalAssociation.find(std::make_pair(elem->getVertex(1),reg2));
-			if (itMap != VertexGlobalAssociation.end()){
-				v5 = itMap->second;
-			}
-			itMap = VertexGlobalAssociation.find(std::make_pair(elem->getVertex(2),reg2));
-			if (itMap != VertexGlobalAssociation.end()){
-				v6 = itMap->second;
-			}
-			MPrism *newPri = new MPrism(v1,v2,v3,v4,v5,v6);
-
-			createdRegion->addPrism(newPri);
-		}
-		for (unsigned int i = 0; i < reg1->getNumMeshElements();i++){
-			MElement* elem = reg1->getMeshElement(i);
-			for (int j = 0;j < elem->getNumVertices();j++){
-				MVertex* vert = elem->getVertex(j);
-				std::map<std::pair<MVertex*,GRegion*>,MVertex* >::iterator itMap = VertexGlobalAssociation.find(std::make_pair(vert,reg1));
-				if (itMap != VertexGlobalAssociation.end()){
-					elem->setVertex(j,itMap->second);
-				}
-			}
-		}
-		for (unsigned int i = 0; i < reg2->getNumMeshElements();i++){
-			MElement* elem = reg2->getMeshElement(i);
-			for (int j = 0;j < elem->getNumVertices();j++){
-				MVertex* vert = elem->getVertex(j);
-				std::map<std::pair<MVertex*,GRegion*>,MVertex* >::iterator itMap = VertexGlobalAssociation.find(std::make_pair(vert,reg2));
-				if (itMap != VertexGlobalAssociation.end()){
-					elem->setVertex(j,itMap->second);
-				}
-			}
-		}
-	}
-
-	for (std::set<GFace*>::iterator itf = ToDuplicateListBoundary.begin();itf != ToDuplicateListBoundary.end();itf++){
-		GFace* fTmp = (*itf);
-		GRegion* reg1 = fTmp->getRegion(0);
-		std::map<std::pair<GFace*,GRegion*>,GFace* >::iterator itMap = GFaceGlobalAssociation.find(std::make_pair(fTmp,reg1));
-		GFace* f1 = itMap->second;
-		f1->addPhysicalEntity(PhysicalBoundary);
-	}
-
-
-	std::cout<<"End of DuplicateBoundaries"<<std::endl;
-	return view;
+  std::cout<<"starting DuplicateBoundaries"<<std::endl;
+  GModel *m = GModel::current();
+  m->setFactory("geo");
+  std::set<GFace*> ToDuplicateList;
+  ToDuplicateList.clear();
+  std::set<GFace*> ToDuplicateListBoundary;
+  ToDuplicateListBoundary.clear();
+  std::vector<GFace*> facesBound;
+  facesBound.clear();
+  std::map<GFace*,SPoint3> centers;
+  std::vector<std::pair<GFace*,GFace*> > pairs;
+  std::vector<std::pair<GFace*,GFace*> > newPairs;
+  int PhysicalInterface = m->setPhysicalName("Interface",3);
+  int PhysicalBoundary = m->setPhysicalName("Boundary",2);
+  for (GModel::fiter itf= m->firstFace();itf != m->lastFace();itf++){
+    GFace* fTmp = (*itf);
+    if (fTmp->numRegions() == 2){
+      ToDuplicateList.insert(fTmp);
+    }
+    else{
+      ToDuplicateListBoundary.insert(fTmp);
+      facesBound.push_back(fTmp);
+    }
+  }
+
+
+
+
+
+
+
+  std::map<std::pair<MVertex*,GRegion*>,MVertex* > VertexGlobalAssociation;
+  std::map<std::pair<GVertex*,GRegion*>,GVertex* > GVertexGlobalAssociation;
+  std::map<std::pair<GEdge*,GRegion*>,GEdge* > GEdgeGlobalAssociation;
+  std::map<std::pair<GFace*,GRegion*>,GFace* > GFaceGlobalAssociation;
+
+  for (GModel::riter itr= m->firstRegion();itr != m->lastRegion();itr++){
+    GRegion* rTmp = (*itr);
+    std::list<GFace*> RegFaces = rTmp->faces();
+    std::map<MVertex*,MVertex* > VertexAssociation;
+    std::map<GVertex*,GVertex* > GVertexAssociation;
+    std::map<GEdge*,GEdge* > GEdgeAssociation;
+    //int counterNbDone = 10000;
+    double xCenterReg = 0.0;
+    double yCenterReg = 0.0;
+    double zCenterReg = 0.0;
+    int counterPts = 0;
+    for(std::list<GFace*>::iterator it2=RegFaces.begin();it2!=RegFaces.end();it2++){
+      GFace* fTemp = (*it2);
+      std::list<GVertex*> verticesFace = fTemp->vertices();
+      for (std::list<GVertex*>::iterator it3=verticesFace.begin();it3!=verticesFace.end();it3++){
+        xCenterReg = xCenterReg + (*it3)->x();
+        yCenterReg = yCenterReg + (*it3)->y();
+        zCenterReg = zCenterReg + (*it3)->z();
+        counterPts++;
+      }
+    }
+    xCenterReg = xCenterReg/counterPts;
+    yCenterReg = yCenterReg/counterPts;
+    zCenterReg = zCenterReg/counterPts;
+    //duplication noeud et aretes au niveau de la region directement
+    std::list<GVertex*> vlist;
+
+
+    std::list<GFace*> listFacesTmp = rTmp->faces();
+    for (std::list<GFace*>::iterator itTp = listFacesTmp.begin();itTp != listFacesTmp.end();itTp++){
+      std::list<GVertex*> vlist2;
+      vlist2 = (*itTp)->vertices();
+      for (std::list<GVertex*>::iterator itTp2 = vlist2.begin();itTp2 != vlist2.end();itTp2++){
+        if(std::find(vlist.begin(), vlist.end(), *itTp2) == vlist.end())
+          vlist.push_back(*itTp2);
+      }
+    }
+
+
+    for (std::list<GVertex*>::iterator itv = vlist.begin();itv != vlist.end();itv++){
+      //duplication Gvertex
+      GVertex* vTmp = (*itv);
+      double ponderatedX = 0.99999999999 * vTmp->x() + 0.00000000001 * xCenterReg;
+      double ponderatedY = 0.99999999999 * vTmp->y() + 0.00000000001 * yCenterReg;
+      double ponderatedZ = 0.99999999999 * vTmp->z() + 0.00000000001 * zCenterReg;
+      GVertex* newv = m->addVertex(ponderatedX,ponderatedY,ponderatedZ,vTmp->prescribedMeshSizeAtVertex());
+      GVertexAssociation[vTmp] = newv;
+      GVertexGlobalAssociation[std::make_pair(vTmp,rTmp)] = newv;
+      //creation des Gedge correspondantes
+      //			GEdge* newE = m->addLine(vTmp,newv);
+      //			SurroudingEdges[vTmp] = newE;
+      //maintenant traitement mesh
+      MVertex *vMesh = vTmp->mesh_vertices[0];
+      MVertex *newMv = new MVertex(vMesh->x(), vMesh->y(), vMesh->z(), (GEntity*)newv);
+      VertexAssociation[vMesh] = newMv;
+      VertexGlobalAssociation[std::make_pair(vMesh,rTmp)] = newMv;
+      newv->addMeshVertex(newMv);
+    }
+    //maintenant on soccupe de duppliquer les edges de la region
+    std::list<GEdge*> elist = rTmp->edges();
+
+    std::vector<GFace*> SurroundingsFaces;
+    for (std::list<GEdge*>::iterator ite = elist.begin();ite != elist.end();ite++){
+      //duplication Gedge
+      GEdge* eTmp = (*ite);
+      GEdge* newE = m->addLine(GVertexAssociation[eTmp->getEndVertex()],GVertexAssociation[eTmp->getBeginVertex()]);
+      GEdgeAssociation[eTmp] = newE;
+      GEdgeGlobalAssociation[std::make_pair(eTmp,rTmp)] = newE;
+      //creation des GFace correspondantes
+      //			GEdge* firstE = SurroudingEdges.find(eTmp->getEndVertex())->second;
+      //			GEdge* lastE = SurroudingEdges.find(eTmp->getBeginVertex())->second;
+      //			std::vector<GEdge*> VecEdgesTmp;
+      //			VecEdgesTmp.push_back(eTmp);
+      //			VecEdgesTmp.push_back(firstE);
+      //			VecEdgesTmp.push_back(newE);
+      //			VecEdgesTmp.push_back(lastE);
+      //			std::vector<std::vector<GEdge*> > VecOfVecTmp;
+      //			VecOfVecTmp.push_back(VecEdgesTmp);
+      //			GFace* newFaceTmp = m->addPlanarFace(VecOfVecTmp);
+      //			SurroundingsFaces.push_back(newFaceTmp);
+      //maintenant traitement mesh
+      for (unsigned int i = 0; i < eTmp->mesh_vertices.size();i++){
+        MVertex *vMesh = eTmp->mesh_vertices[i];
+        MVertex *newMv = new MVertex(vMesh->x(), vMesh->y(), vMesh->z(), (GEntity*)newE);
+        VertexAssociation[vMesh] = newMv;
+        VertexGlobalAssociation[std::make_pair(vMesh,rTmp)] = newMv;
+        newE->addMeshVertex(newMv);
+      }
+      for (unsigned int i = 0; i < eTmp->getNumMeshElements();i++){
+        MElement* elem = eTmp->getMeshElement(i);
+        MVertex *firstETmp = VertexAssociation.find(elem->getVertex(0))->second;
+        MVertex *lastETmp = VertexAssociation.find(elem->getVertex(1))->second;
+        MLine *newLine = new MLine(firstETmp,lastETmp);
+        newE->addLine(newLine);
+      }
+    }
+    for (std::list<GFace*>::iterator itf = RegFaces.begin();itf != RegFaces.end();itf++){
+      GFace* fTmp = (*itf);
+      std::vector<GEdge*> newEdgesVector;
+      std::list<GEdge*> elistFace = fTmp->edges();
+      for (std::list<GEdge*>::iterator ite = elistFace.begin();ite != elistFace.end();ite++){
+        GEdge* eTmp = (*ite);
+        GEdge* eToFind = GEdgeAssociation[eTmp];
+        newEdgesVector.push_back(eToFind);
+      }
+      std::vector<std::vector<GEdge*> > VecOfVec;
+      VecOfVec.push_back(newEdgesVector);
+      //creation de la nouvelle face
+      GFace* GFaceAssociation = m->addPlanarFace(VecOfVec);
+      //maintenant traitement mesh
+      for (unsigned int i = 0; i < fTmp->mesh_vertices.size();i++){
+        MVertex *vMesh = fTmp->mesh_vertices[i];
+        MVertex *newMv = new MVertex(vMesh->x(), vMesh->y(), vMesh->z(), (GEntity*)GFaceAssociation);
+        VertexAssociation[vMesh] = newMv;
+        VertexGlobalAssociation[std::make_pair(vMesh,rTmp)] = newMv;
+        GFaceAssociation->addMeshVertex(newMv);
+      }
+      for (unsigned int i = 0; i < fTmp->getNumMeshElements();i++){
+        MElement* elem = fTmp->getMeshElement(i);
+        MVertex *firstE = VertexAssociation.find(elem->getVertex(0))->second;
+        MVertex *secondE = VertexAssociation.find(elem->getVertex(1))->second;
+        MVertex *thirdE = VertexAssociation.find(elem->getVertex(2))->second;
+        MTriangle *newTri = new MTriangle(firstE,secondE,thirdE);
+        GFaceAssociation->addTriangle(newTri);
+      }
+      GFaceGlobalAssociation[std::make_pair(fTmp,rTmp)] = GFaceAssociation;
+    }
+  }
+  int counterNbDone = 10000;
+  //maintenant on va traiter les faces initiales
+  for (std::set<GFace*>::iterator itf = ToDuplicateList.begin();itf != ToDuplicateList.end();itf++){
+    counterNbDone++;
+    GFace* fTmp = (*itf);
+    GRegion* reg1 = fTmp->getRegion(0);
+    GRegion* reg2 = fTmp->getRegion(1);
+    //pour commencer on cree des aretes entre les vertex
+    std::list<GVertex*> vlist = fTmp->vertices();
+    std::map<GVertex*,GEdge* > SurroudingEdges;
+    for (std::list<GVertex*>::iterator itv = vlist.begin();itv != vlist.end();itv++){
+      GVertex* vTmp = (*itv);
+      GVertex* v1=0;
+      GVertex* v2=0;
+      std::map<std::pair<GVertex*,GRegion*>,GVertex* >::iterator itMap = GVertexGlobalAssociation.find(std::make_pair(vTmp,reg1));
+      if (itMap != GVertexGlobalAssociation.end()){
+        v1 = itMap->second;
+      }
+      itMap = GVertexGlobalAssociation.find(std::make_pair(vTmp,reg2));
+      if (itMap != GVertexGlobalAssociation.end()){
+        v2 = itMap->second;
+      }
+      GEdge* newE = m->addLine(v1,v2);
+      SurroudingEdges[vTmp] = newE;
+    }
+    //ici tous les vertex sont traites
+    //on va traiter les edges
+    std::list<GEdge*> elist = fTmp->edges();
+    std::vector<GEdge*> newEdgesVector;
+    std::vector<GFace*> SurroundingsFaces;
+    for (std::list<GEdge*>::iterator ite = elist.begin();ite != elist.end();ite++){
+      //duplication Gedge
+      GEdge* eTmp = (*ite);
+      GEdge* e1=0;
+      GEdge* e2=0;
+      std::map<std::pair<GEdge*,GRegion*>,GEdge* >::iterator itMap = GEdgeGlobalAssociation.find(std::make_pair(eTmp,reg1));
+      if (itMap != GEdgeGlobalAssociation.end()){
+        e1 = itMap->second;
+      }
+      itMap = GEdgeGlobalAssociation.find(std::make_pair(eTmp,reg2));
+      if (itMap != GEdgeGlobalAssociation.end()){
+        e2 = itMap->second;
+      }
+      //creation des GFace correspondantes
+      GEdge* firstE = SurroudingEdges.find(eTmp->getBeginVertex())->second;
+      GEdge* lastE = SurroudingEdges.find(eTmp->getEndVertex())->second;
+      if (firstE->getBeginVertex() != e1->getEndVertex()){
+        firstE->reverse();
+      }
+      if (firstE->getBeginVertex() != e1->getEndVertex()){
+        e1->reverse();
+      }
+      if (firstE->getBeginVertex() != e1->getEndVertex()){
+        firstE->reverse();
+      }
+      if (e2->getBeginVertex() != firstE->getEndVertex()){
+        e2->reverse();
+      }
+      if (lastE->getBeginVertex() != e2->getEndVertex()){
+        lastE->reverse();
+      }
+      std::vector<GEdge*> VecEdgesTmp;
+      VecEdgesTmp.push_back(e1);
+      VecEdgesTmp.push_back(firstE);
+      VecEdgesTmp.push_back(e2);
+      VecEdgesTmp.push_back(lastE);
+      std::vector<std::vector<GEdge*> > VecOfVecTmp;
+      VecOfVecTmp.push_back(VecEdgesTmp);
+      GFace* newFaceTmp = m->addPlanarFace(VecOfVecTmp);
+      SurroundingsFaces.push_back(newFaceTmp);
+    }
+    std::vector<GFace*> VectorFaces;
+    std::list<GFace*> listFaces;
+    GFace* f1;
+    GFace* f2;
+    std::map<std::pair<GFace*,GRegion*>,GFace* >::iterator itMap = GFaceGlobalAssociation.find(std::make_pair(fTmp,reg1));
+    if (itMap != GFaceGlobalAssociation.end()){
+      f1 = itMap->second;
+    }
+    itMap = GFaceGlobalAssociation.find(std::make_pair(fTmp,reg2));
+    if (itMap != GFaceGlobalAssociation.end()){
+      f2 = itMap->second;
+    }
+    VectorFaces.push_back(f1);
+    listFaces.push_back(f1);
+    for (unsigned int i = 0;i < SurroundingsFaces.size();i++){
+      VectorFaces.push_back(SurroundingsFaces[i]);
+      listFaces.push_back(SurroundingsFaces[i]);
+    }
+    VectorFaces.push_back(f2);
+    listFaces.push_back(f2);
+    std::vector<std::vector<GFace*> > VecOfVecGFace;
+    VecOfVecGFace.push_back(VectorFaces);
+    //creation de la nouvelle region
+    GRegion* createdRegion = new GRegion(m,counterNbDone);
+    createdRegion->addPhysicalEntity(PhysicalInterface);
+    createdRegion->set(listFaces);
+    m->add(createdRegion);
+    for (unsigned int i = 0; i < fTmp->getNumMeshElements();i++){
+      MElement* elem = fTmp->getMeshElement(i);
+      MVertex* v1=0;
+      MVertex* v2=0;
+      MVertex* v3=0;
+      MVertex* v4=0;
+      MVertex* v5=0;
+      MVertex* v6=0;
+      std::map<std::pair<MVertex*,GRegion*>,MVertex* >::iterator itMap = VertexGlobalAssociation.find(std::make_pair(elem->getVertex(0),reg1));
+      if (itMap != VertexGlobalAssociation.end()){
+        v1 = itMap->second;
+      }
+      itMap = VertexGlobalAssociation.find(std::make_pair(elem->getVertex(1),reg1));
+      if (itMap != VertexGlobalAssociation.end()){
+        v2 = itMap->second;
+      }
+      itMap = VertexGlobalAssociation.find(std::make_pair(elem->getVertex(2),reg1));
+      if (itMap != VertexGlobalAssociation.end()){
+        v3 = itMap->second;
+      }
+      itMap = VertexGlobalAssociation.find(std::make_pair(elem->getVertex(0),reg2));
+      if (itMap != VertexGlobalAssociation.end()){
+        v4 = itMap->second;
+      }
+      itMap = VertexGlobalAssociation.find(std::make_pair(elem->getVertex(1),reg2));
+      if (itMap != VertexGlobalAssociation.end()){
+        v5 = itMap->second;
+      }
+      itMap = VertexGlobalAssociation.find(std::make_pair(elem->getVertex(2),reg2));
+      if (itMap != VertexGlobalAssociation.end()){
+        v6 = itMap->second;
+      }
+      MPrism *newPri = new MPrism(v1,v2,v3,v4,v5,v6);
+
+      createdRegion->addPrism(newPri);
+    }
+    for (unsigned int i = 0; i < reg1->getNumMeshElements();i++){
+      MElement* elem = reg1->getMeshElement(i);
+      for (int j = 0;j < elem->getNumVertices();j++){
+        MVertex* vert = elem->getVertex(j);
+        std::map<std::pair<MVertex*,GRegion*>,MVertex* >::iterator itMap = VertexGlobalAssociation.find(std::make_pair(vert,reg1));
+        if (itMap != VertexGlobalAssociation.end()){
+          elem->setVertex(j,itMap->second);
+        }
+      }
+    }
+    for (unsigned int i = 0; i < reg2->getNumMeshElements();i++){
+      MElement* elem = reg2->getMeshElement(i);
+      for (int j = 0;j < elem->getNumVertices();j++){
+        MVertex* vert = elem->getVertex(j);
+        std::map<std::pair<MVertex*,GRegion*>,MVertex* >::iterator itMap = VertexGlobalAssociation.find(std::make_pair(vert,reg2));
+        if (itMap != VertexGlobalAssociation.end()){
+          elem->setVertex(j,itMap->second);
+        }
+      }
+    }
+  }
+
+  for (std::set<GFace*>::iterator itf = ToDuplicateListBoundary.begin();itf != ToDuplicateListBoundary.end();itf++){
+    GFace* fTmp = (*itf);
+    GRegion* reg1 = fTmp->getRegion(0);
+    std::map<std::pair<GFace*,GRegion*>,GFace* >::iterator itMap = GFaceGlobalAssociation.find(std::make_pair(fTmp,reg1));
+    GFace* f1 = itMap->second;
+    f1->addPhysicalEntity(PhysicalBoundary);
+  }
+
+
+  std::cout<<"End of DuplicateBoundaries"<<std::endl;
+  return view;
 }
 
 PView *GMSH_DuplicateBoundariesPlugin::ComputeBestSeeds(PView *view)
 {
-	std::cout<<"starting DuplicateBoundaries"<<std::endl;
-	GModel *m = GModel::current();
-	m->setFactory("geo");
-	return view;
+  std::cout<<"starting DuplicateBoundaries"<<std::endl;
+  GModel *m = GModel::current();
+  m->setFactory("geo");
+  return view;
 }
-
diff --git a/Plugin/ThinLayerFixMesh.cpp b/Plugin/ThinLayerFixMesh.cpp
index 7a8b786b481b0aa6541ce90045ed4aa8919feed3..270eb394276bfd96fd251633bf89db4cbcadf5c6 100644
--- a/Plugin/ThinLayerFixMesh.cpp
+++ b/Plugin/ThinLayerFixMesh.cpp
@@ -1,9 +1,9 @@
-/*
- * ThinLayerFixMesh.cpp
- *
- *  Created on: Oct 13, 2014
- *      Author: nicolas
- */
+// Gmsh - Copyright (C) 1997-2013 C. Geuzaine, J.-F. Remacle
+//
+// See the LICENSE.txt file for license information. Please report all
+// bugs and problems to the public mailing list <gmsh@geuz.org>.
+//
+// Author: Nicolas Kowalski
 
 #include "ThinLayerFixMesh.h"
 #include "GModel.h"
@@ -13,7 +13,9 @@
 #include "meshGFaceDelaunayInsertion.h"
 #endif
 
-//#include "meshGFace.h"
+const double GMSH_ThinLayerFixMeshPlugin::epsilon = 0.00000000001;
+const double GMSH_ThinLayerFixMeshPlugin::angleMax = 0.9;
+const double GMSH_ThinLayerFixMeshPlugin::distP2PMax = 5.0;
 
 extern "C"
 {
@@ -24,17 +26,8 @@ extern "C"
 }
 
 StringXNumber ThingLayerFixMeshOptions_Number[] = {
-//  {GMSH_FULLRC, "Dimension", NULL, 1.},
-//  {GMSH_FULLRC, "PhysicalGroup", NULL, 1.},
-//  {GMSH_FULLRC, "OpenBoundaryPhysicalGroup", NULL, 0.},
 };
 
-
-
-//GMSH_ThinLayerFixMeshPlugin::GMSH_ThinLayerFixMeshPlugin(){}
-
-//GMSH_ThinLayerFixMeshPlugin::~GMSH_ThinLayerFixMeshPlugin(){}
-
 std::string GMSH_ThinLayerFixMeshPlugin::getHelp() const
 {
   return "Fix the mesh in thin parts";
@@ -54,1007 +47,1006 @@ StringXNumber *GMSH_ThinLayerFixMeshPlugin::getOption(int iopt)
 #if defined(HAVE_MESH)
 
 CorrespVerticesFixMesh::CorrespVerticesFixMesh(){
-//	std::cout<<"started init CorrespVerticesFixMesh"<<std::endl;
-//	this->EndTriangle = faceXtetFM();
-//	this->StartPoint = 0;
-//	this->EndPoint = SPoint3(0.0,0.0,0.0);
-//	this->StartNormal = SVector3(0.0,0.0,0.0);
-//	this->EndNormal = SVector3(0.0,0.0,0.0);
-//	this->distP2P = 0.0;
-//	this->angleProd = 0.0;
-//	this->Active = false;
-//	this->EndTriangleActive = false;
-//	this->IsMaster = false;
-//	this->tagMaster = 0;
-//	std::cout<<"completed init CorrespVerticesFixMesh"<<std::endl;
+  //	std::cout<<"started init CorrespVerticesFixMesh"<<std::endl;
+  //	this->EndTriangle = faceXtetFM();
+  //	this->StartPoint = 0;
+  //	this->EndPoint = SPoint3(0.0,0.0,0.0);
+  //	this->StartNormal = SVector3(0.0,0.0,0.0);
+  //	this->EndNormal = SVector3(0.0,0.0,0.0);
+  //	this->distP2P = 0.0;
+  //	this->angleProd = 0.0;
+  //	this->Active = false;
+  //	this->EndTriangleActive = false;
+  //	this->IsMaster = false;
+  //	this->tagMaster = 0;
+  //	std::cout<<"completed init CorrespVerticesFixMesh"<<std::endl;
 }
 CorrespVerticesFixMesh::~CorrespVerticesFixMesh(){}
 void CorrespVerticesFixMesh::setStartPoint(MVertex* v){
-	this->StartPoint = v;
+  this->StartPoint = v;
 }
 void CorrespVerticesFixMesh::setEndPoint(SPoint3 p){
-	this->EndPoint = p;
+  this->EndPoint = p;
 }
 void CorrespVerticesFixMesh::setStartNormal(SVector3 v){
-	this->StartNormal = v;
+  this->StartNormal = v;
 }
 void CorrespVerticesFixMesh::setEndNormal(SVector3 v){
-	this->EndNormal = v;
+  this->EndNormal = v;
 }
 //void CorrespVerticesFixMesh::setEndTriangle(faceXtetFM f){
 //	this->EndTriangle(f.t1,f.i1);
 //}
 void CorrespVerticesFixMesh::setEndTrianglePoint1(MVertex* v){
-	this->EndTrianglePoint1 = v;
+  this->EndTrianglePoint1 = v;
 }
 void CorrespVerticesFixMesh::setEndTrianglePoint2(MVertex* v){
-	this->EndTrianglePoint2 = v;
+  this->EndTrianglePoint2 = v;
 }
 void CorrespVerticesFixMesh::setEndTrianglePoint3(MVertex* v){
-	this->EndTrianglePoint3 = v;
+  this->EndTrianglePoint3 = v;
 }
 void CorrespVerticesFixMesh::setdistP2P(double d){
-	this->distP2P = d;
+  this->distP2P = d;
 }
 void CorrespVerticesFixMesh::setangleProd(double a){
-	this->angleProd = a;
+  this->angleProd = a;
 }
 void CorrespVerticesFixMesh::setActive(bool b){
-	this->Active = b;
+  this->Active = b;
 }
 void CorrespVerticesFixMesh::setEndTriangleActive(bool b){
-	this->EndTriangleActive = b;
+  this->EndTriangleActive = b;
 }
 void CorrespVerticesFixMesh::setIsMaster(bool b){
-	this->IsMaster = b;
+  this->IsMaster = b;
 }
 void CorrespVerticesFixMesh::setTagMaster(int i){
-	this->tagMaster = i;
+  this->tagMaster = i;
 }
 MVertex* CorrespVerticesFixMesh::getStartPoint(){
-	return StartPoint;
+  return StartPoint;
 }
 SPoint3 CorrespVerticesFixMesh::getEndPoint(){
-	return EndPoint;
+  return EndPoint;
 }
 SVector3 CorrespVerticesFixMesh::getStartNormal(){
-	return StartNormal;
+  return StartNormal;
 }
 SVector3 CorrespVerticesFixMesh::getEndNormal(){
-	return EndNormal;
+  return EndNormal;
 }
 //faceXtetFM CorrespVerticesFixMesh::getEndTriangle(){
 //	return EndTriangle;
 //}
 MVertex* CorrespVerticesFixMesh::getEndTrianglePoint1(){
-	return EndTrianglePoint1;
+  return EndTrianglePoint1;
 }
 MVertex* CorrespVerticesFixMesh::getEndTrianglePoint2(){
-	return EndTrianglePoint2;
+  return EndTrianglePoint2;
 }
 MVertex* CorrespVerticesFixMesh::getEndTrianglePoint3(){
-	return EndTrianglePoint3;
+  return EndTrianglePoint3;
 }
 double CorrespVerticesFixMesh::getdistP2P(){
-	return distP2P;
+  return distP2P;
 }
 double CorrespVerticesFixMesh::getangleProd(){
-	return angleProd;
+  return angleProd;
 }
 bool CorrespVerticesFixMesh::getActive(){
-	return Active;
+  return Active;
 }
 bool CorrespVerticesFixMesh::getEndTriangleActive(){
-	return EndTriangleActive;
+  return EndTriangleActive;
 }
 bool CorrespVerticesFixMesh::getIsMaster(){
-	return IsMaster;
+  return IsMaster;
 }
 int CorrespVerticesFixMesh::getTagMaster(){
-	return tagMaster;
+  return tagMaster;
 }
 
 
-
 PView *GMSH_ThinLayerFixMeshPlugin::execute(PView *view)
 {
-	GModel *m = GModel::current();
-	GMSH_ThinLayerFixMeshPlugin::perform();
-//	if (m->getDim() == 3){
-//		view = GMSH_DuplicateBoundariesPlugin::executeDuplicate(view);
-//	}
-//	else if (m->getDim() == 2){
-//		view = GMSH_DuplicateBoundariesPlugin::execute2DWithBound(view);
-//	}
-	return view;
+  // GModel *m = GModel::current();
+  GMSH_ThinLayerFixMeshPlugin::perform();
+  //	if (m->getDim() == 3){
+  //		view = GMSH_DuplicateBoundariesPlugin::executeDuplicate(view);
+  //	}
+  //	else if (m->getDim() == 2){
+  //		view = GMSH_DuplicateBoundariesPlugin::execute2DWithBound(view);
+  //	}
+  return view;
 }
 
 void GMSH_ThinLayerFixMeshPlugin::perform(){
-	VertexToTets.clear();
-	TetToTet4.clear();
-	VertexToCorresp.clear();
-	vecOfThinSheets.clear();
-	GMSH_ThinLayerFixMeshPlugin::fillVertexToTets();
-	GMSH_ThinLayerFixMeshPlugin::fillTetToTet4();
-	//std::cout<<"computeAllDistToOppSide"<<std::endl;
-	std::map<MVertex*,double> AllDist = GMSH_ThinLayerFixMeshPlugin::computeAllDistToOppSide();
-	for (std::map<MVertex*,double>::iterator allDistIt = AllDist.begin();allDistIt != AllDist.end();allDistIt++){
-		//std::cout<<"allDist of point "<<(*allDistIt).first->getNum()<<" with Pos "<<(*allDistIt).first->x()<<" ; "<<(*allDistIt).first->z()<<" ; "<<(*allDistIt).first->y()<<" is "<<(*allDistIt).second<<std::endl;
-		//std::cout<<"   Size of vertexToCorresp "<<VertexToCorresp[(*allDistIt).first].size()<<std::endl;
-//		//std::cout<<"      Testing FaceXTet out of while fourth time "<<VertexToCorresp[(*allDistIt).first][VertexToCorresp[(*allDistIt).first].size() - 1]->getEndTriangle().t1->tet()->getNum()<<std::endl;
-		//std::cout<<"      Testing StartPoint "<<VertexToCorresp[(*allDistIt).first][VertexToCorresp[(*allDistIt).first].size() - 1]->getStartPoint()->getNum()<<std::endl;
-		//std::cout<<"      Testing StartNormal "<<VertexToCorresp[(*allDistIt).first][VertexToCorresp[(*allDistIt).first].size() - 1]->getStartNormal().norm()<<std::endl;
-	}
-	//std::cout<<"checkOppositeTriangles !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!"<<std::endl;
-	GMSH_ThinLayerFixMeshPlugin::checkOppositeTriangles();
-	//std::cout<<"fillvecOfThinSheets !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!"<<std::endl;
-	GMSH_ThinLayerFixMeshPlugin::fillvecOfThinSheets();
-	//std::cout<<"Out of fillvecOfThinSheets"<<std::endl;
-//	std::set<MVertex*> constr_vertices;
-	for (unsigned int i = 0;i < vecOfThinSheets.size();i++){
-		if (vecOfThinSheets[i].size() > 1){
-			GFace* OnSurf;
-			for (unsigned int j = 0;j < vecOfThinSheets[i].size();j++){
-				//find a point on the surface
-				MVertex* vertOnSurf = vecOfThinSheets[i][j]->getEndTrianglePoint1();
-				if (vertOnSurf->onWhat()->dim() < 2){
-					vertOnSurf = vecOfThinSheets[i][j]->getEndTrianglePoint2();
-				}
-				if (vertOnSurf->onWhat()->dim() < 2){
-					vertOnSurf = vecOfThinSheets[i][j]->getEndTrianglePoint3();
-				}
-				OnSurf = dynamic_cast<GFace*>(vertOnSurf->onWhat());
-				SPoint2 ParOnSurf = OnSurf->parFromPoint(vecOfThinSheets[i][j]->getEndPoint(),1);
-				MVertex* StartPo = vecOfThinSheets[i][j]->getStartPoint();
-				double param1 = 0.0;
-				double param2 = 0.0;
-				StartPo->getParameter(0,param1);
-				StartPo->getParameter(1,param2);
-				//std::cout<<" PointBegin is "<<StartPo->x()<<" ; "<<StartPo->y()<<" ; "<<StartPo->z()<<" with param "<<param1<<" ; "<<param2<<std::endl;
-				//std::cout<<"insertion of point "<<vecOfThinSheets[i][j]->getEndPoint().x()<<" ; "<<vecOfThinSheets[i][j]->getEndPoint().y()<<" ; "<<vecOfThinSheets[i][j]->getEndPoint().z()<<" with param "<<ParOnSurf.x()<<" ; "<<ParOnSurf.y()<<std::endl;
-				MFaceVertex *v = new MFaceVertex(vecOfThinSheets[i][j]->getEndPoint().x(),vecOfThinSheets[i][j]->getEndPoint().y(),vecOfThinSheets[i][j]->getEndPoint().z(),OnSurf,ParOnSurf.x(),ParOnSurf.y());
-				OnSurf->setMeshingAlgo(ALGO_2D_PACK_PRLGRMS_CSTR);
-				OnSurf->constr_vertices.insert(v);
-//				OnSurf->addMeshVertex(v);
-//				constr_vertices.insert(v);
-				//std::cout<<"inserted point with tag "<<v->getNum()<<" on surface "<<OnSurf->tag()<<std::endl;
-			}
-//			OnSurf->setMeshingAlgo(ALGO_2D_PACK_PRLGRMS_CSTR);
-//			OnSurf->GFace::deleteMesh();
-//			buildBackGroundMesh (OnSurf);
-//			meshGFace::modifyInitialMeshForTakingIntoAccountBoundaryLayers(OnSurf);
-//			OnSurf->meshStatistics.status = GFace::PENDING;
-//			OnSurf->meshStatistics.nbTriangle = OnSurf->meshStatistics.nbEdge = 0;
-//			OnSurf->correspondingVertices.clear();
-//			std::map<MVertex* , MVertex*>* equivalence;
-//			std::map<MVertex*, SPoint2> * parametricCoordinates;
-//			bowyerWatsonParallelogramsConstrained(OnSurf,constr_vertices);
-		}
-//		constr_vertices.clear();
-	}
-	for (std::map<MVertex*,std::vector<CorrespVerticesFixMesh*> >::iterator it1 = VertexToCorresp.begin();it1 != VertexToCorresp.end();it1++){
-		std::vector<CorrespVerticesFixMesh*> vecCorr = (*it1).second;
-		for (unsigned int i = 0;i < vecCorr.size();i++){
-			delete vecCorr[i];
-		}
-	}
+  VertexToTets.clear();
+  TetToTet4.clear();
+  VertexToCorresp.clear();
+  vecOfThinSheets.clear();
+  GMSH_ThinLayerFixMeshPlugin::fillVertexToTets();
+  GMSH_ThinLayerFixMeshPlugin::fillTetToTet4();
+  //std::cout<<"computeAllDistToOppSide"<<std::endl;
+  std::map<MVertex*,double> AllDist = GMSH_ThinLayerFixMeshPlugin::computeAllDistToOppSide();
+  for (std::map<MVertex*,double>::iterator allDistIt = AllDist.begin();allDistIt != AllDist.end();allDistIt++){
+    //std::cout<<"allDist of point "<<(*allDistIt).first->getNum()<<" with Pos "<<(*allDistIt).first->x()<<" ; "<<(*allDistIt).first->z()<<" ; "<<(*allDistIt).first->y()<<" is "<<(*allDistIt).second<<std::endl;
+    //std::cout<<"   Size of vertexToCorresp "<<VertexToCorresp[(*allDistIt).first].size()<<std::endl;
+    //		//std::cout<<"      Testing FaceXTet out of while fourth time "<<VertexToCorresp[(*allDistIt).first][VertexToCorresp[(*allDistIt).first].size() - 1]->getEndTriangle().t1->tet()->getNum()<<std::endl;
+    //std::cout<<"      Testing StartPoint "<<VertexToCorresp[(*allDistIt).first][VertexToCorresp[(*allDistIt).first].size() - 1]->getStartPoint()->getNum()<<std::endl;
+    //std::cout<<"      Testing StartNormal "<<VertexToCorresp[(*allDistIt).first][VertexToCorresp[(*allDistIt).first].size() - 1]->getStartNormal().norm()<<std::endl;
+  }
+  //std::cout<<"checkOppositeTriangles !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!"<<std::endl;
+  GMSH_ThinLayerFixMeshPlugin::checkOppositeTriangles();
+  //std::cout<<"fillvecOfThinSheets !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!"<<std::endl;
+  GMSH_ThinLayerFixMeshPlugin::fillvecOfThinSheets();
+  //std::cout<<"Out of fillvecOfThinSheets"<<std::endl;
+  //	std::set<MVertex*> constr_vertices;
+  for (unsigned int i = 0;i < vecOfThinSheets.size();i++){
+    if (vecOfThinSheets[i].size() > 1){
+      GFace* OnSurf;
+      for (unsigned int j = 0;j < vecOfThinSheets[i].size();j++){
+        //find a point on the surface
+        MVertex* vertOnSurf = vecOfThinSheets[i][j]->getEndTrianglePoint1();
+        if (vertOnSurf->onWhat()->dim() < 2){
+          vertOnSurf = vecOfThinSheets[i][j]->getEndTrianglePoint2();
+        }
+        if (vertOnSurf->onWhat()->dim() < 2){
+          vertOnSurf = vecOfThinSheets[i][j]->getEndTrianglePoint3();
+        }
+        OnSurf = dynamic_cast<GFace*>(vertOnSurf->onWhat());
+        SPoint2 ParOnSurf = OnSurf->parFromPoint(vecOfThinSheets[i][j]->getEndPoint(),1);
+        MVertex* StartPo = vecOfThinSheets[i][j]->getStartPoint();
+        double param1 = 0.0;
+        double param2 = 0.0;
+        StartPo->getParameter(0,param1);
+        StartPo->getParameter(1,param2);
+        //std::cout<<" PointBegin is "<<StartPo->x()<<" ; "<<StartPo->y()<<" ; "<<StartPo->z()<<" with param "<<param1<<" ; "<<param2<<std::endl;
+        //std::cout<<"insertion of point "<<vecOfThinSheets[i][j]->getEndPoint().x()<<" ; "<<vecOfThinSheets[i][j]->getEndPoint().y()<<" ; "<<vecOfThinSheets[i][j]->getEndPoint().z()<<" with param "<<ParOnSurf.x()<<" ; "<<ParOnSurf.y()<<std::endl;
+        MFaceVertex *v = new MFaceVertex(vecOfThinSheets[i][j]->getEndPoint().x(),vecOfThinSheets[i][j]->getEndPoint().y(),vecOfThinSheets[i][j]->getEndPoint().z(),OnSurf,ParOnSurf.x(),ParOnSurf.y());
+        OnSurf->setMeshingAlgo(ALGO_2D_PACK_PRLGRMS_CSTR);
+        OnSurf->constr_vertices.insert(v);
+        //				OnSurf->addMeshVertex(v);
+        //				constr_vertices.insert(v);
+        //std::cout<<"inserted point with tag "<<v->getNum()<<" on surface "<<OnSurf->tag()<<std::endl;
+      }
+      //			OnSurf->setMeshingAlgo(ALGO_2D_PACK_PRLGRMS_CSTR);
+      //			OnSurf->GFace::deleteMesh();
+      //			buildBackGroundMesh (OnSurf);
+      //			meshGFace::modifyInitialMeshForTakingIntoAccountBoundaryLayers(OnSurf);
+      //			OnSurf->meshStatistics.status = GFace::PENDING;
+      //			OnSurf->meshStatistics.nbTriangle = OnSurf->meshStatistics.nbEdge = 0;
+      //			OnSurf->correspondingVertices.clear();
+      //			std::map<MVertex* , MVertex*>* equivalence;
+      //			std::map<MVertex*, SPoint2> * parametricCoordinates;
+      //			bowyerWatsonParallelogramsConstrained(OnSurf,constr_vertices);
+    }
+    //		constr_vertices.clear();
+  }
+  for (std::map<MVertex*,std::vector<CorrespVerticesFixMesh*> >::iterator it1 = VertexToCorresp.begin();it1 != VertexToCorresp.end();it1++){
+    std::vector<CorrespVerticesFixMesh*> vecCorr = (*it1).second;
+    for (unsigned int i = 0;i < vecCorr.size();i++){
+      delete vecCorr[i];
+    }
+  }
 }
 
 void GMSH_ThinLayerFixMeshPlugin::checkOppositeTriangles(){
-	//all endTriangle will be set to active or not
-	for (std::map<MVertex*,std::vector<CorrespVerticesFixMesh*> >::iterator it1 = VertexToCorresp.begin();it1 != VertexToCorresp.end();it1++){
-//		std::cout<<"   Entering For"<<std::endl;
-		MVertex* vertTmp = (*it1).first;
-		//std::cout<<"   Vert Tested is "<<vertTmp->getNum()<<" and its vector size is "<<(*it1).second.size()<<" pos "<<vertTmp->x()<<" ; "<<vertTmp->y()<<" ; "<<vertTmp->z()<<std::endl;
-		std::vector<CorrespVerticesFixMesh*> vecCorr = (*it1).second;
-		for (unsigned int i = 0;i < vecCorr.size();i++){
-			//std::cout<<"      Entering deeper For"<<std::endl;
-			CorrespVerticesFixMesh* currentCorr = vecCorr[i];
-//			std::cout<<"      Step 1"<<std::endl;
-//			faceXtetFM currentEndTri = (*(currentCorr->getEndTriangle()));
-//			std::cout<<"      Step 2"<<std::endl;
-			MVertex* endP0 = currentCorr->getEndTrianglePoint1();
-//			std::cout<<"      Step 3"<<std::endl;
-			MVertex* endP1 = currentCorr->getEndTrianglePoint2();
-//			std::cout<<"      Step 4"<<std::endl;
-			MVertex* endP2 = currentCorr->getEndTrianglePoint3();
-//			std::cout<<"      Step 5"<<std::endl;
-			std::map<MVertex*,std::vector<CorrespVerticesFixMesh*> >::iterator it2 = VertexToCorresp.find(endP0);
-//			std::cout<<"      Step 6 ?"<<std::endl;
-//			std::cout<<"      Tet is "<<currentCorr->getEndTriangle().t1->tet()->getNum()<<std::endl;
-//			std::cout<<"      Face number is "<<currentCorr->getEndTriangle().i1<<std::endl;
-//			std::cout<<"      Tet is made of vertex 0 "<<currentCorr->getEndTriangle().t1->tet()->getVertex(0)->getNum()<<std::endl;
-//			std::cout<<"      Tet is made of vertex 1 "<<currentCorr->getEndTriangle().t1->tet()->getVertex(1)->getNum()<<std::endl;
-//			std::cout<<"      Tet is made of vertex 2 "<<currentCorr->getEndTriangle().t1->tet()->getVertex(2)->getNum()<<std::endl;
-//			std::cout<<"      Tet is made of vertex 3 "<<currentCorr->getEndTriangle().t1->tet()->getVertex(3)->getNum()<<std::endl;
-//			std::cout<<"      Adresses of endP0 "<<endP0<<" and endP1 "<<endP1<<" and endP2 "<<endP2<<std::endl;
-			//std::cout<<"      endP0 is "<<endP0->getNum()<<" pos "<<endP0->x()<<" ; "<<endP0->y()<<" ; "<<endP0->z()<<std::endl;
-//			std::cout<<"      Step 6"<<std::endl;
-			std::map<MVertex*,std::vector<CorrespVerticesFixMesh*> >::iterator it3 = VertexToCorresp.find(endP1);
-			//std::cout<<"      endP1 is "<<endP1->getNum()<<" pos "<<endP1->x()<<" ; "<<endP1->y()<<" ; "<<endP1->z()<<std::endl;
-//			std::cout<<"      Step 7"<<std::endl;
-			std::map<MVertex*,std::vector<CorrespVerticesFixMesh*> >::iterator it4 = VertexToCorresp.find(endP2);
-			//std::cout<<"      endP2 is "<<endP2->getNum()<<" pos "<<endP2->x()<<" ; "<<endP2->y()<<" ; "<<endP2->z()<<std::endl;
-//			std::cout<<"      Step 8"<<std::endl;
-			(*it1).second[i]->setEndTriangleActive(false);
-			//std::cout<<"      Starting tests"<<std::endl;
-			bool test0 = false;
-			bool test1 = false;
-			bool test2 = false;
-			if (endP0->onWhat()->dim() < 2){
-				test0 = true;
-				//std::cout<<"         test0 true by dim"<<std::endl;
-			}
-			if (endP1->onWhat()->dim() < 2){
-				test1 = true;
-				//std::cout<<"         test1 true by dim"<<std::endl;
-			}
-			if (endP2->onWhat()->dim() < 2){
-				test2 = true;
-				//std::cout<<"         test2 true by dim"<<std::endl;
-			}
-			if (it2 != VertexToCorresp.end()){
-				if ((*it2).second.size() > 0){
-					if ((*it2).second[0]->getActive()){
-						test0 = true;
-						//std::cout<<"         test0 true by active"<<std::endl;
-					}
-				}
-			}
-			if (it3 != VertexToCorresp.end()){
-				if ((*it3).second.size() > 0){
-					if ((*it3).second[0]->getActive()){
-						test1 = true;
-						//std::cout<<"         test1 true by active"<<std::endl;
-					}
-				}
-			}
-			if (it4 != VertexToCorresp.end()){
-				if ((*it4).second.size() > 0){
-					if ((*it4).second[0]->getActive()){
-						test2 = true;
-						//std::cout<<"         test2 true by active"<<std::endl;
-					}
-				}
-			}
-			if (test0){
-				if (test1){
-					if (test2){
-						(*it1).second[i]->setEndTriangleActive(true);
-						//std::cout<<"                        EndTriangle Activated"<<std::endl;
-					}
-				}
-			}
-//			if (it2 != VertexToCorresp.end()){
-////				std::cout<<"         Passed Number 1"<<std::endl;
-//				if (it3 != VertexToCorresp.end()){
-////					std::cout<<"            Passed Number 2"<<std::endl;
-//					if (it4 != VertexToCorresp.end()){
-////						std::cout<<"               Passed Number 3"<<std::endl;
-//						if (((*it2).second.size() > 0)  || (endP0->onWhat()->dim() < 2)){
-//							std::cout<<"         Passed Number 1 Bis"<<std::endl;
-//							if (((*it3).second.size() > 0)  || (endP1->onWhat()->dim() < 2)){
-//								std::cout<<"            Passed Number 2 Bis"<<std::endl;
-//								if (((*it4).second.size() > 0)  || (endP2->onWhat()->dim() < 2)){
-//									std::cout<<"               Passed Number 3 Bis"<<std::endl;
-//									if (((*it2).second[0]->getActive()) || (endP0->onWhat()->dim() < 2)){
-//										std::cout<<"                  Passed Number 4"<<std::endl;
-//										if (((*it3).second[0]->getActive()) || (endP1->onWhat()->dim() < 2)){
-//											std::cout<<"                     Passed Number 5"<<std::endl;
-//											if (((*it4).second[0]->getActive()) || (endP2->onWhat()->dim() < 2)){
-//												std::cout<<"                        Passed Number 6"<<std::endl;
-//												(*it1).second[i]->setEndTriangleActive(true);
-//											}
-//										}
-//									}
-//								}
-//							}
-//						}
-//					}
-//				}
-//			}
-			//std::cout<<"      Exiting out of deeper For"<<std::endl;
-		}
-//		std::cout<<"   Getting Out Of For"<<std::endl;
-	}
+  //all endTriangle will be set to active or not
+  for (std::map<MVertex*,std::vector<CorrespVerticesFixMesh*> >::iterator it1 = VertexToCorresp.begin();it1 != VertexToCorresp.end();it1++){
+    //		std::cout<<"   Entering For"<<std::endl;
+    // MVertex* vertTmp = (*it1).first;
+    //std::cout<<"   Vert Tested is "<<vertTmp->getNum()<<" and its vector size is "<<(*it1).second.size()<<" pos "<<vertTmp->x()<<" ; "<<vertTmp->y()<<" ; "<<vertTmp->z()<<std::endl;
+    std::vector<CorrespVerticesFixMesh*> vecCorr = (*it1).second;
+    for (unsigned int i = 0;i < vecCorr.size();i++){
+      //std::cout<<"      Entering deeper For"<<std::endl;
+      CorrespVerticesFixMesh* currentCorr = vecCorr[i];
+      //			std::cout<<"      Step 1"<<std::endl;
+      //			faceXtetFM currentEndTri = (*(currentCorr->getEndTriangle()));
+      //			std::cout<<"      Step 2"<<std::endl;
+      MVertex* endP0 = currentCorr->getEndTrianglePoint1();
+      //			std::cout<<"      Step 3"<<std::endl;
+      MVertex* endP1 = currentCorr->getEndTrianglePoint2();
+      //			std::cout<<"      Step 4"<<std::endl;
+      MVertex* endP2 = currentCorr->getEndTrianglePoint3();
+      //			std::cout<<"      Step 5"<<std::endl;
+      std::map<MVertex*,std::vector<CorrespVerticesFixMesh*> >::iterator it2 = VertexToCorresp.find(endP0);
+      //			std::cout<<"      Step 6 ?"<<std::endl;
+      //			std::cout<<"      Tet is "<<currentCorr->getEndTriangle().t1->tet()->getNum()<<std::endl;
+      //			std::cout<<"      Face number is "<<currentCorr->getEndTriangle().i1<<std::endl;
+      //			std::cout<<"      Tet is made of vertex 0 "<<currentCorr->getEndTriangle().t1->tet()->getVertex(0)->getNum()<<std::endl;
+      //			std::cout<<"      Tet is made of vertex 1 "<<currentCorr->getEndTriangle().t1->tet()->getVertex(1)->getNum()<<std::endl;
+      //			std::cout<<"      Tet is made of vertex 2 "<<currentCorr->getEndTriangle().t1->tet()->getVertex(2)->getNum()<<std::endl;
+      //			std::cout<<"      Tet is made of vertex 3 "<<currentCorr->getEndTriangle().t1->tet()->getVertex(3)->getNum()<<std::endl;
+      //			std::cout<<"      Adresses of endP0 "<<endP0<<" and endP1 "<<endP1<<" and endP2 "<<endP2<<std::endl;
+      //std::cout<<"      endP0 is "<<endP0->getNum()<<" pos "<<endP0->x()<<" ; "<<endP0->y()<<" ; "<<endP0->z()<<std::endl;
+      //			std::cout<<"      Step 6"<<std::endl;
+      std::map<MVertex*,std::vector<CorrespVerticesFixMesh*> >::iterator it3 = VertexToCorresp.find(endP1);
+      //std::cout<<"      endP1 is "<<endP1->getNum()<<" pos "<<endP1->x()<<" ; "<<endP1->y()<<" ; "<<endP1->z()<<std::endl;
+      //			std::cout<<"      Step 7"<<std::endl;
+      std::map<MVertex*,std::vector<CorrespVerticesFixMesh*> >::iterator it4 = VertexToCorresp.find(endP2);
+      //std::cout<<"      endP2 is "<<endP2->getNum()<<" pos "<<endP2->x()<<" ; "<<endP2->y()<<" ; "<<endP2->z()<<std::endl;
+      //			std::cout<<"      Step 8"<<std::endl;
+      (*it1).second[i]->setEndTriangleActive(false);
+      //std::cout<<"      Starting tests"<<std::endl;
+      bool test0 = false;
+      bool test1 = false;
+      bool test2 = false;
+      if (endP0->onWhat()->dim() < 2){
+        test0 = true;
+        //std::cout<<"         test0 true by dim"<<std::endl;
+      }
+      if (endP1->onWhat()->dim() < 2){
+        test1 = true;
+        //std::cout<<"         test1 true by dim"<<std::endl;
+      }
+      if (endP2->onWhat()->dim() < 2){
+        test2 = true;
+        //std::cout<<"         test2 true by dim"<<std::endl;
+      }
+      if (it2 != VertexToCorresp.end()){
+        if ((*it2).second.size() > 0){
+          if ((*it2).second[0]->getActive()){
+            test0 = true;
+            //std::cout<<"         test0 true by active"<<std::endl;
+          }
+        }
+      }
+      if (it3 != VertexToCorresp.end()){
+        if ((*it3).second.size() > 0){
+          if ((*it3).second[0]->getActive()){
+            test1 = true;
+            //std::cout<<"         test1 true by active"<<std::endl;
+          }
+        }
+      }
+      if (it4 != VertexToCorresp.end()){
+        if ((*it4).second.size() > 0){
+          if ((*it4).second[0]->getActive()){
+            test2 = true;
+            //std::cout<<"         test2 true by active"<<std::endl;
+          }
+        }
+      }
+      if (test0){
+        if (test1){
+          if (test2){
+            (*it1).second[i]->setEndTriangleActive(true);
+            //std::cout<<"                        EndTriangle Activated"<<std::endl;
+          }
+        }
+      }
+      //			if (it2 != VertexToCorresp.end()){
+      ////				std::cout<<"         Passed Number 1"<<std::endl;
+      //				if (it3 != VertexToCorresp.end()){
+      ////					std::cout<<"            Passed Number 2"<<std::endl;
+      //					if (it4 != VertexToCorresp.end()){
+      ////						std::cout<<"               Passed Number 3"<<std::endl;
+      //						if (((*it2).second.size() > 0)  || (endP0->onWhat()->dim() < 2)){
+      //							std::cout<<"         Passed Number 1 Bis"<<std::endl;
+      //							if (((*it3).second.size() > 0)  || (endP1->onWhat()->dim() < 2)){
+      //								std::cout<<"            Passed Number 2 Bis"<<std::endl;
+      //								if (((*it4).second.size() > 0)  || (endP2->onWhat()->dim() < 2)){
+      //									std::cout<<"               Passed Number 3 Bis"<<std::endl;
+      //									if (((*it2).second[0]->getActive()) || (endP0->onWhat()->dim() < 2)){
+      //										std::cout<<"                  Passed Number 4"<<std::endl;
+      //										if (((*it3).second[0]->getActive()) || (endP1->onWhat()->dim() < 2)){
+      //											std::cout<<"                     Passed Number 5"<<std::endl;
+      //											if (((*it4).second[0]->getActive()) || (endP2->onWhat()->dim() < 2)){
+      //												std::cout<<"                        Passed Number 6"<<std::endl;
+      //												(*it1).second[i]->setEndTriangleActive(true);
+      //											}
+      //										}
+      //									}
+      //								}
+      //							}
+      //						}
+      //					}
+      //				}
+      //			}
+      //std::cout<<"      Exiting out of deeper For"<<std::endl;
+    }
+    //		std::cout<<"   Getting Out Of For"<<std::endl;
+  }
 }
 
 void GMSH_ThinLayerFixMeshPlugin::fillvecOfThinSheets(){
-	for (std::map<MVertex*,std::vector<CorrespVerticesFixMesh*> >::iterator it1 = VertexToCorresp.begin();it1 != VertexToCorresp.end();it1++){
-		MVertex* vertTmp = (*it1).first;
-		std::vector<CorrespVerticesFixMesh*> vecCorr = (*it1).second;
-		for (unsigned int i = 0;i < vecCorr.size();i++){
-			CorrespVerticesFixMesh* currentCorr = vecCorr[i];
-			//std::cout<<"going to test vecCorr["<<i<<"]"<<" vertex "<<currentCorr->getStartPoint()->getNum()<<" and pos "<<currentCorr->getStartPoint()->x()<<" ; "<<currentCorr->getStartPoint()->y()<<" ; "<<currentCorr->getStartPoint()->z()<<std::endl;
-			if (currentCorr->getStartPoint()->onWhat()->dim() == 2)
-				//std::cout<<"On a surface ; ";
-			if (currentCorr->getActive())
-				//std::cout<<"Is active ; ";
-			if (currentCorr->getEndTriangleActive())
-				//std::cout<<"End Triangle active ; ";
-			if (currentCorr->getTagMaster() == (-2))
-				//std::cout<<"Has yet to be used ; ";
-			//std::cout<<std::endl;
-			if ((currentCorr->getStartPoint()->onWhat()->dim() == 2) && (currentCorr->getActive()) && (currentCorr->getEndTriangleActive()) && (currentCorr->getTagMaster() == (-2))){
-				//Found the first node of a new master sheet
-				//std::cout<<"entering a new master sheet !"<<std::endl;
-				std::vector<CorrespVerticesFixMesh*> MasterSheet;
-				MasterSheet.clear();
-				(*it1).second[i]->setTagMaster(-1);
-//				faceXtetFM faceEndSlave = (*((*it1).second[i]->getEndTriangle()));
-//				faceXtetFM faceEndSlave = ((*it1).second[i]->getEndTriangle());
-				{
-					std::map<MVertex*,std::vector<CorrespVerticesFixMesh*> >::iterator it2 = VertexToCorresp.find((*it1).second[i]->getEndTrianglePoint1());
-					if (it2 != VertexToCorresp.end()){
-						if ((*it2).second.size() > 0){
-							if ((*it1).second[i]->getEndTrianglePoint1()->onWhat()->dim() == 2){
-								(*it2).second[0]->setTagMaster((*it1).second[i]->getStartPoint()->onWhat()->tag());
-							}
-						}
-					}
-					it2 = VertexToCorresp.find((*it1).second[i]->getEndTrianglePoint2());
-					if (it2 != VertexToCorresp.end()){
-						if ((*it2).second.size() > 0){
-							if ((*it1).second[i]->getEndTrianglePoint2()->onWhat()->dim() == 2){
-								(*it2).second[0]->setTagMaster((*it1).second[i]->getStartPoint()->onWhat()->tag());
-							}
-						}
-					}
-					it2 = VertexToCorresp.find((*it1).second[i]->getEndTrianglePoint3());
-					if (it2 != VertexToCorresp.end()){
-						if ((*it2).second.size() > 0){
-							if ((*it1).second[i]->getEndTrianglePoint3()->onWhat()->dim() == 2){
-								(*it2).second[0]->setTagMaster((*it1).second[i]->getStartPoint()->onWhat()->tag());
-							}
-						}
-					}
-				}
-//				for (unsigned int j = 0;j < 3;j++){
-//					std::map<MVertex*,std::vector<CorrespVerticesFixMesh*> >::iterator it2 = VertexToCorresp.find(faceEndSlave.v[j]);
-//					if (it2 != VertexToCorresp.end()){
-//						if (faceEndSlave.v[j]->onWhat()->dim() == 2){
-//							(*it2).second[0]->setTagMaster((*it1).second[i]->getStartPoint()->onWhat()->tag());
-//						}
-//					}
-//				}
-				MasterSheet.push_back((*it1).second[i]);
-				std::set<MVertex*> CurrentSheet;
-				CurrentSheet.clear();
-				CurrentSheet.insert((*it1).second[i]->getStartPoint());
-				while (CurrentSheet.size() != 0){
-					MVertex* VToDo = (*CurrentSheet.begin());
-					std::vector<MTetrahedron*> surroundingTet = VertexToTets[VToDo];
-					for (unsigned int j = 0;j < surroundingTet.size();j++){
-						for (unsigned int k = 0;k < surroundingTet[j]->getNumVertices();k++){
-							MVertex* ToInsertTmp = surroundingTet[j]->getVertex(k);
-							std::map<MVertex*,std::vector<CorrespVerticesFixMesh*> >::iterator it2 = VertexToCorresp.find(ToInsertTmp);
-							if (ToInsertTmp->onWhat()->tag() == VToDo->onWhat()->tag()){//TODO: OR that onwhat -> dim <, for edges
-								if (it2 != VertexToCorresp.end()){
-									if ((*it2).second.size() > 0){
-										CorrespVerticesFixMesh* correspToInsert = ((*it2).second)[0];
-										//std::cout<<"      Testing "<<((*it2).second)[0]->getStartPoint()->getNum()<<" with ";
-										if (correspToInsert->getStartPoint()->onWhat()->dim() == 2)
-											//std::cout<<"On a surface ; ";
-										if (correspToInsert->getActive())
-											//std::cout<<"Is active ; ";
-										if (correspToInsert->getEndTriangleActive())
-											//std::cout<<"End Triangle active ; ";
-										if (correspToInsert->getTagMaster() == (-2))
-											//std::cout<<"Has yet to be used ; ";
-										//std::cout<<std::endl;
-										if ((correspToInsert->getStartPoint()->onWhat()->dim() == 2) && (correspToInsert->getActive()) && (correspToInsert->getEndTriangleActive()) && (correspToInsert->getTagMaster() == (-2))){
-											MasterSheet.push_back((*it2).second[0]);
-											(*it2).second[0]->setTagMaster(-1);
-											//										faceXtetFM faceEndSlave2 = (*((*it2).second[0]->getEndTriangle()));
-											//										faceXtetFM faceEndSlave2 = ((*it2).second[0]->getEndTriangle());
-											{
-												std::map<MVertex*,std::vector<CorrespVerticesFixMesh*> >::iterator it3 = VertexToCorresp.find((*it2).second[0]->getEndTrianglePoint1());
-												if (it3 != VertexToCorresp.end()){
-													if ((*it3).second.size() > 0){
-														if ((*it2).second[0]->getEndTrianglePoint1()->onWhat()->dim() == 2){
-															(*it3).second[0]->setTagMaster((*it2).second[i]->getStartPoint()->onWhat()->tag());
-														}
-													}
-												}
-												it3 = VertexToCorresp.find((*it2).second[0]->getEndTrianglePoint2());
-												if (it3 != VertexToCorresp.end()){
-													if ((*it3).second.size() > 0){
-														if ((*it2).second[0]->getEndTrianglePoint2()->onWhat()->dim() == 2){
-															(*it3).second[0]->setTagMaster((*it2).second[i]->getStartPoint()->onWhat()->tag());
-														}
-													}
-												}
-												it3 = VertexToCorresp.find((*it2).second[0]->getEndTrianglePoint3());
-												if (it3 != VertexToCorresp.end()){
-													if ((*it3).second.size() > 0){
-														if ((*it2).second[0]->getEndTrianglePoint3()->onWhat()->dim() == 2){
-															(*it3).second[0]->setTagMaster((*it2).second[i]->getStartPoint()->onWhat()->tag());
-														}
-													}
-												}
-											}
-											//										for (unsigned int j = 0;j < 3;j++){
-											//											std::map<MVertex*,std::vector<CorrespVerticesFixMesh*> >::iterator it3 = VertexToCorresp.find(faceEndSlave2.v[j]);
-											//											if (it3 != VertexToCorresp.end()){
-											//												if (faceEndSlave2.v[j]->onWhat()->dim() == 2){
-											//													(*it3).second[0]->setTagMaster((*it2).second[i]->getStartPoint()->onWhat()->tag());
-											//												}
-											//											}
-											//										}
-											CurrentSheet.insert(ToInsertTmp);
-										}
-									}
-								}
-							}
-						}
-					}
-					CurrentSheet.erase(VToDo);
-				}
-				vecOfThinSheets.push_back(MasterSheet);
-				//std::cout<<"describing new MasterSheet !"<<std::endl;
-				for (unsigned int j = 0;j < MasterSheet.size();j++){
-					//std::cout<<"Number "<<j<<" is "<<MasterSheet[j]->getStartPoint()->getNum()<<" with position "<<MasterSheet[j]->getStartPoint()->x()<<" ; "<<MasterSheet[j]->getStartPoint()->y()<<" ; "<<MasterSheet[j]->getStartPoint()->z()<<std::endl;
-				}
-				//std::cout<<"exiting the master sheet !"<<std::endl;
-			}
-		}
-	}
+  for (std::map<MVertex*,std::vector<CorrespVerticesFixMesh*> >::iterator it1 = VertexToCorresp.begin();it1 != VertexToCorresp.end();it1++){
+    // MVertex* vertTmp = (*it1).first;
+    std::vector<CorrespVerticesFixMesh*> vecCorr = (*it1).second;
+    for (unsigned int i = 0;i < vecCorr.size();i++){
+      CorrespVerticesFixMesh* currentCorr = vecCorr[i];
+      //std::cout<<"going to test vecCorr["<<i<<"]"<<" vertex "<<currentCorr->getStartPoint()->getNum()<<" and pos "<<currentCorr->getStartPoint()->x()<<" ; "<<currentCorr->getStartPoint()->y()<<" ; "<<currentCorr->getStartPoint()->z()<<std::endl;
+      if (currentCorr->getStartPoint()->onWhat()->dim() == 2)
+        //std::cout<<"On a surface ; ";
+        if (currentCorr->getActive())
+          //std::cout<<"Is active ; ";
+          if (currentCorr->getEndTriangleActive())
+            //std::cout<<"End Triangle active ; ";
+            if (currentCorr->getTagMaster() == (-2))
+              //std::cout<<"Has yet to be used ; ";
+              //std::cout<<std::endl;
+              if ((currentCorr->getStartPoint()->onWhat()->dim() == 2) && (currentCorr->getActive()) && (currentCorr->getEndTriangleActive()) && (currentCorr->getTagMaster() == (-2))){
+                //Found the first node of a new master sheet
+                //std::cout<<"entering a new master sheet !"<<std::endl;
+                std::vector<CorrespVerticesFixMesh*> MasterSheet;
+                MasterSheet.clear();
+                (*it1).second[i]->setTagMaster(-1);
+                //				faceXtetFM faceEndSlave = (*((*it1).second[i]->getEndTriangle()));
+                //				faceXtetFM faceEndSlave = ((*it1).second[i]->getEndTriangle());
+                {
+                  std::map<MVertex*,std::vector<CorrespVerticesFixMesh*> >::iterator it2 = VertexToCorresp.find((*it1).second[i]->getEndTrianglePoint1());
+                  if (it2 != VertexToCorresp.end()){
+                    if ((*it2).second.size() > 0){
+                      if ((*it1).second[i]->getEndTrianglePoint1()->onWhat()->dim() == 2){
+                        (*it2).second[0]->setTagMaster((*it1).second[i]->getStartPoint()->onWhat()->tag());
+                      }
+                    }
+                  }
+                  it2 = VertexToCorresp.find((*it1).second[i]->getEndTrianglePoint2());
+                  if (it2 != VertexToCorresp.end()){
+                    if ((*it2).second.size() > 0){
+                      if ((*it1).second[i]->getEndTrianglePoint2()->onWhat()->dim() == 2){
+                        (*it2).second[0]->setTagMaster((*it1).second[i]->getStartPoint()->onWhat()->tag());
+                      }
+                    }
+                  }
+                  it2 = VertexToCorresp.find((*it1).second[i]->getEndTrianglePoint3());
+                  if (it2 != VertexToCorresp.end()){
+                    if ((*it2).second.size() > 0){
+                      if ((*it1).second[i]->getEndTrianglePoint3()->onWhat()->dim() == 2){
+                        (*it2).second[0]->setTagMaster((*it1).second[i]->getStartPoint()->onWhat()->tag());
+                      }
+                    }
+                  }
+                }
+                //				for (unsigned int j = 0;j < 3;j++){
+                //					std::map<MVertex*,std::vector<CorrespVerticesFixMesh*> >::iterator it2 = VertexToCorresp.find(faceEndSlave.v[j]);
+                //					if (it2 != VertexToCorresp.end()){
+                //						if (faceEndSlave.v[j]->onWhat()->dim() == 2){
+                //							(*it2).second[0]->setTagMaster((*it1).second[i]->getStartPoint()->onWhat()->tag());
+                //						}
+                //					}
+                //				}
+                MasterSheet.push_back((*it1).second[i]);
+                std::set<MVertex*> CurrentSheet;
+                CurrentSheet.clear();
+                CurrentSheet.insert((*it1).second[i]->getStartPoint());
+                while (CurrentSheet.size() != 0){
+                  MVertex* VToDo = (*CurrentSheet.begin());
+                  std::vector<MTetrahedron*> surroundingTet = VertexToTets[VToDo];
+                  for (unsigned int j = 0;j < surroundingTet.size();j++){
+                    for (unsigned int k = 0;k < surroundingTet[j]->getNumVertices();k++){
+                      MVertex* ToInsertTmp = surroundingTet[j]->getVertex(k);
+                      std::map<MVertex*,std::vector<CorrespVerticesFixMesh*> >::iterator it2 = VertexToCorresp.find(ToInsertTmp);
+                      if (ToInsertTmp->onWhat()->tag() == VToDo->onWhat()->tag()){//TODO: OR that onwhat -> dim <, for edges
+                        if (it2 != VertexToCorresp.end()){
+                          if ((*it2).second.size() > 0){
+                            CorrespVerticesFixMesh* correspToInsert = ((*it2).second)[0];
+                            //std::cout<<"      Testing "<<((*it2).second)[0]->getStartPoint()->getNum()<<" with ";
+                            if (correspToInsert->getStartPoint()->onWhat()->dim() == 2)
+                              //std::cout<<"On a surface ; ";
+                              if (correspToInsert->getActive())
+                                //std::cout<<"Is active ; ";
+                                if (correspToInsert->getEndTriangleActive())
+                                  //std::cout<<"End Triangle active ; ";
+                                  if (correspToInsert->getTagMaster() == (-2))
+                                    //std::cout<<"Has yet to be used ; ";
+                                    //std::cout<<std::endl;
+                                    if ((correspToInsert->getStartPoint()->onWhat()->dim() == 2) && (correspToInsert->getActive()) && (correspToInsert->getEndTriangleActive()) && (correspToInsert->getTagMaster() == (-2))){
+                                      MasterSheet.push_back((*it2).second[0]);
+                                      (*it2).second[0]->setTagMaster(-1);
+                                      //										faceXtetFM faceEndSlave2 = (*((*it2).second[0]->getEndTriangle()));
+                                      //										faceXtetFM faceEndSlave2 = ((*it2).second[0]->getEndTriangle());
+                                      {
+                                        std::map<MVertex*,std::vector<CorrespVerticesFixMesh*> >::iterator it3 = VertexToCorresp.find((*it2).second[0]->getEndTrianglePoint1());
+                                        if (it3 != VertexToCorresp.end()){
+                                          if ((*it3).second.size() > 0){
+                                            if ((*it2).second[0]->getEndTrianglePoint1()->onWhat()->dim() == 2){
+                                              (*it3).second[0]->setTagMaster((*it2).second[i]->getStartPoint()->onWhat()->tag());
+                                            }
+                                          }
+                                        }
+                                        it3 = VertexToCorresp.find((*it2).second[0]->getEndTrianglePoint2());
+                                        if (it3 != VertexToCorresp.end()){
+                                          if ((*it3).second.size() > 0){
+                                            if ((*it2).second[0]->getEndTrianglePoint2()->onWhat()->dim() == 2){
+                                              (*it3).second[0]->setTagMaster((*it2).second[i]->getStartPoint()->onWhat()->tag());
+                                            }
+                                          }
+                                        }
+                                        it3 = VertexToCorresp.find((*it2).second[0]->getEndTrianglePoint3());
+                                        if (it3 != VertexToCorresp.end()){
+                                          if ((*it3).second.size() > 0){
+                                            if ((*it2).second[0]->getEndTrianglePoint3()->onWhat()->dim() == 2){
+                                              (*it3).second[0]->setTagMaster((*it2).second[i]->getStartPoint()->onWhat()->tag());
+                                            }
+                                          }
+                                        }
+                                      }
+                                      //										for (unsigned int j = 0;j < 3;j++){
+                                      //											std::map<MVertex*,std::vector<CorrespVerticesFixMesh*> >::iterator it3 = VertexToCorresp.find(faceEndSlave2.v[j]);
+                                      //											if (it3 != VertexToCorresp.end()){
+                                      //												if (faceEndSlave2.v[j]->onWhat()->dim() == 2){
+                                      //													(*it3).second[0]->setTagMaster((*it2).second[i]->getStartPoint()->onWhat()->tag());
+                                      //												}
+                                      //											}
+                                      //										}
+                                      CurrentSheet.insert(ToInsertTmp);
+                                    }
+                          }
+                        }
+                      }
+                    }
+                  }
+                  CurrentSheet.erase(VToDo);
+                }
+                vecOfThinSheets.push_back(MasterSheet);
+                //std::cout<<"describing new MasterSheet !"<<std::endl;
+                for (unsigned int j = 0;j < MasterSheet.size();j++){
+                  //std::cout<<"Number "<<j<<" is "<<MasterSheet[j]->getStartPoint()->getNum()<<" with position "<<MasterSheet[j]->getStartPoint()->x()<<" ; "<<MasterSheet[j]->getStartPoint()->y()<<" ; "<<MasterSheet[j]->getStartPoint()->z()<<std::endl;
+                }
+                //std::cout<<"exiting the master sheet !"<<std::endl;
+              }
+    }
+  }
 }
 std::map<MVertex*,double> GMSH_ThinLayerFixMeshPlugin::computeAllDistToOppSide(){
-	std::map<MVertex*,double> AllDistToOppSide;
-	AllDistToOppSide.clear();
-	GModel *m = GModel::current();
-//	std::vector<MElement*> crackElements;
-	std::set<MVertex*> BoundaryVertices;
-	int countdown = 0;
+  std::map<MVertex*,double> AllDistToOppSide;
+  AllDistToOppSide.clear();
+  GModel *m = GModel::current();
+  //	std::vector<MElement*> crackElements;
+  std::set<MVertex*> BoundaryVertices;
+  int countdown = 0;
 
 
 
-	for (GModel::riter itr= m->firstRegion();itr != m->lastRegion();itr++){
-		GRegion* rTmp = (*itr);
-		//std::cout<<"   Entering region "<<rTmp->tag()<<std::endl;
-		for(unsigned int i = 0; i < rTmp->tetrahedra.size(); i++){
-			countdown++;
-			//std::cout<<"      Entering tet "<<rTmp->tetrahedra[i]->getNum()<<" its the "<<countdown<<"st"<<std::endl;
-			MTet4* tet4Tmp = TetToTet4[rTmp->tetrahedra[i]];
-			//std::cout<<"      Neighbours 0: "<<tet4Tmp->getNeigh(0)<<" Neighbours 1: "<<tet4Tmp->getNeigh(1)<<" Neighbours 2: "<<tet4Tmp->getNeigh(2)<<" Neighbours 3: "<<tet4Tmp->getNeigh(3)<<std::endl;
-			for (unsigned int j = 0;j < 4;j++){
-				//std::cout<<"         Entering neighbour "<<j<<std::endl;
-				if (tet4Tmp->getNeigh(j) == 0){
-					//std::cout<<"         Test Passed "<<std::endl;
-					//find the 4th point,and fill the two vector of the boundary triangle
-					faceXtetFM fxtTmp(tet4Tmp,j);
-					//std::cout<<"         fxtTmp created "<<std::endl;
-					for (int k = 0;k < 3;k++){
-						//std::cout<<"            Entering Point "<<k<<std::endl;
-						MVertex* toTest = fxtTmp.v[k];
-						if (toTest->onWhat()->dim() == 2){
-							//std::cout<<"               Passed First test "<<std::endl;
-							if(BoundaryVertices.find(toTest) == BoundaryVertices.end()){
-								//std::cout<<"                  Passed Second test "<<std::endl;
-								BoundaryVertices.insert(toTest);
-							}
-						}
-						//std::cout<<"            Exiting Point "<<k<<std::endl;
-					}
-					//			crackElements.push_back(rTmp->getMeshElement(j));
-				}
-				//std::cout<<"         Exiting neighbour "<<j<<std::endl;
-			}
-			//std::cout<<"      Exiting tet "<<rTmp->tetrahedra[i]->getNum()<<std::endl;
-		}
-		//std::cout<<"   Exiting region "<<rTmp->tag()<<std::endl;
-	}
-	//std::cout<<"Entering computeDistToOppSide"<<std::endl;
-	countdown = 0;
-	for(std::set<MVertex*>::iterator it = BoundaryVertices.begin(); it != BoundaryVertices.end(); it++){
-		countdown++;
-		//std::cout<<"   entering Bound Vert "<<(*it)->getNum()<<" it's the "<<countdown<<"st"<<std::endl;
-		MVertex* toCompute = (*it);
-		double resultTmp = computeDistToOppSide(toCompute);
-		int lastTmp = VertexToCorresp[toCompute].size() - 1;
-		//std::cout<<"            getEndNormal is "<<VertexToCorresp[toCompute][lastTmp]->getEndNormal().x()<<" ; "<<VertexToCorresp[toCompute][lastTmp]->getEndNormal().y()<<" ; "<<VertexToCorresp[toCompute][lastTmp]->getEndNormal().z()<<std::endl;
-		//std::cout<<"            getEndNormal is "<<VertexToCorresp[toCompute][lastTmp]->getEndNormal().x()<<" ; "<<VertexToCorresp[toCompute][lastTmp]->getEndNormal().y()<<" ; "<<VertexToCorresp[toCompute][lastTmp]->getEndNormal().z()<<std::endl;
-		//std::cout<<"            getEndNormal is "<<VertexToCorresp[toCompute][lastTmp]->getEndNormal().x()<<" ; "<<VertexToCorresp[toCompute][lastTmp]->getEndNormal().y()<<" ; "<<VertexToCorresp[toCompute][lastTmp]->getEndNormal().z()<<std::endl;
-//		std::cout<<"         Testing FaceXTet out of while third time "<<VertexToCorresp[toCompute][lastTmp]->getEndTriangle().t1->tet()->getNum()<<std::endl;
-		//std::cout<<"            LastTmp is "<<lastTmp<<std::endl;
-		//std::cout<<"            ToCompute is "<<toCompute->getNum()<<std::endl;
-		//std::cout<<"               ToCompute adress is "<<toCompute<<std::endl;
-		//std::cout<<"            VertexToCorresp[toCompute][lastTmp] is "<<VertexToCorresp[toCompute][lastTmp]<<std::endl;
-//		std::cout<<"            getEndTriangle is "<<VertexToCorresp[toCompute][lastTmp]->getEndTriangle()<<std::endl;
-//		std::cout<<"            t1 is "<<VertexToCorresp[toCompute][lastTmp]->getEndTriangle().t1<<std::endl;
-//		std::cout<<"            tet is "<<VertexToCorresp[toCompute][lastTmp]->getEndTriangle().t1->tet()<<std::endl;
-//		std::cout<<"         Testing FaceXTet out of while popo "<<VertexToCorresp[toCompute][lastTmp]->getEndTriangle().t1->tet()->getNum()<<std::endl;
-		//std::cout<<"     size of AllDistToOppSide is "<<AllDistToOppSide.size()<<std::endl;
-		//std::cout<<"            LastTmp is "<<lastTmp<<std::endl;
-		//std::cout<<"            ToCompute is "<<toCompute->getNum()<<std::endl;
-		//std::cout<<"               ToCompute adress is "<<toCompute<<std::endl;
-		//std::cout<<"            VertexToCorresp[toCompute][lastTmp] is "<<VertexToCorresp[toCompute][lastTmp]<<std::endl;
-//		std::cout<<"            getEndTriangle is "<<VertexToCorresp[toCompute][lastTmp]->getEndTriangle()<<std::endl;
-		//std::cout<<"            getEndNormal is "<<VertexToCorresp[toCompute][lastTmp]->getEndNormal()<<std::endl;
-		//std::cout<<"            getEndNormal is "<<VertexToCorresp[toCompute][lastTmp]->getEndNormal().x()<<" ; "<<VertexToCorresp[toCompute][lastTmp]->getEndNormal().y()<<" ; "<<VertexToCorresp[toCompute][lastTmp]->getEndNormal().z()<<std::endl;
-		//std::cout<<"            getEndNormal is "<<VertexToCorresp[toCompute][lastTmp]->getEndNormal().x()<<" ; "<<VertexToCorresp[toCompute][lastTmp]->getEndNormal().y()<<" ; "<<VertexToCorresp[toCompute][lastTmp]->getEndNormal().z()<<std::endl;
-//		std::cout<<"            t1 is "<<VertexToCorresp[toCompute][lastTmp]->getEndTriangle().t1<<std::endl;
-//		std::cout<<"            tet is "<<VertexToCorresp[toCompute][lastTmp]->getEndTriangle().t1->tet()<<std::endl;
-		//std::cout<<"            VertexToCorresp[toCompute][lastTmp] is "<<VertexToCorresp[toCompute][lastTmp]<<std::endl;
-//		std::cout<<"            getEndTriangle is "<<VertexToCorresp[toCompute][lastTmp]->getEndTriangle()<<std::endl;
-		//std::cout<<"            getEndNormal is "<<VertexToCorresp[toCompute][lastTmp]->getEndNormal()<<std::endl;
-		//std::cout<<"            getEndNormal is "<<VertexToCorresp[toCompute][lastTmp]->getEndNormal().x()<<" ; "<<VertexToCorresp[toCompute][lastTmp]->getEndNormal().y()<<" ; "<<VertexToCorresp[toCompute][lastTmp]->getEndNormal().z()<<std::endl;
-//		std::cout<<"     VertexToCorresp[toCompute][lastTmp]->getEndTriangle().t1 adress is "<<&(VertexToCorresp[toCompute][lastTmp]->getEndTriangle().t1)<<std::endl;
-		//std::cout<<"            VertexToCorresp[toCompute][lastTmp] is "<<VertexToCorresp[toCompute][lastTmp]<<std::endl;
-//		std::cout<<"            getEndTriangle is "<<VertexToCorresp[toCompute][lastTmp]->getEndTriangle()<<std::endl;
-		//std::cout<<"            getEndNormal is "<<VertexToCorresp[toCompute][lastTmp]->getEndNormal()<<std::endl;
-		//std::cout<<"            getEndNormal is "<<VertexToCorresp[toCompute][lastTmp]->getEndNormal().x()<<" ; "<<VertexToCorresp[toCompute][lastTmp]->getEndNormal().y()<<" ; "<<VertexToCorresp[toCompute][lastTmp]->getEndNormal().z()<<std::endl;
-//		std::cout<<"     VertexToCorresp[toCompute][lastTmp]->getEndTriangle().t1 adress is "<<&(VertexToCorresp[toCompute][lastTmp]->getEndTriangle().t1)<<std::endl;
-		//std::cout<<"               ToCompute adress is "<<toCompute<<std::endl;
-//		std::cout<<"         Testing FaceXTet out of while popo 2 "<<VertexToCorresp[toCompute][lastTmp]->getEndTriangle().t1->tet()->getNum()<<std::endl;
-		AllDistToOppSide.insert(std::make_pair(toCompute, resultTmp));
-		//std::cout<<"     AllDistToOppSide[toCompute] is "<<AllDistToOppSide[toCompute]<<std::endl;
-		//std::cout<<"               ToCompute adress is "<<toCompute<<std::endl;
-		//std::cout<<"            VertexToCorresp[toCompute][lastTmp] is "<<VertexToCorresp[toCompute][lastTmp]<<std::endl;
-//		std::cout<<"            getEndTriangle is "<<VertexToCorresp[toCompute][lastTmp]->getEndTriangle()<<std::endl;
-		//std::cout<<"            getEndNormal is "<<VertexToCorresp[toCompute][lastTmp]->getEndNormal()<<std::endl;
-		//std::cout<<"            getEndNormal is "<<VertexToCorresp[toCompute][lastTmp]->getEndNormal().x()<<" ; "<<VertexToCorresp[toCompute][lastTmp]->getEndNormal().y()<<" ; "<<VertexToCorresp[toCompute][lastTmp]->getEndNormal().z()<<std::endl;
-//		std::cout<<"     VertexToCorresp[toCompute][lastTmp]->getEndTriangle().t1 adress is "<<&(VertexToCorresp[toCompute][lastTmp]->getEndTriangle().t1)<<std::endl;
-		//std::cout<<"               ToCompute adress is "<<toCompute<<std::endl;
-		//std::cout<<"            VertexToCorresp[toCompute][lastTmp] is "<<VertexToCorresp[toCompute][lastTmp]<<std::endl;
-//		std::cout<<"            getEndTriangle is "<<VertexToCorresp[toCompute][lastTmp]->getEndTriangle()<<std::endl;
-//		std::cout<<"     VertexToCorresp[toCompute][lastTmp]->getEndTriangle().t1 adress is "<<&(VertexToCorresp[toCompute][lastTmp]->getEndTriangle().t1)<<std::endl;
-		//std::cout<<"     AllDistToOppSide[toCompute] adress is "<<&AllDistToOppSide[toCompute]<<std::endl;
-		//std::cout<<"            VertexToCorresp[toCompute][lastTmp] is "<<VertexToCorresp[toCompute][lastTmp]<<std::endl;
-//		std::cout<<"            getEndTriangle is "<<VertexToCorresp[toCompute][lastTmp]->getEndTriangle()<<std::endl;
-//		std::cout<<"     VertexToCorresp[toCompute][lastTmp]->getEndTriangle().t1 adress is "<<&(VertexToCorresp[toCompute][lastTmp]->getEndTriangle().t1)<<std::endl;
-		//std::cout<<"            VertexToCorresp[toCompute][lastTmp] is "<<VertexToCorresp[toCompute][lastTmp]<<std::endl;
-//		std::cout<<"            getEndTriangle is "<<VertexToCorresp[toCompute][lastTmp]->getEndTriangle()<<std::endl;
-//		std::cout<<"     VertexToCorresp[toCompute][lastTmp]->getEndTriangle().t1 adress is "<<&(VertexToCorresp[toCompute][lastTmp]->getEndTriangle().t1)<<std::endl;
-		//std::cout<<"            VertexToCorresp[toCompute][lastTmp] is "<<VertexToCorresp[toCompute][lastTmp]<<std::endl;
-//		std::cout<<"            getEndTriangle is "<<VertexToCorresp[toCompute][lastTmp]->getEndTriangle()<<std::endl;
-//		std::cout<<"     VertexToCorresp[toCompute][lastTmp]->getEndTriangle().t1 adress is "<<&(VertexToCorresp[toCompute][lastTmp]->getEndTriangle().t1)<<std::endl;
-		//std::cout<<"            LastTmp is "<<lastTmp<<std::endl;
-		//std::cout<<"            ToCompute is "<<toCompute->getNum()<<std::endl;
-		//std::cout<<"               ToCompute adress is "<<toCompute<<std::endl;
-		//std::cout<<"            VertexToCorresp[toCompute][lastTmp] is "<<VertexToCorresp[toCompute][lastTmp]<<std::endl;
-//		std::cout<<"            getEndTriangle is "<<VertexToCorresp[toCompute][lastTmp]->getEndTriangle()<<std::endl;
-//		std::cout<<"            t1 is "<<VertexToCorresp[toCompute][lastTmp]->getEndTriangle().t1<<std::endl;
-//		std::cout<<"            tet is "<<VertexToCorresp[toCompute][lastTmp]->getEndTriangle().t1->tet()<<std::endl;
-//		std::cout<<"         Testing FaceXTet out of while popo 3 "<<VertexToCorresp[toCompute][lastTmp]->getEndTriangle().t1->tet()->getNum()<<std::endl;
-//		AllDistToOppSide[toCompute] = 0.0;
-//		std::cout<<"            LastTmp is "<<lastTmp<<std::endl;
-//		std::cout<<"            ToCompute is "<<toCompute->getNum()<<std::endl;
-//		std::cout<<"            getEndTriangle is "<<VertexToCorresp[toCompute][lastTmp]->getEndTriangle()<<std::endl;
-//		std::cout<<"            t1 is "<<VertexToCorresp[toCompute][lastTmp]->getEndTriangle().t1<<std::endl;
-//		std::cout<<"            tet is "<<VertexToCorresp[toCompute][lastTmp]->getEndTriangle().t1->tet()<<std::endl;
-//		std::cout<<"     size of AllDistToOppSide is "<<AllDistToOppSide.size()<<std::endl;
-//		std::cout<<"            LastTmp is "<<lastTmp<<std::endl;
-//		std::cout<<"            ToCompute is "<<toCompute->getNum()<<std::endl;
-//		std::cout<<"            getEndTriangle is "<<VertexToCorresp[toCompute][lastTmp]->getEndTriangle()<<std::endl;
-//		std::cout<<"            t1 is "<<VertexToCorresp[toCompute][lastTmp]->getEndTriangle().t1<<std::endl;
-//		std::cout<<"            tet is "<<VertexToCorresp[toCompute][lastTmp]->getEndTriangle().t1->tet()<<std::endl;
-		AllDistToOppSide[toCompute] = resultTmp;
-		//std::cout<<" observation "<<countdown<<std::endl;
-		//std::cout<<"            LastTmp is "<<lastTmp<<std::endl;
-		//std::cout<<"            ToCompute is "<<toCompute->getNum()<<std::endl;
-		//std::cout<<"            VertexToCorresp[toCompute][lastTmp] is "<<VertexToCorresp[toCompute][lastTmp]<<std::endl;
-//		std::cout<<"            getEndTriangle is "<<VertexToCorresp[toCompute][lastTmp]->getEndTriangle()<<std::endl;
-//		std::cout<<"            t1 is "<<VertexToCorresp[toCompute][lastTmp]->getEndTriangle().t1<<std::endl;
-//		std::cout<<"            tet is "<<VertexToCorresp[toCompute][lastTmp]->getEndTriangle().t1->tet()<<std::endl;
-//		std::cout<<"         Testing FaceXTet out of while bis repetita "<<VertexToCorresp[toCompute][lastTmp]->getEndTriangle().t1->tet()->getNum()<<std::endl;
-		for (std::map<MVertex*,double>::iterator allDistIt = AllDistToOppSide.begin();allDistIt != AllDistToOppSide.end();allDistIt++){
-			//std::cout<<"allDist of point "<<(*allDistIt).first->getNum()<<" with Pos "<<(*allDistIt).first->x()<<" ; "<<(*allDistIt).first->z()<<" ; "<<(*allDistIt).first->y()<<" is "<<(*allDistIt).second<<std::endl;
-			//std::cout<<"   Size of vertexToCorresp "<<VertexToCorresp[(*allDistIt).first].size()<<std::endl;
-			MVertex* toComputeTest = (*allDistIt).first;
-			//std::cout<<"   ToComputeTest is "<<toComputeTest->getNum()<<std::endl;
-			int lastTmpTest = VertexToCorresp[toComputeTest].size() - 1;
-//			std::cout<<"         Testing FaceXTet out of while ter repetita "<<VertexToCorresp[toComputeTest][lastTmpTest]->getEndTriangle().t1->tet()->getNum()<<std::endl;
-//			std::cout<<"      Testing FaceXTet out of while fourth time "<<VertexToCorresp[(*allDistIt).first][VertexToCorresp[(*allDistIt).first].size() - 1]->getEndTriangle().t1->tet()->getNum()<<std::endl;
-		}
-	}
+  for (GModel::riter itr= m->firstRegion();itr != m->lastRegion();itr++){
+    GRegion* rTmp = (*itr);
+    //std::cout<<"   Entering region "<<rTmp->tag()<<std::endl;
+    for(unsigned int i = 0; i < rTmp->tetrahedra.size(); i++){
+      countdown++;
+      //std::cout<<"      Entering tet "<<rTmp->tetrahedra[i]->getNum()<<" its the "<<countdown<<"st"<<std::endl;
+      MTet4* tet4Tmp = TetToTet4[rTmp->tetrahedra[i]];
+      //std::cout<<"      Neighbours 0: "<<tet4Tmp->getNeigh(0)<<" Neighbours 1: "<<tet4Tmp->getNeigh(1)<<" Neighbours 2: "<<tet4Tmp->getNeigh(2)<<" Neighbours 3: "<<tet4Tmp->getNeigh(3)<<std::endl;
+      for (unsigned int j = 0;j < 4;j++){
+        //std::cout<<"         Entering neighbour "<<j<<std::endl;
+        if (tet4Tmp->getNeigh(j) == 0){
+          //std::cout<<"         Test Passed "<<std::endl;
+          //find the 4th point,and fill the two vector of the boundary triangle
+          faceXtetFM fxtTmp(tet4Tmp,j);
+          //std::cout<<"         fxtTmp created "<<std::endl;
+          for (int k = 0;k < 3;k++){
+            //std::cout<<"            Entering Point "<<k<<std::endl;
+            MVertex* toTest = fxtTmp.v[k];
+            if (toTest->onWhat()->dim() == 2){
+              //std::cout<<"               Passed First test "<<std::endl;
+              if(BoundaryVertices.find(toTest) == BoundaryVertices.end()){
+                //std::cout<<"                  Passed Second test "<<std::endl;
+                BoundaryVertices.insert(toTest);
+              }
+            }
+            //std::cout<<"            Exiting Point "<<k<<std::endl;
+          }
+          //			crackElements.push_back(rTmp->getMeshElement(j));
+        }
+        //std::cout<<"         Exiting neighbour "<<j<<std::endl;
+      }
+      //std::cout<<"      Exiting tet "<<rTmp->tetrahedra[i]->getNum()<<std::endl;
+    }
+    //std::cout<<"   Exiting region "<<rTmp->tag()<<std::endl;
+  }
+  //std::cout<<"Entering computeDistToOppSide"<<std::endl;
+  countdown = 0;
+  for(std::set<MVertex*>::iterator it = BoundaryVertices.begin(); it != BoundaryVertices.end(); it++){
+    countdown++;
+    //std::cout<<"   entering Bound Vert "<<(*it)->getNum()<<" it's the "<<countdown<<"st"<<std::endl;
+    MVertex* toCompute = (*it);
+    double resultTmp = computeDistToOppSide(toCompute);
+    // int lastTmp = VertexToCorresp[toCompute].size() - 1;
+    //std::cout<<"            getEndNormal is "<<VertexToCorresp[toCompute][lastTmp]->getEndNormal().x()<<" ; "<<VertexToCorresp[toCompute][lastTmp]->getEndNormal().y()<<" ; "<<VertexToCorresp[toCompute][lastTmp]->getEndNormal().z()<<std::endl;
+    //std::cout<<"            getEndNormal is "<<VertexToCorresp[toCompute][lastTmp]->getEndNormal().x()<<" ; "<<VertexToCorresp[toCompute][lastTmp]->getEndNormal().y()<<" ; "<<VertexToCorresp[toCompute][lastTmp]->getEndNormal().z()<<std::endl;
+    //std::cout<<"            getEndNormal is "<<VertexToCorresp[toCompute][lastTmp]->getEndNormal().x()<<" ; "<<VertexToCorresp[toCompute][lastTmp]->getEndNormal().y()<<" ; "<<VertexToCorresp[toCompute][lastTmp]->getEndNormal().z()<<std::endl;
+    //		std::cout<<"         Testing FaceXTet out of while third time "<<VertexToCorresp[toCompute][lastTmp]->getEndTriangle().t1->tet()->getNum()<<std::endl;
+    //std::cout<<"            LastTmp is "<<lastTmp<<std::endl;
+    //std::cout<<"            ToCompute is "<<toCompute->getNum()<<std::endl;
+    //std::cout<<"               ToCompute adress is "<<toCompute<<std::endl;
+    //std::cout<<"            VertexToCorresp[toCompute][lastTmp] is "<<VertexToCorresp[toCompute][lastTmp]<<std::endl;
+    //		std::cout<<"            getEndTriangle is "<<VertexToCorresp[toCompute][lastTmp]->getEndTriangle()<<std::endl;
+    //		std::cout<<"            t1 is "<<VertexToCorresp[toCompute][lastTmp]->getEndTriangle().t1<<std::endl;
+    //		std::cout<<"            tet is "<<VertexToCorresp[toCompute][lastTmp]->getEndTriangle().t1->tet()<<std::endl;
+    //		std::cout<<"         Testing FaceXTet out of while popo "<<VertexToCorresp[toCompute][lastTmp]->getEndTriangle().t1->tet()->getNum()<<std::endl;
+    //std::cout<<"     size of AllDistToOppSide is "<<AllDistToOppSide.size()<<std::endl;
+    //std::cout<<"            LastTmp is "<<lastTmp<<std::endl;
+    //std::cout<<"            ToCompute is "<<toCompute->getNum()<<std::endl;
+    //std::cout<<"               ToCompute adress is "<<toCompute<<std::endl;
+    //std::cout<<"            VertexToCorresp[toCompute][lastTmp] is "<<VertexToCorresp[toCompute][lastTmp]<<std::endl;
+    //		std::cout<<"            getEndTriangle is "<<VertexToCorresp[toCompute][lastTmp]->getEndTriangle()<<std::endl;
+    //std::cout<<"            getEndNormal is "<<VertexToCorresp[toCompute][lastTmp]->getEndNormal()<<std::endl;
+    //std::cout<<"            getEndNormal is "<<VertexToCorresp[toCompute][lastTmp]->getEndNormal().x()<<" ; "<<VertexToCorresp[toCompute][lastTmp]->getEndNormal().y()<<" ; "<<VertexToCorresp[toCompute][lastTmp]->getEndNormal().z()<<std::endl;
+    //std::cout<<"            getEndNormal is "<<VertexToCorresp[toCompute][lastTmp]->getEndNormal().x()<<" ; "<<VertexToCorresp[toCompute][lastTmp]->getEndNormal().y()<<" ; "<<VertexToCorresp[toCompute][lastTmp]->getEndNormal().z()<<std::endl;
+    //		std::cout<<"            t1 is "<<VertexToCorresp[toCompute][lastTmp]->getEndTriangle().t1<<std::endl;
+    //		std::cout<<"            tet is "<<VertexToCorresp[toCompute][lastTmp]->getEndTriangle().t1->tet()<<std::endl;
+    //std::cout<<"            VertexToCorresp[toCompute][lastTmp] is "<<VertexToCorresp[toCompute][lastTmp]<<std::endl;
+    //		std::cout<<"            getEndTriangle is "<<VertexToCorresp[toCompute][lastTmp]->getEndTriangle()<<std::endl;
+    //std::cout<<"            getEndNormal is "<<VertexToCorresp[toCompute][lastTmp]->getEndNormal()<<std::endl;
+    //std::cout<<"            getEndNormal is "<<VertexToCorresp[toCompute][lastTmp]->getEndNormal().x()<<" ; "<<VertexToCorresp[toCompute][lastTmp]->getEndNormal().y()<<" ; "<<VertexToCorresp[toCompute][lastTmp]->getEndNormal().z()<<std::endl;
+    //		std::cout<<"     VertexToCorresp[toCompute][lastTmp]->getEndTriangle().t1 adress is "<<&(VertexToCorresp[toCompute][lastTmp]->getEndTriangle().t1)<<std::endl;
+    //std::cout<<"            VertexToCorresp[toCompute][lastTmp] is "<<VertexToCorresp[toCompute][lastTmp]<<std::endl;
+    //		std::cout<<"            getEndTriangle is "<<VertexToCorresp[toCompute][lastTmp]->getEndTriangle()<<std::endl;
+    //std::cout<<"            getEndNormal is "<<VertexToCorresp[toCompute][lastTmp]->getEndNormal()<<std::endl;
+    //std::cout<<"            getEndNormal is "<<VertexToCorresp[toCompute][lastTmp]->getEndNormal().x()<<" ; "<<VertexToCorresp[toCompute][lastTmp]->getEndNormal().y()<<" ; "<<VertexToCorresp[toCompute][lastTmp]->getEndNormal().z()<<std::endl;
+    //		std::cout<<"     VertexToCorresp[toCompute][lastTmp]->getEndTriangle().t1 adress is "<<&(VertexToCorresp[toCompute][lastTmp]->getEndTriangle().t1)<<std::endl;
+    //std::cout<<"               ToCompute adress is "<<toCompute<<std::endl;
+    //		std::cout<<"         Testing FaceXTet out of while popo 2 "<<VertexToCorresp[toCompute][lastTmp]->getEndTriangle().t1->tet()->getNum()<<std::endl;
+    AllDistToOppSide.insert(std::make_pair(toCompute, resultTmp));
+    //std::cout<<"     AllDistToOppSide[toCompute] is "<<AllDistToOppSide[toCompute]<<std::endl;
+    //std::cout<<"               ToCompute adress is "<<toCompute<<std::endl;
+    //std::cout<<"            VertexToCorresp[toCompute][lastTmp] is "<<VertexToCorresp[toCompute][lastTmp]<<std::endl;
+    //		std::cout<<"            getEndTriangle is "<<VertexToCorresp[toCompute][lastTmp]->getEndTriangle()<<std::endl;
+    //std::cout<<"            getEndNormal is "<<VertexToCorresp[toCompute][lastTmp]->getEndNormal()<<std::endl;
+    //std::cout<<"            getEndNormal is "<<VertexToCorresp[toCompute][lastTmp]->getEndNormal().x()<<" ; "<<VertexToCorresp[toCompute][lastTmp]->getEndNormal().y()<<" ; "<<VertexToCorresp[toCompute][lastTmp]->getEndNormal().z()<<std::endl;
+    //		std::cout<<"     VertexToCorresp[toCompute][lastTmp]->getEndTriangle().t1 adress is "<<&(VertexToCorresp[toCompute][lastTmp]->getEndTriangle().t1)<<std::endl;
+    //std::cout<<"               ToCompute adress is "<<toCompute<<std::endl;
+    //std::cout<<"            VertexToCorresp[toCompute][lastTmp] is "<<VertexToCorresp[toCompute][lastTmp]<<std::endl;
+    //		std::cout<<"            getEndTriangle is "<<VertexToCorresp[toCompute][lastTmp]->getEndTriangle()<<std::endl;
+    //		std::cout<<"     VertexToCorresp[toCompute][lastTmp]->getEndTriangle().t1 adress is "<<&(VertexToCorresp[toCompute][lastTmp]->getEndTriangle().t1)<<std::endl;
+    //std::cout<<"     AllDistToOppSide[toCompute] adress is "<<&AllDistToOppSide[toCompute]<<std::endl;
+    //std::cout<<"            VertexToCorresp[toCompute][lastTmp] is "<<VertexToCorresp[toCompute][lastTmp]<<std::endl;
+    //		std::cout<<"            getEndTriangle is "<<VertexToCorresp[toCompute][lastTmp]->getEndTriangle()<<std::endl;
+    //		std::cout<<"     VertexToCorresp[toCompute][lastTmp]->getEndTriangle().t1 adress is "<<&(VertexToCorresp[toCompute][lastTmp]->getEndTriangle().t1)<<std::endl;
+    //std::cout<<"            VertexToCorresp[toCompute][lastTmp] is "<<VertexToCorresp[toCompute][lastTmp]<<std::endl;
+    //		std::cout<<"            getEndTriangle is "<<VertexToCorresp[toCompute][lastTmp]->getEndTriangle()<<std::endl;
+    //		std::cout<<"     VertexToCorresp[toCompute][lastTmp]->getEndTriangle().t1 adress is "<<&(VertexToCorresp[toCompute][lastTmp]->getEndTriangle().t1)<<std::endl;
+    //std::cout<<"            VertexToCorresp[toCompute][lastTmp] is "<<VertexToCorresp[toCompute][lastTmp]<<std::endl;
+    //		std::cout<<"            getEndTriangle is "<<VertexToCorresp[toCompute][lastTmp]->getEndTriangle()<<std::endl;
+    //		std::cout<<"     VertexToCorresp[toCompute][lastTmp]->getEndTriangle().t1 adress is "<<&(VertexToCorresp[toCompute][lastTmp]->getEndTriangle().t1)<<std::endl;
+    //std::cout<<"            LastTmp is "<<lastTmp<<std::endl;
+    //std::cout<<"            ToCompute is "<<toCompute->getNum()<<std::endl;
+    //std::cout<<"               ToCompute adress is "<<toCompute<<std::endl;
+    //std::cout<<"            VertexToCorresp[toCompute][lastTmp] is "<<VertexToCorresp[toCompute][lastTmp]<<std::endl;
+    //		std::cout<<"            getEndTriangle is "<<VertexToCorresp[toCompute][lastTmp]->getEndTriangle()<<std::endl;
+    //		std::cout<<"            t1 is "<<VertexToCorresp[toCompute][lastTmp]->getEndTriangle().t1<<std::endl;
+    //		std::cout<<"            tet is "<<VertexToCorresp[toCompute][lastTmp]->getEndTriangle().t1->tet()<<std::endl;
+    //		std::cout<<"         Testing FaceXTet out of while popo 3 "<<VertexToCorresp[toCompute][lastTmp]->getEndTriangle().t1->tet()->getNum()<<std::endl;
+    //		AllDistToOppSide[toCompute] = 0.0;
+    //		std::cout<<"            LastTmp is "<<lastTmp<<std::endl;
+    //		std::cout<<"            ToCompute is "<<toCompute->getNum()<<std::endl;
+    //		std::cout<<"            getEndTriangle is "<<VertexToCorresp[toCompute][lastTmp]->getEndTriangle()<<std::endl;
+    //		std::cout<<"            t1 is "<<VertexToCorresp[toCompute][lastTmp]->getEndTriangle().t1<<std::endl;
+    //		std::cout<<"            tet is "<<VertexToCorresp[toCompute][lastTmp]->getEndTriangle().t1->tet()<<std::endl;
+    //		std::cout<<"     size of AllDistToOppSide is "<<AllDistToOppSide.size()<<std::endl;
+    //		std::cout<<"            LastTmp is "<<lastTmp<<std::endl;
+    //		std::cout<<"            ToCompute is "<<toCompute->getNum()<<std::endl;
+    //		std::cout<<"            getEndTriangle is "<<VertexToCorresp[toCompute][lastTmp]->getEndTriangle()<<std::endl;
+    //		std::cout<<"            t1 is "<<VertexToCorresp[toCompute][lastTmp]->getEndTriangle().t1<<std::endl;
+    //		std::cout<<"            tet is "<<VertexToCorresp[toCompute][lastTmp]->getEndTriangle().t1->tet()<<std::endl;
+    AllDistToOppSide[toCompute] = resultTmp;
+    //std::cout<<" observation "<<countdown<<std::endl;
+    //std::cout<<"            LastTmp is "<<lastTmp<<std::endl;
+    //std::cout<<"            ToCompute is "<<toCompute->getNum()<<std::endl;
+    //std::cout<<"            VertexToCorresp[toCompute][lastTmp] is "<<VertexToCorresp[toCompute][lastTmp]<<std::endl;
+    //		std::cout<<"            getEndTriangle is "<<VertexToCorresp[toCompute][lastTmp]->getEndTriangle()<<std::endl;
+    //		std::cout<<"            t1 is "<<VertexToCorresp[toCompute][lastTmp]->getEndTriangle().t1<<std::endl;
+    //		std::cout<<"            tet is "<<VertexToCorresp[toCompute][lastTmp]->getEndTriangle().t1->tet()<<std::endl;
+    //		std::cout<<"         Testing FaceXTet out of while bis repetita "<<VertexToCorresp[toCompute][lastTmp]->getEndTriangle().t1->tet()->getNum()<<std::endl;
+    for (std::map<MVertex*,double>::iterator allDistIt = AllDistToOppSide.begin();allDistIt != AllDistToOppSide.end();allDistIt++){
+      //std::cout<<"allDist of point "<<(*allDistIt).first->getNum()<<" with Pos "<<(*allDistIt).first->x()<<" ; "<<(*allDistIt).first->z()<<" ; "<<(*allDistIt).first->y()<<" is "<<(*allDistIt).second<<std::endl;
+      //std::cout<<"   Size of vertexToCorresp "<<VertexToCorresp[(*allDistIt).first].size()<<std::endl;
+      // MVertex* toComputeTest = (*allDistIt).first;
+      //std::cout<<"   ToComputeTest is "<<toComputeTest->getNum()<<std::endl;
+      // int lastTmpTest = VertexToCorresp[toComputeTest].size() - 1;
+      //			std::cout<<"         Testing FaceXTet out of while ter repetita "<<VertexToCorresp[toComputeTest][lastTmpTest]->getEndTriangle().t1->tet()->getNum()<<std::endl;
+      //			std::cout<<"      Testing FaceXTet out of while fourth time "<<VertexToCorresp[(*allDistIt).first][VertexToCorresp[(*allDistIt).first].size() - 1]->getEndTriangle().t1->tet()->getNum()<<std::endl;
+    }
+  }
 
-	//std::cout<<"first observation"<<std::endl;
-	for (std::map<MVertex*,double>::iterator allDistIt = AllDistToOppSide.begin();allDistIt != AllDistToOppSide.end();allDistIt++){
-		//std::cout<<"allDist of point "<<(*allDistIt).first->getNum()<<" with Pos "<<(*allDistIt).first->x()<<" ; "<<(*allDistIt).first->z()<<" ; "<<(*allDistIt).first->y()<<" is "<<(*allDistIt).second<<std::endl;
-		//std::cout<<"   Size of vertexToCorresp "<<VertexToCorresp[(*allDistIt).first].size()<<std::endl;
-//		std::cout<<"      Testing FaceXTet out of while fourth time "<<VertexToCorresp[(*allDistIt).first][VertexToCorresp[(*allDistIt).first].size() - 1]->getEndTriangle().t1->tet()->getNum()<<std::endl;
-	}
+  //std::cout<<"first observation"<<std::endl;
+  for (std::map<MVertex*,double>::iterator allDistIt = AllDistToOppSide.begin();allDistIt != AllDistToOppSide.end();allDistIt++){
+    //std::cout<<"allDist of point "<<(*allDistIt).first->getNum()<<" with Pos "<<(*allDistIt).first->x()<<" ; "<<(*allDistIt).first->z()<<" ; "<<(*allDistIt).first->y()<<" is "<<(*allDistIt).second<<std::endl;
+    //std::cout<<"   Size of vertexToCorresp "<<VertexToCorresp[(*allDistIt).first].size()<<std::endl;
+    //		std::cout<<"      Testing FaceXTet out of while fourth time "<<VertexToCorresp[(*allDistIt).first][VertexToCorresp[(*allDistIt).first].size() - 1]->getEndTriangle().t1->tet()->getNum()<<std::endl;
+  }
 
-	return AllDistToOppSide;
+  return AllDistToOppSide;
 }
 
 double GMSH_ThinLayerFixMeshPlugin::computeDistToOppSide(MVertex* v){
-	double DistToOppSide = 0.0;
-	//We assume v is on the boundary
-	//First we need to get the internal normal
-	//std::cout<<"      Entering ComputeDistToOppSide Function"<<std::endl;
-	SVector3 InteriorNormal = GMSH_ThinLayerFixMeshPlugin::computeInteriorNormal(v);
-	//std::cout<<"      Normal computed"<<std::endl;
-	//Then we find the first triangle
-	MTet4* FirstTet = GMSH_ThinLayerFixMeshPlugin::getTetFromPoint(v,InteriorNormal);
-	//std::cout<<"   FirstTet is tet "<<FirstTet->tet()->getNum()<<std::endl;
-	//std::cout<<"      got FirstTet"<<std::endl;
-	MTet4* CurrentTet = FirstTet;
-	//std::cout<<"      set currentTet"<<std::endl;
-	MTet4* PastTet = FirstTet;
-	//std::cout<<"      set PastTet"<<std::endl;
-	SPoint3 CurrentPos = SPoint3(v->x(),v->y(),v->z());
-	//std::cout<<"      set CurrentPos"<<std::endl;
-	SPoint3 LastPos = CurrentPos;
-	//std::cout<<"      set LasPos"<<std::endl;
-	int CurrentTriValue = 0;
-	int* CurrentTri = &CurrentTriValue;
-	//std::cout<<"      set CurrentTri"<<std::endl;
-	CorrespVerticesFixMesh* CVTemp = new CorrespVerticesFixMesh();
-	//std::cout<<"      Created CVTemp"<<std::endl;
-	CorrespVerticesFixMesh CVTemp2;
-	//std::cout<<"      Created CVTemp2"<<std::endl;
-	CVTemp->setStartPoint(v);
-	CVTemp2.setStartPoint(v);
-	//std::cout<<"      setStartPoint"<<std::endl;
-	CVTemp->setStartNormal(InteriorNormal);
-	CVTemp2.setStartNormal(InteriorNormal);
-	//std::cout<<"      setStartNormal"<<std::endl;
-	FindNewPoint((&CurrentPos),CurrentTri,&CurrentTet,InteriorNormal);
-	DistToOppSide += CurrentPos.distance(LastPos);
-	LastPos = CurrentPos;
-	//std::cout<<"      Found New Point"<<std::endl;
-//	faceXtetFM fxtCV(PastTet,(*CurrentTri));
-//	CVTemp->setEndTriangle(&fxtCV);
-//	while(CurrentTet->getNeigh((*CurrentTri)) != 0){
-	int countWhile = 0;
-	int prevprevtet = 1;
-	int prevtet = 2;
-	while((CurrentTet != 0) && (countWhile < 50)){
-		//std::cout<<"                                    Entering While"<<std::endl;
-		//std::cout<<"CurrentTet is "<<CurrentTet->tet()->getNum()<< "adress "<<CurrentTet<< " and currentTri "<<(*CurrentTri)<<std::endl;
-		//std::cout<<"currentPos is "<<CurrentPos.x()<<" ; "<<CurrentPos.y()<<" ; "<<CurrentPos.z()<<std::endl;
-		countWhile++;
-		faceXtetFM fxtCVtmp(PastTet,(*CurrentTri));
-		PastTet = CurrentTet;
-		CVTemp->setEndTrianglePoint1(PastTet->tet()->getVertex(faces[(*CurrentTri)][0]));
-		CVTemp->setEndTrianglePoint2(PastTet->tet()->getVertex(faces[(*CurrentTri)][1]));
-		CVTemp->setEndTrianglePoint3(PastTet->tet()->getVertex(faces[(*CurrentTri)][2]));
-		CVTemp2.setEndTrianglePoint1(PastTet->tet()->getVertex(faces[(*CurrentTri)][0]));
-		CVTemp2.setEndTrianglePoint2(PastTet->tet()->getVertex(faces[(*CurrentTri)][1]));
-		CVTemp2.setEndTrianglePoint3(PastTet->tet()->getVertex(faces[(*CurrentTri)][2]));
-//		CVTemp->setEndTriangle(fxtCVtmp);
-//		CVTemp2.setEndTriangle(fxtCVtmp);
-		//std::cout<<"         FaceXTetCreated"<<std::endl;
-		//std::cout<<"         Testing FaceXTet in while "<<fxtCVtmp.t1->tet()->getNum()<<std::endl;
-		//std::cout<<"            CurrentTet before FindNewPoint "<<CurrentTet<<std::endl;
-		FindNewPoint((&CurrentPos),CurrentTri,&CurrentTet,InteriorNormal);
-		//std::cout<<"            CurrentTet after FindNewPoint "<<CurrentTet<<std::endl;
-		//std::cout<<"         FoundNewPoint While"<<std::endl;
-//		CurrentTet = CurrentTet->getNeigh((*CurrentTri));
-//		//std::cout<<"         GotNeigh While"<<std::endl;
-		DistToOppSide += CurrentPos.distance(LastPos);
-		LastPos = CurrentPos;
+  double DistToOppSide = 0.0;
+  //We assume v is on the boundary
+  //First we need to get the internal normal
+  //std::cout<<"      Entering ComputeDistToOppSide Function"<<std::endl;
+  SVector3 InteriorNormal = GMSH_ThinLayerFixMeshPlugin::computeInteriorNormal(v);
+  //std::cout<<"      Normal computed"<<std::endl;
+  //Then we find the first triangle
+  MTet4* FirstTet = GMSH_ThinLayerFixMeshPlugin::getTetFromPoint(v,InteriorNormal);
+  //std::cout<<"   FirstTet is tet "<<FirstTet->tet()->getNum()<<std::endl;
+  //std::cout<<"      got FirstTet"<<std::endl;
+  MTet4* CurrentTet = FirstTet;
+  //std::cout<<"      set currentTet"<<std::endl;
+  MTet4* PastTet = FirstTet;
+  //std::cout<<"      set PastTet"<<std::endl;
+  SPoint3 CurrentPos = SPoint3(v->x(),v->y(),v->z());
+  //std::cout<<"      set CurrentPos"<<std::endl;
+  SPoint3 LastPos = CurrentPos;
+  //std::cout<<"      set LasPos"<<std::endl;
+  int CurrentTriValue = 0;
+  int* CurrentTri = &CurrentTriValue;
+  //std::cout<<"      set CurrentTri"<<std::endl;
+  CorrespVerticesFixMesh* CVTemp = new CorrespVerticesFixMesh();
+  //std::cout<<"      Created CVTemp"<<std::endl;
+  CorrespVerticesFixMesh CVTemp2;
+  //std::cout<<"      Created CVTemp2"<<std::endl;
+  CVTemp->setStartPoint(v);
+  CVTemp2.setStartPoint(v);
+  //std::cout<<"      setStartPoint"<<std::endl;
+  CVTemp->setStartNormal(InteriorNormal);
+  CVTemp2.setStartNormal(InteriorNormal);
+  //std::cout<<"      setStartNormal"<<std::endl;
+  FindNewPoint((&CurrentPos),CurrentTri,&CurrentTet,InteriorNormal);
+  DistToOppSide += CurrentPos.distance(LastPos);
+  LastPos = CurrentPos;
+  //std::cout<<"      Found New Point"<<std::endl;
+  //	faceXtetFM fxtCV(PastTet,(*CurrentTri));
+  //	CVTemp->setEndTriangle(&fxtCV);
+  //	while(CurrentTet->getNeigh((*CurrentTri)) != 0){
+  int countWhile = 0;
+  int prevprevtet = 1;
+  int prevtet = 2;
+  while((CurrentTet != 0) && (countWhile < 50)){
+    //std::cout<<"                                    Entering While"<<std::endl;
+    //std::cout<<"CurrentTet is "<<CurrentTet->tet()->getNum()<< "adress "<<CurrentTet<< " and currentTri "<<(*CurrentTri)<<std::endl;
+    //std::cout<<"currentPos is "<<CurrentPos.x()<<" ; "<<CurrentPos.y()<<" ; "<<CurrentPos.z()<<std::endl;
+    countWhile++;
+    faceXtetFM fxtCVtmp(PastTet,(*CurrentTri));
+    PastTet = CurrentTet;
+    CVTemp->setEndTrianglePoint1(PastTet->tet()->getVertex(faces[(*CurrentTri)][0]));
+    CVTemp->setEndTrianglePoint2(PastTet->tet()->getVertex(faces[(*CurrentTri)][1]));
+    CVTemp->setEndTrianglePoint3(PastTet->tet()->getVertex(faces[(*CurrentTri)][2]));
+    CVTemp2.setEndTrianglePoint1(PastTet->tet()->getVertex(faces[(*CurrentTri)][0]));
+    CVTemp2.setEndTrianglePoint2(PastTet->tet()->getVertex(faces[(*CurrentTri)][1]));
+    CVTemp2.setEndTrianglePoint3(PastTet->tet()->getVertex(faces[(*CurrentTri)][2]));
+    //		CVTemp->setEndTriangle(fxtCVtmp);
+    //		CVTemp2.setEndTriangle(fxtCVtmp);
+    //std::cout<<"         FaceXTetCreated"<<std::endl;
+    //std::cout<<"         Testing FaceXTet in while "<<fxtCVtmp.t1->tet()->getNum()<<std::endl;
+    //std::cout<<"            CurrentTet before FindNewPoint "<<CurrentTet<<std::endl;
+    FindNewPoint((&CurrentPos),CurrentTri,&CurrentTet,InteriorNormal);
+    //std::cout<<"            CurrentTet after FindNewPoint "<<CurrentTet<<std::endl;
+    //std::cout<<"         FoundNewPoint While"<<std::endl;
+    //		CurrentTet = CurrentTet->getNeigh((*CurrentTri));
+    //		//std::cout<<"         GotNeigh While"<<std::endl;
+    DistToOppSide += CurrentPos.distance(LastPos);
+    LastPos = CurrentPos;
 
-		if (CurrentTet != 0){
-			if ((CurrentTet->tet()->getNum()) == prevprevtet){
-				//std::cout<<"reached standstill"<<std::endl;
-				while (1){
+    if (CurrentTet != 0){
+      if ((CurrentTet->tet()->getNum()) == prevprevtet){
+        //std::cout<<"reached standstill"<<std::endl;
+        while (1){
 
-				}
-			}
-			prevprevtet = prevtet;
-			prevtet=CurrentTet->tet()->getNum();
-		}
-		//std::cout<<"                                    Exiting While"<<std::endl;
-	}
-	//std::cout<<"      Out Of While"<<std::endl;
-	CVTemp->setEndPoint(LastPos);
-	CVTemp2.setEndPoint(LastPos);
-	faceXtetFM fxtCV(PastTet,(*CurrentTri));
-	//std::cout<<"         Testing FaceXTet out of while "<<fxtCV.t1->tet()->getNum()<<std::endl;
-	CVTemp->setEndTrianglePoint1(PastTet->tet()->getVertex(faces[(*CurrentTri)][0]));
-	CVTemp->setEndTrianglePoint2(PastTet->tet()->getVertex(faces[(*CurrentTri)][1]));
-	CVTemp->setEndTrianglePoint3(PastTet->tet()->getVertex(faces[(*CurrentTri)][2]));
-	CVTemp2.setEndTrianglePoint1(PastTet->tet()->getVertex(faces[(*CurrentTri)][0]));
-	CVTemp2.setEndTrianglePoint2(PastTet->tet()->getVertex(faces[(*CurrentTri)][1]));
-	CVTemp2.setEndTrianglePoint3(PastTet->tet()->getVertex(faces[(*CurrentTri)][2]));
-//	CVTemp->setEndTriangle(fxtCV);
-//	CVTemp2.setEndTriangle(fxtCV);
-//	//std::cout<<"         Testing FaceXTet out of while second time "<<CVTemp->getEndTriangle().t1->tet()->getNum()<<std::endl;
-//	//std::cout<<"         Testing FaceXTet out of while second time CVTemp2 "<<CVTemp2.getEndTriangle().t1->tet()->getNum()<<std::endl;
-//	CVTemp->setEndTriangle(&fxtCV);
-//	SVector3 EndDir1(fxtCV.v[1]->x() - fxtCV.v[0]->x(),fxtCV.v[1]->y() - fxtCV.v[0]->y(),fxtCV.v[1]->z() - fxtCV.v[0]->z());
-//	SVector3 EndDir2(fxtCV.v[2]->x() - fxtCV.v[0]->x(),fxtCV.v[2]->y() - fxtCV.v[0]->y(),fxtCV.v[2]->z() - fxtCV.v[0]->z());
-//	SVector3 EndNormal(EndDir1.y() * EndDir2.z() - EndDir1.z() * EndDir2.y(),EndDir1.z() * EndDir2.x() - EndDir1.x() * EndDir2.z(),EndDir1.x() * EndDir2.y() - EndDir1.y() * EndDir2.x());
-	SVector3 EndNormal(-InteriorNormal.x(),-InteriorNormal.y(),-InteriorNormal.z());
-	EndNormal.normalize();
-	CVTemp->setEndNormal(EndNormal);
-	CVTemp2.setEndNormal(EndNormal);
-	CVTemp->setangleProd(fabs(CVTemp->getStartNormal().x() * CVTemp->getEndNormal().x() + CVTemp->getStartNormal().y() * CVTemp->getEndNormal().y() + CVTemp->getStartNormal().z() * CVTemp->getEndNormal().z()));
-	CVTemp2.setangleProd(fabs(CVTemp2.getStartNormal().x() * CVTemp2.getEndNormal().x() + CVTemp2.getStartNormal().y() * CVTemp2.getEndNormal().y() + CVTemp2.getStartNormal().z() * CVTemp2.getEndNormal().z()));
-	CVTemp->setdistP2P(DistToOppSide);
-	CVTemp2.setdistP2P(DistToOppSide);
-	if ((CVTemp->getangleProd() > angleMax) &&(CVTemp->getdistP2P() < distP2PMax)){
-		CVTemp->setActive(true);
-	}
-	else{
-		CVTemp->setActive(false);
-	}
-	if ((CVTemp2.getangleProd() > angleMax) &&(CVTemp2.getdistP2P() < distP2PMax)){
-		CVTemp2.setActive(true);
-	}
-	else{
-		CVTemp2.setActive(false);
-	}
-	CVTemp->setTagMaster(-2);
-	CVTemp2.setTagMaster(-2);
-	//std::cout<<"            getEndNormal is "<<CVTemp2.getEndNormal().x()<<" ; "<<CVTemp2.getEndNormal().y()<<" ; "<<CVTemp2.getEndNormal().z()<<std::endl;
-	//std::cout<<"            getEndNormal is "<<CVTemp2.getEndNormal().x()<<" ; "<<CVTemp2.getEndNormal().y()<<" ; "<<CVTemp2.getEndNormal().z()<<std::endl;
+        }
+      }
+      prevprevtet = prevtet;
+      prevtet=CurrentTet->tet()->getNum();
+    }
+    //std::cout<<"                                    Exiting While"<<std::endl;
+  }
+  //std::cout<<"      Out Of While"<<std::endl;
+  CVTemp->setEndPoint(LastPos);
+  CVTemp2.setEndPoint(LastPos);
+  faceXtetFM fxtCV(PastTet,(*CurrentTri));
+  //std::cout<<"         Testing FaceXTet out of while "<<fxtCV.t1->tet()->getNum()<<std::endl;
+  CVTemp->setEndTrianglePoint1(PastTet->tet()->getVertex(faces[(*CurrentTri)][0]));
+  CVTemp->setEndTrianglePoint2(PastTet->tet()->getVertex(faces[(*CurrentTri)][1]));
+  CVTemp->setEndTrianglePoint3(PastTet->tet()->getVertex(faces[(*CurrentTri)][2]));
+  CVTemp2.setEndTrianglePoint1(PastTet->tet()->getVertex(faces[(*CurrentTri)][0]));
+  CVTemp2.setEndTrianglePoint2(PastTet->tet()->getVertex(faces[(*CurrentTri)][1]));
+  CVTemp2.setEndTrianglePoint3(PastTet->tet()->getVertex(faces[(*CurrentTri)][2]));
+  //	CVTemp->setEndTriangle(fxtCV);
+  //	CVTemp2.setEndTriangle(fxtCV);
+  //	//std::cout<<"         Testing FaceXTet out of while second time "<<CVTemp->getEndTriangle().t1->tet()->getNum()<<std::endl;
+  //	//std::cout<<"         Testing FaceXTet out of while second time CVTemp2 "<<CVTemp2.getEndTriangle().t1->tet()->getNum()<<std::endl;
+  //	CVTemp->setEndTriangle(&fxtCV);
+  //	SVector3 EndDir1(fxtCV.v[1]->x() - fxtCV.v[0]->x(),fxtCV.v[1]->y() - fxtCV.v[0]->y(),fxtCV.v[1]->z() - fxtCV.v[0]->z());
+  //	SVector3 EndDir2(fxtCV.v[2]->x() - fxtCV.v[0]->x(),fxtCV.v[2]->y() - fxtCV.v[0]->y(),fxtCV.v[2]->z() - fxtCV.v[0]->z());
+  //	SVector3 EndNormal(EndDir1.y() * EndDir2.z() - EndDir1.z() * EndDir2.y(),EndDir1.z() * EndDir2.x() - EndDir1.x() * EndDir2.z(),EndDir1.x() * EndDir2.y() - EndDir1.y() * EndDir2.x());
+  SVector3 EndNormal(-InteriorNormal.x(),-InteriorNormal.y(),-InteriorNormal.z());
+  EndNormal.normalize();
+  CVTemp->setEndNormal(EndNormal);
+  CVTemp2.setEndNormal(EndNormal);
+  CVTemp->setangleProd(fabs(CVTemp->getStartNormal().x() * CVTemp->getEndNormal().x() + CVTemp->getStartNormal().y() * CVTemp->getEndNormal().y() + CVTemp->getStartNormal().z() * CVTemp->getEndNormal().z()));
+  CVTemp2.setangleProd(fabs(CVTemp2.getStartNormal().x() * CVTemp2.getEndNormal().x() + CVTemp2.getStartNormal().y() * CVTemp2.getEndNormal().y() + CVTemp2.getStartNormal().z() * CVTemp2.getEndNormal().z()));
+  CVTemp->setdistP2P(DistToOppSide);
+  CVTemp2.setdistP2P(DistToOppSide);
+  if ((CVTemp->getangleProd() > angleMax) &&(CVTemp->getdistP2P() < distP2PMax)){
+    CVTemp->setActive(true);
+  }
+  else{
+    CVTemp->setActive(false);
+  }
+  if ((CVTemp2.getangleProd() > angleMax) &&(CVTemp2.getdistP2P() < distP2PMax)){
+    CVTemp2.setActive(true);
+  }
+  else{
+    CVTemp2.setActive(false);
+  }
+  CVTemp->setTagMaster(-2);
+  CVTemp2.setTagMaster(-2);
+  //std::cout<<"            getEndNormal is "<<CVTemp2.getEndNormal().x()<<" ; "<<CVTemp2.getEndNormal().y()<<" ; "<<CVTemp2.getEndNormal().z()<<std::endl;
+  //std::cout<<"            getEndNormal is "<<CVTemp2.getEndNormal().x()<<" ; "<<CVTemp2.getEndNormal().y()<<" ; "<<CVTemp2.getEndNormal().z()<<std::endl;
 
-	VertexToCorresp[v].push_back(CVTemp);
-//	VertexToCorresp[v].push_back(&CVTemp2);
-	//std::cout<<"              getEndNormal test is "<<VertexToCorresp[v][VertexToCorresp[v].size() - 1]->getEndNormal().x()<<" ; "<<VertexToCorresp[v][VertexToCorresp[v].size() - 1]->getEndNormal().y()<<" ; "<<VertexToCorresp[v][VertexToCorresp[v].size() - 1]->getEndNormal().z()<<std::endl;
-	//std::cout<<"              getEndNormal is "<<VertexToCorresp[v][VertexToCorresp[v].size() - 1]->getEndNormal().x()<<" ; "<<VertexToCorresp[v][VertexToCorresp[v].size() - 1]->getEndNormal().y()<<" ; "<<VertexToCorresp[v][VertexToCorresp[v].size() - 1]->getEndNormal().z()<<std::endl;
-	//std::cout<<"              getEndNormal is "<<VertexToCorresp[v][VertexToCorresp[v].size() - 1]->getEndNormal().x()<<" ; "<<VertexToCorresp[v][VertexToCorresp[v].size() - 1]->getEndNormal().y()<<" ; "<<VertexToCorresp[v][VertexToCorresp[v].size() - 1]->getEndNormal().z()<<std::endl;
-	//std::cout<<"              getEndNormal is "<<VertexToCorresp[v][VertexToCorresp[v].size() - 1]->getEndNormal().x()<<" ; "<<VertexToCorresp[v][VertexToCorresp[v].size() - 1]->getEndNormal().y()<<" ; "<<VertexToCorresp[v][VertexToCorresp[v].size() - 1]->getEndNormal().z()<<std::endl;
+  VertexToCorresp[v].push_back(CVTemp);
+  //	VertexToCorresp[v].push_back(&CVTemp2);
+  //std::cout<<"              getEndNormal test is "<<VertexToCorresp[v][VertexToCorresp[v].size() - 1]->getEndNormal().x()<<" ; "<<VertexToCorresp[v][VertexToCorresp[v].size() - 1]->getEndNormal().y()<<" ; "<<VertexToCorresp[v][VertexToCorresp[v].size() - 1]->getEndNormal().z()<<std::endl;
+  //std::cout<<"              getEndNormal is "<<VertexToCorresp[v][VertexToCorresp[v].size() - 1]->getEndNormal().x()<<" ; "<<VertexToCorresp[v][VertexToCorresp[v].size() - 1]->getEndNormal().y()<<" ; "<<VertexToCorresp[v][VertexToCorresp[v].size() - 1]->getEndNormal().z()<<std::endl;
+  //std::cout<<"              getEndNormal is "<<VertexToCorresp[v][VertexToCorresp[v].size() - 1]->getEndNormal().x()<<" ; "<<VertexToCorresp[v][VertexToCorresp[v].size() - 1]->getEndNormal().y()<<" ; "<<VertexToCorresp[v][VertexToCorresp[v].size() - 1]->getEndNormal().z()<<std::endl;
+  //std::cout<<"              getEndNormal is "<<VertexToCorresp[v][VertexToCorresp[v].size() - 1]->getEndNormal().x()<<" ; "<<VertexToCorresp[v][VertexToCorresp[v].size() - 1]->getEndNormal().y()<<" ; "<<VertexToCorresp[v][VertexToCorresp[v].size() - 1]->getEndNormal().z()<<std::endl;
 
-	return DistToOppSide;
+  return DistToOppSide;
 }
 
 SVector3 GMSH_ThinLayerFixMeshPlugin::computeInteriorNormal(MVertex* v){
-	SPoint3 InteriorNormal(0.0,0.0,0.0);
-	//std::cout<<"         Entering computeInteriorNormal"<<std::endl;
-	std::vector<MTetrahedron*> currentVecTet = VertexToTets[v];
-	std::vector<SPoint3> vecInteriorNodes;
-	std::vector<SPoint3> vecFirstDir;
-	std::vector<SPoint3> vecSecondDir;
-	for (unsigned int i = 0;i < currentVecTet.size();i++){
-		//std::cout<<"            Entering for "<<i<<std::endl;
-		MTet4* tet4Tmp = TetToTet4[currentVecTet[i]];
-		for (int j = 0;j < 4 ; j++){
-			//std::cout<<"            Entering for "<<j<<std::endl;
-			if (tet4Tmp->getNeigh(j) == 0){
-				//std::cout<<"               Test Passed neigh zero "<<std::endl;
-				//find the 4th point,and fill the two vector of the boundary triangle
-				faceXtetFM fxtTmp(tet4Tmp,j);
-				//std::cout<<"               Face Created "<<j<<std::endl;
-				for (int k = 0;k < 4;k++){
-					//std::cout<<"                  Entering for "<<k<<std::endl;
-					bool foundInteriorPoint = true;
-					for (int l = 0;l < 3;l++){
-						if (tet4Tmp->tet()->getVertex(k) == fxtTmp.v[l]){
-							foundInteriorPoint = false;
-						}
-					}
-					if (foundInteriorPoint){
-						SPoint3 pointTmp(tet4Tmp->tet()->getVertex(k)->x(),tet4Tmp->tet()->getVertex(k)->y(),tet4Tmp->tet()->getVertex(k)->z());
-						vecInteriorNodes.push_back(pointTmp);
-					}
-				}
-				SPoint3 pointTmp1(fxtTmp.v[1]->x() - fxtTmp.v[0]->x(),fxtTmp.v[1]->y() - fxtTmp.v[0]->y(),fxtTmp.v[1]->z() - fxtTmp.v[0]->z());
-				SPoint3 pointTmp2(fxtTmp.v[2]->x() - fxtTmp.v[0]->x(),fxtTmp.v[2]->y() - fxtTmp.v[0]->y(),fxtTmp.v[2]->z() - fxtTmp.v[0]->z());
-				vecFirstDir.push_back(pointTmp1);
-				vecSecondDir.push_back(pointTmp2);
-			}
-		}
-	}
-	//std::cout<<"         Out of loop for "<<std::endl;
-	//at this point we have all the info necessary.
-	SPoint3 pointInteriorAverage(0.0,0.0,0.0);
-	for (unsigned int i = 0;i < vecInteriorNodes.size();i++){
-		pointInteriorAverage += SPoint3(vecInteriorNodes[i].x(),vecInteriorNodes[i].y(),vecInteriorNodes[i].z());
-//		pointInteriorAverage.x() += vecInteriorNodes[i].x();
-//		pointInteriorAverage.y() += vecInteriorNodes[i].y();
-//		pointInteriorAverage.z() += vecInteriorNodes[i].z();
-	}
-	pointInteriorAverage = SPoint3(pointInteriorAverage.x() / (double(vecInteriorNodes.size())),pointInteriorAverage.y() / (double(vecInteriorNodes.size())),pointInteriorAverage.z() / (double(vecInteriorNodes.size())));
-//	pointInteriorAverage.x() = pointInteriorAverage.x() / (double(vecInteriorNodes.size()));
-//	pointInteriorAverage.y() = pointInteriorAverage.y() / (double(vecInteriorNodes.size()));
-//	pointInteriorAverage.z() = pointInteriorAverage.z() / (double(vecInteriorNodes.size()));
-	SPoint3 dirInteriorAverage(pointInteriorAverage.x() - v->x(),pointInteriorAverage.y() - v->y(),pointInteriorAverage.z() - v->z());
-	double norme = sqrt(dirInteriorAverage.x() * dirInteriorAverage.x() + dirInteriorAverage.y() * dirInteriorAverage.y() + dirInteriorAverage.z() * dirInteriorAverage.z());
-	dirInteriorAverage = SPoint3(dirInteriorAverage.x() / norme,dirInteriorAverage.y() / norme,dirInteriorAverage.z() / norme);
-//	dirInteriorAverage.x() = dirInteriorAverage.x() / norme;
-//	dirInteriorAverage.y() = dirInteriorAverage.y() / norme;
-//	dirInteriorAverage.z() = dirInteriorAverage.z() / norme;
-	std::vector<SPoint3> vecOrthogDir;
-	for(unsigned int i = 0;i < vecFirstDir.size();i++){
-		SPoint3 pointTmp(vecFirstDir[i].y() * vecSecondDir[i].z() - vecFirstDir[i].z() * vecSecondDir[i].y(),vecFirstDir[i].z() * vecSecondDir[i].x() - vecFirstDir[i].x() * vecSecondDir[i].z(),vecFirstDir[i].x() * vecSecondDir[i].y() - vecFirstDir[i].y() * vecSecondDir[i].x());
-		vecOrthogDir.push_back(pointTmp);
-	}
-	for(unsigned int i = 0;i < vecOrthogDir.size();i++){
-		double prodScalTmp = vecOrthogDir[i].x() * dirInteriorAverage.x() + vecOrthogDir[i].y() * dirInteriorAverage.y() + vecOrthogDir[i].z() * dirInteriorAverage.z();
-		if (prodScalTmp < 0.0){
-			vecOrthogDir[i] = SPoint3(- vecOrthogDir[i].x(),- vecOrthogDir[i].y(),- vecOrthogDir[i].z());
-//			vecOrthogDir[i].x() = - vecOrthogDir[i].x();
-//			vecOrthogDir[i].y() = - vecOrthogDir[i].y();
-//			vecOrthogDir[i].z() = - vecOrthogDir[i].z();
-		}
-		double normeTmp = sqrt(vecOrthogDir[i].x() * vecOrthogDir[i].x() + vecOrthogDir[i].y() * vecOrthogDir[i].y() + vecOrthogDir[i].z() * vecOrthogDir[i].z());
-		vecOrthogDir[i] = SPoint3(vecOrthogDir[i].x() / normeTmp,vecOrthogDir[i].y() / normeTmp,vecOrthogDir[i].z() / normeTmp);
-//		vecOrthogDir[i].x() = vecOrthogDir[i].x() / normeTmp;
-//		vecOrthogDir[i].y() = vecOrthogDir[i].y() / normeTmp;
-//		vecOrthogDir[i].z() = vecOrthogDir[i].z() / normeTmp;
-		InteriorNormal += SPoint3(vecOrthogDir[i].x(),vecOrthogDir[i].y(),vecOrthogDir[i].z());
-//		InteriorNormal.x() += vecOrthogDir[i].x();
-//		InteriorNormal.y() += vecOrthogDir[i].y();
-//		InteriorNormal.z() += vecOrthogDir[i].z();
-	}
-	norme = sqrt(InteriorNormal.x() * InteriorNormal.x() + InteriorNormal.y() * InteriorNormal.y() + InteriorNormal.z() * InteriorNormal.z());
-	InteriorNormal = SPoint3(InteriorNormal.x() / norme,InteriorNormal.y() / norme,InteriorNormal.z() / norme);
-//	InteriorNormal.x() = InteriorNormal.x() / norme;
-//	InteriorNormal.y() = InteriorNormal.y() / norme;
-//	InteriorNormal.z() = InteriorNormal.z() / norme;
-	return InteriorNormal;
+  SPoint3 InteriorNormal(0.0,0.0,0.0);
+  //std::cout<<"         Entering computeInteriorNormal"<<std::endl;
+  std::vector<MTetrahedron*> currentVecTet = VertexToTets[v];
+  std::vector<SPoint3> vecInteriorNodes;
+  std::vector<SPoint3> vecFirstDir;
+  std::vector<SPoint3> vecSecondDir;
+  for (unsigned int i = 0;i < currentVecTet.size();i++){
+    //std::cout<<"            Entering for "<<i<<std::endl;
+    MTet4* tet4Tmp = TetToTet4[currentVecTet[i]];
+    for (int j = 0;j < 4 ; j++){
+      //std::cout<<"            Entering for "<<j<<std::endl;
+      if (tet4Tmp->getNeigh(j) == 0){
+        //std::cout<<"               Test Passed neigh zero "<<std::endl;
+        //find the 4th point,and fill the two vector of the boundary triangle
+        faceXtetFM fxtTmp(tet4Tmp,j);
+        //std::cout<<"               Face Created "<<j<<std::endl;
+        for (int k = 0;k < 4;k++){
+          //std::cout<<"                  Entering for "<<k<<std::endl;
+          bool foundInteriorPoint = true;
+          for (int l = 0;l < 3;l++){
+            if (tet4Tmp->tet()->getVertex(k) == fxtTmp.v[l]){
+              foundInteriorPoint = false;
+            }
+          }
+          if (foundInteriorPoint){
+            SPoint3 pointTmp(tet4Tmp->tet()->getVertex(k)->x(),tet4Tmp->tet()->getVertex(k)->y(),tet4Tmp->tet()->getVertex(k)->z());
+            vecInteriorNodes.push_back(pointTmp);
+          }
+        }
+        SPoint3 pointTmp1(fxtTmp.v[1]->x() - fxtTmp.v[0]->x(),fxtTmp.v[1]->y() - fxtTmp.v[0]->y(),fxtTmp.v[1]->z() - fxtTmp.v[0]->z());
+        SPoint3 pointTmp2(fxtTmp.v[2]->x() - fxtTmp.v[0]->x(),fxtTmp.v[2]->y() - fxtTmp.v[0]->y(),fxtTmp.v[2]->z() - fxtTmp.v[0]->z());
+        vecFirstDir.push_back(pointTmp1);
+        vecSecondDir.push_back(pointTmp2);
+      }
+    }
+  }
+  //std::cout<<"         Out of loop for "<<std::endl;
+  //at this point we have all the info necessary.
+  SPoint3 pointInteriorAverage(0.0,0.0,0.0);
+  for (unsigned int i = 0;i < vecInteriorNodes.size();i++){
+    pointInteriorAverage += SPoint3(vecInteriorNodes[i].x(),vecInteriorNodes[i].y(),vecInteriorNodes[i].z());
+    //		pointInteriorAverage.x() += vecInteriorNodes[i].x();
+    //		pointInteriorAverage.y() += vecInteriorNodes[i].y();
+    //		pointInteriorAverage.z() += vecInteriorNodes[i].z();
+  }
+  pointInteriorAverage = SPoint3(pointInteriorAverage.x() / (double(vecInteriorNodes.size())),pointInteriorAverage.y() / (double(vecInteriorNodes.size())),pointInteriorAverage.z() / (double(vecInteriorNodes.size())));
+  //	pointInteriorAverage.x() = pointInteriorAverage.x() / (double(vecInteriorNodes.size()));
+  //	pointInteriorAverage.y() = pointInteriorAverage.y() / (double(vecInteriorNodes.size()));
+  //	pointInteriorAverage.z() = pointInteriorAverage.z() / (double(vecInteriorNodes.size()));
+  SPoint3 dirInteriorAverage(pointInteriorAverage.x() - v->x(),pointInteriorAverage.y() - v->y(),pointInteriorAverage.z() - v->z());
+  double norme = sqrt(dirInteriorAverage.x() * dirInteriorAverage.x() + dirInteriorAverage.y() * dirInteriorAverage.y() + dirInteriorAverage.z() * dirInteriorAverage.z());
+  dirInteriorAverage = SPoint3(dirInteriorAverage.x() / norme,dirInteriorAverage.y() / norme,dirInteriorAverage.z() / norme);
+  //	dirInteriorAverage.x() = dirInteriorAverage.x() / norme;
+  //	dirInteriorAverage.y() = dirInteriorAverage.y() / norme;
+  //	dirInteriorAverage.z() = dirInteriorAverage.z() / norme;
+  std::vector<SPoint3> vecOrthogDir;
+  for(unsigned int i = 0;i < vecFirstDir.size();i++){
+    SPoint3 pointTmp(vecFirstDir[i].y() * vecSecondDir[i].z() - vecFirstDir[i].z() * vecSecondDir[i].y(),vecFirstDir[i].z() * vecSecondDir[i].x() - vecFirstDir[i].x() * vecSecondDir[i].z(),vecFirstDir[i].x() * vecSecondDir[i].y() - vecFirstDir[i].y() * vecSecondDir[i].x());
+    vecOrthogDir.push_back(pointTmp);
+  }
+  for(unsigned int i = 0;i < vecOrthogDir.size();i++){
+    double prodScalTmp = vecOrthogDir[i].x() * dirInteriorAverage.x() + vecOrthogDir[i].y() * dirInteriorAverage.y() + vecOrthogDir[i].z() * dirInteriorAverage.z();
+    if (prodScalTmp < 0.0){
+      vecOrthogDir[i] = SPoint3(- vecOrthogDir[i].x(),- vecOrthogDir[i].y(),- vecOrthogDir[i].z());
+      //			vecOrthogDir[i].x() = - vecOrthogDir[i].x();
+      //			vecOrthogDir[i].y() = - vecOrthogDir[i].y();
+      //			vecOrthogDir[i].z() = - vecOrthogDir[i].z();
+    }
+    double normeTmp = sqrt(vecOrthogDir[i].x() * vecOrthogDir[i].x() + vecOrthogDir[i].y() * vecOrthogDir[i].y() + vecOrthogDir[i].z() * vecOrthogDir[i].z());
+    vecOrthogDir[i] = SPoint3(vecOrthogDir[i].x() / normeTmp,vecOrthogDir[i].y() / normeTmp,vecOrthogDir[i].z() / normeTmp);
+    //		vecOrthogDir[i].x() = vecOrthogDir[i].x() / normeTmp;
+    //		vecOrthogDir[i].y() = vecOrthogDir[i].y() / normeTmp;
+    //		vecOrthogDir[i].z() = vecOrthogDir[i].z() / normeTmp;
+    InteriorNormal += SPoint3(vecOrthogDir[i].x(),vecOrthogDir[i].y(),vecOrthogDir[i].z());
+    //		InteriorNormal.x() += vecOrthogDir[i].x();
+    //		InteriorNormal.y() += vecOrthogDir[i].y();
+    //		InteriorNormal.z() += vecOrthogDir[i].z();
+  }
+  norme = sqrt(InteriorNormal.x() * InteriorNormal.x() + InteriorNormal.y() * InteriorNormal.y() + InteriorNormal.z() * InteriorNormal.z());
+  InteriorNormal = SPoint3(InteriorNormal.x() / norme,InteriorNormal.y() / norme,InteriorNormal.z() / norme);
+  //	InteriorNormal.x() = InteriorNormal.x() / norme;
+  //	InteriorNormal.y() = InteriorNormal.y() / norme;
+  //	InteriorNormal.z() = InteriorNormal.z() / norme;
+  return InteriorNormal;
 }
 
 MTet4* GMSH_ThinLayerFixMeshPlugin::getTetFromPoint(MVertex* v, SVector3 InteriorNormal){
-	MTet4* TetToGet = 0;
-	std::vector<MTetrahedron*> currentVecTet = VertexToTets[v];
-	//std::cout<<"   entering getTetFromPoint, vertex "<<v->x()<<" ; "<<v->y()<<" ; "<<v->z()<<" and dir "<<InteriorNormal.x()<<" ; "<<InteriorNormal.y()<<" ; "<<InteriorNormal.z()<<std::endl;
-	for (unsigned int i = 0;i < currentVecTet.size();i++){
-		std::vector<SVector3> vecDir;
-		for (int j = 0;j < 4 ; j++){
-			if (currentVecTet[i]->getVertex(j) != v){
-				SVector3 DirTmp(currentVecTet[i]->getVertex(j)->x() - v->x(),currentVecTet[i]->getVertex(j)->y() - v->y(),currentVecTet[i]->getVertex(j)->z() - v->z());
-				vecDir.push_back(DirTmp);
-			}
-		}
-		bool IsPositiv = GMSH_ThinLayerFixMeshPlugin::IsPositivOrientation(vecDir[0],vecDir[1],vecDir[2]);
-		if (!IsPositiv){
-			SVector3 DirTmp1 = vecDir[1];
-			SVector3 DirTmp2 = vecDir[0];
-			SVector3 DirTmp3 = vecDir[2];
-			vecDir.clear();
-			vecDir.push_back(DirTmp1);
-			vecDir.push_back(DirTmp2);
-			vecDir.push_back(DirTmp3);
-		}
-		bool isPositiv1 = GMSH_ThinLayerFixMeshPlugin::IsPositivOrientation(vecDir[0],vecDir[1],InteriorNormal);
-		bool isPositiv2 = GMSH_ThinLayerFixMeshPlugin::IsPositivOrientation(vecDir[1],vecDir[2],InteriorNormal);
-		bool isPositiv3 = GMSH_ThinLayerFixMeshPlugin::IsPositivOrientation(vecDir[2],vecDir[0],InteriorNormal);
-		if (isPositiv1){
-			if (isPositiv2){
-				if (isPositiv3){
-					TetToGet = TetToTet4[currentVecTet[i]];
-					//std::cout<<"      Found one fitting ! "<<TetToGet->tet()->getNum()<<std::endl;
-				}
-			}
-		}
-	}
-	//std::cout<<"   exiting getTetFromPoint with result "<<TetToGet<<std::endl;
-	//std::cout<<"   getTetFromPoint is tet "<<TetToGet->tet()->getNum()<<std::endl;
-	return TetToGet;
+  MTet4* TetToGet = 0;
+  std::vector<MTetrahedron*> currentVecTet = VertexToTets[v];
+  //std::cout<<"   entering getTetFromPoint, vertex "<<v->x()<<" ; "<<v->y()<<" ; "<<v->z()<<" and dir "<<InteriorNormal.x()<<" ; "<<InteriorNormal.y()<<" ; "<<InteriorNormal.z()<<std::endl;
+  for (unsigned int i = 0;i < currentVecTet.size();i++){
+    std::vector<SVector3> vecDir;
+    for (int j = 0;j < 4 ; j++){
+      if (currentVecTet[i]->getVertex(j) != v){
+        SVector3 DirTmp(currentVecTet[i]->getVertex(j)->x() - v->x(),currentVecTet[i]->getVertex(j)->y() - v->y(),currentVecTet[i]->getVertex(j)->z() - v->z());
+        vecDir.push_back(DirTmp);
+      }
+    }
+    bool IsPositiv = GMSH_ThinLayerFixMeshPlugin::IsPositivOrientation(vecDir[0],vecDir[1],vecDir[2]);
+    if (!IsPositiv){
+      SVector3 DirTmp1 = vecDir[1];
+      SVector3 DirTmp2 = vecDir[0];
+      SVector3 DirTmp3 = vecDir[2];
+      vecDir.clear();
+      vecDir.push_back(DirTmp1);
+      vecDir.push_back(DirTmp2);
+      vecDir.push_back(DirTmp3);
+    }
+    bool isPositiv1 = GMSH_ThinLayerFixMeshPlugin::IsPositivOrientation(vecDir[0],vecDir[1],InteriorNormal);
+    bool isPositiv2 = GMSH_ThinLayerFixMeshPlugin::IsPositivOrientation(vecDir[1],vecDir[2],InteriorNormal);
+    bool isPositiv3 = GMSH_ThinLayerFixMeshPlugin::IsPositivOrientation(vecDir[2],vecDir[0],InteriorNormal);
+    if (isPositiv1){
+      if (isPositiv2){
+        if (isPositiv3){
+          TetToGet = TetToTet4[currentVecTet[i]];
+          //std::cout<<"      Found one fitting ! "<<TetToGet->tet()->getNum()<<std::endl;
+        }
+      }
+    }
+  }
+  //std::cout<<"   exiting getTetFromPoint with result "<<TetToGet<<std::endl;
+  //std::cout<<"   getTetFromPoint is tet "<<TetToGet->tet()->getNum()<<std::endl;
+  return TetToGet;
 }
 
 bool GMSH_ThinLayerFixMeshPlugin::IsPositivOrientation(SVector3 a, SVector3 b, SVector3 c){
-	bool result = false;
-	SPoint3 ProdVec(a.y() * b.z() - a.z() * b.y(),a.z() * b.x() - a.x() * b.z(),a.x() * b.y() - a.y() * b.x());
-	double ProdScal = ProdVec.x() * c.x() + ProdVec.y() * c.y() + ProdVec.z() * c.z();
-	if (ProdScal >= 0.0){
-		result = true;
-	}
-	return result;
+  bool result = false;
+  SPoint3 ProdVec(a.y() * b.z() - a.z() * b.y(),a.z() * b.x() - a.x() * b.z(),a.x() * b.y() - a.y() * b.x());
+  double ProdScal = ProdVec.x() * c.x() + ProdVec.y() * c.y() + ProdVec.z() * c.z();
+  if (ProdScal >= 0.0){
+    result = true;
+  }
+  return result;
 }
 
 
 void GMSH_ThinLayerFixMeshPlugin::FindNewPoint(SPoint3* CurrentPoint, int* CurrentTri, MTet4** CurrentTet, SVector3 InteriorNormal){
-	double distanceP2P = 0.0;
-	double alphaMax;
-	double betaMax;
-	SPoint3 ResultPoint;
-	int triToGet = -1;
-	//std::cout<<"   Entered FindNewPoint"<<std::endl;
-	for (unsigned int n = 0;n < 4 ; n++){
-		//calculer matrice a inverser
-		faceXtetFM fxt((*CurrentTet),n);
-		double a = fxt.v[1]->x() - fxt.v[0]->x();
-		double b = fxt.v[2]->x() - fxt.v[0]->x();
-		double c = InteriorNormal.x();
-		double d = fxt.v[1]->y() - fxt.v[0]->y();
-		double e = fxt.v[2]->y() - fxt.v[0]->y();
-		double f = InteriorNormal.y();
-		double g = fxt.v[1]->z() - fxt.v[0]->z();
-		double h = fxt.v[2]->z() - fxt.v[0]->z();
-		double i = InteriorNormal.z();
-		//produit matrice inverse par vecteur donne poids
-		double detMat = a * e * i  + b * f * g + c * d * h - c * e * g - f * h * a - i * b * d;
-		double ai = e * i - f * h;
-		double bi = c * h - b * i;
-		double ci = b * f - c * e;
-		double di = f * g - d * i;
-		double ei = a * i - c * g;
-		double fi = c * d - a * f;
-//		double gi = d * h - e * g;
-//		double hi = b * g - a * h;
-//		double ii = a * e - b * d;
-		double oppx = (*CurrentPoint).x() - fxt.v[0]->x();
-		double oppy = (*CurrentPoint).y() - fxt.v[0]->y();
-		double oppz = (*CurrentPoint).z() - fxt.v[0]->z();
-		double alpha = ai / detMat * oppx + bi / detMat * oppy + ci / detMat * oppz;
-		double beta = di / detMat * oppx + ei / detMat * oppy + fi / detMat * oppz;
-//		double gamma = gi / detMat * oppx + hi / detMat * oppy + ii / detMat * oppz;
-		//Test si poids entre 0 et 1 et si length maximale
-		if ((alpha >= (0.0-epsilon)) && (alpha <= (1.0 + epsilon))){
-			if ((beta >= (0.0-epsilon)) && (beta <= (1.0 + epsilon))){
-				if (((1.0 - alpha - beta) >= (0.0-epsilon)) && ((1.0 - alpha - beta) <= (1.0 + epsilon))){
-					SPoint3 PointTmp(fxt.v[0]->x() + alpha * (fxt.v[1]->x() - fxt.v[0]->x()) + beta * (fxt.v[2]->x() - fxt.v[0]->x()),fxt.v[0]->y() + alpha * (fxt.v[1]->y() - fxt.v[0]->y()) + beta * (fxt.v[2]->y() - fxt.v[0]->y()),fxt.v[0]->z() + alpha * (fxt.v[1]->z() - fxt.v[0]->z()) + beta * (fxt.v[2]->z() - fxt.v[0]->z()));
-					double distanceTmp = PointTmp.distance((*CurrentPoint));
-					if (distanceTmp > distanceP2P){
-						distanceP2P = distanceTmp;
-						ResultPoint = PointTmp;
-						triToGet = n;
-						alphaMax = alpha;
-						betaMax = beta;
-					}
-				}
-			}
-		}
-	}
-	//std::cout<<"   End of For loop"<<std::endl;
-	//test si trop proche d'un point / une arete
-	if (((alphaMax < epsilon) && (betaMax < epsilon)) || ((alphaMax < epsilon) && ((1.0 - alphaMax - betaMax) < epsilon)) || (((1.0 - alphaMax - betaMax) < epsilon) && (betaMax < epsilon))){
-		//proche d'un point
-		//std::cout<<"      Close to point"<<std::endl;
-		double DistMinTmp = 10000000.0;
-		int indexMinTmp;
-		for (unsigned int i = 0;i < 4;i++){
-			double distanceTmp = sqrt(((*CurrentTet)->tet()->getVertex(i)->x() - ResultPoint.x()) * ((*CurrentTet)->tet()->getVertex(i)->x() - ResultPoint.x()) + ((*CurrentTet)->tet()->getVertex(i)->y() - ResultPoint.y()) * ((*CurrentTet)->tet()->getVertex(i)->y() - ResultPoint.y()) + ((*CurrentTet)->tet()->getVertex(i)->z() - ResultPoint.z()) * ((*CurrentTet)->tet()->getVertex(i)->z() - ResultPoint.z()));
-			if (distanceTmp < DistMinTmp){
-				DistMinTmp = distanceTmp;
-				indexMinTmp = i;
-			}
-		}
-		////std::cout<<"NewTet before is "<<NewTet<<std::endl;
-		MTet4* NewTet = GMSH_ThinLayerFixMeshPlugin::getTetFromPoint((*CurrentTet)->tet()->getVertex(indexMinTmp),InteriorNormal);
-		//std::cout<<"NewTet after is "<<NewTet<<std::endl;
-		SPoint3 PointTmp((*CurrentTet)->tet()->getVertex(indexMinTmp)->x(),(*CurrentTet)->tet()->getVertex(indexMinTmp)->y(),(*CurrentTet)->tet()->getVertex(indexMinTmp)->z());
-		(*CurrentPoint) = PointTmp;
-		(*CurrentTet) = NewTet;
-	}
-	else if ((alphaMax < epsilon) || (betaMax < epsilon) || ((1.0 - alphaMax - betaMax) < epsilon)){
-		//trop proche d'une arete
-		//std::cout<<"      Close to edge"<<std::endl;
-	}
-	else{
-		//std::cout<<"      Close to nothing"<<std::endl;
-		//std::cout<<"      ResultPoint is "<<ResultPoint.x()<<"; "<<ResultPoint.y()<<"; "<<ResultPoint.z()<<"; "<<" and tritoget is "<<triToGet<<std::endl;
-		//std::cout<<"      CurrentPoint is "<<(*CurrentPoint).x()<<"; "<<(*CurrentPoint).y()<<"; "<<(*CurrentPoint).z()<<std::endl;
-		(*CurrentPoint) = ResultPoint;
-		//std::cout<<"      test 1"<<std::endl;
-		//std::cout<<"      CurrentTri is "<<(*CurrentTri)<<std::endl;
-		(*CurrentTri) = triToGet;
-		//std::cout<<"      test 2"<<std::endl;
-		//std::cout<<"      CurrentTet is "<<(*CurrentTet)<<" and has neighbours "<< (*CurrentTet)->getNeigh(0)<<" ; "<< (*CurrentTet)->getNeigh(1)<<" ; "<< (*CurrentTet)->getNeigh(2)<<" ; "<< (*CurrentTet)->getNeigh(3)<<std::endl;
-		(*CurrentTet) = (*CurrentTet)->getNeigh(triToGet);
-		//std::cout<<"      CurrentTet has been changed to "<<(*CurrentTet)<<std::endl;
-		//std::cout<<"      test 3"<<std::endl;
-	}
-	//std::cout<<"   Exit FindNewPoint"<<std::endl;
+  double distanceP2P = 0.0;
+  double alphaMax;
+  double betaMax;
+  SPoint3 ResultPoint;
+  int triToGet = -1;
+  //std::cout<<"   Entered FindNewPoint"<<std::endl;
+  for (unsigned int n = 0;n < 4 ; n++){
+    //calculer matrice a inverser
+    faceXtetFM fxt((*CurrentTet),n);
+    double a = fxt.v[1]->x() - fxt.v[0]->x();
+    double b = fxt.v[2]->x() - fxt.v[0]->x();
+    double c = InteriorNormal.x();
+    double d = fxt.v[1]->y() - fxt.v[0]->y();
+    double e = fxt.v[2]->y() - fxt.v[0]->y();
+    double f = InteriorNormal.y();
+    double g = fxt.v[1]->z() - fxt.v[0]->z();
+    double h = fxt.v[2]->z() - fxt.v[0]->z();
+    double i = InteriorNormal.z();
+    //produit matrice inverse par vecteur donne poids
+    double detMat = a * e * i  + b * f * g + c * d * h - c * e * g - f * h * a - i * b * d;
+    double ai = e * i - f * h;
+    double bi = c * h - b * i;
+    double ci = b * f - c * e;
+    double di = f * g - d * i;
+    double ei = a * i - c * g;
+    double fi = c * d - a * f;
+    //		double gi = d * h - e * g;
+    //		double hi = b * g - a * h;
+    //		double ii = a * e - b * d;
+    double oppx = (*CurrentPoint).x() - fxt.v[0]->x();
+    double oppy = (*CurrentPoint).y() - fxt.v[0]->y();
+    double oppz = (*CurrentPoint).z() - fxt.v[0]->z();
+    double alpha = ai / detMat * oppx + bi / detMat * oppy + ci / detMat * oppz;
+    double beta = di / detMat * oppx + ei / detMat * oppy + fi / detMat * oppz;
+    //		double gamma = gi / detMat * oppx + hi / detMat * oppy + ii / detMat * oppz;
+    //Test si poids entre 0 et 1 et si length maximale
+    if ((alpha >= (0.0-epsilon)) && (alpha <= (1.0 + epsilon))){
+      if ((beta >= (0.0-epsilon)) && (beta <= (1.0 + epsilon))){
+        if (((1.0 - alpha - beta) >= (0.0-epsilon)) && ((1.0 - alpha - beta) <= (1.0 + epsilon))){
+          SPoint3 PointTmp(fxt.v[0]->x() + alpha * (fxt.v[1]->x() - fxt.v[0]->x()) + beta * (fxt.v[2]->x() - fxt.v[0]->x()),fxt.v[0]->y() + alpha * (fxt.v[1]->y() - fxt.v[0]->y()) + beta * (fxt.v[2]->y() - fxt.v[0]->y()),fxt.v[0]->z() + alpha * (fxt.v[1]->z() - fxt.v[0]->z()) + beta * (fxt.v[2]->z() - fxt.v[0]->z()));
+          double distanceTmp = PointTmp.distance((*CurrentPoint));
+          if (distanceTmp > distanceP2P){
+            distanceP2P = distanceTmp;
+            ResultPoint = PointTmp;
+            triToGet = n;
+            alphaMax = alpha;
+            betaMax = beta;
+          }
+        }
+      }
+    }
+  }
+  //std::cout<<"   End of For loop"<<std::endl;
+  //test si trop proche d'un point / une arete
+  if (((alphaMax < epsilon) && (betaMax < epsilon)) || ((alphaMax < epsilon) && ((1.0 - alphaMax - betaMax) < epsilon)) || (((1.0 - alphaMax - betaMax) < epsilon) && (betaMax < epsilon))){
+    //proche d'un point
+    //std::cout<<"      Close to point"<<std::endl;
+    double DistMinTmp = 10000000.0;
+    int indexMinTmp;
+    for (unsigned int i = 0;i < 4;i++){
+      double distanceTmp = sqrt(((*CurrentTet)->tet()->getVertex(i)->x() - ResultPoint.x()) * ((*CurrentTet)->tet()->getVertex(i)->x() - ResultPoint.x()) + ((*CurrentTet)->tet()->getVertex(i)->y() - ResultPoint.y()) * ((*CurrentTet)->tet()->getVertex(i)->y() - ResultPoint.y()) + ((*CurrentTet)->tet()->getVertex(i)->z() - ResultPoint.z()) * ((*CurrentTet)->tet()->getVertex(i)->z() - ResultPoint.z()));
+      if (distanceTmp < DistMinTmp){
+        DistMinTmp = distanceTmp;
+        indexMinTmp = i;
+      }
+    }
+    ////std::cout<<"NewTet before is "<<NewTet<<std::endl;
+    MTet4* NewTet = GMSH_ThinLayerFixMeshPlugin::getTetFromPoint((*CurrentTet)->tet()->getVertex(indexMinTmp),InteriorNormal);
+    //std::cout<<"NewTet after is "<<NewTet<<std::endl;
+    SPoint3 PointTmp((*CurrentTet)->tet()->getVertex(indexMinTmp)->x(),(*CurrentTet)->tet()->getVertex(indexMinTmp)->y(),(*CurrentTet)->tet()->getVertex(indexMinTmp)->z());
+    (*CurrentPoint) = PointTmp;
+    (*CurrentTet) = NewTet;
+  }
+  else if ((alphaMax < epsilon) || (betaMax < epsilon) || ((1.0 - alphaMax - betaMax) < epsilon)){
+    //trop proche d'une arete
+    //std::cout<<"      Close to edge"<<std::endl;
+  }
+  else{
+    //std::cout<<"      Close to nothing"<<std::endl;
+    //std::cout<<"      ResultPoint is "<<ResultPoint.x()<<"; "<<ResultPoint.y()<<"; "<<ResultPoint.z()<<"; "<<" and tritoget is "<<triToGet<<std::endl;
+    //std::cout<<"      CurrentPoint is "<<(*CurrentPoint).x()<<"; "<<(*CurrentPoint).y()<<"; "<<(*CurrentPoint).z()<<std::endl;
+    (*CurrentPoint) = ResultPoint;
+    //std::cout<<"      test 1"<<std::endl;
+    //std::cout<<"      CurrentTri is "<<(*CurrentTri)<<std::endl;
+    (*CurrentTri) = triToGet;
+    //std::cout<<"      test 2"<<std::endl;
+    //std::cout<<"      CurrentTet is "<<(*CurrentTet)<<" and has neighbours "<< (*CurrentTet)->getNeigh(0)<<" ; "<< (*CurrentTet)->getNeigh(1)<<" ; "<< (*CurrentTet)->getNeigh(2)<<" ; "<< (*CurrentTet)->getNeigh(3)<<std::endl;
+    (*CurrentTet) = (*CurrentTet)->getNeigh(triToGet);
+    //std::cout<<"      CurrentTet has been changed to "<<(*CurrentTet)<<std::endl;
+    //std::cout<<"      test 3"<<std::endl;
+  }
+  //std::cout<<"   Exit FindNewPoint"<<std::endl;
 }
 
 void GMSH_ThinLayerFixMeshPlugin::fillVertexToTets(){
-	GModel *m = GModel::current();
-	for (GModel::riter itr= m->firstRegion();itr != m->lastRegion();itr++){
-		GRegion* rTmp = (*itr);
-		for (unsigned int i = 0; i < rTmp->tetrahedra.size();i++){
-			MTetrahedron* elem = rTmp->tetrahedra[i];
-			for (unsigned int j = 0; j < 4;j++){
-				std::vector<MTetrahedron*> emptyTetVec;
-				emptyTetVec.clear();
-				VertexToTets[elem->getVertex(j)] = emptyTetVec;
-				std::vector<CorrespVerticesFixMesh*> emptyCVVec;
-				emptyCVVec.clear();
-				VertexToCorresp[elem->getVertex(j)] = emptyCVVec;
-			}
-		}
-	}
-	for (GModel::riter itr= m->firstRegion();itr != m->lastRegion();itr++){
-		GRegion* rTmp = (*itr);
-		for (unsigned int i = 0; i < rTmp->tetrahedra.size();i++){
-			MTetrahedron* elem = rTmp->tetrahedra[i];
-			for (unsigned int j = 0; j < 4;j++){
-				VertexToTets[elem->getVertex(j)].push_back(elem);
-			}
-		}
-	}
+  GModel *m = GModel::current();
+  for (GModel::riter itr= m->firstRegion();itr != m->lastRegion();itr++){
+    GRegion* rTmp = (*itr);
+    for (unsigned int i = 0; i < rTmp->tetrahedra.size();i++){
+      MTetrahedron* elem = rTmp->tetrahedra[i];
+      for (unsigned int j = 0; j < 4;j++){
+        std::vector<MTetrahedron*> emptyTetVec;
+        emptyTetVec.clear();
+        VertexToTets[elem->getVertex(j)] = emptyTetVec;
+        std::vector<CorrespVerticesFixMesh*> emptyCVVec;
+        emptyCVVec.clear();
+        VertexToCorresp[elem->getVertex(j)] = emptyCVVec;
+      }
+    }
+  }
+  for (GModel::riter itr= m->firstRegion();itr != m->lastRegion();itr++){
+    GRegion* rTmp = (*itr);
+    for (unsigned int i = 0; i < rTmp->tetrahedra.size();i++){
+      MTetrahedron* elem = rTmp->tetrahedra[i];
+      for (unsigned int j = 0; j < 4;j++){
+        VertexToTets[elem->getVertex(j)].push_back(elem);
+      }
+    }
+  }
 }
 
 static void setLcsFM(MTriangle *t, std::map<MVertex*, double> &vSizes,
-                   std::set<MVertex*> &bndVertices)
+                     std::set<MVertex*> &bndVertices)
 {
   for(int i = 0; i < 3; i++){
     bndVertices.insert(t->getVertex(i));
@@ -1074,7 +1066,7 @@ static void setLcsFM(MTriangle *t, std::map<MVertex*, double> &vSizes,
 }
 
 static void setLcsFM(MTetrahedron *t, std::map<MVertex*, double> &vSizes,
-                   std::set<MVertex*> &bndVertices)
+                     std::set<MVertex*> &bndVertices)
 {
   for (int i = 0; i < 4; i++){
     for (int j = i + 1; j < 4; j++){
@@ -1098,67 +1090,67 @@ static void setLcsFM(MTetrahedron *t, std::map<MVertex*, double> &vSizes,
 }
 
 void GMSH_ThinLayerFixMeshPlugin::fillTetToTet4(){
-	GModel *m = GModel::current();
-	std::vector<double> vSizes;
-	std::vector<double> vSizesBGM;
-	MTet4Factory myFactory(1600000);
-	std::set<MTet4*, compareTet4Ptr> &allTets = myFactory.getAllTets();
-	std::set<MTet4*, compareTet4Ptr> activeTets;
-	int NUM = 0;
+  GModel *m = GModel::current();
+  std::vector<double> vSizes;
+  std::vector<double> vSizesBGM;
+  MTet4Factory myFactory(1600000);
+  std::set<MTet4*, compareTet4Ptr> &allTets = myFactory.getAllTets();
+  std::set<MTet4*, compareTet4Ptr> activeTets;
+  int NUM = 0;
 
-	for (GModel::riter itr= m->firstRegion();itr != m->lastRegion();itr++){
-		GRegion* gr = (*itr);
-		{ // leave this in a block so the map gets deallocated directly
-			std::map<MVertex*, double> vSizesMap;
-			std::set<MVertex*> bndVertices;
-			for(GModel::fiter it = gr->model()->firstFace(); it != gr->model()->lastFace(); ++it){
-				GFace *gf = *it;
-				for(unsigned int i = 0; i < gf->triangles.size(); i++){
-					setLcsFM(gf->triangles[i], vSizesMap, bndVertices);
-				}
-			}
-			for(unsigned int i = 0; i < gr->tetrahedra.size(); i++)
-				setLcsFM(gr->tetrahedra[i], vSizesMap, bndVertices);
-			for(std::map<MVertex*, double>::iterator it = vSizesMap.begin();
-					it != vSizesMap.end(); ++it){
-				it->first->setIndex(NUM++);
-				vSizes.push_back(it->second);
-				vSizesBGM.push_back(it->second);
-			}
-		}
-		for(unsigned int i = 0; i < gr->tetrahedra.size(); i++)
-		{
-			MTet4* currentTet4 = myFactory.Create(gr->tetrahedra[i], vSizes,vSizesBGM);
-			TetToTet4[gr->tetrahedra[i]] = currentTet4;
-			allTets.insert(currentTet4);
-		}
-	}
+  for (GModel::riter itr= m->firstRegion();itr != m->lastRegion();itr++){
+    GRegion* gr = (*itr);
+    { // leave this in a block so the map gets deallocated directly
+      std::map<MVertex*, double> vSizesMap;
+      std::set<MVertex*> bndVertices;
+      for(GModel::fiter it = gr->model()->firstFace(); it != gr->model()->lastFace(); ++it){
+        GFace *gf = *it;
+        for(unsigned int i = 0; i < gf->triangles.size(); i++){
+          setLcsFM(gf->triangles[i], vSizesMap, bndVertices);
+        }
+      }
+      for(unsigned int i = 0; i < gr->tetrahedra.size(); i++)
+        setLcsFM(gr->tetrahedra[i], vSizesMap, bndVertices);
+      for(std::map<MVertex*, double>::iterator it = vSizesMap.begin();
+          it != vSizesMap.end(); ++it){
+        it->first->setIndex(NUM++);
+        vSizes.push_back(it->second);
+        vSizesBGM.push_back(it->second);
+      }
+    }
+    for(unsigned int i = 0; i < gr->tetrahedra.size(); i++)
+      {
+        MTet4* currentTet4 = myFactory.Create(gr->tetrahedra[i], vSizes,vSizesBGM);
+        TetToTet4[gr->tetrahedra[i]] = currentTet4;
+        allTets.insert(currentTet4);
+      }
+  }
 
 
-	std::vector<MTet4*> vecAllTet4;
-	vecAllTet4.clear();
-	for (std::set<MTet4*, compareTet4Ptr>::iterator itTp = allTets.begin();itTp != allTets.end();itTp++){
-		vecAllTet4.push_back((*itTp));
-//		//std::cout<<"inserted "<<(*itTp)->tet()->getNum()<<std::endl;
-	}
-	connectTets(vecAllTet4);
+  std::vector<MTet4*> vecAllTet4;
+  vecAllTet4.clear();
+  for (std::set<MTet4*, compareTet4Ptr>::iterator itTp = allTets.begin();itTp != allTets.end();itTp++){
+    vecAllTet4.push_back((*itTp));
+    //		//std::cout<<"inserted "<<(*itTp)->tet()->getNum()<<std::endl;
+  }
+  connectTets(vecAllTet4);
 
 
 
-//	GModel *m = GModel::current();
-//	std::vector<MTet4*> vecAllTet4;
-//	vecAllTet4.clear();
-//	for (GModel::riter itr= m->firstRegion();itr != m->lastRegion();itr++){
-//		GRegion* rTmp = (*itr);
-//		for (unsigned int i = 0; i < rTmp->tetrahedra.size();i++){
-//			MTetrahedron* elem = rTmp->tetrahedra[i];
-//			MTet4 tet4tmp = MTet4(elem,0.0);
-//			MTet4* currentTet4 = &tet4tmp;
-//			TetToTet4[elem] = currentTet4;
-//			vecAllTet4.push_back(currentTet4);
-//		}
-//	}
-//	connectTets(vecAllTet4);
+  //	GModel *m = GModel::current();
+  //	std::vector<MTet4*> vecAllTet4;
+  //	vecAllTet4.clear();
+  //	for (GModel::riter itr= m->firstRegion();itr != m->lastRegion();itr++){
+  //		GRegion* rTmp = (*itr);
+  //		for (unsigned int i = 0; i < rTmp->tetrahedra.size();i++){
+  //			MTetrahedron* elem = rTmp->tetrahedra[i];
+  //			MTet4 tet4tmp = MTet4(elem,0.0);
+  //			MTet4* currentTet4 = &tet4tmp;
+  //			TetToTet4[elem] = currentTet4;
+  //			vecAllTet4.push_back(currentTet4);
+  //		}
+  //	}
+  //	connectTets(vecAllTet4);
 }
 
 /****************static declarations****************/
@@ -1177,4 +1169,4 @@ PView *GMSH_ThinLayerFixMeshPlugin::execute(PView *view)
   return view;
 }
 
-#endif
\ No newline at end of file
+#endif
diff --git a/Plugin/ThinLayerFixMesh.h b/Plugin/ThinLayerFixMesh.h
index 083283736869a69e9d869d58ace2d8eb44bb0c40..5575cb496a769e9b1e918ab16a73a6bb83b8b2f1 100644
--- a/Plugin/ThinLayerFixMesh.h
+++ b/Plugin/ThinLayerFixMesh.h
@@ -1,9 +1,9 @@
-/*
- * ThinLayerFixMesh.h
- *
- *  Created on: Oct 13, 2014
- *      Author: nicolas
- */
+// Gmsh - Copyright (C) 1997-2013 C. Geuzaine, J.-F. Remacle
+//
+// See the LICENSE.txt file for license information. Please report all
+// bugs and problems to the public mailing list <gmsh@geuz.org>.
+//
+// Author: Nicolas Kowalski
 
 #ifndef THINLAYERFIXMESH_H_
 #define THINLAYERFIXMESH_H_
@@ -15,7 +15,6 @@
 #include "meshGRegionDelaunayInsertion.h"
 #endif
 
-
 extern "C"
 {
   GMSH_Plugin *GMSH_RegisterThinLayerFixMeshPlugin();
@@ -30,39 +29,39 @@ struct faceXtetFM{
   int i1;
   faceXtetFM(MTet4 *_t=0, int iFac=0) : t1(_t), i1(iFac)
   {
-//	  std::cout<<"entering faceXTet"<<std::endl;
-//	  std::cout<<"tag of tet is "<<t1->tet()->getNum()<<std::endl;
-//	  std::cout<<"first vec of tet is "<<t1->tet()->getVertex(0)->getNum()<<std::endl;
-//	  std::cout<<"second vec of tet is "<<t1->tet()->getVertex(1)->getNum()<<std::endl;
-//	  std::cout<<"third vec of tet is "<<t1->tet()->getVertex(2)->getNum()<<std::endl;
-//	  std::cout<<"fourth vec of tet is "<<t1->tet()->getVertex(3)->getNum()<<std::endl;
+    //	  std::cout<<"entering faceXTet"<<std::endl;
+    //	  std::cout<<"tag of tet is "<<t1->tet()->getNum()<<std::endl;
+    //	  std::cout<<"first vec of tet is "<<t1->tet()->getVertex(0)->getNum()<<std::endl;
+    //	  std::cout<<"second vec of tet is "<<t1->tet()->getVertex(1)->getNum()<<std::endl;
+    //	  std::cout<<"third vec of tet is "<<t1->tet()->getVertex(2)->getNum()<<std::endl;
+    //	  std::cout<<"fourth vec of tet is "<<t1->tet()->getVertex(3)->getNum()<<std::endl;
     MVertex *v0 = t1->tet()->getVertex(faces[iFac][0]);
-//    std::cout<<"after first vert"<<std::endl;
+    //    std::cout<<"after first vert"<<std::endl;
     MVertex *v1 = t1->tet()->getVertex(faces[iFac][1]);
-//    std::cout<<"after second vert"<<std::endl;
+    //    std::cout<<"after second vert"<<std::endl;
     MVertex *v2 = t1->tet()->getVertex(faces[iFac][2]);
-//    std::cout<<"after third vert"<<std::endl;
+    //    std::cout<<"after third vert"<<std::endl;
 
     unsorted[0] = v0;
-//    std::cout<<"after first unsorted"<<std::endl;
+    //    std::cout<<"after first unsorted"<<std::endl;
     unsorted[1] = v1;
-//    std::cout<<"after second unsorted"<<std::endl;
+    //    std::cout<<"after second unsorted"<<std::endl;
     unsorted[2] = v2;
-//    std::cout<<"after third unsorted"<<std::endl;
+    //    std::cout<<"after third unsorted"<<std::endl;
 
     v[0] = std::min(std::min(v0,v1),v2);
-//    std::cout<<"after min"<<std::endl;
+    //    std::cout<<"after min"<<std::endl;
     v[2] = std::max(std::max(v0,v1),v2);
-//    std::cout<<"after max"<<std::endl;
+    //    std::cout<<"after max"<<std::endl;
     v[1] = (v0 != v[0] && v0 != v[2]) ? v0 : (v1 != v[0] && v1 != v[2]) ? v1 : v2;
-//    std::cout<<"after minimax"<<std::endl;
+    //    std::cout<<"after minimax"<<std::endl;
     //
     //    std::sort(v, v + 3);
   }
 
   inline MVertex * getVertex (int i) const { return unsorted[i];}
 
- inline bool operator < (const faceXtetFM & other) const
+  inline bool operator < (const faceXtetFM & other) const
   {
     if (v[0] < other.v[0]) return true;
     if (v[0] > other.v[0]) return false;
@@ -92,51 +91,51 @@ struct faceXtetFM{
 
 class CorrespVerticesFixMesh{
 private:
-	MVertex* StartPoint;
-	SPoint3 EndPoint;
-	SVector3 StartNormal;
-	SVector3 EndNormal;
-	MVertex* EndTrianglePoint1;
-	MVertex* EndTrianglePoint2;
-	MVertex* EndTrianglePoint3;
-//	faceXtetFM EndTriangle;
-	double distP2P;
-	double angleProd;
-	bool Active;
-	bool EndTriangleActive;
-	bool IsMaster;
-	int tagMaster;
+  MVertex* StartPoint;
+  SPoint3 EndPoint;
+  SVector3 StartNormal;
+  SVector3 EndNormal;
+  MVertex* EndTrianglePoint1;
+  MVertex* EndTrianglePoint2;
+  MVertex* EndTrianglePoint3;
+  //	faceXtetFM EndTriangle;
+  double distP2P;
+  double angleProd;
+  bool Active;
+  bool EndTriangleActive;
+  bool IsMaster;
+  int tagMaster;
 public:
-	CorrespVerticesFixMesh();
-	~CorrespVerticesFixMesh();
-	void setStartPoint(MVertex* v);
-	void setEndPoint(SPoint3 p);
-	void setStartNormal(SVector3 v);
-	void setEndNormal(SVector3 v);
-//	void setEndTriangle(faceXtetFM f);
-	void setEndTrianglePoint1(MVertex* v);
-	void setEndTrianglePoint2(MVertex* v);
-	void setEndTrianglePoint3(MVertex* v);
-	void setdistP2P(double d);
-	void setangleProd(double a);
-	void setActive(bool b);
-	void setEndTriangleActive(bool b);
-	void setIsMaster(bool b);
-	void setTagMaster(int i);
-	MVertex* getStartPoint();
-	SPoint3 getEndPoint();
-	SVector3 getStartNormal();
-	SVector3 getEndNormal();
-//	faceXtetFM getEndTriangle();
-	MVertex* getEndTrianglePoint1();
-	MVertex* getEndTrianglePoint2();
-	MVertex* getEndTrianglePoint3();
-	double getdistP2P();
-	double getangleProd();
-	bool getActive();
-	bool getEndTriangleActive();
-	bool getIsMaster();
-	int getTagMaster();
+  CorrespVerticesFixMesh();
+  ~CorrespVerticesFixMesh();
+  void setStartPoint(MVertex* v);
+  void setEndPoint(SPoint3 p);
+  void setStartNormal(SVector3 v);
+  void setEndNormal(SVector3 v);
+  //	void setEndTriangle(faceXtetFM f);
+  void setEndTrianglePoint1(MVertex* v);
+  void setEndTrianglePoint2(MVertex* v);
+  void setEndTrianglePoint3(MVertex* v);
+  void setdistP2P(double d);
+  void setangleProd(double a);
+  void setActive(bool b);
+  void setEndTriangleActive(bool b);
+  void setIsMaster(bool b);
+  void setTagMaster(int i);
+  MVertex* getStartPoint();
+  SPoint3 getEndPoint();
+  SVector3 getStartNormal();
+  SVector3 getEndNormal();
+  //	faceXtetFM getEndTriangle();
+  MVertex* getEndTrianglePoint1();
+  MVertex* getEndTrianglePoint2();
+  MVertex* getEndTrianglePoint3();
+  double getdistP2P();
+  double getangleProd();
+  bool getActive();
+  bool getEndTriangleActive();
+  bool getIsMaster();
+  int getTagMaster();
 };
 #endif
 
@@ -144,42 +143,38 @@ class GMSH_ThinLayerFixMeshPlugin : public GMSH_PostPlugin
 {
 private:
 public:
-	GMSH_ThinLayerFixMeshPlugin(){}
-	//~GMSH_ThinLayerFixMeshPlugin();
-	std::string getName() const { return "ThinLayerFixMesh"; }
-	std::string getShortHelp() const
-	{
-		return "Fix the mesh in thin parts";
-	}
-	std::string getHelp() const;
-	int getNbOptions() const;
-	StringXNumber* getOption(int iopt);
-	PView *execute(PView *);
+  GMSH_ThinLayerFixMeshPlugin(){}
+  //~GMSH_ThinLayerFixMeshPlugin();
+  std::string getName() const { return "ThinLayerFixMesh"; }
+  std::string getShortHelp() const
+  {
+    return "Fix the mesh in thin parts";
+  }
+  std::string getHelp() const;
+  int getNbOptions() const;
+  StringXNumber* getOption(int iopt);
+  PView *execute(PView *);
 #if defined(HAVE_MESH)
-	static void perform();
-	static void checkOppositeTriangles();
-	static void fillvecOfThinSheets();
-	static std::map<MVertex*,double> computeAllDistToOppSide();
-	static double computeDistToOppSide(MVertex* v);
-	static SVector3 computeInteriorNormal(MVertex* v);
-	static MTet4* getTetFromPoint(MVertex* v, SVector3 InteriorNormal);
-	static bool IsPositivOrientation(SVector3 a, SVector3 b, SVector3 c);
-	static void FindNewPoint(SPoint3* CurrentPoint, int* CurrentTri, MTet4** CurrentTet, SVector3 InteriorNormal);
-	static std::map<MVertex*,std::vector<MTetrahedron*> > VertexToTets;
-	static std::map<MTetrahedron*,MTet4*> TetToTet4;
-	static std::map<MVertex*,std::vector<CorrespVerticesFixMesh*> > VertexToCorresp;
-	static std::vector<std::vector<CorrespVerticesFixMesh*> > vecOfThinSheets;
-//	static const double epsilon = 0.00001;
-	static const double epsilon = 0.00000000001;
-	static const double angleMax = 0.9;
-//	static const double distP2PMax = 0.3;
-	static const double distP2PMax = 5.0;
-	static void fillVertexToTets();
-	static void fillTetToTet4();
+  static void perform();
+  static void checkOppositeTriangles();
+  static void fillvecOfThinSheets();
+  static std::map<MVertex*,double> computeAllDistToOppSide();
+  static double computeDistToOppSide(MVertex* v);
+  static SVector3 computeInteriorNormal(MVertex* v);
+  static MTet4* getTetFromPoint(MVertex* v, SVector3 InteriorNormal);
+  static bool IsPositivOrientation(SVector3 a, SVector3 b, SVector3 c);
+  static void FindNewPoint(SPoint3* CurrentPoint, int* CurrentTri,
+                           MTet4** CurrentTet, SVector3 InteriorNormal);
+  static std::map<MVertex*,std::vector<MTetrahedron*> > VertexToTets;
+  static std::map<MTetrahedron*,MTet4*> TetToTet4;
+  static std::map<MVertex*,std::vector<CorrespVerticesFixMesh*> > VertexToCorresp;
+  static std::vector<std::vector<CorrespVerticesFixMesh*> > vecOfThinSheets;
+  static const double epsilon;
+  static const double angleMax;
+  static const double distP2PMax;
+  static void fillVertexToTets();
+  static void fillTetToTet4();
 #endif
 };
 
-
-
-
-#endif /* THINLAYERFIXMESH_H_ */
+#endif