Skip to content

Commit

Permalink
Physics tabulation notifier
Browse files Browse the repository at this point in the history
  • Loading branch information
niess committed Sep 2, 2024
1 parent 529976e commit 211ca81
Show file tree
Hide file tree
Showing 6 changed files with 210 additions and 62 deletions.
3 changes: 2 additions & 1 deletion examples/pumas/dump.c
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,8 @@ int main(int argc, char * argv[])

/* Compute the material's physics data */
struct pumas_physics * physics;
pumas_physics_create(&physics, PUMAS_PARTICLE_MUON, mdf, dedx, NULL);
pumas_physics_create(
&physics, PUMAS_PARTICLE_MUON, mdf, dedx, NULL, NULL);

/* Dump the physics data for subsequent usage */
FILE * stream = fopen(dump, "wb");
Expand Down
4 changes: 2 additions & 2 deletions examples/pumas/loader.c
Original file line number Diff line number Diff line change
Expand Up @@ -63,8 +63,8 @@ static enum pumas_return load_pumas_materials(struct pumas_physics ** physics,

/* If no binary dump, initialise from the MDF and dump */
enum pumas_return rc;
if ((rc = pumas_physics_create(physics, particle, mdf, dedx, NULL)) !=
PUMAS_RETURN_SUCCESS)
if ((rc = pumas_physics_create(
physics, particle, mdf, dedx, NULL, NULL)) != PUMAS_RETURN_SUCCESS)
return rc;

/* Dump the library configuration */
Expand Down
2 changes: 1 addition & 1 deletion examples/pumas/straight.c
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ int main(int narg, char * argv[])
* can a few seconds, depending on the number of materials in the MDF.
*/
pumas_physics_create(&physics, PUMAS_PARTICLE_MUON,
"examples/data/materials.xml", NULL, NULL);
"examples/data/materials.xml", NULL, NULL, NULL);

/* Map the PUMAS material index */
pumas_physics_material_index(physics, MATERIAL_NAME, &medium.material);
Expand Down
2 changes: 1 addition & 1 deletion examples/pumas/tabulate.c
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ int main(int argc, char * argv[])
struct pumas_physics * physics;
struct pumas_physics_settings settings = { .dry = 1, .update = 1};
pumas_physics_create(
&physics, PUMAS_PARTICLE_MUON, mdf, dedx, &settings);
&physics, PUMAS_PARTICLE_MUON, mdf, dedx, &settings, NULL);

/* Exit to the OS */
exit(EXIT_SUCCESS);
Expand Down
24 changes: 23 additions & 1 deletion include/pumas.h
Original file line number Diff line number Diff line change
Expand Up @@ -191,6 +191,8 @@ enum pumas_return {
PUMAS_RETURN_UNKNOWN_PARTICLE,
/** Some input value is not valid. */
PUMAS_RETURN_VALUE_ERROR,
/** An external interrupt was caught. */
PUMAS_RETURN_INTERRUPT,
/** The number of PUMAS return codes. */
PUMAS_N_RETURNS
};
Expand Down Expand Up @@ -814,6 +816,25 @@ struct pumas_physics_settings {
int dry;
};

/**
* Notifier interface for monitoring physics tabulation.
*
* The notifier callback functions must return one of `PUMAS_RETURN_SUCCESS` or
* `PUMAS_RETURN_INTERRUPT` (if physics computation shall be aborted).
*
* **Note** that this object might be overloaded by users, since it only defines
* an interface.
*/
struct pumas_physics_notifier {
/** Configuration callback. */
enum pumas_return (*configure)(
struct pumas_physics_notifier * self, const char * title, int steps);

/** Notification callback. */
enum pumas_return (*notify)(
struct pumas_physics_notifier * self);
};

/**
* Create physics tables.
*
Expand Down Expand Up @@ -898,7 +919,8 @@ struct pumas_physics_settings {
PUMAS_API enum pumas_return pumas_physics_create(
struct pumas_physics ** physics, enum pumas_particle particle,
const char * mdf_path, const char * dedx_path,
const struct pumas_physics_settings * settings);
const struct pumas_physics_settings * settings,
struct pumas_physics_notifier * notifier);

/**
* Destroy a physics instance.
Expand Down
Loading

0 comments on commit 211ca81

Please sign in to comment.