Ejemplo n.º 1
0
        internal void LoadVariableFromParameter(string componentName, string fieldName, ParameterValues parameters, Type dataType, Type[] dimensionTypes)
        {
            if (dimensionTypes.Length == 0)
            {
                var methodInfo  = this.GetType().GetMethod("LoadNonDimensionalVariableFromParameters");
                var typedMethod = methodInfo.MakeGenericMethod(new Type[] { dataType });

                typedMethod.Invoke(this, new object[] { componentName.ToLowerInvariant(), fieldName.ToLowerInvariant(), parameters });
            }
            else if (dimensionTypes.Length == 1)
            {
                //var p = (ParameterValue1Dimensional<T>)parameters[fieldName];
                var p = parameters[fieldName.ToLowerInvariant()];

                if (dimensionTypes[0] == typeof(Timestep))
                {
                    Type     d1       = typeof(FieldParameter1DimensionalTime <>);
                    Type[]   typeArgs = { dataType };
                    Type     d1Typed  = d1.MakeGenericType(typeArgs);
                    object[] args     = { this, p };


                    object value = Activator.CreateInstance(d1Typed, args);

                    //var value = new FieldParameter1DimensionalTime<T>(this, p);

                    var key = new Tuple <string, string>(componentName.ToLowerInvariant(), fieldName.ToLowerInvariant());

                    if (_variablesKeysAlreadyUsed.Contains(key))
                    {
                        throw new ArgumentException();
                    }

                    _dimensionalVariables.Add(key, value);
                    _variablesKeysAlreadyUsed.Add(key);
                }
                else if (typeof(IDimension).IsAssignableFrom(dimensionTypes[0]))
                {
                    Type     d1       = typeof(FieldParameter1Dimensional <,>);
                    Type[]   typeArgs = { dimensionTypes[0], dataType };
                    Type     d1Typed  = d1.MakeGenericType(typeArgs);
                    object[] args     = { this, p };


                    object value = Activator.CreateInstance(d1Typed, args);

                    //var value = new FieldParameter1DimensionalTime<T>(this, p);

                    var key = new Tuple <string, string>(componentName.ToLowerInvariant(), fieldName.ToLowerInvariant());

                    if (_variablesKeysAlreadyUsed.Contains(key))
                    {
                        throw new ArgumentException();
                    }

                    _dimensionalVariables.Add(key, value);
                    _variablesKeysAlreadyUsed.Add(key);
                }
                else
                {
                    throw new ArgumentException("Unknown dimension type");
                }
            }
            else if (dimensionTypes.Length == 2)
            {
                var p = parameters[fieldName.ToLowerInvariant()];

                if (dimensionTypes[0] == typeof(Timestep) && typeof(IDimension).IsAssignableFrom(dimensionTypes[1]))
                {
                    Type     d1       = typeof(FieldParameter2DimensionalTime <,>);
                    Type[]   typeArgs = { dimensionTypes[1], dataType };
                    Type     d1Typed  = d1.MakeGenericType(typeArgs);
                    object[] args     = { this, p };


                    object value = Activator.CreateInstance(d1Typed, args);

                    var key = new Tuple <string, string>(componentName.ToLowerInvariant(), fieldName.ToLowerInvariant());

                    if (_variablesKeysAlreadyUsed.Contains(key))
                    {
                        throw new ArgumentException();
                    }

                    _dimensionalVariables.Add(key, value);
                    _variablesKeysAlreadyUsed.Add(key);
                }
                else if (typeof(IDimension).IsAssignableFrom(dimensionTypes[0]) && typeof(IDimension).IsAssignableFrom(dimensionTypes[1]))
                {
                    Type     d1       = typeof(FieldParameter2Dimensional <, ,>);
                    Type[]   typeArgs = { dimensionTypes[0], dimensionTypes[1], dataType };
                    Type     d1Typed  = d1.MakeGenericType(typeArgs);
                    object[] args     = { this, p };


                    object value = Activator.CreateInstance(d1Typed, args);

                    var key = new Tuple <string, string>(componentName.ToLowerInvariant(), fieldName.ToLowerInvariant());

                    if (_variablesKeysAlreadyUsed.Contains(key))
                    {
                        throw new ArgumentException();
                    }

                    _dimensionalVariables.Add(key, value);
                    _variablesKeysAlreadyUsed.Add(key);
                }
                else
                {
                    throw new ArgumentException("Unknown dimension type");
                }
            }
            else
            {
                throw new ArgumentOutOfRangeException();
            }
        }
Ejemplo n.º 2
0
        internal void LoadVariableFromParameter(string componentName, string fieldName, ParameterValues parameters, Type dataType, Type[] dimensionTypes)
        {
            if (dimensionTypes.Length == 0)
            {
                object value = ((IParameterValueNonDimensionalTypeless)parameters[fieldName.ToLowerInvariant()]).GetElement().GetUntypedValue();

                Add0DimensionalVariable(componentName.ToLowerInvariant(), fieldName.ToLowerInvariant(), dataType, value);
            }
            else if (dimensionTypes.Length == 1)
            {
                //var p = (ParameterValue1Dimensional<T>)parameters[fieldName];
                var p = parameters[fieldName.ToLowerInvariant()];

                if (dimensionTypes[0] == typeof(Timestep))
                {
                    Type     d1       = typeof(FieldParameter1DimensionalTime <>);
                    Type[]   typeArgs = { dataType };
                    Type     d1Typed  = d1.MakeGenericType(typeArgs);
                    object[] args     = { this, p };


                    object value = Activator.CreateInstance(d1Typed, args);

                    //var value = new FieldParameter1DimensionalTime<T>(this, p);

                    var key = new Tuple <string, string>(componentName.ToLowerInvariant(), fieldName.ToLowerInvariant());

                    if (_variables.ContainsKey(key))
                    {
                        throw new ArgumentException();
                    }

                    _variables.Add(key, value);
                }
                else if (typeof(IDimension).IsAssignableFrom(dimensionTypes[0]))
                {
                    Type     d1       = typeof(FieldParameter1Dimensional <,>);
                    Type[]   typeArgs = { dimensionTypes[0], dataType };
                    Type     d1Typed  = d1.MakeGenericType(typeArgs);
                    object[] args     = { this, p };


                    object value = Activator.CreateInstance(d1Typed, args);

                    //var value = new FieldParameter1DimensionalTime<T>(this, p);

                    var key = new Tuple <string, string>(componentName.ToLowerInvariant(), fieldName.ToLowerInvariant());

                    if (_variables.ContainsKey(key))
                    {
                        throw new ArgumentException();
                    }

                    _variables.Add(key, value);
                }
                else
                {
                    throw new ArgumentException("Unknown dimension type");
                }
            }
            else if (dimensionTypes.Length == 2)
            {
                var p = parameters[fieldName.ToLowerInvariant()];

                if (dimensionTypes[0] == typeof(Timestep) && typeof(IDimension).IsAssignableFrom(dimensionTypes[1]))
                {
                    Type     d1       = typeof(FieldParameter2DimensionalTime <,>);
                    Type[]   typeArgs = { dimensionTypes[1], dataType };
                    Type     d1Typed  = d1.MakeGenericType(typeArgs);
                    object[] args     = { this, p };


                    object value = Activator.CreateInstance(d1Typed, args);

                    var key = new Tuple <string, string>(componentName.ToLowerInvariant(), fieldName.ToLowerInvariant());

                    if (_variables.ContainsKey(key))
                    {
                        throw new ArgumentException();
                    }

                    _variables.Add(key, value);
                }
                else if (typeof(IDimension).IsAssignableFrom(dimensionTypes[0]) && typeof(IDimension).IsAssignableFrom(dimensionTypes[1]))
                {
                    Type     d1       = typeof(FieldParameter2Dimensional <, ,>);
                    Type[]   typeArgs = { dimensionTypes[0], dimensionTypes[1], dataType };
                    Type     d1Typed  = d1.MakeGenericType(typeArgs);
                    object[] args     = { this, p };


                    object value = Activator.CreateInstance(d1Typed, args);

                    var key = new Tuple <string, string>(componentName.ToLowerInvariant(), fieldName.ToLowerInvariant());

                    if (_variables.ContainsKey(key))
                    {
                        throw new ArgumentException();
                    }

                    _variables.Add(key, value);
                }
                else
                {
                    throw new ArgumentException("Unknown dimension type");
                }
            }
            else
            {
                throw new ArgumentOutOfRangeException();
            }
        }
Ejemplo n.º 3
0
 public void Set2DimensionalParameter <D1, D2, T>(string componentName, string fieldName, ParameterValues parameter)
     where T : struct
     where D1 : IDimension
     where D2 : IDimension
 {
     Set2DimensionalParameter <D1, D2, T>(componentName.ToLowerInvariant(), fieldName.ToLowerInvariant(), parameter, fieldName.ToLowerInvariant());
 }
Ejemplo n.º 4
0
        public void Set2DimensionalParameter <D1, D2, T>(string componentName, string fieldName, ParameterValues parameters, string parameterName)
            where T : struct
            where D1 : IDimension
            where D2 : IDimension
        {
            var fieldKey = new Tuple <string, string>(componentName.ToLowerInvariant(), fieldName.ToLowerInvariant());

            if (!_dimensionalVariables.ContainsKey(fieldKey))
            {
                throw new InvalidOperationException();
            }

            var p = (ParameterValue2Dimensional <T>)parameters[parameterName.ToLowerInvariant()];

            if (typeof(D1) == typeof(Timestep) && typeof(D2).BaseType == typeof(System.Enum))
            {
                var value = new FieldParameter2DimensionalTime <D2, T>(this, p);

                _dimensionalVariables[fieldKey] = value;
            }
            else if (typeof(D1).BaseType == typeof(Enum) && typeof(D2).BaseType == typeof(Enum))
            {
                var value = new FieldParameter2Dimensional <D1, D2, T>(this, p);

                _dimensionalVariables[fieldKey] = value;
            }
            else
            {
                throw new ArgumentException("Unknown dimension type");
            }
        }
Ejemplo n.º 5
0
 public void LoadTwoDimensionalVariableFromParameters <D1, D2, T>(string componentName, string fieldName, ParameterValues parameter)
     where T : struct
     where D1 : IDimension
     where D2 : IDimension
 {
     LoadTwoDimensionalVariableFromParameters <D1, D2, T>(componentName.ToLowerInvariant(), fieldName.ToLowerInvariant(), parameter, fieldName.ToLowerInvariant());
 }
Ejemplo n.º 6
0
        public void LoadTwoDimensionalVariableFromParameters <D1, D2, T>(string componentName, string fieldName, ParameterValues parameters, string parameterName)
            where T : struct
            where D1 : IDimension
            where D2 : IDimension
        {
            var p = (ParameterValue2Dimensional <T>)parameters[parameterName.ToLowerInvariant()];

            if (typeof(D1) == typeof(Timestep) && typeof(IDimension).IsAssignableFrom(typeof(D2)))
            {
                var value = new FieldParameter2DimensionalTime <D2, T>(this, p);

                Add2DimensionalParameter <Timestep, D2, T>(componentName.ToLowerInvariant(), fieldName.ToLowerInvariant(), value);
            }
            else if (typeof(IDimension).IsAssignableFrom(typeof(D1)) && typeof(IDimension).IsAssignableFrom(typeof(D2)))
            {
                var value = new FieldParameter2Dimensional <D1, D2, T>(this, p);

                Add2DimensionalParameter <D1, D2, T>(componentName.ToLowerInvariant(), fieldName.ToLowerInvariant(), value);
            }
            else
            {
                throw new ArgumentException("Unknown dimension type");
            }
        }
Ejemplo n.º 7
0
        public void LoadNonDimensionalVariableFromParameters <T>(string componentName, string fieldName, ParameterValues parameters) where T : struct
        {
            T value = ((ParameterValueNonDimensional <T>)parameters[fieldName.ToLowerInvariant()]).Value;

            AddNonDimensionalVariable <T>(componentName.ToLowerInvariant(), fieldName.ToLowerInvariant(), value);
        }