|
3 | 3 | import matplotlib.colors as clr |
4 | 4 | import matplotlib.pyplot as plt |
5 | 5 | import numpy as np |
| 6 | +from bresenham import bresenham |
| 7 | +import sys |
6 | 8 | import taichi as ti |
7 | 9 | import taichi.math as tm |
8 | 10 | from celeris.utils import ( |
@@ -233,7 +235,35 @@ def __init__( # noqa: C901, PLR0913, PLR0915 |
233 | 235 | self.dzdt_F_coef = dzdt_F_coef |
234 | 236 | self.dzdt_I_coef = dzdt_I_coef |
235 | 237 |
|
| 238 | + self.force_sensor_begin_scaled = [0.0, 0.0] |
| 239 | + self.force_sensor_end_scaled = [1.0, 1.0] |
| 240 | + self.force_sensor_begin_pixel = [0.0, 0.0] |
| 241 | + self.force_sensor_end_pixel = [1.0, 1.0] |
| 242 | + self.hydrostatic_forces = ti.field(dtype=ti.f32, shape=(self.maxsteps)) |
| 243 | + self.hydrostatic_forces_from_numpy = ti.field(dtype=ti.f32, shape=(self.maxsteps)) |
| 244 | + self.hydrostatic_forces.fill(-1.0) |
| 245 | + self.hydrostatic_forces_numpy = np.zeros((self.maxsteps)) |
| 246 | + self.hydrostatic_forces_list = [] |
| 247 | + self.hydrostatic_force = ti.field(dtype=ti.f32, shape=(1)) |
| 248 | + # self.hydrostatic_forces_numpy = np.zeros((1, self.maxsteps)) |
| 249 | + self.step = 0 |
236 | 250 | if self.bc.celeris == True: # noqa: E712 |
| 251 | + if checjson('force_sensor_begin', self.bc.configfile) == 1: |
| 252 | + self.force_sensor_begin = self.bc.configfile['force_sensor_begin'] |
| 253 | + self.force_sensor_begin_scaled[0] = self.force_sensor_begin[0] / self.bc.configfile['WIDTH'] |
| 254 | + self.force_sensor_begin_scaled[1] = self.force_sensor_begin[1] / self.bc.configfile['HEIGHT'] |
| 255 | + else: |
| 256 | + self.force_sensor_begin = [0.0, 0.0] |
| 257 | + self.force_sensor_begin_scaled = [0.0, 0.0] |
| 258 | + |
| 259 | + if checjson('force_sensor_end', self.bc.configfile) == 1: |
| 260 | + self.force_sensor_end = self.bc.configfile['force_sensor_end'] |
| 261 | + self.force_sensor_end_scaled[0] = self.force_sensor_end[0] / self.bc.configfile['WIDTH'] |
| 262 | + self.force_sensor_end_scaled[1] = self.force_sensor_end[1] / self.bc.configfile['HEIGHT'] |
| 263 | + else: |
| 264 | + self.force_sensor_end = [self.bc.configfile['WIDTH'], self.bc.configfile['HEIGHT']] |
| 265 | + self.force_sensor_end_scaled = [1.0, 1.0] |
| 266 | + |
237 | 267 | if checjson('whiteWaterDecayRate', self.bc.configfile) == 1: |
238 | 268 | self.whiteWaterDecayRate = float( |
239 | 269 | self.bc.configfile['whiteWaterDecayRate'] |
@@ -969,10 +999,23 @@ def tridiag_coeffs_Y(self): # noqa: N802, D102 |
969 | 999 | self.coefMaty[i, j] = ti.Vector([a, b, c, 0.0], self.precision) |
970 | 1000 |
|
971 | 1001 | @ti.kernel |
972 | | - def Pass1(self): # noqa: N802, D102 |
| 1002 | + def Pass1(self, step: int): # noqa: N802, D102 |
973 | 1003 | # PASS 0 and Pass1 - edge value construction |
974 | 1004 | # using Generalized minmod limiter |
975 | 1005 | zro = ti.Vector([0.0, 0.0, 0.0, 0.0], self.precision) |
| 1006 | + |
| 1007 | + # Bresenham's line algorithm |
| 1008 | + # bresenham_list = list( |
| 1009 | + # bresenham( |
| 1010 | + # self.force_sensor_begin[0], |
| 1011 | + # self.force_sensor_begin[1], |
| 1012 | + # self.force_sensor_end[0], |
| 1013 | + # self.force_sensor_end[1], |
| 1014 | + # ) |
| 1015 | + # ) |
| 1016 | + # print("Bresenham List: ", bresenham_list) |
| 1017 | + hydrostatic_force = 0.0 |
| 1018 | + |
976 | 1019 | for i, j in self.State: |
977 | 1020 | # Compute the coordinates of the neighbors |
978 | 1021 | rightIdx = ti.min(i + 1, self.nx - 1) # noqa: N806 |
@@ -1128,6 +1171,41 @@ def Pass1(self): # noqa: N802, D102 |
1128 | 1171 | [maxInundatedDepth, maxVelocityU, maxVelocityV, maxVelocityC], |
1129 | 1172 | self.precision, |
1130 | 1173 | ) |
| 1174 | + |
| 1175 | + if (j >= self.force_sensor_begin[1] and j <= self.force_sensor_end[1]) and (i >= self.force_sensor_begin[0] and i <= self.force_sensor_end[0]): |
| 1176 | + # print("Calculating hydrostatic force at: ", i, j) |
| 1177 | + # Calculate the hydrostatic force |
| 1178 | + # Assuming a simple hydrostatic force calculation |
| 1179 | + # hydrostatic_force = 1/2 density * g * w * h |
| 1180 | + # where density is assumed to be 1 for simplicity |
| 1181 | + # and h is the water height at (i, j) |
| 1182 | + hsqr = float(self.H[i, j][0]) * float(self.H[i, j][0]) |
| 1183 | + hydrostatic_force += 1000 * 0.5 * 1000.0 * float(self.g) * float(hsqr) * float(self.dy) |
| 1184 | + |
| 1185 | + self.hydrostatic_forces[int(0)] = float(hydrostatic_force) |
| 1186 | + self.hydrostatic_forces[int(step)] = float(hydrostatic_force) |
| 1187 | + |
| 1188 | + |
| 1189 | + def overwrite_force(self): |
| 1190 | + # open forces.evt to overwrite |
| 1191 | + print("Overwriting forces.evt") |
| 1192 | + with open("forces.evt", "w") as f: |
| 1193 | + max_steps = 10000 # self.hydrostatic_forces.shape[0] |
| 1194 | + for i in range(max_steps): |
| 1195 | + if (i < max_steps - 1): |
| 1196 | + f.write(f"{0.0} ") |
| 1197 | + else: |
| 1198 | + f.write(f"{0.0}\n") |
| 1199 | + |
| 1200 | + |
| 1201 | + def write_hydrostatic_force(self): |
| 1202 | + # open forces.evt to append |
| 1203 | + with open("forces.evt", "a") as f: |
| 1204 | + f.write(f"{self.hydrostatic_forces[int(0)]} ") |
| 1205 | + |
| 1206 | + def update_step(self): |
| 1207 | + self.step += 1 |
| 1208 | + |
1131 | 1209 |
|
1132 | 1210 | @ti.kernel |
1133 | 1211 | def Pass1_SedTrans(self): # noqa: N802, D102 |
|
0 commit comments