~ubuntu-branches/ubuntu/natty/dolfin/natty

« back to all changes in this revision

Viewing changes to dolfin/mesh/SubsetIterator.h

  • Committer: Bazaar Package Importer
  • Author(s): Johannes Ring
  • Date: 2011-02-24 10:34:44 UTC
  • mfrom: (1.1.7 upstream) (14.1.4 sid)
  • Revision ID: james.westby@ubuntu.com-20110224103444-n3fwnmh32lfoske0
Tags: 0.9.10-1
* New upstream release. This release fixes bug "FTBFS: error:
  'SCOTCH_Dgraph' was not declared in this scope" (closes: #612602).
* debian/control:
  - Add libslepc3.1-dev and libboost-thread-dev to Build-Depends and
    Depends field in binary package libdolfin0-dev.
  - Bump build dependency on python-ufc to >= 2.0.0.
  - Remove Build-Depends-Indep field as upstream no longer ships the
    user manual.
  - Remove old fields Conflicts, Provides, and Replaces from
    libdolfin0-dev, libdolfin0, libdolfin0-dbg, and python-dolfin.
* Remove all patches as they are now incorporated upstream.
* Add dolfin-plot and dolfin-version to debian/dolfin-bin.install.
* Remove .doc-base file since the user manual is removed by upstream.
* Remove targets clean and install/dolfin-doc from debian/rules since
  they are no longer needed.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
// Copyright (C) 2010 Anders Logg.
 
2
// Licensed under the GNU LGPL Version 2.1.
 
3
//
 
4
// First added:  2010-11-17
 
5
// Last changed: 2010-11-17
 
6
 
 
7
#ifndef __SUBSET_ITERATOR_H
 
8
#define __SUBSET_ITERATOR_H
 
9
 
 
10
#include <vector>
 
11
 
 
12
#include <dolfin/common/types.h>
 
13
#include <dolfin/log/log.h>
 
14
#include "MeshFunction.h"
 
15
#include "Mesh.h"
 
16
#include "MeshEntity.h"
 
17
 
 
18
namespace dolfin
 
19
{
 
20
 
 
21
  /// A _SubsetIterator_ is similar to a _MeshEntityIterator_ but
 
22
  /// iterates over a specified subset of the range of entities as
 
23
  /// specified by a _MeshFunction_ that labels the entites.
 
24
 
 
25
  class SubsetIterator
 
26
  {
 
27
  public:
 
28
 
 
29
    /// Create iterator for given mesh function. The iterator visits
 
30
    /// all entities that match the given label.
 
31
    SubsetIterator(const MeshFunction<uint>& labels, uint label)
 
32
      : entity(labels.mesh(), labels.dim(), 0)
 
33
    {
 
34
      // Extract subset
 
35
      subset.clear();
 
36
      for (MeshEntityIterator entity(labels.mesh(), labels.dim()); !entity.end(); ++entity)
 
37
      {
 
38
        if (labels[*entity] == label)
 
39
          subset.push_back(entity->index());
 
40
      }
 
41
      info("Iterating over subset, found %d entities out of %d.",
 
42
           subset.size(), labels.size());
 
43
 
 
44
      // Set iterator
 
45
      it = subset.begin();
 
46
    }
 
47
 
 
48
    /// Destructor
 
49
    virtual ~SubsetIterator() {}
 
50
 
 
51
    /// Step to next mesh entity (prefix increment)
 
52
    SubsetIterator& operator++()
 
53
    {
 
54
      ++it;
 
55
      return *this;
 
56
    }
 
57
 
 
58
    /// Dereference operator
 
59
    MeshEntity& operator*()
 
60
    { return *operator->(); }
 
61
 
 
62
    /// Member access operator
 
63
    MeshEntity* operator->()
 
64
    { entity._index = *it; return &entity; }
 
65
 
 
66
    /// Check if iterator has reached the end
 
67
    bool end() const
 
68
    { return it == subset.end(); }
 
69
 
 
70
  private:
 
71
 
 
72
    // Mesh entity
 
73
    MeshEntity entity;
 
74
 
 
75
    // Subset
 
76
    std::vector<uint> subset;
 
77
 
 
78
    // Iterator
 
79
    std::vector<uint>::iterator it;
 
80
 
 
81
  };
 
82
 
 
83
}
 
84
 
 
85
#endif