Nektar++
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
Composite.h
Go to the documentation of this file.
1 ////////////////////////////////////////////////////////////////////////////////
2 //
3 // File: Composite.h
4 //
5 // For more information, please see: http://www.nektar.info/
6 //
7 // The MIT License
8 //
9 // Copyright (c) 2006 Division of Applied Mathematics, Brown University (USA),
10 // Department of Aeronautics, Imperial College London (UK), and Scientific
11 // Computing and Imaging Institute, University of Utah (USA).
12 //
13 // License for the specific language governing rights and limitations under
14 // Permission is hereby granted, free of charge, to any person obtaining a
15 // copy of this software and associated documentation files (the "Software"),
16 // to deal in the Software without restriction, including without limitation
17 // the rights to use, copy, modify, merge, publish, distribute, sublicense,
18 // and/or sell copies of the Software, and to permit persons to whom the
19 // Software is furnished to do so, subject to the following conditions:
20 //
21 // The above copyright notice and this permission notice shall be included
22 // in all copies or substantial portions of the Software.
23 //
24 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
25 // OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
26 // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
27 // THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
28 // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
29 // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
30 // DEALINGS IN THE SOFTWARE.
31 //
32 // Description: Mesh Composite Object.
33 //
34 ////////////////////////////////////////////////////////////////////////////////
35 
36 #ifndef NEKMESHUTILS_MESHELEMENTS_COMPOSITE
37 #define NEKMESHUTILS_MESHELEMENTS_COMPOSITE
38 
41 
42 namespace Nektar
43 {
44 namespace NekMeshUtils
45 {
46 /**
47  * @brief A composite is a collection of elements.
48  *
49  * All elements should be of the same type, i.e. have the same tag.
50  */
51 class Composite
52 {
53 public:
55  {
56  }
57 
58  /**
59  * @brief Generate a Nektar++ string describing the composite.
60  *
61  * The list of composites may include individual element IDs or ranges of
62  * element IDs.
63  */
64  NEKMESHUTILS_EXPORT std::string GetXmlString(bool doSort = true)
65  {
66  std::stringstream st;
68  bool range = false;
69  int vId = m_items[0]->GetId();
70  int prevId = vId;
71 
72  st << " " << m_tag << "[" << vId;
73 
74  for (it = m_items.begin() + 1; it != m_items.end(); ++it)
75  {
76  // store previous element ID and get current one
77  prevId = vId;
78  vId = (*it)->GetId();
79 
80  // continue an already started range
81  if (prevId > -1 && vId == prevId + 1)
82  {
83  range = true;
84  // if this is the last element, it's the end of a range, so
85  // write
86  if (*it == m_items.back())
87  {
88  st << "-" << vId;
89  }
90  continue;
91  }
92 
93  // terminate a range, if present
94  if (range)
95  {
96  st << "-" << prevId;
97  range = false;
98  }
99 
100  // write what will be either a single entry or start of new range
101  st << "," << vId;
102  }
103  // terminate
104  st << "] ";
105  return st.str();
106  }
107 
108  /// ID of composite.
109  unsigned int m_id;
110  /// Element type tag.
111  std::string m_tag;
112  /// boundary label
113  std::string m_label;
114  /// Determines whether items can be reordered.
115  bool m_reorder;
116  /// List of elements in this composite.
117  std::vector<ElementSharedPtr> m_items;
118 };
119 
120 /// Shared pointer to a composite.
121 typedef boost::shared_ptr<Composite> CompositeSharedPtr;
122 /// Container of composites; key is the composite id, value is the
123 /// composite.
124 typedef std::map<unsigned int, CompositeSharedPtr> CompositeMap;
125 }
126 }
127 
128 #endif
std::vector< ElementSharedPtr > m_items
List of elements in this composite.
Definition: Composite.h:117
std::map< unsigned int, CompositeSharedPtr > CompositeMap
Container of composites; key is the composite id, value is the composite.
Definition: Composite.h:124
bool m_reorder
Determines whether items can be reordered.
Definition: Composite.h:115
NEKMESHUTILS_EXPORT std::string GetXmlString(bool doSort=true)
Generate a Nektar++ string describing the composite.
Definition: Composite.h:64
A composite is a collection of elements.
Definition: Composite.h:51
boost::shared_ptr< Composite > CompositeSharedPtr
Shared pointer to a composite.
Definition: Composite.h:121
NEKMESHUTILS_EXPORT Composite()
Definition: Composite.h:54
StandardMatrixTag boost::call_traits< LhsDataType >::const_reference rhs typedef NekMatrix< LhsDataType, StandardMatrixTag >::iterator iterator
unsigned int m_id
ID of composite.
Definition: Composite.h:109
#define NEKMESHUTILS_EXPORT
std::string m_label
boundary label
Definition: Composite.h:113
std::string m_tag
Element type tag.
Definition: Composite.h:111