Пример #1
0
        public static void SetValue <T>(this IBasicModelInterface model, string variable, T value)
        {
            var length = BasicModelInterfaceLibrary.GetTotalLength(model.GetShape(variable));
            var values = Enumerable.Repeat(value, length).ToArray();

            model.SetValues(variable, values);
        }
        /// <summary>
        ///     Run model in one step from start to end.
        /// </summary>
        /// <param name="library"></param>
        /// <param name="configPath"></param>
        public static void Run(string library, string configPath)
        {
            var model = new BasicModelInterfaceLibrary(library)
            {
                Logger = (level, message) => Console.WriteLine("{0}: {1}", level, message)
            };

            model.Initialize(configPath);

            var sameTimeCounter = 0;

            DateTime t = model.StartTime;

            while (t < model.StopTime)
            {
                // check if model time step increases
                if (t == model.CurrentTime)
                {
                    sameTimeCounter++;

                    if (sameTimeCounter == 100)
                    {
                        throw new InvalidOperationException("Model current_time did not increase after 100 updates");
                    }
                }

                t = model.CurrentTime;
                model.Update(-1.0);

                // reset model time step counter
                if (t != model.CurrentTime)
                {
                    sameTimeCounter = 0;
                }
            }

            model.Finish();
        }