Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Maint/allow for matrix rank errors to be optional #134

Merged
merged 3 commits into from
Jul 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions docs/sphinx/changelog.rst
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ Changelog
New Features
============
- Added projection operators to the residualBase (:pull:`133`). By `Nathan Miller`_.
- Allow the user to turn off rank-deficient errors (:pull:`134`). By `Nathan Miller`_.

******************
0.4.3 (07-12-2024)
Expand Down
6 changes: 3 additions & 3 deletions src/cpp/tardigrade_hydra.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1568,7 +1568,7 @@ namespace tardigradeHydra{

unsigned int rank = linearSolver.rank( );

if ( rank != getResidual( )->size( ) ){
if ( *getRankDeficientError( ) && ( rank != getResidual( )->size( ) ) ){

TARDIGRADE_ERROR_TOOLS_CATCH( throw convergence_error( "The Jacobian is not full rank" ) );

Expand Down Expand Up @@ -1601,7 +1601,7 @@ namespace tardigradeHydra{

unsigned int rank = linearSolver.rank( );

if ( rank != getResidual( )->size( ) ){
if ( *getRankDeficientError( ) && ( rank != getResidual( )->size( ) ) ){

TARDIGRADE_ERROR_TOOLS_CATCH( throw convergence_error( "The Jacobian is not full rank" ) );

Expand Down Expand Up @@ -1940,7 +1940,7 @@ namespace tardigradeHydra{

TARDIGRADE_ERROR_TOOLS_CATCH(

if ( rank != getResidual( )->size( ) ){
if ( *getRankDeficientError( ) && ( rank != getResidual( )->size( ) ) ){

throw convergence_error( "The Jacobian is not full rank" );

Expand Down
17 changes: 17 additions & 0 deletions src/cpp/tardigrade_hydra.h
Original file line number Diff line number Diff line change
Expand Up @@ -709,6 +709,9 @@ namespace tardigradeHydra{
//!< Get a reference to the current value of mu_k
const bool* getUseLevenbergMarquardt( ){ return &_use_LM_step; }

//!< Get a reference to the flag for whether to throw an error if the LHS matrix is rank-deficient
const bool* getRankDeficientError( ){ return &_rank_deficient_error; }

//!< Set the gradient descent sigma parameter
void setGradientSigma( const floatType &value ){
/*!
Expand Down Expand Up @@ -805,6 +808,18 @@ namespace tardigradeHydra{

}

//!< Set whether rank deficiency is a reason to throw an error
void setRankDeficientError( const bool &value ){
/*!
* Set whether a rank-deficient LHS will cause an error
*
* \param &value: The value of the parameter
*/

_rank_deficient_error = value;

}

floatVector getSubConfiguration( const floatVector &configurations, const unsigned int &lowerIndex, const unsigned int &upperIndex );

floatVector getSubConfigurationJacobian( const floatVector &configurations, const unsigned int &lowerIndex, const unsigned int &upperIndex );
Expand Down Expand Up @@ -1127,6 +1142,8 @@ namespace tardigradeHydra{

bool _use_LM_step = false; //!< Flag for whether to attempt a Levenberg-Marquardt step

bool _rank_deficient_error = true; //!< Flag for whether a rank-deficient LHS will throw a convergence error

floatType _mu_k = -1; //!< The Levenberg-Marquardt scaling parameter

floatType _lsAlpha; //!< The line-search alpha value i.e., the term by which it is judged that the line-search is converging
Expand Down
24 changes: 24 additions & 0 deletions src/cpp/tests/test_tardigrade_hydra.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -278,6 +278,12 @@ namespace tardigradeHydra{

}

static void checkRankDeficientError( hydraBase &hydra ){

BOOST_CHECK( &hydra._rank_deficient_error == hydra.getRankDeficientError( ) );

}

static void checkUsePreconditioner( hydraBase &hydra ){

BOOST_CHECK( &hydra._use_preconditioner == hydra.getUsePreconditioner( ) );
Expand Down Expand Up @@ -843,6 +849,14 @@ BOOST_AUTO_TEST_CASE( test_hydraBase_getUseLevenbergMarquardt, * boost::unit_tes

}

BOOST_AUTO_TEST_CASE( test_hydraBase_getRankDeficientError, * boost::unit_test::tolerance( DEFAULT_TEST_TOLERANCE ) ){

tardigradeHydra::hydraBase hydra;

tardigradeHydra::unit_test::hydraBaseTester::checkRankDeficientError( hydra );

}

BOOST_AUTO_TEST_CASE( test_hydraBase_setGradientSigma, * boost::unit_test::tolerance( DEFAULT_TEST_TOLERANCE ) ){

tardigradeHydra::hydraBase hydra;
Expand Down Expand Up @@ -923,6 +937,16 @@ BOOST_AUTO_TEST_CASE( test_hydraBase_setUseLevenbergMarquardt, * boost::unit_tes

}

BOOST_AUTO_TEST_CASE( test_hydraBase_setRankDeficientError, * boost::unit_test::tolerance( DEFAULT_TEST_TOLERANCE ) ){

tardigradeHydra::hydraBase hydra;

hydra.setRankDeficientError( false );

BOOST_TEST( false == *hydra.getRankDeficientError( ) );

}

BOOST_AUTO_TEST_CASE( test_hydraBase_decomposeStateVariableVector, * boost::unit_test::tolerance( DEFAULT_TEST_TOLERANCE ) ){

floatType time = 1.1;
Expand Down
Loading