Example #1
0
        static void Main(string[] args)
        {
            if (args.Length < 1)
            {
                Console.WriteLine("Missing first argument");
                Console.WriteLine("Please specify a model file");
                return;
            }

            Log.SetDebugLogFile("debug.txt");
            try
            {
                using (Plot3d plotter = new Plot3d())
                {
                    Thread calcThread = new Thread(() => calc(plotter, args[0]));
                    calcThread.Start();
                    plotter.Run(30.0);
                    calcThread.Abort();
                }
            }
            catch (Exception e)
            {
                Console.WriteLine(e.Message);
                Console.WriteLine(e.StackTrace);
            }
            finally
            {
                Log.Debug.Close();
            }
        }
Example #2
0
 static void calc(Plot3d plotter, string filename)
 {
     try
     {
         var      sys   = new FormulaSystem(filename, plotter);
         DateTime start = DateTime.Now;
         Log.Debug.WriteLine("Started at {0}", start);
         sys.Reach();
         DateTime end = DateTime.Now;
         Log.Debug.WriteLine("Finished at {0}", end);
         Log.Debug.WriteLine("Total time: {0}s", (end - start).TotalSeconds);
         Log.Debug.Flush();
         Log.WriteLine("Total time: {0}s", (end - start).TotalSeconds);
     }
     catch (Exception e)
     {
         Console.WriteLine(e.Message);
         Console.WriteLine(e.StackTrace);
     }
 }
Example #3
0
        public FormulaSystem(string filename, Plot3d plotter)
            : base()
        {
            axisValue[0] = new REAL(0.0);
            axisValue[1] = new REAL(0.0);
            axisValue[2] = new REAL(0.0);
            Load(filename, "M");

            string[]            cNames   = new string[cVariables.Count];
            string[]            dNames   = new string[dVariables.Count];
            DoubleInterval[]    cInitial = new DoubleInterval[cVariables.Count];
            FPIntegerInterval[] dInitial = new FPIntegerInterval[dVariables.Count];
            int i = 0;

            foreach (var kvp in cVariables)
            {
                cNames[i]   = kvp.Key.name;
                cInitial[i] = kvp.Value.Clone();
                i++;
            }
            i = 0;
            foreach (var kvp in dVariables)
            {
                dNames[i]   = kvp.Key.Expr;
                dInitial[i] = kvp.Value.Clone();
                i++;
            }

            // build the ODEs
            ode = new List <AST>();
            foreach (var kvp in cVariables)
            {
                AST f;
                if (odes.TryGetValue(kvp.Key.name, out f))
                {
                    ode.Add(f);
                }
            }

            Print(Log.Output);
            Print(Log.Debug);

            Initialize(cNames, cInitial, dNames, dInitial, order, period);

            if (IsPolynomial)
            {
                Log.WriteLine("Using polynomial solver");
            }
            else if (ContainsSqrt)
            {
                Log.WriteLine("Using approximate Taylor expansion solver");
            }
            else
            {
                Log.WriteLine("Using non-polynomial Taylor model solver");
            }

            // look for lower and upper bounds
            foreach (var kvp in dVariables)
            {
                FixedPointNumber fp = kvp.Key;
                int lo     = -(1 << ((int)fp.bits - 1));
                int up     = (1 << ((int)fp.bits - 1)) - 1;
                var solver = ctx.MkSimpleSolver();
                AddController(ctx, solver, kvp.Key.Expr);
                lo = LowerBound(ctx, solver, fp.Expr, fp.bits, lo, up);
                up = UpperBound(ctx, solver, fp.Expr, fp.bits, lo, up);
                var ival = new FPIntegerInterval(lo, up, fp.bits, fp.decimals);
                controlBounds.Add(fp.Expr, ival);
                Log.Debug.WriteLine("Control variable '{0}' always in {1}", kvp.Key, ival);
            }

            Dictionary <string, DoubleInterval> initialValues = GetSystemState(initialState); // initialState.ToDictionary();

            if (!timeAxis)
            {
                axisInitialValue[0] = axisValue[0].Eval(initialValues);
            }
            axisInitialValue[1] = axisValue[1].Eval(initialValues);
            if (!searchIndexAxis)
            {
                axisInitialValue[2] = axisValue[2].Eval(initialValues);
            }

            this.plotter = plotter;
            if (plotter != null)
            {
                plotter.SetMinMax(axisMin[0], axisMax[0], axisMin[1], axisMax[1], axisMin[2], axisMax[2]);
                plotter.DefaultSettings();
                plotter.DrawEvent += Draw;
            }
        }