FEI  Version of the Day
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
snl_fei_Factory.cpp
1 /*--------------------------------------------------------------------*/
2 /* Copyright 2005 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 #ifndef _snl_fei_Factory_cpp_
9 #define _snl_fei_Factory_cpp_
10 
11 #include <fei_macros.hpp>
12 
13 #include <snl_fei_Factory.hpp>
14 
15 //----------------------------------------------------------------------------
18  : fei::Factory(comm),
19  comm_(comm),
20  broker_(),
21  matrixGraph_(),
22  nodeIDType_(0),
23  lsc_(),
24  feData_(),
25  wrapper_(wrapper),
26  outputLevel_(0),
27  blockMatrix_(false)
28 {
29  if (wrapper_.get() != NULL) {
30  lsc_ = wrapper->getLinearSystemCore();
31  feData_ = wrapper->getFiniteElementData();
32  }
33 }
34 
35 //----------------------------------------------------------------------------
38  : fei::Factory(comm),
39  comm_(comm),
40  broker_(),
41  matrixGraph_(),
42  nodeIDType_(0),
43  lsc_(lsc),
44  feData_(),
45  wrapper_(),
46  outputLevel_(0),
47  blockMatrix_(false)
48 {
49 }
50 
51 //----------------------------------------------------------------------------
53  fei::SharedPtr<FiniteElementData> feData, int nodeIDType)
54  : fei::Factory(comm),
55  comm_(comm),
56  broker_(),
57  matrixGraph_(),
58  nodeIDType_(nodeIDType),
59  lsc_(),
60  feData_(feData),
61  wrapper_(NULL),
62  outputLevel_(0),
63  blockMatrix_(false)
64 {
65 }
66 
67 //----------------------------------------------------------------------------
69 {
70 }
71 
72 //----------------------------------------------------------------------------
75 {
77  if (wrapper_.get() != NULL) {
78  factory.reset(new snl_fei::Factory(comm_, wrapper_));
79  }
80  else if (lsc_.get() != NULL) {
81  factory.reset(new snl_fei::Factory(comm_, lsc_));
82  }
83  else if (feData_.get() != NULL) {
84  factory.reset(new snl_fei::Factory(comm_, feData_, nodeIDType_));
85  }
86 
87  return(factory);
88 }
89 
90 //----------------------------------------------------------------------------
91 void
93 {
94  fei::Factory::parameters(parameterset);
95 
96  int err = 0;
97  if (lsc_.get() != NULL || feData_.get() != NULL) {
98  int numParams = 0;
99  const char** paramStrings = NULL;
100  std::vector<std::string> stdstrings;
101  fei::utils::convert_ParameterSet_to_strings(&parameterset, stdstrings);
102  fei::utils::strings_to_char_ptrs(stdstrings, numParams, paramStrings);
103  char** nc_paramStrings = const_cast<char**>(paramStrings);
104  if (lsc_.get() != NULL) {
105  err += lsc_->parameters(numParams, nc_paramStrings);
106  }
107  if (feData_.get() != NULL) {
108  err += feData_->parameters(numParams, nc_paramStrings);
109  }
110 
111  delete [] paramStrings;
112 
113  if (err != 0) {
114  FEI_OSTRINGSTREAM osstr;
115  osstr << "snl_fei::Factory::parameters received err="<<err
116  << " from either feiData_->parameters or lsc_->parameters.";
117  throw std::runtime_error(osstr.str());
118  }
119  }
120 
121  parameterset.getIntParamValue("outputLevel", outputLevel_);
122 
123  const fei::Param* param = 0;
124  fei::Param::ParamType ptype = fei::Param::BAD_TYPE;
125 
126  param = parameterset.get("BLOCK_GRAPH");
127  ptype = param != NULL ? param->getType() : fei::Param::BAD_TYPE;
128  if (ptype != fei::Param::BAD_TYPE) {
129  blockMatrix_ = true;
130  }
131 
132  param = parameterset.get("BLOCK_MATRIX");
133  ptype = param != NULL ? param->getType() : fei::Param::BAD_TYPE;
134  if (ptype != fei::Param::BAD_TYPE) {
135  if (ptype == fei::Param::BOOL) {
136  blockMatrix_ = param->getBoolValue();
137  }
138  else {
139  blockMatrix_ = true;
140  }
141  }
142 
143  param = parameterset.get("AZ_matrix_type");
144  ptype = param != NULL ? param->getType() : fei::Param::BAD_TYPE;
145  if (ptype != fei::Param::BAD_TYPE) {
146  if (ptype == fei::Param::STRING) {
147  if (param->getStringValue() == "AZ_VBR_MATRIX") {
148  blockMatrix_ = true;
149  }
150  }
151  }
152 }
153 
154 //----------------------------------------------------------------------------
158  const char* name)
159 {
160  static fei::MatrixGraph_Impl2::Factory factory;
161  matrixGraph_ = factory.createMatrixGraph(rowSpace, columnSpace, name);
162  return(matrixGraph_);
163 }
164 
165 //----------------------------------------------------------------------------
168  int numVectors)
169 {
170  (void)vecSpace;
172  if (matrixGraph_.get() == NULL) {
173  fei::console_out() << "snl_fei::Factory ERROR: when using LinearSystemCore or FiniteElementData"
174  << ", you must create a MatrixGraph before you can create vectors"<<FEI_ENDL;
175  return(dummy);
176  }
177 
178  if (matrixGraph_->getGlobalNumSlaveConstraints() > 0 &&
179  reducer_.get() == NULL) {
180  reducer_ = matrixGraph_->getReducer();
181  }
182 
183  createBroker(matrixGraph_);
184 
185  return( broker_->createVector() );
186 }
187 
188 //----------------------------------------------------------------------------
191  bool isSolutionVector,
192  int numVectors)
193 {
195  (void)vecSpace;
196  if (matrixGraph_.get() == NULL) {
197  fei::console_out() << "snl_fei::Factory ERROR: when using LinearSystemCore"
198  << ", you must create a MatrixGraph before you can create vectors"<<FEI_ENDL;
199  return(dummy);
200  }
201 
202  if (matrixGraph_->getGlobalNumSlaveConstraints() > 0 &&
203  reducer_.get() == NULL) {
204  reducer_ = matrixGraph_->getReducer();
205  }
206 
207  createBroker(matrixGraph_);
208 
209  return( broker_->createVector(isSolutionVector) );
210 }
211 
212 //----------------------------------------------------------------------------
215  int numVectors)
216 {
217  matrixGraph_ = matrixGraph;
218 
219  if (matrixGraph_->getGlobalNumSlaveConstraints() > 0 &&
220  reducer_.get() == NULL) {
221  reducer_ = matrixGraph_->getReducer();
222  }
223 
224  createBroker(matrixGraph_);
225 
226  return( broker_->createVector() );
227 }
228 
229 //----------------------------------------------------------------------------
232  bool isSolutionVector,
233  int numVectors)
234 {
235  matrixGraph_ = matrixGraph;
236 
237  if (matrixGraph_->getGlobalNumSlaveConstraints() > 0 &&
238  reducer_.get() == NULL) {
239  reducer_ = matrixGraph_->getReducer();
240  }
241 
242  createBroker(matrixGraph_);
243 
244  return( broker_->createVector(isSolutionVector) );
245 }
246 
247 //----------------------------------------------------------------------------
250 {
251  matrixGraph_ = matrixGraph;
253 
254  if (matrixGraph_.get() == NULL) {
255  fei::console_out() << "snl_fei::Factory ERROR: when using LinearSystemCore"
256  << ", you must create a MatrixGraph before you can create matrices"<<FEI_ENDL;
257  return(mptr);
258  }
259 
260  if (matrixGraph_->getGlobalNumSlaveConstraints() > 0 &&
261  reducer_.get() == NULL) {
262  reducer_ = matrixGraph_->getReducer();
263  }
264 
265  createBroker(matrixGraph_);
266 
267  broker_->setMatrixGraph(matrixGraph);
268 
269  return(broker_->createMatrix());
270 }
271 
272 //----------------------------------------------------------------------------
275 {
276  matrixGraph_ = matrixGraph;
277 
278  if (matrixGraph_.get() == NULL) {
279  fei::console_out() << "snl_fei::Factory ERROR: you may not create a LinearSystem with "
280  << "a NULL MatrixGraph object." << FEI_ENDL;
282  return(linsys);
283  }
284 
285  if (matrixGraph_->getGlobalNumSlaveConstraints() > 0 &&
286  reducer_.get() == NULL) {
287  reducer_ = matrixGraph_->getReducer();
288  }
289 
290  createBroker(matrixGraph_);
291 
292  broker_->setMatrixGraph(matrixGraph);
293 
294  return( broker_->createLinearSystem() );
295 }
296 
297 //----------------------------------------------------------------------------
300 {
302  return(solver);
303 }
304 
305 //----------------------------------------------------------------------------
308 {
309  return( wrapper_ );
310 }
311 
312 //----------------------------------------------------------------------------
314 {
315  return(outputLevel_);
316 }
317 
318 //----------------------------------------------------------------------------
319 int
320 snl_fei::Factory::createBroker(fei::SharedPtr<fei::MatrixGraph> matrixGraph)
321 {
322  int err = -1;
323  if (lsc_.get() != NULL) {
324  err = createBroker_LinSysCore(matrixGraph, lsc_);
325  }
326  if (feData_.get() != NULL) {
327  err = createBroker_FEData(matrixGraph, feData_);
328  }
329 
330  return(err);
331 }
332 
333 //----------------------------------------------------------------------------
334 int
335 snl_fei::Factory::createBroker_LinSysCore(fei::SharedPtr<fei::MatrixGraph> matrixGraph,
337 {
338  if (broker_.get() == NULL) {
339  fei::SharedPtr<snl_fei::Broker> brokerptr(new snl_fei::Broker_LinSysCore(lsc, matrixGraph, reducer_, blockMatrix_));
340  broker_ = brokerptr;
341  }
342 
343  return(0);
344 }
345 
346 //----------------------------------------------------------------------------
347 int
348 snl_fei::Factory::createBroker_FEData(fei::SharedPtr<fei::MatrixGraph> matrixGraph,
350 {
351  if (broker_.get() == NULL) {
353  brokerptr(new snl_fei::Broker_FEData(feData, matrixGraph,
354  nodeIDType_));
355  broker_ = brokerptr;
356  }
357 
358  return(0);
359 }
360 
361 
362 #endif
363 
void strings_to_char_ptrs(std::vector< std::string > &stdstrings, int &numStrings, const char **&charPtrs)
Definition: fei_utils.cpp:178
ParamType getType() const
Definition: fei_Param.hpp:98
const Param * get(const char *name) const
void convert_ParameterSet_to_strings(const fei::ParameterSet *paramset, std::vector< std::string > &paramStrings)
Definition: fei_utils.cpp:270
virtual void parameters(const fei::ParameterSet &paramset)
Definition: fei_Factory.cpp:38
Factory(MPI_Comm comm, fei::SharedPtr< LibraryWrapper > wrapper)
bool getBoolValue() const
Definition: fei_Param.hpp:122
virtual fei::SharedPtr< fei::Reducer > getReducer()=0
virtual fei::SharedPtr< fei::MatrixGraph > createMatrixGraph(fei::SharedPtr< fei::VectorSpace > rowSpace, fei::SharedPtr< fei::VectorSpace > columnSpace, const char *name)
fei::SharedPtr< LibraryWrapper > get_LibraryWrapper() const
fei::SharedPtr< fei::Factory > clone() const
void reset(T *p=0)
virtual fei::SharedPtr< fei::LinearSystem > createLinearSystem(fei::SharedPtr< fei::MatrixGraph > &matrixGraph)
virtual fei::SharedPtr< fei::MatrixGraph > createMatrixGraph(fei::SharedPtr< fei::VectorSpace > rowSpace, fei::SharedPtr< fei::VectorSpace > columnSpace, const char *name)
T * get() const
std::ostream & console_out()
const std::string & getStringValue() const
Definition: fei_Param.hpp:104
virtual void parameters(const fei::ParameterSet &parameterset)
int getOutputLevel() const
virtual fei::SharedPtr< fei::Matrix > createMatrix(fei::SharedPtr< fei::MatrixGraph > matrixGraph)
virtual fei::SharedPtr< fei::Solver > createSolver(const char *name=0)
virtual fei::SharedPtr< fei::Vector > createVector(fei::SharedPtr< fei::VectorSpace > vecSpace, int numVectors=1)
int getIntParamValue(const char *name, int &paramValue) const