25 #ifdef HAVE_TEUCHOS_COMPLEX
26 #define STYPE std::complex<double>
33 #ifdef HAVE_TEUCHOS_COMPLEX
34 #define SCALARMAX STYPE(10,0)
36 #define SCALARMAX STYPE(10)
39 template<
typename TYPE>
49 template<
typename TYPE>
61 std::complex<T>
GetRandom( std::complex<T>, std::complex<T> );
79 int main(
int argc,
char* argv[])
89 if (argc>1)
if (argv[1][0]==
'-' && argv[1][1]==
'v') verbose =
true;
94 int numberFailedTests = 0;
96 std::string testName =
"", testType =
"";
98 #ifdef HAVE_TEUCHOS_COMPLEX
104 if (verbose) std::cout<<std::endl<<
"********** CHECKING TEUCHOS SERIAL BAND DENSE SOLVER - " << testType <<
"-VALUED **********"<<std::endl<<std::endl;
118 AB1 = Teuchos::generalToBanded( A1, kl, ku,
true );
121 C1 = Teuchos::bandedToGeneral( AB1 );
122 testName =
"Converting matrix formats: generalToBanded and bandedToGeneral random A:";
124 numberFailedTests +=
ReturnCodeCheck(testName, returnCode, 0, verbose);
128 testName =
"Generating right-hand side vector using A*x, where x is a random vector:";
129 numberFailedTests +=
ReturnCodeCheck(testName, returnCode, 0, verbose);
131 testName =
"Generating right-hand side vector using A^T*x, where x is a random vector:";
132 numberFailedTests +=
ReturnCodeCheck(testName, returnCode, 0, verbose);
134 #ifdef HAVE_TEUCHOS_COMPLEX
137 testName =
"Generating right-hand side vector using A^H*x, where x is a random vector:";
138 numberFailedTests +=
ReturnCodeCheck(testName, returnCode, 0, verbose);
149 returnCode = solver1.
factor();
150 testName =
"Simple solve: factor() random A:";
151 numberFailedTests +=
ReturnCodeCheck(testName, returnCode, 0, verbose);
154 returnCode = solver1.
solve();
155 testName =
"Simple solve: solve() random A (NO_TRANS):";
157 numberFailedTests +=
ReturnCodeCheck(testName, returnCode, 0, verbose);
163 returnCode = solver1.
solve();
164 testName =
"Simple solve: solve() random A (TRANS):";
166 numberFailedTests +=
ReturnCodeCheck(testName, returnCode, 0, verbose);
168 #ifdef HAVE_TEUCHOS_COMPLEX
173 returnCode = solver1.
solve();
174 testName =
"Simple solve: solve() random A (CONJ_TRANS):";
176 numberFailedTests +=
ReturnCodeCheck(testName, returnCode, 0, verbose);
180 #ifdef HAVE_TEUCHOSNUMERICS_EIGEN
191 #ifdef HAVE_TEUCHOS_COMPLEX
202 AB2 = Teuchos::generalToBanded( A2, kl, ku,
true );
205 C2 = Teuchos::bandedToGeneral( AB2 );
206 testName =
"Converting matrix formats: generalToBanded and bandedToGeneral random A:";
208 numberFailedTests +=
ReturnCodeCheck(testName, returnCode, 0, verbose);
215 returnCode = solver2.
factor();
216 testName =
"Solve with iterative refinement: factor() random A:";
217 numberFailedTests +=
ReturnCodeCheck(testName, returnCode, 0, verbose);
220 returnCode = solver2.
solve();
221 testName =
"Solve with iterative refinement: solve() random A (NO_TRANS):";
223 numberFailedTests +=
ReturnCodeCheck(testName, returnCode, 0, verbose);
229 returnCode = solver2.
solve();
230 testName =
"Solve with iterative refinement: solve() random A (TRANS):";
232 numberFailedTests +=
ReturnCodeCheck(testName, returnCode, 0, verbose);
234 #ifdef HAVE_TEUCHOS_COMPLEX
239 returnCode = solver2.
solve();
240 testName =
"Solve with iterative refinement: solve() random A (CONJ_TRANS):";
242 numberFailedTests +=
ReturnCodeCheck(testName, returnCode, 0, verbose);
256 #ifdef HAVE_TEUCHOS_COMPLEX
267 AB3 = Teuchos::generalToBanded( A3, kl, ku,
true );
270 C3 = Teuchos::bandedToGeneral( AB3 );
271 testName =
"Converting matrix formats: generalToBanded and bandedToGeneral random A:";
273 numberFailedTests +=
ReturnCodeCheck(testName, returnCode, 0, verbose);
283 returnCode = solver3.
factor();
284 testName =
"Solve with matrix equilibration: factor() random A:";
285 numberFailedTests +=
ReturnCodeCheck(testName, returnCode, 0, verbose);
288 returnCode = solver3.
solve();
289 testName =
"Solve with matrix equilibration: solve() random A (NO_TRANS):";
291 numberFailedTests +=
ReturnCodeCheck(testName, returnCode, 0, verbose);
297 returnCode = solver3.
solve();
298 testName =
"Solve with matrix equilibration: solve() random A (TRANS):";
300 numberFailedTests +=
ReturnCodeCheck(testName, returnCode, 0, verbose);
302 #ifdef HAVE_TEUCHOS_COMPLEX
307 returnCode = solver3.
solve();
308 testName =
"Solve with matrix equilibration: solve() random A (CONJ_TRANS):";
310 numberFailedTests +=
ReturnCodeCheck(testName, returnCode, 0, verbose);
318 returnCode = solver3.
solve();
319 testName =
"Solve with matrix equilibration: solve() without factor() random A (NO_TRANS):";
321 numberFailedTests +=
ReturnCodeCheck(testName, returnCode, 0, verbose);
326 if(numberFailedTests > 0)
329 std::cout <<
"Number of failed tests: " << numberFailedTests << std::endl;
330 std::cout <<
"End Result: TEST FAILED" << std::endl;
334 if(numberFailedTests == 0)
335 std::cout <<
"End Result: TEST PASSED!" << std::endl;
340 template<
typename TYPE>
341 int PrintTestResults(std::string testName, TYPE calculatedResult, TYPE expectedResult,
bool verbose)
344 if(calculatedResult == expectedResult)
346 if(verbose) std::cout << testName <<
" successful." << std::endl;
351 if(verbose) std::cout << testName <<
" unsuccessful." << std::endl;
357 int ReturnCodeCheck(std::string testName,
int returnCode,
int expectedResult,
bool verbose)
360 if(expectedResult == 0)
364 if(verbose) std::cout << testName <<
" test successful." << std::endl;
369 if(verbose) std::cout << testName <<
" test unsuccessful. Return code was " << returnCode <<
"." << std::endl;
377 if(verbose) std::cout << testName <<
" test successful -- failed as expected." << std::endl;
382 if(verbose) std::cout << testName <<
" test unsuccessful -- did not fail as expected. Return code was " << returnCode <<
"." << std::endl;
389 template<
typename TYPE>
396 std::complex<T>
GetRandom( std::complex<T> Low, std::complex<T> High)
398 T lowMag = Low.real();
399 T highMag = High.real();
402 return std::complex<T>( real, imag );
412 double GetRandom(
double Low,
double High)
422 for (
int i=0; i<m; i++)
423 for (
int j=0; j<
n; j++)
424 if (j>= i-kl && j<=i+ku)
435 for (
int i=0; i<
n; i++)
455 MagnitudeType temp = norm_diff;
459 if (temp > Tolerance)
477 MagnitudeType norm_diff = diff.
normInf();
478 MagnitudeType norm_m2 = Matrix2.
normInf();
479 MagnitudeType temp = norm_diff;
483 if (temp > Tolerance)
int PrintTestResults(std::string, TYPE, TYPE, bool)
Non-member helper functions on the templated serial, dense matrix/vector classes. ...
Templated serial dense matrix class.
void solveToRefinedSolution(bool flag)
Set whether or not to use iterative refinement to improve solutions to linear systems.
int setMatrix(const RCP< SerialBandDenseMatrix< OrdinalType, ScalarType > > &AB)
Sets the pointer for coefficient matrix.
Teuchos::SerialDenseVector< int, std::complex< Real > > DVector
int multiply(ETransp transa, ETransp transb, ScalarType alpha, const SerialDenseMatrix< OrdinalType, ScalarType > &A, const SerialDenseMatrix< OrdinalType, ScalarType > &B, ScalarType beta)
Multiply A * B and add them to this; this = beta * this + alpha*A*B.
int setVectors(const RCP< SerialDenseMatrix< OrdinalType, ScalarType > > &X, const RCP< SerialDenseMatrix< OrdinalType, ScalarType > > &B)
Sets the pointers for left and right hand side vector(s).
This class creates and provides basic support for dense vectors of templated type as a specialization...
ScalarTraits< ScalarType >::magnitudeType normFrobenius() const
Returns the Frobenius-norm of the matrix.
This structure defines some basic traits for a scalar field type.
Templated serial dense matrix class.
TEUCHOS_DEPRECATED RCP< T > rcp(T *p, Dealloc_T dealloc, bool owns_mem)
Deprecated.
TYPE GetRandom(TYPE, TYPE)
This class creates and provides basic support for banded dense matrices of templated type...
A class for representing and solving banded dense linear systems.
bool CompareVectors(TYPE1 *Vector1, TYPE2 *Vector2, OType Size, TYPE2 Tolerance)
Teuchos::SerialDenseMatrix< int, std::complex< Real > > DMatrix
std::string Teuchos_Version()
int ReturnCodeCheck(std::string, int, int, bool)
int solve()
Computes the solution X to AX = B for the this matrix and the B provided to SetVectors()..
int main(int argc, char *argv[])
bool CompareMatrices(TYPE1 *Matrix1, TYPE2 *Matrix2, OType Rows, OType Columns, OType LDM, TYPE2 Tolerance)
Teuchos::RCP< DMatrix > GetRandomBandedMatrix(int m, int n, int kl, int ku)
Teuchos::SerialBandDenseMatrix< OTYPE, STYPE > BDMatrix
ScalarTraits< ScalarType >::magnitudeType normInf() const
Returns the Infinity-norm of the matrix.
int factor()
Computes the in-place LU factorization of the matrix using the LAPACK routine _GBTRF.
Templated serial dense vector class.
Defines basic traits for the scalar field type.
void solveWithTransposeFlag(Teuchos::ETransp trans)
Teuchos::RCP< DVector > GetRandomVector(int n)
Smart reference counting pointer class for automatic garbage collection.
Reference-counted pointer class and non-member templated function implementations.
void factorWithEquilibration(bool flag)
This class creates and provides basic support for dense rectangular matrix of templated type...