FEI Version of the Day
fei_VectorReducer.hpp
00001 /*
00002 // @HEADER
00003 // ************************************************************************
00004 //             FEI: Finite Element Interface to Linear Solvers
00005 //                  Copyright (2005) Sandia Corporation.
00006 //
00007 // Under the terms of Contract DE-AC04-94AL85000 with Sandia Corporation, the
00008 // U.S. Government retains certain rights in this software.
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 Alan Williams (william@sandia.gov) 
00038 //
00039 // ************************************************************************
00040 // @HEADER
00041 */
00042 
00043 
00044 #ifndef _fei_VectorReducer_hpp_
00045 #define _fei_VectorReducer_hpp_
00046 
00047 #include <fei_iosfwd.hpp>
00048 #include <fei_VectorSpace.hpp>
00049 #include <fei_Reducer.hpp>
00050 #include <fei_Vector.hpp>
00051 
00052 #undef fei_file
00053 #define fei_file "fei_VectorReducer.hpp"
00054 
00055 #include <fei_ErrMacros.hpp>
00056 
00057 namespace fei {
00058 
00059   class VectorReducer : public fei::Vector {
00060   public:
00061 
00063     VectorReducer(fei::SharedPtr<fei::Reducer> reducer,
00064                   fei::SharedPtr<fei::Vector> target,
00065             bool isSolutionVector=false);
00066 
00068     virtual ~VectorReducer();
00069 
00071     fei::SharedPtr<fei::Vector> getTargetVector()
00072       { return(target_); }
00073 
00077     const char* typeName() const { return(target_->typeName()); }
00078 
00081     int update(double a,
00082          const fei::Vector* x,
00083          double b);
00084 
00091     int scatterToOverlap();
00092 
00093     void setCommSizes() { target_->setCommSizes(); }
00094 
00098     int gatherFromOverlap(bool accumulate = true);
00099 
00101     int putScalar(double scalar);
00102 
00106     int sumIn(int numValues, const int* indices, const double* values,
00107         int vectorIndex=0);
00108 
00112     int copyIn(int numValues, const int* indices, const double* values,
00113          int vectorIndex=0);
00114 
00117     fei::SharedPtr<fei::VectorSpace> getVectorSpace() const
00118       { return(target_->getVectorSpace()); }
00119 
00122     void setVectorSpace(fei::SharedPtr<fei::VectorSpace> vecSpace)
00123     { target_->setVectorSpace( vecSpace ); }
00124 
00131     int sumInFieldData(int fieldID,
00132            int idType,
00133            int numIDs,
00134            const int* IDs,
00135            const double* data,
00136            int vectorIndex=0);
00137 
00144     int copyInFieldData(int fieldID,
00145       int idType,
00146       int numIDs,
00147       const int* IDs,
00148       const double* data,
00149       int vectorIndex=0);
00150 
00151     int copyInFieldDataLocalIDs(int fieldID,
00152       int idType,
00153       int numIDs,
00154       const int* localIDs,
00155       const double* data,
00156       int vectorIndex=0);
00157 
00164     int copyOutFieldData(int fieldID,
00165        int idType,
00166        int numIDs,
00167        const int* IDs,
00168        double* data,
00169        int vectorIndex=0);
00170 
00171     int writeToFile(const char* filename,
00172         bool matrixMarketFormat=true);
00173 
00174     int writeToStream(FEI_OSTREAM& ostrm,
00175           bool matrixMarketFormat=true);
00176 
00177     int copyOut(int numValues,
00178     const int* indices,
00179     double* values,
00180     int vectorIndex=0) const;
00181 
00182   private:
00185     int copyOut_FE(int nodeNumber, int dofOffset, double& value);
00186 
00187     int giveToUnderlyingVector(int numValues,
00188              const int* indices,
00189              const double* values,
00190              bool sumInto=true,
00191              int vectorIndex=0);
00192 
00193     int sumIntoFEVector(int blockID,
00194       int connOffset,
00195       int numNodes,
00196       const int* nodeNumbers,
00197       const int* numIndicesPerNode,
00198       const double* values);
00199 
00200     fei::SharedPtr<fei::Reducer> reducer_;
00201     fei::SharedPtr<fei::Vector> target_;
00202     bool isSolution_;
00203 
00204     int localProc_;
00205     int numProcs_;
00206   };//class VectorReducer
00207 
00208 } //namespace fei
00209 
00210 #endif // _fei_VectorReducer_hpp_
00211 
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Friends