https://mooseframework.inl.gov
NSFVMixtureFunctorMaterial.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 #include "NS.h"
12 
15 registerMooseObjectRenamed("NavierStokesApp",
16  NSFVMixtureMaterial,
17  "08/01/2024 00:00",
19 
20 template <bool is_ad>
23 {
25  params.addClassDescription(
26  "Compute the arithmetic mean of material properties using a phase fraction.");
27  params.addRequiredParam<std::vector<MooseFunctorName>>(
28  "phase_1_names", "The names of the properties for phase 1.");
29  params.addRequiredParam<std::vector<MooseFunctorName>>(
30  "phase_2_names", "The names of the properties for phase 2.");
31  params.addRequiredParam<std::vector<MooseFunctorName>>(
32  "prop_names", "The name of the mixture properties output from the material.");
33  params.addRequiredParam<MooseFunctorName>("phase_1_fraction", "Phase 1 fraction.");
34  params.addParam<bool>(
35  "limit_phase_fraction", false, "Whether to bound the phase fraction between 0 and 1");
36  return params;
37 }
38 
39 template <bool is_ad>
41  const InputParameters & parameters)
42  : FunctorMaterial(parameters),
43  _phase_1_names(getParam<std::vector<MooseFunctorName>>("phase_1_names")),
44  _phase_2_names(getParam<std::vector<MooseFunctorName>>("phase_2_names")),
45  _mixture_names(getParam<std::vector<MooseFunctorName>>("prop_names")),
46  _phase_1_fraction(getFunctor<GenericReal<is_ad>>("phase_1_fraction")),
47  _limit_pf(getParam<bool>("limit_phase_fraction"))
48 {
49 
50  if (_phase_1_names.size() != _phase_2_names.size())
51  paramError("phase_2_names", "Phase 1 and Phase 2 names do not have the same length.");
52 
53  if (_phase_1_names.size() != _mixture_names.size())
54  paramError("prop_names", "Phase 1 and mixture property names do not have the same length.");
55 
56  for (const auto prop_index : index_range(_phase_1_names))
57  {
60 
61  addFunctorProperty<GenericReal<is_ad>>(
62  _mixture_names[prop_index],
63  [this, prop_index](const auto & r, const auto & t) -> GenericReal<is_ad>
64  {
65  // Avoid messing up the fluid properties, but keep the same dependencies
66  // AD-version needs to preserve sparsity pattern
67  const auto phase_1_fraction =
68  _limit_pf
69  ? (is_ad ? std::max(std::min(_phase_1_fraction(r, t), (GenericReal<is_ad>)1),
70  (GenericReal<is_ad>)0) +
71  0 * _phase_1_fraction(r, t)
72  : std::max(std::min(_phase_1_fraction(r, t), (GenericReal<is_ad>)1),
74  : _phase_1_fraction(r, t);
75  return phase_1_fraction * (*_phase_1_properties[prop_index])(r, t) +
76  (1.0 - phase_1_fraction) * (*_phase_2_properties[prop_index])(r, t);
77  });
78  }
79 }
80 
const bool _limit_pf
Whether to bound the phase fraction between 0 and 1 to avoid outlandish properties.
NSFVMixtureFunctorMaterialTempl(const InputParameters &parameters)
Moose::GenericType< Real, is_ad > GenericReal
const Moose::Functor< GenericReal< is_ad > > & _phase_1_fraction
Phase 1 fraction.
static InputParameters validParams()
void addParam(const std::string &name, const std::initializer_list< typename T::value_type > &value, const std::string &doc_string)
std::vector< const Moose::Functor< GenericReal< is_ad > > * > _phase_2_properties
Vector of phase 2 properties.
registerMooseObject("NavierStokesApp", WCNSLinearFVMixtureFunctorMaterial)
std::vector< const Moose::Functor< GenericReal< is_ad > > * > _phase_1_properties
Vector of phase 1 properties.
This is the material class used to compute phase averaged properties of mixtures. ...
const std::vector< MooseFunctorName > _phase_2_names
Vector of phase 2 properties names.
void addRequiredParam(const std::string &name, const std::string &doc_string)
const std::vector< MooseFunctorName > _mixture_names
Vector of mixture properties names.
void paramError(const std::string &param, Args... args) const
registerMooseObjectRenamed("NavierStokesApp", NSFVMixtureMaterial, "08/01/2024 00:00", NSFVMixtureFunctorMaterial)
const Moose::Functor< T > & getFunctor(const std::string &name)
const std::vector< MooseFunctorName > _phase_1_names
Vector of phase 1 properties names.
void addClassDescription(const std::string &doc_string)
auto index_range(const T &sizable)