Click here to Skip to main content
15,895,192 members
Articles / Programming Languages / C#

Integration: Mechanics + Hydraulics + Navigation

Rate me:
Please Sign up or sign in to vote.
5.00/5 (46 votes)
3 Feb 2011CPOL21 min read 61.8K   6.1K   88  
Sample of integration of branches of engineering.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

using CategoryTheory;

using BaseTypes;

using DiagramUI;
using DiagramUI.Interfaces;
using DiagramUI.Helpers;

using DataPerformer.Interfaces;


namespace DataPerformer.Helpers
{
    /// <summary>
    /// Transformer of differential equatuins
    /// </summary>
    public class StateTransformer : AbstractDoubleTransformer, IMeasure, ITimeMeasureProvider
    {
        #region Fields

 
        IDifferentialEquationProcessor processor;


        ITimeMeasureProvider provider;


    
   
        double time;


        double step;

        #endregion

        #region Ctor

        protected StateTransformer(IObjectCollection collection, IDifferentialEquationProcessor processor, 
            ITimeMeasureProvider provider) : base(collection)
        {
            this.processor = processor;
            this.provider = provider;
        }

        public StateTransformer(IObjectCollection collection,
            IDifferentialEquationProcessor processor)
            : this(collection, processor, null)
        {
            provider = this;
            processor.TimeProvider = provider;
        }
        
        public StateTransformer(IObjectCollection collection)
            : this(collection, new InternalRungeProcessor())
        {
        }



        #endregion


        #region IMeasure Members

        Func<object> IMeasure.Parameter
        {
            get { return GetTime; }
        }

        string IMeasure.Name
        {
            get { return "Time"; }
        }

        object IMeasure.Type
        {
            get { return a; }
        }

        #endregion

        #region ITimeMeasureProvider Members

        IMeasure ITimeMeasureProvider.TimeMeasure
        {
            get { return this; }
        }

        double ITimeMeasureProvider.Time
        {
            get
            {
                return time;
            }
            set
            {
                time = value;
            }
        }

        double ITimeMeasureProvider.Step
        {
            get
            {
                return step;
            }
            set
            {
                step = value;
            }
        }

        #endregion


        #region Members

        protected override void Prepare()
        {
            if (processor == null)
            {
                processor = new InternalRungeProcessor();
            }
            base.Prepare();
            processor.Set(collection);
        }

        /// <summary>
        /// Calculation
        /// </summary>
        /// <param name="input">Input</param>
        /// <param name="output">Output</param>
        public override void Calculate(object[] input, object[] output)
        {
           ITimeMeasureProvider old = processor.TimeProvider;
            try
            {
                using (new TimeProviderBackup(collection, provider, DifferentialEquationProcessor.Processor))
                {
                    using (new ComponentCollectionBackup(collection))
                    {
                        processor.TimeProvider = provider;

                        // Input
                        double[] inp = input[0] as double[];

                        // Sets state vector
                        collection.SetStateVector(inp);
                        double start = provider.Time;
                        double step = provider.Step;
                        runtime.StartAll(start);
                        runtime.UpdateAll();

                        // Solution of differential equations
                        processor.Step(start, start + step);
                        provider.Time = start + step;
                        collection.GetStateVector(outbuffer);

                        // Sets final vector
                        output[0] = outbuffer;
                    }
                }
            }
            catch (Exception ex)
            {
                ex.Log();
            }
            processor.TimeProvider = old;
        }


        #endregion

        object GetTime()
        {
            return time;
        }

        #region Internal Runge Processor

        class InternalRungeProcessor : RungeProcessor
        {
            #region Fields

 
            #endregion

            internal InternalRungeProcessor()
            {
            }

        }

        #endregion


     }
}

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
Architect
Russian Federation Russian Federation
Ph. D. Petr Ivankov worked as scientific researcher at Russian Mission Control Centre since 1978 up to 2000. Now he is engaged by Aviation training simulators http://dinamika-avia.com/ . His additional interests are:

1) Noncommutative geometry

http://front.math.ucdavis.edu/author/P.Ivankov

2) Literary work (Russian only)

http://zhurnal.lib.ru/editors/3/3d_m/

3) Scientific articles
http://arxiv.org/find/all/1/au:+Ivankov_Petr/0/1/0/all/0/1

Comments and Discussions