示例#1
0
 private static async Task <Auxiliary> CreateAuxiliary(string name, string model, string eqn,
                                                       GraphicalFunction graph, Range range, Range scale,
                                                       NonNegative nonNegative, VariableAccess access)
 {
     return(await CreateVariable <Auxiliary>(name, model, eqn, graph, range, scale, nonNegative,
                                             access));
 }
示例#2
0
        private static async Task <Stock> CreateStock(string name, string model, string eqn, List <string> inflow,
                                                      List <string> outflow,
                                                      GraphicalFunction graph,
                                                      Range range, Range scale, NonNegative nonNegative, VariableAccess access)
        {
            var stock = await CreateVariable <Stock>(name, model, eqn, graph, range, scale, nonNegative, access);

            stock.Inflow  = StringUtils.CleanNames(inflow);
            stock.Outflow = StringUtils.CleanNames(outflow);
            stock.SetChildren();
            return(stock);
        }
示例#3
0
        /// <summary>
        ///     Adjust Value when a graphical function is defined
        /// </summary>
        /// <param name="value"></param>
        public void AdjustValue(float value)
        {
            if (float.IsNaN(value) || float.IsInfinity(value))
            {
                throw new ArgumentOutOfRangeException();
            }

            // Graphical function
            Value = GraphicalFunction?.GetOutput(value) ?? value;
            if (NonNegative != null)
            {
                Value = NonNegative.GetOutputInsideRange(Value);
            }
        }
示例#4
0
        public static async Task <Flow> CreateInstance(string name, XMileModel model, string eqn,
                                                       GraphicalFunction graph, Range range,
                                                       Range scale,
                                                       NonNegative nonNegative, VariableAccess access)
        {
            if (model == null)
            {
                throw new ArgumentNullException(nameof(model));
            }

            var variable = await CreateFlow(name, model.Name, eqn, graph, range, scale, nonNegative, access);

            model.Variables.Add(variable);
            return(variable);
        }
示例#5
0
        public static async Task <T> CreateVariable <T>(string name, string model, string eqn, GraphicalFunction graph,
                                                        Range range, Range scale,
                                                        NonNegative nonNegative, VariableAccess access) where T : IVariable, new()
        {
            var variable = new T
            {
                Model             = model,
                Name              = StringUtils.CleanName(name),
                GraphicalFunction = graph,
                Range             = range,
                Scale             = scale,
                Units             = Units.CreateInstanceFromEquation(eqn),
                NonNegative       = nonNegative,
                Access            = access
            };

            variable.FullName = StringUtils.FullName(variable.Model, variable.Name);

            var factory = await EquationFactory.CreateInstance(model, eqn);

            variable.Equation = factory.Equation;
            variable.Value    = factory.Value;
            variable.AdjustValue(factory.Value);
            variable.Initialize();
            variable.SetChildren();
            return(variable);
        }
示例#6
0
 public static async Task <Flow> CreateFlow(string name, string model, string eqn, GraphicalFunction graph,
                                            Range range, Range scale,
                                            NonNegative nonNegative, VariableAccess access)
 {
     return(await CreateVariable <Flow>(name, model, eqn, graph, range, scale, nonNegative, access));
 }