-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathMainForm.Save.cs
More file actions
165 lines (147 loc) · 6.71 KB
/
MainForm.Save.cs
File metadata and controls
165 lines (147 loc) · 6.71 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Data.Linq;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Windows.Forms.DataVisualization.Charting;
using Inaprop;
namespace Inaprop
{
public partial class MainForm
{
/// <summary>
/// PropのCSV出力
/// # header
/// Inaprop version
/// 各種パラメータ
/// # recorder
/// 分布にそった値
/// </summary>
/// <param name="prop"></param>
private void exportCSVprop(Prop prop, int partition, double start = 0)
{
if (partition < 2 || start < 0 || start > prop.Radius)
{
MessageBox.Show("Invalid value", "Error",
MessageBoxButtons.OK, MessageBoxIcon.Error);
}
// File Open
string stCurrentDir = System.IO.Directory.GetCurrentDirectory();
string exportPath = "/";
string exportName = prop.Name;
System.Text.Encoding enc = System.Text.Encoding.GetEncoding("Shift_JIS");
// 開く2つ目の引数は上書きか追加か
System.IO.StreamWriter sr = new System.IO.StreamWriter(stCurrentDir + exportPath + exportName + ".csv", true, enc);
// Header
//sr.WriteLine("Inaprop ver." + this.ProductVersion);
//sr.WriteLine("----");
sr.WriteLine("Number of blades" + "," + prop.Blade);
sr.WriteLine("radius(m)" + "," + prop.Radius);
sr.WriteLine("thrust(N)" + "," + prop.Thrust);
sr.WriteLine("Power(W)" + "," + prop.Power);
sr.WriteLine("Efficiency(%)" + "," + prop.Efficiency);
sr.WriteLine("speed(m/s)" + "," + prop.Uinf);
sr.WriteLine("rpm" + "," + prop.Rpm);
sr.WriteLine("hub rad.(m)" + "," + prop.Radius_in);
sr.WriteLine("air density(kg/m3)" + "," + prop.Rho);
sr.WriteLine("kinematic viscosity coeff.(kg/m-s)" + "," + prop.Nu);
sr.WriteLine("design METHOD" + "," + prop.Method);
sr.WriteLine("====");
// 出力用変数定義
double[] radius = new double[partition];
double[] chord = new double[partition];
double[] phi_deg = new double[partition];
double[] gamma = new double[partition];
double[] reinolds = new double[partition];
double[] Cl = new double[partition];
double[] Cd = new double[partition];
double[] thickness = new double[partition];
//partitionが分割数、divisionが何個の分割の山があるか
int division = partition - 1;
//prop.Rがn+1の配列を持っているので他のと合わせる必要がある
double[] radius_prop = new double[Prop.n];
for (int i = 0; i < Prop.n; i++)
{
radius_prop[i] = prop.R[i];
}
//補間
if (partition == Prop.n)
{
radius = radius_prop; //参照コピー、値をコピーならprop.R.CopyTo(radius);
chord = prop.ci;
phi_deg = prop.phi;
gamma = prop.gamma;
reinolds = prop.Re;
Cl = prop.CLs;
Cd = prop.CDs;
thickness = prop.thickness;
}
else
{
radius = Spline_Interpolate(radius_prop, radius_prop, partition, start);
//radius = Spline_Interpolate(prop.R, prop.R, partition, start);
chord = Spline_Interpolate(radius_prop, prop.ci, partition, start);
phi_deg = Spline_Interpolate(radius_prop, prop.phi, partition, start);
gamma = Spline_Interpolate(radius_prop, prop.gamma, partition, start);
reinolds = Spline_Interpolate(radius_prop, prop.Re, partition, start);
Cl = Spline_Interpolate(radius_prop, prop.CLs, partition, start);
Cd = Spline_Interpolate(radius_prop, prop.CDs, partition, start);
thickness = Spline_Interpolate(radius_prop, prop.thickness, partition, start);
}
// レコード
string[] parameterName = { "Position(m)", "chord(m)", "phi(deg)", "gamma", "Re", "CL", "CD", "Thickness"};
string s = string.Join(",", parameterName);
sr.WriteLine(s);
for (int i = 0; i < partition; i++)
{
string[] s1 = {radius[i].ToString("F3"), chord[i].ToString("F3"), phi_deg[i].ToString("F2"),
gamma[i].ToString("F3"), reinolds[i].ToString("F1"),
Cl[i].ToString("F2"), Cd[i].ToString("F2"),
(thickness[i] * chord[i]).ToString("F3")};
string s2 = string.Join(",", s1);
sr.WriteLine(s2);
}
//フィイルクローズ
sr.Close();
}
// DataTabke Header and Body
DataTable dth = new DataTable();
DataTable dtb = new DataTable();
//DataTableにすべき
//DataTableをそのまま保存すべき
//翼厚を追加
/// <summary>
/// 補間のためのメソッド。開始点と終了点は補間前後で不変。
/// </summary>
/// <param name="x1">補間したい既知のx軸</param>
/// <param name="y1">補間したい既知のy軸</param>
/// <param name="count2">補間した後の個数</param>
/// <param name ="init_value">補間した後のx軸のstart位置</param>
/// <returns>補間された後のy軸</returns>
private double[] Spline_Interpolate(double[] x1, double[] y1, int count2, double init_value)
{
double[] y2 = new double[count2];
var y_known = new Dictionary<double, double>();
for (int i = 0; i < y1.Count(); i++)
{
y_known.Add(x1[i], y1[i]);
}
var y_scaler = new SplineInterpolator(y_known);
//double start = y_known.First().Key;
double start = init_value;
double end = y_known.Last().Key;
double step = (end - start) / count2;
int iter = 0;
for (double x = start + 0.00001, i = 0; x <= end; x += step, i++)
{
iter = (int)i;
y2[iter] = y_scaler.GetValue(x);
}
return y2;
}
}
}