Versions Compared

Key

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

...


The source code for implementation of the Initialize method in the SimpleRiverEngineWrapper is shown below.

Code Block
titleOatc.OpenMI.Examples.ModelComponents.SimpleRiver.Wrapper.SimpleRiverEngineWrapper : Oatc.OpenMI.Sdk.Wrapper.IEngine
	public void Initialize(System.Collections.Hashtable properties) {    \_inputExchangeItems
		{
			_inputExchangeItems = new ArrayList();
			_outputExchangeItems = new ArrayList(); 

			//ArrayList of-- Create and  Oatc.OpenMI.Sdk.Backbone.InputExchangeItem objects    \_outputExchangeItemsinitialize the engine --
			_simpleRiverEngine = new ArrayListSimpleRiverEngineDotNetAccess(); //ArrayList of
             Oatc.OpenMI.Sdk.Backbone.OutputExchangeItem objectsif (properties["FilePath"].ToString().Length > 1)
          // \-\\- Create and initialize the engine \-\\- {
         \_simpleRiverEngine = new SimpleRiverEngineDotNetAccess();    \_simpleRiverEngine.Initialize((string)properties\['"FilePath'\]"].ToString());
      // \-\\- Simulation start time -      }
           // Theelse
 start time is obtained from the engine core as a string. This{
 string is    // passed and converted to a System.DateTime. Then the  string currentDir //= OatcSystem.OpenMIIO.Sdk.DevelopmentSupport.CalendarConverter class is used to convertDirectory.GetCurrentDirectory();
          // this time into the ModifiedJulianDay (this is the OpenMI standard time)    char \[\_simpleRiverEngine.Initialize(currentDir);
            }
			// -- Time horizon --
			char [] delimiter = new char\[\]{'-',' ',':'};    string\[\
			string[] strings = \_simpleRiverEngine.GetSimulationStartDate().Split(delimiter);
			int  StartYear  int StartYear = Convert.ToInt32(strings\[0\]);    
			int StartMonth  = Convert.ToInt32(strings\[1\]);
			int  StartDay  int StartDay = Convert.ToInt32(strings\[2\]);    int StartHour
			int StartHour   = Convert.ToInt32(strings\[3\]);    
			int StartMinute = Convert.ToInt32(strings\[4\]);    
			int StartSecond = Convert.ToInt32(strings\[5\]);    
			DateTime startDate = new DateTime(StartYear,StartMonth,StartDay,StartHour,StartMinute,StartSecond);    \
			_simulationStartTime = Oatc.OpenMI.Sdk.DevelopmentSupport.CalendarConverter.Gregorian2ModifiedJulian(startDate);    

			// \-\\- Build exchange items \--\\-    -
			Dimension flowDimension = new Dimension();    
			Unit flowUnit = new Unit('"m3/sec'",1,0,'"m3/sec'"); //The Simple River only uses    // quantities with the unit m3/sec.    Quantity flowQuantity 
			
			Quantity flowQuantity   = new Quantity(flowUnit,'"description'",'"Flow',    ",global::OpenMI.Standard.ValueType.Scalar,flowDimension);    
			Quantity inFlowQuantity = new Quantity(flowUnit,'"description'",'"InFlow',    ",global::OpenMI.Standard.ValueType.Scalar,flowDimension);    int numberOfNodes = \_simpleRiverEngine.GetNumberOfNodes();    for (int i = 0; i < numberOfNodes \-1; i++) //For each branch    {       OutputExchangeItem flowFromBranch = new OutputExchangeItem();       InputExchangeItem inFlowToBranch = new InputExchangeItem();       // One ElementSet is created for each branch. The ElementID's are       // Branch:<Branch number>. E.g. 'Branch:3'       ElementSet branch = new ElementSet('description','Branch:' + i.ToString(),ElementType.XYPolyLine,new SpatialReference('ref'));       branch.AddElement(new Element('Branch:' + i.ToString()));       branch.Elements\[0\].AddVertex(new Vertex(_simpleRiverEngine.       GetXCo-ordinate(i),_simpleRiverEngine.GetYCo-ordinate(i),0));       branch.Elements\[0\].AddVertex(new Vertex(_simpleRiverEngine.       GetXCo-ordinate(i+1),_simpleRiverEngine.GetYCo-ordinate(i+1),0));       flowFromBranch.ElementSet = branch;       flowFromBranch.Quantity = flowQuantity;       inFlowToBranch.ElementSet = branch;       inFlowToBranch.Quantity = inFlowQuantity;       \_outputExchangeItems.Add(flowFromBranch);       \_inputExchangeItems.Add(inFlowToBranch);    }    for (int i = 0; i < numberOfNodes; i++) //For all nodes    {       InputExchangeItem inflowToNode = new InputExchangeItem();       // Each node is a ID-based ElementSet. The ElementSet ID are       // Node:<node number>. E.g. 'Node:3'       ElementSet node = new ElementSet('description','Node:' +       i.ToString(),ElementType.IDBased,new SpatialReference('ref'));       node.AddElement(new Element('Node:' + i.ToString()));       inflowToNode.Quantity = inFlowQuantity;       inflowToNode.ElementSet = node;      \_inputExchangeItems.Add(inflowToNode);    }    ElementSet Branches = new ElementSet('description','AllBranches',    ElementType.XYPolyLine,new SpatialReference('ref'));    for (int i = 0; i < numberOfNodes - 1;i++) //Create an InputExchangeItem that    // has all branches in one ElementSet    {       Element branch = new Element('Branch: ' + i.ToString());       branch.AddVertex(new Vertex(_simpleRiverEngine.       GetXCo-ordinate(i),_simpleRiverEngine.GetYCo-ordinate(i),0));       branch.AddVertex(new Vertex(_simpleRiverEngine.       GetXCo-ordinate(i+1),_simpleRiverEngine.GetYCo-ordinate(i+1),0));       Branches.AddElement(branch);    }    InputExchangeItem inFlowToBranches = new InputExchangeItem();    inFlowToBranches.ElementSet = Branches;    inFlowToBranches.Quantity = inFlowQuantity;    \_inputExchangeItems.Add(inFlowToBranches); 
		}

As you can see from the implementation of the Initialize method, some methods need to be implemented in the MyEngineDotNetAccess class, the MyEngineDLLAccess class and the engine core.

...