diff --git a/src/specmicp_common/physics/laws.cpp b/src/specmicp_common/physics/laws.cpp index dbaf0ca..e58a7c3 100644 --- a/src/specmicp_common/physics/laws.cpp +++ b/src/specmicp_common/physics/laws.cpp @@ -1,78 +1,83 @@ /* ============================================================================= Copyright (c) 2014 - 2016 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 "laws.hpp" #include "units.hpp" #include namespace specmicp { namespace laws { scalar_t debye_huckel(scalar_t sqrtI, scalar_t zi, scalar_t ao) { if (zi == 0.0) return 0.0; scalar_t res = 0.0; const scalar_t zisquare = std::pow(zi, 2); res = - constants::Adebye*zisquare*sqrtI; const scalar_t denom = (1 + ao*constants::Bdebye*sqrtI); res /= denom; return res; } scalar_t extended_debye_huckel(scalar_t I, scalar_t sqrtI, scalar_t zi, scalar_t ao, scalar_t bdot) { const scalar_t tmp = debye_huckel(sqrtI, zi, ao); return tmp + bdot*I; } scalar_t extended_debye_huckel(scalar_t I, scalar_t zi, scalar_t ao, scalar_t bdot) { const scalar_t tmp = debye_huckel(std::sqrt(I), zi, ao); return tmp + bdot*I; } scalar_t density_water(scalar_t temperature, units::LengthUnit length_unit, units::MassUnit mass_unit) { scalar_t scaling = 1.0; if (mass_unit == units::MassUnit::gram) scaling *= 1e-3; if (length_unit == units::LengthUnit::centimeter) scaling *= 1e-6; else if (length_unit == units::LengthUnit::decimeter) scaling = 1e-3; return scaling*constants::water_density_25; } +scalar_t density_water(units::UnitsSet units_set) +{ + return density_water(0, units_set.length, units_set.mass); +} + } // end namespace laws } // end namespace specmicp diff --git a/src/specmicp_common/physics/laws.hpp b/src/specmicp_common/physics/laws.hpp index af56647..b7959c8 100644 --- a/src/specmicp_common/physics/laws.hpp +++ b/src/specmicp_common/physics/laws.hpp @@ -1,136 +1,144 @@ /* ============================================================================= Copyright (c) 2014 - 2016 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_LAWS_LAWS_HPP #define SPECMICP_LAWS_LAWS_HPP //! \file laws.hpp //! \brief Simple physical laws #include "../types.hpp" #include "constants.hpp" namespace specmicp { namespace units { enum class LengthUnit; enum class MassUnit; + +struct UnitsSet; } //end namespace units //! \namespace specmicp::laws //! \brief Physical laws namespace laws { //! \brief Return the pressure of a perfect gas //! //! \param n the number of moles (mol) //! \param V the volume (m^3) //! \param T the temperature (K) inline constexpr scalar_t pressure_perfect_gas(scalar_t n, scalar_t V, scalar_t T=298.15) { return n*constants::gas_constant*T/V; } //! \brief Return the number of moles for a perfect gas //! //! \param P the pressure (Pa) //! \param V the volume (m^3) //! \param T the temperature (K) inline constexpr scalar_t mole_perfect_gas(scalar_t P, scalar_t V, scalar_t T=298.15) { return P*V/(constants::gas_constant*T); } //! \brief The Debye-Huckel law //! //! at 25°C //! //! \f[ \log \gamma_k = - \frac{A z_k^2 \sqrt{I}}{1 + a B \sqrt{I}} \f] //! //! \param sqrtI square root of the ionic strength //! \param zi Charge of the ion //! \param ao ion size parameter //! scalar_t SPECMICP_DLL_PUBLIC SPECMICP_PURE_F debye_huckel(scalar_t sqrtI, scalar_t zi, scalar_t ao); //! \brief The Bdot law //! //! at 25°C //! //! \f[ \log \gamma_k = - \frac{A z_k^2 \sqrt{I}}{1 + a B \sqrt{I}} + \dot{B} I \f] //! //! //! \param I square ionic strength //! \param zi Charge of the ion //! \param ao ion size parameter //! \param bdot 'bdot' parameter //! scalar_t SPECMICP_DLL_PUBLIC SPECMICP_PURE_F extended_debye_huckel(scalar_t I, scalar_t zi, scalar_t ao, scalar_t bdot); //! \brief The Bdot law //! //! at 25°C //! //! This version accepts the value of \f$\sqrt{I}\f$. //! //! \f[ \log \gamma_k = - \frac{A z_k^2 \sqrt{I}}{1 + a B \sqrt{I}} + \dot{B} I \f] //! //! \param I square ionic strength //! \param sqrtI square root of the ionic strength //! \param zi Charge of the ion //! \param ao ion size parameter //! \param bdot 'bdot' parameter //! scalar_t SPECMICP_DLL_PUBLIC SPECMICP_PURE_F extended_debye_huckel(scalar_t I, scalar_t sqrtI, scalar_t zi, scalar_t ao, scalar_t bdot); //! \brief Return the density of water in the correct units //! //! \param temperature the temperature //! \param length_unit the lenght unit //! \param mass_unit the mass unit scalar_t SPECMICP_DLL_PUBLIC SPECMICP_PURE_F density_water(scalar_t temperature, units::LengthUnit length_unit, units::MassUnit mass_unit); +//! \brief Return the density of water in the correct units at 25C +//! +//! \param units_set the units set +scalar_t +SPECMICP_DLL_PUBLIC SPECMICP_PURE_F +density_water(units::UnitsSet units_set); } // end namespace laws } // end namespace specmicp #endif // SPECMICP_LAWS_LAWS_HPP