BELFEM 0.9.0
Berkeley Lab Finite Element Framework
Loading...
Searching...
No Matches
fn_circuit_state_io.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,
4 * through 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_CIRCUIT_STATE_IO_HPP
13#define BELFEM_FN_CIRCUIT_STATE_IO_HPP
14
15#include "typedefs.hpp"
16#include "cl_Vector.hpp"
17#include "cl_ShiftRegister.hpp"
18#include "hdf5_types.hpp"
19#ifdef BELFEM_HDF5
20#include "hdf5_tools.hpp"
21#endif
22
23namespace belfem
24{
25 namespace electronics
26 {
27//------------------------------------------------------------------------------
28
33 inline void
35 hid_t & aGroup,
36 const string & aLabel,
37 const ShiftRegister< real > & aRegister )
38 {
39#ifdef BELFEM_HDF5
40 herr_t tStatus = 0 ;
41
42 uint tCapacity = ( uint ) aRegister.capacity() ;
43 hdf5::save_scalar_to_file( aGroup, aLabel + "_cap", tCapacity, tStatus );
44
45 Vector< real > tSamples( aRegister.size() );
46 for ( index_t k = 0; k < aRegister.size(); ++k )
47 {
48 tSamples( k ) = aRegister( k );
49 }
50 hdf5::save_vector_to_file( aGroup, aLabel, tSamples, tStatus );
51#endif
52 }
53
54//------------------------------------------------------------------------------
55
66 inline void
68 hid_t & aGroup,
69 const string & aLabel,
70 ShiftRegister< real > & aRegister )
71 {
72#ifdef BELFEM_HDF5
73 herr_t tStatus = 0 ;
74
75 uint tCapacity = 0 ;
76 hdf5::load_scalar_from_file( aGroup, aLabel + "_cap", tCapacity, tStatus );
77 BELFEM_ERROR( tCapacity == ( uint ) aRegister.capacity(),
78 "Register %s in the restart file has capacity %u, the circuit expects %u ( BDF order changed? ). Delete the memdump to restart with a cold circuit.",
79 aLabel.c_str(),
80 tCapacity,
81 ( uint ) aRegister.capacity() );
82
83 Vector< real > tSamples ;
84 hdf5::load_vector_from_file( aGroup, aLabel, tSamples, tStatus );
85 BELFEM_ERROR( tSamples.length() <= aRegister.capacity(),
86 "Register %s in the restart file holds %lu samples, more than its stated capacity %u. Delete the memdump to restart with a cold circuit.",
87 aLabel.c_str(),
88 ( long unsigned int ) tSamples.length(),
89 tCapacity );
90
91 aRegister.clear() ;
92 for ( index_t k = tSamples.length(); k > 0; --k )
93 {
94 aRegister.push( tSamples( k - 1 ) );
95 }
96#endif
97 }
98
99//------------------------------------------------------------------------------
100 }
101}
102
103#endif //BELFEM_FN_CIRCUIT_STATE_IO_HPP
#define BELFEM_ERROR(aCheck,...)
Definition assert.hpp:264
auto size() const -> decltype(mSize)
Get current number of elements.
Definition cl_ShiftRegister.hpp:370
void push(T &aValue)
Definition cl_ShiftRegister.hpp:269
auto capacity() const -> decltype(mCapacity)
Get maximum capacity.
Definition cl_ShiftRegister.hpp:381
void clear()
Clear all elements.
Definition cl_ShiftRegister.hpp:414
size_t length() const
get the length of the vector
Definition cl_AR_Vector.hpp:257
Definition cl_Capacitor.cpp:18
void load_shift_register(hid_t &aGroup, const string &aLabel, ShiftRegister< real > &aRegister)
restore one history register saved by save_shift_register().
Definition fn_circuit_state_io.hpp:67
void save_shift_register(hid_t &aGroup, const string &aLabel, const ShiftRegister< real > &aRegister)
write one time-stepping history register into the restart group, as aLabel ( samples,...
Definition fn_circuit_state_io.hpp:34
void save_vector_to_file(hid_t &aLoc, const std::string &aLabel, const Vector< T > &aVector, herr_t &aStatus)
Definition hdf5_tools.hpp:549
void load_scalar_from_file(hid_t &aLoc, const std::string &aLabel, T &aValue, herr_t &aStatus)
Definition hdf5_tools.hpp:300
void save_scalar_to_file(hid_t &aLoc, const std::string &aLabel, const T &aValue, herr_t &aStatus)
saves a scalar value to a file file must be open
Definition hdf5_tools.hpp:235
void load_vector_from_file(hid_t &aLoc, const std::string &aLabel, Vector< T > &aVector, herr_t &aStatus)
Definition hdf5_tools.hpp:634
USER GUIDES:
Definition cl_Capacitor.cpp:16
int hid_t
Definition hdf5_types.hpp:20
unsigned int uint
Definition typedefs.hpp:30
uint32_t index_t
Definition typedefs.hpp:52
int herr_t
Definition hdf5_types.hpp:21