SPH
SimulationJobs.cpp
Go to the documentation of this file.
3 #include "io/LogWriter.h"
4 #include "io/Logger.h"
5 #include "io/Output.h"
6 #include "run/IRun.h"
7 #include "run/SpecialEntries.h"
9 
11 
13 class EnergyLogWriter : public ILogWriter {
14 public:
16 
17 private:
18  virtual void write(const Storage& storage, const Statistics& stats) override {
19  const Float t = stats.get<Float>(StatisticsId::RUN_TIME);
20  const Float e = TotalEnergy().evaluate(storage);
21  logger->write(t, " ", e);
22  }
23 };
24 
25 static std::string getIdentifier(const std::string& name) {
26  std::string escaped = replaceAll(name, " ", "-");
27  return lowercase(escaped);
28 }
29 
30 // ----------------------------------------------------------------------------------------------------------
31 // SphJob
32 // ----------------------------------------------------------------------------------------------------------
33 
34 static RunSettings overrideSettings(const RunSettings& settings,
35  const RunSettings& overrides,
36  const bool isResumed) {
37  RunSettings actual = settings;
38  actual.addEntries(overrides);
39 
40  if (!isResumed) {
41  // reset the (potentially) overriden values back to original
45  actual.set(
47  }
48  return actual;
49 }
50 
51 static void addTimeSteppingCategory(VirtualSettings& connector, RunSettings& settings, bool& resumeRun) {
52  auto courantEnabler = [&settings] {
55  return criteria.has(TimeStepCriterionEnum::COURANT);
56  };
57  auto derivativeEnabler = [&settings] {
61  };
62  auto divergenceEnabler = [&settings] {
65  return criteria.has(TimeStepCriterionEnum::DIVERGENCE);
66  };
67 
68  VirtualSettings::Category& rangeCat = connector.addCategory("Integration");
69  rangeCat.connect<Float>("Duration [s]", settings, RunSettingsId::RUN_END_TIME);
70  rangeCat.connect("Use start time of input", "is_resumed", resumeRun);
71  rangeCat.connect<Float>("Maximal timestep [s]", settings, RunSettingsId::TIMESTEPPING_MAX_TIMESTEP);
72  rangeCat.connect<Float>("Initial timestep [s]", settings, RunSettingsId::TIMESTEPPING_INITIAL_TIMESTEP);
73  rangeCat.connect<EnumWrapper>("Integrator", settings, RunSettingsId::TIMESTEPPING_INTEGRATOR);
75  "Time step criteria", settings, RunSettingsId::TIMESTEPPING_CRITERION);
76  rangeCat.connect<Float>("Courant number", settings, RunSettingsId::TIMESTEPPING_COURANT_NUMBER)
77  .setEnabler(courantEnabler);
78  rangeCat.connect<Float>("Derivative factor", settings, RunSettingsId::TIMESTEPPING_DERIVATIVE_FACTOR)
79  .setEnabler(derivativeEnabler);
80  rangeCat.connect<Float>("Divergence factor", settings, RunSettingsId::TIMESTEPPING_DIVERGENCE_FACTOR)
81  .setEnabler(divergenceEnabler);
82  rangeCat.connect<Float>("Max step change", settings, RunSettingsId::TIMESTEPPING_MAX_INCREASE);
83 }
84 
85 static void addGravityCategory(VirtualSettings& connector, RunSettings& settings) {
86  VirtualSettings::Category& gravityCat = connector.addCategory("Gravity");
87  gravityCat.connect<EnumWrapper>("Gravity solver", settings, RunSettingsId::GRAVITY_SOLVER);
88  gravityCat.connect<Float>("Opening angle", settings, RunSettingsId::GRAVITY_OPENING_ANGLE)
89  .setEnabler([&settings] {
91  });
92  gravityCat.connect<int>("Multipole order", settings, RunSettingsId::GRAVITY_MULTIPOLE_ORDER);
93  gravityCat.connect<EnumWrapper>("Softening kernel", settings, RunSettingsId::GRAVITY_KERNEL);
94  gravityCat.connect<Float>(
95  "Recomputation period [s]", settings, RunSettingsId::GRAVITY_RECOMPUTATION_PERIOD);
96 }
97 
98 static void addOutputCategory(VirtualSettings& connector, RunSettings& settings, const SharedToken& owner) {
99  auto enabler = [&settings] {
100  const IoEnum type = settings.get<IoEnum>(RunSettingsId::RUN_OUTPUT_TYPE);
101  return type != IoEnum::NONE;
102  };
103 
104  VirtualSettings::Category& outputCat = connector.addCategory("Output");
105  outputCat.connect<EnumWrapper>("Format", settings, RunSettingsId::RUN_OUTPUT_TYPE)
106  .setValidator([](const IVirtualEntry::Value& value) {
107  const IoEnum type = IoEnum(value.get<EnumWrapper>());
108  return type == IoEnum::NONE || getIoCapabilities(type).has(IoCapability::OUTPUT);
109  })
110  .addAccessor(owner,
111  [&settings](const IVirtualEntry::Value& value) {
112  const IoEnum type = IoEnum(value.get<EnumWrapper>());
113  Path name = Path(settings.get<std::string>(RunSettingsId::RUN_OUTPUT_NAME));
114  if (Optional<std::string> extension = getIoExtension(type)) {
115  name.replaceExtension(extension.value());
116  }
117  settings.set(RunSettingsId::RUN_OUTPUT_NAME, name.native());
118  })
119  .setSideEffect(); // needs to update the 'File mask' entry
120  outputCat.connect<Path>("Directory", settings, RunSettingsId::RUN_OUTPUT_PATH)
121  .setEnabler(enabler)
123  outputCat.connect<std::string>("File mask", settings, RunSettingsId::RUN_OUTPUT_NAME).setEnabler(enabler);
125  .setEnabler([&settings] {
126  const IoEnum type = settings.get<IoEnum>(RunSettingsId::RUN_OUTPUT_TYPE);
127  return type == IoEnum::TEXT_FILE || type == IoEnum::VTK_FILE;
128  });
129  outputCat.connect<EnumWrapper>("Output spacing", settings, RunSettingsId::RUN_OUTPUT_SPACING)
130  .setEnabler(enabler);
131  outputCat.connect<Float>("Output interval [s]", settings, RunSettingsId::RUN_OUTPUT_INTERVAL)
132  .setEnabler([&] {
133  const IoEnum type = settings.get<IoEnum>(RunSettingsId::RUN_OUTPUT_TYPE);
134  const OutputSpacing spacing = settings.get<OutputSpacing>(RunSettingsId::RUN_OUTPUT_SPACING);
135  return type != IoEnum::NONE && spacing != OutputSpacing::CUSTOM;
136  });
137  outputCat.connect<std::string>("Custom times [s]", settings, RunSettingsId::RUN_OUTPUT_CUSTOM_TIMES)
138  .setEnabler([&] {
139  const IoEnum type = settings.get<IoEnum>(RunSettingsId::RUN_OUTPUT_TYPE);
140  const OutputSpacing spacing = settings.get<OutputSpacing>(RunSettingsId::RUN_OUTPUT_SPACING);
141  return type != IoEnum::NONE && spacing == OutputSpacing::CUSTOM;
142  });
143 }
144 
145 static void addLoggerCategory(VirtualSettings& connector, RunSettings& settings) {
146  VirtualSettings::Category& loggerCat = connector.addCategory("Logging");
147  loggerCat.connect<EnumWrapper>("Logger", settings, RunSettingsId::RUN_LOGGER);
148  loggerCat.connect<Path>("Log file", settings, RunSettingsId::RUN_LOGGER_FILE)
150  .setEnabler(
151  [&settings] { return settings.get<LoggerEnum>(RunSettingsId::RUN_LOGGER) == LoggerEnum::FILE; });
152  loggerCat.connect<int>("Log verbosity", settings, RunSettingsId::RUN_LOGGER_VERBOSITY);
153 }
154 
155 
156 class SphRun : public IRun {
157 protected:
159 
160 public:
162  : domain(domain) {
163  settings = run;
165  }
166 
167  virtual void setUp(SharedPtr<Storage> storage) override {
169  solver = Factory::getSolver(*scheduler, settings, std::move(bc));
170 
171  for (Size matId = 0; matId < storage->getMaterialCnt(); ++matId) {
172  solver->create(*storage, storage->getMaterial(matId));
173  }
174  }
175 
176  virtual void tearDown(const Storage& storage, const Statistics& stats) override {
177  // last dump after simulation ends
178  output->dump(storage, stats);
179  }
180 };
181 
182 SphJob::SphJob(const std::string& name, const RunSettings& overrides)
183  : IRunJob(name) {
185 
186  settings.addEntries(overrides);
187 }
188 
189 RunSettings SphJob::getDefaultSettings(const std::string& name) {
190  const Size dumpCnt = 10;
191  const Interval timeRange(0, 10);
192 
199  .set(RunSettingsId::RUN_END_TIME, timeRange.upper())
201  .set(RunSettingsId::RUN_OUTPUT_INTERVAL, timeRange.size() / dumpCnt)
225  return settings;
226 }
227 
229  VirtualSettings connector;
230  addGenericCategory(connector, instName);
231  addTimeSteppingCategory(connector, settings, isResumed);
232 
233  auto stressEnabler = [this] {
235  };
236  auto avEnabler = [this] {
239  };
240  auto asEnabler = [this] { return settings.get<bool>(RunSettingsId::SPH_AV_USE_STRESS); };
241  // auto acEnabler = [this] { return settings.get<bool>(RunSettingsId::SPH_USE_AC); };
242  auto deltaSphEnabler = [this] { return settings.get<bool>(RunSettingsId::SPH_USE_DELTASPH); };
243  auto enforceEnabler = [this] {
246  };
247 
248  VirtualSettings::Category& solverCat = connector.addCategory("SPH solver");
250  solverCat.connect<Vector>("Constant acceleration", settings, RunSettingsId::FRAME_CONSTANT_ACCELERATION);
251  solverCat.connect<Float>("Tides mass [M_earth]", settings, RunSettingsId::FRAME_TIDES_MASS)
252  .setUnits(Constants::M_earth);
253  solverCat.connect<Vector>("Tides position [R_earth]", settings, RunSettingsId::FRAME_TIDES_POSITION)
254  .setUnits(Constants::R_earth);
255  solverCat.connect<EnumWrapper>("Solver type", settings, RunSettingsId::SPH_SOLVER_TYPE);
256  solverCat.connect<EnumWrapper>("SPH discretization", settings, RunSettingsId::SPH_DISCRETIZATION);
258  "Adaptive smoothing length", settings, RunSettingsId::SPH_ADAPTIVE_SMOOTHING_LENGTH);
259  solverCat.connect<Float>("Minimal smoothing length", settings, RunSettingsId::SPH_SMOOTHING_LENGTH_MIN)
260  .setEnabler([this] {
262  EMPTY_FLAGS;
263  });
264  solverCat
265  .connect<Float>("Neighbor count enforcing strength", settings, RunSettingsId::SPH_NEIGHBOUR_ENFORCING)
266  .setEnabler(enforceEnabler);
267  solverCat.connect<Interval>("Neighbor range", settings, RunSettingsId::SPH_NEIGHBOUR_RANGE)
268  .setEnabler(enforceEnabler);
269  solverCat
271  .setEnabler([this] {
273  });
274  solverCat
275  .connect<bool>("Apply correction tensor", settings, RunSettingsId::SPH_STRAIN_RATE_CORRECTION_TENSOR)
276  .setEnabler(stressEnabler);
277  solverCat.connect<bool>("Sum only undamaged particles", settings, RunSettingsId::SPH_SUM_ONLY_UNDAMAGED);
278  solverCat.connect<EnumWrapper>("Continuity mode", settings, RunSettingsId::SPH_CONTINUITY_MODE);
279  solverCat.connect<EnumWrapper>("Neighbour finder", settings, RunSettingsId::SPH_FINDER);
280  solverCat.connect<EnumWrapper>("Boundary condition", settings, RunSettingsId::DOMAIN_BOUNDARY);
281 
282  VirtualSettings::Category& avCat = connector.addCategory("Artificial viscosity");
283  avCat.connect<EnumWrapper>("Artificial viscosity type", settings, RunSettingsId::SPH_AV_TYPE);
284  avCat.connect<bool>("Apply Balsara switch", settings, RunSettingsId::SPH_AV_USE_BALSARA)
285  .setEnabler(avEnabler);
286  avCat.connect<Float>("Artificial viscosity alpha", settings, RunSettingsId::SPH_AV_ALPHA)
287  .setEnabler(avEnabler);
288  avCat.connect<Float>("Artificial viscosity beta", settings, RunSettingsId::SPH_AV_BETA)
289  .setEnabler(avEnabler);
290  avCat.connect<bool>("Apply artificial stress", settings, RunSettingsId::SPH_AV_USE_STRESS);
291  avCat.connect<Float>("Artificial stress factor", settings, RunSettingsId::SPH_AV_STRESS_FACTOR)
292  .setEnabler(asEnabler);
293  avCat.connect<Float>("Artificial stress exponent", settings, RunSettingsId::SPH_AV_STRESS_EXPONENT)
294  .setEnabler(asEnabler);
295  avCat.connect<bool>("Apply artificial conductivity", settings, RunSettingsId::SPH_USE_AC);
296  avCat.connect<EnumWrapper>("Signal speed", settings, RunSettingsId::SPH_AC_SIGNAL_SPEED)
297  .setEnabler([this] { return settings.get<bool>(RunSettingsId::SPH_USE_AC); });
298 
299  VirtualSettings::Category& modCat = connector.addCategory("SPH modifications");
300  modCat.connect<bool>("Enable XPSH", settings, RunSettingsId::SPH_USE_XSPH);
301  modCat.connect<Float>("XSPH epsilon", settings, RunSettingsId::SPH_XSPH_EPSILON).setEnabler([this] {
303  });
304  modCat.connect<bool>("Enable delta-SPH", settings, RunSettingsId::SPH_USE_DELTASPH);
305  modCat.connect<Float>("delta-SPH alpha", settings, RunSettingsId::SPH_VELOCITY_DIFFUSION_ALPHA)
306  .setEnabler(deltaSphEnabler);
307  modCat.connect<Float>("delta-SPH delta", settings, RunSettingsId::SPH_DENSITY_DIFFUSION_DELTA)
308  .setEnabler(deltaSphEnabler);
309 
310  auto scriptEnabler = [this] { return settings.get<bool>(RunSettingsId::SPH_SCRIPT_ENABLE); };
311 
312  VirtualSettings::Category& scriptCat = connector.addCategory("Scripts");
313  scriptCat.connect<bool>("Enable script", settings, RunSettingsId::SPH_SCRIPT_ENABLE);
314  scriptCat.connect<Path>("Script file", settings, RunSettingsId::SPH_SCRIPT_FILE)
315  .setEnabler(scriptEnabler)
317  .setFileFormats({ { "Chaiscript script", "chai" } });
318  scriptCat.connect<Float>("Script period [s]", settings, RunSettingsId::SPH_SCRIPT_PERIOD)
319  .setEnabler(scriptEnabler);
320  scriptCat.connect<bool>("Run only once", settings, RunSettingsId::SPH_SCRIPT_ONESHOT)
321  .setEnabler(scriptEnabler);
322 
323  addGravityCategory(connector, settings);
324  addOutputCategory(connector, settings, *this);
325  addLoggerCategory(connector, settings);
326 
327  return connector;
328 }
329 
330 AutoPtr<IRun> SphJob::getRun(const RunSettings& overrides) const {
331  SPH_ASSERT(overrides.size() < 15); // not really required, just checking that we don't override everything
333  SharedPtr<IDomain> domain;
334  if (boundary != BoundaryEnum::NONE) {
335  domain = this->getInput<IDomain>("boundary");
336  }
337 
338  RunSettings run = overrideSettings(settings, overrides, isResumed);
341  }
342 
343  return makeAuto<SphRun>(run, domain);
344 }
345 
346 static JobRegistrar sRegisterSph(
347  "SPH run",
348  "simulations",
349  [](const std::string& name) { return makeAuto<SphJob>(name, EMPTY_SETTINGS); },
350  "Runs a SPH simulation, using provided initial conditions.");
351 
352 // ----------------------------------------------------------------------------------------------------------
353 // SphStabilizationJob
354 // ----------------------------------------------------------------------------------------------------------
355 
356 class SphStabilizationRun : public SphRun {
357 public:
358  using SphRun::SphRun;
359 
360  virtual void setUp(SharedPtr<Storage> storage) override {
362  solver = makeAuto<StabilizationSolver>(*scheduler, settings, std::move(bc));
363 
364  for (Size matId = 0; matId < storage->getMaterialCnt(); ++matId) {
365  solver->create(*storage, storage->getMaterial(matId));
366  }
367  }
368 };
369 
371  VirtualSettings connector = SphJob::getSettings();
372 
373  VirtualSettings::Category& stabCat = connector.addCategory("Stabilization");
374  stabCat.connect<Float>("Damping coefficient", settings, RunSettingsId::SPH_STABILIZATION_DAMPING);
375 
376  return connector;
377 }
378 
380  RunSettings run = overrideSettings(settings, overrides, isResumed);
382  SharedPtr<IDomain> domain;
383  if (boundary != BoundaryEnum::NONE) {
384  domain = this->getInput<IDomain>("boundary");
385  }
386  return makeAuto<SphStabilizationRun>(run, domain);
387 }
388 
389 static JobRegistrar sRegisterSphStab(
390  "SPH stabilization",
391  "stabilization",
392  "simulations",
393  [](const std::string& name) { return makeAuto<SphStabilizationJob>(name, EMPTY_SETTINGS); },
394  "Runs a SPH simulation with a damping term, suitable for stabilization of non-equilibrium initial "
395  "conditions.");
396 
397 
398 // ----------------------------------------------------------------------------------------------------------
399 // NBodyJob
400 // ----------------------------------------------------------------------------------------------------------
401 
402 class NBodyRun : public IRun {
403 private:
404  bool useSoft;
405 
406 public:
407  NBodyRun(const RunSettings& run, const bool useSoft)
408  : useSoft(useSoft) {
409  settings = run;
411  }
412 
413  virtual void setUp(SharedPtr<Storage> storage) override {
415 
416  const bool aggregateEnable = settings.get<bool>(RunSettingsId::NBODY_AGGREGATES_ENABLE);
417  const AggregateEnum aggregateSource =
419  if (aggregateEnable) {
420  AutoPtr<AggregateSolver> aggregates = makeAuto<AggregateSolver>(*scheduler, settings);
421  aggregates->createAggregateData(*storage, aggregateSource);
422  solver = std::move(aggregates);
423  } else if (useSoft) {
424  solver = makeAuto<SoftSphereSolver>(*scheduler, settings);
425  } else {
426  solver = makeAuto<HardSphereSolver>(*scheduler, settings);
427  }
428 
430  solver->create(*storage, mtl);
431 
432  setPersistentIndices(*storage);
433  }
434 
435  virtual void tearDown(const Storage& storage, const Statistics& stats) override {
436  output->dump(storage, stats);
437  }
438 };
439 
440 NBodyJob::NBodyJob(const std::string& name, const RunSettings& overrides)
441  : IRunJob(name) {
442 
443  settings = getDefaultSettings(name);
444  settings.addEntries(overrides);
445 }
446 
447 RunSettings NBodyJob::getDefaultSettings(const std::string& name) {
448  const Interval timeRange(0, 1.e6_f);
449  RunSettings settings;
450  settings.set(RunSettingsId::RUN_NAME, name)
458  .set(RunSettingsId::RUN_END_TIME, timeRange.upper())
459  .set(RunSettingsId::RUN_OUTPUT_INTERVAL, timeRange.size() / 10)
478  return settings;
479 }
480 
482  VirtualSettings connector;
483  addGenericCategory(connector, instName);
484  addTimeSteppingCategory(connector, settings, isResumed);
485  addGravityCategory(connector, settings);
486 
487  VirtualSettings::Category& aggregateCat = connector.addCategory("Aggregates (experimental)");
488  aggregateCat.connect<bool>("Enable aggregates", settings, RunSettingsId::NBODY_AGGREGATES_ENABLE);
489  aggregateCat.connect<EnumWrapper>("Initial aggregates", settings, RunSettingsId::NBODY_AGGREGATES_SOURCE)
490  .setEnabler([this] { return settings.get<bool>(RunSettingsId::NBODY_AGGREGATES_ENABLE); });
491 
492  VirtualSettings::Category& softCat = connector.addCategory("Soft-body physics (experimental)");
493  softCat.connect("Enable soft-body", "soft.enable", useSoft);
494  softCat.connect<Float>("Repel force strength", settings, RunSettingsId::SOFT_REPEL_STRENGTH)
495  .setEnabler([this] { return useSoft; });
496  softCat.connect<Float>("Friction force strength", settings, RunSettingsId::SOFT_FRICTION_STRENGTH)
497  .setEnabler([this] { return useSoft; });
498 
499  auto collisionEnabler = [this] {
500  return !useSoft && !settings.get<bool>(RunSettingsId::NBODY_AGGREGATES_ENABLE) &&
503  };
504  auto mergeLimitEnabler = [this] {
505  if (useSoft) {
506  return false;
507  }
508  const CollisionHandlerEnum handler =
510  if (handler == CollisionHandlerEnum::NONE) {
511  return false;
512  }
513  const bool aggregates = settings.get<bool>(RunSettingsId::NBODY_AGGREGATES_ENABLE);
514  const OverlapEnum overlap = settings.get<OverlapEnum>(RunSettingsId::COLLISION_OVERLAP);
515  return aggregates || handler == CollisionHandlerEnum::MERGE_OR_BOUNCE ||
517  };
518 
519  VirtualSettings::Category& collisionCat = connector.addCategory("Collisions");
520  collisionCat.connect<EnumWrapper>("Collision handler", settings, RunSettingsId::COLLISION_HANDLER)
521  .setEnabler([this] { //
522  return !useSoft && !settings.get<bool>(RunSettingsId::NBODY_AGGREGATES_ENABLE);
523  });
524  collisionCat.connect<EnumWrapper>("Overlap handler", settings, RunSettingsId::COLLISION_OVERLAP)
525  .setEnabler(collisionEnabler);
526  collisionCat.connect<Float>("Normal restitution", settings, RunSettingsId::COLLISION_RESTITUTION_NORMAL)
527  .setEnabler(collisionEnabler);
528  collisionCat
529  .connect<Float>("Tangential restitution", settings, RunSettingsId::COLLISION_RESTITUTION_TANGENT)
530  .setEnabler(collisionEnabler);
531  collisionCat.connect<Float>("Merge velocity limit", settings, RunSettingsId::COLLISION_BOUNCE_MERGE_LIMIT)
532  .setEnabler(mergeLimitEnabler);
533  collisionCat
534  .connect<Float>("Merge rotation limit", settings, RunSettingsId::COLLISION_ROTATION_MERGE_LIMIT)
535  .setEnabler(mergeLimitEnabler);
536 
537  addLoggerCategory(connector, settings);
538  addOutputCategory(connector, settings, *this);
539  return connector;
540 }
541 
542 AutoPtr<IRun> NBodyJob::getRun(const RunSettings& overrides) const {
543  RunSettings run = overrideSettings(settings, overrides, isResumed);
544  return makeAuto<NBodyRun>(run, useSoft);
545 }
546 
547 static JobRegistrar sRegisterNBody(
548  "N-body run",
549  "simulations",
550  [](const std::string& name) { return makeAuto<NBodyJob>(name, EMPTY_SETTINGS); },
551  "Runs N-body simulation using given initial conditions.");
552 
553 
AggregateEnum
#define SPH_ASSERT(x,...)
Definition: Assert.h:94
NAMESPACE_SPH_BEGIN
Definition: BarnesHut.cpp:13
const EmptyFlags EMPTY_FLAGS
Definition: Flags.h:16
uint32_t Size
Integral type used to index arrays (by default).
Definition: Globals.h:16
double Float
Precision used withing the code. Use Float instead of float or double where precision is important.
Definition: Globals.h:13
Basic interface defining a single run.
VirtualSettings::Category & addGenericCategory(VirtualSettings &connector, std::string &instanceName)
Adds a common settings category, used by all jobs.
Definition: Job.cpp:43
Logging routines of the run.
#define NAMESPACE_SPH_END
Definition: Object.h:12
Saving and loading particle data.
@ NBODY
Main N-body simulation, using initial conditions either from SPH (handoff) or manually specified.
NAMESPACE_SPH_BEGIN std::string getIdentifier(const std::string &name)
Definition: Project.h:12
Additional bindings to IVirtualSettings.
Helper solver used to converge into stable initial conditions.
@ RUN_TIME
Current time of the simulation in code units. Does not necessarily have to be 0 when run starts.
void setPersistentIndices(Storage &storage)
Adds or updates a quantity holding particle indices to the storage.
Definition: Storage.cpp:865
std::string replaceAll(const std::string &source, const std::string &old, const std::string &s)
Replaces all occurences of string with a new string.
std::string lowercase(const std::string &s)
Converts all uppercase characters to their lowercase variants. Other characters are unchanged.
Definition: StringUtils.cpp:94
Wrapper of an integral value providing functions for reading and modifying individual bits.
Definition: Flags.h:20
constexpr INLINE bool has(const TEnum flag) const
Checks if the object has a given flag.
Definition: Flags.h:77
constexpr INLINE bool hasAny(const TEnum flag, const TArgs... others) const
Checks if the object has any of given flags.
Definition: Flags.h:83
std::string instName
Definition: Job.h:100
Base class for objects logging run statistics.
Definition: LogWriter.h:10
SharedPtr< ILogger > logger
Definition: LogWriter.h:12
ILogWriter(const SharedPtr< ILogger > &logger, const Float period=0._f)
Constructs the log file.
Definition: LogWriter.cpp:12
void write(TArgs &&... args)
Creates and logs a message by concatenating arguments.
Definition: Logger.h:37
virtual Expected< Path > dump(const Storage &storage, const Statistics &stats)=0
Saves data from particle storage into the file.
Base class for jobs running a simulation.
Definition: Job.h:266
Defines the interface for a run.
Definition: IRun.h:61
SharedPtr< IScheduler > scheduler
Scheduler used for parallelization.
Definition: IRun.h:75
SharedPtr< ILogger > logger
Logging.
Definition: IRun.h:69
AutoPtr< IOutput > output
Data output.
Definition: IRun.h:66
Statistics run(Storage &storage)
Runs the simulation.
Definition: IRun.cpp:187
AutoPtr< ISolver > solver
Solver.
Definition: IRun.h:81
RunSettings settings
Definition: IRun.h:63
virtual void create(Storage &storage, IMaterial &material) const =0
Initializes all quantities needed by the solver in the storage.
Object representing a 1D interval of real numbers.
Definition: Interval.h:17
INLINE Float lower() const
Returns lower bound of the interval.
Definition: Interval.h:74
INLINE Float upper() const
Returns upper bound of the interval.
Definition: Interval.h:79
INLINE Float size() const
Returns the size of the interval.
Definition: Interval.h:89
static RunSettings getDefaultSettings(const std::string &name)
virtual AutoPtr< IRun > getRun(const RunSettings &overrides) const override
Returns the actual simulation object.
virtual VirtualSettings getSettings() override
Returns a settings object which allows to query and modify the state of the job.
NBodyJob(const std::string &name, const RunSettings &overrides=EMPTY_SETTINGS)
virtual void setUp(SharedPtr< Storage > storage) override
Prepares the run, creates logger, output, ...
NBodyRun(const RunSettings &run, const bool useSoft)
virtual void tearDown(const Storage &storage, const Statistics &stats) override
Called after the run.
Material that does not require any initialization or finalization.
Definition: IMaterial.h:200
Object representing a path on a filesystem.
Definition: Path.h:17
Path & replaceExtension(const std::string &newExtension)
Changes the extension of the file.
Definition: Path.cpp:76
std::string native() const
Returns the native version of the path.
Definition: Path.cpp:71
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.
Definition: Settings.h:326
static const Settings & getDefaults()
\brief Returns a reference to object containing default values of all settings.
Flags< TValue > getFlags(const TEnum idx) const
Returns Flags from underlying value stored in settings.
Definition: Settings.h:348
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.
Definition: Settings.h:226
void addEntries(const Settings &settings)
Adds entries from different Settings object into this one, overriding current entries.
Definition: Settings.h:297
Size size() const
Returns the number of entries in the settings.
virtual AutoPtr< IRun > getRun(const RunSettings &overrides) const override
Returns the actual simulation object.
bool isResumed
RunSettings settings
Definition: SimulationJobs.h:9
virtual VirtualSettings getSettings() override
Returns a settings object which allows to query and modify the state of the job.
static RunSettings getDefaultSettings(const std::string &name)
SphJob(const std::string &name, const RunSettings &overrides=EMPTY_SETTINGS)
virtual void setUp(SharedPtr< Storage > storage) override
Prepares the run, creates logger, output, ...
SphRun(const RunSettings &run, SharedPtr< IDomain > domain)
SharedPtr< IDomain > domain
virtual void tearDown(const Storage &storage, const Statistics &stats) override
Called after the run.
virtual VirtualSettings getSettings() override
Returns a settings object which allows to query and modify the state of the job.
virtual AutoPtr< IRun > getRun(const RunSettings &overrides) const override
Returns the actual simulation object.
virtual void setUp(SharedPtr< Storage > storage) override
Prepares the run, creates logger, output, ...
Object holding various statistics about current run.
Definition: Statistics.h:22
TValue get(const StatisticsId idx) const
Returns value of a statistic.
Definition: Statistics.h:88
Container storing all quantities used within the simulations.
Definition: Storage.h:230
Size getMaterialCnt() const
Return the number of materials in the storage.
Definition: Storage.cpp:437
MaterialView getMaterial(const Size matIdx) const
Returns an object containing a reference to given material.
Definition: Storage.cpp:366
Returns the total energy of all particles.
Definition: Integrals.h:132
virtual Float evaluate(const Storage &storage) const override
Computes the integral quantity using particles in the storage.
Definition: Integrals.cpp:69
Variant, an implementation of type-safe union, similar to std::variant or boost::variant.
Definition: Variant.h:171
INLINE T & get()
Returns the stored value.
Definition: Variant.h:335
EntryControl & connect(const std::string &name, const std::string &key, TValue &value)
Connects to given reference.
Holds a map of virtual entries, associated with a unique name.
Category & addCategory(const std::string &name)
Creates a new category of entries.
Optional< std::string > getIoExtension(const IoEnum type)
Returns the file extension associated with given IO type.
Definition: Settings.cpp:343
Flags< IoCapability > getIoCapabilities(const IoEnum type)
Returns the capabilities of given file format.
Definition: Settings.cpp:412
CollisionHandlerEnum
Definition: Settings.h:808
@ NONE
No collision handling.
ForceEnum
Definition: Settings.h:658
@ PRESSURE
Use force from pressure gradient in the solver.
@ SELF_GRAVITY
Use gravitational force in the model.
LoggerEnum
Definition: Settings.h:846
@ FILE
Print log to file.
@ KD_TREE
Using K-d tree.
TimeStepCriterionEnum
Definition: Settings.h:567
@ DIVERGENCE
Time step computed from velocity divergence.
@ DERIVATIVES
Time step computed by limiting value-to-derivative ratio of quantiites.
@ COURANT
Time step determined using CFL condition.
@ ACCELERATION
Time step computed from ratio of acceleration and smoothing length.
const EmptySettingsTag EMPTY_SETTINGS
Definition: Settings.h:32
GravityEnum
Definition: Settings.h:785
@ BARNES_HUT
Use Barnes-Hut algorithm, approximating gravity by multipole expansion (up to octupole order)
OutputSpacing
Definition: Settings.h:918
@ CUSTOM
User-defined list of output times.
IoEnum
Definition: Settings.h:859
@ TEXT_FILE
Formatted human-readable text file.
@ NONE
No input/output.
@ LEAP_FROG
Leap-frog 2nd-order integration.
@ PREDICTOR_CORRECTOR
Predictor-corrector scheme.
@ STANDARD
P_i / rho_i^2 + P_j / rho_j^2.
@ OUTPUT
The format can be used as file output.
@ SPH_KERNEL
Use gravity smoothing kernel corresponding to selected SPH kernel.
OverlapEnum
Definition: Settings.h:826
SolverEnum
Definition: Settings.h:697
@ ASYMMETRIC_SOLVER
Generic solver evaluating all derivatives asymmetrically.
ArtificialViscosityEnum
Definition: Settings.h:683
@ STANDARD
Standard artificial viscosity term by Monaghan (1989).
@ NONE
No artificial viscosity.
@ CUBIC_SPLINE
M4 B-spline (piecewise cubic polynomial)
BoundaryEnum
Definition: Settings.h:604
@ NONE
Do not use any boundary conditions (= vacuum conditions)
SmoothingLengthEnum
Definition: Settings.h:768
@ RUN_OUTPUT_QUANTITIES
List of quantities to write to text output. Binary output always stores all quantitites.
@ SPH_SCRIPT_FILE
Path of an arbitrary ChaiScript script executed each timestep.
@ SPH_STRAIN_RATE_CORRECTION_TENSOR
@ RUN_OUTPUT_INTERVAL
Time interval of dumping data to disk.
@ SPH_CONTINUITY_MODE
Specifies how the density is evolved, see ContinuityEnum.
@ TIMESTEPPING_MAX_TIMESTEP
@ SPH_AV_STRESS_FACTOR
Multiplicative factor of the artificial stress term (= strength of the viscosity)
@ RUN_LOGGER
Selected logger of a run, see LoggerEnum.
@ RUN_VERBOSE_NAME
Path of a file where the verbose log is printed.
@ SPH_AV_STRESS_EXPONENT
Weighting function exponent n in artificial stress term.
@ SPH_USE_AC
Enables the artificial thermal conductivity term.
@ FINDER_LEAF_SIZE
Maximum number of particles in a leaf node.
@ SOFT_REPEL_STRENGTH
Magnitude of the repel force for the soft-body solver.
@ SPH_KERNEL
Index of SPH Kernel, see KernelEnum.
@ RUN_OUTPUT_SPACING
Type of output spacing in time, see enum OutputSpacing.
@ COLLISION_HANDLER
Specifies how the collisions of particles should be handler; see CollisionHandlerEnum.
@ SPH_SOLVER_FORCES
List of forces to compute by the solver.
@ SPH_AV_TYPE
Type of used artificial viscosity.
@ RUN_LOGGER_FILE
Path of a file where the log is printed, used only when selected logger is LoggerEnum::FILE.
@ SPH_AV_BETA
Artificial viscosity beta coefficient.
@ SPH_AV_ALPHA
Artificial viscosity alpha coefficient.
@ RUN_OUTPUT_PATH
Path where all output files (dumps, logs, ...) will be written.
@ SPH_SOLVER_TYPE
Selected solver for computing derivatives of physical variables.
@ NBODY_MAX_ROTATION_ANGLE
@ RUN_DIAGNOSTICS_INTERVAL
@ TIMESTEPPING_INITIAL_TIMESTEP
@ COLLISION_BOUNCE_MERGE_LIMIT
@ SPH_ADAPTIVE_SMOOTHING_LENGTH
Solution for evolutions of the smoothing length.
@ SPH_AV_USE_STRESS
Whether to use artificial stress.
@ GRAVITY_SOLVER
Algorithm to compute gravitational acceleration.
@ RUN_OUTPUT_CUSTOM_TIMES
List of comma-separated output times, used when RUN_OUTPUT_SPACING is set to CUSTOM.
@ TIMESTEPPING_DERIVATIVE_FACTOR
Multiplicative factor k for the derivative criterion; dt = k * v / dv.
@ SPH_SMOOTHING_LENGTH_MIN
Minimal value of smoothing length.
@ SPH_USE_XSPH
Turn on the XSPH correction.
@ COLLISION_ALLOWED_OVERLAP
@ SPH_DISCRETIZATION
Specifies a discretization of SPH equations; see DiscretizationEnum.
@ RUN_OUTPUT_TYPE
Selected format of the output file, see IoEnum.
@ SPH_VELOCITY_DIFFUSION_ALPHA
Alpha-coefficient of the delta-SPH modification.
@ RUN_OUTPUT_FIRST_INDEX
Index of the first generated output file. Might not be zero if the simulation is resumed.
@ NBODY_AGGREGATES_SOURCE
Specifies the initial aggregates used in the simulation. See AggregateEnum.
@ TIMESTEPPING_INTEGRATOR
Selected timestepping integrator.
@ TIMESTEPPING_MAX_INCREASE
@ COLLISION_RESTITUTION_TANGENT
@ GRAVITY_MULTIPOLE_ORDER
Order of multipole expansion.
@ TIMESTEPPING_COURANT_NUMBER
Courant number.
@ SPH_FINDER
Structure for searching nearest neighbours of particles.
@ COLLISION_ROTATION_MERGE_LIMIT
@ SOFT_FRICTION_STRENGTH
Magnitude of the friction force for the soft-body solver.
@ COLLISION_OVERLAP
Specifies how particle overlaps should be handled.
@ SPH_DENSITY_DIFFUSION_DELTA
Delta-coefficient of the delta-SPH modification, see Marrone et al. 2011.
@ RUN_LOGGER_VERBOSITY
Number specifying log verbosity. Can be between 0 and 3, going from least to most verbose.
@ SPH_SCRIPT_ENABLE
Enables or disables scripted term.
@ TIMESTEPPING_DIVERGENCE_FACTOR
Multiplicative factor for the divergence criterion.
@ RUN_NAME
User-specified name of the run, used in some output files.
@ GRAVITY_RECOMPUTATION_PERIOD
@ GRAVITY_OPENING_ANGLE
Opening angle Theta for multipole approximation of gravity.
@ SPH_USE_DELTASPH
Turn on the delta-SPH correction.
@ DOMAIN_BOUNDARY
Type of boundary conditions.
@ SPH_SCRIPT_ONESHOT
Whether to execute the script only once or periodically.
@ SPH_STABILIZATION_DAMPING
@ GRAVITY_KERNEL
Gravity smoothing kernel.
@ SPH_ASYMMETRIC_COMPUTE_RADII_HASH_MAP
@ SPH_AC_SIGNAL_SPEED
Type of the signal speed used by artificial conductivity.
@ FRAME_CONSTANT_ACCELERATION
@ COLLISION_RESTITUTION_NORMAL
@ RUN_OUTPUT_NAME
File name of the output file (including extension), where d is a placeholder for output number.
constexpr Float R_earth
Earth radius.
Definition: Constants.h:60
constexpr Float M_earth
Earth mass.
Definition: Constants.h:54
AutoPtr< ISolver > getSolver(IScheduler &scheduler, const RunSettings &settings)
Definition: Factory.cpp:278
AutoPtr< ILogger > getLogger(const RunSettings &settings)
Definition: Factory.cpp:529
AutoPtr< IBoundaryCondition > getBoundaryConditions(const RunSettings &settings, SharedPtr< IDomain > domain)
Definition: Factory.cpp:460
SharedPtr< IScheduler > getScheduler(const RunSettings &settings=RunSettings::getDefaults())
Definition: Factory.cpp:178
Wrapper of an enum.
Definition: Settings.h:37
Helper class, allowing to register job into the global list of jobs.
Definition: Job.h:203