Source: chemistry/SolventSolutionModeler.js

/**
 * This module manages the solvent configuration for solution calculations.
 * It determines how solvent properties are calculated and where they come from.
 * 
 * @module SolventSolutionModeler
 * @description Defines the solvent model to use in solution calculations and
 * provides methods to retrieve solvent properties (density, molecular weight, 
 * specific heat).
 * 
 * Three solvent models are supported:
 * 
 * 1. WATER/AQUEOUS (0, Default):
 *    - Uses water constants defined in Constants
 *    - Density from Constants.DENSITY_OF_WATER
 *    - Molecular weight from Constants.MW_OF_WATER
 *    - Specific heat from Constants.CP_OF_WATER
 * 
 * 2. NONWATER/NONAQUEOUS (1):
 *    - Uses properties of the specie with id=0 from KnowledgeBase
 *    - Density from specie.getDensity()
 *    - Molecular weight from specie.getMolecularWeight()
 *    - Specific heat from specie.getCp()
 * 
 * 3. UNDEFINED/NOSOLVENT (2):
 *    - Assumes no specific solvent in the system
 *    - Calculations are based on the mixture of species
 *    - Requires SolventConcentrationModel (solventConcentration parameter in solutionModellers in configuration.json) to be set as SOLVENTFINITE
 *    - Automatically switches to NONWATER if SolventConcentrationModel is SOLVENTINFINITE
 *    - Property methods should not be called when using this model
 * 
 * @property {number} DEFAULT - The default model (0)
 * @property {number} WATER/AQUEOUS - Uses water constants (0)
 * @property {number} NONWATER/NONAQUEOUS - Uses properties of specie with id=0 (1)
 * @property {number} UNDEFINED/NOSOLVENT - No specific solvent (2)
 * @property {number} simulationModel - The currently active simulation model
 * 
 * @singleton
 */
define([
    './SolventConcentrationSolutionModeler',
    './KnowledgeBase',
    './Constants'
], function (SolventConcentrationSolutionModeler, KnowledgeBase, Constants) {
    var instance = null;
    function SolventSolutionModeler () {
        // The default model used when no other model is selected
        this.DEFAULT = 0;

        // The WATER model assumes that water is the solvent. The properties are
        // then taken from the Constants class.
        this.WATER = 0;
        this.AQUEOUS = 0;

        // The NONWATER model assumes the solvent is not necessarily water. The
        // properties of the solvent are taken from the specie with id=0.
        this.NONWATER = 1;
        this.NONAQUEOUS = 1;

        // The NOSOLVENT model assumes that there's not a specific solvent in the
        // system. All the calculations are then done from the mixture of species.
        //
        // This model requires the SolventConcentrationModel to be set as
        // SOLVENTFINITE. If not, the model switches to NOWATER.
        this.UNDEFINED = 2;
        this.NOSOLVENT = 2;

        // Stores the simulation model being used
        this.simulationModel = this.DEFAULT;
    };

    /**
     * Resets the default status
     */
    SolventSolutionModeler.prototype.setDefault = function () {
        this.simulationModel = this.DEFAULT;
    };

    /**
     * Gets the simulation model used
     * @returns {*} An integer representing the simulation model
     */
    SolventSolutionModeler.prototype.getSimulationModel = function () {
        var effectiveModel = this.simulationModel;

        if (effectiveModel === this.NOSOLVENT
            && SolventConcentrationSolutionModeler.simulationModel === SolventConcentrationSolutionModeler.SOLVENTINFINITE) {
            effectiveModel = this.NONWATER;
        }

        return effectiveModel;
    };

    /**
     * Gets the density of the solvent
     * @returns {number}
     */
    SolventSolutionModeler.prototype.getSolventDensity = function () {
        var density = 0.0;

        if (this.simulationModel === this.NONWATER) {
            density = KnowledgeBase.getSpecies(0).getDensity();
        }
        else if (this.simulationModel === this.WATER) {
            density = Constants.DENSITY_OF_WATER;
        }
        else if (this.simulationModel === this.NOSOLVENT) {
            // Shouldn't be called if the model is no solvent
        }
        return density;
    };

    /**
     * Gets the molecular weight of the solvent
     * @returns {number}
     */
    SolventSolutionModeler.prototype.getSolventMW = function () {
        var mW = 0.0;

        if (this.simulationModel === this.NONWATER) {
            mW = KnowledgeBase.getSpecies(0).getMolecularWeight();
        }
        else if (this.simulationModel === this.WATER) {
            mW = Constants.MW_OF_WATER;
        }
        else if (this.simulationModel === this.NOSOLVENT) {
            // Shouldn't be called if the model is no solvent
        }

        return mW;
    };

    /**
     * Gets the specific heat of the solvent
     * @returns {number}
     */
    SolventSolutionModeler.prototype.getSolventSpecificHeat = function () {
        var cP = 0.0;

        if (this.simulationModel === this.NONWATER) {
            cP = KnowledgeBase.getSpecies(0).getCp();
        }
        else if (this.simulationModel === this.WATER) {
            cP = Constants.CP_OF_WATER;
        }
        else if (this.simulationModel === this.NOSOLVENT) {
            // Shouldn't be called if the model is no solvent
        }

        return cP;
    };

    /**
     * Load the characteristics of the model from the problem file
     * @param model value of solutionModellers.solvent from configuration
     */
    SolventSolutionModeler.prototype.loadProperties = function(model) {
        if (model.toUpperCase() === "WATER" || model.toUpperCase() === "AQUEOUS")
            this.simulationModel = this.AQUEOUS;
        else if (model.toUpperCase() === "NONWATER" || model.toUpperCase() === "NONAQUEOUS")
            this.simulationModel = this.NONAQUEOUS;
        else if (model.toUpperCase() === "NOSOLVENT" || model.toUpperCase() === "UNDEFINED")
            this.simulationModel = this.UNDEFINED;
    };

    SolventSolutionModeler.getInstance = function() {
        if(instance === null) {
            instance = new SolventSolutionModeler();
        }
        return instance;
    };
    return SolventSolutionModeler.getInstance();
});