From 0f99234156dd0174485ca83431de76aa3825584a Mon Sep 17 00:00:00 2001 From: fverdugo Date: Tue, 9 Jul 2019 17:32:32 +0200 Subject: [PATCH] Using the machinery based on FETerm objects --- src/FESpaces/FEOperators.jl | 42 +++++++++++++++++++++++++++---------- 1 file changed, 31 insertions(+), 11 deletions(-) diff --git a/src/FESpaces/FEOperators.jl b/src/FESpaces/FEOperators.jl index 2aa7639de..0dbf28041 100644 --- a/src/FESpaces/FEOperators.jl +++ b/src/FESpaces/FEOperators.jl @@ -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 @@ -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 """