1# LibCEED.jl Docs 2 3Documentation for the LibCEED.jl Julia interface to the 4[libCEED](https://github.com/ceed/libceed) library. 5 6For further information, see also the [libCEED 7documentation](https://libceed.readthedocs.io/). 8 9Several [short examples](Examples.md) are included to demonstrate the 10functionality. 11 12### Installation 13 14The LibCEED.jl package can be installed with Julia's package manager by running 15`] add LibCEED`. This will automatically install a pre-built binary of the 16libCEED library. If you require features of a specific build of libCEED (e.g. 17CUDA/GPU support, specific compiler flags, etc.) then you should compile your 18own version of the libCEED library, and configure LibCEED.jl to use this binary 19as described in the [Configuring LibCEED.jl](@ref) section. 20 21!!! warning "The pre-built libCEED binaries do not support CUDA backends" 22 The pre-built binaries automatically installed by LibCEED.jl (through the 23 [libCEED_jll](https://juliahub.com/ui/Packages/libCEED_jll/LB2fn) package) 24 are not built with CUDA support. If you want to run libCEED on the GPU, you 25 will have to build libCEED from source and configure LibCEED.jl as described 26 in the [Configuring LibCEED.jl](@ref) section. 27 28#### Configuring LibCEED.jl 29 30By default, LibCEED.jl will use the pre-built libCEED binaries provided by the 31[libCEED_jll](https://juliahub.com/ui/Packages/libCEED_jll/LB2fn) package. If 32you wish to use a different libCEED binary (e.g. one built from source), 33LibCEED.jl can be configured using Julia's _preferences_ mechanism. Note that 34this preference will be set for the currently active Julia environemnt, and can 35be different between different environments. The Julia session must be restarted 36for changes to take effect. 37 38```julia 39julia> using LibCEED 40julia> set_libceed_path!("/path/to/libceed.so") 41[ Info: Setting the libCEED library path to /path/to/libceed.so. 42[ Info: Restart the Julia session for changes to take effect. 43``` 44 45See the [library configuration documentation](LibCEED.md) for more details. For 46information on Julia's preferences system, see 47[Preferences.jl](https://github.com/JuliaPackaging/Preferences.jl). 48 49### Features of the high-level interface for libCEED 50 51#### User Q-functions 52 53With LibCEED.jl, it is much easier to write dimension-independent user-defined 54Q-functions that automatically work on the GPU. See the [related 55documentation](UserQFunctions.md) for more information. 56 57#### Safe access to CeedVector objects 58 59When accessing [`CeedVector`](@ref) objects, the C interface requires the user 60to manually call `CeedVectorGetArray`, paired with `CeedVectorRestoreArray`. If 61the user wants read-only access, then the user must call 62`CeedVectorGetArrayRead`, paired with `CeedVectorRestoreArrayRead`. This can 63possibly be bug-prone, because the user may forget to restore the array, or may 64match the `Read` version to get the array with non-`Read` version to restore the 65array (or vice versa). 66 67In LibCEED.jl, this difficulty is mitigated using the [`witharray`](@ref) 68function and [`@witharray`](@ref) macro. There are also read-only versions, 69[`witharray_read`](@ref) and [`@witharray_read`](@ref). When using this 70functionality, it is impossible to forget to restore the array, and the correct 71version is always paired properly. 72 73For example, in `ex1-volume`, the following C code 74```c 75// Compute and print the sum of the entries of 'v' giving the mesh volume. 76const CeedScalar *v_host; 77CeedVectorGetArrayRead(v, CEED_MEM_HOST, &v_host); 78CeedScalar vol = 0.; 79for (CeedInt i = 0; i < sol_size; i++) { 80 vol += v_host[i]; 81} 82CeedVectorRestoreArrayRead(v, &v_host); 83``` 84is replaced with the following equivalent Julia code 85```julia 86# Compute and print the sum of the entries of 'v' giving the mesh volume. 87vol = witharray_read(sum, v, MEM_HOST) 88``` 89 90In `ex2-surface`, the following C code 91```c 92// Initialize 'u' with sum of coordinates, x+y+z. 93CeedScalar *u_host; 94const CeedScalar *x_host; 95CeedVectorGetArray(u, CEED_MEM_HOST, &u_host); 96CeedVectorGetArrayRead(mesh_coords, CEED_MEM_HOST, &x_host); 97for (CeedInt i = 0; i < sol_size; i++) { 98 u_host[i] = 0; 99 for (CeedInt d = 0; d < dim; d++) 100 u_host[i] += x_host[i+d*sol_size]; 101} 102CeedVectorRestoreArray(u, &u_host); 103CeedVectorRestoreArrayRead(mesh_coords, &x_host); 104``` 105is replaced with the following equivalent Julia code 106```julia 107@witharray_read(x_host=mesh_coords, size=(mesh_size÷dim, dim), 108 @witharray(u_host=u, size=(sol_size,1), 109 sum!(u_host, x_host))) 110``` 111The macro version can provide better performance if a closure is required, and 112allow for convenient reshaping of the vector into equivalently sized matrices 113or tensors. 114 115### Library configuration 116```@contents 117Pages = [ 118 "LibCEED.md", 119] 120``` 121 122### Ceed objects 123```@contents 124Pages = [ 125 "Ceed.md", 126 "CeedVector.md", 127 "ElemRestriction.md", 128 "Basis.md", 129 "QFunction.md", 130 "Operator.md", 131] 132``` 133 134### Utilities 135```@contents 136Pages = [ 137 "Misc.md", 138 "Globals.md", 139 "Quadrature.md", 140] 141``` 142 143### C interface 144```@contents 145Pages = ["C.md"] 146``` 147