~ubuntu-branches/ubuntu/utopic/dune-grid/utopic

« back to all changes in this revision

Viewing changes to dune/grid/uggrid/uggridleveliterator.hh

  • Committer: Package Import Robot
  • Author(s): Ansgar Burchardt
  • Date: 2014-02-14 10:49:16 UTC
  • mfrom: (1.3.1) (5.1.4 experimental)
  • Revision ID: package-import@ubuntu.com-20140214104916-2clchnny3eu7ks4w
Tags: 2.3.0-2
InstallĀ /usr/share/dune-grid.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
// -*- tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*-
 
2
// vi: set et ts=4 sw=2 sts=2:
1
3
#ifndef DUNE_UGGRIDLEVELITERATOR_HH
2
4
#define DUNE_UGGRIDLEVELITERATOR_HH
3
5
 
9
11
 
10
12
namespace Dune {
11
13
 
12
 
//**********************************************************************
13
 
//
14
 
// --UGGridLevelIterator
15
 
// --LevelIterator
 
14
  //**********************************************************************
 
15
  //
 
16
  // --UGGridLevelIterator
 
17
  // --LevelIterator
16
18
  /** \brief Iterator over all entities of a given codimension and level of a grid.
17
19
   * \ingroup UGGrid
18
20
   */
19
 
    template<int codim, PartitionIteratorType pitype, class GridImp>
20
 
class UGGridLevelIterator : 
21
 
        public Dune::UGGridEntityPointer <codim,GridImp>
22
 
{
 
21
  template<int codim, PartitionIteratorType pitype, class GridImp>
 
22
  class UGGridLevelIterator :
 
23
    public Dune::UGGridEntityPointer <codim,GridImp>
 
24
  {
23
25
    enum {dim = GridImp::dimension};
24
26
 
25
27
    friend class UGGridEntity<codim,GridImp::dimension,GridImp>;
28
30
    // The type of the UG entity we're pointing to
29
31
    typedef typename UG_NS<dim>::template Entity<codim>::T UGEntity;
30
32
 
31
 
public:
 
33
  public:
32
34
 
33
35
    typedef typename GridImp::template Codim<codim>::Entity Entity;
34
36
 
35
 
  //! Constructor
 
37
    //! Constructor
36
38
    explicit UGGridLevelIterator()
37
39
    {
38
 
        this->virtualEntity_.setToTarget(nullptr,nullptr);
 
40
      this->virtualEntity_.setToTarget(nullptr,nullptr);
39
41
    }
40
42
 
41
 
  //! Constructor
 
43
    //! Constructor
42
44
    explicit UGGridLevelIterator(const GridImp& gridImp, int level) : gridImp_(&gridImp)
43
45
    {
44
 
        typename UG_NS<dim>::Grid *theGrid = const_cast<typename UG_NS<dim>::Grid* >(gridImp_->multigrid_->grids[level]);
45
 
        assert(theGrid);
46
 
        if (codim==dim) {
47
 
            if (pitype==All_Partition || pitype==Ghost_Partition)
48
 
                this->virtualEntity_.setToTarget((UGEntity*)UG_NS<dim>::PFirstNode(theGrid),gridImp_);
49
 
            else if (pitype == Dune::Interior_Partition || pitype == Dune::InteriorBorder_Partition)
50
 
                this->virtualEntity_.setToTarget((UGEntity*)UG_NS<dim>::FirstNode(theGrid),gridImp_);
51
 
            else // overlap and overlap-front
52
 
                this->virtualEntity_.setToTarget(0,nullptr);
53
 
 
54
 
        }
55
 
        else if (codim==0) {
56
 
            if (pitype==All_Partition || pitype==Ghost_Partition)
57
 
                this->virtualEntity_.setToTarget((UGEntity*)UG_NS<dim>::PFirstElement(theGrid),gridImp_);
58
 
            else if (pitype == Dune::Interior_Partition || pitype == Dune::InteriorBorder_Partition)
59
 
                this->virtualEntity_.setToTarget((UGEntity*)UG_NS<dim>::FirstElement(theGrid),gridImp_);
60
 
            else // overlap and overlap-front
61
 
                this->virtualEntity_.setToTarget(0,nullptr);
62
 
        }
63
 
        else
64
 
            DUNE_THROW(NotImplemented, "UGGrid level iterators for codimension " << codim);
65
 
    
66
 
        if (this->virtualEntity_.getTarget() && !entityOK_())
67
 
            increment();
 
46
      typename UG_NS<dim>::Grid *theGrid = const_cast<typename UG_NS<dim>::Grid* >(gridImp_->multigrid_->grids[level]);
 
47
      assert(theGrid);
 
48
      if (codim==dim) {
 
49
        if (pitype==All_Partition || pitype==Ghost_Partition)
 
50
          this->virtualEntity_.setToTarget((UGEntity*)UG_NS<dim>::PFirstNode(theGrid),gridImp_);
 
51
        else if (pitype == Dune::Interior_Partition || pitype == Dune::InteriorBorder_Partition)
 
52
          this->virtualEntity_.setToTarget((UGEntity*)UG_NS<dim>::FirstNode(theGrid),gridImp_);
 
53
        else     // overlap and overlap-front
 
54
          this->virtualEntity_.setToTarget(0,nullptr);
 
55
 
 
56
      }
 
57
      else if (codim==0) {
 
58
        if (pitype==All_Partition || pitype==Ghost_Partition)
 
59
          this->virtualEntity_.setToTarget((UGEntity*)UG_NS<dim>::PFirstElement(theGrid),gridImp_);
 
60
        else if (pitype == Dune::Interior_Partition || pitype == Dune::InteriorBorder_Partition)
 
61
          this->virtualEntity_.setToTarget((UGEntity*)UG_NS<dim>::FirstElement(theGrid),gridImp_);
 
62
        else     // overlap and overlap-front
 
63
          this->virtualEntity_.setToTarget(0,nullptr);
 
64
      }
 
65
      else
 
66
        DUNE_THROW(NotImplemented, "UGGrid level iterators for codimension " << codim);
 
67
 
 
68
      if (this->virtualEntity_.getTarget() && !entityOK_())
 
69
        increment();
68
70
    }
69
71
 
70
72
    //! prefix increment
71
73
    void increment()
72
74
    {
73
 
        assert(this->level() == UG_NS<dim>::myLevel(this->virtualEntity_.getTarget()));
74
 
        // Increment
75
 
        do {
76
 
            this->virtualEntity_.setToTarget(UG_NS<dim>::succ(this->virtualEntity_.getTarget()),gridImp_);
77
 
        } 
78
 
        while (this->virtualEntity_.getTarget() && !entityOK_());
 
75
      assert(this->level() == UG_NS<dim>::myLevel(this->virtualEntity_.getTarget()));
 
76
      // Increment
 
77
      do {
 
78
        this->virtualEntity_.setToTarget(UG_NS<dim>::succ(this->virtualEntity_.getTarget()),gridImp_);
 
79
      }
 
80
      while (this->virtualEntity_.getTarget() && !entityOK_());
79
81
    }
80
82
 
81
 
private:
 
83
  private:
82
84
    /**
83
85
     * \brief Return true iff the current entity is within the right
84
86
     *        partition.
85
87
     */
86
88
    bool entityOK_()
87
 
    { 
88
 
        if (pitype == All_Partition)
89
 
            return true;
 
89
    {
 
90
      if (pitype == All_Partition)
 
91
        return true;
90
92
 
91
 
        Dune::PartitionType entityPIType = this->virtualEntity_.partitionType();
92
 
        if (pitype == Ghost_Partition && entityPIType == GhostEntity)
93
 
            return true;
94
 
        else if (pitype == Interior_Partition && entityPIType == InteriorEntity)
95
 
            return true;
96
 
        else if (pitype == InteriorBorder_Partition && 
97
 
                 (entityPIType == BorderEntity ||
98
 
                  entityPIType == InteriorEntity))
99
 
            return true;
100
 
        return false;
 
93
      Dune::PartitionType entityPIType = this->virtualEntity_.partitionType();
 
94
      if (pitype == Ghost_Partition && entityPIType == GhostEntity)
 
95
        return true;
 
96
      else if (pitype == Interior_Partition && entityPIType == InteriorEntity)
 
97
        return true;
 
98
      else if (pitype == InteriorBorder_Partition &&
 
99
               (entityPIType == BorderEntity ||
 
100
                entityPIType == InteriorEntity))
 
101
        return true;
 
102
      return false;
101
103
    }
102
104
 
103
105
    // /////////////////////////////////////
105
107
    // /////////////////////////////////////
106
108
    const GridImp* gridImp_;
107
109
 
108
 
};
 
110
  };
109
111
 
110
112
}  // namespace Dune
111
 
  
 
113
 
112
114
#endif