Skip to content

Precompute SRK quantities using CEPTR#398

Merged
baperry2 merged 22 commits intoAMReX-Combustion:developmentfrom
baperry2:ceptr-srk
Jun 28, 2023
Merged

Precompute SRK quantities using CEPTR#398
baperry2 merged 22 commits intoAMReX-Combustion:developmentfrom
baperry2:ceptr-srk

Conversation

@baperry2
Copy link
Copy Markdown
Contributor

@baperry2 baperry2 commented Jun 1, 2023

There are bunch of quantities related to critical parameters that get computed every time the SRK EOS is initialized. These are constants for each species, so they can be precomputed and put into the machine generated code from CEPTR. Additionally, instead of being stored as thread private arrays, they are now stored as global arrays. This yields a small speedup on both CPU and GPU.

This PR also modifies the EosEval utility so it can be used to test the SRK EOS.

Mechanisms will need to be regenerated before merging. For now, the modified drm19 is included as an example.

@baperry2 baperry2 requested a review from marchdf June 1, 2023 20:37
Copy link
Copy Markdown
Contributor

@marchdf marchdf left a comment

Choose a reason for hiding this comment

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

Fantastic!

@marchdf
Copy link
Copy Markdown
Contributor

marchdf commented Jun 1, 2023

To avoid any back and forth, can you open a PR in PeleC with this branch so we catch any warnings/etc?

@baperry2
Copy link
Copy Markdown
Contributor Author

baperry2 commented Jun 2, 2023

@marchdf @malihass I believe this is good to go other than regenerating the QSS mechanisms, where I'm getting some unrelated diffs, as shown below. Not sure what's causing this.

[bperry@el1 Models]$ git diff CH4_lean_qss/mechanism.H
diff --git a/Support/Mechanism/Models/CH4_lean_qss/mechanism.H b/Support/Mechanism/Models/CH4_lean_qss/mechanism.H
index e64b1fdb..460675e6 100644
--- a/Support/Mechanism/Models/CH4_lean_qss/mechanism.H
+++ b/Support/Mechanism/Models/CH4_lean_qss/mechanism.H
@@ -6458,2740 +6458,2733 @@ aJacobian(amrex::Real* J, amrex::Real* sc, amrex::Real T, const int consP)
   const amrex::Real x7 = 6.0 * sc[5] + x6;
   amrex::Real x10 = -g_RT[11] - g_RT[1] + g_RT_qss[3];
   amrex::Real x11 = -3286.0048277048199 * invT - 4.82 * tc[0];
-  amrex::Real x16 = 1.27e+20 * x7 * exp(x11) / kf_qss[2];
   amrex::Real x17 = log(
     0.2813 * exp(-0.0097087378640776708 * tc[1]) +
     0.7187 * exp(-0.00077459333849728897 * tc[1]) + exp(-4160.0 * invT));
   amrex::Real x20 =
-    -0.29097730287517898 * x17 + 0.43429448190325198 * log(x16) - 0.4;
+    -0.29097730287517898 * x17 +
+    0.43429448190325198 * log(1.27e+20 * x7 * exp(x11) / kf_qss[2]) - 0.4;
   amrex::Real x24 = -0.55155399201712996 * x17 - 0.14 * x20 + 0.75;
   amrex::Real x26 = ((x20) * (x20)) / ((x24) * (x24)) + 1.0;
-  amrex::Real x29 =
-    exp(M_LN10 * (0.43429448190325198 * x17 / x26)) / (x16 + 1.0);
-  amrex::Real x31 = refC * x29 * exp(x10 + x11);
-  amrex::Real x34 = -kf_qss[10] * sc[2] - kf_qss[14] * sc[1] -
+  amrex::Real x30 = exp(M_LN10 * (0.43429448190325198 * x17 / x26)) /
+                    (1.0 + 1.27e+20 * x7 * exp(x11) / kf_qss[2]);
+  amrex::Real x32 = refC * x30 * exp(x10 + x11);
+  amrex::Real x35 = -kf_qss[10] * sc[2] - kf_qss[14] * sc[1] -
                     kf_qss[15] * sc[1] - kf_qss[16] * sc[1] -
                     kf_qss[23] * sc[4] - kf_qss[40] * sc[3] -
-                    1.27e+20 * x31 * x7 + 10.0e-13;
-  const amrex::Real x39 = exp(-g_RT[1] + g_RT[5] + g_RT_qss[1] - g_RT_qss[3]);
-  const amrex::Real x43 = (kf_qss[16] * sc[5] * x39 + 10.0e-13) / x34;
-  amrex::Real x45 = g_RT[4] - g_RT[5];
-  const amrex::Real x47 = exp(-g_RT[7] + g_RT_qss[1] - x45);
-  amrex::Real x52 =
-    -kf_qss[16] * sc[5] * x39 - kf_qss[18] * sc[4] - kf_qss[20] * sc[5] * x47 -
+                    1.27e+20 * x32 * x7 + 10.0e-13;
+  const amrex::Real x40 = exp(-g_RT[1] + g_RT[5] + g_RT_qss[1] - g_RT_qss[3]);
+  const amrex::Real x44 = (kf_qss[16] * sc[5] * x40 + 10.0e-13) / x35;
+  amrex::Real x48 = g_RT[4] - g_RT[5];
+  const amrex::Real x50 = exp(-g_RT[7] + g_RT_qss[1] - x48);
+  amrex::Real x53 =
+    -kf_qss[16] * sc[5] * x40 - kf_qss[18] * sc[4] - kf_qss[20] * sc[5] * x50 -
     kf_qss[28] * sc[12] - kf_qss[29] * sc[3] - kf_qss[30] * sc[3] -
     kf_qss[31] * sc[0] - kf_qss[32] * sc[5] - kf_qss[33] * sc[8] -

@malihass
Copy link
Copy Markdown
Collaborator

malihass commented Jun 5, 2023

I tried regenerating the qss mechs and I do not see these diffs. I just see some diff because of precision + the srk variables
Did you regenerate the mechs with poetry run convert -lq ${PELE_PHYSICS_HOME}/Support/Mechanism/Models/list_qss_mech

I also tried in the development branch and I do not see diffs aside from the usual precision differences.

@baperry2
Copy link
Copy Markdown
Contributor Author

baperry2 commented Jun 5, 2023

I get the diff above running on Eagle. The exact same thing on my MacBook leads to no diffs. I'll just use the versions from my MacBook.

@baperry2
Copy link
Copy Markdown
Contributor Author

I just went back to having these quantities be threadprivate arrays, PeleC is no longer complaining so I'm going to merge this.

@baperry2 baperry2 merged commit 7a1fdcc into AMReX-Combustion:development Jun 28, 2023
@baperry2 baperry2 deleted the ceptr-srk branch June 28, 2023 15:08
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.

3 participants