コード例 #1
0
        private void InitializeInternalVectors()
        {
            for (int i = 0; i <= BDForder; i++)
            {
                temperature.Add(new Dictionary <int, IVector>());
            }
            //temperature.Clear();
            rhs.Clear();
            stabilizingRhs.Clear();
            rhsPrevious.Clear();
            diffusionConductivityTimesTemperature.Clear();
            massTransportConductivityTimesTemperature.Clear();
            stabilizingConductivityTimesTemperature.Clear();
            capacityTimesTemperature.Clear();
            effectiveTemperature.Clear();

            foreach (ILinearSystem linearSystem in linearSystems.Values)
            {
                int id = linearSystem.Subdomain.ID;
                diffusionConductivityTimesTemperature.Add(id, linearSystem.CreateZeroVector());
                massTransportConductivityTimesTemperature.Add(id, linearSystem.CreateZeroVector());
                stabilizingConductivityTimesTemperature.Add(id, linearSystem.CreateZeroVector());
                capacityTimesTemperature.Add(id, linearSystem.CreateZeroVector());
                //temperature.Add(id, linearSystem.CreateZeroVector());
                rhs.Add(id, linearSystem.CreateZeroVector());
                stabilizingRhs.Add(id, linearSystem.CreateZeroVector());
                rhsPrevious.Add(id, linearSystem.CreateZeroVector());
                effectiveTemperature.Add(id, linearSystem.CreateZeroVector());

                // Account for initial conditions coming from a previous solution.
                //TODO: This doesn't work as intended. The solver (previously the LinearSystem) initializes the solution to zero.
                for (int i = 0; i <= BDForder; i++)
                {
                    if (linearSystem.Solution != null)
                    {
                        temperature[i].Add(id, linearSystem.Solution.Copy());
                    }
                    else
                    {
                        temperature[i].Add(id, initialTemperature.Copy());
                    }
                }
            }
        }
コード例 #2
0
        /// <summary>
        /// Plot vector nodes to the Eucledian plain.
        /// </summary>
        /// <param name="vector">A vector Node/Coordinate.</param>
        /// <exception cref="OctagonSquare.ProximityMatch.Exceptions.DimensionException">Thrown when invalid number of dimensions.</exception>
        /// <exception cref="OctagonSquare.ProximityMatch.Exceptions.CoordinateException">Thrown when coordinates are missing.</exception>
        /// <exception cref="OctagonSquare.ProximityMatch.Exceptions.UniqueIdException">Thrown when uniqueId is exists.</exception>
        public void Plot(IVector vector, out long uniqueid)
        {
            try
            {
                if (this.Dimension != vector.Coordinate.Length)
                {
                    throw new DimensionException("Invalid dimension!!.");
                }

                if (this.Dimension < 2)
                {
                    throw new DimensionException("Atleast two dimensions are required!!.");
                }

                if (!vector.Coordinate.All(x => x.HasValue))
                {
                    throw new CoordinateException("Missing coordinate.");
                }

                if (vector.UniqueId <= 0)
                {
                    vector.UniqueId = GenerateUniqueId();
                }

                //All good, try create a vector node/coordinate now.

                if (this.ItemDictionary.ContainsKey(vector.UniqueId))
                {
                    throw new UniqueIdException("UniqueId already exist!!.");
                }

                this.ItemDictionary.Add(vector.UniqueId, vector.Copy <IVector>());
                uniqueid = vector.UniqueId;

                var vectorNode = new VectorNode(
                    uniqueid: vector.UniqueId,
                    angles: GenerateAngles(vector),
                    distance: EuclideanDistance(vector.Coordinate, CreateDouble(vector.Coordinate.Length))
                    );

                //Indexing vectors based on cos(beta) angle and Euclidean distance from orgin.
                var angleKey             = Math.Truncate(vectorNode.Angles[0]);
                var distanceFromOrginKey = Math.Truncate(vectorNode.DistanceFromOrgin / 10);

                if (this.VectorDictionary.ContainsKey(angleKey))
                {
                    if (this.VectorDictionary[angleKey].ContainsKey(distanceFromOrginKey))
                    {
                        this.VectorDictionary[angleKey][distanceFromOrginKey].Add(vectorNode);
                    }
                    else
                    {
                        this.VectorDictionary[angleKey].Add(distanceFromOrginKey, new List <VectorNode> {
                            vectorNode
                        });
                    }
                }
                else
                {
                    var distanceFromOrginDictionary = new Dictionary <double, List <VectorNode> >();
                    distanceFromOrginDictionary.Add(distanceFromOrginKey, new List <VectorNode>()
                    {
                        vectorNode
                    });
                    this.VectorDictionary.Add(angleKey, distanceFromOrginDictionary);
                }

                //Build indexes.
                AddIndex(vector);

                mu += angleKey;
                n++;

                //Ploting done!! now fire the finished event.
                PlotingFinishedEvent(new PlotEventArgs(vectorNode));
            }
            catch (Exception exception)
            {
                throw exception;
            }
        }