Page Menu
Home
c4science
Search
Configure Global Search
Log In
Files
F80418928
hdf5_all.cpp
No One
Temporary
Actions
Download File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Subscribers
None
File Metadata
Details
File Info
Storage
Attached
Created
Sat, Aug 31, 15:21
Size
3 KB
Mime Type
text/x-c
Expires
Mon, Sep 2, 15:21 (2 d)
Engine
blob
Format
Raw Data
Handle
20338860
Attached To
rSPECMICP SpecMiCP / ReactMiCP
hdf5_all.cpp
View Options
#include "catch.hpp"
#include "specmicp_common/io/hdf5_eigen.hpp"
#include "specmicp_common/io/hdf5_timesteps.hpp"
using
namespace
specmicp
::
io
;
TEST_CASE
(
"HDF5 timesteps"
,
"[io],[hdf5],[timesteps]"
)
{
HDF5File
file_in
(
"test_hdf5_timesteps.hdf5"
,
HDF5_OpenMode
::
CreateTruncate
);
file_in
.
create_group
(
"/not_a_timestep"
);
file_in
.
create_group
(
"/11.1"
);
file_in
.
create_group
(
"/22.2"
);
file_in
.
create_group
(
"/33.3"
);
file_in
.
create_group
(
"/44.4"
);
file_in
.
close
();
SECTION
(
"Read file"
)
{
HDF5File
file_out
(
"test_hdf5_timesteps.hdf5"
,
HDF5_OpenMode
::
OpenReadOnly
);
auto
nb
=
file_out
.
get_number_objects
();
CHECK
(
nb
==
5
);
HDF5Timesteps
timesteps
(
file_out
);
CHECK
(
timesteps
.
size
()
==
4
);
CHECK
(
timesteps
.
get_number
(
"22.2"
)
==
22.2
);
CHECK
(
timesteps
.
get_string
(
11.1
)
==
"11.1"
);
CHECK
(
timesteps
.
get_string
(
22.2
)
==
"22.2"
);
CHECK
(
timesteps
.
get_string
(
33.3
)
==
"33.3"
);
CHECK
(
timesteps
.
get_string
(
44.4
)
==
"44.4"
);
CHECK
(
timesteps
.
get_string
(
33.2
)
==
"33.3"
);
CHECK_THROWS
(
timesteps
.
get_string
(
55.5
)
==
"55.5"
);
}
}
TEST_CASE
(
"HDF5_eigen"
,
"[io],[hdf5],[eigen]"
)
{
SECTION
(
"Simple case"
)
{
Eigen
::
Matrix2d
mat
;
mat
<<
1
,
2
,
3
,
4
;
HDF5File
file
(
"test_eigen_simple_case.hdf5"
,
HDF5_OpenMode
::
CreateTruncate
);
auto
matrix_group
=
file
.
create_group
(
"/matrix"
);
save_eigen_matrix
(
*
matrix_group
.
get
(),
"Double 2x2 matrix"
,
mat
);
Eigen
::
Matrix2d
matr
;
read_eigen_matrix
(
*
matrix_group
.
get
(),
"Double 2x2 matrix"
,
matr
);
CHECK
(
matr
.
cols
()
==
2
);
CHECK
(
matr
.
rows
()
==
2
);
CHECK
(
matr
(
1
,
1
)
==
4
);
CHECK
(
matr
(
1
,
0
)
==
3
);
Eigen
::
Matrix4i
mat2
;
mat2
<<
1
,
2
,
3
,
4
,
5
,
6
,
7
,
8
,
1
,
2
,
3
,
4
,
5
,
6
,
7
,
8
;
auto
dataset
=
save_eigen_matrix
(
file
,
"Integer 4x4 matrix"
,
"/matrix"
,
mat2
);
Eigen
::
MatrixXi
matr2
;
read_eigen_matrix
(
*
dataset
.
get
(),
matr2
);
CHECK
(
matr2
.
rows
()
==
4
);
CHECK
(
matr2
.
cols
()
==
4
);
CHECK
(
matr2
(
1
,
2
)
==
mat2
(
1
,
2
));
CHECK
(
matr2
(
2
,
3
)
==
mat2
(
2
,
3
));
CHECK
(
matr2
(
3
,
1
)
==
mat2
(
3
,
1
));
Eigen
::
Matrix
<
double
,
Eigen
::
Dynamic
,
Eigen
::
Dynamic
,
Eigen
::
RowMajor
>
mat3
;
mat3
.
resize
(
4
,
4
);
mat3
<<
1
,
2
,
3
,
4
,
1
,
2
,
3
,
4
,
1
,
2
,
3
,
4
,
1
,
2
,
3
,
4
;
save_eigen_matrix
(
file
,
"Row major matrix"
,
"/matrix"
,
mat3
);
Eigen
::
Matrix
<
double
,
Eigen
::
Dynamic
,
Eigen
::
Dynamic
,
Eigen
::
RowMajor
>
matr3
;
read_eigen_matrix
(
file
,
"Row major matrix"
,
"/matrix"
,
matr3
);
CHECK
(
mat3
.
rows
()
==
matr3
.
rows
());
CHECK
(
mat3
.
cols
()
==
matr3
.
cols
());
CHECK
(
mat3
.
norm
()
==
matr3
.
norm
());
CHECK
(
mat3
(
1
,
1
)
==
matr3
(
1
,
1
));
CHECK
(
mat3
(
2
,
3
)
==
matr3
(
2
,
3
));
Eigen
::
VectorXd
vec1
(
6
);
vec1
<<
1
,
2
,
3
,
4
,
5
,
6
;
auto
vector_group
=
file
.
create_group
(
"/vector"
);
save_eigen_matrix
(
file
,
"double 6x1 vector"
,
"/vector"
,
vec1
);
Eigen
::
VectorXd
vec2
;
read_eigen_matrix
(
file
,
"double 6x1 vector"
,
"/vector"
,
vec2
);
CHECK
(
vec2
.
rows
()
==
vec1
.
rows
());
CHECK
(
vec2
.
norm
()
==
vec1
.
norm
());
}
}
Event Timeline
Log In to Comment