summaryrefslogtreecommitdiff
path: root/Basic_And_Applied_Thermodynamics_by_P._K._Nag/Chapter04.ipynb
blob: ca6e53da65b1f96d58e94b48a9c251274b802b6c (plain)
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
{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# Chapter 04:First Law of Thermodynamics"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Ex4.1:pg-72"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "\n",
      " Example 4.1\n",
      "\n",
      " The internal energy of the gas decrease by  21.85  kJ in the process.\n"
     ]
    }
   ],
   "source": [
    "\n",
    "\n",
    "V1 = 0.3 # Initial volume in m**3\n",
    "\n",
    "V2 = 0.15 # Final volume in m**3\n",
    "\n",
    "P = 0.105 # Initial Pressure in MPa\n",
    "\n",
    "Q = -37.6 # Heat transferred in kJ\n",
    "\n",
    "W = P*(V2-V1)*1e6 # Work done\n",
    "\n",
    "U = Q*1e3-W # Internal energy change\n",
    "\n",
    "print \"\\n Example 4.1\"\n",
    "\n",
    "print \"\\n The internal energy of the gas decrease by \",abs(U)/1e3 ,\" kJ in the process.\"\n",
    "\n"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Ex4.2:pg-73"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "\n",
      " Example 4.2\n",
      "\n",
      " The heat flow into the system along the path adb is  62.5  kJ\n",
      "\n",
      " The heat liberated along the path b-a is  -73  kJ\n",
      "\n",
      " The heat absorbed in the path ad and db are  52.5  kJ nd  10.0  kJ respectively.\n"
     ]
    }
   ],
   "source": [
    "Qacb = 84 # Heat transfer along the path acb in kJ \n",
    "\n",
    "Wacb = 32 # Work done along the path acb in kJ\n",
    "\n",
    "Uba = Qacb-Wacb # Ub-Ua\n",
    "\n",
    "# Part (a)\n",
    "\n",
    "Wadb = 10.5 # Work done along the path adb in kJ\n",
    "\n",
    "Qadb = Uba+Wadb # Heat flow into the system along the path adb\n",
    "\n",
    "print \"\\n Example 4.2\"\n",
    "\n",
    "print \"\\n The heat flow into the system along the path adb is \",Qadb ,\" kJ\"\n",
    "\n",
    "\n",
    "\n",
    "\n",
    "\n",
    "# Part (b)\n",
    "\n",
    "Wb_a = -21 # work done along the path ba in kJ\n",
    "\n",
    "Uab = - Uba # Change in internal energy along the path ab in kJ\n",
    "\n",
    "Qb_a = Uab+Wb_a # Heat liberated along the path b-a\n",
    "\n",
    "print \"\\n The heat liberated along the path b-a is \",Qb_a,\" kJ\"\n",
    "\n",
    "\n",
    "\n",
    "# Part (c)\n",
    "\n",
    "Wdb = 0 # Constant volume\n",
    "\n",
    "Wad = 10.5 # work done along the path ad in kJ\n",
    "\n",
    "Wadb = Wdb-Wad # work done along the path adb in kJ\n",
    "\n",
    "Ud = 42\n",
    "\n",
    "Ua = 0\n",
    "\n",
    "Qad = Ud-Ua+Wad # Heat flow into the system along the path ad in kJ\n",
    "\n",
    "Qdb = Qadb-Qad  #Heat flow into the system along the path db in kJ\n",
    "\n",
    "print \"\\n The heat absorbed in the path ad and db are \",Qad ,\" kJ nd \",Qdb ,\" kJ respectively.\"\n",
    "\n"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Ex4.3:pg-73"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 10,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "\n",
      " Example 4.3\n",
      "The completed table is: [[0, 2170, -2170], [21000, 0, 21000], [-2100, 34500, -36600], [-35900, -53670, 17770]]\n",
      "\n",
      " Net rate of work output is  -284  kW\n"
     ]
    }
   ],
   "source": [
    "# Process a-b\n",
    "\n",
    "Qab = 0 # Heat transfer along the path ab in kJ/ min\n",
    "\n",
    "Wab = 2170 # Work transfer along the path ab in kJ/min\n",
    "\n",
    "Eab = Qab-Wab # Change in internal energy along the path ab in kJ/min\n",
    "\n",
    "# Process b-c\n",
    "\n",
    "Qbc = 21000 # Heat transfer along the path bc in kJ/ min\n",
    "\n",
    "Wbc = 0 # Work transfer along the path bc in kJ/min\n",
    "\n",
    "Ebc = Qbc-Wbc # Change in internal energy along the path bc in kJ/min\n",
    "\n",
    "# Process c-d\n",
    "\n",
    "Qcd = -2100 # Heat transfer along the path cd in kJ/ min\n",
    "\n",
    "Ecd = -36600  # Change in internal energy along the path cd in kJ/min\n",
    "\n",
    "Wcd = Qcd-Ecd  # Work transfer along the path cd in kJ/min\n",
    "\n",
    "# Process d-a\n",
    "\n",
    "Q = -17000  # Total heat transfer in kJ/min\n",
    "\n",
    "Qda = Q-Qab-Qbc-Qcd # Heat transfer along the path da in kJ/ min \n",
    "\n",
    "Eda = -Eab-Ebc-Ecd  # Change in internal energy along the path da in kJ/min \n",
    "\n",
    "Wda = Qda-Eda # Work transfer along the path da in kJ/min\n",
    "\n",
    "print \"\\n Example 4.3\"\n",
    "\n",
    "\n",
    "\n",
    "M = [[Qab, Wab, Eab] , [Qbc, Wbc, Ebc], [Qcd, Wcd, Ecd], [Qda, Wda, Eda]]\n",
    "\n",
    "print\"The completed table is:\",M\n",
    "     \n",
    "W = Qab+Qbc+Qcd+Qda\n",
    "     \n",
    "print \"\\n Net rate of work output is \",W/60 ,\" kW\"\n",
    "\n"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Ex4.4:pg-75"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 14,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "\n",
      " Example 4.4\n",
      "\n",
      " Part A:\n",
      "\n",
      " For the quasi static process is: \n",
      " \n",
      "Q:    37.2676405731 kJ\n",
      "\n",
      " dU:  -92.1338891945 kJ\n",
      "\n",
      " W:  129.4 kJ \n",
      "\n",
      " Part B:\n",
      "\n",
      " Work transfer for the process is  122.13 kJ.\n",
      "\n",
      "\n",
      " Part C:\n",
      "\n",
      " Wb is not equal to integral(p*dv) since the process is not quasi static.\n"
     ]
    }
   ],
   "source": [
    "# Part (a)\n",
    "\n",
    "m = 3 # mass of substance in kg\n",
    "\n",
    "V1 = 0.22 # Initial volume of system in m**3\n",
    "\n",
    "P1 = 500 # Initial pressure of system in kPa \n",
    "\n",
    "P2 = 100 # Final pressure of system in kPa  \n",
    "\n",
    "V2 = V1*(P1/P2)**(1/1.2) # Final volume of system\n",
    "\n",
    "dU = 3.56*(P2*V2-P1*V1) # Change in internal energy of substance in kJ/kg\n",
    "\n",
    "n = 1.2 # polytropic index\n",
    "\n",
    "W = (P2*V2-P1*V1)/(1-n) # work done in process\n",
    "\n",
    "Q = dU+W # Heat addition in process\n",
    "\n",
    "\n",
    "\n",
    "print \"\\n Example 4.4\"\n",
    "\n",
    "print \"\\n Part A:\"\n",
    "\n",
    "print \"\\n For the quasi static process is: \\n \"\n",
    "\n",
    "print \"Q:   \",Q ,\"kJ\"\n",
    "\n",
    "print \"\\n dU: \",dU ,\"kJ\"\n",
    "\n",
    "print \"\\n W: \",round(W,2) ,\"kJ\",\n",
    "\n",
    "#The provided in the textbook is wrong\n",
    "\n",
    "# Part (b)\n",
    "\n",
    "print \"\\n\\n Part B:\"\n",
    "\n",
    "Qb = 30 # heat transfer in kJ \n",
    "\n",
    "Wb = Qb-dU # Work done in kJ\n",
    "\n",
    "print \"\\n Work transfer for the process is \",round(Wb,2) ,\"kJ.\" \n",
    "\n",
    "#The answers vary due to round off error\n",
    "\n",
    "# Part (c)\n",
    "\n",
    "print \"\\n\\n Part C:\"\n",
    "\n",
    "print \"\\n Wb is not equal to integral(p*dv) since the process is not quasi static.\"\n",
    "\n"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Ex4.5:pg-76"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 34,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "\n",
      " Example 4.5\n",
      "\n",
      " The work done by the system is  8.55  kJ\n",
      "\n",
      " The heat flow into the system is  68.085  kJ\n"
     ]
    }
   ],
   "source": [
    "import numpy as np\n",
    "from scipy.integrate import quad\n",
    "V1 = 0.03 # initial volume in m**3\n",
    "\n",
    "P1 = 170.0 # Initial pressure in kPa\n",
    "\n",
    "P2 = 400.0 # Final pressure in kPa\n",
    "\n",
    "V2 = 0.06 # Final volume in m**3\n",
    "\n",
    "U = 3.15*(P2*V2-P1*V1) # internal energy in kJ\n",
    "\n",
    "b = np.matrix([P1, P2])\n",
    "\n",
    "B=b.transpose()\n",
    "\n",
    "A = np.matrix([[1,V1],[1,V2]]) \n",
    "\n",
    "x = A.getI()*B \n",
    "\n",
    "a = x[0] ; b = x[1] \n",
    "\n",
    "def pressure(V): \n",
    "    P = a+b*V\n",
    "    return P\n",
    "\n",
    "    endfunction \n",
    "\n",
    "\n",
    "W, err = quad(pressure, V1, V2)\n",
    "    \n",
    "#W = integrate(pressure,V1,V2)  \n",
    "    \n",
    "Q = U+W # heat flow into the system in kJ\n",
    "    \n",
    "    \n",
    "    \n",
    "print \"\\n Example 4.5\"\n",
    "    \n",
    "print \"\\n The work done by the system is \",W ,\" kJ\"\n",
    "    \n",
    "print \"\\n The heat flow into the system is \",Q ,\" kJ\"\n",
    "    \n",
    "    "
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 2",
   "language": "python",
   "name": "python2"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 2
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython2",
   "version": "2.7.11"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 0
}