Newer
Older
Ruben Heinrich
committed
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
#============================== R6 ================================
#'Constructor for the OGS6 base class
OGS6 <- R6::R6Class("OGS6",
public = list(
initialize = function(sim_name,
sim_id,
sim_path) {
# 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))
private$.sim_input <- list()
private$.sim_output <- list()
private$.sim_name <- sim_name
private$.sim_id <- sim_id
private$.sim_path <- sim_path
},
add_sim_input = function(name, value) {
private$.sim_input[[name]] <- value
},
set_sim_input_obj_param = function(obj_name, obj_param_name, value) {
private$.sim_input[[obj_name]]$obj_param_name <- value
},
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)
}
}
),
private = list(
.sim_input = NULL,
.sim_output = NULL,
.sim_name = NULL,
.sim_id = NULL,
.sim_path = NULL
)
)
#============================== 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)
}
}