public void SetParameter(IEntity entity, string parameterName, Parameter parameter, bool beforeTemperature = true, bool onload = true) { if (entity == null) { throw new ArgumentNullException(nameof(entity)); } if (parameterName == null) { throw new ArgumentNullException(nameof(parameterName)); } if (parameter == null) { throw new ArgumentNullException(nameof(parameter)); } string expression = null; if (parameter is SingleParameter sp) { expression = sp.Image; } if (parameter is AssignmentParameter asg) { expression = asg.Value; } try { double value = Evaluator.EvaluateDouble(expression); entity.SetParameter(parameterName, value); var context = Evaluator.GetEvaluationContext(); bool isDynamic = context.HaveSpiceProperties(expression) || context.HaveFunctions(expression) || context.GetExpressionParameters(expression, false).Any(); if (isDynamic) { SimulationPreparations.SetParameter(entity, parameterName, expression, beforeTemperature, onload); } } catch (Exception ex) { Result.Validation.Add( new ValidationEntry( ValidationEntrySource.Reader, ValidationEntryLevel.Warning, $"Exception during evaluation of parameter with expression: `{expression}`: {ex}", parameter.LineInfo)); } }
/// <summary> /// Sets voltage initial condition for node. /// </summary> /// <param name="nodeName">Name of node.</param> /// <param name="expression">Expression string.</param> public void SetICVoltage(string nodeName, string expression) { if (nodeName == null) { throw new ArgumentNullException(nameof(nodeName)); } if (expression == null) { throw new ArgumentNullException(nameof(expression)); } var nodeId = NameGenerator.GenerateNodeName(nodeName); SimulationPreparations.SetICVoltage(nodeId, expression); }
public void SetParameter(IEntity entity, string parameterName, string expression, bool beforeTemperature = true, bool onload = true, Simulation simulation = null) { if (entity == null) { throw new ArgumentNullException(nameof(entity)); } if (parameterName == null) { throw new ArgumentNullException(nameof(parameterName)); } if (expression == null) { throw new ArgumentNullException(nameof(expression)); } double value = Evaluator.EvaluateDouble(expression, simulation); try { entity.SetParameter(parameterName, value); var context = Evaluator.GetEvaluationContext(); bool isDynamic = context.HaveSpiceProperties(expression) || context.HaveFunctions(expression) || context.GetExpressionParameters(expression, false).Any(); if (isDynamic) { SimulationPreparations.SetParameter(entity, parameterName, expression, beforeTemperature, onload); } } catch (Exception e) { Result.Validation.Add( new ValidationEntry( ValidationEntrySource.Reader, ValidationEntryLevel.Warning, $"Problem with setting parameter = {parameterName} with value = {value}", exception: e)); } }