Nektar++
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
NekVectorConstantSized.hpp
Go to the documentation of this file.
1 /////////////////////////////////////////////////////////////////////////////////
2 ////
3 //// File: NekConstantSizedVector.hpp
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: Generic N-Dimensional Vector.
33 ////
34 /////////////////////////////////////////////////////////////////////////////////
35 //
36 //#ifndef NEKTAR_LIB_UTILITIES_LINEAR_ALGEBRA_NEK_CONSTANT_SIZED_VECTOR_HPP
37 //#define NEKTAR_LIB_UTILITIES_LINEAR_ALGEBRA_NEK_CONSTANT_SIZED_VECTOR_HPP
38 //
39 //#include <LibUtilities/LinearAlgebra/NekVectorFwd.hpp>
40 //#include <LibUtilities/LinearAlgebra/NekVectorTypeTraits.hpp>
41 //#include <LibUtilities/LinearAlgebra/NekVectorCommon.hpp>
42 //#include <LibUtilities/LinearAlgebra/PointerWrapper.h>
43 //
44 //#include <ExpressionTemplates/ExpressionTemplates.hpp>
45 //#include <LibUtilities/BasicUtils/ErrorUtil.hpp>
46 //
47 //
48 //#include <algorithm>
49 //#include <boost/static_assert.hpp>
50 //
51 //
52 //namespace Nektar
53 //{
54 //
55 //
56 // template<typename dataType, typename dim, typename space>
57 // class NekVector<dataType, dim, space>
58 // {
59 // public:
60 // typedef dataType DataType;
61 //
62 // NekVector() :
63 // m_impl()
64 // {
65 // std::fill_n(m_impl, dim::Value, DataType());
66 // }
67 //
68 // explicit NekVector(typename boost::call_traits<DataType>::const_reference a) :
69 // m_impl()
70 // {
71 // std::fill_n(m_impl, dim::Value, a);
72 // }
73 //
74 // /// \brief Constructs a vector with initial value a.
75 // ///
76 // /// \param size The size of the vector. Since the size of the vector is specified in the template, this parameter is ignored.
77 // /// \param a The value with which to initialize the vector.
78 // ///
79 // /// This constructor is provided for generic methods which don't know if the vector they
80 // /// are creating is constant sized or variable sized.
81 // NekVector(unsigned int size, typename boost::call_traits<DataType>::const_reference a) :
82 // m_impl()
83 // {
84 // ASSERTL1(size == dim::Value, std::string("Attempting to construct a constant sized vector of size ") +
85 // boost::lexical_cast<std::string>(dim::Value) +
86 // std::string(" with a size ") +
87 // boost::lexical_cast<std::string>(size));
88 // std::fill_n(m_impl, dim::Value, a);
89 // }
90 //
91 // explicit NekVector(const std::string& vectorValues) :
92 // m_impl()
93 // {
94 // std::vector<DataType> values = FromString<DataType>(vectorValues);
95 //
96 // ASSERTL0(values.size() == dim::Value, "Error converting string values to vector");
97 //
98 // std::copy(values.begin(), values.end(), &m_impl[0]);
99 // }
100 //
101 // NekVector(typename boost::call_traits<DataType>::const_reference x,
102 // typename boost::call_traits<DataType>::const_reference y,
103 // typename boost::call_traits<DataType>::const_reference z) :
104 // m_impl()
105 // {
106 // BOOST_STATIC_ASSERT(dim::Value == 3);
107 // m_impl[0] = x;
108 // m_impl[1] = y;
109 // m_impl[2] = z;
110 // }
111 //
112 // NekVector(typename boost::call_traits<DataType>::const_reference x,
113 // typename boost::call_traits<DataType>::const_reference y,
114 // typename boost::call_traits<DataType>::const_reference z,
115 // typename boost::call_traits<DataType>::const_reference w) :
116 // m_impl()
117 // {
118 // BOOST_STATIC_ASSERT(dim::Value == 4);
119 // m_impl[0] = x;
120 // m_impl[1] = y;
121 // m_impl[2] = z;
122 // m_impl[3] = w;
123 // }
124 //
125 // NekVector(const NekVector<DataType, dim, space>& rhs) :
126 // m_impl()
127 // {
128 // std::copy(rhs.m_impl, rhs.m_impl+dim::Value, m_impl);
129 // }
130 //
131 // explicit NekVector(const DataType* const ptr) :
132 // m_impl()
133 // {
134 // std::copy(ptr, ptr+dim::Value, &m_impl[0]);
135 // }
136 //
137 // ~NekVector()
138 // {
139 //#ifdef _DEBUG
140 // std::fill_n(m_impl, dim::Value, DataType());
141 //#endif //_DEBUG
142 // }
143 //
144 //#ifdef NEKTAR_USE_EXPRESSION_TEMPLATES
145 // template<typename L, typename Op, typename R>
146 // NekVector(const expt::Node<L, Op, R>& rhs) :
147 // m_impl()
148 // {
149 // #ifdef _DEBUG
150 // boost::tuple<unsigned int, unsigned int, unsigned int> sizes =
151 // MatrixSize<Node<L, Op, R>, typename Node<L, Op, R>::Indices, 0>::GetRequiredSize(rhs.GetData());
152 // ASSERTL0(sizes.get<0>() == dim::Value, "Data sizes are not equal.");
153 // #endif
154 //
155 // /// TODO Make sure this works correctly with eWrapper
156 // //BOOST_MPL_ASSERT(( boost::is_same<typename Expression<ExpressionPolicyType>::ResultType, NekVector<DataType, VariableSizedVector, space> > ));
157 // expt::ExpressionEvaluator::Evaluate(rhs, *this);
158 // }
159 //#endif
160 //
161 //#ifdef NEKTAR_USE_EXPRESSION_TEMPLATES
162 // template<typename L, typename Op, typename R>
163 // NekVector<DataType, dim, space>& operator=(const expt::Node<L, Op, R>& rhs)
164 // {
165 // rhs.Evaluate(*this);
166 // return *this;
167 // }
168 //#endif
169 //
170 // /// \brief Returns the number of dimensions for the point.
171 // unsigned int GetDimension() const
172 // {
173 // return dim::Value;
174 // }
175 //
176 // /// \brief Treating the vector as a column vector, how many rows it has.
177 // unsigned int GetRows() const
178 // {
179 // return dim::Value;
180 // }
181 //
182 // const DataType* GetRawPtr() const
183 // {
184 // return &m_impl[0];
185 // }
186 //
187 // typedef const DataType* const_iterator;
188 // const_iterator begin() const { return GetRawPtr(); }
189 // const_iterator end() const { return GetRawPtr() + GetDimension(); }
190 //
191 // typename boost::call_traits<DataType>::const_reference operator()(unsigned int i) const
192 // {
193 // ASSERTL1(( i >= 0) && (i < GetDimension()), "Invalid access to m_data via parenthesis operator");
194 // return m_impl[i];
195 // }
196 //
197 // typename boost::call_traits<DataType>::const_reference operator[](unsigned int i) const
198 // {
199 // return m_impl[i];
200 // }
201 //
202 // typename boost::call_traits<DataType>::const_reference x() const
203 // {
204 // BOOST_STATIC_ASSERT(dim::Value >= 1);
205 // return m_impl[0];
206 // }
207 //
208 // typename boost::call_traits<DataType>::const_reference y() const
209 // {
210 // BOOST_STATIC_ASSERT(dim::Value >= 2);
211 // return m_impl[1];
212 // }
213 //
214 // typename boost::call_traits<DataType>::const_reference z() const
215 // {
216 // BOOST_STATIC_ASSERT(dim::Value >= 3);
217 // return m_impl[2];
218 // }
219 //
220 // typename boost::call_traits<DataType>::const_reference w() const
221 // {
222 // BOOST_STATIC_ASSERT(dim::Value >= 4);
223 // return m_impl[3];
224 // }
225 //
226 //
227 //// typename boost::call_traits<DataType>::reference x()
228 //// {
229 //// BOOST_STATIC_ASSERT(dim::Value >= 1);
230 //// return m_impl[0];
231 //// }
232 ////
233 //// typename boost::call_traits<DataType>::reference y()
234 //// {
235 //// BOOST_STATIC_ASSERT(dim::Value >= 2);
236 //// return m_impl[1];
237 //// }
238 ////
239 //// typename boost::call_traits<DataType>::reference z()
240 //// {
241 //// BOOST_STATIC_ASSERT(dim::Value >= 3);
242 //// return m_impl[2];
243 //// }
244 ////
245 ////
246 //// typename boost::call_traits<DataType>::reference w()
247 //// {
248 //// BOOST_STATIC_ASSERT(dim::Value >= 4);
249 //// return m_impl[3];
250 //// }
251 //
252 // // Unitary operators
253 // NekVector<DataType, dim, space> operator-() const { return Negate(*this); }
254 //
255 // DataType Magnitude() const { return Nektar::Magnitude(*this); }
256 //
257 // DataType Dot(const NekVector<DataType, dim, space>& rhs) const { return Nektar::Dot(*this, rhs); }
258 //
259 // NekVector<DataType, dim, space> Cross(const NekVector<DataType, dim, space>& rhs) const
260 // {
261 // return Nektar::Cross(*this, rhs);
262 // }
263 //
264 // std::string AsString() const { return Nektar::AsString(*this); }
265 //
266 // // Norms
267 // DataType L1Norm() const { return Nektar::L1Norm(*this); }
268 // DataType L2Norm() const { return Nektar::L2Norm(*this); }
269 // DataType InfinityNorm() const { return Nektar::InfinityNorm(*this); }
270 //
271 // PointerWrapper GetWrapperType() const { return eCopy; }
272 //
273 // protected:
274 // DataType* GetImpl() { return &m_impl[0]; }
275 //
276 // NekVector<DataType, dim, space>& operator=(const NekVector<DataType, dim, space>& rhs)
277 // {
278 // std::copy(rhs.m_impl, rhs.m_impl+dim::Value, m_impl);
279 // return *this;
280 // }
281 //
282 // NekVector<DataType, dim, space>& operator=(const NekVector<DataType, VariableSizedVector, space>& rhs)
283 // {
284 // ASSERTL0(GetDimension() == rhs.GetDimension(), "Assignment to a constant sized vector must have the same number of elements.");
285 // std::copy(rhs.GetRawPtr(), rhs.GetRawPtr()+dim::Value, m_impl);
286 // return *this;
287 // }
288 //
289 // private:
290 // DataType m_impl[dim::Value];
291 //
292 // };
293 //
294 // // \param DataType The type of data held by each element of the vector.
295 // // \param dim The number of elements in the vector. If set to 0, the vector
296 // // will have a variable number of elements.
297 // // \param space The space of the vector.
298 // template<typename DataType, typename dim, typename space>
299 // class NekVector : public NekVector<DataType, dim, space>
300 // {
301 // public:
302 // typedef NekVector<DataType, dim, space> BaseType;
303 //
304 // /// \brief Creates a constant sized vector with each element initialized to
305 // /// the default value for DataType.
306 // NekVector() : BaseType() {}
307 //
308 // /// \brief Creates a constant sized vector with each element set to a.
309 // /// \param a The value to assign to each element of the vector.
310 // explicit NekVector(typename boost::call_traits<DataType>::const_reference a) :
311 // BaseType(a) {}
312 //
313 // NekVector(unsigned int size, typename boost::call_traits<DataType>::const_reference a) :
314 // BaseType(size, a) {}
315 //
316 // /// \brief Creates a vector from the elements in a delimited string.
317 // /// \param vectorValues A string the the vector values.
318 // ///
319 // ///
320 // explicit NekVector(const std::string& vectorValues) : BaseType(vectorValues) {}
321 //
322 // NekVector(typename boost::call_traits<DataType>::const_reference x,
323 // typename boost::call_traits<DataType>::const_reference y,
324 // typename boost::call_traits<DataType>::const_reference z) :
325 // BaseType(x, y, z) {}
326 //
327 // NekVector(typename boost::call_traits<DataType>::const_reference x,
328 // typename boost::call_traits<DataType>::const_reference y,
329 // typename boost::call_traits<DataType>::const_reference z,
330 // typename boost::call_traits<DataType>::const_reference w) :
331 // BaseType(x,y,z,w) {}
332 //
333 // NekVector(const NekVector<DataType, dim, space>& rhs) :
334 // BaseType(rhs) {}
335 //
336 // explicit NekVector(const DataType* const ptr) :
337 // BaseType(ptr) {}
338 //
339 //
340 //#ifdef NEKTAR_USE_EXPRESSION_TEMPLATES
341 // template<typename L, typename Op, typename R>
342 // NekVector(const expt::Node<L, Op, R>& rhs) :
343 // BaseType()
344 // {
345 // #ifdef _DEBUG
346 // boost::tuple<unsigned int, unsigned int, unsigned int> sizes =
347 // MatrixSize<expt::Node<L, Op, R>, typename expt::Node<L, Op, R>::Indices, 0>::GetRequiredSize(rhs.GetData());
348 // ASSERTL0(sizes.get<0>() == dim::Value, "Data sizes are not equal.");
349 // #endif
350 //
351 // /// TODO Make sure this works correctly with eWrapper
352 // //BOOST_MPL_ASSERT(( boost::is_same<typename Expression<ExpressionPolicyType>::ResultType, NekVector<DataType, VariableSizedVector, space> > ));
353 // expt::ExpressionEvaluator::Evaluate(rhs, *this);
354 // }
355 //#endif
356 //
357 //#ifdef NEKTAR_USE_EXPRESSION_TEMPLATES
358 // template<typename L, typename Op, typename R>
359 // NekVector<DataType, dim, space>& operator=(const expt::Node<L, Op, R>& rhs)
360 // {
361 // rhs.Evaluate(*this);
362 // return *this;
363 // }
364 //#endif
365 //
366 //
367 //
368 // NekVector<DataType, dim, space>& operator=(const NekVector<DataType, dim, space>& rhs)
369 // {
370 // BaseType::operator=(rhs);
371 // return *this;
372 // }
373 //
374 // NekVector<DataType, dim, space>& operator=(const NekVector<DataType, VariableSizedVector, space>& rhs)
375 // {
376 // BaseType::operator=(rhs);
377 // return *this;
378 // }
379 //
380 // using BaseType::GetRawPtr;
381 // DataType* GetRawPtr()
382 // {
383 // return this->GetImpl();
384 // }
385 //
386 //
387 // typedef DataType* iterator;
388 //
389 //
390 // iterator begin() { return GetRawPtr(); }
391 // iterator end() { return GetRawPtr() + this->GetDimension(); }
392 //
393 //
394 // /// \brief Returns i^{th} element.
395 // /// \param i The element to return.
396 // /// \pre i < dim
397 // /// \return A reference to the i^{th} element.
398 // ///
399 // /// Retrieves the i^{th} element. Since it returns a reference you may
400 // /// assign a new value (i.e., p(2) = 3.2;)
401 // ///
402 // /// This operator performs range checking.
403 // typename boost::call_traits<DataType>::reference operator()(unsigned int i)
404 // {
405 // ASSERTL1((i >= 0) && (i < this->GetDimension()), "Invalid access to m_data via parenthesis operator");
406 // return this->GetImpl()[i];
407 // }
408 //
409 // typename boost::call_traits<DataType>::reference operator[](unsigned int i)
410 // {
411 // return this->GetImpl()[i];
412 // }
413 //
414 // using BaseType::operator();
415 // using BaseType::operator[];
416 //
417 // using BaseType::x;
418 // typename boost::call_traits<DataType>::reference x()
419 // {
420 // BOOST_STATIC_ASSERT(dim::Value >= 1);
421 // return this->GetImpl()[0];
422 // }
423 //
424 // using BaseType::y;
425 // typename boost::call_traits<DataType>::reference y()
426 // {
427 // BOOST_STATIC_ASSERT(dim::Value >= 2);
428 // return this->GetImpl()[1];
429 // }
430 //
431 // using BaseType::z;
432 // typename boost::call_traits<DataType>::reference z()
433 // {
434 // BOOST_STATIC_ASSERT(dim::Value >= 3);
435 // return this->GetImpl()[2];
436 // }
437 //
438 // using BaseType::w;
439 // typename boost::call_traits<DataType>::reference w()
440 // {
441 // BOOST_STATIC_ASSERT(dim::Value >= 4);
442 // return this->GetImpl()[3];
443 // }
444 //
445 // void SetX(typename boost::call_traits<DataType>::const_reference val)
446 // {
447 // BOOST_STATIC_ASSERT(dim::Value >= 1);
448 // this->GetImpl()[0] = val;
449 // }
450 //
451 // void SetY(typename boost::call_traits<DataType>::const_reference val)
452 // {
453 // BOOST_STATIC_ASSERT(dim::Value >= 2);
454 // this->GetImpl()[1] = val;
455 // }
456 //
457 // void SetZ(typename boost::call_traits<DataType>::const_reference val)
458 // {
459 // BOOST_STATIC_ASSERT(dim::Value >= 3);
460 // this->GetImpl()[2] = val;
461 // }
462 //
463 // void SetW(typename boost::call_traits<DataType>::const_reference val)
464 // {
465 // BOOST_STATIC_ASSERT(dim::Value >= 4);
466 // this->GetImpl()[3] = val;
467 // }
468 //
469 // /// Arithmetic Routines
470 //
471 // NekVector<DataType, dim, space>& operator+=(const NekVector<DataType, dim, space>& rhs)
472 // {
473 // AddEqual(*this, rhs);
474 // return *this;
475 // }
476 //
477 // NekVector<DataType, dim, space>& operator-=(const NekVector<DataType, dim, space>& rhs)
478 // {
479 // SubtractEqual(*this, rhs);
480 // return *this;
481 // }
482 //
483 // NekVector<DataType, dim, space>& operator*=(typename boost::call_traits<DataType>::const_reference rhs)
484 // {
485 // MultiplyEqual(*this, rhs);
486 // return *this;
487 // }
488 //
489 // NekVector<DataType, dim, space>& operator/=(typename boost::call_traits<DataType>::const_reference rhs)
490 // {
491 // DivideEqual(*this, rhs);
492 // return *this;
493 // }
494 //
495 //
496 //
497 // void Normalize() { return Nektar::Normalize(*this); }
498 //
499 //
500 //
501 // };
502 //
503 //
504 //
505 //}
506 //
507 //#endif // NEKTAR_LIB_UTILITIES_LINEAR_ALGEBRA_NEK_CONSTANT_SIZED_VECTOR_HPP