Batch Run Scenarios using WaterObjects.NET Tool

Perform Batch Run using WaterObjects.NET Tool

Introduction

Unlike other Hydraulic & Hydrology products, HAMMER doesn't have a Batch Run feature. So, if we need to run multiple scenarios at once, we have to compute the Steady State run first then the HAMMER computation and wait till the computation to start another scenario. Now, this may not come that often but when it does, you will look for the Batch Run feature and may disappoint when the feature is not there.

Using WaterObjects, I wrote my own tool to perform the HAMMER Batch Run. From the tool, we can select multiple scenarios (unlike the main software, it's much easier to select the multiple scenarios when it is displayed in tree view, agree?). Once, selections are made, click on Batch It button and let it Batch Run the scenarios.

Here's another feature that I like compared to main software, separate User Notifications tab for each scenario. I know User Notification has a scenario column which can be sorted but having it on separate tabs is more convenient. So, after the Batch Run, User Notifications will be shown in tabs.

The Batch Run results (computation results) will be viewable in the main software, make sure read the instruction below. Note: the generated User Notification will, however, not be available in the main HAMMER software.

The programming details covered herein are applicable to several of Bentley’s hydraulics and hydrology (H&H) applications including WaterGEMS, WaterCAD, HAMMER, SewerGEMS, SewerCAD, SewerGEMS Sanitary, CivilStorm, StormCAD, PondPack etc. In fact, most of the lines of code can be used to create the tool that can work with most H&H applications. This tool in particular, however, will work with WaterGEMS and WaterCAD only.

How to Run the Tool

If you simply obtain the executable (.exe) file then make sure to place/copy this file in the right directory. For example, for the .exe needs to be placed in the \Program Files (x86)\Bentley\HAMMER8\ directory installed directory. Once the exe file is in the right location, run it and a window as shown in the figure above will show up.

Here's the step to properly run (to get the results back in main UI):
   -     Once the scenarios are ready, close the model from HAMMER software.
   -     Open up the tool, Browse to the model and select the model's database.
   -     Pick the scenarios for Batch Run and Click Batch Run.
   -     Review User Notifications. These notifications will be seen in HAMMER.
   -     [Optional] Close the tool.
   -     Open up the model in HAMMER and results will be there.


Programming Details

Bentleys WaterObjects.NET API will be primarily discussed in the sections below using C# as a programming language. It is assumed that the reader has some basic knowledge about the .NET programming. How to run scenarios and collect User Notifications
To run any scenario we need to know what solver/engine is required. In the example below, I am running EPANET engine which is the default engine for WaterGEMS and WaterCAD. The INumericalEngine is the base engine type from which we can cast to requierd (Water in this case) NumericEnginetype.

public INumericalEngine EpaNetEngine { get { return DomainDataSet.NumericalEngine(StandardCalculationOptionFieldName.EpaNetEngine); } }
public IWaterNumericalEngine WaterNumericalEpaNetEngine { get { return (IWaterNumericalEngine)EpaNetEngine; } }

Once we have these properties, running scenarios is matter of calling Run on the IWaterNumericalEngine. Now, the Run methods doesn't take one scenario rather a collection of scenarios in the form of ModelingELementCollection.

To collect Warning and Error type of exception, we need to catch them as EngineWarningsException and EngineFatalErrorExceptionrespectively, as shown below.

public IUserNotification[] RunEpaNetEngine(ModelingElementCollection scenarios)
{
   List userNotifications = new List<IUserNotification>();

   try
   {
      WaterNumericalEpaNetEngine.Run(scenarios);
   }
   catch (EngineFatalErrorException efee)
   {
      foreach (IUserNotification un in efee.UserNotifications)
         userNotifications.Add(un);
   }
   catch (EngineWarningsException ewe)
   {
      foreach (IUserNotification un in ewe.UserNotifications)
         userNotifications.Add(un);
   }

   return userNotifications.ToArray();
}
Notes

In the actual solution (Visual Studio file), there are a lot more lines of code than the code discussed above, and may not have an exact match. There, the solution file may exhibit slightly different code lines than above. The above code is to highlight the key codes for the task.

What if the Tool does Not Work or Help is Needed?

-If you just received the exe file, make sure the file is placed in the right location
-If you are working with Visual Studio/Express, you can contact me (by email at Akshaya(dot)Niraula(at)bentley.com).

History

•     2014/02/28 - Initial Post
•     2014/06/04 - Added Support to De/Select all Scenarios