|
NGen
|
#include <serialization.hpp>
Inheritance diagram for models::bmi::protocols::NgenSerializationProtocol:
Collaboration diagram for models::bmi::protocols::NgenSerializationProtocol:Public Member Functions | |
| NgenSerializationProtocol (const ModelPtr &model, const Properties &properties) | |
| Save-side state serialization protocol. | |
| NgenSerializationProtocol () | |
| virtual | ~NgenSerializationProtocol () override |
Static Protected Member Functions | |
| static auto | error_or_warning (const ProtocolError &err) -> expected< void, ProtocolError > |
| Handle a ProtocolError by either throwing it or logging it as a warning. | |
Private Member Functions | |
| auto | run (const ModelPtr &model, const Context &ctx) const -> expected< void, ProtocolError > override |
| Append one state record to the shared file when the frequency fires. | |
| nsel_NODISCARD auto | check_support (const ModelPtr &model) -> expected< void, ProtocolError > override |
| Probe the model for all four reserved serialization variable names. | |
| auto | initialize (const ModelPtr &model, const Properties &properties) -> expected< void, ProtocolError > override |
Parse top-level path and the save sub-block from the serialization configuration. | |
| bool | is_supported () const override final |
| Whether the protocol is supported by the model. | |
Private Attributes | |
| int | frequency |
| bool | supported = false |
| bool | check |
| bool | is_fatal |
| std::shared_ptr<::ngen::serialization::RecordBackend > | backend_ |
| models::bmi::protocols::NgenSerializationProtocol::NgenSerializationProtocol | ( | const ModelPtr & | model, |
| const Properties & | properties ) |
Save-side state serialization protocol.
Drives the four reserved BMI variables to capture a model's state and appends the bytes to a shared file as a SerializationRecord tagged with the feature id (from Context) and current time step.
SetValue(create) -> GetValue(size) -> GetValue(state) -> append record -> SetValue(free)
All protocol instances pointed at the same path write into the same file; one entity (id) may have at most one record per time step but may have records at multiple steps.
Storage I/O is delegated to a RecordBackend; concurrency and I/O sharing across instances are the backend's contract. The BMI capture scope (SetValue(create) ... SetValue(free)) is per-call and managed by an RAII ScopedCapture guard so an exception partway through still releases the model-side resources.
Cross-process coordination (separate processes writing to the same file) is not this protocol's concern — engines that fan writes out across processes own that coordination, typically via per-rank file naming.
References initialize().
| models::bmi::protocols::NgenSerializationProtocol::NgenSerializationProtocol | ( | ) |
|
overridevirtualdefault |
|
overrideprivatevirtual |
Probe the model for all four reserved serialization variable names.
Implements models::bmi::protocols::NgenBmiProtocol.
References models::bmi::protocols::INTEGRATION_ERROR, models::bmi::protocols::RESERVED_VARS, and models::bmi::protocols::UNITIALIZED_MODEL.
|
inlinestaticprotectedinherited |
Handle a ProtocolError by either throwing it or logging it as a warning.
| err | The ProtocolError to handle |
| ProtocolError | if the error is of type PROTOCOL_ERROR |
References models::bmi::protocols::INTEGRATION_ERROR, models::bmi::protocols::PROTOCOL_ERROR, models::bmi::protocols::PROTOCOL_WARNING, models::bmi::protocols::UNITIALIZED_MODEL, and models::bmi::protocols::UNSUPPORTED_PROTOCOL.
Referenced by models::bmi::protocols::NgenBmiProtocols::run(), and run().
|
overrideprivatevirtual |
Parse top-level path and the save sub-block from the serialization configuration.
Recognized keys: serialization.path (string, required when save.check is true) serialization.save.check (bool, default true when save block present) serialization.save.frequency (int, default 1; see run()) serialization.save.fatal (bool, default true)
Absent top-level or save sub-block disables the protocol silently.
Implements models::bmi::protocols::NgenBmiProtocol.
References ngen::serialization::FileBackend::create(), models::bmi::protocols::INTEGRATION_ERROR, models::bmi::protocols::PROTOCOL_ERROR, models::bmi::protocols::PROTOCOL_WARNING, models::bmi::protocols::SERIALIZATION_CHECK_KEY, models::bmi::protocols::SERIALIZATION_CONFIGURATION_KEY, models::bmi::protocols::SERIALIZATION_FATAL_KEY, models::bmi::protocols::SERIALIZATION_FREQUENCY_KEY, models::bmi::protocols::SERIALIZATION_PATH_KEY, and models::bmi::protocols::SERIALIZATION_SAVE_KEY.
Referenced by NgenSerializationProtocol().
|
finaloverrideprivatevirtual |
Whether the protocol is supported by the model.
Implements models::bmi::protocols::NgenBmiProtocol.
References supported.
|
overrideprivatevirtual |
Append one state record to the shared file when the frequency fires.
Frequency semantics match NgenMassBalance::run(): frequency > 0 : fire every frequency time steps frequency < 0 : fire only at the final time step frequency == 0 : disabled at initialize() time
Implements models::bmi::protocols::NgenBmiProtocol.
References models::bmi::protocols::NgenBmiProtocol::error_or_warning(), models::bmi::protocols::PROTOCOL_ERROR, models::bmi::protocols::PROTOCOL_WARNING, ngen::serialization::relaxed, models::bmi::protocols::SERIALIZATION_SIZE_NAME, models::bmi::protocols::SERIALIZATION_STATE_NAME, models::bmi::protocols::UNITIALIZED_MODEL, and ngen::serialization::UNPARSEABLE_TIMESTAMP_SENTINEL.
|
private |
|
private |
|
private |
|
private |
|
private |
Referenced by is_supported().