diff --git a/src/FESpaces/AffineFEOperators.jl b/src/FESpaces/AffineFEOperators.jl index 7e870836e..f27964182 100644 --- a/src/FESpaces/AffineFEOperators.jl +++ b/src/FESpaces/AffineFEOperators.jl @@ -28,11 +28,11 @@ function AffineFEOperator(trial::FESpace,test::FESpace,assem::Assembler,terms::A uhd = zero(trial) - matvecdata, matdata, vecdata = collect_cell_matrix_and_vector(v,u,uhd,terms) + matvecdata, matdata, vecdata = collect_cell_matrix_and_vector(uhd,u,v,terms) A,b = assemble_matrix_and_vector(assem,matvecdata,matdata,vecdata) - #matdata = collect_cell_matrix(v,u,terms) - #vecdata = collect_cell_vector(v,uhd,terms) + #matdata = collect_cell_matrix(u,v,terms) + #vecdata = collect_cell_vector(uhd,v,terms) #A = assemble_matrix(assem,matdata...) #b = assemble_vector(assem,vecdata...) diff --git a/src/FESpaces/FEOperatorsFromTerms.jl b/src/FESpaces/FEOperatorsFromTerms.jl index ce26813de..2747f1820 100644 --- a/src/FESpaces/FEOperatorsFromTerms.jl +++ b/src/FESpaces/FEOperatorsFromTerms.jl @@ -54,7 +54,7 @@ function allocate_jacobian(op::FEOperatorFromTerms,uh) @assert is_a_fe_function(uh) du = get_cell_basis(op.trial) v = get_cell_basis(op.test) - _, cellidsrows, cellidscols = collect_cell_jacobian(uh,v,du,op.terms) + _, cellidsrows, cellidscols = collect_cell_jacobian(uh,du,v,op.terms) allocate_matrix(op.assem, cellidsrows, cellidscols) end @@ -62,7 +62,7 @@ function jacobian!(A::AbstractMatrix,op::FEOperatorFromTerms,uh) @assert is_a_fe_function(uh) du = get_cell_basis(op.trial) v = get_cell_basis(op.test) - cellmats, cellidsrows, cellidscols = collect_cell_jacobian(uh,v,du,op.terms) + cellmats, cellidsrows, cellidscols = collect_cell_jacobian(uh,du,v,op.terms) assemble_matrix!(A,op.assem, cellmats, cellidsrows, cellidscols) A end @@ -71,7 +71,7 @@ function residual_and_jacobian!(b::AbstractVector,A::AbstractMatrix,op::FEOperat @assert is_a_fe_function(uh) du = get_cell_basis(op.trial) v = get_cell_basis(op.test) - data = collect_cell_jacobian_and_residual(uh,v,du,op.terms) + data = collect_cell_jacobian_and_residual(uh,du,v,op.terms) assemble_matrix_and_vector!(A, b, op.assem,data...) (b,A) end @@ -80,7 +80,7 @@ function residual_and_jacobian(op::FEOperatorFromTerms,uh) @assert is_a_fe_function(uh) du = get_cell_basis(op.trial) v = get_cell_basis(op.test) - data = collect_cell_jacobian_and_residual(uh,v,du,op.terms) + data = collect_cell_jacobian_and_residual(uh,du,v,op.terms) A, b = assemble_matrix_and_vector(op.assem,data...) (b, A) end diff --git a/src/FESpaces/FETerms.jl b/src/FESpaces/FETerms.jl index 49ede90c2..f9d02eebe 100644 --- a/src/FESpaces/FETerms.jl +++ b/src/FESpaces/FETerms.jl @@ -8,7 +8,7 @@ Returns an object representing the contribution to the Jacobian of the given term. Returns nothing if the term has not contribution to the Jacobian (typically for source terms) """ -function get_cell_jacobian(t::FETerm,uh,v,du) +function get_cell_jacobian(t::FETerm,uh,du,v) @abstractmethod end @@ -28,11 +28,11 @@ end """ """ -function get_cell_jacobian_and_residual(t::FETerm,uh,v,du) +function get_cell_jacobian_and_residual(t::FETerm,uh,du,v) @assert is_a_fe_function(uh) @assert is_a_fe_cell_basis(v) @assert is_a_fe_cell_basis(du) - celljac = get_cell_jacobian(t,uh,v,du) + celljac = get_cell_jacobian(t,uh,du,v) cellres = get_cell_residual(t,uh,v) _setup_jac_and_res(celljac,cellres) end @@ -68,7 +68,7 @@ Returns an object representing the contribution to the system matrix of the given term. Returns nothing if the term has not contribution (typically for source terms) """ -function get_cell_matrix(t::AffineFETerm,v,u) +function get_cell_matrix(t::AffineFETerm,u,v) @abstractmethod end @@ -77,7 +77,7 @@ Returns an object (e.g. a CellVector) representing the contribution to the system rhs of the given term. Returns nothing if the term has not contribution (typically for linear terms) """ -function get_cell_vector(t::AffineFETerm,v,uhd) +function get_cell_vector(t::AffineFETerm,uhd,v) @abstractmethod end @@ -91,20 +91,20 @@ function get_cell_values(t::FETerm,uhd) @abstractmethod end -function get_cell_jacobian(t::AffineFETerm,uh,v,du) +function get_cell_jacobian(t::AffineFETerm,uh,du,v) @assert is_a_fe_function(uh) @assert is_a_fe_cell_basis(v) @assert is_a_fe_cell_basis(du) - get_cell_matrix(t,v,du) + get_cell_matrix(t,du,v) end """ """ -function get_cell_matrix_and_vector(t::AffineFETerm,v,u,uhd) +function get_cell_matrix_and_vector(t::AffineFETerm,uhd,u,v) @assert is_a_fe_function(uhd) @assert is_a_fe_cell_basis(v) @assert is_a_fe_cell_basis(u) - cellmat = get_cell_matrix(t,v,u) + cellmat = get_cell_matrix(t,u,v) cellvec = _get_cell_vector_tmp_hack(cellmat,t,v,uhd) #TODO cellvals = get_cell_values(t,uhd) _setup_cell_matrix_and_vector(cellmat,cellvec,cellvals) @@ -116,7 +116,7 @@ function _get_cell_vector_tmp_hack(cellmat,t,v,uhd) #TODO end function _get_cell_vector_tmp_hack(cellmat::SkeletonCellMatrix,t,v,uhd) #TODO - cellvec = get_cell_vector(t,v,uhd) + cellvec = get_cell_vector(t,uhd,v) cellvec end @@ -152,7 +152,7 @@ abstract type LinearFETerm <: AffineFETerm end """ abstract type FESource <: AffineFETerm end -function get_cell_matrix(t::FESource,v,u) +function get_cell_matrix(t::FESource,u,v) nothing end @@ -160,7 +160,7 @@ end """ """ -function collect_cell_jacobian(uh,v,du,terms) +function collect_cell_jacobian(uh,du,v,terms) @assert is_a_fe_function(uh) @assert is_a_fe_cell_basis(v) @assert is_a_fe_cell_basis(du) @@ -168,7 +168,7 @@ function collect_cell_jacobian(uh,v,du,terms) r = [] c = [] for term in terms - cellvals = get_cell_jacobian(term,uh,v,du) + cellvals = get_cell_jacobian(term,uh,du,v) cellids = get_cell_id(term) _push_matrix_contribution!(w,r,c,cellvals,cellids) end @@ -177,14 +177,14 @@ end """ """ -function collect_cell_matrix(v,u,terms) +function collect_cell_matrix(u,v,terms) @assert is_a_fe_cell_basis(v) @assert is_a_fe_cell_basis(u) w = [] r = [] c = [] for term in terms - cellvals = get_cell_matrix(term,v,u) + cellvals = get_cell_matrix(term,u,v) cellids = get_cell_id(term) _push_matrix_contribution!(w,r,c,cellvals,cellids) end @@ -208,13 +208,13 @@ end """ """ -function collect_cell_vector(v,uhd,terms) +function collect_cell_vector(uhd,v,terms) @assert is_a_fe_cell_basis(v) @assert is_a_fe_function(uhd) w = [] r = [] for term in terms - cellvals = get_cell_vector(term,v,uhd) + cellvals = get_cell_vector(term,uhd,v) cellids = get_cell_id(term) _push_vector_contribution!(w,r,cellvals,cellids) end @@ -223,7 +223,7 @@ end """ """ -function collect_cell_matrix_and_vector(v,u,uhd,terms) +function collect_cell_matrix_and_vector(uhd,u,v,terms) @assert is_a_fe_cell_basis(v) @assert is_a_fe_cell_basis(u) @assert is_a_fe_function(uhd) @@ -233,7 +233,7 @@ function collect_cell_matrix_and_vector(v,u,uhd,terms) vecdata = ([],[]) for term in terms - cellmatvec, cellmat, cellvec = get_cell_matrix_and_vector(term,v,u,uhd) + cellmatvec, cellmat, cellvec = get_cell_matrix_and_vector(term,uhd,u,v) cellids = get_cell_id(term) _push_matrix_contribution!(matvecdata...,cellmatvec,cellids) _push_matrix_contribution!(matdata...,cellmat,cellids) @@ -245,7 +245,7 @@ end """ """ -function collect_cell_jacobian_and_residual(uh,v,du,terms) +function collect_cell_jacobian_and_residual(uh,du,v,terms) @assert is_a_fe_function(uh) @assert is_a_fe_cell_basis(v) @assert is_a_fe_cell_basis(du) @@ -255,7 +255,7 @@ function collect_cell_jacobian_and_residual(uh,v,du,terms) vecdata = ([],[]) for term in terms - cellmatvec, cellmat, cellvec = get_cell_jacobian_and_residual(term,uh,v,du) + cellmatvec, cellmat, cellvec = get_cell_jacobian_and_residual(term,uh,du,v) cellids = get_cell_id(term) _push_matrix_contribution!(matvecdata...,cellmatvec,cellids) _push_matrix_contribution!(matdata...,cellmat,cellids) @@ -322,7 +322,7 @@ function AffineFETerm( AffineFETermFromIntegration(biform,liform,trian,quad) end -function get_cell_matrix(t::AffineFETermFromIntegration,v,u) +function get_cell_matrix(t::AffineFETermFromIntegration,u,v) @assert is_a_fe_cell_basis(v) @assert is_a_fe_cell_basis(u) _v = restrict(v,t.trian) @@ -330,7 +330,7 @@ function get_cell_matrix(t::AffineFETermFromIntegration,v,u) integrate(t.biform(_u,_v),t.trian,t.quad) end -function get_cell_vector(t::AffineFETermFromIntegration,v,uhd) +function get_cell_vector(t::AffineFETermFromIntegration,uhd,v) @assert is_a_fe_function(uhd) @assert is_a_fe_cell_basis(v) _v = restrict(v,t.trian) @@ -377,11 +377,11 @@ function FESource( FESourceFromIntegration(liform,trian,quad) end -function get_cell_matrix(t::FESourceFromIntegration,v,u) +function get_cell_matrix(t::FESourceFromIntegration,u,v) nothing end -function get_cell_vector(t::FESourceFromIntegration,v,uhd) +function get_cell_vector(t::FESourceFromIntegration,uhd,v) @assert is_a_fe_function(uhd) @assert is_a_fe_cell_basis(v) _v = restrict(v,t.trian) @@ -424,7 +424,7 @@ function LinearFETerm( LinearFETermFromIntegration(biform,trian,quad) end -function get_cell_matrix(t::LinearFETermFromIntegration,v,u) +function get_cell_matrix(t::LinearFETermFromIntegration,u,v) @assert is_a_fe_cell_basis(v) @assert is_a_fe_cell_basis(u) _v = restrict(v,t.trian) @@ -432,7 +432,7 @@ function get_cell_matrix(t::LinearFETermFromIntegration,v,u) integrate(t.biform(_u,_v),t.trian,t.quad) end -function get_cell_vector(t::LinearFETermFromIntegration,v,uhd) +function get_cell_vector(t::LinearFETermFromIntegration,uhd,v) @assert is_a_fe_function(uhd) @assert is_a_fe_cell_basis(v) _v = restrict(v,t.trian) @@ -477,7 +477,7 @@ function FETerm( NonLinearFETerm(res,jac,trian,quad) end -function get_cell_jacobian(t::NonLinearFETerm,uh,v,du) +function get_cell_jacobian(t::NonLinearFETerm,uh,du,v) @assert is_a_fe_function(uh) @assert is_a_fe_cell_basis(v) @assert is_a_fe_cell_basis(du) @@ -506,17 +506,17 @@ struct AffineFETermFromCellMatVec <: AffineFETerm trian::Triangulation end -function get_cell_matrix(t::AffineFETermFromCellMatVec,v,u) +function get_cell_matrix(t::AffineFETermFromCellMatVec,u,v) @assert is_a_fe_cell_basis(v) @assert is_a_fe_cell_basis(u) _v = restrict(v,t.trian) _u = restrict(u,t.trian) - cellmatvec = t.matvecfun(_v,_u) + cellmatvec = t.matvecfun(_u,_v) cellmat, _ = unpair_arrays(cellmatvec) cellmat end -function get_cell_vector(t::AffineFETermFromCellMatVec,v,uhd) +function get_cell_vector(t::AffineFETermFromCellMatVec,uhd,v) @assert is_a_fe_function(uhd) @assert is_a_fe_cell_basis(v) trial = TrialFESpace(get_fe_space(uhd)) @@ -524,7 +524,7 @@ function get_cell_vector(t::AffineFETermFromCellMatVec,v,uhd) _v = restrict(v,t.trian) _u = restrict(u,t.trian) _cellvals = get_cell_values(t,uhd) - cellmatvec = t.matvecfun(_v,_u) + cellmatvec = t.matvecfun(_u,_v) cellmatvec_with_diri = attach_dirichlet_bcs(cellmatvec,_cellvals) _, cellvec_with_diri = unpair_arrays(cellmatvec_with_diri) cellvec_with_diri @@ -545,14 +545,14 @@ function get_cell_values(t::AffineFETermFromCellMatVec,uhd) reindex(cellvals,t.trian) end -function get_cell_matrix_and_vector(t::AffineFETermFromCellMatVec,v,u,uhd) +function get_cell_matrix_and_vector(t::AffineFETermFromCellMatVec,uhd,u,v) @assert is_a_fe_function(uhd) @assert is_a_fe_cell_basis(v) @assert is_a_fe_cell_basis(u) _v = restrict(v,t.trian) _u = restrict(u,t.trian) _cellvals = get_cell_values(t,uhd) - cellmatvec = t.matvecfun(_v,_u) + cellmatvec = t.matvecfun(_u,_v) cellmatvec_with_diri = attach_dirichlet_bcs(cellmatvec,_cellvals) (cellmatvec_with_diri, nothing, nothing) end @@ -562,7 +562,7 @@ struct FETermFromCellJacRes <: FETerm trian::Triangulation end -function get_cell_jacobian(t::FETermFromCellJacRes,uh,v,du) +function get_cell_jacobian(t::FETermFromCellJacRes,uh,du,v) @assert is_a_fe_function(uh) @assert is_a_fe_cell_basis(v) @assert is_a_fe_cell_basis(du) @@ -591,7 +591,7 @@ function get_cell_id(t::FETermFromCellJacRes) get_cell_id(t.trian) end -function get_cell_jacobian_and_residual(t::FETermFromCellJacRes,uh,v,du) +function get_cell_jacobian_and_residual(t::FETermFromCellJacRes,uh,du,v) @assert is_a_fe_function(uh) @assert is_a_fe_cell_basis(v) @assert is_a_fe_cell_basis(du) diff --git a/test/FESpacesTests/FETermsTests.jl b/test/FESpacesTests/FETermsTests.jl index d3bc4bc55..0a3953e3d 100644 --- a/test/FESpacesTests/FETermsTests.jl +++ b/test/FESpacesTests/FETermsTests.jl @@ -59,14 +59,14 @@ t_source = FESource(w,strian,squad) t_affine = AffineFETerm(a,l,trian,quad) -matdata = collect_cell_matrix(v,u,[t_affine, t_linear]) -vecdata = collect_cell_vector(v,uhd,[t_affine, t_linear, t_source]) +matdata = collect_cell_matrix(u,v,[t_affine, t_linear]) +vecdata = collect_cell_vector(uhd,v,[t_affine, t_linear, t_source]) A = assemble_matrix(assem,matdata...) b = assemble_vector(assem,vecdata...) x = A \ b @test x ≈ get_free_values(uh) -data = collect_cell_matrix_and_vector(v,u,uhd,[t_affine, t_linear, t_source]) +data = collect_cell_matrix_and_vector(uhd,u,v,[t_affine, t_linear, t_source]) A, b = allocate_matrix_and_vector(assem,data...) assemble_matrix_and_vector!(A,b,assem,data...) x = A \ b @@ -75,7 +75,7 @@ A, b = assemble_matrix_and_vector(assem,data...) x = A \ b @test x ≈ get_free_values(uh) -matdata = collect_cell_jacobian(uh,v,u,[t_affine]) +matdata = collect_cell_jacobian(uh,u,v,[t_affine]) vecdata = collect_cell_residual(uh,v,[t_affine]) A = assemble_matrix(assem,matdata...) b = assemble_vector(assem,vecdata...) @@ -87,14 +87,14 @@ x = A \ -b t_linear = LinearFETerm(a,trian,quad) t_source = FESource(l,trian,quad) -matdata = collect_cell_matrix(v,u,[t_linear, t_source]) -vecdata = collect_cell_vector(v,uhd,[t_linear, t_source]) +matdata = collect_cell_matrix(u,v,[t_linear, t_source]) +vecdata = collect_cell_vector(uhd,v,[t_linear, t_source]) A = assemble_matrix(assem,matdata...) b = assemble_vector(assem,vecdata...) x = A \ b @test x ≈ get_free_values(uh) -matdata = collect_cell_jacobian(uh,v,u,[t_linear, t_source]) +matdata = collect_cell_jacobian(uh,u,v,[t_linear, t_source]) vecdata = collect_cell_residual(uh,v,[t_linear, t_source]) A = assemble_matrix(assem,matdata...) b = assemble_vector(assem,vecdata...) @@ -105,14 +105,14 @@ x = A \ -b t_nonlinear = FETerm(r,j,trian,quad) -matdata = collect_cell_jacobian(uh,v,u,[t_nonlinear]) +matdata = collect_cell_jacobian(uh,u,v,[t_nonlinear]) vecdata = collect_cell_residual(uh,v,[t_nonlinear]) A = assemble_matrix(assem,matdata...) b = assemble_vector(assem,vecdata...) x = A \ -b @test (x.+1) ≈ ones(length(x)) -data = collect_cell_jacobian_and_residual(uh,v,u,[t_nonlinear]) +data = collect_cell_jacobian_and_residual(uh,u,v,[t_nonlinear]) A, b = allocate_matrix_and_vector(assem,data...) assemble_matrix_and_vector!(A,b,assem,data...) x = A \ -b @@ -152,14 +152,14 @@ end t_matvec_Ω = AffineFETermFromCellMatVec(matvecfun,trian) -matdata = collect_cell_matrix(v,u,[t_matvec_Ω,]) -vecdata = collect_cell_vector(v,uhd,[t_matvec_Ω,]) +matdata = collect_cell_matrix(u,v,[t_matvec_Ω,]) +vecdata = collect_cell_vector(uhd,v,[t_matvec_Ω,]) A = assemble_matrix(assem,matdata...) b = assemble_vector(assem,vecdata...) x = A \ b @test x ≈ get_free_values(uh) -data = collect_cell_matrix_and_vector(v,u,uhd,[t_matvec_Ω,]) +data = collect_cell_matrix_and_vector(uhd,u,v,[t_matvec_Ω,]) A, b = allocate_matrix_and_vector(assem,data...) assemble_matrix_and_vector!(A,b,assem,data...) x = A \ b @@ -193,14 +193,14 @@ end t_jacres_Ω = FETermFromCellJacRes(jacresfun,trian) -matdata = collect_cell_jacobian(uh,v,u,[t_jacres_Ω]) +matdata = collect_cell_jacobian(uh,u,v,[t_jacres_Ω]) vecdata = collect_cell_residual(uh,v,[t_jacres_Ω]) A = assemble_matrix(assem,matdata...) b = assemble_vector(assem,vecdata...) x = A \ -b @test (x.+1) ≈ ones(length(x)) -data = collect_cell_jacobian_and_residual(uh,v,u,[t_jacres_Ω]) +data = collect_cell_jacobian_and_residual(uh,u,v,[t_jacres_Ω]) A, b = allocate_matrix_and_vector(assem,data...) assemble_matrix_and_vector!(A,b,assem,data...) x = A \ -b diff --git a/test/GridapTests/PoissonTests.jl b/test/GridapTests/PoissonTests.jl index dbea1a73f..b19c3705e 100644 --- a/test/GridapTests/PoissonTests.jl +++ b/test/GridapTests/PoissonTests.jl @@ -81,7 +81,7 @@ for data in [ vector_data, scalar_data ] l_Γn(v) = v*(nn*∇(uh_Γn)) t_Γn = FESource(l_Γn,ntrian,nquad) - a_Γd(v,u) = (γ/h)*v*u - v*(dn*∇(u)) - (dn*∇(v))*u + a_Γd(u,v) = (γ/h)*v*u - v*(dn*∇(u)) - (dn*∇(v))*u l_Γd(v) = (γ/h)*v*uh_Γd - (dn*∇(v))*u t_Γd = AffineFETerm(a_Γd,l_Γd,dtrian,dquad) diff --git a/test/MultiFieldTests/MultiFieldFEOperatorsTests.jl b/test/MultiFieldTests/MultiFieldFEOperatorsTests.jl index 888a67055..94d2c2b0c 100644 --- a/test/MultiFieldTests/MultiFieldFEOperatorsTests.jl +++ b/test/MultiFieldTests/MultiFieldFEOperatorsTests.jl @@ -74,7 +74,7 @@ jac = ∇(ϕ) jac_q = evaluate(jac,q) x_q = evaluate(ϕ,q) -function cell_kernel!(A,B,x,y,j,w) +function cell_kernel!(A,B,y,x,j,w) A_vu = A[1,1] A_vp = A[1,2] @@ -118,7 +118,7 @@ end function cellmat_Ω(x,y) x_q = evaluate(x,q) y_q = evaluate(y,q) - apply_cellmatvec(cell_kernel!,x_q,y_q,jac_q,w_q) + apply_cellmatvec(cell_kernel!,y_q,x_q,jac_q,w_q) end t2_Ω = AffineFETermFromCellMatVec(cellmat_Ω,trian)