Skip to content
GitLab
Menu
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
Marco De Lucia
RedModRphree
Commits
88a879aa
Commit
88a879aa
authored
Apr 28, 2021
by
Marco De Lucia
Browse files
Fixed demos with imports, out_bal & co in ReactTrans now assigned at the end to GlobalEnv
parent
4a6597de
Changes
6
Show whitespace changes
Inline
Side-by-side
R/Rphree_Kinetics.R
View file @
88a879aa
## Functions for dealing with simulations with kinetics
### Marco De Lucia, delucia@gfz-potsdam.de, 2009-2021
### Time-stamp: "Last modified 2021-04-28 1
6:06:07
delucia"
### Time-stamp: "Last modified 2021-04-28 1
7:23:36
delucia"
##' This function runs the generated input buffer (or a list thereof)
##' through \code{phreeqc}, which has been already loaded as
##' dependency. Also the database must be previously and explicitely
##' loaded by the user using, e.g.,
\code{db <-
##' RPhreeFile('/path/to/database.dat', is.db=TRUE)}
followed by
##'
\code{phreeqc::phrLoadDatabaseString(db)} or using one of the
##'
databases included in \code{phreeqc}, e.g.,
##'
\code{phreeqc::phrLoadDatabaseString(phreeqc.dat)}.
##'
##' Parallelization is achieved using \code{%dopar%} from package
##' loaded by the user using, e.g.,
##'
\code{db <-
RPhreeFile('/path/to/database.dat', is.db=TRUE)}
##'
followed by
##'
\code{phreeqc::phrLoadDatabaseString(db)}
##'
or using one of the databases included in \code{phreeqc}, e.g.,
##'
\code{phreeqc::phrLoadDatabaseString(phreeqc.dat)}
##' Parallelization is achieved using \code{
\
%dopar
\
%} from package
##' \code{foreach}, while the backend should have been previously set
##' with appropriate call to \code{doParallel}. At the moment the
##' function doesn't check that the SELCTED_OUTPUT block is
...
...
@@ -51,8 +51,6 @@ RunPQC <- function(input, procs=1, second=TRUE) {
}
}
else
{
## go parallel!
## old one
## res <- parallel::mclapply(input, .runPQC, mc.silent=TRUE, mc.cores=procs)
res
<-
foreach
::
foreach
(
i
=
seq_along
(
input
),
.combine
=
rbind
)
%dopar%
.runPQC
(
input
[[
i
]],
onlysecond
=
second
)
...
...
R/Rphree_Pourbaix.R
View file @
88a879aa
### Licence: LGPL version 2.1
## Time-stamp: "Last modified 2021-04-28 17:
04:27
delucia"
## Time-stamp: "Last modified 2021-04-28 17:
20:11
delucia"
##' @title Revert a string
##' @param x character vector. All element of the vector will be
...
...
@@ -439,7 +439,7 @@ Pourbaix <- function(element, pe=seq(-5,8), pH=seq(6,12), Tc=25, Patm=1, base, f
if
(
missing
(
ann.title
))
{
mymain
<-
paste
(
"Pourbaix diagram for"
,
ifelse
(
missing
(
element
),
"the specified system"
,
ifelse
(
has_valence
,
valence
,
element
)),
"\n T="
,
Tc
,
"\
U3f43
C / P="
,
Patm
,
"atm"
)
"\n T="
,
Tc
,
"\
u00B0
C / P="
,
Patm
,
"atm"
)
}
else
mymain
<-
ann.title
...
...
R/Rphree_ReactTrans.R
View file @
88a879aa
## Functions for dealing with surrogate simulations
### Marco De Lucia, delucia@gfz-potsdam.de, 2009-2021
### Time-stamp: "Last modified 2021-04-28 1
5:54:48
delucia"
### Time-stamp: "Last modified 2021-04-28 1
8:13:39
delucia"
##' This function takes the current state of a chemical system in form
...
...
@@ -294,8 +294,6 @@ ReactTranspBalanceEq <- function(setup, init, maxtime, step=c("time","iter","fix
spr_string
<-
paste0
(
"%0"
,
pad
,
"d"
)
names
(
saved_complete
)
<-
paste0
(
"step_"
,
sprintf
(
spr_string
,
seq
(
0
,
maxiter
)))
utils
::
globalVariables
(
c
(
"out_inp"
,
"out_res"
,
"out_bal"
))
out_inp
<-
vector
(
mode
=
"list"
,
length
=
length
(
maxiter
))
out_res
<-
vector
(
mode
=
"list"
,
length
=
length
(
maxiter
))
out_bal
<-
vector
(
mode
=
"list"
,
length
=
length
(
maxiter
))
...
...
@@ -406,7 +404,6 @@ ReactTranspBalanceEq <- function(setup, init, maxtime, step=c("time","iter","fix
# so that the first run on Rphree is actually one and the next ones end
time
<-
time
+
dt
iter
<-
iter
+
1
#cat("ENTERING ADV","\n")
## transform the pH/pe back into activities
state_T
<-
AdvectionPQC
(
pH2Act
(
state_C
),
inflow
=
bound
,
dx
=
dx
,
dt
=
dt
,
U
=
U
)
...
...
@@ -491,6 +488,10 @@ ReactTranspBalanceEq <- function(setup, init, maxtime, step=c("time","iter","fix
msg
(
"Parallelization cluster stopped"
)
}
msg
(
"assign out_balance, out_input and out_results to global environment for possible later use"
)
assign
(
"out_balance"
,
out_bal
,
envir
=
.GlobalEnv
)
assign
(
"out_results"
,
out_res
,
envir
=
.GlobalEnv
)
assign
(
"out_input"
,
out_inp
,
envir
=
.GlobalEnv
)
msg
(
"total time of chemistry: "
,
round
(
sum
(
timing
[,
3
]),
3
),
"seconds"
)
msg
(
"total number of simulations: "
,
sum
(
timing
[,
1
]))
...
...
@@ -604,8 +605,6 @@ ReactTranspBalanceKin <- function(setup, init, maxtime, step=c("time","iter","fi
spr_string
<-
paste0
(
"%0"
,
pad
,
"d"
)
names
(
saved_complete
)
<-
paste0
(
"step_"
,
sprintf
(
spr_string
,
seq
(
0
,
maxiter
)))
utils
::
globalVariables
(
c
(
"out_inp"
,
"out_res"
,
"out_bal"
))
out_inp
<-
vector
(
mode
=
"list"
,
length
=
length
(
maxiter
))
out_res
<-
vector
(
mode
=
"list"
,
length
=
length
(
maxiter
))
out_bal
<-
vector
(
mode
=
"list"
,
length
=
length
(
maxiter
))
...
...
@@ -711,7 +710,6 @@ ReactTranspBalanceKin <- function(setup, init, maxtime, step=c("time","iter","fi
# so that the first run on Rphree is actually one and the next ones end
time
<-
time
+
dt
iter
<-
iter
+
1
#cat("ENTERING ADV","\n")
## transform the pH/pe back into activities
state_T
<-
AdvectionPQC
(
pH2Act
(
state_C
),
inflow
=
bound
,
dx
=
dx
,
dt
=
dt
,
U
=
U
)
...
...
@@ -737,10 +735,8 @@ ReactTranspBalanceKin <- function(setup, init, maxtime, step=c("time","iter","fi
out_bal
[[
iter
]]
<-
bal
totbal
<-
apply
(
bal
,
1
,
mae
)
## cat(":: Surrogate Balance Summary:\n")
## print(summary(totbal))
## tol2 <- unname(quantile(totbal, .85))
## cat(" :RT: Balance Checked\n")
nonok
<-
which
(
totbal
>
tol
)
if
(
length
(
nonok
)
>
0
){
...
...
@@ -804,6 +800,11 @@ ReactTranspBalanceKin <- function(setup, init, maxtime, step=c("time","iter","fi
msg
(
"Parallelization cluster stopped"
)
}
msg
(
"assign out_balance, out_input and out_results to global environment for possible later use"
)
assign
(
"out_balance"
,
out_bal
,
envir
=
.GlobalEnv
)
assign
(
"out_results"
,
out_res
,
envir
=
.GlobalEnv
)
assign
(
"out_input"
,
out_inp
,
envir
=
.GlobalEnv
)
msg
(
"total time of chemistry: "
,
round
(
sum
(
timing
[,
3
]),
3
),
"seconds"
)
msg
(
"total number of simulations: "
,
sum
(
timing
[,
1
]))
msg
(
" Bye."
)
...
...
demo/demo-eq-surr-RF.R
View file @
88a879aa
### Licence: LGPL version 2.1
## Time-stamp: "Last modified 2018-08-29 15:15:50 delucia"
## Time-stamp: "Last modified 2021-04-28 18:23:19 delucia"
require
(
e1071
)
require
(
import
)
db
<-
RPhreeFile
(
system.file
(
"extdata"
,
"phreeqc_kin.dat"
,
package
=
"RedModRphree"
),
is.db
=
TRUE
)
phreeqc
::
phrLoadDatabaseString
(
db
)
...
...
demo/demo-kin-surr-RF.R
View file @
88a879aa
## Licence: LGPL version 2.1
## Time-stamp: "Last modified 20
18-05-06 21:29:53
delucia"
## Time-stamp: "Last modified 20
21-04-28 18:27:32
delucia"
library
(
RedModRphree
)
require
(
e1071
)
require
(
import
)
db
<-
RPhreeFile
(
system.file
(
"extdata"
,
"phreeqc_kin.dat"
,
package
=
"RedModRphree"
),
is.db
=
TRUE
)
base
<-
c
(
"SOLUTION 1"
,
"units mol/kgw"
,
"temp 25.0"
,
"water 1"
,
...
...
man/RunPQC.Rd
View file @
88a879aa
...
...
@@ -22,14 +22,17 @@ a data.frame containing the SELECTED_OUTPUT, ordered if
This function runs the generated input buffer (or a list thereof)
through \code{phreeqc}, which has been already loaded as
dependency. Also the database must be previously and explicitely
loaded by the user using, e.g., \code{db <-
RPhreeFile('/path/to/database.dat', is.db=TRUE)} followed by
\code{phreeqc::phrLoadDatabaseString(db)} or using one of the
databases included in \code{phreeqc}, e.g.,
\code{phreeqc::phrLoadDatabaseString(phreeqc.dat)}.
}
\details{
loaded by the user using, e.g.,
\code{db <- RPhreeFile('/path/to/database.dat', is.db=TRUE)}
followed by
\code{phreeqc::phrLoadDatabaseString(db)}
or using one of the databases included in \code{phreeqc}, e.g.,
\code{phreeqc::phrLoadDatabaseString(phreeqc.dat)}
Parallelization is achieved using \code{\%dopar\%} from package
\code{foreach}, while the backend should have been previously set
with appropriate call to \code{doParallel}. At the moment the
function doesn't check that the SELCTED_OUTPUT block is
well-formed, so this is responsibility of the user.
}
\author{
MDL
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment