Introduction to OpenMI Jan Gregersen LicTek http://www.LicTek.com
Jan 15, 2015
Introduction to OpenMI
Jan Gregersen LicTek
http://www.LicTek.com
Jan Gregersen
My model
Connecting things - When two and two is five
USB
• Provides freedom of choice for the users
• Provides opportunities for suppliers
Standard
Introduction
Jan Gregersen
My model
About this presentation
• Examples of use
• How to create OpenMI linked systems
• How does OpenMI work
• How to migrate models
• Hardcoded configurations
• Optimization, calibration, ..
• Support
Introduction
Jan Gregersen
My model
Examples of use: Integrated modelling
precip
Runoff
flow
Leakage
GW
Level
Met. Database
Hymos
Mike She GW
RR
RR
RR
RR
RR
RR
RR
RR
RR
Sobek RR
Mike Basin
ISIS
Examples of use
Jan Gregersen
Examples of use: Hydropower DSS
HP
Web service
Forecasted:
Precipitation
Temperature
Evaporation
Hydropower DSS Define
scenarios
Web service
Estimated
power price
On-line
Water level in
reservoir
Numeric model
Numeric model Simulated
Revenue
Water level
Downstream flow
Operates
Use UseUse
Use UseUse
Creates
or optimization tool
User
Examples of use
Jan Gregersen
My model
Examples of use: Sewer to sewer
Mike Urban to Mike Urban
Water Level
Flow
Model 1 Model 2
Wave
Examples of use
Jan Gregersen
My model
How to create OpenMI linked systems : 1,2 Run
OMI file
Model Engine Input files1: Populate models
2: Configure
3: Run
How to create OpenMI linked system
Jan Gregersen
River model
RR model
River and groundwater models
How to create OpenMI linked systems : Demo
How to create OpenMI linked system
Jan Gregersen
My model
How does OpenMI work : OpenMI is OO
Very short introduction to Object Oriented programming
Class Rectangle
double diagonal
Class Polygon
String ID
double Area
bool IsPointInside(double x, double y)
double GetOverlapping Area(Polygon polygon
double GetDistanceToPoint(double x, double y)
Class Polyline
String ID
double GetDistanceToPoint(double x, double y)
Interface Geometrystring IDdouble DistanceToPoint (double x, double y)
implements implements
inherits
How does OpenMI work
Jan Gregersen
void Initialize(IArgument[] properties)
string ComponentIDstring ComponentDescriptionstring ModelIDstring ModelDescriptionITimeSpan TimeHorizon
IInputExchangeItem GetInputExchangeItem(int index)IOutputExchangeItem GetOutputExchangeItem(int idex)int InputExchangeItemCountint OutputExchangeItemCount
void AddLink (ILink link)void RemoveLink(string linkID)string Validate()
void Prepare()IValueSet GetValues(ITime time, string linkID)ITimeStamp EarliestInputTime
void Finish()void Dispose()
From outside all OpenMI compliant
components look the same
OpenMI.Standard.ILinkableComponent
How does OpenMI work : ILinkableComponent
River model
RR model
How does OpenMI work
Jan Gregersen
My model
void Initialize(IArgument[] properties)
string ComponentIDstring ComponentDescriptionstring ModelIDstring ModelDescriptionITimeSpan TimeHorizon
IInputExchangeItem GetInputExchangeItem(int index)IOutputExchangeItem GetOutputExchangeItem(int idex)int InputExchangeItemCountint OutputExchangeItemCount
void AddLink (ILink link)void RemoveLink(string linkID)string Validate()
void Prepare()IValueSet GetValues(ITime time, string linkID)ITimeStamp EarliestInputTime
void Finish()void Dispose()
1. Read OMI file
2. Create component
3. Invoke (call) Initialize
1. Component will read input files and initialize
How does OpenMI work : GUI Add model
How does OpenMI work
Jan Gregersen
My model
How does OpenMI work : The OMI file
<?xml version="1.0"?>
<LinkableComponent Type=“RainfallRunoffModelLC" Assembly="..\bin\RainfallRunoffModel.dll">
<Arguments>
<Argument Key=“Path" ReadOnly="true" Value=“..\data" />
</Arguments>
</LinkableComponent>
How does OpenMI work
Jan Gregersen
My model
How does OpenMI work : Model properties
void Initialize(IArgument[] properties)
string ComponentIDstring ComponentDescriptionstring ModelIDstring ModelDescriptionITimeSpan TimeHorizon
IInputExchangeItem GetInputExchangeItem(int index)IOutputExchangeItem GetOutputExchangeItem(int idex)int InputExchangeItemCountint OutputExchangeItemCount
void AddLink (ILink link)void RemoveLink(string linkID)string Validate()
void Prepare()IValueSet GetValues(ITime time, string linkID)ITimeStamp EarliestInputTime
void Finish()void Dispose()
How does OpenMI work
Jan Gregersen
My model
How does OpenMI work : Create and add link
void Initialize(IArgument[] properties)
string ComponentIDstring ComponentDescriptionstring ModelIDstring ModelDescriptionITimeSpan TimeHorizon
IInputExchangeItem GetInputExchangeItem(int index)IOutputExchangeItem GetOutputExchangeItem(int idex)int InputExchangeItemCountint OutputExchangeItemCount
void AddLink (ILink link)void RemoveLink(string linkID)string Validate()
void Prepare()IValueSet GetValues(ITime time, string linkID)ITimeStamp EarliestInputTime
void Finish()void Dispose()
1. Query and display exchange items
2. User selects output and input
3. Create a link object
4. Add the link to both components
How does OpenMI work
Jan Gregersen
My model
How does OpenMI work : ExchangeItems
Where What
How
How does OpenMI work
Jan Gregersen
My model
How does OpenMI Work : GetValues()
void Initialize(IArgument[] properties)
string ComponentIDstring ComponentDescriptionstring ModelIDstring ModelDescriptionITimeSpan TimeHorizon
IInputExchangeItem GetInputExchangeItem(int index)IOutputExchangeItem GetOutputExchangeItem(int idex)int InputExchangeItemCountint OutputExchangeItemCount
void AddLink (ILink link)void RemoveLink(string linkID)string Validate()
void Prepare()IValueSet GetValues(ITime time, string linkID)ITimeStamp EarliestInputTime
void Finish()void Dispose()
GetValues(time)
GetValues(time)
How does OpenMI work
Jan Gregersen
My model
How does OpenMI Work : GetValues()
GetValues(time)
My modelGetValues(time)
ID-Based link Geo-referenced bi-directional link
How does OpenMI work
Jan Gregersen
How does OpenMI Work : The Standard
Jan Gregersen
How to migrate models
How to migrate models
Jan Gregersen
The OpenMI SDK
• Source code C# (and Java)
• Default implementaion
• Wrapper
•Targeting developers
The OpenMI Configuration Editor
• Create linked systems
• Run linked systems
•Targeting users (e.g. modellers)
The OpenMI Standard
• The OpenMI.Standard interfaces
• The OpenMI standard definition
• XSD’s
• Provided by OA
• Rigid release proceedure
• Non frequent releases
• The one and only Standard
• Makes components linkable
How to migrate models:
SDK: Balancing stability and flexibility
• Provided by OATC
• Flexible release proceedures
• Frequent releases
• One of many
• Makes OpenMI easier
• OATC.SDK targeting models
• Not required
• Components compliant to
same version of the standard
can be linked regardless of
which SDK is used.
How to migrate models
Jan Gregersen
User Interface
Input file
Output file
Engine
Write
Read
Write
My model
Run
How most models are organized
How to migrate models
Jan Gregersen
User Interface
Input file
Output file
Engine
Write
Read
Write
My model
Run
OpenMI is linking models
How to migrate models
Jan Gregersen
User Interface
Input file
Output file
Engine
Write
Read
Write
My model
RunOpenMI.Standard
<<ILinkableComponent>>
How to migrate models
Jan Gregersen
User Interface
Input file
Output file
Engine
Write
Read
Write
Some
model
My model
GetValues()
GetValues()
RunOpenMI.Standard
<<ILinkableComponent>>
How to migrate models
Jan Gregersen
User Interface
Input file
Output file
Engine
Write
Read
Write
Some
model
My model
GetValues()
GetValues()
RunOpenMI.Standard
<<ILinkableComponent>>
void Initialize(IArgument[] properties)
string ComponentIDstring ComponentDescriptionstring ModelIDstring ModelDescriptionITimeSpan TimeHorizonint InputExchangeItemCountIInputExchangeItem GetInputExchangeItem(int inputExchangeItemIndex)int OutputExchangeItemCountIOutputExchangeItem GetOutputExchangeItem(int outputExchangeItemIndex)
void AddLink (ILink link)void RemoveLink(string linkID)string Validate()
void Prepare()IValueSet GetValues(ITime time, string linkID)ITimeStamp EarliestInputTime
void Finish()void Dispose()
How do I set values ?
How to migrate models
Jan Gregersen
User Interface
Input file
Output file
Engine
Write
Read
Write
Some
model
My model
SDK
(Wrapper)
GetValues()
GetValues()
Run
Oatc.OpenMI.Sdk
<<IEngine>>
OpenMI.Standard
<<ILinkableComponent>>
How to migrate models
Jan Gregersen
User Interface
Input file
Output file
Engine
Write
Read
Write
Some
model
My model
SDK
(Wrapper)
GetValues()
GetValues()
Run
Oatc.OpenMI.Sdk
<<IEngine>>
OpenMI.Standard
<<ILinkableComponent>>
// -- 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);
How to migrate models
Jan Gregersen
User Interface
Input file
Output file
Engine
Write
Read
Write
Some
model
My model
SDK
(Wrapper)
GetValues()
GetValues()
Run
Oatc.OpenMI.Sdk
<<IEngine>>
OpenMI.Standard
<<ILinkableComponent>>
Buffers results from the engine core
Mapping of values associated to one array of times /timespans to values represented on another array of times/timespans
t t
Mapping of values associated to one ElementSet to be represented on another ElementSet
•Link administration
•Exception handling
•Events handling
•And more..
How to migrate models
Jan GregersenHow to migrate models
void Initialize(IArgument[] properties)
string ComponentIDstring ComponentDescriptionstring ModelIDstring ModelDescriptionITimeSpan TimeHorizon
IInputExchangeItem GetInputExchangeItem(int index)IOutputExchangeItem GetOutputExchangeItem(int idex)int InputExchangeItemCountint OutputExchangeItemCount
void AddLink (ILink link)void RemoveLink(string linkID)string Validate()
void Prepare()IValueSet GetValues(ITime time, string linkID)ITimeStamp EarliestInputTime
void Finish()void Dispose()
// -- 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);
OpenMI.Standard.IlinkableComponent
Oatc.OpenMI.Sdk.Wrapper.IEngine
Jan GregersenHow to migrate models
<< interface >>OpenMI.Standard.ILinkableComponent
<< interface >>Oatc.OpenMI.Sdk.Wrapper.IEngine
<< abstract class >>Oatc.OpenMI.Sdk.Backbone.LinkableComponent
<< abstract class >>Oatc.OpenMI.Sdk.Wrapper.LinkableEngine
<< Class >>RiverModel.Engine
<< dll >>Fortran Engine
<< Class >>Rivermodel.EngineWrapper
<< Class >>Rivermodel.LinkableComponent
Implements
Implements
Inherits
Inherits
access
access
IEngine
access
create
Migration design pattern
Jan Gregersen
1. Make sure that your engine is a Dll not a Exe
2. Separate initialization, Perform time step, and finalization
3. Implement IEngine
4. Attach the SDK wrapper
5. Done
6. See also the simple river example
Five steps to a compliant model
How to migrate models
Jan Gregersen
Remarks about the configuration editor
• Enables user to create linked
systems and run these
• Is using the OpenMI standard
– not part of the standard
• We encurage other people to
create more sofisticated GUI’s
How to migrate models
Jan Gregersen
• The SDK makes model migration easier
• The SDK is aimed at time stepping numerical models
• The SDK is not mandatory to use (only the standard matters)
• SDK and the standard together provides stability and flexibility
Final remarks on model migration
How to migrate models
Jan Gregersen
Hard coded OpenMI configurations
Hardcoded configurations
Jan Gregersen
Calibration
Calibration
Calc.. New
parameters
GetValues()
SaveState()
RestoreState()
GetValues()
Measured values
GetValues()
GetValues()
New parameters
Simulated discharge
While (M – S)2 > a
All time steps
Jan Gregersen
http://sourceforge.net/projects/Openmi
• Help forum
• Discussion forum
• Feature request
http://Wiki.OpenMI.org
• Getting started
• HowTo
• Documentation
Support through the Internet
• General info
• News & Calendar
• Compliant models
• Documentation
Getting help
Jan Gregersen
www.OpenMI.org
Jan Gregersen
www.sourceforge.net/projects/openmi
Getting help
Jan Gregersen
Wiki.OpenMI.org
Getting help
Jan GregersenJan GregersenGetting help
OpenMI Workshops
• End users training
• Developers training
• Tailored training
Consulting
• Model provider
• Consultants
People to people
OpenMI training
• OpenMI Life workshops
• Conference workshops
• Specific workshops
Jan Gregersen
Thank you for your attention