Skip to content
This repository has been archived by the owner on Feb 28, 2022. It is now read-only.

Commit

Permalink
Fixing TransientFEOperator for autoDiff
Browse files Browse the repository at this point in the history
  • Loading branch information
oriolcg committed Oct 5, 2021
1 parent 0bbda57 commit 2caea13
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 7 deletions.
13 changes: 10 additions & 3 deletions src/TransientFETools/TransientFEOperators.jl
Original file line number Diff line number Diff line change
Expand Up @@ -193,11 +193,18 @@ function TransientFEOperator(res::Function,jac::Function,jac_t::Function,
end

function TransientFEOperator(res::Function,trial,test;order::Integer=1)
jacs = ()
for i in 1:order+1
function jac_0(t,x,dx0,dv)
function res_0(y)
x0 = (y,x[2:end]...)
res(t,x0,dv)
end
jacobian(res_0,x[1])
end
jacs = (jac_0,)
for i in 2:order+1
function jac_i(t,x,dxi,dv)
function res_i(y)
x[i] = y
x = (x[1:i-1]...,y,x[i+1:end]...)
res(t,x,dv)
end
jacobian(res_i,x[i])
Expand Down
8 changes: 4 additions & 4 deletions test/TransientFEsTests/HeatEquationAutoDiffTests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -50,11 +50,11 @@ dv = get_fe_basis(V0)
du = get_trial_fe_basis(U₀)
uh = FEFunction(U₀,rand(num_free_dofs(U₀)))

cell_j = get_array(jac(0.5,uh,uh,du,dv))
cell_j_t = get_array(jac_t(0.5,uh,uh,du,dv))
cell_j = get_array(jac(0.5,(uh,uh),du,dv))
cell_j_t = get_array(jac_t(0.5,(uh,uh),du,dv))

cell_j_auto = get_array(jacobian(x->res(0.5,x,uh,dv),uh))
cell_j_t_auto = get_array(jacobian(x->res(0.5,uh,x,dv),uh))
cell_j_auto = get_array(jacobian(x->res(0.5,(x,uh),dv),uh))
cell_j_t_auto = get_array(jacobian(x->res(0.5,(uh,x),dv),uh))

test_array(cell_j_auto,cell_j,)
test_array(cell_j_t_auto,cell_j_t,)
Expand Down

0 comments on commit 2caea13

Please sign in to comment.