예제 #1
0
        /// <summary>
        /// Registers that a model has a dev parameter.
        /// </summary>
        /// <param name="model">A model.</param>
        /// <param name="generator">A model generator.</param>
        /// <param name="parameter">A parameter.</param>
        /// <param name="tolerance">A tolerance (value of dev).</param>
        /// <param name="distributionName">Distribution name.</param>
        public void RegisterModelDev(
            Model model,
            Func <string, Model> generator,
            Parameter parameter,
            Parameter tolerance,
            string distributionName)
        {
            if (model == null)
            {
                throw new ArgumentNullException(nameof(model));
            }

            if (generator == null)
            {
                throw new ArgumentNullException(nameof(generator));
            }

            if (parameter == null)
            {
                throw new ArgumentNullException(nameof(parameter));
            }

            if (tolerance == null)
            {
                throw new ArgumentNullException(nameof(tolerance));
            }

            if (!ModelsWithDev.ContainsKey(model))
            {
                ModelsWithDev[model] = new Dictionary <Parameter, ParameterRandomness>();
            }

            ModelsWithDev[model][parameter] = new ParameterRandomness
            {
                RandomDistributionName = distributionName,
                Tolerance = tolerance,
            };

            if (!ModelsGenerators.ContainsKey(model))
            {
                ModelsGenerators[model] = generator;
            }
        }
예제 #2
0
        /// <summary>
        /// Registers that a model has a lot parameter.
        /// </summary>
        /// <param name="model">A model.</param>
        /// <param name="generator">A model generator.</param>
        /// <param name="parameter">A parameter.</param>
        /// <param name="tolerance">A tolerance (value of lot).</param>
        /// <param name="distributionName">Distribution name.</param>
        public void RegisterModelLot(
            Model model,
            Func <string, Model> generator,
            Parameter parameter,
            Parameter tolerance,
            string distributionName)
        {
            if (!ModelsWithLot.ContainsKey(model))
            {
                ModelsWithLot[model] = new Dictionary <Parameter, ParameterRandomness>();
            }

            ModelsWithLot[model][parameter] = new ParameterRandomness
            {
                RandomDistributionName = distributionName,
                Tolerance = tolerance,
            };

            if (!ModelsGenerators.ContainsKey(model))
            {
                ModelsGenerators[model] = generator;
            }
        }
예제 #3
0
        /// <summary>
        /// Gets the stochastic model LOT parameters.
        /// </summary>
        /// <param name="baseModel">A base model.</param>
        /// <returns>
        /// A dictionary of LOT parameters and their tolerance value.
        /// </returns>
        public Dictionary <Parameter, ParameterRandomness> GetStochasticModelLotParameters(Model baseModel)
        {
            if (ModelsWithLot.ContainsKey(baseModel))
            {
                return(ModelsWithLot[baseModel]);
            }

            return(null);
        }
예제 #4
0
 /// <summary>
 /// Registers a model in the registry.
 /// </summary>
 /// <param name="model">A model to register.</param>
 public void RegisterModelInstance(Model model)
 {
     AllModels[model.Name] = model;
 }
예제 #5
0
        /// <summary>
        /// Provides a model for component.
        /// </summary>
        /// <param name="componentName">A component name.</param>
        /// <param name="simulation">Simulation.</param>
        /// <param name="model">A model for component.</param>
        /// <returns>
        /// If a model is stochastic (dev, lot) then a copy of model with be returned.
        /// If a model is not stochastic then a raw model is returned.
        /// </returns>
        public Model ProvideStochasticModel(string componentName, BaseSimulation simulation, Model model)
        {
            if (ModelsGenerators.ContainsKey(model))
            {
                string modelId           = $"{model.Name}#{componentName}_{simulation.Name}";
                var    modelForComponent = ModelsGenerators[model](modelId);

                if (!StochasticModels.ContainsKey(simulation))
                {
                    StochasticModels[simulation] = new Dictionary <Model, List <Model> >();
                }

                if (!StochasticModels[simulation].ContainsKey(model))
                {
                    StochasticModels[simulation][model] = new List <Model>();
                }

                StochasticModels[simulation][model].Add(modelForComponent);
                return(modelForComponent);
            }

            return(model);
        }
예제 #6
0
        private static void RegisterDevAndLotModels(ParameterCollection parameters, IStochasticModelsRegistry stochasticModelRegistry, SpiceSharp.Components.Model model, Func <string, SpiceSharp.Components.Model> generator)
        {
            for (var i = 0; i < parameters.Count; i++)
            {
                var    parameter    = parameters[i].Image;
                string distribution = null;

                if (parameter.Contains("/"))
                {
                    var parts = parameter.Split('/');
                    parameter    = parts[0].ToUpper();
                    distribution = parts[1];
                }
                else
                {
                    parameter = parameter.ToUpper();
                }

                if (parameter == "DEV")
                {
                    stochasticModelRegistry.RegisterModelDev(
                        model,
                        generator,
                        parameters[i - 1],
                        parameters[i + 1],
                        distribution);

                    i++;
                }
                else if (parameter == "LOT")
                {
                    stochasticModelRegistry.RegisterModelLot(
                        model,
                        generator,
                        parameters[i - 1],
                        parameters[i + 1],
                        distribution);
                    i++;
                }
            }
        }