October 7, 2015, 15:37
|
Reading 2D array from dictionary
|
#1
|
Member
Join Date: Aug 2015
Posts: 37
Rep Power: 11
|
I'm interested in reading a 2D data array with arbitrary dimensions m x n from a dictionary. I've seen an implementation which uses a List<List<scalar>>, and expects input in the format listName
5 // number of rows
( 4 (1.0 1.0 1.0 1.0) // row 1
4 (1.0 1.0 1.0 1.0) // row 2...
4 (1.0 1.0 1.0 1.0)
4 (1.0 1.0 1.0 1.0)
4 (1.0 1.0 1.0 1.0)
)
This is workable, but it doesn't naturally enforce the condition that all rows must have the same number of elements - if row 2 had an extra element, the code would accept it nonetheless. Applying this condition after-the-fact via assertions seems like a band-aid solution. I would prefer a class which naturally stores 2D data, and accepts input like listName
5, 4 // 5 rows with 4 elements each
( (1.0 1.0 1.0 1.0) // row 1
(1.0 1.0 1.0 1.0) // row 2...
(1.0 1.0 1.0 1.0)
(1.0 1.0 1.0 1.0)
(1.0 1.0 1.0 1.0)
)
Is there an OpenFOAM data type which is naturally suited to this? I looked into using a Matrix<>, but the intended usage of this class isn't clear to me and I haven't found a template to follow...
|
|
|