AMReX-Astro / AMReX-Astro/Castro

`gwstrain` STF projection subtracts only diagonal element instead of full trace

Open Beginner friendly
#3,237 3 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

ai-code-audit bug :bug: gravity
Dominant language
C++
Stars
340
Forks
105
Avg merge
3d 8h
Merged PRs (30d)
8

Description

Summary

In Castro::gwstrain, the symmetric trace-free (STF) projection is documented as
STF(A^{ij}) = 1/2 A^{ij} + 1/2 A^{ji} - 1/3 delta^{ij} sum_k A^{kk}, but the implementation subtracts only dQtt(m,m) for each diagonal component. This does not remove the full trace and yields an incorrect STF tensor.

Location

  • Source/driver/sum_utils.cpp:476
  • Source/driver/sum_utils.cpp:486

Problem Details

Current code:

dQ(l,m) = 0.5_rt * dQtt(l,m) + 0.5_rt * dQtt(m,l);
if (l == m) {
    dQ(l,m) -= (1.0_rt / 3.0_rt) * dQtt(m,m);
}

For diagonal entries, the subtraction must use the full trace
dQtt(0,0) + dQtt(1,1) + dQtt(2,2), not the single matching diagonal element.

Impact

  • Incorrect gravitational-wave quadrupole STF tensor.
  • Biased h_plus / h_cross diagnostics, especially when anisotropy is significant.

Suggested Patch

diff --git a/Source/driver/sum_utils.cpp b/Source/driver/sum_utils.cpp
--- a/Source/driver/sum_utils.cpp
+++ b/Source/driver/sum_utils.cpp
@@
-            for (int l = 0; l < 3; ++l) {
+            const Real tr = dQtt(0,0) + dQtt(1,1) + dQtt(2,2);
+
+            for (int l = 0; l < 3; ++l) {
                 for (int m = 0; m < 3; ++m) {
                     dQ(l,m) = 0.5_rt * dQtt(l,m) + 0.5_rt * dQtt(m,l);
                     if (l == m) {
-                        dQ(l,m) -= (1.0_rt / 3.0_rt) * dQtt(m,m);
+                        dQ(l,m) -= (1.0_rt / 3.0_rt) * tr;
                     }
                 }
             }

Prepared by Codex

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start in Source/driver/sum_utils.cpp at lines 476 and 486, where Castro::gwstrain constructs the symmetric trace-free tensor. Compare the implementation with the documented STF formula and inspect the diagonal calculation. Done means the computed tensor removes the complete three-dimensional trace and preserves the intended h_plus and h_cross diagnostics.

Written by the indexing model from the issue text.

Assessment

Tech stack
cpp
Domain
hpc
Issue type
Bug
Difficulty
2/5
Estimated time
1-3 hours
Activity status
Active
Clarity
Clearly specified
Newbie friendliness
78/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.