forked from idaholab/moose
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Closes idaholab#18212
- Loading branch information
Showing
6 changed files
with
180 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
# ADMatchedValueBC | ||
|
||
!syntax description /BCs/ADMatchedValueBC | ||
|
||
## Description | ||
|
||
`ADMatchedValueBC` is a `ADNodalBC` which applies to systems of two or more variables, | ||
and can be used to impose equality of two solutions along a given `boundary`. | ||
This class is appropriate for systems of partial differential equations (PDEs) of | ||
the form | ||
\begin{equation} | ||
\begin{aligned} | ||
-\nabla^2 u &= f_1 && \quad \in \Omega \\ | ||
-\nabla^2 v &= f_2 && \quad \in \Omega \\ | ||
\frac{\partial u}{\partial n} &= h_1 && \quad \in \partial \Omega_N \\ | ||
\frac{\partial v}{\partial n} &= h_2 && \quad \in \partial \Omega_N \\ | ||
u &= v && \quad \in \partial \Omega_D, | ||
\end{aligned} | ||
\end{equation} | ||
where $\Omega \subset \mathbb{R}^n$ is the domain, and $\partial | ||
\Omega = \partial \Omega_D \cup \partial \Omega_N$ is its boundary, | ||
$u$, $v$ are the unknowns, $f_1$, $f_2$ are forcing functions (which | ||
may depend on both $u$ and $v$), and $h_1$ and $h_2$ are given | ||
fluxes. The `v` parameter is used to specify the variable whose value | ||
is tied to $u$. In the example below, the other variable's name | ||
happens to be `v` as well. | ||
|
||
## Example Input Syntax | ||
|
||
!listing test/tests/bcs/ad_matched_value_bc/test.i start=[left_u] end=[] include-end=true | ||
|
||
!syntax parameters /BCs/ADMatchedValueBC | ||
|
||
!syntax inputs /BCs/ADMatchedValueBC | ||
|
||
!syntax children /BCs/ADMatchedValueBC |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
//* 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 "ADNodalBC.h" | ||
|
||
/** | ||
* Implements a simple coupled boundary condition where u=v on the boundary. | ||
*/ | ||
class ADMatchedValueBC : public ADNodalBC | ||
{ | ||
public: | ||
static InputParameters validParams(); | ||
|
||
ADMatchedValueBC(const InputParameters & parameters); | ||
|
||
protected: | ||
virtual ADReal computeQpResidual() override; | ||
|
||
const ADVariableValue & _v; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
//* 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 "ADMatchedValueBC.h" | ||
|
||
registerMooseObject("MooseApp", ADMatchedValueBC); | ||
|
||
InputParameters | ||
ADMatchedValueBC::validParams() | ||
{ | ||
InputParameters params = ADNodalBC::validParams(); | ||
params.addRequiredCoupledVar("v", "The variable whose value we are to match."); | ||
params.addClassDescription("Implements a nodal BC which equates two different Variables' values " | ||
"on a specified boundary."); | ||
return params; | ||
} | ||
|
||
ADMatchedValueBC::ADMatchedValueBC(const InputParameters & parameters) | ||
: ADNodalBC(parameters), _v(adCoupledValue("v")) | ||
{ | ||
} | ||
|
||
ADReal | ||
ADMatchedValueBC::computeQpResidual() | ||
{ | ||
return _u - _v[_qp]; | ||
} |
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
[Mesh] | ||
[square] | ||
type = GeneratedMeshGenerator | ||
nx = 2 | ||
ny = 2 | ||
dim = 2 | ||
[] | ||
[] | ||
|
||
# Solves a pair of coupled diffusion equations where u=v on the boundary | ||
|
||
[Variables] | ||
[u] | ||
order = FIRST | ||
family = LAGRANGE | ||
initial_condition = 3 | ||
[] | ||
|
||
[v] | ||
order = FIRST | ||
family = LAGRANGE | ||
initial_condition = 2 | ||
[] | ||
[] | ||
|
||
[Kernels] | ||
[diff_u] | ||
type = ADDiffusion | ||
variable = u | ||
[] | ||
|
||
[diff_v] | ||
type = ADDiffusion | ||
variable = v | ||
[] | ||
[] | ||
|
||
[BCs] | ||
[right_v] | ||
type = ADDirichletBC | ||
variable = v | ||
boundary = 1 | ||
value = 3 | ||
[] | ||
|
||
[left_u] | ||
type = ADMatchedValueBC | ||
variable = u | ||
boundary = 3 | ||
v = v | ||
[] | ||
[] | ||
|
||
[Executioner] | ||
type = Steady | ||
solve_type = 'NEWTON' | ||
|
||
nl_rel_tol = 1e-10 | ||
l_tol = 1e-12 | ||
[] | ||
|
||
[Outputs] | ||
file_base = out | ||
exodus = true | ||
[] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
[Tests] | ||
requirement = "MOOSE shall support matching variable values on a boundary using automatic differentiation" | ||
design = 'ADMatchedValueBC.md' | ||
issues = "#18212" | ||
[test] | ||
type = 'Exodiff' | ||
input = 'test.i' | ||
exodiff = 'out.e' | ||
detail = '' | ||
[] | ||
[jacobian] | ||
type = 'PetscJacobianTester' | ||
input = 'test.i' | ||
ratio_tol = 1e-8 | ||
difference_tol = 1e-7 | ||
detail = 'and shall be able to produce the exact Jacobian' | ||
[] | ||
[] |