Newer
Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
#===== r2ogs6_chemical_system =====
#'r2ogs6_chemical_system
#'@description tag: chemical_system
#'@param chemical_solver string:
#'@param database string:
#'@param solution r2ogs6_solution:
#'@param mesh Optional: string:
#'@param equilibrium_reactants Optional: list, r2ogs6_phase_component:
#'@param knobs Optional: list:
#'@param kinetic_reactants Optional: list, r2ogs6_kinetic_reactant:
#'@param rates Optional: list, r2ogs6_rate:
#'@export
r2ogs6_chemical_system <- function(chemical_solver,
database,
solution,
mesh = NULL,
equilibrium_reactants = NULL,
knobs = NULL,
kinetic_reactants = NULL,
rates = NULL) {
#Coerce input
new_r2ogs6_chemical_system(
chemical_solver,
database,
solution,
mesh,
equilibrium_reactants,
knobs,
kinetic_reactants,
rates
)
}
new_r2ogs6_chemical_system <- function(chemical_solver,
database,
solution,
mesh = NULL,
equilibrium_reactants = NULL,
knobs = NULL,
kinetic_reactants = NULL,
rates = NULL) {
assertthat::assert_that(assertthat::is.string(chemical_solver))
assertthat::assert_that(assertthat::is.string(database))
assertthat::assert_that(class(solution) == "r2ogs6_solution")
validate_is_null_or_string(mesh)
if(!is.null(equilibrium_reactants)){
validate_wrapper_list(equilibrium_reactants,
"r2ogs6_phase_component")
}
if(!is.null(knobs)){
knobs <- validate_param_list(knobs,
c("max_iter",
"relative_convergence_tolerance",
"tolerance",
"step_size",
"scaling"))
}
if(!is.null(kinetic_reactants)){
validate_wrapper_list(kinetic_reactants,
"r2ogs6_kinetic_reactant")
}
if(!is.null(rates)){
validate_wrapper_list(rates,
"r2ogs6_rate")
}
structure(
list(
chemical_solver = chemical_solver,
database = database,
solution = solution,
mesh = mesh,
equilibrium_reactants = equilibrium_reactants,
knobs = knobs,
kinetic_reactants = kinetic_reactants,
rates = rates,
tag_name = "chemical_system",
is_subclass = FALSE,
attr_names = c("chemical_solver"),
flatten_on_exp = character()
),
class = "r2ogs6_chemical_system"
)
}
#===== r2ogs6_solution =====
#'r2ogs6_solution
#'@description tag: solution
#'@param temperature string | double: Temperature
#'@param pressure string | double: Pressure
#'@param pe string | double: pe
#'@param components list: Components
#'@param charge_balance Optional: string: Charge balance
#'@export
r2ogs6_solution <- function(temperature,
pressure,
pe,
components,
charge_balance = NULL) {
#Coerce input
temperature <- coerce_string_to_numeric(temperature)
pressure <- coerce_string_to_numeric(pressure)
pe <- coerce_string_to_numeric(pe)
new_r2ogs6_solution(temperature,
pressure,
pe,
components,
charge_balance)
}
new_r2ogs6_solution <- function(temperature,
pressure,
pe,
components,
charge_balance = NULL) {
assertthat::assert_that(is.double(temperature))
assertthat::assert_that(is.double(pressure))
assertthat::assert_that(is.double(pe))
assertthat::assert_that(is.character(components))
names(components) <- rep("component", length(components))
validate_is_null_or_string(charge_balance)
structure(
list(
temperature = temperature,
pressure = pressure,
pe = pe,
components = components,
charge_balance = charge_balance,
tag_name = "solution",
is_subclass = TRUE,
attr_names = character(),
flatten_on_exp = character()
),
class = "r2ogs6_solution"
)
}
#===== r2ogs6_phase_component =====
#'r2ogs6_phase_component
#'@description S3 class describing .prj phase_component
#'@param name The component name
#'@param initial_amount The initial amount of the component
#'@param saturation_index The saturation index of the component
#'@export
r2ogs6_phase_component <- function(name,
initial_amount,
saturation_index) {
#Coerce input
initial_amount <- coerce_string_to_numeric(initial_amount)
saturation_index <- coerce_string_to_numeric(saturation_index)
new_r2ogs6_phase_component(name,
initial_amount,
saturation_index)
}
new_r2ogs6_phase_component <- function(name,
initial_amount,
saturation_index) {
assertthat::assert_that(assertthat::is.string(name))
assertthat::assert_that(is.double(initial_amount))
assertthat::assert_that(is.double(saturation_index))
structure(
list(
name = name,
initial_amount = initial_amount,
saturation_index = saturation_index,
tag_name = "phase_component",
is_subclass = TRUE,
attr_names = character(),
flatten_on_exp = character()
),
class = "r2ogs6_phase_component"
)
}
#===== r2ogs6_kinetic_reactant =====
#'r2ogs6_kinetic_reactant
#'@description S3 class describing .prj kinetic_reactant
#'@param name The component name
#'@param initial_amount The initial amount of the component
#'@param chemical_formula The chemical formula of the component
#'@param fix_amount Should the amount be fixed or not?
#'@export
r2ogs6_kinetic_reactant <- function(name,
initial_amount,
chemical_formula = NULL,
fix_amount = NULL) {
#Coerce input
initial_amount <- coerce_string_to_numeric(initial_amount)
new_r2ogs6_kinetic_reactant(name,
initial_amount,
chemical_formula,
fix_amount)
}
new_r2ogs6_kinetic_reactant <- function(name,
initial_amount,
chemical_formula = NULL,
fix_amount = NULL) {
assertthat::assert_that(assertthat::is.string(name))
assertthat::assert_that(is.double(initial_amount))
validate_is_null_or_string(chemical_formula,
fix_amount)
structure(
list(
name = name,
initial_amount = initial_amount,
chemical_formula = chemical_formula,
fix_amount = fix_amount,
tag_name = "kinetic_reactant",
is_subclass = TRUE,
attr_names = character(),
flatten_on_exp = character()
),
class = "r2ogs6_kinetic_reactant"
)
}
#===== r2ogs6_rate =====
#'r2ogs6_rate
#'@description S3 class describing .prj rate
#'@param kinetic_reactant string: References a kinetic_reactant object
#'@param expression character: Statements
#'@export
r2ogs6_rate <- function(kinetic_reactant,
expression) {
#Coerce input
new_r2ogs6_rate(kinetic_reactant, expression)
}
new_r2ogs6_rate <- function(kinetic_reactant,
expression) {
assertthat::assert_that(assertthat::is.string(kinetic_reactant))
assertthat::assert_that(is.character(expression))
names(expression) <- rep("statement", length(expression))
structure(
list(
kinetic_reactant = kinetic_reactant,
expression = expression,
tag_name = "rate",
is_subclass = TRUE,
attr_names = character(),
flatten_on_exp = character()
),
class = "r2ogs6_rate"
)
}