Ejemplo n.º 1
0
 /// <summary>
 /// Occurs for each tick of the timer. Increases the time elapsed, the step number,
 /// and moves the functions and creates a new future.
 /// </summary>
 private void TimeStep()
 {
     _timeElapsed += _dt;
     _ypast        = _ycurrent;
     _ycurrent     = _yfuture;
     _yfuture      = new YValues(_ypast, _ycurrent, _current);
     // _numOfSteps++;
 }
Ejemplo n.º 2
0
        /// <summary>
        /// Clears out the graphic and resets the program.
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void ClearButton_Click(object sender, EventArgs e)
        {
            _startButton.Enabled  = true;
            _resumeButton.Enabled = false;
            _pauseButton.Enabled  = false;
            _clearButton.Enabled  = false;
            _timer.Enabled        = false;
            _graphics.Clear(Color.Beige);
            _timeElapsed    = 0;
            _timeShown.Text = _timeElapsed.ToString("E03");
            _graphics.Dispose();

            _ycurrent = new YValues();
            _ypast    = new YValues();
            _yfuture  = new YValues();
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Initializes values with previous and current values at n*dt sec
        /// </summary>
        /// <param name="n">number of steps passed</param>
        /// <param name="past">past values</param>
        /// <param name="current">current values</param>
        /// <param name="cblue">speed through current medium</param>
        public YValues(YValues past, YValues current, int cblue)
        {
            _values[0]   = 0;
            _values[254] = 0;

            double r2 = cblue * _dt / _dx;

            for (int i = 1; i < _values.Length / 2; i++)
            {
                _values[i] = 2 * (1 - (_r1 * _r1)) * current.Element(i) - past.Element(i) +
                             _r1 * _r1 * (current.Element(i + 1) + current.Element(i - 1));
            }
            for (int i = _values.Length / 2; i < _values.Length - 1; i++)
            {
                _values[i] = 2 * (1 - (r2 * r2)) * current.Element(i) - past.Element(i) +
                             r2 * r2 * (current.Element(i + 1) + current.Element(i - 1));
            }
        }
Ejemplo n.º 4
0
        /// <summary>
        /// Changes the current medium, and resets the program.
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void MaterialsList_SelectedIndexChanged(object sender, EventArgs e)
        {
            _timer.Enabled        = false;
            _startButton.Enabled  = true;
            _pauseButton.Enabled  = false;
            _resumeButton.Enabled = false;
            _clearButton.Enabled  = false;
            _timeElapsed          = 0;
            _timeShown.Text       = _timeElapsed.ToString("E03");

            int selected = _materialsList.SelectedIndex;

            if (selected == 5)
            {
                var rng = SmallRng.Create();
                selected = _dist.Sample(rng);
            }

            if (selected == 0)
            {
                _current = _glass;
            }
            else if (selected == 1)
            {
                _current = _diamond;
            }
            else if (selected == 2)
            {
                _current = _water;
            }
            else if (selected == 3)
            {
                _current = _air;
            }
            else if (selected == 4)
            {
                _current = _brett;
            }


            _ycurrent = new YValues();
            _ypast    = new YValues();
            _yfuture  = new YValues();
        }