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 linear test residual #181

Merged
merged 10 commits into from
Feb 5, 2025
2 changes: 1 addition & 1 deletion .github/workflows/github-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ jobs:
- name: MiniConda setup
uses: conda-incubator/setup-miniconda@v2
with:
miniforge-variant: Mambaforge
miniforge-variant: Miniforge3
channels: conda-forge,defaults
channel-priority: true
auto-activate-base: false
Expand Down
3 changes: 2 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ set(TARDIGRADE_HYDRA_BUILD_PYTHON_BINDINGS ON CACHE BOOL "Flag for whether the p
set(TARDIGRADE_HYDRA_USE_LIBXSMM OFF CACHE BOOL "Flag for whether to use libxsmm for matrix math")

# Set the internal support libraries
set(INTERNAL_SUPPORT_LIBRARIES "tardigrade_hydraMicromorphic" "tardigrade_hydraLinearElasticity" "tardigrade_hydraLinearViscoelasticity" "tardigrade_hydraThermalExpansion" "tardigrade_hydraPeryznaViscoplasticity" "tardigrade_hydraMicromorphicLinearElasticity" "tardigrade_hydraPeryznaViscodamage" "tardigrade_hydraMicromorphicDruckerPragerPlasticity" "tardigrade_hydraPeryznaJ2Viscoplasticity" "tardigrade_hydraMassChange" "tardigrade_hydraMicromorphicDruckerPragerPlasticityOptimization")
set(INTERNAL_SUPPORT_LIBRARIES "tardigrade_hydraMicromorphic" "tardigrade_hydraLinearElasticity" "tardigrade_hydraLinearTestMaterial" "tardigrade_hydraLinearViscoelasticity" "tardigrade_hydraThermalExpansion" "tardigrade_hydraPeryznaViscoplasticity" "tardigrade_hydraMicromorphicLinearElasticity" "tardigrade_hydraPeryznaViscodamage" "tardigrade_hydraMicromorphicDruckerPragerPlasticity" "tardigrade_hydraPeryznaJ2Viscoplasticity" "tardigrade_hydraMassChange" "tardigrade_hydraMicromorphicDruckerPragerPlasticityOptimization")
set(PROJECT_SOURCE_FILES ${PROJECT_NAME}.cpp ${PROJECT_NAME}.h)
set(PROJECT_PRIVATE_HEADERS "")
foreach(package ${INTERNAL_SUPPORT_LIBRARIES})
Expand All @@ -39,6 +39,7 @@ set(TARDIGRADE_HYDRAPERYZNAVISCODAMAGE_UPSTREAM_LIBRARIES "tardigrade_constituti
set(TARDIGRADE_HYDRAPERYZNAJ2VISCOPLASTICITY_UPSTREAM_LIBRARIES "tardigrade_constitutive_tools" "tardigrade_stress_tools")
set(TARDIGRADE_HYDRAMASSCHANGE_UPSTREAM_LIBRARIES "tardigrade_constitutive_tools" "tardigrade_stress_tools")
set(TARDIGRADE_HYDRAMICROMORPHICLINEARELASTICITY_UPSTREAM_LIBRARIES "tardigrade_constitutive_tools" "tardigrade_micromorphic_tools")
set(TARDIGRADE_HYDRAMICROMORPHICLINEARTESTMATERIAL_UPSTREAM_LIBRARIES "tardigrade_constitutive_tools" "tardigrade_micromorphic_tools")
set(TARDIGRADE_HYDRAMICROMORPHICDRUCKERPRAGERPLASTICITY_UPSTREAM_LIBRARIES "tardigrade_constitutive_tools" "tardigrade_micromorphic_tools")
# Set some Abaqus integration variables
set(UMAT "${PROJECT_NAME}_umat")
Expand Down
8 changes: 7 additions & 1 deletion src/cpp/tardigrade_hydra.h
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@

/*!
* \brief Declares a setDataStorage getter function
* \param getname: The name of the getter function
* \param varname: The name of the variable
* \param classtype: The type of the class to be defined
* \param vartype: The ctype of the variable
Expand Down Expand Up @@ -605,6 +604,10 @@ namespace tardigradeHydra{

T * value;

auto begin( ){ return std::begin( *value ); }

auto end( ){ return std::end( *value ); }

void zero( ){ _ds->zero( ); }

void zero( const unsigned int size ){ _ds->zero( size ); }
Expand Down Expand Up @@ -1120,6 +1123,9 @@ namespace tardigradeHydra{
//! Get the number of terms in the unknown vector
virtual const unsigned int getNumUnknowns( ){ return ( *getNumConfigurations( ) ) * ( *getConfigurationUnknownCount( ) ) + *getNumNonLinearSolveStateVariables( ); }

//! Get the number of additional degrees of freedom
virtual const unsigned int getNumAdditionalDOF( ){ return getAdditionalDOF( )->size( ); }

//! Get the value of the number of constraint equations
virtual const unsigned int getNumConstraints( ){

Expand Down
232 changes: 232 additions & 0 deletions src/cpp/tardigrade_hydraLinearTestMaterial.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,232 @@
/**
******************************************************************************
* \file tardigrade_hydraLinearTestMaterial.cpp
******************************************************************************
* An implementation of a linear test material using the hydra framework. Used
* as an example and as the basis for more complex models.
******************************************************************************
*/

#include<tardigrade_hydraLinearTestMaterial.h>
#include<tardigrade_constitutive_tools.h>

namespace tardigradeHydra{

namespace linearTestMaterial{

void residual::decomposeParameterVector( const floatVector &parameters ){
/*!
* Decompose the parameter vector
*
* \param &parameters: The paramter vector. Assumed to be a vector of length 2 which defines lambda and mu.
*/

TARDIGRADE_ERROR_TOOLS_EVAL(
const unsigned int expected_parameter_size = ( *getNumEquations( ) ) * ( hydra->getNumAdditionalDOF( ) + 9 + 1 )
)

TARDIGRADE_ERROR_TOOLS_CHECK(
parameters.size( ) == expected_parameter_size,
"Parameter vector is expected to have a length of " + std::to_string( expected_parameter_size ) + " but has a length of " + std::to_string( parameters.size( ) )
);

// Decompose the parameter vector
set_F_params( floatVector( std::begin( parameters ), std::begin( parameters ) + ( *getNumEquations( ) ) * ( 9 ) ) );

set_T_params( floatVector( std::begin( parameters ) + ( *getNumEquations( ) ) * ( 9 ), std::begin( parameters ) + ( *getNumEquations( ) ) * ( 9 + 1 ) ) );

set_add_dof_params( floatVector( std::begin( parameters ) + ( *getNumEquations( ) ) * ( 9 + 1 ), std::end( parameters ) ) );

}

void residual::setXPred( ){
/*!
* Compute all of the values of the X vector for the residual calculation
*/

constexpr unsigned int dim = 3;

auto F_params = get_F_params( );

auto T_params = get_T_params( );

auto add_dof_params = get_add_dof_params( );

auto XPred = get_setDataStorage_XPred( );

XPred.zero( *getNumEquations( ) );

unsigned int i = 0;

for
(
auto xi = XPred.begin( );
xi != XPred.end( );
++i, ++xi
)
{

unsigned int j = 0;

// Add the contributions from the deformation gradient
for
(
auto v = std::begin( *hydra->getDeformationGradient( ) );
v != std::end( *hydra->getDeformationGradient( ) );
++j, ++v
)
{

*xi += ( *F_params )[ dim * dim * i + j ] * ( *v );

}

// Add the contributions from the temperature
*xi += ( *T_params )[ i ] * ( *( hydra->getTemperature( ) ) );

// Add the contributions from the additional degrees of freedom
j = 0;
for
(
auto v = std::begin( *hydra->getAdditionalDOF( ) );
v != std::end( *hydra->getAdditionalDOF( ) );
++j, ++v
)
{

*xi += ( *add_dof_params )[ hydra->getNumAdditionalDOF( ) * i + j ] * ( *v );

}

}

}

void residual::setStress( ){
/*!
* Set the stress
*
* Currently uses the Cauchy stress
*/

constexpr unsigned int dim = 3;

auto stress = get_setDataStorage_stress( );

stress.zero( dim * dim );

std::copy(
std::begin( *get_XPred( ) ),
std::begin( *get_XPred( ) ) + dim * dim,
std::begin( *stress.value )
);

}

void residual::setPreviousStress( ){
/*!
* Set the previous stress
*
* Currently uses the Cauchy stress
*/

TARDIGRADE_ERROR_TOOLS_CATCH( throw std::runtime_error( "Not implemented" ) );

}

void residual::setResidual( ){
/*!
* Set the residual value
*/

auto residual = get_setDataStorage_residual( );

residual.zero( *getNumEquations( ) );

std::transform(
std::begin( *get_XPred( ) ),
std::end( *get_XPred( ) ),
std::begin( *( hydra->getUnknownVector( ) ) ),
residual.begin( ),
std::minus< floatType >{}
);

}

void residual::setJacobian( ){
/*!
* Set the Jacobian value
*/

auto jacobian = get_setDataStorage_jacobian( );

jacobian.zero( ( *getNumEquations( ) ) * hydra->getNumUnknowns( ) );

for
(
unsigned int i = 0;
i < std::min( ( *getNumEquations( ) ), hydra->getNumUnknowns( ) );
++i
)
{
( *jacobian.value )[ ( *getNumEquations( ) ) * i + i ] = -1;
}

}

void residual::setdRdT( ){
/*!
* Set the derivative of the residual w.r.t. the temperature
*/

auto dRdT = get_setDataStorage_dRdT( );

dRdT.zero( ( *getNumEquations( ) ) );

std::copy(
std::begin( *get_T_params( ) ),
std::end( *get_T_params( ) ),
dRdT.begin( )
);

}

void residual::setdRdF( ){
/*!
* Set the derivative of the residual w.r.t. the deformation gradient
*/

constexpr unsigned int dim = 3;

auto dRdF = get_setDataStorage_dRdF( );

dRdF.zero( ( *getNumEquations( ) ) * dim * dim );

std::copy(
std::begin( *get_F_params( ) ),
std::end( *get_F_params( ) ),
dRdF.begin( )
);

}

void residual::setdRdAdditionalDOF( ){
/*!
* Set the derivative of the residual w.r.t. the additional DOF
*/

auto dRdAdditionalDOF = get_setDataStorage_dRdAdditionalDOF( );

dRdAdditionalDOF.zero( ( *getNumEquations( ) ) * ( hydra->getNumAdditionalDOF( ) ) );

std::copy(
std::begin( *get_add_dof_params( ) ),
std::end( *get_add_dof_params( ) ),
dRdAdditionalDOF.begin( )
);

}

}

}
Loading
Loading