14 {
"tr",
"target-radius",
ArgEnum::FLOAT,
"Radius of the target [m]" },
15 {
"tp",
"target-period",
ArgEnum::FLOAT,
"Rotational period of the target [h]" },
16 {
"ir",
"impactor-radius",
ArgEnum::FLOAT,
"Radius of the impactor [m]" },
20 "Relative impact energy Q/Q_D^*. This option can be only used together with -tr and -v, it is "
21 "incompatible with -ir." },
24 {
"n",
"particle-count",
ArgEnum::INT,
"Number of particles in the target" },
25 {
"st",
"stabilization-time",
ArgEnum::FLOAT,
"Duration of the stabilization phase [s]" },
26 {
"ft",
"fragmentation-time",
ArgEnum::FLOAT,
"Duration of the fragmentation phase [s]" },
27 {
"rt",
"reaccumulation-time",
ArgEnum::FLOAT,
"Duration of the reaccumulation phase [s]" },
28 {
"i",
"resume-from",
ArgEnum::STRING,
"Resume simulation from given state file" },
32 "Directory containing configuration files and run output files. If not specified, it is determined "
33 "from other arguments. If no arguments are specified, the current working directory is used." },
36 static void printBanner(
ILogger& logger) {
37 logger.
write(
"*******************************************************************************");
38 logger.
write(
"******************************* OpenSPH Impact ********************************");
39 logger.
write(
"*******************************************************************************");
42 static void printNoConfigsMsg(
ILogger& logger,
const Path& outputDir) {
44 logger.
write(
"No configuration files found, the program will generate default configuration ");
45 logger.
write(
"files and save them to directory '" + outputDir.
native() +
"'");
47 logger.
write(
"To start a simulation, re-run this program; it will load the generated files. ");
48 logger.
write(
"You can also specify parameters of the simulation as command-line arguments. ");
49 logger.
write(
"Note that these arguments will override parameters loaded from configuration ");
50 logger.
write(
"files. For more information, execute the program with -h (or --help) argument.");
54 template <
typename TEnum>
62 logger.
write(
"Loaded configuration file '" + path.
native() +
"'");
67 logger.
write(
"No file '" + path.
native() +
"' found, it has been created with default parameters");
91 return outputPath.
value();
103 ss <<
round(60._f * targetPeriod.
value()) <<
"min_";
106 ss <<
round(impactSpeed.
value() / 1.e3_f) <<
"kms_";
112 ss << particleCnt.
value() <<
"p_";
115 std::string name = ss.str();
128 std::string paramsMsg;
134 outputDir =
Path(params.getOutputPath());
138 if (params.resumePath) {
142 throw Exception(
"Cannot resume simulation from file '" + params.resumePath.value() +
"'.\n" +
146 logger.
write(
"Resuming simulation from file '" + params.resumePath.value() +
"'");
148 return resumeFragmentation();
150 return resumeReaccumulation();
152 throw Exception(
"Cannot resume from this file.");
156 logger.
write(
"Starting new simulation");
157 return makeNewSimulation();
166 return logger.
toString() +
"\n" + paramsMsg;
176 return runTime.
valueOr(mult * 3600._f *
radius.valueOr(5.e4_f) / 5.e4_f);
189 if (params.targetPeriod) {
193 loadSettings<BodySettingsId>(outputDir /
Path(
"target.cnf"), targetDefaults, logger, doDryRun);
202 BodySettings impactorBody = loadSettings<BodySettingsId>(
203 outputDir /
Path(
"impactor.cnf"), impactorDefaults, logger, doDryRun);
205 targetIc->
connect(impactorIc,
"target");
210 overrideRunTime(stabDefaults, defaultSphTime(params.stabTime, params.targetRadius, 0.2_f));
213 loadSettings<RunSettingsId>(outputDir /
Path(
"stab.cnf"), stabDefaults, logger, doDryRun);
214 SharedPtr<JobNode> stabTarget = makeNode<SphStabilizationJob>(
"stabilization", stabRun);
215 targetIc->
connect(stabTarget,
"particles");
222 outputDir /
Path(
"geometry.cnf"), geometryDefaults, logger, doDryRun);
224 stabTarget->
connect(setup,
"target");
225 impactorIc->
connect(setup,
"impactor");
227 printRunSettings(targetBody, impactorBody, geometry);
235 overrideRunTime(fragDefaults, defaultSphTime(params.fragTime, params.targetRadius, 1._f));
237 loadSettings<RunSettingsId>(outputDir /
Path(
"frag.cnf"), fragDefaults, logger, doDryRun);
245 overrideRunTime(reacDefaults, params.reacTime.valueOr(3600._f * 24._f * 10._f));
247 loadSettings<RunSettingsId>(outputDir /
Path(
"reac.cnf"), reacDefaults, logger, doDryRun);
255 setup->
connect(frag,
"particles");
258 frag->
connect(handoff,
"particles");
261 handoff->
connect(reac,
"particles");
269 loadFile->
connect(frag,
"particles");
272 frag->
connect(handoff,
"particles");
275 handoff->
connect(reac,
"particles");
283 loadFile->
connect(reac,
"particles");
304 logger.
write(
"Run parameters");
305 logger.
write(
"-------------------------------------");
306 logger.
write(
" Target radius (R_pb): ", 1.e-3_f * targetRadius,
" km");
307 logger.
write(
" Impactor radius (r_imp): ", 1.e-3_f * impactorRadius,
" km");
308 logger.
write(
" Impact speed (v_imp): ", 1.e-3_f * impactSpeed,
" km/s");
309 logger.
write(
" Impact angle (phi_imp): ", impactAngle,
"°");
310 logger.
write(
" Impact energy (Q/Q*_D): ", impactEnergy);
311 logger.
write(
" Target period (P_pb): ", 24._f / spinRate, spinRate == 0._f ?
"" :
"h");
312 logger.
write(
" Particle count (N): ", particleCnt);
313 logger.
write(
"-------------------------------------");
327 if (params.impactSpeed) {
328 params.impactSpeed.value() *= 1.e3_f;
332 params.particleCnt = parser.
tryGetArg<
int>(
"n");
342 if (!targetRadius || !impactSpeed) {
344 "To specify impact energy (-q), you also need to specify the target radius (-tr) and "
345 "impact speed (-v)");
348 targetRadius.value(), impactSpeed.value() * 1.e3_f, impactEnergy.value(), density);
351 params.outputPath = parser.
tryGetArg<std::string>(
"o");
352 params.resumePath = parser.
tryGetArg<std::string>(
"i");
362 if (!factory.isDryRun()) {
363 logger.
write(factory.getBannerMsg());
368 printNoConfigsMsg(logger, factory.getOutputDir());
372 int main(
int argc,
char* argv[]) {
377 parser.
parse(argc, argv);
Float getImpactEnergy(const Float R, const Float r, const Float v)
Computes the impact energy Q from impact parameters.
Float getImpactorRadius(const Float R_pb, const Float v_imp, const Float QOverQ_D, const Float rho)
Calculates the impactor radius to satisfy required impact parameters.
NAMESPACE_SPH_BEGIN Float evalBenzAsphaugScalingLaw(const Float D, const Float rho)
Returns the critical energy Q_D^* as a function of body diameter.
uint32_t Size
Integral type used to index arrays (by default).
double Float
Precision used withing the code. Use Float instead of float or double where precision is important.
constexpr int PRECISION
Number of valid digits of numbers on output.
int main(int argc, char *argv[])
INLINE auto round(const T &f)
@ SPH
Main SPH simulation.
@ NBODY
Main N-body simulation, using initial conditions either from SPH (handoff) or manually specified.
@ IMPACT_ANGLE
Impact angle in degrees, i.e. angle between velocity vector and normal at the impact point.
@ IMPACT_SPEED
Impact speed in m/s.
Exception thrown if the arguments are invalid.
Provides functions for parsing command-line arguments.
void parse(const int argc, char **argv)
Parses the input arguments and stored the parsed values.
Optional< TValue > tryGetArg(const std::string &name) const
Returns the value of an argument or NOTHING if the argument was not parsed.
virtual const char * what() const noexcept
Wrapper of type that either contains a value of given type, or an error message.
const Error & error() const
Returns the error message.
Exception thrown when used passes -h or –help parameter.
Interface providing generic (text, human readable) output of the program.
void setPrecision(const Size newPrecision)
Changes the precision of printed numbers.
void write(TArgs &&... args)
Creates and logs a message by concatenating arguments.
void setScientific(const bool newScientific)
Sets/unsets scientific notation.
virtual void run(const RunSettings &global, IJobCallbacks &callbacks) override
Evaluates the node and all its providers.
void connect(SharedPtr< JobNode > dependent, const std::string &slotName)
Connects this node to given dependent node.
static RunSettings getDefaultSettings(const std::string &name)
INLINE Type & value()
Returns the reference to the stored value.
INLINE Type valueOr(const TOther &other) const
Returns the stored value if the object has been initialized, otherwise returns provided parameter.
Object representing a path on a filesystem.
std::string native() const
Returns the native version of the path.
Path getOutputDir() const
SharedPtr< JobNode > makeSimulation()
RunFactory(const RunParams ¶ms)
std::string getBannerMsg() const
Generic object containing various settings and parameters of the run.
void unset(const TEnum idx)
Removes given parameter from settings.
TValue get(const TEnum idx, std::enable_if_t<!std::is_enum< std::decay_t< TValue >>::value, int >=0) const
Returns a value of given type from the settings.
static const Settings & getDefaults()
\brief Returns a reference to object containing default values of all settings.
Settings & set(const TEnum idx, TValue &&value, std::enable_if_t<!std::is_enum< std::decay_t< TValue >>::value, int >=0)
Saves a value into the settings.
bool tryLoadFileOrSaveCurrent(const Path &path, const Settings &overrides=EMPTY_SETTINGS)
If the specified file exists, loads the settings from it, otherwise creates the file and saves the cu...
static RunSettings getDefaultSettings(const std::string &name)
Logger writing messages to string stream.
std::string toString() const
Returns all written messages as a string. Messages are not erased from the logger by this.
const EmptySettingsTag EMPTY_SETTINGS
@ DAMAGE_MIN
Estimate minimal value of damage used to determine timestepping error.
@ PARTICLE_COUNT
Number of SPH particles in the body.
@ DENSITY
Density at zero pressure.
@ STRESS_TENSOR_MIN
Estimated minial value of stress tensor components used to determined timestepping error.
@ RUN_OUTPUT_INTERVAL
Time interval of dumping data to disk.
@ RUN_OUTPUT_PATH
Path where all output files (dumps, logs, ...) will be written.
Optional< Float > targetPeriod
std::string getOutputPath() const
Returns the name of the created output directory.
Optional< Float > fragTime
Optional< Float > targetRadius
Optional< std::string > resumePath
Optional< Float > stabTime
Optional< int > particleCnt
Optional< Float > impactSpeed
Optional< Float > impactAngle
Optional< Float > reacTime
Optional< std::string > outputPath
Optional< Float > impactorRadius