Lines Matching +full:julia +full:- +full:version
1 # Defining User Q-Functions
4 Q-functions](https://libceed.org/en/latest/libCEEDapi/#gallery-of-qfunctions)
5 natively in Julia. These user Q-functions work with both the CPU and CUDA
8 User Q-functions describe the action of the $D$ operator at quadrature points
10 framework](https://libceed.org/en/latest/libCEEDapi/#theoretical-framework)).
11 Since the Q-functions are invoked at every quadrature point, efficiency is
14 ## Apply mass Q-function in C
16 Before describing how to define user Q-functions in Julia, we will briefly given
17 an example of a user Q-function defined in C. This is the "apply mass"
18 Q-function from `ex1-volume.c`, which computes the action of the mass operator.
22 at each qudarture point). It is the action of $D$ that the Q-function must
23 implement. The C source of the Q-function is:
26 /// libCEED Q-function for applying a mass operator
41 From this example, we see that a user Q-function is a C callback that takes a
49 definition of this Q-function, the `CeedQFunction` object is created by
62 ## Apply mass Q-function in Julia
64 We now replicate this Q-function in Julia. The main way of defining user
65 Q-functions in Julia is using the [`@interior_qf`](@ref) macro. The above C code
66 (both the definition of the Q-function, its creation, and adding the inputs and
67 outputs) is analogous to the following Julia code:
69 ```julia
80 This creates a [`QFunction`](@ref) object named `apply_qfunc`. The Q-function is
81 defined by the tuple on the right-hand side. `ceed` is the name of the
82 [`Ceed`](@ref) object where the Q-function will be created, and the second
86 ```julia
98 diffusion Q-function](@ref applydiff)) these arrays could consists of vectors or
100 specifications, the body of the Q-function is provided.
102 ## [Apply diffusion Q-function in Julia](@id applydiff)
104 For a more sophisticated example of a Q-function, we consider the "apply
105 diffusion" Q-function, used in `ex2-surface`. This Q-function computes the
108 multiplication by $w \det(J) J^{-\intercal} J^{-1}$, where $J$ is the mesh
111 This Q-function is implemented in Julia as follows:
112 ```julia
126 Q-function includes a _constant definition_ `dim=dim`. The
128 which make the specified values available within the body of the Q-function as
129 compile-time constants.
132 of the problem. When the user Q-function is defined, LibCEED.jl will JIT compile
133 the body of the Q-function and make it available to libCEED as a C callback. In
134 the body of this Q-function, `dim` will be available, and its value will be a
135 compile-time constant, allowing for (static) dispatch based on the value of
141 ```julia
150 $w \det(J) J^{-\intercal} J^{-1} \nabla u$, which is also a vector of length `dim` at
155 \det(J) J^{-\intercal} J^{-1}$ evaluated at every quadrature point. In order to
163 After the field specifications, we have the body of the Q-function:
164 ```julia
171 First, the matrix $w \det(J) J^{-\intercal} J^{-1}$ is stored in the variable
175 sized `SMatrix`. The version for the correct spatial dimension is selected using
176 `CeedDim(dim)`, which allows for compile-time dispatch, since `dim` is a
177 constant whose value is known as a constant when the Q-function is JIT compiled.
180 fixed-size `SVector`. The result is placed into the output array, where the
182 evaluates `dXdxdXdxT*dui` using an optimized matrix-vector product for small
187 If the `Ceed` resource uses a CUDA backend, then the user Q-functions defined
189 [`CUDA.jl`](https://github.com/JuliaGPU/CUDA.jl). Some Julia features are not
190 available in GPU code (for example, dynamic dispatch), so if the Q-function is
192 of the user Q-function.