FEI  Version of the Day
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
fei_Reducer.hpp
1 /*--------------------------------------------------------------------*/
2 /* Copyright 2006 Sandia Corporation. */
3 /* Under the terms of Contract DE-AC04-94AL85000, there is a */
4 /* non-exclusive license for use of this work by or on behalf */
5 /* of the U.S. Government. Export of this program may require */
6 /* a license from the United States Government. */
7 /*--------------------------------------------------------------------*/
8 
9 #ifndef _fei_Reducer_hpp_
10 #define _fei_Reducer_hpp_
11 
12 #include <fei_macros.hpp>
13 #include <fei_SharedPtr.hpp>
14 #include <fei_mpi.h>
15 #include <fei_Logger.hpp>
16 #include <fei_CSVec.hpp>
17 #include <fei_FillableMat.hpp>
18 #include <fei_CSVec.hpp>
19 #include <fei_CSRMat.hpp>
20 
21 namespace fei {
22  class MatrixGraph;
23  class Graph;
24  class Matrix;
25  class Vector;
26 
27  class Reducer : private fei::Logger {
28  public:
30  Reducer(fei::SharedPtr<FillableMat> globalSlaveDependencyMatrix,
31  fei::SharedPtr<CSVec> g_vector,
32  MPI_Comm comm);
33 
34  Reducer(fei::SharedPtr<fei::MatrixGraph> matrixGraph);
36 
38 
40  virtual ~Reducer();
41 
43  void setLocalUnreducedEqns(const std::vector<int>& localUnreducedEqns);
44 
45 
49  void addGraphEntries(fei::SharedPtr<fei::SparseRowGraph> matrixGraph);
50 
51  void addGraphIndices(int numRows, const int* rows,
52  int numCols, const int* cols,
53  fei::Graph& graph);
54 
55  void addSymmetricGraphIndices(int numIndices, const int* indices,
56  bool diagonal,
57  fei::Graph& graph);
58 
66  int addMatrixValues(int numRows, const int* rows,
67  int numCols, const int* cols,
68  const double* const* values,
69  bool sum_into,
70  fei::Matrix& feimat,
71  int format);
72 
98  int addVectorValues(int numValues,
99  const int* globalIndices,
100  const double* values,
101  bool sum_into,
102  bool soln_vector,
103  int vectorIndex,
104  fei::Vector& feivec);
105 
106  int copyOutVectorValues(int numValues,
107  const int* globalIndices,
108  double* values,
109  bool soln_vector,
110  int vectorIndex,
111  fei::Vector& feivec);
112 
113  void getSlaveMasterEqns(int slaveEqn, std::vector<int>& masterEqns);
114  bool isSlaveEqn(int unreducedEqn) const;
115  bool isSlaveCol(int unreducedEqn) const;
116 
121  int translateToReducedEqn(int unreducedEqn) const;
122  int translateFromReducedEqn(int reduced_eqn) const;
123  void assembleReducedGraph(fei::Graph* graph,
124  bool global_gather=true);
125  void assembleReducedGraph(fei::SparseRowGraph* srgraph);
126  void assembleReducedMatrix(fei::Matrix& matrix);
127  void assembleReducedVector(bool soln_vector,
128  fei::Vector& feivec);
129 
130  std::vector<int>& getLocalReducedEqns();
131 
132  void initialize();
133  private:
134  void expand_work_arrays(int size);
135 
136  fei::CSRMat csrD_;
137  int* slavesPtr_;
138  fei::FillableMat Kii_, Kid_, Kdi_, Kdd_;
139  fei::CSRMat csrKii, csrKid, csrKdi, csrKdd;
140  fei::CSVec fi_, fd_;
141  fei::CSVec csvec, csvec_i;
142  fei::CSRMat tmpMat1_, tmpMat2_;
143  fei::CSVec tmpVec1_, tmpVec2_;
144 
145  fei::CSVec csg_;
146  bool g_nonzero_;
147 
148  std::vector<int> localUnreducedEqns_;
149  std::vector<int> localReducedEqns_;
150  std::vector<int> nonslaves_;
151  std::vector<int> reverse_;
152  bool* isSlaveEqn_;
153  int numGlobalSlaves_;
154  int numLocalSlaves_;
155  int firstLocalReducedEqn_;
156  int lastLocalReducedEqn_;
157  int lowestGlobalSlaveEqn_;
158  int highestGlobalSlaveEqn_;
159 
160  int localProc_;
161  int numProcs_;
162  MPI_Comm comm_;
163  std::string dbgprefix_;
164  unsigned mat_counter_;
165  unsigned rhs_vec_counter_;
166 
167  bool* bool_array_;
168  int* int_array_;
169  double* double_array_;
170  int array_len_;
171 
172  std::vector<double> work_1D_;
173  std::vector<const double*> work_2D_;
174  };//class Reducer
175 
176 }//namespace fei
177 
178 #endif // _fei_Reducer_hpp_
179