diff --git a/LibTrixi.jl/src/LibTrixi.jl b/LibTrixi.jl/src/LibTrixi.jl index f2f9bcde..499ea49b 100644 --- a/LibTrixi.jl/src/LibTrixi.jl +++ b/LibTrixi.jl/src/LibTrixi.jl @@ -82,6 +82,12 @@ export trixi_version_julia_extended, export trixi_get_t8code_forest, trixi_get_t8code_forest_cfptr, trixi_get_t8code_forest_jl +export trixi_get_p4est_mesh, + trixi_get_p4est_mesh_cfptr, + trixi_get_p4est_mesh_jl +export trixi_get_p8est_mesh, + trixi_get_p8est_mesh_cfptr, + trixi_get_p8est_mesh_jl export trixi_eval_julia, trixi_eval_julia_cfptr, trixi_eval_julia_jl diff --git a/LibTrixi.jl/src/api_c.jl b/LibTrixi.jl/src/api_c.jl index 6b729d82..e3dc1bfe 100644 --- a/LibTrixi.jl/src/api_c.jl +++ b/LibTrixi.jl/src/api_c.jl @@ -539,7 +539,7 @@ trixi_load_element_averaged_primitive_vars_cfptr() = """ - trixi_get_t8code_forest(simstate_handle::Cint)::::Ptr{Trixi.t8_forest} + trixi_get_t8code_forest(simstate_handle::Cint)::Ptr{Trixi.t8_forest} Return t8code forest of the current T8codeMesh. @@ -557,6 +557,46 @@ end trixi_get_t8code_forest_cfptr() = @cfunction(trixi_get_t8code_forest, Ptr{Trixi.t8_forest}, (Cint,)) + +""" + trixi_get_p4est_mesh(simstate_handle::Cint)::Ptr{Trixi.p4est_t} + +Return pointer to p4est data structure of the current P4estMesh (2D). + +!!! warning "Experimental" + The interface to p4est is experimental and implementation details may change at any + time without warning. +""" +function trixi_get_p4est_mesh end + +Base.@ccallable function trixi_get_p4est_mesh(simstate_handle::Cint)::Ptr{Trixi.p4est_t} + simstate = load_simstate(simstate_handle) + return trixi_get_p4est_mesh_jl(simstate) +end + +trixi_get_p4est_mesh_cfptr() = @cfunction(trixi_get_p4est_mesh, Ptr{Trixi.p4est_t}, (Cint,)) + + +""" + trixi_get_p8est_mesh(simstate_handle::Cint)::Ptr{Trixi.p8est_t} + +Return pointer to the p8est data structure of the current P4estMesh (3D). + +Note: In Trixi.jl, the mesh type is `P4estMesh` no matter whether it is a 2D or 3D mesh. + +!!! warning "Experimental" + The interface to p4est is experimental and implementation details may change at any + time without warning. +""" +function trixi_get_p8est_mesh end + +Base.@ccallable function trixi_get_p8est_mesh(simstate_handle::Cint)::Ptr{Trixi.p8est_t} + simstate = load_simstate(simstate_handle) + return trixi_get_p8est_mesh_jl(simstate) +end + +trixi_get_p8est_mesh_cfptr() = @cfunction(trixi_get_p8est_mesh, Ptr{Trixi.p8est_t}, (Cint,)) + ############################################################################################ # Auxiliary ############################################################################################ diff --git a/LibTrixi.jl/src/api_jl.jl b/LibTrixi.jl/src/api_jl.jl index 5d728425..045d2025 100644 --- a/LibTrixi.jl/src/api_jl.jl +++ b/LibTrixi.jl/src/api_jl.jl @@ -218,6 +218,18 @@ function trixi_get_t8code_forest_jl(simstate) return mesh.forest end + +function trixi_get_p4est_mesh_jl(simstate) + mesh, _, _, _ = Trixi.mesh_equations_solver_cache(simstate.semi) + return mesh.p4est +end + + +function trixi_get_p8est_mesh_jl(simstate) + mesh, _, _, _ = Trixi.mesh_equations_solver_cache(simstate.semi) + return mesh.p8est +end + ############################################################################################ # Auxiliary ############################################################################################ diff --git a/src/api.c b/src/api.c index da2b17d2..699e184b 100644 --- a/src/api.c +++ b/src/api.c @@ -753,7 +753,7 @@ double trixi_get_simulation_time(int handle) { /** Get t8code forest * - * For Trixi simulations on t8code meshes, the t8code forest is returned. + * For Trixi.jl simulations on t8code meshes, the t8code forest is returned. * * \param[in] handle simulation handle * @@ -774,6 +774,54 @@ t8_forest_t trixi_get_t8code_forest(int handle) { +/******************************************************************************************/ +/* P4est */ +/******************************************************************************************/ + +/** Get p4est mesh (2D) + * + * For Trixi.jl simulations using P4estMesh in 2D, the p4est data structure is returned. + * + * \param[in] handle simulation handle + * + * \warning The interface to p4est is experimental and implementation details may change + * at any time without warning. + * + * \return Pointer to `p4est` data structure + */ +p4est_t* trixi_get_p4est_mesh(int handle) { + + // Get function pointer + p4est_t* (*get_p4est_mesh)(int) = trixi_function_pointers[TRIXI_FTPR_GET_P4EST_MESH]; + + // Call function + return get_p4est_mesh(handle); +} + + + +/** Get p8est mesh (3D) + * + * For Trixi.jl simulations using P4estMesh in 3D, the p8est data structure is returned. + * + * \param[in] handle simulation handle + * + * \warning The interface to p4est is experimental and implementation details may change + * at any time without warning. + * + * \return Pointer to `p8est` data structure + */ +p8est_t* trixi_get_p8est_mesh(int handle) { + + // Get function pointer + p8est_t* (*get_p8est_mesh)(int) = trixi_function_pointers[TRIXI_FTPR_GET_P8EST_MESH]; + + // Call function + return get_p8est_mesh(handle); +} + + + /******************************************************************************************/ /* Misc */ /******************************************************************************************/