ug4
grid_level.h
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2012-2015: G-CSC, Goethe University Frankfurt
3  * Author: Andreas Vogel
4  *
5  * This file is part of UG4.
6  *
7  * UG4 is free software: you can redistribute it and/or modify it under the
8  * terms of the GNU Lesser General Public License version 3 (as published by the
9  * Free Software Foundation) with the following additional attribution
10  * requirements (according to LGPL/GPL v3 §7):
11  *
12  * (1) The following notice must be displayed in the Appropriate Legal Notices
13  * of covered and combined works: "Based on UG4 (www.ug4.org/license)".
14  *
15  * (2) The following notice must be displayed at a prominent place in the
16  * terminal output of covered works: "Based on UG4 (www.ug4.org/license)".
17  *
18  * (3) The following bibliography is recommended for citation and must be
19  * preserved in all covered files:
20  * "Reiter, S., Vogel, A., Heppner, I., Rupp, M., and Wittum, G. A massively
21  * parallel geometric multigrid solver on hierarchically distributed grids.
22  * Computing and visualization in science 16, 4 (2013), 151-164"
23  * "Vogel, A., Reiter, S., Rupp, M., Nägel, A., and Wittum, G. UG4 -- a novel
24  * flexible software system for simulating pde based models on high performance
25  * computers. Computing and visualization in science 16, 4 (2013), 165-179"
26  *
27  * This program is distributed in the hope that it will be useful,
28  * but WITHOUT ANY WARRANTY; without even the implied warranty of
29  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
30  * GNU Lesser General Public License for more details.
31  */
32 
33 #ifndef __H__UG__LIB_GRID__TOOLS__GRID_LEVEL__
34 #define __H__UG__LIB_GRID__TOOLS__GRID_LEVEL__
35 
36 #include <string>
37 #include <iostream>
38 
39 namespace ug{
40 
41 class GridLevel
42 {
43  public:
45  enum{TOP = -1};
46 
48  enum ViewType{LEVEL = 0, SURFACE = 1};
49 
50  public:
53 
55  GridLevel(int level, ViewType type, bool bWithGhosts = false)
56  : m_level(level), m_type(type), m_bWithGhosts(bWithGhosts)
57  {}
58 
62  {}
63 
65  GridLevel(int level, const std::string& type)
66  : m_level(level), m_bWithGhosts(false)
67  {
68  if(type == "top") {m_type = LEVEL;}
69  else if(type == "surf") {m_type = SURFACE;}
70  else UG_THROW("Grid Level Type not in ['top' | 'surf'].");
71  }
72 
74  int level() const {return m_level;}
75 
77  ViewType type() const {return m_type;}
78 
80  bool ghosts() const {return m_bWithGhosts;}
81 
83  bool top() const {return level() == TOP;}
84 
86  bool is_level() const {return type() == LEVEL;}
87 
89  bool is_surface() const {return type() == SURFACE;}
90 
92  bool operator==(const GridLevel& rhs) const {
93  return (this->level() == rhs.level() && this->type() == rhs.type()
94  && this->ghosts() == rhs.ghosts());
95  }
96 
98  bool operator!=(const GridLevel& rhs) const {
99  return !(this->operator==(rhs));
100  }
101 
103  bool operator<(const GridLevel& rhs) const
104  {
105  if(this->type() != rhs.type()) return this->type() < rhs.type();
106  if(this->ghosts() != rhs.ghosts()) return !this->ghosts();
107  if(this->level() == rhs.level()) return false;
108  if(this->level() == TOP) return false;
109  if(rhs.level() == TOP) return true;
110  return this->level() < rhs.level();
111  }
112 
114  bool operator>(const GridLevel& rhs) const
115  {
116  if(this->type() != rhs.type()) return this->type() > rhs.type();
117  if(this->ghosts() != rhs.ghosts()) return this->ghosts();
118  if(this->level() == rhs.level()) return false;
119  if(this->level() == TOP) return true;
120  if(rhs.level() == TOP) return false;
121  return this->level() > rhs.level();
122  }
123 
125  bool operator<=(const GridLevel& rhs) const
126  {
127  return (*this < rhs || *this == rhs);
128  }
129 
131  bool operator>=(const GridLevel& rhs) const
132  {
133  return (*this > rhs || *this == rhs);
134  }
135 
136  protected:
137  int m_level;
140 };
141 
143 std::ostream& operator<<(std::ostream& out, const GridLevel& v);
144 
146 std::string GridLevelAppendix(const GridLevel& gl, int minfill = 2);
147 
148 } // end namespace ug
149 
150 #endif /* __H__UG__LIB_GRID__TOOLS__GRID_LEVEL__ */
Definition: grid_level.h:42
@ TOP
Definition: grid_level.h:45
bool operator>=(const GridLevel &rhs) const
operator >=
Definition: grid_level.h:131
bool top() const
returns if top level
Definition: grid_level.h:83
bool is_level() const
returns if type is level
Definition: grid_level.h:86
bool operator>(const GridLevel &rhs) const
operator >
Definition: grid_level.h:114
bool operator<(const GridLevel &rhs) const
operator <
Definition: grid_level.h:103
bool operator!=(const GridLevel &rhs) const
operator !=
Definition: grid_level.h:98
ViewType type() const
returns the type
Definition: grid_level.h:77
GridLevel(int level, ViewType type, bool bWithGhosts=false)
constructor
Definition: grid_level.h:55
int m_level
the grid level
Definition: grid_level.h:137
bool is_surface() const
returns if type is surface
Definition: grid_level.h:89
bool m_bWithGhosts
with ghosts (only senseful in parallel)
Definition: grid_level.h:139
GridLevel()
constructor creation surface grid
Definition: grid_level.h:52
int level() const
returns the level
Definition: grid_level.h:74
ViewType m_type
type (i.e. surface or level view)
Definition: grid_level.h:138
bool operator<=(const GridLevel &rhs) const
operator <=
Definition: grid_level.h:125
bool operator==(const GridLevel &rhs) const
operator ==
Definition: grid_level.h:92
bool ghosts() const
returns if ghosts are considered as part of the level
Definition: grid_level.h:80
GridLevel(int level, const std::string &type)
constructor
Definition: grid_level.h:65
GridLevel(int level)
constructor
Definition: grid_level.h:60
ViewType
type of view
Definition: grid_level.h:48
@ SURFACE
Definition: grid_level.h:48
@ LEVEL
Definition: grid_level.h:48
std::ostream & operator<<(std::ostream &outStream, const ug::MathMatrix< 2, 2 > &m)
Definition: math_matrix.cpp:38
#define UG_THROW(msg)
Definition: error.h:57
the ug namespace
std::string GridLevelAppendix(const GridLevel &gl, int minfill)
returns appendix for a grid level
Definition: grid_level.cpp:56