Page MenuHomec4science

data_container.cpp
No OneTemporary

File Metadata

Created
Thu, Oct 10, 05:56

data_container.cpp

/*-------------------------------------------------------------------------------
Copyright (c) 2014,2015 F. 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:
1. Redistributions of source code must retain the above copyright notice, this
list of conditions and the following disclaimer.
2. 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.
3. Neither the name of the copyright holder 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 HOLDER 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"
#include "errors.hpp"
namespace specmicp {
namespace database {
const std::string water_label{"H2O"}; //!< The water label in the database
const std::string electron_label{"E[-]"}; //!< The electron label in the database
scalar_t DataContainer::molar_volume_mineral(index_t m, units::LengthUnit length_unit) const
{
const auto& molar_volume = minerals.molar_volume(m);
if (molar_volume < 0) {
throw db_noninitialized_value("molar volume", minerals.get_label(m));
}
return scaling_molar_volume(length_unit)*molar_volume;
}
scalar_t DataContainer::scaling_molar_volume(units::LengthUnit length_unit) const
{
scalar_t scaling = 1.0;
if (length_unit == units::LengthUnit::meter)
scaling = 1e-6;
else if (length_unit == units::LengthUnit::decimeter)
scaling = 1e-3;
return scaling;
}
//! \brief Return the molar volume (m^3/mol) of a mineral
scalar_t DataContainer::molar_volume_mineral(index_t m) const
{
const auto& molar_volume = minerals.molar_volume(m);
if (molar_volume < 0) {
throw db_noninitialized_value("molar volume", minerals.get_label(m));
}
return 1e-6*molar_volume;
}
//! \brief Return the molar volume (m^3/mol) of a mineral governed by kinetic
scalar_t DataContainer::molar_volume_mineral_kinetic(index_t m) const
{
const auto& molar_volume = minerals_kinetic.molar_volume(m);
if (molar_volume < 0) {
throw db_noninitialized_value("molar volume", minerals_kinetic.get_label(m));
}
return 1e-6*molar_volume;
}
//! Return the molar mass of 'component' in 'mass_unit'/mol
scalar_t DataContainer::molar_mass_basis(index_t component, units::MassUnit mass_unit) const NOEXCEPT
{
scalar_t scaling = 1.0;
if (mass_unit == units::MassUnit::kilogram) scaling=1e-3;
return molar_mass_basis(component)*scaling;
}
//! \brief Return the molar mass (kg/mol) of a mineral
scalar_t DataContainer::molar_mass_mineral(index_t mineral) const {
return 1e-3*components.molar_mass_compounds(minerals.get_nu_row(mineral));
}
//! \brief Return the molar mass (kg/mol) of a mineral governed by kinetic
scalar_t DataContainer::molar_mass_mineral_kinetic(index_t mineral) const {
return 1e-3*components.molar_mass_compounds(minerals_kinetic.get_nu_row(mineral));
}
//! Return the molar mass of 'mineral' in 'mass_unit'/mol
scalar_t DataContainer::molar_mass_mineral(index_t mineral, units::MassUnit mass_unit) const
{
scalar_t scaling = 1.0;
if (mass_unit == units::MassUnit::kilogram) scaling=1e-3;
return scaling*components.molar_mass_compounds(minerals.get_nu_row(mineral));
}
//! 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) const
{
scalar_t scaling = 1.0;
if (mass_unit == units::MassUnit::kilogram) scaling=1e-3;
return scaling*components.molar_mass_compounds(minerals_kinetic.get_nu_row(mineral_kinetic));
}
bool DataContainer::is_valid()
{
return (components.is_valid()
and aqueous.is_valid()
and minerals.is_valid()
and minerals_kinetic.is_valid()
and gas.is_valid()
and sorbed.is_valid()
);
}
} // end namespace database
} // end namespace specmicp

Event Timeline