EBSILON®Professional Online Documentation
EbsScript / Kernel Scripting
In This Topic
    Kernel Scripting
    In This Topic

    Kernel Scripting


    An EbsScript is normally executed in the EBSILON®Professional-user-interface. The EBSILON®Professional calculation kernel can be called from the EbsScript, (via commands like "simulate" or "validate"), the calculation takes place with the parameters, as they were set before calling the calculation kernel. While the calculation kernel is calculating, neither the EbsScript nor the user has an access (even a cancellation is not possible during this). The control is given back to the EbsScript only after the calculation has ended.

    However, with the help of Kernel Scripting, it is possible to have a direct access in the course of the calculation. Component 93 ("Kernel Scripting") is used for this. The behaviour of this component can be programmed by the user by using an EbsScript and the functions  defined in the interface-unit KernelScripting. With this function one has access to the values of pipelines and components in each iteration step. The values of the output lines of component 93 can be set by using these function too.

    Like each component component 93 can be inserted several times into a model too. Thereby, a different EbsScript can be used for each component 93, so that several different components can be created.

    With component 93 you can alternatively

    a) set the results of the output pipelines directly or

    b) define a complete set of equations.

    - With mode "setting the results of the output pipes": Use function ksSetPipeValue - the specification value FDEFEQN has to be set to 1

    - With mode "Define Equations": Use functions ksAddEquation, ksSetEquation  -  the specification value FDEFEQN has to be set to 0

    The functions to set the fluid data of the output pipes ksSetPipeFluidData and fluidSetAnalysis can be used always.

    The calculation kernel of EBSILON®Professional works in a way, in which all the components are called one by one and are initialized first. In this step, the function returns

    - ksGetMode ;  (see below)  the value  "Initializing". 


      The calculation phase starts after the initialization is complete. In this phase, the function 

    - ksGetMode;   returns the value "Calculating".

       Since the solution takes place in iterations, this phase extends itself over many iterations steps.
       The number of the ongoing iteration step can be queried with the function: 

    - ksGetItNo;

      In each iteration step, first all the components are called one by one and set their equations for the matrix.

     After all components have set their equations, the equation system is solved, and then the next iteration step is done, till the convergence criteria are fulfilled or else the maximum number of iterations has been exceeded. Thereafter, all components are called again one by one. In this concluding step, the function ksGetMode returns the value "Finishing". This step can be used to calculate the component result values.


    - ksGetMode returns the value "Finishing".

    This step can be used to calculate the component result values.

    Within the component 93 there is an EbsScript Editor present in the tab "Script" of the properties window. There are special functions for accessing the internal course of the calculation, which are defined in the unit "KernelScripting". This unit must be linked with the line

    uses @KernelScripting;
    
    

    at the start of the script. The "@" before the unit name acts as an identification for an Interface-Unit.  Such an Interface-Unit does not have its own implementation within EbsScript, but instead is implemented directly in EBSILON®Professional. In case of normal EbsScript units created by the user, the identification of the unit must match the name in the EbsScript Explorer and cannot start with "@".

        

    The unit KernelScripting has the following functions: 

    GENERAL FUNCTIONS

    discontinue;  

    arguments:   none
    return value: none

    Purpose of the function:

    The function "discontinue" allows a break in the EbsScript execution in the KernelScripting. The EbsScript will be continued in the next iteration step at the same position. This feature allows to keep local variables:

    Example:

    uses @KernelScripting;
    
    var
    
    i:integer;
    
    begin
    
    i:=1;
    
    while (true) do
    
    begin
    
    println("Step ",ksGetItNo(),": i=",i);
    
    i:=2*i;
    
    discontinue;
    
    end;
    
    end.
    

    In this EbsScript, there is an infinite loop (while (true)). The execution of this loops is interrupted by the "discontinue" command. In the next iteration step, the program execution continues at this position. The execution is finally terminated at the end of the simulation. The next simulation run will start again from the beginning.
    The example yields the following output:

    Step 1: i=1
    
    Step 2: i=2
    
    Step 3: i=4
    
    Step 4: i=8
    
    Step 5: i=16
    
    Step 6: i=32
    
    Step 7: i=64
    
    Step 8: i=128  
    

    ...

     

    ksGetComp : ebsComp93

    Arguments : none
    Return value: EBSCOMP93: active component 93

    Purpose of the function: Returns the current component 93 being processed (as object of the data type ebscomp93)
     

    ksGetFPROG : INTEGER

    Arguments : none
    Return value: INTEGER

    Purpose of the function: Returns the program index, i.e. the value of the specification value FPROG.

    ksGetItNo : INTEGER

    Arguments : none
    Return value: INTEGER

    Purpose of the function: Returns the number of the current iteration step.

    ksGetMode : Mode

    Arguments : none
    Return value: INTEGER: Mode

    Purpose of the function:

    Returns the mode, in which the calculation kernel is currently present:

    Depending on the calculation phase Mode : Value "Initializing"

    initializing (1)      in the initialization phase,

    calculating (2)     during the calculation iterations,

    finishing (3)         in the finishing phase

    auxiliary-call preiteration (4)  help call pre-iteration

     

    ksGetRES (index:Integer) : REAL

    Arguments:  INTEGER: Index (specified result value)                                                                                               
    Return value: REAL: Result value

    Purpose of the function: Returns the value of the result value identified by the index.

     

    procedure ksSetRES (index:Integer; value:Real)

    Arguments:  INTEGER: Index (specified result value)
                         REAL: value
    Return value: none

    Purpose of the procedure: Sets the value of the result value identified by the index.

     

    ksGetSPEC (index:Integer) : REAL

    Arguments:  INTEGER: Index (specified specification value)                     
    Return value: REAL: specification value

    Purpose of the function: Returns the value of the specification value identified by the index.

     

    procedure ksSetSPEC (index:Integer; value:Real)

    Arguments: INTEGER: Index (specified specification value)
                       REAL: specification value   
    return value: none

    Purpose of the procedure: Sets the value of the specification value identified by the index.


    ksGetAccuracyCurrentStep():IterationStepAccuracyType

    Arguments: none                                                                                                           
    Return value: IterationStepAccuracyType

    Purpose of the function: Return the current convergence

     

    ksGetAccuracyTrend():array of IterationStepAccuracyType

    Arguments: none                                                                                                             
    Return value: ARRAY of IterationStepAccuracyType
    Purpose of the function: Returns convergence trend (current convergence at the end of the array)


     

    FUNCTIONS FOR SETTING / GETTING THE CONDITIONS / FLUID PROPERTIES

    ksCopyPipe( source, dest:Integer; copyValues:Boolean = False; copyFluidData:Boolean = True ):Boolean;

    Arguments:  INTEGER: source, dest  
                         BOOLEAN = False: copyValues 
                         BOOLEAN = True: copyFluidData                                                                                                                                                                                                                         

    Return value: BOOLEAN: False / True

    Purpose of the function: Purpose of function: Copy physical values (Default: Off), Fluid specifications (Default: On)

     

    procedure ksGetPipeFluidData (index:Integer; var fluidData:FluidData; definedBy:CompositionDefinedByEnum = CompositionDefinedByMass)

    Arguments: INTEGER: Index (designated pipe)
                       FLUIDDATA: var fluidData
                       CompositionDefinedByMass =CompositionDefinedByEnum (Definition of the composition) 
    Return value: none

    Purpose of the procedure:

    Returns the fluid data (material composition and material-specific quantities) on the inlet line identified by the index.
    FluidData is a data structure (record) defined in the unit KernelScripting.

     

    procedure ksSetPipeFluidData (index:Integer; const fluidData:FluidData; definedBy:CompositionDefinedByEnum = CompositionDefinedByMass)

    Arguments: INTEGER: Index (designated pipe)
                        FLUIDDATA: const fluidData
                        CompositionDefinedByMass =CompositionDefinedByEnum (Definition of the composition) 
    Return value: none 

    Purpose of the procedure:

    Sets the fluid data (material composition and material-specific quantities) on the outlet line identified by the index. FluidData is a data structure (record) defined in the unit KernelScripting. These data must always be set completely. This function can be used only for an outlet pipe.

     

    ksGetPipeValue (index:Integer; physValue:PhysValue) : REAL

    Arguments:  INTEGER: Index (designated line)
                         PHYSVALUE: physValueM (for mass flow),
                                                  physValueP (for pressure),
                                                  physValueH (for enthalpy)
    Return value: REAL: PhysValue

    Purpose of the function:

    Returns the value of the size PhysValue on the line indicated by the index. PhysValue can set the values PhysValueM (for mass flow), PhysValueP (for pressure), PhysValueH (for enthalpy. Other thermodynamic parameters such as temperature or entropy are not available at this point because they do not work for all lines due to time constraints be calculated in each iteration step.
    However, if needed, they can be calculated using property functions such as waterSteamTable within the EbsScripts.

     

    ksSetPipeValue (index:Integer; physValue:PhysValue; value:Real)

    Arguments:  INTEGER: Index (designated result value)
                         PHYSVALUE: physValueM (for mass flow),
                                                physValueP (for pressure),
                                                physValueH (for enthalpy)          
                         REAL: Value
    Return value: none

    Purpose of the function:

    Sets the value of the PhysValue variable on the line designated by the index. This function can be used only for output lines.

    Only mass flow (PhysValueM), pressure (PhysValueP) and enthalpy (PhysValueH) can be set.

    For example, with six input lines, output line 1 has port number 7.

    No values need to be specified for output lines that are not connected in the model. However, if they are used, all values must always be specified.

    This also applies to logic lines, electrical lines and mechanical shafts. Which value is set here for the pressure is not important. For the mass flow, however, M=1 must be set here, since the power is calculated as the product of mass flow and enthalpy. To set the power, H can then be set to the value of the power.

    Note that, as usual in EbsScript, the KernelScripting always works with the Ebsilon standard units (bar, °C, kg/s, kJ/kg, kW, ...).

     

    ksGetGlobalMaxTimeInterval:(time:Real)

    Arguments: none
    Return value: REAL: global max. residual terms

    Purpose of the function:

    Return global (model) maximum residual terms (minimum over the residual terms of all time-limiting components in seconds) (only for time series calculations)

     

    ksGetMaxTimeInterval: REAL

    Arguments: none
    Return value: REAL: global max. residual term of the current Component 93

    Purpose of the function: maximum residual term of the current Component 93 (only for time series calculations)

     

    procedure ksSetMaxTimeInterval: (time:Real)

    Arguments:     REAL: time
    Return value:   none
    Purpose of the procedure: Sets maximum residual term of the current Component 93 (only for time series calculations)

     

    procedure ksGetPipeUniversalFluid:( index:Integer; var universalFluid:UniversalFluidType; definedBy:UniversalCompositionDefinedByEnum = UniversalCompositionDefinedByMass );

    Arguments:   INTEGER: Index 
                          UniversalFluidType: var UniversalFluid
                          UniversalCompositionDefinedByEnum = UniversalCompositionDefinedByMass: definedBy
    Return value:   none

    Purpose of the procedure: Reads Universal Fluid data from the specified port (index).

     

    procedure ksSetPipeUniversalFluid: ( index:Integer; const universalFluid:UniversalFluidType; definedBy:UniversalCompositionDefinedByEnum = UniversalCompositionDefinedByMass )

    Arguments:    INTEGER: Index 
                          UniversalFluidType: const UniversalFluid 
                          UniversalCompositionDefinedByEnum = UniversalCompositionDefinedByMass: definedBy
    Return value:  none

    Purpose of the procedure:  Writes universal fluid data to specified port.

      

    These old functions or procedures:

    are still also available for compatibility reasons, but differ from the new functions KsGetPipeFluidData, KsSetPipeFluidData, KsGetPipeValue und KsSetPipeValueksGet only in the indexing of the pipe. While in case of the new functions mentioned above the index simply matches the connection number of the pipe, in case of the old functions there was a separate indexing for inlets and outlets. In case of the inlet lines, the index and the connection numbers were identical (1-6), in case of outlets there was an offset (the connections 7 to 15 could be addressed via the indices 1 to 9. To maintain clarity, it is recommended to use the new functions, in which the index always matches the number of the connection (1 to 6 for the inlets, 7 to 15 for the outlets).

    It is possible from EbsScript to have a read-only access to all the quantities in the cycle, especially also to all the pipe values, and also to all the valid values of the variables mass flow, pressure and enthalpy in the respective ongoing iterations step (see the explanation given above for ksGetInPipeValue). Changing the values may only be done with the help of the "ksSet..." function implemented for this purpose.

    Certain EbsScript functions cannot be used in the KernelScripting. A call of the calculation kernel is basically not possible. Other functions (profile change, reading of data, changing the colours) act only in the interface and are not relevant for the calculation process.

    An application of the print-command is, on the other hand, possible in the KernelScripting and is extremely useful for diagnostic purposes. The print-outputs can be viewed after the calculation in the EbsKernel output bar, which can be activated from the menu command "View". In the EbsKernel output bar, a sheet is created for each component 93 contained in the cycle, and also a complete sheet for all outputs.

     

    FUNCTIONS FOR SETTING EQUATIONS

     

    Specification of equations as a string

    Normally one calculates in EbsScript the values of the output parameters from the input parameters and sets them on the corresponding outlet lines. However, this method is not suitable for the validation, since no error propagation is observed in this way. As an alternative it is possible to define equations, which can connect the parameters on all connection lines with one another.

    These are the functions

    ksAddEquation ( equation:String; parameterVariables:String = ""; allowGeneralSolver:Boolean = false ):Integer

    Arguments:      STRING: equation
                             STRING ="" : ParameterVariables - Variables whose values are kept as unchangeable parameters (constant) during the solution of the equation system in the
                                                   current iteration step.
                             BOOLEAN = false:  allowGeneralSolver                                                                                                               
    Return value:   INTEGER:

    Purpose of the function: Resets a new equation. Returns return index of new equation or -1 in case of error.

     

    ksSetEquation( eqIndex:Integer; equation:String; parameterVariables:String = ""; allowGeneralSolver:Boolean = false  ):Boolean

    Arguments:       INTEGER: eqindex                                                                                                        
                              STRING: equation                                                                                        
                              STRING ="" : ParameterVariables – Variables whose values are kept constant (constant) during the solution of the equation system in the current iteration step.
    Return value:  BOOLEAN:

    Purpose of the function:  

    Resets the coefficients of the previously set ksAddEquation equation for the current iteration step.
                                            


    ksGetEquation( eqIndex:Integer ):String

    Arguments:     INTEGER: eqIndex                                                                                                           
    Return value:  STRING:

    Purpose of the function:  Returns the equation for the given index as a string.

     

    ksGetMaxEquationIndex: Integer

    Arguments:  none                                                                                                         
    Return value:  INTEGER:       

    Purpose of the function: 

    Returns the maximum index of the equations for the current part 93 (which corresponds to the number of remote equations).

     

    ksRemoveEquation( eqIndex:Integer ):  BOOLEAN 

    Arguments:     INTEGER: eqIndex                                                                                                                
    Return value:  BOOLEAN:

    Purpose of the function:  Removes the equation for the given index.


    and the procedure

    procedure ksRemoveAllEquations   

    Arguments:  none                                                                                                           
    Return value:   none

    Purpose of the procedure: Removes all equations in the component                       

    are available.

     

    The equation is to be specified as string (e.g. "M2 – M1 = 0”).

    The use of these functions is explained with the help of the following example, which shows the calculation of a simple heat exchanger, in which only mass and energy balances (without pressure loss) are taken into account. In the example, the main stream runs from connection 2 to connection 9, the secondary stream from connection 5 to connection 14. Water is used as fluid to avoid composition equations.

    uses @KernelScripting;
    
    var i,iIndex,iLZ:integer;
    strEquation:string;
    bOk:boolean;
    begin
    

    iLZ:=ksGetItNo;
    ksRemoveAllEquations;

    strEquation:="M9-M2=0";
    ksSetEquation (1,strEquation);

    strEquation:="M11-M5=0";
    ksSetEquation (2,strEquation);

    strEquation:="P9-P2=0";
    ksSetEquation (3,strEquation);

    strEquation:="P11-P5=0";
    ksSetEquation (4,strEquation);

    strEquation:=printToString ("m2*H2 - m2*H9 + m5*H5 - m5*H11 = 0");
    ksSetEquation (5,strEquation);

    // Output of the equations in Log-output (optional)
    iIndex:=ksGetMaxEquationIndex;
    for i:=1 to iIndex do begin
    strEquation:=ksGetEquation(i);
    print (strEquation,"\n");
    end;
    end;
    

     

    Specification of equations as structure

     

    Alternatively to the specification of equations as string, it is possible to pass the equations information in a structure. This can be done using the functions

     

    ksAddEquationNew ( equation:EquationType) : INTEGER 

    Arguments:    EQUATION: equation                                                                                                                 
    Return value:  INTEGER:

    Purpose of the function:  Resets a new equation.
       


    ksSetEquationNew ( eqIndex:Integer; equation:EquationType) : BOOLEAN       

    Arguments:     INTEGER: eqIndex
                           EquationType: equation                                                                                     
    Return value:  BOOLEAN

    Purpose of the function: Resets the coefficients for the current iteration step for the previously dropped equation with the given index.

                         


    ksGetEquationNew  ( eqIndex:Integer; equation:EquationType) : BOOLEAN       

    Arguments:      EquationType: eqIndex                                                                                                                 
    Return value:   BOOLEAN

    Purpose of the function: Returns the equation for the given index.


     

    ksGetEquationParameter( eqIndex:Integer; index: integer) : Real       

    Arguments:    INTEGER: eqIndex                                                                             
                           INTEGER: index  
    Return value:  REAL

    Purpose of the function: Returns the value of the parameter with the given "index" for the equation with the index "eqIndex"


    ksGetEquationParameters( eqIndex:Integer; ) :ARRAY OF REAL       

    Arguments:       INTEGER: eqIndex                                                                                                               
    Return value:    ARRAY OF REAL:

    Purpose of the function: Returns values of all parameters for the equation with the index "eqIndex".

     

    procedure ksSetEquationParameter( eqIndex:Integer; index: integer; param:real) : Real       

    Arguments:    INTEGER: eqIndex                                                                             
                           INTEGER: index 
                           REAL: param 
    Return value:  none

    Purpose of the procedure: For the given equation: sets parameter b {index} = param
     


    procedure ksSetEquationParameters( eqIndex:Integer; const params: array * of real; start: integer = 1)

    Arguments:    INTEGER: eqIndex                                                                             
                           ARRAY OF REAL: const params
                           INTEGER=1: param 
    Return value: none
    Purpose of the procedure: For the given equation: sets the parameters b {start}, ..., b {start + length (param)} to the values in the array "param"


     

    Example:

    uses @KernelScripting;
    
    var
    
        equation, equation1:EquationType;
    
    begin
    
        ksRemoveAllEquations;
    
        setLength(equation.LHS, 2);
    
        equation.LHS[0].Coeff.CoeffValue:=CoeffValueReal;
    
        equation.LHS[0].Coeff.Value:=1;
    
        equation.LHS[0].LineIndex:=1;
    
        equation.LHS[0].LineType:=PhysValueM;
    
        equation.LHS[1].Coeff.CoeffValue:=CoeffValueReal;
    
        equation.LHS[1].Coeff.Value:=-1;
    
        equation.LHS[1].LineIndex:=7;
    
        equation.LHS[1].LineType:=PhysValueM;
    
        equation.RHS.CoeffValue:=CoeffValueReal;
    
        equation.RHS.value:=0.0;
    
        ksAddEquationNew(equation);
    
     
    
        equation.LHS[0].LineType:=PhysValueP;
    
        equation.LHS[1].LineType:=PhysValueP;
    
        equation.RHS.value:=0.1;
    
        ksSetEquationNew(2, equation);
    
     
    
        equation.LHS[0].LineType:=PhysValueH;
    
        equation.LHS[1].Coeff.Value:=-2;
    
        equation.LHS[1].LineType:=PhysValueH;
    
        equation.RHS.value:=0;
    
        ksSetEquationNew(3, equation);
    
     
    
        ksGetEquationNew(1, equation1);
    
        println (length(equation1.LHS)," ",equation1.LHS[1].Coeff.Value);
    
    end.
    

     

    Non-linear equations:

    Besides the variables “m1“ – “m20“, “p1“ – “p20“, “p1“ – “p20“ (and “xn2_1“ – “xn2_20“, “xo2_1“ – “xo2_20“ etc. for all substances if material equations are activated), the basic
    arithmetic operations “+“, ”-“, ”*“, ”/“ as well as ”^“ for power, and the mathematical functions exp, ln (natural logarithm), log (logarithm to the base 10), sqrt (root),
    sin, cos, tan, asin, acos, atan, sinh, cosh, tanh, arsinh, arcosh, artanh can be used in the strings that define the equations for a Component 93.

    Moreover, functions from internal units and user-defined standard units can be called which return a numerical type (REAL, INTEGER) and exclusively have parameters (not ”var“ or ”const“) of the numerical type (default parameters are admissible).

    An example of this is the function “propertyCallId“ in the unit “@Standard”. Its use is demonstrated in the component example “Component_93.ebs“, e.g. in the component ”Kernel_Scripting_9“.

    Function “value_of“: value_of(x) has the value x, but always takes the derivation 0, i.e. it behaves as if the value of x had been calculated previously and entered into the equation as a constant.
    Case of application: see component example “Component_93.ebs“ in the component ”Kernel_Scrpting_9“: the partial term

    + 0.15*( H9 - value_of(H9))

    in the temperature equation has the value 0 but a derivation of 0.15 and thus prevents a disappearing of the derivation into the wet steam area.
    Without this partial term, the derivation to H9 has the value 0, i.e. if the wet steam area is crossed during the search for a solution, no change will be made to H9.

     

    Query of the current state of iteration; Measures depending on the progress of the iteration:

    When programming kernel scripting components, it is possible to access the current state of the iteration and influence it directly. The following functions are available for this purpose:

    ksGetCurrentAccuracy( {physValue:PhysValue} ): REAL

    Arguments:      PHYSVALUE: physValue                                                                                                           
    Return value:   REAL:

    Purpose of the function: 

    Allows retrieving the current degree of convergence, in each case for the mass flow (PhysValueM), the pressure (PhysValueP), and the enthalpy (PhysValueH).

    The results of this function in the respective iteration step correspond to the curves displayed in the convergence diagram. Thus it is possible to take certain measures depending on the progress of the iteration.

     

    ksGetFinishingReason(): FinishingReasonEnum

    Arguments:     none                                                                                                           
    Return value:   FinishingReasonEnum

    Purpose of the function: In the last iteration step, enables an analysis why the calculation is terminated:

    FinishingReasonEnum = (=0 / =1/ =2 / =3/ =4); 

    o FinishingReasonConvergency (1), if the specified degree of convergence has been achieved

    o FinishingReasonErrorAbort (2), if an error has led to a premature abort

    o FinishingReasonMaxIterationsReached (3), if the specified maximum number of iteration steps has been reached without the desired degree of convergence being achieved

    o FinishingReasonMaxTimeReached (4), if the specified maximum computing time has been reached

    (2)  Case “2“ applies if e.g. a Component 93 script ends with errors (e.g. zero division or with “exit(-1);“ ) or if a component aborts the simulation in the first step due to  
          inconsistent input data.

    (1)  “normal simulation errors“ are generated only in the last step, therefore in this case the value is “1”

     

    When calling the function outside of the “Finishing” stepFinishingReasonInvalid (0) will be returned:

    = 0, // ksGetFinishingReason called when Mode <> Finishing

    = 1, // calculation was terminated due to convergency

    procedure ksSignalNotConverged( signal:Boolean = True )

    Arguments:    BOOLEAN: Boolean = true: signal
    Return value:  none

    Purpose of the procedure:

    This function serves to prevent the calculation from being terminated in the current iteration step. This is particularly helpful if not all internal calculations have been finished yet.

     

    procedure ksSetComponentCalcState (component:ebscomp; enable_calculation:Boolean; recursive:Boolean = False )

    Arguments:    component : ebscomp
                          enable_calculation: Boolean
                          recursive: BOOLEAN: Boolean = false
    Return value:  none

    Purpose of the procedure:

    This function allows the calculation of a component to be switched off temporarily during the simulation. Temporarily switched off components retain the equations from the previous iteration step. If "component" is a macro object, all objects within the macro can be temporarily switched on or off with "recursive=True".
    Please note that this is a very advanced functionality which, if used incorrectly, can lead to calculation errors that are difficult to understand.

     

     

    Generating error messages:

     

    For kernel scripting and kernel expression it is possible by means of the procedures


    procedure ksSetWarning (text: String)

    procedure ksSetError (text: String; abortCalculation: Boolean = true)

    procedure ksSetComment (text: String)


    to generate error, warning and comment messages. Optionally, a termination of the calculation can also be initiated.
    Calling ksSetError with "abortCalculation = true" aborts the running simulation.

    In macro scripts and kernel scripting, errors can also be set for certain components.

     

    Note:  Equation Changes in KernelScripting

    One of the prerequisites for the speed of the solution procedure in Ebsilon is due to the fact that the structure of the equation system does not change in the course of the iteration (i.e. only changes in the values of the coefficients and the right hand side, but not in the variables are admissible). This saves the repetition of several procedures in each iteration step.

    In KernelScripting, the providing of the equations is within the responsibility of the user. This could lead to the case that structural changes of the equation system were effected during the iteration. The user was then informed of this by means of a warning, but the calculation was executed anyway.

    In Release 12, however, an error message is generated in these cases. The script and model respectively will then have to be adjusted so that no more structural changes occur in the equation system. In many cases this will be possible by using coefficients with the value 0 in certain iteration steps.

     

    Functions for providing non-local equations in KernelScripting

    These functions have been implemented for creating a prototype for the common steam header. They can be used for providing equations from a component for lines that are not directly connected to this component.

    ksGetLineIndexFromLine ( line:ebspipe ):integer

    Arguments:       EBSPIPE: line                                                                                                               
    Return value:     INTEGER: L

    Purpose of the function:  provides the internal line index L of a line

     

    ksGetLineIndexFromComp (comp:ebscomp; link:integer ):integer

    Arguments:      EBSCOMP: comp                                                                                                              
                             INTEGER: link
    Return value:    INTEGER: L

    Purpose of the function:  provides the internal line index L of a line that is connected to a component. This allows to access the corresponding variables via m{L}, p{L}, and h{L}.


    ksGetVariableMatrixIndex( variable:string ):integer

    Arguments:     STRING: variable                                                                                                                
    Return value:  INTEGER:

    Purpose of the function: Provides the internal variable index for a variable (e.g. for ”h1“)

     

    ksGetEquationPivotMatrixIndex (eqIndex:integer ):integer

    Arguments:       INTEGER: eqIndex                                                                                                              
    Return value:    INTEGER:

    Purpose of the function: Provides the internal variable index of the pivot element of an equation

     

    Equations with parameters

    To avoid complex string operations when creating the equation, you can create equations with parameters:
      
    Parameters a1, a2, .., a8192 apply to all equations and are set with ksSetParameters

    Parameters b1, b2, .., b8192 are valid for an equation and are set with ksSetEquationParameters

     

    ksGetMatrixIndexVariable (matrix_index:integer; use_local_naming:boolean = true):string;

    Arguments:      INTEGER: matrix_integer
                             BOOLEAN: use_local_naming                                                                                      
    Return value:   STRING:
    Purpose of the function: Returns the internal variable for the specified matrix index as a string.                      

     

    ksGetParameter (index:Integer) : REAL

    Arguments:      INTEGER: index                                                                                                               
    Return value:   REAL:   

    Purpose of the function: Returns parameter a (index)

     

    ksGetParameters  : ARRAY OF REAL

    Arguments:    none                                                                                                                
    Return value: ARRAY OF REAL  

    Purpose of the function: Returns all "a" parameters (!!! Result field is zero based, so the value of "a (i)" is at index i-1)
     

    procedure ksSetParameter (index:Integer, parameter: REAL)

    Arguments:      INTEGER: index
                             REAL: parameter                                                                                                              
    Return value:  none    

    Purpose of the procedure:  Sets parameter a (index) = parameter

      

    procedure ksSetParameters  : (const params: array * of real; start:integer = 1)

    Arguments:    ARRAY OF REAL : const params
                           INTEGER =1: START                                                                                      
    Return value: none

    Purpose of the procedure: Sets the parameters a (start), ..., a (start + length (param)) to the values in the array "param"                         

     

    procedure ksResetParameters     

    Arguments:    none                                                                                                   
    Return value: none

    Purpose of the procedure: Cancels all previously set "a" parameter values (that is, sets all parameters to 0)

    procedure ksResetEquationParameters (eqIndex:Integer)      

    Arguments:      INTEGER: eqIndex                                                                                                    
    Return value:   none

    Purpose of the procedure:  

    For the specified equation: discards all previously set "b" parameter values (that is, sets all parameters to 0)