Skip to content

Commit b87d15a

Browse files
Coarsening and refinement working in parallel. There are still some
smells, though, to be solved.
1 parent 2f1f2e5 commit b87d15a

File tree

3 files changed

+225
-83
lines changed

3 files changed

+225
-83
lines changed

src/GridapFixes.jl

+16-31
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ function Gridap.Adaptivity.change_domain_o2n(
8787
f_old,
8888
old_trian::Triangulation{Dc},
8989
new_trian::AdaptedTriangulation,
90-
glue::AdaptivityGlue) where {Dc}
90+
glue::AdaptivityGlue{<:Gridap.Adaptivity.MixedGlue}) where {Dc}
9191

9292
oglue = get_glue(old_trian,Val(Dc))
9393
nglue = get_glue(new_trian,Val(Dc))
@@ -143,38 +143,34 @@ struct OldToNewField <: Gridap.Fields.Field
143143
end
144144

145145
function OldToNewField(old_fields::AbstractArray{<:Gridap.Fields.Field},rrule::RefinementRule,child_id::Integer)
146-
if length(old_fields)==1
146+
if child_id != -1
147+
@assert length(old_fields)==1
147148
cell_map = get_cell_map(rrule)[child_id]
148149
old_field=old_fields[1]
149150
fine_to_coarse_field=Gridap.Adaptivity.FineToCoarseField(
150151
[old_field for i=1:Gridap.Adaptivity.num_subcells(rrule)],
151-
rrule)
152+
rrule,
153+
[i for i=1:Gridap.Adaptivity.num_subcells(rrule)])
152154
refined_or_untouched_field=old_fieldcell_map
153155
OldToNewField(RefinedOrUntouchedNewFieldType(),fine_to_coarse_field,refined_or_untouched_field)
154156
else
155-
Gridap.Helpers.@check length(old_fields) == Gridap.Adaptivity.num_subcells(rrule)
156-
Gridap.Helpers.@check child_id==-1
157+
@assert length(old_fields) <= Gridap.Adaptivity.num_subcells(rrule)
158+
if (length(old_fields)==Gridap.Adaptivity.num_subcells(rrule))
159+
# Use optimized version of FineToCoarseField (we can do this for the coarsened owned cells)
160+
child_ids=[i for i=1:length(old_fields)]
161+
fine_to_coarse_field=Gridap.Adaptivity.FineToCoarseField(old_fields,rrule,child_ids)
162+
else
163+
# For the ghost coarsened cells we are missing information. Namely the child_ids of the children.
164+
# TO-DO: by now we can use the wrong child_ids, but we should fix this in the future.
165+
child_ids=[i for i=1:length(old_fields)]
166+
fine_to_coarse_field=Gridap.Adaptivity.FineToCoarseField(old_fields,rrule,child_ids)
167+
end
157168
cell_map = get_cell_map(rrule)[1]
158-
fine_to_coarse_field=Gridap.Adaptivity.FineToCoarseField(old_fields,rrule)
159169
refined_or_untouched_field=old_fields[1]cell_map
160170
OldToNewField(CoarsenedNewFieldType(),fine_to_coarse_field,refined_or_untouched_field)
161171
end
162172
end
163173

164-
function OldToNewField(old_field::Gridap.Fields.Field,rrule::RefinementRule,child_id::Integer)
165-
Gridap.Helpers.@notimplemented
166-
end
167-
168-
# # Necessary for distributed meshes, where not all children of a coarse cell may belong to the processor.
169-
# function FineToCoarseField(fine_fields::AbstractArray{<:Field},rrule::RefinementRule,child_ids::AbstractArray{<:Integer})
170-
# fields = Vector{Field}(undef,num_subcells(rrule))
171-
# fields = fill!(fields,ConstantField(0.0))
172-
# for (k,id) in enumerate(child_ids)
173-
# fields[id] = fine_fields[k]
174-
# end
175-
# return FineToCoarseField(fields,rrule)
176-
# end
177-
178174
function Gridap.Fields.return_cache(a::OldToNewField,x::AbstractArray{<:Point})
179175
f2c_cache=Gridap.Fields.return_cache(a.fine_to_coarse_field,x)
180176
rou_cache=Gridap.Fields.return_cache(a.refined_or_untouched_field,x)
@@ -190,15 +186,4 @@ function Gridap.Fields.evaluate!(cache,a::OldToNewField,x::AbstractArray{<:Point
190186
f2c_cache,rou_cache = cache
191187
Gridap.Fields.evaluate!(rou_cache,a.refined_or_untouched_field,x)
192188
end
193-
end
194-
195-
# Fast evaluation of FineToCoarseFields:
196-
# Points are pre-classified into the children cells, which allows for the search to be
197-
# skipped entirely.
198-
function Gridap.Fields.return_cache(a::OldToNewField,x::AbstractArray{<:Point},child_ids::AbstractArray{<:Integer})
199-
Gridap.Helpers.@notimplemented
200-
end
201-
202-
function Gridap.Fields.evaluate!(cache,a::OldToNewField,x::AbstractArray{<:Point},child_ids::AbstractArray{<:Integer})
203-
Gridap.Helpers.@notimplemented
204189
end

0 commit comments

Comments
 (0)