示例#1
0
 /// <summary>
 /// Set the time step length in seconds
 /// </summary>
 public void SetTimeStepLength(double timeStepLength)
 {
     if (!(SimpleRiverEngineDllAccess.SetTimeStepLength(ref timeStepLength)))
     {
         CreateAndThrowException();
     }
 }
示例#2
0
        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();
            }
        }
示例#3
0
        public int GetNumberOfTimeSteps()
        {
            int numberOfTimeSteps = 0;

            if (!(SimpleRiverEngineDllAccess.GetNumberOfTimeSteps(ref numberOfTimeSteps)))
            {
                CreateAndThrowException();
            }
            return(numberOfTimeSteps);
        }
示例#4
0
 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();
     }
 }
示例#5
0
        public string GetSimulationStartDate()
        {
            StringBuilder simulationStartDate = new StringBuilder("                                                        ");

            if (!(SimpleRiverEngineDllAccess.GetSimulationStartDate(simulationStartDate, (uint)simulationStartDate.Length)))
            {
                CreateAndThrowException();
            }
            return(simulationStartDate.ToString().Trim());
        }
示例#6
0
        /// <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);
        }
示例#7
0
        public string GetModelID()
        {
            StringBuilder id = new StringBuilder("                                                        ");

            if (!(SimpleRiverEngineDllAccess.GetModelID(id, (uint)id.Length)))
            {
                CreateAndThrowException();
            }
            return(id.ToString().Trim());
        }
示例#8
0
        public string GetModelDescription()
        {
            StringBuilder description = new StringBuilder("                                                        ");

            if (!(SimpleRiverEngineDllAccess.GetModelDescription(description, (uint)description.Length)))
            {
                CreateAndThrowException();
            }
            return(description.ToString().Trim());
        }
示例#9
0
        /// <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);
        }
示例#10
0
        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);
        }
示例#11
0
        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);
        }
示例#12
0
        public void Finish()
        {
            if (!(SimpleRiverEngineDllAccess.Finish()))
            {
                CreateAndThrowException();
            }

            while (Kernel32Wrapper.FreeLibrary(_fortranDllHandle))
            {
            }

            _fortranDllHandle = (IntPtr)0;
        }
示例#13
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);
        }
示例#14
0
        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();
            }
        }