44 #include "fei_trilinos_macros.hpp"
46 #include <fei_Factory_Trilinos.hpp>
48 #include <fei_VectorReducer.hpp>
49 #include <fei_MatrixReducer.hpp>
50 #include <fei_Matrix_Local.hpp>
51 #include <fei_Vector_Local.hpp>
53 #ifdef HAVE_FEI_AZTECOO
54 #include <fei_Solver_AztecOO.hpp>
57 #include <fei_Solver_Belos.hpp>
59 #ifdef HAVE_FEI_AMESOS
60 #include <fei_Solver_Amesos.hpp>
63 #ifdef HAVE_FEI_EPETRA
65 Factory_Trilinos::Factory_Trilinos(MPI_Comm comm)
70 use_lpm_epetrabasic_(false),
73 use_feiMatrixLocal_(false),
74 blockEntryMatrix_(false),
75 orderRowsWithLocalColsFirst_(false),
80 Factory_Trilinos::~Factory_Trilinos()
84 int Factory_Trilinos::parameters(
int numParams,
85 const char*
const* paramStrings)
87 std::vector<std::string> stdstrings;
103 bool blkGraph =
false;
104 bool blkMatrix =
false;
109 blockEntryMatrix_ = (blkGraph || blkMatrix);
111 const fei::Param* param = parameterset.
get(
"Trilinos_Solver");
113 if (param->
getType() == fei::Param::STRING) {
115 std::string::size_type ii = strval.find(
"Amesos");
116 if (ii != std::string::npos) {
119 ii = strval.find(
"Belos");
120 if (ii != std::string::npos) {
127 if (use_lpm_epetrabasic_) {
134 orderRowsWithLocalColsFirst_);
143 if (!use_lpm_epetrabasic_) {
162 multiVec->Map().NumMyPoints(),
false));
172 multiVec->Map().NumMyPoints()) {
179 multiVec->Map().NumMyPoints(),
false));
185 bool isSolutionVector,
188 if (use_feiMatrixLocal_) {
197 std::vector<int> indices;
198 int err = 0, localSize;
199 if (reducer_.get() != NULL) {
200 indices = reducer_->getLocalReducedEqns();
201 localSize = indices.size();
204 if (blockEntryMatrix_) {
206 indices.resize(localSize*2);
207 err = vecSpace->
getBlkIndices_Owned(localSize, &indices[0], &indices[localSize], localSize);
211 indices.resize(localSize);
216 throw std::runtime_error(
"error in vecSpace->getIndices_Owned");
220 if (!use_lpm_epetrabasic_) {
223 Trilinos_Helpers::create_Epetra_BlockMap(vecSpace) :
224 Trilinos_Helpers::create_Epetra_Map(comm_, indices);
230 isSolutionVector,
true));
232 catch(std::runtime_error& exc) {
234 << exc.what() <<
"', re-throwing..." << FEI_ENDL;
240 lpm_epetrabasic_.
get(), localSize,
244 if (reducer_.get() != NULL) {
245 feivec.
reset(
new fei::VectorReducer(reducer_,
246 tmpvec, isSolutionVector));
259 bool isSolnVector =
false;
260 return(createVector(vecSpace, isSolnVector, numVectors));
267 bool isSolnVector =
false;
268 return(createVector(matrixGraph, isSolnVector, numVectors));
273 bool isSolutionVector,
276 if (use_feiMatrixLocal_) {
283 if (globalNumSlaves > 0 && reducer_.get()==NULL) {
289 std::vector<int> indices;
290 int err = 0, localSize;
292 if (reducer_.get() != NULL) {
293 indices = reducer_->getLocalReducedEqns();
294 localSize = indices.size();
298 indices.resize(localSize);
302 throw std::runtime_error(
"error in vecSpace->getIndices_Owned");
305 if (!use_lpm_epetrabasic_) {
306 #ifdef HAVE_FEI_EPETRA
309 Trilinos_Helpers::create_Epetra_BlockMap(vecSpace) :
310 Trilinos_Helpers::create_Epetra_Map(comm_, indices);
315 localSize, isSolutionVector,
true));
317 catch(std::runtime_error& exc) {
319 << exc.what() <<
"', re-throwing..." << FEI_ENDL;
323 fei::console_out() <<
"fei_Factory_Trilinos::createVector ERROR, HAVE_FEI_EPETRA not defined."
328 #ifdef HAVE_FEI_EPETRA
331 lpm_epetrabasic_->setRowDistribution(indices);
333 lpm_epetrabasic_.
get(), localSize, isSolutionVector));
337 if (reducer_.get() != NULL) {
338 feivec.
reset(
new fei::VectorReducer(reducer_, tmpvec, isSolutionVector));
351 #ifdef HAVE_FEI_EPETRA
354 if (globalNumSlaves > 0 && reducer_.get()==NULL) {
358 if (use_lpm_epetrabasic_) {
360 Trilinos_Helpers::create_from_LPM_EpetraBasic(matrixGraph,
367 if (use_feiMatrixLocal_) {
368 return(fei::Matrix_Local::create_Matrix_Local(matrixGraph, blockEntryMatrix_));
372 Trilinos_Helpers::create_from_Epetra_Matrix(matrixGraph, blockEntryMatrix_,
373 reducer_, orderRowsWithLocalColsFirst_)
376 fei::console_out() <<
"fei_Factory_Trilinos::createMatrix ERROR, HAVE_FEI_EPETRA "
377 <<
"not defined."<<FEI_ENDL;
383 Factory_Trilinos::createSolver(
const char* name)
387 std::string::size_type ii_amesos = std::string::npos;
388 std::string::size_type ii_belos = std::string::npos;
391 std::string sname(name);
392 ii_amesos = sname.find(
"Amesos");
393 ii_belos = sname.find(
"Belos");
396 if (useAmesos_ || ii_amesos != std::string::npos) {
397 #ifdef HAVE_FEI_AMESOS
398 solver.
reset(
new Solver_Amesos);
401 fei::console_out() <<
"fei_Factory_Trilinos::createSolver: ERROR, Amesos not available (not enabled at compile-time?)"<<FEI_ENDL;
405 if (useBelos_ || ii_belos != std::string::npos) {
406 #ifdef HAVE_FEI_BELOS
407 solver.
reset(
new Solver_Belos);
410 fei::console_out() <<
"fei_Factory_Trilinos::createSolver: ERROR, Belos not available (not enabled at compile-time?)"<<FEI_ENDL;
414 #ifdef HAVE_FEI_AZTECOO
415 solver.
reset(
new Solver_AztecOO);
418 fei::console_out() <<
"fei_Factory_Trilinos::createSolver: ERROR, AztecOO not "
419 <<
"available." << FEI_ENDL;
424 void Factory_Trilinos::create_LinProbMgr(
bool replace_if_already_created)
426 if (!use_lpm_epetrabasic_) {
430 bool need_to_create_lpm =
false;
432 if (lpm_epetrabasic_.get() == NULL) {
433 need_to_create_lpm =
true;
436 if (replace_if_already_created) {
437 need_to_create_lpm =
true;
440 if (need_to_create_lpm) {
441 #ifdef HAVE_FEI_EPETRA
443 newlpm(
new LinProbMgr_EpetraBasic(comm_));
445 lpm_epetrabasic_ = newlpm;
447 fei::console_out() <<
"fei_Factory_Trilinos::create_LinProbMgr ERROR, HAVE_FEI_EPETRA"
448 <<
" not defined."<<FEI_ENDL;
void char_ptrs_to_strings(int numStrings, const char *const *charstrings, std::vector< std::string > &stdstrings)
int getBlkIndices_Owned(int lenBlkIndices, int *globalBlkIndices, int *blkSizes, int &numBlkIndices)
ParamType getType() const
virtual int getGlobalNumSlaveConstraints() const =0
const Param * get(const char *name) const
virtual void parameters(const fei::ParameterSet ¶mset)
virtual fei::SharedPtr< fei::Reducer > getReducer()=0
int getBoolParamValue(const char *name, bool ¶mValue) const
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)
int getIndices_Owned(std::vector< int > &globalIndices) const
std::ostream & console_out()
void parse_strings(std::vector< std::string > &stdstrings, const char *separator_string, fei::ParameterSet ¶mset)
const std::string & getStringValue() const
int getNumBlkIndices_Owned() const
int getNumIndices_Owned() const
int getIntParamValue(const char *name, int ¶mValue) const