FEI Package Browser (Single Doxygen Collection)  Version of the Day
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
fei_Factory_Aztec.cpp
Go to the documentation of this file.
1 /*
2 // @HEADER
3 // ************************************************************************
4 // FEI: Finite Element Interface to Linear Solvers
5 // Copyright (2005) Sandia Corporation.
6 //
7 // Under the terms of Contract DE-AC04-94AL85000 with Sandia Corporation, the
8 // U.S. Government retains certain rights in this software.
9 //
10 // Redistribution and use in source and binary forms, with or without
11 // modification, are permitted provided that the following conditions are
12 // met:
13 //
14 // 1. Redistributions of source code must retain the above copyright
15 // notice, this list of conditions and the following disclaimer.
16 //
17 // 2. Redistributions in binary form must reproduce the above copyright
18 // notice, this list of conditions and the following disclaimer in the
19 // documentation and/or other materials provided with the distribution.
20 //
21 // 3. Neither the name of the Corporation nor the names of the
22 // contributors may be used to endorse or promote products derived from
23 // this software without specific prior written permission.
24 //
25 // THIS SOFTWARE IS PROVIDED BY SANDIA CORPORATION "AS IS" AND ANY
26 // EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
27 // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
28 // PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL SANDIA CORPORATION OR THE
29 // CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
30 // EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
31 // PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
32 // PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
33 // LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
34 // NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
35 // SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
36 //
37 // Questions? Contact Alan Williams (william@sandia.gov)
38 //
39 // ************************************************************************
40 // @HEADER
41 */
42 
43 
44 #include "fei_trilinos_macros.hpp"
45 
46 #include <fei_Factory_Aztec.hpp>
47 
48 #include <fei_VectorReducer.hpp>
49 #include <fei_MatrixReducer.hpp>
50 
52  : fei::Factory(comm),
53  comm_(comm),
54  reducer_(),
55  blockEntryMatrix_(false),
56  outputLevel_(0)
57 {
58 }
59 
61 {
62 }
63 
64 int Factory_Aztec::parameters(int numParams,
65  const char* const* paramStrings)
66 {
67  std::vector<std::string> stdstrings;
68  fei::utils::char_ptrs_to_strings(numParams, paramStrings, stdstrings);
69 
70  fei::ParameterSet paramset;
71  fei::utils::parse_strings(stdstrings, " ", paramset);
72 
73  parameters(paramset);
74  return(0);
75 }
76 
78 {
79  fei::Factory::parameters(parameterset);
80 
81  parameterset.getIntParamValue("outputLevel", outputLevel_);
82 
83  bool blkGraph = false;
84  bool blkMatrix = false;
85 
86  parameterset.getBoolParamValue("BLOCK_GRAPH", blkGraph);
87  parameterset.getBoolParamValue("BLOCK_MATRIX", blkMatrix);
88 
89  blockEntryMatrix_ = (blkGraph || blkMatrix);
90 }
91 
95  const char* name)
96 {
97  static fei::MatrixGraph_Impl2::Factory factory2;
98  return factory2.createMatrixGraph(rowSpace, colSpace, name);
99 }
100 
103  bool isSolutionVector,
104  int numVectors)
105 {
106  std::vector<int> indices;
107  int err = 0, localSize = 0;
108  if (reducer_.get() != NULL) {
109  indices = reducer_->getLocalReducedEqns();
110  localSize = indices.size();
111  }
112  else {
113  if (blockEntryMatrix_) {
114  localSize = vecSpace->getNumBlkIndices_Owned();
115  indices.resize(localSize*2);
116  err = vecSpace->getBlkIndices_Owned(localSize, &indices[0], &indices[localSize], localSize);
117  }
118  else {
119  localSize = vecSpace->getNumIndices_Owned();
120  err = vecSpace->getIndices_Owned(indices);
121  }
122  }
123  if (err != 0) {
124  throw std::runtime_error("fei::Factory_Aztec: error in vecSpace->getIndices_Owned");
125  }
126 
127  fei::SharedPtr<fei::Vector> feivec, tmpvec;
128 
129  if (reducer_.get() != NULL) {
130  feivec.reset(new fei::VectorReducer(reducer_,
131  tmpvec, isSolutionVector));
132  }
133  else {
134  feivec = tmpvec;
135  }
136 
137  return(feivec);
138 }
139 
142  int numVectors)
143 {
144  bool isSolnVector = false;
145  return(createVector(vecSpace, isSolnVector, numVectors));
146 }
147 
150  int numVectors)
151 {
152  bool isSolnVector = false;
153  return(createVector(matrixGraph, isSolnVector, numVectors));
154 }
155 
158  bool isSolutionVector,
159  int numVectors)
160 {
161  int globalNumSlaves = matrixGraph->getGlobalNumSlaveConstraints();
162 
163  if (globalNumSlaves > 0 && reducer_.get()==NULL) {
164  reducer_ = matrixGraph->getReducer();
165  }
166 
167  fei::SharedPtr<fei::Vector> feivec, tmpvec;
168 
169  std::vector<int> indices;
170  int err = 0, localSize;
171  fei::SharedPtr<fei::VectorSpace> vecSpace = matrixGraph->getRowSpace();
172  if (reducer_.get() != NULL) {
173  indices = reducer_->getLocalReducedEqns();
174  localSize = indices.size();
175  }
176  else {
177  localSize = vecSpace->getNumIndices_Owned();
178  indices.resize(localSize);
179  err = vecSpace->getIndices_Owned(indices);
180  }
181  if (err != 0) {
182  throw std::runtime_error("error in vecSpace->getIndices_Owned");
183  }
184 
185  if (reducer_.get() != NULL) {
186  feivec.reset(new fei::VectorReducer(reducer_, tmpvec, isSolutionVector));
187  }
188  else {
189  feivec = tmpvec;
190  }
191 
192  return(feivec);
193 }
194 
197 {
199  int globalNumSlaves = matrixGraph->getGlobalNumSlaveConstraints();
200 
201  if (globalNumSlaves > 0 && reducer_.get()==NULL) {
202  reducer_ = matrixGraph->getReducer();
203  }
204 
205  return feimat;
206 }
207 
210 {
212  return(solver);
213 }
214 
void char_ptrs_to_strings(int numStrings, const char *const *charstrings, std::vector< std::string > &stdstrings)
Definition: fei_utils.cpp:164
int getBlkIndices_Owned(int lenBlkIndices, int *globalBlkIndices, int *blkSizes, int &numBlkIndices)
virtual int getGlobalNumSlaveConstraints() const =0
fei::SharedPtr< fei::Vector > createVector(fei::SharedPtr< fei::VectorSpace > vecSpace, int numVectors=1)
fei::SharedPtr< fei::MatrixGraph > createMatrixGraph(fei::SharedPtr< fei::VectorSpace > rowSpace, fei::SharedPtr< fei::VectorSpace > colSpace, const char *name=NULL)
virtual void parameters(const fei::ParameterSet &paramset)
Definition: fei_Factory.cpp:38
fei::SharedPtr< fei::Reducer > reducer_
virtual fei::SharedPtr< fei::Reducer > getReducer()=0
virtual ~Factory_Aztec()
int getBoolParamValue(const char *name, bool &paramValue) const
Factory_Aztec(MPI_Comm comm)
void reset(T *p=0)
#define MPI_Comm
Definition: fei_mpi.h:56
fei::SharedPtr< fei::Solver > createSolver(const char *name=0)
virtual fei::SharedPtr< fei::VectorSpace > getRowSpace()=0
virtual fei::SharedPtr< fei::MatrixGraph > createMatrixGraph(fei::SharedPtr< fei::VectorSpace > rowSpace, fei::SharedPtr< fei::VectorSpace > columnSpace, const char *name)
T * get() const
int getIndices_Owned(std::vector< int > &globalIndices) const
void parse_strings(std::vector< std::string > &stdstrings, const char *separator_string, fei::ParameterSet &paramset)
Definition: fei_utils.cpp:191
int parameters(int numParams, const char *const *paramStrings)
int getNumBlkIndices_Owned() const
std::vector< int > & getLocalReducedEqns()
fei::SharedPtr< fei::Matrix > createMatrix(fei::SharedPtr< fei::MatrixGraph > matrixGraph)
int getNumIndices_Owned() const
int getIntParamValue(const char *name, int &paramValue) const