Skip to content

Commit

Permalink
use std:: for some math functions
Browse files Browse the repository at this point in the history
  • Loading branch information
zingale committed Jan 26, 2024
1 parent 8f66f04 commit 8ea151b
Show file tree
Hide file tree
Showing 15 changed files with 57 additions and 57 deletions.
12 changes: 6 additions & 6 deletions Diagnostics/DustCollapse/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -105,15 +105,15 @@ int main(int argc, char* argv[])
auto x_maxdist = fmax(fabs(problo[0]), fabs(probhi[0]));
auto y_maxdist = fmax(fabs(problo[1] - yctr), fabs(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);
Expand Down Expand Up @@ -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<int> imask(pow(mask_size, AMREX_SPACEDIM), 1);
Vector<int> imask(std::pow(mask_size, AMREX_SPACEDIM), 1);

// counter
int cnt = 0;
Expand Down
8 changes: 4 additions & 4 deletions Diagnostics/Radiation/gaussian_pulse.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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()));

Expand Down Expand Up @@ -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<int> imask(pow(mask_size, AMREX_SPACEDIM), 1);
Vector<int> 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),
Expand Down
2 changes: 1 addition & 1 deletion Diagnostics/Radiation/lgt_frnt1d.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<int> imask(pow(mask_size, AMREX_SPACEDIM), 1);
Vector<int> 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),
Expand Down
4 changes: 2 additions & 2 deletions Diagnostics/Radiation/rad_shock.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<int> imask(pow(mask_size, AMREX_SPACEDIM), 1);
Vector<int> imask(std::pow(mask_size, AMREX_SPACEDIM), 1);

// counter
auto cnt = 0;
Expand Down Expand Up @@ -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;
}
Expand Down
2 changes: 1 addition & 1 deletion Diagnostics/Radiation/rad_sphere.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<int> imask(pow(mask_size, AMREX_SPACEDIM), 1);
Vector<int> imask(std::pow(mask_size, AMREX_SPACEDIM), 1);

// counter
int cnt = 0;
Expand Down
4 changes: 2 additions & 2 deletions Exec/science/nova/problem_initialize_state_data.H
Original file line number Diff line number Diff line change
Expand Up @@ -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<Real>(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<Real>(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);
Expand Down
30 changes: 15 additions & 15 deletions Exec/science/planet/HotJupiter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down Expand Up @@ -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



Expand All @@ -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]



Expand Down Expand Up @@ -157,28 +157,28 @@ 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{
if(difference(dz2, delta_z)>0.0){
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;
}
Expand All @@ -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<<count_cell<<' ' <<setprecision(5) << "Final value, "<<' '<<"height[km]="<< ' '<< z/1.e5<<' ' <<"pressure[bar]=" <<' ' << P_sol/1.e6 <<' '<< "error="<<' ' << abs(difference(dz_sol, delta_z))<<' ' << abs ((-P1+P_sol)/dz_sol+ grav*((1.0/2.0)*(den1+den_sol))) << '\n';
b: cout<<count_cell<<' ' <<setprecision(5) << "Final value, "<<' '<<"height[km]="<< ' '<< z/1.e5<<' ' <<"pressure[bar]=" <<' ' << P_sol/1.e6 <<' '<< "error="<<' ' << std::abs(difference(dz_sol, delta_z))<<' ' << std::abs ((-P1+P_sol)/dz_sol+ grav*((1.0/2.0)*(den1+den_sol))) << '\n';
T[count] = T_sol;
P[count] = P_sol;
den[count] = den_sol;
Expand All @@ -207,9 +207,9 @@ int main(){
P1 = P_sol;
count_cell++;
if(P_sol < Pc){
optical_depth_radiative = optical_depth_radiative+kappa0*pow(den_sol,2.0)*T_sol*delta_z;
optical_depth_radiative = optical_depth_radiative+kappa0*std::pow(den_sol,2.0)*T_sol*delta_z;
}
optical_depth_atm = optical_depth_atm+kappa0*pow(den_sol,2.0)*T_sol*delta_z;
optical_depth_atm = optical_depth_atm+kappa0*std::pow(den_sol,2.0)*T_sol*delta_z;
if(optical_depth_atm+optical_depth_buffer>=1.0 && P_at_1opticaldepth==0.0 ){
P_at_1opticaldepth=P_sol;
T_at_1opticaldepth=T_sol;
Expand Down
6 changes: 3 additions & 3 deletions Exec/science/wdmerger/Prob.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -252,7 +252,7 @@ Castro::wd_update (Real time, Real dt)
bool local_flag = true;

for (int i = 0; i <= 6; ++i) {
Castro::volInBoundary(time, vol_P[i], vol_S[i], pow(10.0,i), local_flag);
Castro::volInBoundary(time, vol_P[i], vol_S[i], std::pow(10.0,i), local_flag);
}

// Do all of the reductions.
Expand Down Expand Up @@ -355,12 +355,12 @@ Castro::wd_update (Real time, Real dt)

if (mass_P > 0.0 && vol_P[2] > 0.0) {
rho_avg_P = mass_P / vol_P[2];
t_ff_P = sqrt(3.0 * M_PI / (32.0 * C::Gconst * rho_avg_P));
t_ff_P = std::sqrt(3.0 * M_PI / (32.0 * C::Gconst * rho_avg_P));
}

if (mass_S > 0.0 && vol_S[2] > 0.0) {
rho_avg_S = mass_S / vol_S[2];
t_ff_S = sqrt(3.0 * M_PI / (32.0 * C::Gconst * rho_avg_S));
t_ff_S = std::sqrt(3.0 * M_PI / (32.0 * C::Gconst * rho_avg_S));
}

// Compute updated roche Radii
Expand Down
2 changes: 1 addition & 1 deletion Exec/unit_tests/particles_test/Prob.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ void Castro::problem_post_simulation(Vector<std::unique_ptr<AmrLevel> >& amr_lev
auto deltax = it->m_pos[0] - p.m_pos[0];
auto deltay = it->m_pos[1] - p.m_pos[1];

auto delta = sqrt(deltax*deltax + deltay*deltay);
auto delta = std::sqrt(deltax*deltax + deltay*deltay);

// quick nan check here
if (delta == delta)
Expand Down
4 changes: 2 additions & 2 deletions Source/driver/Castro.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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()) {
Expand Down
8 changes: 4 additions & 4 deletions Source/radiation/HypreABec.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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) {
Expand Down Expand Up @@ -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) {
Expand All @@ -1925,5 +1925,5 @@ Real HypreABec::getAbsoluteResidual()
volume += grids[i].numPts();
}

return bnorm * res / sqrt(volume);
return bnorm * res / std::sqrt(volume);
}
8 changes: 4 additions & 4 deletions Source/radiation/HypreMultiABec.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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++) {
Expand All @@ -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) {
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -3891,7 +3891,7 @@ Real HypreMultiABec::getAbsoluteResidual()
}
}

return bnorm * res / sqrt(volume);
return bnorm * res / std::sqrt(volume);
}

void HypreMultiABec::boundaryFlux(int level,
Expand Down
20 changes: 10 additions & 10 deletions Source/radiation/RadMultiGroup.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<nGroups; i++) {
dnugroup[i] = dnugroup[i-1] * groupGrowFactor;
xnu[i+1] = xnu[i] + dnugroup[i];
nugroup[i] = sqrt(xnu[i]*xnu[i+1]);
dlognugroup[i] = log(xnu[i+1]) - log(xnu[i]);
nugroup[i] = std::sqrt(xnu[i]*xnu[i+1]);
dlognugroup[i] = std::log(xnu[i+1]) - std::log(xnu[i]);
}
}
else {
Real highest;
pp.get("highestGroupHz", highest);

Real loglowest = log10(lowest);
Real loghighest = log10(highest);
Real loglowest = std::log10(lowest);
Real loghighest = std::log10(highest);
Real dlognu = (loghighest - loglowest) / Real(nGroups);

for (int i=0; i<nGroups; i++) {
xnu[i] = pow(10.0, loglowest+i*dlognu);
nugroup[i] = pow(10.0, loglowest+(i+0.5)*dlognu);
xnu[i] = std::pow(10.0, loglowest+i*dlognu);
nugroup[i] = std::pow(10.0, loglowest+(i+0.5)*dlognu);
}
xnu[nGroups] = highest;

for (int i=0; i<nGroups; i++) {
dnugroup[i] = xnu[i+1] - xnu[i];
dlognugroup[i] = log(xnu[i+1]) - log(xnu[i]);
dlognugroup[i] = std::log(xnu[i+1]) - std::log(xnu[i]);
}
}

Expand Down
2 changes: 1 addition & 1 deletion Source/radiation/_interpbndry/RadInterpBndryData.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ RadInterpBndryData::setBndryValues(BndryRegister& crse, int c_start,
auto cblo = crse_bx.loVect3d();
auto cbhi = crse_bx.hiVect3d();
int mxlen = crse_bx.longside() + 2;
if (pow(mxlen,(float)AMREX_SPACEDIM-1) > tmplen) {
if (std::pow(mxlen,(float)AMREX_SPACEDIM-1) > tmplen) {
delete [] derives;
#if (AMREX_SPACEDIM == 1)
derives = new Real[1];
Expand Down
2 changes: 1 addition & 1 deletion Source/scf/scf_relax.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 8ea151b

Please sign in to comment.