OpenMI Developers Training

377 views
342 views

Published on

Introduction to developing or migrating models to be compliant to the OpenMI Standard. OpenMI is an open standard which allows dynamic linking of numerical models, such as river models rainfall-runoff models and so on. See also:
http://www.lictek.com

Published in: Technology, Business
0 Comments
0 Likes
Statistics
Notes
  • Be the first to comment

  • Be the first to like this

No Downloads
Views
Total views
377
On SlideShare
0
From Embeds
0
Number of Embeds
1
Actions
Shares
0
Downloads
14
Comments
0
Likes
0
Embeds 0
No embeds

No notes for slide

OpenMI Developers Training

  1. 1. OpenMI Developers Training Jan Gregersen http://www.LicTek.com Jan Gregersen 1
  2. 2. Simple River Runoff Model Simple River OutputExchangeItem InputExchangeItem Quantity ID : Runoff Quantity ID : Inflow DataOperaiton : Distributed ElementSet : Polygons ElementSet : Polyline Y (km) 5 10 Y (km) 10 10 Node:0 Branch:0 Node:1 5 5 Branch:1 Node:2 Branch:2 Node:3 X (km) X (km) 5 10 Jan Gregersen 2
  3. 3. How it works Load components: Query exchange items: Add links: Jan Gregersen 3
  4. 4. How it works Prepare: Run (GetValues): Finish: Jan Gregersen 4
  5. 5. The OpenMI standard DHI - Water & Environment Jan Gregersen
  6. 6. Jan Gregersen 6
  7. 7. Migration of models DHI - Water & Environment Jan Gregersen
  8. 8. Now What ??? Jan Gregersen 8
  9. 9. Org.OpenMI.Utilities Org.OpenMI.Utilities.Buffer Buffers results from the engine core SmartBuffer Mapping of values associated to one array of times /timespans to values represented on another array of times/timespans t t Org.OpenMI.Utilities.Spatial Mapping of values associated to ElementMapper one ElementSet to be represented on another ElementSet Org.OpenMI.Utilities.Wrapper Generic wrapper suited for time SmartWrapper stepping model engines Jan Gregersen 9
  10. 10. LinkableEngine features • Provides a default implementation of the ILinkableComponent interface • Links bookkeeping • Event handling • Buffering • Temporal interpolations, aggregations, extrapolations • Spatial interpolations, aggregations, extrapolations Jan Gregersen 10
  11. 11. Wrapper design pattern Jan Gregersen 11
  12. 12. IEngine Interface // -- Execution control methods (Inherited from IRunEngine) -- void Initialize(Hashtable properties); bool PerformTimeStep(); void Finish(); //-- Time methods (Inherited from IRunEngine) -- ITime GetCurrentTime(); ITime GetInputTime(string QuantityID, string ElementSetID); ITimeStamp GetEarliestNeededTime(); //-- Data access methods (Inherited from IRunEngine) -- void SetValues(string QuantityID, string ElementSetID, IValueSet values); IValueSet GetValues(string QuantityID, string ElementSetID); //-- Component description methods (Inherited from IRunEngine) -- double GetMissingValueDefinition(); string GetComponentID(); string GetComponentDescription(); // -- Model description methods -- string GetModelID(); string GetModelDescription(); double GetTimeHorizon(); // -- Exchange items -- int GetInputExchangeItemCount(); int GetOutputExchangeItemCount(); org.OpenMI.Backbone GetInputExchangeItem(int exchangeItemIndex); org.OpenMI.Backbone GetOutputExchangeItem(int exchangeItemIndex); Jan Gregersen 12
  13. 13. Inside the LinkableEngine has SmartWrapper has SmartInputLinkSet SmartOutputLinkSet UpdateInput() UpdateBuffer() 1 GetValues() access has Link access 1 Link has * * SmartInputLink SmartOutputLink UpdateInput() has UpdateBuffer() GetValues() has SmartBuffer ElementMapper Jan Gregersen 13
  14. 14. GetValues() Model B Model A GetValues(time, LinkID) GetValues(time, LinkID) 1. Update with input from linked models 2. Perform time step and fill internal buffers While (CurrentTime < time & State is “Not Busy”) 3. Map values in time and space Return values Jan Gregersen 14
  15. 15. GetValues() Model B Model A GetValues(time, LinkID) GetValues(time, LinkID) 1. Update with input from linked models 2. Perform time step and fill internal buffers While (CurrentTime < time & State is “Not Busy”) 3. Map values in time and space Return values Jan Gregersen 15
  16. 16. GetValues() Engine Smart A Smart A Smart A Smart A Smart Model B Model A AIP Output Output Element InputLink Input Buffer Access LInkSet LInk Mapper Set Link GetValues(tl LinkID) GetCurrentTime() IsBusy = true UpdateInput(ct) UpdateInput(ct) GetValues(ct,LinkID) SetValues(Quantity,LocationID,Values) For each Input Link Jan Gregersen 16
  17. 17. GetValues() Model B Model A GetValues(time, LinkID) GetValues(time, LinkID) 1. Update with input from linked models 2. Perform time step and fill internal buffers While (CurrentTime < time & State is “Not Busy”) 3. Map values in time and space Return values Jan Gregersen 17
  18. 18. GetValues() Engine Smart A Smart A Smart A Smart A Smart Model B Model A AIP Output Output Element InputLink Input Buffer Access LInkSet LInk Mapper Set Link PerformTimeStep() UpdateBuffers() UpdateBuffer() Getvalues(Quantity,LocationIDs) Addvalues(time, valueSet) For each output link IsBusy = false Jan Gregersen 18
  19. 19. GetValues() Model B Model A GetValues(time, LinkID) GetValues(time, LinkID) 1. Update with input from linked models 2. Perform time step and fill internal buffers While (CurrentTime < time & State is “Not Busy”) 3. Map values in time and space Return values Jan Gregersen 19
  20. 20. GetValues() Engine Smart A Smart A Smart A Smart A Smart Model B Model A AIP Output Output Element InputLink Input Buffer Access LInkSet LInk Mapper Set Link GetValues(time, LinkID) GetValues(time) GetValues(time) MapValues(inpuValues) Jan Gregersen 20
  21. 21. IEngine Interface // -- Execution control methods (Inherited from IRunEngine) -- void Initialize(Hashtable properties); bool PerformTimeStep(); void Finish(); //-- Time methods (Inherited from IRunEngine) -- ITime GetCurrentTime(); ITime GetInputTime(string QuantityID, string ElementSetID); ITimeStamp GetEarliestNeededTime(); //-- Data access methods (Inherited from IRunEngine) -- void SetValues(string QuantityID, string ElementSetID, IValueSet values); IValueSet GetValues(string QuantityID, string ElementSetID); //-- Component description methods (Inherited from IRunEngine) -- double GetMissingValueDefinition(); string GetComponentID(); string GetComponentDescription(); // -- Model description methods -- string GetModelID(); string GetModelDescription(); double GetTimeHorizon(); // -- Exchange items -- int GetInputExchangeItemCount(); int GetOutputExchangeItemCount(); org.OpenMI.Backbone GetInputExchangeItem(int exchangeItemIndex); org.OpenMI.Backbone GetOutputExchangeItem(int exchangeItemIndex); Jan Gregersen 21
  22. 22. Wrapper design pattern Jan Gregersen 22
  23. 23. Migration steps • Change your engine to a dll • Implement Initialize, PerformTimeStep and Finish • Create the EngineDllWrapper class Jan Gregersen 23
  24. 24. Wrapper design pattern Jan Gregersen 24
  25. 25. Migration steps • Create your MyEnigneWrapper • Implement Initialize and Finish • Implement remaining Ienigne methods Jan Gregersen 25
  26. 26. Jan Gregersen 26
  27. 27. The ElementMapper Ground water River Model Model GetValues(time, link) Calculate Return values Has Link Has ElementSet Quantity “GW Recharge” Jan Gregersen 27
  28. 28. Spatial mapping Jan Gregersen 28
  29. 29. ElementMapper Org.OpenMI.Utilties.Spatial ElementMapper Initialise(string methodDescription, IElementSet fromElements, IElementSet toElements) IValueSet MapValues(IValueSet inputValues) r1 m 11 m 12 m 13 . m1n x1 r2 m 21 m 22 m 23 . m2n x2 r3 m 31 m 32 m 33 . m 3n x3 . . . . . . . rm m m1 mm2 mm3 . m mn xn Jan Gregersen 29
  30. 30. Element Mapping RE1 RE1 1 1/ 3 0 GE1 GE2 0 2/3 1/ 2 RE3 A 0 0 0 GE3 GE4 0 0 1/ 2 I L A Jan Gregersen 30
  31. 31. Element • ID Based “Node127” • Point (x1,y1) • Line (x1,y1) (x2,y2) • Polyline (x1,y1) (x2,y2) (x3,y3) (x4,y4) (x1,y1) (x5,y5) • Polygon (x4,y4) (x2,y2) (x3,y3)
  32. 32. ElementSet example H Q H H Q Q H Q H H Q Q H H Q Q H Q H Q H Q H
  33. 33. Quantity • ID ( “Runoff” ) • Description ( “Rainfall runoff” ) • Dimension ( e.g. L3 T-1 ) – GetPower ( <dimensionBase> ) • Unit: – ID ( “CFS” ) – Descr ( “Cubic feet per second “ ) – ConversionFactorToSI ( 0,0283168439 ) – OffsetToSI ( 0 )
  34. 34. ExchangeItem • InputExchangeItem – Quantity – ElementSet • OutputExchangeItem – Quantity – ElementSet – [ DataOperations • ID • Arguments ]
  35. 35. Unidirectional link « t ra e inef c » « t ra e inef c » R eMd l : iv r o e R md l : R oe Min r ga a P rm o I ina le o p n n L k b Cmo e t I ina le o p n n L k b Cmo e t Gt a e(im=1 linI = r g r in) eV lu st et , k Tig eL k D [ ] 1 [ ] 2 Gt a e(im= M e+ d, linI = R R e) eV lu st eR tim _ t k R t iv r D o P rom imS p ef r T e te [ ] 3 r t r V lu S t Rn f eun a e e: u of { h R t e< M e+ d} wile R im R tim _ t P rom imS p ef r T e te { h R t e< 1 wile M im t } r t r V lu S t R eF w eun a e e: iv r lo
  36. 36. Bidirectional links «interface» «interface» Ri verModel : GroundWaterModel : MainProgram ILinkableComponent ILinkableComponent GetValues(t2,TriggerLink) [1] GetValues(time=t1, linkID=QtoRiver) [2] GetValues(time=t2, linkID=HtoGW) [3] Extrapolate (t2) [4] return extrapolated ValueSet: HtoGW (t2) PerformT imeStep (t2) [5] return interpolated ValueSet QtoRiver (t1) PerformTimeStep (t1) [6] GetValues(time=t2, linkID=QtoRiver) [7] return ValueSet QtoRiver (t2) PerformT imeStep (t2) return ValueSet Hriver (t2) RiverModel uses time step t1, GroundwaterModel uses time step t2
  37. 37. Ite ra ti o n C o n tro l l e r « i n te rfa c e » « i n te rfa c e » : R i v e rM o d e l : G ro u n d W a te rM o d e l : IL i n ka b l e C o m p o n e n t IL i n ka b l e C o m p o n e n t IL i n ka b l e C o m p o n e n t M a i n P ro g ra m G e tV a l u e s(ti m e = t2 , l i n kID = H _ S W ) K e e p C u rre n tS ta te [1 ] R i v e rS ta te _ t_ b e g i n K e e p C u rre n tS ta te G W S ta te _ t_ b e g i n In i ti a l G u e ss(Q to G W ) [2 ] R e sto re S ta te (R i v e rS ta te _ t_ b e g i n ) [3 ] R e sto re S ta te (G W S ta te _ t_ b e g i n ) [4 ] G e tV a l u e s(ti m e = t2 , l i n kID = H _ G W ) G e tV a l u e s(ti m e = t2 , l i n kID = Q to G W ) Q to G W _ g u e ss H_ G W [5 ] G e tV a l u e s(ti m e = t2 , l i n kID = H _ S W ) G e tV a l u e s(ti m e = t2 , l i n kID = Q to G W ) Q to G W _ g u e ss H_SW E v a l u a te [6 ] N e w G u e ss(Q to G W ) {u n ti l l Q to G W i s sta b i l i z e d } re su l t: H _ S W [7 ]
  38. 38. « i n te rfa ce » « i n te rfa ce » R i ve rM o d e l : RR m o d e l : M a i n P ro g ra m IL i n ka b l e C o m p o n e n t IL i n ka b l e C o m p o n e n t Use r : IL i ste n e r S ta rt G e tV a l u e s(ti m e = t1 ,T ri g g e rL i n kID ) [1 ] O n E ve n t(S o u rce A fte rG e tV a l u e sC a l l ) re tu rn co m p u ta ti o n th re a d G e tV a l u e s(ti m e = t1 ,l i n kID= Q to R i ve r) [2 ] O n E ve n t(S o u rce A fte rG e tV a l u e sC a l l ) re tu rn co m p u ta ti o n th re a d P e rfo rm T i m e S te p ((_ d t)) [3 ] O n E ve n t(D a ta Ch a n g e d ) re tu rn co m p u ta ti o n th re a d O n E ve n t(S o u rce B e fo re G e tV a l u e sR e tu rn ) {u n ti l RR ti m e = t1 } P a u se [4 ] R e su m e [5 ] re tu rn co m p u ta ti o n th re a d re tu rn V a l u e S e t(Q to R i ve r, t1 ) O n E ve n t(T a rg e tA fte rG e tV a l u e sR e tu rn ) [6 ] re tu rn co m p u ta ti o n th re a d P e rfo rm T i m e S te p (R M _ d t) O n E ve n t(Da ta C h a n g e d ) [7 ] O n E ve n t(S o u rce B e fo re G e tV a l u e sR e tu rn ) re tu rn co m p u ta ti o n th e a d [8 ] re tu rn V a l u e S e t(t1 )
  39. 39. Persistency • OMI File – For identifying a linkable component • Composition – In org.OpenMI.Utilities.Configuration – Holds administration of links and linkable components – Can be run – Can be written and read to / from xml
  40. 40. Exercise 9: Unit Conversion Step 1 Open the DataCombinator Step 2 Adjust the code of GetValues so that it delivers data in the right unit Step 3 Adjust the test program to ask for a quantity which has a conversion factor not equal to one Step 4 Identify a value as missing value (e.g. -999) and adjust the input. Make sure this value is processed correctly. Step 5 Test the program using NUnit

×