From 2d77e1109acba1b3f0ed1b47c23ba6efb6671eb5 Mon Sep 17 00:00:00 2001 From: smpark7 Date: Tue, 7 May 2024 17:58:07 -0700 Subject: [PATCH 1/5] New advection kernel and inflow bc that support using velocity functions --- .../PostprocessorVelocityFunctionInflowBC.h | 26 +++++++++++ .../VelocityFunctionConservativeAdvection.h | 24 ++++++++++ .../PostprocessorVelocityFunctionInflowBC.C | 45 +++++++++++++++++++ .../VelocityFunctionConservativeAdvection.C | 41 +++++++++++++++++ 4 files changed, 136 insertions(+) create mode 100644 include/bcs/PostprocessorVelocityFunctionInflowBC.h create mode 100644 include/kernels/VelocityFunctionConservativeAdvection.h create mode 100644 src/bcs/PostprocessorVelocityFunctionInflowBC.C create mode 100644 src/kernels/VelocityFunctionConservativeAdvection.C diff --git a/include/bcs/PostprocessorVelocityFunctionInflowBC.h b/include/bcs/PostprocessorVelocityFunctionInflowBC.h new file mode 100644 index 0000000..69eca04 --- /dev/null +++ b/include/bcs/PostprocessorVelocityFunctionInflowBC.h @@ -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; +}; diff --git a/include/kernels/VelocityFunctionConservativeAdvection.h b/include/kernels/VelocityFunctionConservativeAdvection.h new file mode 100644 index 0000000..1d35f24 --- /dev/null +++ b/include/kernels/VelocityFunctionConservativeAdvection.h @@ -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; +}; diff --git a/src/bcs/PostprocessorVelocityFunctionInflowBC.C b/src/bcs/PostprocessorVelocityFunctionInflowBC.C new file mode 100644 index 0000000..b22c930 --- /dev/null +++ b/src/bcs/PostprocessorVelocityFunctionInflowBC.C @@ -0,0 +1,45 @@ +#include "PostprocessorVelocityFunctionInflowBC.h" + +registerMooseObject("SquirrelApp", PostprocessorVelocityFunctionInflowBC); + +InputParameters +PostprocessorVelocityFunctionInflowBC::validParams() +{ + InputParameters params = IntegratedBC::validParams(); + params.addRequiredParam("vel_x_func", "The x velocity function"); + params.addRequiredParam("vel_y_func", "The y velocity function"); + params.addRequiredParam("vel_z_func", "The z velocity function"); + params.addRequiredParam( + "postprocessor", "The postprocessor from which to derive the inlet concentration."); + params.addParam("scale", 1, "The amount to scale the postprocessor value by"); + params.addParam("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("scale")), + _offset(getParam("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.; +} diff --git a/src/kernels/VelocityFunctionConservativeAdvection.C b/src/kernels/VelocityFunctionConservativeAdvection.C new file mode 100644 index 0000000..99b48c6 --- /dev/null +++ b/src/kernels/VelocityFunctionConservativeAdvection.C @@ -0,0 +1,41 @@ +#include "VelocityFunctionConservativeAdvection.h" +#include "Function.h" + +registerMooseObject("SquirrelApp", VelocityFunctionConservativeAdvection); + +InputParameters +VelocityFunctionConservativeAdvection::validParams() +{ + InputParameters params = Kernel::validParams(); + params.addRequiredParam("vel_x_func", "The x velocity function"); + params.addRequiredParam("vel_y_func", "The y velocity function"); + params.addRequiredParam("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]; +} From cea76d02227757468144e1d6f22fdfc8d667c01f Mon Sep 17 00:00:00 2001 From: smpark7 Date: Tue, 7 May 2024 18:01:11 -0700 Subject: [PATCH 2/5] Doc stubs for new velocity function objects --- .../PostprocessorVelocityFunctionInflowBC.md | 23 +++++++++++++++++++ .../VelocityFunctionConservativeAdvection.md | 23 +++++++++++++++++++ 2 files changed, 46 insertions(+) create mode 100644 doc/content/source/bcs/PostprocessorVelocityFunctionInflowBC.md create mode 100644 doc/content/source/kernels/VelocityFunctionConservativeAdvection.md diff --git a/doc/content/source/bcs/PostprocessorVelocityFunctionInflowBC.md b/doc/content/source/bcs/PostprocessorVelocityFunctionInflowBC.md new file mode 100644 index 0000000..c240b70 --- /dev/null +++ b/doc/content/source/bcs/PostprocessorVelocityFunctionInflowBC.md @@ -0,0 +1,23 @@ +# PostprocessorVelocityFunctionInflowBC + +!alert construction title=Undocumented Class +The PostprocessorVelocityFunctionInflowBC has not been documented. The content listed below should be used as a starting point for +documenting the class, which includes the typical automatic documentation associated with a +MooseObject; however, what is contained is ultimately determined by what is necessary to make the +documentation clear for users. + +!syntax description /BCs/PostprocessorVelocityFunctionInflowBC + +## Overview + +!! Replace these lines with information regarding the PostprocessorVelocityFunctionInflowBC object. + +## Example Input File Syntax + +!! Describe and include an example of how to use the PostprocessorVelocityFunctionInflowBC object. + +!syntax parameters /BCs/PostprocessorVelocityFunctionInflowBC + +!syntax inputs /BCs/PostprocessorVelocityFunctionInflowBC + +!syntax children /BCs/PostprocessorVelocityFunctionInflowBC diff --git a/doc/content/source/kernels/VelocityFunctionConservativeAdvection.md b/doc/content/source/kernels/VelocityFunctionConservativeAdvection.md new file mode 100644 index 0000000..491f74c --- /dev/null +++ b/doc/content/source/kernels/VelocityFunctionConservativeAdvection.md @@ -0,0 +1,23 @@ +# VelocityFunctionConservativeAdvection + +!alert construction title=Undocumented Class +The VelocityFunctionConservativeAdvection has not been documented. The content listed below should be used as a starting point for +documenting the class, which includes the typical automatic documentation associated with a +MooseObject; however, what is contained is ultimately determined by what is necessary to make the +documentation clear for users. + +!syntax description /Kernels/VelocityFunctionConservativeAdvection + +## Overview + +!! Replace these lines with information regarding the VelocityFunctionConservativeAdvection object. + +## Example Input File Syntax + +!! Describe and include an example of how to use the VelocityFunctionConservativeAdvection object. + +!syntax parameters /Kernels/VelocityFunctionConservativeAdvection + +!syntax inputs /Kernels/VelocityFunctionConservativeAdvection + +!syntax children /Kernels/VelocityFunctionConservativeAdvection From 5933029e6057fbddb7db79a049d046ed54db2d62 Mon Sep 17 00:00:00 2001 From: smpark7 Date: Thu, 9 May 2024 18:13:33 -0700 Subject: [PATCH 3/5] Add PostprocessorPenaltyDirichletBC --- include/bcs/PostprocessorPenaltyDirichletBC.h | 23 ++++++++++++ src/bcs/PostprocessorPenaltyDirichletBC.C | 36 +++++++++++++++++++ 2 files changed, 59 insertions(+) create mode 100644 include/bcs/PostprocessorPenaltyDirichletBC.h create mode 100644 src/bcs/PostprocessorPenaltyDirichletBC.C diff --git a/include/bcs/PostprocessorPenaltyDirichletBC.h b/include/bcs/PostprocessorPenaltyDirichletBC.h new file mode 100644 index 0000000..3fa0962 --- /dev/null +++ b/include/bcs/PostprocessorPenaltyDirichletBC.h @@ -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 _p; + const PostprocessorValue & _pp; +}; diff --git a/src/bcs/PostprocessorPenaltyDirichletBC.C b/src/bcs/PostprocessorPenaltyDirichletBC.C new file mode 100644 index 0000000..b0ccbf8 --- /dev/null +++ b/src/bcs/PostprocessorPenaltyDirichletBC.C @@ -0,0 +1,36 @@ +#include "PostprocessorPenaltyDirichletBC.h" + +registerMooseObject("SquirrelApp", PostprocessorPenaltyDirichletBC); + +InputParameters +PostprocessorPenaltyDirichletBC::validParams() +{ + InputParameters params = IntegratedBC::validParams(); + params.addRequiredParam("penalty", "Penalty scalar"); + params.addRequiredParam("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), + _p(getParam("penalty")), + _pp(getPostprocessorValue("postprocessor")) +{ +} + +Real +PostprocessorPenaltyDirichletBC::computeQpResidual() +{ + return _p * _test[_i][_qp] * (-_pp + _u[_qp]); +} + +Real +PostprocessorPenaltyDirichletBC::computeQpJacobian() +{ + return _p * _phi[_j][_qp] * _test[_i][_qp]; +} From b83c70bf76e46c760837e291567ce0285ee1e76d Mon Sep 17 00:00:00 2001 From: smpark7 Date: Fri, 10 May 2024 13:00:55 -0700 Subject: [PATCH 4/5] Add doc stub for PostprocessorPenaltyDirichletBC --- .../bcs/PostprocessorPenaltyDirichletBC.md | 23 +++++++++++++++++++ 1 file changed, 23 insertions(+) create mode 100644 doc/content/source/bcs/PostprocessorPenaltyDirichletBC.md diff --git a/doc/content/source/bcs/PostprocessorPenaltyDirichletBC.md b/doc/content/source/bcs/PostprocessorPenaltyDirichletBC.md new file mode 100644 index 0000000..d970c71 --- /dev/null +++ b/doc/content/source/bcs/PostprocessorPenaltyDirichletBC.md @@ -0,0 +1,23 @@ +# PostprocessorPenaltyDirichletBC + +!alert construction title=Undocumented Class +The PostprocessorPenaltyDirichletBC has not been documented. The content listed below should be used as a starting point for +documenting the class, which includes the typical automatic documentation associated with a +MooseObject; however, what is contained is ultimately determined by what is necessary to make the +documentation clear for users. + +!syntax description /BCs/PostprocessorPenaltyDirichletBC + +## Overview + +!! Replace these lines with information regarding the PostprocessorPenaltyDirichletBC object. + +## Example Input File Syntax + +!! Describe and include an example of how to use the PostprocessorPenaltyDirichletBC object. + +!syntax parameters /BCs/PostprocessorPenaltyDirichletBC + +!syntax inputs /BCs/PostprocessorPenaltyDirichletBC + +!syntax children /BCs/PostprocessorPenaltyDirichletBC From c157a94fac86998b68a9cedf7c56976f1bb61b85 Mon Sep 17 00:00:00 2001 From: smpark7 Date: Fri, 10 May 2024 13:40:56 -0700 Subject: [PATCH 5/5] Address review comments from @LukeSeifert --- .../source/bcs/PostprocessorPenaltyDirichletBC.md | 15 ++++----------- .../bcs/PostprocessorVelocityFunctionInflowBC.md | 13 ++----------- .../VelocityFunctionConservativeAdvection.md | 14 +++----------- include/bcs/PostprocessorPenaltyDirichletBC.h | 4 ++-- src/bcs/PostprocessorPenaltyDirichletBC.C | 8 ++++---- 5 files changed, 15 insertions(+), 39 deletions(-) diff --git a/doc/content/source/bcs/PostprocessorPenaltyDirichletBC.md b/doc/content/source/bcs/PostprocessorPenaltyDirichletBC.md index d970c71..4ed3e79 100644 --- a/doc/content/source/bcs/PostprocessorPenaltyDirichletBC.md +++ b/doc/content/source/bcs/PostprocessorPenaltyDirichletBC.md @@ -1,20 +1,13 @@ # PostprocessorPenaltyDirichletBC -!alert construction title=Undocumented Class -The PostprocessorPenaltyDirichletBC has not been documented. The content listed below should be used as a starting point for -documenting the class, which includes the typical automatic documentation associated with a -MooseObject; however, what is contained is ultimately determined by what is necessary to make the -documentation clear for users. - !syntax description /BCs/PostprocessorPenaltyDirichletBC ## Overview -!! Replace these lines with information regarding the PostprocessorPenaltyDirichletBC object. - -## Example Input File Syntax - -!! Describe and include an example of how to use the PostprocessorPenaltyDirichletBC object. +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 diff --git a/doc/content/source/bcs/PostprocessorVelocityFunctionInflowBC.md b/doc/content/source/bcs/PostprocessorVelocityFunctionInflowBC.md index c240b70..63c0e4b 100644 --- a/doc/content/source/bcs/PostprocessorVelocityFunctionInflowBC.md +++ b/doc/content/source/bcs/PostprocessorVelocityFunctionInflowBC.md @@ -1,20 +1,11 @@ # PostprocessorVelocityFunctionInflowBC -!alert construction title=Undocumented Class -The PostprocessorVelocityFunctionInflowBC has not been documented. The content listed below should be used as a starting point for -documenting the class, which includes the typical automatic documentation associated with a -MooseObject; however, what is contained is ultimately determined by what is necessary to make the -documentation clear for users. - !syntax description /BCs/PostprocessorVelocityFunctionInflowBC ## Overview -!! Replace these lines with information regarding the PostprocessorVelocityFunctionInflowBC object. - -## Example Input File Syntax - -!! Describe and include an example of how to use the PostprocessorVelocityFunctionInflowBC object. +Sets inflow boundary conditions for a problem with function-based velocity profile and inlet +concentration postprocessor. !syntax parameters /BCs/PostprocessorVelocityFunctionInflowBC diff --git a/doc/content/source/kernels/VelocityFunctionConservativeAdvection.md b/doc/content/source/kernels/VelocityFunctionConservativeAdvection.md index 491f74c..f9dcdc7 100644 --- a/doc/content/source/kernels/VelocityFunctionConservativeAdvection.md +++ b/doc/content/source/kernels/VelocityFunctionConservativeAdvection.md @@ -1,20 +1,12 @@ # VelocityFunctionConservativeAdvection -!alert construction title=Undocumented Class -The VelocityFunctionConservativeAdvection has not been documented. The content listed below should be used as a starting point for -documenting the class, which includes the typical automatic documentation associated with a -MooseObject; however, what is contained is ultimately determined by what is necessary to make the -documentation clear for users. - !syntax description /Kernels/VelocityFunctionConservativeAdvection ## Overview -!! Replace these lines with information regarding the VelocityFunctionConservativeAdvection object. - -## Example Input File Syntax - -!! Describe and include an example of how to use the VelocityFunctionConservativeAdvection object. +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 diff --git a/include/bcs/PostprocessorPenaltyDirichletBC.h b/include/bcs/PostprocessorPenaltyDirichletBC.h index 3fa0962..78935f5 100644 --- a/include/bcs/PostprocessorPenaltyDirichletBC.h +++ b/include/bcs/PostprocessorPenaltyDirichletBC.h @@ -18,6 +18,6 @@ class PostprocessorPenaltyDirichletBC : public IntegratedBC virtual Real computeQpJacobian() override; private: - Real _p; - const PostprocessorValue & _pp; + Real _penalty; + const PostprocessorValue & _postprocessor; }; diff --git a/src/bcs/PostprocessorPenaltyDirichletBC.C b/src/bcs/PostprocessorPenaltyDirichletBC.C index b0ccbf8..4b55cc0 100644 --- a/src/bcs/PostprocessorPenaltyDirichletBC.C +++ b/src/bcs/PostprocessorPenaltyDirichletBC.C @@ -18,19 +18,19 @@ PostprocessorPenaltyDirichletBC::validParams() PostprocessorPenaltyDirichletBC::PostprocessorPenaltyDirichletBC( const InputParameters & parameters) : IntegratedBC(parameters), - _p(getParam("penalty")), - _pp(getPostprocessorValue("postprocessor")) + _penalty(getParam("penalty")), + _postprocessor(getPostprocessorValue("postprocessor")) { } Real PostprocessorPenaltyDirichletBC::computeQpResidual() { - return _p * _test[_i][_qp] * (-_pp + _u[_qp]); + return _penalty * _test[_i][_qp] * (-_postprocessor + _u[_qp]); } Real PostprocessorPenaltyDirichletBC::computeQpJacobian() { - return _p * _phi[_j][_qp] * _test[_i][_qp]; + return _penalty * _phi[_j][_qp] * _test[_i][_qp]; }