SPH
Boundary.cpp
Go to the documentation of this file.
1 
6 #include "Sph.h"
7 #include "catch.hpp"
10 
11 using namespace Sph;
12 
13 class Distribution : public IDistribution {
14 public:
15  virtual Array<Vector> generate(IScheduler&, const Size n, const IDomain& domain) const override {
16  const Box box = domain.getBoundingBox();
17  const Float h = sqrt(1._f / n);
18  const Float dx = h;
19  const Float dy = h; // sqrt(3._f) / 2._f * dx;
20  Array<Vector> r;
21  int row = 0;
22  for (Float y = box.lower()[Y] + 0.5f * dy; y <= box.upper()[Y]; y += dy, row++) {
23  for (Float x = box.lower()[X] + 0.5f * dx; x <= box.upper()[X]; x += dx) {
24  // Float delta = (row % 2) ? 0.5_f * dx : 0._f;
25  r.push(Vector(x /*+ delta*/, y, 0._f, h));
26  }
27  }
28  return r;
29  }
30 };
31 
32 class BoundaryRun : public IRun {
33 private:
35 
36 public:
37  BoundaryRun(AutoPtr<IBoundaryCondition>&& bc, const std::string& name)
38  : BoundaryRun(BoundaryEnum::NONE, name) {
39  this->bc = std::move(bc);
40  }
41 
42  BoundaryRun(const BoundaryEnum boundary, const std::string& name) {
43  // Global settings of the problem
44  this->settings.set(RunSettingsId::RUN_NAME, name)
45  .set(RunSettingsId::RUN_END_TIME, 4._f)
50  .set(RunSettingsId::RUN_OUTPUT_PATH, std::string(""))
51  .set(RunSettingsId::RUN_OUTPUT_NAME, "boundary/" + name + "_%d.scf")
52  .set(RunSettingsId::SPH_AV_ALPHA, 1.5_f)
53  .set(RunSettingsId::SPH_AV_BETA, 3._f)
64  .set(RunSettingsId::DOMAIN_BOUNDARY, boundary)
65  //.set(RunSettingsId::DOMAIN_BOUNDARY, BoundaryEnum::FROZEN_PARTICLES)
66  .set(RunSettingsId::DOMAIN_SIZE, Vector(1._f, 1._f, 1._f));
67  }
68 
69  virtual void setUp(SharedPtr<Storage> storage) override {
70  BodySettings body;
71  body.set(BodySettingsId::DENSITY, 100._f)
73  .set(BodySettingsId::ENERGY, 0.25_f)
80 
81  *storage = Storage(Factory::getMaterial(body));
82  AutoPtr<IDistribution> dist = makeAuto<Distribution>();
83  BlockDomain domain(Vector(0._f), Vector(1._f, 1._f, 1.e-3_f));
84  Array<Vector> pos = dist->generate(*scheduler, 40000, domain);
85  const Float eta = 1.3_f;
86  for (Size i = 0; i < pos.size(); ++i) {
87  pos[i][H] *= eta;
88  }
89  // rho * S / N ??
90  const Float m = body.get<Float>(BodySettingsId::DENSITY) / pos.size();
91 
92  storage->insert<Vector>(QuantityId::POSITION, OrderEnum::SECOND, std::move(pos));
94 
95  EquationHolder eqs = getStandardEquations(settings);
96  if (bc) {
97  this->solver = makeAuto<SymmetricSolver<2>>(*scheduler, settings, eqs, std::move(bc));
98  } else {
99  this->solver = makeAuto<SymmetricSolver<2>>(*scheduler, settings, eqs);
100  }
101  IMaterial& mat = storage->getMaterial(0);
102  solver->create(*storage, mat);
103  MaterialInitialContext context(settings);
104  mat.create(*storage, context);
105 
108  Vector center(0.25, 0, 0);
109  for (Size i = 0; i < r.size(); ++i) {
110  if (getLength(r[i] - center) < 0.01_f) {
111  u[i] = 5._f;
112  }
113  }
114  }
115 
116 protected:
117  virtual void tearDown(const Storage& UNUSED(storage), const Statistics& UNUSED(stats)) override {}
118 };
119 
120 TEST_CASE("Boundary test", "[boundary]") {
121  Storage storage;
122  RunSettings settings;
124  .set(RunSettingsId::DOMAIN_SIZE, Vector(1._f, 1._f, 1._f));
125 
126  BoundaryRun periodic(BoundaryEnum::PERIODIC, "periodic");
127  periodic.run(storage);
128 
129  BoundaryRun ghosts(BoundaryEnum::GHOST_PARTICLES, "ghosts");
130  ghosts.run(storage);
131 
133  frozen.run(storage);
134 }
@ NONE
No collision took place.
const EmptyFlags EMPTY_FLAGS
Definition: Flags.h:16
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 of particles, always a vector quantity.
@ DENSITY
Density, always a scalar quantity.
@ 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.
Includes common headers.
Helper solver used to converge into stable initial conditions.
NAMESPACE_SPH_BEGIN EquationHolder getStandardEquations(const RunSettings &settings, const EquationHolder &other)
Standard SPH equation set, using density and specific energy as independent variables.
Solver using direction summation to compute density and smoothing length.
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
Object providing safe access to continuous memory of data.
Definition: ArrayView.h:17
INLINE TCounter size() const
Definition: ArrayView.h:101
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
BoundaryRun(AutoPtr< IBoundaryCondition > &&bc, const std::string &name)
Definition: Boundary.cpp:37
BoundaryRun(const BoundaryEnum boundary, const std::string &name)
Definition: Boundary.cpp:42
virtual void tearDown(const Storage &UNUSED(storage), const Statistics &UNUSED(stats)) override
Definition: Boundary.cpp:117
virtual void setUp(SharedPtr< Storage > storage) override
Prepares the run, creates logger, output, ...
Definition: Boundary.cpp:69
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
virtual Array< Vector > generate(IScheduler &, const Size n, const IDomain &domain) const override
Generates the requested number of particles in the domain.
Definition: Boundary.cpp:15
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
virtual void create(Storage &storage, const MaterialInitialContext &context)=0
Create all quantities needed by the material.
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
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
TEST_CASE("Boundary test", "[boundary]")
Definition: Boundary.cpp:120
@ 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.
@ COMPRESSED_FILE
@ PREDICTOR_CORRECTOR
Predictor-corrector scheme.
@ 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.
BoundaryEnum
Definition: Settings.h:604
@ GHOST_PARTICLES
Create ghosts to keep particles inside domain.
@ FROZEN_PARTICLES
Highest derivatives of all particles close to the boundary are set to zero.
@ PERIODIC
Periodic boundary conditions.
@ RUN_OUTPUT_QUANTITIES
List of quantities to write to text output. Binary output always stores all quantitites.
@ RUN_OUTPUT_INTERVAL
Time interval of dumping data to disk.
@ TIMESTEPPING_MAX_TIMESTEP
@ 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
@ DOMAIN_BOUNDARY
Type of boundary conditions.
@ 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