@@ -85,66 +85,87 @@ function main(distribute,parts,das)
8585 model = CartesianDiscreteModel (ranks,parts,domain,cells)
8686 Ω = Triangulation (model)
8787 Γ = Boundary (model)
88+ dΩ = Measure (Ω,3 )
89+
90+ function _interpolation_tests (u,model,Ω,Γ,output)
91+ reffe = ReferenceFE (lagrangian,Float64,1 )
92+ V = TestFESpace (model,reffe,dirichlet_tags= " boundary" )
93+ U = TrialFESpace (u,V)
94+ V2 = FESpace (Ω,reffe)
95+ @test get_vector_type (V) <: PVector{<:Vector}
96+ @test get_vector_type (U) <: PVector{<:Vector}
97+ @test get_vector_type (V2) <: PVector{<:Vector}
98+
99+ free_values_partition = map (partition (V. gids)) do indices
100+ ones (Float64,local_length (indices))
101+ end
102+
103+ free_values = PVector (free_values_partition,partition (V. gids))
104+ fh = FEFunction (U,free_values)
105+ zh = zero (U)
106+ uh = interpolate (u,U)
107+ eh = u - uh
108+
109+ uh_dir = interpolate_dirichlet (u,U)
110+ free_values = zero_free_values (U)
111+ dirichlet_values = get_dirichlet_dof_values (U)
112+ uh_dir2 = interpolate_dirichlet! (u,free_values,dirichlet_values,U)
113+
114+ uh_everywhere = interpolate_everywhere (u,U)
115+ dirichlet_values0 = zero_dirichlet_values (U)
116+ uh_everywhere_ = interpolate_everywhere! (u,free_values,dirichlet_values0,U)
117+ eh2 = u - uh_everywhere
118+ eh2_ = u - uh_everywhere_
119+
120+ uh_everywhere2 = interpolate_everywhere (uh_everywhere,U)
121+ uh_everywhere2_ = interpolate_everywhere! (uh_everywhere,free_values,dirichlet_values,U)
122+ eh3 = u - uh_everywhere2
123+
124+ dofs = get_fe_dof_basis (U)
125+ cell_vals = dofs (uh)
126+ gather_free_values! (free_values,U,cell_vals)
127+ gather_free_and_dirichlet_values! (free_values,dirichlet_values,U,cell_vals)
128+ uh4 = FEFunction (U,free_values,dirichlet_values)
129+ eh4 = u - uh4
130+
131+ dΩ = Measure (Ω,3 )
132+ cont = ∫ ( abs2 (eh) )dΩ
133+ cont2 = ∫ ( abs2 (eh2) )dΩ
134+ cont2_ = ∫ ( abs2 (eh2_) )dΩ
135+ cont3 = ∫ ( abs2 (eh3) )dΩ
136+ cont4 = ∫ ( abs2 (eh4) )dΩ
137+ @test sqrt (sum (cont)) < 1.0e-9
138+ @test sqrt (sum (cont2)) < 1.0e-9
139+ @test sqrt (sum (cont2_)) < 1.0e-9
140+ @test sqrt (sum (cont3)) < 1.0e-9
141+ @test sqrt (sum (cont4)) < 1.0e-9
142+
143+ writevtk (Ω,joinpath (output," Ω" ), nsubcells= 10 ,
144+ celldata= [" err" => cont[Ω]],
145+ cellfields= [" uh" => uh," zh" => zh," eh" => eh])
146+
147+ writevtk (Γ,joinpath (output," Γ" ),cellfields= [" uh" => uh])
148+ end
88149
150+ # Testing interpolation with a Julia function
89151 u ((x,y)) = x+ y
152+ _interpolation_tests (u,model,Ω,Γ,output)
153+
154+ # Testing interpolation with a DistributedCellField
155+ # The DistributedCellField MUST be defined in all cells
156+ # (i.e., owned + ghost) for the tests within
157+ # _interpolation_tests(...) to pass. The problematic part is
158+ # in the interpolation of the dirichlet values
159+ Ωghosts = Triangulation (with_ghost, model)
160+ fields = map (local_views (Ωghosts)) do Ω
161+ CellField (u,Ω)
162+ end
163+ u_cf = GridapDistributed. DistributedCellField (fields,Ωghosts)
164+ _interpolation_tests (u_cf,model,Ωghosts,Γ,output)
165+
90166 reffe = ReferenceFE (lagrangian,Float64,1 )
91167 V = TestFESpace (model,reffe,dirichlet_tags= " boundary" )
92168 U = TrialFESpace (u,V)
93- V2 = FESpace (Ω,reffe)
94- @test get_vector_type (V) <: PVector{<:Vector}
95- @test get_vector_type (U) <: PVector{<:Vector}
96- @test get_vector_type (V2) <: PVector{<:Vector}
97-
98- free_values_partition = map (partition (V. gids)) do indices
99- ones (Float64,local_length (indices))
100- end
101-
102- free_values = PVector (free_values_partition,partition (V. gids))
103- fh = FEFunction (U,free_values)
104- zh = zero (U)
105- uh = interpolate (u,U)
106- eh = u - uh
107-
108- uh_dir = interpolate_dirichlet (u,U)
109- free_values = zero_free_values (U)
110- dirichlet_values = get_dirichlet_dof_values (U)
111- uh_dir2 = interpolate_dirichlet! (u,free_values,dirichlet_values,U)
112-
113- uh_everywhere = interpolate_everywhere (u,U)
114- dirichlet_values0 = zero_dirichlet_values (U)
115- uh_everywhere_ = interpolate_everywhere! (u,free_values,dirichlet_values0,U)
116- eh2 = u - uh_everywhere
117- eh2_ = u - uh_everywhere_
118-
119- uh_everywhere2 = interpolate_everywhere (uh_everywhere,U)
120- uh_everywhere2_ = interpolate_everywhere! (uh_everywhere,free_values,dirichlet_values,U)
121- eh3 = u - uh_everywhere2
122-
123- dofs = get_fe_dof_basis (U)
124- cell_vals = dofs (uh)
125- gather_free_values! (free_values,U,cell_vals)
126- gather_free_and_dirichlet_values! (free_values,dirichlet_values,U,cell_vals)
127- uh4 = FEFunction (U,free_values,dirichlet_values)
128- eh4 = u - uh4
129-
130- dΩ = Measure (Ω,3 )
131- cont = ∫ ( abs2 (eh) )dΩ
132- cont2 = ∫ ( abs2 (eh2) )dΩ
133- cont2_ = ∫ ( abs2 (eh2_) )dΩ
134- cont3 = ∫ ( abs2 (eh3) )dΩ
135- cont4 = ∫ ( abs2 (eh4) )dΩ
136- @test sqrt (sum (cont)) < 1.0e-9
137- @test sqrt (sum (cont2)) < 1.0e-9
138- @test sqrt (sum (cont2_)) < 1.0e-9
139- @test sqrt (sum (cont3)) < 1.0e-9
140- @test sqrt (sum (cont4)) < 1.0e-9
141-
142-
143- writevtk (Ω,joinpath (output," Ω" ), nsubcells= 10 ,
144- celldata= [" err" => cont[Ω]],
145- cellfields= [" uh" => uh," zh" => zh," eh" => eh])
146-
147- writevtk (Γ,joinpath (output," Γ" ),cellfields= [" uh" => uh])
148169
149170 # Assembly
150171 Ωass = Triangulation (das,model)
0 commit comments