public FilePersistence(TransCalc tc) { this.tc = tc; cfg_keywords = new Dictionary <CONFIG_KEYWORDS, string>(); cfg_keywords[CONFIG_KEYWORDS.V_IN] = "V_mains"; cfg_keywords[CONFIG_KEYWORDS.B_MAX] = "B"; cfg_keywords[CONFIG_KEYWORDS.H] = "H"; cfg_keywords[CONFIG_KEYWORDS.PERMEABILITY] = "u"; cfg_keywords[CONFIG_KEYWORDS.I_EX] = "Iex"; cfg_keywords[CONFIG_KEYWORDS.CORE_W] = "CoreW"; cfg_keywords[CONFIG_KEYWORDS.CORE_H] = "CoreH"; cfg_keywords[CONFIG_KEYWORDS.CORE_L] = "CoreL"; cfg_keywords[CONFIG_KEYWORDS.Ae_W] = "AeW"; cfg_keywords[CONFIG_KEYWORDS.Ae_H] = "AeH"; cfg_keywords[CONFIG_KEYWORDS.MPATH_W] = "MpathW"; cfg_keywords[CONFIG_KEYWORDS.MPATH_H] = "MpathH"; cfg_keywords[CONFIG_KEYWORDS.WINDOW_SIZE] = "WindowSize"; cfg_keywords[CONFIG_KEYWORDS.COUPLING_COEFF] = "CouplingCoeff"; cfg_keywords[CONFIG_KEYWORDS.STACKING_FACTOR] = "StackingFactor"; cfg_keywords[CONFIG_KEYWORDS.INSULATION] = "Insulation_mm"; cfg_keywords[CONFIG_KEYWORDS.V_OUT] = "Vout"; cfg_keywords[CONFIG_KEYWORDS.IS_V_OUT_AT_MAX_LOAD] = "IsVoutAtMaxLoad"; cfg_keywords[CONFIG_KEYWORDS.I_OUT] = "Iout"; cfg_keywords[CONFIG_KEYWORDS.MAX_TEMP] = "MaxTemp"; cfg_keywords[CONFIG_KEYWORDS.MAX_EQ_R] = "MaxEqR"; cfg_keywords[CONFIG_KEYWORDS.AWG_1] = "Awg1"; cfg_keywords[CONFIG_KEYWORDS.W_FACTOR_1] = "Wfactor1"; cfg_keywords[CONFIG_KEYWORDS.N_1] = "N1"; cfg_keywords[CONFIG_KEYWORDS.N_PER_LAYER_1] = "N_per_layer1"; cfg_keywords[CONFIG_KEYWORDS.PF_1] = "PF1"; cfg_keywords[CONFIG_KEYWORDS.CM_PER_AMP_1] = "CM_Per_Amp1"; cfg_keywords[CONFIG_KEYWORDS.AWG_2] = "Awg2"; cfg_keywords[CONFIG_KEYWORDS.W_FACTOR_2] = "Wfactor2"; cfg_keywords[CONFIG_KEYWORDS.N_2] = "N2"; cfg_keywords[CONFIG_KEYWORDS.N_PER_LAYER_2] = "N_per_layer2"; cfg_keywords[CONFIG_KEYWORDS.CM_PER_AMP_2] = "CM_Per_Amp2"; cfg_keywords[CONFIG_KEYWORDS.H_UNITS] = "H_units"; cfg_keywords[CONFIG_KEYWORDS.TEMP_UNITS] = "Temp_units"; cfg_keywords[CONFIG_KEYWORDS.WEIGHT_UNITS] = "Weight_units"; }
private void Form1_Load(object sender, EventArgs e) { radioButton_V.Select(); label_Vce_Rc.Text = "Vce"; label_VeRe.Text = "Ve"; edit_beta.Text = "150"; trackBar_Beta.LargeChange = 10; trackBar_Beta.Minimum = 10; trackBar_Beta.Maximum = 200; trackBar_Beta.SmallChange = 1; trackBar_Beta.Value = 150; trackBar_Beta.TickFrequency = 10; //trackBar_Beta.TickStyle = TickStyle.None; edit_Vbe.Text = "0.65"; trackBar_Vbe.LargeChange = 100; trackBar_Vbe.Minimum = 600; trackBar_Vbe.Maximum = 1000; trackBar_Vbe.SmallChange = 20; trackBar_Vbe.Value = 650; trackBar_Vbe.TickFrequency = 20; edit_Vcc.Text = "10"; trackBar_Vcc.LargeChange = 10; trackBar_Vcc.SmallChange = 1; trackBar_Vcc.Minimum = 0; trackBar_Vcc.Maximum = 200; trackBar_Vcc.Value = 100; trackBar_Vcc.TickFrequency = 20; edit_Ic.Text = "1"; trackBar_Ic.LargeChange = 500; trackBar_Ic.SmallChange = 100; trackBar_Ic.Minimum = 500; trackBar_Ic.Maximum = 100000; trackBar_Ic.Value = 1000; trackBar_Ic.TickFrequency = 200; edit_Vce_Rc.Text = "5v"; trackBar_Vce_Rc.LargeChange = 10; trackBar_Vce_Rc.SmallChange = 1; trackBar_Vce_Rc.Minimum = 0; trackBar_Vce_Rc.Maximum = 200; trackBar_Vce_Rc.Value = 100; trackBar_Vce_Rc.TickFrequency = 20; edit_VeRe.Text = "1v"; trackBar_Ve_Re.LargeChange = 10; trackBar_Ve_Re.SmallChange = 1; trackBar_Ve_Re.Minimum = 0; trackBar_Ve_Re.Maximum = 50; trackBar_Ve_Re.Value = 10; trackBar_Ve_Re.TickFrequency = 5; bias = new Bias(this); if (validate_beta_calc()) { calculateBias(); } tc = new TransCalc.TransCalc(); SetUnitRadioButtons(); button_saveResults.Enabled = false; radiobutton_mains_US.Select(); radioButton_minimizeRegulation.Select(); }
public void ConvertTextToInput(trans_calc_input_text strin) { common = new trans_calc_input_common(); primary = new trans_calc_input_winding(); if (strin.Vin == "") { throw new Exception("Vin not set"); } common.Vin = double.Parse(strin.Vin, NumberStyles.Float); if (strin.Vin == "120") { common.Freq = 60; } else if (strin.Vin == "220") { common.Freq = 50; } else { throw new Exception($"Unexpected mains voltage: {strin.Vin}, 110 or 220 expected"); } common.IsVoutAtFullLoad = strin.isVoutAtFullLoad; if (strin.Bmax == "" && strin.N1 == "") { throw new Exception("Either Bmax or Primary turns must be set"); } if (strin.Bmax != "") { common.B_max = double.Parse(strin.Bmax, NumberStyles.Float); if (common.B_max < 0.1 || common.B_max > 2) { throw new Exception("Bmax, has to be in the range of 0.1T to 2T"); } } if (strin.permeability != "") { common.permeability = double.Parse(strin.permeability, NumberStyles.Float); if (common.permeability < 1000 || common.permeability > 10000) { throw new Exception("Permeability has to be in the range of 1000 to 10000"); } } if (strin.I_ex != "") { // from mA to A common.I_ex = double.Parse(strin.I_ex, NumberStyles.Float) / 1000; if (common.I_ex < 0.01 || common.I_ex > 2) { throw new Exception("Iex has to be in the range of 10mA to 2A"); } } if (strin.H != "") { common.H = double.Parse(strin.H, NumberStyles.Float); if (tc.H_Units == TransCalc.H_UNITS.OERSTEDS) { common.H = TransCalc.Oe_to_Ampturns(common.H); } else if (tc.H_Units == TransCalc.H_UNITS.AMP_TURNS_IN) { common.H /= 0.0254; } if (common.H < 1 || common.H > 2000) { throw new Exception("Amp t / m has to be in the range of 1 to 2000 Amp-t-m"); } } if (strin.core_L == "" || strin.core_W == "" || strin.core_H == "") { throw new Exception("Core W/H/L not set"); } if (strin.pf != "") { common.pf1 = double.Parse(strin.pf, NumberStyles.Float); if (common.pf1 < 0 || common.pf1 > 1.0) { throw new Exception("pf has to be between 0 and 1"); } } //to m common.Core_L = double.Parse(strin.core_L, NumberStyles.Float) / 100; common.Core_W = double.Parse(strin.core_W, NumberStyles.Float) / 100; common.Core_H = double.Parse(strin.core_H, NumberStyles.Float) / 100; if (common.Core_L < 0.01 || common.Core_L > 0.5) { throw new Exception("Invalid core L"); } if (common.Core_W < 0.01 || common.Core_W > 0.5) { throw new Exception("Invalid core W"); } if (common.Core_H < 0.01 || common.Core_H > 0.5) { throw new Exception("Invalid core H"); } if (strin.Ae_W == "" || strin.Ae_H == "") { throw new Exception("Ae W/H not set"); } //to m common.Ae_W = double.Parse(strin.Ae_W) / 100; if (common.Ae_W < 0.01 || common.Ae_W > 0.5) { throw new Exception("Invalid Ae width"); } common.Ae_H = double.Parse(strin.Ae_H) / 100; if (common.Ae_H < 0.01 || common.Ae_H > 0.5) { throw new Exception("Invalid Ae height"); } if (common.Ae_W > common.Core_W) { throw new Exception("Ae_W > bobbin W"); } if (common.Ae_H > common.Core_H) { throw new Exception("Ae_H > bobbin H"); } if (strin.mpath_H != "" && strin.mpath_W != "") { //cm double Mpath_H = double.Parse(strin.mpath_H, NumberStyles.Float) / 100; double Mpath_W = double.Parse(strin.mpath_W, NumberStyles.Float) / 100; if (Mpath_H < 0.01 || Mpath_H > 0.5) { throw new Exception("Invalid magnetic path value: H"); } if (Mpath_W < 0.01 || Mpath_W > 0.5) { throw new Exception("Invalid magnetic path value: W"); } common.mpath_l_cm = (Mpath_H + Mpath_W) * 2; } if (strin.window_size != "") { // in cm common.WindowSize = double.Parse(strin.window_size, NumberStyles.Float); if (common.WindowSize < 0.1 || common.WindowSize > 50) { throw new Exception("Invalid window size in cm"); } } if (strin.coupling_coeff == "") { throw new Exception("Coupling coefficient not set"); } common.CouplingCoeff = double.Parse(strin.coupling_coeff, NumberStyles.Float); if (common.CouplingCoeff < 0.5 || common.CouplingCoeff > 1.0) { throw new Exception("Coupling coefficient has to be in the range of 0.5 to 1.0"); } if (strin.stackingFactor == "") { throw new Exception("Stacking factor not set"); } common.StackingFactor = double.Parse(strin.stackingFactor, NumberStyles.Float); if (common.StackingFactor < 0.5 || common.StackingFactor > 1.0) { throw new Exception("Stacking factor has to be in the range of 0.5 to 1.0"); } if (strin.insulationThickness != "") { common.InsulationThickness = double.Parse(strin.insulationThickness, NumberStyles.Float); } if (common.WindowSize > 0.0000001) { if (common.InsulationThickness < 0 || common.InsulationThickness > common.WindowSize) { throw new Exception("Insulation thickness in mm cannot exceed window size"); } } if (strin.Vout != "") { common.Vout = double.Parse(strin.Vout, NumberStyles.Float); if (common.Vout < 0.1) { throw new Exception("Invalid Vout value"); } } if (strin.Iout_max != "") { common.Iout_max = double.Parse(strin.Iout_max, NumberStyles.Float); if (common.Iout_max < 0.00000000001) { throw new Exception("Invalid Iout_max value"); } } common.max_temp = double.Parse(strin.maxTemp, NumberStyles.Float); if (!tc.IsTempUnitsC) { common.max_temp = TransCalc.F_to_C(common.max_temp); } if (common.max_temp < 20) { common.max_temp = 20; } if (strin.max_eq_R != "") { common.max_res_R = double.Parse(strin.max_eq_R, NumberStyles.Float); if (common.max_res_R < 1) { throw new Exception("Invalid value of max equivalent R"); } } primary = convertWinding("Primary", strin.awg1, strin.wfactor1, strin.N1, strin.N_per_layer1, strin.ampacity1); if ((strin.N2 != "" || strin.Vout != "")) { secondary = convertWinding("Secondary", strin.awg2, strin.wfactor2, strin.N2, strin.N_per_layer2, strin.ampacity2); processSecondary = true; } else { processSecondary = false; } isMinimizeRegulation = strin.isMinimizeRegulation; }
public TransCalcInput(TransCalc tc) { this.tc = tc; }