示例#1
0
        /// <summary>
        /// Create a simulation using the given solution and the specified inputs/outputs.
        /// </summary>
        /// <param name="Solution">Transient solution to run.</param>
        /// <param name="Input">Expressions in the solution to be defined by input samples.</param>
        /// <param name="Output">Expressions describing outputs to be saved from the simulation.</param>
        public Simulation(TransientSolution Solution)
        {
            solution = Solution;

            // If any system depends on the previous value of an unknown, we need a global variable for it.
            foreach (Expression i in Solution.Solutions.SelectMany(i => i.Unknowns))
            {
                if (Solution.Solutions.Any(j => j.DependsOn(i.Evaluate(t, t0))))
                {
                    AddGlobal(i.Evaluate(t, t0));
                }
            }
            // Also need globals for any Newton's method unknowns.
            foreach (Expression i in Solution.Solutions.OfType <NewtonIteration>().SelectMany(i => i.Unknowns))
            {
                AddGlobal(i.Evaluate(t, t0));
            }

            // Set the global values to the initial conditions of the solution.
            foreach (KeyValuePair <Expression, GlobalExpr <double> > i in globals)
            {
                Expression init = i.Key.Evaluate(t0, 0).Evaluate(Solution.InitialConditions);
                i.Value.Value = init is Constant ? (double)init : 0.0;
            }

            InvalidateProcess();
        }
示例#2
0
        /// <summary>
        /// Create a simulation using the given solution and the specified inputs/outputs.
        /// </summary>
        /// <param name="Solution">Transient solution to run.</param>
        /// <param name="Input">Expressions in the solution to be defined by input samples.</param>
        /// <param name="Output">Expressions describing outputs to be saved from the simulation.</param>
        public Simulation(TransientSolution Solution)
        {
            solution = Solution;

            // If any system depends on the previous value of an unknown, we need a global variable for it.
            for (int n = -1; n >= MaxDelay; n--)
            {
                Arrow t_tn = Arrow.New(t, t + n * Solution.TimeStep);
                IEnumerable <Expression> unknowns_tn = Solution.Solutions.SelectMany(i => i.Unknowns).Select(i => i.Evaluate(t_tn));
                if (!Solution.Solutions.Any(i => i.DependsOn(unknowns_tn)))
                {
                    break;
                }

                foreach (Expression i in Solution.Solutions.SelectMany(i => i.Unknowns))
                {
                    AddGlobal(i.Evaluate(t_tn));
                }
            }

            // Also need globals for any Newton's method unknowns.
            Arrow t_t1 = Arrow.New(t, t - Solution.TimeStep);

            foreach (Expression i in Solution.Solutions.OfType <NewtonIteration>().SelectMany(i => i.Unknowns))
            {
                AddGlobal(i.Evaluate(t_t1));
            }

            // Set the global values to the initial conditions of the solution.
            foreach (KeyValuePair <Expression, GlobalExpr <double> > i in globals)
            {
                // Dumb hack to get f[t - x] -> f[0] for any x.
                Expression i_t0 = i.Key.Evaluate(t, Real.Infinity).Substitute(Real.Infinity, 0);
                Expression init = i_t0.Evaluate(Solution.InitialConditions);
                i.Value.Value = init is Constant ? (double)init : 0.0;
            }

            InvalidateProcess();
        }