示例#1
0
        public void Initialize(IList <Mike1DPluginArgument> arguments, Mike1DData mike1DData)
        {
            // Read arguments from .m1da file. Can also be read from other sources.
            Dictionary <string, XYTable> weirIdTable = new Dictionary <string, XYTable>(StringComparer.OrdinalIgnoreCase);

            foreach (Mike1DPluginArgument arg in arguments)
            {
                if (arg.Key == "Weir")
                {
                    // Assuming value contains structure id and then pairs of water depths and weir coefficients, like:
                    // weir = 'MyStrucId;0.1;0.1;0.5;0.2;1;0.5;5;0.6;10;0.65'
                    string[] split  = arg.Value.SplitQuoted(';', '"');
                    string   weirId = split[0];

                    XYTable table = new XYTable((split.Length - 1) / 2);
                    for (int i = 1; i < split.Length; i++)
                    {
                        double val = double.Parse(split[i], CultureInfo.InvariantCulture);
                        if (i % 2 == 1)
                        {
                            table.XValues[(i - 1) / 2] = val;
                        }
                        else
                        {
                            table.YValues[(i - 1) / 2] = val;
                        }
                    }
                    weirIdTable.Add(weirId, table);
                }
            }

            // Match structures and coefficient tables.
            foreach (IStructure structure in mike1DData.Network.StructureCollection.Structures)
            {
                HonmaWeir honmaWeir = structure as HonmaWeir;
                XYTable   table;
                if (honmaWeir != null && weirIdTable.TryGetValue(structure.ID, out table))
                {
                    _weirCoefficients.Add(new HonmaWeirInfo()
                    {
                        Weir = honmaWeir, Coefficient = table
                    });
                }
            }

            // We need an event when controller has been prepared, which is a two step procedure:
            // ControllerCreatedEvent and then ControllerEvent
            mike1DData.ControllerCreatedEvent += ControllerCreatedEvent;
        }
示例#2
0
        /// <summary>
        /// In PostTimeStepEvent event, update the weir coefficient
        /// Note that this could even be made time dependent.
        /// </summary>
        private void UpdateWeirCoefficients(DateTime time)
        {
            for (int i = 0; i < _weirCoefficients.Count; i++)
            {
                HonmaWeir     weir   = _weirCoefficients[i].Weir;
                XYTable       table  = _weirCoefficients[i].Coefficient;
                IDoubleGetter getter = _weirCoefficients[i].Getter;

                // Update weir coefficient
                if (getter != null)
                {
                    double upstreamWaterLevel = getter.GetValue();
                    double depthOverCrest     = upstreamWaterLevel - weir.CrestLevel;
                    weir.WeirCoefficient = table.YFromX(depthOverCrest, ExtrapolationTypes.Nearest);
                }
            }
        }