Skip to content

Commit

Permalink
Clean up code in ThermalContactCondition and fix broken potential var…
Browse files Browse the repository at this point in the history
…iable retrieval bug (#13)
  • Loading branch information
cticenhour committed Jun 30, 2022
1 parent f0fb3ec commit ceb4ff2
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 17 deletions.
3 changes: 3 additions & 0 deletions include/interfacekernels/ThermalContactCondition.h
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,9 @@ class ThermalContactCondition : public ADInterfaceKernel
/// The electrostatic potential value associated with the primary side of the interface
const ADVariableValue & _potential_primary;

// The electrostatic potential variable associated with the secondary side of the interface
const MooseVariable * _secondary_potential_var;

/// The electrostatic potential value associated with the secondary side of the interface
const ADVariableValue & _potential_secondary;

Expand Down
44 changes: 27 additions & 17 deletions src/interfacekernels/ThermalContactCondition.C
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,8 @@ ThermalContactCondition::validParams()
"User-provided thermal contact conductance coefficient.");
params.addParam<Real>("user_electrical_contact_conductance",
"User-provided electrical contact conductance coefficient.");
params.addRequiredCoupledVar("primary_potential", "Electrostatic potential on the primary block.");
params.addRequiredCoupledVar("primary_potential",
"Electrostatic potential on the primary block.");
params.addRequiredCoupledVar("secondary_potential",
"Electrostatic potential on the secondary block.");
params.addParam<Real>("splitting_factor", 0.5, "Splitting factor of the Joule heating source.");
Expand All @@ -47,7 +48,8 @@ ThermalContactCondition::ThermalContactCondition(const InputParameters & paramet
_thermal_conductivity_primary(getADMaterialProperty<Real>("primary_thermal_conductivity")),
_thermal_conductivity_secondary(
getNeighborADMaterialProperty<Real>("secondary_thermal_conductivity")),
_electrical_conductivity_primary(getADMaterialProperty<Real>("primary_electrical_conductivity")),
_electrical_conductivity_primary(
getADMaterialProperty<Real>("primary_electrical_conductivity")),
_electrical_conductivity_secondary(
getNeighborADMaterialProperty<Real>("secondary_electrical_conductivity")),
_user_thermal_contact_conductance(isParamValid("user_thermal_contact_conductance")
Expand All @@ -57,7 +59,8 @@ ThermalContactCondition::ThermalContactCondition(const InputParameters & paramet
? getParam<Real>("user_electrical_contact_conductance")
: _real_zero),
_potential_primary(adCoupledValue("primary_potential")),
_potential_secondary(adCoupledValue("secondary_potential")),
_secondary_potential_var(getVar("secondary_potential", 0)),
_potential_secondary(_secondary_potential_var->adSlnNeighbor()),
_splitting_factor(getParam<Real>("splitting_factor")),
_mean_hardness(isParamValid("user_thermal_contact_conductance")
? getGenericZeroMaterialProperty<Real, true>("mean_hardness")
Expand All @@ -83,14 +86,6 @@ ThermalContactCondition::computeQpResidual(Moose::DGResidualType type)
ADReal thermal_contact_conductance = 0.0;
ADReal electrical_contact_conductance = 0.0;

ADReal mean_thermal_conductivity =
2 * _thermal_conductivity_primary[_qp] * _thermal_conductivity_secondary[_qp] /
(_thermal_conductivity_primary[_qp] + _thermal_conductivity_secondary[_qp]);

ADReal mean_electrical_conductivity =
2 * _electrical_conductivity_primary[_qp] * _electrical_conductivity_secondary[_qp] /
(_electrical_conductivity_primary[_qp] + _electrical_conductivity_secondary[_qp]);

if (_electrical_conductance_was_set && _thermal_conductance_was_set && !_mean_hardness_was_set)
{
thermal_contact_conductance = _user_thermal_contact_conductance;
Expand All @@ -99,6 +94,14 @@ ThermalContactCondition::computeQpResidual(Moose::DGResidualType type)
else if (_mean_hardness_was_set && !_thermal_conductance_was_set &&
!_electrical_conductance_was_set)
{
ADReal mean_thermal_conductivity =
2 * _thermal_conductivity_primary[_qp] * _thermal_conductivity_secondary[_qp] /
(_thermal_conductivity_primary[_qp] + _thermal_conductivity_secondary[_qp]);

ADReal mean_electrical_conductivity =
2 * _electrical_conductivity_primary[_qp] * _electrical_conductivity_secondary[_qp] /
(_electrical_conductivity_primary[_qp] + _electrical_conductivity_secondary[_qp]);

thermal_contact_conductance =
_alpha_thermal * mean_thermal_conductivity *
std::pow((_mechanical_pressure / _mean_hardness[_qp]), _beta_thermal);
Expand All @@ -119,19 +122,26 @@ ThermalContactCondition::computeQpResidual(Moose::DGResidualType type)

ADReal potential_diff = _potential_primary[_qp] - _potential_secondary[_qp];

ADReal q_electric = electrical_contact_conductance * potential_diff * potential_diff;
ADReal q_electric_primary =
_splitting_factor * electrical_contact_conductance * potential_diff * potential_diff;

ADReal q_electric_secondary =
(1 - _splitting_factor) * electrical_contact_conductance * potential_diff * potential_diff;

ADReal q_temperature = thermal_contact_conductance * (_u[_qp] - _neighbor_value[_qp]);

ADReal res = 0.0;

switch (type)
{
case Moose::Element:
return (q_temperature - _splitting_factor * q_electric) * _test[_i][_qp];
res = (q_temperature - q_electric_primary) * _test[_i][_qp];
break;

case Moose::Neighbor:
return -(q_temperature + (1 - _splitting_factor) * q_electric) * _test_neighbor[_i][_qp];

default:
return 0.0;
res = -(q_temperature + q_electric_secondary) * _test_neighbor[_i][_qp];
break;
}

return res;
}

0 comments on commit ceb4ff2

Please sign in to comment.