https://mooseframework.inl.gov
Loading...
Searching...
No Matches
LinearFVPhaseChangeSource.C
Go to the documentation of this file.
1//* This file is part of the MOOSE framework
2//* https://mooseframework.inl.gov
3//*
4//* All rights reserved, see COPYRIGHT for full restrictions
5//* https://github.com/idaholab/moose/blob/master/COPYRIGHT
6//*
7//* Licensed under LGPL 2.1, please see LICENSE for details
8//* https://www.gnu.org/licenses/lgpl-2.1.html
9
11
12#include "MooseEnum.h"
13
14#include <algorithm>
15
17
20{
22
24 "Linear FV elemental kernel that adds the apparent heat-capacity "
25 "phase-change source term: rho * L * (df/dT) * T_dot, with f the liquid "
26 "fraction.");
27
28 params.addRequiredParam<MooseFunctorName>("L", "Latent heat.");
29 params.addRequiredParam<MooseFunctorName>(NS::density, "The mixture density.");
30 params.addRequiredParam<MooseFunctorName>("T_solidus", "The solidus temperature.");
31 params.addRequiredParam<MooseFunctorName>("T_liquidus", "The liquidus temperature.");
32
33 MooseEnum smoothing("smooth sharp", "smooth");
34 params.addParam<MooseEnum>(
35 "smoothing",
36 smoothing,
37 "Shape of the liquid fraction over the mushy interval. 'smooth' (default) uses a "
38 "smoothstep cubic function and 'sharp' uses a linear liquid fraction.");
39
40 return params;
41}
42
45 _L(getFunctor<Real>("L")),
46 _rho(getFunctor<Real>(NS::density)),
47 _T_solidus(getFunctor<Real>("T_solidus")),
48 _T_liquidus(getFunctor<Real>("T_liquidus")),
49 _smooth(getParam<MooseEnum>("smoothing") == "smooth"),
50 _time_integrator(_sys.getTimeIntegrator(_var_num)),
51 _factor_history(_time_integrator.numStatesRequired(), 0.0),
52 _state_args(_time_integrator.numStatesRequired(), determineState())
53{
54}
55
56Real
57LinearFVPhaseChangeSource::computeDfDT(const Real T, const Real T_sol, const Real dT_pc) const
58{
59 if (_smooth)
60 {
61 // f(s) = 3 s^2 - 2 s^3 => df/dT = 6 s (1 - s) / dT_pc
62 const Real s = std::clamp((T - T_sol) / dT_pc, 0.0, 1.0);
63 return 6.0 * s * (1.0 - s) / dT_pc;
64 }
65
66 // Sharp: linear liquid fraction, i.e. a top-hat derivative over the open mushy interval
67 if (T > T_sol && T < T_sol + dT_pc)
68 return 1.0 / dT_pc;
69 return 0.0;
70}
71
72Real
74{
75 // Element context
76 const auto state = determineState();
77 const auto elem_arg = makeElemArg(_current_elem_info->elem());
78
79 const Real T_sol = _T_solidus(elem_arg, state);
80 const Real T_liq = _T_liquidus(elem_arg, state);
81 const Real dT_pc = T_liq - T_sol;
82
83 // Guard against degenerate or inverted mushy interval
84 if (dT_pc <= 0.0)
85 return 0.0;
86
87 const Real T = _var.getElemValue(*_current_elem_info, state);
88 const Real dfdT = computeDfDT(T, T_sol, dT_pc);
89
90 // Apparent heat capacity term rho * L * (df/dT) * T_dot
91 const Real rhoL = _rho(elem_arg, state) * _L(elem_arg, state);
92 const Real Tdot_coeff = _time_integrator.timeDerivativeMatrixContribution(1.0);
93
94 return rhoL * dfdT * Tdot_coeff * _current_elem_volume;
95}
96
97Real
99{
100 // Element context
101 const auto state = determineState();
102 const auto elem_arg = makeElemArg(_current_elem_info->elem());
103
104 const Real T_sol = _T_solidus(elem_arg, state);
105 const Real T_liq = _T_liquidus(elem_arg, state);
106 const Real dT_pc = T_liq - T_sol;
107
108 // Guard against degenerate or inverted mushy interval
109 if (dT_pc <= 0.0)
110 return 0.0;
111
112 const Real T = _var.getElemValue(*_current_elem_info, state);
113 const Real dfdT = computeDfDT(T, T_sol, dT_pc);
114
115 // Apparent heat capacity term rho * L * (df/dT) * T_dot (explicit RHS part)
116 const Real rhoL = _rho(elem_arg, state) * _L(elem_arg, state);
118
119 return rhoL * dfdT * Told_dt * _current_elem_volume;
120}
121
122void
124{
126 for (const auto i : index_range(_factor_history))
127 _factor_history[i] = 1.0;
128}
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