Skip to content

Commit 4078b83

Browse files
committed
++
1 parent da3b967 commit 4078b83

File tree

2 files changed

+50
-95
lines changed

2 files changed

+50
-95
lines changed

src/core/utilities/box/box.hpp

Lines changed: 0 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -98,22 +98,6 @@ struct Box
9898
NO_DISCARD auto shape() const { return upper - lower + 1; }
9999
NO_DISCARD auto size() const { return core::product(shape(), std::size_t{1}); }
100100

101-
NO_DISCARD Type rows() const
102-
{
103-
if constexpr (dim == 1)
104-
return 1;
105-
if constexpr (dim == 2)
106-
return shape(0);
107-
if constexpr (dim == 3)
108-
return shape(0) * shape(1);
109-
}
110-
NO_DISCARD Type slabs() const
111-
{
112-
if constexpr (dim == 1 || dim == 2)
113-
return 1;
114-
if constexpr (dim == 3)
115-
return shape(0);
116-
}
117101

118102
using iterator = box_iterator<Type, dim>;
119103
NO_DISCARD auto begin() { return iterator{this, lower}; }
@@ -206,38 +190,6 @@ class box_iterator
206190
return *this;
207191
}
208192

209-
auto& operator+=(std::uint32_t s)
210-
{
211-
auto lo = box_->upper;
212-
for (std::uint16_t d = 0; d < dim; ++d)
213-
lo[d] += 1 - box_->lower[d];
214-
if constexpr (dim == 3)
215-
{
216-
{
217-
auto const prod = lo[1] * lo[2];
218-
auto const div = s / prod;
219-
s -= div * prod;
220-
index_[0] += div;
221-
}
222-
auto const div = s / lo[2];
223-
s -= div * lo[2];
224-
index_[1] += div;
225-
}
226-
if constexpr (dim == 2)
227-
{
228-
auto const div = s / lo[1];
229-
s -= div * lo[1];
230-
index_[0] += div;
231-
}
232-
index_[dim - 1] += s;
233-
return *this;
234-
}
235-
auto operator+(std::uint32_t const s) const
236-
{
237-
auto copy = *this;
238-
copy += s;
239-
return copy;
240-
}
241193

242194
bool operator!=(box_iterator const& other) const
243195
{

src/diagnostic/detail/vtkh5_type_writer.hpp

Lines changed: 50 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -111,24 +111,6 @@ struct H5TypeWriter<Writer>::VTKFileFieldInfo
111111
{
112112
}
113113

114-
auto static flat_cell(auto const& shape, auto const& icell)
115-
{
116-
if constexpr (dimension == 2)
117-
return icell[1] + icell[0] * shape[1];
118-
if constexpr (dimension == 3)
119-
return icell[2] + icell[1] * shape[2] + icell[0] * shape[1] * shape[2];
120-
return icell[0];
121-
}
122-
123-
auto z_jump(auto const& shape, auto const& local_box) // only called in a 3d context
124-
{
125-
auto const second_slab_start = [&]() {
126-
auto lo = local_box.lower;
127-
lo[0] += 1;
128-
return lo;
129-
}();
130-
return flat_cell(shape, second_slab_start) - flat_cell(shape, local_box.lower);
131-
}
132114

133115
std::string lvl;
134116
GridLayout const& layout;
@@ -145,12 +127,13 @@ struct H5TypeWriter<Writer>::VTKFileFieldWriter
145127
{
146128
void write2D(auto const& field)
147129
{
148-
auto ds = fw->h5file.getDataSet(finfo.path);
149-
auto const write = [&]() {
150-
auto bit = finfo.local_box.begin();
151-
for (std::uint32_t i = 0; i < finfo.local_box.rows();
152-
++i, bit += finfo.primal_row_len, data_offset += finfo.primal_row_len)
153-
ds.select({data_offset}, {finfo.primal_row_len}).write_raw(&field(*bit));
130+
auto ds = fw->h5file.getDataSet(finfo.path);
131+
auto const lcl_box = finfo.local_box;
132+
auto const write = [&]() {
133+
for (std::uint32_t i = lcl_box.lower[0]; i <= lcl_box.upper[0];
134+
++i, data_offset += finfo.primal_row_len)
135+
ds.select({data_offset}, {finfo.primal_row_len})
136+
.write_raw(&field(i, lcl_box.lower[1]));
154137
};
155138
write();
156139
write();
@@ -159,14 +142,13 @@ struct H5TypeWriter<Writer>::VTKFileFieldWriter
159142

160143
void write3D(auto const& field)
161144
{
162-
auto ds = fw->h5file.getDataSet(finfo.path);
163-
auto const gb_shape = finfo.ghost_box.shape().as_unsigned().toArray();
164-
auto const z_jump = finfo.z_jump(gb_shape, finfo.local_box);
165-
auto bit = finfo.local_box.begin();
166-
for (std::uint32_t s = 0; s < finfo.local_box.slabs(); ++s, bit += z_jump)
167-
for (std::uint32_t i = 0; i < finfo.local_box.rows();
168-
++i, bit += finfo.primal_row_len, data_offset += finfo.primal_row_len)
169-
ds.select({data_offset}, {finfo.primal_row_len}).write_raw(&field(*bit));
145+
auto ds = fw->h5file.getDataSet(finfo.path);
146+
auto const lcl_box = finfo.local_box;
147+
for (std::uint32_t i = lcl_box.lower[0]; i <= lcl_box.upper[0]; ++i)
148+
for (std::uint32_t j = lcl_box.lower[1]; j <= lcl_box.upper[1];
149+
++j, data_offset += finfo.primal_row_len)
150+
ds.select({data_offset}, {finfo.primal_row_len})
151+
.write_raw(&field(i, j, lcl_box.lower[2]));
170152
}
171153

172154

@@ -193,14 +175,14 @@ struct H5TypeWriter<Writer>::VTKFileTensorFieldWriter
193175

194176
void write2D(auto const& tf)
195177
{
196-
auto ds = fw->h5file.getDataSet(finfo.path);
197-
198-
auto const write = [&]() {
199-
auto bit = finfo.local_box.begin();
200-
for (std::uint32_t i = 0; i < finfo.local_box.rows();
201-
++i, bit += finfo.primal_row_len, data_offset += finfo.primal_row_len)
178+
auto ds = fw->h5file.getDataSet(finfo.path);
179+
auto const lcl_box = finfo.local_box;
180+
auto const write = [&]() {
181+
for (std::uint32_t i = lcl_box.lower[0]; i <= lcl_box.upper[0];
182+
++i, data_offset += finfo.primal_row_len)
202183
for (std::uint32_t c = 0; c < N; ++c)
203-
ds.select({data_offset, c}, {finfo.primal_row_len, 1}).write_raw(&tf[c](*bit));
184+
ds.select({data_offset, c}, {finfo.primal_row_len, 1})
185+
.write_raw(&tf[c](i, lcl_box.lower[1]));
204186
};
205187
write();
206188
write();
@@ -209,15 +191,14 @@ struct H5TypeWriter<Writer>::VTKFileTensorFieldWriter
209191

210192
void write3D(auto const& tf)
211193
{
212-
auto ds = fw->h5file.getDataSet(finfo.path);
213-
auto const gb_shape = finfo.ghost_box.shape().as_unsigned().toArray();
214-
auto const z_jump = finfo.z_jump(gb_shape, finfo.local_box);
215-
auto bit = finfo.local_box.begin();
216-
for (std::uint32_t s = 0; s < finfo.local_box.slabs(); ++s, bit += z_jump)
217-
for (std::uint32_t i = 0; i < finfo.local_box.rows();
218-
++i, bit += finfo.primal_row_len, data_offset += finfo.primal_row_len)
194+
auto ds = fw->h5file.getDataSet(finfo.path);
195+
auto const lcl_box = finfo.local_box;
196+
for (std::uint32_t i = lcl_box.lower[0]; i <= lcl_box.upper[0]; ++i)
197+
for (std::uint32_t j = lcl_box.lower[1]; j <= lcl_box.upper[1];
198+
++j, data_offset += finfo.primal_row_len)
219199
for (std::uint32_t c = 0; c < N; ++c)
220-
ds.select({data_offset, c}, {finfo.primal_row_len, 1}).write_raw(&tf[c](*bit));
200+
ds.select({data_offset, c}, {finfo.primal_row_len, 1})
201+
.write_raw(&tf[c](i, j, lcl_box.lower[2]));
221202
}
222203

223204

@@ -282,6 +263,14 @@ struct H5TypeWriter<Writer>::VTKFileWriter
282263
root.template createAttribute<std::string>("GridDescription", "XYZ");
283264
}
284265

266+
267+
auto level_spacing(std::size_t const lvl) const
268+
{
269+
auto const mesh_size = typewriter->h5Writer_.modelView().cellWidth();
270+
return core::for_N_make_array<dimension>(
271+
[&](auto i) { return static_cast<float>(mesh_size[i] / std::pow(2, lvl)); });
272+
}
273+
285274
void writeField(auto const& field, auto const& layout)
286275
{
287276
VTKFileFieldWriter{this, {layout}}(field);
@@ -328,6 +317,20 @@ struct H5TypeWriter<Writer>::VTKFileWriter
328317
path, std::vector<hsize_t>{detail::CHUNK_SIZE},
329318
HighFive::DataSpace({0}, {HighFive::DataSpace::UNLIMITED}));
330319
}
320+
321+
auto level_group = h5file.file().getGroup(level_base + lvl);
322+
if (!level_group.hasAttribute("Spacing"))
323+
{
324+
level_group.template createAttribute<std::array<float, dimension>>(
325+
"Spacing", level_spacing(level));
326+
327+
level_group.createGroup("CellData");
328+
level_group.createGroup("FieldData");
329+
330+
auto steps_group = h5file.file().getGroup(step_level + lvl);
331+
steps_group.createGroup("CellDataOffset");
332+
steps_group.createGroup("FieldDataOffset");
333+
}
331334
}
332335

333336
void initFieldFileLevel(int const level, auto& boxes)

0 commit comments

Comments
 (0)