Jump to content
Geochemist's Workbench Support Forum

Batch run in React with different input


WeiX

Recommended Posts

Hi, I am doing a reaction path modeling in React. React 5 minerals with a ground water and see the equilibrium status with different fixed CO2(aq) concentrations. I am trying to change the CO2(aq) input from 0 to 1.2 mol/kg (and other parameters in the future). I did this manually for 10 input concentrations and realized it's labor-intensive. The results we want are the Step #0 and the last Step. I have to open the txt result file and manually find these two steps. I learnt that I can write script in GWB command window to add in some loops to run and report in batches. I got stuck in the first step. In the command window of React, it would not allow me to type and edit script once I hit "enter". Is there a different window or a command I need to put in to write React script without running each line? Like a Python shell window? Thanks. (I may have other questions regarding the script in the future and I will put in here in the same topic)

Link to comment
Share on other sites

Hello Wei,

The Command pane in the React graphical user interface is used for entering commands to configure the current React instance. You can configure your React instance faster in the Command pane than clicking through various buttons on the interface. With the description you provided above, I think what you would want to use is probably the Plug-in feature. With the Plug-in feature, you can set up a script in a programming language of your choice and then call React to solve the problem and report the results. If you would like to use Python for this, you can get started by following the setup instructions in the GWB Reference Manual for Python under the Plug-in Feature chapter. If you are installing Python, make sure that you are using the same version as the GWB installed (64-bit vs. 32-bit) . There are example files (i.e. GWBplugin_Python_example1, GWBplugin_Python_example2)  provided in the src subfolder where you have The GWB installed. I would also recommend looking at the Report Command chapter to see how to return results calculated by a GWB program.

Please note that if you are using GWB release 10 or earlier, the Plug-in setup instruction and the Report command is listed in the Appendix of the Reference Manual.

Hope this helps,
Jia Wang

Link to comment
Share on other sites

Hi Wei,

Just to add a little bit more detail with regards to option reading in files to React. You can also use a simple text editor (e.g. Notepad) to prepare scripts for React. You would simply need to save the text file with a .rea extension and read it into React. Within a script for React, you can also include control statements (see Control Script chapter in the Reference Manual) for additional options to report results from React. An example using a control script to to add the results of GWB calculations to a spreadsheet containing multiple chemical analysis is provided in the Control script chapter. 

Best regards,
Jia Wang

Link to comment
Share on other sites

Thanks. The Notepad was exactly what I was asking. I tried to add a few loops to change the CO2(aq) input. It seems it did run for 11 iterations in the Result panel (with 11 successful reaction paths and 116 steps in each path. However, when I click the view results, it only gave me the most recent reaction path results. How do I report result after each iteration? Currently, I don't even know if the CO2(aq) is changing in each iteration... the result panel only shows the general status of each iteration. 

For example, if I want to report pH at step #0 of each CO2(aq) input, my script is below. But it won't report what I want, I only see the normal result txt file with the CO2(aq)=1.2 mol/kg iteration. 

# React script, batch run example
data = "C:\Program Files\Gwb\Gtdata\thermo.tdat" verify
temperature = 25 C
H2O   = .005 kg
Na+   = 1000 mg/l
Ca++  = 20 mg/l
Cl-   = 500 mg/l
SO4-- = 2000 mg/l
swap CO2(aq) for HCO3-
SiO2(aq)     = 1e-7 mg/l
Al+++        = 1e-7 mg/l

script start
for {set i 0} {$i<11} {incr i 1} {
eval {"CO2(aq)=" [expr {1.2/10*$i}] mol/kg}

balance on H+

react 80 g of Quartz
react 10 g of Kaolinite
react 2.5 g of Albite
react 5 g of Calcite

fix activity of CO2(aq)
go


puts "The control script $i iteration"
report pH 0

}

 

Link to comment
Share on other sites

Hello Wei,

I think you are very close with your script. Here are a few suggestions that I have.

To report pH from your script to a text file, please see the example given in Multiple Analysis chapter of the Reference manual. Unless you specify a file to write to, the output from your ‘puts’ statements will show up in the Command pane, you should check there to see if you are writing out the correct results.

With regards to writing out results, a relatively simple way to do this is to set the value you wish to report, pH for example, as a Tcl variable and then write it out in a ‘puts’ statement. So perhaps something like this:

set go_initial_ph [eval report pH]
puts “Go initial pH = $go_initial_pH”

You can find an example of this in section 6.2 Interacting with the application program and 6.3 Example control script of the GWB Reference Manual.

With control scripts and report commands, you are only able to report the final results or in your specific case, final pH, of the simulation. If you would like the pH of the fluid after React evaluates the initial conditions, you can perform a ‘go initial’ run and then retrieve the pH value. Then rerun your simulation using ‘go’ and React will trace the entire reaction path, and then retrieve the pH again.

Hope this helps,
Jia Wang

 

Link to comment
Share on other sites

Hi Jia, 

This very helpful. I successfully reported results in the command panel. The final results of each run is what we need for now. I added one more variable (changing calcite to react) in the script and I have two more questions regarding the updated script (noted below). 

Question 1: How do I react non-integral amount of calcite? I tried to put expr{$j+0.5} directly in the react command but it would not work. I also tried to set a new variable input_cal as $j+0.5 and put $input_cal in React, did not work. eval Calcite= $input_cal did not work either with React. The only way works with increasing calcite amount is to put $j directly after React. 

Question 2: In the txt result report file, It only listed the result from the last run. I tried a few different foreach commands but they did not work. How do I put the result line by line in the txt file? 

# React script, batch run example
data = "C:\Program Files\Gwb\Gtdata\thermo.tdat" verify
temperature = 25 C
H2O   = .005 kg
Na+   = 1000 mg/l
Ca++  = 20 mg/l
Cl-   = 500 mg/l
SO4-- = 2000 mg/l
swap CO2(aq) for HCO3-
SiO2(aq)     = 1e-7 mg/l
Al+++        = 1e-7 mg/l

script start
clear all

# vary CO2(aq) input
for {set i 0} {$i<4} {incr i 1} {
set input_CO2 [expr {1.2/3*$i+0.005}]
eval {"CO2(aq)=" $input_CO2 mol/kg}
fix activity of CO2(aq)

# vary calcite input
for {set j 0} {$j<4} {incr j 1} {

# Question 1 react minerals non-integer amount 
react $j g Calcite

react 80 g of Quartz
react 10 g of Kaolinite
react 2.5 g of Albite

balance on H+

go

report set_digits 4
report set_units ?

set go_final_pH [eval report pH]
set go_final_Ca [eval report concentration aqueous Ca++]

# report in command
puts "CO2(aq) = $input_CO2 mol/kg"
puts "calcite = $j g"
puts "pH = $go_final_pH"
puts "Ca++ = $go_final_Ca mol/kg"

# Question 2 report in txt 
set out_id [open "Batch_output.txt" w]
fconfigure $out_id -encoding unicode
puts $out_id "CO2(aq)(mol/kg)\tCalcite(g)\tpH\tCa++" 

foreach a [lrange $out_id 0 end] {

puts -nonewline $out_id "$input_CO2\t"
puts -nonewline $out_id "$j\t"
puts -nonewline $out_id "$go_final_pH\t"
puts $out_id "$go_final_Ca"

}

}

}
close $out_id
 

Thanks,

Wei

Link to comment
Share on other sites

Hello Wei,

I am no expert in Tcl so perhaps there's a more elegant solution to doing these things. With regards to your first question, it seems like the incr command will only take integer values. A way around it would be to use the expr command instead. Here is a short explanation and a good example for that: https://stackoverflow.com/questions/23653209/how-to-increment-variable-by-0-5-in-using-for-loop 

I noticed in the example of the Multiple Analysis chapter of the Reference manual, the section of code specifying the txt file for writing output results is placed near the beginning of script start, before any loops. It seems to have worked when I moved

# Question 2 report in txt 
set out_id [open "Batch_output.txt" w]
fconfigure $out_id -encoding unicode
puts $out_id "CO2(aq)(mol/kg)\tCalcite(g)\tpH\tCa++" 

to right below 

script start
clear all

That way, you are writing out results after each increment change in your loops and not for just the final CO2(aq) concentration and calcite mass. 

Hope this helps,
Jia Wang

Link to comment
Share on other sites

The output file works now. For the non-integer increment, I did not succeed with expr command. It just could not recognize it somehow. But I change the unit of reacted calcite to mg. Then change the increment to 500. 500 mg is 0.5 g anyway. Problem solved anyway. Thanks a lot, Jia!

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
×
×
  • Create New...