24#ifndef HYDROCOUPLEHELPERS_H
25#define HYDROCOUPLEHELPERS_H
84 for (int32_t k = 0; k < d.
rank; ++k)
98 for (int32_t k = d.
rank - 1; k >= 0; --k)
102 expected *= d.
shape[k];
118 for (int32_t k = d.
rank - 1; k >= 0; --k)
120 offset += index[k] * stride;
121 stride *= d.
shape[k];
126 for (int32_t k = 0; k < d.
rank; ++k)
152 d.
rank =
static_cast<int32_t
>(shape.size());
153 d.
shape = shape.data();
171 case CS::Created:
return to == CS::Initializing;
172 case CS::Initializing:
return to == CS::Initialized || to == CS::Failed;
173 case CS::Initialized:
return to == CS::Validating || to == CS::Initializing;
174 case CS::Validating:
return to == CS::Valid || to == CS::Invalid;
175 case CS::Valid:
return to == CS::Preparing || to == CS::Validating;
176 case CS::Invalid:
return to == CS::Validating;
177 case CS::Preparing:
return to == CS::Updated || to == CS::Failed;
178 case CS::Updating:
return to == CS::Updated || to == CS::Done ||
179 to == CS::WaitingForData || to == CS::Failed;
180 case CS::WaitingForData:
return to == CS::Updating || to == CS::Failed;
181 case CS::Updated:
return to == CS::Updating || to == CS::Checkpointing ||
183 case CS::Checkpointing:
return to == CS::Updated || to == CS::Failed;
184 case CS::Done:
return to == CS::Finishing;
185 case CS::Finishing:
return to == CS::Finished || to == CS::Created;
186 case CS::Finished:
return false;
187 case CS::Failed:
return to == CS::Initializing || to == CS::Finishing;
200 template <
typename T>
203 std::vector<int64_t> ones(index.size(), 1);
204 const int64_t one = 1;
217 template <
typename T>
220 std::vector<int64_t> ones(index.size(), 1);
221 const int64_t one = 1;
235 template <
typename T>
237 std::span<const int64_t> start, std::span<const int64_t> count)
251 template <
typename T>
253 std::span<const int64_t> start, std::span<const int64_t> count)
IComponentDataItem is a fundamental unit of data for a component.
Definition hydrocouple.h:1466
virtual bool getValuesInto(const BufferDescriptor &destination, std::span< const int64_t > start, std::span< const int64_t > count, std::string *message=nullptr) const =0
Copies a hyperslab of this item's values into a caller-described buffer.
virtual bool setValuesFrom(const BufferDescriptor &source, std::span< const int64_t > start, std::span< const int64_t > count, std::string *message=nullptr)=0
Copies values from a caller-described buffer into a hyperslab of this item.
ComponentStatus
HydroCouple::ComponentStatus is an enumerator that describes the status of a component over the cours...
Definition hydrocouple.h:541
Core interface definitions for the HydroCouple component-based modeling framework.
Non-normative convenience helpers for the HydroCouple interface standard.
Definition hydrocouplehelpers.h:33
bool setValues(IComponentDataItem &item, std::span< const T > source, std::span< const int64_t > start, std::span< const int64_t > count)
Typed convenience: writes a hyperslab from a flat contiguous span in C order.
Definition hydrocouplehelpers.h:252
constexpr int64_t contiguousByteSize(const BufferDescriptor &d)
Total byte extent of a C-contiguous buffer of the descriptor's shape and kind.
Definition hydrocouplehelpers.h:136
constexpr bool isContiguous(const BufferDescriptor &d)
Checks whether a BufferDescriptor's layout is C-contiguous (row-major, packed).
Definition hydrocouplehelpers.h:93
constexpr int64_t dataKindSize(DataKind kind)
Size in bytes of one element of the given DataKind.
Definition hydrocouplehelpers.h:39
bool setValue(IComponentDataItem &item, const T &value, std::span< const int64_t > index)
Typed convenience: writes the single element at the given index of a data item.
Definition hydrocouplehelpers.h:218
bool getValues(const IComponentDataItem &item, std::span< T > destination, std::span< const int64_t > start, std::span< const int64_t > count)
Typed convenience: reads a hyperslab into a flat contiguous span in C order.
Definition hydrocouplehelpers.h:236
constexpr bool isValidComponentStatusTransition(IModelComponent::ComponentStatus from, IModelComponent::ComponentStatus to)
Encodes the normative component lifecycle state machine.
Definition hydrocouplehelpers.h:165
constexpr int64_t byteOffset(const BufferDescriptor &d, std::span< const int64_t > index)
Byte offset from a descriptor's base address of the element at the given index.
Definition hydrocouplehelpers.h:112
constexpr BufferDescriptor makeContiguous(void *data, DataKind kind, std::span< const int64_t > shape)
Builds a C-contiguous host BufferDescriptor.
Definition hydrocouplehelpers.h:147
constexpr int64_t elementCount(const BufferDescriptor &d)
Number of elements a BufferDescriptor describes (product of shape; 1 for rank 0).
Definition hydrocouplehelpers.h:81
bool getValue(const IComponentDataItem &item, T &value, std::span< const int64_t > index)
Typed convenience: reads the single element at the given index of a data item.
Definition hydrocouplehelpers.h:201
HydroCouple namespace contains the core interface specifications for the HydroCouple component-based ...
Definition hydrocouple.h:58
DataKind
DataKind identifies the element type of a typed data buffer.
Definition hydrocouple.h:87
@ Float32
float
Definition hydrocouple.h:97
@ String
std::string (host memory only)
Definition hydrocouple.h:100
@ Boolean
bool (stored one element per byte)
Definition hydrocouple.h:99
@ Int16
int16_t
Definition hydrocouple.h:91
@ Int8
int8_t
Definition hydrocouple.h:89
@ UInt16
uint16_t
Definition hydrocouple.h:92
@ UInt64
uint64_t
Definition hydrocouple.h:96
@ UInt8
uint8_t
Definition hydrocouple.h:90
@ Int32
int32_t
Definition hydrocouple.h:93
@ Float64
double
Definition hydrocouple.h:98
@ UInt32
uint32_t
Definition hydrocouple.h:94
@ Opaque
Implementation-defined bytes (element size must be agreed out of band).
Definition hydrocouple.h:101
@ Int64
int64_t
Definition hydrocouple.h:95
BufferDescriptor describes a typed, possibly strided, possibly device-resident multi-dimensional arra...
Definition hydrocouple.h:134
DataKind kind
Element type.
Definition hydrocouple.h:136
const int64_t * stridesBytes
Byte step per dimension; nullptr => C-contiguous.
Definition hydrocouple.h:139
int32_t rank
Number of dimensions; 0 denotes a scalar.
Definition hydrocouple.h:137
const int64_t * shape
Extent per dimension; length == rank.
Definition hydrocouple.h:138
void * data
Base address of element (0, 0, ..., 0).
Definition hydrocouple.h:135
static constexpr DataKind kind
Definition hydrocouplehelpers.h:74
static constexpr DataKind kind
Definition hydrocouplehelpers.h:73
static constexpr DataKind kind
Definition hydrocouplehelpers.h:72
static constexpr DataKind kind
Definition hydrocouplehelpers.h:66
static constexpr DataKind kind
Definition hydrocouplehelpers.h:68
static constexpr DataKind kind
Definition hydrocouplehelpers.h:70
static constexpr DataKind kind
Definition hydrocouplehelpers.h:64
static constexpr DataKind kind
Definition hydrocouplehelpers.h:75
static constexpr DataKind kind
Definition hydrocouplehelpers.h:67
static constexpr DataKind kind
Definition hydrocouplehelpers.h:69
static constexpr DataKind kind
Definition hydrocouplehelpers.h:71
static constexpr DataKind kind
Definition hydrocouplehelpers.h:65
DataKindOf maps a C++ type to its DataKind at compile time.
Definition hydrocouplehelpers.h:63
static constexpr DataKind kind
Definition hydrocouplehelpers.h:63