Skip to content

Commit

Permalink
Merge pull request #119 from UCBoulder/tst/add-test-for-zero-mass-rat…
Browse files Browse the repository at this point in the history
…e-change

Tst/add test for zero mass rate change
  • Loading branch information
NateAM authored Jun 18, 2024
2 parents 287340a + a2d15a2 commit 1f000ff
Show file tree
Hide file tree
Showing 2 changed files with 223 additions and 2 deletions.
5 changes: 3 additions & 2 deletions docs/sphinx/changelog.rst
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,9 @@ Internal Changes
- Added a better guess for the mass-change residual to improve convergence (:pull:`110`). By `Nathan Miller`_.
- Replaced the trapezoidal evolveF with the exponential map version (:pull:`111`). By `Nathan Miller`_.
- Rolled back exponential integrator for micromorphic (:pull:`114`). By `Nathan Miller`_.
- Added test for a fully directional integration where we know the answer (:pull:`116`). By `Nathan Miller`_.
- Added test for a fully spherical integration where we know the answer (:pull:`117`). By `Nathan Miller`_.
- Added test for a fully directional integration where we know the answer (:pull:`117`). By `Nathan Miller`_.
- Added test for a fully spherical integration where we know the answer (:pull:`118`). By `Nathan Miller`_.
- Added test for when the mass-change rate is zero (:pull:`119`). By `Nathan Miller`_.

Bug Fixes
=========
Expand Down
220 changes: 220 additions & 0 deletions src/cpp/tests/test_tardigrade_hydraMassChange.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5651,3 +5651,223 @@ BOOST_AUTO_TEST_CASE( test_residual_expectedDeformation2, * boost::unit_test::to
adaptive_tolerance_test( RdStressdAdditionalDOF, dStressdAdditionalDOF, 1e-7 );

}

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

class residualMock : public tardigradeHydra::massChange::residual {

public:

using tardigradeHydra::massChange::residual::residual;

};

class hydraBaseMock : public tardigradeHydra::hydraBase {

public:

using tardigradeHydra::hydraBase::hydraBase;

floatVector elasticityParameters = { 123.4, 56.7 };

floatVector massChangeParameters = { 0.76 };

tardigradeHydra::linearElasticity::residual elasticity;

residualMock massChange;

void setResidualClasses( std::vector< tardigradeHydra::residualBase* > &residuals ){

tardigradeHydra::hydraBase::setResidualClasses( residuals );

}

private:

virtual void setResidualClasses( ){

std::vector< tardigradeHydra::residualBase* > residuals( 2 );

elasticity = tardigradeHydra::linearElasticity::residual( this, 9, elasticityParameters );

massChange = residualMock( this, 9, 1, massChangeParameters, 1.0 );

residuals[ 0 ] = &elasticity;

residuals[ 1 ] = &massChange;

setResidualClasses( residuals );

}

};

floatType time = 1.3862943611198906;

floatType deltaTime = 4.158883083359672;

floatType temperature = 300.0;

floatType previousTemperature = 320.4;

floatVector deformationGradient = { 1.1, 0.0, 0.0,
0.0, 1.0, 0.0,
0.0, 0.0, 1.0 };

floatVector previousDeformationGradient = { 1.0, 0.0, 0.0,
0.0, 1.0, 0.0,
0.0, 0.0, 1.0 };

floatVector additionalDOF = { 1.00, -0.00, 0, 0, 0 };

floatVector previousAdditionalDOF = { 1.00, -0.00, 0.00, 0.00, 0.00 };

floatVector previousStateVariables = { 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 };

floatVector parameters = { 123.4, 56.7, 0.00 };

unsigned int numConfigurations = 2;

unsigned int numNonLinearSolveStateVariables = 0;

unsigned int dimension = 3;

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

floatVector answer = { 1.0, 0, 0, 0, 1.0, 0, 0, 0, 1.0 };

floatVector dStressdF( 9 * 9, 0 );

floatVector dStressdT( 9, 0 );

floatVector dStressdAdditionalDOF( 5 * 9, 0 );

hydra.evaluate( );

BOOST_TEST( answer == floatVector( hydra.getUnknownVector( )->begin( ) + 9, hydra.getUnknownVector( )->begin( ) + 18 ), CHECK_PER_ELEMENT );

floatType eps = 1e-6;

for ( unsigned int i = 0; i < 9; i++ ){

floatType delta = eps * std::fabs( deformationGradient[ i ] ) + eps;

floatVector xp = deformationGradient;

floatVector xm = deformationGradient;

xp[ i ] += delta;

xm[ i ] -= delta;

hydraBaseMock hydrap( time, deltaTime, temperature, previousTemperature, xp, previousDeformationGradient,
additionalDOF, previousAdditionalDOF,
previousStateVariables, parameters, numConfigurations, numNonLinearSolveStateVariables, dimension );

hydraBaseMock hydram( time, deltaTime, temperature, previousTemperature, xm, previousDeformationGradient,
additionalDOF, previousAdditionalDOF,
previousStateVariables, parameters, numConfigurations, numNonLinearSolveStateVariables, dimension );

hydrap.evaluate( );

hydram.evaluate( );

floatVector vp = *hydrap.getStress( );

floatVector vm = *hydram.getStress( );

for ( unsigned int j = 0; j < 9; j++ ){

dStressdF[ 9 * j + i ] = ( vp[ j ] - vm[ j ] ) / ( 2 * delta );

}

}

floatVector RdStressdF( hydra.getFlatdXdF( )->begin( ), hydra.getFlatdXdF( )->begin( ) + 81 );

adaptive_tolerance_test( RdStressdF, dStressdF, 2e-7 );

for ( unsigned int i = 0; i < 1; i++ ){

floatType delta = eps * std::fabs( deformationGradient[ i ] ) + eps;

floatType xp = temperature;

floatType xm = temperature;

xp += delta;

xm -= delta;

hydraBaseMock hydrap( time, deltaTime, xp, previousTemperature, deformationGradient, previousDeformationGradient,
additionalDOF, previousAdditionalDOF,
previousStateVariables, parameters, numConfigurations, numNonLinearSolveStateVariables, dimension );

hydraBaseMock hydram( time, deltaTime, xm, previousTemperature, deformationGradient, previousDeformationGradient,
additionalDOF, previousAdditionalDOF,
previousStateVariables, parameters, numConfigurations, numNonLinearSolveStateVariables, dimension );

hydrap.evaluate( );

hydram.evaluate( );

floatVector vp = *hydrap.getStress( );

floatVector vm = *hydram.getStress( );

for ( unsigned int j = 0; j < 9; j++ ){

dStressdT[ 1 * j + i ] = ( vp[ j ] - vm[ j ] ) / ( 2 * delta );

}

}

floatVector RdStressdT( hydra.getFlatdXdT( )->begin( ), hydra.getFlatdXdT( )->begin( ) + 9 );

BOOST_TEST( dStressdT == RdStressdT, CHECK_PER_ELEMENT );

for ( unsigned int i = 0; i < 5; i++ ){

floatType delta = eps * std::fabs( additionalDOF[ i ] ) + eps;

floatVector xp = additionalDOF;

floatVector xm = additionalDOF;

xp[ i ] += delta;

xm[ i ] -= delta;

hydraBaseMock hydrap( time, deltaTime, temperature, previousTemperature, deformationGradient, previousDeformationGradient,
xp, previousAdditionalDOF,
previousStateVariables, parameters, numConfigurations, numNonLinearSolveStateVariables, dimension );

hydraBaseMock hydram( time, deltaTime, temperature, previousTemperature, deformationGradient, previousDeformationGradient,
xm, previousAdditionalDOF,
previousStateVariables, parameters, numConfigurations, numNonLinearSolveStateVariables, dimension );

hydrap.evaluate( );

hydram.evaluate( );

floatVector vp = *hydrap.getStress( );

floatVector vm = *hydram.getStress( );

for ( unsigned int j = 0; j < 9; j++ ){

dStressdAdditionalDOF[ 5 * j + i ] = ( vp[ j ] - vm[ j ] ) / ( 2 * delta );

}

}

floatVector RdStressdAdditionalDOF( hydra.getFlatdXdAdditionalDOF( )->begin( ), hydra.getFlatdXdAdditionalDOF( )->begin( ) + 9 * 5 );

adaptive_tolerance_test( RdStressdAdditionalDOF, dStressdAdditionalDOF, 1e-7 );

}

0 comments on commit 1f000ff

Please sign in to comment.