Loading...
Searching...
No Matches
MPMFluidConstitutiveModel-Impl.hpp
Go to the documentation of this file.
1// This code is based on Jet framework.
2// Copyright (c) 2018 Doyub Kim
3// CubbyFlow is voxel-based fluid simulation engine for computer games.
4// Copyright (c) 2020 CubbyFlow Team
5// Core Part: Chris Ohk, Junwoo Hwang, Jihong Sin, Seungwoo Yoo
6// AI Part: Dongheon Cho, Minseo Kim
7// We are making my contributions/submissions to this project solely in our
8// personal capacity and are not conveying any rights to any intellectual
9// property of any third parties.
10
11#ifndef CUBBYFLOW_MPM_FLUID_CONSTITUTIVE_MODEL_IMPL_HPP
12#define CUBBYFLOW_MPM_FLUID_CONSTITUTIVE_MODEL_IMPL_HPP
13
15
16#include <cmath>
17#include <stdexcept>
18
19namespace CubbyFlow
20{
21template <size_t N>
23 double targetDensity, double speedOfSound, double eosExponent,
25 : m_targetDensity(targetDensity),
26 m_speedOfSound(speedOfSound),
27 m_eosExponent(eosExponent),
28 m_negativePressureScale(negativePressureScale),
30{
31 if (!std::isfinite(m_targetDensity) || m_targetDensity <= 0.0 ||
32 !std::isfinite(m_speedOfSound) || m_speedOfSound <= 0.0 ||
33 !std::isfinite(m_eosExponent) || m_eosExponent < 1.0 ||
34 !std::isfinite(m_negativePressureScale) ||
36 !std::isfinite(m_eosScale) || m_eosScale <= 0.0)
37 {
38 throw std::invalid_argument{ "Invalid MPM fluid model parameters." };
39 }
40}
41
42template <size_t N>
44{
45 return m_targetDensity;
46}
47
48template <size_t N>
50{
51 return m_speedOfSound;
52}
53
54template <size_t N>
56{
57 return m_eosExponent;
58}
59
60template <size_t N>
62{
63 return m_negativePressureScale;
64}
65
66template <size_t N>
68 double currentVolume) const
69{
70 if (!std::isfinite(mass) || mass <= 0.0 || !std::isfinite(currentVolume) ||
71 currentVolume <= 0.0)
72 {
73 throw std::invalid_argument{ "Invalid MPM fluid mass or volume." };
74 }
75
76 const double density = mass / currentVolume;
77
78 if (!std::isfinite(density) || density <= 0.0)
79 {
80 throw std::invalid_argument{ "Invalid MPM fluid density." };
81 }
82
83 return density;
84}
85
86template <size_t N>
88{
89 if (!std::isfinite(density) || density <= 0.0)
90 {
91 throw std::invalid_argument{ "Invalid MPM fluid density." };
92 }
93
94 const double pressure =
95 ComputePressureFromEos(density, m_targetDensity, m_eosScale,
96 m_eosExponent, m_negativePressureScale);
97
98 if (!std::isfinite(pressure))
99 {
100 throw std::invalid_argument{ "Non-finite MPM fluid pressure." };
101 }
102
103 return pressure;
104}
105
106template <size_t N>
109{
110 if (!std::isfinite(pressure))
111 {
112 throw std::invalid_argument{ "Invalid MPM fluid pressure." };
113 }
114
115 return -pressure * MatrixType::MakeIdentity();
116}
117} // namespace CubbyFlow
118
119#endif
double GetNegativePressureScale() const
Returns the negative-pressure scale.
Definition MPMFluidConstitutiveModel-Impl.hpp:61
MatrixType ComputeCauchyStress(double pressure) const
Converts pressure to the isotropic Cauchy stress -p I.
Definition MPMFluidConstitutiveModel-Impl.hpp:108
double ComputePressure(double density) const
Computes equation-of-state pressure for a density.
Definition MPMFluidConstitutiveModel-Impl.hpp:87
MPMFluidConstitutiveModel(double targetDensity=WATER_DENSITY, double speedOfSound=100.0, double eosExponent=7.0, double negativePressureScale=0.0)
Constructs a weakly compressible MPM fluid model.
Definition MPMFluidConstitutiveModel-Impl.hpp:22
double GetTargetDensity() const
Returns the target density.
Definition MPMFluidConstitutiveModel-Impl.hpp:43
double GetEosExponent() const
Returns the equation-of-state exponent.
Definition MPMFluidConstitutiveModel-Impl.hpp:55
double GetSpeedOfSound() const
Returns the speed of sound.
Definition MPMFluidConstitutiveModel-Impl.hpp:49
double ComputeDensity(double mass, double currentVolume) const
Computes density from particle mass and current volume.
Definition MPMFluidConstitutiveModel-Impl.hpp:67
Definition Matrix.hpp:30
Definition pybind11Utils.hpp:22
double ComputePressureFromEos(double density, double targetDensity, double eosScale, double eosExponent, double negativePressureScale)
Definition PhysicsHelpers.hpp:49
Matrix< T, Rows, 1 > Vector
Definition Matrix.hpp:648