File size: 9,139 Bytes
2afa69c | 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 | """
Geo-Lab AI: ๊ณก๋ฅ ํ์ฒ ๋ฌผ๋ฆฌ ์๋ฎฌ๋ ์ด์
Helical Flow ๊ธฐ๋ฐ ์ธก๋ฐฉ ์นจ์/ํด์
"""
import numpy as np
from dataclasses import dataclass, field
from typing import List, Tuple
@dataclass
class MeanderChannel:
"""๊ณก๋ฅ ํ์ฒ ์ฑ๋ ํํ
1D ์ค์ฌ์ ๊ธฐ๋ฐ์ผ๋ก ์ฑ๋์ ํํํ๊ณ ,
๊ฐ ์ง์ ์์์ ๊ณก๋ฅ , ํญ, ๊น์ด๋ฅผ ์ถ์
"""
# ์ฑ๋ ์ค์ฌ์ ์ขํ
x: np.ndarray = field(default=None)
y: np.ndarray = field(default=None)
# ๊ฐ ์ง์ ์ ์์ฑ
width: np.ndarray = field(default=None) # ์ฑ๋ ํญ (m)
depth: np.ndarray = field(default=None) # ์ฑ๋ ๊น์ด (m)
# ์ ๋ ๋ฐ ์ ์
discharge: float = 100.0 # mยณ/s
velocity: np.ndarray = field(default=None) # m/s
def __post_init__(self):
if self.x is not None and self.width is None:
n = len(self.x)
self.width = np.full(n, 20.0)
self.depth = np.full(n, 3.0)
self.velocity = np.full(n, 1.5)
@classmethod
def create_initial(cls, length: float = 1000.0,
initial_sinuosity: float = 1.2,
n_points: int = 200,
discharge: float = 100.0):
"""์ด๊ธฐ ๊ณก๋ฅ ํ์ฒ ์์ฑ"""
s = np.linspace(0, 1, n_points) # ์ ๊ทํ๋ ๊ฑฐ๋ฆฌ
# ์ฌ์ธํ ๊ธฐ๋ฐ ์ด๊ธฐ ๊ณก๋ฅ
amplitude = length * 0.1 * (initial_sinuosity - 1)
frequency = 3 # ๊ตฝ์ด ์
x = s * length
y = amplitude * np.sin(2 * np.pi * frequency * s)
return cls(x=x, y=y, discharge=discharge)
def calculate_curvature(self) -> np.ndarray:
"""๊ณก๋ฅ ๊ณ์ฐ (1/m)
ฮบ = (x'y'' - y'x'') / (x'^2 + y'^2)^(3/2)
"""
dx = np.gradient(self.x)
dy = np.gradient(self.y)
ddx = np.gradient(dx)
ddy = np.gradient(dy)
denominator = np.power(dx**2 + dy**2, 1.5) + 1e-10
curvature = (dx * ddy - dy * ddx) / denominator
return curvature
def calculate_sinuosity(self) -> float:
"""๊ตด๊ณก๋ = ํ์ฒ ๊ธธ์ด / ์ง์ ๊ฑฐ๋ฆฌ"""
# ๊ฒฝ๋ก ๊ธธ์ด
ds = np.sqrt(np.diff(self.x)**2 + np.diff(self.y)**2)
path_length = np.sum(ds)
# ์ง์ ๊ฑฐ๋ฆฌ
straight_length = np.sqrt(
(self.x[-1] - self.x[0])**2 +
(self.y[-1] - self.y[0])**2
) + 1e-10
return path_length / straight_length
class HelicalFlowErosion:
"""Helical Flow ๊ธฐ๋ฐ ๊ณก๋ฅ ์นจ์/ํด์
๊ณก๋ฅ์์ ๋ฌผ์ ๋์ ํ(helical)์ผ๋ก ํ๋ฆ:
- ํ๋ฉด: ๋ฐ๊นฅ์ชฝ์ผ๋ก (์์ฌ๋ ฅ)
- ๋ฐ๋ฅ: ์์ชฝ์ผ๋ก (์๋ ฅ ๊ตฌ๋ฐฐ)
๊ฒฐ๊ณผ:
- ๋ฐ๊นฅ์ชฝ (๊ณต๊ฒฉ์ฌ๋ฉด): ์นจ์
- ์์ชฝ (ํด์ ์ฌ๋ฉด): ํด์
"""
def __init__(self,
bank_erosion_rate: float = 0.5, # m/yr per unit stress
deposition_rate: float = 0.3):
self.bank_erosion_rate = bank_erosion_rate
self.deposition_rate = deposition_rate
def calculate_bank_migration(self, channel: MeanderChannel,
dt: float = 1.0) -> Tuple[np.ndarray, np.ndarray]:
"""ํ์ ์ด๋ ๊ณ์ฐ
๊ณก๋ฅ ์ด ํฐ ๊ณณ์์ ๋ฐ๊นฅ์ชฝ์ผ๋ก ์นจ์ โ ์ฑ๋ ์ด๋
"""
curvature = channel.calculate_curvature()
# ์นจ์/ํด์ ๋น๋์นญ
# ๊ณก๋ฅ > 0: ์ข์ธก์ด ๋ฐ๊นฅ (์นจ์)
# ๊ณก๋ฅ < 0: ์ฐ์ธก์ด ๋ฐ๊นฅ (์นจ์)
# ์ด๋ ๋ฒกํฐ (์ฑ๋์ ์์ง)
dx = np.gradient(channel.x)
dy = np.gradient(channel.y)
path_length = np.sqrt(dx**2 + dy**2) + 1e-10
# ์์ง ๋ฐฉํฅ (์ผ์ชฝ์ผ๋ก 90๋ ํ์ )
normal_x = -dy / path_length
normal_y = dx / path_length
# ์ด๋๋ = ๊ณก๋ฅ ร ์ ๋ ร erosion rate
migration_rate = curvature * channel.discharge * self.bank_erosion_rate * dt
# ์ด๋๋ ์ ํ
migration_rate = np.clip(migration_rate, -2.0, 2.0)
delta_x = migration_rate * normal_x
delta_y = migration_rate * normal_y
return delta_x, delta_y
def check_cutoff(self, channel: MeanderChannel,
threshold_distance: float = 30.0) -> List[Tuple[int, int]]:
"""์ฐ๊ฐํธ ํ์ฑ ์กฐ๊ฑด ์ฒดํฌ (์ ๋ก ์ ๋จ)"""
n = len(channel.x)
cutoffs = []
# ๊ฐ๊น์ด ๋ ์ ์ฐพ๊ธฐ (๊ฒฝ๋ก์ ๋ฉ๋ฆฌ ๋จ์ด์ก์ง๋ง ๊ณต๊ฐ์ ์ผ๋ก ๊ฐ๊น์ด)
for i in range(n):
for j in range(i + 30, n): # ์ต์ 30์ ๊ฐ๊ฒฉ
dist = np.sqrt(
(channel.x[i] - channel.x[j])**2 +
(channel.y[i] - channel.y[j])**2
)
if dist < threshold_distance:
cutoffs.append((i, j))
break # ์ฒซ ๋ฒ์งธ cutoff๋ง
return cutoffs
class MeanderSimulation:
"""๊ณก๋ฅ ํ์ฒ ์๋ฎฌ๋ ์ด์
"""
def __init__(self, length: float = 1000.0, initial_sinuosity: float = 1.3):
self.channel = MeanderChannel.create_initial(
length=length,
initial_sinuosity=initial_sinuosity
)
self.erosion = HelicalFlowErosion()
self.history: List[Tuple[np.ndarray, np.ndarray]] = []
self.oxbow_lakes: List[Tuple[np.ndarray, np.ndarray]] = []
self.time = 0.0
def step(self, dt: float = 1.0):
"""1 ํ์์คํ
"""
# 1. ํ์ ์ด๋
dx, dy = self.erosion.calculate_bank_migration(self.channel, dt)
self.channel.x += dx
self.channel.y += dy
# 2. ์ฐ๊ฐํธ ์ฒดํฌ
cutoffs = self.erosion.check_cutoff(self.channel)
for start, end in cutoffs:
# ์ฐ๊ฐํธ ์ ์ฅ
ox = self.channel.x[start:end+1].copy()
oy = self.channel.y[start:end+1].copy()
self.oxbow_lakes.append((ox, oy))
# ์ฑ๋ ๋จ์ถ
self.channel.x = np.concatenate([
self.channel.x[:start+1],
self.channel.x[end:]
])
self.channel.y = np.concatenate([
self.channel.y[:start+1],
self.channel.y[end:]
])
# ์์ฑ ๋ฐฐ์ด๋ ์กฐ์
n_new = len(self.channel.x)
self.channel.width = np.full(n_new, 20.0)
self.channel.depth = np.full(n_new, 3.0)
self.channel.velocity = np.full(n_new, 1.5)
self.time += dt
def run(self, total_time: float, save_interval: float = 100.0, dt: float = 1.0):
"""์๋ฎฌ๋ ์ด์
์คํ"""
steps = int(total_time / dt)
save_every = max(1, int(save_interval / dt))
self.history = [(self.channel.x.copy(), self.channel.y.copy())]
for i in range(steps):
self.step(dt)
if (i + 1) % save_every == 0:
self.history.append((self.channel.x.copy(), self.channel.y.copy()))
return self.history
def get_cross_section(self, position: float = 0.5) -> Tuple[np.ndarray, np.ndarray]:
"""๊ณก๋ฅ ๋จ๋ฉด (๋น๋์นญ)
position: ๊ณก๋ฅ ๋ด ์์น (0=์ง์ ๋ถ, 1=์ต๋ ๊ตฝ์ด)
"""
curvature = self.channel.calculate_curvature()
max_curve = np.abs(curvature).max() + 1e-10
asymmetry = np.abs(curvature[int(len(curvature) * 0.5)]) / max_curve
asymmetry = min(1.0, asymmetry * position * 2)
# ๋จ๋ฉด ์์ฑ
x = np.linspace(-30, 30, 100)
# ๋น๋์นญ ๊ณก์
left_depth = 5 + asymmetry * 3 # ๊ณต๊ฒฉ์ฌ๋ฉด (๊น์)
right_depth = 3 - asymmetry * 1 # ํด์ ์ฌ๋ฉด (์์)
y = np.where(
x < 0,
-left_depth * (1 - np.power(x / -30, 2)),
-right_depth * (1 - np.power(x / 30, 2))
)
return x, y
# ํ๋ฆฌ์ปดํจํ
def precompute_meander(max_time: int = 10000,
initial_sinuosity: float = 1.3,
save_every: int = 100) -> dict:
"""๊ณก๋ฅ ์๋ฎฌ๋ ์ด์
ํ๋ฆฌ์ปดํจํ
"""
sim = MeanderSimulation(initial_sinuosity=initial_sinuosity)
history = sim.run(
total_time=max_time,
save_interval=save_every,
dt=1.0
)
return {
'history': history,
'oxbow_lakes': sim.oxbow_lakes,
'final_sinuosity': sim.channel.calculate_sinuosity()
}
if __name__ == "__main__":
print("๊ณก๋ฅ ํ์ฒ ๋ฌผ๋ฆฌ ์๋ฎฌ๋ ์ด์
ํ
์คํธ")
print("=" * 50)
sim = MeanderSimulation(initial_sinuosity=1.3)
print(f"์ด๊ธฐ ๊ตด๊ณก๋: {sim.channel.calculate_sinuosity():.2f}")
sim.run(5000, save_interval=1000)
print(f"5000๋
ํ ๊ตด๊ณก๋: {sim.channel.calculate_sinuosity():.2f}")
print(f"ํ์ฑ๋ ์ฐ๊ฐํธ: {len(sim.oxbow_lakes)}๊ฐ")
print("=" * 50)
print("ํ
์คํธ ์๋ฃ!")
|