Skip to content

Commit

Permalink
[Thermo] Fix calculation of initial density of IdealSolidSolnPhase
Browse files Browse the repository at this point in the history
The density of IdealSolidSolnPhase and BinarySolutionTabulatedThermo objects was
not being computed as part of construction, causing code that interacted with
them using setState/restoreState, such as the 'Solution' constructors in Matlab
and Python, to fail.
  • Loading branch information
speth committed Feb 21, 2019
1 parent 7cf58af commit 77b4679
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 14 deletions.
19 changes: 6 additions & 13 deletions samples/matlab/lithium_ion_battery.m
Original file line number Diff line number Diff line change
Expand Up @@ -48,12 +48,12 @@
S_an = 0.7824; % [m^2] Anode total active material surface area

% Import all Cantera phases
anode = importThermoPhase(inputCTI, 'anode');
cathode = importThermoPhase(inputCTI,'cathode');
elde = importThermoPhase(inputCTI,'electron');
elyt = importThermoPhase(inputCTI,'electrolyte');
anode_interface = importEdge(inputCTI, 'edge_anode_electrolyte', anode, elde, elyt);
cathode_interface = importEdge(inputCTI, 'edge_cathode_electrolyte', cathode, elde, elyt);
anode = Solution(inputCTI, 'anode');
cathode = Solution(inputCTI, 'cathode');
elde = Solution(inputCTI, 'electron');
elyt = Solution(inputCTI, 'electrolyte');
anode_interface = Interface(inputCTI, 'edge_anode_electrolyte', anode, elde, elyt);
cathode_interface = Interface(inputCTI, 'edge_cathode_electrolyte', cathode, elde, elyt);

% Set the temperatures and pressures of all phases
phases = [anode elde elyt cathode];
Expand Down Expand Up @@ -91,13 +91,6 @@
%--------------------------------------------------------------------------
% Helper functions

% This function returns the ThermoPhase class instance from CTI file
function phase = importThermoPhase(inputCTI, name)
doc = XML_Node('doc', inputCTI);
node = findByID(doc, name);
phase = ThermoPhase(node);
end

% This function returns the Cantera calculated anode current (in A)
function anCurr = anode_curr(phi_s,phi_l,X_Li_an,anode,elde,elyt,anode_interface,S_an)

Expand Down
3 changes: 2 additions & 1 deletion src/thermo/IdealSolidSolnPhase.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ void IdealSolidSolnPhase::setDensity(const doublereal rho)
// Unless the input density is exactly equal to the density calculated and
// stored in the State object, we throw an exception. This is because the
// density is NOT an independent variable.
if (rho != density()) {
if (std::abs(rho/density() - 1.0) > 1e-15) {
throw CanteraError("IdealSolidSolnPhase::setDensity",
"Density is not an independent variable");
}
Expand Down Expand Up @@ -365,6 +365,7 @@ bool IdealSolidSolnPhase::addSpecies(shared_ptr<Species> spec)
throw CanteraError("IdealSolidSolnPhase::addSpecies",
"Molar volume not specified for species '{}'", spec->name);
}
calcDensity();
}
return added;
}
Expand Down

0 comments on commit 77b4679

Please sign in to comment.