Skip to content

Commit

Permalink
Add Dirichlet bcs for the divergence of a vector field (idaholab#26105)
Browse files Browse the repository at this point in the history
Co-authored-by: Nuno Nobre <nuno.nobre@stfc.ac.uk>
  • Loading branch information
karthichockalingam and nmnobre committed Nov 20, 2023
1 parent 1ac3ab3 commit a2d64aa
Show file tree
Hide file tree
Showing 2 changed files with 105 additions and 0 deletions.
45 changes: 45 additions & 0 deletions framework/include/bcs/VectorDivPenaltyDirichletBC.h
@@ -0,0 +1,45 @@
//* 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 "VectorIntegratedBC.h"

/**
* Enforces a Dirichlet boundary condition for the divergence of vector nonlinear
* variables in a weak sense by applying a penalty to the difference between the
* current solution and the Dirichlet data.
*/
class VectorDivPenaltyDirichletBC : public VectorIntegratedBC
{
public:
static InputParameters validParams();

VectorDivPenaltyDirichletBC(const InputParameters & parameters);

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

private:
/// The penalty coefficient
Real _penalty;

/// The vector function for the exact solution
const Function * const _function;

/// The function for the x component
const Function & _function_x;

/// The function for the y component
const Function & _function_y;

/// The function for the z component
const Function & _function_z;
};
60 changes: 60 additions & 0 deletions framework/src/bcs/VectorDivPenaltyDirichletBC.C
@@ -0,0 +1,60 @@
//* 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 "VectorDivPenaltyDirichletBC.h"
#include "Function.h"

registerMooseObject("MooseApp", VectorDivPenaltyDirichletBC);

InputParameters
VectorDivPenaltyDirichletBC::validParams()
{
InputParameters params = VectorIntegratedBC::validParams();
params.addRequiredParam<Real>("penalty", "The penalty coefficient");
params.addParam<FunctionName>("function",
"The boundary condition vector function, "
"use as an alternative to a component-wise specification");
params.addParam<FunctionName>("function_x", 0, "The function for the x component");
params.addParam<FunctionName>("function_y", 0, "The function for the y component");
params.addParam<FunctionName>("function_z", 0, "The function for the z component");
params.addClassDescription("Enforces, in a weak sense, a Dirichlet boundary condition on the "
"divergence of a nonlinear vector variable by applying a penalty to "
"the difference between the current solution and the Dirichlet data.");
return params;
}

VectorDivPenaltyDirichletBC::VectorDivPenaltyDirichletBC(const InputParameters & parameters)
: VectorIntegratedBC(parameters),
_penalty(getParam<Real>("penalty")),
_function(isParamValid("function") ? &getFunction("function") : nullptr),
_function_x(getFunction("function_x")),
_function_y(getFunction("function_y")),
_function_z(getFunction("function_z"))
{
}

Real
VectorDivPenaltyDirichletBC::computeQpResidual()
{
RealVectorValue u_exact;
if (_function)
u_exact = _function->vectorValue(_t, _q_point[_qp]);
else
u_exact = {_function_x.value(_t, _q_point[_qp]),
_function_y.value(_t, _q_point[_qp]),
_function_z.value(_t, _q_point[_qp])};

return _penalty * ((_u[_qp] - u_exact) * (_normals[_qp])) * ((_test[_i][_qp]) * (_normals[_qp]));
}

Real
VectorDivPenaltyDirichletBC::computeQpJacobian()
{
return _penalty * ((_phi[_j][_qp]) * (_normals[_qp])) * ((_test[_i][_qp]) * (_normals[_qp]));
}

0 comments on commit a2d64aa

Please sign in to comment.