Skip to content

Commit 4dcd16f

Browse files
committed
First example with Neumann BCs working
1 parent 0f99234 commit 4dcd16f

File tree

1 file changed

+51
-1
lines changed

1 file changed

+51
-1
lines changed

test/FESpacesTests/FEOperatorsTests.jl

+51-1
Original file line numberDiff line numberDiff line change
@@ -84,4 +84,54 @@ zh = zero(U)
8484
solve!(zh,solver,op,cache)
8585
@test free_dofs(zh) free_dofs(uh)
8686

87-
end
87+
# With Neumann BCs
88+
89+
# Manufactured Neumann function
90+
gfun(x) = 1.0
91+
92+
# Construct the FEspace
93+
order = 1
94+
diritags = [1,2,3,4,5,6,7]
95+
fespace = ConformingFESpace(Float64,model,order,diritags)
96+
97+
# Define test and trial
98+
V = TestFESpace(fespace)
99+
U = TrialFESpace(fespace,ufun)
100+
101+
# Setup integration on Neumann boundary
102+
neumanntags = [8,]
103+
btrian = BoundaryTriangulation(model,neumanntags)
104+
bquad = CellQuadrature(btrian,order=2)
105+
106+
# Object describing Neumann function
107+
gfield = CellField(btrian,gfun)
108+
109+
# Integrand of the Neumann BC
110+
g(v) = inner(v,gfield)
111+
112+
# Define weak form terms
113+
t_Ω = AffineFETerm(a,b,trian,quad)
114+
t_Γ = FESource(g,btrian,bquad)
115+
116+
# Define Assembler
117+
assem = SparseMatrixAssembler(V,U)
118+
119+
# Define FE problem
120+
op = LinearFEOperator(V,U,assem,t_Ω,t_Γ)
121+
122+
# Solve!
123+
uh = solve(solver,op)
124+
125+
# Define exact solution and error
126+
e = u - uh
127+
128+
# Compute errors
129+
el2 = sqrt(sum( integrate(l2(e),trian,quad) ))
130+
eh1 = sqrt(sum( integrate(h1(e),trian,quad) ))
131+
132+
#writevtk(trian,"trian",nref=4,cellfields=["uh"=>uh,"u"=>u,"e"=>e])
133+
134+
@test el2 < 1.e-8
135+
@test eh1 < 1.e-8
136+
137+
end # module

0 commit comments

Comments
 (0)