Ejemplo n.º 1
0
        /// <summary>
        /// Use the specified fields to calculate the next set of PrognosticFields according to the shallow fluid model
        /// equations.
        /// </summary>
        /// <param name="fields"></param>
        /// <param name="oldFields"></param>
        /// <param name="olderFields"></param>
        /// <returns></returns>
        public PrognosticFields Update(PrognosticFields fields, PrognosticFields oldFields = null, PrognosticFields olderFields = null)
        {
            var derivativeOfHeight   = DerivativeOfHeight(fields.Velocity, fields.Height);
            var derivativeOfVelocity = DerivativeOfVelocity(fields.Velocity, fields.Height);

            // If oldFields & olderFields are defined, use all three to step the simulation forward. Otherwise, use the
            // less-accurate Euler timestepping method and only the most recent set of fields.
            ScalarField <Face>   height;
            VectorField <Vertex> velocity;

            if (oldFields != null && olderFields != null)
            {
                height   = NumericalDerivatives.AdamsBashforth(_options.Timestep, fields.Height, derivativeOfHeight, oldFields.DerivativeOfHeight, olderFields.DerivativeOfHeight);
                velocity = NumericalDerivatives.AdamsBashforth(_options.Timestep, fields.Velocity, derivativeOfVelocity, oldFields.DerivativeOfVelocity, olderFields.DerivativeOfVelocity);
            }
            else
            {
                height   = NumericalDerivatives.Euler(_options.Timestep, fields.Height, derivativeOfHeight);
                velocity = NumericalDerivatives.Euler(_options.Timestep, fields.Velocity, derivativeOfVelocity);
            }

            var newFields = new PrognosticFields
            {
                DerivativeOfHeight   = derivativeOfHeight,
                DerivativeOfVelocity = derivativeOfVelocity,
                Height   = height,
                Velocity = velocity
            };

            return(newFields);
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Step the simulation forward.
        /// </summary>
        public void StepSimulation()
        {
            var oldestFields = _olderFields;

            _olderFields  = _oldFields;
            _oldFields    = CurrentFields;
            CurrentFields = _fieldUpdater.Update(_oldFields, _olderFields, oldestFields);
        }
Ejemplo n.º 3
0
 /// <summary>
 /// Reset the simulation to the set of fields it was created with.
 /// </summary>
 public void Reset()
 {
     _olderFields  = null;
     _oldFields    = null;
     CurrentFields = _initialFields;
 }
Ejemplo n.º 4
0
 /// <summary>
 /// Creates a simulation on the given surface using the given initial fields & options.
 /// </summary>
 /// <param name="surface"></param>
 /// <param name="initialFields"></param>
 /// <param name="options"></param>
 public SimulationRunner(IPolyhedron surface, PrognosticFields initialFields, IModelParameters options)
 {
     _fieldUpdater  = new PrognosticFieldsUpdater(surface, options);
     _initialFields = initialFields;
     CurrentFields  = initialFields;
 }