NGen
Loading...
Searching...
No Matches
models::bmi::protocols::NgenSerializationProtocol Class Reference

#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_
 

Constructor & Destructor Documentation

◆ NgenSerializationProtocol() [1/2]

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().

◆ NgenSerializationProtocol() [2/2]

models::bmi::protocols::NgenSerializationProtocol::NgenSerializationProtocol ( )

◆ ~NgenSerializationProtocol()

models::bmi::protocols::NgenSerializationProtocol::~NgenSerializationProtocol ( )
overridevirtualdefault

Member Function Documentation

◆ check_support()

auto models::bmi::protocols::NgenSerializationProtocol::check_support ( const ModelPtr & model) -> expected<void, ProtocolError>
overrideprivatevirtual

◆ error_or_warning()

static auto models::bmi::protocols::NgenBmiProtocol::error_or_warning ( const ProtocolError & err) -> expected<void, ProtocolError>
inlinestaticprotectedinherited

Handle a ProtocolError by either throwing it or logging it as a warning.

Parameters
errThe ProtocolError to handle
Returns
expected<void, ProtocolError> Returns an empty expected if the error was logged as a warning, otherwise throws the ProtocolError.
Exceptions
ProtocolErrorif 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().

◆ initialize()

auto models::bmi::protocols::NgenSerializationProtocol::initialize ( const ModelPtr & model,
const Properties & properties ) -> expected<void, ProtocolError>
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().

◆ is_supported()

bool models::bmi::protocols::NgenSerializationProtocol::is_supported ( ) const
finaloverrideprivatevirtual

Whether the protocol is supported by the model.

Implements models::bmi::protocols::NgenBmiProtocol.

References supported.

◆ run()

auto models::bmi::protocols::NgenSerializationProtocol::run ( const ModelPtr & model,
const Context & ctx ) const -> expected<void, ProtocolError>
overrideprivatevirtual

Member Data Documentation

◆ backend_

std::shared_ptr<::ngen::serialization::RecordBackend> models::bmi::protocols::NgenSerializationProtocol::backend_
private

◆ check

bool models::bmi::protocols::NgenSerializationProtocol::check
private

◆ frequency

int models::bmi::protocols::NgenSerializationProtocol::frequency
private

◆ is_fatal

bool models::bmi::protocols::NgenSerializationProtocol::is_fatal
private

◆ supported

bool models::bmi::protocols::NgenSerializationProtocol::supported = false
private

Referenced by is_supported().


The documentation for this class was generated from the following files: