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