diff --git a/flags/entries/weihaoyang/README.md b/flags/entries/weihaoyang/README.md new file mode 100644 index 0000000..9552f14 --- /dev/null +++ b/flags/entries/weihaoyang/README.md @@ -0,0 +1,13 @@ +# Metal-printing flag entry + +This entry predicts the width and depth of a single track on a bare metal plate. The upstream G20 finite-volume enthalpy solver supplies the width and the conduction estimate of depth. A separately compiled energy-coupling model supplies a second depth estimate. The reported depth is the larger estimate. + +For a Gaussian beam of radius `a`, let `X = P / (π H v a²)`, where `P` is incident power, `v` is scan speed and `H` is the sensible volumetric heat required to reach the liquidus. `X` corresponds to the product of normalized enthalpy and normalized thermal diffusion length with absorptivity divided out. The absorptivity is `0.7(1 − exp(−0.66 X))`. The scaling depth is `0.6 a × absorptivity × X`. The parameters come from the published energy-coupling model. The material heat capacity at the high-temperature end of the upstream solid-property table is used as the constant heat capacity in this scaling. [Ye et al. (2019)](https://doi.org/10.1002/adem.201900185) + +This is a reduced-order depth estimate. It leaves the reference solver's in-plane model in use and does not resolve the moving free surface, melt-pool flow or beam reflections. This entry was developed with OpenAI Codex. + +The upstream evaluator compiles both solvers and supplies the case inputs. + +```sh +python3 tools/flags.py run --entry weihaoyang --flag metal-printing +``` diff --git a/flags/entries/weihaoyang/entry.json b/flags/entries/weihaoyang/entry.json new file mode 100644 index 0000000..03bceb9 --- /dev/null +++ b/flags/entries/weihaoyang/entry.json @@ -0,0 +1,13 @@ +{ + "title": "Conduction with energy-coupled keyhole depth", + "who": "weihaoyang", + "ai": "OpenAI Codex", + "libraries": ["OpenPhysicsAI"], + "open": true, + "baseline": false, + "builds_on": "OpenPhysicsAI G20 conduction solver and Ye et al. (2019), doi:10.1002/adem.201900185", + "description": "The G20 finite-volume enthalpy solver predicts lateral melt. The depth is the larger of the conduction prediction and the estimate from a dimensionless laser energy-coupling model with saturating absorptivity. The depth correction uses no benchmark measurements or case IDs.", + "commands": { + "metal-printing": "python3 flags/entries/weihaoyang/predict.py" + } +} diff --git a/flags/entries/weihaoyang/keyhole_scale.c b/flags/entries/weihaoyang/keyhole_scale.c new file mode 100644 index 0000000..320fadb --- /dev/null +++ b/flags/entries/weihaoyang/keyhole_scale.c @@ -0,0 +1,38 @@ +/* SPDX-License-Identifier: Apache-2.0 */ +/* A reduced-order melt-pool depth for laser tracks in a metal plate. */ +#include +#include +#include + +static const double pi = 3.14159265358979323846; + +static double scaled_depth(double power, double speed, double radius, double enthalpy) { + /* beta * L_th / A in Ye et al. (2019): thermal diffusivity cancels. + radius is 2 sigma, or half the D4sigma diameter for a Gaussian beam. */ + const double incident_energy = power / (pi * enthalpy * speed * radius * radius); + const double absorptivity = -0.7 * expm1(-0.66 * incident_energy); + return 0.6 * radius * absorptivity * incident_energy; +} + +int main(int argc, char **argv) { + if (argc != 5) { + fprintf(stderr, "usage: keyhole_scale power_W speed_m_s radius_m enthalpy_J_m3\n"); + return 2; + } + double value[4]; + for (int i = 0; i < 4; i++) { + char *end; + value[i] = strtod(argv[i + 1], &end); + if (end == argv[i + 1] || *end != '\0' || !isfinite(value[i]) || value[i] <= 0.0) { + fprintf(stderr, "keyhole_scale: all four arguments must be finite and positive\n"); + return 2; + } + } + double depth = scaled_depth(value[0], value[1], value[2], value[3]); + if (!isfinite(depth)) { + fprintf(stderr, "keyhole_scale: the computed depth was nonfinite\n"); + return 2; + } + printf("%.12g\n", depth); + return 0; +} diff --git a/flags/entries/weihaoyang/predict.py b/flags/entries/weihaoyang/predict.py new file mode 100644 index 0000000..1a9384e --- /dev/null +++ b/flags/entries/weihaoyang/predict.py @@ -0,0 +1,65 @@ +#!/usr/bin/env python3 +"""Keep G20's conduction width and extend its depth with laser energy coupling.""" + +import json +import os +from pathlib import Path +import subprocess +import sys + + +ROOT = Path(__file__).resolve().parents[3] +ENTRY = Path(__file__).resolve().parent +WORK = ROOT / 'build' / 'flags' / 'weihaoyang' +REFERENCE = ROOT / 'flags' / 'metal-printing' / 'reference_materials.json' +BASE_ABSORPTIVITY = 0.3085 +CELL_METRES = 5e-6 + +sys.path.insert(0, str(ROOT / 'tools')) +import g20_melt as melt # noqa: E402 + + +def compile_solvers(): + WORK.mkdir(parents=True, exist_ok=True) + subprocess.run(['make', '-s', 'build/g20melt'], cwd=ROOT, check=True) + executable = WORK / 'keyhole_scale' + subprocess.run([os.environ.get('CC', 'cc'), '-std=c17', '-O2', '-Wall', '-Wextra', + '-Werror', str(ENTRY / 'keyhole_scale.c'), '-lm', '-o', str(executable)], check=True) + return executable + + +def predict_case(case, metal, executable): + data = case['inputs'] + case_id = case['case'] + temperature = round(data['plate_temperature_c'] + 273.15, 2) + power = data['laser_power_w'] + speed_mm_s = data['scan_speed_mm_per_s'] + diameter_um = data['spot_d4sigma_diameter_um'] + track = {'id': case_id, 'dataset': case_id, 'laser_power_W': power, + 'scan_speed_mm_per_s': speed_mm_s, 'spot': {'D4sigma_diameter_um': diameter_um}} + melt.T0[case_id] = temperature + surface = melt.solve(track, metal, BASE_ABSORPTIVITY, CELL_METRES) + + hot_specific_heat = metal['specific_heat_solid_j_kgk'] + sensible_enthalpy = metal['density_kg_m3'] * hot_specific_heat * (metal['liquidus_k'] - temperature) + physical_inputs = [str(x) for x in (power, speed_mm_s * 1e-3, diameter_um * 0.5e-6, sensible_enthalpy)] + depth_text = subprocess.check_output([str(executable), *physical_inputs], text=True) + keyhole_depth = float(depth_text) + return {'width': surface['width_m'] * 1e6, + 'depth': max(surface['depth_m'], keyhole_depth) * 1e6} + + +def main(): + executable = compile_solvers() + melt.RUNS = WORK / 'runs' + materials = json.loads(REFERENCE.read_text(encoding='utf-8'))['materials'] + cases = json.loads(os.environ['FLAG_CASES']) + predictions = {} + for case in cases: + metal = materials[case['inputs']['alloy']] + predictions[case['case']] = predict_case(case, metal, executable) + print(json.dumps(predictions, allow_nan=False)) + + +if __name__ == '__main__': + main()