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

Add global Celeritas input definition #1562

Draft
wants to merge 28 commits into
base: develop
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
b141f2f
WIP: add Celeritas input file definitions
sethrj Jan 5, 2025
f4c1541
Add `accel` conversion function
sethrj Jan 5, 2025
d5f0e3e
Minor to-do/fixes
sethrj Jan 5, 2025
326bf81
Move root step writer input to a separate file
sethrj Jan 6, 2025
3a988b1
Fix input conversion code
sethrj Jan 6, 2025
67d2a57
Initial API adapter
sethrj Jan 6, 2025
b5076ca
Fix run input adapter
sethrj Jan 6, 2025
24a6192
Initial PGO adapter
sethrj Jan 6, 2025
81ed43e
Second iteration
sethrj Jan 6, 2025
cf9e8e1
Third iteration
sethrj Jan 6, 2025
72786b3
Better than a bot
sethrj Jan 6, 2025
6ef4148
Old RunnerInput
sethrj Jan 6, 2025
af3e311
First attempt for run input
sethrj Jan 6, 2025
7b6cea1
Second attempt for run input
sethrj Jan 6, 2025
c450af1
Fixes and updates
sethrj Jan 6, 2025
5ba26c0
Fix build errors
sethrj Jan 6, 2025
6a6cc80
Merge remote-tracking branch 'upstream/develop' into celer-inp
sethrj Jan 6, 2025
9b4e510
Fix windows failure
sethrj Jan 7, 2025
cd46d68
WIP: physics parameters
sethrj Jan 7, 2025
a8f9035
Add comments
sethrj Jan 8, 2025
9b09dbe
Merge remote-tracking branch 'upstream/develop' into celer-inp
sethrj Jan 8, 2025
912f700
Sketch out additional physics and such
sethrj Jan 9, 2025
c667bf0
Sketch out import
sethrj Jan 11, 2025
d0a927c
Update runner input
sethrj Jan 11, 2025
8eaae78
Generate framework input from SetupOptions
sethrj Jan 11, 2025
69b9ae0
Complete building of input parameters
sethrj Jan 12, 2025
8a4fa91
Merge remote-tracking branch 'upstream/develop' into celer-inp
sethrj Jan 12, 2025
c1c852f
Fix typo
sethrj Jan 12, 2025
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
203 changes: 203 additions & 0 deletions app/celer-g4/RunInput.cc
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,173 @@
//---------------------------------------------------------------------------//
#include "RunInput.hh"

#include <fstream>

#include "corecel/Config.hh"

#include "corecel/io/EnumStringMapper.hh"
#include "corecel/io/Logger.hh"
#include "corecel/math/ArrayUtils.hh"
#include "celeritas/inp/StandaloneInput.hh"
#include "celeritas/phys/PrimaryGeneratorOptions.hh"
#include "accel/SharedParams.hh"

namespace celeritas
{
namespace app
{
namespace
{
//---------------------------------------------------------------------------//
inp::System load_system(RunInput const& ri)
{
inp::System s;

if (celeritas::Device::num_devices())
{
inp::Device d;
d.stack_size = ri.cuda_stack_size;
d.heap_size = ri.cuda_heap_size;
s.device = std::move(d);
}

s.environ = {ri.environ.begin(), ri.environ.end()};

return s;
}

//---------------------------------------------------------------------------//
inp::Problem load_problem(RunInput const& ri)
{
inp::Problem p;

// Model definition
p.model.geometry_file = ri.geometry_file;

// Tuning
{
inp::StateCapacity capacity;
capacity.tracks = ri.num_track_slots;
capacity.initializers = ri.initializer_capacity;
capacity.secondaries = static_cast<size_type>(ri.secondary_stack_factor
* ri.num_track_slots);
capacity.primaries = ri.auto_flush;
p.tuning.capacity = std::move(capacity);
}

if (celeritas::Device::num_devices())
{
inp::DeviceDebug dd;
dd.default_stream = ri.default_stream;
dd.sync_stream = ri.action_times;
p.tuning.device_debug = std::move(dd);
}

if (ri.track_order != TrackOrder::size_)
{
p.tuning.track_order = ri.track_order;
}

{
inp::TrackingLimits limits;
limits.steps = ri.max_steps;
p.tracking.limits = std::move(limits);
}

// Field setup
if (ri.field_type == "rzmap")
{
CELER_LOG_LOCAL(info) << "Loading RZMapField from " << ri.field_file;
std::ifstream inp(ri.field_file);
CELER_VALIDATE(inp,
<< "failed to open field map file at '" << ri.field_file
<< "'");

// Read RZ map from file
RZMapFieldInput rzmap;
inp >> rzmap;

// Replace driver options with user options
rzmap.driver_options = ri.field_options;

p.field = std::move(rzmap);
}
else if (ri.field_type == "uniform")
{
inp::UniformField field;
field.strength = ri.field;

auto field_val = norm(field.strength);
if (field_val > 0)
{
CELER_LOG_LOCAL(info)
<< "Using a uniform field " << field_val << " [T]";
field.driver_options = ri.field_options;
p.field = std::move(field);
}
}
else
{
CELER_VALIDATE(false,
<< "invalid field type '" << ri.field_type << "'");
}

if (ri.sd_type != SensitiveDetectorType::none)
{
// Activate Geant4 SD callbacks
p.scoring.sd.emplace();
}

{
// Diagnostics
auto& d = p.diagnostics;
d.output_file = ri.output_file;
d.export_files.physics = ri.physics_output_file;
d.export_files.offload = ri.offload_output_file;
d.timers.action = ri.action_times;

if (!ri.slot_diagnostic_prefix.empty())
{
inp::SlotDiagnostic slot_diag;
slot_diag.basename = ri.slot_diagnostic_prefix;
d.slot = std::move(slot_diag);
}

if (ri.step_diagnostic)
{
inp::StepDiagnostic step;
step.bins = ri.step_diagnostic_bins;
d.step = std::move(step);
}
}

CELER_VALIDATE(ri.macro_file.empty(),
<< "macro file is no longer supported");

return p;
}

//---------------------------------------------------------------------------//
inp::Events load_events(RunInput const& ri)
{
CELER_VALIDATE(ri.event_file.empty() != !ri.primary_options,
<< "either a event filename or options to generate "
"primaries must be provided (but not both)");

if (!ri.event_file.empty())
{
inp::ReadFileEvents rfe;
rfe.event_file = ri.event_file;
return rfe;
}

CELER_ASSERT(ri.primary_options);
return to_input(ri.primary_options);
}

//---------------------------------------------------------------------------//
} // namespace

//---------------------------------------------------------------------------//
/*!
* Get a string corresponding to the physics list selection.
Expand Down Expand Up @@ -57,6 +217,49 @@ RunInput::operator bool() const
&& (step_diagnostic_bins > 0 || !step_diagnostic);
}

//---------------------------------------------------------------------------//
/*!
* Convert to standalone input format.
*/
inp::StandaloneInput to_input(RunInput const& ri)
{
inp::StandaloneInput si;

si.system = load_system(ri);
si.problem = load_problem(ri);

// Set up Geant4
if (ri.physics_list == PhysicsListSelection::celer_ftfp_bert)
{
// Build hadronic physics
std::get<inp::Problem>(si.problem).physics.hadronic.emplace();
}
else
{
CELER_VALIDATE(ri.physics_list == PhysicsListSelection::celer_em,
<< "invalid physics list selection '"
<< to_cstring(ri.physics_list) << "' (must be 'celer')");
}

si.geant_setup = ri.physics_options;

inp::GeantImport geant_import;
geant_import.ignore_processes.push_back("CoulombScat");
if (CELERITAS_GEANT4_VERSION >= 0x0b0100)
{
CELER_LOG(warning) << "Default Rayleigh scattering 'MinKinEnergyPrim' "
"is not compatible between Celeritas and "
"[email protected]: disabling Rayleigh scattering";
geant_import.ignore_processes.push_back("Rayl");
}
si.physics_import = std::move(geant_import);

si.geant_data = inp::GeantDataImport{};
si.events = load_events(ri);

return si;
}

//---------------------------------------------------------------------------//
} // namespace app
} // namespace celeritas
26 changes: 17 additions & 9 deletions app/celer-g4/RunInput.hh
Original file line number Diff line number Diff line change
Expand Up @@ -25,18 +25,14 @@

namespace celeritas
{
namespace app
{
//---------------------------------------------------------------------------//
//! Physics list selection
enum class PhysicsListSelection
namespace inp
{
ftfp_bert,
celer_ftfp_bert, //!< FTFP BERT with Celeritas EM standard physics
celer_em, //!< Celeritas EM standard physics only
size_,
};
struct StandaloneInput;
}

namespace app
{
//---------------------------------------------------------------------------//
//! Sensitive detector capability
enum class SensitiveDetectorType
Expand All @@ -47,6 +43,16 @@ enum class SensitiveDetectorType
size_,
};

//---------------------------------------------------------------------------//
//! Physics list selection (TODO: remove)
enum class PhysicsListSelection
{
ftfp_bert,
celer_ftfp_bert, //!< FTFP BERT with Celeritas EM standard physics
celer_em, //!< Celeritas EM standard physics only
size_,
};

//---------------------------------------------------------------------------//
/*!
* Input for a single run.
Expand Down Expand Up @@ -121,6 +127,8 @@ struct RunInput
char const* to_cstring(PhysicsListSelection value);
char const* to_cstring(SensitiveDetectorType value);

inp::StandaloneInput to_input(RunInput const& run_input);

//---------------------------------------------------------------------------//
} // namespace app
} // namespace celeritas
1 change: 1 addition & 0 deletions app/celer-sim/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ set(SOURCES
celer-sim.cc
Runner.cc
RunnerOutput.cc
RunnerInput.cc
RunnerInputIO.json.cc
Transporter.cc
)
Expand Down
Loading
Loading