Пример #1
0
        public VectorOI MultiplyNew(Complex rhs)
        {
            var keys = this._components.Keys.ToList();

            VectorOI result = new VectorOI();

            foreach (var key in keys)
            {
                Complex val1    = this[key];
                var     product = val1 * rhs;
                result[key] = product;
            }
            return(result);
        }
Пример #2
0
        public VectorOI AddSelf(VectorOI rhs)
        {
            VectorOI lhs  = this;
            var      keys = this._components.Keys.ToList();

            if (lhs.Count != rhs.Count)
            {
                throw new ArgumentException();
            }

            foreach (var key in keys)
            {
                var val1 = lhs[key];
                var val2 = rhs[key];
                var sum  = val1 + val2;
                this[key] = sum;
            }

            return(this);
        }
        /// <summary>
        /// Execute one iteration of integration, moving
        /// the dynamical system forward in time by
        /// the given delta time.
        /// </summary>
        public void Step(double deltaTime)
        {
            double h      = deltaTime;
            double halfH  = deltaTime * 0.5;
            double sixthH = deltaTime / 6.0;
            double t00    = this.Time;
            double t05    = this.Time + halfH;
            double t10    = this.Time + h;

            VectorOI y0 = _nodes.ToVectorOI(n => n, n => n.Value);

            VectorOI k1 = _nodes.ToVectorOI(n => n, n => n.F(t00, y0));

            VectorOI k1Blend = k1.MultiplyNew(halfH).AddSelf(y0);
            VectorOI k2      = _nodes.ToVectorOI(n => n, n => n.F(t05, k1Blend));

            VectorOI k2Blend = k2.MultiplyNew(halfH).AddSelf(y0);
            VectorOI k3      = _nodes.ToVectorOI(n => n, n => n.F(t05, k2Blend));

            VectorOI k3Blend = k3.MultiplyNew(h).AddSelf(y0);
            VectorOI k4      = _nodes.ToVectorOI(n => n, n => n.F(t10, k3Blend));


            // Perform final runge-kutta weighted average.

            // We mutate k1, k2 and k3 here.
            k2.MultiplySelf(2.0);
            k3.MultiplySelf(2.0);
            VectorOI y1 = k1.AddSelf(k2).AddSelf(k3).AddSelf(k4).MultiplySelf(sixthH).AddSelf(y0);


            // Store results back into each node.
            foreach (var kvp in y1)
            {
                DynamicalNode node = kvp.Key as DynamicalNode;
                node.Value = kvp.Value;
            }

            this.Time = t10;
            this.Iteration++;
        }
Пример #4
0
        public VectorOI AddNew(VectorOI rhs)
        {
            VectorOI lhs  = this;
            var      keys = this._components.Keys.ToList();

            if (lhs.Count != rhs.Count)
            {
                throw new ArgumentException();
            }

            VectorOI result = new VectorOI();

            foreach (var key in keys)
            {
                var val1 = lhs[key];
                var val2 = rhs[key];
                var sum  = val1 + val2;
                result[key] = sum;
            }
            return(result);
        }
 /// <summary>
 /// Function F for only this node (scalar return value).
 /// </summary>
 public virtual Complex F(double t, VectorOI y)
 {
     return(0.0);
 }