Skip to content

RePrimAnd Con2Prim#126

Open
jaykalinani wants to merge 12 commits intoEinsteinToolkit:developmentfrom
jaykalinani:rpa
Open

RePrimAnd Con2Prim#126
jaykalinani wants to merge 12 commits intoEinsteinToolkit:developmentfrom
jaykalinani:rpa

Conversation

@jaykalinani
Copy link
Collaborator

@jaykalinani jaykalinani commented Jan 30, 2026

  • Add RPA support to Con2PrimFactory.

  • Code tested on Vista:

  1. Magnetic rotor test in AMR. Left RPA, right Noble/Palenzuela
Screenshot 2026-01-29 at 8 03 51 PM
  1. magTOV + Z4c + AMR
Noble_RPA
  1. Spherical shock test with Bz=1, vw_lim=10
RPA_Bz1_tol1e-8_iter100_vwlim10 Screenshot 2026-03-04 at 2 59 42 AM

@jaykalinani jaykalinani requested review from MChabanov and lwJi January 30, 2026 02:06
pv.vel = (mu * cache.x) * (r_u + (rb * mu) * b_u);
pv.w_lor = cache.w;
}

Copy link
Collaborator

@MChabanov MChabanov Jan 30, 2026

Choose a reason for hiding this comment

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

Exact same comment as for Palenzuela, see here:
https://github.com/EinsteinToolkit/AsterX/pull/126/changes#r2886212547

Copy link
Collaborator

@MChabanov MChabanov left a comment

Choose a reason for hiding this comment

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

Some comments from my side! Code looks very good!

// where r^i = S^i / D, b^i = B^i / sqrt(D), (r.b) = (B^i S_i)/(D^(3/2)).
// ------------------------------------------------------------------

const vec<CCTK_REAL, 3> mom_up = calc_contraction(gup, cv.mom);
Copy link
Collaborator

Choose a reason for hiding this comment

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

Just an idea: One can extract the code below, where prims are computed, to a separate function, similar to our other C2Ps. Eg for Palenzuela see xPalenzuelaToPrim in

c2p_1DPalenzuela::xPalenzuelaToPrim(CCTK_REAL xPalenzuela_Sol, CCTK_REAL Ssq,

Copy link
Collaborator

@MChabanov MChabanov left a comment

Choose a reason for hiding this comment

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

Great effort! I'm very impressed. Most comments are minor and are mainly related to consistency with the old code. Thanks!

(void)status;
return;
}
rep.set_soft_root_conv();
Copy link
Collaborator

Choose a reason for hiding this comment

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

line 409: the root finding finds the root for rho, such that max(1, max(rho_l, rho_r) ) might always evaluate to 1 ... -> a better choice for the lower limit of the scale might be just 0, ie
Replace with:
fmax(CCTK_REAL(0.0), fmax(abs(result.first), abs(result.second)));

return;
}
rep.set_soft_root_conv();
}
Copy link
Collaborator

Choose a reason for hiding this comment

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

line 494: similar comment as for the entropy C2P.
Palenzuela root finds for hW which should always be >= 1.0. So, that's fine. However, some EOS tables have negative eps in their tables which might lead to a h < 1 in the code. This means that formally you would want h_min (from the table) here as the lower bound and having h>=1 would mess with these values ...

pv.temperature = eos_3p->temp_from_rho_eps_ye(pv.rho, pv.eps, pv.Ye);
pv.entropy = eos_3p->kappa_from_rho_eps_ye(pv.rho, pv.eps, pv.Ye);
rep.adjust_cons = true;
}
Copy link
Collaborator

Choose a reason for hiding this comment

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

Velocity and temperature are limited by the code implemented in the function
c2p::prims_floors_and_ceilings
called below in line 537. Additionally, limiting eps or temp should be equivalent in AsterX to my understanding, hence we might already get away without these limits here.

I suggest to explore whether the limiting we already have is sufficient and if not, this code could be moved to the function c2p::prims_floors_and_ceilings in a consistent way. To avoid calling the EOS too often and having code duplication.

atmo.set(pv, cv, glo);
return;
}

Copy link
Collaborator

Choose a reason for hiding this comment

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

Note that this functionality already exists in line 226 of con2prim.cxx

if (cv.dens <= sqrt_detg * rho_atmo_cut) {

cv.DYe);
set_to_nan(pv, cv);
return;
}
Copy link
Collaborator

Choose a reason for hiding this comment

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

isfinite(cv.dens) is checked below in line 116. cv.dens <= 0 should be captured before

if (cv.dens <= sqrt_detg * rho_atmo_cut) {

Hence, I'm not sure if we need this check here?

CCTK_REAL Ye_raw = cv.DYe / cv.dens;
const CCTK_REAL Ye = fmin(fmax(eos_3p->rgye.min, Ye_raw), eos_3p->rgye.max);
const bool ye_clipped =
(Ye_raw < eos_3p->rgye.min) || (Ye_raw > eos_3p->rgye.max);
Copy link
Collaborator

Choose a reason for hiding this comment

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

That's not part of this PR but this line makes me think that we might want to do something similar for Palenzuela ...

if (std::isfinite(a) && std::isfinite(b) && b >= a) {
const CCTK_REAL width = b - a;
const CCTK_REAL scale =
fmax(CCTK_REAL(1.0), fmax(std::abs(a), std::abs(b)));
Copy link
Collaborator

Choose a reason for hiding this comment

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

Same comment as before for Palenzuela and Entropy:
To my understanding RPA solves for 1/(hW) which has the limits 0 < mu < 1/hmin ...
That means you will likely choose 1 for the scale ...
I would be good to double-check that, in case that's true the better lower limit would be again 0.0, so, replace line 181 with

fmax(CCTK_REAL(0.0), fmax(std::abs(a), std::abs(b)));

{
const auto rgeps = eos_3p->range_eps_from_rho_ye(pv.rho, pv.Ye);
if (cache.eps_raw < rgeps.min || cache.eps_raw > rgeps.max) {
rep.adjust_cons = true;
Copy link
Collaborator

Choose a reason for hiding this comment

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

Why are you setting the flag for recomputation if eps didn't change here?

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