Commit Graph

1235 Commits

Author SHA1 Message Date
Don Cross
5e7162f08d GeoVector must return observation time.
Fixed 3 of the language implementations where I forgot
to make GeoVector return the observation time, not the
backdated time. This is important to preserve existing
behavior.
2022-05-31 21:26:03 -04:00
Don Cross
409451b3c2 Kotlin: light travel time correction. 2022-05-31 20:52:41 -04:00
Don Cross
9afbf0a67f Python: generalized light-travel correction. 2022-05-30 21:37:19 -04:00
Don Cross
765c39d3fa JS: generalized light-travel time correction. 2022-05-30 19:27:25 -04:00
Don Cross
03a0543688 C# light travel: memory allocation optimization
Changed BodyPosition from a class to a struct,
to reduce memory allocation overhead on every
call to GeoVector.
2022-05-30 16:40:47 -04:00
Don Cross
0dd66c8981 C# light travel time correction
Implemented the generalized light travel time corrector for C#.
Reworked Astronomy.GeoVector to use it.
2022-05-29 21:17:25 -04:00
Don Cross
384b5eba96 C light travel time correction
Implemented two new C functions for generic correction
of light travel time:

1. Astronomy_CorrectLightTravel
   This is a completely generic solver that is passed
   a pointer to a function that returns a relative
   position vector for a given time.
   The generic solver keeps calling the function
   whose address is passed, until the light travel
   solution converges. This usually takes 3 or 4 iterations.

2. Astronomy_BackdatePosition
   This is a more specific solver that uses Astronomy_CorrectLightTravel
   to backdate the position of a target body as seen from an
   observer body at a specified observation time.
   It implements the aberration option needed by Astronomy_HelioVector.
   Astronomy_HelioVector now uses Astronomy_BackdatePosition,
   instead of having a redundant light travel solver,
   so the code isn't much larger than it was before.
2022-05-29 18:05:08 -04:00
Don Cross
b4f485eecc Bumped version to 2.1.1. 2022-05-25 21:37:10 -04:00
Don Cross
1902c87828 Merge branch 'gravsim'
Bringing the gravity simulator code into the master branch.
2022-05-25 20:45:20 -04:00
Don Cross
f94824a810 Fixed missing doc for C# GravititySimulator constructor.
The csdown utility was not generating the correct ID
string that matched the C# compiler's XML output file
when a parameter was of a generic type.

Because the GravitySimulator constructor has a bodyStates
parameter of type IEnumerable<StateVector>, we were not
generating the correct method ID string:

CosineKitty.GravitySimulator.#ctor(CosineKitty.Body,CosineKitty.AstroTime,System.Collections.Generic.IEnumerable{CosineKitty.StateVector})

This caused the constructor to not show up in the markdown docs.
I fixed this and now the constructor is documented.
2022-05-25 20:07:16 -04:00
Don Cross
edc27d550a C# docs: fixed link to StateVector[]. 2022-05-25 19:39:07 -04:00
Don Cross
137fc5ce7b Python docs: better formatting of return values. 2022-05-25 17:23:41 -04:00
Don Cross
f02658d63c More documentation fixes.
Corrected a mistake in the explanation of the
C function Astronomy_GravSimInit: the `bodyStates`
parameter is NOT barycentric -- it is relative to the
originBody parameter.

Python had improperly formatted documentation for
Time.FromTerrestrialTime parameter `tt`.

The Python markdown generator `pydown` did not
correctly handle links to compound symbols like
`#GravitySimulator.Update`. It also was trying
to link to `StateVector[]` instead of `StateVector`.

Removed unnecessary and unhelpful documentation
for C# internal class constructors. They do not appear
in the generated markdown documentation anyway.

Other minor wording revisions in the documentation.
2022-05-25 14:12:55 -04:00
Don Cross
4cd03e9a5f C# documentation generator fixes
The C# markdown generator (csdown) was not generating
documentation about constructors. This was especially
needed for the new GravitySimulator class.

Also added markdown for properties like
    GravitySimulator.NumSmallBodies
    GravitySimulator.Time

Made several constructors internal so they don't
need to be listed in the markdown docs.
2022-05-24 21:51:07 -04:00
Don Cross
9c65a27eb1 Improved documentation for gravity simulator.
Added mention of the gravity simulator in the topic
index sections of the markdown docs.
Slight wording changes here and there.
2022-05-23 21:54:00 -04:00
Don Cross
17d42e8119 C#: Provide cube root for .NET Framework.
C# builds for .NET Framework 4 were broken because
the Math.Cbrt function does not exist there.
.NET Core provides a standard cube root function,
but Framework doesn't. Added conditional compilation
to fall back to a less efficient substitute function
on Framework builds.
2022-05-23 20:21:17 -04:00
Don Cross
d28f5ecff3 PY gravsim: passes unit tests
The Python version of the GravitySimulator class
is now passing all unit tests. This completes
the initial coding. I still need to review
documentation across all the language implementations.
2022-05-22 21:16:58 -04:00
Don Cross
4303137c0a PY gravsim: initial coding completed
Finished coding the Python version of the gravity simulator.
No unit tests have been written yet.
Cleaned up documentation in the other languages.
Made some functions static that did not need to be members.
2022-05-22 09:41:44 -04:00
Don Cross
68f118587d PY gravim: work in progress.
Started implementation of the Python gravity simulator.
Updated the `pydown` markdown generator to include
class constructors `__init__` when they contain docstrings.
2022-05-21 23:23:29 -04:00
Don Cross
94589693f5 JS gravsim: finished unit tests, fixed bug
The JavaScript version of the gravity simulator is
now working. I had one bug in the acceleration formula.
Finished the unit tests and also streamlined them a little.
2022-05-19 09:49:37 -04:00
Don Cross
b9db79c6fd JS gravsim: partial completion of unit tests
Implemented half of the GravitySimulator unit tests.
Fixed a bug in the GravitySimulator constructor.

Did some refactoring of test.js:

- Wrote Debug() function as shortcut for conditional output.
- Created generic JPL Horizons state file reader.
2022-05-18 21:14:49 -04:00
Don Cross
26575066fc JS gravsim: work in progress.
Mostly coded, but unit tests not written yet.
2022-05-18 19:52:11 -04:00
Don Cross
f014d13910 C# gravsim: finished implementation.
Unit tests are complete and verified for the C# gravity simulator.
I found and fixed one bug in the GravitySimulator constructor.
2022-05-17 17:20:30 -04:00
Don Cross
019a8f51d4 C# gravsim: first draft of GravitySimulator.Update
Wrote the C# version of GravitySimulator.Update.
Not yet tested.
2022-05-17 15:12:53 -04:00
Don Cross
6a5d04b825 C# gravsim: work in progress
Starting the C# version of class GravitySimulator.
There are no unit tests for it yet.

Added a fix to the C# markdown generator `csdown`
to show `void` as a function return type.
This is the first time I have had any function
in the C# version of Astronomy Engine that has
a void return type!

Fixed and improved documentation in the Kotlin version
of the gravity simulator. Fixed some comments too.
2022-05-17 10:31:42 -04:00
Don Cross
3b98143d52 Forgot to add change to C documentation. 2022-05-16 08:57:16 -04:00
Don Cross
f40b96c237 Kotlin gravsim: finished unit tests.
The Kotlin version of class GravitySimulator is working.
Finished the same unit tests that are present in the C
version of the gravity simulator.
2022-05-15 21:44:22 -04:00
Don Cross
28698cdd6b Kotlin gravsim: some unit tests passing. 2022-05-15 21:08:04 -04:00
Don Cross
b30a54587f Kotlin gravsim: more work in progress.
Added the function GravitySimulator.update().
Not yet tested.
2022-05-15 17:28:18 -04:00
Don Cross
efb59436c1 Kotlin gravsim: work in progress
Started implementing class GravitySimulator,
but it is not finished yet.
2022-05-15 05:02:38 -04:00
Don Cross
026d558fe5 C gravsim: minor code cleanup 2022-05-13 20:17:03 -04:00
Don Cross
636c4196bb C gravsim: added more functions
Added the following functions:

    GravSimTime
    GravSimNumBodies
    GravSimOrigin
    GravSimSwap

The GravSimSwap function allows an instantaneous "undo"
of a simulation step, which required refactoring the internal
data structures of the simulator. I did this because I realized
I needed a way to undo exploration of time steps near a fixed
current time. This will make it easier to implement a
light travel time solver.
2022-05-13 13:38:25 -04:00
Don Cross
d250d17a9f C gravsim: more accurate SSB.
Replaced the piecemeal calculation of solar system
bodies with a unified approach that accounts for
all planets in the SSB calculation. This does improve
accuracy noticeably:

$ ./ctest -v gravsim
C GravSimFile(barystate/Ceres.txt   ): PASS (count = 731, pos error =  0.6640 arcmin, vel error =  0.6225 arcmin)
C GravSimFile(barystate/Pallas.txt  ): PASS (count = 731, pos error =  0.4687 arcmin, vel error =  0.3474 arcmin)
C GravSimFile(barystate/Vesta.txt   ): PASS (count = 731, pos error =  0.5806 arcmin, vel error =  0.5462 arcmin)
C GravSimFile(barystate/Juno.txt    ): PASS (count = 731, pos error =  0.6760 arcmin, vel error =  0.5749 arcmin)
C GravSimFile(heliostate/Ceres.txt  ): PASS (count = 731, pos error =  0.0444 arcmin, vel error =  0.0355 arcmin)
C GravSimFile(heliostate/Pallas.txt ): PASS (count = 731, pos error =  0.1062 arcmin, vel error =  0.0853 arcmin)
C GravSimFile(heliostate/Vesta.txt  ): PASS (count = 731, pos error =  0.1432 arcmin, vel error =  0.1308 arcmin)
C GravSimFile(heliostate/Juno.txt   ): PASS (count = 731, pos error =  0.1553 arcmin, vel error =  0.1328 arcmin)
C GravSimFile(geostate/Ceres.txt    ): PASS (count = 731, pos error =  6.5689 arcmin, vel error =  6.4797 arcmin)
C GravSimFile(geostate/Pallas.txt   ): PASS (count = 731, pos error =  9.3287 arcmin, vel error =  7.3532 arcmin)
C GravSimFile(geostate/Vesta.txt    ): PASS (count = 731, pos error =  3.2980 arcmin, vel error =  3.8862 arcmin)
C GravSimFile(geostate/Juno.txt     ): PASS (count = 731, pos error =  6.0961 arcmin, vel error =  7.7147 arcmin)
C GravitySimulatorTest: PASS (pos score = 9.3287 arcmin, vel score = 7.7147 arcmin)

One curious thing: I don't understand why the heliocentric errors are so small
compared to the barycentric errors. I would have expected the opposite.
This deserves further attention!
2022-05-12 17:39:01 -04:00
Don Cross
f6ae31c619 C gravsim: removed option parameter.
I have decided the ability to select different
collections of gravitating bodies causes far
more complexity in the code than it is worth.

So now the gravity simulator always calculates
the Sun and all planets except Pluto.
This greatly simplifies the core code, gets
a good balance between efficiency and accuracy,
and makes the test matrix much simpler.
2022-05-12 13:35:13 -04:00
Don Cross
3b534bcac1 C gravsim: more efficient GravSimOriginState.
The GravSimOriginState function was doing too
much work for bodies that weren't already calculated
and cached. Instead of always calling Astronomy_BaryState,
it is possible to do a lot less work for most bodies
by recycling the SSB calculation that has already
been done.

Other minor code cleanup -- mostly stuff that makes
the code easier to read and understand.
2022-05-11 13:21:03 -04:00
Don Cross
b2c69ddcfd C gravsim: bug fixes, flexible origin body.
Added an extra parameter `originBody` when creating
a new gravity simulator. This defines the
body center used as a coordinate origin for
both input state vectors and output state vectors.
This allows the caller to do everything in barycentric,
heliocentric, geocentric, or planetocentric coordinates.
This is important to avoid redundant calculations,
since we already have to calculate most/all of the
Solar System bodies anyway.

Fixed a bug: the unit tests were not using the `option`
parameter that was supposed to be passed to
Astronomy_GravSimInit. It was always using the GRAVSIM_ALL_PLANETS
option, which is why the tests always calculated the same answers.

The way I was measuring error was a little dodgy.
I reworked it to work without assuming anything about
the struct layout of astro_state_vector_t in memory.
I also always made it measure relative error converted
into arcminutes, so it is easier for me to understand
the numbers.

There are still excessively large calculation errors
that need to be debugged, so this is a work in progress.

$ ./ctest gravsim
C GravSimFile(0 : barystate/Ceres.txt   ): PASS (count = 731, pos error =  1.8348 arcmin, vel error =  1.7127 arcmin)
C GravSimFile(0 : barystate/Pallas.txt  ): PASS (count = 731, pos error =  1.7055 arcmin, vel error =  1.3432 arcmin)
C GravSimFile(0 : barystate/Vesta.txt   ): PASS (count = 731, pos error =  1.5655 arcmin, vel error =  1.4338 arcmin)
C GravSimFile(0 : barystate/Juno.txt    ): PASS (count = 731, pos error =  1.1724 arcmin, vel error =  0.8732 arcmin)
C GravSimFile(1 : barystate/Ceres.txt   ): PASS (count = 731, pos error =  0.5821 arcmin, vel error =  0.5398 arcmin)
C GravSimFile(1 : barystate/Pallas.txt  ): PASS (count = 731, pos error =  0.4566 arcmin, vel error =  0.3327 arcmin)
C GravSimFile(1 : barystate/Vesta.txt   ): PASS (count = 731, pos error =  0.8185 arcmin, vel error =  0.7616 arcmin)
C GravSimFile(1 : barystate/Juno.txt    ): PASS (count = 731, pos error =  0.3206 arcmin, vel error =  0.2692 arcmin)
C GravSimFile(2 : barystate/Ceres.txt   ): PASS (count = 731, pos error =  0.5821 arcmin, vel error =  0.5398 arcmin)
C GravSimFile(2 : barystate/Pallas.txt  ): PASS (count = 731, pos error =  0.4566 arcmin, vel error =  0.3327 arcmin)
C GravSimFile(2 : barystate/Vesta.txt   ): PASS (count = 731, pos error =  0.8185 arcmin, vel error =  0.7616 arcmin)
C GravSimFile(2 : barystate/Juno.txt    ): PASS (count = 731, pos error =  0.3206 arcmin, vel error =  0.2692 arcmin)
C GravSimFile(0 : heliostate/Ceres.txt  ): PASS (count = 731, pos error =  0.0692 arcmin, vel error =  0.0659 arcmin)
C GravSimFile(0 : heliostate/Pallas.txt ): PASS (count = 731, pos error =  1.0762 arcmin, vel error =  0.8765 arcmin)
C GravSimFile(0 : heliostate/Vesta.txt  ): PASS (count = 731, pos error =  4.6165 arcmin, vel error =  4.2126 arcmin)
C GravSimFile(0 : heliostate/Juno.txt   ): PASS (count = 731, pos error =  1.0013 arcmin, vel error =  0.7634 arcmin)
C GravSimFile(1 : heliostate/Ceres.txt  ): PASS (count = 731, pos error =  1.2524 arcmin, vel error =  1.1585 arcmin)
C GravSimFile(1 : heliostate/Pallas.txt ): PASS (count = 731, pos error =  2.3224 arcmin, vel error =  1.8889 arcmin)
C GravSimFile(1 : heliostate/Vesta.txt  ): PASS (count = 731, pos error =  2.2375 arcmin, vel error =  2.0198 arcmin)
C GravSimFile(1 : heliostate/Juno.txt   ): PASS (count = 731, pos error =  0.4975 arcmin, vel error =  0.4193 arcmin)
C GravSimFile(2 : heliostate/Ceres.txt  ): PASS (count = 731, pos error =  1.2524 arcmin, vel error =  1.1585 arcmin)
C GravSimFile(2 : heliostate/Pallas.txt ): PASS (count = 731, pos error =  2.3224 arcmin, vel error =  1.8889 arcmin)
C GravSimFile(2 : heliostate/Vesta.txt  ): PASS (count = 731, pos error =  2.2375 arcmin, vel error =  2.0198 arcmin)
C GravSimFile(2 : heliostate/Juno.txt   ): PASS (count = 731, pos error =  0.4975 arcmin, vel error =  0.4192 arcmin)
C GravSimFile(0 : geostate/Ceres.txt    ): PASS (count = 731, pos error =  6.5958 arcmin, vel error =  6.5102 arcmin)
C GravSimFile(0 : geostate/Pallas.txt   ): PASS (count = 731, pos error = 11.1674 arcmin, vel error =  8.7643 arcmin)
C GravSimFile(0 : geostate/Vesta.txt    ): PASS (count = 731, pos error = 10.6710 arcmin, vel error = 12.7938 arcmin)
C GravSimFile(0 : geostate/Juno.txt     ): PASS (count = 731, pos error =  7.3953 arcmin, vel error =  9.4322 arcmin)
C GravSimFile(1 : geostate/Ceres.txt    ): PASS (count = 731, pos error =  8.5754 arcmin, vel error =  8.4810 arcmin)
C GravSimFile(1 : geostate/Pallas.txt   ): PASS (count = 731, pos error = 13.2944 arcmin, vel error = 10.4513 arcmin)
C GravSimFile(1 : geostate/Vesta.txt    ): PASS (count = 731, pos error =  7.1130 arcmin, vel error =  8.4571 arcmin)
C GravSimFile(1 : geostate/Juno.txt     ): PASS (count = 731, pos error =  5.5835 arcmin, vel error =  7.0996 arcmin)
C GravSimFile(2 : geostate/Ceres.txt    ): PASS (count = 731, pos error =  8.5754 arcmin, vel error =  8.4810 arcmin)
C GravSimFile(2 : geostate/Pallas.txt   ): PASS (count = 731, pos error = 13.2944 arcmin, vel error = 10.4513 arcmin)
C GravSimFile(2 : geostate/Vesta.txt    ): PASS (count = 731, pos error =  7.1130 arcmin, vel error =  8.4571 arcmin)
C GravSimFile(2 : geostate/Juno.txt     ): PASS (count = 731, pos error =  5.5835 arcmin, vel error =  7.0996 arcmin)
C GravitySimulatorTest: PASS (pos score = 13.2944 arcmin, vel score = 12.7938 arcmin)
2022-05-10 21:20:05 -04:00
Don Cross
b31a66eba8 C gravity simulator: work in progress
Starting implementation of a generalized gravity simulator.
Already calculating the movement of Ceres, but with less
accuracy than I had hoped. I don't know if the lack of modeling
pull of the other asteroids has a larger effect than I expected,
or there is just something wrong with the implementation.
2022-05-09 17:13:51 -04:00
Don Cross
6abce518f6 C#: added iterator helper functions
Added the following iterator functions that wrap
search/next pairs of functions:

    GlobalSolarEclipsesAfter
    LocalSolarEclipsesAfter
    LunarApsidesAfter
    LunarEclipsesAfter
    MoonNodesAfter
    MoonQuartersAfter
    PlanetApsidesAfter
    TransitsAfter

I updated the following C# demos:

    moonphase.cs     ==> MoonQuartersAfter
    lunar_eclipse.cs ==> LunarEclipsesAfter

Fixed an issue in the C# Markdown generator
so that it can now handle generic types like
`IEnumerable<MoonQuarterInfo>`.
2022-05-07 13:02:42 -04:00
Don Cross
5676049596 Kotlin: added iterator helper functions
Added the following iterator functions that wrap
search/next pairs of functions:

    globalSolarEclipsesAfter
    localSolarEclipsesAfter
    lunarApsidesAfter
    lunarEclipsesAfter
    moonNodesAfter
    moonQuartersAfter
    planetApsidesAfter
    transitsAfter

I updated the following Kotlin demos:

    MoonPhase.kt    ==> moonQuartersAfter
    LunarEclipse.kt ==> lunarEclipsesAfter

However, I have not yet figured out how to use these
functions in the corresponding Java demos.
2022-05-06 21:52:27 -04:00
Don Cross
6add6b877a JS: Added enum ApsisKind to replace integers. 2022-05-05 17:11:41 -04:00
Don Cross
5ad71cb702 JS: Replace strings with new enum EclipseKind. 2022-05-05 16:39:51 -04:00
Don Cross
ac7bc9c919 Kotlin: Jupiter's moons returned by name
It makes more sense to report Jupiter's moons with
individually named structure fields rather than an array.
It reduces the overall code and documentation size,
and outside of unit testing, there are few cases
where iterating over an array of moons is more
lucid than using the names of the moons.

This is a breaking change, but hopefully very few
developers are using this function yet.
Fixing the breakage is very simple.
2022-05-05 13:01:19 -04:00
Don Cross
66eeb3e0a0 Python: Jupiter's moons returned by name
It makes more sense to report Jupiter's moons with
individually named structure fields rather than an array.
It reduces the overall code and documentation size,
and outside of unit testing, there are few cases
where iterating over an array of moons is more
lucid than using the names of the moons.

This is a breaking change, but hopefully very few
developers are using this function yet.
Fixing the breakage is very simple.

Also added operator overloads for adding and
subtracting StateVector, just like we already had
for Vector.
2022-05-05 12:39:39 -04:00
Don Cross
af63d1520f JavaScript: Jupiter's moons returned by name
It makes more sense to report Jupiter's moons with
individually named structure fields rather than an array.
It reduces the overall code and documentation size,
and outside of unit testing, there are few cases
where iterating over an array of moons is more
lucid than using the names of the moons.

This is a breaking change, but hopefully very few
developers are using this function yet.
Fixing the breakage is very simple.
2022-05-05 12:10:33 -04:00
Don Cross
50c4099184 C#: Jupiter's moons returned by name
It makes more sense to report Jupiter's moons with
individually named structure fields rather than an array.
It reduces the overall code and documentation size,
and outside of unit testing, there are few cases
where iterating over an array of moons is more
lucid than using the names of the moons.

This is a breaking change, but hopefully very few
developers are using this function yet.
Fixing the breakage is very simple.
2022-05-05 11:38:55 -04:00
Don Cross
2247084943 C/C++: Jupiter's moons returned by name
It makes more sense to report Jupiter's moons with
individually named structure fields rather than an array.
It reduces the overall code and documentation size,
and outside of unit testing, there are few cases
where iterating over an array of moons is more
lucid than using the names of the moons.

This is a breaking change, but hopefully very few
developers are using this function yet.
Fixing the breakage is very simple.
2022-05-05 10:26:25 -04:00
Don Cross
f6cb94d53c Deleted obsolete files. 2022-05-04 21:35:02 -04:00
Don Cross
0151df1b83 Update Kotlin main README, insert version.
Automatically copy the version number from the gradle
settings file into the README. Cleaned up the README.
2022-05-04 21:14:49 -04:00
Don Cross
bdb28eee2e Kotlin demo: rise/set/culmination
Added Kotlin demo to search for rise/set/culmination
of the Sun and Moon.

Enhanced the Time class to allow it to be
directly compared and sorted.
2022-05-03 21:09:56 -04:00
Ebrahim Byagowi
c24d49f742 jvm: Upgrade Java language version to 11 2022-05-03 21:57:57 +04:30