Skip to content

Commit

Permalink
Fixed battery variable
Browse files Browse the repository at this point in the history
  • Loading branch information
bpjmalone9180 committed Oct 5, 2021
1 parent c6627f1 commit 6ec0d91
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 47 deletions.
24 changes: 12 additions & 12 deletions model/battery_test.mdl
Original file line number Diff line number Diff line change
Expand Up @@ -77,34 +77,34 @@ Element TMS{
Q_O.HeatTransferRate = Q_cool;
}
}
linkPorts("TMS.Q_O","Li_ion_cell.Q_I","Q1");
linkPorts("TMS.Q_O","Li_ion_battery.Q_I","Q1");

//-------------------------------------------------------------------------------------------------
// Component Linkages
//-------------------------------------------------------------------------------------------------
linkPortI( "Li_ion_cell.EP_O", "Cable_Single.EP_I" );
linkPortI( "Li_ion_battery.EP_O", "Cable_Single.EP_I" );
linkPortI( "Cable_Single.EP_O", "CLoad.EP_I" );
// linkPortI( "CableLeft.EP_O", "DeltaDC.EP_I" );
// linkPortI( "DeltaDC.EP_O", "CableRight.EP_I" );
// linkPortI( "CableRight.EP_O", "CLoad.EP_I" );

findSourcesAndPropagate();

solverSequence = { "Cable_Single", "Li_ion_cell", "CLoad", "TMS" };
solverSequence = { "Cable_Single", "Li_ion_battery", "CLoad", "TMS" };

void BFPrintOutput()
{
cout << " Case = " << CASE << endl;
cout << " Battery open circuit voltage = " << Li_ion_cell.Voc << endl;
cout << " Battery output voltage (actual/guess) = " << Li_ion_cell.Vout << "/" << Li_ion_cell.Vout_guess << endl;
cout << " Battery heat balance (Qin/Oout) = " << Li_ion_cell.Q_heat << "/" << Li_ion_cell.Q_I.HeatTransferRate << endl;
// cout << " Battery output Resistance (R_0, R_Th) = " << Li_ion_cell.R_0 << ", " << Li_ion_cell.R_Th << endl;
// cout << " Battery current (calc) = " << (Li_ion_cell.Voc-Li_ion_cell.Vout)/Li_ion_cell.RTotal << endl;
cout << " Battery current/power = " << Li_ion_cell.EP_O.I.r << "/" << Li_ion_cell.EP_O.S.r << endl;
cout << " Battery open circuit voltage = " << Li_ion_battery.Voc << endl;
cout << " Battery output voltage (actual/guess) = " << Li_ion_battery.Vout << "/" << Li_ion_battery.Vout_guess << endl;
cout << " Battery heat balance (Qin/Oout) = " << Li_ion_battery.Q_heat << "/" << Li_ion_battery.Q_I.HeatTransferRate << endl;
// cout << " Battery output Resistance (R_0, R_Th) = " << Li_ion_battery.R_0 << ", " << Li_ion_battery.R_Th << endl;
// cout << " Battery current (calc) = " << (Li_ion_battery.Voc-Li_ion_battery.Vout)/Li_ion_battery.RTotal << endl;
cout << " Battery current/power = " << Li_ion_battery.EP_O.I.r << "/" << Li_ion_battery.EP_O.S.r << endl;
cout << " Load power = " << CLoad.P << endl;
cout << " Number of series cells in battery = " << Li_ion_cell.S_map.num_series << endl;
cout << " Number of parallel cells in battery = " << Li_ion_cell.S_map.num_parallel << endl;
cout << " Battery temperature/temp state (oC) = " << Li_ion_cell.T_batt << "/" << (Li_ion_cell.S_eThermMass.T - 491.67)*5./9. << endl;
cout << " Number of series cells in battery = " << Li_ion_battery.S_map.num_series << endl;
cout << " Number of parallel cells in battery = " << Li_ion_battery.S_map.num_parallel << endl;
cout << " Battery temperature/temp state (oC) = " << Li_ion_battery.T_batt << "/" << (Li_ion_battery.S_eThermMass.T - 491.67)*5./9. << endl;
// cout << " Cable current (output port) = " << Cable_Single.EP_O.I.r << endl;
// cout << " Load input voltage = " << CLoad.EP_I.V.r << endl;
// cout << " Load input power = " << CLoad.EP_I.S.r << endl;
Expand Down
70 changes: 35 additions & 35 deletions run/battery_test.run
Original file line number Diff line number Diff line change
Expand Up @@ -82,12 +82,12 @@ run(); // do another steady-state run just to initialize us.
TMS.R_cool = 0;

// Also start out the temperature at 22 C to match the data
Li_ion_cell.T_batt = 22;
Li_ion_cell.S_eThermMass.T = 22. * 9./5. + 491.67; // 22 C converted to R
Li_ion_battery.T_batt = 22;
Li_ion_battery.S_eThermMass.T = 22. * 9./5. + 491.67; // 22 C converted to R

// Turn on integrator for battery SOC
Li_ion_cell.ind_SOC.autoSetup = TRUE;
Li_ion_cell.integ_SOC.autoSetup = TRUE;
Li_ion_battery.ind_SOC.autoSetup = TRUE;
Li_ion_battery.integ_SOC.autoSetup = TRUE;

setOption("switchDes","OFFDESIGN");
setOption("solutionMode", "TRANSIENT");
Expand All @@ -107,46 +107,46 @@ cout << "Transient Solver Vars = " << endl << solver.dependentNames << endl << s
OutFileStream transientCSVStream { filename = "output/batt_transient.csv"; }

// Write the CSV headers
transientCSVStream << "Li_ion_cell.Voc,";
transientCSVStream << "Li_ion_cell.Vout,";
transientCSVStream << "Li_ion_cell.Q_heat,";
transientCSVStream << "Li_ion_cell.R_0,";
transientCSVStream << "Li_ion_cell.R_Th,";
transientCSVStream << "Li_ion_cell.EP_O.I.r,";
transientCSVStream << "Li_ion_cell.EP_O.S.r,";
transientCSVStream << "Li_ion_cell.T_batt,";
transientCSVStream << "Li_ion_cell.S_eThermMass.T,";
transientCSVStream << "Li_ion_cell.SOC,";
transientCSVStream << "Li_ion_cell.dSOCqdt,";
transientCSVStream << "Li_ion_cell.C_rate,";
transientCSVStream << "Li_ion_battery.Voc,";
transientCSVStream << "Li_ion_battery.Vout,";
transientCSVStream << "Li_ion_battery.Q_heat,";
transientCSVStream << "Li_ion_battery.R_0,";
transientCSVStream << "Li_ion_battery.R_Th,";
transientCSVStream << "Li_ion_battery.EP_O.I.r,";
transientCSVStream << "Li_ion_battery.EP_O.S.r,";
transientCSVStream << "Li_ion_battery.T_batt,";
transientCSVStream << "Li_ion_battery.S_eThermMass.T,";
transientCSVStream << "Li_ion_battery.SOC,";
transientCSVStream << "Li_ion_battery.dSOCqdt,";
transientCSVStream << "Li_ion_battery.C_rate,";
transientCSVStream << "time" << endl;

// Use a variable to print only every 100 timesteps.
real time_old = 0;
void csvTransientPrint()
{
transientCSVStream << Li_ion_cell.Voc << ", ";
transientCSVStream << Li_ion_cell.Vout << ", ";
transientCSVStream << Li_ion_cell.Q_heat << ", ";
transientCSVStream << Li_ion_cell.R_0 << ", ";
transientCSVStream << Li_ion_cell.R_Th << ", ";
transientCSVStream << Li_ion_cell.EP_O.I.r << ", ";
transientCSVStream << Li_ion_cell.EP_O.S.r << ", ";
transientCSVStream << Li_ion_cell.T_batt << ", ";
transientCSVStream << Li_ion_cell.S_eThermMass.T << ", ";
transientCSVStream << Li_ion_cell.SOC << ", ";
transientCSVStream << Li_ion_cell.dSOCqdt << ", ";
transientCSVStream << Li_ion_cell.C_rate << ", ";
transientCSVStream << Li_ion_battery.Voc << ", ";
transientCSVStream << Li_ion_battery.Vout << ", ";
transientCSVStream << Li_ion_battery.Q_heat << ", ";
transientCSVStream << Li_ion_battery.R_0 << ", ";
transientCSVStream << Li_ion_battery.R_Th << ", ";
transientCSVStream << Li_ion_battery.EP_O.I.r << ", ";
transientCSVStream << Li_ion_battery.EP_O.S.r << ", ";
transientCSVStream << Li_ion_battery.T_batt << ", ";
transientCSVStream << Li_ion_battery.S_eThermMass.T << ", ";
transientCSVStream << Li_ion_battery.SOC << ", ";
transientCSVStream << Li_ion_battery.dSOCqdt << ", ";
transientCSVStream << Li_ion_battery.C_rate << ", ";
transientCSVStream << time << endl;

if (time-time_old >= 300)
{
cout << "T_batt (oC), " << Li_ion_cell.T_batt << ", ";
//cout << "HeatRate (BTU/s), " << Li_ion_cell.Q_heat << ", ";
cout << "BattCurrent (A), " << Li_ion_cell.EP_O.I.r << ", ";
cout << "BattSOC, " << Li_ion_cell.SOC << ", ";
cout << "BattVoltage (V), " << Li_ion_cell.EP_O.V.r << ", ";
cout << "C-rate, " << Li_ion_cell.C_rate << ", ";
cout << "T_batt (oC), " << Li_ion_battery.T_batt << ", ";
//cout << "HeatRate (BTU/s), " << Li_ion_battery.Q_heat << ", ";
cout << "BattCurrent (A), " << Li_ion_battery.EP_O.I.r << ", ";
cout << "BattSOC, " << Li_ion_battery.SOC << ", ";
cout << "BattVoltage (V), " << Li_ion_battery.EP_O.V.r << ", ";
cout << "C-rate, " << Li_ion_battery.C_rate << ", ";
cout << "CASE, " << CASE << ", ";
cout << "time (s), " << time << endl;
time_old = time;
Expand All @@ -168,7 +168,7 @@ void transient_profile() {
else if ( time < 6600 ){ CLoad.Pdemand = 0.;}

// Stop if battery gets fully drained (or close to it)
if (Li_ion_cell.SOC <= 0.01) {
if (Li_ion_battery.SOC <= 0.01) {
// quit();
}
}
Expand Down

0 comments on commit 6ec0d91

Please sign in to comment.