0% found this document useful (0 votes)
2 views2 pages

Module1_Worksheet

This document is a lab handout for a course on Computational Methods in Chemical Engineering at the National Institute of Technology Warangal. It outlines various programming problems to be solved using Jupyter notebooks, covering topics such as data structures, functions, and numerical methods. The problems are categorized into three levels of difficulty, with specific instructions for coding practices and expected outputs.
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
2 views2 pages

Module1_Worksheet

This document is a lab handout for a course on Computational Methods in Chemical Engineering at the National Institute of Technology Warangal. It outlines various programming problems to be solved using Jupyter notebooks, covering topics such as data structures, functions, and numerical methods. The problems are categorized into three levels of difficulty, with specific instructions for coding practices and expected outputs.
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

Department of Chemical Engineering

National Institute of Technology Warangal


CH1309: Computational Methods in Chemical Engineering
Lab Handout 1

NOTE: Write all solutions in your Jupyter practice notebook, one Markdown heading per problem (e.g. "Problem 21").
Every function needs a docstring with units; every level 2/3 problem starts with pseudocode in a Markdown cell. Run
Kernel → Restart & Run; it must complete without errors. Antoine constants, log10 Psat (mmHg) = A − B/(C +
T(°C)): water (8.07131, 1730.63, 233.426); benzene (6.90565, 1211.033, 220.79); toluene (6.95464, 1344.80, 219.48);
ethanol (8.20417, 1642.89, 230.30); acetone (7.02447, 1161.00, 224.00). R = 8.314 J/(mol K).

Level 1.

1. Given the list L = [4, 8, 15, 16, 23, 42], predict the value of each expression on paper, then verify by running:
a) L[0] b) L[-2] c) L[1:4] d) L[::3] e) L[::-1] f) len(L[2:])
2. A temperature log reads T_log = [349.9, 350.4, 351.2, 350.8, 350.1] (K).
a) Compute the mean and the maximum using an explicit loop (no sum() or max()).
b) Compute both again using sum()/len() and max().
c) Conrm that both routes give the same answers.
3. a) Build a dictionary rho of liquid densities in kg/m3 : water 998, ethanol 789, benzene 876.
b) Add toluene 867.
c) Correct the ethanol value to 789.3.
d) Look up acetone with [Link]("acetone", -1.0) and print the result. Why does this line not crash even though
acetone is absent?
4. Instrument tags were logged with repeats: tags = ["TI101", "PI102", "TI101", "FI103", "PI102"].
Using a set: a) nd how many unique tags there are; b) print the sorted list of unique tags.
5. Given the tuple of Antoine constants ant = (7.02447, 1161.0, 224.0) for acetone:
a) Unpack it into the names A, B, C in a single line.
b) Given hi = 420.0 and lo = 310.0, swap their values without using a temporary variable.
6. A methanolwater mixture has mole fractions y = 0.40 methanol (M = 32.04 g/mol) and y = 0.60 water (M = 18.015
g/mol).
Store the data in a dictionary and compute the mixture molecular weight M = Σyi Mi using an accumulator loop.
Print the result to 3 decimal places.
7. Given L = [351.2, 349.9, 350.8]:
a) What does sorted(L) return, and what happens to L itself?
b) What does [Link]() return?
c) In one sentence: why is the statement L = [Link]() a bug?
8. A lter cake holds 180 g of moisture; each drying cycle removes half of what remains.
Using a while loop, nd how many cycles are needed before the moisture falls below 10 g. Print the moisture after
every cycle, and the nal cycle count.

Level 2.

9. a) Write a function mixture_MW(y, MW) that takes a composition dictionary and a molecular-weight dictionary and
returns the mixture molecular weight. Give it a docstring that states the units.
b) Apply it to ue gas: y = CO2 : 0.12, H2 O: 0.07, N2 : 0.74, O2 : 0.07 with M = 44.01, 18.015, 28.02, 32.00 g/mol.
c) Add the check assert mixture_MW({"N2": 1.0}, MW) == 28.02  a pure component must return its own
molecular weight.
10. Using a nested loop and the Antoine constants from the table above, print a table of Psat for ethanol and acetone at
20, 40 and 60 °C  temperatures as rows, the two species as aligned columns.
Which of the two is more volatile at every temperature in the table?
11. Solve x = e−x by successive substitution using the convergence criteria shown in the lecture: x0 = 0.5, tolerance
1e-10 on |xnew − xold |, maximum 200 iterations.
a) Print the rst ve lines of the iteration trace (iteration number, x, |∆x|).
b) Report the converged x* and the total number of iterations.
12. Write a function flow_regime(rho, v, D, mu) that returns the TUPLE (Re, regime), where regime is "laminar"
(Re < 2100), "transition" (2100 ≤ Re ≤ 4000) or "turbulent" (Re > 4000). Include a docstring with units.
Call it once using keyword arguments written in a dierent order from the denition.

1
13. Write friction_factor(Re): return 64/Re for laminar ow (Re < 2100), otherwise the Blasius formula 0.316 Re−0.25
(smooth pipe, valid to about 105 ).
Add two checks: assert friction_factor(1800) == 64/1800, and verify f(15 000) against the Blasius value com-
puted by hand.
14. A reactor inlet contains the species benzene, toluene, xylene; the outlet contains toluene, xylene, biphenyl, hydrogen.
Using set operations, report: a) the species that survived (intersection); b) all species seen (union); c) the species
generated by reaction (outlet − inlet). Print each, sorted.
15. Collect your flow_regime, friction_factor and mixture_MW functions in one cell, followed by FIVE assert state-
ments checking them against hand-calculated values  at least one per function, and at least two using [Link]
with an explicit rel_tol. All ve must pass on Restart & Run All.

Level 3.

16. Multi-stream balance on nested dictionaries. A distillation column splits a benzenetoluenexylene feed. The
three streams (ows in kmol/h) are:
FEED = {"benzene": 87.5, "toluene": 100.0, "xylene": 62.5}
DIST = {"benzene": 86.0, "toluene": 12.0}
BTMS = {"benzene": 1.5, "toluene": 88.0, "xylene": 62.5}
a) For every component in FEED, sum its ow over DIST and BTMS with a nested loop, using .get(comp, 0.0)
for components absent from a stream (xylene does not leave overhead).
b) Print a reconciliation table: component, ow in, ow out, dierence.
c) Assert closure within 1e-9 for every component and for the overall total.
17. Aliasing bug.
base = [0.2, 0.3, 0.5]; case2 = base; case2[0] = 0.25; case2[1] = 0.25.
a) Find the bug.
b) Fix it in two dierent ways (.copy() and slicing), adding an assert that proves base is intact after each x.
18. Grid-search optimum. A pipe cost model is C(D) = 0.45×10−4 /D5 + 120 D2 (pumping + capital, arbitrary
units).
a) Evaluate C on the grid D = 0.02 to 0.20 m in steps of 0.005 m, tracking the minimum as you go.
b) Report D* and C*, and conrm the optimum is interior by checking that both neighbouring grid points give higher
cost.
c) In one sentence: what limits the accuracy of a grid search?
19. Convert mass% to mole fractions. A laboratory composition CO : 0.118, H O: 0.071, N : 0.742, O : 0.066 does
2 2 2 2
not sum to 1.
a) Compute the raw sum.
b) Normalize the composition with a dictionary comprehension.
c) Assert that the new sum equals 1 within 1e-12, and also assert that the ratio of any two fractions is unchanged by
the normalization.
d) Print the compositions before and after, side by side.

You might also like