opensurgsim
SphRepresentation.h
1 // This file is a part of the OpenSurgSim project.
2 // Copyright 2013-2015, SimQuest Solutions Inc.
3 //
4 // Licensed under the Apache License, Version 2.0 (the "License");
5 // you may not use this file except in compliance with the License.
6 // You may obtain a copy of the License at
7 //
8 // http://www.apache.org/licenses/LICENSE-2.0
9 //
10 // Unless required by applicable law or agreed to in writing, software
11 // distributed under the License is distributed on an "AS IS" BASIS,
12 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 // See the License for the specific language governing permissions and
14 // limitations under the License.
15 
16 #ifndef SURGSIM_PARTICLES_SPHREPRESENTATION_H
17 #define SURGSIM_PARTICLES_SPHREPRESENTATION_H
18 
19 #include <Eigen/Core>
20 #include <vector>
21 
22 #include "SurgSim/Math/Vector.h"
23 #include "SurgSim/Particles/Representation.h"
24 
25 
26 namespace SurgSim
27 {
28 
29 namespace DataStructures
30 {
31 template <class T, size_t N>
32 class Grid;
33 }; // namespace DataStructures
34 
35 namespace Particles
36 {
37 
38 SURGSIM_STATIC_REGISTRATION(SphRepresentation);
39 
47 {
48 public:
49  SURGSIM_CLASSNAME(SurgSim::Particles::SphRepresentation);
50 
53  explicit SphRepresentation(const std::string& name);
54 
56  virtual ~SphRepresentation();
57 
65  void setMassPerParticle(double particleMass);
66 
69  double getMassPerParticle() const;
70 
74  void setDensity(double density);
75 
78  double getDensity() const;
79 
83  void setGasStiffness(double stiffness);
84 
87  double getGasStiffness() const;
88 
92  void setSurfaceTension(double surfaceTension);
93 
96  double getSurfaceTension() const;
97 
100  void setGravity(const SurgSim::Math::Vector3d& gravity);
101 
104  SurgSim::Math::Vector3d getGravity() const;
105 
109  void setViscosity(double viscosity);
110 
113  double getViscosity() const;
114 
118  void setKernelSupport(double support);
119 
122  double getKernelSupport() const;
123 
126  void setStiffness(double stiffness);
127 
130  double getStiffness() const;
131 
134  void setDamping(double damping);
135 
138  double getDamping() const;
139 
142  void setFriction(double friction);
143 
146  double getFriction() const;
147 
148 protected:
149  bool doInitialize() override;
150 
151  bool doUpdate(double dt) override;
152 
153  bool doHandleCollisions(double dt, const SurgSim::Collision::ContactMapType& collisions) override;
154 
159  void computeVelocityAndPosition(double dt);
160 
161  Eigen::Matrix<double, Eigen::Dynamic, 3, Eigen::RowMajor> m_normal;
162  Eigen::Matrix<double, Eigen::Dynamic, 3, Eigen::RowMajor> m_acceleration;
165  double m_mass;
167  double m_gasStiffness;
169  double m_stiffness;
170  double m_damping;
171  double m_friction;
173  double m_viscosity;
174 
176  double m_h;
177  double m_hSquared;
178  double m_kernelPoly6;
179  double m_kernelPoly6Gradient;
180  double m_kernelSpikyGradient;
181  double m_kernelViscosityLaplacian;
182  double m_kernelPoly6Laplacian;
183 
185  std::shared_ptr<SurgSim::DataStructures::Grid<size_t, 3>> m_grid;
186 
187 private:
189  void computeNeighbors();
190 
192  void computeDensityAndPressureField();
193 
195  void computeNormalField();
196 
198  void computeAccelerations();
199 
200 };
201 
202 }; // namespace Particles
203 }; // namespace SurgSim
204 
205 #endif // SURGSIM_PARTICLES_SPHREPRESENTATION_H
double m_surfaceTension
Surface tension.
Definition: SphRepresentation.h:168
Math::Vector m_pressure
Particles&#39; pressure.
Definition: SphRepresentation.h:164
Wraps glewInit() to separate the glew opengl definitions from the osg opengl definitions only imgui n...
Definition: AddRandomSphereBehavior.cpp:36
double m_gasStiffness
Stiffness of the gas considered.
Definition: SphRepresentation.h:167
double m_friction
Collision sliding friction coefficient.
Definition: SphRepresentation.h:171
Math::Vector m_density
Particles&#39; density.
Definition: SphRepresentation.h:163
Eigen::Matrix< double, Eigen::Dynamic, 3, Eigen::RowMajor > m_normal
Particles&#39; normal.
Definition: SphRepresentation.h:161
Eigen::Matrix< double, Eigen::Dynamic, 3, Eigen::RowMajor > m_acceleration
Particles&#39; acceleration.
Definition: SphRepresentation.h:162
double m_damping
Collision damping.
Definition: SphRepresentation.h:170
The Representation class defines the base class for all Particle System.
Definition: Representation.h:40
double m_h
Kernels parameter (support length and its powers)
Definition: SphRepresentation.h:176
Eigen::Matrix< double, 3, 1 > Vector3d
A 3D vector of doubles.
Definition: Vector.h:57
double m_mass
Mass per particle (determine the density of particle per m3)
Definition: SphRepresentation.h:165
SurgSim::Math::Vector3d m_gravity
3D Gravity vector
Definition: SphRepresentation.h:172
Eigen::Matrix< double, Eigen::Dynamic, 1 > Vector
A dynamic size column vector.
Definition: Vector.h:68
double m_densityReference
Density of the reference gas.
Definition: SphRepresentation.h:166
Definitions of small fixed-size vector types.
double m_stiffness
Collision stiffness.
Definition: SphRepresentation.h:169
double m_viscosity
Viscosity coefficient.
Definition: SphRepresentation.h:173
std::shared_ptr< SurgSim::DataStructures::Grid< size_t, 3 > > m_grid
Grid acceleration to evaluate the kernels locally (storing the particles&#39; index)
Definition: SphRepresentation.h:185
SphRepresentation is a Representation dedicated to Smoothed-Particles Hydrodynamics (SPH)...
Definition: SphRepresentation.h:46