Intrepid
http://trilinos.sandia.gov/packages/docs/dev/packages/intrepid/src/Shared/Intrepid_FieldContainer.hpp
Go to the documentation of this file.
00001 // @HEADER
00002 // ************************************************************************
00003 //
00004 //                           Intrepid Package
00005 //                 Copyright (2007) Sandia Corporation
00006 //
00007 // Under terms of Contract DE-AC04-94AL85000, there is a non-exclusive
00008 // license for use of this work by or on behalf of the U.S. Government.
00009 //
00010 // Redistribution and use in source and binary forms, with or without
00011 // modification, are permitted provided that the following conditions are
00012 // met:
00013 //
00014 // 1. Redistributions of source code must retain the above copyright
00015 // notice, this list of conditions and the following disclaimer.
00016 //
00017 // 2. Redistributions in binary form must reproduce the above copyright
00018 // notice, this list of conditions and the following disclaimer in the
00019 // documentation and/or other materials provided with the distribution.
00020 //
00021 // 3. Neither the name of the Corporation nor the names of the
00022 // contributors may be used to endorse or promote products derived from
00023 // this software without specific prior written permission.
00024 //
00025 // THIS SOFTWARE IS PROVIDED BY SANDIA CORPORATION "AS IS" AND ANY
00026 // EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
00027 // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
00028 // PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL SANDIA CORPORATION OR THE
00029 // CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
00030 // EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
00031 // PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
00032 // PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
00033 // LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
00034 // NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
00035 // SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
00036 //
00037 // Questions? Contact Pavel Bochev  (pbboche@sandia.gov)
00038 //                    Denis Ridzal  (dridzal@sandia.gov), or
00039 //                    Kara Peterson (kjpeter@sandia.gov)
00040 //
00041 // ************************************************************************
00042 // @HEADER
00043 
00049 #ifndef INTREPID_FIELDCONTAINER_HPP
00050 #define INTREPID_FIELDCONTAINER_HPP
00051 
00052 #include "Intrepid_ConfigDefs.hpp"
00053 #include "Intrepid_Types.hpp"
00054 #include "Intrepid_Utils.hpp"
00055 #include "Teuchos_Array.hpp"
00056 #include "Teuchos_ArrayRCP.hpp"
00057 #include "Teuchos_ArrayView.hpp"
00058 #include "Shards_Array.hpp"
00059 #include "Teuchos_RCP.hpp"
00060 #include "Teuchos_BLAS.hpp"
00061 #include "Teuchos_oblackholestream.hpp"
00062 #include "Teuchos_Assert.hpp"
00063 
00064 namespace Intrepid {
00065   
00077   template<class Scalar, int ArrayTypeId=0>
00078   class FieldContainer {
00079   public:
00081     typedef Scalar scalar_type;
00082 
00083   protected:
00084     
00087     Teuchos::ArrayRCP<Scalar> data_;
00088 
00089     typedef typename Teuchos::ArrayRCP<Scalar>::iterator data_ptr_t;
00090     data_ptr_t data_ptr_;    
00091 
00096     Teuchos::Array<int> dimensions_;
00097     
00099     int dim0_;
00100     
00102     int dim1_;
00103     
00105     int dim2_;
00106     
00108     int dim3_;
00109     
00111     int dim4_;
00112     
00113   public:
00114     
00115 
00118     ~FieldContainer() {};
00119     
00120     
00123     FieldContainer() : dim0_(0), dim1_(0), dim2_(0), dim3_(0), dim4_(0) 
00124     {
00125       data_.resize(0);
00126       data_ptr_ = Teuchos::NullIteratorTraits<data_ptr_t>::getNull();
00127       dimensions_.resize(0);
00128     } ;
00129     
00130     
00133     FieldContainer(const FieldContainer& right);
00134  
00135     
00140     FieldContainer(const int dim0);
00141     
00142     
00148     FieldContainer(const int dim0,
00149                    const int dim1);
00150 
00151     
00158     FieldContainer(const int dim0,
00159                    const int dim1,
00160                    const int dim2);
00161 
00162     
00170     FieldContainer(const int dim0,
00171                    const int dim1,
00172                    const int dim2,
00173                    const int dim3);
00174     
00175     
00184     FieldContainer(const int dim0,
00185                    const int dim1,
00186                    const int dim2,
00187                    const int dim3,
00188                    const int dim4);
00189     
00190     
00197     FieldContainer(const Teuchos::Array<int>& dimensions);
00198     
00199     
00211     FieldContainer(const Teuchos::Array<int>&        dimensions,
00212                    const Teuchos::ArrayView<Scalar>& data);
00213 
00214 
00225     FieldContainer(const Teuchos::Array<int>&       dimensions,
00226                    const Teuchos::ArrayRCP<Scalar>& data);
00227 
00228 
00240     FieldContainer(const Teuchos::Array<int>&    dimensions,
00241                    Scalar*                       data,
00242                    const bool                    deep_copy = false,
00243                    const bool                    owns_mem  = false);
00244 
00245 
00255     FieldContainer(const shards::Array<Scalar,shards::NaturalOrder>&  data,
00256                    const bool                                         deep_copy = false,
00257                    const bool                                         owns_mem  = false);
00258 
00259 
00260 
00261     
00262     //--------------------------------------------------------------------------------------------//
00263     //                                                                                            //
00264     //                            Access methods of FieldContainer class                          //
00265     //                                                                                            //
00266     //--------------------------------------------------------------------------------------------//
00267     
00270     int rank() const;
00271     
00272     
00275     int size() const;
00276     
00277     
00280     template<class Vector>
00281     void dimensions(Vector& dimensions) const;
00282     
00283     
00288     int dimension(const int whichDim) const;
00289 
00290     
00296     int getEnumeration(const int i0) const;
00297     
00298     
00305     int getEnumeration(const int i0,
00306                        const int i1) const;
00307     
00308     
00316     int getEnumeration(const int i0,
00317                        const int i1,
00318                        const int i2) const;
00319  
00320     
00329     int getEnumeration(const int i0,
00330                        const int i1,
00331                        const int i2,
00332                        const int i3) const;
00333     
00334     
00344     int getEnumeration(const int i0,
00345                        const int i1,
00346                        const int i2,
00347                        const int i3,
00348                        const int i4) const;
00349     
00350         
00356     int getEnumeration(const Teuchos::Array<int>& multiIndex) const;
00357     
00358     
00365     void getMultiIndex(int &     i0,
00366                        const int valueEnum) const;
00367     
00368     
00376     void getMultiIndex(int &     i0,
00377                        int &     i1,
00378                        const int valueEnum) const;
00379     
00380     
00389     void getMultiIndex(int &     i0,
00390                        int &     i1,
00391                        int &     i2,
00392                        const int valueEnum) const;
00393     
00394     
00404     void getMultiIndex(int &     i0,
00405                        int &     i1,
00406                        int &     i2,
00407                        int &     i3,
00408                        const int valueEnum) const;
00409     
00410     
00421     void getMultiIndex(int &     i0,
00422                        int &     i1,
00423                        int &     i2,
00424                        int &     i3,
00425                        int &     i4,
00426                        const int valueEnum) const;
00427     
00428     
00439     template<class Vector>
00440     void getMultiIndex(Vector&    multiIndex,
00441                        const int  valueEnum) const;
00442     
00443     //--------------------------------------------------------------------------------------------//
00444     //                                                                                            //
00445     //                          Methods to shape (resize) a field container                       //
00446     //                                                                                            //
00447     //--------------------------------------------------------------------------------------------//
00448     
00449     
00452     void clear();
00453     
00454     
00459     void resize(const int dim0);
00460     
00461     
00467     void resize(const int dim0,
00468                 const int dim1);
00469     
00470     
00477     void resize(const int dim0,
00478                 const int dim1,
00479                 const int dim2);
00480 
00481     
00489     void resize(const int dim0,
00490                 const int dim1,
00491                 const int dim2,
00492                 const int dim3);
00493     
00494     
00503     void resize(const int dim0,
00504                 const int dim1,
00505                 const int dim2,
00506                 const int dim3,
00507                 const int dim4);
00508     
00509     
00515     void resize(const Teuchos::Array<int>& newDimensions);
00516         
00517     
00523     void resize(const FieldContainer<Scalar, ArrayTypeId>& anotherContainer);
00524     
00525     
00564     void resize(const int             numPoints,
00565                 const int             numFields,
00566                 const EFunctionSpace  spaceType,
00567                 const EOperator       operatorType,
00568                 const int             spaceDim);
00569     
00570     //--------------------------------------------------------------------------------------------//
00571     //                                                                                            //
00572     //                     Methods to read and write values to FieldContainer                     //
00573     //                                                                                            //
00574     //--------------------------------------------------------------------------------------------//
00575 
00576     
00579     void initialize(const Scalar value = 0); 
00580         
00581     
00586     Scalar getValue(const Teuchos::Array<int>& multiIndex) const;
00587     
00588     
00594     void setValue(const Scalar               dataValue,
00595                   const Teuchos::Array<int>& multiIndex);
00596     
00597     
00603     void setValue(const Scalar  dataValue,
00604                   const int     order);
00605     
00606     
00612     void setValues(const Teuchos::ArrayView<Scalar>& dataArray);
00613     
00614     
00621     void setValues(const Scalar* dataPtr, 
00622                    const int     numData); 
00623     
00624     
00627     Teuchos::ArrayRCP<Scalar> getData() {
00628       return data_;
00629     }    
00630 
00631 
00634     Teuchos::ArrayRCP<const Scalar> getData() const {
00635       return data_;
00636     }    
00637 
00638 
00643     const Scalar& operator () (const int i0) const;
00644     
00649     Scalar&       operator () (const int i0);
00650     
00651     
00657     const Scalar& operator () (const int i0,
00658                                const int i1) const;
00659     
00665     Scalar&       operator () (const int i0,
00666                                const int i1);
00667     
00668     
00675     const Scalar& operator () (const int i0,
00676                                const int i1,
00677                                const int i2) const;
00678     
00685     Scalar&       operator () (const int i0,
00686                                const int i1,
00687                                const int i2);
00688     
00689     
00697     const Scalar& operator () (const int i0,
00698                                const int i1,
00699                                const int i2,
00700                                const int i3) const;
00701     
00709     Scalar&       operator () (const int i0,
00710                                const int i1,
00711                                const int i2,
00712                                const int i3);
00713     
00714     
00723     const Scalar& operator () (const int i0,
00724                                const int i1,
00725                                const int i2,
00726                                const int i3,
00727                                const int i4) const;
00728     
00737     Scalar&       operator () (const int i0,
00738                                const int i1,
00739                                const int i2,
00740                                const int i3,
00741                                const int i4);
00742     
00743         
00747     const Scalar & operator [] (const int address) const;
00748 
00749     
00753     Scalar &       operator [] (const int address);
00754     
00755     
00758     FieldContainer& operator  = (const FieldContainer& right);
00759     
00760   }; // end class FieldContainer
00761   
00762   
00763   //--------------------------------------------------------------------------------------------//
00764   //                                                                                            //
00765   //                        Function declarations related to FieldContainer                     //
00766   //                                                                                            //
00767   //--------------------------------------------------------------------------------------------//
00768   
00772   template<class Scalar, int ArrayTypeId>
00773     std::ostream& operator << (std::ostream& os, const FieldContainer<Scalar, ArrayTypeId>& container);
00774  
00775   
00776 } // end namespace Intrepid
00777 
00778 // include templated definitions
00779 #include <Intrepid_FieldContainerDef.hpp>
00780 
00781 #endif
00782