gridap / GridapODEs.jl

Time stepping for Gridap
MIT License
33 stars 7 forks source link

new API for transient FE operators #52

Closed oriolcg closed 2 years ago

oriolcg commented 3 years ago

As @fverdugo suggested, it would be nice to have this API

res(t,u,v) = m(∂tt(u),v) + c(∂t(u),v) + a(u,v) - b(v,t)

instead of

res(t,(u,ut,utt),v) = m(utt,v) + c(ut,v) + a(u,v) - b(v,t)

That should be easy to do by defining a new struct (or similar) such as

struct TransientFEFunction
  x::Tuple{Vararg{FEFunction}}
end

and implementing the functions: ∂t(u::TransientFEFunction)=u.x[2] and ∂tt(u::TransientFEFunction)=u.x[3]. However, there is the issue of what to do for the 0-th time derivative, i.e. in a(u,v), since now this will contain a tuple. We should use some operator to get the first entry like a(∂(u),v) with ∂(u::TransientFEFunction)=u.x[1]. Any suggestion on the notation or other approaches, @santiagobadia @fverdugo ?

fverdugo commented 3 years ago

Unfortunately, it is not so straightforward since you don't want to implement this for fe functions only, and you also want that your transient type behavies like a cell field.

I would try something like this:

struct TransientCellField{A,B} <: CellField
  cellfield::A
  derivatives::T
end

# Make this object behave like a CellField
# by delegating the methods to the internal cellfield
# e.g.
get_data(f::FEBasis) = get_data(f.cellfield)
DomainStyle(::Type{<:TransientCellField{A}}) where A = DomainStyle(A)

# Idem for
get_triangulation(f::TransientCellField)
gradient(a::TransientCellField)
∇∇(a::TransientCellField)
change_domain(a::TransientCellField,trian::Triangulation,target_domain::DomainStyle)

#Time derivative
# ∂t can be called in the resulting object until we run out of
# derivatives
function ∂t(f::TransientCellField)
  cellfield, derivatives = first_and_tail(f.derivatives)
  TransientCellField(cellfield,derivatives)
end

I am not sure if this will work when the cell field is a basis. I believe that the proper way to handle basis is to use the abstract type FEBasis introduced in the mixed_dims branch and implement also this type

struct TransientFEBasis{A,B} <: FEBasis
  febasis::A
  derivatives::T
end

which should implement the same methods as TransientCellField plus these extra one:

BasisStyle(::Type{<:TransientFEBasis{A}}) where A = BasisStyle(A)
oriolcg commented 3 years ago

@fverdugo, @santiagobadia The new API is working in the branch https://github.com/gridap/GridapODEs.jl/tree/new_API_transient_fe_operators. I'll wait for the PR until the branch update_to_Gridap_0_16 is merged, which is ready and waiting for Gridap@0.16 to be registered.

After these merges, I think it should be a good point to release GridapODEs@0.7

fverdugo commented 3 years ago

Great! Does this work also for mixed-dimensional PDEs ? I think it's the more problematic case...

oriolcg commented 3 years ago

Good point, I haven't tried. I'll add a test for that.