Skip to content

MIKE+ API overview

MIKE+ database

There are two kinds of MIKE+ database. One is postgis database, another is sqlite database. Both can be easily accessed by MIKE+ API. MIKE+ database is organized by DataModule. DataModule provides a set of APIs to access the data in MIKE+ database. You can use DataModule to query data, modify data and delete data in MIKE+ database.

Setup MIKE+ API workspace

To setup MIKE+ API workspace, you need to reference DHI.Mike.Install.dll in your project. You can find it in MIKE+ installation folder. It will help your project to locate all the MIKE+ dependent assemblies from MIKE+ installation folder.

using DHI.Mike.Install;

// 24 is assembly version for MIKE+ 2026. 23 is for MIKE+ 2025.
MikeImport.Setup(24, MikeProducts.MikePlus);

How to modify MIKE+ database

Please use IDataTableContainer to access all the MIKE+ datatables. All the datatables are inherited from BaseTable. You can query data, insert data and delete data in MIKE+ database. If table has geometry, it will inherit from BaseTableGeometry. Using the command in BaseTable can help you to maintain the data relationship between tables. For example, if you changed a "From node" ID of a link, it will also update the link geometry if SetValuesByCommand has been used. Please see the detail in DataModule.

Examples to create DataTableContainer entity

using DHI.Amelia.DataModule.Interface.Services;
using DHI.Amelia.DataModule.Services.DataTables;
using DHI.Amelia.DataModule.Services.DataSource;
private IDataTableContainer CreateDataTableContainer(string dbOrmuppFile)
{
    // dbOrmuppFile - can be .sqlite file or .mupp file
    var dataSource = BaseDataSource.Create(dbOrmuppFile);
    if (dataSource != null && (dataSource.DbConnection == null || dataSource.DbConnection.State == ConnectionState.Closed))
    {
        dataSource.OpenDatabase();
        if (dataSource != null)
        {
            var dataTables = new DataTableContainer() { DataSource = dataSource };
            dataTables.SetActiveModel(dataSource.ActiveModel);
            dataTables.SetEumAppUnitSystem(dataSource.UnitSystemOption);

            return dataTables;
        }
    }

    return null;
}

Examples to query data, modify data and delete data inside IDataTableContainer

var dataTables = CreateDataTableContainer(dbOrmuppFile);
// To get all the ids of all the row in LinkTable
var muids = dataTables[DbTableNames.LinkTable].GetMuids(); 
// Get FromNodeID, ToNodeID and Diameter data from LinkTable
IList<string> fieldsToGet = new List<string>() { LinkFields.FromNodeID, LinkFields.ToNodeID, LinkFields.Diameter };
dataTables[DbTableNames.LinkTable].GetMuidAndFieldsWhereOrder(fieldsToGet);
// To set the FromNodeID of "Link_1"
var cmdResult = dataTables[DbTableNames.LinkTable].SetValuesByCommand("Link_1", new Dictionary<string, object>() { { LinkFields.FromNodeID, "Node_1" }}
// To insert a new link into LinkTable, the geometry is null
dataTables[DbTableNames.LinkTable].InsertByCommand(ref "Link_2", null, new Dictionary<string, object>() { { LinkFields.FromNodeID, "Node_1" }, { LinkFields.ToNodeID, "Node_2" }, { LinkFields.Diameter, 5.0 }});
// To Delete a link from LinkTable
dataTables[DbTableNames.LinkTable].DeleteByCommand("Link_2");
Table 1 Assemblies which need to be referenced by using DataTableContainer

Assembly
DHI.Amelia.DataModule.Interface
DHI.Amelia.DataModule
DHI.Amelia.GlobalUtility
DHI.Amelia.Infrastructure.Interface
DHI.Amelia.ProjectLoaderPFS.Interface.dll
DHI.Tracing

How to run simulation by using MIKE+ API

You can use command line to run all the MIKE+ supported engines. You can also reference to DHI.Amelia.Tools.EngineTool and using the EngineTool to run all kind of simulations.

Examples to run CS simulation by using MIKE+ API

using DHI.Amelia.DataModule.Services.DataTables;
using DHI.Amelia.DataModule.Interface.Services;
using DHI.Amelia.DataModule.Services.DataSource;
using DHI.Amelia.DataModule.Services.ImportExportPfsFile;
using DHI.Amelia.Tools.EngineTool;
using DHI.Amelia.GlobalUtility.DataType;
private void Run_MIKE_Plus_CS_Engine(string dbOrmuppFile)
{
    var dataTables = CreateDataTableContainer(dbOrmuppFile);
    (dataTables as DataTableContainer).ImportExportPfsFile = new ImportExportPfsFile();

    var engineTool = new EngineTool { DataTables = _dataTables };
    // Run the active simulation in MIKE+, you can also give a simulation id to run
    engineTool.RunEngine_CS(out DhiEngineSimpleLauncher launcher, out List<string> msgs);
    launcher.Start();
    launcher.EngineStatusCB += _StatusCB;

    void _StatusCB(DhiEngineSimpleLauncher.EngineStatusType type, MUSimulationOption simType)
    {
        switch (type)
        {
            case DhiEngineSimpleLauncher.EngineStatusType.SimEnd:
                launcher.EngineStatusCB -= _StatusCB;
                launcher = null;
                Environment.Exit(0);
                break;
        }
    }
}