Skip to content

Commit 7aa2928

Browse files
Add a function to optimize FK tables in the C-API
1 parent 8593c86 commit 7aa2928

4 files changed

Lines changed: 30 additions & 0 deletions

File tree

examples/cpp/evolve-grid.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -276,8 +276,13 @@ int main() {
276276
// Print the results
277277
print_results(dxsec_grid, dxsec_fktable);
278278

279+
// write the unoptimised FK table into disk
279280
pineappl_grid_write(fktable, "evolved-grid.pineappl.lz4");
280281

282+
// optimise the FK table and then write into disk
283+
pineappl_fktable* fktable_opt = pineappl_fktable_optimize(fktable, PINEAPPL_FK_ASSUMPTIONS_NF3_SYM);
284+
pineappl_grid_write(fktable_opt, "evolved-grid-optimised.pineappl.lz4");
285+
281286
pineappl_grid_delete(grid);
282287
pineappl_grid_delete(fktable);
283288
}

pineappl/src/fk_table.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ pub struct FkTable {
3131
/// tables are typically stored at very small `Q2 = Q0`, the PDFs `f(x,Q0)` of heavy quarks are
3232
/// typically set to zero at this scale or set to the same value as their anti-quark PDF. This is
3333
/// used to optimize the size of FK tables.
34+
#[repr(C)]
3435
#[derive(Debug, Clone, Copy, Eq, PartialEq)]
3536
pub enum FkAssumptions {
3637
/// All quark PDFs are non-zero at the FK table scale and completely independent.

pineappl_capi/cbindgen.toml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,8 @@ rename_variants = "ScreamingSnakeCase"
3838
"Channels" = "pineappl_channels"
3939
"Conv" = "pineappl_conv"
4040
"ConvType" = "pineappl_conv_type"
41+
"FkAssumptions" = "pineappl_fk_assumptions"
42+
"FkTable" = "pineappl_fktable"
4143
"Grid" = "pineappl_grid"
4244
"GridOptFlags" = "pineappl_gof"
4345
"Interp" = "pineappl_interp"

pineappl_capi/src/lib.rs

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@ use ndarray::{Array4, CowArray, Ix4};
6060
use pineappl::boc::{Bin, BinsWithFillLimits, Channel, Kinematics, Order, ScaleFuncForm, Scales};
6161
use pineappl::convolutions::{Conv, ConvType, ConvolutionCache};
6262
use pineappl::evolution::{AlphasTable, OperatorSliceInfo};
63+
use pineappl::fk_table::{FkAssumptions, FkTable};
6364
use pineappl::grid::{Grid, GridOptFlags};
6465
use pineappl::interpolation::{Interp as InterpMain, InterpMeth, Map, ReweightMeth};
6566
use pineappl::packed_array::ravel_multi_index;
@@ -2273,3 +2274,24 @@ pub unsafe extern "C" fn pineappl_grid_evolve(
22732274

22742275
Box::new(fk_table.unwrap().into_grid())
22752276
}
2277+
2278+
/// Optimize the size of this FK-table by removing heavy quark flavors assumed to be zero.
2279+
///
2280+
/// # Safety
2281+
///
2282+
/// If `grid` does not point to a valid `Grid` object, for example when `grid` is the null pointer,
2283+
/// this function is not safe to call.
2284+
///
2285+
/// # Panics
2286+
///
2287+
/// This function panics if `grid` is not an FK table-like object.
2288+
#[no_mangle]
2289+
pub unsafe extern "C" fn pineappl_fktable_optimize(
2290+
grid: *mut Grid,
2291+
assumptions: FkAssumptions,
2292+
) -> Box<FkTable> {
2293+
let grid = unsafe { &mut *grid };
2294+
let mut fktable = FkTable::try_from(grid.clone()).unwrap();
2295+
fktable.optimize(assumptions);
2296+
Box::new(fktable)
2297+
}

0 commit comments

Comments
 (0)