https://mooseframework.inl.gov
Loading...
Searching...
No Matches
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
16 NSFVMixtureMaterial,
17 "08/01/2024 00:00",
19
20template <bool is_ad>
23{
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
39template <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 =
69 ? (is_ad ? std::max(std::min(_phase_1_fraction(r, t), (GenericReal<is_ad>)1),
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
Moose::GenericType< Real, is_ad > GenericReal
registerMooseObject("NavierStokesApp", WCNSLinearFVMixtureFunctorMaterial)
registerMooseObjectRenamed("NavierStokesApp", NSFVMixtureMaterial, "08/01/2024 00:00", NSFVMixtureFunctorMaterial)
const Moose::Functor< T > & getFunctor(const std::string &name)
static InputParameters validParams()
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)
void paramError(const std::string &param, Args... args) const
This is the material class used to compute phase averaged properties of mixtures.
const std::vector< MooseFunctorName > _phase_1_names
Vector of phase 1 properties names.
const std::vector< MooseFunctorName > _phase_2_names
Vector of phase 2 properties names.
std::vector< const Moose::Functor< GenericReal< is_ad > > * > _phase_1_properties
Vector of phase 1 properties.
const std::vector< MooseFunctorName > _mixture_names
Vector of mixture properties names.
const Moose::Functor< GenericReal< is_ad > > & _phase_1_fraction
Phase 1 fraction.
NSFVMixtureFunctorMaterialTempl(const InputParameters &parameters)
const bool _limit_pf
Whether to bound the phase fraction between 0 and 1 to avoid outlandish properties.
std::vector< const Moose::Functor< GenericReal< is_ad > > * > _phase_2_properties
Vector of phase 2 properties.