@@ -3143,8 +3143,8 @@ Castro::normalize_species (MultiFab& S_new, int ng)
31433143
31443144 Real lsmall_x = network_rp::small_x;
31453145
3146- ReduceOps<ReduceOpMin, ReduceOpMax > reduce_op;
3147- ReduceData<Real, Real > reduce_data (reduce_op);
3146+ ReduceOps<ReduceOpSum > reduce_op;
3147+ ReduceData<int > reduce_data (reduce_op);
31483148 using ReduceTuple = typename decltype (reduce_data)::Type;
31493149
31503150#ifdef AMREX_USE_OMP
@@ -3160,35 +3160,34 @@ Castro::normalize_species (MultiFab& S_new, int ng)
31603160 // then normalize them so that they sum to 1.
31613161
31623162 reduce_op.eval (bx, reduce_data,
3163- [=] AMREX_GPU_DEVICE (int i, int j, int k) -> ReduceTuple
3163+ [=] AMREX_GPU_DEVICE (int i, int j, int k) noexcept -> ReduceTuple
31643164 {
31653165 Real rhoX_sum = 0 .0_rt;
3166- Real rhoInv = 1 .0_rt / u (i,j,k,URHO);
3166+ Real rho = u (i,j,k,URHO);
3167+ Real rhoInv = 1 .0_rt / rho;
31673168
3168- Real minX = 1 .0_rt;
3169- Real maxX = 0 .0_rt;
3169+ int failed{};
31703170
31713171 for (int n = 0 ; n < NumSpec; ++n) {
31723172 // Abort if X is unphysically large.
31733173 Real X = u (i,j,k,UFS+n) * rhoInv;
31743174
31753175 // Only do the abort check if the density is greater than a user-defined cutoff.
3176- if (u (i,j,k,URHO) >= castro::abundance_failure_rho_cutoff) {
3177- minX = amrex::min (minX, X);
3178- maxX = amrex::max (maxX, X);
3179-
3176+ if (rho >= castro::abundance_failure_rho_cutoff) {
31803177 if (X < -castro::abundance_failure_tolerance ||
31813178 X > 1 .0_rt + castro::abundance_failure_tolerance) {
31823179#ifndef AMREX_USE_GPU
3183- std::cout << " (i, j, k) = " << i << " " << j << " " << k << " " << " , X[" << n << " ] = " << X << " (density here is: " << u (i,j,k,URHO) << " )" << std::endl;
3180+ std::cout << " (i, j, k) = " << i << " " << j << " " << k << " " << " , X[" << n << " ] = " << X
3181+ << " (density here is: " << rho << " )" << std::endl;
31843182#elif defined(ALLOW_GPU_PRINTF)
31853183 AMREX_DEVICE_PRINTF (" (i, j, k) = %d %d %d, X[%d] = %g (density here is: %g)\n " ,
3186- i, j, k, n, X, u (i,j,k,URHO) );
3184+ i, j, k, n, X, rho );
31873185#endif
3186+ failed = 1 ;
31883187 }
31893188 }
31903189
3191- u (i,j,k,UFS+n) = amrex::max (lsmall_x * u (i,j,k,URHO ), amrex::min ( u (i,j,k,URHO), u (i,j,k,UFS+n)) );
3190+ u (i,j,k,UFS+n) = amrex::Clamp ( u (i,j,k,UFS+n ), lsmall_x * rho, rho );
31923191 rhoX_sum += u (i,j,k,UFS+n);
31933192 }
31943193
@@ -3198,16 +3197,14 @@ Castro::normalize_species (MultiFab& S_new, int ng)
31983197 u (i,j,k,UFS+n) *= fac;
31993198 }
32003199
3201- return {minX, maxX };
3200+ return {failed };
32023201 });
32033202 }
32043203
32053204 ReduceTuple hv = reduce_data.value ();
3206- Real minX = amrex::get<0 >(hv);
3207- Real maxX = amrex::get<1 >(hv);
3205+ int num_failed = amrex::get<0 >(hv);
32083206
3209- if (minX < -castro::abundance_failure_tolerance ||
3210- maxX > 1 .0_rt + castro::abundance_failure_tolerance) {
3207+ if (num_failed > 0 ) {
32113208 amrex::Error (" Invalid mass fraction in Castro::normalize_species()" );
32123209 }
32133210}
0 commit comments