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
48
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
64namespace 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
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/*
779template<class FadType, class Scalar>
780struct Return_Type< Intrepid::FieldContainer<FadType>, Scalar>{
781 typedef FadType& return_type;
782 typedef FadType const_return_type;
783};
784
785template<class FadType, class Scalar>
786struct 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
914
915
916
917
918
919
920
921
922#if defined(Intrepid_SHOW_DEPRECATED_WARNINGS)
923#ifdef __GNUC__
924#warning "The Intrepid package is deprecated"
925#endif
926#endif
927
Definition file for utility class to provide multidimensional containers.
Contains definitions of custom data types in Intrepid.
Intrepid utilities.
FieldContainer()
Default constructor.
Implementation of a templated lexicographical container for a multi-indexed scalar quantity....
void setValues(const Scalar *dataPtr, const int numData)
Fills an existing FieldContainer with Scalars referenced by dataPtr without changing rank and dimensi...
int size() const
Returns size of the FieldContainer defined as the product of its dimensions.
const Scalar & operator()(const int i0) const
Overloaded () operators for rank-1 containers. Data cannot be modified.
void dimensions(Vector &dimensions) const
void resize(const int dim0, const int dim1, const int dim2, const int dim3)
Resizes FieldContainer to a rank-4 container with specified dimensions, initialized by 0.
void resize(const Teuchos::Array< int > &newDimensions)
Resizes FieldContainer to arbitrary rank container, initialized by 0, with dimensions specified in th...
void resize(const int dim0, const int dim1, const int dim2)
Resizes FieldContainer to a rank-3 container with specified dimensions, initialized by 0.
Teuchos::ArrayRCP< Scalar > getData()
Exposes data of FieldContainer, data can be modified.
FieldContainer(const int dim0)
Creates a rank-1 FieldContainer with the specified dimension, initialized by 0.
void resize(const FieldContainer< Scalar, ArrayTypeId > &anotherContainer)
Resizes FieldContainer to have the same rank and dimensions as another FieldContainer,...
int getEnumeration(const int i0, const int i1, const int i2, const int i3, const int i4) const
Returns enumeration of a value (its order relative to the container), based on its multi-index,...
void resize(const int dim0)
Resizes FieldContainer to a rank-1 container with the specified dimension, initialized by 0.
void getMultiIndex(int &i0, int &i1, int &i2, int &i3, int &i4, const int valueEnum) const
Returns the multi-index of a value, based on its enumeration, as a list, for rank-5 containers.
int getEnumeration(const int i0, const int i1, const int i2, const int i3) const
Returns enumeration of a value (its order relative to the container), based on its multi-index,...
FieldContainer(const int dim0, const int dim1, const int dim2, const int dim3)
Creates a rank-4 FieldContainer with the specified dimensions, initialized by 0.
void resize(const int dim0, const int dim1)
Resizes FieldContainer to a rank-2 container with specified dimensions, initialized by 0.
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.
void resize(const int numPoints, const int numFields, const EFunctionSpace spaceType, const EOperator operatorType, const int spaceDim)
Resizes FieldContainer to a container whose rank depends on the specified field and operator types an...
FieldContainer(const int dim0, const int dim1, const int dim2)
Creates a rank-3 FieldContainer with the specified dimensions, initialized by 0.
void clear()
Clears FieldContainer to trivial container (one with rank = 0 and size = 0).
void getMultiIndex(int &i0, int &i1, int &i2, int &i3, const int valueEnum) const
Returns the multi-index of a value, based on its enumeration, as a list, for rank-4 containers.
void setValue(const Scalar dataValue, const Teuchos::Array< int > &multiIndex)
Assign value by its multi-index.
void getMultiIndex(Vector &multiIndex, const int valueEnum) const
Returns the multi-index of a value, based on its enumeration, as a vector, for containers of arbitrar...
FieldContainer(const shards::Array< Scalar, shards::NaturalOrder > &data, const bool deep_copy=false, const bool owns_mem=false)
Creates a FieldContainer either as a wrapper of the shards::Array<Scalar,shards::NaturalOrder> array ...
void resize(const int dim0, const int dim1, const int dim2, const int dim3, const int dim4)
Resizes FieldContainer to a rank-5 container with specified dimensions, initialized by 0.
int getEnumeration(const int i0) const
Returns enumeration of a value (its order relative to the container), based on its multi-index,...
FieldContainer(const Teuchos::Array< int > &dimensions, const Teuchos::ArrayRCP< Scalar > &data)
Creates a FieldContainer of arbitrary rank, using dimensions specified in the dimensions array,...
int rank() const
Return rank of the FieldContainer = number of indices used to tag the multi-indexed value.
Teuchos::ArrayRCP< const Scalar > getData() const
Exposes data of FieldContainer, data cannot be modified.
FieldContainer & operator=(const FieldContainer &right)
Assignment operator *this = right.
int getEnumeration(const Teuchos::Array< int > &multiIndex) const
Returns enumeration of a value (its order relative to the container), based on its multi-index,...
FieldContainer(const Teuchos::Array< int > &dimensions)
Creates a FieldContainer of arbitrary rank,, initialized by 0, using dimensions specified in an array...
void getMultiIndex(int &i0, int &i1, const int valueEnum) const
Returns the multi-index of a value, based on its enumeration, as a list, for rank-2 containers.
const Scalar & operator[](const int address) const
Overloaded [] operator. Returns value based on its enumeration. Data cannot be modified.
void setValues(const Teuchos::ArrayView< Scalar > &dataArray)
Fills an existing FieldContainer with Scalars stored in a Teuchos::Array without changing rank and di...
void getMultiIndex(int &i0, int &i1, int &i2, const int valueEnum) const
Returns the multi-index of a value, based on its enumeration, as a list, for rank-3 containers.
void initialize(const Scalar value=0)
Initializes a field container by assigning value to all its elements.
FieldContainer(const int dim0, const int dim1)
Creates a rank-2 FieldContainer with the specified dimensions, initialized by 0.
FieldContainer(const FieldContainer &right)
Copy constructor.
int dimension(const int whichDim) const
Returns the specified dimension.
int getEnumeration(const int i0, const int i1, const int i2) const
Returns enumeration of a value (its order relative to the container), based on its multi-index,...
FieldContainer(const Teuchos::Array< int > &dimensions, const Teuchos::ArrayView< Scalar > &data)
Creates a FieldContainer of arbitrary rank, using dimensions specified in the dimensions array,...
void setValue(const Scalar dataValue, const int order)
Assign value by its enumeration (order relative to the FieldContainer).
Scalar scalar_type
The template parameter of this class; the type of objects stored.
int getEnumeration(const int i0, const int i1) const
Returns enumeration of a value (its order relative to the container), based on its multi-index,...
FieldContainer(const int dim0, const int dim1, const int dim2, const int dim3, const int dim4)
Creates a rank-5 FieldContainer with the specified dimensions, initialized by 0.
Scalar getValue(const Teuchos::Array< int > &multiIndex) const
Retrieve value by its multi-index. To retrieve it by enumeration use the overloaded [].
FieldContainer(const Teuchos::Array< int > &dimensions, Scalar *data, const bool deep_copy=false, const bool owns_mem=false)
Creates a FieldContainer of arbitrary rank, using dimensions specified in the dimensions array,...