Special_Shape_Data_Syntax - nasa/gunns GitHub Wiki

{{>toc}}

Special Shape Data Syntax and Tricks

Most shape data values for links in GunnShow are primitive types, like int, double, etc. There are also some fancier types that require special ways to initialize. This page discusses these special types.

The important thing to remember is that every shape data value in a GunnShow drawing is an argument to a C++ object constructor call, with all the syntax rules that apply.

A link’s shape data fields in the GunnShow drawing get exported as arguments to the link’s config or input data class constructor within the initializer list of the network’s config or input data constructor. For instance, a hypothetical Network class’s config data class is called NetworkConfigData, and its constructor looks something like this when exported from GunnShow:


NetworkConfigData::NetworkConfigData(const std::string& name, Network* network)
    :
    Link1ConfigData(name + ".Link1", &network->netNodeList, <Link1ShapeData>, <Link1ShapeData>, ...),
    Link2ConfigData(name + ".Link2", &network->netNodeList, <Link2ShapeData>, <Link2ShapeData>, ...),

Enumerations

Enumerated types within GUNNS are usually class-scoped within their respective classes. We try to avoid using global enumerations because of the risk of name collisions. In GunnShow shape data, you usually have to class-scope the enum value as Class::Value. For instance, the GunnsFluidExternalSupplyConfigData class has a member FluidProperties::FluidType mConvertToType. When assigning this shape data value, you must scope it with the FluidProperties class, such as: FluidProperties::GUNNS_N2.

Non-Primitive Objects

Some links have shape data attributes that are themselves class objects. For instance, BatteryElectNiHConfigData has a term SensorAnalogConfigData mVoltageSensor:


class BatteryElectNiHConfigData : public GunnsBasicLinkConfigData
{
    public:
    ...
    SensorAnalogConfigData mVoltageSensor; /**< (--) trick_chkpnt_io(**) voltage sensor config data*/

    /// @brief Default Battery Elect Configuration Data Constructor
    BatteryElectNiHConfigData(
        ...
        const SensorAnalogConfigData voltageSensor = SensorAnalogConfigData(-999.0,999.0),
        ...
    );

Note that the default value for the class constructor is a SensorAnalogConfigData object constructor. This is the same syntax you use in the GunnShowShapeData:

You are literally constructing the imbedded config or input data object directly inside the link’s config or input data constructor call. You can specify different values for the imbedded object’s constructor arguments as desired.

Object Pointers and References

Some links have pointers or references in their Config or Input shape data that are intended to point to another object.

References (denoted by a & in their type) must be set to the name of another object in the network or drawing, or defined inline as described above.

Pointers (denoted by a * in their type) can either be set to the address of another object in the network or drawing, or left 0 (NULL) in the drawing and set later via the Trick Input File (like Array Pointers below). Here is an example of several SensorAnalogConfigData object pointers in the SwitchCardElect link shape data:

Array Pointers

Some links have pointer types in their Config or Input shape data that are intended to point to an array of values. For instance, GunnsFluidExternalSupplyInputData has a term double* mDemandMassFractions:


class GunnsFluidExternalSupplyInputData : public GunnsFluidSourceInputData
{
    public:
        double  mDemandTemperature;   /**< (K)  trick_chkpnt_io(**) Initial demand temperature */
        double* mDemandMassFractions; /**< (--) trick_chkpnt_io(**) Initial demand mass fractions */
        /// @brief    Default constructs this Fluid External Supply input data.
        GunnsFluidExternalSupplyInputData(const bool    malfBlockageFlag    = false,
                                          const double  malfBlockageValue   = 0.0,
                                          const double  flowDemand          = 0.0,
                                          const double  demandTemperature   = 0.0,
                                                double* demandMassFractions = 0);

In GunnShow, the pointer’s shape data looks like this, with its default 0 (NULL) value:

There are several ways to initialize such arrays. The recommended way is less convenient, but safer. The more convenient ways produce memory or Valgrind errors and are not recommended here, but we note them anyway in case you like to live dangerously.

Recommended Initialization

  • In the GunnShow drawing, leave this pointer value 0, as shown above.
  • In the Trick Input File, allocate and initialize a new array of the correct type and size, and then point the link’s shape data pointer to the newly allocated Trick array, as follows:

    # Declare and have Trick allocate memory for a new array, in this example a double[2]:
    array = trick.alloc_type(2, "double")

    # Initialize the desired array values:
    array = [0.4, 0.6]

    # Assign the link's shape data pointer to the array:
    mySimObject.myNetwork.netInput.myLink.mDemandMassFractions = array

Other Initializations

These are NOT RECOMMENDED — use at your own risk!

Inline define a new array directly in the GunnShow shape data like so:

The resulting exported network code looks like this:


MyNetworkInputData::MyNetworkInputData(MyNetwork* network)
    :
    ...
    myLink(false, 0.0, 0.0, 0.0, (double []) {0.4, 0.6}),
    ...

This is convenient because you don’t need the Trick Input File. The reason I don’t recommend this is that in our unit test framework, it compiles and works, but Valgrind reports many memory errors. This is with the C++98 standard which we still adhere to. In C++11, there are better and safer ways to do this.

Non-GunnShow Terms

Some GUNNS classes have Config or Input data that can’t be set from the GunnShow drawing:

class type attribute description
GunnsBasicLinkInputData int* mInitialNodeMap All links’ input data have this array of port node assignments. It is an array pointer and should be set via the Trick Input File as described above. If left to its default NULL, it has no effect. If it is pointed to an array, the array values override the GunnShow drawing connections for which nodes each port connects to. For instance, allocating and pointing this term to an int 2 {4, 15} will connect the link’s port 0 to Node 4, and port 1 to Node 15. The array size must match the number of link ports.
⚠️ **GitHub.com Fallback** ⚠️