![]() |
|
|||
File indexing completed on 2025-02-22 10:31:32
0001 //----------------------------------*-C++-*----------------------------------// 0002 // Copyright 2024 UT-Battelle, LLC, and other Celeritas developers. 0003 // See the top-level COPYRIGHT file for details. 0004 // SPDX-License-Identifier: (Apache-2.0 OR MIT) 0005 //---------------------------------------------------------------------------// 0006 //! \file celeritas/user/SlotDiagnostic.hh 0007 //---------------------------------------------------------------------------// 0008 #pragma once 0009 0010 #include <memory> 0011 #include <string> 0012 0013 #include "corecel/cont/Span.hh" 0014 #include "corecel/data/AuxInterface.hh" 0015 #include "celeritas/global/ActionInterface.hh" 0016 0017 namespace celeritas 0018 { 0019 //---------------------------------------------------------------------------// 0020 class AuxStateVec; 0021 class ParticleParams; 0022 0023 //---------------------------------------------------------------------------// 0024 /*! 0025 * Print diagnostic output about what's in what slots. 0026 * 0027 * Currently this only prints the particle ID as a function of track slot, 0028 * which can later be combined with postprocessing data to print the charge of 0029 * each particle. We could in the future extend the class to use thread ID 0030 * and/or write action ID or any other ID/status instead. Special IDs are: 0031 * - \c -1 : track slot is inactive 0032 * - \c -2 : track has been flagged as an error 0033 * 0034 * A "JSON lines" file (one line per step) is opened for each stream, and a 0035 * separate file is opened once during construction to write appropriate 0036 * metadata. 0037 * 0038 * The filename base is appended with the stream ID or \c metadata. If 0039 * the filename is a directory, that directory must already exist. 0040 * For example, you could pass a filename base of \c 0041 * slot-diag- to get filenames \c slot-diag-metadata.json, \c 0042 * slot-diag-0.jsonl, etc. 0043 * 0044 * \todo Instead of writing separate files, we should probably use a 0045 * multi-stream output manager (not yet implemented) to save the result for the 0046 * end. 0047 * 0048 * \note To plot the resulting files, see \c 0049 * scripts/user/plot-slot-diagnostic.py 0050 */ 0051 class SlotDiagnostic final : public CoreStepActionInterface, 0052 public AuxParamsInterface 0053 { 0054 public: 0055 // Construct and add to core params 0056 static std::shared_ptr<SlotDiagnostic> 0057 make_and_insert(CoreParams const& core, std::string filename_base); 0058 0059 // Construct with IDs and filename base 0060 SlotDiagnostic(ActionId action_id, 0061 AuxId aux_id, 0062 std::string filename_base, 0063 size_type num_stream, 0064 std::shared_ptr<ParticleParams const> particle); 0065 0066 //!@{ 0067 //! \name Metadata interface 0068 //! Label for the auxiliary data and action 0069 std::string_view label() const final { return sad_.label(); } 0070 // Description of the action 0071 std::string_view description() const final { return sad_.description(); } 0072 //!@} 0073 0074 //!@{ 0075 //! \name Step action interface 0076 //! Index of this class instance in its registry 0077 ActionId action_id() const final { return sad_.action_id(); } 0078 //! Index of this class instance in its registry 0079 StepActionOrder order() const final { return StepActionOrder::user_post; } 0080 // Execute the action with host data 0081 void step(CoreParams const& params, CoreStateHost& state) const final; 0082 // Execute the action with device data 0083 void step(CoreParams const& params, CoreStateDevice& state) const final; 0084 //!@} 0085 0086 //!@{ 0087 //! \name Aux params interface 0088 //! Index of this class instance in its registry 0089 AuxId aux_id() const final { return aux_id_; } 0090 // Build state data for a stream 0091 UPState create_state(MemSpace m, StreamId id, size_type size) const final; 0092 //!@} 0093 0094 private: 0095 struct State; 0096 0097 //// DATA //// 0098 0099 StaticActionData sad_; 0100 AuxId aux_id_; 0101 std::string filename_base_; 0102 0103 //// HELPER FUNCTIONS //// 0104 0105 Span<int> get_host_buffer(AuxStateVec&) const; 0106 void write_buffer(AuxStateVec&) const; 0107 }; 0108 0109 //---------------------------------------------------------------------------// 0110 } // namespace celeritas
[ Source navigation ] | [ Diff markup ] | [ Identifier search ] | [ general search ] |
This page was automatically generated by the 2.3.7 LXR engine. The LXR team |
![]() ![]() |