Newton Dynamics  4.00
ndBodySphFluid.h
1 /* Copyright (c) <2003-2022> <Julio Jerez, Newton Game Dynamics>
2 *
3 * This software is provided 'as-is', without any express or implied
4 * warranty. In no event will the authors be held liable for any damages
5 * arising from the use of this software.
6 *
7 * Permission is granted to anyone to use this software for any purpose,
8 * including commercial applications, and to alter it and redistribute it
9 * freely, subject to the following restrictions:
10 *
11 * 1. The origin of this software must not be misrepresented; you must not
12 * claim that you wrote the original software. If you use this software
13 * in a product, an acknowledgment in the product documentation would be
14 * appreciated but is not required.
15 *
16 * 2. Altered source versions must be plainly marked as such, and must not be
17 * misrepresented as being the original software.
18 *
19 * 3. This notice may not be removed or altered from any source distribution.
20 */
21 
22 #ifndef __ND_BODY_SPH_FLUID_CPU_H__
23 #define __ND_BODY_SPH_FLUID_CPU_H__
24 
25 #include "ndNewtonStdafx.h"
26 #include "ndBodyParticleSet.h"
27 
28 D_MSV_NEWTON_ALIGN_32
30 {
31  public:
32  D_NEWTON_API ndBodySphFluid();
33  D_NEWTON_API ndBodySphFluid(const ndLoadSaveBase::ndLoadDescriptor& desc);
34  D_NEWTON_API virtual ~ndBodySphFluid ();
35 
36  ndFloat32 GetViscosity() const;
37  void SetViscosity(ndFloat32 viscosity);
38 
39  ndFloat32 GetParticleMass() const;
40  void SetParticleMass(ndFloat32 mass);
41 
42  ndFloat32 GetRestDensity() const;
43  void SetRestDensity(ndFloat32 resDensity);
44 
45  ndFloat32 GetGasConstant() const;
46  void SetGasConstant(ndFloat32 gasConst);
47 
48  ndFloat32 GetSphGridSize() const;
49 
50  virtual ndBodySphFluid* GetAsBodySphFluid();
51  D_NEWTON_API virtual void Save(const ndLoadSaveBase::ndSaveDescriptor& desc) const;
52 
53  D_NEWTON_API void Execute(ndThreadPool* const threadPool);
54 
55  protected:
56  D_NEWTON_API virtual void Update(const ndWorld* const world, ndFloat32 timestep);
57  virtual bool RayCast(ndRayCastNotify& callback, const ndFastRay& ray, const ndFloat32 maxT) const;
58 
59  private:
60  enum ndGridType
61  {
62  ndAdjacentGrid = 0,
63  ndHomeGrid = 1,
64  };
65 
66  class ndGridHash;
67  class ndParticlePair;
68  class ndWorkingBuffers;
70 
71  void SortGrids(ndThreadPool* const threadPool);
72  void BuildPairs(ndThreadPool* const threadPool);
73  void CreateGrids(ndThreadPool* const threadPool);
74  void CaculateAabb(ndThreadPool* const threadPool);
75  void SortXdimension(ndThreadPool* const threadPool);
76  void CalculateScans(ndThreadPool* const threadPool);
77  void SortCellBuckects(ndThreadPool* const threadPool);
78  void IntegrateParticles(ndThreadPool* const threadPool);
79  void CalculateAccelerations(ndThreadPool* const threadPool);
80  void CalculateParticlesDensity(ndThreadPool* const threadPool);
81 
82  ndWorkingBuffers* m_workingBuffers;
83  ndFloat32 m_mass;
84  ndFloat32 m_viscosity;
85  ndFloat32 m_restDensity;
86  ndFloat32 m_gasConstant;
87  ndFloat32 m_timestep;
88 } D_GCC_NEWTON_ALIGN_32 ;
89 
90 inline bool ndBodySphFluid::RayCast(ndRayCastNotify&, const ndFastRay&, const ndFloat32) const
91 {
92  return false;
93 }
94 
95 inline ndBodySphFluid* ndBodySphFluid::GetAsBodySphFluid()
96 {
97  return this;
98 }
99 
100 inline ndFloat32 ndBodySphFluid::GetViscosity() const
101 {
102  return m_viscosity;
103 }
104 
105 inline void ndBodySphFluid::SetViscosity(ndFloat32 viscosity)
106 {
107  m_viscosity = viscosity;
108 }
109 
110 inline ndFloat32 ndBodySphFluid::GetParticleMass() const
111 {
112  return m_mass;
113 }
114 
115 inline void ndBodySphFluid::SetParticleMass(ndFloat32 mass)
116 {
117  m_mass = mass;
118 }
119 
120 inline ndFloat32 ndBodySphFluid::GetRestDensity() const
121 {
122  return m_restDensity;
123 }
124 
125 inline void ndBodySphFluid::SetRestDensity(ndFloat32 restDensity)
126 {
127  m_restDensity = restDensity;
128 }
129 
130 inline ndFloat32 ndBodySphFluid::GetGasConstant() const
131 {
132  return m_gasConstant;
133 }
134 
135 inline void ndBodySphFluid::SetGasConstant(ndFloat32 gasConst)
136 {
137  m_gasConstant = gasConst;
138 }
139 
140 inline ndFloat32 ndBodySphFluid::GetSphGridSize() const
141 {
142  return GetParticleRadius() * ndFloat32(2.0f) * ndFloat32(1.5f);
143  //return GetParticleRadius() * ndFloat32(2.0f) * ndFloat32(0.75f);
144 }
145 
146 #endif
147 
148 
ndRayCastNotify
Definition: ndRayCastNotify.h:31
ndBodySphFluid::ndParticleKernelDistance
Definition: ndBodySphFluid.cpp:93
ndBodySphFluid
Definition: ndBodySphFluid.h:30
ndFastRay
Definition: ndFastRay.h:48
ndBodySphFluid::ndGridHash
Definition: ndBodySphFluid.cpp:31
ndThreadPool
Definition: ndThreadPool.h:65
ndBodySphFluid::ndParticlePair
Definition: ndBodySphFluid.cpp:87
ndLoadSaveBase::ndLoadDescriptor
Definition: ndSaveLoadSytem.h:59
ndLoadSaveBase::ndSaveDescriptor
Definition: ndSaveLoadSytem.h:93
ndBodyParticleSet
Definition: ndBodyParticleSet.h:29
ndBodySphFluid::ndWorkingBuffers
Definition: ndBodySphFluid.cpp:99
ndWorld
Definition: ndWorld.h:47