From dfe4a6505a462e3446183f1baf975cd0474ca9dc Mon Sep 17 00:00:00 2001 From: David Parkhurst Date: Fri, 20 Sep 2024 08:51:21 -0600 Subject: [PATCH 1/6] mixing by water mass times mixing fraction --- mytest/mix_unequal | 17 ++++++++++ src/step.cpp | 79 ++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 96 insertions(+) create mode 100644 mytest/mix_unequal diff --git a/mytest/mix_unequal b/mytest/mix_unequal new file mode 100644 index 000000000..0fedff45c --- /dev/null +++ b/mytest/mix_unequal @@ -0,0 +1,17 @@ +database ../database/phreeqc.dat +SOLUTION 1 +-temp 10 +Na 1 +Cl 1 +-water 0.4 +END +SOLUTION 2 +-temp 20 +K 10 +Br 10 +-water 0.6 +END +MIX +1 0.4 +2 0.6 +END \ No newline at end of file diff --git a/src/step.cpp b/src/step.cpp index be02a1f43..b8553a27d 100644 --- a/src/step.cpp +++ b/src/step.cpp @@ -610,6 +610,8 @@ add_surface(cxxSurface *surface_ptr) } return (OK); } +//#define USE_NEW_ACCOUNTING +#ifdef USE_NEW_ACCOUNTING /* ---------------------------------------------------------------------- */ int Phreeqc:: add_mix(cxxMix *mix_ptr) @@ -620,6 +622,7 @@ add_mix(cxxMix *mix_ptr) * and other variables. */ LDBLE sum_fractions, intensive, extensive; + LDBLE sum_fractions_water=0, sum_positive_water=0, intensive_water=0, extensive_water=0; cxxSolution *solution_ptr; int count_positive; LDBLE sum_positive; @@ -634,10 +637,21 @@ add_mix(cxxMix *mix_ptr) std::map::const_iterator it; for (it = mix_ptr->Get_mixComps().begin(); it != mix_ptr->Get_mixComps().end(); it++) { + solution_ptr = Utilities::Rxn_find(Rxn_solution_map, it->first); + if (solution_ptr == NULL) + { + error_string = sformatf("Mix solution not found, %d.", + it->first); + error_msg(error_string, CONTINUE); + input_error++; + continue; + } sum_fractions += it->second; + sum_fractions_water += it->second * solution_ptr->Get_mass_water(); if (it->second > 0) { sum_positive += it->second; + sum_positive_water += it->second * solution_ptr->Get_mass_water(); count_positive++; } } @@ -653,8 +667,72 @@ add_mix(cxxMix *mix_ptr) continue; } extensive = it->second; + extensive_water = it->second * solution_ptr->Get_mass_water(); intensive = extensive / sum_fractions; + intensive_water = extensive_water / sum_fractions_water; + if (count_positive < (int) mix_ptr->Get_mixComps().size()) + { + if (it->second > 0) + { + intensive = extensive / sum_positive; + intensive_water = extensive_water / sum_positive; + } + else + { + intensive = 0; + } + } + add_solution(solution_ptr, extensive, intensive_water); + } + return (OK); +} +#else +/* ---------------------------------------------------------------------- */ +int Phreeqc:: +add_mix(cxxMix* mix_ptr) +/* ---------------------------------------------------------------------- */ +{ + /* + * calls add_solution to accumulate all data in master->totals + * and other variables. + */ + LDBLE sum_fractions, intensive, extensive; + cxxSolution* solution_ptr; + int count_positive; + LDBLE sum_positive; + + if (mix_ptr == NULL) + return (OK); + if (mix_ptr->Get_mixComps().size() == 0) + return (OK); + sum_fractions = 0.0; + sum_positive = 0.0; + count_positive = 0; + std::map::const_iterator it; + for (it = mix_ptr->Get_mixComps().begin(); it != mix_ptr->Get_mixComps().end(); it++) + { + sum_fractions += it->second; + if (it->second > 0) + { + sum_positive += it->second; + count_positive++; + } + } + for (it = mix_ptr->Get_mixComps().begin(); it != mix_ptr->Get_mixComps().end(); it++) + { + solution_ptr = Utilities::Rxn_find(Rxn_solution_map, it->first); + if (solution_ptr == NULL) + { + error_string = sformatf("Mix solution not found, %d.", + it->first); + error_msg(error_string, CONTINUE); + input_error++; + continue; + } + extensive = it->second; + intensive = extensive / sum_fractions; + if (count_positive < (int)mix_ptr->Get_mixComps().size()) { if (it->second > 0) { @@ -669,6 +747,7 @@ add_mix(cxxMix *mix_ptr) } return (OK); } +#endif /* ---------------------------------------------------------------------- */ int Phreeqc:: add_pp_assemblage(cxxPPassemblage *pp_assemblage_ptr) From 9b1c36846ad419192da8382eb482efe7d0fb35b8 Mon Sep 17 00:00:00 2001 From: David Parkhurst Date: Fri, 20 Sep 2024 09:57:39 -0600 Subject: [PATCH 2/6] account for water mass in addition to mixing fractions --- mytest/mix_unequal | 21 ++++++++++++++++++++- mytest/mix_unequal_101.sel | 5 +++++ src/step.cpp | 2 +- 3 files changed, 26 insertions(+), 2 deletions(-) create mode 100644 mytest/mix_unequal_101.sel diff --git a/mytest/mix_unequal b/mytest/mix_unequal index 0fedff45c..636cb3699 100644 --- a/mytest/mix_unequal +++ b/mytest/mix_unequal @@ -1,4 +1,12 @@ database ../database/phreeqc.dat +SELECTED_OUTPUT 101 + -file mix_unequal_101.sel +USER_PUNCH 101 + -headings Mu SC + -start +10 PUNCH STR_F$(MU, 20, 12) +20 PUNCH STR_F$(SC, 20, 10) + -end SOLUTION 1 -temp 10 Na 1 @@ -11,7 +19,18 @@ K 10 Br 10 -water 0.6 END -MIX +MIX 1 +# T = (0.4*0.4*10 + 0.6*0.6*20)/(0.16+0.34) = 16.92, mass = 0.52 +# Cl = (0.4*0.4*1)/0.52 = 0.3077 mmol/kgw +# K = (0.6*0.6*10)/0.52 = 6.92 mmol/kgw 1 0.4 2 0.6 +END + +# T = (0.4*0.2*10 + 0.6*0.7*20)/(0.08+0.34) = 18.4, mass = (0.4*0.2+0.6*0.7) = 0.5 +# Cl = (0.4*0.2*1)/0.5 = 0.3077 mmol/kgw = 0.16 +# K = (0.6*0.7*10)/0.5 = 6.92 mmol/kgw = 8.4 +MIX +1 0.2 +2 0.7 END \ No newline at end of file diff --git a/mytest/mix_unequal_101.sel b/mytest/mix_unequal_101.sel new file mode 100644 index 000000000..07b27d3b6 --- /dev/null +++ b/mytest/mix_unequal_101.sel @@ -0,0 +1,5 @@ + Mu SC + 0.001000066900 86.7123676799 + 0.010000092689 1291.7967477434 + 0.007230851816 873.0591328226 + 0.008560087209 1068.6105946250 diff --git a/src/step.cpp b/src/step.cpp index b8553a27d..9afc78bd0 100644 --- a/src/step.cpp +++ b/src/step.cpp @@ -610,7 +610,7 @@ add_surface(cxxSurface *surface_ptr) } return (OK); } -//#define USE_NEW_ACCOUNTING +#define USE_NEW_ACCOUNTING #ifdef USE_NEW_ACCOUNTING /* ---------------------------------------------------------------------- */ int Phreeqc:: From 8990faab9a98c5d03cfa7ffaa3863adb9e961462 Mon Sep 17 00:00:00 2001 From: David Parkhurst Date: Fri, 20 Sep 2024 09:58:43 -0600 Subject: [PATCH 3/6] added mix_unequal to cmake lists --- mytest/CMakeLists.txt | 1 + 1 file changed, 1 insertion(+) diff --git a/mytest/CMakeLists.txt b/mytest/CMakeLists.txt index 913ab2636..b8f966af2 100644 --- a/mytest/CMakeLists.txt +++ b/mytest/CMakeLists.txt @@ -255,6 +255,7 @@ set(TESTS minteqv4 missing_surf_related_equi missing_surf_related_kin + mix_unequal mixes mmb mmb2 From 537f5911c76d7e8978f87030a2cd45de30817bc1 Mon Sep 17 00:00:00 2001 From: David Parkhurst Date: Mon, 23 Sep 2024 16:45:20 -0600 Subject: [PATCH 4/6] Fix ah2o in adding a solution. Fixed bad_graph database. --- mytest/bad_graph | 2 +- src/Solution.cxx | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/mytest/bad_graph b/mytest/bad_graph index e0e5d7842..726005ca9 100644 --- a/mytest/bad_graph +++ b/mytest/bad_graph @@ -1,4 +1,4 @@ -DATABASE C:\GitPrograms\phreeqc3-1\database\llnl.dat +DATABASE ../database/llnl.dat SELECTED_OUTPUT 101 -file bad_graph_101.sel USER_PUNCH 101 diff --git a/src/Solution.cxx b/src/Solution.cxx index a326adf56..9bf4a56ea 100644 --- a/src/Solution.cxx +++ b/src/Solution.cxx @@ -1409,7 +1409,7 @@ cxxSolution::add(const cxxSolution & addee, LDBLE extensive) this->ph = f1 * this->ph + f2 * addee.ph; this->pe = f1 * this->pe + f2 * addee.pe; this->mu = f1 * this->mu + f2 * addee.mu; - this->ah2o = f1 * this->mu + f2 * addee.ah2o; + this->ah2o = f1 * this->ah2o + f2 * addee.ah2o; this->total_h += addee.total_h * extensive; this->total_o += addee.total_o * extensive; this->cb += addee.cb * extensive; From 34727efc7bc091db401dc408c76ce3d095bd791c Mon Sep 17 00:00:00 2001 From: David Parkhurst Date: Sun, 6 Oct 2024 20:42:44 -0600 Subject: [PATCH 5/6] Marked old error in mix. Updated test case. --- mytest/mix_unequal | 5 +++-- mytest/mix_unequal_101.sel | 10 +++++----- src/step.cpp | 4 +--- 3 files changed, 9 insertions(+), 10 deletions(-) diff --git a/mytest/mix_unequal b/mytest/mix_unequal index 636cb3699..6ef86a3ab 100644 --- a/mytest/mix_unequal +++ b/mytest/mix_unequal @@ -2,10 +2,11 @@ database ../database/phreeqc.dat SELECTED_OUTPUT 101 -file mix_unequal_101.sel USER_PUNCH 101 - -headings Mu SC + -headings Mu SC TC -start 10 PUNCH STR_F$(MU, 20, 12) 20 PUNCH STR_F$(SC, 20, 10) +30 PUNCH STR_F$(TC, 20, 10) -end SOLUTION 1 -temp 10 @@ -20,7 +21,7 @@ Br 10 -water 0.6 END MIX 1 -# T = (0.4*0.4*10 + 0.6*0.6*20)/(0.16+0.34) = 16.92, mass = 0.52 +# T = (0.4*0.4*10 + 0.6*0.6*20)/(0.16+0.36) = 16.92307692, mass = 0.52 # Cl = (0.4*0.4*1)/0.52 = 0.3077 mmol/kgw # K = (0.6*0.6*10)/0.52 = 6.92 mmol/kgw 1 0.4 diff --git a/mytest/mix_unequal_101.sel b/mytest/mix_unequal_101.sel index 07b27d3b6..a1ad39e86 100644 --- a/mytest/mix_unequal_101.sel +++ b/mytest/mix_unequal_101.sel @@ -1,5 +1,5 @@ - Mu SC - 0.001000066900 86.7123676799 - 0.010000092689 1291.7967477434 - 0.007230851816 873.0591328226 - 0.008560087209 1068.6105946250 + Mu SC TC + 0.001000066900 86.7123676711 10.0000000000 + 0.010000092689 1291.7967478544 20.0000000000 + 0.007230851816 873.0591329232 16.9230769231 + 0.008560087209 1068.6105947361 18.4000000000 diff --git a/src/step.cpp b/src/step.cpp index 9afc78bd0..d46066d21 100644 --- a/src/step.cpp +++ b/src/step.cpp @@ -610,8 +610,6 @@ add_surface(cxxSurface *surface_ptr) } return (OK); } -#define USE_NEW_ACCOUNTING -#ifdef USE_NEW_ACCOUNTING /* ---------------------------------------------------------------------- */ int Phreeqc:: add_mix(cxxMix *mix_ptr) @@ -687,7 +685,7 @@ add_mix(cxxMix *mix_ptr) } return (OK); } -#else +#ifdef SKIP_ERROR /* ---------------------------------------------------------------------- */ int Phreeqc:: add_mix(cxxMix* mix_ptr) From c59a7d08cefeb294607a54f15942b07d34a7c637 Mon Sep 17 00:00:00 2001 From: David Parkhurst Date: Tue, 8 Oct 2024 08:09:11 -0600 Subject: [PATCH 6/6] Tony's fix in heat transport --- src/transport.cpp | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) diff --git a/src/transport.cpp b/src/transport.cpp index 6e69e8df7..a98fe718a 100644 --- a/src/transport.cpp +++ b/src/transport.cpp @@ -1653,14 +1653,17 @@ init_heat_mix(int l_nmix) { if (implicit) { - LDBLE viscos_f0; + LDBLE viscos_f; l_heat_nmix = l_nmix; for (i = 1; i <= count_cells + 1; i++) { heat_mix_array[i - 1] = heat_mix_array[i] / l_heat_nmix; /* for implicit, m[i] has mixf with higher cell */ - viscos_f0 = sol_D[i - 1].viscos_f0 * exp(heat_diffc / sol_D[i - 1].tk_x - heat_diffc / 298.15); - viscos_f0 += sol_D[i].viscos_f0 * exp(heat_diffc / sol_D[i].tk_x - heat_diffc / 298.15); - heat_mix_array[i - 1] *= (viscos_f0 / 2); + if (print_viscosity) + { + viscos_f = sol_D[i - 1].viscos_f * exp(heat_diffc / sol_D[i - 1].tk_x - heat_diffc / 298.15); + viscos_f += sol_D[i].viscos_f * exp(heat_diffc / sol_D[i].tk_x - heat_diffc / 298.15); + heat_mix_array[i - 1] *= (viscos_f / 2); + } } } else @@ -4352,9 +4355,9 @@ find_J(int icell, int jcell, LDBLE mixf, LDBLE DDt, int stagnant) b_j *= sol_D[icell].spec[i].Dwt; else { - dum2 = sol_D[icell].spec[i].Dwt / sol_D[icell].viscos_f0; + dum2 = sol_D[icell].spec[i].Dwt / sol_D[icell].viscos_f; dum2 *= exp(sol_D[icell].spec[i].dw_t / sol_D[jcell].tk_x - sol_D[icell].spec[i].dw_t / sol_D[icell].tk_x); - dum2 *= sol_D[jcell].viscos_f0; + dum2 *= sol_D[jcell].viscos_f; b_j *= dum2; } if (sol_D[icell].spec[i].dw_a_v_dif) @@ -4463,9 +4466,9 @@ find_J(int icell, int jcell, LDBLE mixf, LDBLE DDt, int stagnant) b_i *= sol_D[jcell].spec[j].Dwt; else { - dum2 = sol_D[jcell].spec[j].Dwt / sol_D[jcell].viscos_f0; + dum2 = sol_D[jcell].spec[j].Dwt / sol_D[jcell].viscos_f; dum2 *= exp(sol_D[jcell].spec[j].dw_t / sol_D[icell].tk_x - sol_D[jcell].spec[j].dw_t / sol_D[jcell].tk_x); - dum2 *= sol_D[icell].viscos_f0; + dum2 *= sol_D[icell].viscos_f; b_i *= dum2; } if (sol_D[icell].spec[i].dw_a_v_dif)