Skip to content

Commit

Permalink
Merge pull request #142 from UCBoulder/maint/replace-floatVector-with…
Browse files Browse the repository at this point in the history
…-specified-tensor-size-where-possible

Maint/replace float vector with specified tensor size where possible
  • Loading branch information
NateAM committed Jul 25, 2024
2 parents f69c9fa + 916616a commit ad464a2
Show file tree
Hide file tree
Showing 14 changed files with 1,454 additions and 1,435 deletions.
4 changes: 4 additions & 0 deletions docs/sphinx/changelog.rst
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,10 @@ Changelog
0.5.0 (unreleased)
******************

Internal Changes
================
- Working towards removing floatVector in favor of specific sizes (:pull:`141`). By `Nathan Miller`_.

******************
0.4.4 (07-12-2024)
******************
Expand Down
43 changes: 20 additions & 23 deletions src/cpp/tardigrade_hydra.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ namespace tardigradeHydra{

hydraBase::hydraBase( const floatType &time, const floatType &deltaTime,
const floatType &temperature, const floatType &previousTemperature,
const floatVector &deformationGradient, const floatVector &previousDeformationGradient,
const secondOrderTensor &deformationGradient, const secondOrderTensor &previousDeformationGradient,
const floatVector &additionalDOF, const floatVector &previousAdditionalDOF,
const floatVector &previousStateVariables, const floatVector &parameters,
const unsigned int numConfigurations, const unsigned int numNonLinearSolveStateVariables,
Expand Down Expand Up @@ -155,7 +155,7 @@ namespace tardigradeHydra{
kernel_type kernel(LIBXSMM_GEMM_FLAG_NONE, dim, dim, dim, 1, 0 );

// Initialize the first configuration with the total deformation gradient
floatVector temp( sot_dim, 0 );
secondOrderTensor temp( sot_dim, 0 );
#else
Eigen::Map < Eigen::Matrix< floatType, 3, 3, Eigen::RowMajor> > mat2( NULL, 3, 3 );
#endif
Expand Down Expand Up @@ -361,7 +361,7 @@ namespace tardigradeHydra{

TARDIGRADE_ERROR_TOOLS_CHECK( lowerIndex <= upperIndex, build_lower_index_out_of_range_error_string( lowerIndex, upperIndex ) )

floatVector Fsc( sot_dim, 0 );
secondOrderTensor Fsc( sot_dim, 0 );
for ( unsigned int i = 0; i < 3; i++ ){ Fsc[ dim * i + i ] = 1.; }

#ifdef TARDIGRADE_HYDRA_USE_LLXSMM
Expand Down Expand Up @@ -416,7 +416,7 @@ namespace tardigradeHydra{

for ( unsigned int index = lowerIndex; index < upperIndex; index++ ){

floatVector Fm, FpT;
secondOrderTensor Fm, FpT;

TARDIGRADE_ERROR_TOOLS_CATCH( Fm = getSubConfiguration( configurations, lowerIndex, index ) );

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

}

floatVector hydraBase::getSubConfiguration( const unsigned int &lowerIndex, const unsigned int &upperIndex ){
secondOrderTensor hydraBase::getSubConfiguration( const unsigned int &lowerIndex, const unsigned int &upperIndex ){
/*!
* Get a sub-configuration \f$\bf{F}^{sc}\f$ defined as
*
Expand All @@ -462,7 +462,7 @@ namespace tardigradeHydra{

}

floatVector hydraBase::getPrecedingConfiguration( const unsigned int &index ){
secondOrderTensor hydraBase::getPrecedingConfiguration( const unsigned int &index ){
/*!
* Get the sub-configuration preceding but not including the index
*
Expand All @@ -473,7 +473,7 @@ namespace tardigradeHydra{

}

floatVector hydraBase::getFollowingConfiguration( const unsigned int &index ){
secondOrderTensor hydraBase::getFollowingConfiguration( const unsigned int &index ){
/*!
* Get the sub-configuration following but not including the index
*
Expand All @@ -484,7 +484,7 @@ namespace tardigradeHydra{

}

floatVector hydraBase::getConfiguration( const unsigned int &index ){
secondOrderTensor hydraBase::getConfiguration( const unsigned int &index ){
/*!
* Get the configuration indicated by the provided index
*
Expand All @@ -495,7 +495,7 @@ namespace tardigradeHydra{

}

floatVector hydraBase::getPreviousSubConfiguration( const unsigned int &lowerIndex, const unsigned int &upperIndex ){
secondOrderTensor hydraBase::getPreviousSubConfiguration( const unsigned int &lowerIndex, const unsigned int &upperIndex ){
/*!
* Get a previous sub-configuration \f$\bf{F}^{sc}\f$ defined as
*
Expand All @@ -509,7 +509,7 @@ namespace tardigradeHydra{

}

floatVector hydraBase::getPreviousPrecedingConfiguration( const unsigned int &index ){
secondOrderTensor hydraBase::getPreviousPrecedingConfiguration( const unsigned int &index ){
/*!
* Get the previous sub-configuration preceding but not including the index
*
Expand All @@ -520,7 +520,7 @@ namespace tardigradeHydra{

}

floatVector hydraBase::getPreviousFollowingConfiguration( const unsigned int &index ){
secondOrderTensor hydraBase::getPreviousFollowingConfiguration( const unsigned int &index ){
/*!
* Get the previous sub-configuration following but not including the index
*
Expand All @@ -531,7 +531,7 @@ namespace tardigradeHydra{

}

floatVector hydraBase::getPreviousConfiguration( const unsigned int &index ){
secondOrderTensor hydraBase::getPreviousConfiguration( const unsigned int &index ){
/*!
* Get the previous configuration indicated by the provided index
*
Expand Down Expand Up @@ -622,7 +622,7 @@ namespace tardigradeHydra{

}

void hydraBase::calculateFirstConfigurationJacobians( const floatVector &configurations, floatVector &dC1dC, floatVector &dC1dCn ){
void hydraBase::calculateFirstConfigurationJacobians( const floatVector &configurations, fourthOrderTensor &dC1dC, floatVector &dC1dCn ){
/*!
* Get the Jacobian of the first configuration w.r.t. the total mapping and the remaining configurations.
*
Expand All @@ -637,20 +637,17 @@ namespace tardigradeHydra{
const unsigned int sot_dim = getSOTDimension( );
const unsigned int num_configs = *getNumConfigurations( );

dC1dC = floatVector( sot_dim * sot_dim, 0 );
dC1dC = secondOrderTensor( sot_dim * sot_dim, 0 );

dC1dCn = floatVector( sot_dim * ( num_configs - 1 ) * sot_dim, 0 );

floatVector eye( sot_dim, 0 );
for ( unsigned int i = 0; i < dim; i++ ){ eye[ dim * i + i ] = 1; }
secondOrderTensor fullConfiguration = getSubConfiguration( configurations, 0, num_configs );

floatVector fullConfiguration = getSubConfiguration( configurations, 0, num_configs );

floatVector invCsc = getSubConfiguration( configurations, 1, num_configs );
secondOrderTensor invCsc = getSubConfiguration( configurations, 1, num_configs );
Eigen::Map < Eigen::Matrix< floatType, 3, 3, Eigen::RowMajor > > mat( invCsc.data( ), dim, dim );
mat = mat.inverse( ).eval( );

floatVector dInvCscdCsc = tardigradeVectorTools::computeFlatDInvADA( invCsc, dim, dim );
fourthOrderTensor dInvCscdCsc = tardigradeVectorTools::computeFlatDInvADA( invCsc, dim, dim );

floatVector dInvCscdCs = tardigradeVectorTools::matrixMultiply( dInvCscdCsc, getSubConfigurationJacobian( configurations, 1, num_configs ), sot_dim, sot_dim, sot_dim, num_configs * sot_dim );

Expand Down Expand Up @@ -693,7 +690,7 @@ namespace tardigradeHydra{
* Set the Jacobians of the first configuration w.r.t. the total configuration and the remaining sub-configurations
*/

floatVector dF1dF;
secondOrderTensor dF1dF;

floatVector dF1dFn;

Expand All @@ -710,7 +707,7 @@ namespace tardigradeHydra{
* Set the Jacobians of the previous first configuration w.r.t. the total configuration and the remaining sub-configurations
*/

floatVector dF1dF;
secondOrderTensor dF1dF;

floatVector dF1dFn;

Expand Down Expand Up @@ -1333,7 +1330,7 @@ namespace tardigradeHydra{

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

Xmat[ i ] = floatVector( configurations->begin( ) + sot_dim * i, configurations->begin( ) + sot_dim * ( i + 1 ) );
Xmat[ i ] = secondOrderTensor( configurations->begin( ) + sot_dim * i, configurations->begin( ) + sot_dim * ( i + 1 ) );

}

Expand Down
42 changes: 24 additions & 18 deletions src/cpp/tardigrade_hydra.h
Original file line number Diff line number Diff line change
Expand Up @@ -217,6 +217,12 @@ namespace tardigradeHydra{
typedef std::vector< floatType > floatVector; //!< Define a vector of floats
typedef std::vector< std::vector< floatType > > floatMatrix; //!< Define a matrix of floats

//Define tensors of known size
typedef std::vector< floatType > dimVector; //!< Dimension vector
typedef std::vector< floatType > secondOrderTensor; //!< Second order tensors
typedef std::vector< floatType > thirdOrderTensor; //!< Third order tensors
typedef std::vector< floatType > fourthOrderTensor; //!< Fourth order tensors

#ifdef TARDIGRADE_HYDRA_USE_LLXSMM
typedef libxsmm_mmfunction<floatType> kernel_type; //!< The libxsmm kernel type
#endif
Expand Down Expand Up @@ -615,7 +621,7 @@ namespace tardigradeHydra{
//! Main constructor for objects of type hydraBase. Sets all quantities required for most solves.
hydraBase( const floatType &time, const floatType &deltaTime,
const floatType &temperature, const floatType &previousTemperature,
const floatVector &deformationGradient, const floatVector &previousDeformationGradient,
const secondOrderTensor &deformationGradient, const secondOrderTensor &previousDeformationGradient,
const floatVector &additionalDOF, const floatVector &previousAdditionalDOF,
const floatVector &previousStateVariables, const floatVector &parameters,
const unsigned int numConfigurations, const unsigned int numNonLinearSolveStateVariables,
Expand Down Expand Up @@ -645,10 +651,10 @@ namespace tardigradeHydra{
const floatType* getPreviousTemperature( ){ return &_previousTemperature; };

//! Get a reference to the deformation gradient
const floatVector* getDeformationGradient( ){ return &_deformationGradient; }
const secondOrderTensor* getDeformationGradient( ){ return &_deformationGradient; }

//! Get a reference to the previous deformation gradient
const floatVector* getPreviousDeformationGradient( ){ return &_previousDeformationGradient; }
const secondOrderTensor* getPreviousDeformationGradient( ){ return &_previousDeformationGradient; }

//! Get a reference to the additional degrees of freedom
const floatVector* getAdditionalDOF( ){ return &_additionalDOF; }
Expand Down Expand Up @@ -853,25 +859,25 @@ namespace tardigradeHydra{

}

floatVector getSubConfiguration( const floatVector &configurations, const unsigned int &lowerIndex, const unsigned int &upperIndex );
secondOrderTensor 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 );
secondOrderTensor getSubConfigurationJacobian( const floatVector &configurations, const unsigned int &lowerIndex, const unsigned int &upperIndex );

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

floatVector getPrecedingConfiguration( const unsigned int &index );
secondOrderTensor getPrecedingConfiguration( const unsigned int &index );

floatVector getFollowingConfiguration( const unsigned int &index );
secondOrderTensor getFollowingConfiguration( const unsigned int &index );

floatVector getConfiguration( const unsigned int &index );
secondOrderTensor getConfiguration( const unsigned int &index );

floatVector getPreviousSubConfiguration( const unsigned int &lowerIndex, const unsigned int &upperIndex );
secondOrderTensor getPreviousSubConfiguration( const unsigned int &lowerIndex, const unsigned int &upperIndex );

floatVector getPreviousPrecedingConfiguration( const unsigned int &index );
secondOrderTensor getPreviousPrecedingConfiguration( const unsigned int &index );

floatVector getPreviousFollowingConfiguration( const unsigned int &index );
secondOrderTensor getPreviousFollowingConfiguration( const unsigned int &index );

floatVector getPreviousConfiguration( const unsigned int &index );
secondOrderTensor getPreviousConfiguration( const unsigned int &index );

floatVector getSubConfigurationJacobian( const unsigned int &lowerIndex, const unsigned int &upperIndex );

Expand Down Expand Up @@ -996,7 +1002,7 @@ namespace tardigradeHydra{

virtual void updateUnknownVector( const floatVector &newUnknownVector );

virtual void calculateFirstConfigurationJacobians( const floatVector &configurations, floatVector &dC1dC, floatVector &dC1dCn );
virtual void calculateFirstConfigurationJacobians( const floatVector &configurations, fourthOrderTensor &dC1dC, floatVector &dC1dCn );

virtual void performArmijoTypeLineSearch( const floatVector &X0, const floatVector &deltaX );

Expand Down Expand Up @@ -1147,9 +1153,9 @@ namespace tardigradeHydra{

floatType _previousTemperature; //!< The previous temperature

floatVector _deformationGradient; //!< The current deformation gradient
secondOrderTensor _deformationGradient; //!< The current deformation gradient

floatVector _previousDeformationGradient; //!< The previous deformation gradient
secondOrderTensor _previousDeformationGradient; //!< The previous deformation gradient

floatVector _additionalDOF; //!< The current additional degrees of freedom

Expand Down Expand Up @@ -1307,11 +1313,11 @@ namespace tardigradeHydra{

TARDIGRADE_HYDRA_DECLARE_ITERATION_STORAGE( private, dResidualNormdX, floatVector, setdResidualNormdX )

TARDIGRADE_HYDRA_DECLARE_NAMED_ITERATION_STORAGE( private, set_dF1dF, get_dF1dF, dF1dF, floatVector, setFirstConfigurationJacobians )
TARDIGRADE_HYDRA_DECLARE_NAMED_ITERATION_STORAGE( private, set_dF1dF, get_dF1dF, dF1dF, secondOrderTensor, setFirstConfigurationJacobians )

TARDIGRADE_HYDRA_DECLARE_NAMED_ITERATION_STORAGE( private, set_dF1dFn, get_dF1dFn, dF1dFn, floatVector, setFirstConfigurationJacobians )

TARDIGRADE_HYDRA_DECLARE_NAMED_PREVIOUS_STORAGE( private, set_previousdF1dF, get_previousdF1dF, previousdF1dF, floatVector, setPreviousFirstConfigurationJacobians )
TARDIGRADE_HYDRA_DECLARE_NAMED_PREVIOUS_STORAGE( private, set_previousdF1dF, get_previousdF1dF, previousdF1dF, secondOrderTensor, setPreviousFirstConfigurationJacobians )

TARDIGRADE_HYDRA_DECLARE_NAMED_PREVIOUS_STORAGE( private, set_previousdF1dFn, get_previousdF1dFn, previousdF1dFn, floatVector, setPreviousFirstConfigurationJacobians )

Expand Down
Loading

0 comments on commit ad464a2

Please sign in to comment.