示例#1
0
        protected override double RunSolverOneStep(int TimestepNo, double phystime, double dt)
        {
            base.EndTime       = 0.0;
            base.NoOfTimesteps = 0;

            // Flux Derivatives
            // =================

            {
                // compute
                df1_dx_Numerical.Clear();
                df1_dx_Numerical.DerivativeByFlux(1.0, f1, 0);
                df1_dy_Numerical.DerivativeByFlux(1.0, f1, 1);


                Console.WriteLine("Local Derivatives: ");

                // print diagnostic:
                df1_dx_Analytical.Acc(-1.0, df1_dx_Numerical);
                df1_dy_Analytical.Acc(-1.0, df1_dy_Numerical);

                double err_dx = df1_dx_Analytical.L2Norm();
                Console.WriteLine("|| df/dx_Numerical - df/dx_Analytical ||_2 = " + err_dx);
                passed = passed && (err_dx < 1.0e-10);

                double err_dy = df1_dy_Analytical.L2Norm();
                Console.WriteLine("|| df/dy_Numerical - df/dy_Analytical ||_2 = " + err_dy);
                passed = passed && (err_dy < 1.0e-10);

                Console.WriteLine("--------------------------------------------");
            }



            //PlotCurrentState(0, 0);


            //OrthonormalityTest();

            //PlotCell0();

            return(0.0); // return some artificial timestep
        }
示例#2
0
文件: Program.cs 项目: xyuan/BoSSS
        /// <summary>
        /// performs some timesteps
        /// </summary>
        protected override double RunSolverOneStep(int TimestepNo, double phystime, double dt)
        {
            using (new FuncTrace()) {
                /*
                 * u.ProjectField((x, y, z) => (x*x*3));
                 *
                 * //dx_u.Derivative(1.0, u, 0);
                 * //dy_u.Derivative(1.0, u, 1);
                 *
                 * dx_u_byflux.DerivativeByFlux(1.0, u, 0);
                 * //dy_u_byflux.DerivativeByFlux(1.0, u, 1);
                 *
                 * double min, max;
                 * dx_u_byflux.GetExtremalValues(out min, out max);
                 * Console.WriteLine(min + " < dx_u_byflux < " + max);
                 *
                 * base.TerminationKey = true;
                 *
                 * base.NoOfTimesteps = -1;
                 * return dt;
                 *
                 */

                ScalarFunction sf = ((_2D)((x, y) => 1 - x * x - y * y)).Vectorize();


                u.ProjectField(sf);
                var err = u.L2Error(sf, 4);



                double min_x, max_x, min_y, max_y, min_u, max_u;
                dx_u_byflux.GetExtremalValues(out min_x, out max_x);
                dy_u_byflux.GetExtremalValues(out min_y, out max_y);
                u.GetExtremalValues(out min_u, out max_u);

                Console.WriteLine(min_u + " < u < " + max_u);
                Console.WriteLine(min_x + " < dx_u_byflux < " + max_x);
                Console.WriteLine(min_y + " < dy_u_byflux < " + max_y);

                //double Apl, Ami;
                //EvaluateLevelSetVolume(u, out Apl, out Ami);

                if (dt <= 0)
                {
                    // if dt <= 0, we're free to set the timestep on our own
                    //base.NoOfTimesteps = -1;
                    //dt = 1;

                    base.NoOfTimesteps = 1;
                    base.EndTime       = Math.PI / 200.0;
                    dt = base.EndTime / ((double)base.NoOfTimesteps);


                    base.NoOfTimesteps *= 1; // run till' infinity
                    base.EndTime        = 1.0e20;
                }

                if (base.GridDat.MyRank == 0)
                {
                    Console.Write("Timestp. #" + TimestepNo + " of " + base.NoOfTimesteps + " ... \t");
                }
                //eEule.Perform(dt);

                //if ((TimestepNo) % 1 == 0)
                //    PlotCurrentState(phystime, (int)TimestepNo);
                if (base.GridDat.MyRank == 0)
                {
                    Console.WriteLine("finished!");
                }


                // print diagnostic:
                if (TimestepNo == 1)
                {
                    du_dx_Analytical.Acc(-1.0, dx_u_byflux);
                    du_dy_Analytical.Acc(-1.0, dy_u_byflux);

                    double err_dx = du_dx_Analytical.L2Norm();
                    Console.WriteLine("|| df/dx_Numerical - df/dx_Analytical ||_2 = " + err_dx);
                    double err_dy = du_dy_Analytical.L2Norm();
                    Console.WriteLine("|| df/dy_Numerical - df/dy_Analytical ||_2 = " + err_dy);
                    Console.WriteLine("--------------------------------------------");
                }
                return(dt);
            }
        }