...
Typically when you are making a model (wrapper) in DeltaShell and you work with an external / native dll you should define a C# interface and a C# implementation of that interface (which in turn typically calls methods in a native dll), for example:
Code Block | ||
---|---|---|
| ||
// model interface
public interface IMyModelApi
{
void Initialize();
void DoTimeStep();
double GetValue(int location);
void SetValue(int location, double value);
}
// implementation
public class MyModelApi : IMyModelApi
{
public void Initialize() {/*implementation*/}
public void DoTimeStep() {/*implementation*/}
public double GetValue(int location)
{
// typically interaction with native dll
}
void SetValue(int location, double value)
{
// typically interaction with native dll
}
}
|
You would normally create an instance of the implementation like this to use in your model wrapper:
Code Block | ||
---|---|---|
| ||
IMyModelApi api = new MyModelApi();
// usage:
public void Initialize
{
api.SetValue(pumpId, 5.0); //set initial value
api.Initialize();
}
|
...
So if you previously did this:
Code Block | ||
---|---|---|
| ||
IMyModelApi api = new MyModelApi();
api.Initialize();
|
You can now do this:
Code Block | ||
---|---|---|
| ||
IMyModelApi api = RemoteInstanceContainer.CreateInstance<IMyModelApi, MyModelApi>();
api.Initialize();
|
...
There is one extra step you have to take to clean things up when you're done with the run:
Code Block | ||
---|---|---|
| ||
RemoteInstanceContainer.RemoveInstance(api);
|
...
- all primitive types (int, double, string, etc)
- enums
- NOT decimal
- double[], bool[], int[], short[], float[], byte[], string[]
- 'Array' if of above type at runtime!
- ref/out keywords on above types. Only ref on the array types.
- Type, DateTime, TimeSpan, DateTime[] (through type converter)
- ..more through type converters
- ..more support can be added in the code, ask!
...
To work without a type converter, you can annotate a class as follows:
Code Block | ||
---|---|---|
| ||
[ProtoContract]
public class CurvilinearGrid
{
[ProtoMember(1)] public int SizeN;
[ProtoMember(2)] public int SizeM;
[ProtoMember(3)] public double[] X;
[ProtoMember(4)] public double[] Y;
// additional code
}
|
...