SPH
Setup.cpp
Go to the documentation of this file.
1 #include "tests/Setup.h"
3 #include "physics/Eos.h"
4 #include "physics/Rheology.h"
5 #include "quantities/Quantity.h"
6 #include "sph/Materials.h"
8 #include "system/Factory.h"
9 
11 
12 Storage Tests::getStorage(const Size particleCnt) {
13  BodySettings settings;
14  settings.set(BodySettingsId::DENSITY, 1._f);
15  Storage storage(makeAuto<NullMaterial>(settings));
16 
17  AutoPtr<IDistribution> distribution = Factory::getDistribution(settings);
18  SphericalDomain domain(Vector(0._f), 1._f);
19  Array<Vector> positions = distribution->generate(SEQUENTIAL, particleCnt, domain);
20  storage.insert<Vector>(QuantityId::POSITION, OrderEnum::SECOND, std::move(positions));
21 
24  // density = 1, therefore total mass = volume, therefore mass per particle = volume / N
26  return storage;
27 }
28 
29 Storage Tests::getGassStorage(const Size particleCnt, BodySettings settings, const IDomain& domain) {
30  // setup settings
31  const Float rho0 = settings.get<Float>(BodySettingsId::DENSITY);
32  const Float u0 = settings.get<Float>(BodySettingsId::ENERGY);
37 
38  // create storage and particle positions
39  Storage storage(makeAuto<EosMaterial>(settings, Factory::getEos(settings)));
40  AutoPtr<IDistribution> distribution = Factory::getDistribution(settings);
41  Array<Vector> r = distribution->generate(SEQUENTIAL, particleCnt, domain);
42  storage.insert<Vector>(QuantityId::POSITION, OrderEnum::SECOND, std::move(r));
43 
44  // set needed quantities and materials
46  const Float m0 = rho0 * domain.getVolume() / storage.getParticleCnt();
49  MaterialView material = storage.getMaterial(0);
50  material->create(storage, MaterialInitialContext());
51  material->initialize(SEQUENTIAL, storage, material.sequence());
52  return storage;
53 }
54 
55 Storage Tests::getGassStorage(const Size particleCnt, BodySettings settings, const Float radius) {
56  return getGassStorage(particleCnt, settings, SphericalDomain(Vector(0.f), radius));
57 }
58 
59 Storage Tests::getSolidStorage(const Size particleCnt, BodySettings settings, const IDomain& domain) {
60  const Float u0 = settings.get<Float>(BodySettingsId::ENERGY);
61  const Float rho0 = settings.get<Float>(BodySettingsId::DENSITY);
63  .set(BodySettingsId::DENSITY_RANGE, Interval(1.e-3_f * rho0, INFTY));
64 
65  AutoPtr<IRheology> rheology = Factory::getRheology(settings);
66  if (!rheology) {
67  rheology = makeAuto<ElasticRheology>();
68  }
69 
70  Storage storage(makeAuto<SolidMaterial>(settings, Factory::getEos(settings), std::move(rheology)));
71  AutoPtr<IDistribution> distribution = Factory::getDistribution(settings);
72  Array<Vector> positions = distribution->generate(SEQUENTIAL, particleCnt, domain);
73  storage.insert<Vector>(QuantityId::POSITION, OrderEnum::SECOND, std::move(positions));
74 
76  const Float m0 = rho0 * domain.getVolume() / storage.getParticleCnt();
81  MaterialView material = storage.getMaterial(0);
82 
83  MaterialInitialContext context;
84  context.rng = makeRng<UniformRng>();
85  material->create(storage, context);
86  material->initialize(SEQUENTIAL, storage, material.sequence());
87  return storage;
88 }
89 
90 Storage Tests::getSolidStorage(const Size particleCnt, BodySettings settings, const Float radius) {
91  return getSolidStorage(particleCnt, settings, SphericalDomain(Vector(0.f), radius));
92 }
93 
94 Size Tests::getClosestParticle(const Storage& storage, const Vector& p) {
96  Float closestDistSqr = INFTY;
97  Size closestIdx = Size(-1);
98  for (Size i = 0; i < r.size(); ++i) {
99  const Float distSqr = getSqrLength(r[i] - p);
100  if (distSqr < closestDistSqr) {
101  closestDistSqr = distSqr;
102  closestIdx = i;
103  }
104  }
105  SPH_ASSERT(closestDistSqr < INFTY);
106  return closestIdx;
107 }
108 
109 
#define SPH_ASSERT(x,...)
Definition: Assert.h:94
NAMESPACE_SPH_BEGIN
Definition: BarnesHut.cpp:13
const float radius
Definition: CurveDialog.cpp:18
Filling spatial domain with SPH particles.
Object defining computational domain.
Equations of state.
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
SPH-specific implementation of particle materials.
constexpr INLINE Float sphereVolume(const Float radius)
Computes a volume of a sphere given its radius.
Definition: MathUtils.h:375
constexpr Float INFTY
Definition: MathUtils.h:38
#define NAMESPACE_SPH_END
Definition: Object.h:12
@ FLAG
ID of original body, used to implement discontinuities between bodies in SPH.
@ DEVIATORIC_STRESS
Deviatoric stress tensor, always a traceless tensor.
@ POSITION
Positions (velocities, accelerations) of particles, always a vector quantity,.
@ ENERGY
Specific internal energy, always a scalar quantity.
@ DENSITY
Density, always a scalar quantity.
@ MASS
Paricles masses, always a scalar quantity.
Holder of quantity values and their temporal derivatives.
@ SECOND
Quantity with 1st and 2nd derivative.
@ FIRST
Quantity with 1st derivative.
@ ZERO
Quantity without derivatives, or "zero order" of quantity.
Rheology of materials.
SequentialScheduler SEQUENTIAL
Global instance of the sequential scheduler.
Definition: Scheduler.cpp:43
Helper functions performing common tasks in unit testing and benchmarks.
INLINE Float getSqrLength(const Vector &v)
Definition: Vector.h:574
BasicVector< Float > Vector
Definition: Vector.h:539
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
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 Float getVolume() const =0
Returns the total volume of the domain.
Object representing a 1D interval of real numbers.
Definition: Interval.h:17
Non-owning wrapper of a material and particles with this material.
Definition: IMaterial.h:30
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
Spherical domain, defined by the center of sphere and its radius.
Definition: Domain.h:102
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
Size getParticleCnt() const
Returns the number of particles.
Definition: Storage.cpp:445
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
Symmetric traceless 2nd order tensor.
static INLINE TracelessTensor null()
Returns a tensor with all zeros.
Creating code components based on values from settings.
@ NONE
Gass or material with no stress tensor.
@ NONE
No fragmentation.
@ IDEAL_GAS
Equation of state for ideal gas.
@ TILLOTSON
Tillotson (1962) equation of state.
@ 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.
@ DENSITY
Density at zero pressure.
@ EOS
Equation of state for this material, see EosEnum for options.
@ RHEOLOGY_YIELDING
Model of stress reducing used within the rheological model.
AutoPtr< IRheology > getRheology(const BodySettings &settings)
Definition: Factory.cpp:69
AutoPtr< IDistribution > getDistribution(const BodySettings &settings, Function< bool(Float)> progressCallback=nullptr)
Definition: Factory.cpp:228
AutoPtr< IEos > getEos(const BodySettings &settings)
Definition: Factory.cpp:47
Storage getSolidStorage(const Size particleCnt, BodySettings settings, const IDomain &domain)
Returns a storage with stress tensor.
Definition: Setup.cpp:59
Storage getStorage(const Size particleCnt)
Definition: Setup.cpp:12
Storage getGassStorage(const Size particleCnt, BodySettings settings, const IDomain &domain)
Returns a storage with ideal gas particles, having pressure, energy and sound speed.
Definition: Setup.cpp:29
Size getClosestParticle(const Storage &storage, const Vector &p)
Returns the index to the particle closest to given point.
Definition: Setup.cpp:94
Shared data used when creating all bodies in the simulation.
Definition: IMaterial.h:89
AutoPtr< IRng > rng
Random number generator.
Definition: IMaterial.h:91