Skip to content

Commit

Permalink
Using the machinery based on FETerm objects
Browse files Browse the repository at this point in the history
  • Loading branch information
fverdugo committed Jul 9, 2019
1 parent fba1b83 commit 0f99234
Showing 1 changed file with 31 additions and 11 deletions.
42 changes: 31 additions & 11 deletions src/FESpaces/FEOperators.jl
Original file line number Diff line number Diff line change
Expand Up @@ -249,14 +249,34 @@ end
"""
Struct representing a nonlinear FE Operator
"""
struct NonLinearFEOperator{Z} <:FEOperator
res::Function
jac::Function
struct NonLinearFEOperator <:FEOperator
testfesp::FESpaceLike
trialfesp::FESpaceLike
assem::AssemblerLike
trian::Triangulation{Z}
quad::CellQuadrature{Z}
terms::Tuple{<:FETerm}
end

function NonLinearFEOperator(
testfesp::FESpaceLike,
trialfesp::FESpaceLike,
assem::AssemblerLike,
terms::Vararg{<:FETerm})
NonLinearFEOperator(testfesp,trialfesp,assem,terms)
end

function NonLinearFEOperator(
res::Function,
jac::Function,
testfesp::FESpaceLike,
trialfesp::FESpaceLike,
assem::AssemblerLike,
trian::Triangulation,
quad::CellQuadrature)

term = NonLinearFETerm(res,jac,trian,quad)

NonLinearFEOperator(testfesp,trialfesp,assem,term)

end

TrialFESpace(op::NonLinearFEOperator) = op.trialfesp
Expand All @@ -265,33 +285,33 @@ TestFESpace(op::NonLinearFEOperator) = op.testfesp

function apply(op::NonLinearFEOperator,uh::FEFunctionLike)
cellvec = _cellvec(op,uh)
assemble(op.assem, cellvec)
assemble(op.assem, cellvec...)
end

function apply!(b::AbstractVector,op::NonLinearFEOperator,uh::FEFunctionLike)
cellvec = _cellvec(op,uh)
assemble!(b,op.assem, cellvec)
assemble!(b,op.assem, cellvec...)
end

function jacobian(op::NonLinearFEOperator,uh::FEFunctionLike)
cellmat = _cellmat(op,uh)
assemble(op.assem, cellmat)
assemble(op.assem, cellmat...)
end

function jacobian!(mat::AbstractMatrix,op::NonLinearFEOperator,uh::FEFunctionLike)
cellmat = _cellmat(op,uh)
assemble!(mat,op.assem, cellmat)
assemble!(mat,op.assem, cellmat...)
end

function _cellvec(op,uh)
v = FEBasis(op.testfesp)
integrate(op.res(uh,v), op.trian, op.quad)
setup_cell_residual(uh,v,op.terms...)
end

function _cellmat(op,uh)
v = FEBasis(op.testfesp)
du = FEBasis(op.trialfesp)
integrate(op.jac(uh,v,du), op.trian, op.quad)
setup_cell_jacobian(uh,v,du,op.terms...)
end

"""
Expand Down

0 comments on commit 0f99234

Please sign in to comment.