/**
* This class models the boiling point for a solution
* @module
*/
define([
'./Constants',
'./SolventSolutionModeler',
'./SpecieState',
'./SolventConcentrationSolutionModeler'
], function (Constants, SolventSolutionModeler, SpecieState, SolventConcentrationSolutionModeler) {
var instance = null;
/**
* Models the boiling point of a solution
* @class
*/
function BoilingPointSolutionModeler () {
// Boiling point of the solvent in K
this.boilingPointSolvent = Constants.BOILING_POINT_OF_WATER;
// Elevation constant of the solvent in K kg/mol
this.elevationConstantSolvent = Constants.BOILING_ELEVATION_CONST_WATER;
// The default model when no other model is selected
this.DEFAULT = 0;
// The NOMINALBOILING model assumes that all the solutions behave as pure
// solvent. Boiling point must be specified or water is assumed.
this.NOMINALBOILING = 0;
// The EVALUATEDBOILING model considers that is the solvent and all the
// finite solutes affects the boiling point according to their molality.
//
// All species with infinite amount are assumed ficticious and with no effect.
this.EVALUATEDBOILING = 1;
// Stores the simulation model being used
this.simulationModel = this.DEFAULT;
};
/**
* Returns the boiling point for the solution
* @param s The solution
* @returns {number} The boiling point in K
*/
BoilingPointSolutionModeler.prototype.getValue = function (s) {
// in K
var boilingPoint = 0.0;
// NOMINAL
if (this.simulationModel === this.NOMINALBOILING) {
if (SolventSolutionModeler.simulationModel === SolventSolutionModeler.AQUEOUS) {
boilingPoint = Constants.BOILING_POINT_OF_WATER;
}
else {
boilingPoint = this.boilingPointSolvent;
}
}
// EVALUATED
else if (this.simulationModel === this.EVALUATEDBOILING) {
// calculate number of moles of solutes
var molsSolute = 0.0;
// start in 1 to avoid solvent
var i;
for (i = 1; i < s.getSpeciesCount(); i++) {
var sn = s.getSpeciesAt(i);
if (sn.archetype.state !== SpecieState.SOLID
&& sn.archetype.state !== SpecieState.GAS && !sn.infinite) {
molsSolute += sn.moles;
}
}
// calculate the mass of solvent
var weightSolvent = 0.0;
// SOLVENTINFINITE
if (SolventConcentrationSolutionModeler.simulationModel === SolventConcentrationSolutionModeler.SOLVENTINFINITE) {
// Weight of solvent
weightSolvent = s.liquidVolume * 1000
* SolventSolutionModeler.getSolventDensity();
// subtract the mass for the mols of water replaced
var weightWaterReplaced = 0;
for (i = 0; i < s.getSpeciesCount(); i++) {
var sn = s.getSpeciesAt(i);
if (sn.archetype.state !== SpecieState.SOLID) {
weightWaterReplaced += sn.getWaterReplaced()
* SolventSolutionModeler.getSolventMW();
}
}
if (weightWaterReplaced !== 0) {
weightSolvent -= weightWaterReplaced;
}
// so the weight of solvent is...
weightSolvent = (weightSolvent < 0) ? 0 : weightSolvent;
}
// SOLVENTFINITE
else if (SolventConcentrationSolutionModeler.simulationModel === SolventConcentrationSolutionModeler.SOLVENTFINITE) {
var solvent = s.getSpeciesAt(0);
if (solvent !== null) {
weightSolvent = solvent.getWeight();
}
}
if (SolventSolutionModeler.getSimulationModel() === SolventSolutionModeler.AQUEOUS) {
boilingPoint = Constants.BOILING_POINT_OF_WATER
+ Constants.BOILING_ELEVATION_CONST_WATER * 1000
* molsSolute / weightSolvent;
}
else if (SolventSolutionModeler.getSimulationModel() === SolventSolutionModeler.NONAQUEOUS) {
boilingPoint = this.boilingPointSolvent + this.elevationConstantSolvent
* 1000 * molsSolute / weightSolvent;
}
else if (SolventSolutionModeler.getSimulationModel() === SolventSolutionModeler.NOSOLVENT) {
boilingPoint = this.boilingPointSolvent;
}
}
return boilingPoint;
};
/**
* Resets the default status
*/
BoilingPointSolutionModeler.prototype.setDefault = function () {
this.simulationModel = this.DEFAULT;
};
/**
* Load the characteristics of the model from the problem file
* @param model
* @param boilingPointSolvent
* @param elevationConstantSolvent
*/
BoilingPointSolutionModeler.prototype.loadProperties = function(model, boilingPointSolvent, elevationConstantSolvent) {
if (model.toUpperCase() === "NOMINAL")
this.simulationModel = this.NOMINALBOILING;
else if (model.toUpperCase() === "EVALUATED")
this.simulationModel = this.EVALUATEDBOILING;
var value = 0.0;
// boiling point in K
if (boilingPointSolvent !== null) {
value = parseFloat(boilingPointSolvent)
if (!isNaN(value))
this.boilingPointSolvent = value;
}
// elevation constant in K kg/mol
if (elevationConstantSolvent !== null) {
value = parseFloat(elevationConstantSolvent);
if (!isNaN(value))
this.elevationConstantSolvent = value;
}
};
BoilingPointSolutionModeler.getInstance = function() {
if(instance === null) {
instance = new BoilingPointSolutionModeler();
}
return instance;
};
return BoilingPointSolutionModeler.getInstance();
});