Commit a88dbf1ecbd3b8b2dc65d289b176547d31ca1c68
1 parent
88605249
Exists in
master
and in
61 other branches
9719 ok
Showing
2 changed files
with
122 additions
and
28 deletions
Show diff stats
src/Parameters/DataTypeMath.hh
@@ -317,7 +317,7 @@ Type1 alfvenVelocity(Type1 density, Type2 mag) { | @@ -317,7 +317,7 @@ Type1 alfvenVelocity(Type1 density, Type2 mag) { | ||
317 | if (density <= 0) { | 317 | if (density <= 0) { |
318 | val << NotANumber(); | 318 | val << NotANumber(); |
319 | } else { | 319 | } else { |
320 | - val = 21.83 *mag / std::sqrt(density); | 320 | + val = 21.83 * mag / std::sqrt(density); |
321 | } | 321 | } |
322 | return val; | 322 | return val; |
323 | } | 323 | } |
@@ -342,8 +342,8 @@ Type1 fairfield70(Type1 y_sm, Type2 z_sm,Type3 x_ss) { | @@ -342,8 +342,8 @@ Type1 fairfield70(Type1 y_sm, Type2 z_sm,Type3 x_ss) { | ||
342 | * @return delta Z | 342 | * @return delta Z |
343 | */ | 343 | */ |
344 | template <typename Type1, typename Type2> | 344 | template <typename Type1, typename Type2> |
345 | -Type1 fairfield70(std::vector<Type1> xyz_sm, Type2 x_ss) { | ||
346 | - Type1 val = xyz_sm[2]-std::sqrt(121.0 - 0.537778 * pow(xyz_sm[1], 2.0)) * std::sin(x_ss*DEG2RAD); | 345 | +Type1 fairfield70(std::vector<Type1> xyz_sm, Type2 x_ss) { |
346 | + Type1 val = xyz_sm[2] - std::sqrt(121.0 - 0.537778 * pow(xyz_sm[1], 2.0)) * std::sin(x_ss * DEG2RAD); | ||
347 | return val; | 347 | return val; |
348 | } | 348 | } |
349 | 349 | ||
@@ -354,8 +354,8 @@ Type1 fairfield70(std::vector<Type1> xyz_sm, Type2 x_ss) { | @@ -354,8 +354,8 @@ Type1 fairfield70(std::vector<Type1> xyz_sm, Type2 x_ss) { | ||
354 | * @return delta Z | 354 | * @return delta Z |
355 | */ | 355 | */ |
356 | template <typename Type1, typename Type2> | 356 | template <typename Type1, typename Type2> |
357 | -Type1 fairfield80(std::vector<Type1> xyz_sm, Type2 x_ss) { | ||
358 | - Type1 val = xyz_sm[2]-10.5*std::sqrt(1.0-pow(xyz_sm[1], 2.0)/289.0)* std::sin(x_ss * DEG2RAD); | 357 | +Type1 fairfield80(std::vector<Type1> xyz_sm, Type2 x_ss) { |
358 | + Type1 val = xyz_sm[2] - 10.5 * std::sqrt(1.0 - pow(xyz_sm[1], 2.0) / 289.0) * std::sin(x_ss * DEG2RAD); | ||
359 | return val; | 359 | return val; |
360 | } | 360 | } |
361 | 361 | ||
@@ -370,8 +370,8 @@ Type1 fairfield80(std::vector<Type1> xyz_sm, Type2 x_ss) { | @@ -370,8 +370,8 @@ Type1 fairfield80(std::vector<Type1> xyz_sm, Type2 x_ss) { | ||
370 | * denotes the latitudinal angle of the IMF vector measured from the solar equatorial plane. | 370 | * denotes the latitudinal angle of the IMF vector measured from the solar equatorial plane. |
371 | */ | 371 | */ |
372 | template <typename Type1, typename Type2, typename Type3> | 372 | template <typename Type1, typename Type2, typename Type3> |
373 | -Type1 perreault78(Type1 E_mag, Type2 B_mag,Type3 theta_p) { | ||
374 | - Type1 val = E_mag*B_mag/(4*std::atan(1)*4)*std::pow((7*RE*std::pow(sin(theta_p/2),2)),2); | 373 | +Type1 perreault78(Type1 E_mag, Type2 B_mag, Type3 theta_p) { |
374 | + Type1 val = E_mag * B_mag / (4 * std::atan(1)*4) * std::pow((7 * RE * std::pow(sin(theta_p / 2), 2)), 2); | ||
375 | return val; | 375 | return val; |
376 | } | 376 | } |
377 | 377 | ||
@@ -383,11 +383,11 @@ Type1 perreault78(Type1 E_mag, Type2 B_mag,Type3 theta_p) { | @@ -383,11 +383,11 @@ Type1 perreault78(Type1 E_mag, Type2 B_mag,Type3 theta_p) { | ||
383 | * theta IMF clock angle arctan(By/Bz) | 383 | * theta IMF clock angle arctan(By/Bz) |
384 | */ | 384 | */ |
385 | template <typename Type1, typename Type2> | 385 | template <typename Type1, typename Type2> |
386 | -Type1 newell2007(Type1 mu, std::vector<Type2> Bxyz) { | ||
387 | - Type2 B_mag = std::sqrt(Bxyz[0]*Bxyz[0] + Bxyz[1]*Bxyz[1] + Bxyz[2]*Bxyz[2]); | ||
388 | - Type2 theta = std::atan2(Bxyz[1]/Bxyz[2]); | ||
389 | - Type1 val = std::pow(mu , 4.0/3.0)*std::pow(B_mag , 2.0/3.0)*pow(std::sin(theta/2),8.0/3.0); | ||
390 | - return val; | 386 | +Type1 newell2007(Type1 mu, std::vector<Type2> Bxyz) { |
387 | + Type2 B_mag = std::sqrt(Bxyz[0] * Bxyz[0] + Bxyz[1] * Bxyz[1] + Bxyz[2] * Bxyz[2]); | ||
388 | + Type2 theta = std::atan2(Bxyz[1] / Bxyz[2]); | ||
389 | + Type1 val = std::pow(mu, 4.0 / 3.0) * std::pow(B_mag, 2.0 / 3.0) * pow(std::sin(theta / 2), 8.0 / 3.0); | ||
390 | + return val; | ||
391 | } | 391 | } |
392 | 392 | ||
393 | /** | 393 | /** |
@@ -398,12 +398,81 @@ Type1 newell2007(Type1 mu, std::vector<Type2> Bxyz) { | @@ -398,12 +398,81 @@ Type1 newell2007(Type1 mu, std::vector<Type2> Bxyz) { | ||
398 | * R is the radial distance in RE and DTA is the dipole tilt angle | 398 | * R is the radial distance in RE and DTA is the dipole tilt angle |
399 | */ | 399 | */ |
400 | template <typename Type1, typename Type2, typename Type3, typename Type4> | 400 | template <typename Type1, typename Type2, typename Type3, typename Type4> |
401 | -Type1 lopez90(Type1 Kp, Type2 phi,Type3 R, Type4 DTA) { | ||
402 | - Type1 val = -(0.14*Kp+0.69)*std::pow(phi, 0.3333)*(0.065*R-0.16)*DTA*DEG2RAD; | 401 | +Type1 lopez90(Type1 Kp, Type2 phi, Type3 R, Type4 DTA) { |
402 | + Type1 val = -(0.14 * Kp + 0.69) * std::pow(phi, 0.3333)*(0.065 * R - 0.16) * DTA*DEG2RAD; | ||
403 | return val; | 403 | return val; |
404 | } | 404 | } |
405 | 405 | ||
406 | +template <typename Type1, typename Type2> | ||
407 | +Type1 pv_ionos_te(Type1 alt, Type2 sza) { | ||
408 | + | ||
409 | + Type1 te; | ||
410 | + if (alt > 3000 || alt < 150) { | ||
411 | + te << NotANumber(); | ||
412 | + return te; | ||
413 | + } else { | ||
414 | + | ||
415 | + std::vector<double> pb; | ||
416 | + pb.resize(4); | ||
417 | + // 0 was added to fdsmodt in order to keep indexes as in fortran original source | ||
418 | + const std::vector< double> fdsmodt{0, | ||
419 | + 3.567296, 1.3836078e-02, 1.5086544e-02, 6.0729804e-03, 4.0306677e-03, | ||
420 | + -1.3217842e-02, 7.8089219e-03, -2775.023, -123.7310, 8.828382, | ||
421 | + -96.94563, 15.84634, 138.9812, -139.7511, -84.03277, | ||
422 | + 0.2649297, -1.444215, 0.6347786, -2.192531, -0.5396207, | ||
423 | + 0.6054179, 1.0569388e-04, -8.0908003e-06, 1.3877957e-05, -1.2327257e-05, | ||
424 | + -1.1256760e-05, 1.3830228e-05, -1.4350858e-05}; | ||
425 | + double s = std::sin(sza); | ||
426 | + double c = std::cos(sza); | ||
427 | + double s2 = std::sin(2 * sza); | ||
428 | + double c2 = std::cos(2 * sza); | ||
429 | + double s3 = std::sin(3 * sza); | ||
430 | + double c3 = std::cos(3 * sza); | ||
431 | + for (int j = 1; j < 5; j++) { | ||
432 | + int k = 7 * j; | ||
433 | + pb[j - 1] = fdsmodt[k - 6] + fdsmodt[k - 5] * s + fdsmodt[k - 4] * c + fdsmodt[k - 3] * s2 + fdsmodt[k - 2] * c2 + | ||
434 | + fdsmodt[k - 1] * s3 + fdsmodt[k] * c3; | ||
435 | + } | ||
436 | + te = (Type1) pb[0] + pb[1] / ((alt + pb[2])*(alt + pb[2])) + pb[3] * alt; | ||
437 | + return te; | ||
438 | + } | ||
439 | +} | ||
440 | + | ||
441 | +template <typename Type1, typename Type2> | ||
442 | +Type1 pv_ionos_dn(Type1 alt, Type2 sza) { | ||
406 | 443 | ||
444 | + Type1 dn; | ||
445 | + if (alt > 3000 || alt < 150) { | ||
446 | + dn << NotANumber(); | ||
447 | + return dn; | ||
448 | + } else { | ||
449 | + std::vector<double> bp; | ||
450 | + bp.resize(4); | ||
451 | + // 0 was added to fdsmodde in order to keep indexes as in fortran original source | ||
452 | + const std::vector<double> fdsmodde{0, | ||
453 | + 5.334022, 252.5587, 120.4444, 9.1163822E-02, -6.195264, | ||
454 | + 37.38898, 3.331818, 245.5529, 0.7587564, 0.1453792, | ||
455 | + -0.9461438, 127.1485, -0.3391595, 2.4936652E-02, 0.1879423, | ||
456 | + -5.3126566E-02, 2.9439656E-02, 1.654282, 415.7859, 2.6281483E-02, | ||
457 | + 145.3951, 2.045347, 0.4421963, 3.036170, 9.1009791E-04, | ||
458 | + 141.5824}; | ||
459 | + double s2 = std::sin(sza) * std::sin(sza); | ||
460 | + double szap = sza * (1. - fdsmodde[23] * s2 * std::exp(-fdsmodde[24] * s2 - fdsmodde[25]*(alt - fdsmodde[26])*(alt - fdsmodde[26]))); | ||
461 | + double sinz = std::sin(fdsmodde[18] + szap); | ||
462 | + double s = fdsmodde[1] + fdsmodde[2] / (alt - fdsmodde[3]) | ||
463 | + + sinz * fdsmodde[13] | ||
464 | + + fdsmodde[19] * std::exp(-fdsmodde[20]*((alt - fdsmodde[21])*(alt - fdsmodde[21])) - fdsmodde[22] * szap * szap); | ||
465 | + double o = fdsmodde[4] + fdsmodde[5] / (alt - fdsmodde[6]) + sinz * fdsmodde[14]; | ||
466 | + double c = fdsmodde[7] + fdsmodde[8] / (alt - fdsmodde[9]) + sinz * fdsmodde[15]; | ||
467 | + double m = fdsmodde[10] + fdsmodde[11] / (alt - fdsmodde[12]) + sinz * fdsmodde[16]; | ||
468 | + double ss = s * cos(fdsmodde[17] + szap); | ||
469 | + double calc = (1.77245 * ss * erfc(-ss) + std::exp(-ss * ss) + o); | ||
470 | + if (calc <= 0) | ||
471 | + calc = 0.00001; | ||
472 | + dn = (Type1) c + m * log(calc); | ||
473 | + return dn; | ||
474 | + } | ||
475 | +} | ||
407 | 476 | ||
408 | /** | 477 | /** |
409 | * @brief Operator cross product between two vector | 478 | * @brief Operator cross product between two vector |
@@ -1391,18 +1460,20 @@ std::vector<Type> total(const AMDA::Parameters::Tab2DData<Type>& a, int mode) { | @@ -1391,18 +1460,20 @@ std::vector<Type> total(const AMDA::Parameters::Tab2DData<Type>& a, int mode) { | ||
1391 | } | 1460 | } |
1392 | 1461 | ||
1393 | // Reshape a Tab2D to a vector | 1462 | // Reshape a Tab2D to a vector |
1463 | + | ||
1394 | template <typename Type> | 1464 | template <typename Type> |
1395 | std::vector<Type> reshapeToVector(const AMDA::Parameters::Tab2DData<Type>& a) { | 1465 | std::vector<Type> reshapeToVector(const AMDA::Parameters::Tab2DData<Type>& a) { |
1396 | std::vector<Type> v; | 1466 | std::vector<Type> v; |
1397 | - v.resize(a.getDim1Size()*a.getDim2Size()); | 1467 | + v.resize(a.getDim1Size() * a.getDim2Size()); |
1398 | for (int r = 0; r < a.getDim1Size(); ++r) { | 1468 | for (int r = 0; r < a.getDim1Size(); ++r) { |
1399 | for (int c = 0; c < a.getDim2Size(); ++c) { | 1469 | for (int c = 0; c < a.getDim2Size(); ++c) { |
1400 | - v[r*a.getDim2Size() + c] = a[r][c]; | 1470 | + v[r * a.getDim2Size() + c] = a[r][c]; |
1401 | } | 1471 | } |
1402 | } | 1472 | } |
1403 | 1473 | ||
1404 | return v; | 1474 | return v; |
1405 | } | 1475 | } |
1476 | + | ||
1406 | /* | 1477 | /* |
1407 | * Evaluation of SuperMAG auroral electrojet indices as indicators | 1478 | * Evaluation of SuperMAG auroral electrojet indices as indicators |
1408 | * of substorms and auroral power | 1479 | * of substorms and auroral power |
@@ -1410,7 +1481,7 @@ std::vector<Type> reshapeToVector(const AMDA::Parameters::Tab2DData<Type>& a) { | @@ -1410,7 +1481,7 @@ std::vector<Type> reshapeToVector(const AMDA::Parameters::Tab2DData<Type>& a) { | ||
1410 | */ | 1481 | */ |
1411 | template <typename Type> | 1482 | template <typename Type> |
1412 | Type newell2011(Type a) { | 1483 | Type newell2011(Type a) { |
1413 | - return 0.048*a + 0.241*std::sqrt(a) ; | 1484 | + return 0.048 * a + 0.241 * std::sqrt(a); |
1414 | } | 1485 | } |
1415 | 1486 | ||
1416 | template <typename Type1, typename Type2> | 1487 | template <typename Type1, typename Type2> |
@@ -1490,15 +1561,14 @@ std::vector<Type1> operator/(AMDA::Parameters::TabRow<Type1> a, std::vector<Type | @@ -1490,15 +1561,14 @@ std::vector<Type1> operator/(AMDA::Parameters::TabRow<Type1> a, std::vector<Type | ||
1490 | } | 1561 | } |
1491 | 1562 | ||
1492 | template<typename Type> | 1563 | template<typename Type> |
1493 | -bool isValid(const std::string& num) { | ||
1494 | - bool flag = true; | ||
1495 | - try { | ||
1496 | - Type tmp = boost::lexical_cast<Type>(num); | ||
1497 | - } | ||
1498 | - catch (boost::bad_lexical_cast &e) { | ||
1499 | - flag = false; | ||
1500 | - } | ||
1501 | - return flag; | 1564 | +bool isValid(const std::string& num) { |
1565 | + bool flag = true; | ||
1566 | + try { | ||
1567 | + Type tmp = boost::lexical_cast<Type>(num); | ||
1568 | + } catch (boost::bad_lexical_cast &e) { | ||
1569 | + flag = false; | ||
1570 | + } | ||
1571 | + return flag; | ||
1502 | } | 1572 | } |
1503 | 1573 | ||
1504 | template <typename Type> | 1574 | template <typename Type> |
@@ -1520,8 +1590,8 @@ std::pair<Type, Type> operator+(std::pair<Type, Type> a, std::pair<Type, Type> b | @@ -1520,8 +1590,8 @@ std::pair<Type, Type> operator+(std::pair<Type, Type> a, std::pair<Type, Type> b | ||
1520 | template <typename Type> | 1590 | template <typename Type> |
1521 | std::pair<Type, Type> operator*(std::pair<Type, Type> a, std::pair<Type, Type> b) { | 1591 | std::pair<Type, Type> operator*(std::pair<Type, Type> a, std::pair<Type, Type> b) { |
1522 | std::pair<Type, Type> c; | 1592 | std::pair<Type, Type> c; |
1523 | - c.first = a.first* b.firest; | ||
1524 | - c.second = a.second* b.second; | 1593 | + c.first = a.first * b.firest; |
1594 | + c.second = a.second * b.second; | ||
1525 | return c; | 1595 | return c; |
1526 | } | 1596 | } |
1527 | 1597 |
test/data/functions.xml
@@ -189,6 +189,30 @@ | @@ -189,6 +189,30 @@ | ||
189 | </info_brief> | 189 | </info_brief> |
190 | <new_kernel>lopez90</new_kernel> | 190 | <new_kernel>lopez90</new_kernel> |
191 | </function> | 191 | </function> |
192 | + <function name="pv_ionos_dn(,)" args="2" kind="model" group="space"> | ||
193 | + <prompt_param></prompt_param> | ||
194 | + <default_args>alt(Km), sza(Radians)</default_args> | ||
195 | + <info_brief> | ||
196 | + Electron Density around Venus <br/> | ||
197 | + dn = pv_ionos_dn(alt, sza) <br/> | ||
198 | + alt is the altitude in Km | ||
199 | + sza is the solat zenith angle in radians | ||
200 | + dn is the base 10 log of the model electron density in no/cc | ||
201 | + </info_brief> | ||
202 | + <new_kernel>pv_ionos_dn</new_kernel> | ||
203 | + </function> | ||
204 | + <function name="pv_ionos_te(,)" args="2" kind="model" group="space"> | ||
205 | + <prompt_param></prompt_param> | ||
206 | + <default_args>alt(Km), sza(Radians)</default_args> | ||
207 | + <info_brief> | ||
208 | + Electron temperature around Venus <br/> | ||
209 | + te = pv_ionos_dn(alt, sza) <br/> | ||
210 | + alt is the altitude in Km | ||
211 | + sza is the solat zenith angle in radians | ||
212 | + te is in log10 deg K | ||
213 | + </info_brief> | ||
214 | + <new_kernel>pv_ionos_te</new_kernel> | ||
215 | + </function> | ||
192 | <function name="framesTransformation(,,,)" args="1" kind="frames" group="space"> | 216 | <function name="framesTransformation(,,,)" args="1" kind="frames" group="space"> |
193 | <prompts> | 217 | <prompts> |
194 | <prompt type="list" subtype="frames" default="GSM">Input frame:</prompt> | 218 | <prompt type="list" subtype="frames" default="GSM">Input frame:</prompt> |