KratosMultiphysics
KRATOS Multiphysics (Kratos) is a framework for building parallel, multi-disciplinary simulation software, aiming at modularity, extensibility, and high performance. Kratos is written in C++, and counts with an extensive Python interface.
partitioned_vector.h
Go to the documentation of this file.
1 // | / |
2 // ' / __| _` | __| _ \ __|
3 // . \ | ( | | ( |\__ `
4 // _|\_\_| \__,_|\__|\___/ ____/
5 // Multi-Physics
6 //
7 // License: BSD License
8 // Kratos default license: kratos/license.txt
9 //
10 // Main authors: Pooyan Dadvand
11 // Riccardo Rossi
12 //
13 //
14 
15 
16 #if !defined(KRATOS_PARTITIONED_VECTOR_H_INCLUDED )
17 #define KRATOS_PARTITIONED_VECTOR_H_INCLUDED
18 
19 
20 
21 // System includes
22 #include <string>
23 #include <iostream>
24 #include <vector>
25 
26 
27 // External includes
28 
29 // Project includes
30 #include "includes/define.h"
31 
32 
33 namespace Kratos
34 {
35 
38 
42 
46 
50 
54 
56 
58 template<class TVectorType>
60 {
61 public:
64 
67 
68  typedef std::size_t size_type;
69  typedef TVectorType VectorType;
72  typedef value_type const& const_reference;
73  typedef std::vector<VectorType> VectorsContainerType;
74  typedef std::vector<size_type> PartitionsIndicesVectorType;
75 
79 
81  partitioned_vector () : mVectors(), mPartitionsIndices(1,0) // one partition with size zero
82  {
83  }
84 
85  template<class TSizesVectorType>
86  partitioned_vector (TSizesVectorType const& PartitionSizes)
87  : mVectors(PartitionSizes.size()), mPartitionsIndices(PartitionSizes.size())
88  {
89  resize(PartitionSizes);
90  }
91 
92 
93 
97 
98  // Element access
100  {
101  return GetValue(i);
102  }
103 
105  {
106  return GetValue(i);
107  }
108 
110  {
111  return GetValue(i);
112  }
113 
115  {
116  return GetValue(i);
117  }
118 
119  // Assignment
121  {
122  mVectors= v.mVectors;
123  mPartitionsIndices= v.mPartitionsIndices;
124  return *this;
125  }
126 
127 
131 
132  // Resizing
133  template<class TSizesVectorType>
134  void resize(TSizesVectorType const& PartitionSizes)
135  {
136  mVectors.resize(PartitionSizes.size());
137  mPartitionsIndices.resize(PartitionSizes.size() + 1);
138 
139  mPartitionsIndices[0] = 0;
140 
141  for(size_type i = 0 ; i < PartitionSizes.size() ; i++)
142  {
143  mVectors[i].resize(PartitionSizes[i]);
144  mPartitionsIndices[i+1] = PartitionSizes[i] + mPartitionsIndices[i];
145  }
146  }
147 
148  // Swapping
150  {
151  if (this != &v)
152  {
153  mVectors.swap (v.mVectors);
154  mPartitionsIndices.swap (v.mPartitionsIndices);
155  }
156  }
157 
158 
159 
163 
164 public:
165 
166  size_type size () const
167  {
168  return mPartitionsIndices.back();
169  }
170 
171  const VectorsContainerType &data () const
172  {
173  return mVectors;
174  }
175 
177  {
178  return mVectors;
179  }
180 
181 
183  {
184  return mVectors[i];
185  }
186 
188  {
189  return mVectors[i];
190  }
191 
193  {
194  return mPartitionsIndices[i];
195  }
196 
197 
198 
202 
203 
207 
208 
212 
213 
215 
216 protected:
219 
220 
224 
225 
229 
230 
234 
235 
239 
240 
244 
245 
249 
250 
252 
253 private:
254 
255 
258 
259 
263 
264  VectorsContainerType mVectors;
265  PartitionsIndicesVectorType mPartitionsIndices;
266 
270 
271  reference GetValue(size_type i)
272  {
273  for(size_type partition_index = 0 ; partition_index < mVectors.size() ; partition_index++)
274  if(i < mPartitionsIndices[partition_index+1])
275  return mVectors[partition_index][i - mPartitionsIndices[partition_index]];
276  }
277 
278 
282 
283 
287 
288 
292 
293 
297 
298 
300 
301 }; // Class partitioned_vector
302 
304 
307 
308 
312 
314 
315 
316 } // namespace Kratos.
317 
318 #endif // KRATOS_PARTITIONED_VECTOR_H_INCLUDED defined
double value_type
Definition: array_1d.h:75
Short class definition.
Definition: partitioned_vector.h:60
void swap(partitioned_vector &v)
Definition: partitioned_vector.h:149
std::vector< size_type > PartitionsIndicesVectorType
Definition: partitioned_vector.h:74
size_type size() const
Definition: partitioned_vector.h:166
KRATOS_CLASS_POINTER_DEFINITION(partitioned_vector)
Pointer definition of partitioned_vector.
TVectorType VectorType
Definition: partitioned_vector.h:69
const_reference operator[](size_type i) const
Definition: partitioned_vector.h:109
partitioned_vector & operator=(const partitioned_vector &v)
Definition: partitioned_vector.h:120
const VectorsContainerType & data() const
Definition: partitioned_vector.h:171
std::vector< VectorType > VectorsContainerType
Definition: partitioned_vector.h:73
const VectorType & partition(size_type i) const
Definition: partitioned_vector.h:182
partitioned_vector()
Default constructor.
Definition: partitioned_vector.h:81
VectorsContainerType & data()
Definition: partitioned_vector.h:176
const VectorType & partition_index(size_type i) const
Definition: partitioned_vector.h:192
VectorType::value_type value_type
Definition: partitioned_vector.h:70
std::size_t size_type
Definition: partitioned_vector.h:68
value_type & reference
Definition: partitioned_vector.h:71
value_type const & const_reference
Definition: partitioned_vector.h:72
VectorType & partition(size_type i)
Definition: partitioned_vector.h:187
void resize(TSizesVectorType const &PartitionSizes)
Definition: partitioned_vector.h:134
partitioned_vector(TSizesVectorType const &PartitionSizes)
Definition: partitioned_vector.h:86
const_reference operator()(size_type i) const
Definition: partitioned_vector.h:99
REF: G. R. Cowper, GAUSSIAN QUADRATURE FORMULAS FOR TRIANGLES.
Definition: mesh_condition.cpp:21
v
Definition: generate_convection_diffusion_explicit_element.py:114
integer i
Definition: TensorModule.f:17