SPH
Galaxy.cpp
Go to the documentation of this file.
1 
6 #include "sph/initial/Galaxy.h"
7 #include "Common.h"
8 #include "catch.hpp"
9 
10 using namespace Sph;
11 
12 class GalaxyRun : public IRun {
13 public:
15  settings.set(RunSettingsId::RUN_NAME, std::string("Galaxy Problem"))
21  .set(RunSettingsId::RUN_OUTPUT_PATH, std::string("galaxy"))
22  .set(RunSettingsId::RUN_OUTPUT_NAME, std::string("galaxy_%d.ssf"))
23  .set(RunSettingsId::RUN_END_TIME, 10._f)
33 
34  scheduler = Factory::getScheduler(settings);
35  }
36 
37  virtual void setUp(SharedPtr<Storage> storage) override {
38 
39  GalaxySettings galaxy;
40  galaxy.set(GalaxySettingsId::PARTICLE_RADIUS, 0.001_f);
41 
42  *storage = Galaxy::generateIc(settings, galaxy, Galaxy::NullProgressCallbacks{});
43 
44  solver = makeAuto<HardSphereSolver>(*scheduler, settings);
45 
46  logWriter = makeAuto<NullLogWriter>();
47 
49  triggers.pushBack(makeAuto<ProgressLog>(0.5_f));
50  }
51 
52 protected:
53  virtual void tearDown(const Storage& storage, const Statistics& stats) override {
54  output->dump(storage, stats);
55  }
56 };
57 
58 TEST_CASE("Galaxy", "[galaxy]") {
59  Array<Path> filesToCheck = { Path("galaxy/galaxy_0000.ssf"), Path("galaxy/galaxy_0001.ssf") };
60 
61  for (Path file : filesToCheck) {
63  }
64 
65  measureRun(Path("galaxy/stats"), [] {
66  GalaxyRun run;
67  Storage storage;
68  run.run(storage);
69  });
70 
71  for (Path file : filesToCheck) {
72  REQUIRE(areFilesApproxEqual(file, REFERENCE_DIR / file.fileName()) == SUCCESS);
73  }
74 }
void measureRun(const Path &file, Function< void()> run)
Definition: Common.cpp:67
Outcome areFilesApproxEqual(const Path &path1, const Path &path2)
Checks if two .ssf files are almost equal (may have eps-differences in quantities).
Definition: Common.cpp:29
const SuccessTag SUCCESS
Global constant for successful outcome.
Definition: Outcome.h:141
Generic dynamically allocated resizable storage.
Definition: Array.h:43
virtual void tearDown(const Storage &storage, const Statistics &stats) override
Called after the run.
Definition: Galaxy.cpp:53
GalaxyRun()
Definition: Galaxy.cpp:14
virtual void setUp(SharedPtr< Storage > storage) override
Prepares the run, creates logger, output, ...
Definition: Galaxy.cpp:37
Defines the interface for a run.
Definition: IRun.h:61
Statistics run(Storage &storage)
Runs the simulation.
Definition: IRun.cpp:187
Object representing a path on a filesystem.
Definition: Path.h:17
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
Object holding various statistics about current run.
Definition: Statistics.h:22
Container storing all quantities used within the simulations.
Definition: Storage.h:230
TEST_CASE("Galaxy", "[galaxy]")
Definition: Galaxy.cpp:58
@ ACCELERATION
Time step computed from ratio of acceleration and smoothing length.
@ BINARY_FILE
@ LEAP_FROG
Leap-frog 2nd-order integration.
@ REPEL
Particles are shifted until no overlap happens.
@ RUN_OUTPUT_INTERVAL
Time interval of dumping data to disk.
@ TIMESTEPPING_MAX_TIMESTEP
@ COLLISION_HANDLER
Specifies how the collisions of particles should be handler; see CollisionHandlerEnum.
@ RUN_OUTPUT_PATH
Path where all output files (dumps, logs, ...) will be written.
@ TIMESTEPPING_INITIAL_TIMESTEP
@ TIMESTEPPING_DERIVATIVE_FACTOR
Multiplicative factor k for the derivative criterion; dt = k * v / dv.
@ RUN_OUTPUT_TYPE
Selected format of the output file, see IoEnum.
@ TIMESTEPPING_INTEGRATOR
Selected timestepping integrator.
@ COLLISION_RESTITUTION_TANGENT
@ COLLISION_OVERLAP
Specifies how particle overlaps should be handled.
@ RUN_NAME
User-specified name of the run, used in some output files.
@ GRAVITY_CONSTANT
Gravitational constant. To be generalized.
@ GRAVITY_KERNEL
Gravity smoothing kernel.
@ COLLISION_RESTITUTION_NORMAL
@ RUN_OUTPUT_NAME
File name of the output file (including extension), where d is a placeholder for output number.
SharedPtr< IScheduler > getScheduler(const RunSettings &settings=RunSettings::getDefaults())
Definition: Factory.cpp:178
Outcome removePath(const Path &path, const Flags< RemovePathFlag > flags=EMPTY_FLAGS)
Definition: FileSystem.cpp:137
Storage generateIc(const RunSettings &globals, const GalaxySettings &settings, const IProgressCallbacks &callbacks)
Definition: Galaxy.cpp:422
Definition: MemoryPool.h:5