Skip to content

Commit

Permalink
Propagate conventions to Fortran API (issues with examples not solved…
Browse files Browse the repository at this point in the history
… yet)
  • Loading branch information
Radonirinaunimi committed Nov 28, 2024
1 parent c057145 commit 5ba8af1
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 23 deletions.
10 changes: 5 additions & 5 deletions examples/fortran/lhapdf_example_v1.f90
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ program lhapdf_example
type(pineappl_kinematics) :: kinematics(3)
type(pineappl_interp_tuples) :: interpolations(3)

type (pineappl_xfx) :: xfx(2)
type (pineappl_alphas) :: alphas
type(pineappl_xfx) :: xfx(2)
type(pineappl_alphas) :: alphas

integer(kind(pineappl_reweight_meth)) :: q2_reweight
integer(kind(pineappl_reweight_meth)) :: x_reweight
Expand All @@ -22,8 +22,8 @@ program lhapdf_example

integer, target :: flags(2)

channels = pineappl_channel_new()
call pineappl_channel_add(channels, 3, 2, [0, 0, 1, -1, 2, -2], [1.0_dp, 1.0_dp, 1.0_dp])
channels = pineappl_channels_new()
call pineappl_channels_add(channels, 3, 2, [0, 0, 1, -1, 2, -2], [1.0_dp, 1.0_dp, 1.0_dp])

kinematics = [&
pineappl_kinematics(pineappl_scale, 0), &
Expand All @@ -42,7 +42,7 @@ program lhapdf_example
pineappl_interp_tuples(2e-7, 1.0, 50, 3, x_reweight, x_mapping, interpolation_meth) &
]

grid = pineappl_grid_new2(pineappl_pdg, channels, 1, [2_1, 0_1, 0_1, 0_1], 2, &
grid = pineappl_grid_new2(pineappl_pdg, channels, 1, [2_1, 0_1, 0_1, 0_1, 0_1], 2, &
[0.0_dp, 1.0_dp, 2.0_dp], 2, [pineappl_unpol_pdf, pineappl_unpol_pdf], [2212, 2212], kinematics, interpolations, [1, 1, 0])

call pineappl_grid_fill_all2(grid, 0, 0.5_dp, [100.0_dp, 0.5_dp, 0.5_dp], [0.5_dp, 0.5_dp, 0.5_dp])
Expand Down
20 changes: 10 additions & 10 deletions examples/fortran/pineappl.f90
Original file line number Diff line number Diff line change
Expand Up @@ -121,8 +121,8 @@ function strlen(s) bind(c, name="strlen")
integer (c_size_t) :: strlen
end function strlen

subroutine channel_add(lumi, combinations, nb_combinations, pdg_id_combinations, factors) &
bind(c, name = 'pineappl_channel_add')
subroutine channels_add(lumi, combinations, nb_combinations, pdg_id_combinations, factors) &
bind(c, name = 'pineappl_channels_add')

use iso_c_binding
type (c_ptr), value :: lumi
Expand All @@ -131,7 +131,7 @@ subroutine channel_add(lumi, combinations, nb_combinations, pdg_id_combinations,
real (c_double) :: factors(*)
end subroutine

type (c_ptr) function channel_new() bind(c, name = 'pineappl_channel_new')
type (c_ptr) function channels_new() bind(c, name = 'pineappl_channels_new')
use iso_c_binding
end function

Expand Down Expand Up @@ -481,7 +481,7 @@ subroutine lumi_entry(lumi, entry, pdg_ids, factors) bind(c, name = 'pineappl_lu
real (c_double) :: factors(*)
end subroutine

subroutine channel_entry(lumi, entry, pdg_ids, factors) bind(c, name = 'pineappl_channel_entry')
subroutine channels_entry(lumi, entry, pdg_ids, factors) bind(c, name = 'pineappl_channels_entry')
use iso_c_binding
type (c_ptr), value :: lumi
integer (c_size_t), value :: entry
Expand Down Expand Up @@ -524,10 +524,10 @@ function c_f_string(c_str) result(f_str)
end do
end function

type (pineappl_lumi) function pineappl_channel_new()
type (pineappl_lumi) function pineappl_channels_new()
implicit none

pineappl_channel_new = pineappl_lumi(channel_new())
pineappl_channels_new = pineappl_lumi(channels_new())
end function

integer function pineappl_grid_bin_count(grid)
Expand Down Expand Up @@ -1135,7 +1135,7 @@ subroutine pineappl_lumi_add(lumi, combinations, pdg_id_pairs, factors)
call lumi_add(lumi%ptr, int(combinations, c_size_t), pdg_id_pairs, factors)
end subroutine

subroutine pineappl_channel_add(channels, combinations, nb_combinations, pdg_id_combinations, factors)
subroutine pineappl_channels_add(channels, combinations, nb_combinations, pdg_id_combinations, factors)
use iso_c_binding

implicit none
Expand All @@ -1145,7 +1145,7 @@ subroutine pineappl_channel_add(channels, combinations, nb_combinations, pdg_id_
integer, dimension(2 * combinations), intent(in) :: pdg_id_combinations
real (dp), dimension(combinations), intent(in) :: factors

call channel_add(channels%ptr, int(combinations, c_size_t), int(nb_combinations, c_size_t), pdg_id_combinations, factors)
call channels_add(channels%ptr, int(combinations, c_size_t), int(nb_combinations, c_size_t), pdg_id_combinations, factors)
end subroutine

integer function pineappl_lumi_combinations(lumi, entry)
Expand Down Expand Up @@ -1190,7 +1190,7 @@ subroutine pineappl_lumi_entry(lumi, entry, pdg_ids, factors)
call lumi_entry(lumi%ptr, int(entry, c_size_t), pdg_ids, factors)
end subroutine

subroutine pineappl_channel_entry(lumi, entry, pdg_ids, factors)
subroutine pineappl_channels_entry(lumi, entry, pdg_ids, factors)
use iso_c_binding

implicit none
Expand All @@ -1200,7 +1200,7 @@ subroutine pineappl_channel_entry(lumi, entry, pdg_ids, factors)
integer, intent(out) :: pdg_ids(*)
real (dp), intent(out) :: factors(*)

call channel_entry(lumi%ptr, int(entry, c_size_t), pdg_ids, factors)
call channels_entry(lumi%ptr, int(entry, c_size_t), pdg_ids, factors)
end subroutine

type (pineappl_lumi) function pineappl_lumi_new()
Expand Down
4 changes: 2 additions & 2 deletions examples/fortran/test_v1.f90
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@ program test_pineappl
type (pineappl_xfx) :: xfx1, xfx2
type (pineappl_alphas) :: alphas

channels = pineappl_channel_new()
call pineappl_channel_add(channels, 3, 2, [0, 0, 1, -1, 2, -2], [1.0_dp, 1.0_dp, 1.0_dp])
channels = pineappl_channels_new()
call pineappl_channels_add(channels, 3, 2, [0, 0, 1, -1, 2, -2], [1.0_dp, 1.0_dp, 1.0_dp])

if (pineappl_lumi_count(channels) /= 1) then
write(*, *) "pineappl_lumi_count(): ", pineappl_lumi_count(channels)
Expand Down
14 changes: 8 additions & 6 deletions pineappl_capi/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1396,19 +1396,21 @@ pub extern "C" fn pineappl_channels_new() -> Box<Lumi> {
/// # Safety
///
/// The parameter `lumi` must point to a valid `Lumi` object created by `pineappl_lumi_new`.
/// `pdg_id_combinations` must be an array with length `n_combinations * combinations`, and
/// `factors` with length of `combinations`.
/// `pdg_id_combinations` must be an array with length `nb_combinations * combinations`, and
/// `factors` with length of `combinations`. The `nb_convolutions` describe the number of
/// parton distributions involved, while `combinations` represent the number of different
/// channel combinations.
#[no_mangle]
pub unsafe extern "C" fn pineappl_channels_add(
channels: *mut Lumi,
combinations: usize,
nb_combinations: usize,
nb_convolutions: usize,
pdg_id_combinations: *const i32,
factors: *const f64,
) {
let channels = unsafe { &mut *channels };
let pdg_id_pairs =
unsafe { slice::from_raw_parts(pdg_id_combinations, nb_combinations * combinations) };
unsafe { slice::from_raw_parts(pdg_id_combinations, nb_convolutions * combinations) };
let factors = if factors.is_null() {
vec![1.0; combinations]
} else {
Expand All @@ -1417,9 +1419,9 @@ pub unsafe extern "C" fn pineappl_channels_add(

channels.0.push(Channel::new(
pdg_id_pairs
.chunks(nb_combinations)
.chunks(nb_convolutions)
.zip(factors)
.map(|x| ((0..nb_combinations).map(|i| x.0[i]).collect(), x.1))
.map(|x| ((0..nb_convolutions).map(|i| x.0[i]).collect(), x.1))
.collect(),
));
}
Expand Down

0 comments on commit 5ba8af1

Please sign in to comment.