From 73cea75a7cabb4a3234ac99a65bac2eeaac7a708 Mon Sep 17 00:00:00 2001 From: Connor Date: Tue, 22 Mar 2022 15:57:33 +1100 Subject: [PATCH 01/12] running but sensitivity zero --- src/Arrays/LazyArrays.jl | 2 ++ src/Arrays/PosNegReindex.jl | 2 +- src/Arrays/Tables.jl | 9 ++++++++- src/FESpaces/FEAutodiff.jl | 16 ++++++++++++---- src/FESpaces/UnconstrainedFESpaces.jl | 2 ++ src/Fields/Fields.jl | 1 + src/Geometry/CartesianDiscreteModels.jl | 1 + test/GridapTests/StokesNitscheTests.jl | 3 ++- test/GridapTests/SurfaceCouplingTests.jl | 6 +++++- 9 files changed, 34 insertions(+), 8 deletions(-) diff --git a/src/Arrays/LazyArrays.jl b/src/Arrays/LazyArrays.jl index 76b70f075..a6126aa3c 100644 --- a/src/Arrays/LazyArrays.jl +++ b/src/Arrays/LazyArrays.jl @@ -241,6 +241,8 @@ Base.size(a::LazyArray{G,T,1} where {G,T}) = (length(a.maps),) function Base.sum(a::LazyArray) cache = array_cache(a) + #@code_warntype _sum_lazy_array(cache,a) + #@show typeof(cache) _sum_lazy_array(cache,a) end diff --git a/src/Arrays/PosNegReindex.jl b/src/Arrays/PosNegReindex.jl index 7bb0d3354..2c94c24db 100644 --- a/src/Arrays/PosNegReindex.jl +++ b/src/Arrays/PosNegReindex.jl @@ -9,7 +9,7 @@ end function testargs(k::PosNegReindex,i::Integer) @check length(k.values_pos) !=0 || length(k.values_neg) != 0 "This map has empty domain" - @check eltype(k.values_pos) == eltype(k.values_neg) "This map is type-instable" + #@check eltype(k.values_pos) == eltype(k.values_neg) "This map is type-instable" length(k.values_pos) !=0 ? (one(i),) : (-one(i)) end diff --git a/src/Arrays/Tables.jl b/src/Arrays/Tables.jl index a11902662..2cd362026 100644 --- a/src/Arrays/Tables.jl +++ b/src/Arrays/Tables.jl @@ -326,7 +326,14 @@ Equivalent to [a[i] for in 1:length(a)] """ -collect1d(a) = [a[i] for i in 1:length(a)] +function collect1d(a) + #@show a + #b = collect(Base.Iterators.Flatten(a)) # + [a[i] for i in 1:length(a)] + #@show b + #b +end + function lazy_map(::typeof(getindex),a::Table,b::AbstractArray{<:Integer}) LocalItemFromTable(a,b) diff --git a/src/FESpaces/FEAutodiff.jl b/src/FESpaces/FEAutodiff.jl index bde59856a..35d80120c 100644 --- a/src/FESpaces/FEAutodiff.jl +++ b/src/FESpaces/FEAutodiff.jl @@ -97,11 +97,19 @@ function _hessian(f,uh,fuh::DomainContribution) end function _change_argument(op,f,trian,uh::SingleFieldFEFunction) - U = get_fe_space(uh) + #U = get_fe_space(uh) + function g(cell_u) - cf = CellField(U,cell_u) - cell_grad = f(cf) - get_contribution(cell_grad,trian) + #cf = CellField(U,cell_u) + #cell_grad = f(cf) + cell_grad = f(cell_u) +# get_contribution(cell_grad,trian) + + #@show cell_grad.dict[first(get_domains(cell_grad)) ] + cell_grad.dict[first(get_domains(cell_grad)) ] + + #get_contribution(cell_grad,trian) + end g end diff --git a/src/FESpaces/UnconstrainedFESpaces.jl b/src/FESpaces/UnconstrainedFESpaces.jl index 0a9ca2b05..53574efd5 100644 --- a/src/FESpaces/UnconstrainedFESpaces.jl +++ b/src/FESpaces/UnconstrainedFESpaces.jl @@ -65,6 +65,7 @@ zero_dirichlet_values(f::UnconstrainedFESpace) = allocate_vector(f.vector_type,n get_dirichlet_dof_tag(f::UnconstrainedFESpace) = f.dirichlet_dof_tag function scatter_free_and_dirichlet_values(f::UnconstrainedFESpace,free_values,dirichlet_values) + #= @check eltype(free_values) == eltype(dirichlet_values) """\n The entries stored in free_values and dirichlet_values should be of the same type. @@ -72,6 +73,7 @@ function scatter_free_and_dirichlet_values(f::UnconstrainedFESpace,free_values,d if the Dirichlet values of the underlying space are of type Float64, or when the given free values are Float64 and the Dirichlet values ComplexF64. """ + =# cell_dof_ids = get_cell_dof_ids(f) lazy_map(Broadcasting(PosNegReindex(free_values,dirichlet_values)),cell_dof_ids) end diff --git a/src/Fields/Fields.jl b/src/Fields/Fields.jl index 1786d6111..8887fe67e 100644 --- a/src/Fields/Fields.jl +++ b/src/Fields/Fields.jl @@ -59,6 +59,7 @@ export AffineMap export affine_map export gradient +export _gradient export ∇ export ∇∇ export gradient_type diff --git a/src/Geometry/CartesianDiscreteModels.jl b/src/Geometry/CartesianDiscreteModels.jl index 68c50ab38..48ac4e18e 100644 --- a/src/Geometry/CartesianDiscreteModels.jl +++ b/src/Geometry/CartesianDiscreteModels.jl @@ -14,6 +14,7 @@ struct CartesianDiscreteModel{D,T,F} <: DiscreteModel{D,D} Inner constructor """ function CartesianDiscreteModel(desc::CartesianDescriptor{D,T,F}) where {D,T,F} + @show F grid = CartesianGrid(desc) _grid = UnstructuredGrid(grid) if any(desc.isperiodic) diff --git a/test/GridapTests/StokesNitscheTests.jl b/test/GridapTests/StokesNitscheTests.jl index 2c60e3900..0827b1658 100644 --- a/test/GridapTests/StokesNitscheTests.jl +++ b/test/GridapTests/StokesNitscheTests.jl @@ -70,7 +70,8 @@ l((v,q)) = ∫( (γ/h)*v⋅u - (n_Γ⋅∇(v))⋅u + (q*n_Γ)⋅u )*dΓ + ∫( s0⋅v )*dΓ0 # Define the FEOperator -op = AffineFEOperator(a,l,X,X) +#op = AffineFEOperator(a,l,X,X) +op = FEOperator(a,X,X) # Solve! xh = solve(op) diff --git a/test/GridapTests/SurfaceCouplingTests.jl b/test/GridapTests/SurfaceCouplingTests.jl index 490f958fa..018cd348c 100644 --- a/test/GridapTests/SurfaceCouplingTests.jl +++ b/test/GridapTests/SurfaceCouplingTests.jl @@ -97,7 +97,11 @@ l((v,q)) = # FE problem -op = AffineFEOperator(a,l,X,Y) +jac((u,p),(du,dp),(v,q)) = a((du,dp),(v,q)) + +#op = AffineFEOperator(a,l,X,Y) +op = FEOperator(a,jac,X,Y) + uh, ph = solve(op) # Visualization From dd4cfa70d9aad5164144c165abb14aaad8b59754 Mon Sep 17 00:00:00 2001 From: Connor Date: Tue, 22 Mar 2022 18:12:36 +1100 Subject: [PATCH 02/12] forwarddiff also running! --- src/Arrays/LazyArrays.jl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Arrays/LazyArrays.jl b/src/Arrays/LazyArrays.jl index a6126aa3c..a7f532174 100644 --- a/src/Arrays/LazyArrays.jl +++ b/src/Arrays/LazyArrays.jl @@ -177,7 +177,7 @@ end function _array_cache!(dict::Dict,a::LazyArray) @boundscheck begin - @notimplementedif ! all(map(isconcretetype, map(eltype, a.args))) + #@notimplementedif ! all(map(isconcretetype, map(eltype, a.args))) if ! (eltype(a.maps) <: Function) @notimplementedif ! isconcretetype(eltype(a.maps)) end From ca873902cae9c77e0d5d7622fa0eed7897804647 Mon Sep 17 00:00:00 2001 From: Connor Date: Thu, 24 Mar 2022 08:30:43 +1100 Subject: [PATCH 03/12] orking differnet trians --- src/FESpaces/FEAutodiff.jl | 27 ++++++++++++++++++++++----- src/Polynomials/MonomialBases.jl | 4 ++-- 2 files changed, 24 insertions(+), 7 deletions(-) diff --git a/src/FESpaces/FEAutodiff.jl b/src/FESpaces/FEAutodiff.jl index 35d80120c..031a8801a 100644 --- a/src/FESpaces/FEAutodiff.jl +++ b/src/FESpaces/FEAutodiff.jl @@ -97,19 +97,36 @@ function _hessian(f,uh,fuh::DomainContribution) end function _change_argument(op,f,trian,uh::SingleFieldFEFunction) + #U = get_fe_space(uh) function g(cell_u) + #cf = CellField(U,cell_u) #cell_grad = f(cf) cell_grad = f(cell_u) -# get_contribution(cell_grad,trian) - + #get_contribution(cell_grad,trian) #@show cell_grad.dict[first(get_domains(cell_grad)) ] - cell_grad.dict[first(get_domains(cell_grad)) ] + + #cell_grad.dict[first(get_domains(cell_grad)) ] + + # because the trian has been perturned, it thinks its different ? + #trian_dual = find_equivalent_trian(trian) + + + + for trian_cg in get_domains(cell_grad) + println("tryn..") + if get_cell_node_ids(trian_cg) == get_cell_node_ids(trian) + println("ispos") + return get_contribution(cell_grad,trian_cg) + end + println("no compat trian....") + end + - #get_contribution(cell_grad,trian) +# get_contribution(cell_grad,trian) end g -end +end \ No newline at end of file diff --git a/src/Polynomials/MonomialBases.jl b/src/Polynomials/MonomialBases.jl index 40ccc66d2..49dd1cb28 100644 --- a/src/Polynomials/MonomialBases.jl +++ b/src/Polynomials/MonomialBases.jl @@ -183,7 +183,7 @@ function return_cache( xi = testitem(x) T = gradient_type(V,xi) - TisbitsType = Val(isbits(T)) + TisbitsType = Val(isbitstype(T)) _return_cache(fg,x,T,TisbitsType) end @@ -195,7 +195,7 @@ function _evaluate!( f = fg.fa r, v, c, g = cache - z = zero(Mutable(VectorValue{D,eltype(T)})) + z = zero(Mutable(eltype(x))) ##VectorValue{D,eltype(T)})) np = length(x) ndof = length(f.terms) * num_components(T) n = 1 + _maximum(f.orders) From 35c9a041b37bb9f570c3b3d79b3003d8db17a23d Mon Sep 17 00:00:00 2001 From: Connor Date: Wed, 27 Apr 2022 10:32:23 +1000 Subject: [PATCH 04/12] add diff option 2 --- src/FESpaces/FEAutodiff.jl | 64 +++++++++++++++++++++----------------- 1 file changed, 36 insertions(+), 28 deletions(-) diff --git a/src/FESpaces/FEAutodiff.jl b/src/FESpaces/FEAutodiff.jl index 031a8801a..3865f26ad 100644 --- a/src/FESpaces/FEAutodiff.jl +++ b/src/FESpaces/FEAutodiff.jl @@ -4,7 +4,12 @@ function gradient(f::Function,uh::FEFunction) fuh = f(uh) _gradient(f,uh,fuh) end - +#= +function gradient(f::Function,cell_u::Vector{Vector{T}}) where T + fcell_u = f(cell_u) + _gradient(f,cell_u,fcell_u) +end +=# function _gradient(f,uh,fuh::AbstractArray) @unreachable """\n In order to perform AD on a Function taking a FEFunction as argument, such Function @@ -19,7 +24,18 @@ function _gradient(f,uh,fuh::DomainContribution) for trian in get_domains(fuh) g = _change_argument(gradient,f,trian,uh) cell_u = get_cell_dof_values(uh) - glue = get_glue(trian,Val(num_cell_dims(get_triangulation(uh)))) + cell_id = _compute_cell_ids(uh,trian) + cell_grad = autodiff_array_gradient(g,cell_u,cell_id) + add_contribution!(terms,trian,cell_grad) + end + terms +end + +function _gradient2(f,uh,fuh::DomainContribution) + terms = DomainContribution() + for trian in get_domains(fuh) + g = _change_argument2(f,trian) + cell_u = get_cell_dof_values(uh) cell_id = _compute_cell_ids(uh,trian) cell_grad = autodiff_array_gradient(g,cell_u,cell_id) add_contribution!(terms,trian,cell_grad) @@ -97,36 +113,28 @@ function _hessian(f,uh,fuh::DomainContribution) end function _change_argument(op,f,trian,uh::SingleFieldFEFunction) - - #U = get_fe_space(uh) - + U = get_fe_space(uh) function g(cell_u) + cf = CellField(U,cell_u) + cell_grad = f(cf) + get_contribution2(cell_grad,trian) + end + g +end - #cf = CellField(U,cell_u) - #cell_grad = f(cf) +function _change_argument2(f,trian) + function g(cell_u) cell_grad = f(cell_u) - #get_contribution(cell_grad,trian) - #@show cell_grad.dict[first(get_domains(cell_grad)) ] - - #cell_grad.dict[first(get_domains(cell_grad)) ] - - # because the trian has been perturned, it thinks its different ? - #trian_dual = find_equivalent_trian(trian) - - - - for trian_cg in get_domains(cell_grad) - println("tryn..") - if get_cell_node_ids(trian_cg) == get_cell_node_ids(trian) - println("ispos") - return get_contribution(cell_grad,trian_cg) - end - println("no compat trian....") - end - - -# get_contribution(cell_grad,trian) + get_contribution2(cell_grad,trian) end g +end + +function get_contribution2(cell_grad,trian) + for trian_cg in get_domains(cell_grad) + if get_cell_node_ids(trian_cg) == get_cell_node_ids(trian) + return get_contribution(cell_grad,trian_cg) + end + end end \ No newline at end of file From 7df535cf565132d898a062ae2122d85f52304370 Mon Sep 17 00:00:00 2001 From: Connor Date: Thu, 8 Sep 2022 07:33:49 +1000 Subject: [PATCH 05/12] support for multifield --- src/MultiField/MultiFieldFEAutodiff.jl | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/src/MultiField/MultiFieldFEAutodiff.jl b/src/MultiField/MultiFieldFEAutodiff.jl index 5b439b2a0..91d1a022e 100644 --- a/src/MultiField/MultiFieldFEAutodiff.jl +++ b/src/MultiField/MultiFieldFEAutodiff.jl @@ -86,7 +86,7 @@ function FESpaces._change_argument( end xh = MultiFieldCellField(single_fields) cell_grad = f(xh) - cell_grad_cont_block=get_contribution(cell_grad,trian) + cell_grad_cont_block=get_contribution2(cell_grad,trian) bs = [cell_dofs_field_offsets[i+1]-cell_dofs_field_offsets[i] for i=1:nfields] lazy_map(DensifyInnerMostBlockLevelMap(), Fill(bs,length(cell_grad_cont_block)), @@ -111,7 +111,7 @@ function FESpaces._change_argument( end xh = MultiFieldCellField(single_fields) cell_grad = f(xh) - get_contribution(cell_grad,trian) + get_contribution2(cell_grad,trian) end g end @@ -147,3 +147,11 @@ function FESpaces._hessian(f,uh::MultiFieldFEFunction,fuh::DomainContribution) end terms end + +function get_contribution2(cell_grad,trian) + for trian_cg in get_domains(cell_grad) + if get_cell_node_ids(trian_cg) == get_cell_node_ids(trian) + return get_contribution(cell_grad,trian_cg) + end + end +end From e5bf0a779537636700b291232b73e0dc55d79896 Mon Sep 17 00:00:00 2001 From: Connor Mallon Date: Tue, 28 Feb 2023 17:17:57 +1100 Subject: [PATCH 06/12] working --- src/CellData/DomainContributions.jl | 15 +++++++++++++-- src/FESpaces/FEAutodiff.jl | 20 ++++++++++++++++---- 2 files changed, 29 insertions(+), 6 deletions(-) diff --git a/src/CellData/DomainContributions.jl b/src/CellData/DomainContributions.jl index ac1089921..180118a08 100644 --- a/src/CellData/DomainContributions.jl +++ b/src/CellData/DomainContributions.jl @@ -13,14 +13,25 @@ get_domains(a::DomainContribution) = keys(a.dict) function get_contribution(a::DomainContribution,trian::Triangulation) if haskey(a.dict,trian) - return a.dict[trian] - else + return a.dict[trian] + else + for trian_a in get_domains(a) + if isequivtrian(trian,trian_a) + return get_contribution(a,trian_a) + end + end @unreachable """\n There is not contribution associated with the given mesh in this DomainContribution object. """ end end +function isequivtrian(trian1::AppendedTriangulation,trian2::AppendedTriangulation) + sc1 = trian1.a.subcells + sc2 = trian2.a.subcells + return (sc1.cell_to_points == sc2.cell_to_points && sc1.cell_to_bgcell == sc2.cell_to_bgcell && sc1.point_to_coords == sc2.point_to_coords && sc1.point_to_rcoords == sc2.point_to_rcoords ) +end + Base.getindex(a::DomainContribution,trian::Triangulation) = get_contribution(a,trian) function add_contribution!(a::DomainContribution,trian::Triangulation,b::AbstractArray,op=+) diff --git a/src/FESpaces/FEAutodiff.jl b/src/FESpaces/FEAutodiff.jl index 11bae1ccb..2a7727e74 100644 --- a/src/FESpaces/FEAutodiff.jl +++ b/src/FESpaces/FEAutodiff.jl @@ -30,7 +30,7 @@ function _gradient(f,uh,fuh::DomainContribution) end terms end - +#= function _gradient2(f,uh,fuh::DomainContribution) terms = DomainContribution() for trian in get_domains(fuh) @@ -42,6 +42,7 @@ function _gradient2(f,uh,fuh::DomainContribution) end terms end +=# function _compute_cell_ids(uh,ttrian) strian = get_triangulation(uh) @@ -117,27 +118,38 @@ function _change_argument(op,f,trian,uh::SingleFieldFEFunction) function g(cell_u) cf = CellField(U,cell_u) cell_grad = f(cf) - get_contribution2(cell_grad,trian) + get_contribution(cell_grad,trian) end g end +#= function _change_argument2(f,trian) function g(cell_u) cell_grad = f(cell_u) get_contribution2(cell_grad,trian) - + @show ddd end g end +=# +#= function get_contribution2(cell_grad,trian) for trian_cg in get_domains(cell_grad) - if get_cell_node_ids(trian_cg) == get_cell_node_ids(trian) + if isequivtrian(trian,trian_cg)#get_cell_node_ids(trian_cg) == get_cell_node_ids(trian) return get_contribution(cell_grad,trian_cg) end end end + +function isequivtrian(trian1::AppendedTriangulation,trian2::AppendedTriangulation) + sc1 = trian1.a.subcells + sc2 = trian2.a.subcells + return (sc1.cell_to_points == sc2.cell_to_points && sc1.cell_to_bgcell == sc2.cell_to_bgcell && sc1.point_to_coords == sc2.point_to_coords && sc1.point_to_rcoords == sc2.point_to_rcoords ) +end +=# + #= AD for DomainContribution involving SkeletonTriangulation - Following are the constructs for performing gradient of DomainContribution From 37aa1b458f7cc8046de7319f3872ab77a6cd6e92 Mon Sep 17 00:00:00 2001 From: Connor Mallon Date: Wed, 1 Mar 2023 09:58:14 +1100 Subject: [PATCH 07/12] minor --- src/Geometry/CartesianDiscreteModels.jl | 1 - test/PolynomialsTests/MonomialBasesTests.jl | 2 +- 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/src/Geometry/CartesianDiscreteModels.jl b/src/Geometry/CartesianDiscreteModels.jl index 48ac4e18e..68c50ab38 100644 --- a/src/Geometry/CartesianDiscreteModels.jl +++ b/src/Geometry/CartesianDiscreteModels.jl @@ -14,7 +14,6 @@ struct CartesianDiscreteModel{D,T,F} <: DiscreteModel{D,D} Inner constructor """ function CartesianDiscreteModel(desc::CartesianDescriptor{D,T,F}) where {D,T,F} - @show F grid = CartesianGrid(desc) _grid = UnstructuredGrid(grid) if any(desc.isperiodic) diff --git a/test/PolynomialsTests/MonomialBasesTests.jl b/test/PolynomialsTests/MonomialBasesTests.jl index 5dab24542..07d4380b9 100644 --- a/test/PolynomialsTests/MonomialBasesTests.jl +++ b/test/PolynomialsTests/MonomialBasesTests.jl @@ -5,7 +5,7 @@ using Gridap.TensorValues using Gridap.Fields using Gridap.Polynomials -xi = Point(2,3) +xi = Point(2.0,3.0) np = 5 x = fill(xi,np) From 8c83f8d925d1f44f17b1305ddca829b4fcc05801 Mon Sep 17 00:00:00 2001 From: Connor Mallon Date: Wed, 1 Mar 2023 15:50:58 +1100 Subject: [PATCH 08/12] add case --- src/CellData/DomainContributions.jl | 28 ++++++++++++++++++++++------ 1 file changed, 22 insertions(+), 6 deletions(-) diff --git a/src/CellData/DomainContributions.jl b/src/CellData/DomainContributions.jl index 180118a08..ad19353fd 100644 --- a/src/CellData/DomainContributions.jl +++ b/src/CellData/DomainContributions.jl @@ -14,15 +14,25 @@ get_domains(a::DomainContribution) = keys(a.dict) function get_contribution(a::DomainContribution,trian::Triangulation) if haskey(a.dict,trian) return a.dict[trian] - else + else for trian_a in get_domains(a) - if isequivtrian(trian,trian_a) - return get_contribution(a,trian_a) + if get_cell_node_ids(trian_a) == get_cell_node_ids(trian) + if hasproperty(trian,:a) + if hasproperty(trian.a,:subcells) + if isequivtrian(trian,trian_a) + return get_contribution(a,trian_a) + end + end + elseif hasproperty(trian,:subfacets) + if isequivtrian_subfacet(trian,trian_a) + return get_contribution(a,trian_a) + end + end end end - @unreachable """\n - There is not contribution associated with the given mesh in this DomainContribution object. - """ + @unreachable """\n + There is not contribution associated with the given mesh in this DomainContribution object. + """ end end @@ -32,6 +42,12 @@ function isequivtrian(trian1::AppendedTriangulation,trian2::AppendedTriangulatio return (sc1.cell_to_points == sc2.cell_to_points && sc1.cell_to_bgcell == sc2.cell_to_bgcell && sc1.point_to_coords == sc2.point_to_coords && sc1.point_to_rcoords == sc2.point_to_rcoords ) end +function isequivtrian_subfacet(trian1,trian2) + sf1 = trian1.subfacets + sf2 = trian2.subfacets + return (sf1.facet_to_points == sf2.facet_to_points && sf1.facet_to_normal == sf2.facet_to_normal && sf1.point_to_coords == sf2.point_to_coords && sf1.point_to_rcoords == sf2.point_to_rcoords ) +end + Base.getindex(a::DomainContribution,trian::Triangulation) = get_contribution(a,trian) function add_contribution!(a::DomainContribution,trian::Triangulation,b::AbstractArray,op=+) From f18ab5a370ef541d7f27884cedaf0435b387cca1 Mon Sep 17 00:00:00 2001 From: Connor Mallon Date: Thu, 2 Mar 2023 11:09:10 +1100 Subject: [PATCH 09/12] 1 2 rm unneeded change --- src/Arrays/PosNegReindex.jl | 2 +- src/Arrays/Tables.jl | 9 +---- src/FESpaces/FEAutodiff.jl | 47 +----------------------- src/Fields/Fields.jl | 1 - src/MultiField/MultiFieldFEAutodiff.jl | 12 +----- src/Polynomials/MonomialBases.jl | 2 +- test/GridapTests/StokesNitscheTests.jl | 3 +- test/GridapTests/SurfaceCouplingTests.jl | 6 +-- 8 files changed, 8 insertions(+), 74 deletions(-) diff --git a/src/Arrays/PosNegReindex.jl b/src/Arrays/PosNegReindex.jl index cb56313c6..31a90f1e4 100644 --- a/src/Arrays/PosNegReindex.jl +++ b/src/Arrays/PosNegReindex.jl @@ -9,7 +9,7 @@ end function testargs(k::PosNegReindex,i::Integer) @check length(k.values_pos) !=0 || length(k.values_neg) != 0 "This map has empty domain" - #@check eltype(k.values_pos) == eltype(k.values_neg) "This map is type-instable" + @check eltype(k.values_pos) == eltype(k.values_neg) "This map is type-instable" length(k.values_pos) !=0 ? (one(i),) : (-one(i)) end diff --git a/src/Arrays/Tables.jl b/src/Arrays/Tables.jl index dd0ebb3c7..6965635ce 100644 --- a/src/Arrays/Tables.jl +++ b/src/Arrays/Tables.jl @@ -326,14 +326,7 @@ Equivalent to [a[i] for in 1:length(a)] """ -function collect1d(a) - #@show a - #b = collect(Base.Iterators.Flatten(a)) # - [a[i] for i in 1:length(a)] - #@show b - #b -end - +collect1d(a) = [a[i] for i in 1:length(a)] function lazy_map(::typeof(getindex),a::Table,b::AbstractArray{<:Integer}) LocalItemFromTable(a,b) diff --git a/src/FESpaces/FEAutodiff.jl b/src/FESpaces/FEAutodiff.jl index 2a7727e74..0fc00a4c2 100644 --- a/src/FESpaces/FEAutodiff.jl +++ b/src/FESpaces/FEAutodiff.jl @@ -4,12 +4,7 @@ function gradient(f::Function,uh::FEFunction) fuh = f(uh) _gradient(f,uh,fuh) end -#= -function gradient(f::Function,cell_u::Vector{Vector{T}}) where T - fcell_u = f(cell_u) - _gradient(f,cell_u,fcell_u) -end -=# + function _gradient(f,uh,fuh::AbstractArray) @unreachable """\n In order to perform AD on a Function taking a FEFunction as argument, such Function @@ -30,19 +25,6 @@ function _gradient(f,uh,fuh::DomainContribution) end terms end -#= -function _gradient2(f,uh,fuh::DomainContribution) - terms = DomainContribution() - for trian in get_domains(fuh) - g = _change_argument2(f,trian) - cell_u = get_cell_dof_values(uh) - cell_id = _compute_cell_ids(uh,trian) - cell_grad = autodiff_array_gradient(g,cell_u,cell_id) - add_contribution!(terms,trian,cell_grad) - end - terms -end -=# function _compute_cell_ids(uh,ttrian) strian = get_triangulation(uh) @@ -123,33 +105,6 @@ function _change_argument(op,f,trian,uh::SingleFieldFEFunction) g end -#= -function _change_argument2(f,trian) - function g(cell_u) - cell_grad = f(cell_u) - get_contribution2(cell_grad,trian) - @show ddd - end - g -end -=# - -#= -function get_contribution2(cell_grad,trian) - for trian_cg in get_domains(cell_grad) - if isequivtrian(trian,trian_cg)#get_cell_node_ids(trian_cg) == get_cell_node_ids(trian) - return get_contribution(cell_grad,trian_cg) - end - end -end - -function isequivtrian(trian1::AppendedTriangulation,trian2::AppendedTriangulation) - sc1 = trian1.a.subcells - sc2 = trian2.a.subcells - return (sc1.cell_to_points == sc2.cell_to_points && sc1.cell_to_bgcell == sc2.cell_to_bgcell && sc1.point_to_coords == sc2.point_to_coords && sc1.point_to_rcoords == sc2.point_to_rcoords ) -end -=# - #= AD for DomainContribution involving SkeletonTriangulation - Following are the constructs for performing gradient of DomainContribution diff --git a/src/Fields/Fields.jl b/src/Fields/Fields.jl index 8887fe67e..1786d6111 100644 --- a/src/Fields/Fields.jl +++ b/src/Fields/Fields.jl @@ -59,7 +59,6 @@ export AffineMap export affine_map export gradient -export _gradient export ∇ export ∇∇ export gradient_type diff --git a/src/MultiField/MultiFieldFEAutodiff.jl b/src/MultiField/MultiFieldFEAutodiff.jl index 1eb86f4b9..5da39257a 100644 --- a/src/MultiField/MultiFieldFEAutodiff.jl +++ b/src/MultiField/MultiFieldFEAutodiff.jl @@ -93,7 +93,7 @@ function FESpaces._change_argument( end xh = MultiFieldCellField(single_fields) cell_grad = f(xh) - cell_grad_cont_block=get_contribution2(cell_grad,trian) + cell_grad_cont_block=get_contribution(cell_grad,trian) bs = [cell_dofs_field_offsets[i+1]-cell_dofs_field_offsets[i] for i=1:nfields] lazy_map(DensifyInnerMostBlockLevelMap(), Fill(bs,length(cell_grad_cont_block)), @@ -118,7 +118,7 @@ function FESpaces._change_argument( end xh = MultiFieldCellField(single_fields) cell_grad = f(xh) - get_contribution2(cell_grad,trian) + get_contribution(cell_grad,trian) end g end @@ -155,14 +155,6 @@ function FESpaces._hessian(f,uh::MultiFieldFEFunction,fuh::DomainContribution) terms end -function get_contribution2(cell_grad,trian) - for trian_cg in get_domains(cell_grad) - if get_cell_node_ids(trian_cg) == get_cell_node_ids(trian) - return get_contribution(cell_grad,trian_cg) - end - end -end - # overloads for AD of SkeletonTriangulation DomainContribution with MultiFields function FESpaces._change_argument( diff --git a/src/Polynomials/MonomialBases.jl b/src/Polynomials/MonomialBases.jl index 49dd1cb28..40e6fe5c0 100644 --- a/src/Polynomials/MonomialBases.jl +++ b/src/Polynomials/MonomialBases.jl @@ -195,7 +195,7 @@ function _evaluate!( f = fg.fa r, v, c, g = cache - z = zero(Mutable(eltype(x))) ##VectorValue{D,eltype(T)})) + z = zero(Mutable(eltype(x))) np = length(x) ndof = length(f.terms) * num_components(T) n = 1 + _maximum(f.orders) diff --git a/test/GridapTests/StokesNitscheTests.jl b/test/GridapTests/StokesNitscheTests.jl index 0827b1658..2c60e3900 100644 --- a/test/GridapTests/StokesNitscheTests.jl +++ b/test/GridapTests/StokesNitscheTests.jl @@ -70,8 +70,7 @@ l((v,q)) = ∫( (γ/h)*v⋅u - (n_Γ⋅∇(v))⋅u + (q*n_Γ)⋅u )*dΓ + ∫( s0⋅v )*dΓ0 # Define the FEOperator -#op = AffineFEOperator(a,l,X,X) -op = FEOperator(a,X,X) +op = AffineFEOperator(a,l,X,X) # Solve! xh = solve(op) diff --git a/test/GridapTests/SurfaceCouplingTests.jl b/test/GridapTests/SurfaceCouplingTests.jl index 018cd348c..490f958fa 100644 --- a/test/GridapTests/SurfaceCouplingTests.jl +++ b/test/GridapTests/SurfaceCouplingTests.jl @@ -97,11 +97,7 @@ l((v,q)) = # FE problem -jac((u,p),(du,dp),(v,q)) = a((du,dp),(v,q)) - -#op = AffineFEOperator(a,l,X,Y) -op = FEOperator(a,jac,X,Y) - +op = AffineFEOperator(a,l,X,Y) uh, ph = solve(op) # Visualization From aed6849f4aa71150cf4f04f3f353bc72f470438c Mon Sep 17 00:00:00 2001 From: ConnorMallon Date: Thu, 2 Mar 2023 15:07:04 +1100 Subject: [PATCH 10/12] check deeper for concrete types --- src/Arrays/LazyArrays.jl | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/Arrays/LazyArrays.jl b/src/Arrays/LazyArrays.jl index a7f532174..14a972ae1 100644 --- a/src/Arrays/LazyArrays.jl +++ b/src/Arrays/LazyArrays.jl @@ -177,7 +177,11 @@ end function _array_cache!(dict::Dict,a::LazyArray) @boundscheck begin - #@notimplementedif ! all(map(isconcretetype, map(eltype, a.args))) + if ! all(map(isconcretetype, map(eltype, a.args))) + for n in 1:length(a.args) + @notimplementedif ! all(map(isconcretetype, map(eltype, a.args[n]))) + end + end if ! (eltype(a.maps) <: Function) @notimplementedif ! isconcretetype(eltype(a.maps)) end From 67e64d3deacf972c1b9698f2fa73a132d3dd10ed Mon Sep 17 00:00:00 2001 From: Connor Mallon Date: Thu, 2 Mar 2023 17:05:43 +1100 Subject: [PATCH 11/12] remove --- src/FESpaces/UnconstrainedFESpaces.jl | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/FESpaces/UnconstrainedFESpaces.jl b/src/FESpaces/UnconstrainedFESpaces.jl index 53574efd5..0a9ca2b05 100644 --- a/src/FESpaces/UnconstrainedFESpaces.jl +++ b/src/FESpaces/UnconstrainedFESpaces.jl @@ -65,7 +65,6 @@ zero_dirichlet_values(f::UnconstrainedFESpace) = allocate_vector(f.vector_type,n get_dirichlet_dof_tag(f::UnconstrainedFESpace) = f.dirichlet_dof_tag function scatter_free_and_dirichlet_values(f::UnconstrainedFESpace,free_values,dirichlet_values) - #= @check eltype(free_values) == eltype(dirichlet_values) """\n The entries stored in free_values and dirichlet_values should be of the same type. @@ -73,7 +72,6 @@ function scatter_free_and_dirichlet_values(f::UnconstrainedFESpace,free_values,d if the Dirichlet values of the underlying space are of type Float64, or when the given free values are Float64 and the Dirichlet values ComplexF64. """ - =# cell_dof_ids = get_cell_dof_ids(f) lazy_map(Broadcasting(PosNegReindex(free_values,dirichlet_values)),cell_dof_ids) end From b458315c66b384334f2c4398522be7e6aae2c63d Mon Sep 17 00:00:00 2001 From: Connor Mallon Date: Mon, 6 Mar 2023 16:40:13 +1100 Subject: [PATCH 12/12] minor --- src/Arrays/LazyArrays.jl | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/Arrays/LazyArrays.jl b/src/Arrays/LazyArrays.jl index 14a972ae1..ce3d5df9b 100644 --- a/src/Arrays/LazyArrays.jl +++ b/src/Arrays/LazyArrays.jl @@ -245,8 +245,6 @@ Base.size(a::LazyArray{G,T,1} where {G,T}) = (length(a.maps),) function Base.sum(a::LazyArray) cache = array_cache(a) - #@code_warntype _sum_lazy_array(cache,a) - #@show typeof(cache) _sum_lazy_array(cache,a) end