Skip to content
Snippets Groups Projects
Commit 95452442 authored by Ruben Heinrich's avatar Ruben Heinrich
Browse files

[feature] WIP: Simplified .vtu parameter access

parent 39bd9611
No related branches found
No related tags found
1 merge request!6Merge branch 7 fixed functionality into master
...@@ -111,14 +111,14 @@ OGS6_pvd <- R6::R6Class( ...@@ -111,14 +111,14 @@ OGS6_pvd <- R6::R6Class(
# ... get all rows of PointData or get rows by Name # ... get all rows of PointData or get rows by Name
if(missing(Names)){ if(missing(Names)){
Names <- names(relevant_vtus[[i]]$get_PointData()) Names <- names(relevant_vtus[[i]]$point_data)
} }
assertthat::assert_that(is.character(Names)) assertthat::assert_that(is.character(Names))
for (j in seq_len(length(point_ids))) { for (j in seq_len(length(point_ids))) {
point_data <- point_data <-
relevant_vtus[[i]]$get_PointData_for_point( relevant_vtus[[i]]$get_data_for_point(
point_ids[[j]], point_ids[[j]],
Names) Names)
...@@ -242,14 +242,15 @@ OGS6_vtu <- R6::R6Class( ...@@ -242,14 +242,15 @@ OGS6_vtu <- R6::R6Class(
#'@param point_id number: Point ID #'@param point_id number: Point ID
#'@param Names character: Optional: `Name` attributes of `DataArray` #'@param Names character: Optional: `Name` attributes of `DataArray`
#' elements, defaults to all in `PointData` #' elements, defaults to all in `PointData`
get_PointData_for_point = function(point_id, get_data_for_point = function(point_id,
Names){ Names){
assertthat::assert_that(assertthat::is.number(point_id))
if(missing(Names)){ 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)) assertthat::assert_that(is.character(Names))
point_data <- list() point_data <- list()
...@@ -257,27 +258,13 @@ OGS6_vtu <- R6::R6Class( ...@@ -257,27 +258,13 @@ OGS6_vtu <- R6::R6Class(
for(i in seq_len(length(Names))){ for(i in seq_len(length(Names))){
point_data <- point_data <-
c(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]] names(point_data)[[length(point_data)]] <- Names[[i]]
} }
return(point_data) 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 #'@description
#'Gets number of points #'Gets number of points
#'@return number: The number of points #'@return number: The number of points
...@@ -294,6 +281,12 @@ OGS6_vtu <- R6::R6Class( ...@@ -294,6 +281,12 @@ OGS6_vtu <- R6::R6Class(
private$.vtu_path private$.vtu_path
}, },
#'@field point_data
#'Getter for PointData parameter of '.dsa_vtkUnstructuredGrid'
point_data = function() {
self$dsa_vtkUnstructuredGrid$PointData
},
#'@field vtkUnstructuredGrid #'@field vtkUnstructuredGrid
#'Access to private parameter '.vtkUnstructuredGrid' #'Access to private parameter '.vtkUnstructuredGrid'
vtkUnstructuredGrid = function(value) { vtkUnstructuredGrid = function(value) {
...@@ -302,22 +295,22 @@ OGS6_vtu <- R6::R6Class( ...@@ -302,22 +295,22 @@ OGS6_vtu <- R6::R6Class(
}else{ }else{
# Check class # Check class
private$.vtkUnstructuredGrid <- value private$.vtkUnstructuredGrid <- value
private$.dsa_wrapped_vtkUnstructuredGrid <- private$.dsa_vtkUnstructuredGrid <-
vtk_dsa$WrapDataObject(value) vtk_dsa$WrapDataObject(value)
} }
}, },
#'@field dsa_wrapped_vtkUnstructuredGrid #'@field dsa_vtkUnstructuredGrid
#'Getter for private parameter '.dsa_wrapped_vtkUnstructuredGrid' #'Getter for private parameter '.dsa_vtkUnstructuredGrid'
dsa_wrapped_vtkUnstructuredGrid = function() { dsa_vtkUnstructuredGrid = function() {
private$.dsa_wrapped_vtkUnstructuredGrid private$.dsa_vtkUnstructuredGrid
} }
), ),
private = list( private = list(
.vtu_path = NULL, .vtu_path = NULL,
.vtkUnstructuredGrid = NULL, .vtkUnstructuredGrid = NULL,
.dsa_wrapped_vtkUnstructuredGrid = NULL .dsa_vtkUnstructuredGrid = NULL
) )
) )
......
...@@ -11,9 +11,11 @@ Constructor for the OGS6_vtu base class ...@@ -11,9 +11,11 @@ Constructor for the OGS6_vtu base class
\describe{ \describe{
\item{\code{vtu_path}}{Getter for private parameter '.vtu_path'} \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{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>}} \if{html}{\out{</div>}}
} }
...@@ -21,8 +23,7 @@ Constructor for the OGS6_vtu base class ...@@ -21,8 +23,7 @@ Constructor for the OGS6_vtu base class
\subsection{Public methods}{ \subsection{Public methods}{
\itemize{ \itemize{
\item \href{#method-new}{\code{OGS6_vtu$new()}} \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_data_for_point}{\code{OGS6_vtu$get_data_for_point()}}
\item \href{#method-get_PointData}{\code{OGS6_vtu$get_PointData()}}
\item \href{#method-get_number_of_points}{\code{OGS6_vtu$get_number_of_points()}} \item \href{#method-get_number_of_points}{\code{OGS6_vtu$get_number_of_points()}}
\item \href{#method-clone}{\code{OGS6_vtu$clone()}} \item \href{#method-clone}{\code{OGS6_vtu$clone()}}
} }
...@@ -45,12 +46,12 @@ Creates new OGS6_vtu object ...@@ -45,12 +46,12 @@ Creates new OGS6_vtu object
} }
} }
\if{html}{\out{<hr>}} \if{html}{\out{<hr>}}
\if{html}{\out{<a id="method-get_PointData_for_point"></a>}} \if{html}{\out{<a id="method-get_data_for_point"></a>}}
\if{latex}{\out{\hypertarget{method-get_PointData_for_point}{}}} \if{latex}{\out{\hypertarget{method-get_data_for_point}{}}}
\subsection{Method \code{get_PointData_for_point()}}{ \subsection{Method \code{get_data_for_point()}}{
Gets PointData for point with ID `point_id` Gets PointData for point with ID `point_id`
\subsection{Usage}{ \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}{ \subsection{Arguments}{
...@@ -65,24 +66,6 @@ elements, defaults to all in `PointData`} ...@@ -65,24 +66,6 @@ elements, defaults to all in `PointData`}
} }
} }
\if{html}{\out{<hr>}} \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{html}{\out{<a id="method-get_number_of_points"></a>}}
\if{latex}{\out{\hypertarget{method-get_number_of_points}{}}} \if{latex}{\out{\hypertarget{method-get_number_of_points}{}}}
\subsection{Method \code{get_number_of_points()}}{ \subsection{Method \code{get_number_of_points()}}{
......
...@@ -107,10 +107,10 @@ test_that("OGS6_vtu initialization works", { ...@@ -107,10 +107,10 @@ test_that("OGS6_vtu initialization works", {
#Add test... #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() skip_if_python_modules_missing()
...@@ -119,8 +119,6 @@ test_that("get_PointData works", { ...@@ -119,8 +119,6 @@ test_that("get_PointData works", {
package = "r2ogs6") package = "r2ogs6")
vtu_obj <- OGS6_vtu$new(vtu_path = vtu_path) vtu_obj <- OGS6_vtu$new(vtu_path = vtu_path)
point_data <- vtu_obj$point_data[["HydraulicFlow"]]
pd_data_array <- vtu_obj$get_PointData(Name = "HydraulicFlow") expect_equal(class(point_data), "array")
expect_equal(class(pd_data_array), "array")
}) })
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment