Units in GMAT

Development related to the GMAT core and GUI

Units in GMAT

Postby aero9600 » Fri Jan 23, 2009 3:41 am

I'm working on providing a mechanism to define an internally consistent set of units in GMAT. By the same token, this will allow for sanity checks for implementing user-defined data and reading in data from various sources. My current problem is the following: When estimating an orbit, the estimator class is set up to blindly accept data from the file reader class and use it to compute the difference between the observed value and the expected(modeled) value. There is no way currently for GMAT to decide if the observation data needs to be converted into a different set of units before taking the difference in the values.

First off, I'm assuming initially that everything will be grounded upon the SI base units (length, time, mass, electric current, temp, amount of substance, luminous intensity, and dimensionless). In the odTools branch, I have created a new GmatUnits class that has the SI base units enumerated along with the known named derived units [frequency (Hertz), angle (rad), force(Newtons), pressure(Pascals), Energy(Joules), etc etc] and the "other" derived units [area (length^2), volume(length^3), velocity(length/time), acceleration(length/time^2), density(mass/length^3), etc etc].

Somewhere we will need to create a units environment variable that establishes exactly what the base units will look like. That is to say, the base length unit will be set to kilometers, the base time unit will be seconds, the base temperature unit will be Kelvin, etc. The user should be able to override these choices in the script by changing the global environment variables as well as at the report/plot level specify the desired output units for a given variable. I'm not sure where the best place to accomplish this. Thoughts?

Currently my plan is to have the newly created GmatUnits class store information about the units of a variable, how to display the units (either in the GUI or in output reports), compare units with one or more variables, and calculate conversions from one form to another on the fly. My idea for implementing inside the GMAT code would look similar to the following. Define a variable and it's units:

Real myVelocityVariable = 7.123456;
GmatUnits myVelocityUnits("velocity");

This would initialize a number of protected/private variables using the pre-defined enumerations. For example, "velocity" is a defined keyword that tells GMAT that the SI base units are length in the numerator and time in the denominator. Furthermore, the global environment variables state that length is in kilometers and time is in seconds. Therefore, if the user did nothing else, GMAT would assume that the value of myVelocityVariable is in kilometers per second.

The user will be able to use one of these keywords or, alternatively, a user could create a user-defined unit using the SI base units.

Real myUniqueVariable = 1.3525e-15;
StringArray unitsNumerator = ("mass","length");
StringArray unitsDenominator = ("time");
GmatUnits myUniqueUnits.SetUnits(unitsNumerator,unitsDenominator);

The only problem with the above suggested code is that there is nothing physically connecting myVelocityVariable with myVelocityUnits. I think it would be beneficial if the typedef of Real and Integer could somehow be converted to a struct that contains the actual numerical value and a new GmatUnits variable. This way every Real and Integer throughout GMAT would automatically be provided with a container for units without reprogramming anything. Is this even possible? If so, then the suggested code above would change to something like the following:

Real myVelocityVariable = 7.12345;
myVelocityVariable.Units = "velocity";

Another question is how would one specify that a velocity value is in nanometers per year as opposed to the defined environment unit of kilometers per second. Well, I'm proposing that the user would do something like the following:

Real myVelocityVariable = 7.12345e9;
myVelocityUnits = "velocity";

The idea here is that the "prefix" is one of the enumerated Greek variables representing order of magnitude such as kilo,micro,Giga,Mega, etc. which can be accomplished be adding/subtracting integer numbers to/from the unit powers value internal to the GmatUnits class. Whereas specifying years instead of seconds requires a conversion that can be looked up/calculated and applied. I'm assuming here that changing the LengthPrefix and calling the ConvertTime function will change the value of myVelocityVariable into kilometers per second so that all variables will be internally consistent after that point and further unit checking will not necessarily be required at every calculation step.

I'd appreciate any thoughts and comments you might have on implementing all of this.
Posts: 54
Joined: Mon Jun 09, 2008 6:59 pm

Re: Units in GMAT

Postby aero9600 » Mon Feb 23, 2009 9:45 pm

I had another thought that will most likely solve all the issues that I brought up before. I think that we should establish a way for the units of a given variable to be registered/published in a global list. When sanity checks are needed, the global units registry is checked. If units have been published then they can be checked against the desired/required units and any conversion can be completed if necessary. If the units have not been published, then either nothing happens (ie. the code proceeds assuming everything is ok) or a warning can be printed saying that the units sanity check was not able to complete due to lack of information.
Posts: 54
Joined: Mon Jun 09, 2008 6:59 pm

Return to Core Development

Who is online

Users browsing this forum: No registered users and 2 guests