Click here to Skip to main content
15,888,113 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.6K   6.1K   88  
Sample of integration of branches of engineering.
using System;
using System.Collections.Generic;
using System.Text;
using System.Runtime.Serialization;

using CategoryTheory;
using DiagramUI;
using BaseTypes;


using DataPerformer.Interfaces;
using DataPerformer;

namespace AggregateLibrary
{
    [Serializable()]
    class ForcedRigidBody : RigidBody, IDataConsumer, IPostSetArrow
    {
        #region Fields

        private string forceVector = "";

        private string momentumVector = "";


        private IMeasure force;

        private IMeasure momentum;

        private List<IMeasurements> measurements = new List<IMeasurements>();

        Action update = delegate()
        {
        };

        #endregion

        #region Ctor

        internal ForcedRigidBody()
            : base(false)
        {
        }

        protected ForcedRigidBody(SerializationInfo info, StreamingContext context)
            : base(info, context)
        {
        }


        #endregion

        #region Overriden

        public override object Properties
        {
            get
            {
                object[] o = new object[] { momemtOfInertia, connections, aliasNames, inerialAccelerationStr, forcesStr, mass, initialState,
                forceVector, momentumVector};
                return LibraryObjectWrapper.TransformToBytes(o);
            }
            set
            {
                base.Properties = value;
            }
        }

        public override object Editor
        {
            get
            {
                return new object[] { Form, ResourceImage.RigidBodyVector };
            }
        }

        protected override void SetProperties(object[] o)
        {
            base.SetProperties(o);
            forceVector = o[7] + "";
            momentumVector = o[8] + "";
        }

        #endregion

        #region IDataConsumer Members

        void IDataConsumer.Add(IMeasurements measurements)
        {
            this.measurements.Add(measurements);
        }

        void IDataConsumer.Remove(IMeasurements measurements)
        {
            this.measurements.Remove(measurements);
        }

        void IDataConsumer.UpdateChildrenData()
        {
            StaticDataPerformer.UpdateChildrenData(measurements);
        }

        int IDataConsumer.Count
        {
            get { return measurements.Count; }
        }

        IMeasurements IDataConsumer.this[int number]
        {
            get { return measurements[number]; }
        }

        void IDataConsumer.Reset()
        {
            this.FullReset();
        }

        #endregion

        #region IPostSetArrow Members

        void IPostSetArrow.PostSetArrow()
        {
            Set();
        }

        #endregion

        #region Members

 
        internal List<string> ExternalMeasurements
        {
            get
            {
               List<string> l = new List<string>();
               Dictionary<string,object> d =  this.GetAllMeasuresType();
               foreach (string measure in d.Keys)
               {
                   object o = d[measure];
                   if (!(o is ArrayReturnType))
                   {
                       continue;
                   }
                   ArrayReturnType art = o as ArrayReturnType;
                   int[] dim = art.Dimension;
                   if (dim.Length != 1)
                   {
                       continue;
                   }
                   if (dim[0] == 3)
                   {
                       l.Add(measure);
                   }
               }
               return l;
            }
        }

        internal void Set(string force, string momentum)
        {
            forceVector = force;
            momentumVector = momentum;
            Set();
        }

        internal string[] Vectors
        {
            get
            {
                return new string[] { forceVector, momentumVector };
            }
        }

        private void Set()
        {
            if (forceVector.Length > 0)
            {
                IMeasure m = this.FindMeasure(forceVector, false);
                bool b = IsObject(m);
                if (b)
                {
                    AddForce = delegate()
                    {
                        AddObject(internalAcceleration, m, 0);
                    };
                }
                else
                {
                    AddForce = delegate()
                    {
                        AddDouble(internalAcceleration, m, 0);
                    };
                }
            }
            else
            {
                AddForce = delegate()
                {
                };
            }
            if (momentumVector.Length > 0)
            {
                IMeasure m = this.FindMeasure(momentumVector, false);
                bool b = IsObject(m);
                if (b)
                {
                    AddMomentum = delegate()
                    {
                        AddObject(v3d, m, 0);
                    };
                }
                else
                {
                    AddMomentum = delegate()
                    {
                        AddDouble(v3d, m, 0);
                    };
                }
            }
            else
            {
                AddMomentum = delegate()
                {
                };
            }
        }

        void AddDouble(double[] x, object o, int offset)
        {
            double[] d = o as double[];
            for (int i = 0; i < d.Length; i++)
            {
                x[i + offset] += d[i];
            }
        }

        void AddObject(double[] x, object o, int offset)
        {
            object[] ob = o as object[];
            for (int i = 0; i < 3; i++)
            {
                x[i + offset] += (double)ob[i];
            }
        }

        void AddDouble(double[] x, IMeasure m, int offset)
        {
            AddDouble(x, m.Parameter(), offset);
        }

        void AddObject(double[] x, IMeasure m, int offset)
        {
            AddObject(x, m.Parameter(), offset);
        }

        bool IsObject(IMeasure m)
        {
            ArrayReturnType art = m.Type as ArrayReturnType;
            return art.IsObjectType;
        }

        #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