FEI Version of the Day
fei_Reducer.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_Reducer_hpp_
00045 #define _fei_Reducer_hpp_
00046 
00047 #include <fei_macros.hpp>
00048 #include <fei_SharedPtr.hpp>
00049 #include <fei_mpi.h>
00050 #include <fei_Logger.hpp>
00051 #include <fei_FillableVec.hpp>
00052 #include <fei_FillableMat.hpp>
00053 #include <fei_CSVec.hpp>
00054 #include <fei_CSRMat.hpp>
00055 
00056 namespace fei {
00057   class MatrixGraph;
00058   class Graph;
00059   class Matrix;
00060   class Vector;
00061 
00062   class Reducer : private fei::Logger {
00063    public:
00065     Reducer(fei::SharedPtr<FillableMat> globalSlaveDependencyMatrix,
00066             fei::SharedPtr<CSVec> g_vector,
00067             MPI_Comm comm);
00068 
00069     Reducer(fei::SharedPtr<fei::MatrixGraph> matrixGraph);
00071 
00073 
00075     virtual ~Reducer();
00076 
00078     void setLocalUnreducedEqns(const std::vector<int>& localUnreducedEqns);
00079 
00080     
00084     void addGraphEntries(fei::SharedPtr<fei::SparseRowGraph> matrixGraph);
00085 
00086     void addGraphIndices(int numRows, const int* rows,
00087                          int numCols, const int* cols,
00088                          fei::Graph& graph);
00089 
00090     void addSymmetricGraphIndices(int numIndices, const int* indices,
00091                                   bool diagonal,
00092                                   fei::Graph& graph);
00093 
00101     int addMatrixValues(int numRows, const int* rows,
00102                         int numCols, const int* cols,
00103                         const double* const* values,
00104                         bool sum_into,
00105                         fei::Matrix& feimat,
00106                         int format);
00107 
00133     int addVectorValues(int numValues,
00134                         const int* globalIndices,
00135                         const double* values,
00136                         bool sum_into,
00137                         bool soln_vector,
00138                         int vectorIndex,
00139                         fei::Vector& feivec);
00140 
00141     int copyOutVectorValues(int numValues,
00142                              const int* globalIndices,
00143                              double* values,
00144                              bool soln_vector,
00145                              int vectorIndex,
00146                              fei::Vector& feivec);
00147 
00148     void getSlaveMasterEqns(int slaveEqn, std::vector<int>& masterEqns);
00149     bool isSlaveEqn(int unreducedEqn) const;
00150     bool isSlaveCol(int unreducedEqn) const;
00151 
00156     int translateToReducedEqn(int unreducedEqn) const;
00157     int translateFromReducedEqn(int reduced_eqn) const;
00158     void assembleReducedGraph(fei::Graph* graph,
00159                               bool global_gather=true);
00160     void assembleReducedGraph(fei::SparseRowGraph* srgraph);
00161     void assembleReducedMatrix(fei::Matrix& matrix);
00162     void assembleReducedVector(bool soln_vector,
00163                                fei::Vector& feivec);
00164 
00165     std::vector<int>& getLocalReducedEqns();
00166 
00167     void initialize();
00168    private:
00169     void expand_work_arrays(int size);
00170 
00171     fei::CSRMat csrD_;
00172     int* slavesPtr_;
00173     fei::FillableMat Kii_, Kid_, Kdi_, Kdd_;
00174     fei::CSRMat csrKii, csrKid, csrKdi, csrKdd;
00175     fei::FillableVec fi_, fd_;
00176     fei::CSVec csfi, csvec, csvec_i;
00177     fei::CSRMat tmpMat1_, tmpMat2_;
00178     fei::CSVec tmpVec1_, tmpVec2_;
00179 
00180     fei::CSVec csg_;
00181     bool g_nonzero_;
00182 
00183     std::vector<int> localUnreducedEqns_;
00184     std::vector<int> localReducedEqns_;
00185     std::vector<int> nonslaves_;
00186     std::vector<int> reverse_;
00187     bool* isSlaveEqn_;
00188     int numGlobalSlaves_;
00189     int numLocalSlaves_;
00190     int firstLocalReducedEqn_;
00191     int lastLocalReducedEqn_;
00192     int lowestGlobalSlaveEqn_;
00193     int highestGlobalSlaveEqn_;
00194 
00195     int localProc_;
00196     int numProcs_;
00197     MPI_Comm comm_;
00198     std::string dbgprefix_;
00199     unsigned mat_counter_;
00200     unsigned rhs_vec_counter_;
00201 
00202     bool* bool_array_;
00203     int* int_array_;
00204     double* double_array_;
00205     int array_len_;
00206 
00207     std::vector<double> work_1D_;
00208     std::vector<const double*> work_2D_;
00209   };//class Reducer
00210 
00211 }//namespace fei
00212 
00213 #endif // _fei_Reducer_hpp_
00214 
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Friends