Skip to content

Commit

Permalink
Merge pull request #57 from zjwegert/jordi-dev
Browse files Browse the repository at this point in the history
Bugfix: Distributed RepeatingAffineFEStateMaps
  • Loading branch information
JordiManyer authored Apr 15, 2024
2 parents 5373019 + c7ffd5c commit 9a048d7
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 6 deletions.
1 change: 1 addition & 0 deletions Project.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ DelimitedFiles = "8bb1440f-4735-579b-a4ab-409b98df4dab"
FillArrays = "1a297f60-69ca-5386-bcde-b61e274b549b"
Gridap = "56d4f2e9-7ea1-5844-9cf6-b9c51ca7ce8e"
GridapDistributed = "f9701e48-63b3-45aa-9a63-9bc6c271f355"
GridapP4est = "c2c8e14b-f5fd-423d-9666-1dd9ad120af9"
GridapPETSc = "bcdc36c2-0c3e-11ea-095a-c9dadae499f1"
GridapSolvers = "6d3209ee-5e3c-4db7-a716-942eb12ed534"
JLD2 = "033835bb-8acc-5ee8-8aae-3f567f8a3819"
Expand Down
6 changes: 3 additions & 3 deletions scripts/MPI/inverse_homenisation_ALM.jl
Original file line number Diff line number Diff line change
Expand Up @@ -21,14 +21,14 @@ function main(mesh_partition,distribute,el_size)
γ = 0.05
γ_reinit = 0.5
max_steps = floor(Int,order*minimum(el_size)/10)
tol = 1/(5order^2)/minimum(el_size)
tol = 1/(5*order^2)/minimum(el_size)
C = isotropic_elast_tensor(2,1.,0.3)
η_coeff = 2
α_coeff = 4max_steps*γ
α_coeff = 4*max_steps*γ
vf = 0.5
path = dirname(dirname(@__DIR__))*"/results/inverse_homenisation_ALM_MPI/"
iter_mod = 10
i_am_main(ranks) && mkdir(path)
#i_am_main(ranks) && mkdir(path)

## FE Setup
model = CartesianDiscreteModel(ranks,mesh_partition,dom,el_size,isperiodic=(true,true));
Expand Down
3 changes: 2 additions & 1 deletion src/ChainRules.jl
Original file line number Diff line number Diff line change
Expand Up @@ -714,7 +714,8 @@ struct RepeatingAffineFEStateMap{A,B,C,D,E,F,G} <: AbstractFEStateMap
U, V = repeat_spaces(nblocks,U0,V0)
spaces = (U,V,V_φ,U_reg)
assem_U = SparseMatrixAssembler(
get_matrix_type(assem_U0),get_vector_type(assem_U0),U,V,FESpaces.get_assembly_strategy(assem_U0)
get_local_matrix_type(assem_U0), get_local_vector_type(assem_U0),
U, V, get_assembly_strategy(assem_U0)
)

## Pullback cache
Expand Down
17 changes: 15 additions & 2 deletions src/GridapExtensions.jl
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ function assemble_adjoint_matrix!(f::Function,A::AbstractMatrix,a::Assembler,U::
end

# Assembly addons

"""
function Gridap.FESpaces.allocate_matrix(a::Function,assem::Assembler,U::FESpace,V::FESpace)
v = get_fe_basis(V)
u = get_trial_fe_basis(U)
Expand All @@ -77,6 +77,18 @@ function Gridap.FESpaces.assemble_matrix_and_vector!(
u = get_trial_fe_basis(U)
assemble_matrix_and_vector!(A,b,assem,collect_cell_matrix_and_vector(U,V,a(u,v),l(v),uhd))
end
"""

get_local_matrix_type(a::Assembler) = get_matrix_type(a)
get_local_vector_type(a::Assembler) = get_vector_type(a)

function get_local_matrix_type(a::GridapDistributed.DistributedSparseMatrixAssembler)
return getany(map(get_matrix_type,a.assems))
end

function get_local_vector_type(a::GridapDistributed.DistributedSparseMatrixAssembler)
return getany(map(get_vector_type,a.assems))
end

# PETScNonlinearSolver override

Expand All @@ -88,8 +100,9 @@ function Gridap.Algebra.solve!(x::T,nls::PETScNonlinearSolver,op::Gridap.Algebra
end

# Stuff from ODE refactor

"""
function (+)(a::Gridap.CellData.DomainContribution,b::GridapDistributed.DistributedDomainContribution)
@assert iszero(Gridap.CellData.num_domains(a))
return b
end
"""
1 change: 1 addition & 0 deletions src/LevelSetTopOpt.jl
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ using Gridap.Helpers, Gridap.Algebra, Gridap.TensorValues
using Gridap.Geometry, Gridap.CellData, Gridap.Fields
using Gridap.ReferenceFEs, Gridap.FESpaces, Gridap.MultiField
using Gridap.Geometry: get_faces
using Gridap.FESpaces: get_assembly_strategy
using Gridap: writevtk

using GridapDistributed
Expand Down

0 comments on commit 9a048d7

Please sign in to comment.