GridapSolvers.MultilevelTools
Nested subpartitions
One of the main difficulties of multilevel algorithms is dealing with the complexity of having multiple subcommunicators. We provide some tools to deal with it. In particular we introduce HierarchicalArrays.
GridapSolvers.MultilevelTools.generate_level_parts — Functiongenerate_level_parts(root_parts::AbstractArray,num_procs_x_level::Vector{<:Integer})From a root communicator root_parts, generate a sequence of nested subcommunicators with sizes given by num_procs_x_level.
GridapSolvers.MultilevelTools.HierarchicalArray — TypeHierarchicalArray{T,A,B} <: AbstractVector{T}Array of hierarchical (nested) distributed objects. Each level might live in a different subcommunicator. If a processor does not belong to subcommunicator ranks[i], then array[i] is nothing.
However, it assumes:
- The subcommunicators are nested, so that
ranks[i]containsranks[i+1]. - The first subcommunicator does not have empty parts.
Base.map — FunctionBase.map(f::Function,args::Vararg{HierarchicalArray,N}) where NMaps a function to a set of HierarchicalArrays. The function is applied only in the subcommunicators where the processor belongs to.
GridapSolvers.MultilevelTools.with_level — Functionwith_level(f::Function,a::HierarchicalArray,lev::Integer;default=nothing)Applies a function to the lev-th level of a HierarchicalArray. If the processor does not belong to the subcommunicator of the lev-th level, then default is returned.
ModelHierarchies and FESpaceHierarchies
This objects are the multilevel counterparts of Gridap's DiscreteModel and FESpace.
GridapSolvers.MultilevelTools.ModelHierarchy — Typeconst ModelHierarchy = HierarchicalArray{<:ModelHierarchyLevel}A ModelHierarchy is a hierarchical array of ModelHierarchyLevel objects. It stores the adapted/redistributed models and the corresponding subcommunicators.
For convenience, implements some of the API of DiscreteModel.
GridapSolvers.MultilevelTools.ModelHierarchyLevel — Typestruct ModelHierarchyLevel{A,B,C,D}
level :: Int
model :: A
ref_glue :: B
model_red :: C
red_glue :: D
endSingle level for a ModelHierarchy.
Note that model_red and red_glue might be of type Nothing whenever there is no redistribution in a given level.
ref_glue is of type Nothing on the coarsest level.
GridapSolvers.MultilevelTools.CartesianModelHierarchy — FunctionCartesianModelHierarchy(
ranks::AbstractVector{<:Integer},
np_per_level::Vector{<:NTuple{D,<:Integer}},
domain::Tuple,
nc::NTuple{D,<:Integer};
nrefs::Union{<:Integer,Vector{<:Integer},Vector{<:NTuple{D,<:Integer}},NTuple{D,<:Integer}},
map::Function = identity,
isperiodic::NTuple{D,Bool} = Tuple(fill(false,D)),
add_labels!::Function = (labels -> nothing),
) where DReturns a ModelHierarchy with a Cartesian model as coarsest level. The i-th level will be distributed among np_per_level[i] processors. Two consecutive levels are refined by a factor of nrefs[i].
Parameters:
ranks: Initial communicator. Will be used to generate subcommunicators.domain: Tuple containing the domain limits.nc: Tuple containing the number of cells in each direction for the coarsest model.np_per_level: Vector containing the number of processors we want to distribute each level into. Requires a tuplenp = (np_1,...,np_d)for each level, then each level will be distributed amongprod(np)processors withnp_iprocessors in the i-th direction.nrefs: Vector containing the refinement factor for each level. Hasnlevs-1entries, and each entry can either be an integer (homogeneous refinement) or a tuple withDintegers (inhomogeneous refinement).
GridapSolvers.MultilevelTools.FESpaceHierarchy — Typeconst FESpaceHierarchy = HierarchicalArray{<:FESpaceHierarchyLevel}A FESpaceHierarchy is a hierarchical array of FESpaceHierarchyLevel objects. It stores the adapted/redistributed fe spaces and the corresponding subcommunicators.
For convenience, implements some of the API of FESpace.
Grid transfer operators
To move information between different levels, we will require grid transfer operators. Although any custom-made operator can be used, we provide some options.
GridapSolvers.MultilevelTools.DistributedGridTransferOperator — TypeGridapSolvers.MultilevelTools.RestrictionOperator — FunctionGridapSolvers.MultilevelTools.ProlongationOperator — FunctionGridapSolvers.MultilevelTools.MultiFieldTransferOperator — TypeLocal projection maps
GridapSolvers.MultilevelTools.LocalProjectionMap — Typeabstract type LocalProjectionMap{T} <: Map endGridapSolvers.MultilevelTools.ReffeProjectionMap — Typestruct ReffeProjectionMap{T} <: LocalProjectionMap{T}
op :: Operation{T}
reffe :: Tuple{<:ReferenceFEName,Any,Any}
qdegree :: Int
endMap that projects a field/field-basis onto another local reference space given by a ReferenceFE.
Example:
model = CartesianDiscreteModel((0,1,0,1),(2,2))
reffe_h1 = ReferenceFE(QUAD,lagrangian,Float64,1,space=:Q)
reffe_l2 = ReferenceFE(QUAD,lagrangian,Float64,1,space=:P)
U = FESpace(model,reffe_h1)
u_h1 = interpolate(f,U)
Ω = Triangulation(model)
dΩ = Measure(Ω,2)
Π = LocalProjectionMap(reffe_l2)
u_l2 = Π(u_h1,dΩ)GridapSolvers.MultilevelTools.SpaceProjectionMap — Typestruct SpaceProjectionMap{T} <: LocalProjectionMap{T}
op :: Operation{T}
space :: A
qdegree :: Int
endMap that projects a CellField onto another FESpace. Necessary when the arrival space has constraints (e.g. boundary conditions) that need to be taken into account.