PINSUB

ModelingCreates user-defined input to a control plant.

Use

<Control_PlantInput
     id                  = "1"
     label               = "PlantIn"    
     num_element         = "3"
     variable_id_list    = "1 2 3"
     hold_order          = "0"
     interpreter         = "Python"
     script_name         = "pinsub.py"
     usrsub_fnc_name     = "PINSUB"
     usrsub_param_string = "USER(0.001)"
   />

Format

Fortran Calling Syntax
SUBROUTINE PINSUB (ID, TIME, PAR, NPAR, DFLAG, IFLAG, NVALUE, VALUE)
C/C++ Calling Syntax
void STDCALL PINSUB (int *id, double *time, double *par, int *npar, int *dflag, int *iflag, int *nvalue, double *value)
Python Calling Syntax
def PINSUB(id, time, par, npar, dflag, iflag):
    return value
MATLAB Calling Syntax
Not supported.

Attributes

ID
[integer]
The field element identifier.
TIME
[double precision]
The current simulation time.
PAR
[double precision]
An array that contains the constant arguments from the list provided in the user-defined statement.
NPAR
[integer]
The number of entries in the PAR array.
DFLAG
[logical]
The differencing flag.
IFLAG
[logical]
The initialization flag.
NVALUE
[integer]
The number of values of num_element that Control_PlantInput contains.
Must be provided as argument only to Fortran and C/C++ written subroutines.

Output

VALUE
[double precision]
Output array of dimension NVALUE that contains the values for the Control_PlantInput.

Example

from math import *

def PINSUB(id, time, par, npar, dflag, iflag):
    h_max = par[0]
    t = 1*[0]    
    if iflag==1:
       py_savpar(101, t)

    [t, info] = py_relpar(101)
    old_time = t[0]

    if time>=old_time+h_max:
        old_time = time
        t[0] = old_time
        py_savpar(101, t)  
        
    dz = 0.5*sin(2*pi*old_time)
    vz = pi*cos(2*pi*old_time)
    accz = -2*pi*pi*sin(2*pi*old_time)   

    return [dz, vz, accz]