Skip to content

Commit 0d0c819

Browse files
authored
Merge pull request #52 from gemshub/fix_LU
Fix lu
2 parents 4780439 + 2dba3c7 commit 0d0c819

File tree

5 files changed

+22
-23
lines changed

5 files changed

+22
-23
lines changed

CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
cmake_minimum_required(VERSION 3.16..4.2)
33

44
# Set the name of the project
5-
project(GEMS3K VERSION 4.4.5 LANGUAGES CXX C)
5+
project(GEMS3K VERSION 4.5.0 LANGUAGES CXX C)
66

77
set(CMAKE_CXX_STANDARD 20)
88
set(CMAKE_CXX_STANDARD_REQUIRED ON)

GEMS3K/jama_cholesky.h

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ using namespace TNT;
3636
L = chol.getL();
3737
3838
else
39-
c out << "factorization was not complete.\n";
39+
cout << "factorization was not complete.\n";
4040
4141
</pre>
4242
@@ -115,8 +115,7 @@ Cholesky<Real>::Cholesky(const Array2D<Real> &A)
115115
for (int j = 0; j < n; j++)
116116
{
117117
double d = 0.0;
118-
int k;
119-
for ( k = 0; k < j; k++)
118+
for (int k = 0; k < j; k++)
120119
{
121120
Real s = 0.0;
122121
for (int i = 0; i < k; i++)
@@ -132,8 +131,8 @@ Cholesky<Real>::Cholesky(const Array2D<Real> &A)
132131
// if( !isspd ) // Added SD 29/11/2006
133132
// return;
134133
// L_[j][j] = sqrt(d > 0.0 ? d : 0.0);
135-
L_[j][j] = sqrt(d > 0.0 ? d : 1e-60); // Test change! DK 13.10.2006
136-
for ( k = j+1; k < n; k++)
134+
L_[j][j] = sqrt(d > 0.0 ? d : 1e-60); // Test change! DK 13.10.2006
135+
for (int k = j+1; k < n; k++)
137136
{
138137
L_[j][k] = 0.0;
139138
}
@@ -153,7 +152,7 @@ Cholesky<Real>::Cholesky(const Array2D<Real> &A)
153152
template <class Real>
154153
Array1D<Real> Cholesky<Real>::solve(const Array1D<Real> &b)
155154
{
156-
int k, n = L_.dim1();
155+
int n = L_.dim1();
157156
if (b.dim1() != n)
158157
return Array1D<Real>();
159158

@@ -162,7 +161,7 @@ Array1D<Real> Cholesky<Real>::solve(const Array1D<Real> &b)
162161

163162

164163
// Solve L*y = b;
165-
for ( k = 0; k < n; k++)
164+
for (int k = 0; k < n; k++)
166165
{
167166
for (int i = 0; i < k; i++)
168167
x[k] -= x[i]*L_[k][i];
@@ -171,7 +170,7 @@ Array1D<Real> Cholesky<Real>::solve(const Array1D<Real> &b)
171170
}
172171

173172
// Solve L'*X = Y;
174-
for ( k = n-1; k >= 0; k--)
173+
for (int k = n-1; k >= 0; k--)
175174
{
176175
for (int i = k+1; i < n; i++)
177176
x[k] -= x[i]*L_[i][k];

GEMS3K/jama_lu.h

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33

44
#include "tnt.h"
55
#include <algorithm>
6-
#include "v_detail.h"
76
using namespace TNT;
87
using namespace std;
98

@@ -82,16 +81,16 @@ class LU
8281
// Outer loop.
8382

8483
for (int j = 0; j < n; j++) {
85-
int i;
84+
8685
// Make a copy of the j-th column to localize references.
8786

88-
for ( i = 0; i < m; i++) {
87+
for (int i = 0; i < m; i++) {
8988
LUcolj[i] = LU_[i][j];
9089
}
9190

9291
// Apply previous transformations.
9392

94-
for ( i = 0; i < m; i++) {
93+
for (int i = 0; i < m; i++) {
9594
LUrowi = LU_[i];
9695

9796
// Most of the time is spent in the following dot product.
@@ -108,8 +107,8 @@ class LU
108107
// Find pivot and exchange if necessary.
109108

110109
int p = j;
111-
for ( i = j+1; i < m; i++) {
112-
if (fabs(LUcolj[i]) > fabs(LUcolj[p])) {
110+
for (int i = j+1; i < m; i++) {
111+
if (abs(LUcolj[i]) > abs(LUcolj[p])) {
113112
p = i;
114113
}
115114
}
@@ -128,7 +127,7 @@ class LU
128127

129128
// Compute multipliers.
130129

131-
if ( (j < m) && noZero(LU_[j][j]) ) {
130+
if ( (j < m) && (LU_[j][j] != 0.0) ) {
132131
for (int ii = j+1; ii < m; ii++) {
133132
LU_[ii][j] /= LU_[j][j];
134133
}
@@ -144,7 +143,7 @@ class LU
144143

145144
int isNonsingular () {
146145
for (int j = 0; j < n; j++) {
147-
if ( approximatelyZero( LU_[j][j] ))
146+
if (LU_[j][j] == 0)
148147
return 0;
149148
}
150149
return 1;
@@ -270,7 +269,7 @@ class LU
270269

271270
Array1D<Real> solve (const Array1D<Real> &b)
272271
{
273-
int k;
272+
274273
/* Dimensions: A is mxn, X is nxk, B is mxk */
275274

276275
if (b.dim1() != m) {
@@ -284,14 +283,14 @@ class LU
284283
Array1D<Real> x = permute_copy(b, piv1);
285284

286285
// Solve L*Y = B(piv)
287-
for ( k = 0; k < n; k++) {
286+
for (int k = 0; k < n; k++) {
288287
for (int i = k+1; i < n; i++) {
289288
x[i] -= x[k]*LU_[i][k];
290289
}
291290
}
292291

293292
// Solve U*X = Y;
294-
for ( k = n-1; k >= 0; k--) {
293+
for (int k = n-1; k >= 0; k--) {
295294
x[k] /= LU_[k][k];
296295
for (int i = 0; i < k; i++)
297296
x[i] -= x[k]*LU_[i][k];

GEMS3K/s_solmod3.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@
2828
//-------------------------------------------------------------------
2929

3030
#include "s_solmod.h"
31-
//#include "v_detail.h"
31+
#include "v_detail.h"
3232

3333
//=============================================================================================
3434
// Implementation of ideal mixing model for multicomponent solid solutions
@@ -2433,7 +2433,7 @@ long int TBerman::ExcessPart()
24332433
if( y0jsm <= 0. )
24342434
continue; // skip - this moiety is not present on s site in this end member
24352435

2436-
if (y[s][m] == 0. && y0jsm > 0.) // DM 08.03.2024 // to prevent zerodivide in eq (5.2-3)
2436+
if (approximatelyZero(y[s][m]) && y0jsm > 0.) // DM 08.03.2024 // to prevent zerodivide in eq (5.2-3)
24372437
continue;
24382438

24392439
// looking through the parameters list

GEMS3K/s_solmod5.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ using namespace std;
3131
//#include "verror.h"
3232
#include "s_solmod.h"
3333
#include "jsonconfig.h"
34+
#include "v_detail.h"
3435

3536
//=============================================================================================
3637
// SIT model (NEA version) reimplementation for aqueous electrolyte solutions
@@ -1573,7 +1574,7 @@ void TPitzer::ETHETAS(double ZJ, double ZK, double I, double DH_term, double& et
15731574
//*etheta = 0.0;
15741575
//*ethetap = 0.0;
15751576

1576-
if (ZJ == ZK)
1577+
if (essentiallyEqual(ZJ, ZK))
15771578
return /*(OK)*/;
15781579

15791580
const double XCON = 6.0e0 * DH_term * sqrt(I);

0 commit comments

Comments
 (0)