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
065da5ff
Commit
065da5ff
authored
4 years ago
by
Ruben Heinrich
Browse files
Options
Downloads
Patches
Plain Diff
[feature] .vtu tibble creation is more flexible now
parent
95452442
No related branches found
No related tags found
1 merge request
!6
Merge branch 7 fixed functionality into master
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
R/vtu.R
+41
-25
41 additions, 25 deletions
R/vtu.R
tests/testthat/test-vtu.R
+17
-3
17 additions, 3 deletions
tests/testthat/test-vtu.R
with
58 additions
and
28 deletions
R/vtu.R
+
41
−
25
View file @
065da5ff
...
@@ -106,9 +106,6 @@ OGS6_pvd <- R6::R6Class(
...
@@ -106,9 +106,6 @@ OGS6_pvd <- R6::R6Class(
# For each .vtu file referenced in pvd_path...
# For each .vtu file referenced in pvd_path...
for
(
i
in
seq_len
(
length
(
relevant_vtus
))){
for
(
i
in
seq_len
(
length
(
relevant_vtus
))){
new_row
<-
list
()
timestep_name
<-
paste0
(
"t"
,
i
)
# ... 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
]]
$
point_data
)
Names
<-
names
(
relevant_vtus
[[
i
]]
$
point_data
)
...
@@ -116,21 +113,23 @@ OGS6_pvd <- R6::R6Class(
...
@@ -116,21 +113,23 @@ OGS6_pvd <- R6::R6Class(
assertthat
::
assert_that
(
is.character
(
Names
))
assertthat
::
assert_that
(
is.character
(
Names
))
for
(
j
in
seq_len
(
length
(
point_ids
)))
{
point_data
<-
point_data
<-
relevant_vtus
[[
i
]]
$
get_data_for_points
(
point_ids
,
relevant_vtus
[[
i
]]
$
get_data_for_point
(
Names
)
point_ids
[[
j
]],
Names
)
point_data_row
<-
list
()
new_row
<-
c
(
new_row
,
for
(
j
in
seq_len
(
length
(
point_data
))){
list
(
list
(
point_data
)))
wrapped_point_data
<-
list
(
point_data
[[
j
]])
names
(
new_row
[[
length
(
new_row
)]])
<-
timestep_name
names
(
wrapped_point_data
)
<-
names
(
point_data
)[[
j
]]
names
(
new_row
)[[
length
(
new_row
)]]
<-
paste0
(
"p"
,
(
j
-
1
))
point_data_row
<-
c
(
point_data_row
,
list
(
wrapped_point_data
))
names
(
point_data_row
)[[
length
(
point_data_row
)]]
<-
names
(
point_data
)[[
j
]]
}
}
time_list
<-
c
(
time_list
,
time_list
<-
c
(
time_list
,
list
(
tibble
::
as_tibble_row
(
new_row
)))
list
(
tibble
::
as_tibble_row
(
point_data_row
)))
names
(
time_list
)[[
length
(
time_list
)]]
<-
timestep_name
}
}
# Combine into tibble
# Combine into tibble
...
@@ -238,14 +237,20 @@ OGS6_vtu <- R6::R6Class(
...
@@ -238,14 +237,20 @@ OGS6_vtu <- R6::R6Class(
},
},
#'@description
#'@description
#'Gets PointData for point with ID `point_id`
#'Gets PointData for points with IDs in `point_ids`. If called without
#'@param point_id number: Point ID
#' arguments, this is equivalent to `OGS6_vtu$point_data`.
#'@param point_ids numeric: Optional: Point IDs, defaults to all
#'@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_data_for_point
=
function
(
point_id
,
get_data_for_point
s
=
function
(
point_id
s
,
Names
){
Names
){
assertthat
::
assert_that
(
assertthat
::
is.number
(
point_id
))
if
(
missing
(
point_ids
)){
max_point_id
<-
self
$
get_number_of_points
()
-
1
point_ids
<-
seq
(
0
,
max_point_id
)
}
assertthat
::
assert_that
(
is.numeric
(
point_ids
))
if
(
missing
(
Names
)){
if
(
missing
(
Names
)){
Names
<-
names
(
self
$
point_data
)
Names
<-
names
(
self
$
point_data
)
...
@@ -255,11 +260,22 @@ OGS6_vtu <- R6::R6Class(
...
@@ -255,11 +260,22 @@ OGS6_vtu <- R6::R6Class(
point_data
<-
list
()
point_data
<-
list
()
for
(
i
in
seq_len
(
length
(
Names
))){
for
(
i
in
seq_len
(
length
(
point_ids
))){
point_data
<-
c
(
point_data
,
point_name
<-
paste0
(
"p"
,
point_ids
[[
i
]])
list
(
self
$
point_data
[[
Names
[[
i
]]]][[(
point_id
+
1
)]]))
single_point_data
<-
list
()
names
(
point_data
)[[
length
(
point_data
)]]
<-
Names
[[
i
]]
for
(
j
in
seq_len
(
length
(
Names
))){
single_point_data
<-
c
(
single_point_data
,
list
(
self
$
point_data
[[
Names
[[
j
]]]]
[[(
point_ids
[[
i
]]
+
1
)]]))
names
(
single_point_data
)[[
length
(
single_point_data
)]]
<-
Names
[[
j
]]
}
point_data
<-
c
(
point_data
,
list
(
single_point_data
))
names
(
point_data
)[[
length
(
point_data
)]]
<-
point_name
}
}
return
(
point_data
)
return
(
point_data
)
...
...
This diff is collapsed.
Click to expand it.
tests/testthat/test-vtu.R
+
17
−
3
View file @
065da5ff
...
@@ -63,6 +63,7 @@ test_that("OGS6_pvd$get_PointData_time_tibble works", {
...
@@ -63,6 +63,7 @@ test_that("OGS6_pvd$get_PointData_time_tibble works", {
time_tibble
<-
ogs6_pvd
$
get_PointData_time_tibble
(
Names
=
Names
)
time_tibble
<-
ogs6_pvd
$
get_PointData_time_tibble
(
Names
=
Names
)
expect_equal
(
length
(
time_tibble
),
341
)
expect_equal
(
length
(
time_tibble
),
341
)
expect_equal
(
length
(
time_tibble
[[
1
]]),
2
)
})
})
...
@@ -76,12 +77,12 @@ test_that("OGS6_pvd$get_PointData_at_timestep works", {
...
@@ -76,12 +77,12 @@ test_that("OGS6_pvd$get_PointData_at_timestep works", {
ogs6_pvd
<-
OGS6_pvd
$
new
(
pvd_path
)
ogs6_pvd
<-
OGS6_pvd
$
new
(
pvd_path
)
point_data
<-
ogs6_pvd
$
get_PointData_at_timestep
(
point_ids
=
0
,
point_data
<-
ogs6_pvd
$
get_PointData_at_timestep
(
point_ids
=
c
(
0
,
1
,
2
)
,
Names
=
"HydraulicFlow"
,
Names
=
"HydraulicFlow"
,
timestep
=
0
)
timestep
=
0
)
expect_equal
(
length
(
point_data
),
1
)
expect_equal
(
length
(
point_data
),
3
)
expect_equal
(
names
(
point_data
),
"p0"
)
expect_equal
(
names
(
point_data
),
c
(
"p0"
,
"p1"
,
"p2"
)
)
})
})
...
@@ -101,6 +102,19 @@ test_that("OGS6_vtu initialization works", {
...
@@ -101,6 +102,19 @@ test_that("OGS6_vtu initialization works", {
})
})
test_that
(
"OGS6_vtu$get_data_for_points works"
,
{
vtu_path
<-
system.file
(
"extdata/benchmarks/flow_no_strain"
,
"flow_no_strain_ts_1000_t_100.000000.vtu"
,
package
=
"r2ogs6"
)
vtu_obj
<-
OGS6_vtu
$
new
(
vtu_path
=
vtu_path
)
point_data
<-
vtu_obj
$
get_data_for_points
(
c
(
0
,
1
,
2
),
"HydraulicFlow"
)
expect_equal
(
length
(
point_data
),
3
)
})
#===== generate_structured_mesh =====
#===== generate_structured_mesh =====
...
...
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