xref: /libCEED/julia/LibCEED.jl/src/Operator.jl (revision edb2538e3dd6743c029967fc4e89c6fcafedb8c2)
144554ea0SWill Paznermutable struct Operator
244554ea0SWill Pazner    ref::RefValue{C.CeedOperator}
344554ea0SWill Pazner    qf::AbstractQFunction
444554ea0SWill Pazner    dqf::AbstractQFunction
544554ea0SWill Pazner    dqfT::AbstractQFunction
644554ea0SWill Pazner    sub_ops::Vector{Operator}
744554ea0SWill Pazner    function Operator(ref, qf, dqf, dqfT)
844554ea0SWill Pazner        obj = new(ref, qf, dqf, dqfT, [])
944554ea0SWill Pazner        finalizer(obj) do x
1044554ea0SWill Pazner            # ccall(:jl_safe_printf, Cvoid, (Cstring, Cstring), "Finalizing %s.\n", repr(x))
1144554ea0SWill Pazner            destroy(x)
1244554ea0SWill Pazner        end
1344554ea0SWill Pazner        return obj
1444554ea0SWill Pazner    end
1544554ea0SWill Paznerend
1644554ea0SWill Paznerdestroy(op::Operator) = C.CeedOperatorDestroy(op.ref) # COV_EXCL_LINE
1744554ea0SWill PaznerBase.getindex(op::Operator) = op.ref[]
1844554ea0SWill PaznerBase.show(io::IO, ::MIME"text/plain", op::Operator) = ceed_show(io, op, C.CeedOperatorView)
1944554ea0SWill Pazner
2044554ea0SWill Pazner"""
2144554ea0SWill Pazner    Operator(ceed::Ceed; qf, dqf=QFunctionNone(), dqfT=QFunctionNone(), fields)
2244554ea0SWill Pazner
2344554ea0SWill PaznerCreates a libCEED `CeedOperator` object using the given Q-function `qf`, and optionally its
2444554ea0SWill Paznerderivative and derivative transpose.
2544554ea0SWill Pazner
2644554ea0SWill PaznerAn array of fields must be provided, where each element of the array is a tuple containing
2744554ea0SWill Paznerthe name of the field (as a string or symbol), the corresponding element restriction, basis,
2844554ea0SWill Paznerand vector.
2944554ea0SWill Pazner
3044554ea0SWill Pazner# Examples
3144554ea0SWill Pazner
3244554ea0SWill PaznerCreate the operator that builds the Q-data associated with the mass matrix.
3344554ea0SWill Pazner```
3444554ea0SWill Paznerbuild_oper = Operator(
3544554ea0SWill Pazner    ceed,
3644554ea0SWill Pazner    qf=build_qfunc,
3744554ea0SWill Pazner    fields=[
38*edb2538eSJeremy L Thompson        (:J, mesh_rstr, mesh_basis, CeedVectorActive()),
3944554ea0SWill Pazner        (:w, ElemRestrictionNone(), mesh_basis, CeedVectorNone()),
40*edb2538eSJeremy L Thompson        (:qdata, sol_rstr_i, BasisNone(), CeedVectorActive())
4144554ea0SWill Pazner    ]
4244554ea0SWill Pazner)
4344554ea0SWill Pazner```
4444554ea0SWill Pazner"""
4544554ea0SWill Paznerfunction Operator(c::Ceed; qf, dqf=QFunctionNone(), dqfT=QFunctionNone(), fields)
4644554ea0SWill Pazner    op = Operator(c, qf, dqf, dqfT)
4744554ea0SWill Pazner    for f ∈ fields
4844554ea0SWill Pazner        set_field!(op, String(f[1]), f[2], f[3], f[4])
4944554ea0SWill Pazner    end
5044554ea0SWill Pazner    op
5144554ea0SWill Paznerend
5244554ea0SWill Pazner
5344554ea0SWill Paznerfunction Operator(
5444554ea0SWill Pazner    c::Ceed,
5544554ea0SWill Pazner    qf::AbstractQFunction,
5644554ea0SWill Pazner    dqf::AbstractQFunction,
5744554ea0SWill Pazner    dqfT::AbstractQFunction,
5844554ea0SWill Pazner)
5944554ea0SWill Pazner    ref = Ref{C.CeedOperator}()
6044554ea0SWill Pazner    C.CeedOperatorCreate(c[], qf[], dqf[], dqfT[], ref)
6144554ea0SWill Pazner    Operator(ref, qf, dqf, dqfT)
6244554ea0SWill Paznerend
6344554ea0SWill Pazner
6444554ea0SWill Pazner"""
6544554ea0SWill Pazner    create_composite_operator(c::Ceed, ops)
6644554ea0SWill Pazner
6744554ea0SWill PaznerCreate an [`Operator`](@ref) whose action represents the sum of the operators in the
6844554ea0SWill Paznercollection `ops`.
6944554ea0SWill Pazner"""
7044554ea0SWill Paznerfunction create_composite_operator(c::Ceed, ops)
7144554ea0SWill Pazner    ref = Ref{C.CeedOperator}()
7244554ea0SWill Pazner    C.CeedCompositeOperatorCreate(c[], ref)
7344554ea0SWill Pazner    comp_op = Operator(ref, QFunctionNone(), QFunctionNone(), QFunctionNone())
7444554ea0SWill Pazner    comp_op.sub_ops = ops
7544554ea0SWill Pazner    for op ∈ ops
7644554ea0SWill Pazner        C.CeedCompositeOperatorAddSub(comp_op[], op[])
7744554ea0SWill Pazner    end
7844554ea0SWill Pazner    comp_op
7944554ea0SWill Paznerend
8044554ea0SWill Pazner
8144554ea0SWill Paznerfunction set_field!(
8244554ea0SWill Pazner    op::Operator,
8344554ea0SWill Pazner    fieldname::AbstractString,
8444554ea0SWill Pazner    r::AbstractElemRestriction,
8544554ea0SWill Pazner    b::AbstractBasis,
8644554ea0SWill Pazner    v::AbstractCeedVector,
8744554ea0SWill Pazner)
8844554ea0SWill Pazner    C.CeedOperatorSetField(op[], fieldname, r[], b[], v[])
8944554ea0SWill Paznerend
9044554ea0SWill Pazner
9144554ea0SWill Pazner"""
9244554ea0SWill Pazner    apply!(op::Operator, vin, vout; request=RequestImmediate())
9344554ea0SWill Pazner
9444554ea0SWill PaznerApply the action of the operator `op` to the input vector `vin`, and store the result in the
9544554ea0SWill Pazneroutput vector `vout`.
9644554ea0SWill Pazner
9744554ea0SWill PaznerFor non-blocking application, the user can specify a request object. By default, immediate
9844554ea0SWill Pazner(synchronous) completion is requested.
9944554ea0SWill Pazner"""
10044554ea0SWill Paznerfunction apply!(
10144554ea0SWill Pazner    op::Operator,
10244554ea0SWill Pazner    vin::AbstractCeedVector,
10344554ea0SWill Pazner    vout::AbstractCeedVector;
10444554ea0SWill Pazner    request=RequestImmediate(),
10544554ea0SWill Pazner)
10644554ea0SWill Pazner    C.CeedOperatorApply(op[], vin[], vout[], request[])
10744554ea0SWill Paznerend
10844554ea0SWill Pazner
10944554ea0SWill Pazner"""
11044554ea0SWill Pazner    apply_add!(op::Operator, vin, vout; request=RequestImmediate())
11144554ea0SWill Pazner
11244554ea0SWill PaznerApply the action of the operator `op` to the input vector `vin`, and add the result to the
11344554ea0SWill Pazneroutput vector `vout`.
11444554ea0SWill Pazner
11544554ea0SWill PaznerFor non-blocking application, the user can specify a request object. By default, immediate
11644554ea0SWill Pazner(synchronous) completion is requested.
11744554ea0SWill Pazner"""
11844554ea0SWill Paznerfunction apply_add!(
11944554ea0SWill Pazner    op::Operator,
12044554ea0SWill Pazner    vin::AbstractCeedVector,
12144554ea0SWill Pazner    vout::AbstractCeedVector;
12244554ea0SWill Pazner    request=RequestImmediate(),
12344554ea0SWill Pazner)
12444554ea0SWill Pazner    C.CeedOperatorApplyAdd(op[], vin[], vout[], request[])
12544554ea0SWill Paznerend
12644554ea0SWill Pazner
12744554ea0SWill Pazner"""
12844554ea0SWill Pazner    assemble_diagonal!(op::Operator, diag::CeedVector; request=RequestImmediate())
12944554ea0SWill Pazner
13044554ea0SWill PaznerOverwrites a [`CeedVector`](@ref) with the diagonal of a linear [`Operator`](@ref).
13144554ea0SWill Pazner
13244554ea0SWill Pazner!!! note "Note:"
13344554ea0SWill Pazner    Currently only [`Operator`](@ref)s with a single field are supported.
13444554ea0SWill Pazner"""
13544554ea0SWill Paznerfunction assemble_diagonal!(op::Operator, diag::CeedVector; request=RequestImmediate())
13644554ea0SWill Pazner    C.CeedOperatorLinearAssembleDiagonal(op[], diag[], request[])
13744554ea0SWill Paznerend
13844554ea0SWill Pazner
13944554ea0SWill Pazner"""
14044554ea0SWill Pazner    assemble_diagonal!(op::Operator, diag::CeedVector; request=RequestImmediate())
14144554ea0SWill Pazner
14244554ea0SWill PaznerAdds the diagonal of a linear [`Operator`](@ref) to the given [`CeedVector`](@ref).
14344554ea0SWill Pazner
14444554ea0SWill Pazner!!! note "Note:"
14544554ea0SWill Pazner    Currently only [`Operator`](@ref)s with a single field are supported.
14644554ea0SWill Pazner"""
14744554ea0SWill Paznerfunction assemble_add_diagonal!(op::Operator, diag::CeedVector; request=RequestImmediate())
14844554ea0SWill Pazner    C.CeedOperatorLinearAssembleAddDiagonal(op[], diag[], request[])
14944554ea0SWill Paznerend
150