Ejemplo n.º 1
0
        /// <summary>
        /// Continues the simulation.
        /// </summary>
        /// <param name="simulation">The time-based simulation</param>
        /// <param name="delta">The initial probing timestep.</param>
        public override void Continue(TimeSimulation simulation, ref double delta)
        {
            // Modify the timestep
            delta = Math.Min(delta, MaxStep);

            // Handle breakpoints
            if (Time.Equals(Breakpoints.First) || Breakpoints.First - Time <= MinStep)
            {
                // Cut integration order
                Order = 1;

                // Limit the next timestep
                var mt = Math.Min(_saveDelta, Breakpoints.Delta);
                delta = Math.Min(delta, 0.1 * mt);

                // Spice will divide the first timestep by 10
                if (BaseTime.Equals(0.0))
                {
                    delta /= 10.0;
                }

                // Don't go below MinStep without reason
                delta = Math.Max(delta, 2.0 * MinStep);
            }
            else if (Time + delta >= Breakpoints.First)
            {
                Break      = true;
                _saveDelta = delta;
                delta      = Breakpoints.First - Time;
            }

            base.Continue(simulation, ref delta);
        }
Ejemplo n.º 2
0
 public GeData(BaseTime n) : this(C4dApiPINVOKE.new_GeData__SWIG_13(BaseTime.getCPtr(n)), true)
 {
     if (C4dApiPINVOKE.SWIGPendingException.Pending)
     {
         throw C4dApiPINVOKE.SWIGPendingException.Retrieve();
     }
 }
Ejemplo n.º 3
0
        /// <summary>
        /// Evaluates whether or not the current solution can be accepted.
        /// </summary>
        /// <param name="simulation">The time-based simulation.</param>
        /// <param name="newDelta">The next requested timestep in case the solution is not accepted.</param>
        /// <returns>
        /// <c>true</c> if the time point is accepted; otherwise, <c>false</c>.
        /// </returns>
        /// <exception cref="SpiceSharp.CircuitException">Timestep {0:e} is too small at time {1:e}".FormatString(newDelta, BaseTime)</exception>
        public override bool Evaluate(TimeSimulation simulation, out double newDelta)
        {
            // Spice 3f5 ignores the first timestep
            if (BaseTime.Equals(0.0))
            {
                newDelta = IntegrationStates[0].Delta;
                return(true);
            }

            var result = base.Evaluate(simulation, out newDelta);

            // Limit the expansion of the timestep
            newDelta = Math.Min(Expansion * IntegrationStates[0].Delta, newDelta);

            // Limit the maximum timestep
            if (newDelta > MaxStep)
            {
                newDelta = MaxStep;
            }

            // If the timestep is consistently made smaller than the minimum timestep, throw an exception
            if (newDelta <= MinStep)
            {
                // If we already tried
                if (_oldDelta <= MinStep)
                {
                    throw new CircuitException("Timestep {0:e} is too small at time {1:e}".FormatString(newDelta, BaseTime));
                }
                newDelta = MinStep;
            }

            return(result);
        }
Ejemplo n.º 4
0
            /// <summary>
            /// Accepts a solution at the current timepoint.
            /// </summary>
            public virtual void Accept()
            {
                // Store the accepted solution
                State.Solution.CopyTo(States.Value.Solution);

                // When just starting out, we want to copy all the states to the previous states.
                if (BaseTime.Equals(0.0))
                {
                    foreach (var istate in States)
                    {
                        istate.Delta = Parameters.MaxStep;
                        States.Value.State.CopyTo(istate.State);
                    }
                }

                // Accept all the registered states
                foreach (var state in RegisteredStates)
                {
                    state.Accept();
                }

                // Clear the breakpoints
                while (Time > Breakpoints.First)
                {
                    Breakpoints.ClearBreakpoint();
                }
                Break = false;
            }
Ejemplo n.º 5
0
 public void SetTimeRight(CCurve seq, BaseTime t)
 {
     C4dApiPINVOKE.CKey_SetTimeRight(swigCPtr, CCurve.getCPtr(seq), BaseTime.getCPtr(t));
     if (C4dApiPINVOKE.SWIGPendingException.Pending)
     {
         throw C4dApiPINVOKE.SWIGPendingException.Retrieve();
     }
 }
Ejemplo n.º 6
0
 public void SetTime(int id, BaseTime b)
 {
     C4dApiPINVOKE.BaseContainer_SetTime(swigCPtr, id, BaseTime.getCPtr(b));
     if (C4dApiPINVOKE.SWIGPendingException.Pending)
     {
         throw C4dApiPINVOKE.SWIGPendingException.Retrieve();
     }
 }
Ejemplo n.º 7
0
 public void AnimateObject(BaseList2D op, BaseTime time, ANIMATEFLAGS flags)
 {
     C4dApiPINVOKE.BaseDocument_AnimateObject(swigCPtr, BaseList2D.getCPtr(op), BaseTime.getCPtr(time), (int)flags);
     if (C4dApiPINVOKE.SWIGPendingException.Pending)
     {
         throw C4dApiPINVOKE.SWIGPendingException.Retrieve();
     }
 }
Ejemplo n.º 8
0
 public void SetLoopMaxTime(BaseTime t)
 {
     C4dApiPINVOKE.BaseDocument_SetLoopMaxTime(swigCPtr, BaseTime.getCPtr(t));
     if (C4dApiPINVOKE.SWIGPendingException.Pending)
     {
         throw C4dApiPINVOKE.SWIGPendingException.Retrieve();
     }
 }
Ejemplo n.º 9
0
 public void SetBaseTime(BaseTime v)
 {
     C4dApiPINVOKE.GeData_SetBaseTime(swigCPtr, BaseTime.getCPtr(v));
     if (C4dApiPINVOKE.SWIGPendingException.Pending)
     {
         throw C4dApiPINVOKE.SWIGPendingException.Retrieve();
     }
 }
Ejemplo n.º 10
0
        public void Min_Max__Arg_Is_Not_Deterministic_With_Different_Seed()
        {
            var max = BaseTime.AddYears(1);

            Assertion.IsNotDeterministic(
                i => new DateTimeRandomizer(new Random(i)),
                x => x.DateTime(BaseTime, max)
                );
        }
Ejemplo n.º 11
0
        public bool Draw(SWIGTYPE_p_GeClipMap map, BaseTime clip_left, BaseTime clip_right)
        {
            bool ret = C4dApiPINVOKE.CTrack_Draw(swigCPtr, SWIGTYPE_p_GeClipMap.getCPtr(map), BaseTime.getCPtr(clip_left), BaseTime.getCPtr(clip_right));

            if (C4dApiPINVOKE.SWIGPendingException.Pending)
            {
                throw C4dApiPINVOKE.SWIGPendingException.Retrieve();
            }
            return(ret);
        }
Ejemplo n.º 12
0
        public bool AnimateTrack(BaseDocument doc, BaseList2D op, BaseTime tt, int flags, SWIGTYPE_p_Bool chg)
        {
            bool ret = C4dApiPINVOKE.CTrack_AnimateTrack__SWIG_1(swigCPtr, BaseDocument.getCPtr(doc), BaseList2D.getCPtr(op), BaseTime.getCPtr(tt), flags, SWIGTYPE_p_Bool.getCPtr(chg));

            if (C4dApiPINVOKE.SWIGPendingException.Pending)
            {
                throw C4dApiPINVOKE.SWIGPendingException.Retrieve();
            }
            return(ret);
        }
Ejemplo n.º 13
0
        public bool SetTime(BaseTime t, GvRun r)
        {
            bool ret = C4dApiPINVOKE.GvPort_SetTime(swigCPtr, BaseTime.getCPtr(t), GvRun.getCPtr(r));

            if (C4dApiPINVOKE.SWIGPendingException.Pending)
            {
                throw C4dApiPINVOKE.SWIGPendingException.Retrieve();
            }
            return(ret);
        }
Ejemplo n.º 14
0
        public bool SetTimeRightAdjustValue(CCurve seq, BaseTime t)
        {
            bool ret = C4dApiPINVOKE.CKey_SetTimeRightAdjustValue(swigCPtr, CCurve.getCPtr(seq), BaseTime.getCPtr(t));

            if (C4dApiPINVOKE.SWIGPendingException.Pending)
            {
                throw C4dApiPINVOKE.SWIGPendingException.Retrieve();
            }
            return(ret);
        }
Ejemplo n.º 15
0
        public double GetValue(BaseDocument doc, BaseTime time)
        {
            double ret = C4dApiPINVOKE.CTrack_GetValue(swigCPtr, BaseDocument.getCPtr(doc), BaseTime.getCPtr(time));

            if (C4dApiPINVOKE.SWIGPendingException.Pending)
            {
                throw C4dApiPINVOKE.SWIGPendingException.Retrieve();
            }
            return(ret);
        }
Ejemplo n.º 16
0
        public bool WriteTime(BaseTime v)
        {
            bool ret = C4dApiPINVOKE.HyperFile_WriteTime(swigCPtr, BaseTime.getCPtr(v));

            if (C4dApiPINVOKE.SWIGPendingException.Pending)
            {
                throw C4dApiPINVOKE.SWIGPendingException.Retrieve();
            }
            return(ret);
        }
Ejemplo n.º 17
0
        public int TimeDif(BaseTime t2)
        {
            int ret = C4dApiPINVOKE.BaseTime_TimeDif(swigCPtr, BaseTime.getCPtr(t2));

            if (C4dApiPINVOKE.SWIGPendingException.Pending)
            {
                throw C4dApiPINVOKE.SWIGPendingException.Retrieve();
            }
            return(ret);
        }
Ejemplo n.º 18
0
        public bool RecordKey(BaseList2D op, BaseTime time, DescID id, BaseList2D undo, bool eval_attribmanager, bool autokeying, bool allow_linking)
        {
            bool ret = C4dApiPINVOKE.BaseDocument_RecordKey(swigCPtr, BaseList2D.getCPtr(op), BaseTime.getCPtr(time), DescID.getCPtr(id), BaseList2D.getCPtr(undo), eval_attribmanager, autokeying, allow_linking);

            if (C4dApiPINVOKE.SWIGPendingException.Pending)
            {
                throw C4dApiPINVOKE.SWIGPendingException.Retrieve();
            }
            return(ret);
        }
Ejemplo n.º 19
0
        public BaseTime GetTime(int id, BaseTime preset)
        {
            BaseTime ret = new BaseTime(C4dApiPINVOKE.BaseContainer_GetTime__SWIG_0(swigCPtr, id, BaseTime.getCPtr(preset)), true);

            if (C4dApiPINVOKE.SWIGPendingException.Pending)
            {
                throw C4dApiPINVOKE.SWIGPendingException.Retrieve();
            }
            return(ret);
        }
Ejemplo n.º 20
0
        public bool CollectSounds(SWIGTYPE_p_BaseSound snd, BaseTime from, BaseTime to)
        {
            bool ret = C4dApiPINVOKE.BaseDocument_CollectSounds(swigCPtr, SWIGTYPE_p_BaseSound.getCPtr(snd), BaseTime.getCPtr(from), BaseTime.getCPtr(to));

            if (C4dApiPINVOKE.SWIGPendingException.Pending)
            {
                throw C4dApiPINVOKE.SWIGPendingException.Retrieve();
            }
            return(ret);
        }
Ejemplo n.º 21
0
        public double GetValue(BaseTime time)
        {
            double ret = C4dApiPINVOKE.CCurve_GetValue(swigCPtr, BaseTime.getCPtr(time));

            if (C4dApiPINVOKE.SWIGPendingException.Pending)
            {
                throw C4dApiPINVOKE.SWIGPendingException.Retrieve();
            }
            return(ret);
        }
Ejemplo n.º 22
0
        public int MoveKey(BaseTime time, int idx)
        {
            int ret = C4dApiPINVOKE.CCurve_MoveKey__SWIG_1(swigCPtr, BaseTime.getCPtr(time), idx);

            if (C4dApiPINVOKE.SWIGPendingException.Pending)
            {
                throw C4dApiPINVOKE.SWIGPendingException.Retrieve();
            }
            return(ret);
        }
Ejemplo n.º 23
0
        public CKey AddKey(BaseTime time, SWIGTYPE_p_Int32 nidx)
        {
            global::System.IntPtr cPtr = C4dApiPINVOKE.CCurve_AddKey__SWIG_0(swigCPtr, BaseTime.getCPtr(time), SWIGTYPE_p_Int32.getCPtr(nidx));
            CKey ret = (cPtr == global::System.IntPtr.Zero) ? null : new CKey(cPtr, false);

            if (C4dApiPINVOKE.SWIGPendingException.Pending)
            {
                throw C4dApiPINVOKE.SWIGPendingException.Retrieve();
            }
            return(ret);
        }
Ejemplo n.º 24
0
        public CKey FindKey(BaseTime time)
        {
            global::System.IntPtr cPtr = C4dApiPINVOKE.CCurve_FindKey__SWIG_2(swigCPtr, BaseTime.getCPtr(time));
            CKey ret = (cPtr == global::System.IntPtr.Zero) ? null : new CKey(cPtr, false);

            if (C4dApiPINVOKE.SWIGPendingException.Pending)
            {
                throw C4dApiPINVOKE.SWIGPendingException.Retrieve();
            }
            return(ret);
        }
Ejemplo n.º 25
0
        public CKey AddKeyAdaptTangent(BaseTime time, bool bUndo)
        {
            global::System.IntPtr cPtr = C4dApiPINVOKE.CCurve_AddKeyAdaptTangent__SWIG_1(swigCPtr, BaseTime.getCPtr(time), bUndo);
            CKey ret = (cPtr == global::System.IntPtr.Zero) ? null : new CKey(cPtr, false);

            if (C4dApiPINVOKE.SWIGPendingException.Pending)
            {
                throw C4dApiPINVOKE.SWIGPendingException.Retrieve();
            }
            return(ret);
        }
Ejemplo n.º 26
0
 /// <inheritdoc/>
 public void Accept()
 {
     if (BaseTime.Equals(0.0))
     {
         foreach (var state in _states)
         {
             _states.Value.CopyTo(state);
         }
     }
     foreach (var state in _registeredStates)
     {
         state.Accept();
     }
 }
Ejemplo n.º 27
0
        /// <summary>
        /// Returns the cumulative time based on the given base time and duration iteration
        /// </summary>
        /// <param name="iteration">The iteration.</param>
        /// <returns></returns>
        public DateTime CumulativeTime(int iteration)
        {
            var timeSpan = TimeSpan.Zero;

            if (iteration >= 0)
            {
                for (int i = 0; i <= iteration; i++)
                {
                    timeSpan = timeSpan.Add(_items[i % _items.Count].Duration);
                }
            }

            return(BaseTime.Add(timeSpan));
        }
Ejemplo n.º 28
0
        //internal method to return a collection of Time Zones
        public TimeZoneCustom[] GetTimeZonesInfo(bool CaterForDST)
        {
            List <TimeZoneCustom> timeZones = new List <TimeZoneCustom>();

            DateTime currentTimeUTC = BaseTime.ToUniversalTime();

            //get a list of all the timezone definitions
            foreach (TimeZoneInfo tzi in TimeZoneInfo.GetSystemTimeZones())
            {
                TimeZoneCustom tz = new TimeZoneCustom(BaseTime, tzi, CaterForDST);
                timeZones.Add(tz);
            }
            return(timeZones.ToArray());
        }
Ejemplo n.º 29
0
        /// <summary>
        /// Truncates the timestep based on the states.
        /// </summary>
        /// <param name="sender">The sender (integration method).</param>
        /// <param name="args">The <see cref="TruncateEvaluateEventArgs"/> instance containing the event data.</param>
        protected virtual void TruncateStates(object sender, TruncateEvaluateEventArgs args)
        {
            args.ThrowIfNull(nameof(args));

            // Don't truncate the first step
            if (BaseTime.Equals(0.0))
            {
                return;
            }

            // Truncate!
            var newDelta = args.Delta;

            foreach (var state in TruncatableStates)
            {
                newDelta = Math.Min(newDelta, state.Truncate());
            }

            if (newDelta > 0.9 * IntegrationStates[0].Delta)
            {
                if (Order < MaxOrder)
                {
                    // Try increasing the order
                    Order++;
                    args.Order = Order;

                    // Try truncation again
                    newDelta = args.Delta;
                    foreach (var state in TruncatableStates)
                    {
                        newDelta = Math.Min(newDelta, state.Truncate());
                    }

                    // Increasing the order doesn't make a significant difference
                    if (newDelta <= 1.05 * IntegrationStates[0].Delta)
                    {
                        Order--;
                        args.Order = Order;
                    }
                }
            }
            else
            {
                args.Accepted = false;
            }

            args.Delta = newDelta;
        }
Ejemplo n.º 30
0
        public BaseTime GetCuringTime(string timeData)
        {
            var result  = new BaseTime();
            var time    = DateTime.Now;
            var timeNew = DateTime.Now;

            if (timeData.Length == 4)
            {
                timeNew          = time.AddYears((Convert.ToInt16(timeData) - time.Year));
                result.StartTime = new DateTime(timeNew.Year, 1, 1);
                result.EndTime   = result.StartTime.Value.AddYears(1).AddDays(-1);
            }
            if (timeData.Length > 4)
            {
                timeNew          = Convert.ToDateTime(timeData + "-01 00:00:00");
                result.StartTime = new DateTime(timeNew.Year, timeNew.Month, 1);
                result.EndTime   = result.StartTime.Value.AddMonths(1).AddDays(-1);
            }
            return(result);
        }