Commit Graph

2245 Commits

Author SHA1 Message Date
Don Cross
80780637e6 Added vgtest script, for running ctest through valgrind.
The vgtest script allows checking for memory errors in
Astronomy Engine using valgrind. This helped me find
a bug where I was using uninitialized memory.
2020-08-22 14:34:25 -04:00
Don Cross
3bcc44d0fc Reduced precision of generated PlutoStateTable.
The PlutoStateTable was slightly different when generated
in Linux and Windows, because there was so much precision
after the decimal point. Reduced precision until Linux
and Windows generated the exact same output.
2020-08-22 14:08:07 -04:00
Don Cross
dcd548f0a1 PlutoCheck is now terse unless -v is specified. 2020-08-22 12:08:17 -04:00
Don Cross
bfaa2c185b Pluto integrator: cache all calculated segments.
Instead of remembering the most recent 3 segments of Pluto's orbits,
cache up to all 40 segments within the year span 0000..4000.
Use dynamic memory to allocate them instead of static memory.
Added Astronomy_Reset() to free memory before exit.
2020-08-22 12:01:20 -04:00
Don Cross
10139d3762 Pluto integrator: More refactoring to make code smaller. 2020-08-21 20:09:02 -04:00
Don Cross
64d425994f Pluto integrator: More refactoring to decrease code size.
Also reduced stack usage by sharing bary[5] more.
Eliminated a redundant call to MajorBodyBary() when
calculating one-way outside the bounds of PlutoStateTable.
2020-08-21 19:16:01 -04:00
Don Cross
38139c620b Pluto integrator: making code a little smaller. 2020-08-21 16:59:18 -04:00
Don Cross
90c6b18729 Pluto integrator: simplify calculating table indexes.
There were two places where I was searching for table entries.
I realized I can just directly calculate the same indexes.
This makes the code smaller and faster.
2020-08-21 15:27:14 -04:00
Don Cross
4febeff50e Pluto integrator: added ability to calculate before outside years 0000..4000.
Calculations outside 0000..4000 are slower because they are not cached.
But at least they work now instead of returning an error.
2020-08-20 21:56:43 -04:00
Don Cross
f58778b071 Pluto integrator: Changed dt from 500 to 250 days. Tweaked error threshold. 2020-08-20 15:54:29 -04:00
Don Cross
5c3e5a83d9 Pluto integrator: keep and recycle calculations over segments.
To make Pluto calculations have a low amortized time cost,
calculate up to 3 segments between adjacent pairs of
pre-calulcated states and recycle them. Do linear ramp
fade-mixing between them.

Currently, something is wrong with this because it fails
by inaccurately calculating horizontal coordinates of Pluto
in one test. I'm not sure what's going wrong there yet,
but likely related to multiple calls via search.
2020-08-20 13:49:21 -04:00
Don Cross
a71acd70ca Pluto integrator: settled on dt = 500 days.
This is a happy compromise between speed and accuracy.
Solidified this as a #define PLUTO_DT, which will allow
me to do compile-time math to establish an array size for
an internal buffer of lazy-computed dt increments between
most recently requested segment endpoints.
2020-08-19 17:12:45 -04:00
Don Cross
783aa5008c Pluto integrator: Dramatically improved accuracy and speed.
Now we are getting somewhere!
Using the mean acceleration over the interval seems so much
better than the complicated calculus thing I did.
Now I am using a very large time step: 500 days,
with an error less than 0.2 arcminutes.

C PlutoCheck: dt = 500.000000
C PlutoCheck: 2049-12-19T12:00:00.000Z = 18250.000000 UT = 18250.001076 TT
C PlutoCheck: calc pos = [ 37.4373396436339121, -10.2445033319559062, -14.4764587025278448]
C PlutoCheck: ref  pos = [ 37.4377303529113306, -10.2466292445590774, -14.4773101309873091]
C PlutoCheck: del  pos = [ -0.0003907092774185,   0.0021259126031712,   0.0008514284594643]
C PlutoCheck: diff = 2.323163e-03 AU, 0.198 arcmin
2020-08-19 16:20:51 -04:00
Don Cross
0bfd30d751 Pluto integrator: 'ctest pluto' allows tweaking dt. Default dt = 50 days.
Allow passing in the dt value as an environment variable PLUTO_DT:

$ PLUTO_DT=100 ./ctest pluto
C PlutoCheck: dt = 100.000000
C PlutoCheck: 2049-12-19T12:00:00.000Z = 18250.000000 UT = 18250.001076 TT
C PlutoCheck: calc pos = [ 37.4506659151144774, -10.2638146514621269, -14.4865003148403595]
C PlutoCheck: ref  pos = [ 37.4377303529113306, -10.2466292445590774, -14.4773101309873091]
C PlutoCheck: del  pos = [  0.0129355622031468,  -0.0171854069030495,  -0.0091901838530504]
C PlutoCheck: error = 2.339073e-02 AU, 1.989 arcmin

Default to dt = 50 days.
2020-08-19 14:35:46 -04:00
Don Cross
68b0ec92bd Fixed another Pluto integrator bug: corrected SSB calculation.
I had a bug in the calculation of the Solar System Barycenter.
The position and velocity vectors were both backwards.
This caused the barycentric Sun to be in the wrong place.

C PlutoCheck: 2049-12-19T12:00:00.000Z = 18250.000000 UT = 18250.001076 TT
C PlutoCheck: calc pos = [ 37.4386594210222654, -10.2474739785185811, -14.4777836541558340]
C PlutoCheck: ref  pos = [ 37.4377303529113306, -10.2466292445590774, -14.4773101309873091]
C PlutoCheck: del  pos = [  0.0009290681109348,  -0.0008447339595037,  -0.0004735231685249]
C PlutoCheck: error = 1.342001e-03
2020-08-19 14:23:09 -04:00
Don Cross
a5d011ee78 Pluto integrator: factored out search for nearest starting state. 2020-08-19 12:53:08 -04:00
Don Cross
b6087c9b14 Pluto integrator: fixed a small math mistake.
I didn't implement the math I had derived on paper exactly right.
There was one place where I meant to have (dt^3 / 6), but I had (dt^2 / 6).
This has only a tiny effect on the error. I know this can work better,
so I'm still searching for the real problem.

C PlutoCheck: 2049-12-19T12:00:00.000Z = 18250.000000 UT = 18250.001076 TT
C PlutoCheck: calc pos = [ 37.3682426267669996, -10.0216432448322834, -14.3724661626442582]
C PlutoCheck: ref  pos = [ 37.4377303529113306, -10.2466292445590774, -14.4773101309873091]
C PlutoCheck: del  pos = [ -0.0694877261443310,   0.2249859997267940,   0.1048439683430509]
C PlutoCheck: error = 2.577586e-01
2020-08-18 21:59:37 -04:00
Don Cross
f279cdd9b5 PlutoCheck: made test much more difficult.
I picked a worst-case starting time that is halfway between
two entries in the PlutoStateTable[]. This requires the most
iterations to calculate. Now I have a better metric for
position accuracy:

C PlutoCheck: 2049-12-19T12:00:00.000Z = 18250.000000 UT = 18250.001076 TT
C PlutoCheck: calc pos = [ 37.3682426469732860, -10.0216428456503461, -14.3724660445065933]
C PlutoCheck: ref  pos = [ 37.4377303529113306, -10.2466292445590774, -14.4773101309873091]
C PlutoCheck: del  pos = [ -0.0694877059380445,   0.2249863989087313,   0.1048440864807159]
C PlutoCheck: error = 2.577590e-01

Clearly I still have a lot of work to do!
2020-08-18 20:37:52 -04:00
Don Cross
013fbc03c4 Pluto test: fail if error increases above current amount. 2020-08-18 17:46:10 -04:00
Don Cross
a212630a2a Pluto integrator: fixed bug; now have much more accurate results.
Got 'ctest pluto' error down to 5.675183e-05 AU.
I was adding vectors when I should have been subtracting,
to find heliocentric Pluto from barycentric Pluto.
2020-08-18 15:58:35 -04:00
Don Cross
f94ba04032 Pluto integrator: refined coordinates for Pluto test.
The 'ctest pluto' command was testing against slightly wrong coordinates.
Added 'generate topcalc' command to print out exact TOP2013 values.
Used those values as the reference coordinates in 'ctest pluto'.
Sadly, this increased the measured error from 1.347e-02 AU to 1.412e-02 AU.
2020-08-18 15:33:31 -04:00
Don Cross
b55d216f3e Simplified Pluto integrator looping logic a little bit. 2020-08-18 14:42:23 -04:00
Don Cross
ed43329639 Pluto integrator bug fix: was using stale Sun location to correct coordinates.
When finalizing the position of Pluto, I need to convert
barycentric coordinates to heliocentric coordinates.
I do this by adding the barycentric location of the Sun
to the barycentric location of Pluto to obtain the
heliocentric location of Pluto. But I was using the Sun
coordinates from the simulation starting point, not
at the final time.

This decreases the AU error from 1.369e-02 to 1.347e-02.
I'm still looking for the rest of the error.
2020-08-18 14:23:06 -04:00
Don Cross
850ab79771 Explicitly exclude the pluto_integrator branch from Travis CI for now.
I know this code currently fails unit tests, and will take far too
long if attempted. Therefore, I'm turning off pluto_integrator.
I will turn it back on when I believe it's working.
I just want to be able to back up my code offsite while I'm still
developing it.
2020-08-18 14:11:45 -04:00
Don Cross
071e21c198 Fixed uninitialized memory bug in GravSim().
I wasn't initialzing the acceleration vector in the value returned
by GravSim(). I'm not sure how any of this ever worked!
Found it by using valgrind.
There is no apparent advantage to looping for convergence in GravSim().
Also, it looks like I can use a much larger dt = 10 days.
2020-08-17 22:39:33 -04:00
Don Cross
0fb4d86691 Reworked terse_vector_t to use (x, y, z) instead of c[3].
The code reads so much easier to use normal (x, y, z) coordinates.
2020-08-17 21:31:04 -04:00
Don Cross
2bfef280fd Starting work on using a gravitational simulator to calculate Pluto's movement.
Added PlutoStateTable to C code generator.
This is a table of known correct [tt, pos, vel] tuples for Pluto,
calculated using TOP2013. These serve as seed points from which
to integrate Pluto's motion.

Added PlutoCheck() function to ctest, just to get going.
I have a lot more peformance work to do in order to make
the full blown unit test to finish in a reasonable amount of
time.

Changes in astronomy.c:

Added some generic "terse vector" support.
A terse vector contains 3 components and nothing else.
This is handy for implementing compact formulas for various
vector expressions.

Created enhanced VSOP87 calculations that provide
velocity vectors as well as position vectors for
the Sun, Jupiter, Saturn, Uranus, and Neptune.
These are the "major" bodies that have significant
effects on the motion of Pluto. Also used to convert
heliocentric coordinates to barycentric coordinates.

Implemented first version of the integrator logic.
It is not accurate enough yet, and it is far too slow.
I need to debug the accuracy first, then I will work on
making it faster.
2020-08-17 17:33:03 -04:00
Don Cross
b6db310641 Keeping useful changes from abandoned branch small_pluto.
I was experimenting with an alternative way to calculate Pluto's position.
That idea didn't work out, but in the process, I did make some changes
I want to keep:

1. A typecast in generate/codegen.c that eliminates a build warning
   in Windows (Visual Studio 2015).

2. Expanded generate/vsop/vsop.c to calculate both position and velocity
   vectors. This was tricky to get working, and could come in handy.
2020-08-15 13:28:16 -04:00
Don Cross
3c6b569cd4 Fixed breakage in nodejs demos.
I had to require('./astronomy.js') instead of require('astronomy.js')
to get the nodejs demos working, now that I maintain a redundant
copy of astronomy.js in the demo directories.
2020-08-10 11:37:34 -04:00
Don Cross
db9eb6b180 Maintain redundant copies of Astronomy Engine source in demo folders.
Windows does not support relative links in Git by default.
This broke the first-time experience for Windows users.
From now on I will maintain copies of the astronomy.js
and astronomy.py in the demo folders, so that the demos
will work on Windows immediately after cloning the repo.
2020-08-10 11:08:27 -04:00
Don Cross
f8cc44a0a5 Deleting relative links to astronomy code.
Using Linux relative links to astronomy.py and astronomy.js
from the demo directories just doesn't work in Windows.
This creates a stumbling block for first-time users.
To make it easier for people to get started, I will just
make redundant copies in other directories as needed.
It is better to use a little extra disk space -- hard drives are cheap!

This is the first step: get rid of the links.
2020-08-10 10:41:58 -04:00
Don Cross
941fc73c9a Browser demo positions.html: fix exception, allow edit date.
When I added support for pseudo-bodies like SSB
(Solar System Barycenter), it broke the positions.html demo.
Use an explicit list of the bodies to be calculated.
I should probably get rid of Astronomy.Bodies, because it
seems to invite bugs like this. I will think more about that.

Also, there was no way to manually edit the time.
Added a checkbox called "Automatic" that toggles whether
the time is updated automatically every second or
is entered by the user.

Persist the checkbox and edited time in the saved options.
2020-08-10 10:37:51 -04:00
Don Cross
233232ea1e JS demo programs: validate command line parameters.
Print meaningful error messages and exit, if the JavaScript
demo programs are given invalid command line parameters.
2020-07-23 20:31:25 -04:00
Don Cross
fa13f980b2 JS: Stricter type checking for function parameters. Other fixes.
In the JavaScript version, check throughout for valid
finite numeric/boolean values as needed.
This should make debugging a lot easier for everybody.

In the unit tests for all languages, also check for infinite
results, not just NaN.

I discovered that JS Astronomy.NextLocalSolarEclipse() was broken:
It was trying to call a nonexistent function.
Fixed it, and added unit test that would have caught the breakage.

Fixed mistakes in JS documentation for the field names of the
Observer class.
2020-07-23 20:12:36 -04:00
Don Cross
2c787eca8e Refined the problematic optimizations to -ffp-contract=off.
Instead of turning off all "expensive optimizations" in gcc,
I found I can achieve consistent calculation results on
64-bit ARM processors by turning off just the "fp contract"
optimization.

This optimizer is actually supposed to produce *more* accurate
results, but the effect is to produce results that differ
across languages/processors. For the sake of the unit tests,
I have decided it must be turned off in ctest and generate.
2020-07-22 21:30:51 +00:00
Don Cross
82c4c512e8 Removed the optimizations that were causing calculation problems.
It turns out that in gcc 9.3.0 on aarch64, the "expensive optimizations"
were causing incorrect calculations. I resumed using -O3 but with
expensive optimizations turned off. Now all unit tests pass again.
2020-07-22 20:30:44 +00:00
Don Cross
c4442103c4 More fixes for gcc 9.3.0 aarch64 on Raspberry Pi 3.
Fixed some build warnings that occur on various gcc
optimization levels, and only on this version of gcc.

For now, build ctest with fewer optimizations: -O1
instead of -O3. This is because -O3 and -O2 cause
excessive errors in 'ctest diff' of the order
1.0e-9, where I usually get 1.0e-12. I will have to
come back and figure out exactly which optimization(s)
are causing the problem and turn them off specifically.
This also means I need to document the dangerous optimizations
for people who are using the C version of Astronomy Engine.

When 'ctest diff' fails because of excessive numeric error,
print out the two lines of input text that had the worst
numeric error. This really helps on the Raspberry Pi
where memory is at a premium, and it's hard to open the
full output files using vi.
2020-07-22 18:53:13 +00:00
Don Cross
9daf50c233 Loosene a couple of error thresholds in the C unit tests, for aarch64. 2020-07-22 02:05:06 +00:00
Don Cross
23b5bddf8b Fixed minor breakage in C# demo tests. 2020-07-21 21:01:15 -04:00
Don Cross
69a0548eb7 Upgrading from dotnet core 2.2 to 3.1.
Dotnet core 2.2 is no longer officially supported by Microsoft.
The current LTS is 3.1, so I'm upgrading to it.
2020-07-22 00:30:35 +00:00
Don Cross
e19d50c68c Fixed #72 - resolved build warnings in gcc 9.3.0.
Version 9.3.0 of gcc has extra warnings that detect snprintf
truncations and use of possibly uninitialized variables.
Fixed some warnings of both types.
2020-07-21 23:30:44 +00:00
Don Cross
bccffc0055 Generate JSON ephemeris using J2000 dates instead of Julian dates. 2020-07-11 10:10:27 -04:00
Don Cross
c563237399 Added generation of ephemeris in JSON format.
I'm working on a Solar System gravity simulation.
I need very precise position and velocity data for the major
Solar System bodies. I want to write the simulator as a browser-
based animation, so I will code it in JavaScript. This JSON
generator is a bootstrap to provide the initial solar system
state, plus it allows testing how accurate the simulation
is as it unfolds. Plus it may be useful for any program that
can parse JSON easily.
2020-07-11 09:31:26 -04:00
Don Cross
8a2b12295d Fixed Windows build warning in gravsim. 2020-07-09 22:16:27 -04:00
Don Cross
75c3559326 Add an experimental gravity simulator for Pluto. 2020-07-09 21:32:24 -04:00
Don Cross
84bbeefd5c Made some documentation fixes for the C version.
Added Astronomy_FormatTime to the topic index.
Reworded text to avoid "as explained above", because it turns
out the generated documentation does not always put things
in the same order they appear in the source code comments.
2020-07-09 15:55:26 -04:00
Don Cross
686401d3ef Added C function Astronomy_FormatTime.
It's surprisingly tricky to print a time rounded to the
nearest millisecond, second, or minute using the C code.
I saw a case where positions.c printed '2020-07-09 04:29:60'.
Because printing a date/time is a basic need of an astronomy program,
I added the new function Astronomy_FormatTime to do this.
All the demo programs use this new function, which required
me to update the correct reference output for the unit tests.
2020-07-09 15:25:28 -04:00
Don Cross
f50afb6910 npm version 1.1.1 2020-07-08 21:14:56 -04:00
Don Cross
9c940d7432 Fixed #69 - Support calculating Pluto without any year range limit.
Fixed lingering documentation and code that refers to a limited
year range for calculating Pluto's position.
2020-07-08 19:20:47 -04:00
Don Cross
9347fd0264 codegen: Eliminated unused 'body' parameter in Top2013_List(). 2020-07-08 15:57:26 -04:00