TITLE Example 12.--Advective and diffusive transport of heat and solutes.
      Two different boundary conditions at column ends.
      After diffusion temperature should equal Na-conc in mmol/l.
SOLUTION 0   24.0 mM KNO3
    units mol/kgw
    temp  0     # Incoming solution 0C
    pH    7.0
    pe   12.0   O2(g) -0.67
    K    24.e-3
    N(5) 24.e-3
SOLUTION 1-60   0.001 mM KCl
    units mol/kgw
    temp 25    # Column is at 25C
    pH   7.0
    pe  12.0   O2(g) -0.67
    K    1e-6
    Cl   1e-6
EXCHANGE_SPECIES
    Na+ + X- = NaX
    log_k       0.0
    -gamma      4.0     0.075

    H+ + X- = HX
    log_k       -99.
    -gamma      9.0     0.0

    K+ + X- = KX
    log_k       0.0
    gamma       3.5     0.015
EXCHANGE 1-60
    KX    0.048
PRINT
   -reset   false
   -selected_output false
   -status false
SELECTED_OUTPUT
   -file    ex12.sel
   -reset   false
   -dist    true
   -high_precision  true
   -temp    true
USER_PUNCH
        -head Na_mmol K_mmol Cl_mmol
  10 PUNCH TOT("Na")*1000, TOT("K")*1000, TOT("Cl")*1000
TRANSPORT           # Make column temperature 0C, displace Cl
   -cells   60
   -shifts  60
   -flow_direction  forward
   -boundary_conditions flux  flux
   -lengths 60*0.333333
   -dispersivities        60*0.0     # No dispersion
   -diffusion_coefficient 0.0     # No diffusion
   -thermal_diffusion     1.0     # No retardation for heat
END
SOLUTION 0   Fixed temp 24C, and NaCl conc (first type boundary cond) at inlet
    units  mol/kgw
    temp 24
    pH  7.0
    pe  12.0   O2(g) -0.67
    Na  24.e-3
    Cl  24.e-3
SOLUTION 58-60  Same as soln 0 in cell 20 at closed column end (second type boundary cond)
    units  mol/kgw
    temp 24
    pH  7.0
    pe  12.0   O2(g) -0.67
    Na  24.e-3
    Cl  24.e-3
EXCHANGE 58-60
    NaX  0.048
PRINT
   -selected_output true
TRANSPORT            # Diffuse 24C, NaCl solution from column end
   -shifts 1
   -flow_direction         diffusion
   -boundary_conditions    constant  closed
   -thermal_diffusion      3.0       # heat is retarded equal to Na
   -diffusion_coefficient  0.3e-9    # m^2/s
   -time_step              1.0e+10   # 317 years give 19 mixes
USER_GRAPH 1 Example 12
   -headings Na Cl Temp Analytical
   -chart_title "Diffusion of Solutes and Heat"
   -axis_titles "Distance, in meters" "Millimoles per kilogram water", "Degrees celsius"
   -axis_scale x_axis 0 20
   -axis_scale y_axis 0 25
   -axis_scale sy_axis 0 25
   -initial_solutions false
   -plot_concentration_vs x
   -start
  10 x = DIST
  20 PLOT_XY x, TOT("Na")*1000, symbol = Plus
  30 PLOT_XY x, TOT("Cl")*1000, symbol = Plus
  40 PLOT_XY x, TC, symbol = XCross, color = Magenta, symbol_size = 8, y-axis 2
  50 if (x > 10 OR SIM_TIME <= 0) THEN END
  60 DATA 0.254829592, -0.284496736, 1.421413741, -1.453152027, 1.061405429, 0.3275911
  70 READ a1, a2, a3, a4, a5, a6
# Calculate and plot Cl analytical...
  80 z = x / (2 * SQRT(3e-10 * SIM_TIME / 1.0))
  90 GOSUB 2000
  100 PLOT_XY x, 24 * erfc, color = Blue, symbol = Circle, symbol_size = 10,\
                            line_width = 0
# Calculate and plot 3 times retarded Na and temperature analytical...
  110 z = z * SQRT(3.0)
  120 GOSUB 2000
  130 PLOT_XY x, 24 * erfc, color = Blue, symbol = Circle, symbol_size = 10,\
                            line_width = 0
  140 END
  2000 REM calculate erfc...
  2050 b = 1 / (1 + a6 * z)
  2060 erfc = b * (a1 + b * (a2 + b * (a3 + b * (a4 + b * a5)))) * EXP(-(z * z))
  2080 RETURN
   -end
END