-
Notifications
You must be signed in to change notification settings - Fork 36
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add global Celeritas input definition (#1562)
* 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
Showing
68 changed files
with
2,674 additions
and
61 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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. | ||
|
@@ -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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.