21 Float wallclockDuraction;
26 : wallclockDuraction(wallclockDuraction)
27 , timestepCnt(timestepCnt) {}
33 if (timestepCnt > 0 && timestep >= timestepCnt) {
42 SPH_ASSERT(
false,
"Invalid configuration, asserts should be only enabled in debug builds");
64 , diagnostics(diagnostics)
65 , callbacks(callbacks)
69 logger->
write(
"Running simulation diagnostics");
71 for (
auto& diag : diagnostics) {
79 logger->
write(
" - no problems detected");
150 for (
const std::string& item : items) {
152 times.
push(std::stof(item));
153 }
catch (
const std::invalid_argument&) {
154 throw InvalidSetup(
"Cannot convert '" + item +
"' to a number");
157 if (!std::is_sorted(times.
begin(), times.
end())) {
158 throw InvalidSetup(
"Output times must be in ascending order");
163 if (!times.
empty()) {
177 return makeAuto<LinearOutputTime>(settings);
179 return makeAuto<LogarithmicOutputTime>(settings);
181 return makeAuto<CustomOutputTime>(settings);
189 return this->
run(input, callbacks);
206 this->
setUp(storage);
228 callbacks.
onSetUp(*storage, stats);
233 for (
Float t = timeRange.
lower(); t < timeRange.
upper() && !condition(runTimer, i);
239 SPH_ASSERT(progress >= 0._f && progress <= 1._f);
244 if (
output && nextOutput && t >= nextOutput.
value()) {
249 nextOutput = outputTime->getNextTime();
292 input = std::move(*storage);
352 run.
run(storage, callbacks);
#define SPH_ASSERT(x,...)
#define NOT_IMPLEMENTED
Helper macro marking missing implementation.
Looking for problems in SPH simulation and reporting potential errors.
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.
Base class for all particle materials.
Outcome doRun(Storage &storage, const RunSettings &settings)
Runs a simulation using provided storage as initial conditions.
AutoPtr< IOutputTime > getOutputTimes(const RunSettings &settings)
Basic interface defining a single run.
Base interface for all solvers.
Integrals of motion and other integral quantities.
void setVerboseLogger(AutoPtr< ILogger > &&logger)
Creates a global verbose logger.
Logging routines of the run.
#define NAMESPACE_SPH_END
const NothingType NOTHING
const SuccessTag SUCCESS
Global constant for successful outcome.
INLINE Outcome makeFailed(TArgs &&... args)
Constructs failed object with error message.
Saving and loading particle data.
Simple thread pool with fixed number of threads.
Statistics gathered and periodically displayed during the run.
@ WALLCLOCK_TIME
Current wallclock duration of the simulation.
@ RUN_TIME
Current time of the simulation in code units. Does not necessarily have to be 0 when run starts.
@ TIMESTEP_VALUE
Current value of timestep.
@ INDEX
Current number of time step, indexed from 0.
Array< std::string > split(const std::string &s, const char delimiter)
Splits a string into an array of string using given delimiter.
Algorithms for temporal evolution of the physical model.
Measuring time intervals and executing periodic events.
Triggers of auxiliary actions during the run.
@ ONE_TIME
Execute the trigger only once.
Object providing safe access to continuous memory of data.
INLINE Iterator< StorageType > end() noexcept
INLINE void push(U &&u)
Adds new element to the end of the array, resizing the array if necessary.
void remove(const TCounter idx)
Removes an element with given index from the array.
INLINE T & front() noexcept
INLINE bool empty() const noexcept
INLINE Iterator< StorageType > begin() noexcept
Wrapper of pointer that deletes the resource from destructor.
Expected-like class that does not contain any value.
INLINE const TError & error() const
Returns the error message.
virtual Optional< Float > getNextTime() override
CustomOutputTime(const RunSettings &settings)
DiagnosticsTrigger(ArrayView< const AutoPtr< IDiagnostic >> diagnostics, RawPtr< IRunCallbacks > callbacks, SharedPtr< ILogger > logger, const Float period)
virtual AutoPtr< ITrigger > action(Storage &storage, Statistics &stats)
Action executed when the condition is fulfilled.
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.
@ ADD_TIMESTAMP
Adds a time of writing before each message.
virtual void write(const Storage &storage, const Statistics &stats)=0
Writes to the log using provided storage and statistics.
void write(TArgs &&... args)
Creates and logs a message by concatenating arguments.
virtual Optional< Float > getNextTime()=0
virtual Expected< Path > dump(const Storage &storage, const Statistics &stats)=0
Saves data from particle storage into the file.
Callbacks executed by the simulation to provide feedback to the user.
virtual bool shouldAbortRun() const =0
Returns whether current run should be aborted or not.
virtual void onSetUp(const Storage &storage, Statistics &stats)=0
Called right before the run starts, i.e. after initial conditions are set up.
virtual void onTimeStep(const Storage &storage, Statistics &stats)=0
Called every timestep.
Defines the interface for a run.
SharedPtr< IScheduler > scheduler
Scheduler used for parallelization.
AutoPtr< ILogWriter > logWriter
Writes statistics into logger every timestep.
AutoPtr< ITimeStepping > timeStepping
Timestepping.
SharedPtr< ILogger > logger
Logging.
AutoPtr< IOutput > output
Data output.
void tearDownInternal(const Storage &storage, const Statistics &stats)
Statistics run(Storage &storage)
Runs the simulation.
virtual void setUp(SharedPtr< Storage > storage)=0
Prepares the run, creates logger, output, ...
List< AutoPtr< ITrigger > > triggers
Triggers.
AutoPtr< ISolver > solver
Solver.
void setNullToDefaults(SharedPtr< Storage > storage)
virtual void tearDown(const Storage &storage, const Statistics &stats)=0
Called after the run.
virtual void create(Storage &storage, IMaterial &material) const =0
Initializes all quantities needed by the solver in the storage.
INLINE Float getTimeStep() const
void step(IScheduler &scheduler, ISolver &solver, Statistics &stats)
Interface for triggering generic actions during the run.
virtual TriggerEnum type() const =0
Returns the type of the trigger.
virtual bool condition(const Storage &storage, const Statistics &stats)=0
Returns true if the trigger should be executed.
virtual AutoPtr< ITrigger > action(Storage &storage, Statistics &stats)=0
Action executed when the condition is fulfilled.
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.
Thrown when components of the run are mutually incompatible.
LinearOutputTime(const RunSettings &settings)
virtual Optional< Float > getNextTime() override
ListIterator< T > end()
Returns a bidirectional iterator pointing to the one-past-last element of the list.
void clear()
Removes all elements from the list.
void pushBack(U &&value)
Adds a new element to the back of the list.
ListIterator< T > erase(const ListIterator< T > iter)
Removes an element given by the iterator.
ListIterator< T > begin()
Returns a bidirectional iterator pointing to the first element of the list.
LogarithmicOutputTime(const RunSettings &settings)
virtual Optional< Float > getNextTime() override
virtual void onSetUp(const Storage &, Statistics &) override
Called right before the run starts, i.e. after initial conditions are set up.
virtual bool shouldAbortRun() const override
Returns whether current run should be aborted or not.
virtual void onTimeStep(const Storage &, Statistics &) override
Called every timestep.
INLINE Type & value()
Returns the reference to the stored value.
Object representing a path on a filesystem.
Trigger executing given action every period.
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.
SimpleRun(const RunSettings &settings)
virtual void tearDown(const Storage &UNUSED(storage), const Statistics &UNUSED(stats)) override
virtual void setUp(SharedPtr< Storage > UNUSED(storage)) override
Object holding various statistics about current run.
Statistics & set(const StatisticsId idx, TValue &&value)
Sets new values of a statistic.
Container storing all quantities used within the simulations.
Size getMaterialCnt() const
Return the number of materials in the storage.
void setUserData(SharedPtr< IStorageUserData > newData)
Stores new user data into the storage.
MaterialView getMaterial(const Size matIdx) const
Returns an object containing a reference to given material.
static SharedPtr< ThreadPool > getGlobalInstance()
Returns the global instance of the thread pool.
Basic time-measuring tool. Starts automatically when constructed.
int64_t elapsed(const TimerUnit unit) const
Returns elapsed time in timer units. Does not reset the timer.
Creating code components based on values from settings.
@ CUSTOM
User-defined list of output times.
@ LINEAR
Constant time between consecutive output times.
@ LOGARITHMIC
Constant ratio between consecutive output times.
@ RUN_OUTPUT_INTERVAL
Time interval of dumping data to disk.
@ RUN_VERBOSE_NAME
Path of a file where the verbose log is printed.
@ RUN_OUTPUT_SPACING
Type of output spacing in time, see enum OutputSpacing.
@ RUN_OUTPUT_PATH
Path where all output files (dumps, logs, ...) will be written.
@ TIMESTEPPING_INITIAL_TIMESTEP
@ RUN_OUTPUT_CUSTOM_TIMES
List of comma-separated output times, used when RUN_OUTPUT_SPACING is set to CUSTOM.
@ RUN_NAME
User-specified name of the run, used in some output files.
@ RUN_VERBOSE_ENABLE
Enables verbose log of a simulation.
AutoPtr< IOutput > getOutput(const RunSettings &settings)
AutoPtr< ISolver > getSolver(IScheduler &scheduler, const RunSettings &settings)
AutoPtr< ITimeStepping > getTimeStepping(const RunSettings &settings, const SharedPtr< Storage > &storage)
AutoPtr< ILogWriter > getLogWriter(SharedPtr< ILogger > logger, const RunSettings &settings)
AutoPtr< ILogger > getLogger(const RunSettings &settings)
SharedPtr< IScheduler > getScheduler(const RunSettings &settings=RunSettings::getDefaults())
EndingCondition(const Float wallclockDuraction, const Size timestepCnt)
bool operator()(const Timer &timer, const Size timestep)
Base class for all polymorphic objects.