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
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
Ruben Heinrich
committed
},
#Sets a sim_input list object
set_sim_input = function(name, value) {
private$.sim_input[[name]] <- value
Ruben Heinrich
committed
},
#Adds an element to a sim_input list object
add_to_sim_input = function(name, value) {
private$.sim_input[[name]] <- c(private$.sim_input[[name]], value)
},
#Sets a sim_input object parameter
Ruben Heinrich
committed
set_sim_input_obj_param = function(obj_name, obj_param_name, value) {
private$.sim_input[[obj_name]]$obj_param_name <- value
},
#Adds an element to a sim_input object parameter which is a list
add_to_sim_input_obj_param = function(obj_name, obj_param_name, value) {
private$.sim_input[[obj_name]]$obj_param_name <-
c(private$.sim_input[[obj_name]]$obj_param_name, value)
},
Ruben Heinrich
committed
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
add_sim_output = function(name, value) {
private$.sim_output[[name]] <- value
}
),
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
Ruben Heinrich
committed
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
)
)
#============================== 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)
}
}