DOLFIN
DOLFIN C++ interface
MeshHierarchy.h
1 // Copyright (C) 2015 Chris Richardson
2 //
3 // This file is part of DOLFIN.
4 //
5 // DOLFIN is free software: you can redistribute it and/or modify
6 // it under the terms of the GNU Lesser General Public License as published by
7 // the Free Software Foundation, either version 3 of the License, or
8 // (at your option) any later version.
9 //
10 // DOLFIN is distributed in the hope that it will be useful,
11 // but WITHOUT ANY WARRANTY; without even the implied warranty of
12 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 // GNU Lesser General Public License for more details.
14 //
15 // You should have received a copy of the GNU Lesser General Public License
16 // along with DOLFIN. If not, see <http://www.gnu.org/licenses/>.
17 //
18 
19 #ifndef __MESH_HIERARCHY_H
20 #define __MESH_HIERARCHY_H
21 
22 #include<vector>
23 #include<memory>
24 #include<dolfin/log/log.h>
25 
26 namespace dolfin
27 {
28  class Mesh;
29  class MeshRelation;
30  template <typename T> class MeshFunction;
31 
33 
35  {
36  public:
39  {}
40 
42  explicit MeshHierarchy(std::shared_ptr<const Mesh> mesh)
43  : _meshes(1, mesh), _parent(NULL), _relation(NULL)
44  {}
45 
48  {}
49 
51  unsigned int size() const
52  { return _meshes.size(); }
53 
55  std::shared_ptr<const Mesh> operator[](int i) const
56  {
57  if (i < 0)
58  i += _meshes.size();
59  dolfin_assert(i < (int)_meshes.size());
60  return _meshes[i];
61  }
62 
64  std::shared_ptr<const Mesh> finest() const
65  { return _meshes.back(); }
66 
68  std::shared_ptr<const Mesh> coarsest() const
69  { return _meshes.front(); }
70 
73  std::shared_ptr<const MeshHierarchy> refine
74  (const MeshFunction<bool>& markers) const;
75 
79  std::shared_ptr<const MeshHierarchy> unrefine() const
80  { return _parent; }
81 
83  std::shared_ptr<const MeshHierarchy> coarsen
84  (const MeshFunction<bool>& markers) const;
85 
89  std::vector<std::size_t> weight() const;
90 
92  std::shared_ptr<Mesh> rebalance() const;
93 
94  private:
95 
96  // Basic store of mesh pointers for easy access
97  std::vector<std::shared_ptr<const Mesh> > _meshes;
98 
99  // Parent MeshHierarchy
100  std::shared_ptr<const MeshHierarchy> _parent;
101 
102  // Intermesh relationship data, i.e. parent cell, facet, vertex mappings
103  // instead of using MeshData
104  std::shared_ptr<const MeshRelation> _relation;
105 
106  };
107 }
108 
109 #endif
Definition: adapt.h:41
MeshHierarchy()
Constructor.
Definition: MeshHierarchy.h:38
std::shared_ptr< const Mesh > finest() const
Get the finest mesh of the MeshHierarchy.
Definition: MeshHierarchy.h:64
unsigned int size() const
Number of meshes.
Definition: MeshHierarchy.h:51
Definition: adapt.h:29
std::shared_ptr< Mesh > rebalance() const
Rebalance across processes.
Definition: MeshHierarchy.cpp:164
MeshHierarchy(std::shared_ptr< const Mesh > mesh)
Constructor with initial mesh.
Definition: MeshHierarchy.h:42
std::shared_ptr< const MeshHierarchy > unrefine() const
Definition: MeshHierarchy.h:79
std::shared_ptr< const Mesh > coarsest() const
Get the coarsest mesh of the MeshHierarchy.
Definition: MeshHierarchy.h:68
~MeshHierarchy()
Destructor.
Definition: MeshHierarchy.h:47
std::shared_ptr< const MeshHierarchy > refine(const MeshFunction< bool > &markers) const
Definition: MeshHierarchy.cpp:39
std::vector< std::size_t > weight() const
Definition: MeshHierarchy.cpp:141
Experimental implementation of a list of Meshes as a hierarchy.
Definition: MeshHierarchy.h:34
std::shared_ptr< const MeshHierarchy > coarsen(const MeshFunction< bool > &markers) const
Coarsen finest mesh by one level, based on markers (level n->n)
Definition: MeshHierarchy.cpp:64
std::shared_ptr< const Mesh > operator[](int i) const
Get Mesh i, in range [0:size()] where 0 is the coarsest Mesh.
Definition: MeshHierarchy.h:55