-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsimulation.html
More file actions
169 lines (153 loc) · 6.12 KB
/
Copy pathsimulation.html
File metadata and controls
169 lines (153 loc) · 6.12 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
<!DOCTYPE html>
<html>
<head>
<title>Simulation data</title>
<link rel="stylesheet" href="main.css" />
<link href="https://fonts.googleapis.com/css2?family=Audiowide&display=swap" rel="stylesheet" />
</head>
<body>
<!-- <div id="Temperature">
Temperature Chamber = <input type="text" id="Tc" placeholder="3400" class="user-input" /> [K]
</div> -->
<div class="container">
<!-- <div class="side-box2 left-box" id="Left" style="display: none"> -->
<div class="side-box2 left-box">
<div class="Title2" id="L" style="display: none">Regen Cooling</div>
<div class="All" id="L1" style="display: none">
Channel # = <input type="text" id="R_number" placeholder="25" class="user-input" /> <br>
At Throat:
Width = <input type="text" id="R_w" placeholder="0.0075" class="user-input" /> [m] <br>
Heigth = <input type="text" id="R_h" placeholder="0.0075" class="user-input" /> [m] <br>
</div>
</div>
<div class="side-box2" id="Middle">
<div class="Title2">All Data</div>
<div class="All">
Pressure Chamber = <input type="text" id="pc" placeholder="6.9" class="user-input" /> [MPa] <br>
Mass Ratio = <input type="text" id="mr" placeholder="2.3" class="user-input" /><br>
Mass flow rate total = <input type="text" id="mdot" placeholder="25" class="user-input" /> [Kg] <br>
Oxidizer = <input type="text" id="ox" placeholder="LOX" class="user-input" /><br>
Fuel = <input type="text" id="fuel" placeholder="RP1" class="user-input" />
</div>
</div>
<div class="side-box2 right-box">
<div class="Title2" id="R" style="display: none">Film Cooling</div>
<div class="All" id="R1" style="display: none">
Channel #1 = <input type="text" id="F_number" placeholder="25" class="user-input" /> <br>
</div>
</div>
</div>
<div class="Save Button" onclick="save()">Save</div>
<script>
const fs = require('fs');
const path = require('path');
const filePath = path.join(__dirname, 'IC.json');
// Load existing values into inputs on page load
window.onload = () => {
if (fs.existsSync(filePath)) {
const data = JSON.parse(fs.readFileSync(filePath, 'utf8'));
if (data.pc) {
document.getElementById('pc').placeholder = data.pc;
}
if (data.mr) {
document.getElementById('mr').placeholder = data.mr;
}
if (data.mdot) {
document.getElementById('mdot').placeholder = data.mdot;
}
if (data.ox) {
document.getElementById('ox').placeholder = data.ox;
}
if (data.fuel) {
document.getElementById('fuel').placeholder = data.fuel;
}
if (data.R_w) {
document.getElementById('R_w').placeholder = data.R_w;
}if (data.R_h) {
document.getElementById('R_h').placeholder = data.R_h;
}if (data.R_number) {
document.getElementById('R_number').placeholder = data.R_number;
}
if (data.regen) {
document.getElementById('L').style.display = 'block';
document.getElementById('L1').style.display = 'block';
} else {
document.getElementById('L').style.display = 'none';
document.getElementById('L1').style.display = 'none';
}
if (data.film) {
document.getElementById('R').style.display = 'block';
document.getElementById('R1').style.display = 'block';
} else {
document.getElementById('R').style.display = 'none';
document.getElementById('R1').style.display = 'none';
}
}
};
function save(){
// const T = document.getElementById('T').value;
const pc = document.getElementById('pc').value;
const mr = document.getElementById('mr').value;
const mdot = document.getElementById('mdot').value;
const ox = document.getElementById('ox').value;
const R_w = document.getElementById('R_w').value;
const R_h = document.getElementById('R_h').value;
const R_number = document.getElementById('R_number').value;
const F_number = document.getElementById('F_number').value;
const fuel = document.getElementById('fuel').value;
const fs = require('fs');
const path = require('path');
const filePath = path.join(__dirname, 'IC.json');
let existingData = {};
if (fs.existsSync(filePath)) {
try {
const fileContent = fs.readFileSync(filePath, 'utf8');
existingData = JSON.parse(fileContent);
} catch (err) {
console.error('Error reading existing file:', err);
alert('Error reading existing data. It will be overwritten.');
}
}
// Only update keys if input is not empty
// if (T !== '') {
// existingData.T_0 = T;
// }
if (pc !== '') {
existingData.pc = pc;
}
if (mr !== '') {
existingData.mr = mr;
}
if (mdot !== '') {
existingData.mdot = mdot;
}
if (ox !== '') {
existingData.ox = ox;
}
if (fuel !== '') {
existingData.fuel = fuel;
}
if (R_w !== '') {
existingData.R_w = R_w;
}
if (R_h !== '') {
existingData.R_h = R_h;
}
if (R_number !== '') {
existingData.R_number = R_number;
}
if (F_number !== '') {
existingData.R_number = R_number;
}
fs.writeFile(filePath, JSON.stringify(existingData, null, 2), (err) => {
if (err) {
alert('Error saving file: ' + err.message);
console.error(err);
} else {
// alert('Data saved successfully!');
}
});
}
</script>
</body>
</html>