diff --git a/src/database/selector.cpp b/src/database/selector.cpp index abf71f7..33fcd7f 100644 --- a/src/database/selector.cpp +++ b/src/database/selector.cpp @@ -1,208 +1,208 @@ /*------------------------------------------------------------------------------- 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 "selector.hpp" #include "aqueous_selector.hpp" namespace specmicp { namespace database { void DatabaseSelector::remove_component(const std::vector& id_component_to_remove) { // Find which components are to be removed analyse_component(id_component_to_remove); // Select the ... // Aqueous secondary species select_aqueous(id_component_to_remove); // Minerals select_minerals(id_component_to_remove); select_minerals_kinetic(id_component_to_remove); // Gas if (data->nb_gas() > 0) select_gas(id_component_to_remove); // Sorbed species if (data->nb_sorbed() > 0) select_sorbed(id_component_to_remove); // Compounds ! if (data->nb_compounds() > 0) select_compounds(id_component_to_remove); // Elements data->elements.remove_components(m_is_component_to_remove); // and finally the components select_components(); } void DatabaseSelector::analyse_component(const std::vector& id_component_to_remove) { for (auto it: id_component_to_remove) { if (it == DataContainer::water_index()) { throw std::invalid_argument("Water cannot be removed from the database"); } else if (it == DataContainer::electron_index()) { throw std::invalid_argument("The electron cannot be removed from the database"); } m_is_component_to_remove[it] = no_species; } auto new_ind = 0; for (auto component: data->range_component()) { if (m_is_component_to_remove[component] != no_species) { m_is_component_to_remove[component] = new_ind; ++new_ind; } } m_nb_component_to_keep = new_ind; specmicp_assert(data->nb_component() - id_component_to_remove.size() == new_ind); } // This is the main algorithm to remove secondary species void DatabaseSelector::select_secondary( ReactiveSpeciesList* toselect, const std::vector& id_component_to_remove ) { // first we select which aqueous species we should remove std::vector to_remove(toselect->size(), false); for (index_t j: toselect->range()) { for (const auto& it: id_component_to_remove) { if (toselect->nu_ji(j, it) != 0.0) { to_remove[j] = true; break; } } } // 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: toselect->range()) { if (to_remove[j]) continue; toselect->move_erase(j, new_j, m_is_component_to_remove); ++new_j; } specmicp_assert(new_j == nb_to_keep); // 2) then we resize the arrays toselect->resize(nb_to_keep, nb_component_to_keep()); toselect->set_valid(); // By doing in this order, we avoid bulk copy of arrays } void DatabaseSelector::select_aqueous(const std::vector& id_component_to_remove) { select_secondary(&(data->aqueous), id_component_to_remove); } void DatabaseSelector::select_minerals(const std::vector& id_component_to_remove) { select_secondary(&(data->minerals), id_component_to_remove); } void DatabaseSelector::select_minerals_kinetic(const std::vector& id_component_to_remove) { select_secondary(&(data->minerals_kinetic), id_component_to_remove); } void DatabaseSelector::select_gas(const std::vector& id_component_to_remove) { select_secondary(&(data->gas), id_component_to_remove); } void DatabaseSelector::select_sorbed(const std::vector& id_component_to_remove) { select_secondary(&(data->sorbed), id_component_to_remove); } void DatabaseSelector::select_compounds(const std::vector& id_component_to_remove) { - select_secondary(&(data->sorbed), id_component_to_remove); + select_secondary(&(data->compounds), id_component_to_remove); } void DatabaseSelector::select_components() { for (index_t i: data->range_component()) { index_t new_index = m_is_component_to_remove[i]; if (new_index == no_species) continue; data->components.move_erase(i, new_index); } data->components.resize(nb_component_to_keep()); data->components.set_valid(); } void DatabaseSelector::keep_only_component(const std::vector& id_to_keep) { // First build the list of components to remove std::vector id_to_remove; id_to_remove.reserve(data->nb_component() - id_to_keep.size()); for (index_t id: data->range_aqueous_component()) // avoid removing H2O and E[-] { auto search = std::find(id_to_keep.cbegin(), id_to_keep.cend(), id); if (search == id_to_keep.end()) id_to_remove.push_back(id); } // Then remove them remove_component(id_to_remove); } void DatabaseSelector::remove_all_gas() { data->gas = GasList(0, data->nb_component()); data->gas.set_valid(); } void DatabaseSelector::remove_all_sorbed() { data->sorbed = SorbedList(0, data->nb_component()); data->sorbed.set_valid(); } void DatabaseSelector::remove_all_compounds() { data->compounds = CompoundList(0, data->nb_component()); data->compounds.set_valid(); } //! \brief Remove some specific aqueous species void DatabaseSelector::remove_aqueous(const std::vector& id_aqueous) { AqueousSelector(data).remove_aqueous(id_aqueous); } } // end namespace database } // end namespace specmicp diff --git a/src/database/switch_basis.cpp b/src/database/switch_basis.cpp index 6611b94..4314add 100644 --- a/src/database/switch_basis.cpp +++ b/src/database/switch_basis.cpp @@ -1,142 +1,145 @@ /*------------------------------------------------------------------------------- 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 "switch_basis.hpp" #include #include namespace specmicp { namespace database { index_t BasisSwitcher::get_true_aqueous_index(index_t ind) { return ind - data->nb_component(); } void BasisSwitcher::swap_components(const std::map& swap_to_make) { std::vector id_swap; id_swap.reserve(data->nb_component()); for (index_t i: data->range_component()) { id_swap.push_back(i); } for (const auto& it: swap_to_make) { if (it.first == water_label) { throw std::invalid_argument("Basis switch : water cannot be swapped from basis"); } if (it.first == electron_label) { throw std::invalid_argument("Basis switch : electron cannot be swapped from basis"); } const index_t idc = safe_component_label_to_id(it.first); const index_t idaq = data->nb_component() + safe_aqueous_label_to_id(it.second); id_swap[idc] = idaq; } switch_basis(id_swap); } void BasisSwitcher::switch_basis(std::vector& new_basis) { Eigen::MatrixXd beta = Eigen::MatrixXd::Zero( data->nb_component(), data->nb_component()); Eigen::VectorXd kswap(data->nb_component()); // swap coefficients, build beta matrix and kswap for (index_t i: data->range_component()) { if (new_basis[i] >= data->nb_component()) { index_t j = get_true_aqueous_index(new_basis[i]); beta.row(i).segment(0, data->nb_component()) = data->aqueous.get_nu_row(j); data->aqueous.reset_nu_row(j); data->aqueous.set_nu_ji(j, i, 1.0); kswap(i) = data->logk_aqueous(j); data->aqueous.set_logk(j, 0.0); } else { beta(i, i) = 1.0; kswap(i) = 0.0; } } Matrix betainv = beta.inverse(); data->components.molar_mass_transform(beta); data->aqueous.switch_basis(betainv, kswap); swap_aq_param(new_basis); swap_labels(new_basis); // now do the minerals data->minerals.switch_basis(betainv, kswap); data->minerals_kinetic.switch_basis(betainv, kswap); - // and the gases if (data->nb_gas() > 0) { data->gas.switch_basis(betainv, kswap); } // and sorbed species if (data->nb_sorbed() > 0) { data->sorbed.switch_basis(betainv, kswap); } + if (data->nb_compounds() > 0) + { + data->compounds.switch_basis(betainv, kswap); + } } void BasisSwitcher::swap_aq_param(std::vector& new_basis) { for (index_t i: data->range_component()) { if(new_basis[i] >= data->nb_component()) { const index_t j = get_true_aqueous_index(new_basis[i]); const auto tmp = data->components.ionic_values(i); data->components.set_ionic_values(i, data->aqueous.ionic_values(j)); data->aqueous.set_ionic_values(j, tmp); } } } void BasisSwitcher::swap_labels(std::vector& new_basis) { for (index_t i: data->range_component()) { if (new_basis[i] >= data->nb_component()) { const index_t j = get_true_aqueous_index(new_basis[i]); const auto tmp = data->components.get_label(i); data->components.set_label(i, data->aqueous.get_label(j)); data->aqueous.set_label(j, tmp); } } } } // end namespace database } // end namespace specmicp diff --git a/src/database/yaml_writer.cpp b/src/database/yaml_writer.cpp index 216228c..e8c6969 100644 --- a/src/database/yaml_writer.cpp +++ b/src/database/yaml_writer.cpp @@ -1,264 +1,285 @@ /*------------------------------------------------------------------------------- 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 "yaml_writer.hpp" #include #include "../utils/io/yaml.hpp" #include "section_name.hpp" #include "../utils/dateandtime.hpp" #include namespace specmicp { namespace database { std::string format_equation(index_t species, const ReactiveSpeciesList& slist, const ComponentList& basis); void DatabaseWriterYaml::write(const std::string& filename) { YAML::Emitter root; set_yaml_tree(root); std::ofstream ofile(filename); ofile << root.c_str(); } void DatabaseWriterYaml::set_yaml_tree(YAML::Emitter& root) { root << YAML::Comment("This database was generated automatically by SpecMiCP"); root << YAML::BeginMap; set_metadata(root); set_elements(root); set_basis(root); set_aqueous(root); set_minerals(root); set_gas(root); set_sorbed(root); + set_compound(root); root << YAML::EndMap; } void DatabaseWriterYaml::set_metadata(YAML::Emitter& root) { root << YAML::Key << INDB_SECTION_METADATA << YAML::Key; root << YAML::BeginMap; root << YAML::Key << INDB_ATTRIBUTE_NAME << YAML::Value << data->metadata.name; root << YAML::Key << INDB_ATTRIBUTE_VERSION << YAML::Value << dateandtime::now(); root << YAML::Key << INDB_ATTRIBUTE_PATH << YAML::Value << "N/A"; root << YAML::EndMap; } void DatabaseWriterYaml::set_basis(YAML::Emitter& root) { root << YAML::Key << INDB_SECTION_BASIS << YAML::Key; root << YAML::BeginSeq; for (auto id: data->range_component()) { set_component(id, root); } root << YAML::EndSeq; } void DatabaseWriterYaml::set_component(index_t component, YAML::Emitter& root) { root << YAML::BeginMap; root << YAML::Key << INDB_ATTRIBUTE_LABEL << YAML::Value << data->get_label_component(component); root << YAML::Key << INDB_ATTRIBUTE_MOLARMASS << YAML::Value << data->molar_mass_basis(component, units::MassUnit::gram); if (component >= 2) { root << YAML::Key << INDB_ATTRIBUTE_ACTIVITY << YAML::Value; root << YAML::BeginMap; root << YAML::Key << INDB_ATTRIBUTE_ACTIVITY_A << YAML::Value << data->a_debye_component(component); root << YAML::Key << INDB_ATTRIBUTE_ACTIVITY_B << YAML::Value << data->b_debye_component(component); root << YAML::EndMap; } root << YAML::EndMap; } void DatabaseWriterYaml::set_elements(YAML::Emitter& root) { root << YAML::Key << INDB_SECTION_ELEMENTS << YAML::Value; root << YAML::BeginSeq; for (auto id: data->range_component()) { root << YAML::BeginMap; root << YAML::Key << INDB_ATTRIBUTE_ELEMENT << YAML::Value << data->elements.get_label_element(id); root << YAML::Key << INDB_ATTRIBUTE_COMPONENT << YAML::Value << data->get_label_component(id); root << YAML::EndMap; } root << YAML::EndSeq; } void DatabaseWriterYaml::set_aqueous(YAML::Emitter& root) { root << YAML::Key << INDB_SECTION_AQUEOUS << YAML::Value; root << YAML::BeginSeq; for (auto id: data->range_aqueous()) { set_aqueous_species(id, root); } root << YAML::EndSeq; } void DatabaseWriterYaml::set_aqueous_species(index_t aqueous, YAML::Emitter& root) { root << YAML::BeginMap; root << YAML::Key << INDB_ATTRIBUTE_LABEL << YAML::Value << data->get_label_aqueous(aqueous); root << YAML::Key << INDB_ATTRIBUTE_COMPOSITION << YAML::Value << format_equation(aqueous, data->aqueous, data->components); root << YAML::Key << INDB_ATTRIBUTE_LOGK << YAML::Value << data->logk_aqueous(aqueous); root << YAML::Key << INDB_ATTRIBUTE_ACTIVITY << YAML::Value; root << YAML::BeginMap; root << YAML::Key << INDB_ATTRIBUTE_ACTIVITY_A << YAML::Value << data->a_debye_aqueous(aqueous); root << YAML::Key << INDB_ATTRIBUTE_ACTIVITY_B << YAML::Value << data->b_debye_aqueous(aqueous); root << YAML::EndMap; root << YAML::EndMap; } void DatabaseWriterYaml::set_minerals(YAML::Emitter& root) { root << YAML::Key << INDB_SECTION_MINERALS << YAML::Value; root << YAML::BeginSeq; for (auto id: data->range_mineral()) { set_mineral(id, root); } for (auto id: data->range_mineral_kinetic()) { set_mineral_kinetic(id, root); } root << YAML::EndSeq; } void DatabaseWriterYaml::set_mineral(index_t mineral, YAML::Emitter& root) { root << YAML::BeginMap; root << YAML::Key << INDB_ATTRIBUTE_LABEL << YAML::Value << data->get_label_mineral(mineral); root << YAML::Key << INDB_ATTRIBUTE_COMPOSITION << YAML::Value << format_equation(mineral, data->minerals, data->components) ; root << YAML::Key << INDB_ATTRIBUTE_LOGK << YAML::Value << data->logk_mineral(mineral); if (data->unsafe_molar_volume_mineral(mineral) > 0) { root << YAML::Key << INDB_ATTRIBUTE_MOLARVOLUME << YAML::Value << data->molar_volume_mineral(mineral, units::LengthUnit::centimeter); } root << YAML::EndMap; } void DatabaseWriterYaml::set_mineral_kinetic(index_t mineral, YAML::Emitter& root) { root << YAML::BeginMap; root << YAML::Key << INDB_ATTRIBUTE_LABEL << YAML::Value << data->get_label_mineral_kinetic(mineral); root << YAML::Key << INDB_ATTRIBUTE_COMPOSITION << YAML::Value << format_equation(mineral, data->minerals_kinetic, data->components) ; root << YAML::Key << INDB_ATTRIBUTE_LOGK << YAML::Value << data->logk_mineral_kinetic(mineral); if (data->unsafe_molar_volume_mineral_kinetic(mineral) > 0) { root << YAML::Key << INDB_ATTRIBUTE_MOLARVOLUME << YAML::Value << data->molar_volume_mineral_kinetic(mineral, units::LengthUnit::centimeter); } root << YAML::Key << INDB_ATTRIBUTE_FLAG_KINETIC << YAML::Value << true; root << YAML::EndMap; } void DatabaseWriterYaml::set_gas(YAML::Emitter& root) { root << YAML::Key << INDB_SECTION_GAS << YAML::Value; root << YAML::BeginSeq; for (auto id: data->range_gas()) { set_gas_phase(id, root); } root << YAML::EndSeq; } void DatabaseWriterYaml::set_gas_phase(index_t gas, YAML::Emitter& root) { root << YAML::BeginMap; root << YAML::Key << INDB_ATTRIBUTE_LABEL << YAML::Value << data->get_label_gas(gas); root << YAML::Key << INDB_ATTRIBUTE_COMPOSITION << YAML::Value << format_equation(gas, data->gas, data->components); root << YAML::Key << INDB_ATTRIBUTE_LOGK << YAML::Value << data->logk_gas(gas); root << YAML::EndMap; } void DatabaseWriterYaml::set_sorbed(YAML::Emitter& root) { root << YAML::Key << INDB_SECTION_SORBED << YAML::Value; root << YAML::BeginSeq; for (auto id: data->range_sorbed()) { set_sorbed_species(id, root); } root << YAML::EndSeq; } void DatabaseWriterYaml::set_sorbed_species(index_t sorbed, YAML::Emitter& root) { root << YAML::BeginMap; root << YAML::Key << INDB_ATTRIBUTE_LABEL << YAML::Value << data->get_label_sorbed(sorbed); root << YAML::Key << INDB_ATTRIBUTE_COMPOSITION << YAML::Value << format_equation(sorbed, data->sorbed, data->components); root << YAML::Key << INDB_ATTRIBUTE_NBSITEOCCUPIED << YAML::Value << data->nb_sorption_sites(sorbed); root << YAML::Key << INDB_ATTRIBUTE_LOGK << YAML::Value << data->logk_sorbed(sorbed); root << YAML::EndMap; } +void DatabaseWriterYaml::set_compound(YAML::Emitter& root) +{ + root << YAML::Key << INDB_SECTION_COMPOUNDS << YAML::Value; + root << YAML::BeginSeq; + for (auto id: data->range_compounds()) + { + set_compound_species(id, root); + } + root << YAML::EndSeq; +} + +void DatabaseWriterYaml::set_compound_species(index_t compound, YAML::Emitter& root) +{ + root << YAML::BeginMap; + root << YAML::Key << INDB_ATTRIBUTE_LABEL << YAML::Value << data->get_label_compound(compound); + root << YAML::Key << INDB_ATTRIBUTE_COMPOSITION << YAML::Value << format_equation(compound, data->compounds, data->components); + root << YAML::EndMap; +} + + std::string format_equation(index_t species, const ReactiveSpeciesList& slist, const ComponentList& basis) { std::string equation; for (index_t component: basis.range()) { if (slist.nu_ji(species, component) != 0) { char buffer[10]; std::snprintf(buffer, sizeof(buffer), "%.4f", slist.nu_ji(species, component)); equation += std::string(buffer) + " " + basis.get_label(component) + ", "; } } equation.erase(equation.size()-2, 2); // remove tailing ', ' return equation; } } //end namespace database } //end namespace specmicp diff --git a/src/database/yaml_writer.hpp b/src/database/yaml_writer.hpp index ea19299..2ec32f1 100644 --- a/src/database/yaml_writer.hpp +++ b/src/database/yaml_writer.hpp @@ -1,90 +1,92 @@ /*------------------------------------------------------------------------------- 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_YAMLWRITER #define SPECMICP_DATABASE_YAMLWRITER //! \file database/yaml_writer.hpp //! \brief Write a database on disk #include "module.hpp" namespace YAML { class Emitter; } //end namespace YAML namespace specmicp { namespace database { //! \brief Write a database in the JSON format //! //! This class can be used to save the database used in a computation. //! It will save the current state of the database class SPECMICP_DLL_LOCAL DatabaseWriterYaml: public DatabaseModule { public: DatabaseWriterYaml(RawDatabasePtr& the_database): DatabaseModule(the_database) {} //! \brief Write the database //! //! \param filepath path to the file where the database will be saved void write(const std::string& filepath); //! \brief Format the database as a YAML::Emitter void set_yaml_tree(YAML::Emitter& root); private: // The following methods set a section of the database void set_metadata(YAML::Emitter& root); void set_basis(YAML::Emitter& root); void set_component(index_t component, YAML::Emitter& root); void set_elements(YAML::Emitter& root); void set_aqueous(YAML::Emitter& root); void set_aqueous_species(index_t aqueous, YAML::Emitter& root); void set_minerals(YAML::Emitter& root); void set_mineral(index_t mineral, YAML::Emitter& root); void set_mineral_kinetic(index_t mineral, YAML::Emitter& root); void set_gas(YAML::Emitter& root); void set_gas_phase(index_t gas, YAML::Emitter& root); void set_sorbed(YAML::Emitter& root); void set_sorbed_species(index_t sorbed, YAML::Emitter& root); + void set_compound(YAML::Emitter& root); + void set_compound_species(index_t compound, YAML::Emitter& root); }; } //end namespace database } //end namespace specmicp #endif // SPECMICP_DATABASE_YAMLWRITER