Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[WIP] Add getter function for P4estMesh #126

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions LibTrixi.jl/src/LibTrixi.jl
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,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
Expand Down
42 changes: 41 additions & 1 deletion LibTrixi.jl/src/api_c.jl
Original file line number Diff line number Diff line change
Expand Up @@ -357,7 +357,7 @@ trixi_load_cell_averages_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.

Expand All @@ -375,6 +375,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
############################################################################################
Expand Down
12 changes: 12 additions & 0 deletions LibTrixi.jl/src/api_jl.jl
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,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
############################################################################################
Expand Down
50 changes: 49 additions & 1 deletion src/api.c
Original file line number Diff line number Diff line change
Expand Up @@ -537,7 +537,7 @@ void trixi_load_cell_averages(double * data, 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
*
Expand All @@ -558,6 +558,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 */
/******************************************************************************************/
Expand Down
Loading