Exemplo n.º 1
0
        /// <summary>
        /// Initializes a new instance of the <see cref="Time"/> class.
        /// </summary>
        /// <param name="context">The binding context.</param>
        public Time(IBindingContext context)
            : base(context)
        {
            _bp = context.GetParameterSet <Parameters>();

            // Create derivatives for the numerator and denominator
            _state  = context.GetState <ITimeSimulationState>();
            _method = context.GetState <IIntegrationMethod>();
            if (_bp.Numerator.Length > 1)
            {
                _dNumerator = new IDerivative[_bp.Numerator.Length - 1];
                for (int i = 0; i < _dNumerator.Length; i++)
                {
                    _dNumerator[i] = _method.CreateDerivative();
                }
            }
            else
            {
                _dNumerator = null;
            }
            if (_bp.Denominator.Length > 1)
            {
                _dDenominator = new IDerivative[_bp.Denominator.Length - 1];
                for (int i = 0; i < _dDenominator.Length; i++)
                {
                    _dDenominator[i] = _method.CreateDerivative();
                }
            }
            else
            {
                _dDenominator = null;
            }
        }
Exemplo n.º 2
0
 public DerivativeTesterBehavior(IBindingContext context, Func <double, double> reference, double initial, double relTol, double absTol)
     : base(context)
 {
     _biasing    = context.GetState <IBiasingSimulationState>();
     _method     = context.GetState <IIntegrationMethod>();
     _time       = context.GetState <ITimeSimulationState>();
     _derivative = _method.CreateDerivative();
     _reference  = reference;
     _initial    = initial;
     _relTol     = relTol;
     _absTol     = absTol;
 }
Exemplo n.º 3
0
        /// <summary>
        /// Initializes a new instance of the <see cref="Time"/> class.
        /// </summary>
        /// <param name="context">The context.</param>
        /// <exception cref="ArgumentNullException">Thrown if <paramref name="context"/> is <c>null</c>.</exception>
        public Time(BehavioralBindingContext context)
            : base(context)
        {
            var bp    = context.GetParameterSet <Parameters>();
            var state = context.GetState <IBiasingSimulationState>();

            _method = context.GetState <IIntegrationMethod>();
            _time   = context.GetState <ITimeSimulationState>();

            var derivatives         = new List <Func <double> >(Derivatives.Count);
            var derivativeVariables = new List <IVariable <double> >(Derivatives.Count);
            var builder             = new RealFunctionBuilder();

            builder.VariableFound += (sender, args) =>
            {
                if (args.Variable == null && DerivativeVariables.TryGetValue(args.Node, out var variable))
                {
                    args.Variable = variable;
                }
            };
            bp.RegisterBuilder(context, builder);
            var matLocs = new List <MatrixLocation>(Derivatives.Count * 2);
            var rhsLocs = Variables.GetRhsIndices(state.Map);

            foreach (var pair in Derivatives)
            {
                var variable = DerivativeVariables[pair.Key];
                if (state.Map.Contains(variable))
                {
                    derivatives.Add(builder.Build(pair.Value));
                    derivativeVariables.Add(variable);
                    matLocs.Add(new MatrixLocation(rhsLocs[0], state.Map[variable]));
                    matLocs.Add(new MatrixLocation(rhsLocs[1], state.Map[variable]));
                }
            }
            _value               = builder.Build(Function);
            _derivatives         = derivatives.ToArray();
            _values              = new double[_derivatives.Length * 2 + 2];
            _derivativeVariables = derivativeVariables.ToArray();

            // Get the matrix elements
            _elements = new ElementSet <double>(state.Solver, matLocs.ToArray(), rhsLocs);

            // Create the derivative
            _qcap = _method.CreateDerivative();
        }