Skip to content

Commit 9d885d9

Browse files
authored
Implementation of equilibrium reactions (#3)
* break up equilbrium reactions to impl file: * added symmetric matrix type for the equilibrium enforcement when using reaction extents * add script to take a system and reduce it to RREF for evaluating choice of primary and secondary species * added printers.hpp to output arrays and matrices easily * add log based calculation of aggregate concentrations in SpeciesUtilities file * added aggregate based equilibrium enforcement * add texlive-full for documentation
1 parent fe1be01 commit 9d885d9

26 files changed

+5847
-579
lines changed

.github/workflows/continuousIntegration.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ jobs:
2020
- name: Extract docker image tag hash
2121
id: extract_docker_image_tag_hash
2222
run: |
23-
echo "DOCKER_IMAGE_TAG_HASH=310f70ba6065b94858af2cafeba828ea76c02a1d" >> "$GITHUB_OUTPUT"
23+
echo "DOCKER_IMAGE_TAG_HASH=eaa7c33eb38fed4df436c1085c6a020ad75434ac" >> "$GITHUB_OUTPUT"
2424
2525
# code_style:
2626
# needs: [check_pull_request_is_not_a_draft]

cmake/Macros.cmake

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -41,24 +41,30 @@ macro(hpcReact_add_code_checks)
4141
--suppress=noExplicitConstructor
4242
--suppress=unusedFunction
4343
--suppress=constStatement
44-
--suppress=unusedStructMember )
44+
--suppress=unusedStructMember
45+
-I../hpcReact/src )
4546

46-
blt_add_code_checks( PREFIX ${arg_PREFIX}
47-
SOURCES ${_sources}
48-
UNCRUSTIFY_CFG_FILE ${PROJECT_SOURCE_DIR}/src/uncrustify.cfg
49-
CPPCHECK_FLAGS ${CPPCHECK_FLAGS}
50-
)
47+
if( UNCRUSTIFY_FOUND )
48+
blt_add_code_checks( PREFIX ${arg_PREFIX}
49+
SOURCES ${_sources}
50+
UNCRUSTIFY_CFG_FILE ${PROJECT_SOURCE_DIR}/src/uncrustify.cfg
51+
CPPCHECK_FLAGS ${CPPCHECK_FLAGS}
52+
)
53+
add_test( NAME testUncrustifyCheck
54+
COMMAND bash -c "${CMAKE_MAKE_PROGRAM} uncrustify_check 2> >(tee uncrustify.err) >/dev/null && exit $(cat uncrustify.err | wc -l)"
55+
WORKING_DIRECTORY ${CMAKE_BINARY_DIR} )
56+
endif()
5157

5258
if( CPPCHECK_FOUND )
5359
add_test( NAME testCppCheck
54-
COMMAND bash -c "make cppcheck_check 2> >(tee cppcheck.err) >/dev/null && exit $(cat cppcheck.err | wc -l)"
60+
COMMAND bash -c "${CMAKE_MAKE_PROGRAM} cppcheck_check 2> >(tee cppcheck.err) >/dev/null && exit $(cat cppcheck.err | wc -l)"
5561
WORKING_DIRECTORY ${CMAKE_BINARY_DIR}
5662
)
5763
endif()
5864

5965
if( CLANGTIDY_FOUND )
6066
add_test( NAME testClangTidy
61-
COMMAND bash -c "make clang_tidy_check 2> >(tee tidyCheck.err) >/dev/null && exit $(cat tidyCheck.err | wc -l)"
67+
COMMAND bash -c "${CMAKE_MAKE_PROGRAM} clang_tidy_check 2> >(tee tidyCheck.err) >/dev/null && exit $(cat tidyCheck.err | wc -l)"
6268
WORKING_DIRECTORY ${CMAKE_BINARY_DIR}
6369
)
6470
endif()

hostconfigs/apple/macOS_base.cmake

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ set( DOXYGEN_EXECUTABLE "${HOMEBREW_DIR}/bin/doxygen" CACHE PATH "" FORCE)
2626
set( CPPCHECK_EXECUTABLE "${HOMEBREW_DIR}/bin/cppcheck" CACHE PATH "" FORCE)
2727
set( CLANGTIDY_EXECUTABLE "${HOMEBREW_DIR}/opt/llvm/bin/clang-tidy" CACHE PATH "" FORCE)
2828

29-
set( ENABLE_COVERAGE ON CACHE BOOL "" FORCE)
29+
set( ENABLE_COVERAGE OFF CACHE BOOL "" FORCE)
3030
set( GCOV_EXECUTABLE "/usr/bin/gcov" CACHE PATH "" FORCE)
3131
set( LCOV_EXECUTABLE "${HOMEBREW_DIR}/bin/lcov" CACHE PATH "" FORCE)
3232

scripts/ci_build_and_test_in_container.sh

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,9 @@ fi
2020
echo "Using package manager: $PACKAGE_MANAGER"
2121

2222
if [ "$PACKAGE_MANAGER" == "apt" ]; then
23-
apt update && apt-get install -y libblas-dev liblapack-dev
23+
apt update && apt-get install -y libblas-dev liblapack-dev texlive-full
2424
elif [ "$PACKAGE_MANAGER" == "yum" ]; then
25-
yum install -y blas lapack
25+
yum update && yum install -y blas lapack
2626
fi
2727

2828
# The or_die function run the passed command line and

src/CMakeLists.txt

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,13 @@ set( hpcReact_headers
33
common/macros.hpp
44
common/CArrayWrapper.hpp
55
reactions/bulkGeneric/EquilibriumReactions.hpp
6+
reactions/bulkGeneric/EquilibriumReactionsAggregatePrimaryConcentration_impl.hpp
7+
reactions/bulkGeneric/EquilibriumReactionsReactionExtents_impl.hpp
68
reactions/bulkGeneric/KineticReactions.hpp
9+
reactions/bulkGeneric/KineticReactions_impl.hpp
710
reactions/bulkGeneric/Parameters.hpp
811
reactions/bulkGeneric/ParametersPredefined.hpp
12+
reactions/bulkGeneric/SpeciesUtilities.hpp
913
)
1014

1115
set( hpcReact_sources
@@ -35,6 +39,7 @@ target_include_directories( hpcReact
3539
$<BUILD_INTERFACE:${CMAKE_SOURCE_DIR}/src>
3640
$<INSTALL_INTERFACE:include> )
3741

42+
blt_print_target_properties( TARGET hpcReact )
3843
# install( FILES ${hpcReact_headers}
3944
# DESTINATION include )
4045

src/common/DirectSystemSolve.hpp

Lines changed: 133 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,145 @@
11
#pragma once
22

33
#include "macros.hpp"
4+
#include "symmetricMatrix.hpp"
45
#include <cmath>
56

67
namespace hpcReact
78
{
9+
10+
template< typename REAL_TYPE, int N >
11+
bool isPositiveDefinite( REAL_TYPE const (&A)[N][N] )
12+
{
13+
REAL_TYPE temp[N][N];
14+
15+
// Copy A into temp to avoid modifying original
16+
for( int i = 0; i < N; i++ )
17+
{
18+
for( int j = 0; j < N; j++ )
19+
{
20+
temp[i][j] = A[i][j];
21+
}
22+
}
23+
24+
for( int k = 0; k < N; k++ )
25+
{
26+
// Compute determinant of k-th leading principal minor using Gaussian elimination
27+
if( temp[k][k] <= 0 )
28+
return false; // Must be positive
29+
30+
for( int i = k + 1; i < N; i++ )
31+
{
32+
REAL_TYPE factor = temp[i][k] / temp[k][k];
33+
for( int j = k; j < N; j++ )
34+
{
35+
temp[i][j] -= factor * temp[k][j];
36+
}
37+
}
38+
}
39+
return true;
40+
}
41+
42+
43+
template< typename REAL_TYPE, int N >
44+
void solveNxN_Cholesky( REAL_TYPE const (&A)[N][N], REAL_TYPE const (&b)[N], REAL_TYPE (& x)[N] )
45+
{
46+
REAL_TYPE L[N][N] = {{0}};
47+
48+
// **Cholesky Decomposition**
49+
for( int i = 0; i < N; i++ )
50+
{
51+
for( int j = 0; j <= i; j++ )
52+
{
53+
REAL_TYPE sum = 0;
54+
for( int k = 0; k < j; k++ )
55+
{
56+
sum += L[i][k] * L[j][k];
57+
}
58+
if( i == j )
59+
L[i][j] = sqrt( A[i][i] - sum );
60+
else
61+
L[i][j] = (A[i][j] - sum) / L[j][j];
62+
}
63+
}
64+
65+
// **Forward Substitution: Solve L y = b**
66+
//REAL_TYPE y[N];
67+
for( int i = 0; i < N; i++ )
68+
{
69+
x[i] = b[i];
70+
for( int j = 0; j < i; j++ )
71+
x[i] -= L[i][j] * x[j];
72+
x[i] /= L[i][i];
73+
}
74+
75+
// **Backward Substitution: Solve L^T x = y**
76+
for( int i = N - 1; i >= 0; i-- )
77+
{
78+
// x[i] = y[i];
79+
for( int j = i + 1; j < N; j++ )
80+
x[i] -= L[j][i] * x[j];
81+
x[i] /= L[i][i];
82+
}
83+
}
84+
85+
86+
87+
template< typename REAL_TYPE, int N >
88+
void solveNxN_Cholesky( symmetricMatrix< REAL_TYPE, int, N > const & A,
89+
REAL_TYPE const (&b)[N],
90+
REAL_TYPE (& x)[N] )
91+
{
92+
symmetricMatrix< REAL_TYPE, int, N > L = {0};
93+
94+
// **Cholesky Decomposition**
95+
for( int i = 0; i < N; i++ )
96+
{
97+
for( int j = 0; j <= i; j++ )
98+
{
99+
REAL_TYPE sum = 0;
100+
for( int k = 0; k < j; k++ )
101+
{
102+
sum += L( i, k ) * L( j, k );
103+
}
104+
if( i == j )
105+
{
106+
L( i, j ) = sqrt( A( i, i ) - sum );
107+
}
108+
else
109+
{
110+
L( i, j ) = (A( i, j ) - sum) / L[j][j];
111+
}
112+
}
113+
}
114+
115+
// **Forward Substitution: Solve L y = b**
116+
REAL_TYPE y[N];
117+
for( int i = 0; i < N; i++ )
118+
{
119+
y[i] = b[i];
120+
for( int j = 0; j < i; j++ )
121+
{
122+
y[i] -= L( i, j ) * y[j];
123+
}
124+
y[i] /= L( i, i );
125+
}
126+
127+
// **Backward Substitution: Solve L^T x = y**
128+
for( int i = N - 1; i >= 0; i-- )
129+
{
130+
x[i] = y[i];
131+
for( int j = i + 1; j < N; j++ )
132+
{
133+
x[i] -= L( j, i ) * x[j];
134+
}
135+
x[i] /= L( i, i );
136+
}
137+
}
138+
139+
8140
template< typename REAL_TYPE, int N >
9141
HPCREACT_HOST_DEVICE
10-
void solveNxN_pivoted( REAL_TYPE A[N][N], REAL_TYPE b[N], REAL_TYPE x[N] )
142+
void solveNxN_pivoted( REAL_TYPE (& A)[N][N], REAL_TYPE (& b)[N], REAL_TYPE (& x)[N] )
11143
{
12144

13145

src/common/macros.hpp

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,3 +19,48 @@
1919
/// This macro is used to ignore warnings that that a variable is
2020
/// unused.
2121
#define HPCREACT_UNUSED_VAR( ... ) (void)( __VA_ARGS__ )
22+
23+
24+
#if defined( __clang__ )
25+
#define HPCREACT_NO_MISSING_BRACES( ... ) \
26+
_Pragma("clang diagnostic push") \
27+
_Pragma("clang diagnostic ignored \"-Wmissing-braces\"") \
28+
__VA_ARGS__ \
29+
_Pragma("clang diagnostic pop")
30+
31+
#define HPCREACT_NO_MISSING_BRACES_OPEN \
32+
_Pragma("clang diagnostic push") \
33+
_Pragma("clang diagnostic ignored \"-Wmissing-braces\"")
34+
#define HPCREACT_NO_MISSING_BRACES_CLOSE \
35+
_Pragma("clang diagnostic pop")
36+
37+
#elif defined(__GNUC__)
38+
#define HPCREACT_NO_MISSING_BRACES( ... ) \
39+
_Pragma("GCC diagnostic push") \
40+
_Pragma("GCC diagnostic ignored \"-Wmissing-braces\"") \
41+
__VA_ARGS__ \
42+
_Pragma("GCC diagnostic pop")
43+
44+
#define HPCREACT_NO_MISSING_BRACES_OPEN \
45+
_Pragma("GCC diagnostic push") \
46+
_Pragma("GCC diagnostic ignored \"-Wmissing-braces\"")
47+
#define HPCREACT_NO_MISSING_BRACES_CLOSE \
48+
_Pragma("GCC diagnostic pop")
49+
50+
#elif defined(_MSC_VER)
51+
#define HPCREACT_NO_MISSING_BRACES( ... ) \
52+
__pragma(warning(push)) \
53+
__pragma(warning(disable : 4351)) \
54+
__VA_ARGS__ \
55+
__pragma(warning(pop))
56+
57+
#define HPCREACT_NO_MISSING_BRACES_OPEN \
58+
__pragma(warning(push)) \
59+
__pragma(warning(disable : 4351))
60+
#define HPCREACT_NO_MISSING_BRACES_CLOSE \
61+
__pragma(warning(pop))
62+
#else
63+
#define HPCREACT_NO_MISSING_BRACES( ... ) __VA_ARGS__ // No-op for unknown compilers
64+
#define HPCREACT_NO_MISSING_BRACES_OPEN
65+
#define HPCREACT_NO_MISSING_BRACES_CLOSE
66+
#endif

src/common/printers.hpp

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
#pragma once
2+
3+
#include <stdio.h>
4+
5+
template< typename T, int N >
6+
void print( T const (&a)[N], char const * name, int const numDigits )
7+
{
8+
char format[8];
9+
snprintf( format, 8, "%%%d.%de", numDigits+7, numDigits );
10+
printf( "%-9s = { ", name );
11+
for( int i=0; i<N; ++i )
12+
{
13+
printf( format, a[i] );
14+
if( i < N-1 )
15+
{
16+
printf( ", " );
17+
}
18+
}
19+
printf( " }\n" );
20+
}
21+
22+
template< typename T, int NROWS, int NCOLS >
23+
void print( CArrayWrapper< T, NROWS, NCOLS > const & matrix, char const * name, int const numDigits )
24+
{
25+
char format[8];
26+
snprintf( format, 8, "%%%d.%de", numDigits+7, numDigits );
27+
28+
printf( "%-9s = \n{ \n", name );
29+
for( int i=0; i<NROWS; ++i )
30+
{
31+
printf( " { " );
32+
for( int j=0; j<NCOLS; ++j )
33+
{
34+
printf( format, matrix( i, j ) );
35+
if( j < NCOLS-1 )
36+
{
37+
printf( ", " );
38+
}
39+
}
40+
printf( " },\n" );
41+
}
42+
printf( " }\n" );
43+
}

0 commit comments

Comments
 (0)