Titan  v1.0
A high-performance CUDA-based physics simulation sandbox for robotics, physics, and reinforcement learning.
mass.h
Go to the documentation of this file.
1 //
2 // Created by Jacob Austin on 5/17/18.
3 //
4 
5 #ifndef TITAN_MASS_H
6 #define TITAN_MASS_H
7 
8 #include "vec.h"
9 #include "object.h"
10 
11 namespace titan {
12 
13 class Mass;
14 struct CUDA_MASS;
15 
16 class Mass {
17 public:
18  Mass(const Vec & position, double mass = 0.1, bool fixed = false);
19 
20  //Properties
21  double m; // mass in kg
22  double T; // local time
23  Vec pos; // position in m
24  Vec vel; // velocity in m/s
25 
26  void setExternalForce(const Vec & v) { extern_force = v; }
27  Vec acceleration() { return acc; }
28 
29 #ifdef CONSTRAINTS
30  void addConstraint(CONSTRAINT_TYPE type, const Vec & vec, double num);
31  void clearConstraints(CONSTRAINT_TYPE type);
32  void clearConstraints();
33 
34  void setDrag(double C);
35  void fix();
36  void unfix();
37 #endif
38 
39 #ifdef GRAPHICS
40  Vec color;
41 #endif
42 
43 private:
44  Vec acc; // acceleration in m/s^2
45  Vec extern_force; // force in kg m / s^2
46 
47  bool valid;
48  int ref_count;
49 
50  void decrementRefCount();
51 
52  CUDA_MASS * arrayptr; //Pointer to struct version for GPU cudaMemAlloc
53 
54 #ifdef RK2
55  Vec __rk2_backup_pos;
56  Vec __rk2_backup_vel;
57 #endif
58 
59  Mass();
60  void operator=(CUDA_MASS & mass);
61 
62  friend class Simulation;
63  friend class Spring;
64  friend struct CUDA_SPRING;
65  friend struct CUDA_MASS;
66  friend class Container;
67  friend class Lattice;
68  friend class Beam;
69  friend class Cube;
70 
71 #ifdef CONSTRAINTS
72  LOCAL_CONSTRAINTS constraints;
73 
74 #endif
75 
76 };
77 //Struct with CPU Spring properties used for optimal memory allocation on GPU memory
78 struct CUDA_MASS {
79  CUDA_MASS() = default;
80  CUDA_MASS(Mass & mass);
81 
82  double m; // mass in kg
83  double T; // local time
84  Vec pos; // position in m
85  Vec vel; // velocity in m/s
86  Vec acc; // acceleration in m/s^2
87  Vec force; // vector to accumulate external forces
88  Vec extern_force; // external force applied every timestep
89 
90 #ifdef RK2
91  Vec __rk2_backup_pos;
92  Vec __rk2_backup_vel;
93 #endif
94 
95 #ifdef GRAPHICS
96  Vec color;
97 #endif
98 
99  bool valid;
100 
101 #ifdef CONSTRAINTS
102  CUDA_LOCAL_CONSTRAINTS constraints;
103 #endif
104 
105 };
106 
107 } // namespace titan
108 
109 #endif //TITAN_MASS_H
titan::CUDA_MASS::pos
Vec pos
Definition: mass.h:84
titan::Container
Definition: object.h:230
titan
Definition: mass.h:11
titan::Simulation
Definition: sim.h:37
titan::CUDA_MASS::m
double m
Definition: mass.h:82
titan::CUDA_MASS::T
double T
Definition: mass.h:83
titan::CUDA_MASS::valid
bool valid
Definition: mass.h:99
titan::Spring
Definition: spring.h:19
titan::CUDA_MASS::vel
Vec vel
Definition: mass.h:85
titan::CUDA_MASS
Definition: mass.h:78
titan::Vec
Definition: vec.h:33
titan::CUDA_MASS::acc
Vec acc
Definition: mass.h:86
titan::Mass::m
double m
Definition: mass.h:21
titan::CUDA_SPRING
Definition: spring.h:68
titan::CUDA_MASS::force
Vec force
Definition: mass.h:87
titan::Mass::pos
Vec pos
Definition: mass.h:23
titan::CUDA_MASS::CUDA_MASS
CUDA_MASS(Mass &mass)
titan::Mass::acceleration
Vec acceleration()
Definition: mass.h:27
titan::CUDA_MASS::extern_force
Vec extern_force
Definition: mass.h:88
titan::Beam
Definition: object.h:277
titan::Mass::vel
Vec vel
Definition: mass.h:24
titan::Mass
Definition: mass.h:16
vec.h
titan::Mass::T
double T
Definition: mass.h:22
titan::Cube
Definition: object.h:257
titan::Lattice
Definition: object.h:267
titan::CUDA_MASS::CUDA_MASS
CUDA_MASS()=default
object.h
titan::Mass::Mass
Mass(const Vec &position, double mass=0.1, bool fixed=false)
titan::Mass::setExternalForce
void setExternalForce(const Vec &v)
Definition: mass.h:26