-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwork.html
164 lines (145 loc) · 6.56 KB
/
work.html
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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Thermodynamic Work Calculator</title>
<style>
body {
background-image: url('chem.jpg');
background-size: cover;
background-repeat: no-repeat;
background-attachment: fixed;
font-family: Arial, sans-serif;
margin: 20px;
}
.container {
background-color: antiquewhite;
max-width: 600px;
margin: auto;
padding: 20px;
border: 1px solid #ddd;
border-radius: 8px;
}
label,
select,
input,
button {
display: block;
width: 100%;
margin-top: 10px;
}
button {
padding: 10px;
background-color: #4CAF50;
color: white;
border: none;
cursor: pointer;
}
button:hover {
background-color: #45a049;
}
</style>
</head>
<body>
<div class="container">
<h2>Thermodynamic Work Calculator</h2>
<label for="process">Select Process:</label>
<select id="process" onchange="updateInputFields()">
<option value="">Select a process</option>
<option value="isobaric">Isobaric</option>
<option value="isochoric">Isochoric</option>
<option value="isothermal Reversible">Isothermal Reversible</option>
<option value="isothermal Irreversible">Isothermal Irreversible</option>
</select>
<div id="inputFields"></div>
<button onclick="calculateWork()">Calculate Work Done</button>
<h3 id="result"></h3>
</div>
<script>
function updateInputFields() {
const process = document.getElementById("process").value;
const inputFields = document.getElementById("inputFields");
inputFields.innerHTML = "";
if (process === "isobaric") {
inputFields.innerHTML += `
<label for="pressure">Pressure (P in Pa):</label>
<input type="number" id="pressure" required>
<label for="volumeChange">Change in Volume (ΔV in m³):</label>
<input type="number" id="volumeChange" required>
`;
} else if (process === "isochoric") {
inputFields.innerHTML += `
<p>For an isochoric process, work done is zero as volume does not change.</p>
`;
} else if (process === "isothermal Reversible") {
inputFields.innerHTML += `
<label for="n">Number of moles (n):</label>
<input type="number" id="n" required>
<label for="temperature">Temperature (T in K):</label>
<input type="number" id="temperature" required>
<label for="volumeinitial">Initial Volume (Vi):</label>
<input type="number" id="volumeinitial" required>
<label for="volumefinal">Final Volume (Vf):</label>
<input type="number" id="volumefinal" required>
`;
} else if (process === "isothermal Irreversible") {
inputFields.innerHTML += `
<label for="p">Pressure (p):</label>
<input type="number" id="p" required>
<label for="volumeinitial">Initial Volume (Vi):</label>
<input type="number" id="volumeinitial" required>
<label for="volumefinal">Final Volume (Vf):</label>
<input type="number" id="volumefinal" required>
`;
}
}
function calculateWork() {
const process = document.getElementById("process").value;
let workDone = 0;
const result = document.getElementById("result");
if (process === "isobaric") {
const P = parseFloat(document.getElementById("pressure").value);
const deltaV = parseFloat(document.getElementById("volumeChange").value);
workDone = P * deltaV;
result.textContent = `Work done (W) in an isobaric process is: ${workDone} J`;
} else if (process === "isochoric") {
workDone = 0;
result.textContent = "Work done (W) in an isochoric process is: 0 J (no volume change)";
} else if (process === "isothermal Reversible") {
const n = parseFloat(document.getElementById("n").value);
const T = parseFloat(document.getElementById("temperature").value);
const Vf = parseFloat(document.getElementById("volumefinal").value);
const Vi = parseFloat(document.getElementById("volumeinitial").value);
const R = 8.314; // Gas constant in J/(mol*K)
if (Vi <= 0 || Vf <= 0 ) {
result.textContent = "Error: Volume must be greater than zero.";
return;
} if(T <= 0){
result.textContent = "Error: Temperature must be positive.";
return;
}
workDone = n * R * T * Math.log(Vf/Vi);
result.textContent = `Work done (W) in an isothermal process is: ${workDone.toFixed(2)} J`;
} else if (process === "isothermal Irreversible"){
const p = parseFloat(document.getElementById("p").value);
const Vi = parseFloat(document.getElementById("volumeinitial").value);
const Vf = parseFloat(document.getElementById("volumefinal").value);
if (Vi <= 0 || Vf <= 0) {
result.textContent = "Error: Volume must be greater than zero.";
return;
}
//if(Vf <= Vi){
// result.textContent = "Error: Initial volume must be greater than Final volume.";
// return;
//}
workDone = p * (Vf - Vi);
result.textContent = `Work done (W) in an isothermal process is: ${workDone} J`;
}
else {
result.textContent = "Please select a valid process and enter all required values.";
}
}
</script>
</body>
</html>