Skip to content

Commit

Permalink
add getter for number of dofs
Browse files Browse the repository at this point in the history
  • Loading branch information
benegee committed Feb 22, 2024
1 parent 6da77a8 commit d5ecc49
Show file tree
Hide file tree
Showing 6 changed files with 124 additions and 2 deletions.
10 changes: 8 additions & 2 deletions LibTrixi.jl/src/LibTrixi.jl
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ module LibTrixi

using OrdinaryDiffEq: OrdinaryDiffEq, step!, check_error, DiscreteCallback
using Trixi: Trixi, summary_callback, mesh_equations_solver_cache, nelements,
nelementsglobal, nvariables, nnodes, wrap_array, eachelement, cons2prim,
get_node_vars, eachnode
nelementsglobal, ndofs, ndofsglobal, nvariables, nnodes, wrap_array,
eachelement, cons2prim, get_node_vars, eachnode
using MPI: MPI, run_init_hooks, set_default_error_handler_return
using Pkg

Expand Down Expand Up @@ -31,6 +31,12 @@ export trixi_nelements,
export trixi_nelements_global,
trixi_nelements_global_cfptr,
trixi_nelements_global_jl
export trixi_ndofs,
trixi_ndofs_cfptr,
trixi_ndofs_jl
export trixi_ndofs_global,
trixi_ndofs_global_cfptr,
trixi_ndofs_global_jl
export trixi_nvariables,
trixi_nvariables_cfptr,
trixi_nvariables_jl
Expand Down
30 changes: 30 additions & 0 deletions LibTrixi.jl/src/api_c.jl
Original file line number Diff line number Diff line change
Expand Up @@ -312,6 +312,36 @@ end
trixi_nelements_global_cfptr() = @cfunction(trixi_nelements_global, Cint, (Cint,))


"""
trixi_ndofs(simstate_handle::Cint)::Cint
Return number of degrees of freedom (all quadrature points on all cells of current rank).
"""
function trixi_ndofs end

Base.@ccallable function trixi_ndofs(simstate_handle::Cint)::Cint
simstate = load_simstate(simstate_handle)
return trixi_ndofs_jl(simstate)
end

trixi_ndofs_cfptr() = @cfunction(trixi_ndofs, Cint, (Cint,))


"""
trixi_ndofs_global(simstate_handle::Cint)::Cint
Return number of global eldegrees of freedom (all quadrature points on all cells).
"""
function trixi_ndofs_global end

Base.@ccallable function trixi_ndofs_global(simstate_handle::Cint)::Cint
simstate = load_simstate(simstate_handle)
return trixi_ndofs_global_jl(simstate)
end

trixi_ndofs_global_cfptr() = @cfunction(trixi_ndofs_global, Cint, (Cint,))


"""
trixi_nvariables(simstate_handle::Cint)::Cint
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 @@ -82,6 +82,18 @@ function trixi_nelements_global_jl(simstate)
end


function trixi_ndofs_jl(simstate)
mesh, _, solver, cache = mesh_equations_solver_cache(simstate.semi)
return ndofs(mesh, solver, cache)
end


function trixi_ndofs_global_jl(simstate)
mesh, _, solver, cache = mesh_equations_solver_cache(simstate.semi)
return ndofsglobal(mesh, solver, cache)
end


function trixi_nvariables_jl(simstate)
_, equations, _, _ = mesh_equations_solver_cache(simstate.semi)
return nvariables(equations)
Expand Down
46 changes: 46 additions & 0 deletions src/api.c
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ enum {
TRIXI_FTPR_NDIMS,
TRIXI_FPTR_NELEMENTS,
TRIXI_FPTR_NELEMENTS_GLOBAL,
TRIXI_FPTR_NDOFS,
TRIXI_FPTR_NDOFS_GLOBAL,
TRIXI_FTPR_NVARIABLES,
TRIXI_FTPR_LOAD_CELL_AVERAGES,
TRIXI_FTPR_VERSION_LIBRARY,
Expand Down Expand Up @@ -44,6 +46,8 @@ static const char* trixi_function_pointer_names[] = {
[TRIXI_FTPR_NDIMS] = "trixi_ndims_cfptr",
[TRIXI_FPTR_NELEMENTS] = "trixi_nelements_cfptr",
[TRIXI_FPTR_NELEMENTS_GLOBAL] = "trixi_nelements_global_cfptr",
[TRIXI_FPTR_NDOFS] = "trixi_ndofs_cfptr",
[TRIXI_FPTR_NDOFS_GLOBAL] = "trixi_ndofs_global_cfptr",
[TRIXI_FTPR_NVARIABLES] = "trixi_nvariables_cfptr",
[TRIXI_FTPR_LOAD_CELL_AVERAGES] = "trixi_load_cell_averages_cfptr",
[TRIXI_FTPR_VERSION_LIBRARY] = "trixi_version_library_cfptr",
Expand Down Expand Up @@ -488,6 +492,48 @@ int trixi_nelements_global(int handle) {
}


/**
* @anchor trixi_ndofs_api_c
*
* @brief Return number of local degrees of freedom.
*
* These usually differ from the global count when doing parallel computations.
*
* @param[in] handle simulation handle
*
* @see trixi_ndofs_global_api_c
*/
int trixi_ndofs(int handle) {

// Get function pointer
int (*ndofs)(int) = trixi_function_pointers[TRIXI_FPTR_NDOFS];

// Call function
return ndofs(handle);
}


/**
* @anchor trixi_ndofs_global_api_c
*
* @brief Return number of global degrees of freedom.
*
* These usually differ from the local count when doing parallel computations.
*
* @param[in] handle simulation handle
*
* @see trixi_ndofs_api_c
*/
int trixi_ndofs_global(int handle) {

// Get function pointer
int (*ndofs_global)(int) = trixi_function_pointers[TRIXI_FPTR_NDOFS_GLOBAL];

// Call function
return ndofs_global(handle);
}


/**
* @anchor trixi_nvariables_api_c
*
Expand Down
26 changes: 26 additions & 0 deletions src/api.f90
Original file line number Diff line number Diff line change
Expand Up @@ -271,6 +271,32 @@ integer(c_int) function trixi_nelements_global(handle) bind(c)
integer(c_int), value, intent(in) :: handle
end function

!>
!! @fn LibTrixi::trixi_ndofs::trixi_ndofs(handle)
!!
!! @brief Return number of local degrees of freedom
!!
!! @param[in] handle simulation handle
!!
!! @see @ref trixi_ndofs_api_c "trixi_ndofs (C API)"
integer(c_int) function trixi_ndofs(handle) bind(c)
use, intrinsic :: iso_c_binding, only: c_int
integer(c_int), value, intent(in) :: handle
end function

!>
!! @fn LibTrixi::trixi_ndofs_global::trixi_ndofs_global(handle)
!!
!! @brief Return number of global degrees of freedom
!!
!! @param[in] handle simulation handle
!!
!! @see @ref trixi_ndofs_global_api_c "trixi_ndofs_global (C API)"
integer(c_int) function trixi_ndofs_global(handle) bind(c)
use, intrinsic :: iso_c_binding, only: c_int
integer(c_int), value, intent(in) :: handle
end function

!>
!! @fn LibTrixi::trixi_nvariables::trixi_nvariables(handle)
!!
Expand Down
2 changes: 2 additions & 0 deletions src/trixi.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@ void trixi_step(int handle);
int trixi_ndims(int handle);
int trixi_nelements(int handle);
int trixi_nelements_global(int handle);
int trixi_ndofs(int handle);
int trixi_ndofs_global(int handle);
int trixi_nvariables(int handle);
double trixi_calculate_dt(int handle);
void trixi_load_cell_averages(double * data, int handle);
Expand Down

0 comments on commit d5ecc49

Please sign in to comment.