From ded27d03042a11802110bcc1c8e49f158c68aa4e Mon Sep 17 00:00:00 2001
From: Simon Praetorius <simon.praetorius@tu-dresden.de>
Date: Thu, 26 Jul 2012 09:23:26 +0000
Subject: [PATCH] DOFConstIterator

---
 AMDiS/src/DOFIndexed.h       | 15 ++++++++++++---
 AMDiS/src/DOFMatrix.h        | 13 +++++++++++++
 AMDiS/src/DOFVector.h        | 14 +++++++++++++-
 AMDiS/src/SecondOrderTerm.cc | 22 +++++++++++++++++-----
 4 files changed, 55 insertions(+), 9 deletions(-)

diff --git a/AMDiS/src/DOFIndexed.h b/AMDiS/src/DOFIndexed.h
index 46238a1c..494cc41f 100644
--- a/AMDiS/src/DOFIndexed.h
+++ b/AMDiS/src/DOFIndexed.h
@@ -92,21 +92,30 @@ namespace AMDiS {
   template<typename T>
   class DOFIndexed : public DOFIndexedBase
   {
-  public:
+  public: // typedefs
     typedef T 			value_type;
     typedef DegreeOfFreedom	size_type;
     typedef value_type&		reference;
     typedef value_type const&	const_reference;
+
+    typedef typename std::vector<value_type>::iterator		iterator;
+    typedef typename std::vector<value_type>::const_iterator	const_iterator;
     
   public:
     virtual ~DOFIndexed() {}
 
     /// Returns iterator to the begin of container
-    virtual typename std::vector<value_type>::iterator begin() = 0;
+    virtual iterator begin() = 0;
 
     /// Returns iterator to the end of container
-    virtual typename std::vector<value_type>::iterator end() = 0;
+    virtual iterator end() = 0;
+
+    /// Returns iterator to the begin of container
+    virtual const_iterator begin() const = 0;
 
+    /// Returns iterator to the end of container
+    virtual const_iterator end() const = 0;
+    
     /// Returns container element at index i
     virtual reference operator[](size_type i) = 0;
 
diff --git a/AMDiS/src/DOFMatrix.h b/AMDiS/src/DOFMatrix.h
index cb07a5a3..7a687267 100644
--- a/AMDiS/src/DOFMatrix.h
+++ b/AMDiS/src/DOFMatrix.h
@@ -114,6 +114,19 @@ namespace AMDiS {
       ERROR_EXIT("Shouldn't be used, only fake."); vector<bool> v; 
       return v.end();
     }
+
+    // Only to get rid of the abstract functions, I hope they are not used
+    vector<bool>::const_iterator begin() const
+    {
+      ERROR_EXIT("Shouldn't be used, only fake."); vector<bool> v;
+      return v.begin();
+    }
+
+    vector<bool>::const_iterator end() const
+    {
+      ERROR_EXIT("Shouldn't be used, only fake."); vector<bool> v;
+      return v.end();
+    }
     
     bool dummy; // Must be deleted later
     bool& operator[](int i) 
diff --git a/AMDiS/src/DOFVector.h b/AMDiS/src/DOFVector.h
index 993f92b6..031835ef 100644
--- a/AMDiS/src/DOFVector.h
+++ b/AMDiS/src/DOFVector.h
@@ -392,7 +392,19 @@ namespace AMDiS {
     { 
       return vec.end(); 
     }
-  
+
+    /// Returns const_iterator to the begin of \ref vec
+    typename vector<T>::const_iterator begin() const
+    {
+      return vec.begin();
+    }
+
+    /// Returns const_iterator to the end of \ref vec
+    typename vector<T>::const_iterator end() const
+    {
+      return vec.end();
+    }
+    
     /// Used by DOFAdmin to compress this DOFVector. Implementation of
     /// \ref DOFIndexedBase::compress()
     virtual void compressDOFIndexed(int first, int last,
diff --git a/AMDiS/src/SecondOrderTerm.cc b/AMDiS/src/SecondOrderTerm.cc
index 80edf261..2c3bd0c4 100644
--- a/AMDiS/src/SecondOrderTerm.cc
+++ b/AMDiS/src/SecondOrderTerm.cc
@@ -268,7 +268,7 @@ namespace AMDiS {
 
   Vec2AtQP_SOT::Vec2AtQP_SOT(DOFVectorBase<double> *dv1, DOFVectorBase<double> *dv2, 
 			     BinaryAbstractFunction<double, double, double> *af)
-    : SecondOrderTerm(af->getDegree()), vec1(dv1), vec2(dv2), f(af)
+    : SecondOrderTerm(af ? af->getDegree() : 2*dv1->getFeSpace()->getBasisFcts()->getDegree()), vec1(dv1), vec2(dv2), f(af)
   {
     setSymmetric(true);
 
@@ -293,8 +293,12 @@ namespace AMDiS {
     const DimVec<WorldVector<double> > &grdLambda = elInfo->getGrdLambda();
     const int nPoints = static_cast<int>(LALt.size());
 
-    for (int iq = 0; iq < nPoints; iq++)
-      l1lt(grdLambda, LALt[iq], (*f)(vecAtQPs1[iq], vecAtQPs2[iq]));
+    for (int iq = 0; iq < nPoints; iq++) {
+      if (f)
+	l1lt(grdLambda, LALt[iq], (*f)(vecAtQPs1[iq], vecAtQPs2[iq]));
+      else
+	l1lt(grdLambda, LALt[iq], vecAtQPs1[iq] * vecAtQPs2[iq]);
+    }
   }
 
   void Vec2AtQP_SOT::eval(int nPoints,
@@ -308,7 +312,11 @@ namespace AMDiS {
     
     if (num_rows(D2UhAtQP) > 0) {
       for (int iq = 0; iq < nPoints; iq++) {
-	double factor = (*f)(vecAtQPs1[iq], vecAtQPs2[iq]);
+	double factor = 1.0;
+	if (f)
+	  factor = (*f)(vecAtQPs1[iq], vecAtQPs2[iq]);
+	else
+	  factor = vecAtQPs1[iq] * vecAtQPs2[iq];
 	double resultQP = 0.0;
 	for (int i = 0; i < dow; i++)
 	  resultQP += D2UhAtQP[iq][i][i];	
@@ -322,7 +330,11 @@ namespace AMDiS {
   {
     int nPoints = grdUhAtQP.size();
     for (int iq = 0; iq < nPoints; iq++) {
-      double factor = (*f)(vecAtQPs1[iq], vecAtQPs2[iq]);  
+      double factor = 1.0;
+      if (f)
+	factor = (*f)(vecAtQPs1[iq], vecAtQPs2[iq]);
+      else
+	factor = vecAtQPs1[iq] * vecAtQPs2[iq];
       axpy(factor, grdUhAtQP[iq], result[iq]);      
     }
   }
-- 
GitLab