From a276473c27692849da5ed587d57350a218b3523e Mon Sep 17 00:00:00 2001
From: Thomas Witkowski <thomas.witkowski@gmx.de>
Date: Mon, 22 Oct 2012 09:00:31 +0000
Subject: [PATCH] And now really fixed, go ahead to write productive codes....

---
 AMDiS/src/parallel/MatrixNnzStructure.cc      |  2 +-
 AMDiS/src/parallel/MeshDistributor.h          |  4 ++-
 .../src/parallel/ParallelCoarseSpaceMatVec.cc |  2 +-
 AMDiS/src/parallel/ParallelDofMapping.cc      | 29 ++++---------------
 AMDiS/src/parallel/ParallelDofMapping.h       |  9 ++----
 AMDiS/src/parallel/PetscSolverFeti.cc         |  2 +-
 AMDiS/src/parallel/PetscSolverGlobalMatrix.cc | 22 +++++++-------
 7 files changed, 25 insertions(+), 45 deletions(-)

diff --git a/AMDiS/src/parallel/MatrixNnzStructure.cc b/AMDiS/src/parallel/MatrixNnzStructure.cc
index ba8d9cdd..094f2002 100644
--- a/AMDiS/src/parallel/MatrixNnzStructure.cc
+++ b/AMDiS/src/parallel/MatrixNnzStructure.cc
@@ -138,7 +138,7 @@ namespace AMDiS {
 	// === Iterate on all DOFs of the row mapping. ===
 
 	DofMap::iterator rowIt = rowDofMap[rowComp].begin();
-	DofMap::iterator rowEndIt = rowDofMap[colComp].end();
+	DofMap::iterator rowEndIt = rowDofMap[rowComp].end();
 	for (; rowIt != rowEndIt; ++rowIt) {
 
 	  // Go to the corresponding matrix row (note, both the mapping and the
diff --git a/AMDiS/src/parallel/MeshDistributor.h b/AMDiS/src/parallel/MeshDistributor.h
index 14c1ab5b..f82a7371 100644
--- a/AMDiS/src/parallel/MeshDistributor.h
+++ b/AMDiS/src/parallel/MeshDistributor.h
@@ -137,7 +137,9 @@ namespace AMDiS {
     {
       FUNCNAME("MeshDistributor::getFeSpace()");
 
-      TEST_EXIT_DBG(i < uniqueFeSpaces.size())("Should not happen!\n");
+      TEST_EXIT_DBG(i < uniqueFeSpaces.size())
+	("Try to access FE space %d, but have only %d FE spaces!\n", 
+	 i, uniqueFeSpaces.size());
 
       return uniqueFeSpaces[i];
     }
diff --git a/AMDiS/src/parallel/ParallelCoarseSpaceMatVec.cc b/AMDiS/src/parallel/ParallelCoarseSpaceMatVec.cc
index cc12d3d2..0ea17aa5 100644
--- a/AMDiS/src/parallel/ParallelCoarseSpaceMatVec.cc
+++ b/AMDiS/src/parallel/ParallelCoarseSpaceMatVec.cc
@@ -117,7 +117,7 @@ namespace AMDiS {
       // Mesh has been changed, recompute interior DOF mapping.
       vector<const FiniteElemSpace*> feSpaces = getComponentFeSpaces(seqMat);     
       interiorMap->setComputeMatIndex(!localMatrix);
-      interiorMap->update(feSpaces);
+      interiorMap->update();
 
       int nMat = uniqueCoarseMap.size() + 1;
       nnz.resize(nMat);
diff --git a/AMDiS/src/parallel/ParallelDofMapping.cc b/AMDiS/src/parallel/ParallelDofMapping.cc
index fae07266..b567fa79 100644
--- a/AMDiS/src/parallel/ParallelDofMapping.cc
+++ b/AMDiS/src/parallel/ParallelDofMapping.cc
@@ -175,8 +175,8 @@ namespace AMDiS {
 				    bool isNonLocal,
 				    MeshLevelData &levelData)
   {
-    feSpaces = f1;
-    feSpacesUnique = f0;
+    feSpaces = f0;
+    feSpacesUnique = f1;
     for (vector<const FiniteElemSpace*>::iterator it = feSpacesUnique.begin();
      	 it != feSpacesUnique.end(); ++it) {
       addFeSpace(*it, levelData);
@@ -203,8 +203,8 @@ namespace AMDiS {
 				      bool isNonLocal,
 				      MeshLevelData &levelData)
   {
-    feSpaces = f1;
-    feSpacesUnique = f0;
+    feSpaces = f0;
+    feSpacesUnique = f1;
 
     for (unsigned int component = 0; component < feSpaces.size(); component++) {
       addComponent(component, feSpaces[component], levelData);
@@ -367,31 +367,12 @@ namespace AMDiS {
     nLocalDofs = computeLocalDofs();
     nOverallDofs = computeOverallDofs();
     rStartDofs = computeStartDofs();
-    
+
     // And finally, compute the matrix indices.
     computeMatIndex(needMatIndexFromGlobal);
   }
   
 
-  void ParallelDofMapping::update(vector<const FiniteElemSpace*>& fe)
-  {
-    FUNCNAME("ParallelDofMapping::update()");
-
-    ERROR_EXIT("DAS MUSS ICH MIR MAL UEBERLEGEN!\n");
-
-    // for (vector<const FiniteElemSpace*>::iterator it = fe.begin();
-    // 	 it != fe.end(); ++it)
-    //   if (find(feSpacesUnique.begin(), feSpacesUnique.end(), *it) == 
-    // 	  feSpacesUnique.end())
-    // 	ERROR_EXIT("Wrong FE space!\n");
-
-    // feSpaces = fe;
-
-
-    update();
-  }
-
-  
   void ParallelDofMapping::computeMatIndex(bool globalIndex)
   {
     FUNCNAME("ParallelDofMapping::computeMatIndex()");
diff --git a/AMDiS/src/parallel/ParallelDofMapping.h b/AMDiS/src/parallel/ParallelDofMapping.h
index 189d8c19..bad2f737 100644
--- a/AMDiS/src/parallel/ParallelDofMapping.h
+++ b/AMDiS/src/parallel/ParallelDofMapping.h
@@ -404,7 +404,7 @@ namespace AMDiS {
 
       bool end()
       {
-	return (it != data->feSpacesUnique.end());
+	return (it == data->feSpacesUnique.end());
       }
 
       void next()
@@ -441,7 +441,7 @@ namespace AMDiS {
 
       bool end()
       {
-	return (it != data->feSpaces.end());
+	return (it == data->feSpaces.end());
       }
 
       void next()
@@ -539,7 +539,7 @@ namespace AMDiS {
 
       bool end()
       {
-	return (it != data->feSpaces.end());
+	return (it == data->feSpaces.end());
       }
 
       void next()
@@ -706,9 +706,6 @@ namespace AMDiS {
     /// Update the mapping.
     void update();
 
-    /// Update the mapping.
-    void update(vector<const FiniteElemSpace*>& feSpaces);
-
     /// Returns the global matrix index of a given DOF for a given 
     /// component number.
     inline int getMatIndex(int ithComponent, DegreeOfFreedom d)
diff --git a/AMDiS/src/parallel/PetscSolverFeti.cc b/AMDiS/src/parallel/PetscSolverFeti.cc
index 6c4d4927..d3ede6ba 100644
--- a/AMDiS/src/parallel/PetscSolverFeti.cc
+++ b/AMDiS/src/parallel/PetscSolverFeti.cc
@@ -260,7 +260,7 @@ namespace AMDiS {
 
     MSG("FETI-DP data created on mesh level %d\n", meshLevel);
     for (unsigned int i = 0; i < meshDistributor->getComponentFeSpaces().size(); i++) {
-      const FiniteElemSpace *feSpace = meshDistributor->getFeSpace(i);
+      const FiniteElemSpace *feSpace = meshDistributor->getComponentFeSpace(i);
 
       MSG("FETI-DP data for %d-ith component (FE space %p):\n", i, feSpace);
 
diff --git a/AMDiS/src/parallel/PetscSolverGlobalMatrix.cc b/AMDiS/src/parallel/PetscSolverGlobalMatrix.cc
index d1ed8b8b..47fece85 100644
--- a/AMDiS/src/parallel/PetscSolverGlobalMatrix.cc
+++ b/AMDiS/src/parallel/PetscSolverGlobalMatrix.cc
@@ -164,7 +164,7 @@ namespace AMDiS {
 	    bool isColCoarse = isCoarseSpace(colComponent, col(*icursor));
 
 	    if (isColCoarse == false)
-	      if ((*interiorMap)[dofMat->getColFeSpace()].isSet(col(*icursor)) == false)
+	      if ((*interiorMap)[colComponent].isSet(col(*icursor)) == false)
 		continue;
 
 	    if (isColCoarse == isRowCoarse) {
@@ -199,7 +199,7 @@ namespace AMDiS {
  			   &(colsOther[0]), &(valuesOther[0]), ADD_VALUES);
 	    }
 	  } else {
-	    if ((*interiorMap)[dofMat->getRowFeSpace()].isSet(*cursor) == false)
+	    if ((*interiorMap)[rowComponent].isSet(*cursor) == false)
 	      continue;
 
 	    int localRowIndex = 
@@ -384,10 +384,10 @@ namespace AMDiS {
     VecGetArray(getVecSolInterior(), &vecPointer);    
 
     int c = 0;
-    for (int i = 0; i < nComponents; i++) {
-      DOFVector<double> &dv = *(vec.getDOFVector(i));
+    for (int component = 0; component < nComponents; component++) {
+      DOFVector<double> &dv = *(vec.getDOFVector(component));
 
-      DofMap& d = (*interiorMap)[dv.getFeSpace()].getMap();
+      DofMap& d = (*interiorMap)[component].getMap();
       for (DofMap::iterator it = d.begin(); it != d.end(); ++it)
 	if (it->second.local != -1)
 	  dv[it->first] = vecPointer[c++];
@@ -627,7 +627,7 @@ namespace AMDiS {
 	   cend = end<row>(seqMat->getBaseMatrix()); cursor != cend; ++cursor) {
       // Global index of the current row DOF.
       MultiIndex rowMultiIndex;
-      if ((*interiorMap)[rowFe].find(*cursor, rowMultiIndex) == false)
+      if ((*interiorMap)[nRowMat].find(*cursor, rowMultiIndex) == false)
 	continue;
 
       int globalRowDof = rowMultiIndex.global;
@@ -649,7 +649,7 @@ namespace AMDiS {
 
 	  // Global index of the current column index.
 	  MultiIndex colMultiIndex;
-	  if ((*interiorMap)[colFe].find(col(*icursor), colMultiIndex) == false)
+	  if ((*interiorMap)[nColMat].find(col(*icursor), colMultiIndex) == false)
 	    continue;
 
 	  int globalColDof = colMultiIndex.global;
@@ -707,7 +707,7 @@ namespace AMDiS {
 	for (icursor_type icursor = begin<nz>(cursor), icend = end<nz>(cursor); 
 	     icursor != icend; ++icursor) {
 	  // Global index of the current column index.
-	  int globalColDof = (*interiorMap)[colFe][col(*icursor)].global;
+	  int globalColDof = (*interiorMap)[nColMat][col(*icursor)].global;
 
 	  // Ignore all zero entries, expect it is a diagonal entry.
  	  if (value(*icursor) == 0.0 && globalRowDof != globalColDof)
@@ -781,7 +781,7 @@ namespace AMDiS {
     DOFVector<double>::Iterator dofIt(vec, USED_DOFS);
     for (dofIt.reset(); !dofIt.end(); ++dofIt) {
 
-      if (rankOnly && !(*interiorMap)[feSpace].isRankDof(dofIt.getDOFIndex()))
+      if (rankOnly && !(*interiorMap)[nRowVec].isRankDof(dofIt.getDOFIndex()))
 	continue;
 
       if (isCoarseSpace(nRowVec, dofIt.getDOFIndex())) {
@@ -790,12 +790,12 @@ namespace AMDiS {
 	int index = rowCoarseSpace->getMatIndex(nRowVec, dofIt.getDOFIndex());
 	VecSetValue(vecCoarse, index, *dofIt, ADD_VALUES);
       } else {
-	if ((*interiorMap)[feSpace].isSet(dofIt.getDOFIndex()) == false)
+	if ((*interiorMap)[nRowVec].isSet(dofIt.getDOFIndex()) == false)
 	  continue;
 
 	// Calculate global row index of the DOF.
 	DegreeOfFreedom globalRowDof = 
-	  (*interiorMap)[feSpace][dofIt.getDOFIndex()].global;
+	  (*interiorMap)[nRowVec][dofIt.getDOFIndex()].global;
 	
 	// Get PETSc's mat index of the row DOF.
 	int index = 0;
-- 
GitLab