Branch data Line data Source code
1 : : // *****************************************************************************
2 : : /*!
3 : : \file src/Control/Inciter/CmdLine/CmdLine.hpp
4 : : \copyright 2012-2015 J. Bakosi,
5 : : 2016-2018 Los Alamos National Security, LLC.,
6 : : 2019-2021 Triad National Security, LLC.
7 : : All rights reserved. See the LICENSE file for details.
8 : : \brief Inciter's command line definition
9 : : \details This file defines the heterogeneous stack that is used for storing
10 : : the data from user input during the command-line parsing of the
11 : : computational shock hydrodynamics tool, Inciter.
12 : : */
13 : : // *****************************************************************************
14 : : #ifndef InciterCmdLine_h
15 : : #define InciterCmdLine_h
16 : :
17 : : #include <string>
18 : :
19 : : #include <brigand/algorithms/for_each.hpp>
20 : :
21 : : #include "QuinoaConfig.hpp"
22 : : #include "TaggedTuple.hpp"
23 : : #include "PrintUtil.hpp"
24 : : #include "Tags.hpp"
25 : : #include "HelpFactory.hpp"
26 : : #include "Keywords.hpp"
27 : : #include "Inciter/OutVar.hpp"
28 : :
29 : : namespace inciter {
30 : : //! Inciter control facilitating user input to internal data transfer
31 : : namespace ctr {
32 : :
33 : : //! IO parameters storage
34 : : using ios = tk::TaggedTuple< brigand::list<
35 : : tag::nrestart, int //!< Number of restarts
36 : : , tag::control, kw::control::info::expect::type //!< Control filename
37 : : , tag::input, kw::input::info::expect::type //!< Input filename
38 : : , tag::output, kw::output::info::expect::type //!< Output filename
39 : : //! Refined output (output field data on a refined mesh)
40 : : , tag::refined, kw::refined::info::expect::type
41 : : , tag::screen, kw::screen::info::expect::type //!< Screen output filename
42 : : //! List of side sets to save as field output
43 : : , tag::surface, std::vector< kw::sideset::info::expect::type >
44 : : //! Diagnostics filename
45 : : , tag::diag, kw::diagnostics_cmd::info::expect::type
46 : : , tag::particles, std::string //!< Particles filename
47 : : , tag::outvar, std::vector< OutVar > //!< Output variables
48 : : , tag::restart, kw::restart::info::expect::type //!< Restart dirname
49 : : > >;
50 : :
51 : : //! Member data for tagged tuple
52 : : using CmdLineMembers = brigand::list<
53 : : tag::io, ios
54 : : , tag::virtualization, kw::virtualization::info::expect::type
55 : : , tag::verbose, bool
56 : : , tag::chare, bool
57 : : , tag::nonblocking, bool
58 : : , tag::benchmark, bool
59 : : , tag::feedback, bool
60 : : , tag::help, bool
61 : : , tag::helpctr, bool
62 : : , tag::quiescence, bool
63 : : , tag::trace, bool
64 : : , tag::version, bool
65 : : , tag::license, bool
66 : : , tag::cmdinfo, tk::ctr::HelpFactory
67 : : , tag::ctrinfo, tk::ctr::HelpFactory
68 : : , tag::helpkw, tk::ctr::HelpKw
69 : : , tag::error, std::vector< std::string >
70 : : , tag::lbfreq, kw::lbfreq::info::expect::type
71 : : , tag::rsfreq, kw::rsfreq::info::expect::type
72 : : >;
73 : :
74 : : //! \brief CmdLine : Control< specialized to Inciter >
75 : : //! \details The stack is a tagged tuple
76 : : //! \see Base/TaggedTuple.h
77 : : //! \see Control/Inciter/Types.h
78 : : class CmdLine : public tk::TaggedTuple< CmdLineMembers > {
79 : :
80 : : public:
81 : : //! \brief Inciter command-line keywords
82 : : //! \see tk::grm::use and its documentation
83 : : using keywords = tk::cmd_keywords< kw::verbose
84 : : , kw::charestate
85 : : , kw::nonblocking
86 : : , kw::benchmark
87 : : , kw::feedback
88 : : , kw::virtualization
89 : : , kw::help
90 : : , kw::helpctr
91 : : , kw::helpkw
92 : : , kw::control
93 : : , kw::input
94 : : , kw::output
95 : : , kw::screen
96 : : , kw::restart
97 : : , kw::diagnostics_cmd
98 : : , kw::quiescence
99 : : , kw::lbfreq
100 : : , kw::rsfreq
101 : : , kw::trace
102 : : , kw::version
103 : : , kw::license
104 : : >;
105 : :
106 : : //! Set of tags to ignore when printing this CmdLine
107 : : using ignore =
108 : : brigand::set< tag::cmdinfo
109 : : , tag::ctrinfo
110 : : , tag::helpkw >;
111 : :
112 : : //! \brief Constructor: set all defaults.
113 : : //! \param[in] ctrinfo std::map of control file keywords and their info
114 : : //! \details Anything not set here is initialized by the compiler using the
115 : : //! default constructor for the corresponding type. The ctrinfo map
116 : : //! argument is optional. If not given, it is an empty std::map
117 : : //! constructed in-place and affects nothing. If given, it contains the
118 : : //! control file keywords, all of which are moved into the relevant slot
119 : : //! (tag::ctrinfo). This allows constructing, e.g., a CmdLine object both
120 : : //! with and without this information in place, which are both used at
121 : : //! different stages of the execution. For example, because the
122 : : //! command-line is parsed very early on during runtime while the input
123 : : //! deck is only parsed much later, the control-file keywords and their
124 : : //! information (owned by and generated by the input deck and its
125 : : //! constructor) is not yet available when the CmdLine object is
126 : : //! constructed. However, during command-line parsing it is still possible
127 : : //! to request information on a control file keyword, so it must be
128 : : //! available. The input deck is where all parsed information goes during
129 : : //! control file parsing and is stored at global scope, see, e.g.,
130 : : //! walker::g_inputdeck. This global-scope (still namespace-scope), input
131 : : //! deck object is thus created before command-line parsing. The input
132 : : //! deck object's constructor (working only on type information, available
133 : : //! at compile-time, of all the control file keywords) creates a run-time
134 : : //! map. This is a run-time map, but available before main() starts,
135 : : //! because it is const and it is initialized as a global-scope map. This
136 : : //! map is then passed in here as ctrinfo, and its contents inserted into
137 : : //! the CmdLine object, making the control-file keywords and their info
138 : : //! available during command-line parsing. Since the input deck stack
139 : : //! contains a copy of the command-line stack, the command-line stack must
140 : : //! be possible to be instantiated without passing the ctrinfo map,
141 : : //! otherwise it would be a mutual dependency.
142 : : // cppcheck-suppress noExplicitConstructor
143 : 2855 : CmdLine( tk::ctr::HelpFactory ctrinfo = tk::ctr::HelpFactory() ) {
144 : 2855 : get< tag::io, tag::nrestart >() = 0;
145 [ + - ]: 2855 : get< tag::io, tag::output >() = "out";
146 : 2855 : get< tag::io, tag::refined >() = false;
147 : 2855 : get< tag::io, tag::screen >() =
148 [ + - ][ + - ]: 5710 : tk::baselogname( tk::inciter_executable() );
149 [ + - ]: 2855 : get< tag::io, tag::diag >() = "diag";
150 [ + - ]: 2855 : get< tag::io, tag::particles >() = "track.h5part";
151 [ + - ]: 2855 : get< tag::io, tag::restart >() = "restart";
152 : 2855 : get< tag::virtualization >() = 0.0;
153 : 2855 : get< tag::verbose >() = false; // Quiet output by default
154 : 2855 : get< tag::chare >() = false; // No chare state output by default
155 : 2855 : get< tag::nonblocking>() = false; // Blocking migration by default
156 : 2855 : get< tag::benchmark >() = false; // No benchmark mode by default
157 : 2855 : get< tag::feedback >() = false; // No detailed feedback by default
158 : 2855 : get< tag::lbfreq >() = 1; // Load balancing every time-step by default
159 : 2855 : get< tag::rsfreq >() = 1000;// Chkpt/restart after this many time steps
160 : 2855 : get< tag::trace >() = true; // Output call and stack trace by default
161 : 2855 : get< tag::version >() = false; // Do not display version info by default
162 : 2855 : get< tag::license >() = false; // Do not display license info by default
163 : : // Initialize help: fill from own keywords + add map passed in
164 [ + - ]: 2855 : brigand::for_each< keywords::set >( tk::ctr::Info(get<tag::cmdinfo>()) );
165 : 2855 : get< tag::ctrinfo >() = std::move( ctrinfo );
166 : 2855 : }
167 : :
168 : : /** @name Pack/Unpack: Serialize CmdLine object for Charm++ */
169 : : ///@{
170 : : //! \brief Pack/Unpack serialize member function
171 : : //! \param[in,out] p Charm++'s PUP::er serializer object reference
172 : 1766 : void pup( PUP::er& p ) { tk::TaggedTuple< CmdLineMembers >::pup(p); }
173 : : //! \brief Pack/Unpack serialize operator|
174 : : //! \param[in,out] p Charm++'s PUP::er serializer object reference
175 : : //! \param[in,out] c CmdLine object reference
176 : 1766 : friend void operator|( PUP::er& p, CmdLine& c ) { c.pup(p); }
177 : : //@}
178 : :
179 : : //! Compute and return log file name
180 : : //! \param[in] def Default log file name (so we don't mess with user's)
181 : : //! \param[in] nrestart Number of times restarted
182 : : //! \return Log file name
183 : 4584 : std::string logname( const std::string& def, int nrestart ) const {
184 [ - + ]: 4584 : if (get< tag::io, tag::screen >() != def)
185 : 0 : return get< tag::io, tag::screen >();
186 : : else
187 [ + - ]: 9168 : return tk::logname( tk::inciter_executable(), nrestart );
188 : : }
189 : : };
190 : :
191 : : } // ctr::
192 : : } // inciter::
193 : :
194 : : #endif // InciterCmdLine_h
|