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
35. Unidirectional link
« t rae
in f c»
e « t rae
in f c»
e
Re oe:
ivr dl
M Rm e:
Ro l
d
M Pg m
a r r
in o a I in b C pnn
L k le o oet
a m I in b C pnn
L k le o oet
a m
GVlusim t ,lin D r gr in
e a e t e 1 k = ige k
t ( = I T L )
[]
1
[]
2 GVlusim R t e _t lin D RRe
e a e t e M + d k = t ivr
t ( = im , I Ro )
Pro T e t p
e r im e
f m S
[]
3
r t r VluSt R o
e n a ee u f
u : nf { h Rt e Rt e _t
w ile Rim< M + d
im }
Pro T e t p
e r im e
f m S
{ h Rt e t }
w ile M <1
im
r t r VluSt Re lo
e n a e e ivr w
u : F
36. Bidirectional links
«interface» «interface»
RiverModel : GroundW aterModel :
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)
PerformTimeStep (t2)
[5]
return interpolated ValueSet QtoRiver (t1)
PerformTimeStep (t1)
[6]
GetValues(time=t2, linkID=QtoRiver)
[7]
return ValueSet QtoRiver (t2)
PerformTimeStep (t2)
return ValueSet Hriver (t2)
RiverModel us time s
es tep t1, GroundwaterModel us time s
es tep t2
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