diff --git a/src/database/aqueous_selector.hpp b/src/database/aqueous_selector.hpp index 6eea25a..6313992 100644 --- a/src/database/aqueous_selector.hpp +++ b/src/database/aqueous_selector.hpp @@ -1,61 +1,67 @@ /*------------------------------------------------------------------------------- Copyright (c) 2014,2015 F. Georget , 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. -----------------------------------------------------------------------------*/ #ifndef SPECMICP_DATABASE_AQUEOUSSELECTOR_HPP #define SPECMICP_DATABASE_AQUEOUSSELECTOR_HPP -//! \file mineral_selector.hpp select minerals in the database +//! \file aqueous_selector.hpp +//! \brief Select aqueous in the database #include "module.hpp" namespace specmicp { namespace database { -//! \brief Select equilibrum minerals in the database +//! \class AqueousSelector +//! \brief Select aqueous in the database //! -//! Keep only the solid phases that the user wants +//! Remove aqueous species from the database. +//! This should not be used normally but may be necessary in +//! artificial problem. (e.g. the MoMas benchmark) class AqueousSelector: public DatabaseModule { public: AqueousSelector(RawDatabasePtr thedata): DatabaseModule(thedata) {} //! \brief Remove some specific aqueous species + //! + //! \param id_aqueous vector containing the if of the species to remove void remove_aqueous(const std::vector& id_aqueous); }; } // end namespace database } // end namespace specmicp -#endif // SPECMICP_DATABASE_MINERALSELECTOR_HPP +#endif // SPECMICP_DATABASE_AQUEOUSSELECTOR_HPP diff --git a/src/database/data_container.hpp b/src/database/data_container.hpp index 7f2a379..6e72182 100644 --- a/src/database/data_container.hpp +++ b/src/database/data_container.hpp @@ -1,329 +1,329 @@ /*------------------------------------------------------------------------------- Copyright (c) 2014,2015 F. Georget , 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. -----------------------------------------------------------------------------*/ #ifndef SPECMICP_DATABASE_DATACONTAINER_HPP #define SPECMICP_DATABASE_DATACONTAINER_HPP //! \file data_container.hpp //! \brief Storage class for the thermodynamics database -//! -//! This class is supposed to be share by every thing else in specmicp #include "common.hpp" #include "physics/units.hpp" #include "species/component_list.hpp" #include "species/aqueous_list.hpp" #include "species/mineral_list.hpp" #include "species/gas_list.hpp" #include "species/sorbed_list.hpp" namespace specmicp { namespace database { extern const std::string water_label; //!< The water label in the database constexpr index_t water_id{0}; //!< Index of water in the database extern const std::string electron_label; //!< The electron label in the database constexpr index_t electron_id{1}; //!< Index of the electron in the 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 +//! The database is shared by (almost) everything else using a shared_ptr. +//! This class is only a container. It should not be modified by hand but +//! using the algorithms provided by specimicp::database::Database. +//! +//! \sa specimicp::database::Database struct DataContainer { //! \name Basis //! \brief The basis contains the components // ========================================== //! @{ ComponentList components; //!< The basis //! \brief Return the number of components in the basis index_t nb_component() const {return components.size();} //! \brief Return the number of all aqueous components, not including water and electron index_t nb_aqueous_components() const noexcept {return nb_component()-2;} //! \brief Return the id of component 'label' //! //! Return no_species if the component does not exist index_t get_id_component(const std::string& label) const { return components.get_id(label); } //! \brief Return the id of component 'label' std::string get_label_component(index_t id) const{ return components.get_label(id); } //! \brief Return the molar mass of 'component' in g/mol scalar_t molar_mass_basis(index_t component) const NOEXCEPT {return components.molar_mass(component);} //! \brief Return the molar mass of 'component' in kg/mol scalar_t molar_mass_basis_si(index_t component) const NOEXCEPT {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) const NOEXCEPT; //! \brief Return the charge of a component const scalar_t& charge_component(index_t i) const NOEXCEPT {return components.charge(i);} //! \brief Return the 'a_i' Debye-Huckel parameter for a component const scalar_t& a_debye_component(index_t i) const NOEXCEPT {return components.a_debye(i);} //! \brief Return the 'b_i' extended Debye-Huckel parameter for a component const scalar_t& b_debye_component(index_t i) const NOEXCEPT {return components.b_debye(i);} //! \brief Return the index of the water in the basis constexpr static index_t water_index() noexcept { return water_id; } //! \brief return the index of the electron in the basis constexpr static index_t electron_index() noexcept { return electron_id; } //! \brief Range over the components range_t range_component() const { return components.range();} //! \brief Range over the aqueous components range_t range_aqueous_component() const { return boost::irange(static_cast(2), nb_component());} //! @} //! \name Secondary aqueous species //! \brief The secondary aqueous species // ========================================= //! @{ AqueousList aqueous; //!< The list of aqueous species //! \brief Return the number of aqueous species in the system (not counting components) index_t nb_aqueous() const {return aqueous.size();} //! \brief Return the stoichiometric coefficient of 'i' in the dissociation reaction of species 'j' const scalar_t& nu_aqueous(index_t j, index_t i) const {return aqueous.nu_ji(j, i);} //! \brief Return the logk of dissociation reaction of species 'j' const scalar_t& logk_aqueous(index_t j) const {return aqueous.logk(j);} //! \brief Return the id of aqueous species 'label' //! //! Return no_species if the aqueous species does not exist index_t get_id_aqueous(const std::string& label) const{ return aqueous.get_id(label); } //! \brief Return the id of aqueous species 'label' std::string get_label_aqueous(index_t id) const { return aqueous.get_label(id); } //! \brief Return the charge of a secondary aqueous species const scalar_t& charge_aqueous(index_t j) const NOEXCEPT {return aqueous.charge(j);} //! \brief Return the 'a_i' Debye-Huckel parameter for a secondary aqueous species const scalar_t& a_debye_aqueous(index_t j) const NOEXCEPT {return aqueous.a_debye(j);} //! \brief Return the 'b_i' extended Debye-Huckel parameter for a secondary aqueous species const scalar_t& b_debye_aqueous(index_t j) const NOEXCEPT {return aqueous.b_debye(j);} //! \brief Return true if the corresponding equation is a half-cell reaction bool is_half_cell_reaction(index_t aqueous_species) const NOEXCEPT { return (nu_aqueous(aqueous_species, electron_index()) != 0.0); } //! \brief Range over the secondary aqueous species range_t range_aqueous() const { return aqueous.range();} //! @} //! \name Sorbed species //! \brief The adsorbed species // ========================================= //! @{ SorbedList sorbed; //!< The list of sorbed species //! \brief Return the number of sorbed species index_t nb_sorbed() const {return sorbed.size();} //! \brief Return the stoichiometric coefficient of 'i' in the dissociation reaction of species 'j' const scalar_t& nu_sorbed(index_t j, index_t i) const {return sorbed.nu_ji(j, i);} //! \brief Return the logk of dissociation reaction of species 'j' const scalar_t& logk_sorbed(index_t j) const {return sorbed.logk(j);} //! \brief Return the number of sorption sites occupied by a sorbed species const scalar_t& nb_sorption_sites(index_t sorbed_species) const { return sorbed.nb_sorption_site_occupied(sorbed_species); } //! \brief Return the id of sorbed species 'label' //! //! Return no_species if the sorbed species does not exist index_t get_id_sorbed(const std::string& label) const { return sorbed.get_id(label); } //! \brief Return the id of sorbed species 'label' std::string get_label_sorbed(index_t id) const { return sorbed.get_label(id); } //! \brief Range over the sorbed species range_t range_sorbed() const { return boost::irange((index_t) 0, nb_sorbed());} //! \brief Return true if the corresponding equation is a half-cell reaction bool is_sorbed_half_cell_reaction(index_t sorbed_species) const { return (nu_sorbed(sorbed_species, electron_index()) != 0.0); } //! @} //! \name Minerals //! \brief The solid phases // ========================================= //! @{ MineralList minerals; //!< The list of solid phases at equilibrium MineralList minerals_kinetic; //!< The list of solid phases governed by kinetic laws //! \brief Returns the number of solid phases at equilibrium index_t nb_mineral() {return minerals.size();} //! \brief Returns the number of solid phases governed by kinetic laws index_t nb_mineral_kinetic() {return minerals_kinetic.size();} //! \brief Return the stoichiometric coefficient for 'component' in the dissolution reaction of 'mineral' const scalar_t& nu_mineral(index_t mineral, index_t component) const { return minerals.nu_ji(mineral, component); } //! \brief Return the stoichiometric coefficient for 'component' in the dissolution reaction of 'mineral' const scalar_t& nu_mineral_kinetic(index_t mineral, index_t component) const { return minerals_kinetic.nu_ji(mineral, component); } //! \brief Return the logk for the dissolution reaction of 'mineral' const scalar_t& logk_mineral(index_t mineral) const { return minerals.logk(mineral); } //! \brief Return the logk for dissolution reaction of 'mineral' const scalar_t& logk_mineral_kinetic(index_t mineral) const { return minerals_kinetic.logk(mineral); } //! \brief Return true if the corresponding equation is a half-cell reaction bool is_mineral_half_cell_reaction(index_t mineral_species) const { return (nu_mineral(mineral_species, electron_index()) != 0.0); } //! \brief Return true if the corresponding equation is a half-cell reaction bool is_mineral_kinetic_half_cell_reaction(index_t mineral_species) const { return (nu_mineral_kinetic(mineral_species, electron_index()) != 0.0); } //! \brief Return the id of solid phase 'label' //! //! Return no_species if the solid phase does not exist index_t get_id_mineral(const std::string& label) const { return minerals.get_id(label); } //! \brief Return the id of solid phase 'label' std::string get_label_mineral(index_t id) const { return minerals.get_label(id); } //! \brief Return the id of solid phase 'label' //! //! Return no_species if the solid phase does not exist index_t get_id_mineral_kinetic(const std::string& label) const { return minerals_kinetic.get_id(label); } //! \brief Return the id of solid phase 'label' std::string get_label_mineral_kinetic(index_t id) const { return minerals_kinetic.get_label(id); } //! \brief Range over the solid phases (at equilibrium) range_t range_mineral() const { return minerals.range();} //! \brief Range over the solid phases governed by equilibrium range_t range_mineral_kinetic() const { return minerals_kinetic.range();} //! \brief Return the molar mass (kg/mol) of a mineral scalar_t molar_mass_mineral(index_t mineral) const; //! \brief Return the molar mass (kg/mol) of a mineral governed by kinetic scalar_t molar_mass_mineral_kinetic(index_t mineral) const; //! \brief Return the molar mass of 'mineral' in 'mass_uinit'/mol scalar_t molar_mass_mineral(index_t mineral, units::MassUnit mass_unit) const; //! \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) const; //! \brief Return the scaling factor for the molar volume scalar_t scaling_molar_volume(units::LengthUnit length_unit) const; //! \brief Return the molar volume whatever it is scalar_t unsafe_molar_volume_mineral(index_t m) const { return minerals.molar_volume(m); } //! \brief Return the molar volume (m^3/mol) of a mineral scalar_t molar_volume_mineral(index_t m) const; //! \brief Return the molar volume (m^3/mol) of a mineral governed by kinetic scalar_t molar_volume_mineral_kinetic(index_t m) const; //! \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) const; //! @} //! \name Gas //! \brief The gas present in the system // ========================================= //! @{ GasList gas; //!< The list of gas //! \brief Return the number of gas in the system index_t nb_gas() const {return gas.size();} //! \brief Return the stoichiometric coefficient of 'component' in the dissolution reaction of 'gas_id' const scalar_t& nu_gas(index_t gas_id, index_t component) const {return gas.nu_ji(gas_id, component);} //! \brief Return the logk of he dissolution reaction of 'gas_id' const scalar_t& logk_gas(index_t gas_id) const {return gas.logk(gas_id);} //! \brief Return true if the corresponding equation is a half-cell reaction bool is_gas_half_cell_reaction(index_t gas_species) const { return (nu_gas(gas_species, electron_index()) != 0.0); } //! \brief Return the id of gas 'label' //! //! Return no_species if the gas does not exist index_t get_id_gas(const std::string& label) const { return gas.get_id(label); } //! \brief Return the id of solid phase 'label' std::string get_label_gas(index_t id) const { return gas.get_label(id); } //! \brief Range over the gas phases range_t range_gas() const { return boost::irange((index_t) 0, nb_gas());} //! @} // Status // ------ //! Return true if the database is valid; bool is_valid(); }; } // end namespace database } // end namespace specmicp #include 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; } // end namespace database } // end namespace specmicp #endif // SPECMICP_DATABASE_DATACONTAINER_HPP diff --git a/src/database/oxydo_selector.cpp b/src/database/oxydo_selector.cpp index fd49513..02d5d10 100644 --- a/src/database/oxydo_selector.cpp +++ b/src/database/oxydo_selector.cpp @@ -1,92 +1,97 @@ /*------------------------------------------------------------------------------- Copyright (c) 2014,2015 F. Georget , 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 "oxydo_selector.hpp" namespace specmicp { namespace database { +//! \brief Remove the half-cells reaction corresponding to list_components in 'slist' +void remove_half_cells_secondary( + ReactiveSpeciesList* slist, + const std::vector& list_components); + void OxydoSelector::remove_half_cells(const std::vector& list_components) { std::vector list_id_components(list_components.size()); for (auto i=0; i& list_components) { remove_half_cells_secondary(&(data->aqueous), list_components); remove_half_cells_secondary(&(data->sorbed), list_components); remove_half_cells_secondary(&(data->gas), list_components); remove_half_cells_secondary(&(data->minerals), list_components); remove_half_cells_secondary(&(data->minerals_kinetic), list_components); } //! \brief Remove the half-cells reaction for the aqueous species -void OxydoSelector::remove_half_cells_secondary( +void remove_half_cells_secondary( ReactiveSpeciesList* slist, const std::vector& list_components) { // first we select the species to remove std::vector to_remove(slist->size(), false); for (auto id: slist->range()) { if (slist->nu_ji(id, DataContainer::electron_index()) == 0.0) continue; for (const auto& component: list_components) { if (slist->nu_ji(id, component) != 0.0) to_remove[id] = true; } } // then we remove them, in two steps const auto nb_to_keep = std::count(to_remove.cbegin(), to_remove.cend(), false); auto new_j = 0; // 1) first we copy data in the beginning of the arrays for (index_t j: slist->range()) { if (to_remove[j]) continue; slist->move_erase(j, new_j); ++new_j; } specmicp_assert(new_j == nb_to_keep); // 2) then we resize the arrays slist->resize(nb_to_keep); slist->set_valid(); } } // end namespace database } // end namespace specmicp diff --git a/src/database/oxydo_selector.hpp b/src/database/oxydo_selector.hpp index fb494de..5dd72c8 100644 --- a/src/database/oxydo_selector.hpp +++ b/src/database/oxydo_selector.hpp @@ -1,67 +1,64 @@ /*------------------------------------------------------------------------------- Copyright (c) 2014,2015 F. Georget , 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. -----------------------------------------------------------------------------*/ #ifndef SPECMICP_DATABASE_OXYDOSELECTOR_HPP #define SPECMICP_DATABASE_OXYDOSELECTOR_HPP -//! \file mineral_selector.hpp select minerals in the database +//! \file oxydo_selector.hpp +//! \brief Remove half-cells reactions #include "module.hpp" namespace specmicp { namespace database { -//! \brief Select equilibrum minerals in the database +//! \class OxydoSelector +//! \brief Remove half cells reaction for for given components //! -//! Keep only the solid phases that the user wants class OxydoSelector: public DatabaseModule { public: OxydoSelector(RawDatabasePtr thedata): DatabaseModule(thedata) {} - + //! \brief Remove the halfs-cells reaction for components in 'list_components' void remove_half_cells(const std::vector& list_components); + //! \brief Remove the halfs-cells reaction for components in 'list_components' void remove_half_cells(const std::vector& list_components); -private: - //! \brief Remove the half-cells reaction corresponding to list_components in 'slist' - void remove_half_cells_secondary( - ReactiveSpeciesList* slist, - const std::vector& list_components); }; } // end namespace database } // end namespace specmicp #endif // SPECMICP_DATABASE_MINERALSELECTOR_HPP diff --git a/src/database/reader.hpp b/src/database/reader.hpp index d2d59dd..8a13864 100644 --- a/src/database/reader.hpp +++ b/src/database/reader.hpp @@ -1,137 +1,134 @@ /*------------------------------------------------------------------------------- Copyright (c) 2014,2015 F. Georget , 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. -----------------------------------------------------------------------------*/ #ifndef DATABASE_READER_H #define DATABASE_READER_H -//! \file reader.hpp Read the json database +//! \file reader.hpp Read the database from a json file #include "json/json-forwards.h" #include "module.hpp" #include namespace specmicp { namespace database { //! \brief Read a json file containing a database -//! -//! This is a reader class, it does not transform -//! (reduce to canonical form, swap the basis) the data class DataReader: public DatabaseModule { public: //! \brief Constructor //! //! @param filepath string containing the path to the database DataReader(const std::string& filepath): DatabaseModule() { parse(filepath); } //! \brief Constructor //! //! @param input input stream that contains the database DataReader(std::istream& input): DatabaseModule() { parse(input); } //! Return the databes RawDatabasePtr get_database() {return data;} //! \brief Parse the basis section //! //! Contains the list of primary species void parse_basis(Json::Value& basis_root); //! \brief Parse the aqueous section //! //! Contains the list of secondary species void parse_aqueous(Json::Value& aqueous_root, AqueousList& alist); //! \brief Parse the mineral section //! //! Contains the list of minerals void parse_minerals( Json::Value& minerals, MineralList &minerals_list, MineralList &minerals_kinetic_list ); //! \brief Parse the gas section void parse_gas(Json::Value& gas_root, GasList &glist); //! \brief Parse the sorbed species section void parse_sorbed(Json::Value& sorbed_root, SorbedList &slist); private: //! \brief Parse database //! //! Throw db_invalid_syntax if a syntax error was detected. //! Throws std::invalid_argument if the path to the database is not correct void parse(std::istream& input ); //! \brief Parse database //! //! Throw db_invalid_syntax if a syntax error was detected. //! Throws std::invalid_argument if the path to the database is not correct void parse(const std::string& filepath); //! \brief Parse the metadata section //! //! we don't do much with them for now.... void parse_metadata(Json::Value& root); std::hash m_hash_fn; std::size_t m_electron_hash; }; //! \brief Parse an equation void parse_equation(const std::string &equation, std::map& compo); //! \brief Get the charge of a species by parsing the label //! //! Examples : //! - neutral -> 0 //! - neutral[] -> 0 //! - charge[+] -> +1 //! - charge[-1] -> -1 //! - charge[+2] -> +2 //! - charge[2-] -> -2 double charge_from_label(const std::string& label); } // end namespace database } // end namespace specmicp #endif // DATABASE_READER_H diff --git a/src/database/selector.hpp b/src/database/selector.hpp index 60513e4..5964e17 100644 --- a/src/database/selector.hpp +++ b/src/database/selector.hpp @@ -1,112 +1,119 @@ /*------------------------------------------------------------------------------- Copyright (c) 2014,2015 F. Georget , 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. -----------------------------------------------------------------------------*/ #ifndef SPECMICP_DATABASE_SELECTOR_HPP #define SPECMICP_DATABASE_SELECTOR_HPP -//! \file selector.hpp select species int the database +//! \file selector.hpp Select components in the database #include #include "module.hpp" namespace specmicp { namespace database { -//! \brief Select species in the database +//! \brief Select components in the database //! -//! This is a special class with the only function is to remove some components from the database +//! This class reduce the database by removing some components +//! and all the species associated with these components. class DatabaseSelector: public DatabaseModule { public: DatabaseSelector(RawDatabasePtr thedata): DatabaseModule(thedata), m_is_component_to_remove(thedata->nb_component(), false) {} - //! Remove compoment in the list "id_component_to_remove" + //! \brief Remove compoment in the list "id_component_to_remove" + //! + //! \param id_component_to_remove list of id of the components to remove void remove_component(const std::vector& id_component_to_remove); - //! keep only components in the "id_to_keep" list + //! \brief keep only components in the "id_to_keep" list + //! + //! \param id_to_keep list of id of the components to keep in the database void keep_only_component(const std::vector& id_to_keep); //! \brief Remove all gas phase void remove_all_gas(); //! \brief Remove all gas phase void remove_all_sorbed(); -// //! \brief Remove all half-cell reactions -// void remove_half_cells_reactions(); - //! \brief Remove some specific aqueous species + //! + //! This method should not be used in normal usage. + //! Removing the aqueous species will break the consistency of the database + //! + //! \param id_aqueous list of id of the aqueous to remove void remove_aqueous(const std::vector& id_aqueous); private: //! \brief Analyse wich component should be removed void analyse_component(const std::vector& id_component_to_remove); void select_secondary( ReactiveSpeciesList* toselect, const std::vector& id_component_to_remove ); //! \brief Select the correct aqueous species void select_aqueous(const std::vector& id_component_to_remove); //! \brief Select the correct minerals void select_minerals(const std::vector& id_component_to_remove); //! \brief Select the correct minerals governed by kinetics void select_minerals_kinetic(const std::vector& id_component_to_remove); //! \brief Select the gas phases void select_gas(const std::vector& id_component_to_remove); //! \brief Select the sorbed species void select_sorbed(const std::vector& id_component_to_remove); //! \brief Select components //! //! This should be the last operation void select_components(); //! \brief Return true if the component must be removed bool is_component_to_remove(index_t id) {return m_is_component_to_remove[id];} //! \brief Return the number of component to keep in the db uindex_t nb_component_to_keep() {return m_nb_component_to_keep;} std::vector m_is_component_to_remove; // true if component will be removed uindex_t m_nb_component_to_keep; // total number of component after the purging is done }; } // end namespace database } // end namespace specmicp #endif // SPECMICP_DATABASE_SELECTOR_HPP diff --git a/src/database/switch_basis.hpp b/src/database/switch_basis.hpp index 5bb2ba2..afe6105 100644 --- a/src/database/switch_basis.hpp +++ b/src/database/switch_basis.hpp @@ -1,76 +1,82 @@ /*------------------------------------------------------------------------------- Copyright (c) 2014,2015 F. Georget , 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. -----------------------------------------------------------------------------*/ #ifndef SPECMICP_DATABASE_SWITCHBASIS_HPP #define SPECMICP_DATABASE_SWITCHBASIS_HPP -//! \file switch_basis.hpp Switch basis +//! \file switch_basis.hpp +//! \brief Switch the basis #include "module.hpp" #include namespace specmicp { namespace database { //! \brief Use this class to switch the basis of the database class BasisSwitcher: public DatabaseModule { public: BasisSwitcher(RawDatabasePtr thedata): DatabaseModule(thedata) {} //! \brief Switch the basis //! - //! @param new_basis list of id of the new basis + //! \param new_basis list of id of the new basis //! //! The new basis is a list of id, id = id_component for no swapping //! or id = id_aqueous + nb_component for swapping a secondary species + //! + //! \sa swap_components void switch_basis(std::vector& new_basis); + //! \brief Swap components + //! + //! \param swap_to_make is a map where the keys are the components to swap and the values the id of the aqueous to put in the database void swap_components(std::map& swap_to_make); private: //! \brief Return the true aqueous index index_t get_true_aqueous_index(index_t ind); //! \brief Swap aqueous parameters during a basis transformation void swap_aq_param(std::vector& new_basis); //! \brief Swap labels - called during a basis transformation void swap_labels(std::vector& new_basis); }; } // end namespace database } // end namespace specmicp #endif // SPECMICP_DATABASE_SWITCHBASIS_HPP