|
Module "history_condition"Class ConditionAn instance of Condition can be thought of as something that can be tested as either true or false at a given time. In the history package, Conditions are used to determine when Tags are to be collected. Generally, the facilities of class Tag are used for most conditions, but in special cases a user may wish to create a complicated condition by using the following classes (each of which is an heir of condition) to create a Condition object which is then used as an argument to method set_condition in class Tag. A condition when evaluated by a call to the method evaluate (cycle, time) actually sets two attributes: state and state_final. The explanation of the purpose of state_final involves the intended use of Class Condition to represent conditions under which items should be sampled. Some conditions, particularly those involving a fixed stride in time, may be false at a particular sample but true later on. In order to ensure that the samples collected represent the full time range, we want to collect a sample at the last time even though it may not be the "tick" on which such a periodic condition is true. However, any condition that has past the last time at which it can be true should not be collected. Thus, state_final is set by each condition in a manner appropriate to its nature. Using a conditionA condition c can be tested at a given cycle/time as follows: c.evaluate (cycle, time) if c.state: ...condition was true... if c.state_final: ...condition true when intended for use as "last" sample Module Constants
Conditions availableThese conditions are all heirs of Condition. A routine set with identical arguments to the constructor can be used to change the condition after creation.
Defining new conditionsTo define a new kind of Condition, inherit from Condition and define a method _value (self, cycle, time) which evaluates the condition at that time and returns a tuple-pair of logical values. The first should be the value of the condition, true or false, at the current time. The second should be true or false under assuming this is the "last" timestep. You can assume that _value (res. _value_last) is called only once for a given cycle number, and that these calls are in increasing order for both cycle and time. Note: Your __init__ routine must call Condition.initialize (self). It is recommended that you also redefine __repr__ and __str__, and name any routine which resets the condition set. |