Skip to content

Commit 8924bd8

Browse files
authored
reorder some loops over Jacobians (#1639)
the MathArray2D is Fortran-ordered. Some of the loops should be more efficient if their order is swapped.
1 parent 727afa9 commit 8924bd8

File tree

3 files changed

+15
-35
lines changed

3 files changed

+15
-35
lines changed

integration/integrator_rhs_sdc.H

+11-17
Original file line numberDiff line numberDiff line change
@@ -105,15 +105,8 @@ void jac (const amrex::Real time, BurnT& state, T& int_state, MatrixType& pd)
105105

106106

107107
if (state.T <= EOSData::mintemp || state.T >= integrator_rp::MAX_TEMP) {
108-
109-
for (int j = 1; j <= INT_NEQS; ++j) {
110-
for (int i = 1; i <= INT_NEQS; ++i) {
111-
pd(i,j) = 0.0_rt;
112-
}
113-
}
114-
108+
pd.zero();
115109
return;
116-
117110
}
118111

119112
// Call the specific network routine to get the Jacobian.
@@ -122,15 +115,16 @@ void jac (const amrex::Real time, BurnT& state, T& int_state, MatrixType& pd)
122115

123116
// The Jacobian from the nets is in terms of dYdot/dY, but we want
124117
// it was dXdot/dX, so convert here.
125-
for (int n = 1; n <= NumSpec; n++) {
126-
for (int m = 1; m <= neqs; m++) {
127-
pd(n,m) = pd(n,m) * aion[n-1];
118+
119+
for (int jcol = 1; jcol <= neqs; ++jcol) {
120+
for (int irow = 1; irow <= NumSpec; irow++) {
121+
pd(irow, jcol) = pd(irow, jcol) * aion[irow-1];
128122
}
129123
}
130124

131-
for (int m = 1; m <= neqs; m++) {
132-
for (int n = 1; n <= NumSpec; n++) {
133-
pd(m,n) = pd(m,n) * aion_inv[n-1];
125+
for (int jcol = 1; jcol <= NumSpec; ++jcol) {
126+
for (int irow = 1; irow <= neqs; ++irow) {
127+
pd(irow, jcol) = pd(irow, jcol) * aion_inv[jcol-1];
134128
}
135129
}
136130

@@ -170,9 +164,9 @@ void jac (const amrex::Real time, BurnT& state, T& int_state, MatrixType& pd)
170164

171165
eos_xderivs_t eos_xderivs = composition_derivatives(eos_state);
172166

173-
for (int m = 1; m <= neqs; m++) {
174-
for (int n = 1; n <= NumSpec; n++) {
175-
pd(m, n) -= eos_xderivs.dedX[n-1] * pd(m, net_ienuc);
167+
for (int jcol = 1; jcol <= NumSpec;++jcol) {
168+
for (int irow = 1; irow <= neqs; ++irow) {
169+
pd(irow, jcol) -= eos_xderivs.dedX[jcol-1] * pd(irow, net_ienuc);
176170
}
177171
}
178172

integration/integrator_rhs_strang.H

+1-8
Original file line numberDiff line numberDiff line change
@@ -119,15 +119,8 @@ void jac ([[maybe_unused]] const amrex::Real time, BurnT& state, T& int_state, M
119119
// bounds. Otherwise set the Jacobian to zero and return.
120120

121121
if (state.T <= EOSData::mintemp || state.T >= integrator_rp::MAX_TEMP) {
122-
123-
for (int j = 1; j <= INT_NEQS; ++j) {
124-
for (int i = 1; i <= INT_NEQS; ++i) {
125-
pd(i,j) = 0.0_rt;
126-
}
127-
}
128-
122+
pd.zero();
129123
return;
130-
131124
}
132125

133126
// Call the specific network routine to get the Jacobian.

integration/utils/numerical_jacobian.H

+3-10
Original file line numberDiff line numberDiff line change
@@ -136,15 +136,8 @@ void numerical_jac(BurnT& state, const jac_info_t& jac_info, JacNetArray2D& jac)
136136
state_delp.T += dy;
137137

138138
if (state_delp.T <= EOSData::mintemp || state_delp.T >= integrator_rp::MAX_TEMP) {
139-
140-
for (int i = 1; i <= int_neqs; i++) {
141-
for (int j = 1; j <= int_neqs; j++) {
142-
jac(i,j) = 0.0_rt;
143-
}
144-
}
145-
139+
jac.zero();
146140
return;
147-
148141
}
149142

150143

@@ -195,8 +188,8 @@ void numerical_jac(BurnT& state, const jac_info_t& jac_info, JacNetArray2D& jac)
195188
// now correct the species derivatives
196189
// this constructs dy/dX_k |_e = dy/dX_k |_T - e_{X_k} |_T dy/dT / c_v
197190

198-
for (int m = 1; m <= int_neqs; m++) {
199-
for (int n = 1; n <= NumSpec; n++) {
191+
for (int n = 1; n <= NumSpec; n++) {
192+
for (int m = 1; m <= int_neqs; m++) {
200193
jac(m, n) -= eos_xderivs.dedX[n-1] * jac(m, net_ienuc);
201194
}
202195
}

0 commit comments

Comments
 (0)