Why having `$input$msh$ELEMENTS` as geometry specific list ?
ELEMENTS from MSH file are read in as element geometry specific list
instead of an entire tibble
.
Why this?
# .msh input file ---------------------------------------------------------
"msh" = # loop over blocs
ogs5_read_inputfile_tolist(filepath) %>%
lapply(function(bloc) {
# Convert NODES into tibble of double
nds <- bloc[["NODES"]][-1] # leave out first line
bloc[["NODES"]] <- nds %>%
lapply(stringr::str_split, " ") %>%
unlist %>%
as.double %>%
matrix(nrow = length(nds),
byrow = TRUE) %>%
'colnames<-' (c("n", "x", "y", "z")) %>%
tibble::as_tibble() %>%
dplyr::select(-n) # remove numbering column
# Convert ELEMENTS into tibble
emts <- bloc[["ELEMENTS"]][-1] # leave out first line
# find words
geometries <- stringr::str_extract(emts, "[:alpha:]+") %>%
unique()
bloc[["ELEMENTS"]] <- vector(mode = "list", length(geometries))
names(bloc[["ELEMENTS"]] ) <- geometries
start <- 1
end <- 0
for (g in geometries) {
n <- sum(stringr::str_detect(emts, g))
g_ind <- stringr::str_which(emts, g)
mat <- emts[g_ind] %>%
lapply(stringr::str_split, " ") %>%
unlist %>%
matrix(nrow = n, byrow = TRUE)
colnames(mat) <- c("nr",
"material_id",
"ele_type",
paste0("node", 1:(ncol(mat) - 3)))
bloc[["ELEMENTS"]][[paste0(g)]] <- mat %>%
tibble::as_tibble() %>%
dplyr::mutate_at(dplyr::vars(-ele_type),
list(as.double))
}
# unlist all other blocs
other_skeys <- which(!(names(bloc) == "NODES" |
names(bloc) == "ELEMENTS"))
bloc[other_skeys] <-
bloc[other_skeys] %>%
lapply(unlist)
# add class
bloc <- structure(bloc, class = "ogs5_msh_bloc")
return(bloc) # return bloc
}) %>% # add input class
structure(class = "ogs5_msh"),