[prev in list] [next in list] [prev in thread] [next in thread] 

List:       kde-commits
Subject:    [kstars/hdevalence-gsoc2013] /: Try to move some of the nutation calculations from KSNumbers.
From:       Henry de Valence <hdevalence () hdevalence ! ca>
Date:       2013-06-30 19:54:09
Message-ID: E1UtNhJ-0001l4-DV () scm ! kde ! org
[Download RAW message or body]

Git commit 7a25717fc17139b5555b2d92410c22109f14a15a by Henry de Valence.
Committed on 30/06/2013 at 19:49.
Pushed by hdevalence into branch 'hdevalence-gsoc2013'.

Try to move some of the nutation calculations from KSNumbers.

This implementation doesn't give the same result as of yet, but
it's not obvious (to me) why. It's also
not clear what the difference between the two obliquity calculations
in KSNumbers is, but it's quite large and I presume important. The ported
code follows Meeus, chapter 20.

If anyone wants to take a brief look and see whether I've made
an obvious mistake, it'd be appreciated.

CCMAIL: akarshsimha@gmail.com
CCMAIL: ra.rishab@gmail.com

M  +9    -1    Tests/engine/CMakeLists.txt
A  +38   -0    Tests/engine/testastrovars.cpp     [License: GPL (v2+)]
A  +30   -0    Tests/engine/testastrovars.h     [License: GPL (v2+)]
M  +1    -0    kstars/CMakeLists.txt
A  +238  -0    kstars/engine/astrovars.cpp     [License: GPL (v2+)]
A  +45   -0    kstars/engine/astrovars.h     [License: GPL (v2+)]

http://commits.kde.org/kstars/7a25717fc17139b5555b2d92410c22109f14a15a

diff --git a/Tests/engine/CMakeLists.txt b/Tests/engine/CMakeLists.txt
index 20ea8ff..5f4490c 100644
--- a/Tests/engine/CMakeLists.txt
+++ b/Tests/engine/CMakeLists.txt
@@ -6,7 +6,7 @@ set( TEST_LIBRARIES
    )
 include_directories( ${kstars_SOURCE_DIR} ${EIGEN2_INCLUDE_DIR} )
 
-set( KSEngineTests_SRCS testconvertcoord.cpp )
+set( KSEngineTests_SRCS testconvertcoord.cpp testastrovars.cpp )
 QT4_AUTOMOC( ${KSEngineTests_SRCS} )
 
 #
@@ -16,3 +16,11 @@ QT4_AUTOMOC( ${KSEngineTests_SRCS} )
 add_executable( testconvertcoord testconvertcoord.cpp )
 target_link_libraries( testconvertcoord ${TEST_LIBRARIES} )
 add_test( NAME ConvertCoordTest COMMAND testconvertcoord )
+
+#
+# Test misc calculations
+#
+
+add_executable( testastrovars testastrovars.cpp )
+target_link_libraries( testastrovars ${TEST_LIBRARIES} )
+add_test( NAME AstroVarsTest COMMAND testastrovars )
diff --git a/Tests/engine/testastrovars.cpp b/Tests/engine/testastrovars.cpp
new file mode 100644
index 0000000..d1168bc
--- /dev/null
+++ b/Tests/engine/testastrovars.cpp
@@ -0,0 +1,38 @@
+/***************************************************************************
+ *         testastrovars.cpp - Tests calculation of misc. parameters.
+ *                             -------------------
+ *    begin                : 2013-07-01
+ *    copyright            : (C) 2013 by Henry de Valence
+ *    email                : hdevalence@hdevalence.ca
+ ***************************************************************************/
+
+/***************************************************************************
+ *                                                                         *
+ *   This program is free software; you can redistribute it and/or modify  *
+ *   it under the terms of the GNU General Public License as published by  *
+ *   the Free Software Foundation; either version 2 of the License, or     *
+ *   (at your option) any later version.                                   *
+ *                                                                         *
+ ***************************************************************************/
+
+#include "testastrovars.h"
+
+#include "kstars/engine/astrovars.h"
+#include "kstars/ksnumbers.h"
+
+using namespace KSEngine;
+
+void TestAstroVars::testNutationVars()
+{
+    JulianDate jd = EpochJ2000 + 36525.;
+    double avEcL, avOb;
+    AstroVars::nutationVars(jd, &avEcL, &avOb);
+    KSNumbers num(jd);
+    printf("%f %f\n%f %f\n", avEcL, avOb, num.dEcLong(), num.dObliq());
+    QCOMPARE( avEcL, num.dEcLong() );
+    QCOMPARE( avOb, num.dObliq() );
+}
+
+QTEST_MAIN(TestAstroVars)
+
+#include "testastrovars.moc"
diff --git a/Tests/engine/testastrovars.h b/Tests/engine/testastrovars.h
new file mode 100644
index 0000000..a6f92d2
--- /dev/null
+++ b/Tests/engine/testastrovars.h
@@ -0,0 +1,30 @@
+/***************************************************************************
+ *         testastrovars.h - Tests calculation of misc. parameters.
+ *                             -------------------
+ *    begin                : 2013-07-01
+ *    copyright            : (C) 2013 by Henry de Valence
+ *    email                : hdevalence@hdevalence.ca
+ ***************************************************************************/
+
+/***************************************************************************
+ *                                                                         *
+ *   This program is free software; you can redistribute it and/or modify  *
+ *   it under the terms of the GNU General Public License as published by  *
+ *   the Free Software Foundation; either version 2 of the License, or     *
+ *   (at your option) any later version.                                   *
+ *                                                                         *
+ ***************************************************************************/
+
+#ifndef TESTASTROVARS_H
+#define TESTASTROVARS_H
+
+#include <QtTest>
+
+class TestAstroVars : public QObject
+{
+    Q_OBJECT
+private slots:
+    void testNutationVars();
+};
+
+#endif 
\ No newline at end of file
diff --git a/kstars/CMakeLists.txt b/kstars/CMakeLists.txt
index 67e7527..5ab2693 100644
--- a/kstars/CMakeLists.txt
+++ b/kstars/CMakeLists.txt
@@ -379,6 +379,7 @@ set(kstars_engine_SRCS
     engine/oldprecession.cpp
     engine/oldconversions.cpp
     engine/convertcoord.cpp
+    engine/astrovars.cpp
 )
 
 set(kstars_extra_SRCS
diff --git a/kstars/engine/astrovars.cpp b/kstars/engine/astrovars.cpp
new file mode 100644
index 0000000..0da68ba
--- /dev/null
+++ b/kstars/engine/astrovars.cpp
@@ -0,0 +1,238 @@
+/***************************************************************************
+     engine/astrovars.cpp - functions for use in various calculations
+                             -------------------
+    begin                : 2013-06-28
+    copyright            : (C) 2013 by Henry de Valence
+    email                : hdevalence@hdevalence.ca
+ ***************************************************************************/
+
+/***************************************************************************
+ *                                                                         *
+ *   This program is free software; you can redistribute it and/or modify  *
+ *   it under the terms of the GNU General Public License as published by  *
+ *   the Free Software Foundation; either version 2 of the License, or     *
+ *   (at your option) any later version.                                   *
+ *                                                                         *
+ ***************************************************************************/
+
+#include "astrovars.h"
+#include <iostream>
+
+/*
+ * These variables are taken from a table in chapter 20 of Meeus.
+ */
+static const int NUTTERMS = 63;
+EIGEN_ALIGN16
+static const double _arguments_data[NUTTERMS][5] = {
+    { 0, 0, 0, 0, 1},
+    {-2, 0, 0, 2, 2},
+    { 0, 0, 0, 2, 2},
+    { 0, 0, 0, 0, 2},
+    { 0, 1, 0, 0, 0},
+    { 0, 0, 1, 0, 0},
+    {-2, 1, 0, 2, 2},
+    { 0, 0, 0, 2, 1},
+    { 0, 0, 1, 2, 2},
+    {-2,-1, 0, 2, 2},
+    {-2, 0, 1, 0, 0},
+    {-2, 0, 0, 2, 1},
+    { 0, 0,-1, 2, 2},
+    { 2, 0, 0, 0, 0},
+    { 0, 0, 1, 0, 1},
+    { 2, 0,-1, 2, 2},
+    { 0, 0,-1, 0, 1},
+    { 0, 0, 1, 2, 1},
+    {-2, 0, 2, 0, 0},
+    { 0, 0,-2, 2, 1},
+    { 2, 0, 0, 2, 2},
+    { 0, 0, 2, 2, 2},
+    { 0, 0, 2, 0, 0},
+    {-2, 0, 1, 2, 2},
+    { 0, 0, 0, 2, 0},
+    {-2, 0, 0, 2, 0},
+    { 0, 0,-1, 2, 1},
+    { 0, 2, 0, 0, 0},
+    { 2, 0,-1, 0, 1},
+    {-2, 2, 0, 2, 2},
+    { 0, 1, 0, 0, 1},
+    {-2, 0, 1, 0, 1},
+    { 0,-1, 0, 0, 1},
+    { 0, 0, 2,-2, 0},
+    { 2, 0,-1, 2, 1},
+    { 2, 0, 1, 2, 2},
+    { 0, 1, 0, 2, 2},
+    {-2, 1, 1, 0, 0},
+    { 0,-1, 0, 2, 2},
+    { 2, 0, 0, 2, 1},
+    { 2, 0, 1, 0, 0},
+    {-2, 0, 2, 2, 2},
+    {-2, 0, 1, 2, 1},
+    { 2, 0,-2, 0, 1},
+    { 2, 0, 0, 0, 1},
+    { 0,-1, 1, 0, 0},
+    {-2,-1, 0, 2, 1},
+    {-2, 0, 0, 0, 1},
+    { 0, 0, 2, 2, 1},
+    {-2, 0, 2, 0, 1},
+    {-2, 1, 0, 2, 1},
+    { 0, 0, 1,-2, 0},
+    {-1, 0, 1, 0, 0},
+    {-2, 1, 0, 0, 0},
+    { 1, 0, 0, 0, 0},
+    { 0, 0, 1, 2, 0},
+    { 0, 0,-2, 2, 2},
+    {-1,-1, 1, 0, 0},
+    { 0, 1, 1, 0, 0},
+    { 0,-1, 1, 2, 2},
+    { 2,-1,-1, 2, 2},
+    { 0, 0, 3, 2, 2},
+    { 2,-1, 0, 2, 2}
+};
+
+EIGEN_ALIGN16
+static const double _amp_data[NUTTERMS][4] = {
+    {-171996,-1742, 92025, 89},
+    { -13187,  -16,  5736,-31},
+    {  -2274,   -2,   977, -5},
+    {   2062,    2,  -895,  5},
+    {   1426,  -34,    54, -1},
+    {    712,    1,    -7,  0},
+    {   -517,   12,   224, -6},
+    {   -386,   -4,   200,  0},
+    {   -301,    0,   129, -1},
+    {    217,   -5,   -95,  3},
+    {   -158,    0,     0,  0},
+    {    129,    1,   -70,  0},
+    {    123,    0,   -53,  0},
+    {     63,    0,     0,  0},
+    {     63,    1,   -33,  0},
+    {    -59,    0,    26,  0},
+    {    -58,   -1,    32,  0},
+    {    -51,    0,    27,  0},
+    {     48,    0,     0,  0},
+    {     46,    0,   -24,  0},
+    {    -38,    0,    16,  0},
+    {    -31,    0,    13,  0},
+    {     29,    0,     0,  0},
+    {     29,    0,   -12,  0},
+    {     26,    0,     0,  0},
+    {    -22,    0,     0,  0},
+    {     21,    0,   -10,  0},
+    {     17,   -1,     0,  0},
+    {     16,    0,    -8,  0},
+    {    -16,    1,     7,  0},
+    {    -15,    0,     9,  0},
+    {    -13,    0,     7,  0},
+    {    -12,    0,     6,  0},
+    {     11,    0,     0,  0},
+    {    -10,    0,     5,  0},
+    {     -8,    0,     3,  0},
+    {      7,    0,    -3,  0},
+    {     -7,    0,     0,  0},
+    {     -7,    0,     3,  0},
+    {     -7,    0,     3,  0},
+    {      6,    0,     0,  0},
+    {      6,    0,    -3,  0},
+    {      6,    0,    -3,  0},
+    {     -6,    0,     3,  0},
+    {     -6,    0,     3,  0},
+    {      5,    0,     0,  0},
+    {     -5,    0,     3,  0},
+    {     -5,    0,     3,  0},
+    {     -5,    0,     3,  0},
+    {      4,    0,     0,  0},
+    {      4,    0,     0,  0},
+    {      4,    0,     0,  0},
+    {     -4,    0,     0,  0},
+    {     -4,    0,     0,  0},
+    {     -4,    0,     0,  0},
+    {      3,    0,     0,  0},
+    {     -3,    0,     0,  0},
+    {     -3,    0,     0,  0},
+    {     -3,    0,     0,  0},
+    {     -3,    0,     0,  0},
+    {     -3,    0,     0,  0},
+    {     -3,    0,     0,  0},
+    {     -3,    0,     0,  0}
+};
+
+static const Eigen::Map<const Eigen::Matrix<double,NUTTERMS,5,Eigen::RowMajor>,
+                        Eigen::Aligned>
+                arguments((double*)_arguments_data);
+static const Eigen::Map<const Eigen::Matrix<double,NUTTERMS,4,Eigen::RowMajor>,
+                        Eigen::Aligned>
+                amp((double*)_amp_data);
+
+namespace KSEngine {
+namespace AstroVars {
+
+double centuriesSinceJ2000(const JulianDate jd)
+{
+    return (jd - EpochJ2000) / 36525.;
+}
+
+double moonArgumentOfLatitude(const JulianDate jd)
+{
+    double T = centuriesSinceJ2000(jd);
+    return 93.27191 + 483202.017538*T - 0.0036825*T*T + T*T*T/327270.;
+}
+
+double moonMeanAnomaly(const JulianDate jd)
+{
+    double T = centuriesSinceJ2000(jd);
+    return 134.96298 + 477198.867398*T + 0.0086972*T*T + T*T*T/56250.0;
+}
+
+double moonMeanLongitude(const JulianDate jd)
+{
+    double T = centuriesSinceJ2000(jd);
+    return 218.3164591 + 481267.88134236*T - 0.0013268*T*T + T*T*T/538841. - T*T*T*T/6519400.;
+}
+
+double sunMeanAnomaly(const JulianDate jd)
+{
+    double T = centuriesSinceJ2000(jd);
+    return 357.52910 + 35999.05030*T - 0.0001559*T*T - 0.00000048*T*T*T;
+}
+
+double meanElongationOfMoon(const JulianDate jd)
+{
+    double T = centuriesSinceJ2000(jd);
+    return 297.85036 + 445267.111480*T - 0.0019142*T*T + T*T*T/189474.;
+}
+
+double sunMeanLongitude(const JulianDate jd)
+{
+    double T = centuriesSinceJ2000(jd);
+    return 280.46645 + 36000.76983*T + 0.0003032*T*T;
+}
+
+double lonMoonAscendingNode(const JulianDate jd)
+{
+    double T = centuriesSinceJ2000(jd);
+    return 125.04452 - 1934.136261*T + 0.0020708*T*T + T*T*T/450000.0;
+}
+
+void nutationVars(const JulianDate jd, double *deltaEcLong, double *deltaObliquity)
+{
+    Matrix<double, 5, 1> params;
+    params << meanElongationOfMoon(jd),
+              sunMeanAnomaly(jd),
+              moonMeanAnomaly(jd),
+              moonArgumentOfLatitude(jd),
+              lonMoonAscendingNode(jd);
+    // This vector has all of the dot products of the
+    // params vector with the coefficients in the argument matrix.
+    typedef Array<double, NUTTERMS, 1> nutArr;
+    nutArr sums = (arguments*params).array();
+    double T = centuriesSinceJ2000(jd);
+    nutArr ecLongColumn = 1e-4*(amp.col(0) + (T/10.)*amp.col(1)).array();
+    nutArr obliqColumn  = 1e-4*(amp.col(2) + (T/10.)*amp.col(3)).array();
+    // Take the dot product, and convert from arcsec to degrees.
+    *deltaEcLong = (ecLongColumn * sums.sin()).sum()/3600.;
+    *deltaObliquity = (obliqColumn * sums.cos()).sum()/3600.;
+}
+
+
+}
+}
\ No newline at end of file
diff --git a/kstars/engine/astrovars.h b/kstars/engine/astrovars.h
new file mode 100644
index 0000000..af3d333
--- /dev/null
+++ b/kstars/engine/astrovars.h
@@ -0,0 +1,45 @@
+/***************************************************************************
+     engine/astrovars.h - functions for use in various calculations
+                             -------------------
+    begin                : 2013-06-28
+    copyright            : (C) 2013 by Henry de Valence
+    email                : hdevalence@hdevalence.ca
+ ***************************************************************************/
+
+/***************************************************************************
+ *                                                                         *
+ *   This program is free software; you can redistribute it and/or modify  *
+ *   it under the terms of the GNU General Public License as published by  *
+ *   the Free Software Foundation; either version 2 of the License, or     *
+ *   (at your option) any later version.                                   *
+ *                                                                         *
+ ***************************************************************************/
+
+#ifndef ASTROVARS_H
+#define ASTROVARS_H
+
+#include "types.h"
+
+#include <Eigen/Core>
+
+namespace KSEngine {
+namespace AstroVars {
+
+    double centuriesSinceJ2000( const JulianDate jd );
+    double sunMeanLongitude( const JulianDate jd );
+    double meanElongationOfMoon( const JulianDate jd );
+    double sunMeanAnomaly( const JulianDate jd );
+    double moonMeanAnomaly( const JulianDate jd );
+    double moonMeanLongitude( const JulianDate jd );
+    double moonArgumentOfLatitude( const JulianDate jd );
+    double lonMoonAscendingNode( const JulianDate jd );
+
+    void nutationVars( const JulianDate  jd,
+                             double     *deltaEcLong,
+                             double     *deltaObliquity );
+
+} // NS AstroVars
+} // NS KSEngine
+
+#endif //ASTROVARS_H
+
[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic