-
Notifications
You must be signed in to change notification settings - Fork 0
add initial constitutive relations api #17
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
rrsettgast
wants to merge
8
commits into
main
Choose a base branch
from
feature/addConstitutive
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 1 commit
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
6c89cc5
add initial constitutive relations api
rrsettgast 1413a1b
compiles...still need to deal with params and actual calls for c->act…
rrsettgast 806547d
testKineticReactions is function with activity...need updated answers…
rrsettgast 60498c3
wip
rrsettgast 73861a1
change parameter specification approach
rrsettgast 3d89882
intermediate commit
rrsettgast 0e4e5ce
more changes
rrsettgast 3bd3028
missing file
rrsettgast File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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
42
src/constitutive/ionicStrength/StoichiometricIonicStrength.hpp
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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() |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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; | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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 } | ||
| }; | ||
|
|
||
| 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; | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
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