|
| 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 |
0 commit comments