BELFEM
0.9.3
Berkeley Lab Finite Element Framework
Toggle main menu visibility
Loading...
Searching...
No Matches
fn_rho_database_is_current.hpp
Go to the documentation of this file.
1
/*
2
* BELFEM -- The Berkeley Lab Finite Element Framework
3
* Copyright (c) 2026, The Regents of the University of California, through
4
* Lawrence Berkeley National Laboratory (subject to receipt of any required
5
* approvals from the U.S. Dept. of Energy). All rights reserved.
6
*
7
* Developers: Christian Messe, Gregory Giard
8
*
9
* See the top-level LICENSE file for the complete license and disclaimer.
10
*/
11
12
#ifndef BELFEM_FN_RHO_DATABASE_IS_CURRENT_HPP
13
#define BELFEM_FN_RHO_DATABASE_IS_CURRENT_HPP
14
15
#include "
typedefs.hpp
"
16
#include "
hdf5_tools.hpp
"
17
18
namespace
belfem
19
{
29
constexpr
uint
gRhoDatabaseRevision
= 1 ;
30
42
inline
bool
43
rho_database_is_current
(
const
string
& aPath )
44
{
45
#ifdef BELFEM_HDF5
46
hid_t
tFile = H5Fopen( aPath.c_str(), H5F_ACC_RDONLY, H5P_DEFAULT );
47
48
if
( tFile < 0 )
49
{
50
return
false
;
51
}
52
53
// H5Lexists returns a tri-state: > 0 exists, 0 absent, < 0 error.
54
// Only a definite hit counts as current -- a probe ERROR must land
55
// on the rebuild side, not be swallowed by a bool conversion
56
bool
tIsCurrent = H5Lexists( tFile,
"RRR"
, H5P_DEFAULT ) > 0
57
&& H5Lexists( tFile,
"revision"
, H5P_DEFAULT ) > 0 ;
58
59
if
( tIsCurrent )
60
{
61
tIsCurrent = false ;
62
63
hid_t
tDataSet = H5Dopen2( tFile,
"revision"
, H5P_DEFAULT );
64
65
if
( tDataSet >= 0 )
66
{
67
hid_t
tDataSpace = H5Dget_space( tDataSet );
68
69
hid_t
tDataType = H5Dget_type( tDataSet );
70
71
if
( tDataSpace >= 0 && tDataType >= 0 )
72
{
73
// the read below fills exactly one value, and only from an
74
// integer: HDF5 would convert a stored 1.5 to 1
75
if
( H5Sget_simple_extent_npoints( tDataSpace ) == 1
76
&& H5Tget_class( tDataType ) == H5T_INTEGER )
77
{
78
unsigned
int
tRevision = 0 ;
79
80
if
( H5Dread( tDataSet, H5T_NATIVE_UINT, H5S_ALL, H5S_ALL,
81
H5P_DEFAULT, &tRevision ) >= 0 )
82
{
83
tIsCurrent = tRevision ==
gRhoDatabaseRevision
;
84
}
85
}
86
}
87
if
( tDataType >= 0 )
88
{
89
H5Tclose( tDataType );
90
}
91
if
( tDataSpace >= 0 )
92
{
93
H5Sclose( tDataSpace );
94
}
95
H5Dclose( tDataSet );
96
}
97
}
98
99
H5Fclose( tFile );
100
101
return
tIsCurrent;
102
#else
103
// without HDF5 the database path cannot work at all; keep the
104
// pre-existing behavior rather than forcing a rebuild here
105
return
true
;
106
#endif
107
}
108
}
109
#endif
//BELFEM_FN_RHO_DATABASE_IS_CURRENT_HPP
hdf5_tools.hpp
belfem
USER GUIDES:
Definition
cl_Capacitor.cpp:16
belfem::gRhoDatabaseRevision
constexpr uint gRhoDatabaseRevision
Content revision of the cached rho databases ( <label>_RRR<n>.hdf5 ).
Definition
fn_rho_database_is_current.hpp:29
belfem::hid_t
int hid_t
Definition
hdf5_types.hpp:20
belfem::uint
unsigned int uint
Definition
typedefs.hpp:30
belfem::rho_database_is_current
bool rho_database_is_current(const string &aPath)
Test whether a cached rho database may be loaded: it must carry the "RRR" dataset and a one-element "...
Definition
fn_rho_database_is_current.hpp:43
typedefs.hpp
src
physics
materials
fn_rho_database_is_current.hpp
Generated by
1.18.0