SPH
Collision.cpp
Go to the documentation of this file.
1 
6 #include "Common.h"
7 #include "catch.hpp"
8 
9 using namespace Sph;
10 
11 class Collision : public IRun {
12 public:
14  settings.set(RunSettingsId::RUN_NAME, std::string("Asteroid Collision Problem"))
21  .set(RunSettingsId::RUN_OUTPUT_PATH, std::string("collision"))
22  .set(RunSettingsId::RUN_OUTPUT_NAME, std::string("collision_%d.ssf"))
23  .set(RunSettingsId::RUN_END_TIME, 500._f)
30  .set(RunSettingsId::SPH_AV_ALPHA, 1.5_f)
31  .set(RunSettingsId::SPH_AV_BETA, 3._f)
43 
44  scheduler = Factory::getScheduler(settings);
45  }
46 
47  virtual void setUp(SharedPtr<Storage> storage) override {
48  BodySettings targetBody;
49  targetBody.set(BodySettingsId::ENERGY, 10._f)
57 
58  BodySettings impactorBody = targetBody;
59  impactorBody.set(BodySettingsId::PARTICLE_COUNT, 100)
62 
63  InitialConditions ic(settings);
64  const Float targetRadius = 10.e3_f;
65  BodyView targetView =
66  ic.addMonolithicBody(*storage, SphericalDomain(Vector(0._f), targetRadius), targetBody);
67 
68  const Float spinRate = 2._f * PI / (3600._f * 4._f); // 4h
69  targetView.addRotation(Vector(0._f, 0._f, spinRate), Vector(0._f));
70 
71  const Float impactAngle = 45._f * DEG_TO_RAD;
72  const Float impactorRadius = 1.e3_f;
73  const Vector impactorOrigin =
74  (targetRadius + impactorRadius) * Vector(cos(impactAngle) + 0.05_f, sin(impactAngle), 0._f);
75  BodyView impactorView =
76  ic.addMonolithicBody(*storage, SphericalDomain(impactorOrigin, impactorRadius), impactorBody);
77  impactorView.addVelocity(Vector(-5.e3_f, 0._f, 0._f));
78 
79  logWriter = makeAuto<NullLogWriter>();
80 
82  triggers.pushBack(makeAuto<ProgressLog>(25._f));
83  }
84 
85 protected:
86  virtual void tearDown(const Storage& storage, const Statistics& stats) override {
87  output->dump(storage, stats);
88  }
89 };
90 
91 TEST_CASE("Collision", "[collision]") {
92  Array<Path> filesToCheck = { Path("collision/collision_0000.ssf"), Path("collision/collision_0001.ssf") };
93 
94  for (Path file : filesToCheck) {
96  }
97 
98  measureRun(Path("collision/stats"), [] {
99  Collision run;
100  Storage storage;
101  run.run(storage);
102  });
103 
104  for (Path file : filesToCheck) {
105  REQUIRE(areFilesApproxEqual(file, REFERENCE_DIR / file.fileName()) == SUCCESS);
106  }
107 }
TEST_CASE("Collision", "[collision]")
Definition: Collision.cpp:91
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 EmptyFlags EMPTY_FLAGS
Definition: Flags.h:16
double Float
Precision used withing the code. Use Float instead of float or double where precision is important.
Definition: Globals.h:13
INLINE T sin(const T f)
Definition: MathUtils.h:296
INLINE T cos(const T f)
Definition: MathUtils.h:291
constexpr Float DEG_TO_RAD
Definition: MathUtils.h:369
constexpr Float INFTY
Definition: MathUtils.h:38
constexpr Float PI
Mathematical constants.
Definition: MathUtils.h:361
constexpr Float LARGE
Definition: MathUtils.h:34
const SuccessTag SUCCESS
Global constant for successful outcome.
Definition: Outcome.h:141
BasicVector< Float > Vector
Definition: Vector.h:539
Generic dynamically allocated resizable storage.
Definition: Array.h:43
Non-owning view of particles belonging to the same body.
Definition: Initial.h:20
BodyView & addRotation(const Vector &omega, const RotationOrigin origin)
Adds an angular velocity to all particles of the body.
Definition: Initial.cpp:72
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, ...
Definition: Collision.cpp:47
virtual void tearDown(const Storage &storage, const Statistics &stats) override
Called after the run.
Definition: Collision.cpp:86
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 1D interval of real numbers.
Definition: Interval.h:17
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
@ PRESSURE
Use force from pressure gradient in the solver.
@ SELF_GRAVITY
Use gravitational force in the model.
@ VON_MISES
Von Mises criterion.
@ KD_TREE
Using K-d tree.
@ COURANT
Time step determined using CFL condition.
@ BARNES_HUT
Use Barnes-Hut algorithm, approximating gravity by multipole expansion (up to octupole order)
@ BINARY_FILE
@ PREDICTOR_CORRECTOR
Predictor-corrector scheme.
@ STANDARD
P_i / rho_i^2 + P_j / rho_j^2.
@ 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).
@ HEXAGONAL
Hexagonally close packing.
@ SCALAR_GRADY_KIPP
Grady-Kipp model of fragmentation using scalar damage.
@ TILLOTSON
Tillotson (1962) equation of state.
@ DAMAGE_MIN
Estimate minimal value of damage used to determine timestepping error.
@ RHEOLOGY_DAMAGE
Model of fragmentation used within the rheological model.
@ INITIAL_DISTRIBUTION
Initial distribution of SPH particles within the domain, see DistributionEnum for options.
@ ENERGY
Initial specific internal energy.
@ PARTICLE_COUNT
Number of SPH particles in the body.
@ STRESS_TENSOR_MIN
Estimated minial value of stress tensor components used to determined timestepping error.
@ EOS
Equation of state for this material, see EosEnum for options.
@ ENERGY_RANGE
Allowed range of specific internal energy.
@ RHEOLOGY_YIELDING
Model of stress reducing used within the rheological model.
@ SPH_STRAIN_RATE_CORRECTION_TENSOR
@ RUN_OUTPUT_INTERVAL
Time interval of dumping data to disk.
@ TIMESTEPPING_MAX_TIMESTEP
@ FINDER_LEAF_SIZE
Maximum number of particles in a leaf node.
@ SPH_SOLVER_FORCES
List of forces to compute by the solver.
@ SPH_AV_TYPE
Type of used artificial viscosity.
@ 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.
@ TIMESTEPPING_INITIAL_TIMESTEP
@ SPH_ADAPTIVE_SMOOTHING_LENGTH
Solution for evolutions of the smoothing length.
@ GRAVITY_SOLVER
Algorithm to compute gravitational acceleration.
@ TIMESTEPPING_DERIVATIVE_FACTOR
Multiplicative factor k for the derivative criterion; dt = k * v / dv.
@ SPH_DISCRETIZATION
Specifies a discretization of SPH equations; see DiscretizationEnum.
@ RUN_OUTPUT_TYPE
Selected format of the output file, see IoEnum.
@ TIMESTEPPING_INTEGRATOR
Selected timestepping integrator.
@ TIMESTEPPING_COURANT_NUMBER
Courant number.
@ SPH_FINDER
Structure for searching nearest neighbours of particles.
@ 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.
@ GRAVITY_KERNEL
Gravity smoothing kernel.
@ 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
Definition: MemoryPool.h:5