@@ -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