diff --git a/R/vtu.R b/R/vtu.R index 7a11970fd3fc6004a357d40b783a95d093840a9c..388b81b68aff4d8f2530da5643c7f7e343d66f2b 100644 --- a/R/vtu.R +++ b/R/vtu.R @@ -111,14 +111,14 @@ OGS6_pvd <- R6::R6Class( # ... get all rows of PointData or get rows by Name if(missing(Names)){ - Names <- names(relevant_vtus[[i]]$get_PointData()) + Names <- names(relevant_vtus[[i]]$point_data) } assertthat::assert_that(is.character(Names)) for (j in seq_len(length(point_ids))) { point_data <- - relevant_vtus[[i]]$get_PointData_for_point( + relevant_vtus[[i]]$get_data_for_point( point_ids[[j]], Names) @@ -242,14 +242,15 @@ OGS6_vtu <- R6::R6Class( #'@param point_id number: Point ID #'@param Names character: Optional: `Name` attributes of `DataArray` #' elements, defaults to all in `PointData` - get_PointData_for_point = function(point_id, - Names){ + get_data_for_point = function(point_id, + Names){ + + assertthat::assert_that(assertthat::is.number(point_id)) if(missing(Names)){ - Names <- names(self$get_PointData()) + Names <- names(self$point_data) } - assertthat::assert_that(assertthat::is.number(point_id)) assertthat::assert_that(is.character(Names)) point_data <- list() @@ -257,27 +258,13 @@ OGS6_vtu <- R6::R6Class( for(i in seq_len(length(Names))){ point_data <- c(point_data, - list(self$get_PointData(Names[[i]])[[(point_id + 1)]])) + list(self$point_data[[Names[[i]]]][[(point_id + 1)]])) names(point_data)[[length(point_data)]] <- Names[[i]] } return(point_data) }, - #'@description - #'Gets PointData of `DataArray` element with `Name` attribute - #'@param Name string: Optional: `Name` attribute of `DataArray` - #' elements, defaults to all in `PointData` - get_PointData = function(Name){ - - if(missing(Name)){ - return(self$dsa_wrapped_vtkUnstructuredGrid$PointData) - } - - assertthat::assert_that(assertthat::is.string(Name)) - return(self$dsa_wrapped_vtkUnstructuredGrid$PointData[[Name]]) - }, - #'@description #'Gets number of points #'@return number: The number of points @@ -294,6 +281,12 @@ OGS6_vtu <- R6::R6Class( private$.vtu_path }, + #'@field point_data + #'Getter for PointData parameter of '.dsa_vtkUnstructuredGrid' + point_data = function() { + self$dsa_vtkUnstructuredGrid$PointData + }, + #'@field vtkUnstructuredGrid #'Access to private parameter '.vtkUnstructuredGrid' vtkUnstructuredGrid = function(value) { @@ -302,22 +295,22 @@ OGS6_vtu <- R6::R6Class( }else{ # Check class private$.vtkUnstructuredGrid <- value - private$.dsa_wrapped_vtkUnstructuredGrid <- + private$.dsa_vtkUnstructuredGrid <- vtk_dsa$WrapDataObject(value) } }, - #'@field dsa_wrapped_vtkUnstructuredGrid - #'Getter for private parameter '.dsa_wrapped_vtkUnstructuredGrid' - dsa_wrapped_vtkUnstructuredGrid = function() { - private$.dsa_wrapped_vtkUnstructuredGrid + #'@field dsa_vtkUnstructuredGrid + #'Getter for private parameter '.dsa_vtkUnstructuredGrid' + dsa_vtkUnstructuredGrid = function() { + private$.dsa_vtkUnstructuredGrid } ), private = list( .vtu_path = NULL, .vtkUnstructuredGrid = NULL, - .dsa_wrapped_vtkUnstructuredGrid = NULL + .dsa_vtkUnstructuredGrid = NULL ) ) diff --git a/man/OGS6_vtu.Rd b/man/OGS6_vtu.Rd index c110b5ccc1f4dbd673ccd712d73f8dfb2aa81e6a..fd7cb032ec18ec96109455b66dd9e62777a09a01 100644 --- a/man/OGS6_vtu.Rd +++ b/man/OGS6_vtu.Rd @@ -11,9 +11,11 @@ Constructor for the OGS6_vtu base class \describe{ \item{\code{vtu_path}}{Getter for private parameter '.vtu_path'} +\item{\code{point_data}}{Getter for PointData parameter of '.dsa_vtkUnstructuredGrid'} + \item{\code{vtkUnstructuredGrid}}{Access to private parameter '.vtkUnstructuredGrid'} -\item{\code{dsa_wrapped_vtkUnstructuredGrid}}{Getter for private parameter '.dsa_wrapped_vtkUnstructuredGrid'} +\item{\code{dsa_vtkUnstructuredGrid}}{Getter for private parameter '.dsa_vtkUnstructuredGrid'} } \if{html}{\out{</div>}} } @@ -21,8 +23,7 @@ Constructor for the OGS6_vtu base class \subsection{Public methods}{ \itemize{ \item \href{#method-new}{\code{OGS6_vtu$new()}} -\item \href{#method-get_PointData_for_point}{\code{OGS6_vtu$get_PointData_for_point()}} -\item \href{#method-get_PointData}{\code{OGS6_vtu$get_PointData()}} +\item \href{#method-get_data_for_point}{\code{OGS6_vtu$get_data_for_point()}} \item \href{#method-get_number_of_points}{\code{OGS6_vtu$get_number_of_points()}} \item \href{#method-clone}{\code{OGS6_vtu$clone()}} } @@ -45,12 +46,12 @@ Creates new OGS6_vtu object } } \if{html}{\out{<hr>}} -\if{html}{\out{<a id="method-get_PointData_for_point"></a>}} -\if{latex}{\out{\hypertarget{method-get_PointData_for_point}{}}} -\subsection{Method \code{get_PointData_for_point()}}{ +\if{html}{\out{<a id="method-get_data_for_point"></a>}} +\if{latex}{\out{\hypertarget{method-get_data_for_point}{}}} +\subsection{Method \code{get_data_for_point()}}{ Gets PointData for point with ID `point_id` \subsection{Usage}{ -\if{html}{\out{<div class="r">}}\preformatted{OGS6_vtu$get_PointData_for_point(point_id, Names)}\if{html}{\out{</div>}} +\if{html}{\out{<div class="r">}}\preformatted{OGS6_vtu$get_data_for_point(point_id, Names)}\if{html}{\out{</div>}} } \subsection{Arguments}{ @@ -65,24 +66,6 @@ elements, defaults to all in `PointData`} } } \if{html}{\out{<hr>}} -\if{html}{\out{<a id="method-get_PointData"></a>}} -\if{latex}{\out{\hypertarget{method-get_PointData}{}}} -\subsection{Method \code{get_PointData()}}{ -Gets PointData of `DataArray` element with `Name` attribute -\subsection{Usage}{ -\if{html}{\out{<div class="r">}}\preformatted{OGS6_vtu$get_PointData(Name)}\if{html}{\out{</div>}} -} - -\subsection{Arguments}{ -\if{html}{\out{<div class="arguments">}} -\describe{ -\item{\code{Name}}{string: Optional: `Name` attribute of `DataArray` -elements, defaults to all in `PointData`} -} -\if{html}{\out{</div>}} -} -} -\if{html}{\out{<hr>}} \if{html}{\out{<a id="method-get_number_of_points"></a>}} \if{latex}{\out{\hypertarget{method-get_number_of_points}{}}} \subsection{Method \code{get_number_of_points()}}{ diff --git a/tests/testthat/test-vtu.R b/tests/testthat/test-vtu.R index c19a996e280bf3981ed18a3828f20f396fd9bc85..a2bda7e8320b538a2b1812259445ad7377a49825 100644 --- a/tests/testthat/test-vtu.R +++ b/tests/testthat/test-vtu.R @@ -107,10 +107,10 @@ test_that("OGS6_vtu initialization works", { #Add test... -#===== get_PointData ===== +#===== OGS6_vtu$point_data has expected format ===== -test_that("get_PointData works", { +test_that("point_data works", { skip_if_python_modules_missing() @@ -119,8 +119,6 @@ test_that("get_PointData works", { package = "r2ogs6") vtu_obj <- OGS6_vtu$new(vtu_path = vtu_path) - - pd_data_array <- vtu_obj$get_PointData(Name = "HydraulicFlow") - - expect_equal(class(pd_data_array), "array") + point_data <- vtu_obj$point_data[["HydraulicFlow"]] + expect_equal(class(point_data), "array") })