Skip to content

Commit

Permalink
Add mean value constraint
Browse files Browse the repository at this point in the history
  • Loading branch information
fredrikekre committed Sep 29, 2022
1 parent 1231ef4 commit fb9c982
Showing 1 changed file with 27 additions and 1 deletion.
28 changes: 27 additions & 1 deletion docs/src/literate/stokes-flow.jl
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,12 @@
# \boldsymbol{u} = \boldsymbol{0} \quad \forall \boldsymbol{x}\ \in\
# \Gamma_2 \cup \Gamma_4 := \{ \boldsymbol{x}:\ ||\boldsymbol{x}|| \in \{0.5, 1\}\}.
# ```
# No boundary conditions are needed for the pressure.
# With this formulation and boundary conditions for ``\boldsymbol{u}`` the pressure will
# only be determined up to a constant. We will add an additional constraint which fixes this
# constant. In particular, we will enforce that the mean value of the pressure on the
# boundary is 0, see [deal.ii
# step-11](https://www.dealii.org/current/doxygen/deal.II/step_11.html) for some more
# discussion around this.
#
# The corresponding weak form reads as follows: Find ``(\boldsymbol{u}, p) \in \mathbb{U}
# \times \mathrm{L}_2`` s.t.
Expand Down Expand Up @@ -194,6 +199,15 @@ end
# For the remaining part of the boundary we add a homogeneous Dirichlet boundary condition
# on both components of the velocity field. This is done using the [`Dirichlet`](@ref)
# constructor, which we have discussed in other tutorials.
#
# As discussed in the introduction, we will add a constraint to the mean value of the
# pressure. We do this by constructing an [`AffineConstraint`](@ref) for the pressure dofs
# on the boundary:
# ```math
# 0 = \int_{\partial\Omega} p\ \mathrm{d}\Gamma \approx \sum_{i=1}^{D} p_i \quad \Rightarrow
# \quad p_1 = \sum_{i=2}^{D} -p_i,
# ```
# where ``\{p_i: i \in 1..D\}`` are the pressure dofs on the boundary.

function setup_constraints(dh)
ch = ConstraintHandler(dh)
Expand All @@ -206,6 +220,18 @@ function setup_constraints(dh)
Γ24 = union(getfaceset(dh.grid, "Γ2"), getfaceset(dh.grid, "Γ4"))
dbc = Dirichlet(:u, Γ24, (x, t) -> [0, 0], [1, 2])
add!(ch, dbc)
## Mean value constraint: Ensure that \sum
ch_mean = ConstraintHandler(dh)
∂Ω = union(getfaceset(dh.grid, "Γ1"), getfaceset(dh.grid, "Γ2"),
getfaceset(dh.grid, "Γ3"), getfaceset(dh.grid, "Γ4"))
add!(ch_mean, Dirichlet(:p, ∂Ω, (x, t) -> 0))
close!(ch_mean)
mean_value_constraint = AffineConstraint(
pop!(ch_mean.prescribed_dofs),
[d => -1. for d in ch_mean.prescribed_dofs],
0.0
)
add!(ch, mean_value_constraint)
## Finalize
close!(ch)
update!(ch, 0)
Expand Down

0 comments on commit fb9c982

Please sign in to comment.