Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
21 commits
Select commit Hold shift + click to select a range
6c89cc5
add initial constitutive relations api
rrsettgast Nov 27, 2025
1413a1b
compiles...still need to deal with params and actual calls for c->act…
rrsettgast Jan 8, 2026
806547d
testKineticReactions is function with activity...need updated answers…
rrsettgast Jan 9, 2026
60498c3
wip
rrsettgast Jan 12, 2026
73861a1
change parameter specification approach
rrsettgast Jan 13, 2026
3d89882
intermediate commit
rrsettgast Feb 19, 2026
0e4e5ce
more changes
rrsettgast Feb 25, 2026
3bd3028
missing file
rrsettgast Feb 25, 2026
70ea0e9
Merge remote-tracking branch 'origin/main' into feature/addConstitutive
frankfeifan Jul 28, 2026
e3fdc55
uncrustify
frankfeifan Jul 28, 2026
9f62f74
fixed unit inconsistency in ion size
frankfeifan Jul 30, 2026
7442fd8
convert A_gamma to log10 scale
frankfeifan Jul 30, 2026
289c764
fixed dActivities_dConcentrations
frankfeifan Jul 30, 2026
da23938
fixed inconsistent size in activity param
frankfeifan Jul 30, 2026
3eafe2e
rename logPrimarySpeciesConcentration in the lambda to avoid the dupl…
frankfeifan Jul 30, 2026
1624d4d
refact the tests to reveal the activity model
frankfeifan Jul 30, 2026
2d3857c
uncrustify
frankfeifan Jul 30, 2026
03e7097
Refactor and enable activity coefficient returnfrom the activity models
frankfeifan Aug 13, 2026
6cf4020
Add EQ36 validation test for the carbonate activity model
frankfeifan Aug 13, 2026
997a7f3
Merge remote-tracking branch 'origin/main' into feature/addConstitutive
frankfeifan Aug 13, 2026
f66badd
include math.h for gcc build
frankfeifan Aug 15, 2026
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
63 changes: 63 additions & 0 deletions src/constitutive/activity/Bdot.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
/*
* ------------------------------------------------------------------------------------------------------------
* 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 Bdot
{
public:
using RealType = REAL_TYPE;
using IndexType = INDEX_TYPE;

struct Params : public IONIC_STRENGTH_TYPE::PARAMS
{

};


template< typename ARRAY_1D_TO_CONST,
typename ARRAY_1D >
static inline HPCREACT_HOST_DEVICE
void
calculateActivities( IONIC_STRENGTH_TYPE::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 A_gamma = 2;
RealType const B_gamma = 1.6;
auto const & speciesCharge = params.m_speciesCharge;
auto const & a = params.m_ionSizeParameter;
auto const & b = params.m_bdotParameter;



constexpr IndexType numSpecies = params.numSpecies();
for( IndexType i=0; i<numSpecies; ++i )
{
RealType const gamma_coeff = -A_gamma * sqrtI / ( 1 + a[i] * B_gamma * sqrtI );
activities[i] = gamma_coeff * speciesCharge[i] * speciesCharge[i] + b[i] * ionicStrength;
}
}

};


} // 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
42 changes: 42 additions & 0 deletions src/constitutive/ionicStrength/StoichiometricIonicStrength.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
/*
* ------------------------------------------------------------------------------------------------------------
* 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 >
class SpeciatedIonicStrength
{
public:

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

};


} // namespace hpcReact
22 changes: 22 additions & 0 deletions src/constitutive/unitTests/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
# Specify list of tests
set( testSourceFiles
testBdot.cpp
testIonicStrength.cpp )


set( dependencyList hpcReact gtest )

if( ENABLE_CUDA )
list( APPEND dependencyList cuda )
endif()

# Add gtest C++ based tests
foreach(test ${testSourceFiles})
get_filename_component( test_name ${test} NAME_WE )
blt_add_executable( NAME ${test_name}
SOURCES ${test}
OUTPUT_DIR ${TEST_OUTPUT_DIRECTORY}
DEPENDS_ON ${dependencyList} )
blt_add_test( NAME ${test_name}
COMMAND ${test_name} )
endforeach()
49 changes: 49 additions & 0 deletions src/constitutive/unitTests/testBdot.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
/*
* ------------------------------------------------------------------------------------------------------------
* SPDX-License-Identifier: (BSD-3-Clause)
*
* Copyright (c) 2025- Lawrence Livermore National Security LLC
* All rights reserved
*
* See top level LICENSE files for details.
* ------------------------------------------------------------------------------------------------------------
*/


#include "constitutive/activity/Bdot.hpp"
#include "reactions/reactionsSystems/Parameters.hpp"
#include "constitutive/ionicStrength/SpeciatedIonicStrength.hpp"
#include "common/pmpl.hpp"

#include <gtest/gtest.h>

using namespace hpcReact;




constexpr SpeciatedIonicStrength<double, int>::Params<3> testParams
{
// Species charge
{ 1.0, -1.0, 2.0 }
};

TEST( testBdot, testIonicStrength )
{
double speciesConcentration[ testParams.numSpecies() ] = { 0.1, 0.2, 0.3 };

double I = SpeciatedIonicStrength< double, int >::calculate( testParams,
speciesConcentration );

double expectedI = 0.5 * ( 0.1 * 1.0 * 1.0 + 0.2 * (-1.0) * (-1.0) + 0.3 * 2.0 * 2.0 );
EXPECT_DOUBLE_EQ( I, expectedI );

}


int main( int argc, char * * argv )
{
::testing::InitGoogleTest( &argc, argv );
int const result = RUN_ALL_TESTS();
return result;
}
48 changes: 48 additions & 0 deletions src/constitutive/unitTests/testIonicStrength.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
/*
* ------------------------------------------------------------------------------------------------------------
* SPDX-License-Identifier: (BSD-3-Clause)
*
* Copyright (c) 2025- Lawrence Livermore National Security LLC
* All rights reserved
*
* See top level LICENSE files for details.
* ------------------------------------------------------------------------------------------------------------
*/


#include "constitutive/ionicStrength/SpeciatedIonicStrength.hpp"
#include "common/CArrayWrapper.hpp"
#include "common/pmpl.hpp"

#include <gtest/gtest.h>

using namespace hpcReact;


using IonicStrength = SpeciatedIonicStrength<double, int, 3>;

constexpr IonicStrength::Params testParams
{
// Species charge
{ 1.0, -1.0, 2.0 }

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The sum of charges needs to be 0. Suggesting to change 1.0 to -1.0

};

TEST( testBdot, testIonicStrength )
{
double speciesConcentration[ testParams.numSpecies() ] = { 0.1, 0.2, 0.3 };

double I = IonicStrength::calculate( testParams,
speciesConcentration );

double expectedI = 0.5 * ( 0.1 * 1.0 * 1.0 + 0.2 * (-1.0) * (-1.0) + 0.3 * 2.0 * 2.0 );
EXPECT_DOUBLE_EQ( I, expectedI );

}


int main( int argc, char * * argv )
{
::testing::InitGoogleTest( &argc, argv );
int const result = RUN_ALL_TESTS();
return result;
}
14 changes: 14 additions & 0 deletions src/reactions/reactionsSystems/Parameters.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,10 @@ struct KineticReactionsParameters
};






template< typename REAL_TYPE,
typename INT_TYPE,
typename INDEX_TYPE,
Expand All @@ -136,12 +140,18 @@ struct MixedReactionsParameters
CArrayWrapper< RealType, NUM_REACTIONS > const & rateConstantForward,
CArrayWrapper< RealType, NUM_REACTIONS > const & rateConstantReverse,
CArrayWrapper< IntType, NUM_REACTIONS > mobileSecondarySpeciesFlag,
CArrayWrapper< RealType, NUM_SPECIES > const & speciesCharge,
CArrayWrapper< RealType, NUM_SPECIES > const & ionSizeParameter,
CArrayWrapper< RealType, NUM_SPECIES > const & bdotParameter,
IntType const reactionRatesUpdateOption = 1 ):
m_stoichiometricMatrix( stoichiometricMatrix ),
m_equilibriumConstant( equilibriumConstant ),
m_rateConstantForward( rateConstantForward ),
m_rateConstantReverse( rateConstantReverse ),
m_mobileSecondarySpeciesFlag( mobileSecondarySpeciesFlag ),
m_speciesCharge( speciesCharge ),
m_ionSizeParameter( ionSizeParameter ),
m_bdotParameter( bdotParameter ),
m_reactionRatesUpdateOption( reactionRatesUpdateOption )
{}

Expand Down Expand Up @@ -250,6 +260,10 @@ struct MixedReactionsParameters
CArrayWrapper< RealType, NUM_REACTIONS > m_rateConstantReverse;
CArrayWrapper< IntType, NUM_REACTIONS > m_mobileSecondarySpeciesFlag;

CArrayWrapper< RealType, NUM_SPECIES > m_speciesCharge;
CArrayWrapper< RealType, NUM_SPECIES > m_ionSizeParameter;
CArrayWrapper< RealType, NUM_SPECIES > m_bdotParameter;

IntType m_reactionRatesUpdateOption; // 0: forward and reverse rate. 1: quotient form.
};

Expand Down
Loading