Intrepid
Intrepid_FieldContainer.hpp
Go to the documentation of this file.
1 // @HEADER
2 // ************************************************************************
3 //
4 // Intrepid Package
5 // Copyright (2007) Sandia Corporation
6 //
7 // Under terms of Contract DE-AC04-94AL85000, there is a non-exclusive
8 // license for use of this work by or on behalf of the U.S. Government.
9 //
10 // Redistribution and use in source and binary forms, with or without
11 // modification, are permitted provided that the following conditions are
12 // met:
13 //
14 // 1. Redistributions of source code must retain the above copyright
15 // notice, this list of conditions and the following disclaimer.
16 //
17 // 2. Redistributions in binary form must reproduce the above copyright
18 // notice, this list of conditions and the following disclaimer in the
19 // documentation and/or other materials provided with the distribution.
20 //
21 // 3. Neither the name of the Corporation nor the names of the
22 // contributors may be used to endorse or promote products derived from
23 // this software without specific prior written permission.
24 //
25 // THIS SOFTWARE IS PROVIDED BY SANDIA CORPORATION "AS IS" AND ANY
26 // EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
27 // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
28 // PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL SANDIA CORPORATION OR THE
29 // CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
30 // EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
31 // PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
32 // PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
33 // LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
34 // NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
35 // SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
36 //
37 // Questions? Contact Pavel Bochev (pbboche@sandia.gov)
38 // Denis Ridzal (dridzal@sandia.gov), or
39 // Kara Peterson (kjpeter@sandia.gov)
40 //
41 // ************************************************************************
42 // @HEADER
43 
49 #ifndef INTREPID_FIELDCONTAINER_HPP
50 #define INTREPID_FIELDCONTAINER_HPP
51 
52 #include "Intrepid_ConfigDefs.hpp"
53 #include "Intrepid_Types.hpp"
54 #include "Intrepid_Utils.hpp"
55 #include "Teuchos_Array.hpp"
56 #include "Teuchos_ArrayRCP.hpp"
57 #include "Teuchos_ArrayView.hpp"
58 #include "Shards_Array.hpp"
59 #include "Teuchos_RCP.hpp"
60 #include "Teuchos_BLAS.hpp"
61 #include "Teuchos_oblackholestream.hpp"
62 #include "Teuchos_Assert.hpp"
63 
64 namespace Intrepid {
65 
77  template<class Scalar, int ArrayTypeId=0>
79  public:
81  typedef Scalar scalar_type;
82 
83  protected:
84 
87  Teuchos::ArrayRCP<Scalar> data_;
88 
89  typedef typename Teuchos::ArrayRCP<Scalar>::iterator data_ptr_t;
90  data_ptr_t data_ptr_;
91 
96  Teuchos::Array<int> dimensions_;
97 
99  int dim0_;
100 
102  int dim1_;
103 
105  int dim2_;
106 
108  int dim3_;
109 
111  int dim4_;
112 
113  public:
114 
115 
119 
120 
123  FieldContainer() : dim0_(0), dim1_(0), dim2_(0), dim3_(0), dim4_(0)
124  {
125  data_.resize(0);
126  data_ptr_ = Teuchos::NullIteratorTraits<data_ptr_t>::getNull();
127  dimensions_.resize(0);
128  } ;
129 
130 
133  FieldContainer(const FieldContainer& right);
134 
135 
140  FieldContainer(const int dim0);
141 
142 
148  FieldContainer(const int dim0,
149  const int dim1);
150 
151 
158  FieldContainer(const int dim0,
159  const int dim1,
160  const int dim2);
161 
162 
170  FieldContainer(const int dim0,
171  const int dim1,
172  const int dim2,
173  const int dim3);
174 
175 
184  FieldContainer(const int dim0,
185  const int dim1,
186  const int dim2,
187  const int dim3,
188  const int dim4);
189 
190 
197  FieldContainer(const Teuchos::Array<int>& dimensions);
198 
199 
211  FieldContainer(const Teuchos::Array<int>& dimensions,
212  const Teuchos::ArrayView<Scalar>& data);
213 
214 
225  FieldContainer(const Teuchos::Array<int>& dimensions,
226  const Teuchos::ArrayRCP<Scalar>& data);
227 
228 
240  FieldContainer(const Teuchos::Array<int>& dimensions,
241  Scalar* data,
242  const bool deep_copy = false,
243  const bool owns_mem = false);
244 
245 
255  FieldContainer(const shards::Array<Scalar,shards::NaturalOrder>& data,
256  const bool deep_copy = false,
257  const bool owns_mem = false);
258 
259 
260 
261 
262  //--------------------------------------------------------------------------------------------//
263  // //
264  // Access methods of FieldContainer class //
265  // //
266  //--------------------------------------------------------------------------------------------//
267 
270  int rank() const;
271 
272 
275  int size() const;
276 
277 
280  template<class Vector>
281  void dimensions(Vector& dimensions) const;
282 
283 
288  int dimension(const int whichDim) const;
289 
290 
296  int getEnumeration(const int i0) const;
297 
298 
305  int getEnumeration(const int i0,
306  const int i1) const;
307 
308 
316  int getEnumeration(const int i0,
317  const int i1,
318  const int i2) const;
319 
320 
329  int getEnumeration(const int i0,
330  const int i1,
331  const int i2,
332  const int i3) const;
333 
334 
344  int getEnumeration(const int i0,
345  const int i1,
346  const int i2,
347  const int i3,
348  const int i4) const;
349 
350 
356  int getEnumeration(const Teuchos::Array<int>& multiIndex) const;
357 
358 
365  void getMultiIndex(int & i0,
366  const int valueEnum) const;
367 
368 
376  void getMultiIndex(int & i0,
377  int & i1,
378  const int valueEnum) const;
379 
380 
389  void getMultiIndex(int & i0,
390  int & i1,
391  int & i2,
392  const int valueEnum) const;
393 
394 
404  void getMultiIndex(int & i0,
405  int & i1,
406  int & i2,
407  int & i3,
408  const int valueEnum) const;
409 
410 
421  void getMultiIndex(int & i0,
422  int & i1,
423  int & i2,
424  int & i3,
425  int & i4,
426  const int valueEnum) const;
427 
428 
439  template<class Vector>
440  void getMultiIndex(Vector& multiIndex,
441  const int valueEnum) const;
442 
443  //--------------------------------------------------------------------------------------------//
444  // //
445  // Methods to shape (resize) a field container //
446  // //
447  //--------------------------------------------------------------------------------------------//
448 
449 
452  void clear();
453 
454 
459  void resize(const int dim0);
460 
461 
467  void resize(const int dim0,
468  const int dim1);
469 
470 
477  void resize(const int dim0,
478  const int dim1,
479  const int dim2);
480 
481 
489  void resize(const int dim0,
490  const int dim1,
491  const int dim2,
492  const int dim3);
493 
494 
503  void resize(const int dim0,
504  const int dim1,
505  const int dim2,
506  const int dim3,
507  const int dim4);
508 
509 
515  void resize(const Teuchos::Array<int>& newDimensions);
516 
517 
523  void resize(const FieldContainer<Scalar, ArrayTypeId>& anotherContainer);
524 
525 
564  void resize(const int numPoints,
565  const int numFields,
566  const EFunctionSpace spaceType,
567  const EOperator operatorType,
568  const int spaceDim);
569 
570  //--------------------------------------------------------------------------------------------//
571  // //
572  // Methods to read and write values to FieldContainer //
573  // //
574  //--------------------------------------------------------------------------------------------//
575 
576 
579  void initialize(const Scalar value = 0);
580 
581 
586  Scalar getValue(const Teuchos::Array<int>& multiIndex) const;
587 
588 
594  void setValue(const Scalar dataValue,
595  const Teuchos::Array<int>& multiIndex);
596 
597 
603  void setValue(const Scalar dataValue,
604  const int order);
605 
606 
612  void setValues(const Teuchos::ArrayView<Scalar>& dataArray);
613 
614 
621  void setValues(const Scalar* dataPtr,
622  const int numData);
623 
624 
627  Teuchos::ArrayRCP<Scalar> getData() {
628  return data_;
629  }
630 
631 
634  Teuchos::ArrayRCP<const Scalar> getData() const {
635  return data_;
636  }
637 
638 
643  const Scalar& operator () (const int i0) const;
644 
649  Scalar& operator () (const int i0);
650 
651 
657  const Scalar& operator () (const int i0,
658  const int i1) const;
659 
665  Scalar& operator () (const int i0,
666  const int i1);
667 
668 
675  const Scalar& operator () (const int i0,
676  const int i1,
677  const int i2) const;
678 
685  Scalar& operator () (const int i0,
686  const int i1,
687  const int i2);
688 
689 
697  const Scalar& operator () (const int i0,
698  const int i1,
699  const int i2,
700  const int i3) const;
701 
709  Scalar& operator () (const int i0,
710  const int i1,
711  const int i2,
712  const int i3);
713 
714 
723  const Scalar& operator () (const int i0,
724  const int i1,
725  const int i2,
726  const int i3,
727  const int i4) const;
728 
737  Scalar& operator () (const int i0,
738  const int i1,
739  const int i2,
740  const int i3,
741  const int i4);
742 
743 
747  const Scalar & operator [] (const int address) const;
748 
749 
753  Scalar & operator [] (const int address);
754 
755 
759 
760  }; // end class FieldContainer
761 
762 
763  //--------------------------------------------------------------------------------------------//
764  // //
765  // Function declarations related to FieldContainer //
766  // //
767  //--------------------------------------------------------------------------------------------//
768 
772  template<class Scalar, int ArrayTypeId>
773  std::ostream& operator << (std::ostream& os, const FieldContainer<Scalar, ArrayTypeId>& container);
774 
775 
776 } // end namespace Intrepid
777 
778 /*
779 template<class FadType, class Scalar>
780 struct Return_Type< Intrepid::FieldContainer<FadType>, Scalar>{
781  typedef FadType& return_type;
782  typedef FadType const_return_type;
783 };
784 
785 template<class FadType, class Scalar>
786 struct Return_Type<const Intrepid::FieldContainer<FadType>, Scalar>{
787  typedef FadType& return_type;
788  typedef FadType const_return_type;
789 };
790 */
791 
792 // include templated definitions
794 
795 #endif
796 
922 #if defined(Intrepid_SHOW_DEPRECATED_WARNINGS)
923 #ifdef __GNUC__
924 #warning "The Intrepid package is deprecated"
925 #endif
926 #endif
927 
int size() const
Returns size of the FieldContainer defined as the product of its dimensions.
const Scalar & operator[](const int address) const
Overloaded [] operator. Returns value based on its enumeration. Data cannot be modified.
FieldContainer & operator=(const FieldContainer &right)
Assignment operator *this = right.
Scalar scalar_type
The template parameter of this class; the type of objects stored.
int dim3_
4th dimension of the array
Teuchos::Array< int > dimensions_
Array to store dimensions (dimensions) for the multi-indices. Admissible range (dimension) for the k-...
void clear()
Clears FieldContainer to trivial container (one with rank = 0 and size = 0)
int dim1_
2nd dimension of the array
int dimension(const int whichDim) const
Returns the specified dimension.
int dim2_
3rd dimension of the array
Teuchos::ArrayRCP< Scalar > data_
Array to store the multi-indexed quantity.
Contains definitions of custom data types in Intrepid.
void getMultiIndex(int &i0, const int valueEnum) const
Returns the multi-index of a value, based on its enumeration, as a list, for rank-1 containers...
int rank() const
Return rank of the FieldContainer = number of indices used to tag the multi-indexed value...
int getEnumeration(const int i0) const
Returns enumeration of a value (its order relative to the container), based on its multi-index...
Intrepid utilities.
const Scalar & operator()(const int i0) const
Overloaded () operators for rank-1 containers. Data cannot be modified.
void setValue(const Scalar dataValue, const Teuchos::Array< int > &multiIndex)
Assign value by its multi-index.
void setValues(const Teuchos::ArrayView< Scalar > &dataArray)
Fills an existing FieldContainer with Scalars stored in a Teuchos::Array without changing rank and di...
~FieldContainer()
Default destructor.
Implementation of a templated lexicographical container for a multi-indexed scalar quantity...
void resize(const int dim0)
Resizes FieldContainer to a rank-1 container with the specified dimension, initialized by 0...
FieldContainer()
Default constructor.
void initialize(const Scalar value=0)
Initializes a field container by assigning value to all its elements.
Teuchos::ArrayRCP< const Scalar > getData() const
Exposes data of FieldContainer, data cannot be modified.
Teuchos::ArrayRCP< Scalar > getData()
Exposes data of FieldContainer, data can be modified.
int dim0_
1st dimension of the array
Definition file for utility class to provide multidimensional containers.
int dim4_
5th dimension of the array
Scalar getValue(const Teuchos::Array< int > &multiIndex) const
Retrieve value by its multi-index. To retrieve it by enumeration use the overloaded []...
void dimensions(Vector &dimensions) const
Returns array with the dimensions of the container.