Skip to content

Commit

Permalink
Merge pull request #12 from smpark7/function-flow
Browse files Browse the repository at this point in the history
Add support for function-based velocity advection on constant and higher order discontinuous variables
  • Loading branch information
LukeSeifert authored May 13, 2024
2 parents 2cafe66 + c157a94 commit cb4101d
Show file tree
Hide file tree
Showing 9 changed files with 240 additions and 0 deletions.
16 changes: 16 additions & 0 deletions doc/content/source/bcs/PostprocessorPenaltyDirichletBC.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
# PostprocessorPenaltyDirichletBC

!syntax description /BCs/PostprocessorPenaltyDirichletBC

## Overview

Enforces a Postprocessor Dirichlet boundary condition in a weak sense by penalizing differences
between the current solution and the Dirichlet data. See
[PenaltyDirichletBC](https://mooseframework.inl.gov/source/bcs/PenaltyDirichletBC.html) for more
information on penalty BCs.

!syntax parameters /BCs/PostprocessorPenaltyDirichletBC

!syntax inputs /BCs/PostprocessorPenaltyDirichletBC

!syntax children /BCs/PostprocessorPenaltyDirichletBC
14 changes: 14 additions & 0 deletions doc/content/source/bcs/PostprocessorVelocityFunctionInflowBC.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
# PostprocessorVelocityFunctionInflowBC

!syntax description /BCs/PostprocessorVelocityFunctionInflowBC

## Overview

Sets inflow boundary conditions for a problem with function-based velocity profile and inlet
concentration postprocessor.

!syntax parameters /BCs/PostprocessorVelocityFunctionInflowBC

!syntax inputs /BCs/PostprocessorVelocityFunctionInflowBC

!syntax children /BCs/PostprocessorVelocityFunctionInflowBC
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
# VelocityFunctionConservativeAdvection

!syntax description /Kernels/VelocityFunctionConservativeAdvection

## Overview

Implements a variant of
[ConservativeAdvection](https://mooseframework.inl.gov/source/kernels/ConservativeAdvection.html)
with the velocity set by a user-provided function.

!syntax parameters /Kernels/VelocityFunctionConservativeAdvection

!syntax inputs /Kernels/VelocityFunctionConservativeAdvection

!syntax children /Kernels/VelocityFunctionConservativeAdvection
23 changes: 23 additions & 0 deletions include/bcs/PostprocessorPenaltyDirichletBC.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
#pragma once

#include "IntegratedBC.h"

/**
* Weakly enforce a Dirichlet BC using a penalty term similar to PenaltyDirichletBC, but with a
* postprocessor value instead of a scalar.
*/
class PostprocessorPenaltyDirichletBC : public IntegratedBC
{
public:
static InputParameters validParams();

PostprocessorPenaltyDirichletBC(const InputParameters & parameters);

protected:
virtual Real computeQpResidual() override;
virtual Real computeQpJacobian() override;

private:
Real _penalty;
const PostprocessorValue & _postprocessor;
};
26 changes: 26 additions & 0 deletions include/bcs/PostprocessorVelocityFunctionInflowBC.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
#pragma once

#include "IntegratedBC.h"

/**
* Computes the inflow boundary condition contribution with inlet concentration set by a
* postprocessor, and the velocity set by functions.
*/
class PostprocessorVelocityFunctionInflowBC : public IntegratedBC
{
public:
PostprocessorVelocityFunctionInflowBC(const InputParameters & parameters);

static InputParameters validParams();

protected:
virtual Real computeQpResidual() override;
virtual Real computeQpJacobian() override;

const Function & _vel_x_func;
const Function & _vel_y_func;
const Function & _vel_z_func;
const PostprocessorValue & _pp_value;
const Real & _scale;
const Real & _offset;
};
24 changes: 24 additions & 0 deletions include/kernels/VelocityFunctionConservativeAdvection.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
#pragma once

#include "Kernel.h"

/**
* Computes the conservative advection residual and jacobian contributions with velocity
* set by functions.
*/
class VelocityFunctionConservativeAdvection : public Kernel
{
public:
VelocityFunctionConservativeAdvection(const InputParameters & parameters);

static InputParameters validParams();

protected:
virtual Real computeQpResidual() override;
virtual Real computeQpJacobian() override;

// velocity functions
const Function & _vel_x_func;
const Function & _vel_y_func;
const Function & _vel_z_func;
};
36 changes: 36 additions & 0 deletions src/bcs/PostprocessorPenaltyDirichletBC.C
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
#include "PostprocessorPenaltyDirichletBC.h"

registerMooseObject("SquirrelApp", PostprocessorPenaltyDirichletBC);

InputParameters
PostprocessorPenaltyDirichletBC::validParams()
{
InputParameters params = IntegratedBC::validParams();
params.addRequiredParam<Real>("penalty", "Penalty scalar");
params.addRequiredParam<PostprocessorName>("postprocessor",
"Postprocessor to set the boundary value of the variable");
params.addClassDescription("Enforces a Dirichlet boundary condition "
"in a weak sense by penalizing differences between the current "
"solution and the Dirichlet postprocessor value.");
return params;
}

PostprocessorPenaltyDirichletBC::PostprocessorPenaltyDirichletBC(
const InputParameters & parameters)
: IntegratedBC(parameters),
_penalty(getParam<Real>("penalty")),
_postprocessor(getPostprocessorValue("postprocessor"))
{
}

Real
PostprocessorPenaltyDirichletBC::computeQpResidual()
{
return _penalty * _test[_i][_qp] * (-_postprocessor + _u[_qp]);
}

Real
PostprocessorPenaltyDirichletBC::computeQpJacobian()
{
return _penalty * _phi[_j][_qp] * _test[_i][_qp];
}
45 changes: 45 additions & 0 deletions src/bcs/PostprocessorVelocityFunctionInflowBC.C
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
#include "PostprocessorVelocityFunctionInflowBC.h"

registerMooseObject("SquirrelApp", PostprocessorVelocityFunctionInflowBC);

InputParameters
PostprocessorVelocityFunctionInflowBC::validParams()
{
InputParameters params = IntegratedBC::validParams();
params.addRequiredParam<FunctionName>("vel_x_func", "The x velocity function");
params.addRequiredParam<FunctionName>("vel_y_func", "The y velocity function");
params.addRequiredParam<FunctionName>("vel_z_func", "The z velocity function");
params.addRequiredParam<PostprocessorName>(
"postprocessor", "The postprocessor from which to derive the inlet concentration.");
params.addParam<Real>("scale", 1, "The amount to scale the postprocessor value by");
params.addParam<Real>("offset", 0, "The amount to offset the scaled postprocessor by");
return params;
}

PostprocessorVelocityFunctionInflowBC::PostprocessorVelocityFunctionInflowBC(
const InputParameters & parameters)
: IntegratedBC(parameters),
_vel_x_func(getFunction("vel_x_func")),
_vel_y_func(getFunction("vel_y_func")),
_vel_z_func(getFunction("vel_z_func")),
_pp_value(getPostprocessorValue("postprocessor")),
_scale(getParam<Real>("scale")),
_offset(getParam<Real>("offset"))
{
}

Real
PostprocessorVelocityFunctionInflowBC::computeQpResidual()
{
RealVectorValue velocity = {_vel_x_func.value(_t, _q_point[_qp]),
_vel_y_func.value(_t, _q_point[_qp]),
_vel_z_func.value(_t, _q_point[_qp])};
Real inlet_conc = _scale * _pp_value + _offset;
return _test[_i][_qp] * inlet_conc * velocity * _normals[_qp];
}

Real
PostprocessorVelocityFunctionInflowBC::computeQpJacobian()
{
return 0.;
}
41 changes: 41 additions & 0 deletions src/kernels/VelocityFunctionConservativeAdvection.C
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
#include "VelocityFunctionConservativeAdvection.h"
#include "Function.h"

registerMooseObject("SquirrelApp", VelocityFunctionConservativeAdvection);

InputParameters
VelocityFunctionConservativeAdvection::validParams()
{
InputParameters params = Kernel::validParams();
params.addRequiredParam<FunctionName>("vel_x_func", "The x velocity function");
params.addRequiredParam<FunctionName>("vel_y_func", "The y velocity function");
params.addRequiredParam<FunctionName>("vel_z_func", "The z velocity function");
return params;
}

VelocityFunctionConservativeAdvection::VelocityFunctionConservativeAdvection(
const InputParameters & parameters)
: Kernel(parameters),
_vel_x_func(getFunction("vel_x_func")),
_vel_y_func(getFunction("vel_y_func")),
_vel_z_func(getFunction("vel_z_func"))
{
}

Real
VelocityFunctionConservativeAdvection::computeQpResidual()
{
RealVectorValue v = {_vel_x_func.value(_t, _q_point[_qp]),
_vel_y_func.value(_t, _q_point[_qp]),
_vel_z_func.value(_t, _q_point[_qp])};
return -_grad_test[_i][_qp] * v * _u[_qp];
}

Real
VelocityFunctionConservativeAdvection::computeQpJacobian()
{
RealVectorValue v = {_vel_x_func.value(_t, _q_point[_qp]),
_vel_y_func.value(_t, _q_point[_qp]),
_vel_z_func.value(_t, _q_point[_qp])};
return -_grad_test[_i][_qp] * v * _phi[_j][_qp];
}

0 comments on commit cb4101d

Please sign in to comment.