Skip to content
Snippets Groups Projects
Commit ee1b52d3 authored by Jakub Klinkovský's avatar Jakub Klinkovský
Browse files

Fixing the TFQMR solver.

parent 8b0a59cb
No related branches found
No related tags found
No related merge requests found
...@@ -75,7 +75,7 @@ class tnlTFQMRSolver : public tnlObject, ...@@ -75,7 +75,7 @@ class tnlTFQMRSolver : public tnlObject,
bool setSize( IndexType size ); bool setSize( IndexType size );
tnlVector< RealType, Device, IndexType > d, r, w, u, v, r_ast, u_new, Au, Au_new; tnlVector< RealType, Device, IndexType > d, r, w, u, v, r_ast, Au;
const MatrixType* matrix; const MatrixType* matrix;
const PreconditionerType* preconditioner; const PreconditionerType* preconditioner;
......
...@@ -36,10 +36,9 @@ template< typename Matrix, ...@@ -36,10 +36,9 @@ template< typename Matrix,
typename Preconditioner > typename Preconditioner >
tnlString tnlTFQMRSolver< Matrix, Preconditioner > :: getType() const tnlString tnlTFQMRSolver< Matrix, Preconditioner > :: getType() const
{ {
/*return tnlString( "tnlTFQMRSolver< " ) + return tnlString( "tnlTFQMRSolver< " ) +
tnlString( getType< RealType >() + ", " + this->matrix -> getType() + ", " +
Device :: getDeviceType() + ", " + this->preconditioner -> getType() + " >";
tnlString( getType< RealType >() + " >";*/
} }
template< typename Matrix, template< typename Matrix,
...@@ -84,9 +83,6 @@ bool tnlTFQMRSolver< Matrix, Preconditioner > :: solve( const Vector& b, Vector& ...@@ -84,9 +83,6 @@ bool tnlTFQMRSolver< Matrix, Preconditioner > :: solve( const Vector& b, Vector&
dbgFunctionName( "tnlTFQMRSolver", "Solve" ); dbgFunctionName( "tnlTFQMRSolver", "Solve" );
if( ! this -> setSize( matrix -> getRows() ) ) return false; if( ! this -> setSize( matrix -> getRows() ) ) return false;
this -> resetIterations();
this -> setResidue( this -> getConvergenceResidue() + 1.0 );
RealType tau, theta, eta, rho, alpha, w_norm; RealType tau, theta, eta, rho, alpha, w_norm;
RealType b_norm = b. lpNorm( 2.0 ); RealType b_norm = b. lpNorm( 2.0 );
if( b_norm == 0.0 ) if( b_norm == 0.0 )
...@@ -102,38 +98,31 @@ bool tnlTFQMRSolver< Matrix, Preconditioner > :: solve( const Vector& b, Vector& ...@@ -102,38 +98,31 @@ bool tnlTFQMRSolver< Matrix, Preconditioner > :: solve( const Vector& b, Vector&
theta = eta = 0.0; theta = eta = 0.0;
r_ast = r; r_ast = r;
rho = r_ast. scalarProduct( r ); rho = r_ast. scalarProduct( r );
alpha = 0.0; // TODO // only to avoid compiler warning; alpha is initialized inside the loop
alpha = 0.0;
this->resetIterations(); this->resetIterations();
this -> setResidue( tau / b_norm ); this->setResidue( tau / b_norm );
while( this->nextIteration() ) while( this->nextIteration() )
{ {
// start counting from 0 const IndexType iter = this->getIterations();
const IndexType iter = this->getIterations() - 1;
// cerr << "Starting TFQMR iteration " << iter << endl;
if( iter % 2 == 0 ) { if( iter % 2 == 1 ) {
alpha = rho / v. scalarProduct( this -> r_ast ); alpha = rho / v. scalarProduct( this -> r_ast );
} }
else { else {
// not necessary in even iteration since the previous odd iteration // not necessary in odd iter since the previous iteration
// already computed v_{m+1} = A*u_{m+1} // already computed v_{m+1} = A*u_{m+1}
matrix -> vectorProduct( u, Au ); matrix -> vectorProduct( u, Au );
} }
w.addVector( Au, -alpha ); w.addVector( Au, -alpha );
// cerr << "alpha = " << alpha << endl; d.addVector( u, 1.0, theta * theta * eta / alpha );
//cerr << "theta * theta / alpha * eta = " << theta * theta / alpha * eta << endl;
d. addVector( u, 1.0, theta * theta * eta / alpha );
w_norm = w. lpNorm( 2.0 ); w_norm = w. lpNorm( 2.0 );
// cerr << "w_norm / b_norm = residue = " << w_norm / b_norm << endl;
theta = w_norm / tau; theta = w_norm / tau;
const RealType c = 1.0 / sqrt( 1.0 + theta * theta ); const RealType c = 1.0 / sqrt( 1.0 + theta * theta );
tau = tau * theta * c; tau = tau * theta * c;
// cerr << "tau * sqrt(m+1) = " << tau * sqrt(iter+1) << endl;
eta = c * c * alpha; eta = c * c * alpha;
//cerr << "eta = " << eta << endl;
x.addVector( d, eta ); x.addVector( d, eta );
this->setResidue( tau * sqrt(iter+1) / b_norm ); this->setResidue( tau * sqrt(iter+1) / b_norm );
...@@ -141,8 +130,7 @@ bool tnlTFQMRSolver< Matrix, Preconditioner > :: solve( const Vector& b, Vector& ...@@ -141,8 +130,7 @@ bool tnlTFQMRSolver< Matrix, Preconditioner > :: solve( const Vector& b, Vector&
break; break;
} }
if( iter % 2 == 1 ) if( iter % 2 == 0 ) {
{
const RealType rho_new = w. scalarProduct( this -> r_ast ); const RealType rho_new = w. scalarProduct( this -> r_ast );
const RealType beta = rho_new / rho; const RealType beta = rho_new / rho;
rho = rho_new; rho = rho_new;
...@@ -159,6 +147,10 @@ bool tnlTFQMRSolver< Matrix, Preconditioner > :: solve( const Vector& b, Vector& ...@@ -159,6 +147,10 @@ bool tnlTFQMRSolver< Matrix, Preconditioner > :: solve( const Vector& b, Vector&
this -> refreshSolverMonitor(); this -> refreshSolverMonitor();
} }
// this->matrix->vectorProduct( x, r );
// r.addVector( b, 1.0, -1.0 );
// this->setResidue( r.lpNorm( 2.0 ) / b_norm );
this->refreshSolverMonitor( true ); this->refreshSolverMonitor( true );
return this->checkConvergence(); return this->checkConvergence();
}; };
...@@ -179,9 +171,7 @@ bool tnlTFQMRSolver< Matrix, Preconditioner > :: setSize( IndexType size ) ...@@ -179,9 +171,7 @@ bool tnlTFQMRSolver< Matrix, Preconditioner > :: setSize( IndexType size )
! u. setSize( size ) || ! u. setSize( size ) ||
! v. setSize( size ) || ! v. setSize( size ) ||
! r_ast. setSize( size ) || ! r_ast. setSize( size ) ||
! u_new. setSize( size ) || ! Au. setSize( size ) )
! Au. setSize( size ) ||
! Au_new. setSize( size ) )
{ {
cerr << "I am not able to allocate all supporting vectors for the TFQMR solver." << endl; cerr << "I am not able to allocate all supporting vectors for the TFQMR solver." << endl;
return false; return false;
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment