Exemplo n.º 1
0
        /// <summary>
        /// Create a linear spline interpolation based on arbitrary points (sorted ascending).
        /// </summary>
        /// <param name="points">The sample points t, sorted ascending. Supports both lists and arrays.</param>
        /// <param name="values">The sample point values x(t). Supports both lists and arrays.</param>
        /// <returns>
        /// An interpolation scheme optimized for the given sample points and values,
        /// which can then be used to compute interpolations and extrapolations
        /// on arbitrary points.
        /// </returns>
        public static IInterpolation LinearBetweenPoints(IList <double> points, IList <double> values)
        {
            var method = new LinearSplineInterpolation();

            method.Initialize(points, values);
            return(method);
        }
Exemplo n.º 2
0
        /// <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();
            }
        }
Exemplo n.º 3
0
        /// <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();
            }
        }