I can propose a first extension of the schema in order to support user-defined functions.
The solution provides two modules, one for the functions and one for the algorithm.
FUNCTIONS:
- Function can be embedded in the XML document or external defined;
- EXTERNAL functions have attributes "name" and "language" (C, Modelica)
- EMBEDDED functions are designed with name (attribute), list of output, input, protected variables (with "type" and "default value" attributes) and algorithm; every of these sections is optional;
- it is optionally possible to define a set inverse and derivative of a functions as additional elements of "Function";
- INVERSE functions should be allowed only with one output variable and at least one input variable is necessary. The output of the inverse function should be an input of the original function and the output of the original function should be input variable of the inverse;
- DERIVATIVES of a function must have at least one output and one input variable. Input variables have the additional attributes "derived" ,"zeroDerivative", both defined as boolean, and "order" defined as integer. If derived=true then the function is derived with respect of that variable; the function is differentiated with respect of the variables in the same order they are defined (from the first to the last); if a variable has derived=true, it should also be of Real type. The derivative function is only valid if variables with zeroDerivative=true are independent of the variables the function is differentiated with respect to (i.e. the derivative of that input variable is "zero"); the attribute "order" defines the order of the derivative with respect of that variable and the default value is 1;
- an element FunctionsList is defined as an unbounded list of the previous discussed functions (embedded and external). This element will be referred by the main schema.
ALGORITHMS:
the following statements are supported:
- ASSIGN, identifier=expression;
- BREAK, that shall be used in while and for loops only;
- RETURN;
- IF, with optional (0-unbounded) elseif and (0-1) else branches. The else branch is the one taken in account if all the other conditions are not satisfied. Each branch is defined by a condition expression and a list of statements, except Else that has not condition;
- WHILE, defined by condition expression and list of statements;
- FOR loop, defined by an index and the list of statements. The index is an identifier and has the attributes StartValue, FinalValue (required) and Step (optional, 1 by default);
- FUNCTION CALL statement with the name of the called function and the list of arguments (expressions)
- ASSERTION, with a required condition (expression) and an optional message. The assertion has an optional attribute "level" that can have value "error" (default) or "warning". If level=error then the algorithm should not be executed, if level=warning the warning message is returned but the algorithm should not be skipped
Vectors and records aren't supported,at least for this first draft.
ADDITIONAL FUNCTION CALL EXPRESSION
- an expression FunctionCall has been added to the expression definition. A function call should return one value only, in order to be used in the expression. The function call is defined by the name of the function (attribute) and a list of arguments (expression type)
ADDITIONAL EQUATIONS
The list of dynamic equations has been updated, adding the element FunctionSetEquations. This element contains the equations due to the functions and it's defined by a list of output variables and a function call named as "SourceFunction". The name "set" is to remind that the element defines a set of scalar equations, one for each output variable.
In attach the updated schema modules for expression, equations, algorithms, functions, plus some graphical representations of the key elements.
Best
Roberto