SPH
IMaterial.h
Go to the documentation of this file.
1 #pragma once
2 
7 
8 #include "math/rng/Rng.h"
12 #include "quantities/QuantityIds.h"
13 #include "sph/initial/UvMapping.h"
14 #include "system/Settings.h"
15 
17 
18 class Storage;
19 class IMaterial;
20 class IScheduler;
21 
30 class MaterialView {
31 private:
33  IndexSequence seq;
34 
35 public:
37  : mat(std::move(material))
38  , seq(seq) {
39  SPH_ASSERT(material != nullptr);
40  }
41 
44  SPH_ASSERT(mat != nullptr);
45  return *mat;
46  }
47 
50  SPH_ASSERT(mat != nullptr);
51  return *mat;
52  }
53 
55  INLINE operator IMaterial&() {
56  return this->material();
57  }
58 
60  INLINE operator const IMaterial&() const {
61  return this->material();
62  }
63 
66  return &this->material();
67  }
68 
71  return &this->material();
72  }
73 
76  return seq;
77  }
78 
80  INLINE const IndexSequence sequence() const {
81  return seq;
82  }
83 };
84 
85 
92 
94 
97 
100 
102 
104  explicit MaterialInitialContext(const RunSettings& settings);
105 };
106 
110 class IMaterial : public Polymorphic {
111 protected:
114 
117 
120 
122  const static Interval DEFAULT_RANGE;
123  const static Float DEFAULT_MINIMAL;
124 
125 public:
126  explicit IMaterial(const BodySettings& settings)
127  : params(settings) {}
128 
129  template <typename TValue>
130  INLINE IMaterial& setParam(const BodySettingsId paramIdx, TValue&& value) {
131  params.set(paramIdx, std::forward<TValue>(value));
132  return *this;
133  }
134 
136  template <typename TValue>
137  INLINE TValue getParam(const BodySettingsId paramIdx) const {
138  return params.get<TValue>(paramIdx);
139  }
140 
142  INLINE const BodySettings& getParams() const {
143  return params;
144  }
145 
150  void setRange(const QuantityId id, const Interval& range, const Float minimal);
151 
155  INLINE void setRange(const QuantityId id, const BodySettingsId rangeId, const BodySettingsId minimalId) {
156  this->setRange(id, params.get<Interval>(rangeId), params.get<Float>(minimalId));
157  }
158 
163  INLINE Float minimal(const QuantityId id) const {
164  return minimals.tryGet(id).valueOr(DEFAULT_MINIMAL);
165  }
166 
172  INLINE const Interval range(const QuantityId id) const {
173  return ranges.tryGet(id).valueOr(DEFAULT_RANGE);
174  }
175 
177  virtual void create(Storage& storage, const MaterialInitialContext& context) = 0;
178 
185  virtual void initialize(IScheduler& scheduler, Storage& storage, const IndexSequence sequence) = 0;
186 
193  virtual void finalize(IScheduler& scheduler, Storage& storage, const IndexSequence sequence) = 0;
194 };
195 
196 
200 class NullMaterial : public IMaterial {
201 public:
202  explicit NullMaterial(const BodySettings& body)
203  : IMaterial(body) {}
204 
205  virtual void create(Storage& UNUSED(storage), const MaterialInitialContext& UNUSED(context)) override {}
206 
207  virtual void initialize(IScheduler& UNUSED(scheduler),
208  Storage& UNUSED(storage),
209  const IndexSequence UNUSED(sequence)) override {}
210 
211  virtual void finalize(IScheduler& UNUSED(scheduler),
212  Storage& UNUSED(storage),
213  const IndexSequence UNUSED(sequence)) override {}
214 };
215 
#define SPH_ASSERT(x,...)
Definition: Assert.h:94
NAMESPACE_SPH_BEGIN
Definition: BarnesHut.cpp:13
Key-value associative container implemented as a sorted array.
double Float
Precision used withing the code. Use Float instead of float or double where precision is important.
Definition: Globals.h:13
Helper objects allowing to iterate in reverse, iterate over multiple containeres, etc.
#define INLINE
Macros for conditional compilation based on selected compiler.
Definition: Object.h:31
#define UNUSED(x)
Definition: Object.h:37
#define NAMESPACE_SPH_END
Definition: Object.h:12
Quantity identifiers.
QuantityId
Unique IDs of basic quantities of SPH particles.
Definition: QuantityIds.h:19
Random number generators.
INLINE Optional< TValue & > tryGet(const TKey &key)
Returns a reference to the value matching the given key, or NOTHING if no such value exists.
Definition: FlatMap.h:118
Material settings and functions specific for one material.
Definition: IMaterial.h:110
FlatMap< QuantityId, Interval > ranges
Allowed range of quantities.
Definition: IMaterial.h:119
INLINE TValue getParam(const BodySettingsId paramIdx) const
Returns a parameter associated with given particle.
Definition: IMaterial.h:137
static const Float DEFAULT_MINIMAL
Definition: IMaterial.h:123
FlatMap< QuantityId, Float > minimals
Minimal values used in timestepping, do not affect values of quantities themselves.
Definition: IMaterial.h:116
INLINE const Interval range(const QuantityId id) const
Returns the range of allowed quantity values.
Definition: IMaterial.h:172
INLINE Float minimal(const QuantityId id) const
Returns the scale value of the quantity.
Definition: IMaterial.h:163
IMaterial(const BodySettings &settings)
Definition: IMaterial.h:126
INLINE const BodySettings & getParams() const
Returns settings containing material parameters.
Definition: IMaterial.h:142
virtual void finalize(IScheduler &scheduler, Storage &storage, const IndexSequence sequence)=0
Finalizes the material for the time step.
static const Interval DEFAULT_RANGE
Default values.
Definition: IMaterial.h:122
INLINE void setRange(const QuantityId id, const BodySettingsId rangeId, const BodySettingsId minimalId)
Sets the timestepping parameters of given quantity.
Definition: IMaterial.h:155
virtual void initialize(IScheduler &scheduler, Storage &storage, const IndexSequence sequence)=0
Initialize all quantities and material parameters.
BodySettings params
Per-material parameters.
Definition: IMaterial.h:113
INLINE IMaterial & setParam(const BodySettingsId paramIdx, TValue &&value)
Definition: IMaterial.h:130
void setRange(const QuantityId id, const Interval &range, const Float minimal)
Sets the timestepping parameters of given quantity.
Definition: IMaterial.cpp:17
virtual void create(Storage &storage, const MaterialInitialContext &context)=0
Create all quantities needed by the material.
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
Non-owning wrapper of a material and particles with this material.
Definition: IMaterial.h:30
INLINE MaterialView(RawPtr< IMaterial > &&material, IndexSequence seq)
Definition: IMaterial.h:36
INLINE const IndexSequence sequence() const
Returns iterable index sequence, const version.
Definition: IMaterial.h:80
INLINE IMaterial & material() const
Returns the const reference to the material of the particles.
Definition: IMaterial.h:49
INLINE IMaterial & material()
Returns the reference to the material of the particles.
Definition: IMaterial.h:43
INLINE IndexSequence sequence()
Returns iterable index sequence.
Definition: IMaterial.h:75
INLINE RawPtr< const IMaterial > operator->() const
Overloaded -> operator for convenient access to material functions.
Definition: IMaterial.h:70
INLINE RawPtr< IMaterial > operator->()
Overloaded -> operator for convenient access to material functions.
Definition: IMaterial.h:65
Material that does not require any initialization or finalization.
Definition: IMaterial.h:200
virtual void initialize(IScheduler &UNUSED(scheduler), Storage &UNUSED(storage), const IndexSequence UNUSED(sequence)) override
Definition: IMaterial.h:207
virtual void create(Storage &UNUSED(storage), const MaterialInitialContext &UNUSED(context)) override
Definition: IMaterial.h:205
virtual void finalize(IScheduler &UNUSED(scheduler), Storage &UNUSED(storage), const IndexSequence UNUSED(sequence)) override
Definition: IMaterial.h:211
NullMaterial(const BodySettings &body)
Definition: IMaterial.h:202
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
Container storing all quantities used within the simulations.
Definition: Storage.h:230
Generic storage and input/output routines of settings.
BodySettingsId
Settings of a single body / gas phase / ...
Definition: Settings.h:1394
Overload of std::swap for Sph::Array.
Definition: Array.h:578
Shared data used when creating all bodies in the simulation.
Definition: IMaterial.h:89
MaterialInitialContext()=default
SharedPtr< IScheduler > scheduler
Definition: IMaterial.h:93
AutoPtr< IUvMapping > uvMap
If used, texture mapping coordinates are generated provided mapping.
Definition: IMaterial.h:99
Float kernelRadius
Kernel radius in units of smoothing length.
Definition: IMaterial.h:96
AutoPtr< IRng > rng
Random number generator.
Definition: IMaterial.h:91
Base class for all polymorphic objects.
Definition: Object.h:88