Skip to content

Commit

Permalink
DistributedAdaptedDiscreteModels now keep the parent gids
Browse files Browse the repository at this point in the history
  • Loading branch information
JordiManyer committed Oct 7, 2024
1 parent 17f8de2 commit 5d1fd16
Showing 1 changed file with 23 additions and 9 deletions.
32 changes: 23 additions & 9 deletions src/Adaptivity.jl
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,12 @@

const DistributedAdaptedDiscreteModel{Dc,Dp} = GenericDistributedDiscreteModel{Dc,Dp,<:AbstractArray{<:AdaptedDiscreteModel{Dc,Dp}}}

struct DistributedAdaptedDiscreteModelCache{A,B,C}
model_matedata::A
parent_metadata::B
parent_gids::C
end

function DistributedAdaptedDiscreteModel(
model :: DistributedDiscreteModel,
parent :: DistributedDiscreteModel,
Expand All @@ -12,23 +18,26 @@ function DistributedAdaptedDiscreteModel(
AdaptedDiscreteModel(model,parent,glue)
end
gids = get_cell_gids(model)
metadata = hasproperty(model,:metadata) ? model.metadata : nothing
metadata = DistributedAdaptedDiscreteModelCache(
model.metadata,parent.metadata,get_cell_gids(parent)
)
return GenericDistributedDiscreteModel(models,gids;metadata)
end

function Adaptivity.get_model(model::DistributedAdaptedDiscreteModel)
GenericDistributedDiscreteModel(
map(get_model,local_views(model)),
get_cell_gids(model);
metadata = hasproperty(model,:metadata) ? model.metadata : nothing
metadata = model.metadata.model_metadata
)
end

function Adaptivity.get_parent(model::DistributedAdaptedDiscreteModel)
msg = " Error: Cannot get global parent model. \n
We do not keep the global ids of the parent model within the children.\n
You can extract the local parents with map(get_parent,local_views(model))"
@notimplemented msg
GenericDistributedDiscreteModel(
map(get_parent,local_views(model)),
model.metadata.parent_gids;
metadata = model.metadata.parent_metadata
)
end

function Adaptivity.get_adaptivity_glue(model::DistributedAdaptedDiscreteModel)
Expand All @@ -48,7 +57,7 @@ function Adaptivity.refine(
fmodel = GenericDistributedDiscreteModel(
map(get_model,local_views(_fmodel)),
get_cell_gids(_fmodel);
metadata=_fmodel.metadata
metadata=_fmodel.metadata.model_metadata
)
glues = get_adaptivity_glue(_fmodel)
return DistributedAdaptedDiscreteModel(fmodel,cmodel,glues)
Expand Down Expand Up @@ -592,7 +601,9 @@ function Adaptivity.refine(
end

fgids = get_cell_gids(fmodel)
metadata = fmodel.metadata
metadata = DistributedAdaptedDiscreteModelCache(
fmodel.metadata,cmodel.metadata,get_cell_gids(cmodel)
)
return GenericDistributedDiscreteModel(fmodels,fgids;metadata)
end

Expand Down Expand Up @@ -909,7 +920,10 @@ function Adaptivity.refine(
) where Dc
fmodels, f_own_to_local = refine_local_models(cmodel,args...;kwargs...)
fgids = refine_cell_gids(cmodel,fmodels,f_own_to_local)
return GenericDistributedDiscreteModel(fmodels,fgids)
metadata = DistributedAdaptedDiscreteModelCache(
nothing,cmodel.metadata,get_cell_gids(cmodel)
)
return GenericDistributedDiscreteModel(fmodels,fgids;metadata)
end

"""
Expand Down

0 comments on commit 5d1fd16

Please sign in to comment.