From 142c2db6d99df2ef5319e33598c272616b33a47c Mon Sep 17 00:00:00 2001 From: Michael Zingale Date: Sun, 28 Jan 2024 19:39:25 -0500 Subject: [PATCH] use std:: for some math functions (#2734) --- Diagnostics/DustCollapse/main.cpp | 32 +++++++++---------- Diagnostics/Radiation/Radiation_utils.H | 2 +- Diagnostics/Radiation/gaussian_pulse.cpp | 8 ++--- Diagnostics/Radiation/lgt_frnt1d.cpp | 4 +-- Diagnostics/Radiation/rad_shock.cpp | 4 +-- Diagnostics/Radiation/rad_sphere.cpp | 2 +- Diagnostics/Sedov/main.cpp | 10 +++--- .../nova/problem_initialize_state_data.H | 4 +-- Exec/science/planet/HotJupiter.cpp | 30 ++++++++--------- Exec/science/wdmerger/Prob.cpp | 6 ++-- Exec/unit_tests/particles_test/Prob.cpp | 2 +- Source/driver/Castro.cpp | 8 ++--- Source/radiation/HypreABec.cpp | 8 ++--- Source/radiation/HypreMultiABec.cpp | 8 ++--- Source/radiation/RadMultiGroup.cpp | 20 ++++++------ .../_interpbndry/RadInterpBndryData.cpp | 2 +- Source/scf/scf_relax.cpp | 2 +- 17 files changed, 76 insertions(+), 76 deletions(-) diff --git a/Diagnostics/DustCollapse/main.cpp b/Diagnostics/DustCollapse/main.cpp index 7e2a0763de..9ac8619009 100644 --- a/Diagnostics/DustCollapse/main.cpp +++ b/Diagnostics/DustCollapse/main.cpp @@ -102,18 +102,18 @@ int main(int argc, char* argv[]) #if (AMREX_SPACEDIM == 1) int nbins = domain.length(0); #elif (AMREX_SPACEDIM == 2) - auto x_maxdist = fmax(fabs(problo[0]), fabs(probhi[0])); - auto y_maxdist = fmax(fabs(problo[1] - yctr), fabs(probhi[1] - yctr)); + auto x_maxdist = std::max(std::abs(problo[0]), std::abs(probhi[0])); + auto y_maxdist = std::max(std::abs(problo[1] - yctr), std::abs(probhi[1] - yctr)); - auto max_dist = sqrt(x_maxdist*x_maxdist + y_maxdist*y_maxdist); + auto max_dist = std::sqrt(x_maxdist*x_maxdist + y_maxdist*y_maxdist); int nbins = int(max_dist / dx_fine); #else - auto x_maxdist = fmax(fabs(problo[0] - xctr), fabs(probhi[0] - xctr)); - auto y_maxdist = fmax(fabs(problo[1] - yctr), fabs(probhi[1] - yctr)); - auto z_maxdist = fmax(fabs(problo[2] - zctr), fabs(probhi[2] - zctr)); + auto x_maxdist = std::max(std::abs(problo[0] - xctr), std::abs(probhi[0] - xctr)); + auto y_maxdist = std::max(std::abs(problo[1] - yctr), std::abs(probhi[1] - yctr)); + auto z_maxdist = std::max(std::abs(problo[2] - zctr), std::abs(probhi[2] - zctr)); - auto max_dist = sqrt(x_maxdist*x_maxdist + y_maxdist*y_maxdist + + auto max_dist = std::sqrt(x_maxdist*x_maxdist + y_maxdist*y_maxdist + z_maxdist*z_maxdist); int nbins = int(max_dist / dx_fine); @@ -147,7 +147,7 @@ int main(int argc, char* argv[]) // over levels, we will compare to the finest level index space to // determine if we've already output here int mask_size = domain.length().max(); - Vector imask(pow(mask_size, AMREX_SPACEDIM), 1); + Vector imask(std::pow(mask_size, AMREX_SPACEDIM), 1); // counter int cnt = 0; @@ -210,21 +210,21 @@ int main(int argc, char* argv[]) // analytic expression for the radius as a function of time t = 0.00 Real max_dens = 1.e9; - if (fabs(data.Time()) <= 1.e-8) + if (std::abs(data.Time()) <= 1.e-8) max_dens = 1.e9; - else if (fabs(data.Time() - 0.01) <= 1.e-8) + else if (std::abs(data.Time() - 0.01) <= 1.e-8) max_dens = 1.043345e9; - else if (fabs(data.Time() - 0.02) <= 1.e-8) + else if (std::abs(data.Time() - 0.02) <= 1.e-8) max_dens = 1.192524e9; - else if (fabs(data.Time() - 0.03) <= 1.e-8) + else if (std::abs(data.Time() - 0.03) <= 1.e-8) max_dens = 1.527201e9; - else if (fabs(data.Time() - 0.04) <= 1.e-8) + else if (std::abs(data.Time() - 0.04) <= 1.e-8) max_dens = 2.312884e9; - else if (fabs(data.Time() - 0.05) <= 1.e-8) + else if (std::abs(data.Time() - 0.05) <= 1.e-8) max_dens = 4.779133e9; - else if (fabs(data.Time() - 0.06) <= 1.e-8) + else if (std::abs(data.Time() - 0.06) <= 1.e-8) max_dens = 24.472425e9; - else if (fabs(data.Time() - 0.065) <= 1.e-8) + else if (std::abs(data.Time() - 0.065) <= 1.e-8) max_dens = 423.447291e9; else { Print() << "Dont know the maximum density at this time: " << data.Time() < r, slicefile << std::setw(w) << r[i]; for (auto it=vars.begin(); it!=vars.end(); ++it) { - if(fabs((*it)[i]) < SMALL) (*it)[i] = 0.0; + if(std::abs((*it)[i]) < SMALL) (*it)[i] = 0.0; slicefile << std::setw(w) << (*it)[i]; } diff --git a/Diagnostics/Radiation/gaussian_pulse.cpp b/Diagnostics/Radiation/gaussian_pulse.cpp index b04020a567..570b0f637b 100644 --- a/Diagnostics/Radiation/gaussian_pulse.cpp +++ b/Diagnostics/Radiation/gaussian_pulse.cpp @@ -64,9 +64,9 @@ int main(int argc, char* argv[]) // compute the size of the radially-binned array -- we'll do it to // the furtherest corner of the domain - double x_maxdist = max(fabs(probhi[0] - xctr), fabs(problo[0] - xctr)); - double y_maxdist = max(fabs(probhi[1] - yctr), fabs(problo[1] - yctr)); - double maxdist = sqrt(x_maxdist*x_maxdist + y_maxdist*y_maxdist); + double x_maxdist = std::max(std::abs(probhi[0] - xctr), std::abs(problo[0] - xctr)); + double y_maxdist = std::max(std::abs(probhi[1] - yctr), std::abs(problo[1] - yctr)); + double maxdist = std::sqrt(x_maxdist*x_maxdist + y_maxdist*y_maxdist); double dx_fine = *(std::min_element(dx.begin(), dx.end())); @@ -102,7 +102,7 @@ int main(int argc, char* argv[]) // over levels, we will compare to the finest level index space to // determine if we've already output here int mask_size = domain.length().max(); - Vector imask(pow(mask_size, AMREX_SPACEDIM), 1); + Vector imask(std::pow(mask_size, AMREX_SPACEDIM), 1); // loop over the data, starting at the finest grid, and if we haven't // already stored data in that grid location (according to imask), diff --git a/Diagnostics/Radiation/lgt_frnt1d.cpp b/Diagnostics/Radiation/lgt_frnt1d.cpp index 55f61a5ffe..9b1743b3b4 100644 --- a/Diagnostics/Radiation/lgt_frnt1d.cpp +++ b/Diagnostics/Radiation/lgt_frnt1d.cpp @@ -53,7 +53,7 @@ int main(int argc, char* argv[]) // compute the size of the radially-binned array -- we'll do it to // the furtherest corner of the domain - double maxdist = fabs(probhi[0] - problo[0]); + double maxdist = std::abs(probhi[0] - problo[0]); double dx_fine = *(std::min_element(dx.begin(), dx.end())); int nbins = int(maxdist / dx_fine); @@ -93,7 +93,7 @@ int main(int argc, char* argv[]) // over levels, we will compare to the finest level index space to // determine if we've already output here int mask_size = domain.length().max(); - Vector imask(pow(mask_size, AMREX_SPACEDIM), 1); + Vector imask(std::pow(mask_size, AMREX_SPACEDIM), 1); // loop over the data, starting at the finest grid, and if we haven't // already stored data in that grid location (according to imask), diff --git a/Diagnostics/Radiation/rad_shock.cpp b/Diagnostics/Radiation/rad_shock.cpp index 43176c4e27..3fbfcab5d8 100644 --- a/Diagnostics/Radiation/rad_shock.cpp +++ b/Diagnostics/Radiation/rad_shock.cpp @@ -106,7 +106,7 @@ int main(int argc, char* argv[]) // over levels, we will compare to the finest level index space to // determine if we've already output here int mask_size = domain.length().max(); - Vector imask(pow(mask_size, AMREX_SPACEDIM), 1); + Vector imask(std::pow(mask_size, AMREX_SPACEDIM), 1); // counter auto cnt = 0; @@ -214,7 +214,7 @@ int main(int argc, char* argv[]) slicefile << std::setw(w) << vars_bin[isv[i]+((*it)+1)*nbins]; auto it = comps.end()-1; - slicefile << std::setw(w) << pow(vars_bin[isv[i]+((*it)+1)*nbins] / arad, 0.25); + slicefile << std::setw(w) << std::pow(vars_bin[isv[i]+((*it)+1)*nbins] / arad, 0.25); slicefile << std::endl; } diff --git a/Diagnostics/Radiation/rad_sphere.cpp b/Diagnostics/Radiation/rad_sphere.cpp index 8eda551489..55bc63695d 100644 --- a/Diagnostics/Radiation/rad_sphere.cpp +++ b/Diagnostics/Radiation/rad_sphere.cpp @@ -142,7 +142,7 @@ int main(int argc, char* argv[]) // over levels, we will compare to the finest level index space to // determine if we've already output here int mask_size = domain.length()[0]; - Vector imask(pow(mask_size, AMREX_SPACEDIM), 1); + Vector imask(std::pow(mask_size, AMREX_SPACEDIM), 1); // counter int cnt = 0; diff --git a/Diagnostics/Sedov/main.cpp b/Diagnostics/Sedov/main.cpp index f6153d6bc0..4a32f24b6b 100644 --- a/Diagnostics/Sedov/main.cpp +++ b/Diagnostics/Sedov/main.cpp @@ -148,7 +148,7 @@ int main(int argc, char* argv[]) #else double x_maxdist = amrex::max(std::abs(probhi[0] - xctr), - std::fabs(problo[0] - xctr)); + std::abs(problo[0] - xctr)); double y_maxdist = amrex::max(std::abs(probhi[1] - yctr), std::abs(problo[1] - yctr)); double z_maxdist = amrex::max(std::abs(probhi[2] - zctr), @@ -342,10 +342,10 @@ int main(int argc, char* argv[]) // write the data in columns const auto SMALL = 1.e-20; for (auto i = 0; i < nbins; i++) { - if (fabs(dens_bin[i]) < SMALL) dens_bin[i] = 0.0; - if (fabs( vel_bin[i]) < SMALL) vel_bin[i] = 0.0; - if (fabs(pres_bin[i]) < SMALL) pres_bin[i] = 0.0; - if (fabs( e_bin[i]) < SMALL) e_bin[i] = 0.0; + if (std::abs(dens_bin[i]) < SMALL) dens_bin[i] = 0.0; + if (std::abs( vel_bin[i]) < SMALL) vel_bin[i] = 0.0; + if (std::abs(pres_bin[i]) < SMALL) pres_bin[i] = 0.0; + if (std::abs( e_bin[i]) < SMALL) e_bin[i] = 0.0; slicefile << std::setw(w) << r[i] << std::setw(w) << dens_bin[i] << std::setw(w) << vel_bin[i] << std::setw(w) << pres_bin[i] << std::setw(w) << e_bin[i] << std::endl; } diff --git a/Exec/science/nova/problem_initialize_state_data.H b/Exec/science/nova/problem_initialize_state_data.H index 37a7bb3894..4dea3d43eb 100644 --- a/Exec/science/nova/problem_initialize_state_data.H +++ b/Exec/science/nova/problem_initialize_state_data.H @@ -121,10 +121,10 @@ void problem_initialize_state_data (int i, int j, int k, if (problem::num_vortices % 2 == 0){ temp_pert = delta * (1.0_rt + std::sin(static_cast(problem::num_vortices)*M_PI*x/problem::L) )* - delta*exp(-pow(ydist / problem::width, 2)); + delta*std::exp(-pow(ydist / problem::width, 2)); } else { temp_pert = delta * (1.0_rt + std::cos(static_cast(problem::num_vortices)*M_PI*x/problem::L) )* - delta*exp(-pow(ydist / problem::width, 2)); + delta*std::exp(-pow(ydist / problem::width, 2)); } state(i,j,k,UTEMP) = state(i,j,k, UTEMP)*(1.0_rt + temp_pert); diff --git a/Exec/science/planet/HotJupiter.cpp b/Exec/science/planet/HotJupiter.cpp index 108db17923..059b255df5 100644 --- a/Exec/science/planet/HotJupiter.cpp +++ b/Exec/science/planet/HotJupiter.cpp @@ -19,10 +19,10 @@ long double Temp(long double P1,long double Pc,long double P_char,long double T_ long double Temp; if(Pc>P1){ - Temp = Td * pow(1.0e0 + (Lad / (Lin - Lad))*pow((P1/Pc),exp1),exp2); + Temp = Td * std::pow(1.0e0 + (Lad / (Lin - Lad)) * std::pow((P1/Pc),exp1),exp2); } else{ - Temp = T_char * pow(P1/P_char,Lad); + Temp = T_char * std::pow(P1/P_char,Lad); } return Temp; } @@ -95,9 +95,9 @@ int main(){ //Defining the properties of the planet atmosphere // the density limit at the top of the atmosphere P_top=den_top*R*Td ; // the pressure limit at the density limit - Tc = Td * pow(Lin/(Lin-Lad),exp2); //the temperature at the radiative-convective boundary (RCB) - Pc = P_char * pow(Tc/T_char,1.0/Lad); //the pressure at the RCB - Pd = pow((Lin-Lad)/(2.0*Lin-Lad),1.0/exp1)*Pc; //the characteristic pressure defining the radiative zone + Tc = Td * std::pow(Lin/(Lin-Lad),exp2); //the temperature at the radiative-convective boundary (RCB) + Pc = P_char * std::pow(Tc/T_char,1.0/Lad); //the pressure at the RCB + Pd = std::pow((Lin-Lad)/(2.0*Lin-Lad),1.0/exp1)*Pc; //the characteristic pressure defining the radiative zone @@ -112,7 +112,7 @@ int main(){ } buffer_height=z_top*2.25/4.0; // the height at which the buffer and the top of the atmosphere meet (not continuous at RCB).-> needs sponge - optical_depth_buffer=6.35e-3*T_buffer*pow(den_buffer,2.0)*(z_top-buffer_height);// the optical depth in the buffer region [dimensionless] + optical_depth_buffer=6.35e-3*T_buffer*std::pow(den_buffer,2.0)*(z_top-buffer_height);// the optical depth in the buffer region [dimensionless] @@ -157,14 +157,14 @@ int main(){ den2 = density(P2, T2, R); T3 = T1; den3 = den1; - dz2 = abs ((-P1+P2)* (1.0/grav)/((1.0/2.0)*(den1+den2))); - dz3 = abs ((-P1+P3)* (1.0/grav)/((1.0/2.0)*(den1+den3))); + dz2 = std::abs ((-P1+P2)* (1.0/grav)/((1.0/2.0)*(den1+den2))); + dz3 = std::abs ((-P1+P3)* (1.0/grav)/((1.0/2.0)*(den1+den3))); a: if(difference(dz2, delta_z)*difference(dz3, delta_z)<0.0){ P_sol = (P2+P3)/2.0; T_sol = Temp(P_sol, Pc, P_char, T_char, Td, Lin, Lad, exp1, exp2); den_sol = density(P_sol,T_sol, R); - dz_sol = abs ((-P1+P_sol)* (1.0/grav)/((1.0/2.0)*(den1+den_sol))); + dz_sol = std::abs ((-P1+P_sol)* (1.0/grav)/((1.0/2.0)*(den1+den_sol))); count2++; } else{ @@ -172,13 +172,13 @@ int main(){ P3 = P3 - P3/dP_factor/1.0; T3 = Temp(P3, Pc, P_char, T_char, Td, Lin, Lad, exp1, exp2); den3 = density(P3, T3, R); - dz3 = abs ((-P1+P3)* (1.0/grav)/((1.0/2.0)*(den1+den3))); + dz3 = std::abs ((-P1+P3)* (1.0/grav)/((1.0/2.0)*(den1+den3))); } else if(difference(dz2, delta_z)<0.0){ P2 = P2 + P2/dP_factor/1.0; T2 = Temp(P2, Pc, P_char, T_char, Td, Lin, Lad, exp1, exp2); den2 = density(P2,T2,R); - dz2 = abs ((-P1+P2)* (1.0/grav)/((1.0/2.0)*(den1+den2))); + dz2 = std::abs ((-P1+P2)* (1.0/grav)/((1.0/2.0)*(den1+den2))); } goto a; } @@ -192,11 +192,11 @@ int main(){ if(count2>100000){ goto b; } - if(abs(difference(dz_sol, delta_z)) >= error_expected){ + if(std::abs(difference(dz_sol, delta_z)) >= error_expected){ goto a; } - b: cout< SMALL*dx[0]) || (fabs(dx[0] - dx[2]) > SMALL*dx[0]) ) + if ( (std::abs(dx[0] - dx[1]) > SMALL*dx[0]) || (std::abs(dx[0] - dx[2]) > SMALL*dx[0]) ) { amrex::Abort("We don't support dx != dy != dz"); } @@ -4215,12 +4215,12 @@ Castro::get_numpts () #elif (AMREX_SPACEDIM == 2) long ny = bx.size()[1]; Real ndiagsq = Real(nx*nx + ny*ny); - numpts_1d = int(sqrt(ndiagsq))+2*NUM_GROW; + numpts_1d = int(std::sqrt(ndiagsq))+2*NUM_GROW; #elif (AMREX_SPACEDIM == 3) long ny = bx.size()[1]; long nz = bx.size()[2]; Real ndiagsq = Real(nx*nx + ny*ny + nz*nz); - numpts_1d = int(sqrt(ndiagsq))+2*NUM_GROW; + numpts_1d = int(std::sqrt(ndiagsq))+2*NUM_GROW; #endif if (verbose && ParallelDescriptor::IOProcessor()) { diff --git a/Source/radiation/HypreABec.cpp b/Source/radiation/HypreABec.cpp index 638d4715bb..6461c2ff2f 100644 --- a/Source/radiation/HypreABec.cpp +++ b/Source/radiation/HypreABec.cpp @@ -1779,7 +1779,7 @@ void HypreABec::solve(MultiFab& dest, int icomp, MultiFab& rhs, BC_Mode inhom) Real bnorm; bnorm = hypre_StructInnerProd((hypre_StructVector *) b, (hypre_StructVector *) b); - bnorm = sqrt(bnorm); + bnorm = std::sqrt(bnorm); const BoxArray& grids = acoefs->boxArray(); Real volume = 0.0; @@ -1788,7 +1788,7 @@ void HypreABec::solve(MultiFab& dest, int icomp, MultiFab& rhs, BC_Mode inhom) } Real reltol_new = (bnorm > 0.0 - ? abstol / bnorm * sqrt(volume) + ? abstol / bnorm * std::sqrt(volume) : reltol); if (reltol_new > reltol) { @@ -1898,7 +1898,7 @@ Real HypreABec::getAbsoluteResidual() Real bnorm; bnorm = hypre_StructInnerProd((hypre_StructVector *) b, (hypre_StructVector *) b); - bnorm = sqrt(bnorm); + bnorm = std::sqrt(bnorm); Real res; if (solver_flag == 0) { @@ -1925,5 +1925,5 @@ Real HypreABec::getAbsoluteResidual() volume += grids[i].numPts(); } - return bnorm * res / sqrt(volume); + return bnorm * res / std::sqrt(volume); } diff --git a/Source/radiation/HypreMultiABec.cpp b/Source/radiation/HypreMultiABec.cpp index 311c78c0a4..5f5e749255 100644 --- a/Source/radiation/HypreMultiABec.cpp +++ b/Source/radiation/HypreMultiABec.cpp @@ -3476,7 +3476,7 @@ void HypreMultiABec::solve() hypre_SStructInnerProd((hypre_SStructVector *) b, (hypre_SStructVector *) b, &bnorm); - bnorm = sqrt(bnorm); + bnorm = std::sqrt(bnorm); Real volume = 0.0; for (int level = crse_level; level <= fine_level; level++) { @@ -3486,7 +3486,7 @@ void HypreMultiABec::solve() } Real reltol_new = (bnorm > 0.0 - ? abstol / bnorm * sqrt(volume) + ? abstol / bnorm * std::sqrt(volume) : reltol); if (reltol_new > reltol) { @@ -3830,7 +3830,7 @@ Real HypreMultiABec::getAbsoluteResidual() hypre_SStructInnerProd((hypre_SStructVector *) b, (hypre_SStructVector *) b, &bnorm); - bnorm = sqrt(bnorm); + bnorm = std::sqrt(bnorm); Real res; if (solver_flag == 100) { @@ -3891,7 +3891,7 @@ Real HypreMultiABec::getAbsoluteResidual() } } - return bnorm * res / sqrt(volume); + return bnorm * res / std::sqrt(volume); } void HypreMultiABec::boundaryFlux(int level, diff --git a/Source/radiation/RadMultiGroup.cpp b/Source/radiation/RadMultiGroup.cpp index 83a1811ffc..4a8e682d78 100644 --- a/Source/radiation/RadMultiGroup.cpp +++ b/Source/radiation/RadMultiGroup.cpp @@ -43,37 +43,37 @@ void Radiation::get_groups(int verbose) if (lowest == 0.0) { nugroup[0] = 0.5*dnugroup[0]; - dlognugroup[0] = 2.0 * (log(xnu[1]) - log(nugroup[0])); + dlognugroup[0] = 2.0 * (std::log(xnu[1]) - std::log(nugroup[0])); } else { - nugroup[0] = sqrt(xnu[0]*xnu[1]); - dlognugroup[0] = log(xnu[1]) - log(xnu[0]); + nugroup[0] = std::sqrt(xnu[0]*xnu[1]); + dlognugroup[0] = std::log(xnu[1]) - std::log(xnu[0]); } for (int i=1; i tmplen) { + if (std::pow(mxlen,(float)AMREX_SPACEDIM-1) > tmplen) { delete [] derives; #if (AMREX_SPACEDIM == 1) derives = new Real[1]; diff --git a/Source/scf/scf_relax.cpp b/Source/scf/scf_relax.cpp index 1add2074e3..ec55704406 100644 --- a/Source/scf/scf_relax.cpp +++ b/Source/scf/scf_relax.cpp @@ -338,7 +338,7 @@ Castro::do_hscf_solve() amrex::Error(); } - Real omega = sqrt(omegasq); + Real omega = std::sqrt(omegasq); // Rotational period is 2 pi / omega. // Let's also be sure not to let the period