Skip to content

Commit

Permalink
Started porting code to new version of Gridap.ODEs
Browse files Browse the repository at this point in the history
  • Loading branch information
JordiManyer committed Dec 11, 2023
1 parent b30c808 commit 14b5427
Show file tree
Hide file tree
Showing 7 changed files with 29 additions and 27 deletions.
4 changes: 1 addition & 3 deletions src/GridapDistributed.jl
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,7 @@ using Gridap.CellData
using Gridap.Visualization
using Gridap.FESpaces
using Gridap.MultiField
using Gridap.ODEs.TransientFETools
using Gridap.ODEs.ODETools
using Gridap.ODEs

using MPI
using PartitionedArrays
Expand All @@ -29,7 +28,6 @@ import Gridap.TensorValues: inner, outer, double_contraction, symmetric_part
import LinearAlgebra: det, tr, cross, dot, , diag
import Base: inv, abs, abs2, *, +, -, /, adjoint, transpose, real, imag, conj, getproperty, propertynames
import Gridap.Fields: grad2curl
import Gridap.ODEs.ODETools: ∂t, ∂tt

export FullyAssembledRows
export SubAssembledRows
Expand Down
10 changes: 5 additions & 5 deletions src/TransientDistributedCellField.jl
Original file line number Diff line number Diff line change
Expand Up @@ -10,21 +10,21 @@ end
local_views(f::TransientSingleFieldDistributedCellField) = local_views(f.cellfield)

# Constructors
function TransientFETools.TransientCellField(single_field::DistributedSingleFieldFEFunction,derivatives::Tuple)
function ODEs.TransientCellField(single_field::DistributedSingleFieldFEFunction,derivatives::Tuple)
TransientSingleFieldDistributedCellField(single_field,derivatives)
end

function TransientFETools.TransientCellField(single_field::DistributedCellField,derivatives::Tuple)
TransientSingleFieldDistributedCellField(single_field,derivatives)
function ODEs.TransientCellField(single_field::DistributedCellField,derivatives::Tuple)
TransientSingleFieldDistributedCellField(single_field,derivatives)
end

# Time derivative
function ∂t(f::TransientDistributedCellField)
function ODEs.∂t(f::TransientDistributedCellField)
cellfield, derivatives = first_and_tail(f.derivatives)
TransientCellField(cellfield,derivatives)
end

∂tt(f::TransientDistributedCellField) = ∂t(∂t(f))
ODEs.∂tt(f::TransientDistributedCellField) = ∂t(∂t(f))

# Integration related
function Fields.integrate(f::TransientDistributedCellField,b::DistributedMeasure)
Expand Down
20 changes: 10 additions & 10 deletions src/TransientFESpaces.jl
Original file line number Diff line number Diff line change
Expand Up @@ -4,35 +4,35 @@ Fields.evaluate(U::DistributedSingleFieldFESpace,t::Nothing) = U

(U::DistributedSingleFieldFESpace)(t) = U

∂t(U::DistributedSingleFieldFESpace) = HomogeneousTrialFESpace(U)
∂t(U::DistributedMultiFieldFESpace) = MultiFieldFESpace(∂t.(U.field_fe_space))
∂tt(U::DistributedSingleFieldFESpace) = HomogeneousTrialFESpace(U)
∂tt(U::DistributedMultiFieldFESpace) = MultiFieldFESpace(∂tt.(U.field_fe_spaces))
ODEs.∂t(U::DistributedSingleFieldFESpace) = HomogeneousTrialFESpace(U)
ODEs.∂t(U::DistributedMultiFieldFESpace) = MultiFieldFESpace(∂t.(U.field_fe_space))
ODEs.∂tt(U::DistributedSingleFieldFESpace) = HomogeneousTrialFESpace(U)
ODEs.∂tt(U::DistributedMultiFieldFESpace) = MultiFieldFESpace(∂tt.(U.field_fe_spaces))

function TransientMultiFieldFESpace(spaces::Vector{<:DistributedSingleFieldFESpace})
MultiFieldFESpace(spaces)
end

# Functions for transient FE Functions

function ODETools.allocate_jacobian(
op::TransientFETools.TransientFEOperatorFromWeakForm,
function ODEs.allocate_jacobian(
op::ODEs.TransientFEOpFromWeakForm,
t0::Real,
duh::Union{DistributedCellField,DistributedMultiFieldFEFunction},
cache)
_matdata_jacobians = TransientFETools.fill_initial_jacobians(op,t0,duh)
_matdata_jacobians = ODEs.fill_initial_jacobians(op,t0,duh)
matdata = _vcat_distributed_matdata(_matdata_jacobians)
allocate_matrix(op.assem_t,matdata)
end

function ODETools.jacobians!(
function ODEs.jacobians!(
A::AbstractMatrix,
op::TransientFETools.TransientFEOperatorFromWeakForm,
op::ODEs.TransientFEOpFromWeakForm,
t::Real,
xh::TransientDistributedCellField,
γ::Tuple{Vararg{Real}},
cache)
_matdata_jacobians = TransientFETools.fill_jacobians(op,t,xh,γ)
_matdata_jacobians = ODEs.fill_jacobians(op,t,xh,γ)
matdata = _vcat_distributed_matdata(_matdata_jacobians)
assemble_matrix_add!(A,op.assem_t, matdata)
A
Expand Down
4 changes: 2 additions & 2 deletions src/TransientMultiFieldDistributedCellField.jl
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ end
local_views(f::TransientMultiFieldDistributedCellField) = local_views(f.cellfield)

# Constructors
function TransientFETools.TransientCellField(multi_field::DistributedMultiFieldFEFunction,derivatives::Tuple)
function ODEs.TransientCellField(multi_field::DistributedMultiFieldFEFunction,derivatives::Tuple)
transient_single_fields = _to_transient_single_distributed_fields(multi_field,derivatives)
TransientMultiFieldDistributedCellField(multi_field,derivatives,transient_single_fields)
end
Expand Down Expand Up @@ -53,7 +53,7 @@ Base.iterate(f::TransientMultiFieldDistributedCellField) = iterate(f.transient_
Base.iterate(f::TransientMultiFieldDistributedCellField,state) = iterate(f.transient_single_fields,state)

# Time derivative
function ∂t(f::TransientMultiFieldDistributedCellField)
function ODEs.∂t(f::TransientMultiFieldDistributedCellField)
cellfield, derivatives = first_and_tail(f.derivatives)
transient_single_field_derivatives = TransientDistributedCellField[]
for transient_single_field in f.transient_single_fields
Expand Down
8 changes: 6 additions & 2 deletions test/StokesOpenBoundaryTests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ function main(distribute,parts)
ph0 = interpolate_everywhere(p(0.0),P0)
xh0 = interpolate_everywhere([uh0,ph0],X0)

op = TransientFEOperator(res,jac,jac_t,X,Y)
op = TransientFEOperator(res,(jac,jac_t),X,Y)

t0 = 0.0
tF = 1.0
Expand All @@ -90,7 +90,7 @@ function main(distribute,parts)
ls = LUSolver()
ode_solver = ThetaMethod(ls,dt,θ)

sol_t = solve(ode_solver,op,xh0,t0,tF)
sol_t = solve(ode_solver,op,t0,tF,xh0)

l2(w) = ww

Expand All @@ -112,4 +112,8 @@ function main(distribute,parts)
end
end

with_debug() do distribute
main(distribute,(2,2))
end

end #module
4 changes: 2 additions & 2 deletions test/TransientDistributedCellFieldTests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ module TransientDistributedCellFieldTests

using Gridap
using GridapDistributed
using Gridap.ODEs.ODETools: ∂t, ∂tt
using Gridap.ODEs.TransientFETools: TransientCellField
using Gridap.ODEs: ∂t, ∂tt
using Gridap.ODEs: TransientCellField
using PartitionedArrays
using Test

Expand Down
6 changes: 3 additions & 3 deletions test/TransientMultiFieldDistributedCellFieldTests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@ module TransientMultiFieldDistributedCellFieldTests

using Gridap
using GridapDistributed
using Gridap.ODEs.ODETools: ∂t, ∂tt
using Gridap.ODEs.TransientFETools: TransientCellField
using Gridap.ODEs.TransientFETools: TransientTrialFESpace, TransientMultiFieldFESpace
using Gridap.ODEs: ∂t, ∂tt
using Gridap.ODEs: TransientCellField
using Gridap.ODEs: TransientTrialFESpace, TransientMultiFieldFESpace
using PartitionedArrays
using Test

Expand Down

0 comments on commit 14b5427

Please sign in to comment.