Skip to content

Commit

Permalink
Allowing Dirichlet BCs to take state - needed for limiters Refs idaho…
Browse files Browse the repository at this point in the history
  • Loading branch information
tanoret committed Nov 26, 2024
1 parent 2a74993 commit 460817c
Show file tree
Hide file tree
Showing 30 changed files with 52 additions and 57 deletions.
2 changes: 1 addition & 1 deletion framework/include/fvbcs/FVDirichletBC.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ class FVDirichletBC : public FVDirichletBCBase

static InputParameters validParams();

ADReal boundaryValue(const FaceInfo & fi) const override;
ADReal boundaryValue(const FaceInfo & fi, const Moose::StateArg & state) const override;

private:
const Real & _val;
Expand Down
2 changes: 1 addition & 1 deletion framework/include/fvbcs/FVDirichletBCBase.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,5 +23,5 @@ class FVDirichletBCBase : public FVBoundaryCondition

static InputParameters validParams();

virtual ADReal boundaryValue(const FaceInfo & fi) const = 0;
virtual ADReal boundaryValue(const FaceInfo & fi, const Moose::StateArg & state) const = 0;
};
2 changes: 1 addition & 1 deletion framework/include/fvbcs/FVFunctionDirichletBC.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ class FVFunctionDirichletBC : public FVDirichletBCBase

static InputParameters validParams();

ADReal boundaryValue(const FaceInfo & fi) const override;
ADReal boundaryValue(const FaceInfo & fi, const Moose::StateArg & state) const override;

private:
const Function & _function;
Expand Down
2 changes: 1 addition & 1 deletion framework/include/fvbcs/FVFunctorDirichletBC.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ class FVFunctorDirichletBCTempl : public FVDirichletBCBase

static InputParameters validParams();

ADReal boundaryValue(const FaceInfo & fi) const override;
ADReal boundaryValue(const FaceInfo & fi, const Moose::StateArg & state) const override;

private:
/// The value for this BC
Expand Down
2 changes: 1 addition & 1 deletion framework/include/fvbcs/FVPostprocessorDirichletBC.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ class FVPostprocessorDirichletBC : public FVDirichletBCBase

static InputParameters validParams();

ADReal boundaryValue(const FaceInfo & fi) const override;
ADReal boundaryValue(const FaceInfo & fi, const Moose::StateArg & state) const override;

private:
/// The value for this BC
Expand Down
2 changes: 1 addition & 1 deletion framework/src/fvbcs/FVDirichletBC.C
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ FVDirichletBC::FVDirichletBC(const InputParameters & parameters)
}

ADReal
FVDirichletBC::boundaryValue(const FaceInfo & /*fi*/) const
FVDirichletBC::boundaryValue(const FaceInfo & /*fi*/, const Moose::StateArg & /*state*/) const
{
return _val;
}
2 changes: 1 addition & 1 deletion framework/src/fvbcs/FVFunctionDirichletBC.C
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ FVFunctionDirichletBC::FVFunctionDirichletBC(const InputParameters & parameters)
}

ADReal
FVFunctionDirichletBC::boundaryValue(const FaceInfo & fi) const
FVFunctionDirichletBC::boundaryValue(const FaceInfo & fi, const Moose::StateArg & /*state*/) const
{
return _function.value(_t, fi.faceCentroid());
}
9 changes: 5 additions & 4 deletions framework/src/fvbcs/FVFunctorDirichletBC.C
Original file line number Diff line number Diff line change
Expand Up @@ -52,17 +52,18 @@ FVFunctorDirichletBCTempl<is_ad>::FVFunctorDirichletBCTempl(const InputParameter

template <bool is_ad>
ADReal
FVFunctorDirichletBCTempl<is_ad>::boundaryValue(const FaceInfo & fi) const
FVFunctorDirichletBCTempl<is_ad>::boundaryValue(const FaceInfo & fi,
const Moose::StateArg & state) const
{
auto sfa = singleSidedFaceArg(&fi);
if (!_use_other_side)
return _functor(sfa, determineState());
return _functor(sfa, state);
else if (fi.elemPtr() == sfa.face_side)
return _functor({&fi, Moose::FV::LimiterType::CentralDifference, true, false, fi.neighborPtr()},
determineState());
state);
else
return _functor({&fi, Moose::FV::LimiterType::CentralDifference, true, false, fi.elemPtr()},
determineState());
state);
}

template class FVFunctorDirichletBCTempl<false>;
Expand Down
3 changes: 2 additions & 1 deletion framework/src/fvbcs/FVPostprocessorDirichletBC.C
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,8 @@ FVPostprocessorDirichletBC::FVPostprocessorDirichletBC(const InputParameters & p
}

ADReal
FVPostprocessorDirichletBC::boundaryValue(const FaceInfo & /*fi*/) const
FVPostprocessorDirichletBC::boundaryValue(const FaceInfo & /*fi*/,
const Moose::StateArg & /*state*/) const
{
return _postprocessor_value;
}
17 changes: 4 additions & 13 deletions framework/src/variables/MooseVariableFV.C
Original file line number Diff line number Diff line change
Expand Up @@ -489,16 +489,12 @@ MooseVariableFV<OutputType>::isDirichletBoundaryFace(const FaceInfo & fi,

template <typename OutputType>
ADReal
MooseVariableFV<OutputType>::getDirichletBoundaryFaceValue(
const FaceInfo & fi,
const Elem * const libmesh_dbg_var(elem),
const Moose::StateArg & libmesh_dbg_var(state)) const
MooseVariableFV<OutputType>::getDirichletBoundaryFaceValue(const FaceInfo & fi,
const Elem * const libmesh_dbg_var(elem),
const Moose::StateArg & state) const
{
mooseAssert(isDirichletBoundaryFace(fi, elem, state),
"This function should only be called on Dirichlet boundary faces.");
mooseAssert(state.state == 0,
"getDirichletBoundaryFaceValue currently only supports evaluating at the current "
"time/iteration state");

const auto & diri_pr = getDirichletBC(fi);

Expand All @@ -507,7 +503,7 @@ MooseVariableFV<OutputType>::getDirichletBoundaryFaceValue(

const FVDirichletBCBase & bc = *diri_pr.second;

return ADReal(bc.boundaryValue(fi));
return ADReal(bc.boundaryValue(fi, state));
}

template <typename OutputType>
Expand Down Expand Up @@ -736,12 +732,7 @@ MooseVariableFV<OutputType>::evaluate(const FaceArg & face, const StateArg & sta
const FaceInfo * const fi = face.fi;
mooseAssert(fi, "The face information must be non-null");
if (isDirichletBoundaryFace(*fi, face.face_side, state))
{
mooseAssert(state.state == 0,
"We have not yet added support for evaluating Dirichlet boundary conditions at "
"states other than the current solution state (e.g. current time)");
return getDirichletBoundaryFaceValue(*fi, face.face_side, state);
}
else if (isExtrapolatedBoundaryFace(*fi, face.face_side, state))
{
bool two_term_boundary_expansion = _two_term_boundary_expansion;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ class INSFVInletIntensityTKEBC : public FVDirichletBCBase
public:
static InputParameters validParams();
INSFVInletIntensityTKEBC(const InputParameters & params);
ADReal boundaryValue(const FaceInfo & fi) const override;
ADReal boundaryValue(const FaceInfo & fi, const Moose::StateArg & state) const override;

protected:
/// x-velocity
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ class INSFVMixingLengthTKEDBC : public FVDirichletBCBase
public:
static InputParameters validParams();
INSFVMixingLengthTKEDBC(const InputParameters & params);
ADReal boundaryValue(const FaceInfo & fi) const override;
ADReal boundaryValue(const FaceInfo & fi, const Moose::StateArg & state) const override;

protected:
/// C-mu closure coefficient
Expand Down
3 changes: 2 additions & 1 deletion modules/navier_stokes/include/fvbcs/INSFVOutletPressureBC.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,8 @@ class INSFVOutletPressureBCTempl : public FVDirichletBCBase, public T
static InputParameters validParams();
INSFVOutletPressureBCTempl(const InputParameters & params);

ADReal boundaryValue(const FaceInfo & /* fi */) const override;
ADReal boundaryValue(const FaceInfo & /* fi */,
const Moose::StateArg & /* state */) const override;

protected:
/// AD Functor that gives the distribution of pressure on the boundary
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,8 @@ class INSFVSwitchableOutletPressureBC : public INSFVOutletPressureBCTempl<INSFVF
static InputParameters validParams();
INSFVSwitchableOutletPressureBC(const InputParameters & params);

ADReal boundaryValue(const FaceInfo & /* fi */) const override;
ADReal boundaryValue(const FaceInfo & /* fi */,
const Moose::StateArg & /* state */) const override;

private:
/// Boolean switch to turn boundary condition on/off
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ class INSFVTKEDWallFunctionBC : public FVDirichletBCBase

static InputParameters validParams();

ADReal boundaryValue(const FaceInfo & fi) const override;
ADReal boundaryValue(const FaceInfo & fi, const Moose::StateArg & state) const override;

private:
/// the dimension of the domain
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ class INSFVTurbulentViscosityWallFunction : public FVDirichletBCBase

static InputParameters validParams();

ADReal boundaryValue(const FaceInfo & fi) const override;
ADReal boundaryValue(const FaceInfo & fi, const Moose::StateArg & state) const override;

private:
/// the dimension of the domain
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ class WCNSFVInletTemperatureBC : public FVDirichletBCBase, public INSFVFlowBC
WCNSFVInletTemperatureBC(const InputParameters & params);

protected:
ADReal boundaryValue(const FaceInfo & fi) const override;
ADReal boundaryValue(const FaceInfo & fi, const Moose::StateArg & state) const override;

/// Scaling factor
const Real _scaling_factor;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ class WCNSFVInletVelocityBC : public FVDirichletBCBase, public INSFVFlowBC
WCNSFVInletVelocityBC(const InputParameters & params);

protected:
ADReal boundaryValue(const FaceInfo & fi) const override;
ADReal boundaryValue(const FaceInfo & fi, const Moose::StateArg & state) const override;

/// Scaling factor
const Real _scaling_factor;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ class WCNSFVSwitchableInletVelocityBC : public WCNSFVInletVelocityBC
WCNSFVSwitchableInletVelocityBC(const InputParameters & params);

protected:
ADReal boundaryValue(const FaceInfo & fi) const override;
ADReal boundaryValue(const FaceInfo & fi, const Moose::StateArg & state) const override;

/// Boolean switch to turn boundary condition on/off
const bool & _switch_bc;
Expand Down
3 changes: 1 addition & 2 deletions modules/navier_stokes/src/fvbcs/INSFVInletIntensityTKEBC.C
Original file line number Diff line number Diff line change
Expand Up @@ -40,10 +40,9 @@ INSFVInletIntensityTKEBC::INSFVInletIntensityTKEBC(const InputParameters & param
}

ADReal
INSFVInletIntensityTKEBC::boundaryValue(const FaceInfo & fi) const
INSFVInletIntensityTKEBC::boundaryValue(const FaceInfo & fi, const Moose::StateArg & state) const
{
const auto boundary_face = singleSidedFaceArg(&fi);
const auto state = determineState();

ADRealVectorValue velocity(_u(boundary_face, state));
if (_v)
Expand Down
3 changes: 1 addition & 2 deletions modules/navier_stokes/src/fvbcs/INSFVMixingLengthTKEDBC.C
Original file line number Diff line number Diff line change
Expand Up @@ -36,10 +36,9 @@ INSFVMixingLengthTKEDBC::INSFVMixingLengthTKEDBC(const InputParameters & params)
}

ADReal
INSFVMixingLengthTKEDBC::boundaryValue(const FaceInfo & fi) const
INSFVMixingLengthTKEDBC::boundaryValue(const FaceInfo & fi, const Moose::StateArg & state) const
{
const auto boundary_face = singleSidedFaceArg(&fi);
const auto state = determineState();

return std::pow(_C_mu(boundary_face, state), 0.75) * std::pow(_k(boundary_face, state), 1.5) /
(0.07 * _characteristic_length(boundary_face, state));
Expand Down
5 changes: 3 additions & 2 deletions modules/navier_stokes/src/fvbcs/INSFVOutletPressureBC.C
Original file line number Diff line number Diff line change
Expand Up @@ -50,10 +50,11 @@ INSFVOutletPressureBCTempl<T>::INSFVOutletPressureBCTempl(const InputParameters

template <class T>
ADReal
INSFVOutletPressureBCTempl<T>::boundaryValue(const FaceInfo & fi) const
INSFVOutletPressureBCTempl<T>::boundaryValue(const FaceInfo & fi,
const Moose::StateArg & state) const
{
if (_functor)
return (*_functor)(singleSidedFaceArg(&fi), determineState());
return (*_functor)(singleSidedFaceArg(&fi), state);
else if (_function)
return _function->value(_t, fi.faceCentroid());
else
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,10 +38,11 @@ INSFVSwitchableOutletPressureBC::INSFVSwitchableOutletPressureBC(const InputPara
}

ADReal
INSFVSwitchableOutletPressureBC::boundaryValue(const FaceInfo & fi) const
INSFVSwitchableOutletPressureBC::boundaryValue(const FaceInfo & fi,
const Moose::StateArg & state) const
{
if (_switch_bc)
return INSFVOutletPressureBCTempl<INSFVFlowBC>::boundaryValue(fi) * _face_limiter;
return INSFVOutletPressureBCTempl<INSFVFlowBC>::boundaryValue(fi, state) * _face_limiter;
else
// The two-term expansion = false piece is critical as it prevents infinite recursion that would
// occur with a Green-Gauss gradient calculation which would call back to this "Dirichlet"
Expand All @@ -50,6 +51,6 @@ INSFVSwitchableOutletPressureBC::boundaryValue(const FaceInfo & fi) const
/*two_term_expansion=*/false,
/*correct_skewness=*/false,
fi.elemPtr(),
determineState()) *
state) *
_face_limiter;
}
3 changes: 1 addition & 2 deletions modules/navier_stokes/src/fvbcs/INSFVTKEDWallFunctionBC.C
Original file line number Diff line number Diff line change
Expand Up @@ -50,11 +50,10 @@ INSFVTKEDWallFunctionBC::INSFVTKEDWallFunctionBC(const InputParameters & params)
}

ADReal
INSFVTKEDWallFunctionBC::boundaryValue(const FaceInfo & fi) const
INSFVTKEDWallFunctionBC::boundaryValue(const FaceInfo & fi, const Moose::StateArg & state) const
{
const Real dist = std::abs((fi.elemCentroid() - fi.faceCentroid()) * fi.normal());
const Elem & _current_elem = fi.elem();
const auto state = determineState();
const auto mu = _mu(makeElemArg(&_current_elem), state);
const auto rho = _rho(makeElemArg(&_current_elem), state);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,8 @@ INSFVTurbulentViscosityWallFunction::INSFVTurbulentViscosityWallFunction(
}

ADReal
INSFVTurbulentViscosityWallFunction::boundaryValue(const FaceInfo & fi) const
INSFVTurbulentViscosityWallFunction::boundaryValue(const FaceInfo & fi,
const Moose::StateArg & /* state */) const
{
const Real wall_dist = std::abs((fi.elemCentroid() - fi.faceCentroid()) * fi.normal());
const Elem & _current_elem = fi.elem();
Expand Down
3 changes: 1 addition & 2 deletions modules/navier_stokes/src/fvbcs/WCNSFVInletTemperatureBC.C
Original file line number Diff line number Diff line change
Expand Up @@ -82,9 +82,8 @@ WCNSFVInletTemperatureBC::WCNSFVInletTemperatureBC(const InputParameters & param
}

ADReal
WCNSFVInletTemperatureBC::boundaryValue(const FaceInfo & fi) const
WCNSFVInletTemperatureBC::boundaryValue(const FaceInfo & fi, const Moose::StateArg & state) const
{
const auto state = determineState();

if (_area_pp)
if (MooseUtils::absoluteFuzzyEqual(*_area_pp, 0))
Expand Down
4 changes: 2 additions & 2 deletions modules/navier_stokes/src/fvbcs/WCNSFVInletVelocityBC.C
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ WCNSFVInletVelocityBC::WCNSFVInletVelocityBC(const InputParameters & params)
}

ADReal
WCNSFVInletVelocityBC::boundaryValue(const FaceInfo & fi) const
WCNSFVInletVelocityBC::boundaryValue(const FaceInfo & fi, const Moose::StateArg & state) const
{
if (_area_pp)
if (MooseUtils::absoluteFuzzyEqual(*_area_pp, 0))
Expand All @@ -67,7 +67,7 @@ WCNSFVInletVelocityBC::boundaryValue(const FaceInfo & fi) const
return _scaling_factor * (*_velocity_pp);
else
{
ADReal rho = (*_rho)(singleSidedFaceArg(&fi), determineState());
ADReal rho = (*_rho)(singleSidedFaceArg(&fi), state);

return _scaling_factor * (*_mdot_pp) / (*_area_pp * rho);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,10 +39,11 @@ WCNSFVSwitchableInletVelocityBC::WCNSFVSwitchableInletVelocityBC(const InputPara
}

ADReal
WCNSFVSwitchableInletVelocityBC::boundaryValue(const FaceInfo & fi) const
WCNSFVSwitchableInletVelocityBC::boundaryValue(const FaceInfo & fi,
const Moose::StateArg & state) const
{
if (_switch_bc)
return WCNSFVInletVelocityBC::boundaryValue(fi) * _face_limiter;
return WCNSFVInletVelocityBC::boundaryValue(fi, state) * _face_limiter;
else
// The two-term expansion = false piece is critical as it prevents infinite recursion that would
// occur with a Green-Gauss gradient calculation which would call back to this "Dirichlet"
Expand All @@ -51,6 +52,6 @@ WCNSFVSwitchableInletVelocityBC::boundaryValue(const FaceInfo & fi) const
/*two_term_expansion=*/false,
/*correct_skewness=*/false,
fi.elemPtr(),
determineState()) *
state) *
_face_limiter;
}
2 changes: 1 addition & 1 deletion test/include/fvbcs/FVUseFunctorSideForSsfDirichletBC.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ class FVUseFunctorSideForSsfDirichletBCTempl : public FVDirichletBCBase

static InputParameters validParams();

ADReal boundaryValue(const FaceInfo & fi) const override;
ADReal boundaryValue(const FaceInfo & fi, const Moose::StateArg & state) const override;

bool hasFaceSide(const FaceInfo & fi, bool fi_elem_side) const override;

Expand Down
6 changes: 3 additions & 3 deletions test/src/fvbcs/FVUseFunctorSideForSsfDirichletBC.C
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,10 @@ FVUseFunctorSideForSsfDirichletBCTempl<is_ad>::FVUseFunctorSideForSsfDirichletBC

template <bool is_ad>
ADReal
FVUseFunctorSideForSsfDirichletBCTempl<is_ad>::boundaryValue(const FaceInfo & fi) const
FVUseFunctorSideForSsfDirichletBCTempl<is_ad>::boundaryValue(const FaceInfo & fi,
const Moose::StateArg & state) const
{
return _functor(makeFace(fi, Moose::FV::LimiterType::CentralDifference, true, false),
Moose::currentState());
return _functor(makeFace(fi, Moose::FV::LimiterType::CentralDifference, true, false), state);
}

template <bool is_ad>
Expand Down

0 comments on commit 460817c

Please sign in to comment.