| Line | Branch | Exec | Source |
|---|---|---|---|
| 1 | // Copyright (C) 2025 Tiago V. L. Amorim (@tiagovla) | ||
| 2 | // | ||
| 3 | // This file is part of oiseau (https://github.com/tiagovla/oiseau) | ||
| 4 | // | ||
| 5 | // SPDX-License-Identifier: GPL-3.0-or-later | ||
| 6 | |||
| 7 | #pragma once | ||
| 8 | |||
| 9 | #include <array> | ||
| 10 | #include <cstddef> | ||
| 11 | #include <istream> | ||
| 12 | #include <string> | ||
| 13 | #include <utility> | ||
| 14 | #include <vector> | ||
| 15 | |||
| 16 | namespace oiseau::io { | ||
| 17 | |||
| 18 | struct MeshFormatSection { | ||
| 19 | double version{}; | ||
| 20 | int is_binary{}; | ||
| 21 | std::size_t data_size{}; | ||
| 22 | |||
| 23 | 2 | MeshFormatSection() = default; | |
| 24 | 3 | MeshFormatSection(double version, int is_binary, std::size_t data_size) | |
| 25 | 3 | : version(version), is_binary(is_binary), data_size(data_size) {} | |
| 26 | }; | ||
| 27 | |||
| 28 | struct EntityEntry { | ||
| 29 | std::size_t tag; | ||
| 30 | std::vector<double> boundary_coords; | ||
| 31 | std::vector<int> physical_tags; | ||
| 32 | std::vector<int> bounding_tags; | ||
| 33 | |||
| 34 | 2 | EntityEntry(std::size_t tag, std::vector<double>&& boundary_coords, | |
| 35 | std::vector<int>&& physical_tags, std::vector<int>&& bounding_tags) | ||
| 36 | 2 | : tag(tag), | |
| 37 | 2 | boundary_coords(std::move(boundary_coords)), | |
| 38 | 2 | physical_tags(std::move(physical_tags)), | |
| 39 | 2 | bounding_tags(std::move(bounding_tags)) {} | |
| 40 | 3 | EntityEntry(std::size_t tag, std::vector<double>&& boundary_coords, | |
| 41 | std::vector<int>&& physical_tags) | ||
| 42 | 3 | : tag(tag), | |
| 43 | 3 | boundary_coords(std::move(boundary_coords)), | |
| 44 | 3 | physical_tags(std::move(physical_tags)) {} | |
| 45 | }; | ||
| 46 | |||
| 47 | struct EntitiesSection { | ||
| 48 | std::array<std::vector<EntityEntry>, 4> blocks{}; | ||
| 49 | |||
| 50 | 2 | EntitiesSection() = default; | |
| 51 | 2 | explicit EntitiesSection(std::array<std::vector<EntityEntry>, 4>&& blocks) : blocks(blocks) {} | |
| 52 | }; | ||
| 53 | |||
| 54 | struct PhysicalNamesSection { | ||
| 55 | int num_physical_names{}; | ||
| 56 | std::vector<int> dimensions{}; | ||
| 57 | std::vector<int> physical_tags{}; | ||
| 58 | std::vector<std::string> names{}; | ||
| 59 | |||
| 60 | 2 | PhysicalNamesSection() = default; | |
| 61 | 1 | PhysicalNamesSection(int num_physical_names, std::vector<int>&& dimensions, | |
| 62 | std::vector<int>&& physical_tags, std::vector<std::string>&& names) | ||
| 63 | 1 | : num_physical_names(num_physical_names), | |
| 64 | 1 | dimensions(std::move(dimensions)), | |
| 65 | 1 | physical_tags(std::move(physical_tags)), | |
| 66 | 1 | names(std::move(names)) {}; | |
| 67 | }; | ||
| 68 | |||
| 69 | struct NodesBlock { | ||
| 70 | int entity_dim; | ||
| 71 | int entity_tag; | ||
| 72 | int parametric; | ||
| 73 | std::size_t num_nodes_in_block; | ||
| 74 | std::vector<std::size_t> node_tags; | ||
| 75 | std::vector<double> node_coords; | ||
| 76 | |||
| 77 | 5 | NodesBlock(int entity_dim, int entity_tag, int parametric, std::size_t num_nodes_in_block, | |
| 78 | std::vector<std::size_t>&& node_tags, std::vector<double>&& node_coords) | ||
| 79 | 5 | : entity_dim(entity_dim), | |
| 80 | 5 | entity_tag(entity_tag), | |
| 81 | 5 | parametric(parametric), | |
| 82 | 5 | num_nodes_in_block(num_nodes_in_block), | |
| 83 | 5 | node_tags(std::move(node_tags)), | |
| 84 | 5 | node_coords(std::move(node_coords)) {} | |
| 85 | }; | ||
| 86 | |||
| 87 | struct NodesSection { | ||
| 88 | std::size_t num_entity_blocks{}; | ||
| 89 | std::size_t num_nodes{}; | ||
| 90 | std::size_t min_node_tag{}; | ||
| 91 | std::size_t max_node_tag{}; | ||
| 92 | std::vector<NodesBlock> blocks{}; | ||
| 93 | |||
| 94 | 2 | NodesSection() = default; | |
| 95 | 3 | NodesSection(std::size_t num_entity_blocks, std::size_t num_nodes, std::size_t min_node_tag, | |
| 96 | std::size_t max_node_tag, std::vector<NodesBlock>&& blocks) | ||
| 97 | 3 | : num_entity_blocks(num_entity_blocks), | |
| 98 | 3 | num_nodes(num_nodes), | |
| 99 | 3 | min_node_tag(min_node_tag), | |
| 100 | 3 | max_node_tag(max_node_tag), | |
| 101 | 3 | blocks(std::move(blocks)) {} | |
| 102 | }; | ||
| 103 | |||
| 104 | struct ElementBlock { | ||
| 105 | int entity_dim; | ||
| 106 | int entity_tag; | ||
| 107 | int element_type; | ||
| 108 | std::size_t num_elements_in_block; | ||
| 109 | std::vector<std::size_t> data; | ||
| 110 | |||
| 111 | 3 | ElementBlock(int entity_dim, int entity_tag, int element_type, std::size_t num_elements_in_block, | |
| 112 | std::vector<std::size_t>&& data) | ||
| 113 | 3 | : entity_dim(entity_dim), | |
| 114 | 3 | entity_tag(entity_tag), | |
| 115 | 3 | element_type(element_type), | |
| 116 | 3 | num_elements_in_block(num_elements_in_block), | |
| 117 | 3 | data(std::move(data)) {} | |
| 118 | }; | ||
| 119 | |||
| 120 | struct ElementSection { | ||
| 121 | std::size_t num_element_blocks{}; | ||
| 122 | std::size_t num_elements{}; | ||
| 123 | std::size_t min_element_tag{}; | ||
| 124 | std::size_t max_element_tag{}; | ||
| 125 | std::vector<ElementBlock> blocks{}; | ||
| 126 | |||
| 127 | 2 | ElementSection() = default; | |
| 128 | 2 | ElementSection(std::size_t num_element_blocks, std::size_t num_elements, | |
| 129 | std::size_t min_element_tag, std::size_t max_element_tag, | ||
| 130 | std::vector<ElementBlock>&& blocks) | ||
| 131 | 2 | : num_element_blocks(num_element_blocks), | |
| 132 | 2 | num_elements(num_elements), | |
| 133 | 2 | min_element_tag(min_element_tag), | |
| 134 | 2 | max_element_tag(max_element_tag), | |
| 135 | 2 | blocks(std::move(blocks)) {} | |
| 136 | }; | ||
| 137 | |||
| 138 | class GMSHFile { | ||
| 139 | public: | ||
| 140 | GMSHFile(MeshFormatSection&& mesh_format_section, PhysicalNamesSection&& physical_names_section, | ||
| 141 | EntitiesSection&& entities_section, NodesSection&& nodes_section, | ||
| 142 | ElementSection&& elements_section) | ||
| 143 | : mesh_format_section(std::move(mesh_format_section)), | ||
| 144 | physical_names_section(std::move(physical_names_section)), | ||
| 145 | entities_section(std::move(entities_section)), | ||
| 146 | nodes_section(std::move(nodes_section)), | ||
| 147 | elements_section(std::move(elements_section)) {} | ||
| 148 | |||
| 149 |
1/2✓ Branch 6 taken 2 times.
✗ Branch 7 not taken.
|
2 | explicit GMSHFile(std::istream& f_handler) { read(f_handler); } |
| 150 | |||
| 151 | MeshFormatSection mesh_format_section; | ||
| 152 | PhysicalNamesSection physical_names_section; | ||
| 153 | EntitiesSection entities_section; | ||
| 154 | NodesSection nodes_section; | ||
| 155 | ElementSection elements_section; | ||
| 156 | |||
| 157 | private: | ||
| 158 | void read(std::istream& f_handler); | ||
| 159 | }; | ||
| 160 | |||
| 161 | namespace detail { | ||
| 162 | MeshFormatSection mesh_format_handler(std::istream& f_handler); | ||
| 163 | PhysicalNamesSection physical_names_handler(std::istream& f_handler); | ||
| 164 | EntitiesSection entities_handler(std::istream& f_handler, bool is_binary); | ||
| 165 | NodesSection nodes_handler(std::istream& f_handler, bool is_binary); | ||
| 166 | ElementSection elements_handler(std::istream& f_handler, bool is_binary); | ||
| 167 | |||
| 168 | } // namespace detail | ||
| 169 | } // namespace oiseau::io | ||
| 170 |