← All examples
49

Canonical Grid model

Materials starter - Diffusion scenarios

Synthetic constant-surface diffusion into a semi-infinite solid, with explicit engineering-unit conversions and repeatable temperature scenarios.

Scale
Small
Source
materials-diffusion-scenarios.grid
Length
78 lines
Collection
Advanced language
Level
Intermediate
Runtime
Portable
Version
1.0.0
materials-diffusion-scenarios.grid
Get Grid
MODEL "Materials starter - Diffusion scenarios"
DESCRIPTION "Synthetic constant-surface diffusion into a semi-infinite solid, with explicit engineering-unit conversions and repeatable temperature scenarios."
VERSION "1.0.0"
TAGS "materials", "starter", "diffusion", "scenarios"

strict

# Bounds are teaching limits, not an experimentally validated material window.
input Temperature_C = 726.85
  VALIDATE BETWEEN 0 AND 1500 MESSAGE "Use 0 to 1500 degrees Celsius in this example; the Arrhenius equation uses absolute kelvin."
input Duration_h = 1
  VALIDATE BETWEEN 0.000001 AND 10000 MESSAGE "Use a positive duration from 0.000001 to 10000 hours."
input Depth_um = 100
  VALIDATE BETWEEN 0 AND 1000000 MESSAGE "Depth must be nonnegative; this starter accepts up to 1,000,000 micrometers."

# CONVERT uses Grid's shared unit system; temperature is an absolute value.
Temperature_K = CONVERT(Temperature_C, "C", "K")
Duration_s = CONVERT(Duration_h, "h", "s")
Depth_m = CONVERT(Depth_um, "um", "m")
Prefactor_m2_s = 0.00002
Activation_J_mol = 140000
GasConstant_J_mol_K = 8.31446261815324
InitialConcentration_wt_pct = 0.2
SurfaceConcentration_wt_pct = 1.0

output Diffusivity_m2_s = Prefactor_m2_s * EXP(-(Activation_J_mol / (GasConstant_J_mol_K * Temperature_K)))
DiffusionLength_m = SQRT(Diffusivity_m2_s * Duration_s)
Uptake = ERFC(Depth_m / (2 * DiffusionLength_m))
output SelectedTemperature_K = Temperature_K
output SelectedDuration_s = Duration_s
output SelectedDepth_m = Depth_m
output DiffusionLength_um = CONVERT(DiffusionLength_m, "m", "um")
output NormalizedUptake = Uptake
output Concentration_wt_pct = InitialConcentration_wt_pct + (SurfaceConcentration_wt_pct - InitialConcentration_wt_pct) * Uptake
output Assumptions = "Semi-infinite, homogeneous solid; constant temperature and diffusivity; initially uniform concentration; fixed surface concentration; no finite back face, phase change, or concentration-dependent diffusivity. Synthetic parameters do not identify a material."
output ScenarioGuide = "In I/O, save Baseline at 726.85 C. Change Temperature_C to 826.85, save Higher temperature, then restore Baseline or reset inputs. Concentration at 100 um: 0.3858379883 -> 0.6627775552 -> 0.3858379883 wt pct. Export .gridoc to retain saved scenarios."

Profile = MAP(SEQUENCE(51, 1, 0, 1), (sample_index) => {
  depth_um: sample_index * 10,
  concentration: InitialConcentration_wt_pct + (SurfaceConcentration_wt_pct - InitialConcentration_wt_pct) * ERFC(CONVERT(sample_index * 10, "um", "m") / (2 * DiffusionLength_m))
})

A1 = "Diffusivity (m^2/s)"
B1 = Diffusivity_m2_s
A2 = "sqrt(Dt) (micrometers)"
B2 = DiffusionLength_um
A3 = "Normalized uptake at selected depth"
B3 = NormalizedUptake
A4 = "Concentration at selected depth (wt pct)"
B4 = Concentration_wt_pct
A5 = "Absolute temperature (K)"
B5 = SelectedTemperature_K
A6 = "Duration (s)"
B6 = SelectedDuration_s
A7 = "Depth (m)"
B7 = SelectedDepth_m
A9 = Assumptions
A10 = ScenarioGuide

Charts_1!type = "charts"
Charts_1!config = <toml>
  version = 1
  kind = "charts"
  title = "Diffusion profile"
  [layout]
  title = "Concentration after the selected heat treatment"
  x_axis = "Depth (micrometers)"
  y_axis = "Concentration (wt pct)"
  [[charts]]
  type = "line"
  smooth = false
  bind = "Profile"
  x = "depth_um"
  y = "concentration"
  label = "Constant-surface solution"
</toml>

END MODEL