Skip to content

fix: two-temperature model energy source and heat-diffusion stencil - #1250

Open
MZKC wants to merge 1 commit into
develop-2.0.0from
fix/ttm-energy-source-and-laplacian
Open

fix: two-temperature model energy source and heat-diffusion stencil#1250
MZKC wants to merge 1 commit into
develop-2.0.0from
fix/ttm-energy-source-and-laplacian

Conversation

@MZKC

@MZKC MZKC commented Jun 18, 2026

Copy link
Copy Markdown
Contributor

Summary

Three issues in the two-temperature model (TTM), the most visible being that the
electron temperature kept rising even after the laser pulse had passed.

  1. Energy source (the reported symptom). fdtd_eh.f90 passed the
    time-accumulated absorbed energy density
    u_energy = -∫ div(Poynting) dt to ttm_main as the source S(r,t). But
    ttm_main multiplies the source by dt, so S must be the instantaneous
    absorbed power density -div(Poynting). With the accumulated energy,
    div(Poynting) → 0 after the pulse but u_energy stays at its final value,
    so Te keeps being driven up every step. Pass -divS instead.

  2. Heat-diffusion stencil. div(kappa grad Te) was computed by applying a
    central first difference twice, giving [f(i±2) − 2 f(i)] / (4h²): this skips
    the midpoint, decouples the even/odd grid points and is blind to the
    checkerboard mode
    . Replaced with the conservative half-grid (midpoint) flux
    form [kappa_{i+½}(Te_{i+1}−Te_i) − kappa_{i−½}(Te_i−Te_{i−1})] / h²,
    kappa_{i+½} = (kappa_i + kappa_{i+1})/2.

  3. Init typo. init_ttm_alloc allocated rhs_l but re-initialised rhs_e
    (copy-paste). Harmless (ttm_main zeroes rhs_l each step) but corrected.

The now-unused calc_nabla helper and NABLA_* arrays are removed.

Verification

Unit tests (standalone).

  • Stencil: on a grid-checkerboard mode the old double-difference returns 0
    (cannot damp it) while the midpoint stencil gives 4·kappa/h².
  • Runaway: with a square-pulse source, the accumulated-energy source keeps
    heating Te after the pulse, while the instantaneous-power source lets Te
    relax once the pulse is over.

Integration (Wisteria-O, A64FX): FDTD + TTM. theory='maxwell', an absorbing
(Lorentz–Drude) sphere with the TTM enabled (ttm.inp_ttm, Tini = 300 K), a
5 fs pulse, total 20 fs. Both binaries absorb the same total energy (18.36, col 2):

quantity pre-fix fixed
max avg Te 3191 K, at t = 20 fs (the last sample — still rising) 299 K, at t = 4.1 fs (during the pulse)
avg Te at t = 20 fs 3191 K (the maximum) 232 K (turned over and relaxing)
avg Tl at t = 20 fs 342 K 299 K

Pre-fix the electron temperature rises monotonically to ~3200 K and is still the
maximum at the end of the run — the reported runaway. After the fix Te reaches
its peak during the pulse and then decreases, i.e. it no longer keeps rising once
the light has passed.

The absorbing medium and TTM parameters here are representative (the runaway is
parameter-independent); plugging in specific silicon optical/TTM parameters does
not change the qualitative result.

🤖 Generated with Claude Code

Three issues in the two-temperature model (TTM):

1. Energy source. fdtd_eh.f90 passed the time-accumulated absorbed energy
   density (u_energy = -int divS dt) to ttm_main as the source S(r,t). But
   ttm_main multiplies the source by dt, so S must be the instantaneous absorbed
   power density -div(Poynting). With the accumulated energy, divS -> 0 after the
   pulse but u_energy stays at its final value, so the electron temperature kept
   rising even after the light had passed. Pass -divS instead.

2. Heat diffusion stencil. div(kappa grad Te) was computed by applying a central
   first difference twice, giving [f(i+-2) - 2 f(i)]/(4 h^2): this skips the
   midpoint, decouples the even/odd grid points and is blind to the checkerboard
   mode. Replaced with the conservative half-grid (midpoint) flux form
   [kappa_{i+1/2}(Te_{i+1}-Te_i) - kappa_{i-1/2}(Te_i-Te_{i-1})]/h^2.

3. init_ttm_alloc allocated rhs_l but re-initialised rhs_e (copy-paste); harmless
   because ttm_main zeroes rhs_l each step, but corrected.

The now-unused calc_nabla helper and NABLA_* arrays are removed.

Verified with a standalone test: the old stencil returns 0 for a checkerboard
mode while the midpoint stencil gives 4*kappa/h^2; and with a square-pulse source
the accumulated-energy source keeps heating Te after the pulse whereas the
instantaneous-power source lets Te relax.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
@jenkins-diana

Copy link
Copy Markdown

Can one of the admins verify this patch?

@MZKC
MZKC requested a review from syamada0 June 18, 2026 07:44

@MZKC MZKC left a comment

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The core fixes are correct: instantaneous -divS as the TTM source (instead of the time-accumulated u_energy), the dt_em factor on the reported deposited energy, the conservative midpoint-flux Laplacian (replacing the even/odd-decoupled double-central-difference), and the rhs_l=0.0d0 alloc-zero typo. One boundary-handling caveat on the new stencil, inline.

Comment thread src/ttm/ttm.f90
iy = ijk_media_myrnk(2,ii)
iz = ijk_media_myrnk(3,ii)
rhs_e(ix,iy,iz) = rhs_e(ix,iy,iz) &
+ ( 0.5d0*(work(ix ,iy,iz)+work(ix+1,iy,iz))*(Te(ix+1,iy,iz)-Te(ix ,iy,iz)) &

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

+ ( 0.5d0*(work(ix  ,iy,iz)+work(ix+1,iy,iz))*(Te(ix+1,iy,iz)-Te(ix  ,iy,iz))   &

The conservative midpoint-flux form is the right fix for the decoupled stencil. Boundary caveat: this loop runs over media points (ijk_media_myrnk) but the face coefficient is 0.5*(kappa_i + kappa_{i±1}). At a media/non-media boundary the neighbor has work=0 (kappa via where(Tl/=0)) and Te≈0, so the face still carries ~kappa_i/2 * (0 - Te_i) ≠ 0 — heat conducts into the vacuum/non-media side, i.e. artificial surface cooling rather than the intended zero-flux boundary. Consider zeroing the face coefficient when the neighbor is not a media point (mask on Tl_{i±1}/=0 or kappa_{i±1}>0). The old central-difference path had a related leak so this isn't a regression, but the new stencil doesn't yet enforce the documented zero-flux boundary.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Leaving this PR's stencil as-is: the media-boundary heat-flux handling is being addressed in the three-temperature-model work (#1268). As noted, this is not a regression versus the previous central-difference path.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants