Add matched diffusive resolution cases for pinball response
This commit is contained in:
1 parent
7b81584458
commit
e9213dd2cc
3 files changed
+143
-24
No files matched your search
@@ -24,19 +24,31 @@ COLUMNS = ('step', 'y', 'v', 'cme_F', 'cme_U', 'cme_L', 'wen_F', 'wen_U', 'wen_L
|
||||
ROOT = Path(__file__).resolve().parents[2]
|
||||
|
||||
|
||||
def config():
|
||||
return json.loads(Path(__file__).with_name('config.json').read_text())
|
||||
def config(diameter=D):
|
||||
"""Diffusive refinement preserves the inlet/outlet and half-grid y walls."""
|
||||
scale = diameter / D
|
||||
if diameter not in (20, 40, 60):
|
||||
raise ValueError('diameter must be 20, 40 or 60')
|
||||
cfg = json.loads(Path(__file__).with_name('config.json').read_text())
|
||||
cfg['grid']['nx'] = round((cfg['grid']['nx'] - 1) * scale + 1)
|
||||
cfg['grid']['ny'] = round((cfg['grid']['ny'] - 2) * scale + 2)
|
||||
cfg['physics']['velocity'] = U / scale
|
||||
return cfg
|
||||
|
||||
|
||||
def scaled_points(points, scale):
|
||||
return tuple((scale*x, .5 + scale*(y-.5)) for x, y in points)
|
||||
|
||||
|
||||
class Structure:
|
||||
"""Exact damped oscillator update for a force held over dt=1; no force filter."""
|
||||
def __init__(self, mass_ratio=10., frequency=1.e-4, zeta=0.):
|
||||
def __init__(self, mass_ratio=10., frequency=1.e-4, zeta=0., diameter=D):
|
||||
if not (math.isfinite(mass_ratio) and mass_ratio > 0. and
|
||||
math.isfinite(frequency) and frequency > 0. and
|
||||
math.isfinite(zeta) and 0. <= zeta < 1.):
|
||||
raise ValueError('positive finite mass ratio/frequency and 0 <= zeta < 1 required')
|
||||
self.mass_ratio, self.frequency = mass_ratio, frequency
|
||||
self.mass = mass_ratio * 3. * math.pi * D * D / 4.
|
||||
self.mass = mass_ratio * 3. * math.pi * diameter * diameter / 4.
|
||||
self.omega = 2. * math.pi * frequency
|
||||
self.zeta = zeta
|
||||
self.stiffness = self.mass * self.omega**2
|
||||
@@ -55,15 +67,15 @@ class Structure:
|
||||
-self.omega**2*self.es*z + (self.ec - self.a*self.es)*self.v)
|
||||
|
||||
|
||||
def summarize(rows):
|
||||
def summarize(rows, diameter=D, block_steps=10*PERIOD):
|
||||
windows = []
|
||||
for start in range(0, len(rows), 10*PERIOD):
|
||||
block = rows[start:start + 10*PERIOD]
|
||||
for start in range(0, len(rows), block_steps):
|
||||
block = rows[start:start + block_steps]
|
||||
fy = block[:, 3:9].sum(axis=1)
|
||||
windows.append(dict(start_step=int(block[0, 0]), end_step=int(block[-1, 0]),
|
||||
y_mean_D=float(block[:, 1].mean()/D),
|
||||
y_rms_D=float(np.sqrt(np.mean(block[:, 1]**2))/D),
|
||||
y_peak_D=float(np.abs(block[:, 1]).max()/D),
|
||||
y_mean_D=float(block[:, 1].mean()/diameter),
|
||||
y_rms_D=float(np.sqrt(np.mean(block[:, 1]**2))/diameter),
|
||||
y_peak_D=float(np.abs(block[:, 1]).max()/diameter),
|
||||
fy_mean=float(fy.mean()), fy_rms=float(np.sqrt(np.mean(fy**2))),
|
||||
mean_power=float(np.mean(fy*block[:, 2]))))
|
||||
return windows
|
||||
@@ -76,16 +88,26 @@ def main():
|
||||
ap.add_argument('--smoke', action='store_true', help='32+32 steps, no physical result')
|
||||
ap.add_argument('--case', choices=STRUCTURES, default='Z0',
|
||||
help='predeclared structure; all cases have zero structural damping')
|
||||
ap.add_argument('--D', type=int, choices=(20, 40, 60), default=20,
|
||||
help='diameter in cells; diffusive scaling, matched geometry and physical duration')
|
||||
ap.add_argument('--wall-seconds', type=float, default=7200., help='whole-case wall-clock cap')
|
||||
args = ap.parse_args()
|
||||
if not math.isfinite(args.wall_seconds) or args.wall_seconds <= 0:
|
||||
ap.error('--wall-seconds must be finite and positive')
|
||||
scale, time_scale = args.D / D, (args.D // int(D))**2
|
||||
velocity = U / scale
|
||||
centres, probes = scaled_points(CENTRES, scale), scaled_points(PROBES, scale)
|
||||
period = PERIOD*time_scale
|
||||
out = args.out.resolve()
|
||||
if out == ROOT or ROOT in out.parents:
|
||||
ap.error('output must be outside the checkout')
|
||||
out.mkdir(parents=True, exist_ok=False)
|
||||
cfg = config()
|
||||
cfg = config(args.D)
|
||||
(out/'config.json').write_text(json.dumps(cfg, indent=2)+'\n')
|
||||
source = subprocess.check_output(['git', '-C', str(ROOT), 'rev-parse', 'HEAD'], text=True).strip()
|
||||
s = Structure(*STRUCTURES[args.case], zeta=0.)
|
||||
warmup, count = (32, 32) if args.smoke else (WARMUP, STEPS)
|
||||
mass_ratio, frequency = STRUCTURES[args.case]
|
||||
s = Structure(mass_ratio, frequency/time_scale, zeta=0., diameter=args.D)
|
||||
warmup, count = (32, 32) if args.smoke else (WARMUP*time_scale, STEPS*time_scale)
|
||||
rows = np.lib.format.open_memmap(out/'steps.npy', mode='w+', dtype=np.float64,
|
||||
shape=(count, len(COLUMNS)))
|
||||
rows[:] = np.nan
|
||||
@@ -99,21 +121,26 @@ def main():
|
||||
structure=dict(mass=s.mass, stiffness=s.stiffness, damping=s.damping,
|
||||
mass_ratio_three_disks=s.mass_ratio,
|
||||
zeta=s.zeta, fn=s.frequency, Tn=1./s.frequency, y0=0., v0=0.),
|
||||
warmup_steps=warmup, requested_steps=count, dt=1., D=D, U=U, nu=NU,
|
||||
duration_Tn=count*s.frequency, duration_tU_D=count*U/D,
|
||||
summary_block_steps=10*PERIOD,
|
||||
warmup_steps=warmup, requested_steps=count, dt=1., D=args.D, U=velocity, nu=NU,
|
||||
relative_to_D20=dict(dx=1/scale, dt=1/time_scale),
|
||||
centres=centres, probes=probes, wall_planes=(.5, cfg['grid']['ny']-1.5),
|
||||
wall_cap_seconds=args.wall_seconds,
|
||||
duration_Tn=count*s.frequency, duration_tU_D=count*velocity/args.D,
|
||||
summary_block_steps=10*period,
|
||||
rhs='sum of three instantaneous CME_y + Wen_y, one-step lag, no filtering')
|
||||
try:
|
||||
with Simulation(str(out/'config.json')) as sim:
|
||||
# Match Legacy object order; probes remain passive and fixed in the lab.
|
||||
for c in PROBES:
|
||||
sim.add_body('sensor', c, 5.)
|
||||
envelope = Translation((0., 0., -D, D), .05, shared=True)
|
||||
bodies = [sim.add_body('circle', c, D/2, translation=envelope) for c in CENTRES]
|
||||
for c in probes:
|
||||
sim.add_body('sensor', c, 5.*scale)
|
||||
envelope = Translation((0., 0., -args.D, args.D), .05/scale, shared=True)
|
||||
bodies = [sim.add_body('circle', c, args.D/2, translation=envelope) for c in centres]
|
||||
sim.initialize()
|
||||
# At release obtain the last instantaneous force, not a warmup average.
|
||||
remaining = warmup - 1
|
||||
while remaining:
|
||||
if time.monotonic()-started > args.wall_seconds:
|
||||
raise TimeoutError('whole-case wall cap during warmup')
|
||||
chunk = min(10000, remaining)
|
||||
sim.run(chunk)
|
||||
remaining -= chunk
|
||||
@@ -123,8 +150,10 @@ def main():
|
||||
report['warmup_elapsed_s'] = time.monotonic()-started
|
||||
print(json.dumps(dict(event='release', **report)), flush=True)
|
||||
for n in range(count):
|
||||
if n % 1000 == 0 and time.monotonic()-started > args.wall_seconds:
|
||||
raise TimeoutError('whole-case wall cap during response')
|
||||
y1, v1 = (0., 0.) if args.fixed else s.candidate(f_last)
|
||||
if not all(map(math.isfinite, (y1, v1))) or abs(y1) > D:
|
||||
if not all(map(math.isfinite, (y1, v1))) or abs(y1) > args.D:
|
||||
status = 'stopped_nonfinite_or_travel_bound'
|
||||
break
|
||||
if not args.fixed:
|
||||
@@ -143,10 +172,10 @@ def main():
|
||||
completed = n+1
|
||||
s.y, s.v = y1, v1
|
||||
f_last = float(cme.sum(dtype=np.float64)+wen.sum(dtype=np.float64))
|
||||
if completed % PERIOD == 0:
|
||||
if completed % period == 0:
|
||||
rows.flush()
|
||||
print(json.dumps(dict(event='progress', step=completed, t_Tn=completed*s.frequency,
|
||||
y_D=s.y/D, elapsed_s=time.monotonic()-started)), flush=True)
|
||||
y_D=s.y/args.D, elapsed_s=time.monotonic()-started)), flush=True)
|
||||
else:
|
||||
status = 'smoke_completed' if args.smoke else 'duration_completed_not_qualified'
|
||||
except BaseException as exc:
|
||||
@@ -155,7 +184,7 @@ def main():
|
||||
finally:
|
||||
rows.flush()
|
||||
report.update(status=status, completed_steps=completed, elapsed_s=time.monotonic()-started,
|
||||
windows=summarize(rows[:completed]),
|
||||
windows=summarize(rows[:completed], args.D, 10*period),
|
||||
totals={key: float(rows[:completed, i].sum()) for key, i in
|
||||
[('eq_only', 12), ('no_donor', 13), ('crossings', 14)]},
|
||||
limitation='Uncontrolled development response only. No automatic settling, grid convergence, control or historical-solver equivalence claim.')
|
||||
|
||||
Reference in new issue
Block a user