SPH
Sedov.cpp
Go to the documentation of this file.
1 
6 #include "Sph.h"
7 #include "catch.hpp"
8 #include <iostream>
9 
10 using namespace Sph;
11 
13 public:
14  virtual Array<Vector> generate(IScheduler&, const Size n, const IDomain& domain) const override {
15  const Box box = domain.getBoundingBox();
16  const Float h = sqrt(1._f / n);
17  const Float dx = h;
18  const Float dy = sqrt(3._f) / 2._f * dx;
19  Array<Vector> r;
20  int row = 0;
21  for (Float y = box.lower()[Y]; y <= box.upper()[Y]; y += dy, row++) {
22  for (Float x = box.lower()[X]; x <= box.upper()[X]; x += dx) {
23  Float delta = (row % 2) ? 0.5_f * dx : 0._f;
24  r.push(Vector(x + delta, y, 0._f, h));
25  }
26  }
27  return r;
28  }
29 };
30 
31 class Sedov : public IRun {
32 public:
33  Sedov() {
34  // Global settings of the problem
35  this->settings.set(RunSettingsId::RUN_NAME, std::string("Sedov Blast Problem"))
36  .set(RunSettingsId::RUN_END_TIME, 8._f)
39  .set(RunSettingsId::RUN_OUTPUT_PATH, std::string(""))
40  .set(RunSettingsId::RUN_OUTPUT_NAME, std::string("sedov/sedov_%d.txt"))
41  .set(RunSettingsId::SPH_AV_ALPHA, 1.5_f)
42  .set(RunSettingsId::SPH_AV_BETA, 3._f)
50  .set(RunSettingsId::SPH_USE_AC, true)
54  //.set(RunSettingsId::DOMAIN_BOUNDARY, BoundaryEnum::FROZEN_PARTICLES)
56  }
57 
58  virtual void setUp(SharedPtr<Storage> storage) override {
59  BodySettings body;
60  body.set(BodySettingsId::DENSITY, 1._f)
67  .set(BodySettingsId::ADIABATIC_INDEX, 1.6666666666_f)
69 
70  *storage = Storage(Factory::getMaterial(body));
71  AutoPtr<IDistribution> dist = makeAuto<PlanarDistribution>(); // Factory::getDistribution(body);
72  BlockDomain domain(Vector(0._f), Vector(1._f, 1._f, 1.e-3_f));
73  Array<Vector> pos = dist->generate(*scheduler, 100000, domain);
74  const Float eta = 1.5_f;
75  for (Size i = 0; i < pos.size(); ++i) {
76  pos[i][H] *= eta;
77  }
78  const Float m = body.get<Float>(BodySettingsId::DENSITY) / pos.size();
79 
80  storage->insert<Vector>(QuantityId::POSITION, OrderEnum::SECOND, std::move(pos));
82  m); // rho * S / N
83 
84  EquationHolder eqs = getStandardEquations(settings);
85  this->solver = makeAuto<SymmetricSolver<2>>(*scheduler, settings, eqs);
86  IMaterial& mat = storage->getMaterial(0);
87  solver->create(*storage, mat);
88  MaterialInitialContext context(settings);
89  mat.create(*storage, context);
90 
93  Float E0 = 0._f;
94  for (Size i = 0; i < r.size(); ++i) {
95  if (getLength(r[i]) < 0.015_f) {
96  u[i] = 4._f;
97  E0 += u[i] * m;
98  }
99  }
100  std::cout << "E0 = " << E0 << std::endl;
101  }
102 
103 protected:
104  virtual void tearDown(const Storage& UNUSED(storage), const Statistics& UNUSED(stats)) override {}
105 };
106 
107 TEST_CASE("Sedov", "[sedov]") {
108  Sedov run;
109  Storage storage;
110  run.run(storage);
111 }
uint32_t Size
Integral type used to index arrays (by default).
Definition: Globals.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 sqrt(const T f)
Return a squared root of a value.
Definition: MathUtils.h:78
constexpr Float INFTY
Definition: MathUtils.h:38
#define UNUSED(x)
Definition: Object.h:37
@ POSITION
Positions (velocities, accelerations) of particles, always a vector quantity,.
@ ENERGY
Specific internal energy, always a scalar quantity.
@ MASS
Paricles masses, always a scalar quantity.
@ SECOND
Quantity with 1st and 2nd derivative.
@ ZERO
Quantity without derivatives, or "zero order" of quantity.
TEST_CASE("Sedov", "[sedov]")
Definition: Sedov.cpp:107
Includes common headers.
NAMESPACE_SPH_BEGIN EquationHolder getStandardEquations(const RunSettings &settings, const EquationHolder &other)
Standard SPH equation set, using density and specific energy as independent variables.
INLINE Float getLength(const Vector &v)
Returns the length of the vector. Enabled only for vectors of floating-point precision.
Definition: Vector.h:579
BasicVector< Float > Vector
Definition: Vector.h:539
@ H
Definition: Vector.h:25
@ Y
Definition: Vector.h:23
@ X
Definition: Vector.h:22
Generic dynamically allocated resizable storage.
Definition: Array.h:43
INLINE void push(U &&u)
Adds new element to the end of the array, resizing the array if necessary.
Definition: Array.h:306
INLINE TCounter size() const noexcept
Definition: Array.h:193
Block aligned with coordinate axes, defined by its center and length of each side.
Definition: Domain.h:185
Helper object defining three-dimensional interval (box).
Definition: Box.h:17
INLINE const Vector & lower() const
Returns lower bounds of the box.
Definition: Box.h:82
INLINE const Vector & upper() const
Returns upper bounds of the box.
Definition: Box.h:94
Container holding equation terms.
Definition: EquationTerm.h:238
Base class for generating vertices with specific distribution.
Definition: Distribution.h:21
virtual Array< Vector > generate(IScheduler &scheduler, const Size n, const IDomain &domain) const =0
Generates the requested number of particles in the domain.
Base class for computational domains.
Definition: Domain.h:29
virtual Box getBoundingBox() const =0
Returns the bounding box of the domain.
Material settings and functions specific for one material.
Definition: IMaterial.h:110
Defines the interface for a run.
Definition: IRun.h:61
Statistics run(Storage &storage)
Runs the simulation.
Definition: IRun.cpp:187
Interface that allows unified implementation of sequential and parallelized versions of algorithms.
Definition: Scheduler.h:27
Object representing a 1D interval of real numbers.
Definition: Interval.h:17
virtual Array< Vector > generate(IScheduler &, const Size n, const IDomain &domain) const override
Generates the requested number of particles in the domain.
Definition: Sedov.cpp:14
Definition: Sedov.cpp:31
virtual void setUp(SharedPtr< Storage > storage) override
Prepares the run, creates logger, output, ...
Definition: Sedov.cpp:58
virtual void tearDown(const Storage &UNUSED(storage), const Statistics &UNUSED(stats)) override
Definition: Sedov.cpp:104
Sedov()
Definition: Sedov.cpp:33
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.
Definition: Settings.h:326
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
Quantity & insert(const QuantityId key, const OrderEnum order, const TValue &defaultValue)
Creates a quantity in the storage, given its key, value type and order.
Definition: Storage.cpp:270
MaterialView getMaterial(const Size matIdx) const
Returns an object containing a reference to given material.
Definition: Storage.cpp:366
Array< TValue > & getValue(const QuantityId key)
Retrieves a quantity values from the storage, given its key and value type.
Definition: Storage.cpp:191
@ PRESSURE
Use force from pressure gradient in the solver.
@ NONE
Gass or material with no stress tensor.
@ UNIFORM_GRID
Partitioning particles into a grid uniform in space.
@ COURANT
Time step determined using CFL condition.
@ TEXT_FILE
Formatted human-readable text file.
@ EULER_EXPLICIT
Explicit (forward) 1st-order integration.
@ CUBIC_SPLINE
M4 B-spline (piecewise cubic polynomial)
@ NONE
No fragmentation.
@ IDEAL_GAS
Equation of state for ideal gas.
@ RHEOLOGY_DAMAGE
Model of fragmentation used within the rheological model.
@ DENSITY_RANGE
Allowed range of density. Densities of all particles all clamped to fit in the range.
@ ENERGY
Initial specific internal energy.
@ ADIABATIC_INDEX
Adiabatic index used by some equations of state (such as ideal gas)
@ DENSITY
Density at zero pressure.
@ 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.
@ CONTINUITY_EQUATION
Smoothing length is evolved using continuity equation.
@ RUN_OUTPUT_INTERVAL
Time interval of dumping data to disk.
@ TIMESTEPPING_MAX_TIMESTEP
@ SPH_USE_AC
Enables the artificial thermal conductivity term.
@ SPH_KERNEL
Index of SPH Kernel, see KernelEnum.
@ SPH_SOLVER_FORCES
List of forces to compute by the solver.
@ 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.
@ TIMESTEPPING_INITIAL_TIMESTEP
@ SPH_ADAPTIVE_SMOOTHING_LENGTH
Solution for evolutions of the smoothing length.
@ 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.
@ DOMAIN_TYPE
Computational domain, enforced by boundary conditions.
@ RUN_NAME
User-specified name of the run, used in some output files.
@ DOMAIN_SIZE
(Vector) size of a block domain
@ RUN_OUTPUT_NAME
File name of the output file (including extension), where d is a placeholder for output number.
@ BLOCK
Block with edge sizes given by vector.
AutoPtr< IMaterial > getMaterial(const BodySettings &settings)
Definition: Factory.cpp:508
Definition: MemoryPool.h:5
Shared data used when creating all bodies in the simulation.
Definition: IMaterial.h:89