26 std::string escaped =
replaceAll(name,
" ",
"-");
36 const bool isResumed) {
52 auto courantEnabler = [&settings] {
57 auto derivativeEnabler = [&settings] {
62 auto divergenceEnabler = [&settings] {
70 rangeCat.
connect(
"Use start time of input",
"is_resumed", resumeRun);
77 .setEnabler(courantEnabler);
79 .setEnabler(derivativeEnabler);
81 .setEnabler(divergenceEnabler);
89 .setEnabler([&settings] {
99 auto enabler = [&settings] {
125 .setEnabler([&settings] {
130 .setEnabler(enabler);
190 const Size dumpCnt = 10;
233 auto stressEnabler = [
this] {
236 auto avEnabler = [
this] {
243 auto enforceEnabler = [
this] {
266 .setEnabler(enforceEnabler);
268 .setEnabler(enforceEnabler);
276 .setEnabler(stressEnabler);
285 .setEnabler(avEnabler);
287 .setEnabler(avEnabler);
289 .setEnabler(avEnabler);
292 .setEnabler(asEnabler);
294 .setEnabler(asEnabler);
306 .setEnabler(deltaSphEnabler);
308 .setEnabler(deltaSphEnabler);
315 .setEnabler(scriptEnabler)
317 .setFileFormats({ {
"Chaiscript script",
"chai" } });
319 .setEnabler(scriptEnabler);
321 .setEnabler(scriptEnabler);
323 addGravityCategory(connector,
settings);
324 addOutputCategory(connector,
settings, *
this);
325 addLoggerCategory(connector,
settings);
335 domain = this->getInput<IDomain>(
"boundary");
343 return makeAuto<SphRun>(run, domain);
349 [](
const std::string& name) {
return makeAuto<SphJob>(name,
EMPTY_SETTINGS); },
350 "Runs a SPH simulation, using provided initial conditions.");
384 domain = this->getInput<IDomain>(
"boundary");
386 return makeAuto<SphStabilizationRun>(run, domain);
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 "
419 if (aggregateEnable) {
421 aggregates->createAggregateData(*storage, aggregateSource);
422 solver = std::move(aggregates);
423 }
else if (useSoft) {
444 settings.addEntries(overrides);
448 const Interval timeRange(0, 1.e6_f);
484 addTimeSteppingCategory(connector, settings, isResumed);
485 addGravityCategory(connector, settings);
493 softCat.
connect(
"Enable soft-body",
"soft.enable", useSoft);
495 .setEnabler([
this] {
return useSoft; });
497 .setEnabler([
this] {
return useSoft; });
499 auto collisionEnabler = [
this] {
504 auto mergeLimitEnabler = [
this] {
525 .setEnabler(collisionEnabler);
527 .setEnabler(collisionEnabler);
530 .setEnabler(collisionEnabler);
532 .setEnabler(mergeLimitEnabler);
535 .setEnabler(mergeLimitEnabler);
537 addLoggerCategory(connector, settings);
538 addOutputCategory(connector, settings, *
this);
543 RunSettings run = overrideSettings(settings, overrides, isResumed);
544 return makeAuto<NBodyRun>(run, useSoft);
550 [](
const std::string& name) {
return makeAuto<NBodyJob>(name,
EMPTY_SETTINGS); },
551 "Runs N-body simulation using given initial conditions.");
#define SPH_ASSERT(x,...)
const EmptyFlags EMPTY_FLAGS
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.
Basic interface defining a single run.
VirtualSettings::Category & addGenericCategory(VirtualSettings &connector, std::string &instanceName)
Adds a common settings category, used by all jobs.
Logging routines of the run.
#define NAMESPACE_SPH_END
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)
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.
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.
Wrapper of an integral value providing functions for reading and modifying individual bits.
constexpr INLINE bool has(const TEnum flag) const
Checks if the object has a given flag.
constexpr INLINE bool hasAny(const TEnum flag, const TArgs... others) const
Checks if the object has any of given flags.
Base class for objects logging run statistics.
SharedPtr< ILogger > logger
ILogWriter(const SharedPtr< ILogger > &logger, const Float period=0._f)
Constructs the log file.
void write(TArgs &&... args)
Creates and logs a message by concatenating arguments.
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.
Defines the interface for a run.
SharedPtr< IScheduler > scheduler
Scheduler used for parallelization.
SharedPtr< ILogger > logger
Logging.
AutoPtr< IOutput > output
Data output.
Statistics run(Storage &storage)
Runs the simulation.
AutoPtr< ISolver > solver
Solver.
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.
INLINE Float lower() const
Returns lower bound of the interval.
INLINE Float upper() const
Returns upper bound of the interval.
INLINE Float size() const
Returns the size of the interval.
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.
Object representing a path on a filesystem.
Path & replaceExtension(const std::string &newExtension)
Changes the extension of the file.
std::string native() const
Returns the native version of the path.
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.
Flags< TValue > getFlags(const TEnum idx) const
Returns Flags from underlying value stored in 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.
void addEntries(const Settings &settings)
Adds entries from different Settings object into this one, overriding current entries.
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.
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.
TValue get(const StatisticsId idx) const
Returns value of a statistic.
Container storing all quantities used within the simulations.
Size getMaterialCnt() const
Return the number of materials in the storage.
MaterialView getMaterial(const Size matIdx) const
Returns an object containing a reference to given material.
Returns the total energy of all particles.
virtual Float evaluate(const Storage &storage) const override
Computes the integral quantity using particles in the storage.
Variant, an implementation of type-safe union, similar to std::variant or boost::variant.
INLINE T & get()
Returns the stored value.
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.
Flags< IoCapability > getIoCapabilities(const IoEnum type)
Returns the capabilities of given file format.
@ NONE
No collision handling.
@ PRESSURE
Use force from pressure gradient in the solver.
@ SELF_GRAVITY
Use gravitational force in the model.
@ 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
@ BARNES_HUT
Use Barnes-Hut algorithm, approximating gravity by multipole expansion (up to octupole order)
@ CUSTOM
User-defined list of output times.
@ TEXT_FILE
Formatted human-readable text file.
@ 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.
@ ASYMMETRIC_SOLVER
Generic solver evaluating all derivatives asymmetrically.
@ STANDARD
Standard artificial viscosity term by Monaghan (1989).
@ NONE
No artificial viscosity.
@ CUBIC_SPLINE
M4 B-spline (piecewise cubic polynomial)
@ NONE
Do not use any boundary conditions (= vacuum conditions)
@ 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_NEIGHBOUR_ENFORCING
@ 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.
@ NBODY_AGGREGATES_ENABLE
@ 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.
constexpr Float M_earth
Earth mass.
AutoPtr< ISolver > getSolver(IScheduler &scheduler, const RunSettings &settings)
AutoPtr< ILogger > getLogger(const RunSettings &settings)
AutoPtr< IBoundaryCondition > getBoundaryConditions(const RunSettings &settings, SharedPtr< IDomain > domain)
SharedPtr< IScheduler > getScheduler(const RunSettings &settings=RunSettings::getDefaults())
Helper class, allowing to register job into the global list of jobs.