[Thermo] Fix calculation of initial density of IdealSolidSolnPhase

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.
This commit is contained in:
Ray Speth 2019-02-20 19:33:18 -05:00
parent 7cf58af69e
commit 77b467929c
2 changed files with 8 additions and 14 deletions

View file

@ -48,12 +48,12 @@ S_ca = 1.1167; % [m^2] Cathode total active material surface area
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];
@ -91,13 +91,6 @@ set(gca,'fontsize',14)
%--------------------------------------------------------------------------
% 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)

View file

@ -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");
}
@ -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;
}