Page MenuHomec4science

data_container.hpp
No OneTemporary

File Metadata

Created
Mon, Jun 24, 09:31

data_container.hpp

/*-------------------------------------------------------
- Module : database
- File : data_container.hpp
- 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.
---------------------------------------------------------*/
#ifndef SPECMICP_DATABASE_DATACONTAINER_HPP
#define SPECMICP_DATABASE_DATACONTAINER_HPP
//! \file data_container.hpp Storage class for thermodynamics database
#include "common_def.hpp"
#include <map>
#include "boost/range/irange.hpp"
#include "physics/units.hpp"
namespace specmicp {
namespace database {
//! \brief Storage class - Contains the database
//!
//! - Should not be accessed directly but through interfaces
//! Correct interfaces are subclasses of DatabaseModule
//! - Should be shared with a smart pointer
struct DataContainer
{
DataContainer():
is_canonical(false)
{}
// Basis
// ------
index_t nb_component; //!< Number of components == size of the basis
vector_labels_t labels_basis; //!< labels of the components
std::map<std::string, index_t> map_labels_basis; //!< map labels <-> id
data_vector_t _molar_mass_basis; //!< molar mass of the basis // (g/mol)
//! \brief Return the molar mass of 'component' in g/mol
scalar_t molar_mass_basis(index_t component) {return _molar_mass_basis(component);}
//! \brief Return the molar mass of 'component' in kg/mol
scalar_t molar_mass_basis_si(index_t component) {return 1e-3*molar_mass_basis(component);}
//! \brief Return the molar mass of 'component' in 'mass_unit'/mol
scalar_t molar_mass_basis(index_t component, units::MassUnit mass_unit);
Eigen::Matrix<scalar_t, Eigen::Dynamic, 3> param_aq; //!< Aqueous parameters (both for basis and secondary species)
//! Return the charge of a component
scalar_t& charge_component(index_t i) {return param_aq(i, 0);}
//! Return the 'a_i' Debye-Huckel parameter for a component
scalar_t& a_debye_component(index_t i) {return param_aq(i, 1);}
//! Return the 'b_i' extended Debye-Huckel parameter for a component
scalar_t& b_debye_component(index_t i) {return param_aq(i, 2);}
// Secondary aqueous species
// -------------------------
index_t nb_aqueous; //!< Number of aqueous species (not taking into acount the basis)
vector_labels_t labels_aqueous; //!< labels of the aqueous species
reaction_mat_t nu_aqueous; //!< Stoechiometric coefficient for aqueous species
logK_vector_t logk_aqueous; //!< LogK for aqueous species
//! Return the charge of a secondary aqueous species
scalar_t& charge_aqueous(index_t j) {return param_aq(j+nb_component, 0);}
//! Return the 'a_i' Debye-Huckel parameter for a secondary aqueous species
scalar_t& a_debye_aqueous(index_t j) {return param_aq(j+nb_component, 1);}
//! Return the 'b_i' extended Debye-Huckel parameter for a secondary aqueous species
scalar_t& b_debye_aqueous(index_t j) {return param_aq(j+nb_component, 2);}
// Minerals
// ---------
index_t nb_mineral; //!< Number of minerals (used in computation)
vector_labels_t labels_minerals; //!< labels of the minerals
reaction_mat_t nu_mineral; //!< Stoichiometric coefficient for minerals
logK_vector_t logk_mineral; //!< LogK for minerals
data_vector_t _molar_volume_mineral; //!< molar volume of mineral (cm3/mol)
list_stability_t _stability_mineral; //!< Stability of a mineral
MineralStabilityClass stability_mineral(index_t m) const {return _stability_mineral[m];}
MineralStabilityClass& stability_mineral(index_t m) {return _stability_mineral[m];}
index_t nb_mineral_kinetic; //!< Number of minerals (governed by kinetics)
vector_labels_t labels_minerals_kinetic; //!< labels of the minerals (governed by kinetics)
reaction_mat_t nu_mineral_kinetic; //!< Stoichiometric coefficient for minerals (governed by kinetics)
logK_vector_t logk_mineral_kinetic; //!< LogK for minerals (governed by kinetics)
data_vector_t _molar_volume_mineral_kinetic; //!< molar volume of mineral (cm3/mol)
// Gas
// ----
index_t nb_gas; //!< Number of gas
vector_labels_t labels_gas; //!< labels of the gas phase
reaction_mat_t nu_gas; //!< Stoichiometric coefficient for the gas
logK_vector_t logk_gas; //!< log(K) gas
// Ranges
// ------
//! \brief Range over the components
range_t range_component() { return boost::irange((index_t) 0, nb_component);}
//! \brief Range over the aqueous components
range_t range_aqueous_component() { return boost::irange((index_t) 1, nb_component);}
//! \brief Range over the secondary aqueous species
range_t range_aqueous() { return boost::irange((index_t) 0, nb_aqueous);}
//! \brief Range over the solid phases (at equilibrium)
range_t range_mineral() { return boost::irange((index_t) 0, nb_mineral);}
//! \brief Range over the solid phases governed by equilibrium
range_t range_mineral_kinetic() { return boost::irange((index_t) 0, nb_mineral_kinetic);}
//! \brief Range over the gas phases
range_t range_gas() { return boost::irange((index_t) 0, nb_gas);}
// Status
// ------
bool is_canonical; //!< true if the database is in canonical form
// Computed variables
// ------------------
// The following functions are provided for convenience
// They provide variables computed from the main data
//! \brief Return the molar mass (kg/mol) of a mineral
scalar_t molar_mass_mineral(index_t m);
//! \brief Return the molar mass (kg/mol) of a mineral governed by kinetic
scalar_t molar_mass_mineral_kinetic(index_t m);
//! \brief Return the molar mass of 'mineral' in 'mass_uinit'/mol
scalar_t molar_mass_mineral(index_t mineral, units::MassUnit mass_unit);
//! \brief Return the molar mass of 'mineral_kinetic' in 'mass_uinit'/mol
scalar_t molar_mass_mineral_kinetic(index_t mineral_kinetic, units::MassUnit mass_unit);
//! \brief Return the molar volume (m^3/mol) of a mineral
scalar_t molar_volume_mineral(index_t m);
//! \brief Return the molar volume (m^3/mol) of a mineral governed by kinetic
scalar_t molar_volume_mineral_kinetic(index_t m);
//! \brief Return the molar volume of a mineral in mol/(length_unit)^3
scalar_t molar_volume_mineral(index_t m, units::LengthUnit length_unit);
};
} // end namespace database
} // end namespace specmicp
#include <memory>
namespace specmicp {
namespace database {
//! \brief Pointer to a database
//!
//! This is a smart pointer so we don't have to worry about memory leaks.
//! It is intented to be shared between all the modules that needs it.
using RawDatabasePtr = std::shared_ptr<DataContainer>;
} // end namespace database
} // end namespace specmicp
#endif // SPECMICP_DATABASE_DATACONTAINER_HPP

Event Timeline