Skip to content

Commit ffcfaaf

Browse files
committed
Add new changes to interpolation_fe
1 parent 2bbb8a7 commit ffcfaaf

5 files changed

Lines changed: 36 additions & 21 deletions

File tree

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,3 +7,4 @@ Manifest.toml
77
tmp/
88
.vscode/
99
*.code-workspace
10+
*.DS_Store

Project.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ Random = "9a3f8284-a2c9-5f02-9a11-845980a1fd5c"
2020
SpecialFunctions = "276daf66-3868-5448-9aa4-cd146d93841b"
2121

2222
[compat]
23-
Gridap = "0.16.3"
23+
Gridap = "0.16.4"
2424
GridapGmsh = "0.4"
2525
SpecialFunctions = "1"
2626
julia = "1.3"

assets/interpolation/.DS_Store

-6 KB
Binary file not shown.
File renamed without changes.

src/interpolation_fe.jl

Lines changed: 34 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -43,20 +43,13 @@ partition = (5,5)
4343
# obtain the `FEFunction` in the new space from the old one by
4444
# evaluating the appropriate degrees of freedom. Interpolation works
4545
# using the composite type `Interpolable` to tell `Gridap` that the
46-
# argument can be interpolated between triangulations. This can be
47-
# done using any of the methods
48-
# ```julia
49-
# interpolate(ifₕ::Interpolable, new_fe_space::FESpace)
50-
# interpolate_everywhere(ifₕ::Interpolable, new_fe_space::FESpace)
51-
# interpolate_dirichlet(ifₕ::Interpolable, new_fe_space::FESpace)
52-
# ```
53-
# available in `Gridap`
46+
# argument can be interpolated between triangulations.
5447

5548
# ## Interpolating between Lagrangian FE Spaces
5649

5750
# Let us define the infinite dimensional function
5851

59-
f(x) = x[1] + x[2]
52+
f(x) = x[1] + x[2]
6053

6154
# This function will be interpolated to the source `FESpace`
6255
# $V_1$. The space can be built using
@@ -66,7 +59,7 @@ V₁ = FESpace(𝒯₁, reffe₁)
6659

6760
# Finally to build the function $f_h$, we do
6861

69-
fₕ = interpolate_everywhere(f,V₁)
62+
fₕ = interpolate_everywhere(f,V₁)
7063

7164
# To construct arbitrary points in the domain, we use `Random` package:
7265

@@ -81,8 +74,8 @@ fₕ(pt), fₕ.(pts)
8174

8275
# We can also check our results using
8376

84-
@test fₕ(pt) f(pt)
85-
@test fₕ.(pts) f.(pts)
77+
@test fₕ(pt) f(pt)
78+
@test fₕ.(pts) f.(pts)
8679

8780
# Now let us define the new triangulation $\mathcal{T}_2$ of
8881
# $\Omega$. We define the map
@@ -119,10 +112,31 @@ ifₕ = Interpolable(fₕ)
119112

120113
gₕ = interpolate_everywhere(ifₕ, V₂)
121114

122-
# Like earlier we can check our results
115+
# We can also use
116+
# `interpolate` if interpolating only on the free dofs or
117+
# `interpolate_dirichlet` if interpolating the Dirichlet dofs of the
118+
# `FESpace`.
119+
120+
ḡₕ = interpolate(ifₕ, V₂)
121+
122+
# The finite element function $\bar{g}_h$ is the same as $g_h$ in this
123+
# example since all the dofs are free.
124+
125+
@test gₕ.cell_dof_values == ḡₕ.cell_dof_values
126+
127+
# Now we obtain a finite element function using `interpolate_dirichlet`
128+
129+
g̃ₕ = interpolate_dirichlet(ifₕ, V₂)
130+
131+
# Now $\tilde{g}_h$ will be equal to 0 since there are
132+
# no Dirichlet nodes defined in the `FESpace`. We can check by running
133+
134+
g̃ₕ.cell_dof_values
135+
136+
# Like earlier we can check our results for `gₕ`:
123137

124-
@test fₕ(pt) gₕ(pt) f(pt)
125-
@test fₕ.(pts) gₕ.(pts) f.(pts)
138+
@test fₕ(pt) gₕ(pt) f(pt)
139+
@test fₕ.(pts) gₕ.(pts) f.(pts)
126140

127141
# We can visualize the results using Paraview
128142

@@ -131,7 +145,7 @@ writevtk(get_triangulation(gₕ), "target", cellfields=["gₕ"=>gₕ])
131145

132146
# which produces the following output
133147

134-
# ![Target](../assets/interpolation/target.png)
148+
# ![Target](../assets/interpolation_fe/source_and_target.png)
135149

136150
# ## Interpolating between Raviart-Thomas FESpaces
137151

@@ -146,14 +160,14 @@ writevtk(get_triangulation(gₕ), "target", cellfields=["gₕ"=>gₕ])
146160

147161
# Assuming a function
148162

149-
f(x) = VectorValue([x[1], x[2]])
163+
f(x) = VectorValue([x[1], x[2]])
150164

151165
# on the domain, we build the associated finite dimensional version
152166
# $f_h \in V_1$.
153167

154168
reffe₁ = ReferenceFE(raviart_thomas, Float64, 1) # RT space of order 1
155169
V₁ = FESpace(𝒯₁, reffe₁)
156-
fₕ = interpolate_everywhere(f, V₁)
170+
fₕ = interpolate_everywhere(f, V₁)
157171

158172
# As before, we can evaluate the RT function on any arbitrary point in
159173
# the domain.
@@ -163,7 +177,7 @@ fₕ(pt), fₕ.(pts)
163177
# Constructing the target RT space and building the `Interpolable`
164178
# object,
165179

166-
reffe₂ = ReferenceFE(raviart_thomas, Float64, 2) # RT space of order 2
180+
reffe₂ = ReferenceFE(raviart_thomas, Float64, 1) # RT space of order 1
167181
V₂ = FESpace(𝒯₂, reffe₂)
168182
if= Interpolable(fₕ)
169183

@@ -173,4 +187,4 @@ gₕ = interpolate_everywhere(ifₕ, V₂)
173187

174188
# Like earlier we can check our results
175189

176-
gₕ(pt), f(pt)
190+
gₕ(pt), f(pt)

0 commit comments

Comments
 (0)