User:DanteStroe

From ASCEND
(Redirected from Dante Stroe)
Jump to: navigation, search

Dante Stroe

Proposal: http://socghop.appspot.com/student_project/show/google/gsoc2009/ascend/t124021684017

Mentor: Ben Allan.

Subversion branch: dante:

Detailed plan

By mid-term review:

  • 18/06/2009
  • Completed the parser modifications s.t. ASCEND now understands "LINK('key',a,b)" syntax, where 'key' is the key that links identifies the set of instances "a" and "b" inside the the link table. The test model z-link.a4l has also been modified.
  • Added a Link table object (struct link_table_t) to the model instance type that will store the aforementioned links. The link table is in fact a "gl_list" where each entry in the list represents a pointer to a "LINK" entry that is currently defined in the following way:

/**
  * DS: Entry in the Link table (which is in fact a list) associated with each model

  * instantiator.
  */
  struct link_entry_t {

    union {

      struct Statement * statptr; /* pointer to the declarative statement */
      struct VariableList * vl; /* used if the we use the GUI to LINK, otherwise NULL */

    } u;
    struct gl_list_t *instances_cache;    /**< (cache) pointer to the list of instances that are linked*/

    symchar* key_cache;                   /**< key that defines the linked instances */
    unsigned long length;   /**< Number of instances in the linked_instances list. */

    unsigned long capacity; /**< Capacity of the link entry, in terms of the number of the instances that can be linked. */
    unsigned int flags;     /**< Status flags.used to differentiate between LINK statements in the declarative part(FIXED) and the ones in the methods (not fied). */

  }
  • This is defined as part of the TypeDescription class. where the "link_table" is declared as an attribute as part of the ModelArgs union element of the TypeDescription:

struct ModelArgs {
   struct gl_list_t *link_table; /**< pointer to the table of "LINK" relationships of the model*/

 ....

Instantiation and LINK statements

  • Additions to the "instantiate" class can be followed at this rev diff
  • In order for LINK statements to have consistent instances in the ENTRIES, they have to be instantiate only after all the models, relations, logical statements and "when" statements have been instantiated. (Otherwise we run the risk of having the Link statements invalid after the instantiation a re-instantiation procedures are carried on).
    • Compiler initially had 5 instantiation/re-instantiation phases, and now it has 6 :
      • 1. Models (instantiate models and disregard any other type of statements)
      • 2. Relations (instantiate "relations" and disregard any other type of statements)
      • 3. Logical Statements (instantiate logicals and disregard any other type of statements)
      • 4. When Statements (instantiate "when"s and disregard any other type of statements)
      • 5. LINK Statements (instantiate LINKS and disregard any other type of statements) - Added
      • 6. default (visit instance tree once more and if it is the case warn about any un-executed statements).

For the purpose of adding this new "LINK" phase in the instantiation procedure the following functions were added. They were implemented and documented in a similar fashion (if the case) with respect to the other instantiation functions:

  • These functions set the bits such that the following functions only execute the LINK statements, as well as the FORs and select(re-evaluate) statements that contain LINKs.

void Pass5SetLinkBits(struct Instance *inst)

struct Instance *Pass5InstantiateModel(struct Instance *result, unsigned long *pcount)
  • By now the pass5pendings was already set by silent visit to the instance tree. (which means we updated the pending instances from the last phase)

void Pass5ProcessPendingInstances(void)
  • Try to execute all the LINK statements in instance work. It assumes that work is the top of the pending instance list. Will skip all non-LINK statements. (Note: Only models get here)

static void Pass5ExecuteLinkStatements(struct BitList *blist, struct Instance *work, int *changed)
  • Statement processing. We are processing just the LINK statements that are stand-alone as well as the ones inside FORs (That's what we should be left with anyway, since this is the last phase of instantiation). This Executes each LINK with "ExecuteLNK(instance,statement)" function and each FOR that contains a LINK with "Pass5ExecuteFOR(instance,statement)" (this only executes the LINKs inside the FOR)

static int Pass5ExecuteStatement(struct Instance *inst,struct Statement *statement)
  • This is where all the sanity checks are done for the LINK statement and parameters correctness aw well as the addLinkEntry function is called for the given model.

int ExecuteLNK(struct Instance *inst, struct Statement *statement)
  • Near future tasks:
    • Implement the rest of functions present at [1]
    • Unit testing of the all the functions implemented
    • At this point ascend should be able compile models with "LINK" syntax and store it
    • Regression testing and making sure committed code is properly documented

By final review:

  • Initial value modeling
    • Modify the DAE solver implementation to make use of the newly implemented "LINK" relationship, however in the form of DERIV(dx_dt,x) . (Note: this implies that "t" is declared as the independent variable in use beforehand, and the compiler should know this until instructed otherwise). This relation would inherit/extend the LINK relationship. See Improved DAE syntax.
    • Add functionality to relation classes, to make use of the Link information present for given instances in the case of derivatives. Need
    • Testing and documentation
  • Update on completed tasks:
    • Finished and corrected implementation of testing suite for the LINK syntax (in general) : dante:models/test/z-link.a4c. The file also contains some fail cases and a special LINK type with key 'testSuite' that runs a procedure to test the functions described in LINK
    • Created 'ode' type LINKS that are defined by the 'ode' key and a list of instances out of which, currently, the last one is the independent variable, whereas the rest are the differential variable in decreasing order. Ex:

LINK('ode',dx_dt,x,t);
    • The derivative chains declared in LINK can be arbitrarily long, however the solver does not handle more than 2nd order derivatives
    • The "ode" LINKS can be declared in both the declarative and procedural part of the model.
    • If multiple derivative chains are declared, they must all have the same independent variable, otherwise the user is prompted with an error message.
    • The LINKs don't make use of the .ode_type/ode_id attributes of the instances, but rather, the LINK structure. This implies that if one variable is present in two or more derivative chains, there is no longer the need to declare additional variables.
      • The implementation was done in ascend/ascend/system/analyze.c" for the solver and "ascend/ascend/integrator/integrator.c" for the integrator. For this purpose the follwing external functions were implemented in "\ascend\ascend\compiler\link.c":

extern int getOdeId(struct Instance *model,struct Instance *inst);

extern int getOdeType(struct Instance *model,struct Instance *inst);

The functions return the ode_type and ode_id (as in prev syntax) of a given variable in a model from the LINK table structures, if the variable pertains to any derivative chains.

  • The following model is not yet functional, due to the fact that the instances that are vector elements inside LINKs, which are inside a "FOR", are not properly evaluated. (currently working on that):
  • Other feasible targets this week:
    • Implement "INDEPENDENT t" type syntax for the independent variable of the derivative chains, with the restriction of having only a single declaration of this type in a model. This implies that the independent variable will no longer have to be declared inside the 'ode'-type LINKs. This would be implemented by using the LINK structure as well.
    • Replace the "LINK('ode',dx_dt,x)" type of syntax, with DER(dx_dt,x).(To be agreed if this is smth desirable or LINK is enough for now)
    • update: since the latest commit, changeset 2570, the following block of code:

LINK('ode',dx_dt,x,t);

DER(dx_dt,x);
INDEPENDENT t;
  • either of the two new statements can be declared in any order and in any part of the model as with LINK; The example models have also been updated with the new syntax.