Skip to content

Commit 37358dc

Browse files
committed
included zone class
1 parent b9b0c79 commit 37358dc

29 files changed

+2562
-133
lines changed

include/array/array.hpp

Lines changed: 27 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,33 @@ class PYBIND11_EXPORT Array : public Data {
9494
bool isNone() const override;
9595
/** @brief True when payload is a scalar numeric value. */
9696
bool isScalar() const override;
97+
/** @brief Number of array dimensions. */
98+
size_t dimensions() const override {
99+
return this->_dimensions;
100+
}
101+
/** @brief Total number of elements. */
102+
size_t size() const override {
103+
return this->_size;
104+
}
105+
/** @brief Shape vector. */
106+
std::vector<size_t> shape() const override {
107+
return this->_shape;
108+
}
109+
/** @brief NumPy dtype short name (for example ``float64``). */
110+
std::string dtype() const override;
111+
/** @brief Create a filled array payload with requested shape/dtype. */
112+
std::shared_ptr<Data> full(
113+
const std::vector<size_t>& shape,
114+
double value,
115+
const std::string& dtypeName) const override;
116+
/** @brief Flatten according to NumPy-like ``order`` semantics. */
117+
std::shared_ptr<Data> ravel(const std::string& order = "K") const override;
118+
/** @brief Take one index along axis and return result as a new payload. */
119+
std::shared_ptr<Data> take(int64_t index, size_t axis) const override;
120+
/** @brief Read one value at indices and cast to int64. */
121+
int64_t itemAsInt64(const std::vector<size_t>& indices) const override;
122+
/** @brief Write one value at indices from int64. */
123+
void setItemFromInt64(const std::vector<size_t>& indices, int64_t value) override;
97124
/** @brief True when memory is contiguous in C or Fortran order. */
98125
bool isContiguous() const;
99126
/** @brief True when memory is C-order contiguous. */
@@ -204,21 +231,6 @@ class PYBIND11_EXPORT Array : public Data {
204231
consultation of array properties
205232
*/
206233

207-
/** @brief Number of array dimensions. */
208-
size_t dimensions() const {
209-
return this->_dimensions;
210-
}
211-
212-
/** @brief Total number of elements. */
213-
size_t size() const {
214-
return this->_size;
215-
}
216-
217-
/** @brief Shape vector. */
218-
std::vector<size_t> shape() const {
219-
return this->_shape;
220-
}
221-
222234
/** @brief Strides (bytes per dimension). */
223235
std::vector<size_t> strides() const {
224236
return this->_strides;

include/cgns/zone.hpp

Lines changed: 125 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,125 @@
1+
#ifndef ZONE_HPP
2+
#define ZONE_HPP
3+
4+
# include <iostream>
5+
# include <memory>
6+
# include <functional>
7+
# include <string>
8+
# include <vector>
9+
# include <array>
10+
# include <algorithm>
11+
# include <cstdint>
12+
# include <variant>
13+
# include <type_traits>
14+
# include <utility>
15+
# include <sstream>
16+
# include <tuple>
17+
18+
# include "node/node.hpp"
19+
20+
// Zone is compiled in the same shared library as Node.
21+
#ifndef ZONE_EXPORT
22+
#define ZONE_EXPORT NODE_EXPORT
23+
#endif
24+
25+
/**
26+
* @brief CGNS Zone helper built on top of Node.
27+
*
28+
* The class mirrors a subset of treelab Zone capabilities and focuses on:
29+
* - zone dimensional metadata (points/cells)
30+
* - field container creation/access helpers
31+
* - coordinate shortcuts
32+
* - shape inference and boundary extraction for structured zones
33+
*
34+
* Not implemented by design: save(), useEquation().
35+
*/
36+
class ZONE_EXPORT Zone : public Node {
37+
public:
38+
using NamedData = std::pair<std::string, std::shared_ptr<Data>>;
39+
using NamedDataList = std::vector<NamedData>;
40+
using DataList = std::vector<std::shared_ptr<Data>>;
41+
using ShapePair = std::pair<std::vector<size_t>, std::vector<size_t>>;
42+
using ZoneList = std::vector<std::shared_ptr<Zone>>;
43+
44+
explicit Zone(const std::string& name = "Zone");
45+
46+
bool isStructured() const;
47+
bool isUnstructured() const;
48+
std::vector<std::string> getElementsTypes() const;
49+
50+
size_t dim() const;
51+
std::vector<size_t> shape() const;
52+
std::vector<size_t> shapeOfCoordinates() const;
53+
size_t numberOfPoints() const;
54+
size_t numberOfCells() const;
55+
56+
DataList newFields(
57+
const std::vector<std::pair<std::string, double>>& inputFields,
58+
const std::string& container = "FlowSolution",
59+
const std::string& gridLocation = "auto",
60+
const std::string& dtype = "float64",
61+
bool ravel = false);
62+
63+
void removeFields(
64+
const std::vector<std::string>& fieldNames,
65+
const std::string& container = "FlowSolution");
66+
67+
DataList fields(
68+
const std::vector<std::string>& fieldNames,
69+
const std::string& container = "FlowSolution",
70+
const std::string& behaviorIfNotFound = "create",
71+
const std::string& dtype = "float64",
72+
bool ravel = false);
73+
74+
std::shared_ptr<Data> field(
75+
const std::string& fieldName,
76+
const std::string& container = "FlowSolution",
77+
const std::string& behaviorIfNotFound = "create",
78+
const std::string& dtype = "float64",
79+
bool ravel = false);
80+
81+
DataList xyz(bool ravel = false) const;
82+
DataList xy(bool ravel = false) const;
83+
DataList xz(bool ravel = false) const;
84+
DataList yz(bool ravel = false) const;
85+
std::shared_ptr<Data> x(bool ravel = false) const;
86+
std::shared_ptr<Data> y(bool ravel = false) const;
87+
std::shared_ptr<Data> z(bool ravel = false) const;
88+
89+
NamedDataList allFields(
90+
bool includeCoordinates = true,
91+
bool appendContainerToFieldName = false,
92+
bool ravel = false) const;
93+
94+
void assertFieldsSizeCoherency() const;
95+
std::string inferLocation(const std::string& container) const;
96+
bool hasFields() const;
97+
98+
ShapePair getArrayShapes() const;
99+
void updateShape();
100+
bool isEmpty() const;
101+
102+
ZoneList boundaries();
103+
std::shared_ptr<Zone> boundary(
104+
const std::string& index = "i",
105+
const std::string& bound = "min");
106+
std::shared_ptr<Zone> imin();
107+
std::shared_ptr<Zone> imax();
108+
std::shared_ptr<Zone> jmin();
109+
std::shared_ptr<Zone> jmax();
110+
std::shared_ptr<Zone> kmin();
111+
std::shared_ptr<Zone> kmax();
112+
113+
private:
114+
std::vector<std::array<int64_t, 3>> extractZoneShapeEntries(const char* context) const;
115+
std::vector<size_t> shapeAtLocation(const std::string& location, const char* context) const;
116+
117+
std::shared_ptr<Node> ensureZoneTypeNode();
118+
std::shared_ptr<Node> zoneTypeNode() const;
119+
std::shared_ptr<Node> containerNode(const std::string& containerName) const;
120+
std::vector<std::shared_ptr<Node>> directChildrenByType(const std::string& nodeType) const;
121+
122+
static std::string defaultGridLocationFor(const std::string& containerName);
123+
};
124+
125+
#endif

include/data/data.hpp

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
# include <memory>
66
# include <cstdint>
77
# include <type_traits>
8+
# include <vector>
89

910
/**
1011
* @brief Abstract interface for payload values attached to Node instances.
@@ -33,6 +34,48 @@ class Data {
3334
/** @brief True when payload is a scalar numeric value. */
3435
virtual bool isScalar() const = 0;
3536

37+
/** @brief Number of payload dimensions. */
38+
virtual size_t dimensions() const = 0;
39+
/** @brief Total number of payload elements. */
40+
virtual size_t size() const = 0;
41+
/** @brief Shape of payload dimensions. */
42+
virtual std::vector<size_t> shape() const = 0;
43+
/** @brief Human-readable dtype name (for example ``float64``). */
44+
virtual std::string dtype() const = 0;
45+
46+
/**
47+
* @brief Build a filled array-like payload.
48+
* @param shape Output shape.
49+
* @param value Fill value.
50+
* @param dtypeName Target dtype name.
51+
*/
52+
virtual std::shared_ptr<Data> full(
53+
const std::vector<size_t>& shape,
54+
double value,
55+
const std::string& dtypeName) const = 0;
56+
/**
57+
* @brief Return a flattened view/copy according to backend semantics.
58+
* @param order Flattening order (``C``, ``F``, ``A``, ``K``).
59+
*/
60+
virtual std::shared_ptr<Data> ravel(const std::string& order = "K") const = 0;
61+
/**
62+
* @brief Extract a slice by taking one index along a given axis.
63+
* @param index Index to take (negative indices allowed by backend).
64+
* @param axis Axis where index is taken.
65+
*/
66+
virtual std::shared_ptr<Data> take(int64_t index, size_t axis) const = 0;
67+
/**
68+
* @brief Read one element at multidimensional indices and cast to int64.
69+
* @param indices Index tuple with one index per dimension.
70+
*/
71+
virtual int64_t itemAsInt64(const std::vector<size_t>& indices) const = 0;
72+
/**
73+
* @brief Write one element at multidimensional indices from int64.
74+
* @param indices Index tuple with one index per dimension.
75+
* @param value New value converted to payload dtype.
76+
*/
77+
virtual void setItemFromInt64(const std::vector<size_t>& indices, int64_t value) = 0;
78+
3679
/** @brief Extract payload as UTF-8 string when available. */
3780
virtual std::string extractString() const = 0;
3881

include/node/node.hpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ struct NODE_EXPORT ParameterValue {
9090
};
9191

9292
/**
93-
* @brief Hierarchical node for CGNS-like tree structures.
93+
* @brief Hierarchical node for tree structures.
9494
*
9595
* A Node stores:
9696
* - name/type metadata
@@ -138,10 +138,11 @@ class NODE_EXPORT Node : public std::enable_shared_from_this<Node> {
138138
*/
139139
Node(const std::string& name = "", const std::string& type = "DataArray_t");
140140

141-
~Node();
141+
virtual ~Node();
142142

143143
/** @brief Access navigation helper bound to this node. */
144144
Navigation& pick();
145+
Navigation& pick() const;
145146

146147
/** @brief Shared pointer to this node (or null when unmanaged). */
147148
std::shared_ptr<Node> selfPtr();

0 commit comments

Comments
 (0)