/// <summary> /// Set the time step length in seconds /// </summary> public void SetTimeStepLength(double timeStepLength) { if (!(SimpleRiverEngineDllAccess.SetTimeStepLength(ref timeStepLength))) { CreateAndThrowException(); } }
public void AddInflow(int index, double inflow) { int n = index + 1; // one is added because convenrion in C# is to start from zero whereas Fortran normally starts from 1 if (!(SimpleRiverEngineDllAccess.AddInflow(ref n, ref inflow))) { CreateAndThrowException(); } }
public int GetNumberOfTimeSteps() { int numberOfTimeSteps = 0; if (!(SimpleRiverEngineDllAccess.GetNumberOfTimeSteps(ref numberOfTimeSteps))) { CreateAndThrowException(); } return(numberOfTimeSteps); }
public void PerformTimeStep() { if (!(SimpleRiverEngineDllAccess.PerformTimeStep())) { // note that for some more advanced models the return value from PerformTimeStep can be used // to make the SmartWrapper redo the time step. One example could be for situations where a model // has adoptive time steps. For the SimpleRiver model a return value that is false indicates an error CreateAndThrowException(); } }
public string GetSimulationStartDate() { StringBuilder simulationStartDate = new StringBuilder(" "); if (!(SimpleRiverEngineDllAccess.GetSimulationStartDate(simulationStartDate, (uint)simulationStartDate.Length))) { CreateAndThrowException(); } return(simulationStartDate.ToString().Trim()); }
/// <summary> /// Return the input time as seconds since start of simulation /// </summary> /// <returns></returns> public double GetInputTime() { double time = 0; if (!(SimpleRiverEngineDllAccess.GetInputTime(ref time))) { CreateAndThrowException(); } return(time); }
public string GetModelID() { StringBuilder id = new StringBuilder(" "); if (!(SimpleRiverEngineDllAccess.GetModelID(id, (uint)id.Length))) { CreateAndThrowException(); } return(id.ToString().Trim()); }
public string GetModelDescription() { StringBuilder description = new StringBuilder(" "); if (!(SimpleRiverEngineDllAccess.GetModelDescription(description, (uint)description.Length))) { CreateAndThrowException(); } return(description.ToString().Trim()); }
/// <summary> /// Return the time step length in seconds /// </summary> /// <returns></returns> public double GetTimeStepLength() { double timeStepLength = -999; if (!(SimpleRiverEngineDllAccess.GetTimeStepLength(ref timeStepLength))) { CreateAndThrowException(); } return(timeStepLength); }
public double GetYCoordinate(int nodeIndex) { double yCoordinate = 0; int index = nodeIndex + 1; //Fortran starts arrays from 1 and C# starts from 0 if (!(SimpleRiverEngineDllAccess.GetYCoordinate(ref index, ref yCoordinate))) { CreateAndThrowException(); } return(yCoordinate); }
public double GetFlow(int index) { double flow = 0; int n = index + 1; //one is added because the convention in C# is to normally start from zero, whereas for Fortran the convention is to normally start from 1 if (!(SimpleRiverEngineDllAccess.GetFlow(ref n, ref flow))) { CreateAndThrowException(); } return(flow); }
public void Finish() { if (!(SimpleRiverEngineDllAccess.Finish())) { CreateAndThrowException(); } while (Kernel32Wrapper.FreeLibrary(_fortranDllHandle)) { } _fortranDllHandle = (IntPtr)0; }
private static void CreateAndThrowException() { int numberOfMessages = SimpleRiverEngineDllAccess.GetNumberOfMessages(); string message = "Error Message from SimpleRiver Fortran Core "; for (int i = 0; i < numberOfMessages; i++) { int n = i; StringBuilder messageFromCore = new StringBuilder(" "); SimpleRiverEngineDllAccess.GetMessage(ref n, messageFromCore, (uint)messageFromCore.Length); message += "; "; message += messageFromCore.ToString().Trim(); } throw new Exception(message); }
public void Initialize(string filePath, string simFileName) { string enginedll = @"Oatc.OpenMI.Examples.ModelComponents.SimpleRiver.Engine.dll"; string enginePath = enginedll; Trace.TraceInformation("Looking for engineDll: {0}", enginePath); if (!File.Exists(enginePath)) { // ADH: Why did this work before? string folder = Directory.GetParent( Assembly.GetAssembly(GetType()).Location).FullName; enginePath = Path.Combine(folder, enginedll); Trace.TraceInformation("Looking for engineDll: {0}", enginePath); if (!File.Exists(enginePath)) { throw new SimpleRiverException("Cannot find dll " + enginedll); } } _fortranDllHandle = Kernel32Wrapper.LoadLibrary(enginePath); if (_fortranDllHandle.ToInt32() == 0) { throw new SimpleRiverException("Failed fortran dll load " + enginedll); } string curDir = System.IO.Directory.GetCurrentDirectory(); if (!(SimpleRiverEngineDllAccess.SetSimFileName(simFileName, ((uint)simFileName.Length)))) { CreateAndThrowException(); } if (!(SimpleRiverEngineDllAccess.Initialize(filePath, ((uint)filePath.Length)))) { CreateAndThrowException(); } }