[05910c]: src / thermophysicalModels / specie / equationOfState / mixturePengRobinson / mixturePengRobinsonI.H  Maximize  Restore  History

Download this file

451 lines (367 with data), 13.5 kB

  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
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
/*---------------------------------------------------------------------------*\
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright held by original author
\\/ M anipulation |
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
OpenFOAM is free software; you can redistribute it and/or modify it
under the terms of the GNU General Public License as published by the
Free Software Foundation; either version 2 of the License, or (at your
option) any later version.
OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
for more details.
You should have received a copy of the GNU General Public License
along with OpenFOAM; if not, write to the Free Software Foundation,
Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
Author
Christian Lucas
Institut f��r Thermodynamik
Technische Universit��t Braunschweig
Germany
\*---------------------------------------------------------------------------*/
#include "mixturePengRobinson.H"
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
namespace Foam
{
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
// Construct from components
// CL: needed for operator*
inline mixturePengRobinson::mixturePengRobinson
(
const pengRobinson& pr,
label numOfComp,
DynamicList<scalar> weigths,
DynamicList<mixturePengRobinson*> mixtureComponents,
scalar a0,
scalar b,
scalar Tcrit,
scalar n,
scalar rhostd
)
:
pengRobinson(pr),
numOfComp(numOfComp),
weigths(weigths),
mixtureComponents(mixtureComponents),
singleComponent(1)
{
a0_=a0;
b_=b;
Tcrit_=Tcrit;
n_=n;
rhostd_=rhostd;
}
// Construct from components
// CL: needed for operator+
inline mixturePengRobinson::mixturePengRobinson
(
const pengRobinson& pr,
label numOfComp,
DynamicList<scalar> weigths,
DynamicList<mixturePengRobinson*> mixtureComponents
)
:
pengRobinson(pr),
numOfComp(numOfComp),
weigths(weigths),
mixtureComponents(mixtureComponents),
singleComponent(0)
{
TSave=0.0;
//CL: following three DynamicList have no size in the new object
//CL: resize DynamicList
aComponents.resize(numOfComp);
daComponents.resize(numOfComp);
d2aComponents.resize(numOfComp);
rhostd_=this->rho(Pstd, Tstd, Pstd*this->W()/(Tstd*this->R()));
}
// Construct as named copy
inline mixturePengRobinson::mixturePengRobinson(const word& name, const mixturePengRobinson& pr)
:
pengRobinson(name, pr)
{}
// Construct and return a clone
inline autoPtr<mixturePengRobinson> mixturePengRobinson::clone() const
{
return autoPtr<mixturePengRobinson>(new mixturePengRobinson(*this));
}
// Selector from Istream
inline autoPtr<mixturePengRobinson> mixturePengRobinson::New(Istream& is)
{
return autoPtr<mixturePengRobinson>(new mixturePengRobinson(is));
}
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
//CL: updates the coefficents of the model after the construction of the mixture
//CL: uses the van der waals mixing rule
inline void mixturePengRobinson::updateModelCoefficients(const scalar T) const
{
// CL: to make sure that the coefficents are only updated if the mixture has more than 1 component
if (singleComponent==0)
{
// Checking if the mixture coefficient were already calculated for this temperature
if(TSave!=T)
{
label i,j;
aSave=0;
daSave=0;
d2aSave=0;
b_=0;
//CL: filling vector a, dadT and d2adT2
for (i=0;i<numOfComp;i++)
{
aComponents[i]=mixtureComponents[i]->a(T);
daComponents[i]=mixtureComponents[i]->dadT(T);
d2aComponents[i]=mixtureComponents[i]->d2adT2(T);
}
for (i=0;i<numOfComp;i++)
{
//CL: getting a(T), dadT(T) and d2adT2(T) for the mixture
//CL: using van der waals mixing rule
//CL: TODO: Include possibility to use coupling cofficients k_ij (see paper reference)
for (j=0;j<numOfComp;j++)
{
aSave=aSave+weigths[i]*weigths[j]*pow(aComponents[i]*aComponents[j],0.5)*this->W()*this->W();
// first and second order temperature derivative of the van der waals mixing rule for a(T)
if(i==j)
{
daSave=daSave+weigths[i]*weigths[i]*daComponents[i]*this->W()*this->W();
d2aSave=d2aSave+weigths[i]*weigths[i]*d2aComponents[i]*this->W()*this->W();
}
else
{
daSave=daSave+0.5*weigths[i]*weigths[j]*this->W()*this->W()
*(pow(aComponents[i]/aComponents[j],0.5)*daComponents[j]+pow(aComponents[j]/aComponents[i],0.5)*daComponents[i]);
d2aSave=d2aSave+0.5*weigths[i]*weigths[j]*this->W()*this->W()*
(
pow(aComponents[i]/aComponents[j],0.5)*d2aComponents[i]+pow(aComponents[j]/aComponents[i],0.5)*d2aComponents[j]
+0.5*pow(aComponents[i]*aComponents[j],-0.5)*(pow(daComponents[i],2)+pow(daComponents[j],2))
-0.5*daComponents[i]*daComponents[j]*(pow(aComponents[i]/aComponents[j],0.5)/aComponents[j]
+pow(aComponents[j]/aComponents[i],0.5)/aComponents[i])
);
}
}
//CL: getting b for the mixture
//CL: using van der waals mixing rule
b_=b_+weigths[i]*mixtureComponents[i]->b()*this->W();
//CL: saving the temperature at which the mixture coefficients are valid
TSave=T;
}
}
}
}
//returns the pressure for a given density and temperature
inline scalar mixturePengRobinson::p(const scalar rho, const scalar T) const
{
updateModelCoefficients(T);
return pengRobinson::p(rho,T);
}
//Real deviative dp/dv at constant temperature
//(molar values)
inline scalar mixturePengRobinson::dpdv(const scalar rho, const scalar T) const
{
updateModelCoefficients(T);
return pengRobinson::dpdv(rho,T);
}
//Real deviative dp/dT at constant molar volume
//(molar values)
inline scalar mixturePengRobinson::dpdT(const scalar rho, const scalar T) const
{
updateModelCoefficients(T);
return pengRobinson::dpdT(rho,T);
}
//Real deviative dv/dT at constant pressure
//(molar values)
inline scalar mixturePengRobinson::dvdT(const scalar rho, const scalar T) const
{
updateModelCoefficients(T);
return pengRobinson::dvdT(rho,T);
}
//Real deviative dv/dp at constant temperature
//(molar values)
inline scalar mixturePengRobinson::dvdp(const scalar rho, const scalar T) const
{
updateModelCoefficients(T);
return pengRobinson::dvdp(rho,T);
}
//needed to calculate the internal energy
//(molar values)
inline scalar mixturePengRobinson::integral_p_dv
(
const scalar rho,
const scalar T
) const
{
updateModelCoefficients(T);
return pengRobinson::integral_p_dv(rho,T);
}
//needed to calculate the entropy
//(molar values)
inline scalar mixturePengRobinson::integral_dpdT_dv
(
const scalar rho,
const scalar T
) const
{
updateModelCoefficients(T);
return pengRobinson::integral_dpdT_dv(rho,T);
}
//(molar values)
inline scalar mixturePengRobinson::d2pdT2(const scalar rho, const scalar T) const
{
updateModelCoefficients(T);
return pengRobinson::d2pdT2(rho,T);
}
//(molar values)
inline scalar mixturePengRobinson::d2pdv2(const scalar rho, const scalar T) const
{
updateModelCoefficients(T);
return pengRobinson::d2pdv2(rho,T);
}
//(molar values)
inline scalar mixturePengRobinson::d2vdT2(const scalar rho, const scalar T) const
{
updateModelCoefficients(T);
return pengRobinson::d2vdT2(rho,T);
}
//(molar values)
inline scalar mixturePengRobinson::d2pdvdT(const scalar rho, const scalar T) const
{
updateModelCoefficients(T);
return pengRobinson::d2pdvdT(rho,T);
}
// the result of this intergal is needed for the nasa based cp polynomial
//(molar values)
inline scalar mixturePengRobinson::integral_d2pdT2_dv
(
const scalar rho,
const scalar T
) const
{
updateModelCoefficients(T);
return pengRobinson::integral_d2pdT2_dv(rho,T);
}
//Isobar expansion Coefficent beta = 1/v (dv/dt) at constant p
//(molar values)
inline scalar mixturePengRobinson::isobarExpCoef
(
const scalar rho,
const scalar T
) const
{
updateModelCoefficients(T);
return pengRobinson::isobarExpCoef(rho,T);
}
//isothemal compressiblity kappa (not Thermal conductivity)
//(molar values)
inline scalar mixturePengRobinson::isothermalCompressiblity
(
const scalar rho,
const scalar T
) const
{
updateModelCoefficients(T);
return pengRobinson::isothermalCompressiblity(rho,T);
}
//- Return density [kg/m^3]on
inline scalar mixturePengRobinson::rho
(
const scalar p,
const scalar T,
const scalar rho0
) const
{
updateModelCoefficients(T);
return pengRobinson::rho(p,T,rho0);
}
//- Return density [kg/m^3]on
inline scalar mixturePengRobinson::rho(const scalar p, const scalar T) const
{
updateModelCoefficients(T);
return pengRobinson::rho(p,T);
}
//- Return compressibility drho/dp at T=constant [s^2/m^2]
inline scalar mixturePengRobinson::psi(const scalar rho, const scalar T) const
{
this->updateModelCoefficients(T);
return pengRobinson::psi(rho,T);
}
//- Return compression factor []
inline scalar mixturePengRobinson::Z
(
const scalar p,
const scalar T,
const scalar rho0
) const
{
updateModelCoefficients(T);
return pengRobinson::Z(p,T,rho0);
}
// * * * * * * * * * * * * * * * Member Operators * * * * * * * * * * * * * //
inline void mixturePengRobinson::operator+=(const mixturePengRobinson& pr)
{
//CL: Resizes the DynamicList if number of compontens is larger than the DynamicList
if((weigths.size()<numOfComp+1)||(mixtureComponents.size()<numOfComp+1))
{
weigths.setSize(2*numOfComp);
mixtureComponents.setSize(2*numOfComp);
}
//Cl: oldClass+=pr
//CL: Saving the object pointer and weigths of pr (which is @ mixtureComponents[0] and weigths[0]) at the numOfComp's value of the oldClass
weigths[numOfComp]=pr.weigths[0];
mixtureComponents[numOfComp]=pr.mixtureComponents[0];
pengRobinson::operator+=(pr);
//CL: increase number of Components by 1
numOfComp=numOfComp+1;
//CL: resize DynamicList so that they have a defined size in the mixture object
aComponents.resize(numOfComp);
daComponents.resize(numOfComp);
d2aComponents.resize(numOfComp);
//CL: setting TSave=0--> results that all coefficients (a, da, d2a) are calculated in updateModelCoefficients
TSave=0.0;
singleComponent=0;
rhostd_=this->rho(Pstd, Tstd, Pstd*this->W()/(Tstd*this->R()));
}
// * * * * * * * * * * * * * * * Friend Operators * * * * * * * * * * * * * //
inline mixturePengRobinson operator+
(
const mixturePengRobinson& pr1,
const mixturePengRobinson& pr2
)
{
//CL:save both a pointer to the objector pr1 and pr2 and the weights in the new object
DynamicList<scalar> weigths=pr1.weigths;
DynamicList<mixturePengRobinson*> mixtureComponents=pr1.mixtureComponents;
//CL: Resizes the DynamicList if number of compontens is larger than the DynamicList
if((weigths.size()<pr1.numOfComp+1)||(mixtureComponents.size()<pr1.numOfComp+1))
{
weigths.setSize(2*pr1.numOfComp);
mixtureComponents.setSize(2*pr1.numOfComp);
}
//CL: Getting the new weigths and mixtureComponents lists,
//CL: Saving the object pointer and weigths of pr2 (which is @ mixtureComponents[0] and weigths[0]) at the numOfComp's value of the new object
weigths[pr1.numOfComp]=pr2.weigths[0];
mixtureComponents[pr1.numOfComp]=pr2.mixtureComponents[0];
return mixturePengRobinson(static_cast<const pengRobinson&>(pr1)+static_cast<const pengRobinson&>(pr2),
pr1.numOfComp+1, weigths, mixtureComponents);
}
inline mixturePengRobinson operator*
(
const scalar s,
const mixturePengRobinson& pr
)
{
//CL: saving the "concentraction" of the component of the mixture in the vector weights
//CL: saved at the Position "numOfComp-1"
DynamicList<scalar> weigths=pr.weigths;
weigths[pr.numOfComp-1]=s*pr.nMoles();
return mixturePengRobinson(s*static_cast<const pengRobinson&>(pr), pr.numOfComp, weigths,
pr.mixtureComponents,pr.a0_,pr.b_,pr.Tcrit_,pr.n_,pr.rhostd_);
}
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
} // End namespace Foam
// ************************************************************************* //

Get latest updates about Open Source Projects, Conferences and News.

Sign up for the SourceForge newsletter:

JavaScript is required for this form.





No, thanks