Skip to content

Commit

Permalink
Adapted ZeroMeanDistributedFESpaces to latest changes in Gridap.master
Browse files Browse the repository at this point in the history
  • Loading branch information
amartinhuertas committed Sep 16, 2020
1 parent 94df2cd commit 0b95e0f
Show file tree
Hide file tree
Showing 3 changed files with 52 additions and 45 deletions.
12 changes: 6 additions & 6 deletions Manifest.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,9 @@ version = "2.12.0"

[[ArrayLayouts]]
deps = ["FillArrays", "LinearAlgebra", "SparseArrays"]
git-tree-sha1 = "e3e0a1e7dcbfdb1fc1061bfd889581a1d942cfcb"
git-tree-sha1 = "bd09f450716f55c5a47b24de277a8825e2450729"
uuid = "4c555306-a7a7-4459-81d9-ec55ddd5c99a"
version = "0.4.5"
version = "0.4.7"

[[BSON]]
git-tree-sha1 = "dd36d7cf3d185eeaaf64db902c15174b22f5dafb"
Expand Down Expand Up @@ -135,8 +135,8 @@ version = "0.10.12"

[[Gridap]]
deps = ["AbstractTrees", "BSON", "BlockArrays", "Combinatorics", "DocStringExtensions", "FastGaussQuadrature", "FileIO", "FillArrays", "ForwardDiff", "JLD2", "JSON", "LineSearches", "LinearAlgebra", "NLsolve", "QuadGK", "SparseArrays", "StaticArrays", "Test", "WriteVTK"]
git-tree-sha1 = "7838554a8092b4e69042be94639f0276a55f3ecb"
repo-rev = "fe_space_with_dof_potentially_removed"
git-tree-sha1 = "d5470611f212c4ca8feda47b384ecda3cd8ec5b6"
repo-rev = "master"
repo-url = "https://github.com/gridap/Gridap.jl"
uuid = "56d4f2e9-7ea1-5844-9cf6-b9c51ca7ce8e"
version = "0.14.0"
Expand All @@ -153,9 +153,9 @@ version = "0.1.14"

[[JSON]]
deps = ["Dates", "Mmap", "Parsers", "Unicode"]
git-tree-sha1 = "b34d7cef7b337321e97d22242c3c2b91f476748e"
git-tree-sha1 = "81690084b6198a2e1da36fcfda16eeca9f9f24e4"
uuid = "682c06a0-de6a-54ab-a142-c8b1cf79cde6"
version = "0.21.0"
version = "0.21.1"

[[LibGit2]]
deps = ["Printf"]
Expand Down
29 changes: 19 additions & 10 deletions src/ZeroMeanDistributedFESpaces.jl
Original file line number Diff line number Diff line change
Expand Up @@ -49,14 +49,14 @@ end
function _generate_zero_mean_funs(dV::ZeroMeanDistributedFESpace, funs)
dpartial_sums_fixed_val=
DistributedData(dV.spaces, funs, dV.vol_i, dV.vol) do part, V, fun, vol_i, vol
if (get_val_parameter(V.remove_dof))
if (constant_fixed(V))
fv=get_free_values(fun)
dv=get_dirichlet_values(fun)
c=Gridap.FESpaces._compute_new_fixedval(fv,
dv,
vol_i,
vol,
V.dof_to_remove)
V.dof_to_fix)
else
fv=get_free_values(fun)
c=-dot(fv,vol_i)/vol
Expand All @@ -72,7 +72,7 @@ function _generate_zero_mean_funs(dV::ZeroMeanDistributedFESpace, funs)
dfuns = DistributedData(dV.spaces, funs, dfixed_val) do part, V, fun, fixed_val
free_values=get_free_values(fun)
fv=apply(+,free_values, Fill(fixed_val,length(free_values)))
if (get_val_parameter(V.remove_dof))
if (constant_fixed(V))
dirichlet_values=get_dirichlet_values(fun)
dv = dirichlet_values .+ fixed_val
return FEFunction(V,fv,dv)
Expand All @@ -82,6 +82,15 @@ function _generate_zero_mean_funs(dV::ZeroMeanDistributedFESpace, funs)
end
end

function constant_fixed(V::FESpaceWithConstantFixed{CS,Gridap.FESpaces.FixConstant}) where {CS}
true
end

function constant_fixed(V::FESpaceWithConstantFixed{CS,CA}) where {CS,CA}
false
end


function ZeroMeanDistributedFESpace(::Type{V};
model::DistributedDiscreteModel,
kwargs...) where V
Expand All @@ -93,17 +102,17 @@ function ZeroMeanDistributedFESpace(::Type{V};
comm = get_comm(model)
spaces = DistributedData(init_local_spaces,comm,model.models)

dof_lid_to_remove = _compute_dof_lid_to_remove(model,spaces)
dof_lid_to_fix = _compute_dof_lid_to_fix(model,spaces)

function init_local_spaces_with_dof_removed(part,lspace,dof_lid_to_remove)
Gridap.FESpaces.FESpaceWithDofPotentiallyRemoved(
lspace, dof_lid_to_remove != -1, dof_lid_to_remove)
function init_local_spaces_with_dof_removed(part,lspace,dof_lid_to_fix)
Gridap.FESpaces.FESpaceWithConstantFixed(
lspace, dof_lid_to_fix != -1, dof_lid_to_fix)
end

spaces_dof_removed = DistributedData(init_local_spaces_with_dof_removed,
comm,
spaces,
dof_lid_to_remove)
dof_lid_to_fix)

order=Gridap.FESpaces._get_kwarg(:order,kwargs)
dvol_i, dvol = _setup_vols(model,spaces,order)
Expand Down Expand Up @@ -134,7 +143,7 @@ function _setup_vols(model,spaces,order)
(dvol_i,dvol)
end

function _compute_dof_lid_to_remove(model,spaces)
function _compute_dof_lid_to_fix(model,spaces)
dof_lids_candidates=DistributedData(model.gids,spaces) do part, cell_gids, lspace
n_free_dofs = num_free_dofs(lspace)
lid_to_n_local_minus_ghost=zeros(Int32,n_free_dofs)
Expand Down Expand Up @@ -167,5 +176,5 @@ function _compute_dof_lid_to_remove(model,spaces)
end
end

dof_lid_to_remove = scatter(comm,part_dof_lids_candidates)
dof_lid_to_fix = scatter(comm,part_dof_lids_candidates)
end
56 changes: 27 additions & 29 deletions test/DistributedStokesTests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -45,35 +45,33 @@ function run(comm,subdomains,assembly_strategy::AbstractString, global_dofs::Boo
add_tag_from_tags!(labels,"neumann",[5])
end

# Build local and global test FE spaces
spaces = DistributedData(comm, model) do part, (model,gids)
labels = get_face_labeling(model)
V = TestFESpace(
reffe=:QLagrangian,
conformity=:H1,
valuetype=VectorValue{2,Float64},
model=model,
labels=labels,
order=2,
dirichlet_tags=["diri0","diri1"])
Q = TestFESpace(
reffe=:PLagrangian,
conformity=:L2,
valuetype=Float64,
model=model,
order=1) #,
#constraint=:zeromean)
MultiFieldFESpace([V,Q])
end
Y=GridapDistributed.DistributedFESpaceFromLocalFESpaces(vector_type,model,spaces)

# Build local and global trial FE spaces
trialspaces = DistributedData(comm, Y) do part, (y,gids)
U=TrialFESpace(y.spaces[1],[u,u])
P=TrialFESpace(y.spaces[2])
MultiFieldFESpace([U,P])
end
X=GridapDistributed.DistributedFESpaceFromLocalFESpaces(vector_type,trialspaces,Y.gids)
# FE Spaces
order = 2
V = FESpace(
vector_type,
valuetype = VectorValue{2,Float64},
reffe=:QLagrangian,
order = order,
model = model,
conformity = :H1,
dirichlet_tags=["diri0","diri1"],
)

Q = FESpace(
vector_type,
reffe=:PLagrangian,
conformity=:L2,
valuetype=Float64,
model=model,
order=order-1)
#constraint=:zeromean)

Y=MultiFieldFESpace(model,[V,Q])

U=TrialFESpace(V,[u,u])
P=TrialFESpace(Q)
X=MultiFieldFESpace(Y,[U,P])

if (assembly_strategy == "RowsComputedLocally")
strategy = RowsComputedLocally(Y; global_dofs=global_dofs)
Expand Down Expand Up @@ -113,7 +111,7 @@ function run(comm,subdomains,assembly_strategy::AbstractString, global_dofs::Boo
# Assembler
assem = SparseMatrixAssembler(matrix_type, vector_type, X, Y, strategy)

# FE solution
# # FE solution
op = AffineFEOperator(assem, terms)
xh = solve(op)

Expand Down

0 comments on commit 0b95e0f

Please sign in to comment.