Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
set( hpcReact_headers
common/macros.hpp
common/CArrayWrapper.hpp
constitutive/activity/Bdot.hpp
reactions/exampleSystems/BulkGeneric.hpp
reactions/geochemistry/Carbonate.hpp
reactions/geochemistry/Forge.hpp
Expand Down Expand Up @@ -67,10 +68,11 @@ message(STATUS "HPCReact/src CMAKE_CURRENT_SOURCE_DIR: ${CMAKE_CURRENT_SOURCE_DI
# hpcReact_add_code_checks( PREFIX hpcReact
# EXCLUDES "blt/*" )

add_subdirectory( common/unitTests )
add_subdirectory( constitutive/unitTests)
add_subdirectory( reactions/exampleSystems/unitTests )
add_subdirectory( reactions/geochemistry/unitTests )
add_subdirectory( reactions/massActions/unitTests )
add_subdirectory( common/unitTests )
add_subdirectory( docs )

hpcReact_add_code_checks( PREFIX hpcReact
Expand Down
85 changes: 85 additions & 0 deletions src/constitutive/activity/Bdot.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
/*
* ------------------------------------------------------------------------------------------------------------
* SPDX-License-Identifier: (BSD-3-Clause)
*
* Copyright (c) 2025- Lawrence Livermore National Security LLC
* All rights reserved
*
* See top level LICENSE files for details.
* ------------------------------------------------------------------------------------------------------------
*/
#pragma once

#include "DebyeHuckel.hpp"

namespace hpcReact
{

template< typename REAL_TYPE,
typename INDEX_TYPE,
typename IONIC_STRENGTH_TYPE >
class Bdot
{
public:
using RealType = REAL_TYPE;
using IndexType = INDEX_TYPE;



struct Params : public IONIC_STRENGTH_TYPE::Params
{
RealType m_ionSizeParameter[IONIC_STRENGTH_TYPE::Params::numSpecies()];
RealType m_bdotParameter[IONIC_STRENGTH_TYPE::Params::numSpecies()];
};



template< typename ARRAY_1D_TO_CONST,
typename ARRAY_1D >
static inline HPCREACT_HOST_DEVICE
void
calculateActivities( Params const & params,
ARRAY_1D_TO_CONST const & speciesConcentrations,
ARRAY_1D & activities )
{

RealType const ionicStrength = IONIC_STRENGTH_TYPE::calculate( params, speciesConcentrations );
RealType const sqrtI = sqrt(ionicStrength);
RealType const rho_w = 997.0479; // kg/m3
RealType const eps_r = 78.54; // dimensionless
RealType const T_K = 298.15;
RealType const A_gamma = DebyeHuckel<RealType>::A_gamma( T_K, rho_w, eps_r );
RealType const B_gamma = DebyeHuckel<RealType>::B_gamma( T_K, rho_w, eps_r );
auto const & speciesCharge = params.m_speciesCharge;
auto const & a = params.m_ionSizeParameter;
auto const & b = params.m_bdotParameter;



const IndexType numSpecies = params.numSpecies();
for( IndexType i=0; i<numSpecies; ++i )
{
RealType const DebyeHuckel_term = DebyeHuckel<RealType>::log10_gamma( sqrtI,
speciesCharge[i],
a[i],
A_gamma,
B_gamma );
activities[i] = DebyeHuckel_term + b[i] * ionicStrength;
}
}

private:
// -------------------------------------------------------------
// Physical constants (CODATA 2018-ish), SI units
// -------------------------------------------------------------
static constexpr double pi = 3.14159265358979323846;
static constexpr double e0 = 8.8541878128e-12; // vacuum permittivity [F/m]
static constexpr double eChg = 1.602176634e-19; // elementary charge [C]
static constexpr double kB = 1.380649e-23; // Boltzmann constant [J/K]
static constexpr double NA = 6.02214076e23; // Avogadro [1/mol]
static constexpr double ln10 = 2.3025850929940459;

};


} // namespace hpcReact
155 changes: 155 additions & 0 deletions src/constitutive/activity/DebyeHuckel.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,155 @@
#pragma once

#include "common/macros.hpp"

#include <cmath>

/**
* @file DebyeHuckel.hpp
* @brief Debye–Hückel A^γ and B parameters for aqueous electrolytes.
*
* This header provides helper functions to compute the Debye–Hückel
* parameters A^γ and B in their "native" (natural-log) form for
* molal (mol/kg) activity-coefficient models.
*
* The functions are expressed in terms of fundamental physical constants
* and water properties (density and relative permittivity). They can be
* used directly in Debye–Hückel or extended Debye–Hückel/B-dot models.
*/

template< typename REAL_TYPE >
class DebyeHuckel
{
public:
using RealType = REAL_TYPE;

/// π (pi).
static constexpr RealType pi = 3.141592653589793e+00;

/// Vacuum permittivity ε₀ [F/m].
static constexpr RealType e0 = 8.854187812800001e-12;

/// Elementary charge e [C].
static constexpr RealType eChg = 1.602176634000000e-19;

/// Boltzmann constant k_B [J/K].
static constexpr RealType kB = 1.380649000000000e-23;

/// Avogadro constant N_A [1/mol].
static constexpr RealType NA = 6.022140760000000e+23;

/// Natural logarithm of 10, ln(10).
static constexpr RealType ln10 = 2.302585092994046e+00;

/// Inverse of ln(10).
static constexpr RealType invln10 = 4.342944819032518e-01;


// -------------------------------------------------------------
// Debye–Hückel A^γ (natural log, molal scale)
// -------------------------------------------------------------

/**
* @brief Debye–Hückel A^γ parameter in natural-log form.
*
* Computes the coefficient A^γ(T,ρ,ε_r) used in the Debye–Hückel
* expression for the natural logarithm of the activity coefficient:
*
* \f[
* \ln \gamma_i =
* - A^\gamma_{\ln}(T,P) \, z_i^2
* \frac{\sqrt{I}}{1 + B(T,P)\, a_i \sqrt{I}}
* \f]
*
* where:
* - \f$ I \f$ is ionic strength in mol/kg (molal),
* - \f$ z_i \f$ is the ionic charge,
* - \f$ a_i \f$ is the ion-size parameter (length),
* - A^γ is independent of the log base (this function is for ln).
*
* The implementation follows the "native" Debye–Hückel form,
* using fundamental physical constants without any 1/ln(10) factors.
*
* @param T_K Temperature in kelvin [K].
* @param rho_w Density of water in g/L (≈ kg/m³ numerically).
* @param eps_r Relative permittivity (dielectric constant) of water.
* @return A^γ in units consistent with molal ionic strength, for use
* in ln(γ) expressions.
*/
static inline HPCREACT_HOST_DEVICE
RealType A_gamma( RealType const T_K,
RealType const rho_w,
RealType const eps_r )
{
RealType const num = ::pow( eChg, 3.0 ) * ::sqrt( 2.0 * pi * NA * rho_w );
RealType const den = ::pow( 4.0 * pi * e0 * eps_r * kB * T_K, 1.5 );
return num / den;
}


// -------------------------------------------------------------
// Debye–Hückel B (natural log, molal scale)
// -------------------------------------------------------------

/**
* @brief Debye–Hückel B parameter in natural-log form.
*
* Computes the Debye–Hückel length-scale parameter B(T,ρ,ε_r) used
* in the extended Debye–Hückel law:
*
* \f[
* \ln \gamma_i =
* - A^\gamma_{\ln}(T,P) \, z_i^2
* \frac{\sqrt{I}}{1 + B(T,P)\, a_i \sqrt{I}} \; ,
* \f]
*
* where:
* - \f$ I \f$ is ionic strength in mol/kg,
* - \f$ a_i \f$ is an ion-size parameter (length).
*
* The combination \f$ B a_i \sqrt{I} \f$ is dimensionless; the
* absolute units of B therefore depend on the length units chosen
* for \f$ a_i \f$.
*
* @param T_K Temperature in kelvin [K].
* @param rho_w Density of water in g/L (≈ kg/m³ numerically).
* @param eps_r Relative permittivity (dielectric constant) of water.
* @return B parameter for use in ln(γ) expressions.
*/
static inline HPCREACT_HOST_DEVICE
RealType B_gamma( RealType const T_K,
RealType const rho_w,
RealType const eps_r )
{
RealType const num = 2.0 * NA * rho_w * eChg * eChg;
RealType const den = e0 * eps_r * kB * T_K;
return ::sqrt( num / den );
}


static inline HPCREACT_HOST_DEVICE
RealType log10_gamma( RealType const I,
RealType const zi,
RealType const ai,
RealType const T_K )
{
RealType const sqrtI = sqrt(I);
RealType const A = A_gamma(T_K);
RealType const B = B_gamma(T_K);
RealType const denom = 1 + B * ai * sqrtI;
return -A * zi * zi * sqrtI / denom;
}


static inline HPCREACT_HOST_DEVICE
RealType log10_gamma( RealType const sqrtI,
RealType const zi,
RealType const ai,
RealType const A,
RealType const B )
{
RealType const denom = 1 + B * ai * sqrtI;
return -A * zi * zi * sqrtI / denom;
}

};
51 changes: 51 additions & 0 deletions src/constitutive/activity/Identity.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
/*
* ------------------------------------------------------------------------------------------------------------
* SPDX-License-Identifier: (BSD-3-Clause)
*
* Copyright (c) 2025- Lawrence Livermore National Security LLC
* All rights reserved
*
* See top level LICENSE files for details.
* ------------------------------------------------------------------------------------------------------------
*/
#pragma once

#include "common/macros.hpp"

namespace hpcReact
{

template< typename REAL_TYPE,
typename INDEX_TYPE,
typename IONIC_STRENGTH_TYPE >
class Identity
{
public:
using RealType = REAL_TYPE;
using IndexType = INDEX_TYPE;

struct Params
{
HPCREACT_HOST_DEVICE static constexpr IndexType numSpecies() { return IONIC_STRENGTH_TYPE::Params::numSpecies(); }
};

template< typename ARRAY_1D_TO_CONST,
typename ARRAY_1D,
typename PARAMS >
static inline HPCREACT_HOST_DEVICE
void
calculateActivities( PARAMS const & ,
ARRAY_1D_TO_CONST const & speciesConcentrations,
ARRAY_1D & activities )
{
constexpr IndexType numSpecies = PARAMS::numSpecies();
for( IndexType i=0; i<numSpecies; ++i )
{
activities[i] = speciesConcentrations[i];
}
}

};


} // namespace hpcReact
59 changes: 59 additions & 0 deletions src/constitutive/ionicStrength/SpeciatedIonicStrength.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
/*
* ------------------------------------------------------------------------------------------------------------
* SPDX-License-Identifier: (BSD-3-Clause)
*
* Copyright (c) 2025- Lawrence Livermore National Security LLC
* All rights reserved
*
* See top level LICENSE files for details.
* ------------------------------------------------------------------------------------------------------------
*/
#pragma once

#include "common/CArrayWrapper.hpp"
#include "common/macros.hpp"

namespace hpcReact
{

template< typename REAL_TYPE,
typename INDEX_TYPE,
int NUM_SPECIES >
class SpeciatedIonicStrength
{
public:
using RealType = REAL_TYPE;
using IndexType = INDEX_TYPE;

struct Params
{

HPCREACT_HOST_DEVICE static constexpr IndexType numSpecies() { return NUM_SPECIES; }
HPCREACT_HOST_DEVICE constexpr CArrayWrapper< RealType, NUM_SPECIES > & speciesCharge() { return m_speciesCharge; }

CArrayWrapper< RealType, NUM_SPECIES > m_speciesCharge;
};


template< typename ARRAY_1D_TO_CONST >
static inline HPCREACT_HOST_DEVICE
REAL_TYPE
calculate( Params const & params,
ARRAY_1D_TO_CONST const & speciesConcentration )
{
REAL_TYPE I = 0.0;
auto const & numSpecies = params.numSpecies();
auto const & speciesCharge = params.m_speciesCharge;
for( int i=0; i<numSpecies; ++i )
{
I += speciesConcentration[i] * speciesCharge[i] * speciesCharge[i];
}
I *= 0.5;
return I;
}


};


} // namespace hpcReact
Loading