SPH
SimpleCollision.cpp
Go to the documentation of this file.
1 #include "Sph.h"
2 #include <iostream>
3 
4 using namespace Sph;
5 
6 // Runs a single impact simulation.
7 class Collision : public IRun {
8 public:
9  virtual void setUp(SharedPtr<Storage> storage) override {
10  InitialConditions ic(settings);
11 
12  BodySettings body;
14 
15  // Domain representing the target asteroid (R = 100km)
16  SphericalDomain targetDomain(Vector(0._f), 1.e5_f);
17  ic.addMonolithicBody(*storage, targetDomain, body);
18 
19  // Add only 100 particles to impatcor
21 
22  // Domain representing the impactor (R = 20km)
23  SphericalDomain impactorDomain(Vector(1.4e5_f, 0._f, 0._f), 2.e4_f);
24 
25  // Function addMonolithicBody returns an object of type BodyView, which allows to add velocity or
26  // rotation to the created body.
27  BodyView impactor = ic.addMonolithicBody(*storage, impactorDomain, body);
28 
29  // Set the impact velocity to 5km/s
30  impactor.addVelocity(Vector(-5.e3_f, 0._f, 0._f));
31 
32  settings.set(RunSettingsId::RUN_NAME, std::string("Simple collision"));
33 
34  // Let's run the simulation for 10 seconds
35  settings.set(RunSettingsId::RUN_END_TIME, 10._f);
36 
37  // Limit the time step by CFL criterion
39 
40  // Set the maximal time step to 0.1s.
41  settings.set(RunSettingsId::TIMESTEPPING_MAX_TIMESTEP, 0.1_f);
42  }
43 
44  virtual void tearDown(const Storage& storage, const Statistics& stats) override {
45  BinaryOutput io(Path("output.ssf"));
46  io.dump(storage, stats);
47  }
48 };
49 
50 int main() {
51  try {
52  Collision simulation;
53  Storage storage;
54  simulation.run(storage);
55  } catch (const Exception& e) {
56  std::cout << "Error during simulation: " << e.what() << std::endl;
57  return -1;
58  }
59  return 0;
60 }
int main()
Includes common headers.
BasicVector< Float > Vector
Definition: Vector.h:539
Output saving data to binary data without loss of precision.
Definition: Output.h:335
virtual Expected< Path > dump(const Storage &storage, const Statistics &stats) override
Saves data from particle storage into the file.
Definition: Output.cpp:512
Non-owning view of particles belonging to the same body.
Definition: Initial.h:20
BodyView & addVelocity(const Vector &v)
Adds a velocity vector to all particles of the body.
Definition: Initial.cpp:38
virtual void setUp(SharedPtr< Storage > storage) override
Prepares the run, creates logger, output, ...
virtual void tearDown(const Storage &storage, const Statistics &stats) override
Called after the run.
Generic exception.
Definition: Exceptions.h:10
virtual const char * what() const noexcept
Definition: Exceptions.h:18
Defines the interface for a run.
Definition: IRun.h:61
Statistics run(Storage &storage)
Runs the simulation.
Definition: IRun.cpp:187
Object for adding one or more bodies with given material into a Storage.
Definition: Initial.h:106
BodyView addMonolithicBody(Storage &storage, const BodySettings &body)
Creates a monolithic body by filling given domain with particles.
Definition: Initial.cpp:81
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
Spherical domain, defined by the center of sphere and its radius.
Definition: Domain.h:102
Object holding various statistics about current run.
Definition: Statistics.h:22
Container storing all quantities used within the simulations.
Definition: Storage.h:230
@ COURANT
Time step determined using CFL condition.
@ PARTICLE_COUNT
Number of SPH particles in the body.
@ TIMESTEPPING_MAX_TIMESTEP
@ RUN_NAME
User-specified name of the run, used in some output files.
Definition: MemoryPool.h:5