public EvaluateExpression ( string formula ) : double | ||
formula | string | |
리턴 | double |
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; } }
void ThreadedEvaluate(int TID, int chunkSize, int extra) { AK.ExpressionSolver solver_ = new AK.ExpressionSolver(); AK.Variable u_ = solver_.SetGlobalVariable("theta", 0); AK.Variable v_ = solver_.SetGlobalVariable("phi", 0); AK.Expression exp_ = solver_.SymbolicateExpression(expr); float umin = (float)solver_.EvaluateExpression(uminExpr); float umax = (float)solver_.EvaluateExpression(umaxExpr); float vmin = (float)solver_.EvaluateExpression(vminExpr); float vmax = (float)solver_.EvaluateExpression(vmaxExpr); System.Random rand = new System.Random(); for (int i = 0; i < chunkSize + extra; i++) { float u = (float)(chunkSize * TID + i) / (resolution - 1); u_.value = umin + (umax - umin) * u; for (int j = 0; j < resolution; j++) { float v = (float)j / (resolution - 1); v_.value = vmin + (vmax - vmin) * v; float result = (float)exp_.Evaluate(); Vector3 spherical = new Vector3((float)u_.value, (float)v_.value, result); Vector3 cartesian = SphericalToCartesian(spherical); Vector3 vel = new Vector3( (float)rand.NextDouble(), (float)rand.NextDouble(), (float)rand.NextDouble()); vel = vel.normalized * 0.1f; float sqrt2 = Mathf.Sqrt(2.0f); Color c = Color.cyan * Mathf.Sqrt(u * u + v * v) / sqrt2 + Color.yellow * (1.0f - Mathf.Sqrt(u * u + v * v) / sqrt2) + Color.red * Mathf.Sqrt(u * u + (1 - v) * (1 - v)) / sqrt2 + Color.green * (1.0f - Mathf.Sqrt(u * u + (1 - v) * (1 - v)) / sqrt2); Vector3 pos = new Vector3(cartesian.x, cartesian.z, cartesian.y); Particle p = new Particle() { position = pos, velocity = vel, color = c }; lock (insert_lck) { results.Add(p); } } } }
private static void TestNames() { ExpressionSolver solver = new ExpressionSolver(); try { solver.EvaluateExpression("0hakka"); throw new System.Exception("Test failed"); } catch (ESInvalidNameException) { // As expected } try { solver.EvaluateExpression("0.0.0"); throw new System.Exception("Test failed"); } catch (ESInvalidNameException) { // As expected } }
private static void TestNames() { ExpressionSolver solver = new ExpressionSolver(); try { solver.EvaluateExpression("0hakka"); throw new System.Exception("Test failed"); } catch (ESInvalidNameException) { // As expected } try { solver.EvaluateExpression("0.0.0"); throw new System.Exception("Test failed"); } catch (ESInvalidNameException) { // As expected } }
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; }