-
Notifications
You must be signed in to change notification settings - Fork 0
/
MConstitutive.cpp
executable file
·263 lines (211 loc) · 5.67 KB
/
MConstitutive.cpp
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
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
#include "MConstitutive.h"
#include <stdio.h>
void MConstitutive::PrintScreenLog(const std::string &msg, FILE** logfile)
{
printf("%s\n", msg.c_str());
fprintf(*logfile, "%s\n", msg.c_str());
}
int MConstitutive::Constitutive(MParticle &p, MMaterial &mater, FILE** logfile, real gvdt)
{
char msg[300];
switch (mater.model)
{
// Elastic
case 1: break;
F3DM1(p, mater, gvdt);
AViscosity(p, mater);
break;
// Elastic-plastic
case 3: break;
// Fluid Hydrodynamic
case 9:
F3DM9(p, mater);
AViscosity(p, mater);
HieUpdate(p, gvdt);
if (EquationOfState(p, mater, logfile) != OK) return ERROR;
StressUp(p);
break;
// Elastic-plastic hydrodynamic
case 10: break;
default:
sprintf(msg, "Material type %5d is not supported.", mater.model);
PrintScreenLog(msg, logfile);
return ERROR;
}
return OK;
}
int MConstitutive::F3DM9(MParticle &p, MMaterial &mater)
{
real davg, xmu;
RealMatrix davgMatrix;
// Dynamic viscosity hardcoded, to be changed
if (mater.eos==13)
xmu = mater.strinput(1);
else if (mater.eos==28 || mater.eos==29)
xmu = mater.av_l*mater.rho;
// Deviatoric part of stress tensor
if ( fabs(xmu)<1.e-10 )
p.s.clear();
else
{
davg = 1.0/3.0 * p.tracerod;
davgMatrix.clear();
for (int i=0; i<3; i++) davgMatrix(i,i)=davg;
// Deviatoric part of stress tensor
p.s = 2 * xmu * (p.rod - davgMatrix);
}
return OK;
}
/*
int MConstitutive::LIEUPD(MParticle &p, MMaterial &mater, real gvdt)
{
real qpm = 0.5;
//??????????????????????????
p.e = p.e +(p.einc - gvdt*qpm)*p.mass/p.rho
return OK;
integer:: nn,nn1,davg
real(kind=real_acc) :: qp,qpm
real(kind=real_acc) :: sss(3,3),ss(9),ppp(3,3),pp(9)
!
sss = par(nn)%q(1:3,1:3)
ppp = par(nn)%rod(1:3,1:3)
pp = pack(ppp,.true.)
ss = reshape(source=sss,shape=shape(ss))
qpm = dot_product(ss,pp)
! qp=sum(qpm)
!
par(nn)%e = par(nn)%e + (par(nn)%einc - mcm_dt*qpm) * par(nn)%mass/par(nn)%rho
!
end
*/
//}
int MConstitutive::F3DM1(MParticle &p, MMaterial &mater, real gvdt)
{
real ym = 2.1e10; //mater.strinput(42); //Young's modulus
real pr = 0.3; //mater.strinput(42); //Poison's ratio
real gg = 0.0; //mater.strinput(42); // shear modulus
gg = ym/(2*(1+pr));
gvdt = 0.5;
RealMatrix davgMatrix, p_incrMatrix;
real gdt, gd2, blk, davg, p_incr;
gdt = gvdt*gg;
gd2 = 2.0*gdt;
blk = gvdt*ym/(1.0-2.0*(pr));
davg = 1.0/3.0 * p.tracerod;
p_incr = blk*davg;
for (int i=0; i<3; i++)
{
davgMatrix(i,i)=davg;
p_incrMatrix(i,i) = p_incr;
}
p.sigma = p.sigma + p_incrMatrix + gd2*(p.rod - davgMatrix); // + gv.sph_dt(p.sigma*p.spin + p.spin*p.sigma)
return OK;
}
void MConstitutive::AViscosity(MParticle &p, MMaterial &mater)
{
if (p.tracerod<0.0)
{
real q = mater.av_l * p.rho * p.c * p.h * fabs(p.tracerod) + // linear
mater.av_q * p.rho * SQR(p.h*p.tracerod); // quadratic
p.q.clear();
for (int i=0; i<3; i++) p.q(i,i)=q;
}
}
int MConstitutive::EquationOfState(MParticle &p, MMaterial &mater, FILE **logfile)
{
char msg[300];
switch (mater.eos)
{
// EOSes to be implemented
case 1: case 4: case 41:
sprintf(msg, "EOS %5d not supported yet.", mater.eos);
PrintScreenLog(msg, logfile);
return ERROR;
break;
// Monaghan quasi-incompressible fluid
case 28:
EOS28(p, mater);
break;
// Morris quasi-incompressible fluid
case 29:
EOS29(p, mater);
break;
// Perfect gas
case 13:
EOS13(p, mater);
break;
}
return OK;
}
int MConstitutive::EOS28(MParticle &p, MMaterial &mater)
{
// ASSIGN EOS PARAMETERS PER MATERIAL
real b = mater.eosinput(0);
real gamma = mater.eosinput(1);
// CALCULATE pressure and sound speed, Monaghan 94.
p.p = b * ( pow(p.rho/p.rho0,gamma) - 1.0);
p.c = sqrt(b * gamma/p.rho0);
return OK;
}
// EOS 29 is the equation introduced by Morris 97.
int MConstitutive::EOS29(MParticle &p, MMaterial &mater)
{
// CALCULATE pressure and sound speed, Morris 97.
p.c = mater.eosinput(0);
p.p = SQR(p.c) * (p.rho - p.rho0);
//p.p = SQR(p.c) * p.rho;
return OK;
}
int MConstitutive::EOS13(MParticle &p, MMaterial &mater)
{
real gamma_m1 = mater.eosinput(0)-1;
// specific 'trial' value for internal energy
real e1try = p.etry/p.mass;
real dvol = p.mass/p.rho - p.mass/p.rhoold;
real vol0 = p.mass/p.rho0;
// CALCULATE p (according to J ANDERSON: Modern Compressible Flow
// James' notes)
p.p = (p.rho*gamma_m1*e1try) / (1.0+0.5*p.rho*gamma_m1*dvol/p.mass);
// CALCULATE e(i)
p.e = p.etry - 0.5*dvol*p.p;
/***************************************************************/
return OK;
}
int MConstitutive::StressUp(MParticle &p)
{
RealMatrix pressure;
pressure.clear();
for (int i=0; i<3; i++) pressure(i,i)=p.p;
p.sigma = -pressure + p.s;
return OK;
}
// Purpose: Calculate trial value of e
int MConstitutive::HieUpdate(MParticle &p, real gvdt)
{
real pold, othird=1./3, trace_q, volold, volnew, vavg, eincr, dvol;
real mean_incr;
RealMatrix de;
int i, j, k, l;
pold = -othird * (p.sigma(0,0) + p.sigma(1,1) + p.sigma(2,2));
trace_q = othird*(p.q(0,0) + p.q(1,1) + p.q(2,2));
volold = p.mass/p.rhoold;
volnew = p.mass/p.rho;
for(l=0; l<3; l++)
for (k=0; k<3; k++)
if (k==l)
de(k,l) = p.rod(k,l)*(0.5*(p.sigma(k,l)+pold+p.s(k,l)) - p.q(k,l)+trace_q);
else
de(k,l) = p.rod(k,l)*(0.5*(p.sigma(k,l)+p.s(k,l)) - p.q(k,l));
vavg = 0.5*(volnew + volold);
for(l=0, eincr=0.0; l<3; l++)
for (k=0; k<3; k++)
eincr += de(k,l);
eincr *= vavg;
// calculate energy increment due to hydrostatic (mean) terms
dvol = volnew - volold;
mean_incr = dvol * (0.5*pold + trace_q);
// calculate trial value of internal energy
p.etry = p.e + gvdt*eincr - mean_incr;
p.qold = p.q;
return OK;
}