Changeset 6778
- Timestamp:
- Apr 9, 2009, 8:42:12 AM (16 years ago)
- Location:
- anuga_core/source/anuga
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
anuga_core/source/anuga/shallow_water/shallow_water_ext.c
r6737 r6778 190 190 } 191 191 192 193 // Optimised squareroot computation 194 // 195 //See 196 //http://www.lomont.org/Math/Papers/2003/InvSqrt.pdf 197 //and http://mail.opensolaris.org/pipermail/tools-gcc/2005-August/000047.html 198 float fast_squareroot_approximation(float number) { 199 float x; 200 const float f = 1.5; 201 202 // Allow i and y to occupy the same memory 203 union 204 { 205 long i; 206 float y; 207 } u; 208 209 // Good initial guess 210 x = number * 0.5; 211 u.y = number; 212 u.i = 0x5f3759df - ( u.i >> 1 ); 213 214 // Take a few iterations 215 u.y = u.y * ( f - ( x * u.y * u.y ) ); 216 u.y = u.y * ( f - ( x * u.y * u.y ) ); 217 218 return number * u.y; 219 } 220 221 222 223 // Optimised squareroot computation (double version, slower) 224 double Xfast_squareroot_approximation(double number) { 225 double x; 226 const double f = 1.5; 227 228 // Allow i and y to occupy the same memory 229 union 230 { 231 long long i; 232 double y; 233 } u; 234 235 // Good initial guess 236 x = number * 0.5; 237 u.y = number; 238 u.i = 0x5fe6ec85e7de30daLL - ( u.i >> 1 ); 239 240 // Take a few iterations 241 u.y = u.y * ( f - ( x * u.y * u.y ) ); 242 u.y = u.y * ( f - ( x * u.y * u.y ) ); 243 244 return number * u.y; 245 } 246 247 192 248 // Innermost flux function (using stage w=z+h) 193 249 int _flux_function_central(double *q_left, double *q_right, … … 262 318 // Maximal and minimal wave speeds 263 319 soundspeed_left = sqrt(g*h_left); 264 soundspeed_right = sqrt(g*h_right); 320 soundspeed_right = sqrt(g*h_right); 321 322 // Code to use fast square root optimisation if desired. 323 //soundspeed_left = fast_squareroot_approximation(g*h_left); 324 //soundspeed_right = fast_squareroot_approximation(g*h_right); 265 325 266 326 s_max = max(u_left + soundspeed_left, u_right + soundspeed_right); -
anuga_core/source/anuga/utilities/compile.py
r6057 r6778 258 258 %(compiler, FN, python_include, utilities_include_dir, root) 259 259 elif FN == "polygon_ext.c": 260 # gcc 4.3.x screws up inthis file if '-O3' is used260 # gcc 4.3.x is problematic with this file if '-O3' is used 261 261 s = '%s -c %s -I"%s" -I"%s" -o "%s.o" -Wall'\ 262 262 %(compiler, FN, python_include, utilities_include_dir, root)
Note: See TracChangeset
for help on using the changeset viewer.