From 50cb43cc389d3cb7963a744d356387181f804912 Mon Sep 17 00:00:00 2001
From: Thomas Witkowski <thomas.witkowski@gmx.de>
Date: Thu, 10 Jul 2008 12:46:58 +0000
Subject: [PATCH] * Residual Estimator faster!!!

---
 AMDiS/src/BasisFunction.cc     |  6 +++--
 AMDiS/src/DOFAdmin.cc          | 10 -------
 AMDiS/src/DOFAdmin.h           |  8 ++++--
 AMDiS/src/ElInfo3d.cc          |  2 +-
 AMDiS/src/ResidualEstimator.cc | 49 ++++++++++++++++++----------------
 AMDiS/src/ResidualEstimator.h  |  8 ++++++
 6 files changed, 45 insertions(+), 38 deletions(-)

diff --git a/AMDiS/src/BasisFunction.cc b/AMDiS/src/BasisFunction.cc
index 878615f3..92b1dcc4 100644
--- a/AMDiS/src/BasisFunction.cc
+++ b/AMDiS/src/BasisFunction.cc
@@ -89,8 +89,10 @@ namespace AMDiS {
   {
     TEST_EXIT_DBG(val)("return value is NULL\n");
 
-    DimVec<double> *grdTmp1 = grdTmpVec1[omp_get_thread_num()];
-    DimVec<double> *grdTmp2 = grdTmpVec2[omp_get_thread_num()];
+    int myRank = omp_get_thread_num();
+
+    DimVec<double> *grdTmp1 = grdTmpVec1[myRank];
+    DimVec<double> *grdTmp2 = grdTmpVec2[myRank];
 
     for (int j = 0; j < dim + 1; j++)
       (*grdTmp2)[j] = 0.0;
diff --git a/AMDiS/src/DOFAdmin.cc b/AMDiS/src/DOFAdmin.cc
index 42e33204..e2f9a884 100755
--- a/AMDiS/src/DOFAdmin.cc
+++ b/AMDiS/src/DOFAdmin.cc
@@ -298,16 +298,6 @@ namespace AMDiS {
 
     return;
   }
-  
-  const int DOFAdmin::getNumberOfDOFs(int i) const { 
-    return nrDOF[i]; 
-  }
-
-  const int DOFAdmin::getNumberOfPreDOFs(int i) const { 
-    TEST_EXIT_DBG((0 <= i) && (4 > i))("");
-
-    return nr0DOF[i]; 
-  }
 
   void DOFAdmin::setNumberOfDOFs(int i,int v) { 
     TEST_EXIT_DBG((0 <= i) && (4 > i))("");
diff --git a/AMDiS/src/DOFAdmin.h b/AMDiS/src/DOFAdmin.h
index 92932bc7..a986c2dd 100644
--- a/AMDiS/src/DOFAdmin.h
+++ b/AMDiS/src/DOFAdmin.h
@@ -204,7 +204,9 @@ namespace AMDiS {
     /** \brief 
      * Returns \ref nrDOF[i]
      */
-    const int getNumberOfDOFs(int i) const;
+    inline const int getNumberOfDOFs(int i) const {
+      return nrDOF[i];
+    }
  
     /** \brief
      * Returns \ref nrDOF
@@ -216,7 +218,9 @@ namespace AMDiS {
     /** \brief
      * Returns \ref nr0DOF[i]
      */
-    const int getNumberOfPreDOFs(int i) const;
+    inline const int getNumberOfPreDOFs(int i) const {
+      return nr0DOF[i];
+    }
  
     /** \brief
      * Returns \ref nr0DOF
diff --git a/AMDiS/src/ElInfo3d.cc b/AMDiS/src/ElInfo3d.cc
index 88b49dd1..d92af234 100644
--- a/AMDiS/src/ElInfo3d.cc
+++ b/AMDiS/src/ElInfo3d.cc
@@ -380,7 +380,7 @@ namespace AMDiS {
 
     if (fillFlag__local.isAnySet()) {
       cvg = Tetrahedron::childVertex[el_type_local];
-      cv = const_cast<int*>( cvg[ichild]);
+      cv = const_cast<int*>(cvg[ichild]);
       ochild = 1 - ichild;
     }
 
diff --git a/AMDiS/src/ResidualEstimator.cc b/AMDiS/src/ResidualEstimator.cc
index a0bb11f2..62dde37a 100644
--- a/AMDiS/src/ResidualEstimator.cc
+++ b/AMDiS/src/ResidualEstimator.cc
@@ -118,6 +118,8 @@ namespace AMDiS {
       jump_.resize(nPointsSurface_);
       localJump_.resize(nPointsSurface_);
       neighbours_ = Global::getGeo(NEIGH, dim);
+      lambdaNeigh_ = NEW DimVec<WorldVector<double> >(dim, NO_INIT);
+      lambda_ = NEW DimVec<double>(dim, NO_INIT);
     }
   }
 
@@ -166,6 +168,11 @@ namespace AMDiS {
       FREE_MEMORY(D2uhqp, WorldMatrix<double>, numPoints);
     }
 
+    if (C1 && (dim > 1)) {
+      DELETE lambdaNeigh_;
+      DELETE lambda_;
+    }
+
     DELETE neighInfo;
   }
 
@@ -185,7 +192,7 @@ namespace AMDiS {
     el = elInfo->getElement();
 
     double det = elInfo->getDet();
-    const DimVec<WorldVector<double> > &Lambda = elInfo->getGrdLambda();
+    const DimVec<WorldVector<double> > &grdLambda = elInfo->getGrdLambda();
 
     est_el = el->getEstimation(row);
 
@@ -289,14 +296,10 @@ namespace AMDiS {
       for (int face = 0; face < neighbours_; face++) {  
 	neigh = const_cast<Element*>(elInfo->getNeighbour(face));
 	if (neigh && neigh->getMark()) {      
-	  WorldVector<int> faceIndEl, faceIndNeigh;
 	  int oppV = elInfo->getOppVertex(face);
-	  DimVec<WorldVector<double> > LambdaNeigh(dim, NO_INIT);
-	  double detNeigh;
-	  DimVec<double> lambda(dim, NO_INIT);
 	      
-	  el->sortFaceIndices(face, &faceIndEl);
-	  neigh->sortFaceIndices(oppV, &faceIndNeigh);
+	  el->sortFaceIndices(face, &faceIndEl_);
+	  neigh->sortFaceIndices(oppV, &faceIndNeigh_);
 	    
 	  neighInfo->setElement(const_cast<Element*>(neigh));
 	  neighInfo->setFillFlag(Mesh::FILL_COORDS);
@@ -313,14 +316,14 @@ namespace AMDiS {
 
 	  if (ldp) {
 	    ::std::list<LeafDataPeriodic::PeriodicInfo>::iterator it;
+	    ::std::list<LeafDataPeriodic::PeriodicInfo>& infoList = 
+		dynamic_cast<LeafDataPeriodic*>(ldp)->getInfoList();
 
-	    for (it = dynamic_cast<LeafDataPeriodic*>(ldp)->getInfoList().begin();
-		 it != dynamic_cast<LeafDataPeriodic*>(ldp)->getInfoList().end();
-		 ++it) {
+	    for (it = infoList.begin(); it != infoList.end(); ++it) {
 	      if (it->elementSide == face) {
 		for (int i = 0; i < dim; i++) {
-		  i1 = faceIndEl[i];
-		  i2 = faceIndNeigh[i];
+		  i1 = faceIndEl_[i];
+		  i2 = faceIndNeigh_[i];
 
 		  for (j = 0; j < dim; j++) {
 		    if (i1 == el->getVertexOfPosition(INDEX_OF_DIM(dim - 1, 
@@ -343,8 +346,8 @@ namespace AMDiS {
       
 	  if (!periodicCoords) {
 	    for (int i = 0; i < dim; i++) {
-	      i1 = faceIndEl[i];
-	      i2 = faceIndNeigh[i];
+	      i1 = faceIndEl_[i];
+	      i2 = faceIndNeigh_[i];
 	      for (j = 0; j < dow; j++)
 		neighInfo->getCoord(i2)[j] = elInfo->getCoord(i1)[j];
 	    }
@@ -355,7 +358,7 @@ namespace AMDiS {
 	    neighInfo = parametric->addParametricInfo(neighInfo);
 	  }
 	      
-	  detNeigh = abs(neighInfo->calcGrdLambda(LambdaNeigh));
+	  double detNeigh = abs(neighInfo->calcGrdLambda(*lambdaNeigh_));
 	      
 	  for (iq = 0; iq < nPointsSurface_; iq++) {
 	    jump_[iq].set(0.0);
@@ -370,23 +373,23 @@ namespace AMDiS {
 	    uh[system]->getLocalVector(neigh, uhNeigh[system]);
 			
 	    for (iq = 0; iq < nPointsSurface_; iq++) {
-	      lambda[face] = 0.0;
+	      (*lambda_)[face] = 0.0;
 	      for (int i = 0; i < dim; i++) {
-		lambda[faceIndEl[i]] = surfaceQuad_->getLambda(iq, i);
+		(*lambda_)[faceIndEl_[i]] = surfaceQuad_->getLambda(iq, i);
 	      }
 		  
-	      basFcts[system]->evalGrdUh(lambda, 
-					 Lambda, 
+	      basFcts[system]->evalGrdUh(*lambda_, 
+					 grdLambda, 
 					 uhEl[system], 
 					 &grdUhEl_[iq]);
 		  
-	      lambda[oppV] = 0.0;
+	      (*lambda_)[oppV] = 0.0;
 	      for (int i = 0; i < dim; i++) {
-		lambda[faceIndNeigh[i]] = surfaceQuad_->getLambda(iq, i);
+		(*lambda_)[faceIndNeigh_[i]] = surfaceQuad_->getLambda(iq, i);
 	      }
 		  
-	      basFcts[system]->evalGrdUh(lambda, 
-					 LambdaNeigh, 
+	      basFcts[system]->evalGrdUh(*lambda_, 
+					 *lambdaNeigh_, 
 					 uhNeigh[system], 
 					 &grdUhNeigh_[iq]);
 		  
diff --git a/AMDiS/src/ResidualEstimator.h b/AMDiS/src/ResidualEstimator.h
index b111703f..71b4b47d 100644
--- a/AMDiS/src/ResidualEstimator.h
+++ b/AMDiS/src/ResidualEstimator.h
@@ -169,6 +169,14 @@ namespace AMDiS {
 
     Vector<WorldVector<double> > localJump_;
 
+    WorldVector<int> faceIndEl_;
+    
+    WorldVector<int> faceIndNeigh_;
+
+    DimVec<WorldVector<double> > *lambdaNeigh_;
+
+    DimVec<double> *lambda_;
+
     int neighbours_;
   };
 }
-- 
GitLab