Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

Include Page
OPENMI:4.3 Step 3 - Accessing the functions in the engine core
OPENMI:4.3 Step 3 - Accessing the functions in the engine core

4.

...

 

 The third step is to implement the MyEngineDLLAccess class (Figure 9).
Image Removed
Fig 9. MyEngineDllAccess class
 
Because you are using a C# implementation of OpenMI, your engine needs to be accessible from .NET. In the pattern shown above this is handled in two wrappers, MyEngineDLLAccess and MyEngineDotNetAccess. The MyEngineDLLAccess class will make a one-to-one conversion of all exported functions in the engine core code to public .NET methods. The MyEngineDotNetAccess class will change some of the calling conventions.
The specific implementation of the MyEngineDLLAccess class depends on the compiler you are using. Start by implementing export methods for the Initialize, PerformTimeStep, and Finish functions.
The code listed below shows an example of such an implementation for the Simple River Fortran engine. Note that this implementation corresponds to a particular Fortran compiler; the syntax may vary between compilers.

Code Block

using System; using System.Run-time.InteropServices; using System.Text; namespace MyOrganisation.OpenMI.MyModel {     public class MyEngineDLLAccess     {          \[DllImport(@"Oatc.OpenMI.Examples.ModelComponents.SimpleRiver.Engine.dll", 	       EntryPoint = "INITIALIZE", 	       SetLastError=true, 	       ExactSpelling = true, 	       CallingConvention=CallingConvention.Cdecl)\] 	       public static extern bool Initialize(string filePath, uint length);            \[DllImport(@"Oatc.OpenMI.Examples.ModelComponents.SimpleRiver.Engine.dll", 		EntryPoint = "PERFORMTIMESTEP", 		SetLastError=true, 		ExactSpelling = true, 		CallingConvention=CallingConvention.Cdecl)\] 		public static extern bool PerformTimeStep();            \[DllImport(@"Oatc.OpenMI.Examples.ModelComponents.SimpleRiver.Engine.dll", 	       EntryPoint = "FINISH", 	       SetLastError=true, 	       ExactSpelling = true, 	       CallingConvention=CallingConvention.Cdecl)\] 	       public static extern bool Finish();     } }

4.4 Step 4: Implementing the MyEngineDotNetAccess

...