21 , bodyIndex(bodyIndex) {}
30 for (
Size i = 0; i < r.
size(); ++i) {
31 if (flag[i] == bodyIndex) {
41 for (
Size i = 0; i < v.
size(); ++i) {
42 if (flag[i] == bodyIndex) {
53 for (
Size i = 0; i < r.
size(); ++i) {
54 if (flag[i] == bodyIndex) {
55 v[i] +=
cross(omega, r[i] - origin);
61 Vector BodyView::getOrigin(
const RotationOrigin origin)
const {
73 return this->
addRotation(omega, this->getOrigin(origin));
77 : context(settings) {}
97 return this->
addMonolithicBody(storage, domain, std::move(material), *distribution);
114 this->setQuantities(body, *material, domain.
getVolume());
115 storage.
merge(std::move(body));
124 return BodyView(storage, bodyIndex++);
129 , material(material) {}
157 auto assign = [&](
const Vector& p) {
158 for (
Size i = 0; i < bodies.
size(); ++i) {
159 if (bodies[i].domain->contains(p)) {
160 pos_bodies[i].
push(p);
166 for (
const Vector& p : positions) {
174 for (
Size i = 0; i < bodyStorages.
size(); ++i) {
176 const Float volume = bodies[i].domain->getVolume();
177 this->setQuantities(bodyStorages[i], bodyStorages[i].
getMaterial(0), volume);
178 environVolume -= volume;
182 this->setQuantities(enviroStorage, enviroStorage.
getMaterial(0), environVolume);
185 storage.
merge(std::move(enviroStorage));
186 for (
Storage& body : bodyStorages) {
187 storage.
merge(std::move(body));
190 return BodyView(storage, bodyIndex++);
212 Size bailoutCounter = 0;
213 constexpr
Size bailoutTarget = 1000;
215 while (bailoutCounter < bailoutTarget) {
219 while (bailoutCounter < bailoutTarget) {
223 center = box.
lower() + rng() * box.
size();
233 auto checkOverlap = [&spheres](
const Sphere& sphere) {
234 for (
const Sphere& s : spheres) {
235 if (s.intersects(sphere)) {
242 if (checkOverlap(sphere)) {
256 for (
Size i = 0; i < positions.
size();) {
257 if (sphere.
contains(positions[i])) {
258 spherePositions.
push(positions[i]);
266 if (spherePositions.
size() < minN) {
268 positions.
pushAll(std::move(spherePositions));
272 spheres.
push(sphere);
277 this->setQuantities(body, *material, sphere.
volume());
280 storage.
merge(std::move(body));
295 Float prelimM = 0._f;
296 for (
Size i = 0; i < r.
size(); ++i) {
301 const Float normalization = totalM / prelimM;
302 for (
Size i = 0; i < r.
size(); ++i) {
303 m[i] *= normalization;
311 for (
Size i = 0; i < r.
size(); ++i) {
316 const Float totalM = volume * rho0;
326 material.
create(storage, context);
340 while (moveCnt != 0) {
342 for (
Size i = 0; i < r.
size(); ++i) {
345 if (neighs.
size() <= 1) {
350 const Vector dr = r[n.index] - r[i];
367 for (
Size i = 0; i < r.
size(); ++i) {
368 r_com += m[i] * r[i];
373 for (
Size i = 0; i < r.
size(); ++i) {
#define SPH_ASSERT(x,...)
#define NOT_IMPLEMENTED
Helper macro marking missing implementation.
Filling spatial domain with SPH particles.
Object defining computational domain.
uint32_t Size
Integral type used to index arrays (by default).
double Float
Precision used withing the code. Use Float instead of float or double where precision is important.
Base class for all particle materials.
Base interface for all solvers.
Vector moveToCenterOfMassSystem(ArrayView< const Float > m, ArrayView< Vector > r)
Modifies particle positions so that their center of mass lies at the origin.
void repelParticles(ArrayView< Vector > r, const Float radius)
Displaces particles so that no two particles overlap.
Generating initial conditions of SPH particles.
Integrals of motion and other integral quantities.
AutoPtr< IMaterial > getMaterial(const MaterialEnum type)
constexpr INLINE Float pow< 3 >(const Float v)
#define NAMESPACE_SPH_END
Tool to measure time spent in functions and profile the code.
#define PROFILE_SCOPE(name)
@ FLAG
ID of original body, used to implement discontinuities between bodies in SPH.
@ POSITION
Positions (velocities, accelerations) of particles, always a vector quantity,.
@ MASS
Paricles masses, always a scalar quantity.
@ UVW
Texture mapping coordinates,.
Holder of quantity values and their temporal derivatives.
@ SECOND
Quantity with 1st and 2nd derivative.
@ ZERO
Quantity without derivatives, or "zero order" of quantity.
SequentialScheduler SEQUENTIAL
Global instance of the sequential scheduler.
Interface for executing tasks (potentially) asynchronously.
Object representing a three-dimensional sphere.
StaticArray< T0 &, sizeof...(TArgs)+1 > tie(T0 &t0, TArgs &... rest)
Creates a static array from a list of l-value references.
Container for storing particle quantities and materials.
Objects for generating random vectors.
INLINE Float getLength(const Vector &v)
Returns the length of the vector. Enabled only for vectors of floating-point precision.
INLINE BasicVector< float > cross(const BasicVector< float > &v1, const BasicVector< float > &v2)
Cross product between two vectors.
BasicVector< Float > Vector
Object providing safe access to continuous memory of data.
INLINE TCounter size() const
Generic dynamically allocated resizable storage.
INLINE void push(U &&u)
Adds new element to the end of the array, resizing the array if necessary.
void remove(const TCounter idx)
Removes an element with given index from the array.
void insert(const TCounter position, U &&value)
Inserts a new element to given position in the array.
INLINE TCounter size() const noexcept
INLINE bool empty() const noexcept
void pushAll(const TIter first, const TIter last)
Non-owning view of particles belonging to the same body.
RotationOrigin
Predefined types of center point.
@ CENTER_OF_MASS
Rotate the body around its center of mass.
@ FRAME_ORIGIN
Add angular velocity with respect to origin of coordinates.
BodyView(Storage &storage, const Size bodyIndex)
BodyView & addRotation(const Vector &omega, const RotationOrigin origin)
Adds an angular velocity to all particles of the body.
BodyView & addVelocity(const Vector &v)
Adds a velocity vector to all particles of the body.
BodyView & displace(const Vector &dr)
Moves the particles of the body in given direction.
Helper object defining three-dimensional interval (box).
INLINE const Vector & lower() const
Returns lower bounds of the box.
INLINE Vector size() const
Returns box dimensions.
Computes the center of mass of particles.
virtual Vector evaluate(const Storage &storage) const override
Computes the integral quantity using particles in the storage.
virtual Size findAll(const Size index, const Float radius, Array< NeighbourRecord > &neighbours) const =0
Finds all neighbours within given radius from the point given by index.
Base class for generating vertices with specific distribution.
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.
virtual Box getBoundingBox() const =0
Returns the bounding box of the domain.
virtual Float getVolume() const =0
Returns the total volume of the domain.
virtual bool contains(const Vector &v) const =0
Checks if the given point lies inside the domain.
Material settings and functions specific for one material.
INLINE TValue getParam(const BodySettingsId paramIdx) const
Returns a parameter associated with given particle.
INLINE const BodySettings & getParams() const
Returns settings containing material parameters.
virtual void create(Storage &storage, const MaterialInitialContext &context)=0
Create all quantities needed by the material.
void build(IScheduler &scheduler, ArrayView< const Vector > points, Flags< FinderFlag > flags=FinderFlag::MAKE_RANK)
Constructs the struct with an array of vectors.
virtual Array< Vector > generate(const Storage &storage) const =0
BodyView addMonolithicBody(Storage &storage, const BodySettings &body)
Creates a monolithic body by filling given domain with particles.
InitialConditions(const RunSettings &settings)
Creates new initial conditions.
BodyView addHeterogeneousBody(Storage &storage, const BodySetup &environment, ArrayView< const BodySetup > bodies)
Creates particles composed of different materials.
void addRubblePileBody(Storage &storage, const IDomain &domain, const PowerLawSfd &sfd, const BodySettings &bodySettings)
Creates a rubble-pile body, composing of monolithic spheres.
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.
static const Settings & getDefaults()
\brief Returns a reference to object containing default values of all settings.
INLINE bool contains(const Vector &v) const
INLINE Float volume() const
Container storing all quantities used within the simulations.
void merge(Storage &&other)
Merges another storage into this object.
void resize(const Size newParticleCnt, const Flags< ResizeFlag > flags=EMPTY_FLAGS)
Changes number of particles for all quantities stored in the storage.
Quantity & insert(const QuantityId key, const OrderEnum order, const TValue &defaultValue)
Creates a quantity in the storage, given its key, value type and order.
StaticArray< Array< TValue > &, 3 > getAll(const QuantityId key)
Retrieves quantity buffers from the storage, given its key and value type.
Array< TValue > & getDt(const QuantityId key)
Retrieves a quantity derivative from the storage, given its key and value type.
Size getParticleCnt() const
Returns the number of particles.
void propagate(const Function< void(Storage &storage)> &functor)
Executes a given functor recursively for all dependent storages.
MaterialView getMaterial(const Size matIdx) const
Returns an object containing a reference to given material.
@ KEEP_EMPTY_UNCHANGED
Empty buffers will not be resized to new values.
Array< TValue > & getValue(const QuantityId key)
Retrieves a quantity values from the storage, given its key and value type.
Wrapper for generating random vectors.
Float getAdditional(const Size i)
Creating code components based on values from settings.
@ PARTICLE_COUNT
Number of SPH particles in the body.
@ DENSITY
Density at zero pressure.
@ SMOOTHING_LENGTH_ETA
Eta-factor between smoothing length and particle concentration (h = eta * n^(-1/d) )
Provides a convenient way to construct objects from settings.
AutoPtr< IMaterial > getMaterial(const BodySettings &settings)
AutoPtr< ISymmetricFinder > getFinder(const RunSettings &settings)
AutoPtr< IDistribution > getDistribution(const BodySettings &settings, Function< bool(Float)> progressCallback=nullptr)
AutoPtr< IDomain > getDomain(const RunSettings &settings)
Vector velocity(const Float a, const Float e, const Float u, const Float n)
Computes the velocity vector on the elliptic trajectory.
Holds data needed to create a single body in addHeterogeneousBody function.
SharedPtr< IDomain > domain
SharedPtr< IMaterial > material
BodySetup()
Creates a body with undefined domain and material.
SharedPtr< IScheduler > scheduler
AutoPtr< IUvMapping > uvMap
If used, texture mapping coordinates are generated provided mapping.
AutoPtr< IRng > rng
Random number generator.
Holds information about a neighbour particles.
Holds the information about a power-law size-frequency distributions.