https://mooseframework.inl.gov
Loading...
Searching...
No Matches
LinearFVPhaseChangeSource.C
Go to the documentation of this file.
2
3#include "MooseEnum.h"
4
5#include <algorithm>
6
8
11{
13
15 "Linear FV elemental kernel that adds the apparent heat-capacity "
16 "phase-change source term: rho * L * (df/dT) * T_dot, with f the liquid "
17 "fraction.");
18
19 params.addRequiredParam<MooseFunctorName>("L", "Latent heat.");
20 params.addRequiredParam<MooseFunctorName>(NS::density, "The mixture density.");
21 params.addRequiredParam<MooseFunctorName>("T_solidus", "The solidus temperature.");
22 params.addRequiredParam<MooseFunctorName>("T_liquidus", "The liquidus temperature.");
23
24 MooseEnum smoothing("smooth sharp", "smooth");
25 params.addParam<MooseEnum>(
26 "smoothing",
27 smoothing,
28 "Shape of the liquid fraction over the mushy interval. 'smooth' (default) uses a "
29 "smoothstep cubic function and 'sharp' uses a linear liquid fraction.");
30
31 return params;
32}
33
36 _L(getFunctor<Real>("L")),
37 _rho(getFunctor<Real>(NS::density)),
38 _T_solidus(getFunctor<Real>("T_solidus")),
39 _T_liquidus(getFunctor<Real>("T_liquidus")),
40 _smooth(getParam<MooseEnum>("smoothing") == "smooth"),
41 _time_integrator(_sys.getTimeIntegrator(_var_num)),
42 _factor_history(_time_integrator.numStatesRequired(), 0.0),
43 _state_args(_time_integrator.numStatesRequired(), determineState())
44{
45}
46
47Real
48LinearFVPhaseChangeSource::computeDfDT(const Real T, const Real T_sol, const Real dT_pc) const
49{
50 if (_smooth)
51 {
52 // f(s) = 3 s^2 - 2 s^3 => df/dT = 6 s (1 - s) / dT_pc
53 const Real s = std::clamp((T - T_sol) / dT_pc, 0.0, 1.0);
54 return 6.0 * s * (1.0 - s) / dT_pc;
55 }
56
57 // Sharp: linear liquid fraction, i.e. a top-hat derivative over the open mushy interval
58 if (T > T_sol && T < T_sol + dT_pc)
59 return 1.0 / dT_pc;
60 return 0.0;
61}
62
63Real
65{
66 // Element context
67 const auto state = determineState();
68 const auto elem_arg = makeElemArg(_current_elem_info->elem());
69
70 const Real T_sol = _T_solidus(elem_arg, state);
71 const Real T_liq = _T_liquidus(elem_arg, state);
72 const Real dT_pc = T_liq - T_sol;
73
74 // Guard against degenerate or inverted mushy interval
75 if (dT_pc <= 0.0)
76 return 0.0;
77
78 const Real T = _var.getElemValue(*_current_elem_info, state);
79 const Real dfdT = computeDfDT(T, T_sol, dT_pc);
80
81 // Apparent heat capacity term rho * L * (df/dT) * T_dot
82 const Real rhoL = _rho(elem_arg, state) * _L(elem_arg, state);
83 const Real Tdot_coeff = _time_integrator.timeDerivativeMatrixContribution(1.0);
84
85 return rhoL * dfdT * Tdot_coeff * _current_elem_volume;
86}
87
88Real
90{
91 // Element context
92 const auto state = determineState();
93 const auto elem_arg = makeElemArg(_current_elem_info->elem());
94
95 const Real T_sol = _T_solidus(elem_arg, state);
96 const Real T_liq = _T_liquidus(elem_arg, state);
97 const Real dT_pc = T_liq - T_sol;
98
99 // Guard against degenerate or inverted mushy interval
100 if (dT_pc <= 0.0)
101 return 0.0;
102
103 const Real T = _var.getElemValue(*_current_elem_info, state);
104 const Real dfdT = computeDfDT(T, T_sol, dT_pc);
105
106 // Apparent heat capacity term rho * L * (df/dT) * T_dot (explicit RHS part)
107 const Real rhoL = _rho(elem_arg, state) * _L(elem_arg, state);
109
110 return rhoL * dfdT * Told_dt * _current_elem_volume;
111}
112
113void
115{
117 for (const auto i : index_range(_factor_history))
118 _factor_history[i] = 1.0;
119}
const double T
registerMooseObject("NavierStokesApp", LinearFVPhaseChangeSource)
const Elem * elem() const
Moose::ElemArg makeElemArg(const Elem *elem, bool correct_skewnewss=false) const
void addRequiredParam(const std::string &name, const std::string &doc_string)
void addParam(const std::string &name, const std::initializer_list< typename T::value_type > &value, const std::string &doc_string)
void addClassDescription(const std::string &doc_string)
virtual void setCurrentElemInfo(const ElemInfo *elem_info)
const ElemInfo * _current_elem_info
static InputParameters validParams()
MooseLinearVariableFV< Real > & _var
Finite-volume elemental kernel that adds the apparent heat-capacity phase-change source term: rho * L...
virtual void setCurrentElemInfo(const ElemInfo *elem_info) override
static InputParameters validParams()
LinearFVPhaseChangeSource(const InputParameters &params)
Constructor.
const Moose::Functor< Real > & _rho
Density.
std::vector< Real > _factor_history
Current and older values of the material property multiplier.
const Moose::Functor< Real > & _T_solidus
Solidus Temperature.
const Moose::Functor< Real > & _T_liquidus
Liquidus Temperature.
const TimeIntegrator & _time_integrator
The time integrator to use in this kernel, will provide information on how many states are required i...
const Moose::Functor< Real > & _L
Latent heat.
const bool _smooth
Whether to use the smoothstep liquid fraction (true, default) or the linear ("sharp") liquid fraction...
Real computeDfDT(const Real T, const Real T_sol, const Real dT_pc) const
Compute df/dT at temperature T for the selected liquid-fraction shape.
virtual Real timeDerivativeRHSContribution(dof_id_type dof_id, const std::vector< Real > &factors={}) const
virtual Real timeDerivativeMatrixContribution(const Real factor) const
Real getElemValue(const ElemInfo &elem_info, const StateArg &state) const
Moose::StateArg determineState() const
static const std::string density
Definition NS.h:34