Skip to content

Commit c8475b3

Browse files
authored
Merge pull request #6055 from gassmoeller/avoid_pow
Replace std::pow where possible
2 parents 532b6aa + 7e39162 commit c8475b3

File tree

59 files changed

+434
-403
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

59 files changed

+434
-403
lines changed

benchmarks/burstedde/burstedde.cc

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -360,20 +360,20 @@ namespace aspect
360360

361361
Tensor<1,dim> g;
362362

363-
g[0]=((y*z+3.*std::pow(x,2)*std::pow(y,3)*z)- mu*(2.+6.*x*y))
364-
-dmudx*(2.+4.*x+2.*y+6.*std::pow(x,2)*y)
365-
-dmudy*(x+std::pow(x,3)+y+2.*x*std::pow(y,2))
363+
g[0]=((y*z+3.*Utilities::fixed_power<2>(x)*Utilities::fixed_power<3>(y)*z)- mu*(2.+6.*x*y))
364+
-dmudx*(2.+4.*x+2.*y+6.*Utilities::fixed_power<2>(x)*y)
365+
-dmudy*(x+Utilities::fixed_power<3>(x)+y+2.*x*Utilities::fixed_power<2>(y))
366366
-dmudz*(-3.*z-10.*x*y*z);
367367

368-
g[1]=((x*z+3.*std::pow(x,3)*std::pow(y,2)*z)- mu*(2.+2.*std::pow(x,2)+2.*std::pow(y,2)))
369-
-dmudx*(x+std::pow(x,3)+y+2.*x*std::pow(y,2))
370-
-dmudy*(2.+2.*x+4.*y+4.*std::pow(x,2)*y)
371-
-dmudz*(-3.*z-5.*std::pow(x,2)*z);
368+
g[1]=((x*z+3.*Utilities::fixed_power<3>(x)*Utilities::fixed_power<2>(y)*z)- mu*(2.+2.*Utilities::fixed_power<2>(x)+2.*Utilities::fixed_power<2>(y)))
369+
-dmudx*(x+Utilities::fixed_power<3>(x)+y+2.*x*Utilities::fixed_power<2>(y))
370+
-dmudy*(2.+2.*x+4.*y+4.*Utilities::fixed_power<2>(x)*y)
371+
-dmudz*(-3.*z-5.*Utilities::fixed_power<2>(x)*z);
372372

373-
g[2]=((x*y+std::pow(x,3)*std::pow(y,3)) - mu*(-10.*y*z))
373+
g[2]=((x*y+Utilities::fixed_power<3>(x)*Utilities::fixed_power<3>(y)) - mu*(-10.*y*z))
374374
-dmudx*(-3.*z-10.*x*y*z)
375-
-dmudy*(-3.*z-5.*std::pow(x,2)*z)
376-
-dmudz*(-4.-6.*x-6.*y-10.*std::pow(x,2)*y);
375+
-dmudy*(-3.*z-5.*Utilities::fixed_power<2>(x)*z)
376+
-dmudz*(-4.-6.*x-6.*y-10.*Utilities::fixed_power<2>(x)*y);
377377

378378
return g;
379379
}

benchmarks/compressibility_formulations/plugins/compressibility_formulations.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -155,7 +155,7 @@ namespace aspect
155155
if (this->get_parameters().formulation_mass_conservation ==
156156
Parameters<dim>::Formulation::MassConservation::isentropic_compression)
157157
{
158-
out.compressibilities[i] = reference_compressibility - std::pow(thermal_expansivity, 2) * in.temperature[i]
158+
out.compressibilities[i] = reference_compressibility - Utilities::fixed_power<2>(thermal_expansivity) * in.temperature[i]
159159
/ (out.densities[i] * out.specific_heat[i]);
160160
}
161161
}

benchmarks/layeredflow/layeredflow.cc

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,10 +54,10 @@ namespace aspect
5454
- beta*std::log(beta*beta+pow(1.-y0,2.0))+2.*(1.-y0)*std::atan(yminus)
5555
+ 2.*numbers::PI*(1.+2.*epsilon) );
5656

57-
const double C2 = ( beta*std::log( beta*beta+std::pow(1+y0,2.) )- 2.*(1.+y0)*std::atan(yplus)
57+
const double C2 = ( beta*std::log( beta*beta+Utilities::fixed_power<2>(1+y0) )- 2.*(1.+y0)*std::atan(yplus)
5858
+ numbers::PI*(1.+2.*epsilon) )*C1 ;
5959
const double y = pos[1]-1.0;
60-
const double v_x = (-beta*C1*std::log(beta*beta+std::pow(y-y0,2.0))+2.*(y-y0)*C1*std::atan((y-y0)/beta)
60+
const double v_x = (-beta*C1*std::log(beta*beta+Utilities::fixed_power<2>(y-y0))+2.*(y-y0)*C1*std::atan((y-y0)/beta)
6161
+ numbers::PI*(1.+2.*epsilon)*y*C1+C2)/(2.*numbers::PI);
6262
const double v_y = 0;
6363
return Point<2> (v_x,v_y);

benchmarks/nsinker/nsinker.cc

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -292,7 +292,7 @@ namespace aspect
292292
{
293293
double dist = p.distance(Point<2>(centers[s](0), centers[s](1)));
294294
double temp = 1-std::exp(-delta*
295-
std::pow(std::max(0.0,dist-omega/2.0),2));
295+
Utilities::fixed_power<2>(std::max(0.0,dist-omega/2.0)));
296296
chi *= temp;
297297
}
298298
return chi;
@@ -310,7 +310,7 @@ namespace aspect
310310
{
311311
double dist = p.distance(centers[s]);
312312
double temp = 1-std::exp(-delta*
313-
std::pow(std::max(0.0,dist-omega/2.0),2));
313+
Utilities::fixed_power<2>(std::max(0.0,dist-omega/2.0)));
314314
chi *= temp;
315315
}
316316
return chi;

benchmarks/nsinker_spherical_shell/nsinker.cc

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -311,7 +311,7 @@ namespace aspect
311311
{
312312
double dist = p.distance(Point<2>(centers[s](0), centers[s](1)));
313313
double temp = 1-std::exp(-delta*
314-
std::pow(std::max(0.0,dist-omega/2.0),2));
314+
Utilities::fixed_power<2>(std::max(0.0,dist-omega/2.0)));
315315
chi *= temp;
316316
}
317317
return chi;
@@ -329,7 +329,7 @@ namespace aspect
329329
{
330330
double dist = p.distance(centers[s]);
331331
double temp = 1-std::exp(-delta*
332-
std::pow(std::max(0.0,dist-omega/2.0),2));
332+
Utilities::fixed_power<2>(std::max(0.0,dist-omega/2.0)));
333333
chi *= temp;
334334
}
335335
return chi;

benchmarks/solitary_wave/solitary_wave.cc

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -399,13 +399,13 @@ namespace aspect
399399

400400
double length_scaling (const double porosity) const
401401
{
402-
return std::sqrt(reference_permeability * std::pow(porosity,3) * (xi_0 + 4.0/3.0 * eta_0) / eta_f);
402+
return std::sqrt(reference_permeability * Utilities::fixed_power<3>(porosity) * (xi_0 + 4.0/3.0 * eta_0) / eta_f);
403403
}
404404

405405
double velocity_scaling (const double porosity) const
406406
{
407407
const Point<dim> surface_point = this->get_geometry_model().representative_point(0.0);
408-
return reference_permeability * std::pow(porosity,2) * (reference_rho_s - reference_rho_f)
408+
return reference_permeability * Utilities::fixed_power<2>(porosity) * (reference_rho_s - reference_rho_f)
409409
* this->get_gravity_model().gravity_vector(surface_point).norm() / eta_f;
410410
}
411411

@@ -451,7 +451,7 @@ namespace aspect
451451

452452
melt_out->compaction_viscosities[i] = xi_0 * (1.0 - porosity);
453453
melt_out->fluid_viscosities[i]= eta_f;
454-
melt_out->permeabilities[i]= reference_permeability * std::pow(porosity,3);
454+
melt_out->permeabilities[i]= reference_permeability * Utilities::fixed_power<3>(porosity);
455455
melt_out->fluid_densities[i]= reference_rho_f;
456456
melt_out->fluid_density_gradients[i] = 0.0;
457457
}

benchmarks/solubility/plugin/solubility.cc

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -172,7 +172,7 @@ namespace aspect
172172
double porosity = std::max(in.composition[q][porosity_idx],0.0);
173173

174174
fluid_out->fluid_viscosities[q] = eta_f;
175-
fluid_out->permeabilities[q] = reference_permeability * std::pow(porosity,3) * std::pow(1.0-porosity,2);
175+
fluid_out->permeabilities[q] = reference_permeability * Utilities::fixed_power<3>(porosity) * Utilities::fixed_power<2>(1.0-porosity);
176176

177177
fluid_out->fluid_densities[q] = reference_rho_f * std::exp(fluid_compressibility * (in.pressure[q] - this->get_surface_pressure()));
178178

@@ -387,7 +387,7 @@ namespace aspect
387387
reference_darcy_coefficient () const
388388
{
389389
// 0.01 = 1% melt
390-
return reference_permeability * std::pow(0.01,3.0) / eta_f;
390+
return reference_permeability * Utilities::fixed_power<3>(0.01) / eta_f;
391391
}
392392

393393

benchmarks/yamauchi_takei_2016_anelasticity/anelasticity_temperature.cc

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -290,7 +290,7 @@ namespace aspect
290290
isothermal_volume_change=r2.first;
291291
compressibility=isothermal_volume_change*std::exp((gruneisen_parameter+1)*(std::pow(isothermal_volume_change,-1)-1));
292292
pressure_dependent_density=reference_density*isothermal_volume_change;
293-
integrated_thermal_expansivity=(2.832e-5*(temperature-273))+((0.758e-8/2)*(std::pow(temperature,2)-std::pow(273,2)));
293+
integrated_thermal_expansivity=(2.832e-5*(temperature-273))+((0.758e-8/2)*(Utilities::fixed_power<2>(temperature)-Utilities::fixed_power<2>(273)));
294294
density=pressure_dependent_density*(1-(compressibility*integrated_thermal_expansivity));
295295
}
296296
// determine J1 term (real part of complex compliance)
@@ -299,8 +299,8 @@ namespace aspect
299299
std::erf((std::log(peak_period/normalized_period))/(std::sqrt(2)*peak_width)))));
300300
// determine J2 term (imaginary part of complex compliance)
301301
//double loss_compliance=unrelaxed_compliance*(M_PI/2)*(background_amplitude*(std::pow(normalized_period,background_slope))+
302-
// (peak_amplitude*std::exp(-1*(std::pow(std::log(peak_period/normalized_period),2)/
303-
// (2*std::pow(peak_width,2))))))+(unrelaxed_compliance*normalized_period);
302+
// (peak_amplitude*std::exp(-1*(Utilities::fixed_power<2>(std::log(peak_period/normalized_period))/
303+
// (2*Utilities::fixed_power<2>(peak_width))))))+(unrelaxed_compliance*normalized_period);
304304
// calculate anharmonic Vs
305305
// anharmonic_Vs=1/(std::sqrt(density*unrelaxed_compliance)*1e3);
306306
// calculate Vs

cookbooks/inner_core_convection/inner_core_convection.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -175,7 +175,7 @@ namespace aspect
175175

176176
// The gravity is zero in the center of the Earth, and we assume the density to be constant and equal to 1.
177177
// We fix the surface pressure to 0 (and we are only interested in pressure differences anyway).
178-
return gravity_magnitude * 0.5 * (1.0 - std::pow(radius/max_radius,2));
178+
return gravity_magnitude * 0.5 * (1.0 - Utilities::fixed_power<2>(radius/max_radius));
179179
}
180180
else
181181
return hydrostatic_pressure_profile.value(Point<1>(radius));

cookbooks/morency_doin_2004/morency_doin.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ namespace aspect
7070
*/
7171
const double e2inv = std::sqrt((strain_rate[0][0]*strain_rate[0][0] + strain_rate[0][1]*strain_rate[0][1])/2.0);
7272

73-
const double edot = std::sqrt(std::pow(e2inv,2) + std::pow(min_strain_rate,2));
73+
const double edot = std::sqrt(Utilities::fixed_power<2>(e2inv) + Utilities::fixed_power<2>(min_strain_rate));
7474

7575
// Calculate 1/(v_eff^v) and 1/(v_eff^p)
7676
double one_over_veffv = 0.0;

0 commit comments

Comments
 (0)