Skip to content

Commit

Permalink
Add temperature-based models
Browse files Browse the repository at this point in the history
  • Loading branch information
streeve committed May 8, 2024
1 parent 8912646 commit b1cae3a
Show file tree
Hide file tree
Showing 4 changed files with 149 additions and 32 deletions.
45 changes: 44 additions & 1 deletion src/CabanaPD_ForceModels.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,52 @@ struct BaseForceModel
: delta( _delta ){};

BaseForceModel( const BaseForceModel& model ) { delta = model.delta; }

// No-op for temperature.
KOKKOS_INLINE_FUNCTION
void thermalStretch( double&, const int, const int ) const {}
};

template <typename TemperatureType>
struct BaseTemperatureModel
{
double alpha;
double temp0;

// Temperature field
TemperatureType temperature;

BaseTemperatureModel(){};
BaseTemperatureModel( const TemperatureType _temp, const double _alpha,
const double _temp0 )
: alpha( _alpha )
, temp0( _temp0 )
, temperature( _temp ){};

BaseTemperatureModel( const BaseTemperatureModel& model )
{
alpha = model.alpha;
temp0 = model.temp0;
temperature = model.temperature;
}

void set_param( const double _alpha, const double _temp0 )
{
alpha = _alpha;
temp0 = _temp0;
}

// Update stretch with temperature effects.
KOKKOS_INLINE_FUNCTION
void thermalStretch( double& s, const int i, const int j ) const
{
double temp_avg = 0.5 * ( temperature( i ) + temperature( j ) ) - temp0;
s -= alpha * temp_avg;
}
};

template <typename ModelType, typename DamageType>
template <typename ModelType, typename DamageType,
typename ThermalType = TemperatureIndependent, typename... DataTypes>
struct ForceModel;

} // namespace CabanaPD
Expand Down
6 changes: 6 additions & 0 deletions src/CabanaPD_Types.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,12 @@ struct Elastic
struct Fracture
{
};
struct TemperatureDependent
{
};
struct TemperatureIndependent
{
};

struct PMB
{
Expand Down
62 changes: 58 additions & 4 deletions src/force/CabanaPD_ForceModels_PMB.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,12 @@
namespace CabanaPD
{
template <>
struct ForceModel<PMB, Elastic> : public BaseForceModel
struct ForceModel<PMB, Elastic, TemperatureIndependent> : public BaseForceModel
{
using base_type = BaseForceModel;
using base_model = PMB;
using fracture_type = Elastic;
using thermal_type = TemperatureIndependent;

using base_type::delta;

Expand Down Expand Up @@ -52,7 +53,8 @@ struct ForceModel<PMB, Elastic> : public BaseForceModel
};

template <>
struct ForceModel<PMB, Fracture> : public ForceModel<PMB, Elastic>
struct ForceModel<PMB, Fracture, TemperatureIndependent>
: public ForceModel<PMB, Elastic, TemperatureIndependent>
{
using base_type = ForceModel<PMB, Elastic>;
using base_model = typename base_type::base_model;
Expand Down Expand Up @@ -90,7 +92,8 @@ struct ForceModel<PMB, Fracture> : public ForceModel<PMB, Elastic>
};

template <>
struct ForceModel<LinearPMB, Elastic> : public ForceModel<PMB, Elastic>
struct ForceModel<LinearPMB, Elastic, TemperatureIndependent>
: public ForceModel<PMB, Elastic, TemperatureIndependent>
{
using base_type = ForceModel<PMB, Elastic>;
using base_model = typename base_type::base_model;
Expand All @@ -104,7 +107,8 @@ struct ForceModel<LinearPMB, Elastic> : public ForceModel<PMB, Elastic>
};

template <>
struct ForceModel<LinearPMB, Fracture> : public ForceModel<PMB, Fracture>
struct ForceModel<LinearPMB, Fracture, TemperatureIndependent>
: public ForceModel<PMB, Fracture, TemperatureIndependent>
{
using base_type = ForceModel<PMB, Fracture>;
using base_model = typename base_type::base_model;
Expand All @@ -121,6 +125,56 @@ struct ForceModel<LinearPMB, Fracture> : public ForceModel<PMB, Fracture>
using base_type::s0;
};

template <typename TemperatureType>
struct ForceModel<PMB, Elastic, TemperatureDependent, TemperatureType>
: public ForceModel<PMB, Elastic, TemperatureIndependent>,
BaseTemperatureModel<TemperatureType>
{
using base_type = ForceModel<PMB, Elastic, TemperatureIndependent>;
using base_temperature_type = BaseTemperatureModel<TemperatureType>;
using base_model = PMB;
using fracture_type = Elastic;
using thermal_type = TemperatureDependent;

using base_type::c;
using base_type::delta;
using base_type::K;

// Thermal coefficients
using base_temperature_type::alpha;
using base_temperature_type::temp0;

// Explicitly use the temperature-dependent stretch.
using base_temperature_type::thermalStretch;

// ForceModel(){};
ForceModel( const double _delta, const double _K,
const TemperatureType _temp, const double _alpha,
const double _temp0 = 0.0 )
: base_type( _delta, _K )
, base_temperature_type( _temp, _alpha, _temp0 )
{
set_param( _delta, _K, _alpha, _temp0 );
}

void set_param( const double _delta, const double _K, const double _alpha,
const double _temp0 )
{
base_type::set_param( _delta, _K );
base_temperature_type::set_param( _alpha, _temp0 );
}
};

template <typename ModelType, typename DamageType, typename ThermalType,
typename ParticleType>
auto createForceModel( ParticleType particles, const double delta,
const double K, const double alpha, const double temp0 )
{
auto temp = particles.sliceTemperature();
using temp_type = decltype( temp );
return ForceModel<ModelType, DamageType, ThermalType, temp_type>(
delta, K, temp, alpha, temp0 );
}
} // namespace CabanaPD

#endif
68 changes: 41 additions & 27 deletions src/force/CabanaPD_Force_PMB.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -69,17 +69,19 @@

namespace CabanaPD
{
template <class ExecutionSpace>
class Force<ExecutionSpace, ForceModel<PMB, Elastic>>
template <class ExecutionSpace, class... ModelParams>
class Force<ExecutionSpace, ForceModel<PMB, Elastic, ModelParams...>>
{
public:
using exec_space = ExecutionSpace;
using model_type = ForceModel<PMB, Elastic, ModelParams...>;

protected:
bool _half_neigh;
ForceModel<PMB, Elastic> _model;
model_type _model;

public:
using exec_space = ExecutionSpace;

Force( const bool half_neigh, const ForceModel<PMB, Elastic> model )
Force( const bool half_neigh, const model_type model )
: _half_neigh( half_neigh )
, _model( model )
{
Expand All @@ -103,7 +105,7 @@ class Force<ExecutionSpace, ForceModel<PMB, Elastic>>
const NeighListType& neigh_list, const int n_local,
ParallelType& neigh_op_tag ) const
{
auto c = _model.c;
auto model = _model;
const auto vol = particles.sliceVolume();

auto force_full = KOKKOS_LAMBDA( const int i, const int j )
Expand All @@ -115,7 +117,10 @@ class Force<ExecutionSpace, ForceModel<PMB, Elastic>>
double xi, r, s;
double rx, ry, rz;
getDistanceComponents( x, u, i, j, xi, r, s, rx, ry, rz );
const double coeff = c * s * vol( j );

model.thermalStretch( s, i, j );

const double coeff = model.c * s * vol( j );
fx_i = coeff * rx / r;
fy_i = coeff * ry / r;
fz_i = coeff * rz / r;
Expand Down Expand Up @@ -167,19 +172,22 @@ class Force<ExecutionSpace, ForceModel<PMB, Elastic>>
}
};

template <class ExecutionSpace>
class Force<ExecutionSpace, ForceModel<PMB, Fracture>>
: public Force<ExecutionSpace, ForceModel<PMB, Elastic>>
template <class ExecutionSpace, class... ModelParams>
class Force<ExecutionSpace, ForceModel<PMB, Fracture, ModelParams...>>
: public Force<ExecutionSpace, ForceModel<PMB, Elastic, ModelParams...>>
{
public:
using exec_space = ExecutionSpace;
using model_type = ForceModel<PMB, Fracture>;

protected:
using base_type = Force<ExecutionSpace, ForceModel<PMB, Elastic>>;
using base_type =
Force<ExecutionSpace, ForceModel<PMB, Elastic, ModelParams...>>;
using base_type::_half_neigh;
ForceModel<PMB, Fracture> _model;
model_type _model;

public:
using exec_space = ExecutionSpace;

Force( const bool half_neigh, const ForceModel<PMB, Fracture> model )
Force( const bool half_neigh, const model_type model )
: base_type( half_neigh, model )
, _model( model )
{
Expand All @@ -192,7 +200,7 @@ class Force<ExecutionSpace, ForceModel<PMB, Fracture>>
const NeighListType& neigh_list, MuView& mu,
const int n_local, ParallelType& ) const
{
auto c = _model.c;
auto model = _model;
auto break_coeff = _model.bond_break_coeff;
const auto vol = particles.sliceVolume();
const auto nofail = particles.sliceNoFail();
Expand All @@ -217,6 +225,8 @@ class Force<ExecutionSpace, ForceModel<PMB, Fracture>>
double rx, ry, rz;
getDistanceComponents( x, u, i, j, xi, r, s, rx, ry, rz );

model.thermalStretch( s, i, j );

// Break if beyond critical stretch unless in no-fail zone.
if ( r * r >= break_coeff * xi * xi && !nofail( i ) &&
!nofail( j ) )
Expand All @@ -226,7 +236,7 @@ class Force<ExecutionSpace, ForceModel<PMB, Fracture>>
// Else if statement is only for performance.
else if ( mu( i, n ) > 0 )
{
const double coeff = c * s * vol( j );
const double coeff = model.c * s * vol( j );
double muij = mu( i, n );
fx_i = muij * coeff * rx / r;
fy_i = muij * coeff * ry / r;
Expand Down Expand Up @@ -291,19 +301,21 @@ class Force<ExecutionSpace, ForceModel<PMB, Fracture>>
}
};

template <class ExecutionSpace>
class Force<ExecutionSpace, ForceModel<LinearPMB, Elastic>>
: public Force<ExecutionSpace, ForceModel<PMB, Elastic>>
template <class ExecutionSpace, class... ModelParams>
class Force<ExecutionSpace, ForceModel<LinearPMB, Elastic, ModelParams...>>
: public Force<ExecutionSpace, ForceModel<PMB, Elastic, ModelParams...>>
{
public:
using exec_space = ExecutionSpace;
using model_type = ForceModel<LinearPMB, Elastic>;

protected:
using base_type = Force<ExecutionSpace, ForceModel<PMB, Elastic>>;
using base_type::_half_neigh;
ForceModel<LinearPMB, Elastic> _model;
model_type _model;

public:
using exec_space = ExecutionSpace;

Force( const bool half_neigh, const ForceModel<LinearPMB, Elastic> model )
Force( const bool half_neigh, const model_type model )
: base_type( half_neigh, model )
, _model( model )
{
Expand All @@ -316,7 +328,7 @@ class Force<ExecutionSpace, ForceModel<LinearPMB, Elastic>>
const NeighListType& neigh_list, const int n_local,
ParallelType& neigh_op_tag ) const
{
auto c = _model.c;
auto model = _model;
const auto vol = particles.sliceVolume();

auto force_full = KOKKOS_LAMBDA( const int i, const int j )
Expand All @@ -331,7 +343,9 @@ class Force<ExecutionSpace, ForceModel<LinearPMB, Elastic>>
getLinearizedDistanceComponents( x, u, i, j, xi, linear_s, xi_x,
xi_y, xi_z );

const double coeff = c * linear_s * vol( j );
model.thermalStretch( linear_s, i, j );

const double coeff = model.c * linear_s * vol( j );
fx_i = coeff * xi_x / xi;
fy_i = coeff * xi_y / xi;
fz_i = coeff * xi_z / xi;
Expand Down

0 comments on commit b1cae3a

Please sign in to comment.