コード例 #1
0
        /// <summary>
        /// Inherited member. Divides the simulation into threads, and begins.
        /// </summary>
        public override void Begin()
        {
            Random Rnd = new Random();

            //processorCT = UI.PachydermAc_PlugIn.Instance.ProcessorSpec();
            processorCT  = 4;
            Current_Ray  = new int[processorCT];
            Detections   = new List <int[]> [Receiver.Count, processorCT];
            SequenceList = new List <int[]> [Receiver.Count];

            T_List = new System.Threading.Thread[processorCT];

            for (int P_I = 0; P_I < processorCT; P_I++)
            {
                for (int i = 0; i < Receiver.Count; i++)
                {
                    Detections[i, P_I] = new List <int[]>();
                }

                Calc_Params T = new Calc_Params(P_I * Raycount / processorCT, (P_I + 1) * Raycount / processorCT, P_I, Rnd.Next());
                System.Threading.ParameterizedThreadStart TS = new System.Threading.ParameterizedThreadStart(delegate { Calculate(T); });
                T_List[P_I] = new System.Threading.Thread(TS);
                T_List[P_I].Start();
            }
        }
コード例 #2
0
        /// <summary>
        /// Inherited member. Divides the simulation into threads, and begins.
        /// </summary>
        public override void Begin()
        {
            Random Rnd = new Random();

            _processorCt = UI.PachydermAc_PlugIn.Instance.ProcessorSpec();
            _currentRay  = new int[_processorCt];
            _rayTotal    = new int[_processorCt];
            _lost        = new double[_processorCt];
            _eInit       = new double[_processorCt];
            _u           = new double[_processorCt];
            _v           = new double[_processorCt];
            _tlist       = new System.Threading.Thread[_processorCt];

            for (int P_I = 0; P_I < _processorCt; P_I++)
            {
                int start = (int)Math.Floor((double)P_I * Raycount / _processorCt);
                int end;
                if (P_I == _processorCt - 1)
                {
                    end = Raycount;
                }
                else
                {
                    end = (P_I + 1) * Raycount / _processorCt;
                }
                Calc_Params T = new Calc_Params(Room, start, end, P_I, Rnd.Next());
                System.Threading.ParameterizedThreadStart TS = new System.Threading.ParameterizedThreadStart(delegate { Calculate(T); });
                _tlist[P_I] = new System.Threading.Thread(TS);
                _tlist[P_I].Start();
            }

            System.Runtime.GCSettings.LatencyMode = System.Runtime.GCLatencyMode.Batch;
        }
コード例 #3
0
        /// <summary>
        /// Inherited member. Divides the simulation into threads, and begins.
        /// </summary>
        public override void Begin()
        {
            Random Rnd = new Random();
            processorCT = UI.PachydermAc_PlugIn.Instance.ProcessorSpec();
            Current_Ray = new int[processorCT];
            Detections = new List<int[]>[Receiver.Count, processorCT];
            SequenceList = new List<int[]>[Receiver.Count];

            T_List = new System.Threading.Thread[processorCT];

            for (int P_I = 0; P_I < processorCT; P_I++)
            {
                for (int i = 0; i < Receiver.Count; i++)
                {
                    Detections[i, P_I] = new List<int[]>();
                }
                 
                Calc_Params T = new Calc_Params(P_I * Raycount / processorCT, (P_I + 1) * Raycount / processorCT, P_I, Rnd.Next());
                System.Threading.ParameterizedThreadStart TS = new System.Threading.ParameterizedThreadStart(delegate { Calculate(T); });
                T_List[P_I] = new System.Threading.Thread(TS);
                T_List[P_I].Start();
            }
        }
コード例 #4
0
        /// <summary>
        /// Called by each thread from the begin method.
        /// </summary>
        /// <param name="i">the object is type "Calc_Params" which holds all the necessary information to run a portion of the simulation.</param>
        public void Calculate(object i)
        {
            Calc_Params Params = (Calc_Params)i;
            Random      RND    = new Random(Params.RandomSeed);

            ST = DateTime.Now;
            Hare.Geometry.Point Origin = Source.H_Origin();
            ///'''''''''''''Renewable Variables''''''''''''''''''
            double SumLength;
            double u = 0;
            double v = 0;

            Hare.Geometry.Point Point = new Hare.Geometry.Point();
            int ChosenIndex           = 0;
            List <Hare.Geometry.Point> Start;
            int        Reflections;
            List <int> Sequence = new List <int>();

            ///''''''''''''''''''''''''''''''''''''''''''''''''''

            for (Current_Ray[Params.ThreadID] = 0; Current_Ray[Params.ThreadID] < Params.EndIndex - Params.StartIndex; Current_Ray[Params.ThreadID]++)
            {
                BroadRay R = Source.Directions(Current_Ray[Params.ThreadID] + Params.StartIndex, Params.ThreadID, ref RND);
                SumLength   = 0;
                Reflections = 0;
                Sequence.Clear();
                List <int> code = new List <int> {
                    0
                };
                List <double> leg = new List <double> {
                    0
                };
                do
                {
                    ///Only useable with homogeneous media///
                    SumLength += leg[0];
                    R.Ray_ID   = RND.Next();
                    if (Room.shoot(R, out u, out v, out ChosenIndex, out Start, out leg, out code))
                    {
                        if (!Room.IsPlanar(ChosenIndex))
                        {
                            break;
                        }
                        Reflections++;
                        ReflectRay(ref R, ref u, ref v, ref ChosenIndex);
                        if (Reflections > ImageOrder + 1)
                        {
                            bool[] B = Receiver.SimpleCheck(R, Start[0], SumLength);
                            for (int q = 0; q < B.Length; q++)
                            {
                                if (B[q])
                                {
                                    Detections[q, Params.ThreadID].Add(Sequence.ToArray());
                                }
                            }
                        }
                    }
                    else
                    {
                        //Rhino.RhinoDoc.ActiveDoc.Objects.AddCurve(new LineCurve(Pachyderm_Acoustic.Utilities.PachTools.HPttoRPt(R.origin), Pachyderm_Acoustic.Utilities.PachTools.HPttoRPt(R.origin + R.direction) * 5));
                        break;
                    }
                    Sequence.Add(Room.PlaneID(ChosenIndex));
                    R.origin = Start[0];
                }while (SumLength < CutoffLength);
            }
        }
コード例 #5
0
        /// <summary>
        /// Called by each thread from the begin method.
        /// </summary>
        /// <param name="i">the object is type "Calc_Params" which holds all the necessary information to run a portion of the simulation.</param>
        public void Calculate(object i)
        {
            ///Homogeneous media only...
            Calc_Params Params = (Calc_Params)i;
            Random      Rnd    = new Random(Params.RandomSeed);

            _st = DateTime.Now;
            Point             Origin = Source.H_Origin();
            int               Dir_ID = Params.StartIndex;
            List <Point>      Start;
            List <double>     leg;
            List <int>        code;
            Queue <OctaveRay> Rays = new Queue <OctaveRay>();
            BroadRay          R;
            int               order;

            double Threshold_Power_1 = 0;

            double[] Threshold_Power_2 = new double[8];
            double[] Threshold_Power_3 = new double[8];
            for (_currentRay[Params.ThreadID] = 0; _currentRay[Params.ThreadID] < Params.EndIndex - Params.StartIndex; _currentRay[Params.ThreadID]++)
            {
                R = Source.Directions(_currentRay[Params.ThreadID] + Params.StartIndex, Params.ThreadID, ref Rnd, _octaves);
                for (int oct = 0; oct < 8; oct++)
                {
                    R.Energy[oct] /= Raycount;
                }
                for (int j = 0; j < 8; j++)
                {
                    _eInit[Params.ThreadID] += R.Energy[j];
                }
                Threshold_Power_1 = R.Energy[h_oct] * 1E-2;
                foreach (int o in _octaves)
                {
                    Threshold_Power_2[o] = R.Energy[o] * 1E-4;  //Cease splitting at 0.0001 sound intensity, or 40 dB down.
                    Threshold_Power_3[o] = R.Energy[o] * 1E-10; //Finish 16 digits (double Precision) under 60 dB of decay.
                }
                order = 0;
                double u = 0, v = 0;
                do
                {
                    R.Ray_ID = Rnd.Next();
                    if (!Params.Room.shoot(R, out u, out v, out R.Surf_ID, out Start, out leg, out code))
                    {
                        //Ray is lost... move on...
                        for (int j = 0; j < 8; j++)
                        {
                            _lost[Params.ThreadID] += R.Energy[j];
                        }
                        goto Do_Scattered;
                    }

                    if (order > IS_Order)
                    {
                        //Specular ray order exceeds order of image source calculation. Start logging specular part.
                        RecMain.CheckBroadbandRay(R, Start[0]);
                    }
                    R.Energy[0] *= Math.Pow(10, -.1 * Room.Attenuation(code[0])[0] * leg[0]);
                    R.Energy[1] *= Math.Pow(10, -.1 * Room.Attenuation(code[0])[1] * leg[0]);
                    R.Energy[2] *= Math.Pow(10, -.1 * Room.Attenuation(code[0])[2] * leg[0]);
                    R.Energy[3] *= Math.Pow(10, -.1 * Room.Attenuation(code[0])[3] * leg[0]);
                    R.Energy[4] *= Math.Pow(10, -.1 * Room.Attenuation(code[0])[4] * leg[0]);
                    R.Energy[5] *= Math.Pow(10, -.1 * Room.Attenuation(code[0])[5] * leg[0]);
                    R.Energy[6] *= Math.Pow(10, -.1 * Room.Attenuation(code[0])[6] * leg[0]);
                    R.Energy[7] *= Math.Pow(10, -.1 * Room.Attenuation(code[0])[7] * leg[0]);
                    R.AddLeg(leg[0] / Room.Sound_speed(code[0]));
                    R.origin = Start[0];

                    order++;

                    ///////////////////////////////////////////////////////////////
                    //The Split Case : Specular and Diffuse Explicit
                    ///Standard Energy Conservation Routine-
                    // 1. Multiply by Reflection energy. (1 - Absorption)
                    double cos_theta;
                    Room.Absorb(ref R, out cos_theta, u, v);
                    // 2. Apply Transmission (if any).
                    //// a. Create new source for transmitted energy (E * Transmission).
                    //// b. Modify E (E * 1 - Transmission).
                    foreach (int oct in _octaves)
                    {
                        if (Params.Room.TransmissionValue[R.Surf_ID][oct] > 0.0)
                        {
                            Rays.Enqueue(R.SplitRay(oct, Params.Room.TransmissionValue[R.Surf_ID][oct]));
                        }
                    }
                    //3. Apply Scattering
                    Room.Scatter_Early(ref R, ref Rays, ref Rnd, cos_theta, u, v);
                    ///////////////////////////////////////////////////////////////

                    //Utilities.PachTools.Ray_Acoustics.SpecularReflection(ref R.direction, ref Room, ref _u[Params.ThreadID], ref _v[Params.ThreadID], ref R.Surf_ID);
                } while (R.Energy[h_oct] > Threshold_Power_1);

                foreach (int o in _octaves)
                {
                    Rays.Enqueue(R.SplitRay(o));                        //Split all rays into individual octaves.
                }
Do_Scattered:

                if (Rays.Count > 0)
                {
                    do
                    {
                        OctaveRay OR = Rays.Dequeue();
                        _rayTotal[Params.ThreadID]++;
                        do
                        {
                            OR.Ray_ID = Rnd.Next();
                            if (!Params.Room.shoot(OR, out u, out v, out OR.Surf_ID, out Start, out leg, out code))
                            {
                                _lost[Params.ThreadID] += OR.Intensity;
                                goto Do_Scattered;
                            }
                            RecMain.CheckRay(OR, Start[0]);

                            OR.Intensity *= Math.Pow(10, -.1 * Room.Attenuation(code[0])[OR.Octave] * leg[0]);
                            OR.AddLeg(leg[0] / Room.Sound_speed(code[0]));
                            OR.origin = Start[0];

                            ///Standard Energy Conservation Routine-
                            // 1. Multiply by Reflection energy. (1 - Absorption)
                            double cos_theta;
                            Room.Absorb(ref OR, out cos_theta, u, v);

                            // 2. Apply Transmission (if any).
                            if (Params.Room.TransmissionValue[OR.Surf_ID][OR.Octave] > 0.0)
                            {
                                //_rayTotal[Params.ThreadID]++;
                                //// a. Create new source for transmitted energy (E * Transmission).
                                //// b. Modify E (E * 1 - Transmission).
                                if (Rnd.NextDouble() < Params.Room.TransmissionValue[OR.Surf_ID][OR.Octave])
                                {
                                    OR.direction *= -1;
                                    Utilities.PachTools.Ray_Acoustics.SpecularReflection(ref OR.direction, ref Room, ref _u[OR.ThreadID], ref _v[OR.ThreadID], ref OR.Surf_ID);
                                }
                            }

                            // 3. Apply Scattering.
                            Room.Scatter_Late(ref OR, ref Rays, ref Rnd, cos_theta, u, v);
                        }while (OR.t_sum < COTime && OR.Intensity > Threshold_Power_2[OR.Octave]);

                        do
                        {
                            OR.Ray_ID = Rnd.Next();
                            if (!Params.Room.shoot(OR, out u, out v, out OR.Surf_ID, out Start, out leg, out code))
                            {
                                _lost[OR.ThreadID] += OR.Intensity;
                                goto Do_Scattered;
                            }

                            RecMain.CheckRay(OR, Start[0]);
                            //OctChecks.Enqueue(new object[] { OR.Clone(), new Hare.Geometry.Point(Start[0].x, Start[0].y, Start[0].z) });
                            OR.Intensity *= Math.Pow(10, -.1 * Room.Attenuation(code[0])[OR.Octave] * leg[0]);
                            OR.AddLeg(leg[0] / Room.Sound_speed(code[0]));
                            OR.origin = Start[0];

                            ///Standard Energy Conservation Routine-
                            // 1. Multiply by Reflection energy. (1 - Absorption)
                            double cos_theta;
                            Room.Absorb(ref OR, out cos_theta, u, v);

                            // 2. Apply Transmission (if any).
                            if (Params.Room.TransmissionValue[OR.Surf_ID][OR.Octave] > 0.0)
                            {
                                //// a. Create new source for transmitted energy (E * Transmission).
                                //// b. Modify E (E * 1 - Transmission).
                                if (Rnd.NextDouble() < Params.Room.TransmissionValue[OR.Surf_ID][OR.Octave])
                                {
                                    OR.direction *= -1;
                                    Utilities.PachTools.Ray_Acoustics.SpecularReflection(ref OR.direction, ref Params.Room, ref _u[OR.ThreadID], ref _v[OR.ThreadID], ref OR.Surf_ID);
                                }
                            }

                            // 3. Apply Scattering.
                            Room.Scatter_Simple(ref OR, ref Rnd, cos_theta, u, v);
                        }while (OR.t_sum < COTime && OR.Intensity > Threshold_Power_3[OR.Octave]);
                    }while (Rays.Count > 0);
                }
            }
            _ts = DateTime.Now - _st;
        }
コード例 #6
0
        /// <summary>
        /// Inherited member. Divides the simulation into threads, and begins.
        /// </summary>
        public override void Begin()
        {
            Random Rnd = new Random();
            _processorCt = UI.PachydermAc_PlugIn.Instance.ProcessorSpec();
            _currentRay = new int[_processorCt];
            _rayTotal = new int[_processorCt];
            _lost = new double[_processorCt];
            _eInit = new double[_processorCt];
            _u = new double[_processorCt];
            _v = new double[_processorCt];
            _tlist = new System.Threading.Thread[_processorCt];
            
            for (int P_I = 0; P_I < _processorCt; P_I++)
            {
                int start = (int)Math.Floor((double)P_I * Raycount / _processorCt);
                int end;
                if (P_I == _processorCt - 1) end = Raycount;
                else end = (P_I + 1) * Raycount / _processorCt;
                Calc_Params T = new Calc_Params(Room, start, end, P_I, Rnd.Next());
                System.Threading.ParameterizedThreadStart TS = new System.Threading.ParameterizedThreadStart(delegate { Calculate(T); });
                _tlist[P_I] = new System.Threading.Thread(TS);
                _tlist[P_I].Start();
            }

            System.Runtime.GCSettings.LatencyMode = System.Runtime.GCLatencyMode.Batch;
        }
コード例 #7
0
        /// <summary>
        /// Used by specular raytracer.
        /// </summary>
        /// <param name="Sequences">List of surface index sequences to try.</param>
        public void Lookup_Sequences(List<int[]>[] Sequences)
        {
            processorCT = UI.PachydermAc_PlugIn.Instance.ProcessorSpec();
            ThreadPaths = new List<Deterministic_Reflection>[Rec.Length,processorCT];
            int SrfCT = Room.PlaneCount;
            CurrentSrf = new int[processorCT];
            Random R = new Random();
            T_List = new System.Threading.Thread[processorCT];
            for (int p = 0; p < Rec.Length; p++)
            {
                for (int P_I = 0; P_I < processorCT; P_I++)
                {
                    ThreadPaths[p, P_I] = new List<Deterministic_Reflection>();
                    Calc_Params T = new Calc_Params(P_I * Sequences[p].Count / processorCT, (P_I + 1) * Sequences[p].Count / processorCT, P_I, R.Next());
                    System.Threading.ParameterizedThreadStart TS = new System.Threading.ParameterizedThreadStart(delegate
                    {
                        for (int i = T.StartIndex; i < T.EndIndex; i++)
                        {
                            ProcessPath(Sequences[p][i], T.ThreadID, p);
                        }
                    });
                    T_List[P_I] = new System.Threading.Thread(TS);
                    T_List[P_I].Start();
                }
                do
                {
                    System.Threading.Thread.Sleep(1000);
                    if (ThreadState() != System.Threading.ThreadState.Running) break;
                } while (true);

                for (int t = 0; t < processorCT; t++)
                {
                    ValidPaths[p].AddRange(ThreadPaths[p, t]);
                }
            }
        }
コード例 #8
0
        /// <summary>
        /// Inherited member. Divides the simulation into threads, and begins.
        /// </summary>
        public override void Begin()
        {
            processorCT = UI.PachydermAc_PlugIn.Instance.ProcessorSpec();
            ThreadPaths = new List<Deterministic_Reflection>[Rec.Length, processorCT];
            int SrfCT = Room.PlaneCount;
            CurrentSrf = new int[processorCT];
            CurrentEdge = new int[processorCT];
            Rnd = new Random[processorCT];
            T_List = new System.Threading.Thread[processorCT];
            elementCt = Room.PlaneCount + ((this.Diffraction) ? Room.EdgeCount : 0);

            for (int P_I = 0; P_I < processorCT; P_I++)
            {
                for (int i = 0; i < Rec.Length; i++)
                {
                    ThreadPaths[i,P_I] = new List<Deterministic_Reflection>();
                    ValidPaths[i] = new List<Deterministic_Reflection>();
                }
                int start = (int)Math.Floor((double)P_I * SrfCT / processorCT);
                int end;
                if (P_I == processorCT - 1) end = SrfCT;
                else end = (P_I + 1) * SrfCT / processorCT;
                
                Calc_Params T = new Calc_Params(start, end, P_I, Room.R_Seed.Next());
                System.Threading.ParameterizedThreadStart TS = new System.Threading.ParameterizedThreadStart(delegate { Calculate(T); });
                T_List[P_I] = new System.Threading.Thread(TS);
                T_List[P_I].Start();
            }
        }