7. The Model Chooser

7.1. Introduction

The chooser widget and Python interface of the Model object are described in this section. They are needed when a database contains several meshes or several sets of coordinates. When this is not the case, this section can be skipped. It is worth mentioning that the chooser for the Model object is very similar to the chooser of the Field object.

The chooser is a sub-object of the Model object permitting to select or rather choose among the various models and their meshes that may be present in the Model object's database. The chooser can be understood as a sequence of key-value pairs, with the keys being the Model enumerators, and the values being the selected enumerator values. It permits to select which mesh should be loaded.

The keys-value pairs are arranged in a sequence to represent a desired hierarchy (for instance, first the (optimization-)GENERATION, then the (per-generation) VARIANT, then the (computational) DISCIPLINE. This will allow to enumerate the different meshes in that order. Usually, the default hierarchy is sufficient.

7.2. The Graphical User Interface

The chooser widget, which is found on the "Load" page of the Model editor is the graphical interface to the chooser sub-object.

The chooser widget allows for defining the enumerator hierarchy and for selecting enumerator values.

Depending on

  • The datasets present in the database,

  • And the enumerator hierarchy,

the possible enumerator values are determined by the chooser. These values are available in the drop-down combo boxes. The chooser will always allow to select any of the currently possible enumerator values. However, it is not possible to select a non-existent enumerator value. Thus, the choice presented and allowed by the chooser will always be a valid one.

The display level can be set using the drop-down combo box at the upper right of the widget. There are the following display levels:

  • Level 1: Only display those enumerators that allow for choosing between multiple values. This level is the default.

  • Level 2: Additionally display those enumerators allowing for a single value which is not "None".

  • Level 3: Display all enumerators.

7.3. The Python Interface of the Model Chooser

We assume that the variable "m" references a Model object. To obtain the current hierarchy and enumerator values of the chooser sub-object, enter

>>> m.ch
[('GENERATION', 'Iter_001'), ('VARIANT', 'Var_014'), 
 ('DISCIPLINE', 'Wela'), ('MESHCYCLE', None), ('COORCYCLE', None)]


for item in m.ch:
    print item.name    # The enumerator name (key).
    print item.value   # The enumerator value.
    print item.names   # The list of possible names at this level.
    print item.values  # The list of possible values.

Thus, the chooser consists of a sequence of so-called items. These items can be accessed

  • By index:

    >>> print m.ch[2]
    ('DISCIPLINE', 'Wela')


    >>> for i in range(len(m.ch)):
    ...    print m.ch[i]
    ('GENERATION', 'Iter_001')
    ('VARIANT', 'Var_014')
    ('DISCIPLINE', 'Wela')
    ('MESHCYCLE', None)
    ('COORCYCLE', None)
  • By name:

    >>> print m.ch['DISCIPLINE']
    ('DISCIPLINE', 'Wela')

On an item, the name and value can be changed:

  • Setting the value can be done:

    >>> m.ch['DISCIPLINE'].value = 'WT'

    If the value of "WT" is not a valid one, an exception will be raised.

    For enumerators known to baspl++, there is a shortcut:

    >>> m.ch.discipline = 'WT'

For more information on the Python interface of chooser objects, see also Section 4.3.

7.4. Re-Loading

When a change is made to the chooser, this change is by default not immediately reflected on the Model object's data (for performance reasons). It is thus possible to reset the chooser to the previously selected values by pressing the "Reset" button. To make the changes take effect, the "Apply" button in the chooser widget must be pressed, or in the Python environment, assuming that "f" references the mesh object,


has the same effect.

When stepping through different meshes, it can be convenient to have the Model object re-loading automatically when the cycle changes. This is achieved by ticking the Synchronized check box in the chooser widget. From the Python environment:

f.ch.synchronized = True

The Model object will now be re-loaded automatically each time a value of the chooser's enumerators is changed, and it is no longer necessary to call the load() function.