Skip to content

Commit

Permalink
Add global Celeritas input definition (#1562)
Browse files Browse the repository at this point in the history
* Add Celeritas input file definitions
* Add `accel` conversion function
* Move root step writer input to a separate file
* Initial API adapter
* Fix run input adapter
* Initial PGO adapter
* Sketch out additional physics and such
* Sketch out import
* Update runner input
* Generate framework input from SetupOptions
* Complete building of input parameters
* Rename environ to avoid windows errors
  • Loading branch information
sethrj authored Jan 24, 2025
1 parent d1498bb commit 85601c2
Show file tree
Hide file tree
Showing 68 changed files with 2,674 additions and 61 deletions.
3 changes: 1 addition & 2 deletions .github/workflows/build-docker.yml
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ jobs:
. /etc/profile
echo "/opt/view/bin" >> $GITHUB_PATH
echo "CMAKE_PREFIX_PATH=${CMAKE_PREFIX_PATH}" >> $GITHUB_ENV
# NOTE: checkout must occur *after* setting up environment to use the right Git version
# NOTE: checkout must occur *after* setting up environment for git tags to work
# NOTE: depth must be enough to include the previous tag
- name: Check out Celeritas
uses: actions/checkout@v4
Expand All @@ -66,7 +66,6 @@ jobs:
- name: Configure Celeritas
run: |
git config --global --add safe.directory ${PWD}
git fetch --tags
ln -fs scripts/cmake-presets/ci-${{matrix.image}}.json CMakeUserPresets.json
cmake --preset=${CMAKE_PRESET}
- name: Build Celeritas
Expand Down
202 changes: 202 additions & 0 deletions app/celer-g4/RunInput.cc
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,172 @@
//---------------------------------------------------------------------------//
#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.environment = {ri.environ.begin(), ri.environ.end()};

return s;
}

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

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

// Control
p.control.capacity = [&ri] {
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;
return capacity;
}();

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

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

{
inp::TrackingLimits& limits = p.tracking.limits;
limits.steps = ri.max_steps;
}

// 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 +216,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

0 comments on commit 85601c2

Please sign in to comment.