//private void wakeCalculation(ILArray<double> Ct, int i, ILCell wind, out ILArray<double> v_nac) public static void Calculate(ILArray <double> Ct, int i, ILMatFile wind, out ILArray <double> v_nac) { //% v_nac = WAKECALCULATION(Ct,i,wind) //This function calculates the wake //Currently it is a very very simplified wake calculation. It just serves as //a placeholder for a correct wake calculation that will come later ILArray <double> scaling = ILMath.linspace(0.5, 0.9, Ct.Length); v_nac = scaling * wind.GetArray <double>("wind").GetValue(i - 1, 1); }
private void SetExampleScene(ILPanel panel) { ILScene scene = new ILScene(); try { ILLabel.DefaultFont = new System.Drawing.Font("Helvetica", 8); //ilPanel1.Driver = RendererTypes.GDI; #region upper left plot // prepare some data ILArray <float> P = 1, x = ILMath.linspace <float>(-2, 2, 40), y = ILMath.linspace <float>(2, -2, 40); ILArray <float> F = ILMath.meshgrid(x, y, P); // a simple RBF ILArray <float> Z = ILMath.exp(-(1.2f * F * F + P * P)); // surface expects a single matrix Z[":;:;2"] = F; Z[":;:;1"] = P; // add a plot cube var pc = scene.Add(new ILPlotCube { // shrink viewport to upper left quadrant ScreenRect = new RectangleF(0.05f, 0, 0.4f, 0.5f), // 3D rotation TwoDMode = false, Children = { // add surface new ILSurface(Z) { // disable mouse hover marking Fill = { Markable = false }, Wireframe ={ Markable = false }, // make it shiny UseLighting = true, Children = { new ILColorbar() } }, //ILLinePlot.CreateXPlots(Z["1:10;:;0"], markers: new List<MarkerStyle>() { // MarkerStyle.None,MarkerStyle.None,MarkerStyle.None,MarkerStyle.None,MarkerStyle.Circle, MarkerStyle.Cross, MarkerStyle.Plus, MarkerStyle.TriangleDown }), //new ILLegend("hi","n","ku","zs","le", "blalblalblalblalb\\color{red} hier gehts rot") }, Rotation = Matrix4.Rotation(new Vector3(1.1f, -0.4f, -0.69f), 1.3f) }); #endregion #region top right plot // create a gear shape var gear = new ILGear(toothCount: 30, inR: 0.5f, outR: 0.9f) { Fill = { Markable = false, Color = Color.DarkGreen } }; // group with right clipping plane var clipgroup = new ILGroup() { Clipping = new ILClipParams() { Plane0 = new Vector4(1, 0, 0, 0) }, Children = { // a camera holding the (right) clipped gear new ILCamera() { // shrink viewport to upper top quadrant ScreenRect = new RectangleF(0.5f, 0, 0.5f, 0.5f), // populate interactive changes back to the global scene IsGlobal = true, // adds the gear to the camera Children ={ gear }, Position = new Vector3(0, 0, -15) } } }; // setup the scene var gearGroup = scene.Add(new ILGroup { clipgroup, clipgroup // <- second time: group is cloned }); gearGroup.First <ILCamera>().Parent.Clipping = new ILClipParams() { Plane0 = new Vector4(-1, 0, 0, 0) }; // make the left side transparent green gearGroup.First <ILTriangles>().Color = Color.FromArgb(100, Color.Green); // synchronize both cameras; source: left side gearGroup.First <ILCamera>().PropertyChanged += (s, arg) => { gearGroup.Find <ILCamera>().ElementAt(1).CopyFrom(s as ILCamera, false); }; #endregion #region left bottom plot // start value int nrBalls = 10; bool addBalls = true; var balls = new ILPoints("balls") { Positions = ILMath.tosingle(ILMath.randn(3, nrBalls)), Colors = ILMath.tosingle(ILMath.rand(3, nrBalls)), Color = null, Markable = false }; var leftBottomCam = scene.Add(new ILCamera { ScreenRect = new RectangleF(0, 0.5f, 0.5f, 0.5f), Projection = Projection.Perspective, Children = { balls } }); // funny label string harmony = @"\color{red}H\color{blue}a\color{green}r\color{yellow}m\color{magenta}o\color{cyan}n\color{black}y\reset "; var ballsLabel = scene.Add(new ILLabel(tag: "harmony") { Text = harmony, Fringe = { Color = Color.FromArgb(240, 240, 240) }, Position = new Vector3(-0.75f, -0.25f, 0) }); long oldFPS = 1; PointF currentMousePos = new PointF(); // setup the swarm. Start with a few balls, increase number // until framerate drops below 60 fps. ILArray <float> velocity = ILMath.tosingle(ILMath.randn(3, nrBalls)); EventHandler <ILRenderEventArgs> updateBallsRenderFrame = (s, arg) => { // transform viewport coords into 3d scene coords Vector3 mousePos = new Vector3(currentMousePos.X * 2 - 1, currentMousePos.Y * -2 + 1, 0); // framerate dropped? -> stop adding balls if (panel.FPS < oldFPS && panel.FPS < 60) { addBalls = false; } oldFPS = panel.FPS; Computation.UpdateBalls(mousePos, balls, velocity, addBalls); // balls buffers have been changed -> must call configure() to publish balls.Configure(); // update balls label ballsLabel.Text = harmony + "(" + balls.Positions.DataCount.ToString() + " balls)"; }; // saving the mouse position in MouseMove is easier for // transforming the coordinates into the viewport leftBottomCam.MouseMove += (s, arg) => { // save the mouse position currentMousePos = arg.LocationF; }; panel.BeginRenderFrame += updateBallsRenderFrame; m_cleanUpExample = () => { leftBottomCam.MouseMove -= (s, arg) => { // save the mouse position currentMousePos = arg.LocationF; }; panel.BeginRenderFrame -= updateBallsRenderFrame; }; #endregion panel.Scene = scene; } catch (Exception exc) { System.Diagnostics.Trace.WriteLine("ILPanel_Load Error:"); System.Diagnostics.Trace.WriteLine("===================="); System.Diagnostics.Trace.WriteLine(exc.ToString()); MessageBox.Show(exc.ToString()); } }
protected static ILArray <double> linspace(double start, double end, double length) { return(ILMath.linspace(start, end, length)); }
private void Dipole_Imaging_Load(object sender, EventArgs e) { try { DataTable table = new DataTable(); if (inforadio == 0) { table.Columns.AddRange(new DataColumn[] { new DataColumn("a (m)"), new DataColumn("C1"), new DataColumn("C2"), new DataColumn("P1"), new DataColumn("P2"), new DataColumn("X (m)"), new DataColumn("Z/n (m)"), new DataColumn("V (mV)"), new DataColumn("I (mA)"), new DataColumn("R (Ω)"), new DataColumn("K (m)"), new DataColumn("ρa (Ω.m)"), new DataColumn("Za (m)") }); string[] MyDataLines = MyDataString.Split('\n'); L = MyDataLines.Length; double[] data_a = new double[L]; double[] data_C1 = new double[L]; double[] data_C2 = new double[L]; double[] data_P1 = new double[L]; double[] data_P2 = new double[L]; double[] data_V = new double[L]; double[] data_I = new double[L]; double[] data_R = new double[L]; double[] data_K = new double[L]; double[] data_Rho = new double[L]; double[] data_dis = new double[L]; double[] data_n = new double[L]; double[] data_Z = new double[L]; double pi = 3.14; for (int i = 0; i < L; i++) { string[] MyDataColumns = MyDataLines[i].Split('\t'); data_a[i] = Convert.ToDouble(MyDataColumns[selected[0]]); data_C1[i] = Convert.ToDouble(MyDataColumns[selected[1]]); data_C2[i] = Convert.ToDouble(MyDataColumns[selected[2]]); data_P1[i] = Convert.ToDouble(MyDataColumns[selected[3]]); data_P2[i] = Convert.ToDouble(MyDataColumns[selected[4]]); data_V[i] = Convert.ToDouble(MyDataColumns[selected[5]]); data_I[i] = Convert.ToDouble(MyDataColumns[selected[6]]); data_R[i] = data_V[i] / data_I[i]; data_n[i] = data_P1[i] - data_C2[i]; data_K[i] = data_n[i] * data_a[i] * pi * (data_n[i] + 2) * (data_n[i] + 1); data_Rho[i] = data_R[i] * data_K[i]; data_dis[i] = (data_P1[i] + data_C2[i]) * data_a[i] / 2; data_Z[i] = data_n[i] * data_a[i] / 3; object[] Data_Row = { data_a[i], data_C1[i], data_C2[i], data_P1[i], data_P2[i], data_dis[i],data_n[i], data_V[i], data_I[i], data_R[i], data_K[i], data_Rho[i], data_Z[i] }; table.Rows.Add(Data_Row); } dataGridView1.DataSource = table; dis = data_dis; Rho = data_Rho; n = data_n; double[] X = data_dis; double[] Y = data_n; double[] Z = data_Rho; /* * double[] Z = new double[data_Rho.Length]; * for (int i = 0; i < data_Rho.Length; i++) * { * Z[i] = Math.Log10(data_Rho[i]); * } */ double minX = X.Min(); double maxX = X.Max(); double minY = Y.Min(); double maxY = Y.Max(); double intX = 1; double intY = 0.1; int LX = Convert.ToInt32((maxX - minX) / intX); int LY = Convert.ToInt32((maxY - minY) / intY); double[] intpX = new double[LX]; double[] intpY = new double[LY]; for (int i = 0; i < LX; i++) { if (i == 0) { intpX[i] = minX; } else { intpX[i] = intpX[i - 1] + intX; } } for (int i = 0; i < LY; i++) { if (i == 0) { intpY[i] = minY; } else { intpY[i] = intpY[i - 1] + intY; } } // IDW int nX = intpX.Length; int nY = intpY.Length; int N = nX * nY; double[] intpZ = new double[N]; double[] susX = new double[N]; double[] susY = new double[N]; for (int i = 0; i < nY; i++) { for (int j = 0; j < nX; j++) { susX[j + (nX * (i))] = intpX[j]; susY[j + (nX * (i))] = intpY[i]; } } double k = 2; for (int i = 0; i < N; i++) { double[] d_obs = new double[X.Length]; double[] d_ok = new double[X.Length]; double[] spd_ok = new double[X.Length]; double[] Zspd_ok = new double[X.Length]; double[] s_spd_ok = new double[X.Length]; double[] s_Zspd_ok = new double[X.Length]; for (int j = 0; j < X.Length; j++) { d_obs[j] = Math.Sqrt(Math.Pow(X[j] - susX[i], 2) + Math.Pow(Y[j] - susY[i], 2)); d_ok[j] = Math.Pow(d_obs[j], k); spd_ok[j] = 1 / (d_ok[j] + 0.00001); Zspd_ok[j] = Z[j] * spd_ok[j]; if (j == 0) { s_spd_ok[j] = spd_ok[j]; s_Zspd_ok[j] = Zspd_ok[j]; } else { s_spd_ok[j] = s_spd_ok[j - 1] + spd_ok[j]; s_Zspd_ok[j] = s_Zspd_ok[j - 1] + Zspd_ok[j]; } } intpZ[i] = s_Zspd_ok[X.Length - 1] / s_spd_ok[X.Length - 1]; } ILArray <double> ILintpZ = intpZ; ILArray <double> matrix = ILMath.zeros(nY, nX); for (int i = 0; i < nY; i++) { ILArray <int> rangeX = ILMath.vec <int>(0, nX - 1); ILArray <int> rangeZ = ILMath.vec <int>(0 + (nX) * (i), (nX * (i + 1) - 1)); matrix[i, rangeX] = ILintpZ[rangeZ]; } ILArray <float> matrixf = ILMath.convert <double, float>(matrix); ILArray <float> matrixl = ILMath.log10(matrixf); ILArray <float> Xf = ILMath.convert <double, float>(intpX); ILArray <float> Yf = -1 * ILMath.convert <double, float>(intpY); matrixgen = matrixf; Xgen = X; Ygen = Y; // Example ILArray <float> ZZZ = ILSpecialData.sincf(40, 50); ILArray <float> XXX = ILMath.linspace <float>(1, 2, 50); ILArray <float> YYY = ILMath.linspace <float>(1, 2, 40); ilPanel1.Scene.Add(new ILPlotCube { Axes = { XAxis = { Label = { Text = "Distance (m)" } }, YAxis = { Label = { Text = "n" } } }, Children = { new ILSurface(matrixf, Xf, Yf) { // make thin transparent wireframes Wireframe = { Color = Color.FromArgb(50,Color.LightGray) }, // choose a different colormap Colormap = new ILColormap(Colormaps.Jet), // add a colorbar (see below) Children = { new ILColorbar() } } } }); } if (inforadio == 1) { table.Columns.AddRange(new DataColumn[] { new DataColumn("a (m)"), new DataColumn("C1"), new DataColumn("C2"), new DataColumn("P1"), new DataColumn("P2"), new DataColumn("X (m)"), new DataColumn("Z/n (m)"), new DataColumn("R (Ω)"), new DataColumn("K (m)"), new DataColumn("ρa (Ω.m)"), new DataColumn("Za (m)") }); string[] MyDataLines = MyDataString.Split('\n'); L = MyDataLines.Length; double[] data_a = new double[L]; double[] data_C1 = new double[L]; double[] data_C2 = new double[L]; double[] data_P1 = new double[L]; double[] data_P2 = new double[L]; double[] data_R = new double[L]; double[] data_K = new double[L]; double[] data_Rho = new double[L]; double[] data_dis = new double[L]; double[] data_n = new double[L]; double[] data_Z = new double[L]; double pi = 3.14; for (int i = 0; i < L; i++) { string[] MyDataColumns = MyDataLines[i].Split('\t'); data_a[i] = Convert.ToDouble(MyDataColumns[selected[0]]); data_C1[i] = Convert.ToDouble(MyDataColumns[selected[1]]); data_C2[i] = Convert.ToDouble(MyDataColumns[selected[2]]); data_P1[i] = Convert.ToDouble(MyDataColumns[selected[3]]); data_P2[i] = Convert.ToDouble(MyDataColumns[selected[4]]); data_R[i] = Convert.ToDouble(MyDataColumns[selected[5]]); data_n[i] = data_P1[i] - data_C2[i]; data_K[i] = data_n[i] * data_a[i] * pi * (data_n[i] + 2) * (data_n[i] + 1); data_Rho[i] = data_R[i] * data_K[i]; data_dis[i] = (data_P1[i] + data_C2[i]) * data_a[i] / 2; data_Z[i] = data_n[i] * data_a[i] / 3; object[] Data_Row = { data_a[i], data_C1[i], data_C2[i], data_P1[i], data_P2[i], data_dis[i],data_n[i], data_R[i], data_K[i], data_Rho[i], data_Z[i] }; table.Rows.Add(Data_Row); } dataGridView1.DataSource = table; dis = data_dis; Rho = data_Rho; n = data_n; double[] X = data_dis; double[] Y = data_n; double[] Z = data_Rho; double minX = X.Min(); double maxX = X.Max(); double minY = Y.Min(); double maxY = Y.Max(); double intX = 1; double intY = 0.1; int LX = Convert.ToInt32((maxX - minX) / intX); int LY = Convert.ToInt32((maxY - minY) / intY); double[] intpX = new double[LX]; double[] intpY = new double[LY]; for (int i = 0; i < LX; i++) { if (i == 0) { intpX[i] = minX; } else { intpX[i] = intpX[i - 1] + intX; } } for (int i = 0; i < LY; i++) { if (i == 0) { intpY[i] = minY; } else { intpY[i] = intpY[i - 1] + intY; } } // IDW int nX = intpX.Length; int nY = intpY.Length; int N = nX * nY; double[] intpZ = new double[N]; double[] susX = new double[N]; double[] susY = new double[N]; for (int i = 0; i < nY; i++) { for (int j = 0; j < nX; j++) { susX[j + (nX * (i))] = intpX[j]; susY[j + (nX * (i))] = intpY[i]; } } double k = 2; for (int i = 0; i < N; i++) { double[] d_obs = new double[X.Length]; double[] d_ok = new double[X.Length]; double[] spd_ok = new double[X.Length]; double[] Zspd_ok = new double[X.Length]; double[] s_spd_ok = new double[X.Length]; double[] s_Zspd_ok = new double[X.Length]; for (int j = 0; j < X.Length; j++) { d_obs[j] = Math.Sqrt(Math.Pow(X[j] - susX[i], 2) + Math.Pow(Y[j] - susY[i], 2)); d_ok[j] = Math.Pow(d_obs[j], k); spd_ok[j] = 1 / (d_ok[j] + 0.00001); Zspd_ok[j] = Z[j] * spd_ok[j]; if (j == 0) { s_spd_ok[j] = spd_ok[j]; s_Zspd_ok[j] = Zspd_ok[j]; } else { s_spd_ok[j] = s_spd_ok[j - 1] + spd_ok[j]; s_Zspd_ok[j] = s_Zspd_ok[j - 1] + Zspd_ok[j]; } } intpZ[i] = s_Zspd_ok[X.Length - 1] / s_spd_ok[X.Length - 1]; } ILArray <double> ILintpZ = intpZ; ILArray <double> matrix = ILMath.zeros(nY, nX); for (int i = 0; i < nY; i++) { ILArray <int> rangeX = ILMath.vec <int>(0, nX - 1); ILArray <int> rangeZ = ILMath.vec <int>(0 + (nX) * (i), (nX * (i + 1) - 1)); matrix[i, rangeX] = ILintpZ[rangeZ]; } ILArray <float> matrixf = ILMath.convert <double, float>(matrix); ILArray <float> Xf = ILMath.convert <double, float>(intpX); ILArray <float> Yf = -1 * ILMath.convert <double, float>(intpY); matrixgen = matrixf; Xgen = X; Ygen = Y; // Example ILArray <float> ZZZ = ILSpecialData.sincf(40, 50); ILArray <float> XXX = ILMath.linspace <float>(1, 2, 50); ILArray <float> YYY = ILMath.linspace <float>(1, 2, 40); ilPanel1.Scene.Add(new ILPlotCube { Axes = { XAxis = { Label = { Text = "Distance (m)" } }, YAxis = { Label = { Text = "n" } } }, Children = { new ILSurface(matrixf, Xf, Yf) { // make thin transparent wireframes Wireframe = { Color = Color.FromArgb(50,Color.LightGray) }, // choose a different colormap Colormap = new ILColormap(Colormaps.Jet), // add a colorbar (see below) Children = { new ILColorbar() } } } }); } if (inforadio == 2) { table.Columns.AddRange(new DataColumn[] { new DataColumn("Distance (m)"), new DataColumn("Za (m)"), new DataColumn("ρa (Ω.m)") }); string[] MyDataLines = MyDataString.Split('\n'); L = MyDataLines.Length; double[] data_dis = new double[L]; double[] data_Z = new double[L]; double[] data_Rho = new double[L]; for (int i = 0; i < L; i++) { string[] MyDataColumns = MyDataLines[i].Split('\t'); data_Z[i] = Convert.ToDouble(MyDataColumns[selected[1]]); data_dis[i] = Convert.ToDouble(MyDataColumns[selected[0]]); data_Rho[i] = Convert.ToDouble(MyDataColumns[selected[2]]); object[] Data_Row = { data_dis[i], data_Z[i], data_Rho[i] }; table.Rows.Add(Data_Row); } dataGridView1.DataSource = table; dis = data_dis; Rho = data_Rho; n = data_Z; double[] X = data_dis; double[] Y = data_Z; double[] Z = data_Rho; double minX = X.Min(); double maxX = X.Max(); double minY = Y.Min(); double maxY = Y.Max(); double intX = 1; double intY = 1; int LX = Convert.ToInt32((maxX - minX) / intX); int LY = Convert.ToInt32((maxY - minY) / intY); double[] intpX = new double[LX]; double[] intpY = new double[LY]; for (int i = 0; i < LX; i++) { if (i == 0) { intpX[i] = minX; } else { intpX[i] = intpX[i - 1] + intX; } } for (int i = 0; i < LY; i++) { if (i == 0) { intpY[i] = minY; } else { intpY[i] = intpY[i - 1] + intY; } } // IDW int nX = intpX.Length; int nY = intpY.Length; int N = nX * nY; double[] intpZ = new double[N]; double[] susX = new double[N]; double[] susY = new double[N]; for (int i = 0; i < nY; i++) { for (int j = 0; j < nX; j++) { susX[j + (nX * (i))] = intpX[j]; susY[j + (nX * (i))] = intpY[i]; } } double k = 2; for (int i = 0; i < N; i++) { double[] d_obs = new double[X.Length]; double[] d_ok = new double[X.Length]; double[] spd_ok = new double[X.Length]; double[] Zspd_ok = new double[X.Length]; double[] s_spd_ok = new double[X.Length]; double[] s_Zspd_ok = new double[X.Length]; for (int j = 0; j < X.Length; j++) { d_obs[j] = Math.Sqrt(Math.Pow(X[j] - susX[i], 2) + Math.Pow(Y[j] - susY[i], 2)); d_ok[j] = Math.Pow(d_obs[j], k); spd_ok[j] = 1 / (d_ok[j] + 0.00001); Zspd_ok[j] = Z[j] * spd_ok[j]; if (j == 0) { s_spd_ok[j] = spd_ok[j]; s_Zspd_ok[j] = Zspd_ok[j]; } else { s_spd_ok[j] = s_spd_ok[j - 1] + spd_ok[j]; s_Zspd_ok[j] = s_Zspd_ok[j - 1] + Zspd_ok[j]; } } intpZ[i] = s_Zspd_ok[X.Length - 1] / s_spd_ok[X.Length - 1]; } ILArray <double> ILintpZ = intpZ; ILArray <double> matrix = ILMath.zeros(nY, nX); for (int i = 0; i < nY; i++) { ILArray <int> rangeX = ILMath.vec <int>(0, nX - 1); ILArray <int> rangeZ = ILMath.vec <int>(0 + (nX) * (i), (nX * (i + 1) - 1)); matrix[i, rangeX] = ILintpZ[rangeZ]; } ILArray <float> matrixf = ILMath.convert <double, float>(matrix); ILArray <float> Xf = ILMath.convert <double, float>(intpX); ILArray <float> Yf = -1 * ILMath.convert <double, float>(intpY); matrixgen = matrixf; Xgen = X; Ygen = Y; // Example ILArray <float> ZZZ = ILSpecialData.sincf(40, 50); ILArray <float> XXX = ILMath.linspace <float>(1, 2, 50); ILArray <float> YYY = ILMath.linspace <float>(1, 2, 40); ilPanel1.Scene.Add(new ILPlotCube { Axes = { XAxis = { Label = { Text = "Distance (m)" } }, YAxis = { Label = { Text = "Z" } } }, Children = { new ILSurface(matrixf, Xf, Yf) { // make thin transparent wireframes Wireframe = { Color = Color.FromArgb(50,Color.LightGray) }, // choose a different colormap Colormap = new ILColormap(Colormaps.Jet), // add a colorbar (see below) Children = { new ILColorbar() } } } }); } } catch (Exception ex) { MessageBox.Show(ex.Message); return; } }