FGFunction Class Reference

#include <FGFunction.h>

Inherits FGParameter.

List of all members.


Detailed Description

The FGFunction class is a powerful and versatile resource that allows algebraic functions to be defined in a JSBSim configuration file. It is similar in concept to MathML (Mathematical Markup Language, www.w3.org/Math/), but simpler and more terse. A function definition consists of an operation, a value, a table, or a property (which evaluates to a value). The currently supported operations are:

An operation is defined in the configuration file as in the following example:

  <sum>
    <value> 3.14159 </value>
    <property> velocities/qbar </property>
    <product>
      <value> 0.125 </value>
      <property> metrics/wingarea </property>
    </product>
  </sum>

A full function definition, such as is used in the aerodynamics section of a configuration file includes the function element, and other elements. It should be noted that there can be only one non-optional (non-documentation) element - that is, one operation element - in the top-level function definition. Multiple value and/or property elements cannot be immediate child members of the function element. Almost always, the first operation within the function element will be a product or sum. For example:

<function name="aero/coefficient/Clr">
    <description>Roll moment due to yaw rate</description>
    <product>
        <property>aero/qbar-area</property>
        <property>metrics/bw-ft</property>
        <property>aero/bi2vel</property>
        <property>velocities/r-aero-rad_sec</property>
        <table>
            <independentVar>aero/alpha-rad</independentVar>
            <tableData>
                 0.000  0.08
                 0.094  0.19
            </tableData>
        </table>
    </product>
</function>

The "lowest level" in a function is always a value or a property, which cannot itself contain another element. As shown, operations can contain values, properties, tables, or other operations. In the first above example, the sum element contains all three. What is evaluated is written algebraically as:

 3.14159 + qbar + (0.125 * wingarea) 

Some operations can take only a single argument. That argument, however, can be an operation (such as sum) which can contain other items. The point to keep in mind is that it evaluates to a single value - which is just what the trigonometric functions require (except atan2, which takes two arguments).

Author:
Jon Berndt

Definition at line 149 of file FGFunction.h.


Public Member Functions

void cacheValue (bool shouldCache)
 Specifies whether to cache the value of the function, so it is calculated only once per frame.
 FGFunction (FGPropertyManager *PropertyManager, Element *element, string prefix="")
 Constructor.
string GetName (void) const
 Retrieves the name of the function.
double GetValue (void) const
 Retrieves the value of the function object.
string GetValueAsString (void) const
 The value that the function evaluates to, as a string.
virtual ~FGFunction ()
 Destructor.

Constructor & Destructor Documentation

FGFunction ( FGPropertyManager PropertyManager,
Element element,
string  prefix = "" 
)

When this constructor is called, the XML element pointed to in memory by the element argument is traversed. If other FGParameter-derived objects (values, functions, properties, or tables) are encountered, this instance of the FGFunction object will store a pointer to the found object and pass the relevant Element pointer to the constructor for the new object. In other words, each FGFunction object maintains a list of "child" FGParameter-derived objects which in turn may each contain its own list, and so on. At runtime, each object evaluates its child parameters, which each may have its own child parameters to evaluate.

Parameters:
PropertyManager a pointer to the property manager instance.
element a pointer to the Element object containing the function definition.
prefix an optional prefix to prepend to the name given to the property that represents this function (if given).

Definition at line 47 of file FGFunction.cpp.


Member Function Documentation

void cacheValue ( bool  shouldCache  ) 

If shouldCache is true, then the value of the function is calculated, and a flag is set so further calculations done this frame will use the cached value. In order to turn off caching, cacheValue must be called with a false argument.

Parameters:
shouldCache specifies whether the function should cache the computed value.

Definition at line 210 of file FGFunction.cpp.

double GetValue ( void   )  const [virtual]

Returns:
the total value of the function.

Implements FGParameter.

Definition at line 222 of file FGFunction.cpp.

string GetValueAsString ( void   )  const

Returns:
the value of the function as a string.

Definition at line 321 of file FGFunction.cpp.


The documentation for this class was generated from the following files:

Generated on Tue May 26 00:55:10 2009 for JSBSim Flight Dynamics Model by  doxygen 1.5.5