diff --git a/R/prj_curves.R b/R/prj_curves.R index 50dbf3fcbe359456f2074c0ee5ee2953294e506b..e712c29cab6f04b9ae0638a21c7a6e39731b6b95 100644 --- a/R/prj_curves.R +++ b/R/prj_curves.R @@ -39,15 +39,15 @@ new_r2ogs6_curve <- function(name, coords, values){ #'as_node.r2ogs6_curve #'@description Implementation of generic function as_node for S3 class r2ogs6_curve -#'@param obj A r2ogs6_curve class object -as_node.r2ogs6_curve <- function(obj) { +#'@param x A r2ogs6_curve class object +as_node.r2ogs6_curve <- function(x) { node <- list(curve = structure(list())) - coords_str <- paste(obj$coords, collapse = " ") - values_str <- paste(obj$values, collapse = " ") + coords_str <- paste(x$coords, collapse = " ") + values_str <- paste(x$values, collapse = " ") - node <- add_children(node, list(name = obj$name, + node <- add_children(node, list(name = x$name, coords = coords_str, values = values_str)) @@ -57,9 +57,9 @@ as_node.r2ogs6_curve <- function(obj) { #'input_add.r2ogs6_curve #'@description Implementation of generic function input_add for S3 class r2ogs6_curve -#'@param obj A r2ogs6_curve class object +#'@param x A r2ogs6_curve class object #'@param ogs6_obj A OGS6 class object #'@export -input_add.r2ogs6_curve <- function(obj, ogs6_obj) { - ogs6_obj$add_curve(obj) +input_add.r2ogs6_curve <- function(x, ogs6_obj) { + ogs6_obj$add_curve(x) } \ No newline at end of file diff --git a/R/prj_linear_solvers.R b/R/prj_linear_solvers.R index fc0700aa164d9811cc287a10e9a1b0c396d83020..01fa5f0c67ab0232e7a47aa21add5bd960256be5 100644 --- a/R/prj_linear_solvers.R +++ b/R/prj_linear_solvers.R @@ -15,24 +15,20 @@ r2ogs6_linear_solver <- function(name, eigen, lis = NULL, petsc = NULL){ #Make this more user friendly #... - new_r2ogs6_linear_solver(name, eigen, lis, petsc) + validate_r2ogs6_linear_solver(new_r2ogs6_linear_solver(name, eigen, lis, petsc)) } new_r2ogs6_linear_solver <- function(name, eigen, lis = NULL, petsc = NULL){ assertthat::assert_that(assertthat::is.string(name)) + assertthat::assert_that(is.list(eigen)) - validate_param_list(eigen, 4, c("solver_type", "precon_type", "max_iteration_step", "error_tolerance")) if(!is.null(lis)){ assertthat::assert_that(assertthat::is.string(lis)) } - if(!is.null(petsc)){ - validate_param_list(petsc, 2, c("prefix", "parameters")) - } - structure(list(name = name, eigen = eigen, lis = lis, @@ -42,17 +38,34 @@ new_r2ogs6_linear_solver <- function(name, eigen, lis = NULL, petsc = NULL){ } +validate_r2ogs6_linear_solver <- function(r2ogs6_linear_solver){ + + assertthat::assert_that(length(r2ogs6_linear_solver$eigen) == 4) + names(r2ogs6_linear_solver$eigen) <- c("solver_type", "precon_type", "max_iteration_step", "error_tolerance") + + if(!is.null(r2ogs6_linear_solver$petsc)){ + assertthat::assert_that(is.vector(r2ogs6_linear_solver$petsc)) + assertthat::assert_that(length(r2ogs6_linear_solver$petsc) == 2) + names(r2ogs6_linear_solver$petsc) <- c("prefix", "parameters") + } + + return(invisible(r2ogs6_linear_solver)) +} + + #'as_node.r2ogs6_linear_solver #'@description Implementation of generic function as_node for S3 class r2ogs6_linear_solver -#'@param obj A r2ogs6_linear_solver class object -as_node.r2ogs6_linear_solver <- function(obj) { +#'@param x A r2ogs6_linear_solver class object +as_node.r2ogs6_linear_solver <- function(x) { node <- list(linear_solver = structure(list())) - node <- add_children(node, list(name = obj$name, - eigen = obj$eigen, - lis = obj$lis, - petsc = obj$petsc)) + eigen_node <- simple_vector_to_node("eigen", x$eigen) + + node <- add_children(node, list(name = x$name, + eigen_node, + lis = x$lis, + petsc = x$petsc)) return(node) } @@ -60,9 +73,9 @@ as_node.r2ogs6_linear_solver <- function(obj) { #'input_add.r2ogs6_linear_solver #'@description Implementation of generic function input_add for S3 class r2ogs6_linear_solver -#'@param obj A r2ogs6_linear_solver class object +#'@param x A r2ogs6_linear_solver class object #'@param ogs6_obj A OGS6 class object #'@export -input_add.r2ogs6_linear_solver <- function(obj, ogs6_obj) { - ogs6_obj$add_linear_solver(obj) +input_add.r2ogs6_linear_solver <- function(x, ogs6_obj) { + ogs6_obj$add_linear_solver(x) } \ No newline at end of file diff --git a/R/prj_media.R b/R/prj_media.R index aa1989b5330d48d24552148be813c905db524d7d..5abd946b36fbf064bdb29427576f0906e7dddba0 100644 --- a/R/prj_media.R +++ b/R/prj_media.R @@ -25,7 +25,7 @@ new_r2ogs6_medium_property <- function(name, type, value = NULL, ...){ assertthat::assert_that(assertthat::is.string(type)) if(!is.null(value)){ - assertthat::assert_that(is.numeric(value), length(value) == 1) + assertthat::assert_that(assertthat::is.number(value)) } structure( @@ -41,15 +41,15 @@ new_r2ogs6_medium_property <- function(name, type, value = NULL, ...){ #'as_node.r2ogs6_medium_property #'@description Implementation of generic function as_node for S3 class r2ogs6_medium_property -#'@param obj A r2ogs6_medium_property class object -as_node.r2ogs6_medium_property <- function(obj) { +#'@param x A r2ogs6_medium_property class object +as_node.r2ogs6_medium_property <- function(x) { node <- list(property = structure(list())) - node <- add_children(node, list(name = obj$name, - type = obj$type, - value = obj$value)) + node <- add_children(node, list(name = x$name, + type = x$type, + value = x$value)) - return(node) + return(invisible(node)) } @@ -71,6 +71,7 @@ new_r2ogs6_medium_phase <- function(type, properties) { assertthat::assert_that(assertthat::is.string(type)) assertthat::assert_that(type %in% prj_medium_phase_types) + validate_wrapper_list(properties, "r2ogs6_medium_property") structure( list( @@ -84,14 +85,16 @@ new_r2ogs6_medium_phase <- function(type, properties) { #'as_node.r2ogs6_medium_phase #'@description Implementation of generic function as_node for S3 class r2ogs6_medium_phase -#'@param obj A r2ogs6_medium_phase class object -as_node.r2ogs6_medium_phase <- function(obj) { +#'@param x A r2ogs6_medium_phase class object +as_node.r2ogs6_medium_phase <- function(x) { node <- list(phase = structure(list())) - node <- add_children(node, list(type = obj$type, - properties = obj$properties)) + properties_node <- adopt_nodes("properties", x$properties) + + node <- add_children(node, list(type = x$type, + properties_node)) - return(node) + return(invisible(node)) } @@ -132,24 +135,27 @@ new_r2ogs6_medium <- function(phases, properties, id = NULL) { #'as_node.r2ogs6_medium #'@description Implementation of generic function as_node for S3 class r2ogs6_medium -#'@param obj A r2ogs6_medium class object -as_node.r2ogs6_medium <- function(obj) { - medium_node <- list(medium = structure(list())) +#'@param x A r2ogs6_medium class object +as_node.r2ogs6_medium <- function(x) { + node <- list(medium = structure(list())) + + node <- add_attr(node, x$id, "id") - medium_node <- add_attr(medium_node, obj$id, "id") + phases_node <- adopt_nodes("phases", x$phases) + properties_node <- adopt_nodes("properties", x$properties) - medium_node <- add_children(medium_node, list(phases = obj$phases, - properties = obj$properties)) + node <- add_children(node, list(phases_node, + properties_node)) - return(medium_node) + return(invisible(node)) } #'input_add.r2ogs6_medium #'@description Implementation of generic function input_add for S3 class r2ogs6_medium -#'@param obj A r2ogs6_medium class object +#'@param x A r2ogs6_medium class object #'@param ogs6_obj An OGS6 class object #'@export -input_add.r2ogs6_medium <- function(obj, ogs6_obj) { - ogs6_obj$add_medium(obj) +input_add.r2ogs6_medium <- function(x, ogs6_obj) { + ogs6_obj$add_medium(x) } \ No newline at end of file diff --git a/R/prj_nonlinear_solvers.R b/R/prj_nonlinear_solvers.R index d0ad9e7dc1bf0b57ca56b13f5413355a0ff39d3c..01cf07371a7e36fafcb040d1e0dd8abe74bb7fdc 100644 --- a/R/prj_nonlinear_solvers.R +++ b/R/prj_nonlinear_solvers.R @@ -37,15 +37,15 @@ new_r2ogs6_nonlinear_solver <- function(name, type, max_iter, linear_solver){ #'as_node.r2ogs6_nonlinear_solver #'@description Implementation of generic function as_node for S3 class r2ogs6_nonlinear_solver -#'@param obj A r2ogs6_nonlinear_solver class object -as_node.r2ogs6_nonlinear_solver <- function(obj) { +#'@param x A r2ogs6_nonlinear_solver class object +as_node.r2ogs6_nonlinear_solver <- function(x) { node <- list(nonlinear_solver = structure(list())) - node <- add_children(node, list(name = obj$name, - type = obj$type, - max_iter = obj$max_iter, - linear_solver = obj$linear_solver)) + node <- add_children(node, list(name = x$name, + type = x$type, + max_iter = x$max_iter, + linear_solver = x$linear_solver)) return(node) } @@ -53,9 +53,9 @@ as_node.r2ogs6_nonlinear_solver <- function(obj) { #'input_add.r2ogs6_nonlinear_solver #'@description Implementation of generic function input_add for S3 class r2ogs6_nonlinear_solver -#'@param obj A r2ogs6_nonlinear_solver class object +#'@param x A r2ogs6_nonlinear_solver class object #'@param ogs6_obj A OGS6 class object #'@export -input_add.r2ogs6_nonlinear_solver <- function(obj, ogs6_obj) { - ogs6_obj$add_nonlinear_solver(obj) +input_add.r2ogs6_nonlinear_solver <- function(x, ogs6_obj) { + ogs6_obj$add_nonlinear_solver(x) } diff --git a/R/prj_parameters.R b/R/prj_parameters.R index f5ec04664058c8fb74bcc517107a5e981d8414bc..f4706d70c1c55bab575086efe9b11df86d48dba8 100644 --- a/R/prj_parameters.R +++ b/R/prj_parameters.R @@ -36,18 +36,18 @@ new_r2ogs6_parameter <- function(name, type, values) { #'as_node.r2ogs6_parameter #'@description Implementation of generic function as_node for S3 class r2ogs6_parameter -#'@param obj A r2ogs6_parameter class object -as_node.r2ogs6_parameter <- function(obj) { +#'@param x A r2ogs6_parameter class object +as_node.r2ogs6_parameter <- function(x) { node <- list(parameter = structure(list())) - node <- add_children(node, list(name = obj$name, - type = obj$type)) + node <- add_children(node, list(name = x$name, + type = x$type)) - if(length(obj$values) == 1){ - node <- add_children(node, list(value = obj$values[[1]])) + if(length(x$values) == 1){ + node <- add_children(node, list(value = x$values[[1]])) }else{ - val_string <- paste(obj$values, collapse = " ") + val_string <- paste(x$values, collapse = " ") node <- add_children(node, list(values = val_string)) } @@ -57,9 +57,9 @@ as_node.r2ogs6_parameter <- function(obj) { #'input_add.r2ogs6_parameter #'@description Implementation of generic function input_add for S3 class r2ogs6_parameter -#'@param obj A r2ogs6_parameter class object +#'@param x A r2ogs6_parameter class object #'@param ogs6_obj A OGS6 class object #'@export -input_add.r2ogs6_parameter <- function(obj, ogs6_obj) { - ogs6_obj$add_parameter(obj) +input_add.r2ogs6_parameter <- function(x, ogs6_obj) { + ogs6_obj$add_parameter(x) } \ No newline at end of file diff --git a/R/prj_process_variables.R b/R/prj_process_variables.R index f5d38194f526d4312ba3a013ec70e5281cb3cbad..b27a450d97533a7d07606c511484b319fc056145 100644 --- a/R/prj_process_variables.R +++ b/R/prj_process_variables.R @@ -41,28 +41,30 @@ new_r2ogs6_process_variable <- function(name, components, order, initial_conditi #'as_node.r2ogs6_process_variable #'@description Implementation of generic function as_node for S3 class r2ogs6_process_variable -#'@param obj A r2ogs6_process_variable class object -as_node.r2ogs6_process_variable <- function(obj) { +#'@param x A r2ogs6_process_variable class object +as_node.r2ogs6_process_variable <- function(x) { node <- list(process_variable = structure(list())) - node <- add_children(node, list(name = obj$name, - components = obj$components, - order = obj$order, - initial_condition = obj$initial_condition, - boundary_conditions = obj$boundary_conditions)) + boundary_conditions_node <- adopt_nodes("boundary_conditions", x$boundary_conditions) - return(node) + node <- add_children(node, list(name = x$name, + components = x$components, + order = x$order, + initial_condition = x$initial_condition, + boundary_conditions_node)) + + return(invisible(node)) } #'input_add.r2ogs6_process_variable #'@description Implementation of generic function input_add for S3 class r2ogs6_process_variable -#'@param obj A r2ogs6_process_variable class object +#'@param x A r2ogs6_process_variable class object #'@param ogs6_obj A OGS6 class object #'@export -input_add.r2ogs6_process_variable <- function(obj, ogs6_obj) { - ogs6_obj$add_process_variable(obj) +input_add.r2ogs6_process_variable <- function(x, ogs6_obj) { + ogs6_obj$add_process_variable(x) } @@ -124,17 +126,17 @@ new_r2ogs6_boundary_condition <- function(type, parameter, component = NULL, mes #'as_node.r2ogs6_boundary_condition #'@description Implementation of generic function as_node for S3 class r2ogs6_boundary_condition -#'@param obj A r2ogs6_boundary_condition class object -as_node.r2ogs6_boundary_condition <- function(obj) { +#'@param x A r2ogs6_boundary_condition class object +as_node.r2ogs6_boundary_condition <- function(x) { node <- list(boundary_condition = structure(list())) - node <- add_children(node, list(mesh = obj$mesh, - geometrical_set = obj$geometrical_set, - geometry = obj$geometry, - type = obj$type, - component = obj$component, - parameter = obj$parameter)) + node <- add_children(node, list(mesh = x$mesh, + geometrical_set = x$geometrical_set, + geometry = x$geometry, + type = x$type, + component = x$component, + parameter = x$parameter)) - return(node) + return(invisible(node)) } diff --git a/R/prj_processes.R b/R/prj_processes.R index 1c02b26fc37b60490b462043291e531d49981708..da4df7a6c312b2b67b47fc906f024f15fbf2e311 100644 --- a/R/prj_processes.R +++ b/R/prj_processes.R @@ -87,38 +87,37 @@ validate_r2ogs6_process <- function(r2ogs6_process){ #Add more validation functionality... - return(r2ogs6_process) + return(invisible(r2ogs6_process)) } #'as_node.r2ogs6_process #'@description Implementation of generic function as_node for S3 class r2ogs6_process -#'@param obj A r2ogs6_process class object -#'@param ... Ellipsis -as_node.r2ogs6_process <- function(obj) { +#'@param x A r2ogs6_process class object +as_node.r2ogs6_process <- function(x) { node <- list(process = structure(list())) - sbf_str <- paste(obj$specific_body_force, collapse = " ") + sbf_str <- paste(x$specific_body_force, collapse = " ") - const_rel_node <- simple_vector_to_node("constitutive_relation", obj$constitutive_relation) - proc_var_node <- simple_vector_to_node("process_variables", obj$process_variables) + const_rel_node <- simple_vector_to_node("constitutive_relation", x$constitutive_relation) + proc_var_node <- simple_vector_to_node("process_variables", x$process_variables) sec_var_node <- list(secondary_variables = structure(list())) - for(i in seq_len(length(obj$secondary_variables))){ + for(i in seq_len(length(x$secondary_variables))){ sec_var_node[[1]] <- c(sec_var_node[[1]], list(secondary_variable = structure(list()))) - attributes(sec_var_node[[1]][[i]]) <- list(internal_name = obj$secondary_variables[[i]][[1]], - output_name = obj$secondary_variables[[i]][[2]]) + attributes(sec_var_node[[1]][[i]]) <- list(internal_name = x$secondary_variables[[i]][[1]], + output_name = x$secondary_variables[[i]][[2]]) } - node <- add_children(node, list(name = obj$name, - type = obj$type, - coupling_scheme = obj$coupling_scheme, - integration_order = obj$integration_order, - dimension = obj$dimension, + node <- add_children(node, list(name = x$name, + type = x$type, + coupling_scheme = x$coupling_scheme, + integration_order = x$integration_order, + dimension = x$dimension, const_rel_node, proc_var_node, sec_var_node, @@ -130,9 +129,9 @@ as_node.r2ogs6_process <- function(obj) { #'input_add.r2ogs6_process #'@description Implementation of generic function input_add for S3 class r2ogs6_process -#'@param obj A r2ogs6_process class object +#'@param x A r2ogs6_process class object #'@param ogs6_obj A OGS6 class object #'@export -input_add.r2ogs6_process <- function(obj, ogs6_obj) { - ogs6_obj$add_process(obj) +input_add.r2ogs6_process <- function(x, ogs6_obj) { + ogs6_obj$add_process(x) } \ No newline at end of file diff --git a/R/prj_test_definition.R b/R/prj_test_definition.R index 90f545284627818a9b20405ef0d4e9d9fd28b248..7e46407c45da1b1bc79ef41d9e1ea24eee8a2cb6 100644 --- a/R/prj_test_definition.R +++ b/R/prj_test_definition.R @@ -38,15 +38,15 @@ new_r2ogs6_vtkdiff <- function(regex, field, absolute_tolerance, relative_tolera #'as_node.r2ogs6_vtkdiff #'@description Implementation of generic function as_node for S3 class r2ogs6_vtkdiff -#'@param obj A r2ogs6_vtkdiff class object -as_node.r2ogs6_vtkdiff <- function(obj) { +#'@param x A r2ogs6_vtkdiff class object +as_node.r2ogs6_vtkdiff <- function(x) { node <- list(vtkdiff = structure(list())) - node <- add_children(node, list(regex = obj$regex, - field = obj$field, - absolute_tolerance = obj$absolute_tolerance, - relative_tolerance = obj$relative_tolerance)) + node <- add_children(node, list(regex = x$regex, + field = x$field, + absolute_tolerance = x$absolute_tolerance, + relative_tolerance = x$relative_tolerance)) return(node) } @@ -54,9 +54,9 @@ as_node.r2ogs6_vtkdiff <- function(obj) { #'input_add.r2ogs6_vtkdiff #'@description Implementation of generic function input_add for S3 class r2ogs6_vtkdiff -#'@param obj A r2ogs6_vtkdiff class object +#'@param x A r2ogs6_vtkdiff class object #'@param ogs6_obj A OGS6 class object #'@export -input_add.r2ogs6_vtkdiff <- function(obj, ogs6_obj) { - ogs6_obj$add_vtkdiff(obj) +input_add.r2ogs6_vtkdiff <- function(x, ogs6_obj) { + ogs6_obj$add_vtkdiff(x) } \ No newline at end of file diff --git a/R/prj_time_loop.R b/R/prj_time_loop.R index 045355bfc46f3374324ca9356626936f366b8d6a..d74b72d433e03e13b98210a06ea639cc85b22465 100644 --- a/R/prj_time_loop.R +++ b/R/prj_time_loop.R @@ -38,25 +38,52 @@ new_r2ogs6_time_loop <- function(processes, output, global_processes_coupling = #'as_node.r2ogs6_time_loop #'@description Implementation of generic function as_node for S3 class r2ogs6_time_loop -#'@param obj A r2ogs6_time_loop class object -as_node.r2ogs6_time_loop <- function(obj) { +#'@param x A r2ogs6_time_loop class object +as_node.r2ogs6_time_loop <- function(x) { node <- list(time_loop = structure(list())) - node <- add_children(node, list(as_node(obj$global_processes_coupling), - as_node(obj$processes), - as_node(obj$output))) + processes_node <- adopt_nodes("processes", x$processes) - return(node) + node <- add_children(node, list(as_node(x$global_processes_coupling), + processes_node, + as_node(x$output))) + + return(invisible(node)) } #'input_add.r2ogs6_time_loop #'@description Implementation of generic function input_add for S3 class r2ogs6_time_loop -#'@param obj A r2ogs6_time_loop class object +#'@param x A r2ogs6_time_loop class object #'@param ogs6_obj A OGS6 class object #'@export -input_add.r2ogs6_time_loop <- function(obj, ogs6_obj){ - ogs6_obj$add_time_loop(obj) +input_add.r2ogs6_time_loop <- function(x, ogs6_obj){ + ogs6_obj$add_time_loop(x) +} + + +#============================== TIME_LOOP GLOBAL PROCESSES COUPLING ================================ + +#WIP!!!!!!!!!!!!!! + +new_r2ogs6_global_processes_coupling <- function() { + + structure( + list( + ), + class = "r2ogs6_global_processes_coupling" + ) +} + +#'as_node.r2ogs6_global_processes_coupling +#'@description Implementation of generic function as_node for S3 class r2ogs6_global_processes_coupling +#'@param x A r2ogs6_global_processes_coupling class object +as_node.r2ogs6_global_processes_coupling <- function(x) { + node <- list(global_processes_coupling = structure(list())) + + node <- add_children(node, list()) + + return(invisible(node)) } @@ -85,7 +112,11 @@ r2ogs6_tl_process <- function(ref, nonlinear_solver, convergence_criterion, new_r2ogs6_tl_process <- function(ref, nonlinear_solver, convergence_criterion, time_discretization, time_stepping) { - #Val... + assertthat::assert_that(assertthat::is.string(ref)) + assertthat::assert_that(assertthat::is.string(nonlinear_solver)) + assertthat::assert_that(is.vector(convergence_criterion)) + assertthat::assert_that(is.vector(time_discretization)) + assertthat::assert_that(is.list(time_stepping)) structure( list(ref = ref, @@ -101,16 +132,29 @@ new_r2ogs6_tl_process <- function(ref, nonlinear_solver, convergence_criterion, #'as_node.r2ogs6_tl_process #'@description Implementation of generic function as_node for S3 class r2ogs6_tl_process -#'@param obj A r2ogs6_tl_process class object -as_node.r2ogs6_tl_process <- function(obj) { - node <- list(process = structure(list(), ref = obj$ref)) +#'@param x A r2ogs6_tl_process class object +as_node.r2ogs6_tl_process <- function(x) { + node <- list(process = structure(list(), ref = x$ref)) + + convergence_criterion_node <- simple_vector_to_node("convergence_criterion", + x$convergence_criterion) + time_discretization_node <- simple_vector_to_node("time_discretization", + x$time_discretization) + + time_stepping_node <- list(time_stepping = structure(list())) + timesteps_node <- timesteps_as_node(x$time_stepping[[4]]) + time_stepping_node <- add_children(time_stepping_node, list(type = x$time_stepping[[1]], + t_initial = x$time_stepping[[2]], + t_end = x$time_stepping[[3]], + timesteps_node)) + - node <- add_children(node, list(nonlinear_solver = obj$nonlinear_solver, - convergence_criterion = obj$convergence_criterion, - time_discretization = obj$time_discretization, - time_stepping = obj$time_stepping)) + node <- add_children(node, list(nonlinear_solver = x$nonlinear_solver, + convergence_criterion_node, + time_discretization_node, + time_stepping_node)) - return(node) + return(invisible(node)) } @@ -144,6 +188,8 @@ new_r2ogs6_tl_output <- function(type, prefix, suffix, timesteps, variables, com assertthat::assert_that(is.list(timesteps)) assertthat::assert_that(is.list(variables)) + names(variables) <- rep("variable", length(variables)) + if(!is.null(compress_output)){ valid_vals <- c("false", "true") assertthat::assert_that(compress_output %in% valid_vals) @@ -164,17 +210,40 @@ new_r2ogs6_tl_output <- function(type, prefix, suffix, timesteps, variables, com #'as_node.r2ogs6_tl_output #'@description Implementation of generic function as_node for S3 class r2ogs6_tl_output -#'@param obj A r2ogs6_tl_output class object -as_node.r2ogs6_tl_output <- function(obj) { +#'@param x A r2ogs6_tl_output class object +as_node.r2ogs6_tl_output <- function(x) { node <- list(output = structure(list())) - node <- add_children(node, list(type = obj$type, - prefix = obj$prefix, - suffix = obj$suffix, - compress_output = obj$compress_output, - timesteps = obj$timesteps, - variables = obj$variables + timesteps_node <- timesteps_as_node(x$timesteps, TRUE) + variables_node <- simple_vector_to_node("variables", x$variables) + + node <- add_children(node, list(type = x$type, + prefix = x$prefix, + suffix = x$suffix, + compress_output = x$compress_output, + timesteps_node, + variables_node )) - return(node) + return(invisible(node)) +} + +#Helper +timesteps_as_node <- function(timesteps, in_output = FALSE){ + + node <- list(timesteps = structure(list())) + + for(i in seq_len(length(timesteps))){ + names(timesteps[[i]])[[1]] <- "repeat" + + if(!in_output){ + names(timesteps[[i]])[[2]] <- "delta_t" + }else{ + names(timesteps[[i]])[[2]] <- "each_steps" + } + + node[[1]] <- c(node[[1]], simple_vector_to_node("pair", timesteps[[i]])) + } + + return(invisible(node)) }