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

Feat/add levenberg marquardt backup to solve failure #135

Merged
merged 2 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 @@ -13,6 +13,7 @@ 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`_.
- Added a Levenberg-Marquardt solve in the case of a convergence failure (:pull:`135`). By `Nathan Miller`_.

******************
0.4.3 (07-12-2024)
Expand Down
21 changes: 20 additions & 1 deletion src/cpp/tardigrade_hydra.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1866,7 +1866,26 @@ namespace tardigradeHydra{
}
catch( const convergence_error &e ){

throw;
//Try a Levenberg-Marquardt solve if there is a convergence error
setRankDeficientError( false );

setUseLevenbergMarquardt( true );

try{

solveNonLinearProblem( );

}
catch( const convergence_error &e ){

throw;

}
catch( std::exception &e ){

TARDIGRADE_ERROR_TOOLS_CATCH( throw; )

}

}
catch( std::exception &e ){
Expand Down
4 changes: 2 additions & 2 deletions src/cpp/tardigrade_hydra.h
Original file line number Diff line number Diff line change
Expand Up @@ -948,6 +948,8 @@ namespace tardigradeHydra{

virtual void formPreconditioner( );

virtual void solveNonLinearProblem( );

virtual void formMaxRowPreconditioner( );

virtual void initializeUnknownVector( );
Expand Down Expand Up @@ -1216,8 +1218,6 @@ namespace tardigradeHydra{

void setPreviousFirstConfigurationJacobians( );

void solveNonLinearProblem( );

void performPreconditionedSolve( floatVector &deltaX_tr );

void solveNewtonUpdate( floatVector &deltaX_tr );
Expand Down
90 changes: 90 additions & 0 deletions src/cpp/tests/test_tardigrade_hydra.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5676,3 +5676,93 @@ BOOST_AUTO_TEST_CASE( test_hydraBase_updateUnknownVector, * boost::unit_test::to
BOOST_TEST( hydra.checkProject( ) );

}

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

class residualMock : public tardigradeHydra::residualBase{

public:

bool project_called = false;

using tardigradeHydra::residualBase::residualBase;

virtual void projectSuggestedX( std::vector< double > &trialX,
const std::vector< double > &Xp ) override{

project_called = true;

}

};

class hydraBaseMock : public tardigradeHydra::hydraBase{

public:

residualMock r1;

residualMock r2;

using tardigradeHydra::hydraBase::hydraBase;

unsigned int num_calls = 0;

protected:

virtual void solveNonLinearProblem( ) override{

num_calls++;

throw tardigradeHydra::convergence_error( "failure to converge" );

}

using tardigradeHydra::hydraBase::setResidualClasses;

};

floatType time = 1.1;

floatType deltaTime = 2.2;

floatType temperature = 5.3;

floatType previousTemperature = 23.4;

floatVector deformationGradient = { 1.05, 0, 0,
0.00, 1, 0,
0.00, 1, 1};

floatVector previousDeformationGradient = { -0.21576496, -0.31364397, 0.45809941,
-0.12285551, -0.88064421, -0.20391149,
0.47599081, -0.63501654, -0.64909649 };

floatVector previousStateVariables = { 0, 0, 0, 0, 0, 0, 0, 0, 0 };

floatVector parameters = { 123.4, 56.7 };

unsigned int numConfigurations = 2;

unsigned int numNonLinearSolveStateVariables = 0;

unsigned int dimension = 3;

floatVector unknownVector = { 1, 1, 1, 1, 1, 1, 1, 1, 1,
2, 2, 2, 2, 2, 2, 2, 2, 2 };

hydraBaseMock hydra( time, deltaTime, temperature, previousTemperature, deformationGradient, previousDeformationGradient,
{ }, { },
previousStateVariables, parameters, numConfigurations, numNonLinearSolveStateVariables, dimension );

// try{hydra.evaluate();}catch(std::exception &e){tardigradeErrorTools::printNestedExceptions(e);}
//
BOOST_CHECK_THROW( hydra.evaluate( ), tardigradeHydra::convergence_error );

BOOST_TEST( *hydra.getUseLevenbergMarquardt( ) );

BOOST_TEST( !( *hydra.getRankDeficientError( ) ) );

BOOST_TEST( hydra.num_calls == 2 );

}
Loading