Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 4 additions & 3 deletions src/kernels.jl
Original file line number Diff line number Diff line change
Expand Up @@ -173,13 +173,14 @@ function emit_kernels(wf::WeakForm; coeffs = true, expression = Val(false))
end

"""
emit_dirichlet(analysis)
emit_dirichlet(analysis; expression = Val(false))

One `(piece, field, g)` per essential condition of `analysis`, with `g(X, T, P)` the prescribed value.
`expression = Val(true)` returns the generated `Expr` in place of each `g`.
"""
function emit_dirichlet(analysis)
function emit_dirichlet(analysis; expression = Val(false))
s = analysis.slots
return Tuple((bc.piece, bc.field, compile(assert_differentiated(bc.g), (s.X, s.T, s.P))) for bc in analysis.essential)
return Tuple((bc.piece, bc.field, compile(assert_differentiated(bc.g), (s.X, s.T, s.P); expression)) for bc in analysis.essential)
end

"""
Expand Down
35 changes: 35 additions & 0 deletions test/Kernels/dirichlet_expression.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
# `emit_dirichlet(analysis; expression = Val(true))` returns the generated `Expr`s, which build the function the
# default call compiles.
import FiniteElementMethod
using FiniteElementMethod: emit_dirichlet
using FiniteElementMethod.RuntimeGeneratedFunctions: RuntimeGeneratedFunction
using Ferrite: Vec
using Symbolics
using Test

include(joinpath(@__DIR__, "..", "shared", "strongform_seam.jl"))
using .StrongFormSeam: analyse, BC

@variables t x y k
@variables u(..)
Dx, Dy, Dt = Differential(x), Differential(y), Differential(t)
U = u(t, x, y)

@testset "expression form of the Dirichlet data round-trips" begin
eq = Dt(U) ~ Dx(k * Dx(U)) + Dy(k * Dy(U))
# Constant, space-dependent and time-dependent prescribed values.
bcs = [BC("left", U ~ 1), BC("right", U ~ 0.1 * y + x), BC("top", U ~ sin(t) * x)]
an = analyse([eq], bcs; depvars = [U], t, sivs = [x, y], params = [k])
compiled, generated = emit_dirichlet(an), emit_dirichlet(an; expression = Val(true))
@test length(generated) == length(compiled) == 3
P = [2.0]
for ((piece, field, g), (epiece, efield, ex)) in zip(compiled, generated)
@test (epiece, efield) == (piece, field)
@test ex isa Expr
evaluated = RuntimeGeneratedFunction(FiniteElementMethod, FiniteElementMethod, ex)
for _ in 1:5
X, T = Vec(rand(), rand()), rand()
@test isequal(evaluated(X, T, P), g(X, T, P))
end
end
end
Loading