Hide keyboard shortcuts

Hot-keys on this page

r m x p   toggle line displays

j k   next/prev highlighted chunk

0   (zero) top of page

1   (one) first highlighted chunk

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

451

452

453

454

455

456

457

458

459

460

461

462

463

464

465

466

467

468

469

470

471

472

473

474

475

476

477

478

479

480

481

482

483

484

485

486

487

488

489

490

491

492

493

494

495

496

497

498

499

500

501

502

503

504

505

506

507

508

509

510

511

512

513

514

515

516

517

518

519

520

521

522

523

524

525

526

527

528

529

530

531

532

533

534

535

536

537

538

539

540

541

542

543

544

545

546

547

548

549

550

551

552

553

554

555

556

557

558

559

560

561

562

563

564

565

566

567

568

569

570

571

572

573

574

575

576

577

578

579

580

581

582

583

584

585

586

587

588

589

590

591

592

593

594

595

596

597

598

599

600

601

602

603

604

605

606

607

608

609

610

611

612

613

614

615

616

617

618

619

620

621

622

623

624

625

626

627

628

629

630

631

632

633

634

635

636

637

638

639

640

641

642

643

644

645

646

647

648

649

650

651

652

653

654

655

656

657

658

659

660

661

662

663

664

665

666

667

668

669

670

671

672

673

674

675

676

677

678

679

680

681

682

683

684

685

686

687

688

689

#!/usr/bin/env python 

# -*- coding: ascii -*- 

 

r""" 

RocketProps models liquid rocket propellants that are injected into  

liquid rocket chambers. 

 

RocketProps calculates the various propellant properties required 

to analyse a liquid propellant thrust chamber.  

This includes density, viscosity, vapor pressure, 

heat of vaporization, surface tension, heat capacity and thermal conductivity.  

Other properties such as critical temperature and pressure, normal boiling point,  

molecular weight and freezing temperature are available. 

 

 

RocketProps 

Copyright (C) 2020 Applied Python 

 

This program 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 3 of the License, or 

(at your option) any later version. 

 

This program 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 this program. If not, see <http://www.gnu.org/licenses/>. 

 

----------------------- 

 

""" 

import os 

here = os.path.abspath(os.path.dirname(__file__)) 

 

 

# for multi-file projects see LICENSE file for authorship info 

# for single file projects, insert following information 

__author__ = 'Charlie Taylor' 

__copyright__ = 'Copyright (c) 2020 Charlie Taylor' 

__license__ = 'GPL-3' 

exec( open(os.path.join( here,'_version.py' )).read() ) # creates local __version__ variable 

__email__ = "cet@appliedpython.com" 

__status__ = "4 - Beta" # "3 - Alpha", "4 - Beta", "5 - Production/Stable" 

 

# 

# import statements here. (built-in first, then 3rd party, then yours) 

# 

from math import exp, log 

import importlib 

from rocketprops.unit_conv_data import get_value 

from rocketprops.prop_names import prop_names 

 

 

TREF_K = get_value( 20.0, 'degC', 'degK') 

 

 

def get_prop( name, suppress_warning=False ): 

""" 

Return a Propellant object for the named propellant. 

 

:param name: name of propellant (for example "N2O4" or "LOX") 

:param suppress_warning: if True, then do not print warnings. 

:type name: string 

:type suppress_warning: boolean 

:return: Propellant object for named propellant 

:rtype: Propellant 

""" 

pname = prop_names.get_primary_name( name ) 

if pname is None: 

if not suppress_warning: 

print('WARNING... propellant "%s" is not available.'%name) 

return None 

 

filename = pname + '_prop' 

 

try: 

prop_obj = importlib.import_module( 'rocketprops.props.%s'%filename ) 

return prop_obj.Prop() # create instance and return it 

except: 

if not suppress_warning: 

print('WARNING... propellant "%s" is not available.'%name) 

return None 

 

 

 

class Propellant(object): 

"""RocketProps models liquid rocket propellants that are injected into liquid rocket chambers. 

""" 

 

def __init__(self, name='MMH'): 

""" 

Standard Condition for a liquid propellant is defined here as  

saturated liquid at Room Temperature (RT=20 C). 

 

If the propellant is not liquid at RT, then Standard Condition 

is Normal Boiling Point (NBP), i.e. saturated liquid at 1 atm pressure. 

 

NOTE: Propellant is designed as a Base Class... needs to be overriden 

by a specific propellant class. 

 

:param name : name of propellant 

:type name : str 

:return: None 

:rtype: None  

""" 

 

self.name = name 

self.pname = prop_names.get_primary_name( name ) 

self.set_std_state() # MUST Override Propellant to avoid Exception. 

 

@property 

def SGc(self): 

"""Return critical specific gravity.""" 

if self.Zc is None: 

return None 

 

lbm_per_cuin = self.Pc * self.MolWt / (18540.0 * self.Tc * self.Zc) 

return lbm_per_cuin * 27.67990471 # g/ml 

 

def set_std_state(self): 

raise NotImplementedError 

 

def summ_print(self): 

"""Print a summary of the Propellant object.""" 

print('====== RocketProps State Point of Liquid %s ====='%(self.pname, )) 

print( 'Name = %s'%prop_names.paren_desc( self.pname ) ) 

print( 'T = %12g'%self.T ,'degR') 

print( 'P = %12g'%self.P ,'psia') 

print( 'Pvap = %12g'%self.Pvap ,'psia') 

print( 'Pc = %12g'%self.Pc ,'psia') 

print( 'Tc = %12g'%self.Tc ,'degR') 

print( 'SGliq = %12g'%self.SG ,'g/cc') 

print( 'SGvap = %12g'%self.SGVapAtTdegR( self.T ) ,'g/cc') 

print( 'visc = %12g'%self.visc ,'poise') 

print( 'cond = %12g'%self.cond ,'BTU/hr/ft/delF') 

print( 'Tnbp = %12g'%self.Tnbp,'degR') 

print( 'Tfreeze = %12g'%self.Tfreeze,'degR') 

#print( 'Ttriple = %12g'%self.Ttriple,'degR') 

print( 'Cp = %12g'%self.Cp ,'BTU/lbm/delF') 

print( 'MolWt = %12g'%self.MolWt,'g/gmole') 

print( 'Hvap = %12g'%self.Hvap ,'BTU/lbm') 

if isinstance(self.surf, float): 

print( 'surf = %12g'%self.surf ,'lbf/in') 

else: 

print( 'surf = %12s'%self.surf ,'lbf/in') 

 

def TAtTr(self, Tr): 

"""Given reduced temperature, return absolute temperature in degR.""" 

return self.Tc * Tr 

 

def TdegRAtPsat(self, Psat): 

"""Given saturation pressure in psia, solve for saturation temperature in degR""" 

trmin = self.trL[0] 

trmax = 1.0 

 

for i in range(40): 

Tr = (trmin + trmax) / 2.0 

P = self.PvapAtTr(Tr) 

if P < Psat: 

trmin = Tr 

else: 

trmax = Tr 

 

return self.Tc * (trmin + trmax) / 2.0 

 

 

# ========= methods for absolute temperature deg rankine (TdegR) ============= 

 

def PvapAtTdegR(self, TdegR): 

"""Given temperature in degR, return saturation pressure in psia.""" 

Tr = TdegR / self.Tc 

return 10.0**self.log10p_terp( Tr ) 

 

def ViscAtTdegR(self, TdegR): 

"""Given temperature in degR, return viscosity of saturated liquid in poise.""" 

Tr = TdegR / self.Tc 

return 10.0**self.log10visc_terp( Tr ) 

 

def CondAtTdegR(self, TdegR): 

"""Given temperature in degR, return thermal conductivity of saturated liquid in BTU/hr-ft-R.""" 

Tr = TdegR / self.Tc 

return self.cond_terp( Tr ) 

 

def CpAtTdegR(self, TdegR): 

"""Given temperature in degR, return Heat Capacity of saturated liquid in BTU/lbm-R.""" 

Tr = TdegR / self.Tc 

return self.cp_terp( Tr ) 

 

def HvapAtTdegR(self, TdegR): 

"""Given temperature in degR, return heat of vaporization of saturated liquid in BTU/lbm.""" 

Tr = TdegR / self.Tc 

return self.hvap_terp( Tr ) 

 

def SurfAtTdegR(self, TdegR): 

"""Given temperature in degR, return surface tension of saturated liquid in lbf/in.""" 

Tr = TdegR / self.Tc 

return self.surf_terp( Tr ) 

 

def SGLiqAtTdegR(self, TdegR): 

"""Given temperature in degR, return specific gravity of saturated liquid in g/ml.""" 

Tr = TdegR / self.Tc 

return self.SG_liq_terp( Tr ) 

 

def SGVapAtTdegR(self, TdegR): 

"""Given temperature in degR, return specific gravity of Saturated Vapor in g/ml.""" 

Tr = TdegR / self.Tc 

return 10.0**self.log10SG_vap_terp( Tr ) 

 

def ZLiqAtTdegR(self, TdegR): 

"""Given temperature in degR, return compressibility of saturated liquid.""" 

Tr = TdegR / self.Tc 

return self.ZAtTr( Tr ) 

 

def ZVapAtTdegR(self, TdegR): 

"""Given temperature in degR, return compressibility of Saturated Vapor.""" 

Tr = TdegR / self.Tc 

return ZVapAtTr( Tr ) 

 

# ========= methods for reduced temperature (Tr) ============= 

 

def PvapAtTr(self, Tr): 

"""Given reduced temperature (Tr), return vapor pressure of saturated liquid in psia.""" 

return 10.0**self.log10p_terp( Tr ) 

 

def ViscAtTr(self, Tr): 

"""Given reduced temperature (Tr), return viscosity of saturated liquid in poise.""" 

return 10.0**self.log10visc_terp( Tr ) 

 

def CondAtTr(self, Tr): 

"""Given reduced temperature (Tr), return thermal conductivity of saturated liquid in BTU/hr-ft-R.""" 

return self.cond_terp( Tr ) 

 

def CpAtTr(self, Tr): 

"""Given reduced temperature (Tr), return heat capacity of saturated liquid in BTU/lbm-R.""" 

return self.cp_terp( Tr ) 

 

def HvapAtTr(self, Tr): 

"""Given reduced temperature (Tr), return heat of vaporization of saturated liquid in BTU/lbm.""" 

return self.hvap_terp( Tr ) 

 

def SurfAtTr(self, Tr): 

"""Given reduced temperature (Tr), return surface tension of saturated liquid in lbf/in.""" 

return self.surf_terp( Tr ) 

 

def SGLiqAtTr(self, Tr): 

"""Given reduced temperature (Tr), return specific gravity of saturated liquid in g/ml.""" 

return self.SG_liq_terp( Tr ) 

 

def SGVapAtTr(self, Tr): 

"""Given reduced temperature (Tr), return specific of Saturated Vapor in g/ml.""" 

return 10.0**self.log10SG_vap_terp( Tr ) 

 

def ZLiqAtTr(self, Tr): 

"""Given reduced temperature (Tr), return compressibility of saturated liquid.""" 

P = self.PvapAtTr( Tr ) 

sg = self.SGLiqAtTr( Tr ) 

T = Tr * self.Tc 

return P * self.MolWt / (18540.0 * T * (sg/27.67990471)) 

 

def ZVapAtTr(self, Tr): 

"""Given reduced temperature (Tr), return compressibility of Saturated Vapor.""" 

P = self.PvapAtTr( Tr ) 

sg = self.SGVapAtTr( Tr ) 

T = Tr * self.Tc 

return P * self.MolWt / (18540.0 * T * (sg/27.67990471)) 

 

# ================================================================ 

 

def Tr_data_range(self): 

"""Return tuple of reduced temperature range, (Trmin, Trmax)""" 

return self.trL[0], self.trL[-1] 

 

def T_data_range(self): 

"""Return tuple of temperature range, (Tmin, Tmax) in degR""" 

return self.tL[0], self.tL[-1] 

 

def P_data_range(self): 

"""Return tuple of pressure range, (Pmin, Pmax) in psia""" 

Plo = 10.0**( self.log10pL[0] ) 

Phi = 10.0**( self.log10pL[-1] ) 

return Plo, Phi 

 

def plot_sat_props(self, save_figures=False): 

"""Create and launch matplotlib plots of all saturation properties.""" 

import matplotlib.pyplot as plt 

 

trL = [self.trL[0] + i*(self.trL[-1]-self.trL[0])/200.0 for i in range(201) ] 

 

# ================== T and P ============================= 

fig, (ax1,ax2) = plt.subplots(2, 1, figsize=(6,8)) 

ax1.set_title( self.name + ' Temperature and Pressure' ) 

 

ax1.plot( self.trL, self.tL, 'rs', label='Temperature' ) 

ax1.plot( trL, [tr*self.Tc for tr in trL], 'r-', label='degR' ) 

ax1.set_ylabel( 'Temperature (degR)' ) 

ax1.grid() 

ax1.legend() 

 

ax2.grid() 

ax2.set_ylabel( 'Pressure (psia)' ) 

ax2.set_xlabel('Reduced Temperature (Tr)') 

ax2.semilogy( self.trL, [10.0**p for p in self.log10pL], 'gs', label='Pressure' ) 

ax2.semilogy( trL, [self.PvapAtTr(tr) for tr in trL], 'g-', label='psia' ) 

ax2.legend() 

fig.tight_layout() 

 

if save_figures: 

fname = '%s_TandP.png'%self.pname 

plt.savefig(fname) 

 

 

# ================== visc and cond ============================= 

fig, (ax1,ax2) = plt.subplots(2, 1, figsize=(6,8)) 

ax1.set_title( self.name + ' Viscosity and Thermal Conductivity' ) 

 

try: 

ax1.semilogy( self.trL, [10.0**p for p in self.log10viscL], 'rs', label='Visc' ) 

ax1.semilogy( trL, [self.ViscAtTr(tr) for tr in trL], 'r-', label='poise' ) 

except: 

pass 

ax1.set_ylabel( 'Viscosity (poise)' ) 

ax1.grid() 

ax1.legend() 

 

ax2.grid() 

ax2.set_ylabel( 'Thermal Conductivity (BTU/hr-ft-F)' ) 

ax2.set_xlabel('Reduced Temperature (Tr)') 

try: 

ax2.plot( self.trL, self.condL, 'gs', label='ThermCond' ) 

ax2.plot( trL, [self.CondAtTr(tr) for tr in trL], 'g-', label='BTU/h-f-F' ) 

except: 

pass 

ax2.legend() 

fig.tight_layout() 

 

if save_figures: 

fname = '%s_ViscCond.png'%self.pname 

plt.savefig(fname) 

 

# ================== Cp and Hvap ============================= 

fig, (ax1,ax2) = plt.subplots(2, 1, figsize=(6,8)) 

ax1.set_title( self.name + ' Cp and Heat of Vaporization' ) 

 

 

if self.name=='PH2': 

CP_LIMIT = 16.0 

else: 

CP_LIMIT = 2.0 

 

def drop_high_vals( xL, yL ): 

while yL[-1] > CP_LIMIT and xL[-1]>0.9: 

xL = xL[:-1] 

yL = yL[:-1] 

return xL, yL 

xL, yL = drop_high_vals( self.trL, self.cpL ) 

ax1.plot( xL, yL, 'rs', label='Cp' ) 

 

xL, yL = drop_high_vals( trL, [self.CpAtTr(tr) for tr in trL]) 

ax1.plot( xL, yL, 'r-', label='BTU/lbm-F' ) 

ax1.set_ylabel( 'Cp (BTU/lbm-F)' ) 

ax1.grid() 

ax1.legend() 

 

ax2.grid() 

ax2.set_ylabel( 'Heat of Vaporization (BTU/lbm)' ) 

ax2.set_xlabel('Reduced Temperature (Tr)') 

ax2.plot( self.trL, self.hvapL, 'gs', label='Hvap' ) 

ax2.plot( trL, [self.HvapAtTr(tr) for tr in trL], 'g-', label='BTU/lbm' ) 

ax2.legend() 

fig.tight_layout() 

 

if save_figures: 

fname = '%s_CpHvap.png'%self.pname 

plt.savefig(fname) 

 

# ================== Surface Tension and Density ============================= 

fig, (ax1,ax2) = plt.subplots(2, 1, figsize=(6,8)) 

ax1.set_title( self.name + ' Surface Tension and Density' ) 

 

ax1.plot( self.trL, self.surfL, 'rs', label='SurfTen' ) 

ax1.plot( trL, [self.SurfAtTr(tr) for tr in trL], 'r-', label='lbf/in' ) 

ax1.set_ylabel( 'Surface Tension (lbf/in)' ) 

ax1.grid() 

ax1.legend() 

 

ax2.grid() 

ax2.set_ylabel( 'Specific Gravity (SG)' ) 

ax2.set_xlabel('Reduced Temperature (Tr)') 

ax2.plot( self.trL, self.SG_liqL, 'gs', label='Liquid' ) 

ax2.plot( trL, [self.SGLiqAtTr(tr) for tr in trL], 'g-' ) 

 

ax2.plot( self.trL, [10.0**r for r in self.log10SG_vapL], 'bs', label='Vapor' ) 

ax2.plot( trL, [self.SGVapAtTr(tr) for tr in trL], 'b-' ) 

 

ax2.legend() 

fig.tight_layout() 

 

if save_figures: 

fname = '%s_SurfSG.png'%self.pname 

plt.savefig(fname) 

 

 

# ======================================================== 

plt.show() 

 

def Visc_compressed(self, TdegR, Ppsia): 

r'''Adjusts viscosity of a liquid for high pressure using an empirical 

formula developed by Lucas. 

 

This code is modified from thermo package: https://thermo.readthedocs.io/en/latest/index.html 

also see: equation 9-9.1 in 5th Ed. of Gases and Liquids. 

 

:param TdegR: temperature in degR 

:param Ppsia: pressure in psia 

:type TdegR: float 

:type Ppsia: float 

:return: viscosity at (TdegR, Ppsia) in poise 

''' 

# need to use thermo internal units of degK, Pa 

T = get_value( TdegR, 'degR', 'degK') 

Tc = get_value( self.Tc, 'degR', 'degK') 

P = get_value( Ppsia, 'psia', 'Pa') 

Pc = get_value( self.Pc, 'psia', 'Pa') 

P_sat = get_value( self.PvapAtTdegR( TdegR ), 'psia', 'Pa') 

 

Tr = T/Tc 

mu_sat = self.ViscAtTr( Tr ) 

if P <= P_sat: 

return mu_sat 

 

C = -0.07921+2.1616*Tr - 13.4040*Tr**2 + 44.1706*Tr**3 - 84.8291*Tr**4 \ 

+ 96.1209*Tr**5-59.8127*Tr**6+15.6719*Tr**7 

D = 0.3257/((1.0039-Tr**2.573)**0.2906) - 0.2086 

A = 0.9991 - 4.674E-4/(1.0523*Tr**-0.03877 - 1.0513) 

dPr = (P-P_sat)/Pc 

if dPr < 0: 

dPr = 0 

return (1. + D*(dPr/2.118)**A)/(1. + C*self.omega*dPr)*mu_sat 

 

 

 

def SG_compressed(self, TdegR, Ppsia): 

"""Calculates compressed-liquid specific gravity, 

unless overridden, uses COSTALD since COSTALD matched non-alcohol REFPROP propellants best. 

 

:param TdegR: temperature in degR 

:param Ppsia: pressure in psia 

:type TdegR: float 

:type Ppsia: float 

:return: specific gravity at (TdegR, Ppsia) in g/ml  

""" 

return self.SG_compressedCOSTALD( TdegR, Ppsia ) 

 

def SG_compressedCOSTALD(self, TdegR, Ppsia): 

r'''Calculates compressed-liquid specific gravity, using the COSTALD CSP method. 

 

This code is modified from thermo package: https://thermo.readthedocs.io/en/latest/index.html 

 

:param TdegR: temperature in degR 

:param Ppsia: pressure in psia 

:type TdegR: float 

:type Ppsia: float 

:return: specific gravity at (TdegR, Ppsia) in g/ml 

''' 

a = -9.070217 

b = 62.45326 

d = -135.1102 

f = 4.79594 

g = 0.250047 

h = 1.14188 

j = 0.0861488 

k = 0.0344483 

 

# convert to internal units from thermo  

T = get_value( TdegR, 'degR', 'degK') 

Tc = get_value( self.Tc, 'degR', 'degK') 

P = get_value( Ppsia, 'psia', 'Pa') 

Pc = get_value( self.Pc, 'psia', 'Pa') 

Psat = get_value( self.PvapAtTdegR( TdegR ), 'psia', 'Pa') 

 

SGsat = self.SGLiqAtTdegR( TdegR ) 

if P < Psat: 

print('Warning... Pressure below saturation pressure for T=%g degR, P=%g psia'%(TdegR, Ppsia)) 

return SGsat 

 

 

Vs = self.MolWt / SGsat # [cm^3/mol] 

 

tau = 1 - T/Tc 

e = exp(f + g*self.omega + h*self.omega**2) 

C = j + k*self.omega 

B = Pc*(-1 + a*tau**(1/3.) + b*tau**(2/3.) + d*tau + e*tau**(4/3.)) 

 

try: 

V_dense = Vs*(1 - C*log((B + P)/(B + Psat))) # [cm^3/mol] 

 

# convert to SG 

SG_dense = self.MolWt / V_dense # g/cm^3 

except: 

print('WARNING... SG_compressed has error at T=%g R, P=%g psia'%(TdegR, Ppsia)) 

return None 

return SG_dense 

 

 

 

def SG_compressedCZ1(self, TdegR, Ppsia): 

r'''Calculates compressed-liquid specific gravity, using the Chang Zhao method. 

 

This code is derived from equation 4-12.3 in 5th Ed. of Gases and Liquids. 

 

:param TdegR: temperature in degR 

:param Ppsia: pressure in psia 

:type TdegR: float 

:type Ppsia: float 

:return: specific gravity at (TdegR, Ppsia) in g/ml 

''' 

a0 = -170.335 

a1 = -28.578 

a2 = 124.809 

a3 = -55.5393 

a4 = 130.01 

b0 = 0.164813 

b1 = -0.0914427 

C = exp(1) 

D = 1.00588 

 

 

# convert to internal units from thermo  

T = get_value( TdegR, 'degR', 'degK') 

Tc = get_value( self.Tc, 'degR', 'degK') 

P = get_value( Ppsia, 'psia', 'bar') 

Pc = get_value( self.Pc, 'psia', 'bar') 

Psat = get_value( self.PvapAtTdegR( TdegR ), 'psia', 'bar') 

 

SGsat = self.SGLiqAtTdegR( TdegR ) 

if P < Psat: 

print('Warning in SG_compressed... Pressure below Psat for T=%g degR, P=%g psia'%(TdegR, Ppsia)) 

return SGsat 

 

Vs = self.MolWt / SGsat # [cm^3/mol] 

 

Tr = T / Tc 

if Tr > 0.94: 

print('Warning in SG_compressed... Reduced Temperature > 0.95 Tr=%g '%Tr ) 

 

A = a0 + a1*Tr + a2*Tr**3 + a3*Tr**6 + a4/Tr 

B = b0 + self.omega * b1 

 

numer = A*Pc + C**( (D-Tr)**B ) * (P - Psat) 

denom = A*Pc + C*(P - Psat) 

 

try: 

V_dense = Vs * numer / denom # [cm^3/mol] 

 

# convert to SG 

SG_dense = self.MolWt / V_dense # g/cm^3 

except: 

print('WARNING... SG_compressed has error at T=%g R, P=%g psia'%(TdegR, Ppsia)) 

return None 

return SG_dense 

 

def SG_compressedCZ2(self, TdegR, Ppsia): 

r'''Calculates compressed-liquid specific gravity, using the Chang Zhao method 

as modified in Journal of Molecular Liquids 160 (2011) 94-102 

 

:param TdegR: temperature in degR 

:param Ppsia: pressure in psia 

:type TdegR: float 

:type Ppsia: float 

:return: specific gravity at (TdegR, Ppsia) in g/ml 

''' 

a0= 482.85416 

a1=-1154.2977 

a2= 790.09727 

a3=-212.14413 

a4= 93.4904 

b0= 0.0264002 

b1= 0.42711522 

b2= 0.5 

c1= 9.2892236 

c2= 2.5103968 

c3= 0.5939722 

c4= 0.0010895002 

D= 1.00001 

E= 0.80329503 

 

Pr = Ppsia / self.Pc 

Tr = TdegR / self.Tc 

Psat = self.PvapAtTdegR( TdegR ) 

Psatr = Psat / self.Pc 

 

SGsat = self.SGLiqAtTdegR( TdegR ) 

if Ppsia < Psat: 

print('Warning in SG_compressed... Pressure below Psat for T=%g degR, P=%g psia'%(TdegR, Ppsia)) 

return SGsat 

 

Vs = self.MolWt / SGsat # [cm^3/mol] 

 

if Tr > 0.94: 

print('Warning in SG_compressed... Reduced Temperature > 0.95 Tr=%g '%Tr ) 

 

A = a0 + a1*Tr + a2*Tr**3 + a3*Tr**6 + a4/Tr 

B = b0 + b1/(b2+self.omega) 

C = c1 * (1-Tr)**c2 + (1 - (1-Tr)**c2) * exp( c3 + c4*(Pr - Psatr) ) 

 

numer = A + C**( (D-Tr)**B ) * (Pr - Psatr)**E 

denom = A + C*(Pr - Psatr)**E 

 

try: 

V_dense = Vs * numer / denom # [cm^3/mol] 

 

# convert to SG 

SG_dense = self.MolWt / V_dense # g/cm^3 

except: 

print('WARNING... SG_compressed has error at T=%g R, P=%g psia'%(TdegR, Ppsia)) 

return None 

return SG_dense 

 

 

def SG_compressedNasrfar(self, TdegR, Ppsia): 

r'''Calculates compressed-liquid specific gravity, using the Nasrfar Moshfeghian method 

from Journal of Molecular Liquids 160 (2011) 94-102 

 

:param TdegR: temperature in degR 

:param Ppsia: pressure in psia 

:type TdegR: float 

:type Ppsia: float 

:return: specific gravity at (TdegR, Ppsia) in g/ml 

''' 

 

Pr = Ppsia / self.Pc 

Tr = TdegR / self.Tc 

Psat = self.PvapAtTdegR( TdegR ) 

Psatr = Psat / self.Pc 

SGsat = self.SGLiqAtTdegR( TdegR ) 

if Ppsia < Psat: 

print('Warning in SG_compressed... Pressure below Psat for T=%g degR, P=%g psia'%(TdegR, Ppsia)) 

return SGsat 

 

Vs = self.MolWt / SGsat # [cm^3/mol] 

 

j0=1.3168E-3 

j1=3.4448E-2 

j2= 5.4131E-2 

L= 9.6840E-2 

M=8.6761E-6 

f0= 48.8756 

G= 0.7185 

I= 3.4031E-5 

c0= 5.5526 

c1=-2.7659 

Om0=7.9019E-2 

Om1=-2.8431E-2 

R = 8.3144598 # m^3-Pa / mol-K 

 

J = j0 + j1*(1-Tr)**(1./3.) + j2*(1-Tr)**(2./3.) 

F = f0 * (1-Tr) 

C = c0 + c1 * self.omega 

TcK = get_value( self.Tc, 'degR', 'degK') 

PcMPa = get_value( self.Pc, 'psia', 'MPa') 

 

Om = Om0 + Om1*self.omega 

Vinf = Om * R * TcK / PcMPa # cm^3/mol 

 

if Tr > 0.94: 

print('Warning in SG_compressed... Reduced Temperature > 0.95 Tr=%g '%Tr ) 

 

dpr = max(0, Pr - Psatr) 

numer = J + L*dpr + M*dpr**3 

denom = F + G*dpr + I*dpr**3 

 

vrat = C * numer / denom 

V_dense = vrat * (Vinf - Vs) + Vs # [cm^3/mol] 

 

SG_dense = self.MolWt / (V_dense) # g/cm^3 

 

return SG_dense 

 

 

if __name__ == '__main__': 

 

C = get_prop('Ethane') 

if C: 

C.summ_print() 

C.plot_sat_props()