| 1 |
|
|---|
| 2 | This little file is an illustration of a working case of the treatment of a fmu object in COMMON-LISP.
|
|---|
| 3 | This is working on a 64bits Linux 4.9.0-8-amd64 #1 SMP Debian 4.9.130-2 (2018-10-27) x86_64 GNU/Linux
|
|---|
| 4 | SBCL 1.3.14.debian
|
|---|
| 5 | ; SLIME 2.23
|
|---|
| 6 |
|
|---|
| 7 | ;;************************************************************************************************************
|
|---|
| 8 | ;; First we load the package that I have called cl-fmi.
|
|---|
| 9 | CL-USER> (in-package :cl-fmi)
|
|---|
| 10 | #<PACKAGE "CL-FMI">
|
|---|
| 11 | ;;************************************************************************************************************
|
|---|
| 12 | ;; Then we define a parameter containing the path to the fmu file.
|
|---|
| 13 | FMI> (defparameter test-fmu-file-path-64 "/home/frederic/quicklisp/local-projects/cl-fmi/test/linux64/Modelica_Blocks_Continuous_SecondOrder_64bits.fmu")
|
|---|
| 14 | TEST-FMU-FILE-PATH-64
|
|---|
| 15 |
|
|---|
| 16 | ;; The following is the instantiation of the fmu-info object of the class fmi2-information I have defined elsewhere.
|
|---|
| 17 | ;; The instantiation method unzip the fmu file, goes through the xml file and dispatch info in the class slots.
|
|---|
| 18 | ;; We also in this identifies the library location.
|
|---|
| 19 | FMI> (defparameter fmu-info (make-fmi2-information test-fmu-file-path-64 :unzip t))
|
|---|
| 20 |
|
|---|
| 21 | "unzip"
|
|---|
| 22 | "/home/frederic/quicklisp/local-projects/cl-fmi/test/linux64/unzip-3763774181/"
|
|---|
| 23 | UNZIP DIRECTORY : /home/frederic/quicklisp/local-projects/cl-fmi/test/linux64/unzip-3763774181/
|
|---|
| 24 |
|
|---|
| 25 | "unzip finished" UPDATE OF *foreign-library-directories*
|
|---|
| 26 | FMU PATHNAME : /home/frederic/quicklisp/local-projects/cl-fmi/test/linux64/Modelica_Blocks_Continuous_SecondOrder_64bits.fmu
|
|---|
| 27 | FMU DIRECTORY : /home/frederic/quicklisp/local-projects/cl-fmi/test/linux64/
|
|---|
| 28 | UNZIP FLAG : T
|
|---|
| 29 | UNZIP DIRECTORY : /home/frederic/quicklisp/local-projects/cl-fmi/test/linux64/unzip-3763774181/
|
|---|
| 30 | INPUT LIB DIR FLAG : NIL
|
|---|
| 31 | IDENTIFIED LIB DIR FLAG : /home/frederic/quicklisp/local-projects/cl-fmi/test/linux64/unzip-3763774181/binaries/linux64/
|
|---|
| 32 | FMU-INFO
|
|---|
| 33 |
|
|---|
| 34 | ;; Small confirmation that the instance is indeed a fmi2-information class
|
|---|
| 35 | FMI> (class-of fmu-info)
|
|---|
| 36 | #<STANDARD-CLASS CL-FMI::FMI2-INFORMATION>
|
|---|
| 37 |
|
|---|
| 38 | ;;************************************************************************************************************
|
|---|
| 39 | ;; Then we generate the fmu-test object , instance of an instance-me model exchange class I have defined elsewhere.
|
|---|
| 40 | FMI> (defparameter fmu-test (make-instance-me fmu-info ))
|
|---|
| 41 | FMU-TEST
|
|---|
| 42 |
|
|---|
| 43 | FMI> (class-of fmu-test)
|
|---|
| 44 | #<STANDARD-CLASS CL-FMI::INSTANCE-ME>
|
|---|
| 45 |
|
|---|
| 46 | ;;************************************************************************************************************
|
|---|
| 47 | ;; At this stage we can talk to it ... and the library was indeed accessed in this case.
|
|---|
| 48 | ;; Pre initialization stage
|
|---|
| 49 | ;; Here we reset the object
|
|---|
| 50 | FMI> (fmi2reset (p fmu-test))
|
|---|
| 51 | :FMI2OK
|
|---|
| 52 | ;; We can set the time ... notice the accessor (p fmu-test) to the process pointer.
|
|---|
| 53 | FMI> (fmi2settime (p fmu-test) 0.0d0)
|
|---|
| 54 | :FMI2OK
|
|---|
| 55 | ;; We can set the experimental plan ... notice the fmi2 boolean variables
|
|---|
| 56 | FMI> (fmi2SetupExperiment (p fmu-test) fmi2True 1.0d-5 0.0d0 fmi2True 1.0d0)
|
|---|
| 57 | :FMI2OK
|
|---|
| 58 |
|
|---|
| 59 | ;; Initialization stage
|
|---|
| 60 | FMI>(fmi2enterinitializationmode (p fmu-test))
|
|---|
| 61 | :FMI2OK
|
|---|
| 62 | ;; The fmu-info helps us locate the variables
|
|---|
| 63 | ;; At this moment we need to identify the parameters and variables to initialize
|
|---|
| 64 | ;; We only access the fmu-info object so no status message here
|
|---|
| 65 | FMI> (fmi2-print-variables fmu-info :index t :variability t :causality t :type t)
|
|---|
| 66 | ---------------
|
|---|
| 67 | MODEL VARIABLES
|
|---|
| 68 | y 0 continuous Real by Default output
|
|---|
| 69 | yd 1 continuous Real by Default output
|
|---|
| 70 | der(y) 2 continuous Real by Default local
|
|---|
| 71 | der(yd) 3 continuous Real by Default local
|
|---|
| 72 | u 4 continuous Real by Default input
|
|---|
| 73 | D 5 fixed Real by Default parameter
|
|---|
| 74 | k 6 fixed Real by Default parameter
|
|---|
| 75 | w 7 fixed Real by Default parameter
|
|---|
| 76 | y_start 8 fixed Real by Default parameter
|
|---|
| 77 | yd_start 9 fixed Real by Default parameter
|
|---|
| 78 | initType 10 fixed Modelica.Blocks.Types.Init calculatedParameter
|
|---|
| 79 | ---------------
|
|---|
| 80 | MODEL STRUCTURE
|
|---|
| 81 | ---------------
|
|---|
| 82 | INDEX of OUTPUT VARIABLES : (1 2)
|
|---|
| 83 | ---------------
|
|---|
| 84 | INDEX of DERIVATIVE VARIABLES : (3 4)
|
|---|
| 85 | NIL
|
|---|
| 86 | ;; TO Ease the readability we can assign some values to parameters
|
|---|
| 87 | FMI> (defparameter D 0.7d0)
|
|---|
| 88 | (defparameter k 1.0d0)
|
|---|
| 89 | (defparameter w 100.0d0)
|
|---|
| 90 | (defparameter y_start 0.0d0)
|
|---|
| 91 | (defparameter yd_start 0.0d0)
|
|---|
| 92 | ;; And send them to the real parameters of the FMU object
|
|---|
| 93 | FMI> (fmi2-set-real (p fmu-test) '(5 6 7 8 9) (list D k w y_start yd_start))
|
|---|
| 94 | :FMI2OK
|
|---|
| 95 | ;; And check that it worked.
|
|---|
| 96 | FMI> (fmi2-get-real (p fmu-test) '(1 2 3 4 5 6 7 8))
|
|---|
| 97 | :FMI2OK
|
|---|
| 98 | ((1 0.0d0) (2 0.0d0) (3 0.0d0) (4 0.0d0) (5 0.7d0) (6 1.0d0) (7 100.0d0)
|
|---|
| 99 | (8 0.0d0))
|
|---|
| 100 |
|
|---|
| 101 | ;; Let us get out of initialization
|
|---|
| 102 | FMI> (fmi2ExitInitializationMode (p fmu-test))
|
|---|
| 103 | :FMI2OK
|
|---|
| 104 |
|
|---|
| 105 | ;;************************************************************************************************************
|
|---|
| 106 | ;; Let us enter the continuous mode
|
|---|
| 107 | FMI> (fmi2entercontinuoustimemode (p fmu-test))
|
|---|
| 108 | :FMI2OK
|
|---|
| 109 | ;; At this stage we can set variables and see the impact for example on the derivatives
|
|---|
| 110 | ;; Once we can do this we can exploit the model and feed it to a solver.
|
|---|
| 111 | ;; u is the variable 4 it is an input
|
|---|
| 112 | FMI> (fmi2-set-real (p fmu-test) '(4) '(1.0d-2))
|
|---|
| 113 | :FMI2OK
|
|---|
| 114 | ;; We can set time also at this stage ... as an input to the get derivatives
|
|---|
| 115 | ;; It was already done but we can do it.
|
|---|
| 116 | FMI> (fmi2settime (p fmu-test) 0.0d0)
|
|---|
| 117 | :FMI2OK
|
|---|
| 118 | ;; First let us set the states variables
|
|---|
| 119 | ;; Setting of the State variables (here there are two )
|
|---|
| 120 | FMI> (fmi2-set-continuous-states (p fmu-test) '(0.0d0 0.0d0))
|
|---|
| 121 | :FMI2OK
|
|---|
| 122 | ;; Getting the value of the Derivatives of the State variables
|
|---|
| 123 | FMI> (fmi2-get-derivatives (p fmu-test) 2 )
|
|---|
| 124 | :FMI2OK
|
|---|
| 125 | ((1 0.0d0) (2 100.0d0))
|
|---|
| 126 |
|
|---|
| 127 |
|
|---|
| 128 |
|
|---|
| 129 |
|
|---|
| 130 |
|
|---|
| 131 |
|
|---|
| 132 |
|
|---|
| 133 |
|
|---|
| 134 |
|
|---|
| 135 |
|
|---|
| 136 |
|
|---|
| 137 |
|
|---|
| 138 |
|
|---|
| 139 |
|
|---|
| 140 |
|
|---|
| 141 |
|
|---|
| 142 |
|
|---|
| 143 |
|
|---|
| 144 |
|
|---|
| 145 |
|
|---|
| 146 |
|
|---|
| 147 |
|
|---|