Newer
Older
Ruben Heinrich
committed
#============================== R6 ================================
#'OGS6
#'@description Constructor for the OGS6 base class
#'@param sim_name The name of the simulation
#'@param sim_id The ID of the simulation
#'@param sim_path The path where all relevant files for the simulation will be saved
#'@param ogs_bin_path Path to OpenGeoSys6 /bin directory
Ruben Heinrich
committed
OGS6 <- R6::R6Class("OGS6",
public = list(
initialize = function(sim_name,
sim_id,
sim_path,
ogs_bin_path) {
Ruben Heinrich
committed
# Basic validation
assertthat::assert_that(assertthat::is.string(sim_name))
assertthat::assert_that(is.integer(sim_id))
assertthat::assert_that(assertthat::is.string(sim_path))
assertthat::assert_that(assertthat::is.string(ogs_bin_path))
Ruben Heinrich
committed
private$.sim_input <- list()
private$.sim_output <- list()
private$.sim_name <- sim_name
private$.sim_id <- sim_id
private$.sim_path <- sim_path
private$.ogs_bin_path <- ogs_bin_path
private$.meshes <- list()
private$.geometry <- NULL
private$.processes <- list()
private$.time_loop <- NULL
private$.media <- list()
private$.parameters <- list()
private$.curves <- list()
private$.process_variables <- list()
private$.nonlinear_solvers <- list()
private$.linear_solvers <- list()
private$.test_definition <- list()
Ruben Heinrich
committed
},
add_sim_output = function(name, value) {
private$.sim_output[[name]] <- value
Ruben Heinrich
committed
},
add_mesh = function(mesh){
assertthat::assert_that(assertthat::is.string(mesh))
private$.meshes <- c(private$.meshes, mesh)
},
add_geometry = function(geometry){
assertthat::assert_that(assertthat::is.string(geometry))
private$.geometry <- c(private$.geometry, geometry)
Ruben Heinrich
committed
},
add_process = function(process){
assertthat::assert_that(class(process) == "r2ogs6_process")
private$.processes <- c(private$.processes, process)
},
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
add_time_loop = function(time_loop){
assertthat::assert_that(class(time_loop) == "r2ogs6_time_loop")
if(!is.null(private$.time_loop)){
warning("Overwriting time_loop variable of OGS6 object", call. = FALSE)
}
private$.time_loop <- time_loop
},
add_medium = function(medium){
assertthat::assert_that(class(medium) == "r2ogs6_medium")
private$.media <- c(private$.media, medium)
},
add_parameter = function(parameter){
assertthat::assert_that(class(parameter) == "r2ogs6_parameter")
private$.parameters <- c(private$.parameters, parameter)
},
add_curve = function(curve){
assertthat::assert_that(class(curve) == "r2ogs6_curve")
private$.curves <- c(private$.curves, curve)
},
add_process_variable = function(process_variable){
assertthat::assert_that(class(process_variable) == "r2ogs6_process_variable")
private$.process_variables <- c(private$.process_variables, process_variable)
},
add_nonlinear_solver = function(nonlinear_solver){
assertthat::assert_that(class(parameter) == "r2ogs6_nonlinear_solver")
private$.nonlinear_solvers <- c(private$.nonlinear_solvers, nonlinear_solver)
},
add_linear_solver = function(linear_solver){
assertthat::assert_that(class(linear_solver) == "r2ogs6_linear_solver")
private$.linear_solvers <- c(private$.linear_solvers, linear_solver)
},
add_vtkdiff = function(vtkdiff){
assertthat::assert_that(class(vtkdiff) == "r2ogs6_vtkdiff")
private$.test_definition <- c(private$.test_definition, vtkdiff)
},
get_status = function(){
ready_for_sim <- list_has_element(private$.processes, "process")
ready_for_sim <- obj_is_null(private$.time_loop, "time_loop")
ready_for_sim <- list_has_element(private$.media, "medium")
ready_for_sim <- list_has_element(private$.parameters, "parameter")
ready_for_sim <- list_has_element(private$.process_variables, "process_variable")
ready_for_sim <- list_has_element(private$.nonlinear_solvers, "nonlinear_solver")
ready_for_sim <- list_has_element(private$.linear_solvers, "linear_solver")
if(ready_for_sim){
cat("Your simulation object has all necessary components. You can try to start the
simulation by calling run_simulation() on your OGS6 object. Note that this will
call more validation functions so you may not be done just yet.", "\n")
}
return(invisible(ready_for_sim))
},
validate = function(){
if(!self$get_status()){
stop("There are some components missing from your OGS6 object.", call. = FALSE)
}
Ruben Heinrich
committed
}
Ruben Heinrich
committed
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
),
active = list(
sim_input = function(value) {
if (missing(value)) {
private$.sim_input
} else {
stop("To modify `$sim_input`, use set_sim_input().", call. = FALSE)
}
},
sim_output = function(value) {
if (missing(value)) {
private$.sim_output
} else {
stop("To modify `$sim_output`, use set_sim_output().", call. = FALSE)
}
},
sim_name = function(value) {
if (missing(value)) {
private$.sim_name
} else {
stop("`$sim_name` is read only", call. = FALSE)
}
},
sim_id = function(value) {
if (missing(value)) {
private$.sim_id
} else {
stop("`$sim_id` is read only", call. = FALSE)
}
},
sim_path = function(value) {
if (missing(value)) {
private$.sim_path
} else {
stop("`$sim_path` is read only", call. = FALSE)
}
},
ogs_bin_path = function(value) {
if (missing(value)) {
private$.ogs_bin_path
} else {
stop("`$ogs_bin_path` is read only", call. = FALSE)
}
Ruben Heinrich
committed
}
),
private = list(
.sim_input = NULL,
.sim_output = NULL,
.sim_name = NULL,
.sim_id = NULL,
.sim_path = NULL,
.ogs_bin_path = NULL,
.meshes = NULL,
.geometry = NULL,
.processes = NULL,
.time_loop = NULL,
.media = NULL,
.parameters = NULL,
.curves = NULL,
.process_variables = NULL,
.nonlinear_solvers = NULL,
.linear_solvers = NULL,
.test_definition = NULL
Ruben Heinrich
committed
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
)
)
#============================== S3 ================================
#'Constructor for the ogs6 base class
#'
#'@param sim_io ...
#'@param sim_name A string value representing the simulation name
#'@param sim_id An integer value representing the simulation ID
#'@param sim_path A string value describing the path where the IO files will be saved
new_ogs6 <- function(sim_io = list(input = list(), output = list()),
sim_name = character(),
sim_id = integer(),
sim_path = character()) {
# Basic validation
if (!is.character(sim_name)) {
stop("'sim_name' has to be of type character", call. = FALSE)
}
if (!is.integer(sim_id)) {
stop("'sim_id' has to be of type integer", call. = FALSE)
}
if (!is.character(sim_path)) {
stop("'sim_path' has to be of type character", call. = FALSE)
}
structure(
sim_io,
sim_name = sim_name,
sim_id = sim_id,
sim_path = sim_path,
class = "ogs6"
)
}
#' Validating functions for an ogs6 class object (to be run before a simulation is started)
validate_ogs6 <- function(ogs6_obj) {
if (!class(ogs6_obj) == "ogs6") {
stop("ogs6_obj is not of class 'ogs6' ", call. = FALSE)
}
if (is.null(x$input)) {
stop("'input' list missing.", call. = FALSE)
}
if (is.null(x$output)) {
stop("'output' list missing.", call. = FALSE)
}
}