diff --git a/src/reactmicp/io/CMakeLists.txt b/src/reactmicp/io/CMakeLists.txt index 736ccc8..8d41310 100644 --- a/src/reactmicp/io/CMakeLists.txt +++ b/src/reactmicp/io/CMakeLists.txt @@ -1,43 +1,45 @@ set( reactmicp_io_srcs configuration.cpp configuration_common.cpp configuration_unsaturated.cpp + configuration_chloride.cpp reactive_transport.cpp saturated_react.cpp ) set( reactmicp_io_headers configuration.hpp configuration_common.hpp configuration_unsaturated.hpp + configuration_chloride.hpp reactive_transport.hpp saturated_react.hpp ) set( reactmicp_io_hdf5_srcs hdf5_unsaturated.cpp hdf5_chloride.cpp ) set( reactmicp_io_hdf5_headers hdf5_unsaturated.hpp hdf5_chloride.hpp ) if (HDF5_FOUND) list(APPEND reactmicp_io_srcs ${reactmicp_io_hdf5_srcs} ) list(APPEND reactmicp_io_headers ${reactmicp_io_hdf5_headers} ) set_source_files_properties( ${reactmicp_io_hdf5_srcs} PROPERTIES COMPILE_DEFINITIONS HDF5_DEFINITIONS ) endif() add_to_reactmicp_srcs_list(reactmicp_io_srcs) add_to_reactmicp_headers_list(reactmicp_io_headers) INSTALL(FILES ${reactmicp_io_headers} DESTINATION ${INCLUDE_INSTALL_DIR}/reactmicp/io ) diff --git a/src/reactmicp/io/configuration_chloride.cpp b/src/reactmicp/io/configuration_chloride.cpp new file mode 100644 index 0000000..b626751 --- /dev/null +++ b/src/reactmicp/io/configuration_chloride.cpp @@ -0,0 +1,111 @@ +/* ============================================================================= + + Copyright (c) 2014-2017 F. Georget Princeton University + Copyright (c) 2017-2018 F. Georget EPFL + 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 "configuration_chloride.hpp" + +#include "specmicp_database/database.hpp" +#include "reactmicp/systems/chloride/boundary_conditions.hpp" +#include "specmicp_common/io/safe_config.hpp" +#include "specmicp_common/log.hpp" +#include "configuration_common.hpp" + +#define S_BCS_A_FIXEDNODES "fixed_nodes" +#define S_BCS_A_FIXEDCONCENTRATIONS "fixed_concentrations" +#define S_BCS_A_FIXEDPOTENTIAL "fixed_potentials" +#define S_BCS_V_FIXEDALLPOTENTIALS "fix_all_potentials" + + +#define S_BCS_SS_CONSTRAINTS "constraints" + +namespace specmicp { +namespace io { + +using namespace reactmicp::systems::chloride; + +std::shared_ptr configure_chloride_boundary_conditions( + mesh::Mesh1DPtr amesh, + database::RawDatabasePtr raw_data, + YAMLConfigHandle &&configuration) +{ + auto bcs = BoundaryConditions::make(amesh, raw_data); + if (configuration.has_node(S_BCS_A_FIXEDNODES)) { + const std::vector fixed_nodes = + configuration.list_to_vector(S_BCS_A_FIXEDNODES); + std::ostringstream msg; + msg << "Fixed nodes : "; + for (auto node : fixed_nodes) { + bcs->fix_node(node); + msg << node << "; "; + } + SPC_CONF_LOG << msg.str(); + } + if (configuration.has_node(S_BCS_A_FIXEDCONCENTRATIONS)) { + const std::vector fixed_conc = + configuration.list_to_vector(S_BCS_A_FIXEDCONCENTRATIONS); + std::ostringstream msg; + msg << "Fixed concentrations nodes : "; + for (auto node : fixed_conc) { + bcs->fix_node(node); + msg << node << "; "; + } + SPC_CONF_LOG << msg.str(); + } + if (configuration.has_node(S_BCS_A_FIXEDPOTENTIAL)) { + const std::vector fixed_pot = + configuration.list_to_vector(S_BCS_A_FIXEDPOTENTIAL); + std::ostringstream msg; + msg << "Fixed potential nodes : "; + for (auto node : fixed_pot) { + bcs->fix_node(node); + msg << node << "; "; + } + SPC_CONF_LOG << msg.str(); + } + if (configuration.get_optional_attribute(S_BCS_V_FIXEDALLPOTENTIALS, false)) { + SPC_CONF_LOG << "Fixed all potentials: True"; + bcs->fix_all_potentials(); + } else { + SPC_CONF_LOG << "Fixed all potentials: False"; + } + + if (configuration.has_section(S_BCS_SS_CONSTRAINTS)) { + configure_bcs_constraints(bcs.get(), raw_data.get(), + configuration.get_section(S_BCS_SS_CONSTRAINTS)); + } + + return bcs; +} + +} // namespace io +} // namespace specmicp diff --git a/src/reactmicp/io/configuration_chloride.hpp b/src/reactmicp/io/configuration_chloride.hpp new file mode 100644 index 0000000..9272b60 --- /dev/null +++ b/src/reactmicp/io/configuration_chloride.hpp @@ -0,0 +1,70 @@ +/* ============================================================================= + + Copyright (c) 2014-2017 F. Georget Princeton University + Copyright (c) 2017-2018 F. Georget EPFL + 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_REACTMICP_IO_CONFIGURATIONCHLORIDE_HPP +#define SPECMICP_REACTMICP_IO_CONFIGURATIONCHLORIDE_HPP + +#include "specmicp_common/types.hpp" +#include + +#include "specmicp_database/database_fwd.hpp" +#include "dfpm/meshes/mesh1dfwd.hpp" + +namespace specmicp { + +namespace reactmicp { +namespace systems { +namespace chloride { + +class BoundaryConditions; + +} // namespace chloride +} // namespace systems +} // namespace reactmicp + +namespace io { + +class YAMLConfigHandle; + +std::shared_ptr +configure_chloride_boundary_conditions( + mesh::Mesh1DPtr amesh, + database::RawDatabasePtr raw_data, + YAMLConfigHandle&& configuration); + + +} // namespace io +} // namespace specmicp + +#endif // SPECMICP_REACTMICP_IO_CONFIGURATIONCHLORIDE_HPP diff --git a/src/reactmicp/systems/chloride/boundary_conditions.cpp b/src/reactmicp/systems/chloride/boundary_conditions.cpp index 868ab6e..45a0d57 100644 --- a/src/reactmicp/systems/chloride/boundary_conditions.cpp +++ b/src/reactmicp/systems/chloride/boundary_conditions.cpp @@ -1,224 +1,160 @@ /* ============================================================================= Copyright (c) 2014-2017 F. Georget Princeton University Copyright (c) 2017 F. Georget EPFL 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 "boundary_conditions.hpp" #include "variables.hpp" #include "dfpm/meshes/mesh1d.hpp" #include "specmicp_database/database.hpp" #include "dof_numbering.hpp" #include "specmicp_common/cached_vector.hpp" #include "specmicp/adimensional/adimensional_system_structs.hpp" namespace specmicp { namespace reactmicp { namespace systems { namespace chloride { // =========== Implementation interface =================== struct BoundaryConditions::BoundaryConditionsImpl { BoundaryConditionsImpl(mesh::Mesh1DPtr amesh, database::RawDatabasePtr adatabase): m_mesh(amesh), m_database(adatabase), - m_dof_n(adatabase->nb_component()), - m_constraints(amesh->nb_nodes(), "default", AdimensionalSystemConstraints()) + m_dof_n(adatabase->nb_component()) {} std::vector get_fixed_dofs(); void fix_node(index_t node); // only fix the values, don't set them // variables must still be correctly initialized void fix_all_potentials(); void fix_concentrations_node(index_t node); void fix_potential_node(index_t node); mesh::Mesh1DPtr m_mesh; database::RawDatabasePtr m_database; DofNumbering m_dof_n; std::vector m_fixed_dofs; std::vector m_node_fixed_chemistry; - utils::NameCachedVector m_constraints; }; // ===================== Interface ======================== BoundaryConditions::BoundaryConditions(mesh::Mesh1DPtr amesh, database::RawDatabasePtr adatabase): + AdimReactMiCPConstraints(amesh->nb_nodes()), m_impl(utils::make_pimpl(amesh, adatabase)) { } BoundaryConditions::~BoundaryConditions() { } std::vector BoundaryConditions::get_fixed_dofs() { return m_impl->get_fixed_dofs(); } void BoundaryConditions::fix_node(index_t node) { m_impl->fix_node(node); } void BoundaryConditions::fix_concentrations_node(index_t node) { m_impl->fix_concentrations_node(node); } void BoundaryConditions::fix_potential_node(index_t node) { m_impl->fix_potential_node(node); } void BoundaryConditions::fix_all_potentials() { m_impl->fix_all_potentials(); } -bool BoundaryConditions::has_constraint(const std::string& name) const -{ - return m_impl->m_constraints.has_value(name); -} - -const AdimensionalSystemConstraints& BoundaryConditions::get_constraint(uindex_t node) const -{ - return m_impl->m_constraints[node]; -} - -AdimensionalSystemConstraints& BoundaryConditions::get_constraint(uindex_t node) -{ - return m_impl->m_constraints[node]; -} - -//! \brief Return the constraint identified by 'name' -const AdimensionalSystemConstraints& BoundaryConditions::get_constraint( - const std::string& name) const -{ - return m_impl->m_constraints.get(name); -} - -//! \brief Return the constraint identified by 'name' -AdimensionalSystemConstraints& BoundaryConditions::get_constraint( - const std::string& name) -{ - return m_impl->m_constraints.get(name); -} - -//! \brief Set a new constraints for the given node -AdimensionalSystemConstraints& BoundaryConditions::fork_constraint( - uindex_t node, - const std::string& name - ) -{ - return m_impl->m_constraints.fork(node, name); -} - -//! \brief Fork the given constraint -AdimensionalSystemConstraints& BoundaryConditions::fork_constraint( - const std::string& old_name, - const std::string& new_name - ) -{ - return m_impl->m_constraints.fork(old_name, new_name); -} - -//! \brief Add a constraint -AdimensionalSystemConstraints& BoundaryConditions::add_constraint( - const std::string& name - ) -{ - m_impl->m_constraints.emplace_back_cache(name); - return m_impl->m_constraints.get(name); -} - -//! \brief Set the constraint of the given node -void BoundaryConditions::set_constraint(uindex_t node, const std::string& name) -{ - return m_impl->m_constraints.set(node, name); -} - - // ================== Implementation ====================== std::vector BoundaryConditions::BoundaryConditionsImpl::get_fixed_dofs() { return m_fixed_dofs; } void BoundaryConditions::BoundaryConditionsImpl::fix_node(index_t node) { m_fixed_dofs.reserve(m_fixed_dofs.size() + m_database->nb_aqueous_components() + 1); for (index_t i: m_database->range_aqueous_component()) { m_fixed_dofs.push_back(m_dof_n.dof_component(node, i)); } m_fixed_dofs.push_back(m_dof_n.dof_psi(node)); } void BoundaryConditions::BoundaryConditionsImpl::fix_concentrations_node(index_t node) { m_fixed_dofs.reserve(m_fixed_dofs.size() + m_database->nb_aqueous_components()); for (index_t i: m_database->range_aqueous_component()) { m_fixed_dofs.push_back(m_dof_n.dof_component(node, i)); } } void BoundaryConditions::BoundaryConditionsImpl::fix_potential_node(index_t node) { m_fixed_dofs.push_back(m_dof_n.dof_psi(node)); } void BoundaryConditions::BoundaryConditionsImpl::fix_all_potentials() { for (index_t node: m_mesh->range_nodes()) { m_fixed_dofs.push_back(m_dof_n.dof_psi(node)); } } } // namespace chloride } // namespace systems } // namespace reactmicp } // namespace specmicp diff --git a/src/reactmicp/systems/chloride/boundary_conditions.hpp b/src/reactmicp/systems/chloride/boundary_conditions.hpp index ecfb113..cfa19ee 100644 --- a/src/reactmicp/systems/chloride/boundary_conditions.hpp +++ b/src/reactmicp/systems/chloride/boundary_conditions.hpp @@ -1,129 +1,94 @@ /* ============================================================================= Copyright (c) 2014-2017 F. Georget Princeton University Copyright (c) 2017 F. Georget EPFL 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 REACTMICP_CHLORIDE_BOUNDARYCONDITIONS_HPP #define REACTMICP_CHLORIDE_BOUNDARYCONDITIONS_HPP #include "specmicp_common/types.hpp" #include "specmicp_common/pimpl_ptr.hpp" #include #include "dfpm/meshes/mesh1dfwd.hpp" #include "specmicp_database/database_fwd.hpp" +#include "reactmicp/systems/common/adim_constraints.hpp" + namespace specmicp { struct AdimensionalSystemConstraints; namespace reactmicp { namespace systems { namespace chloride { //! \brief The boundary conditions for the chloride system -class SPECMICP_DLL_PUBLIC BoundaryConditions +class SPECMICP_DLL_PUBLIC BoundaryConditions: + public AdimReactMiCPConstraints { public: BoundaryConditions(mesh::Mesh1DPtr amesh, database::RawDatabasePtr adatabase); ~BoundaryConditions(); static std::shared_ptr make(mesh::Mesh1DPtr amesh, database::RawDatabasePtr adatabase) { return std::make_shared(amesh, adatabase); } std::vector get_fixed_dofs(); //! \brief Fix the concentrations and the potentials of a node //! //! Values need to be initialized in variables void fix_node(index_t node); //! \brief Fix the concentrations of a node void fix_concentrations_node(index_t node); //! \brief Fix the potential of a node void fix_potential_node(index_t node); //! \brief Fix all the potentials void fix_all_potentials(); - //! \brief Return true if the constraints exist - bool has_constraint(const std::string& name) const; - - //! \brief Return the chemical constraint of the given node - const AdimensionalSystemConstraints& get_constraint(uindex_t node) const; - //! \brief Return the chemical constraint of the given node - //! - //! \warning Changing the constraint changes it for all node sharing the - //! same constraint. To modify only this node, use `fork_constraints' first. - //! - AdimensionalSystemConstraints& get_constraint(uindex_t node); - - //! \brief Return the constraint identified by 'name' - const AdimensionalSystemConstraints& get_constraint( - const std::string& name) const; - - //! \brief Return the constraint identified by 'name' - AdimensionalSystemConstraints& get_constraint(const std::string& name); - - //! \brief Set a new constraints for the given node - AdimensionalSystemConstraints& fork_constraint( - uindex_t node, - const std::string& name - ); - - //! \brief Fork the given constraint - AdimensionalSystemConstraints& fork_constraint( - const std::string& old_name, - const std::string& new_name - ); - - //! \brief Add a constraint - AdimensionalSystemConstraints& add_constraint( - const std::string& name - ); - - //! \brief Set the constraint of the given node - void set_constraint(uindex_t node, const std::string& name); private: struct BoundaryConditionsImpl; utils::pimpl_ptr m_impl; }; } // namespace chloride } // namespace systems } // namespace reactmicp } // namespace specmicp #endif // REACTMICP_CHLORIDE_BOUNDARYCONDITIONS_HPP diff --git a/tests/reactmicp/CMakeLists.txt b/tests/reactmicp/CMakeLists.txt index 615e04f..68a3214 100644 --- a/tests/reactmicp/CMakeLists.txt +++ b/tests/reactmicp/CMakeLists.txt @@ -1,98 +1,99 @@ # Reactmicp : Reactive transport solver # ------------------------------------- set(test_reactmicp_files solver/test_reactive_transport_solver.cpp solver/test_coupling.cpp ) add_catch_test(NAME reactmicp SOURCES ${test_reactmicp_files} LINK_LIBRARIES ${REACTMICP_STATIC_LIBS}) # Saturated diffusion using new reactive transport solver # ======================================================= set(test_reactmicp_saturated_files systems/saturated_react/test_reactmicp_saturated_react.cpp systems/saturated_react/speciation_system.cpp systems/saturated_react/variables.cpp systems/saturated_react/transport_program.cpp systems/saturated_react/equilibrium_stagger.cpp ) if ( REACTMICP_ENABLE_SYSTEM_SATURATED ) add_catch_test( NAME reactmicp_saturated_react SOURCES ${test_reactmicp_saturated_files} LINK_LIBRARIES ${REACTMICP_STATIC_LIBS} ) endif( REACTMICP_ENABLE_SYSTEM_SATURATED ) # Unsaturated reactive transport system # ===================================== set(UNSATURATED_DIR systems/unsaturated) set(test_reactmicp_unsaturated_files ${UNSATURATED_DIR}/test_reactmicp_unsaturated.cpp ${UNSATURATED_DIR}/aqueous_equation.cpp ${UNSATURATED_DIR}/aqueous_pressure_equation.cpp ${UNSATURATED_DIR}/boundary_conditions.cpp ${UNSATURATED_DIR}/configuration.cpp ${UNSATURATED_DIR}/equilibrium_stagger.cpp ${UNSATURATED_DIR}/hdf5_unsaturated.cpp ${UNSATURATED_DIR}/pressure_equation.cpp ${UNSATURATED_DIR}/saturation_equation.cpp ${UNSATURATED_DIR}/saturation_pressure_equation.cpp ${UNSATURATED_DIR}/transport_stagger.cpp ${UNSATURATED_DIR}/variables.cpp ) set(TEST_CEMDATA_PATH \"../../data/cemdata.yaml\") set_source_files_properties( ${test_reactmicp_unsaturated_files} PROPERTIES COMPILE_DEFINITIONS "TEST_CEMDATA_PATH=${TEST_CEMDATA_PATH}" ) if ( REACTMICP_ENABLE_SYSTEM_UNSATURATED ) add_catch_test( NAME reactmicp_unsaturated SOURCES ${test_reactmicp_unsaturated_files} LINK_LIBRARIES ${REACTMICP_STATIC_LIBS} ) endif ( REACTMICP_ENABLE_SYSTEM_UNSATURATED ) # unsaturated binary # ------------------ add_subdirectory( binary/unsaturated ) # Chloride reactive transport system # =================================== set(CHLORIDE_DIR systems/chloride) set(test_reactmicp_chloride_files ${CHLORIDE_DIR}/test_reactmicp_chloride.cpp + ${CHLORIDE_DIR}/boundary_conditions.cpp ${CHLORIDE_DIR}/variables.cpp ${CHLORIDE_DIR}/transport_program.cpp ${CHLORIDE_DIR}/transport_stagger.cpp ${CHLORIDE_DIR}/hdf5_chloride.cpp ) set(TEST_CEMDATA_PATH \"../../data/cemdata.yaml\") set_source_files_properties( ${test_reactmicp_chloride_files} PROPERTIES COMPILE_DEFINITIONS "TEST_CEMDATA_PATH=${TEST_CEMDATA_PATH}" ) if ( REACTMICP_ENABLE_SYSTEM_CHLORIDE ) add_catch_test( NAME reactmicp_chloride SOURCES ${test_reactmicp_chloride_files} LINK_LIBRARIES ${REACTMICP_STATIC_LIBS} ) endif ( REACTMICP_ENABLE_SYSTEM_CHLORIDE ) diff --git a/tests/reactmicp/systems/chloride/boundary_conditions.cpp b/tests/reactmicp/systems/chloride/boundary_conditions.cpp new file mode 100644 index 0000000..42327ef --- /dev/null +++ b/tests/reactmicp/systems/chloride/boundary_conditions.cpp @@ -0,0 +1,72 @@ +#include "catch.hpp" + +#include "reactmicp/systems/chloride/boundary_conditions.hpp" +#include "dfpm/meshes/mesh1d.hpp" +#include "specmicp_database/database.hpp" +#include "specmicp/adimensional/adimensional_system_solver_structs.hpp" + +#include +#include + +using namespace specmicp; +using namespace specmicp::reactmicp::systems::chloride; + + +static mesh::Mesh1DPtr get_mesh(index_t nb_nodes) +{ + mesh::Uniform1DMeshGeometry amesh; + amesh.dx = 1.0; + amesh.section = 1.0; + amesh.nb_nodes = nb_nodes; + return mesh::uniform_mesh1d(amesh); +} + + +static specmicp::database::RawDatabasePtr get_database() +{ + static database::RawDatabasePtr raw_data {nullptr}; + if (raw_data == nullptr) + { + specmicp::database::Database thedatabase(TEST_CEMDATA_PATH); + thedatabase.keep_only_components({"H2O","Na[+]", "Cl[-]"}); + thedatabase.remove_half_cell_reactions(); + raw_data = thedatabase.get_database(); + raw_data->freeze_db(); + } + return raw_data; +} + +TEST_CASE("Boundary Conditions", "[Transport,Chemistry]") { + SECTION ("Boundary Conditions") { + + index_t nb_nodes = 10; + auto amesh = get_mesh(nb_nodes); + auto adatabase = get_database(); + + BoundaryConditions bcs(amesh, adatabase); + + bcs.fix_concentrations_node(2); + + bcs.fix_node(0); + + bcs.fix_potential_node(1); + + std::vector fixed = bcs.get_fixed_dofs(); + std::vector fixed_to_check = {0, 1, 2, 5, 6, 7}; + + for (auto dof: fixed) { + auto ret = std::count(fixed_to_check.begin(), fixed_to_check.end(), dof); + REQUIRE(ret == 1); + } + + REQUIRE(bcs.has_constraint("default")); + + AdimensionalSystemConstraints& fixed_adim = bcs.fork_constraint("default", "fixed"); + fixed_adim.set_fixed_saturation(0.5); + + bcs.set_constraint(2, "fixed"); + AdimensionalSystemConstraints& fixed_adim_check = bcs.get_constraint(2); + CHECK(fixed_adim_check.water_parameter == 0.5); + + } +}