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
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. 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
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. 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. 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. 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. 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. 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. 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. 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. 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. 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
23. Migration steps
• Change your engine to a dll
• Implement Initialize, PerformTimeStep
and Finish
• Create the EngineDllWrapper class
Jan Gregersen 23
27. The ElementMapper
Ground water River Model
Model
GetValues(time, link)
Calculate
Return values
Has Link Has
ElementSet
Quantity
“GW Recharge”
Jan Gregersen 27
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. 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. 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)
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
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. « 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. 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. 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