SPH
Materials.cpp
Go to the documentation of this file.
1 #include "sph/Materials.h"
2 #include "io/Logger.h"
3 #include "physics/Eos.h"
4 #include "physics/Rheology.h"
5 #include "quantities/Quantity.h"
6 #include "quantities/Storage.h"
7 #include "system/Factory.h"
8 #include "thread/CheckFunction.h"
9 #include "thread/Scheduler.h"
10 
12 
14  : IMaterial(body)
15  , eos(std::move(eos)) {
16  SPH_ASSERT(this->eos);
17 }
18 
20  : EosMaterial(body, Factory::getEos(body)) {}
21 
22 Pair<Float> EosMaterial::evaluate(const Float rho, const Float u) const {
23  return eos->evaluate(rho, u);
24 }
25 
26 const IEos& EosMaterial::getEos() const {
27  return *eos;
28 }
29 
30 void EosMaterial::create(Storage& storage, const MaterialInitialContext& UNUSED(context)) {
32 
33  // set to defaults if not yet created
34  const Float rho0 = this->getParam<Float>(BodySettingsId::DENSITY);
35  const Float u0 = this->getParam<Float>(BodySettingsId::ENERGY);
38 
41  const Size n = storage.getParticleCnt();
42  Array<Float> p(n), cs(n);
43  for (Size i = 0; i < n; ++i) {
44  tie(p[i], cs[i]) = eos->evaluate(rho[i], u[i]);
45  }
46  storage.insert<Float>(QuantityId::PRESSURE, OrderEnum::ZERO, std::move(p));
47  storage.insert<Float>(QuantityId::SOUND_SPEED, OrderEnum::ZERO, std::move(cs));
48 }
49 
50 void EosMaterial::initialize(IScheduler& scheduler, Storage& storage, const IndexSequence sequence) {
52 
53  ArrayView<Float> rho, u, p, cs;
54  tie(rho, u, p, cs) = storage.getValues<Float>(
56  parallelFor(scheduler, sequence, [&](const Size i) INL {
59  tie(p[i], cs[i]) = eos->evaluate(rho[i], u[i]);
60  });
61 }
62 
64  : EosMaterial(body, std::move(eos))
65  , rheology(std::move(rheology)) {}
66 
68  : SolidMaterial(body, Factory::getEos(body), Factory::getRheology(body)) {}
69 
70 void SolidMaterial::create(Storage& storage, const MaterialInitialContext& context) {
72 
73  EosMaterial::create(storage, context);
74  rheology->create(storage, *this, context);
75 }
76 
77 void SolidMaterial::initialize(IScheduler& scheduler, Storage& storage, const IndexSequence sequence) {
79 
80  EosMaterial::initialize(scheduler, storage, sequence);
81  rheology->initialize(scheduler, storage, MaterialView(this, sequence));
82 }
83 
84 void SolidMaterial::finalize(IScheduler& scheduler, Storage& storage, const IndexSequence sequence) {
86 
87  EosMaterial::finalize(scheduler, storage, sequence);
88  rheology->integrate(scheduler, storage, MaterialView(this, sequence));
89 }
90 
93 
94  BodySettings settings;
95  switch (type) {
97  // this is the default, so we don't have to do anything
98  break;
99  case MaterialEnum::ICE:
100  settings.set(BodySettingsId::TILLOTSON_SMALL_A, 0.3_f)
103  .set(BodySettingsId::DENSITY, 917._f)
110  break;
111  case MaterialEnum::IRON:
112  settings.set(BodySettingsId::TILLOTSON_SMALL_A, 0.5_f)
115  .set(BodySettingsId::DENSITY, 7860._f)
116  .set(BodySettingsId::BULK_MODULUS, 1.28e11_f)
123  break;
125  settings.set(BodySettingsId::TILLOTSON_SMALL_A, 0.5_f)
128  .set(BodySettingsId::DENSITY, 3500._f)
129  .set(BodySettingsId::BULK_MODULUS, 1.31e11_f)
135  break;
136  default:
138  }
139 
140  return Factory::getMaterial(settings);
141 }
142 
#define SPH_ASSERT(x,...)
Definition: Assert.h:94
#define NOT_IMPLEMENTED
Helper macro marking missing implementation.
Definition: Assert.h:100
NAMESPACE_SPH_BEGIN
Definition: BarnesHut.cpp:13
Helper functions to check the internal consistency of the code.
@ NO_THROW
Function cannot throw exceptions.
#define CHECK_FUNCTION(flags)
Definition: CheckFunction.h:40
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
Logging routines of the run.
#define VERBOSE_LOG
Helper macro, creating.
Definition: Logger.h:242
AutoPtr< IMaterial > getMaterial(const MaterialEnum type)
Definition: Materials.cpp:91
SPH-specific implementation of particle materials.
MaterialEnum
Basic materials available in the code.
Definition: Materials.h:79
#define UNUSED(x)
Definition: Object.h:37
#define NAMESPACE_SPH_END
Definition: Object.h:12
#define INL
Definition: Object.h:32
@ PRESSURE
Pressure, affected by yielding and fragmentation model, always a scalar quantity.
@ ENERGY
Specific internal energy, always a scalar quantity.
@ DENSITY
Density, always a scalar quantity.
@ SOUND_SPEED
Sound speed, always a scalar quantity.
Holder of quantity values and their temporal derivatives.
@ ZERO
Quantity without derivatives, or "zero order" of quantity.
Rheology of materials.
Interface for executing tasks (potentially) asynchronously.
INLINE void parallelFor(IScheduler &scheduler, const Size from, const Size to, TFunctor &&functor)
Executes a functor concurrently from all available threads.
Definition: Scheduler.h:98
StaticArray< T0 &, sizeof...(TArgs)+1 > tie(T0 &t0, TArgs &... rest)
Creates a static array from a list of l-value references.
Definition: StaticArray.h:281
Container for storing particle quantities and materials.
Material holding equation of state.
Definition: Materials.h:21
virtual void finalize(IScheduler &UNUSED(scheduler), Storage &UNUSED(storage), const IndexSequence UNUSED(sequence)) override
Definition: Materials.h:49
virtual void initialize(IScheduler &scheduler, Storage &storage, const IndexSequence sequence) override
Initialize all quantities and material parameters.
Definition: Materials.cpp:50
const IEos & getEos() const
Returns the equation of state.
Definition: Materials.cpp:26
EosMaterial(const BodySettings &body, AutoPtr< IEos > &&eos)
Creates the material by specifying an equation of state.
Definition: Materials.cpp:13
Pair< Float > evaluate(const Float rho, const Float u) const
Definition: Materials.cpp:22
virtual void create(Storage &storage, const MaterialInitialContext &context) override
Create all quantities needed by the material.
Definition: Materials.cpp:30
Base class for equations of state.
Definition: Eos.h:16
virtual Pair< Float > evaluate(const Float rho, const Float u) const =0
Computes pressure and local sound speed from given density rho and specific internal energy u.
Material settings and functions specific for one material.
Definition: IMaterial.h:110
virtual void create(Storage &storage, IMaterial &material, const MaterialInitialContext &context) const =0
Creates all the necessary quantities and material parameters needed by the rheology.
virtual void integrate(IScheduler &scheduler, Storage &storage, const MaterialView material)=0
Computes derivatives of the time-dependent quantities of the rheological model.
virtual void initialize(IScheduler &scheduler, Storage &storage, const MaterialView material)=0
Evaluates the stress tensor reduction factors.
Interface that allows unified implementation of sequential and parallelized versions of algorithms.
Definition: Scheduler.h:27
Non-owning wrapper of a material and particles with this material.
Definition: IMaterial.h:30
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
Generalization of material with equation of state.
Definition: Materials.h:60
virtual void initialize(IScheduler &scheduler, Storage &storage, const IndexSequence sequence) override
Initialize all quantities and material parameters.
Definition: Materials.cpp:77
virtual void create(Storage &storage, const MaterialInitialContext &context) override
Create all quantities needed by the material.
Definition: Materials.cpp:70
virtual void finalize(IScheduler &scheduler, Storage &storage, const IndexSequence sequence) override
Finalizes the material for the time step.
Definition: Materials.cpp:84
SolidMaterial(const BodySettings &body, AutoPtr< IEos > &&eos, AutoPtr< IRheology > &&rheology)
Definition: Materials.cpp:63
Array with fixed number of allocated elements.
Definition: StaticArray.h:19
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
auto getValues(const QuantityId first, const QuantityId second, const TArgs... others)
Retrieves an array of quantities from the key.
Definition: Storage.h:359
Array< TValue > & getValue(const QuantityId key)
Retrieves a quantity values from the storage, given its key and value type.
Definition: Storage.cpp:191
Creating code components based on values from settings.
@ TILLOTSON_NONLINEAR_B
Coefficient B of the nonlinear compressive term in Tillotson equation.
@ TILLOTSON_ALPHA
Alpha coefficient in expanded phase of Tillotson equation.
@ TILLOTSON_ENERGY_CV
Specific energy of complete vaporization.
@ TILLOTSON_SMALL_B
"Small b" coefficient in Tillotson equation
@ TILLOTSON_BETA
Beta coefficient in expanded phase of Tillotson equation.
@ ENERGY
Initial specific internal energy.
@ BULK_MODULUS
Bulk modulus of the material.
@ DENSITY
Density at zero pressure.
@ HEAT_CAPACITY
Heat capacity at constant pressure,.
@ TILLOTSON_ENERGY_IV
Specific energy of incipient vaporization.
@ TILLOTSON_SMALL_A
"Small a" coefficient in Tillotson equation
@ TILLOTSON_SUBLIMATION
Specific sublimation energy.
Provides a convenient way to construct objects from settings.
Definition: Factory.h:46
AutoPtr< IMaterial > getMaterial(const BodySettings &settings)
Definition: Factory.cpp:508
AutoPtr< IRheology > getRheology(const BodySettings &settings)
Definition: Factory.cpp:69
AutoPtr< IEos > getEos(const BodySettings &settings)
Definition: Factory.cpp:47
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