Page MenuHomec4science

data_container.cpp
No OneTemporary

File Metadata

Created
Sun, Jun 23, 04:45

data_container.cpp

/*-------------------------------------------------------
- Module : database
- File : data_container.cpp
- Author : Fabien Georget
Copyright (c) 2014, Fabien Georget <fabieng@princeton.edu>, Princeton University
All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:
* Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above copyright
notice, this list of conditions and the following disclaimer in the
documentation and/or other materials provided with the distribution.
* Neither the name of the Princeton University nor the
names of its contributors may be used to endorse or promote products
derived from this software without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
---------------------------------------------------------*/
#include "data_container.hpp"
namespace specmicp {
namespace database {
//! \brief Return the molar mass (kg/mol) of a mineral
scalar_t DataContainer::molar_mass_mineral(index_t m) {
return 1e-3*nu_mineral.row(m).dot(_molar_mass_basis);
}
//! \brief Return the molar mass (kg/mol) of a mineral governed by kinetic
scalar_t DataContainer::molar_mass_mineral_kinetic(index_t m) {
return 1e-3*nu_mineral_kinetic.row(m).dot(_molar_mass_basis);
}
scalar_t DataContainer::molar_volume_mineral(index_t m, units::LengthUnit length_unit)
{
if (_molar_volume_mineral(m) < 0) {
throw db_noninitialized_value("molar volume", labels_minerals[m]);}
if (length_unit == units::LengthUnit::meter)
return 1e-6*_molar_volume_mineral(m);
else if (length_unit == units::LengthUnit::decimeter)
return 1e-3*_molar_volume_mineral(m);
else // cemtimeter
return _molar_volume_mineral(m);
}
//! \brief Return the molar volume (m^3/mol) of a mineral
scalar_t DataContainer::molar_volume_mineral(index_t m)
{
if (_molar_volume_mineral(m) < 0) {
throw db_noninitialized_value("molar volume", labels_minerals[m]);}
return 1e-6*_molar_volume_mineral(m);
}
//! \brief Return the molar volume (m^3/mol) of a mineral governed by kinetic
scalar_t DataContainer::molar_volume_mineral_kinetic(index_t m)
{
if (_molar_volume_mineral_kinetic(m) < 0) {
throw db_noninitialized_value("molar volume", labels_minerals_kinetic[m]);}
return 1e-6*_molar_volume_mineral_kinetic(m);
}
//! Return the molar mass of 'component' in 'mass_unit'/mol
scalar_t DataContainer::molar_mass_basis(index_t component, units::MassUnit mass_unit)
{
scalar_t scaling = 1.0;
if (mass_unit == units::MassUnit::kilogram) scaling=1e-3;
return molar_mass_basis(component)*scaling;
}
//! Return the molar mass of 'mineral' in 'mass_unit'/mol
scalar_t DataContainer::molar_mass_mineral(index_t mineral, units::MassUnit mass_unit)
{
scalar_t scaling = 1.0;
if (mass_unit == units::MassUnit::kilogram) scaling=1e-3;
return scaling*nu_mineral.row(mineral).dot(_molar_mass_basis);;
}
//! Return the molar mass of 'mineral_kinetic' in 'mass_unit'/mol
scalar_t DataContainer::molar_mass_mineral_kinetic(index_t mineral_kinetic, units::MassUnit mass_unit)
{
scalar_t scaling = 1.0;
if (mass_unit == units::MassUnit::kilogram) scaling=1e-3;
return scaling*nu_mineral_kinetic.row(mineral_kinetic).dot(_molar_mass_basis);;
}
} // end namespace database
} // end namespace specmicp

Event Timeline