Skip to content

Commit

Permalink
Fixed constructors of TransientFEOperator and only assemble jacobian …
Browse files Browse the repository at this point in the history
…matrices if they have contributions
  • Loading branch information
AlexandreMagueresse committed Dec 20, 2023
1 parent 39e0599 commit c26edc6
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 22 deletions.
36 changes: 21 additions & 15 deletions src/ODEs/ODEOpsFromTFEOps.jl
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,8 @@ function allocate_odeopcache(
const_form = nothing
if is_form_constant(odeop, k)
jac = jacs[k+1]
matdata = collect_cell_matrix(Ut, V, jac(t, uh, du, v))
dc = jac(t, uh, du, v)
matdata = collect_cell_matrix(Ut, V, dc)
const_form = assemble_matrix(assembler, matdata)
end
const_forms = (const_forms..., const_form)
Expand All @@ -117,7 +118,8 @@ function allocate_odeopcache(
k = order
if is_form_constant(odeop, k)
jac = jacs[k+1]
matdata = collect_cell_matrix(Ut, V, jac(t, uh, du, v))
dc = jac(t, uh, du, v)
matdata = collect_cell_matrix(Ut, V, dc)
const_form = assemble_matrix(assembler, matdata)
end
const_forms = (const_forms..., const_form)
Expand Down Expand Up @@ -167,7 +169,8 @@ function Algebra.residual!(
!add && fill!(r, zero(eltype(r)))

res = get_res(odeop.tfeop)
vecdata = collect_cell_vector(V, res(t, uh, v))
dc = res(t, uh, v)
vecdata = collect_cell_vector(V, dc)
assemble_vector_add!(r, assembler, vecdata)

r
Expand All @@ -184,11 +187,10 @@ function Algebra.residual!(
assembler = get_assembler(odeop.tfeop)

!add && fill!(r, zero(eltype(r)))
dc = DomainContribution()

# Residual
res = get_res(odeop.tfeop)
dc = dc + res(t, uh, v)
dc = res(t, uh, v)

# Mass
order = get_order(odeop)
Expand All @@ -213,11 +215,10 @@ function Algebra.residual!(
assembler = get_assembler(odeop.tfeop)

!add && fill!(r, zero(eltype(r)))
dc = DomainContribution()

# Residual
res = get_res(odeop.tfeop)
dc = dc + res(t, uh, v)
dc = res(t, uh, v)

# Mass
order = get_order(odeop)
Expand All @@ -242,11 +243,10 @@ function Algebra.residual!(
assembler = get_assembler(odeop.tfeop)

!add && fill!(r, zero(eltype(r)))
dc = DomainContribution()

# Residual
res = get_res(odeop.tfeop)
dc = dc + res(t, uh, v)
dc = res(t, uh, v)

# Forms
order = get_order(odeop)
Expand Down Expand Up @@ -309,8 +309,10 @@ function jacobian_add!(
dc = dc + w * jac(t, uh, du, v)
end

matdata = collect_cell_matrix(Ut, V, dc)
assemble_matrix_add!(J, assembler, matdata)
if num_domains(dc) > 0
matdata = collect_cell_matrix(Ut, V, dc)
assemble_matrix_add!(J, assembler, matdata)
end

J
end
Expand Down Expand Up @@ -349,8 +351,10 @@ function jacobian_add!(
end
end

matdata = collect_cell_matrix(Ut, V, dc)
assemble_matrix_add!(J, assembler, matdata)
if num_domains(dc) > 0
matdata = collect_cell_matrix(Ut, V, dc)
assemble_matrix_add!(J, assembler, matdata)
end

J
end
Expand Down Expand Up @@ -380,8 +384,10 @@ function jacobian_add!(
end
end

matdata = collect_cell_matrix(Ut, V, dc)
assemble_matrix_add!(J, assembler, matdata)
if num_domains(dc) > 0
matdata = collect_cell_matrix(Ut, V, dc)
assemble_matrix_add!(J, assembler, matdata)
end

J
end
Expand Down
14 changes: 7 additions & 7 deletions src/ODEs/TransientFEOperators.jl
Original file line number Diff line number Diff line change
Expand Up @@ -236,7 +236,7 @@ function TransientFEOperator(
jac::Function,
trial, test
)
TransientFEOpFromWeakForm(
TransientFEOperator(
res, (jac,),
trial, test
)
Expand All @@ -247,7 +247,7 @@ function TransientFEOperator(
jac::Function, jac_t::Function,
trial, test
)
TransientFEOpFromWeakForm(
TransientFEOperator(
res, (jac, jac_t),
trial, test
)
Expand All @@ -258,7 +258,7 @@ function TransientFEOperator(
jac::Function, jac_t::Function, jac_tt::Function,
trial, test
)
TransientFEOpFromWeakForm(
TransientFEOperator(
res, (jac, jac_t, jac_tt),
trial, test
)
Expand Down Expand Up @@ -368,7 +368,7 @@ function TransientQuasilinearFEOperator(
jac::Function, jac_t::Function,
trial, test
)
TransientQuasilinearFEOpFromWeakForm(
TransientQuasilinearFEOperator(
mass, res, (jac, jac_t),
trial, test
)
Expand All @@ -379,7 +379,7 @@ function TransientQuasilinearFEOperator(
jac::Function, jac_t::Function, jac_tt::Function,
trial, test
)
TransientQuasilinearFEOpFromWeakForm(
TransientQuasilinearFEOperator(
mass, res, (jac, jac_t, jac_tt),
trial, test
)
Expand Down Expand Up @@ -514,7 +514,7 @@ function TransientSemilinearFEOperator(
trial, test;
constant_mass::Bool=false,
)
TransientSemilinearFEOpFromWeakForm(
TransientSemilinearFEOperator(
mass, res, (jac, jac_t),
trial, test;
constant_mass
Expand All @@ -527,7 +527,7 @@ function TransientSemilinearFEOperator(
trial, test;
constant_mass::Bool=false,
)
TransientSemilinearFEOpFromWeakForm(
TransientSemilinearFEOperator(
mass, res, (jac, jac_t, jac_tt),
trial, test;
constant_mass
Expand Down

0 comments on commit c26edc6

Please sign in to comment.