Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
R
r2ogs6
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Iterations
Wiki
Requirements
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
Artifacts
Deploy
Releases
Package Registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
ogs
OpenGeoSys Tools
r2ogs6
Commits
c3e744a8
Commit
c3e744a8
authored
4 years ago
by
Ruben Heinrich
Browse files
Options
Downloads
Patches
Plain Diff
[feature] Refactored .vtu class, added .pvd wrapper class
parent
e6f3d9a9
No related branches found
No related tags found
1 merge request
!6
Merge branch 7 fixed functionality into master
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
R/vtu.R
+134
-65
134 additions, 65 deletions
R/vtu.R
with
134 additions
and
65 deletions
R/vtu.R
+
134
−
65
View file @
c3e744a8
...
@@ -22,7 +22,7 @@ OGS6_pvd <- R6::R6Class(
...
@@ -22,7 +22,7 @@ OGS6_pvd <- R6::R6Class(
private
$
.datasets
<-
lapply
(
dataset_nodes
,
private
$
.datasets
<-
lapply
(
dataset_nodes
,
node_to_object
)
node_to_object
)
private
$
.OGS6_vtus
<-
lapply
(
self
$
abs_vtu_paths
,
private
$
.OGS6_vtus
<-
lapply
(
self
$
abs_vtu_paths
,
read_in_vtu
)
OGS6_vtu
$
new
)
},
},
...
@@ -31,11 +31,11 @@ OGS6_pvd <- R6::R6Class(
...
@@ -31,11 +31,11 @@ OGS6_pvd <- R6::R6Class(
#'@param timestep string: Timestep
#'@param timestep string: Timestep
get_vtu_path_by_timestep
=
function
(
timestep
){
get_vtu_path_by_timestep
=
function
(
timestep
){
assertthat
::
assert_that
(
assertthat
::
is.
string
(
timestep
))
assertthat
::
assert_that
(
assertthat
::
is.
number
(
timestep
))
for
(
i
in
seq_len
(
length
(
private
$
.dataset
s
))){
for
(
i
in
seq_len
(
length
(
self
$
timestep
s
))){
if
(
private
$
.datasets
[[
i
]][[
"
timestep
"
]]
==
timestep
){
if
(
self
$
timestep
s
[[
i
]]
==
timestep
){
return
(
private
$
.datasets
[[
i
]][[
"file"
]])
return
(
self
$
vtu_paths
[[
i
]])
}
}
}
}
...
@@ -50,9 +50,9 @@ OGS6_pvd <- R6::R6Class(
...
@@ -50,9 +50,9 @@ OGS6_pvd <- R6::R6Class(
assertthat
::
assert_that
(
assertthat
::
is.string
(
vtu_path
))
assertthat
::
assert_that
(
assertthat
::
is.string
(
vtu_path
))
for
(
i
in
seq_len
(
length
(
private
$
.dataset
s
))){
for
(
i
in
seq_len
(
length
(
self
$
vtu_path
s
))){
if
(
private
$
.datasets
[[
i
]][[
"file"
]]
==
vtu_path
){
if
(
self
$
vtu_paths
[[
i
]]
==
vtu_path
){
return
(
private
$
.datasets
[[
i
]][[
"
timestep
"
]])
return
(
self
$
timestep
s
[[
i
]])
}
}
}
}
...
@@ -62,28 +62,75 @@ OGS6_pvd <- R6::R6Class(
...
@@ -62,28 +62,75 @@ OGS6_pvd <- R6::R6Class(
#'@description
#'@description
#'Creates a tibble object from PointData
#'Creates a tibble object from PointData
#'@param point_ids numeric: Optional: IDs of the points of interest.
#' Will default to all point IDs if not defined.
#'@param Names character: `Name` attributes of `DataArray` elements
#'@param Names character: `Name` attributes of `DataArray` elements
get_PointData_time_tibble
=
function
(
Names
){
#'@param start_at_timestep number: Timestep to start at
#'@param end_at_timestep number: Timestep to end at
get_PointData_time_tibble
=
function
(
point_ids
,
Names
,
start_at_timestep
,
end_at_timestep
){
if
(
missing
(
point_ids
)){
max_point_id
<-
self
$
OGS6_vtus
[[
1
]]
$
get_number_of_points
()
-
1
point_ids
<-
seq
(
0
,
max_point_id
)
}
assertthat
::
assert_that
(
is.character
(
Names
))
assertthat
::
assert_that
(
is.numeric
(
point_ids
))
if
(
missing
(
start_at_timestep
)){
start_at_timestep
<-
self
$
timesteps
[[
1
]]
}
if
(
missing
(
end_at_timestep
)){
end_at_timestep
<-
self
$
timesteps
[[
length
(
self
$
timesteps
)]]
}
assertthat
::
assert_that
(
assertthat
::
is.number
(
start_at_timestep
))
assertthat
::
assert_that
(
assertthat
::
is.number
(
end_at_timestep
))
relevant_vtus
<-
list
()
for
(
i
in
seq_len
(
length
(
self
$
OGS6_vtus
))){
timestep
<-
self
$
get_timestep_by_vtu_path
(
self
$
vtu_paths
[[
i
]])
if
(
timestep
>=
start_at_timestep
&&
timestep
<=
end_at_timestep
){
relevant_vtus
<-
c
(
relevant_vtus
,
list
(
self
$
OGS6_vtus
[[
i
]]))
}
}
time_list
<-
list
()
time_list
<-
list
()
# For each .vtu file referenced in pvd_path...
# For each .vtu file referenced in pvd_path...
for
(
i
in
seq_len
(
length
(
s
el
f
$
OGS6
_vtus
))){
for
(
i
in
seq_len
(
length
(
r
el
evant
_vtus
))){
new_row
<-
list
()
new_row
<-
list
()
timestep_name
<-
paste0
(
"t"
,
i
)
# ... get all rows of PointData or get rows by Name
if
(
missing
(
Names
)){
Names
<-
names
(
relevant_vtus
[[
i
]]
$
get_PointData
())
}
# ... get row of PointData by Name
assertthat
::
assert_that
(
is.character
(
Names
))
for
(
j
in
seq_len
(
length
(
Names
))){
for
(
j
in
seq_len
(
length
(
point_ids
)))
{
point_data
<-
point_data
<-
self
$
OGS6_vtus
[[
i
]]
$
get_PointData_DataArray
(
Names
[[
j
]])
relevant_vtus
[[
i
]]
$
get_PointData_for_point
(
new_row
<-
c
(
new_row
,
list
(
list
(
point_data
)))
point_ids
[[
j
]],
names
(
new_row
)[[
length
(
new_row
)]]
<-
Names
[[
j
]]
Names
)
new_row
<-
c
(
new_row
,
list
(
list
(
point_data
)))
names
(
new_row
[[
length
(
new_row
)]])
<-
timestep_name
names
(
new_row
)[[
length
(
new_row
)]]
<-
paste0
(
"p"
,
(
j
-
1
))
}
}
time_list
<-
c
(
time_list
,
time_list
<-
c
(
time_list
,
list
(
tibble
::
as_tibble_row
(
new_row
)))
list
(
tibble
::
as_tibble_row
(
new_row
)))
names
(
time_list
)[[
length
(
time_list
)]]
<-
timestep_name
}
}
# Combine into tibble
# Combine into tibble
...
@@ -92,30 +139,21 @@ OGS6_pvd <- R6::R6Class(
...
@@ -92,30 +139,21 @@ OGS6_pvd <- R6::R6Class(
return
(
time_tibble
)
return
(
time_tibble
)
},
},
get_PointData_timeline
=
function
(
point_id
,
Name
,
starting_from_timestep
,
ending_on_timestep
){
# ...
},
#'@description
#'@description
#'Gets PointData at specified timestep. Calls
`get_PointData_timeline`
#'Gets PointData at specified timestep. Calls
#' internally with `start
ing_from
_timestep` and
`ending_on_timestep`
#'
`get_PointData_time_tibble`
internally with `start
_at
_timestep` and
#' both being `timestep`
#'
`end_at_timestep`
both being `timestep`
#'@param point_id number: Point ID
#'@param point_id
s
number: Point ID
s
#'@param Name
string
: `Name` attribute of `DataArray` element
#'@param Name
s character
: `Name` attribute
s
of `DataArray` element
s
#'@param timestep string: Timestep
#'@param timestep string: Timestep
get_PointData_at_timestep
=
function
(
point_id
,
get_PointData_at_timestep
=
function
(
point_id
s
,
Name
,
Name
s
,
timestep
){
timestep
){
self
$
get_PointData_time
lin
e
(
point_id
=
point_id
,
self
$
get_PointData_time
_tibbl
e
(
point_id
s
=
point_id
s
,
Name
=
Name
,
Name
s
=
Name
s
,
start
ing_from
_timestep
=
timestep
,
start
_at
_timestep
=
timestep
,
ending_on
_timestep
=
timestep
)
end_at
_timestep
=
timestep
)
}
}
),
),
...
@@ -135,8 +173,6 @@ OGS6_pvd <- R6::R6Class(
...
@@ -135,8 +173,6 @@ OGS6_pvd <- R6::R6Class(
#'@field vtu_paths
#'@field vtu_paths
#'Getter for `datasets` `file`
#'Getter for `datasets` `file`
#'@return character: .vtu paths as referenced in `pvd_path`, for
#' absolute paths use `abs_vtu_paths`
vtu_paths
=
function
()
{
vtu_paths
=
function
()
{
vtu_paths
<-
lapply
(
private
$
.datasets
,
function
(
x
){
vtu_paths
<-
lapply
(
private
$
.datasets
,
function
(
x
){
...
@@ -146,7 +182,6 @@ OGS6_pvd <- R6::R6Class(
...
@@ -146,7 +182,6 @@ OGS6_pvd <- R6::R6Class(
#'@field abs_vtu_paths
#'@field abs_vtu_paths
#'Gets absolute .vtu paths, e.g. `dirname(pvd_path)` + `datasets` `file`
#'Gets absolute .vtu paths, e.g. `dirname(pvd_path)` + `datasets` `file`
#'@return character: Absolute .vtu paths
abs_vtu_paths
=
function
()
{
abs_vtu_paths
=
function
()
{
abs_vtu_paths
<-
lapply
(
self
$
vtu_paths
,
function
(
x
){
abs_vtu_paths
<-
lapply
(
self
$
vtu_paths
,
function
(
x
){
...
@@ -160,7 +195,7 @@ OGS6_pvd <- R6::R6Class(
...
@@ -160,7 +195,7 @@ OGS6_pvd <- R6::R6Class(
timesteps
=
function
()
{
timesteps
=
function
()
{
timesteps
<-
lapply
(
private
$
.datasets
,
function
(
x
){
timesteps
<-
lapply
(
private
$
.datasets
,
function
(
x
){
x
[[
"timestep"
]]
as.double
(
x
[[
"timestep"
]]
)
})
})
},
},
...
@@ -191,13 +226,49 @@ OGS6_vtu <- R6::R6Class(
...
@@ -191,13 +226,49 @@ OGS6_vtu <- R6::R6Class(
#'@description
#'@description
#'Creates new OGS6_vtu object
#'Creates new OGS6_vtu object
#'@param vtkUnstructuredGrid
#'@param vtu_path string: Path to .vtu file
initialize
=
function
(
vtu_path
,
initialize
=
function
(
vtu_path
)
{
vtkUnstructuredGrid
)
{
self
$
vtkUnstructuredGrid
<-
vtkUnstructuredGrid
vtk_xml_ugr
<-
vtk
$
vtkXMLUnstructuredGridReader
()
vtk_xml_ugr
$
SetFileName
(
vtu_path
)
vtk_xml_ugr
$
Update
()
private
$
.vtu_path
<-
vtu_path
self
$
vtkUnstructuredGrid
<-
vtk_xml_ugr
$
GetOutput
()
},
},
get_PointData_DataArray
=
function
(
Name
){
#'@description
#'Gets PointData for point with ID `point_id`
#'@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
){
if
(
missing
(
Names
)){
Names
<-
names
(
self
$
get_PointData
())
}
assertthat
::
assert_that
(
assertthat
::
is.number
(
point_id
))
assertthat
::
assert_that
(
is.character
(
Names
))
point_data
<-
list
()
for
(
i
in
seq_len
(
length
(
Names
))){
point_data
<-
c
(
point_data
,
list
(
self
$
get_PointData
(
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
)){
if
(
missing
(
Name
)){
return
(
self
$
dsa_wrapped_vtkUnstructuredGrid
$
PointData
)
return
(
self
$
dsa_wrapped_vtkUnstructuredGrid
$
PointData
)
...
@@ -205,12 +276,24 @@ OGS6_vtu <- R6::R6Class(
...
@@ -205,12 +276,24 @@ OGS6_vtu <- R6::R6Class(
assertthat
::
assert_that
(
assertthat
::
is.string
(
Name
))
assertthat
::
assert_that
(
assertthat
::
is.string
(
Name
))
return
(
self
$
dsa_wrapped_vtkUnstructuredGrid
$
PointData
[[
Name
]])
return
(
self
$
dsa_wrapped_vtkUnstructuredGrid
$
PointData
[[
Name
]])
}
}
,
#'@description
#'Gets number of points
#'@return number: The number of points
get_number_of_points
=
function
(){
return
(
self
$
vtkUnstructuredGrid
$
GetNumberOfPoints
())
}
),
),
active
=
list
(
active
=
list
(
#'@field vtu_path
#'Getter for private parameter '.vtu_path'
vtu_path
=
function
()
{
private
$
.vtu_path
},
#'@field vtkUnstructuredGrid
#'@field vtkUnstructuredGrid
#'Access to private parameter '.vtkUnstructuredGrid'
#'Access to private parameter '.vtkUnstructuredGrid'
vtkUnstructuredGrid
=
function
(
value
)
{
vtkUnstructuredGrid
=
function
(
value
)
{
...
@@ -232,29 +315,13 @@ OGS6_vtu <- R6::R6Class(
...
@@ -232,29 +315,13 @@ OGS6_vtu <- R6::R6Class(
),
),
private
=
list
(
private
=
list
(
.vtu_path
=
NULL
,
.vtkUnstructuredGrid
=
NULL
,
.vtkUnstructuredGrid
=
NULL
,
.dsa_wrapped_vtkUnstructuredGrid
=
NULL
.dsa_wrapped_vtkUnstructuredGrid
=
NULL
)
)
)
)
#'read_in_vtu
#'@description Reads in .vtu file via `vtkXMLUnstructuredGridReader` from the
#' python `vtk` library
#'@param vtu_path string: Path to .vtu file
#'@return vtkUnstructuredGrid*: Unstructured Grid
#'@export
read_in_vtu
<-
function
(
vtu_path
)
{
vtk_xml_ugr
<-
vtk
$
vtkXMLUnstructuredGridReader
()
vtk_xml_ugr
$
SetFileName
(
vtu_path
)
vtk_xml_ugr
$
Update
()
return
(
invisible
(
OGS6_vtu
$
new
(
vtu_path
,
vtk_xml_ugr
$
GetOutput
())))
}
#===== generate_structured_mesh =====
#===== generate_structured_mesh =====
...
@@ -263,10 +330,12 @@ read_in_vtu <- function(vtu_path) {
...
@@ -263,10 +330,12 @@ read_in_vtu <- function(vtu_path) {
#' (VTK mesh generator). For full documentation see
#' (VTK mesh generator). For full documentation see
#'https://www.opengeosys.org/docs/tools/meshing/structured-mesh-generation/
#'https://www.opengeosys.org/docs/tools/meshing/structured-mesh-generation/
#'@param args_str string: The arguments the script will be called with
#'@param args_str string: The arguments the script will be called with
#'@param ogs_bin_path string: Optional: Path to OpenGeoSys6 bin folder.
#' Defaults to options("r2ogs6.default_ogs_bin_path").
#'@return string: .vtu file path
#'@return string: .vtu file path
#'@export
#'@export
generate_structured_mesh
=
function
(
o
gs_
bin_path
,
generate_structured_mesh
=
function
(
ar
gs_
str
,
ar
gs_
str
)
{
o
gs_
bin_path
)
{
if
(
missing
(
ogs_bin_path
)){
if
(
missing
(
ogs_bin_path
)){
ogs_bin_path
<-
unlist
(
options
(
"r2ogs6.default_ogs_bin_path"
))
ogs_bin_path
<-
unlist
(
options
(
"r2ogs6.default_ogs_bin_path"
))
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment