public void EnableVectorField()
 {
     //Only allowed on first order problems
     if (simController != null)
     {
         if (simController.GetMotion3DSetup.Order == 1)
         {
             if (!(initialized))
             {
                 InitializeVectorField();
             }
             if (F == null)
             {
                 F = simController.GetMotion3DSetup.F;
             }
             //Enable vector field
             vectorField = 1;
             for (int z = 0; z < 10; z++)
             {
                 for (int y = 0; y < 10; y++)
                 {
                     for (int x = 0; x < 10; x++)
                     {
                         //var d = vectorDist;
                         //instance[x + y * 10 + z * 100].GetComponent<MeshRenderer>().material.color =
                         //new Color(0f, 0f, 0f, 0.1f);
                         instance[x + y * 10 + z * 100].SetActive(true);
                     }
                 }
             }
         }
     }
 }
Beispiel #2
0
    public void FunctionVectorND_Dim()
    {
        //Tests construction and dimensionality
        ExpressionParser parser = new ExpressionParser();
        FunctionVectorND fv1    = new FunctionVectorND(7);

        Assert.AreEqual(fv1.GetDim(), 7);
    }
Beispiel #3
0
    public void FunctionVectorND_Eval_1func1var()
    {
        //Tests basic evaluation of one function of one variable
        ExpressionParser parser = new ExpressionParser();
        FunctionVectorND fv1    = new FunctionVectorND(1);

        fv1.funcs[0] = parser.EvaluateExpression("-(y+1)*(y+3)").ToDelegate("y");
        Assert.AreEqual(fv1.Eval(2)[0], -15, required_accuracy);
    }
Beispiel #4
0
        //Generates a new mesh point
        public VectorND RungeKutta(double t, double h, VectorND v,
                                   FunctionVectorND f)
        {
            VectorND k1 = h * f.Eval(RKCallBuild(t, 0, v, 0, nullVector));
            VectorND k2 = h * f.Eval(RKCallBuild(t, h / 2, v, 0.5, k1));
            VectorND k3 = h * f.Eval(RKCallBuild(t, h / 2, v, 0.5, k2));
            VectorND k4 = h * f.Eval(RKCallBuild(t, h, v, 1.0, k3));

            return(v + (1.0 / 6.0) * (k1 + 2 * k2 + 2 * k3 + k4));
        }
 // Use this for initialization
 public void Start()
 {
     //Initialize update frequency
     updateFrequencyManager = new UpdateFrequencyManager(UPDATE_FREQUENCY);
     //Hook simulation controller reference
     simController = gameObject.GetComponent <Motion3DSimulationController>();
     //Hook arrow reference
     arrow = GameObject.Find("VectorModel");
     arrow.SetActive(false);
     //lazy initialization of vector field. Will initialize on first enable
     vectorField = 0;
     initialized = false;
     F           = null;
 }
Beispiel #6
0
    public void FunctionVectorND_Eval_3funcs2vars()
    {
        //Tests evaluation of 3 dimensional function of 2 variables
        ExpressionParser parser = new ExpressionParser();
        FunctionVectorND fv1    = new FunctionVectorND(3);

        fv1.funcs[0] = parser.EvaluateExpression("x+y-7").ToDelegate("x", "y");
        fv1.funcs[1] = parser.EvaluateExpression("x*y+y").ToDelegate("x", "y");
        fv1.funcs[2] = parser.EvaluateExpression("y^x-17*x").ToDelegate("x", "y");
        VectorND result = fv1.Eval(2, 3);

        Assert.AreEqual(result[0], -2, required_accuracy);
        Assert.AreEqual(result[1], 9, required_accuracy);
        Assert.AreEqual(result[2], -25, required_accuracy);
    }
Beispiel #7
0
    public void RungeKutta_works()
    {
        //3 dimensional function of 2 variables
        ExpressionParser parser = new ExpressionParser();
        FunctionVectorND fv1    = new FunctionVectorND(3);

        fv1.funcs[0] = parser.EvaluateExpression("x+y-7").ToDelegate("x", "y");
        fv1.funcs[1] = parser.EvaluateExpression("x*y+y").ToDelegate("x", "y");
        fv1.funcs[2] = parser.EvaluateExpression("y^x-17*x").ToDelegate("x", "y");
        VectorND v1 = new VectorND(1, 2, 3);

        ODEIVPSolver solver = new ODEIVPSolver(3);
        VectorND     result = solver.RungeKutta(0, 0.1, v1, fv1);

        Assert.AreEqual(result[0], 0.374145833333333, required_accuracy);
        Assert.AreEqual(result[1], 2.072081250000000, required_accuracy);
        Assert.AreEqual(result[2], 3.012229986742000, required_accuracy);
    }
Beispiel #8
0
 //Constructor
 public Motion3DSetup(string expressionX_in, string expressionY_in,
                      string expressionZ_in, Dictionary <string, double> params_in, int order_in)
 {
     expressionX = expressionX_in;
     expressionY = expressionY_in;
     expressionZ = expressionZ_in;
     parameters  = params_in;
     order       = order_in;
     if (order == 1)
     {
         dim = 3;
     }
     else
     {
         dim = 6;
     }
     F_internal = new FunctionVectorND(dim);
     parser     = new ExpressionParser();
     Parse();
 }
Beispiel #9
0
 //Constructor
 public ODEInitialValueProblem(byte dim_in, double h, double tIntercept)
 {
     solution = new DataSet(dim_in, tIntercept, h);
     solver   = new ODEIVPSolver(dim_in);
     F        = new FunctionVectorND(dim_in);
 }