Skip to content

Reuse A Compiled Runtime

Compilation can prepare geometry, bind observable responses and process or bind large physics tables. Do it once when those parts of the problem stay fixed.

Compile With The Declared Source Domain

cpp
SimulationSourceDefinition compile_source{
    .kind = SimulationSourceKind::independent,
    .independent = make_source(maximum_energy_ev),
};

GeometryHandle geometry_handle =
    hold_geometry(geometry, GeometryConcurrency::concurrent_safe);

SimulationModel model{
    .geometry = geometry_handle,
    .materials = materials,
    .observables = observables,
    .packages = packages,
    .source = compile_source,
    .run = SimulationRunSettings{.histories = 10000},
};

SimulationRuntimeBundle runtime =
    compile_simulation_model(std::move(model));

The source stored in SimulationModel lets compilation infer reachable particles and source-energy bounds. For an energy sweep, compile with a source definition whose support covers the complete sweep. A missing model source is allowed for advanced runtime construction, but reachability is then unknown and source-dependent package checks cannot be as specific.

Build A Compatible Source Batch

cpp
SimulationSourceDefinition source{
    .kind = SimulationSourceKind::independent,
    .independent = make_source(1.0e6),
};

SimulationSourceBatch batch =
    make_simulation_source_batch(std::move(source), geometry_handle);

Pass the geometry-aware overload when a general source restricts sampling to physical regions.

Run Several Conditions

cpp
for (Real energy_ev : energies_ev) {
  SimulationSourceDefinition run_source{
      .kind = SimulationSourceKind::independent,
      .independent = make_source(energy_ev),
  };

  SimulationTransportSessionResult result =
      run_simulation_runtime_bundle(
          runtime,
          make_simulation_source_batch(
              std::move(run_source), geometry_handle),
          SimulationRunSettings{
              .histories = 10000,
              .worker_threads = 4,
          });

  const SimulationObservableRow &dose =
      require_simulation_observable_row(
          result,
          TransportPackageId::coupled_em,
          "energy_deposit_dose",
          "total",
          ObservableId{1});
  std::cout << energy_ev << ',' << dose.value << ','
            << dose.standard_error << '\n';
}

The runtime can also be called through runtime.run(batch, settings).

What May Change

Between runs you may change:

  • the sampled source batch within the particle and energy domain compiled into the runtime;
  • history count;
  • worker-thread count;
  • logical history shards;
  • fission generation settings when the compiled model supports that path.

Recompile when geometry, materials, physics data, transport policies, observables or required capability assumptions change.

Reproducibility

Source and package seeds are part of the model. worker_threads controls execution, while logical history identity and canonical shard reduction are reported in SimulationExecutionSummary. Compare results using observable values and uncertainty; do not assume equal wall-clock scheduling implies equal random streams.

NeoMC user documentation.