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 better initial guess for mass change deformation #110

Merged
merged 7 commits into from
May 24, 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
5 changes: 5 additions & 0 deletions docs/sphinx/changelog.rst
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ New Features
- Added a mass-change deformation gradient evolution model (:pull:`104`). By `Nathan Miller`_.
- Added the calculation of the total derivative of the unknown vector w.r.t. the additional degrees of freedom (:pull:`104`). By `Nathan Miller`_.
- Added storage for the derivative of the residual w.r.t. the additional dof (:pull:`104`). By `Nathan Miller`_.
- Added the ability to initialize the unknown vector (:pull:`109`). By `Nathan Miller`_.
- Added function that returns the size of the unknown vector (:pull:`109`). By `Nathan Miller`_.

Breaking Changes
================
Expand Down Expand Up @@ -44,11 +46,14 @@ Internal Changes
- Improved performance of the linear elasticity subroutine (:pull:`99`). By `Nathan Miller`_.
- Using new error_tools check for error function (:pull:`100`). By `Nathan Miller`_.
- Changed Jacobian, dRdF, and dRdD to row-major vectors (:pull:`101`). By `Nathan Miller`_.
- Replaced queries to getUnknownVector purely to get the size of the vector (:pull:`109`). By `Nathan Miller`_.
- Added a better guess for the mass-change residual to improve convergence (:pull:`110`). By `Nathan Miller`_.

Bug Fixes
=========
- Corrected bug where the plastic state variable integration parameter was one minus the expected value (:pull:`71`). By `Nathan Miller`_.
- Corrected issue where libxsmm is not being used but was still required to be installed (:pull:`93`). By `Nathan Miller`_.
- Residuals setting initial guesses now force a reset of the current configurations (:pull:`110`). By `Nathan Miller`_.

******************
0.4.1 (01-24-2024)
Expand Down
51 changes: 42 additions & 9 deletions src/cpp/tardigrade_hydra.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -992,7 +992,7 @@ namespace tardigradeHydra{
* Form a left preconditioner comprised of the inverse of the maximum value of each row
*/

const unsigned int problem_size = getUnknownVector( )->size( );
const unsigned int problem_size = getNumUnknowns( );

_preconditioner.second = floatVector( problem_size, 0 );

Expand Down Expand Up @@ -1246,7 +1246,40 @@ namespace tardigradeHydra{

Xmat[ Xmat.size( ) - 1 ] = *nonLinearSolveStateVariables;

setX( tardigradeVectorTools::appendVectors( Xmat ) );
floatVector X = tardigradeVectorTools::appendVectors( Xmat );

bool resetRequired = false;

for ( auto residual_ptr = getResidualClasses( )->begin( ); residual_ptr != getResidualClasses( )->end( ); residual_ptr++ ){

std::vector< unsigned int > indices;

std::vector< floatType > values;

( *residual_ptr )->suggestInitialIterateValues( indices, values );

if ( indices.size( ) > 0 ){
resetRequired = true;
}

for ( auto i = indices.begin( ); i != indices.end( ); i++ ){

X[ *i ] = values[ ( unsigned int )( i - indices.begin( ) ) ];

}

}

if ( resetRequired ){

updateUnknownVector( X );

}
else{

setX( X );

}

}

Expand Down Expand Up @@ -1397,7 +1430,7 @@ namespace tardigradeHydra{

unsigned int rank;

floatVector deltaX( getUnknownVector( )->size( ), 0 );
floatVector deltaX( getNumUnknowns( ), 0 );

Eigen::Map< Eigen::Vector< floatType, -1 > > dx_map( deltaX.data( ), getUnknownVector( )->size( ) );

Expand Down Expand Up @@ -1517,14 +1550,14 @@ namespace tardigradeHydra{
// Form the maps for dXdF
Eigen::Map< const Eigen::Matrix< floatType, -1, -1, Eigen::RowMajor > > dRdFmat( getFlatdRdF( )->data( ), getResidual( )->size( ), *getConfigurationUnknownCount( ) );

_flatdXdF.second = floatVector( getUnknownVector( )->size( ) * ( *getConfigurationUnknownCount( ) ) );
Eigen::Map< Eigen::Matrix< floatType, -1, -1, Eigen::RowMajor > > dXdFmat( _flatdXdF.second.data( ), getUnknownVector( )->size( ), ( *getConfigurationUnknownCount( ) ) );
_flatdXdF.second = floatVector( getNumUnknowns( ) * ( *getConfigurationUnknownCount( ) ) );
Eigen::Map< Eigen::Matrix< floatType, -1, -1, Eigen::RowMajor > > dXdFmat( _flatdXdF.second.data( ), getNumUnknowns( ), ( *getConfigurationUnknownCount( ) ) );

// Form the maps for dXdT
Eigen::Map< const Eigen::Matrix< floatType, -1, -1, Eigen::RowMajor > > dRdTmat( getdRdT( )->data( ), getResidual( )->size( ), 1 );

_flatdXdT.second = floatVector( getUnknownVector( )->size( ) );
Eigen::Map< Eigen::Matrix< floatType, -1, -1, Eigen::RowMajor > > dXdTmat( _flatdXdT.second.data( ), getUnknownVector( )->size( ), 1 );
_flatdXdT.second = floatVector( getNumUnknowns( ) );
Eigen::Map< Eigen::Matrix< floatType, -1, -1, Eigen::RowMajor > > dXdTmat( _flatdXdT.second.data( ), getNumUnknowns( ), 1 );

// Solve
tardigradeVectorTools::solverType< floatType > solver;
Expand Down Expand Up @@ -1594,8 +1627,8 @@ namespace tardigradeHydra{
Eigen::Map< const Eigen::Matrix< floatType, -1, -1, Eigen::RowMajor > > dRdAdditionalDOF( getFlatdRdAdditionalDOF( )->data( ), getResidual( )->size( ), getAdditionalDOF( )->size( ) );

// Form the map for dXdF
_flatdXdAdditionalDOF.second = floatVector( getUnknownVector( )->size( ) * getAdditionalDOF( )->size( ), 0 );
Eigen::Map< Eigen::Matrix< floatType, -1, -1, Eigen::RowMajor > > dXdAdditionalDOF( _flatdXdAdditionalDOF.second.data( ), getUnknownVector( )->size( ), getAdditionalDOF( )->size( ) );
_flatdXdAdditionalDOF.second = floatVector( getNumUnknowns( ) * getAdditionalDOF( )->size( ), 0 );
Eigen::Map< Eigen::Matrix< floatType, -1, -1, Eigen::RowMajor > > dXdAdditionalDOF( _flatdXdAdditionalDOF.second.data( ), getNumUnknowns( ), getAdditionalDOF( )->size( ) );

// Solve
tardigradeVectorTools::solverType< floatType > solver;
Expand Down
23 changes: 23 additions & 0 deletions src/cpp/tardigrade_hydra.h
Original file line number Diff line number Diff line change
Expand Up @@ -455,6 +455,26 @@ namespace tardigradeHydra{

}

virtual void suggestInitialIterateValues( std::vector< unsigned int > &indices,
std::vector< floatType > &values ){

/*!
* Function which is called which allows the residual to suggest initial values for given
* configurations. This is called when the unknown vector is being initialized. If more than
* one residual attempts to set the initial vector the last residual will override all of the others.
*
* After the initial iterate has been suggested, the iteration data is cleared so that the residual
* starts the iteration in a clean state.
*
* \param &indices: The indices of the unknown vector to set
* \param &values: The values to be set in the unknown vector
*/

indices.clear( );
values.clear( );

}

// Getter functions

//! Get the number of equations the residual defined
Expand Down Expand Up @@ -617,6 +637,9 @@ namespace tardigradeHydra{
//! Get a reference to the number of state variables involved in the non-linear solve
const unsigned int* getNumNonLinearSolveStateVariables( ){ return &_numNonLinearSolveStateVariables; }

//! Get a reference to the number of terms in the unknown vector
virtual const unsigned int getNumUnknowns( ){ return ( *getNumConfigurations( ) ) * ( *getConfigurationUnknownCount( ) ) + *getNumNonLinearSolveStateVariables( ); }

//! Get a reference to the dimension
constexpr unsigned int getDimension( ){ return _dimension; }

Expand Down
2 changes: 1 addition & 1 deletion src/cpp/tardigrade_hydraLinearElasticity.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -595,7 +595,7 @@ namespace tardigradeHydra{

const unsigned int num_unknown_config_vars = ( num_configs - 1 ) * sot_dim;

const unsigned int num_unknowns = hydra->getUnknownVector( )->size( );
const unsigned int num_unknowns = hydra->getNumUnknowns( );

// Form the Jacobian
floatVector jacobian = floatVector( sot_dim * num_unknowns, 0 );
Expand Down
24 changes: 23 additions & 1 deletion src/cpp/tardigrade_hydraMassChange.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1403,7 +1403,7 @@ namespace tardigradeHydra{

const unsigned int sot_dim = hydra->getSOTDimension( );

const unsigned int num_unknowns = hydra->getUnknownVector( )->size( );
const unsigned int num_unknowns = hydra->getNumUnknowns( );

const unsigned int num_equations = *getNumEquations( );

Expand Down Expand Up @@ -1503,6 +1503,28 @@ namespace tardigradeHydra{

}

void residual::suggestInitialIterateValues( std::vector< unsigned int > &indices,
std::vector< floatType > &values ){
/*!
* Suggest initial iterate values to try and improve convergence
*
* \param &indices: The indices of the unknown vector to suggest initial values
* \param &values: The values to suggest
*/

const unsigned int sot_dim = hydra->getSOTDimension( );

const unsigned int configuration = *getMassChangeConfigurationIndex( );

const floatVector *massChangeDeformationGradient = get_massChangeDeformationGradient( );

indices = std::vector< unsigned int >( sot_dim, sot_dim * configuration );

for ( unsigned int i = 0; i < sot_dim; i++ ){ indices[ i ] += i; }
values = *massChangeDeformationGradient;

}

}

}
3 changes: 3 additions & 0 deletions src/cpp/tardigrade_hydraMassChange.h
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,9 @@ namespace tardigradeHydra{

const floatType *getIntegrationParameter( ){ return &_integrationParameter; }

virtual void suggestInitialIterateValues( std::vector< unsigned int > &indices,
std::vector< floatType > &values ) override;

protected:

virtual void decomposeAdditionalDOF( );
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7907,7 +7907,7 @@ namespace tardigradeHydra{

unsigned int numPlasticStrainLikeISVs = plasticStrainLikeISVs->size( );

const unsigned int numUnknowns = hydra->getUnknownVector( )->size( );
const unsigned int numUnknowns = hydra->getNumUnknowns( );

const unsigned int numISVs = get_plasticStateVariables( )->size( );

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

const unsigned int numEquations = *getNumEquations( );

const unsigned int numUnknowns = hydra->getUnknownVector( )->size( );
const unsigned int numUnknowns = hydra->getNumUnknowns( );

const unsigned int numConfigurations = *hydra->getNumConfigurations( );

Expand Down
2 changes: 1 addition & 1 deletion src/cpp/tardigrade_hydraMicromorphicLinearElasticity.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3545,7 +3545,7 @@ namespace tardigradeHydra{

const unsigned int num_configs = *hydra->getNumConfigurations( );

const unsigned int num_unknowns = hydra->getUnknownVector( )->size( );
const unsigned int num_unknowns = hydra->getNumUnknowns( );

floatVector jacobian( *getNumEquations( ) * num_unknowns, 0 );

Expand Down
2 changes: 1 addition & 1 deletion src/cpp/tardigrade_hydraPeryznaViscodamage.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -444,7 +444,7 @@ namespace tardigradeHydra{

const unsigned int num_isvs = get_plasticStateVariables( )->size( );

const unsigned int num_unknowns = hydra->getUnknownVector( )->size( );
const unsigned int num_unknowns = hydra->getNumUnknowns( );

floatVector jacobian( *getNumEquations( ) * num_unknowns, 0 );

Expand Down
2 changes: 1 addition & 1 deletion src/cpp/tardigrade_hydraPeryznaViscoplasticity.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2929,7 +2929,7 @@ namespace tardigradeHydra{

const unsigned int num_isvs = get_plasticStateVariables( )->size( );

const unsigned int num_unknowns = hydra->getUnknownVector( )->size( );
const unsigned int num_unknowns = hydra->getNumUnknowns( );

floatVector jacobian( *getNumEquations( ) * num_unknowns, 0 );

Expand Down
2 changes: 1 addition & 1 deletion src/cpp/tardigrade_hydraThermalExpansion.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ namespace tardigradeHydra{

const unsigned int sot_dim = hydra->getSOTDimension( );

const unsigned int num_unknowns = hydra->getUnknownVector( )->size( );
const unsigned int num_unknowns = hydra->getNumUnknowns( );

floatVector jacobian( *getNumEquations( ) * num_unknowns, 0 );

Expand Down
Loading
Loading