GetGlobalVariable() public méthode

public GetGlobalVariable ( string name ) : Variable
name string
Résultat Variable
Exemple #1
0
    // Evaluate all equations for a given x (called by a thread), and popluate arrays with the results
    void ThreadedEvaluate(float x_temp, int inOrderCount)
    {
        AK.ExpressionSolver subSolver = new AK.ExpressionSolver();
        AK.Expression       subExp    = new AK.Expression();
        subSolver.SetGlobalVariable("x", 0);
        subSolver.SetGlobalVariable("y", 0);
        subSolver.SetGlobalVariable("z", 0);
        AK.Variable subX = subSolver.GetGlobalVariable("x");
        AK.Variable subY = subSolver.GetGlobalVariable("y");
        AK.Variable subZ = subSolver.GetGlobalVariable("z");
        subExp = subSolver.SymbolicateExpression(es.expressions["X"].expression);

        for (float y_temp = ymin; y_temp < ymax; y_temp += delta)
        {
            for (float z_temp = zmin; z_temp < zmax; z_temp += delta)
            {
                if ((int)((z_temp - zmin) / delta) % sleepInterval == 0)
                {
                    Thread.Sleep(1);
                }

                subX.value = x_temp;
                subY.value = z_temp;
                subZ.value = y_temp;

                float x = (float)subExp.Evaluate();

                //Mathf.Clamp(x, -Mathf.Exp(20), Mathf.Exp(20));

                //float y = (float)expY.Evaluate();
                //Mathf.Clamp(y, -Mathf.Exp(20), Mathf.Exp(20));

                //float z = (float)expZ.Evaluate();
                //Mathf.Clamp(z, -Mathf.Exp(20), Mathf.Exp(20));

                Vector3 target = new Vector3(x_temp, y_temp, z_temp);

                Vector3 result = new Vector3(x, 0, 0);
                if (float.IsNaN(x)
                    //   || float.IsNaN(y)
                    //   || float.IsNaN(z)
                    ||
                    Mathf.Abs(x) == 0)
                {
                    result = new Vector3(0, 0, 0);
                }

                //Vector3 direction = result.normalized;
                lock (lck)
                {
                    max_magnitude = (Mathf.Abs(x) > max_magnitude) ? Mathf.Abs(x) : max_magnitude;
                }
                startPts[inOrderCount] = target;
                offsets[inOrderCount]  = result;
                inOrderCount++;
            }
        }
        // numComplete++;
    }
 // Use this for initialization
 void Start()
 {
     vectors  = new List <Transform>();
     startPts = new List <Vector3>();
     offsets  = new List <Vector3>();
     solver   = new AK.ExpressionSolver();
     expX     = new AK.Expression(); expY = new AK.Expression(); expZ = new AK.Expression();
     solver.SetGlobalVariable("x", 0); solver.SetGlobalVariable("y", 0); solver.SetGlobalVariable("z", 0);
     varX          = solver.GetGlobalVariable("x"); varY = solver.GetGlobalVariable("y"); varZ = solver.GetGlobalVariable("z");
     max_magnitude = 0f;
     //CalculateVectors();
     //DrawVectorField();
 }
        public static void TestUndefinedVariablePolicies()
        {
            ExpressionSolver solver = new ExpressionSolver();

            try
            {
                solver.SymbolicateExpression("test");
                throw new System.Exception("ExpressionSolverTest failed");
            }
            catch (AK.ESUnknownExpressionException)
            {
                // Expected behaviour
            }

            solver.undefinedVariablePolicy = ExpressionSolver.UndefinedVariablePolicy.DefineGlobalVariable;
            var exp2 = solver.SymbolicateExpression("test2");

            AssertSameValue(solver.GetGlobalVariable("test2").value, 0);
            AssertSameValue(exp2.Evaluate(), 0);

            solver.undefinedVariablePolicy = ExpressionSolver.UndefinedVariablePolicy.DefineExpressionLocalVariable;
            var exp3  = solver.SymbolicateExpression("sin(test3)");
            var test3 = exp3.GetVariable("test3");

            AssertSameValue(test3.value, 0);
            test3.value = System.Math.PI / 2;
            AssertSameValue(exp3.Evaluate(), 1);
        }
Exemple #4
0
    public void SetupSolver()
    {
        depth = parameter_names.Count;
        width = (int)Mathf.Pow(PARTICLE_COUNT, 1f / (float)depth);

        for (int i = 0; i < depth; i++)
        {
            string name = parameter_names[i];
            indexedParam[i]    = name;
            parameterMin[name] = (float)solver.EvaluateExpression(parameter_min[name]);
            parameterMax[name] = (float)solver.EvaluateExpression(parameter_max[name]);

            solver.SetGlobalVariable(name, 0);
        }

        expr1 = solver.SymbolicateExpression(expression1);
        expr2 = solver.SymbolicateExpression(expression2);
        expr3 = solver.SymbolicateExpression(expression3);

        for (int i = 0; i < depth; i++)
        {
            string      name = parameter_names[i];
            AK.Variable var  = solver.GetGlobalVariable(name);
            //vars.Add(var);
            vars[name] = var;
        }
    }
        public static void TestUndefinedVariablePolicies()
        {
            ExpressionSolver solver = new ExpressionSolver();
            try
            {
                solver.SymbolicateExpression("test");
                throw new System.Exception("ExpressionSolverTest failed");
            }
            catch (AK.ESUnknownExpressionException)
            {
                // Expected behaviour
            }

            solver.undefinedVariablePolicy = ExpressionSolver.UndefinedVariablePolicy.DefineGlobalVariable;
            var exp2 = solver.SymbolicateExpression("test2");
            AssertSameValue(solver.GetGlobalVariable("test2").value,0);
            AssertSameValue(exp2.Evaluate(),0);

            solver.undefinedVariablePolicy = ExpressionSolver.UndefinedVariablePolicy.DefineExpressionLocalVariable;
            var exp3 = solver.SymbolicateExpression("sin(test3)");
            var test3 = exp3.GetVariable("test3");
            AssertSameValue(test3.value,0);
            test3.value = System.Math.PI/2;
            AssertSameValue(exp3.Evaluate(),1);
        }
Exemple #6
0
    void SamplePoints()
    {
        Vector3 start = referencePoint.lastLocalPos;

        //lck = new object();
        //thread_num = SystemInfo.processorCount;

        //thread_num = 1;
        //thread_num = (thread_num > 2) ? 2 : thread_num;

        tmin = (float)solver.EvaluateExpression(t_min);
        tmin = (tmin > 0) ? 0 : tmin;
        tmax = (float)solver.EvaluateExpression(t_max);
        tmax = (tmax < 0) ? 0 : tmax;

        currLocalPos = referencePoint.lastLocalPos;
        currExpX     = vectorField.expressionX;
        currExpY     = vectorField.expressionY;
        currExpZ     = vectorField.expressionZ;

        int lastCount = positions.Count;

        positions.Clear();

        solver = new AK.ExpressionSolver();

        solver.SetGlobalVariable("x", referencePoint.lastLocalPos.x);
        solver.SetGlobalVariable("y", referencePoint.lastLocalPos.y);
        solver.SetGlobalVariable("z", referencePoint.lastLocalPos.z);
        expX = solver.SymbolicateExpression(vectorField.es.expressions[ExpressionSet.ExpOptions.X].expression);
        expY = solver.SymbolicateExpression(vectorField.es.expressions[ExpressionSet.ExpOptions.Y].expression);
        expZ = solver.SymbolicateExpression(vectorField.es.expressions[ExpressionSet.ExpOptions.Z].expression);
        varX = solver.GetGlobalVariable("x");
        varY = solver.GetGlobalVariable("y");
        varZ = solver.GetGlobalVariable("z");

        //solvers = new AK.ExpressionSolver[thread_num];
        //expXs = new AK.Expression[thread_num];
        //expYs = new AK.Expression[thread_num];
        //expZs = new AK.Expression[thread_num];
        //for(int i = 0; i < thread_num; i++)
        //{
        //    solvers[i] = new AK.ExpressionSolver();
        //    solvers[i].SetGlobalVariable("x", 0);
        //    solvers[i].SetGlobalVariable("y", 0);
        //    solvers[i].SetGlobalVariable("z", 0);
        //    expXs[i] = solvers[i].SymbolicateExpression(vectorField.es.expressions[ExpressionSet.ExpOptions.X].expression);
        //    expYs[i] = solvers[i].SymbolicateExpression(vectorField.es.expressions[ExpressionSet.ExpOptions.Y].expression);
        //    expZs[i] = solvers[i].SymbolicateExpression(vectorField.es.expressions[ExpressionSet.ExpOptions.Z].expression);
        //}
        //Thread[] threads = new Thread[thread_num];
        float positiveCount = tmax / time_step;

        positiveCount = (positiveCount > 50000) ? 50000 : positiveCount;
        float negativeCount = -tmin / time_step;

        negativeCount = (negativeCount > 50000) ? 50000 : negativeCount;
        //Vector3[] startPts = new Vector3[thread_num];
        //startPts[0] = referencePoint.lastLocalPos;
        //for(int i = 1; i < thread_num; i++)
        //{
        //    startPts[i] = RK4(startPts[i - 1], time_step);
        //}
        //for(int i = 0; i < thread_num; i++)
        //{
        //    int index = i;
        //    threads[i] = new Thread(() => ThreadedSampling(index, startPts[index], time_step * thread_num, positiveCount / thread_num,
        //        negativeCount / thread_num));
        //    threads[i].Start();
        //}
        ////for (int i = 0; i < 5; i++)
        ////{
        ////    yield return null;
        ////}
        //for (int i = 0; i < thread_num; i++)
        //{
        //    threads[i].Join();
        //}

        Vector3 curr = start;

        for (int i = 0; i < positiveCount; i++)
        {
            curr = RK4(curr, time_step);
            positions.Add(i + 1, curr);
        }
        curr = start;
        for (int i = 0; i < negativeCount; i++)
        {
            curr = RK4(curr, -time_step);
            positions.Add(-i, curr);
        }

        if (positions.Count != lastCount)
        {
            InitializeParticleSystem();
        }

        //RenderParticles();

        currHighlight   = 0;
        thread_finished = true;
    }