Intrepid
http://trilinos.sandia.gov/packages/docs/r10.10/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   protected:
00080     
00083     Teuchos::ArrayRCP<Scalar> data_;
00084 
00085     typedef typename Teuchos::ArrayRCP<Scalar>::iterator data_ptr_t;
00086     data_ptr_t data_ptr_;    
00087 
00092     Teuchos::Array<int> dimensions_;
00093     
00095     int dim0_;
00096     
00098     int dim1_;
00099     
00101     int dim2_;
00102     
00104     int dim3_;
00105     
00107     int dim4_;
00108     
00109   public:
00110     
00111 
00114     ~FieldContainer() {};
00115     
00116     
00119     FieldContainer() : dim0_(0), dim1_(0), dim2_(0), dim3_(0), dim4_(0) 
00120     {
00121       data_.resize(0);
00122       data_ptr_ = Teuchos::NullIteratorTraits<data_ptr_t>::getNull();
00123       dimensions_.resize(0);
00124     } ;
00125     
00126     
00129     FieldContainer(const FieldContainer& right);
00130  
00131     
00136     FieldContainer(const int dim0);
00137     
00138     
00144     FieldContainer(const int dim0,
00145                    const int dim1);
00146 
00147     
00154     FieldContainer(const int dim0,
00155                    const int dim1,
00156                    const int dim2);
00157 
00158     
00166     FieldContainer(const int dim0,
00167                    const int dim1,
00168                    const int dim2,
00169                    const int dim3);
00170     
00171     
00180     FieldContainer(const int dim0,
00181                    const int dim1,
00182                    const int dim2,
00183                    const int dim3,
00184                    const int dim4);
00185     
00186     
00193     FieldContainer(const Teuchos::Array<int>& dimensions);
00194     
00195     
00207     FieldContainer(const Teuchos::Array<int>&        dimensions,
00208                    const Teuchos::ArrayView<Scalar>& data);
00209 
00210 
00221     FieldContainer(const Teuchos::Array<int>&       dimensions,
00222                    const Teuchos::ArrayRCP<Scalar>& data);
00223 
00224 
00236     FieldContainer(const Teuchos::Array<int>&    dimensions,
00237                    Scalar*                       data,
00238                    const bool                    deep_copy = false,
00239                    const bool                    owns_mem  = false);
00240 
00241 
00251     FieldContainer(const shards::Array<Scalar,shards::NaturalOrder>&  data,
00252                    const bool                                         deep_copy = false,
00253                    const bool                                         owns_mem  = false);
00254 
00255 
00256 
00257     
00258     //--------------------------------------------------------------------------------------------//
00259     //                                                                                            //
00260     //                            Access methods of FieldContainer class                          //
00261     //                                                                                            //
00262     //--------------------------------------------------------------------------------------------//
00263     
00266     int rank() const;
00267     
00268     
00271     int size() const;
00272     
00273     
00276     template<class Vector>
00277     void dimensions(Vector& dimensions) const;
00278     
00279     
00284     int dimension(const int whichDim) const;
00285 
00286     
00292     int getEnumeration(const int i0) const;
00293     
00294     
00301     int getEnumeration(const int i0,
00302                        const int i1) const;
00303     
00304     
00312     int getEnumeration(const int i0,
00313                        const int i1,
00314                        const int i2) const;
00315  
00316     
00325     int getEnumeration(const int i0,
00326                        const int i1,
00327                        const int i2,
00328                        const int i3) const;
00329     
00330     
00340     int getEnumeration(const int i0,
00341                        const int i1,
00342                        const int i2,
00343                        const int i3,
00344                        const int i4) const;
00345     
00346         
00352     int getEnumeration(const Teuchos::Array<int>& multiIndex) const;
00353     
00354     
00361     void getMultiIndex(int &     i0,
00362                        const int valueEnum) const;
00363     
00364     
00372     void getMultiIndex(int &     i0,
00373                        int &     i1,
00374                        const int valueEnum) const;
00375     
00376     
00385     void getMultiIndex(int &     i0,
00386                        int &     i1,
00387                        int &     i2,
00388                        const int valueEnum) const;
00389     
00390     
00400     void getMultiIndex(int &     i0,
00401                        int &     i1,
00402                        int &     i2,
00403                        int &     i3,
00404                        const int valueEnum) const;
00405     
00406     
00417     void getMultiIndex(int &     i0,
00418                        int &     i1,
00419                        int &     i2,
00420                        int &     i3,
00421                        int &     i4,
00422                        const int valueEnum) const;
00423     
00424     
00435     template<class Vector>
00436     void getMultiIndex(Vector&    multiIndex,
00437                        const int  valueEnum) const;
00438     
00439     //--------------------------------------------------------------------------------------------//
00440     //                                                                                            //
00441     //                          Methods to shape (resize) a field container                       //
00442     //                                                                                            //
00443     //--------------------------------------------------------------------------------------------//
00444     
00445     
00448     void clear();
00449     
00450     
00455     void resize(const int dim0);
00456     
00457     
00463     void resize(const int dim0,
00464                 const int dim1);
00465     
00466     
00473     void resize(const int dim0,
00474                 const int dim1,
00475                 const int dim2);
00476 
00477     
00485     void resize(const int dim0,
00486                 const int dim1,
00487                 const int dim2,
00488                 const int dim3);
00489     
00490     
00499     void resize(const int dim0,
00500                 const int dim1,
00501                 const int dim2,
00502                 const int dim3,
00503                 const int dim4);
00504     
00505     
00511     void resize(const Teuchos::Array<int>& newDimensions);
00512         
00513     
00519     void resize(const FieldContainer<Scalar, ArrayTypeId>& anotherContainer);
00520     
00521     
00560     void resize(const int             numPoints,
00561                 const int             numFields,
00562                 const EFunctionSpace  spaceType,
00563                 const EOperator       operatorType,
00564                 const int             spaceDim);
00565     
00566     //--------------------------------------------------------------------------------------------//
00567     //                                                                                            //
00568     //                     Methods to read and write values to FieldContainer                     //
00569     //                                                                                            //
00570     //--------------------------------------------------------------------------------------------//
00571 
00572     
00575     void initialize(const Scalar value = 0); 
00576         
00577     
00582     Scalar getValue(const Teuchos::Array<int>& multiIndex) const;
00583     
00584     
00590     void setValue(const Scalar               dataValue,
00591                   const Teuchos::Array<int>& multiIndex);
00592     
00593     
00599     void setValue(const Scalar  dataValue,
00600                   const int     order);
00601     
00602     
00608     void setValues(const Teuchos::ArrayView<Scalar>& dataArray);
00609     
00610     
00617     void setValues(const Scalar* dataPtr, 
00618                    const int     numData); 
00619     
00620     
00623     Teuchos::ArrayRCP<Scalar> getData() {
00624       return data_;
00625     }    
00626 
00627 
00630     Teuchos::ArrayRCP<const Scalar> getData() const {
00631       return data_;
00632     }    
00633 
00634 
00639     const Scalar& operator () (const int i0) const;
00640     
00645     Scalar&       operator () (const int i0);
00646     
00647     
00653     const Scalar& operator () (const int i0,
00654                                const int i1) const;
00655     
00661     Scalar&       operator () (const int i0,
00662                                const int i1);
00663     
00664     
00671     const Scalar& operator () (const int i0,
00672                                const int i1,
00673                                const int i2) const;
00674     
00681     Scalar&       operator () (const int i0,
00682                                const int i1,
00683                                const int i2);
00684     
00685     
00693     const Scalar& operator () (const int i0,
00694                                const int i1,
00695                                const int i2,
00696                                const int i3) const;
00697     
00705     Scalar&       operator () (const int i0,
00706                                const int i1,
00707                                const int i2,
00708                                const int i3);
00709     
00710     
00719     const Scalar& operator () (const int i0,
00720                                const int i1,
00721                                const int i2,
00722                                const int i3,
00723                                const int i4) const;
00724     
00733     Scalar&       operator () (const int i0,
00734                                const int i1,
00735                                const int i2,
00736                                const int i3,
00737                                const int i4);
00738     
00739         
00743     const Scalar & operator [] (const int address) const;
00744 
00745     
00749     Scalar &       operator [] (const int address);
00750     
00751     
00754     FieldContainer& operator  = (const FieldContainer& right);
00755     
00756   }; // end class FieldContainer
00757   
00758   
00759   //--------------------------------------------------------------------------------------------//
00760   //                                                                                            //
00761   //                        Function declarations related to FieldContainer                     //
00762   //                                                                                            //
00763   //--------------------------------------------------------------------------------------------//
00764   
00768   template<class Scalar, int ArrayTypeId>
00769     std::ostream& operator << (std::ostream& os, const FieldContainer<Scalar, ArrayTypeId>& container);
00770  
00771   
00772 } // end namespace Intrepid
00773 
00774 // include templated definitions
00775 #include <Intrepid_FieldContainerDef.hpp>
00776 
00777 #endif
00778