16f5dc8baSWill Pazner# LibCEED.jl Docs 26f5dc8baSWill Pazner 36f5dc8baSWill PaznerDocumentation for the LibCEED.jl Julia interface to the 46f5dc8baSWill Pazner[libCEED](https://github.com/ceed/libceed) library. 56f5dc8baSWill Pazner 66f5dc8baSWill PaznerFor further information, see also the [libCEED 7*13964f07SJed Browndocumentation](https://libceed.org/). 86f5dc8baSWill Pazner 96f5dc8baSWill PaznerSeveral [short examples](Examples.md) are included to demonstrate the 106f5dc8baSWill Paznerfunctionality. 116f5dc8baSWill Pazner 126f5dc8baSWill Pazner### Installation 136f5dc8baSWill Pazner 146f5dc8baSWill PaznerThe LibCEED.jl package can be installed with Julia's package manager by running 156f5dc8baSWill Pazner`] add LibCEED`. This will automatically install a pre-built binary of the 166f5dc8baSWill PaznerlibCEED library. If you require features of a specific build of libCEED (e.g. 176f5dc8baSWill PaznerCUDA/GPU support, specific compiler flags, etc.) then you should compile your 186f5dc8baSWill Paznerown version of the libCEED library, and configure LibCEED.jl to use this binary 196f5dc8baSWill Pazneras described in the [Configuring LibCEED.jl](@ref) section. 206f5dc8baSWill Pazner 216f5dc8baSWill Pazner!!! warning "The pre-built libCEED binaries do not support CUDA backends" 226f5dc8baSWill Pazner The pre-built binaries automatically installed by LibCEED.jl (through the 236f5dc8baSWill Pazner [libCEED_jll](https://juliahub.com/ui/Packages/libCEED_jll/LB2fn) package) 246f5dc8baSWill Pazner are not built with CUDA support. If you want to run libCEED on the GPU, you 256f5dc8baSWill Pazner will have to build libCEED from source and configure LibCEED.jl as described 266f5dc8baSWill Pazner in the [Configuring LibCEED.jl](@ref) section. 276f5dc8baSWill Pazner 286f5dc8baSWill Pazner#### Configuring LibCEED.jl 296f5dc8baSWill Pazner 306f5dc8baSWill PaznerBy default, LibCEED.jl will use the pre-built libCEED binaries provided by the 316f5dc8baSWill Pazner[libCEED_jll](https://juliahub.com/ui/Packages/libCEED_jll/LB2fn) package. If 326f5dc8baSWill Pazneryou wish to use a different libCEED binary (e.g. one built from source), 33186a1480SWill PaznerLibCEED.jl can be configured using Julia's _preferences_ mechanism. Note that 34186a1480SWill Paznerthis preference will be set for the currently active Julia environemnt, and can 35186a1480SWill Paznerbe different between different environments. The Julia session must be restarted 36186a1480SWill Paznerfor changes to take effect. 376f5dc8baSWill Pazner 386f5dc8baSWill Pazner```julia 39186a1480SWill Paznerjulia> using LibCEED 40186a1480SWill Paznerjulia> set_libceed_path!("/path/to/libceed.so") 41186a1480SWill Pazner[ Info: Setting the libCEED library path to /path/to/libceed.so. 42186a1480SWill Pazner[ Info: Restart the Julia session for changes to take effect. 436f5dc8baSWill Pazner``` 446f5dc8baSWill Pazner 45186a1480SWill PaznerSee the [library configuration documentation](LibCEED.md) for more details. For 46186a1480SWill Paznerinformation on Julia's preferences system, see 47186a1480SWill Pazner[Preferences.jl](https://github.com/JuliaPackaging/Preferences.jl). 486f5dc8baSWill Pazner 496f5dc8baSWill Pazner### Features of the high-level interface for libCEED 506f5dc8baSWill Pazner 516f5dc8baSWill Pazner#### User Q-functions 526f5dc8baSWill Pazner 536f5dc8baSWill PaznerWith LibCEED.jl, it is much easier to write dimension-independent user-defined 546f5dc8baSWill PaznerQ-functions that automatically work on the GPU. See the [related 556f5dc8baSWill Paznerdocumentation](UserQFunctions.md) for more information. 566f5dc8baSWill Pazner 576f5dc8baSWill Pazner#### Safe access to CeedVector objects 586f5dc8baSWill Pazner 596f5dc8baSWill PaznerWhen accessing [`CeedVector`](@ref) objects, the C interface requires the user 606f5dc8baSWill Paznerto manually call `CeedVectorGetArray`, paired with `CeedVectorRestoreArray`. If 616f5dc8baSWill Paznerthe user wants read-only access, then the user must call 626f5dc8baSWill Pazner`CeedVectorGetArrayRead`, paired with `CeedVectorRestoreArrayRead`. This can 636f5dc8baSWill Paznerpossibly be bug-prone, because the user may forget to restore the array, or may 646f5dc8baSWill Paznermatch the `Read` version to get the array with non-`Read` version to restore the 656f5dc8baSWill Paznerarray (or vice versa). 666f5dc8baSWill Pazner 676f5dc8baSWill PaznerIn LibCEED.jl, this difficulty is mitigated using the [`witharray`](@ref) 686f5dc8baSWill Paznerfunction and [`@witharray`](@ref) macro. There are also read-only versions, 696f5dc8baSWill Pazner[`witharray_read`](@ref) and [`@witharray_read`](@ref). When using this 706f5dc8baSWill Paznerfunctionality, it is impossible to forget to restore the array, and the correct 716f5dc8baSWill Paznerversion is always paired properly. 726f5dc8baSWill Pazner 736f5dc8baSWill PaznerFor example, in `ex1-volume`, the following C code 746f5dc8baSWill Pazner```c 756f5dc8baSWill Pazner// Compute and print the sum of the entries of 'v' giving the mesh volume. 766f5dc8baSWill Paznerconst CeedScalar *v_host; 776f5dc8baSWill PaznerCeedVectorGetArrayRead(v, CEED_MEM_HOST, &v_host); 786f5dc8baSWill PaznerCeedScalar vol = 0.; 796f5dc8baSWill Paznerfor (CeedInt i = 0; i < sol_size; i++) { 806f5dc8baSWill Pazner vol += v_host[i]; 816f5dc8baSWill Pazner} 826f5dc8baSWill PaznerCeedVectorRestoreArrayRead(v, &v_host); 836f5dc8baSWill Pazner``` 846f5dc8baSWill Pazneris replaced with the following equivalent Julia code 856f5dc8baSWill Pazner```julia 866f5dc8baSWill Pazner# Compute and print the sum of the entries of 'v' giving the mesh volume. 876f5dc8baSWill Paznervol = witharray_read(sum, v, MEM_HOST) 886f5dc8baSWill Pazner``` 896f5dc8baSWill Pazner 906f5dc8baSWill PaznerIn `ex2-surface`, the following C code 916f5dc8baSWill Pazner```c 926f5dc8baSWill Pazner// Initialize 'u' with sum of coordinates, x+y+z. 936f5dc8baSWill PaznerCeedScalar *u_host; 946f5dc8baSWill Paznerconst CeedScalar *x_host; 956f5dc8baSWill PaznerCeedVectorGetArray(u, CEED_MEM_HOST, &u_host); 966f5dc8baSWill PaznerCeedVectorGetArrayRead(mesh_coords, CEED_MEM_HOST, &x_host); 976f5dc8baSWill Paznerfor (CeedInt i = 0; i < sol_size; i++) { 986f5dc8baSWill Pazner u_host[i] = 0; 996f5dc8baSWill Pazner for (CeedInt d = 0; d < dim; d++) 1006f5dc8baSWill Pazner u_host[i] += x_host[i+d*sol_size]; 1016f5dc8baSWill Pazner} 1026f5dc8baSWill PaznerCeedVectorRestoreArray(u, &u_host); 1036f5dc8baSWill PaznerCeedVectorRestoreArrayRead(mesh_coords, &x_host); 1046f5dc8baSWill Pazner``` 1056f5dc8baSWill Pazneris replaced with the following equivalent Julia code 1066f5dc8baSWill Pazner```julia 1076f5dc8baSWill Pazner@witharray_read(x_host=mesh_coords, size=(mesh_size÷dim, dim), 1086f5dc8baSWill Pazner @witharray(u_host=u, size=(sol_size,1), 1096f5dc8baSWill Pazner sum!(u_host, x_host))) 1106f5dc8baSWill Pazner``` 1116f5dc8baSWill PaznerThe macro version can provide better performance if a closure is required, and 1126f5dc8baSWill Paznerallow for convenient reshaping of the vector into equivalently sized matrices 1136f5dc8baSWill Pazneror tensors. 1146f5dc8baSWill Pazner 115186a1480SWill Pazner### Library configuration 116186a1480SWill Pazner```@contents 117186a1480SWill PaznerPages = [ 118186a1480SWill Pazner "LibCEED.md", 119186a1480SWill Pazner] 120186a1480SWill Pazner``` 121186a1480SWill Pazner 1226f5dc8baSWill Pazner### Ceed objects 1236f5dc8baSWill Pazner```@contents 1246f5dc8baSWill PaznerPages = [ 1256f5dc8baSWill Pazner "Ceed.md", 1266f5dc8baSWill Pazner "CeedVector.md", 1276f5dc8baSWill Pazner "ElemRestriction.md", 1286f5dc8baSWill Pazner "Basis.md", 1296f5dc8baSWill Pazner "QFunction.md", 1306f5dc8baSWill Pazner "Operator.md", 1316f5dc8baSWill Pazner] 1326f5dc8baSWill Pazner``` 1336f5dc8baSWill Pazner 1346f5dc8baSWill Pazner### Utilities 1356f5dc8baSWill Pazner```@contents 1366f5dc8baSWill PaznerPages = [ 1376f5dc8baSWill Pazner "Misc.md", 1386f5dc8baSWill Pazner "Globals.md", 1396f5dc8baSWill Pazner "Quadrature.md", 1406f5dc8baSWill Pazner] 1416f5dc8baSWill Pazner``` 1426f5dc8baSWill Pazner 1436f5dc8baSWill Pazner### C interface 1446f5dc8baSWill Pazner```@contents 1456f5dc8baSWill PaznerPages = ["C.md"] 1466f5dc8baSWill Pazner``` 147