-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathparticle.h
160 lines (140 loc) · 3.36 KB
/
particle.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
/*
* particle.h
*
* Created on: Nov 18, 2015
* Author: reza
*/
#ifndef PARTICLE_H_
#define PARTICLE_H_
#include <iostream>
#include <fstream>
#include <vector>
#include <time.h>
#include "vectorclass/vector3d.h"
using namespace std;
inline double kernel(double dij, double hRcp){
// double alpha = 0.167*hRcp; //In 1d = (1./6)*(1./*h)
double alpha = 0.114*hRcp*hRcp; //In 2d = (1./6)*(15/(7*pi*h*h))
// double alpha = 0.080*hRcp*hRcp*hRcp; //In 3d = (1./6)*(3/(2*pi*h*h*h))
double R = dij*hRcp;
double W;
if(R>2.0)
W = 0.;
else if(R>1.0){
double a = (2.-R);
W = alpha*a*a*a;
}
else{
double a = (2.-R);
double b = (1.-R);
W = alpha*(a*a*a - 4.*b*b*b);
}
return W;
}
inline Vec3d gradKernel(Vec3d Rij, double hRcp){
// double alpha = -0.500*hRcp*hRcp; //In 1d = (-3./h)*(1./6)*(1./*h)
double alpha = -0.341*hRcp*hRcp*hRcp; //In 2d = (-3./h)*(1./6)*(15/(7*pi*h*h))
// double alpha = -0.239*hRcp*hRcp*hRcp*hRcp; //In 3d = (-3./h)*(1./6)*(3/(2*pi*h*h*h))
double dij = vector_length(Rij);
double R = dij*hRcp;
double W;
if(R>2.0)
W = 0.;
else if(R>1.0){
double a = (2.-R);
W = alpha*a*a;
}
else{
double a = (2.-R);
double b = (1.-R);
W = alpha*(a*a - 4.*b*b);
}
Vec3d nij = normalize_vector(Rij);
return W*nij;
}
struct particle{
Vec3d r0; //initial position
Vec3d u; //displacement
Vec3d v; //velocity
Vec3d vleap; //velocity leap
Vec3d a; //acceleration
vector<double> gu; //gradient of displacement
vector<double> epsilon; //strain
vector<double> sigma; //stress
double m; //mass
double rho; //density
double V; //Initial volume
double E; //Young modulus
double nu; //Poisson ratio
double U; //Strain energy
int type; //type
particle(): gu(9),epsilon(9),sigma(9){};
};
class particleSystem{
private:
vector<particle> _particle;
public:
int particleSize();
void particleResize(int n);
particle getParticle(int n);
void setParticle(int n, particle p);
Vec3d getPosInit(int n);
void setPosInit(int n, Vec3d r0);
Vec3d getDisp(int n);
void setDisp(int n, Vec3d u);
vector<double> getGradDisp(int n);
void setGradDisp(int n, vector<double> gu);
vector<double> getEpsilon(int n);
void setEpsilon(int n, vector<double> epsilon);
vector<double> getSigma(int n);
void setSigma(int n, vector<double> sigma);
Vec3d getCurrPos(int n);
Vec3d getVel(int n);
void setVel(int n, Vec3d v);
Vec3d getVelLeap(int n);
void setVelLeap(int n, Vec3d vleap);
Vec3d getAcc(int n);
void setAcc(int n, Vec3d acc);
double getMass(int n);
void setMass(int n, double m);
double getDensity(int n);
void setDensity(int n, double rho);
void addDensity(int n, double rho);
double getVolume(int n);
void setVolume(int n, double V);
double getYoung(int n);
void setYoung(int n, double E);
double getPoisson(int n);
void setPoisson(int n, double nu);
double getStrainEnergy(int n);
void setStrainEnergy(int n, double U);
int getType(int n);
void setType(int n, int t);
};
class sph{
private:
particleSystem _pSys;
double t;
double tMax;
double dt;
double h;
double hRcp;
double g;
time_t timeStart;
int fileCounter;
int dumpSkip;
int loopCounter;
public:
sph();
double getT();
double getTMax();
int getDumpSkip();
int getLoopCounter();
void calcDensity();
void calcGradDisp();
void calcStrain();
void calcForce();
void timeIntegration();
void dumpData();
};
#endif /* PARTICLE_H_ */