Skip to content

Commit

Permalink
Merge pull request #24863 from grmnptr/add-flow-resistance-meterial
Browse files Browse the repository at this point in the history
Add friction material with exponential relationship.
  • Loading branch information
grmnptr authored Jul 5, 2023
2 parents b12deee + ec09bb4 commit 083b79b
Show file tree
Hide file tree
Showing 16 changed files with 319 additions and 35 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# ExponentialFrictionMaterial

!syntax description /FunctorMaterials/ExponentialFrictionMaterial

This material is used to simulate friction factor correlations in the form of

\begin{equation}
f(Re) = C_1 \mathrm{Re}^{C_2}~,
\end{equation}

where $C_1$ and $C_2$ are (potentially space-dependent) constants supplied by the user.

!syntax parameters /FunctorMaterials/ExponentialFrictionMaterial

!syntax inputs /FunctorMaterials/ExponentialFrictionMaterial

!syntax children /FunctorMaterials/ExponentialFrictionMaterial
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
# ReynoldsNumberFunctorMaterial

!syntax description /FunctorMaterials/ReynoldsNumberFunctorMaterial

This material is used to compute the Reynolds number defined as:

$\mathrm{Re} = \frac{D|u| \rho}{\mu}$

where $D$ is a characteristic length, $|u|$ is the velocity magnitude, while
$\rho$ and $\mu$ are the density and dynamic viscosity of the fluid.

!syntax parameters /FunctorMaterials/ReynoldsNumberFunctorMaterial

!syntax inputs /FunctorMaterials/ReynoldsNumberFunctorMaterial

!syntax children /FunctorMaterials/ReynoldsNumberFunctorMaterial
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
//* This file is part of the MOOSE framework
//* https://www.mooseframework.org
//*
//* All rights reserved, see COPYRIGHT for full restrictions
//* https://github.com/idaholab/moose/blob/master/COPYRIGHT
//*
//* Licensed under LGPL 2.1, please see LICENSE for details
//* https://www.gnu.org/licenses/lgpl-2.1.html

#pragma once

#include "FunctorMaterial.h"

/**
* Class responsible for generating a friction factor for the
* friction-based pressure loss terms in the form of:
*
* $f(Re) = C_1 Re^{C_2}$
*
* This is common for flows in pipes. Designed to work with both
* INSFV and PINSFV friction loss kernels.
*/
class ExponentialFrictionMaterial : public FunctorMaterial
{
public:
static InputParameters validParams();
ExponentialFrictionMaterial(const InputParameters & parameters);

private:
/// Functor for the Reynolds number
const Moose::Functor<ADReal> & _Re;
/// Speed (velocity magnitude) of the fluid
const Moose::Functor<ADReal> * const _speed;
/// $C_1$ in $f(Re) = C_1 Re^{C_2}$
const Real _c1;
/// $C_2$ in $f(Re) = C_1 Re^{C_2}$
const Real _c2;
/// The name of the output friction factor functor
const std::string _friction_factor_name;
/// If a factor of velocity should be included or not
const bool _include_velocity_factor;
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
//* This file is part of the MOOSE framework
//* https://www.mooseframework.org
//*
//* All rights reserved, see COPYRIGHT for full restrictions
//* https://github.com/idaholab/moose/blob/master/COPYRIGHT
//*
//* Licensed under LGPL 2.1, please see LICENSE for details
//* https://www.gnu.org/licenses/lgpl-2.1.html

#pragma once

#include "FunctorMaterial.h"

/**
* Class responsible for generating functor for computing the Reynolds
* number
*
* $\mathrm{Re} = \frac{\rho |u| D}{\mu}$
*
* where $rho$, $|u|$, $\mu$ and $D$ are the fluid density, velocity magnitude,
* dynamic viscosity and hydraulic diameter, respectively.
*/
class ReynoldsNumberFunctorMaterial : public FunctorMaterial
{
public:
static InputParameters validParams();
ReynoldsNumberFunctorMaterial(const InputParameters & parameters);

private:
/// Speed (velocity magnitude) of the fluid
const Moose::Functor<ADReal> & _speed;
/// Functor for the dynamic viscosity
const Moose::Functor<ADReal> & _mu;
/// Functor for the density
const Moose::Functor<ADReal> & _rho;
/// Functor for the characteristic length
const Moose::Functor<Real> & _characteristic_length;
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
//* This file is part of the MOOSE framework
//* https://www.mooseframework.org
//*
//* All rights reserved, see COPYRIGHT for full restrictions
//* https://github.com/idaholab/moose/blob/master/COPYRIGHT
//*
//* Licensed under LGPL 2.1, please see LICENSE for details
//* https://www.gnu.org/licenses/lgpl-2.1.html

#include "ExponentialFrictionMaterial.h"
#include "MooseMesh.h"
#include "NS.h"

registerMooseObject("NavierStokesApp", ExponentialFrictionMaterial);

InputParameters
ExponentialFrictionMaterial::validParams()
{
InputParameters params = FunctorMaterial::validParams();
params.addClassDescription("Computes a Reynolds number-exponential friction factor.");
params.addRequiredParam<MooseFunctorName>(NS::Reynolds, "The Reynolds number.");
params.addParam<MooseFunctorName>(NS::speed, "The velocity magnitude of the fluid.");
params.addRequiredParam<Real>("c1", "c2 in c1/Re^(c2) expression.");
params.addRequiredParam<Real>("c2", "c2 in c1/Re^(c2) expression.");
params.addRequiredParam<std::string>("friction_factor_name",
"The name of the output friction factor.");
params.addParam<bool>(
"include_velocity_factor",
false,
"If a factor of velocity magnitude should be included in the friction factor. This is "
"typically the case for prorous medium Forcheimer friction therms.");
return params;
}

ExponentialFrictionMaterial::ExponentialFrictionMaterial(const InputParameters & parameters)
: FunctorMaterial(parameters),
_Re(getFunctor<ADReal>(NS::Reynolds)),
_speed(isParamValid(NS::speed) ? &getFunctor<ADReal>(NS::speed) : nullptr),
_c1(getParam<Real>("c1")),
_c2(getParam<Real>("c2")),
_friction_factor_name(getParam<std::string>("friction_factor_name")),
_include_velocity_factor(getParam<bool>("include_velocity_factor"))
{
if (_include_velocity_factor && !_speed)
paramError(NS::speed,
"To be able to include an additional multiplier in the friction factor, please "
"provide the speed of the fluid.");
addFunctorProperty<ADReal>(_friction_factor_name,
[this](const auto & r, const auto & t) -> ADReal
{
return _c1 * std::pow(_Re(r, t), _c2) *
(_include_velocity_factor ? (*_speed)(r, t) : ADReal(1.0));
});
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
//* This file is part of the MOOSE framework
//* https://www.mooseframework.org
//*
//* All rights reserved, see COPYRIGHT for full restrictions
//* https://github.com/idaholab/moose/blob/master/COPYRIGHT
//*
//* Licensed under LGPL 2.1, please see LICENSE for details
//* https://www.gnu.org/licenses/lgpl-2.1.html

#include "ReynoldsNumberFunctorMaterial.h"
#include "MooseMesh.h"
#include "NS.h"

registerMooseObject("NavierStokesApp", ReynoldsNumberFunctorMaterial);

InputParameters
ReynoldsNumberFunctorMaterial::validParams()
{
InputParameters params = FunctorMaterial::validParams();
params.addClassDescription("Computes a Reynolds number.");
params.addRequiredParam<MooseFunctorName>(NS::speed, "The velocity magnitude of the fluid.");
params.addRequiredParam<MooseFunctorName>(NS::density, "The density of the fluid.");
params.addRequiredParam<MooseFunctorName>(NS::mu, "The dynamic viscosity of the fluid.");
params.addRequiredParam<MooseFunctorName>("characteristic_length",
"The characteristic length of the geometry.");

return params;
}

ReynoldsNumberFunctorMaterial::ReynoldsNumberFunctorMaterial(const InputParameters & parameters)
: FunctorMaterial(parameters),
_speed(getFunctor<ADReal>(NS::speed)),
_mu(getFunctor<ADReal>(NS::mu)),
_rho(getFunctor<ADReal>(NS::density)),
_characteristic_length(getFunctor<Real>("characteristic_length"))
{
addFunctorProperty<ADReal>(
NS::Reynolds,
[this](const auto & r, const auto & t) -> ADReal
{ return _rho(r, t) * _speed(r, t) * _characteristic_length(r, t) / _mu(r, t); });
}
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,26 @@ rho = 1.1
prop_names = 'rho mu'
prop_values = '${rho} ${mu}'
[]
[speed_material]
type = PINSFVSpeedFunctorMaterial
superficial_vel_x = vel_x
superficial_vel_y = vel_y
porosity = 1
[]
[Re_material]
type = ReynoldsNumberFunctorMaterial
speed = speed
characteristic_length = 2
rho = ${rho}
mu = ${mu}
[]
[exponential_friction_coefficient]
type = ExponentialFrictionMaterial
friction_factor_name = 'friction_coefficient'
Re = Re
c1 = 0.25
c2 = 0.55
[]
[]

[Executioner]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -154,11 +154,32 @@ velocity_interp_method = 'rc'
[]

[Materials]
inactive = exponential_friction_coefficient
[friction_coefficient]
type = ADGenericFunctorMaterial
prop_names = 'friction_coefficient'
prop_values = '25'
[]
[speed_material]
type = PINSFVSpeedFunctorMaterial
superficial_vel_x = vel_x
superficial_vel_y = vel_y
porosity = 1
[]
[Re_material]
type = ReynoldsNumberFunctorMaterial
speed = speed
characteristic_length = 2
rho = ${rho}
mu = ${mu}
[]
[exponential_friction_coefficient]
type = ExponentialFrictionMaterial
friction_factor_name = 'friction_coefficient'
Re = Re
c1 = 0.25
c2 = 0.55
[]
[]

[Executioner]
Expand Down
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
[Tests]
issues = '#19472 #24856 #16872'
design = 'navier_stokes/insfv.md NSFVAction.md'
[linear-friction]
type = 'Exodiff'
input = 2d-rc-friction.i
exodiff = 2d-rc-friction_out.e
requirement = 'The system shall be able to model linear volumetric friction in a channel.'
design = 'INSFVMomentumFriction.md'
[]
[quadratic-friction]
type = 'Exodiff'
input = 2d-rc-friction.i
exodiff = 2d-rc-friction-quad_out.e
requirement = 'The system shall be able to model quadratic volumetric friction in a channel.'
cli_args = "Outputs/file_base='2d-rc-friction-quad_out' FVKernels/inactive='u_friction_linear "
"v_friction_linear'"
design = 'INSFVMomentumFriction.md'
[]
[exponential-friction-factor]
type = 'Exodiff'
input = 2d-rc-friction.i
exodiff = 2d-rc-friction-exp-factor_out.e
requirement = 'The system shall be able to model quadratic volumetric friction with an exponential friction factor correlation in a channel.'
cli_args = "Outputs/file_base='2d-rc-friction-exp-factor_out' "
"FVKernels/inactive='u_friction_linear v_friction_linear' "
"Materials/inactive='friction_coefficient'"
design = 'ExponentialFrictionMaterial.md'
[]
[exponential-friction-factor-jacobian]
type = PetscJacobianTester
input = 2d-rc-friction.i
requirement = 'The system shall be able to build the correct Jacobian using exponential correlation for the friction factor.'
cli_args = "Outputs/file_base='2d-rc-friction-exp-factor_out' "
"FVKernels/inactive='u_friction_linear v_friction_linear' "
"Materials/inactive='friction_coefficient' Mesh/gen/nx=4 Mesh/gen/ny=4 "
[]
[linear-friction-action]
type = 'Exodiff'
input = 2d-rc-friction-action.i
exodiff = 2d-rc-friction-action_out.e
requirement = 'The system shall be able to model linear volumetric friction in a channel using a custom action syntax.'
[]
[quadratic-friction-action]
type = 'Exodiff'
input = 2d-rc-friction-action.i
exodiff = 2d-rc-friction-action-quad_out.e
requirement = 'The system shall be able to model quadratic volumetric friction in a channel using a custom action syntax.'
cli_args = "Modules/NavierStokesFV/friction_types='forchheimer' "
"Outputs/file_base='2d-rc-friction-action-quad_out'"
[]
[exponential-friction-factor-action]
type = 'Exodiff'
input = 2d-rc-friction-action.i
exodiff = 2d-rc-friction-exp-factor-action_out.e
requirement = 'The system shall be able to model quadratic volumetric friction with an exponential friction factor correlation in a channel a custom action syntax.'
cli_args = "Modules/NavierStokesFV/friction_types='forchheimer' "
"Modules/NavierStokesFV/friction_coeffs='friction_coefficient' "
"Outputs/file_base='2d-rc-friction-exp-factor-action_out' "
design = 'ExponentialFrictionMaterial.md'
[]
[]
Loading

0 comments on commit 083b79b

Please sign in to comment.