26 #include "Amesos_ConfigDefs.h"
32 template<
typename Scalar> Amesos AmesosSolver<Scalar>::factory;
34 template<
typename Scalar>
35 AmesosSolver<Scalar>::AmesosSolver(
const char *solver_type, EpetraMatrix<Scalar> *m, EpetraVector<Scalar> *rhs)
38 solver = factory.Create(solver_type, problem);
39 assert(solver != NULL);
46 template<
typename Scalar>
47 AmesosSolver<Scalar>::~AmesosSolver()
52 template<
typename Scalar>
53 bool AmesosSolver<Scalar>::is_available(
const char *name)
55 return factory.Query(name);
58 template<
typename Scalar>
59 void AmesosSolver<Scalar>::set_use_transpose(
bool use_transpose)
61 solver->SetUseTranspose(use_transpose);
64 template<
typename Scalar>
65 bool AmesosSolver<Scalar>::use_transpose()
67 return solver->UseTranspose();
70 template<
typename Scalar>
71 int AmesosSolver<Scalar>::get_matrix_size()
77 bool AmesosSolver<double>::solve()
82 assert(m->size == rhs->size);
84 problem.SetOperator(m->mat);
85 problem.SetRHS(rhs->vec);
86 Epetra_Vector x(*rhs->std_map);
89 if(!setup_factorization())
91 this->warn(
"AmesosSolver: LU factorization could not be completed");
95 int status = solver->Solve();
103 this->time = this->accumulated();
106 this->sln =
new double[m->size];
108 memset(this->sln, 0, m->size *
sizeof(
double));
110 for (
unsigned int i = 0; i < m->size; i++) this->sln[i] = x[i];
116 bool AmesosSolver<std::complex<double> >::solve()
121 assert(m->size == rhs->size);
125 if(!setup_factorization())
127 this->warn(
"AmesosSolver: LU factorization could not be completed");
131 int status = solver->Solve();
139 this->time = this->accumulated();
142 this->sln =
new std::complex<double>[m->size];
144 memset(this->sln, 0, m->size *
sizeof(std::complex<double>));
149 template<
typename Scalar>
150 bool AmesosSolver<Scalar>::setup_factorization()
154 if(this->factorization_scheme != HERMES_FACTORIZE_FROM_SCRATCH &&
155 solver->NumSymbolicFact() == 0 && solver->NumNumericFact() == 0)
156 eff_fact_scheme = HERMES_FACTORIZE_FROM_SCRATCH;
158 eff_fact_scheme = this->factorization_scheme;
161 switch(eff_fact_scheme)
165 status = solver->SymbolicFactorization();
168 this->warn(
"Symbolic factorization failed.");
174 status = solver->NumericFactorization();
177 this->warn(
"Numeric factorization failed.");
185 template class HERMES_API AmesosSolver<double>;
186 template class HERMES_API AmesosSolver<std::complex<double> >;