Exemple #1
0
        /// <summary>
        /// Returns a list of 3d POINTS. Uses cubic spline to interpolate.
        /// </summary>
        /// <param name="NumberOfPoints"></param>
        /// <returns></returns>
        public List <Point3D> Get3DPoints(int NumberOfPoints)
        {
            List <Point3D>           interpolatedpoints = new List <Point3D>();
            CubicSplineInterpolation spline             = new CubicSplineInterpolation();
            List <double>            xcoors             = new List <double>();
            List <double>            zcoors             = new List <double>();

            for (int i = 0; i < _xsec.Points.Count(); i++)
            {
                xcoors.Add(_xsec.Points[i].X);
                zcoors.Add(_xsec.Points[i].Z);
            }

            spline.Initialize(xcoors, zcoors);
            double xOffset = _xsec.LowestPoint.X;

            double dx = (xcoors.Last() - xcoors.First()) / NumberOfPoints;

            for (int i = 0; i < NumberOfPoints; i++)
            {
                double x = xcoors.First() + i * dx;
                double z = spline.Interpolate(x);

                interpolatedpoints.Add(new Point3D(MidStreamLocation.X - UnityVector.Y * (x - xOffset), MidStreamLocation.Y + UnityVector.X * (x - xOffset), z));
            }
            return(interpolatedpoints);
        }
        /// <summary>
        /// Interpolation of the interface points onto the equidistant Fourier points
        /// </summary>
        protected void InterpolateOntoFourierPoints(MultidimensionalArray interP, double[] samplP)
        {
            int numP = interP.Lengths[0];

            // set interpolation data
            double[] independentVal = new double[numP + 2];
            double[] dependentVal   = new double[numP + 2];
            for (int sp = 1; sp <= numP; sp++)
            {
                independentVal[sp] = interP[sp - 1, 0];
                dependentVal[sp]   = interP[sp - 1, 1];
            }
            // extend the interpolation data for sample points at the boundary of the domain
            independentVal[0]        = interP[numP - 1, 0] - DomainSize;
            dependentVal[0]          = interP[numP - 1, 1];
            independentVal[numP + 1] = interP[0, 0] + DomainSize;
            dependentVal[numP + 1]   = interP[0, 1];

            switch (this.InterpolationType)
            {
            case Interpolationtype.LinearSplineInterpolation:

                LinearSplineInterpolation LinSpline = new LinearSplineInterpolation();
                LinSpline.Initialize(independentVal, dependentVal);

                for (int sp = 0; sp < numFp; sp++)
                {
                    samplP[sp] = LinSpline.Interpolate(FourierP[sp]);
                    //invDFT_coeff[sp] = (Complex)samplP[sp];
                }

                break;

            case Interpolationtype.CubicSplineInterpolation:

                CubicSplineInterpolation CubSpline = new CubicSplineInterpolation();
                CubSpline.Initialize(independentVal, dependentVal);

                for (int sp = 0; sp < numFp; sp++)
                {
                    samplP[sp] = CubSpline.Interpolate(FourierP[sp]);
                    //invDFT_coeff[sp] = (Complex)samplP[sp];
                }

                break;

            default:
                throw new NotImplementedException();
            }
        }
        public void TestClampedCubicSplineInterpolation()
        {
            Random r = new Random(Environment.TickCount);

            TearDown();
            var interpolation = new CubicSplineInterpolation();

            interpolation.Initialize(_times, _rates);
            for (int i = 0; i < 10; ++i)
            {
                double time       = (i + r.Next(-10000, 10000) / 10000);
                double interpRate = interpolation.ValueAt(time, true);
                Debug.WriteLine($"interpolatedRate : {interpRate} Time: {time}");
            }
        }
        /// <summary>
        /// Interpolation of no equidistant sample point onto equidistant Fourier points
        /// </summary>
        public static void InterpolateOntoFourierPoints(MultidimensionalArray samplP, double DomainSize, double[] samplFp)
        {
            int numSp = samplP.Lengths[0];

            // set interpolation data (delete multiple independent values)
            ArrayList independentList = new ArrayList();
            ArrayList dependentList   = new ArrayList();

            for (int sp = 0; sp < numSp; sp++)
            {
                if (independentList.Contains(samplP[sp, 0]) == false)
                {
                    independentList.Add(samplP[sp, 0]);
                    dependentList.Add(samplP[sp, 1]);
                }
            }
            // extend the interpolation data for sample points at the boundary of the domain
            independentList.Insert(0, samplP[numSp - 1, 0] - DomainSize);
            independentList.Insert(independentList.Count, samplP[0, 0] + DomainSize);
            dependentList.Insert(0, samplP[numSp - 1, 1]);
            dependentList.Insert(dependentList.Count, samplP[0, 1]);

            double[] independentVal = (double[])independentList.ToArray(typeof(double));
            double[] dependentVal   = (double[])dependentList.ToArray(typeof(double));

            // set Fourier points
            int numSFp = samplFp.Length;

            double[] FourierP = new double[numSFp];
            for (int i = 0; i < numSFp; i++)
            {
                FourierP[i] = (DomainSize / numSFp) * i;
            }


            switch (InterpolationType)
            {
            case Interpolationtype.LinearSplineInterpolation:

                LinearSplineInterpolation LinSpline = new LinearSplineInterpolation();
                LinSpline.Initialize(independentVal, dependentVal);

                for (int Fp = 0; Fp < numSFp; Fp++)
                {
                    samplFp[Fp] = LinSpline.Interpolate(FourierP[Fp]);
                }

                break;

            case Interpolationtype.CubicSplineInterpolation:

                CubicSplineInterpolation CubSpline = new CubicSplineInterpolation();
                CubSpline.Initialize(independentVal, dependentVal);

                for (int Fp = 0; Fp < numSFp; Fp++)
                {
                    samplFp[Fp] = CubSpline.Interpolate(FourierP[Fp]);
                }

                break;

            default:
                throw new NotImplementedException();
            }
        }