Ejemplo n.º 1
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="dt"></param>
        /// <param name="velocity"></param>
        /// <returns></returns>
        public override double[] ComputeChangerate(double dt, ConventionalDGField[] velocity, double[] current_FLSprop)
        {
            GridData        grdat = (GridData)velocity[0].GridDat;
            FieldEvaluation fEval = new FieldEvaluation(grdat);

            MultidimensionalArray VelocityAtSamplePoints = MultidimensionalArray.Create(current_interfaceP.Lengths);

            int outP = fEval.Evaluate(1, velocity, current_interfaceP, 0, VelocityAtSamplePoints);

            if (outP != 0)
            {
                throw new Exception("points outside the grid for fieldevaluation");
            }

            // change rate for the material points is the velocity at the points
            if (FourierEvolve == Fourier_Evolution.MaterialPoints)
            {
                double[] velAtP = new double[2 * numFp];
                for (int sp = 0; sp < numFp; sp++)
                {
                    velAtP[sp * 2]     = VelocityAtSamplePoints[sp, 0];
                    velAtP[sp * 2 + 1] = VelocityAtSamplePoints[sp, 1];
                }
                return(velAtP);
            }

            // compute an infinitesimal change of sample points at the Fourier points/ change of Fourier modes
            MultidimensionalArray interfaceP_evo = current_interfaceP.CloneAs();
            double dt_infin = dt * 1e-3;

            interfaceP_evo.Acc(dt_infin, VelocityAtSamplePoints);

            RearrangeOntoPeriodicDomain(interfaceP_evo);
            double[] samplP_change = current_samplP.CloneAs();
            InterpolateOntoFourierPoints(interfaceP_evo, samplP_change);

            if (FourierEvolve == Fourier_Evolution.FourierPoints)
            {
                samplP_change.AccV(-1.0, current_samplP);
                samplP_change.ScaleV(1.0 / dt_infin);
                return(samplP_change);
            }
            else
            if (FourierEvolve == Fourier_Evolution.FourierModes)
            {
                Complex[] samplP_complex = new Complex[numFp];
                for (int sp = 0; sp < numFp; sp++)
                {
                    samplP_complex[sp] = (Complex)samplP_change[sp];
                }
                Complex[] DFT_change        = DFT.NaiveForward(samplP_complex, FourierOptions.Matlab);
                double[]  DFT_change_double = new double[2 * numFp];
                for (int sp = 0; sp < numFp; sp++)
                {
                    DFT_change_double[sp * 2]     = (DFT_change[sp].Real - DFT_coeff[sp].Real) / dt_infin;
                    DFT_change_double[sp * 2 + 1] = (DFT_change[sp].Imaginary - DFT_coeff[sp].Imaginary) / dt_infin;
                }
                return(DFT_change_double);
            }
            else
            {
                throw new ArgumentException();
            }
        }
Ejemplo n.º 2
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="velocity"></param>
        /// <returns></returns>
        public override double[] ComputeChangerate(double dt, ConventionalDGField[] velocity, double[] current_FLSprop)
        {
            setMaterialInterfacePoints(current_FLSprop);

            GridData        grdat = (GridData)(velocity[0].GridDat);
            FieldEvaluation fEval = new FieldEvaluation(grdat);

            // Movement of the material interface points
            MultidimensionalArray VelocityAtSamplePointsXY = MultidimensionalArray.Create(current_interfaceP.Lengths);

            int outP = fEval.Evaluate(1, velocity, current_interfaceP, 0, VelocityAtSamplePointsXY);

            if (outP != 0)
            {
                throw new Exception("points outside the grid for fieldevaluation");
            }

            int numIp = current_interfaceP.Lengths[0];


            // change rate for the material points is the velocity at the points
            if (FourierEvolve == Fourier_Evolution.MaterialPoints)
            {
                double[] velAtP = new double[2 * numIp];
                for (int sp = 0; sp < numIp; sp++)
                {
                    velAtP[sp * 2]       = VelocityAtSamplePointsXY[sp, 0];
                    velAtP[(sp * 2) + 1] = VelocityAtSamplePointsXY[sp, 1];
                }
                return(velAtP);
            }

            // compute an infinitesimal change of sample points at the Fourier points/ change of Fourier modes
            MultidimensionalArray interfaceP_evo = current_interfaceP.CloneAs();
            double dt_infin = dt * 1e-3;

            interfaceP_evo.Acc(dt_infin, VelocityAtSamplePointsXY);

            // Movement of the center point
            MultidimensionalArray center_evo       = center.CloneAs();
            MultidimensionalArray VelocityAtCenter = center.CloneAs();

            switch (CenterMove)
            {
            case CenterMovement.None: {
                VelocityAtCenter.Clear();
                break;
            }

            case CenterMovement.Reconstructed: {
                center_evo = GetGeometricCenter(interfaceP_evo);
                //Console.WriteLine("center_evo = ({0}, {1}) / center = ({2}, {3})", center_evo[0, 0], center_evo[0, 1], center[0, 0], center[0, 1]);
                MultidimensionalArray center_change = center_evo.CloneAs();
                center_change.Acc(-1.0, center);
                center_change.Scale(1.0 / dt_infin);
                VelocityAtCenter[0, 0] = center_change[0, 0];
                VelocityAtCenter[0, 1] = center_change[0, 1];
                break;
            }

            case CenterMovement.VelocityAtCenter: {
                outP = fEval.Evaluate(1, velocity, center, 0, VelocityAtCenter);
                if (outP != 0)
                {
                    throw new Exception("center point outside the grid for fieldevaluation");
                }
                center_evo.Acc(dt_infin, VelocityAtCenter);
                break;
            }
            }
            //Console.WriteLine("Velocity at Center point = ({0}, {1})", VelocityAtCenter[0, 0], VelocityAtCenter[0, 1]);

            // transform to polar coordiantes
            MultidimensionalArray interP_evo_polar = interfaceP_polar.CloneAs();

            for (int sp = 0; sp < numIp; sp++)
            {
                double x_c = interfaceP_evo[sp, 0] - center_evo[0, 0];
                double y_c = interfaceP_evo[sp, 1] - center_evo[0, 1];

                double theta = Math.Atan2(y_c, x_c);
                if (theta < 0)
                {
                    theta = Math.PI * 2 + theta;
                }
                ;
                interP_evo_polar[sp, 0] = theta;
                interP_evo_polar[sp, 1] = Math.Sqrt(x_c.Pow2() + y_c.Pow2());
            }

            RearrangeOntoPeriodicDomain(interP_evo_polar);
            double[] samplP_change = current_samplP.CloneAs();
            InterpolateOntoFourierPoints(interP_evo_polar, samplP_change);

            if (FourierEvolve == Fourier_Evolution.FourierPoints)
            {
                samplP_change.AccV(-1.0, current_samplP);
                samplP_change.ScaleV(1.0 / dt_infin);
                double[] FPchange = new double[numFp + 2];
                FPchange[0] = VelocityAtCenter[0, 0];
                FPchange[1] = VelocityAtCenter[0, 1];
                for (int p = 0; p < numFp; p++)
                {
                    FPchange[p + 2] = samplP_change[p];
                }
                return(FPchange);
            }
            else
            if (FourierEvolve == Fourier_Evolution.FourierModes)
            {
                Complex[] samplP_complex = new Complex[numFp];
                for (int sp = 0; sp < numFp; sp++)
                {
                    samplP_complex[sp] = (Complex)samplP_change[sp];
                }
                Complex[] DFTchange        = DFT.NaiveForward(samplP_complex, FourierOptions.Matlab);
                double[]  DFTchange_double = new double[2 * numFp + 2];
                DFTchange_double[0] = VelocityAtCenter[0, 0];
                DFTchange_double[1] = VelocityAtCenter[0, 1];
                for (int sp = 0; sp < numFp; sp++)
                {
                    DFTchange_double[2 + (sp * 2)]     = (DFTchange[sp].Real - DFT_coeff[sp].Real) / dt_infin;
                    DFTchange_double[2 + (sp * 2) + 1] = (DFTchange[sp].Imaginary - DFT_coeff[sp].Imaginary) / dt_infin;
                }
                return(DFTchange_double);
            }
            else
            {
                throw new ArgumentException();
            }
        }