22#define PHARE_DIAGNOSTIC_DETAIL_VTK_H5_TYPE_WRITER_HPP
33
44#include " core/logger.hpp"
5+ #include " core/utilities/algorithm.hpp"
56#include " core/utilities/box/box.hpp"
67#include " core/utilities/mpi_utils.hpp"
78#include " core/data/tensorfield/tensorfield.hpp"
1819
1920// TODO:
2021// remove logging
21- // write as column major/Fortran memory ordering
22+ // write as column major/Fortran memory ordering - done. but badly
2223
2324
2425namespace PHARE ::diagnostic::vtkh5::detail
@@ -45,7 +46,7 @@ class H5TypeWriter : public PHARE::diagnostic::TypeWriter
4546
4647public:
4748 static constexpr auto dimension = Writer::dimension;
48- using Attributes = typename Writer::Attributes ;
49+ using GridLayout = Writer::GridLayout ;
4950 using Box_t = core::Box<int , dimension>;
5051
5152 H5TypeWriter (Writer& h5Writer)
@@ -89,8 +90,9 @@ class H5TypeWriter : public PHARE::diagnostic::TypeWriter
8990
9091 struct VTKFileFieldInfo // assumes all primal
9192 {
92- VTKFileFieldInfo (auto const & field, auto const & layout)
93- : lvl{std::to_string (layout.levelNumber ())}
93+ VTKFileFieldInfo (auto const & field, auto const & lyout)
94+ : lvl{std::to_string (lyout.levelNumber ())}
95+ , layout{lyout}
9496 , ghost_box{layout.AMRGhostBoxFor (field)}
9597 , local_box{layout.AMRToLocal (core::grow (ghost_box, -1 * layout.nbrGhosts ()))}
9698 {
@@ -116,6 +118,7 @@ class H5TypeWriter : public PHARE::diagnostic::TypeWriter
116118 }
117119
118120 std::string lvl;
121+ GridLayout const & layout;
119122 Box_t const ghost_box;
120123 core::Box<std::uint32_t , dimension> const local_box;
121124 std::uint32_t const primal_row_len = local_box.shape(dimension - 1 );
@@ -127,17 +130,12 @@ class H5TypeWriter : public PHARE::diagnostic::TypeWriter
127130 {
128131 void write2D (auto const & field)
129132 {
130- PHARE_LOG_LINE_SS (finfo.ghost_box << " " << finfo.local_box << " "
131- << finfo.primal_row_len );
132133 auto ds = fw->h5file .getDataSet (finfo.path );
133134 auto const write = [&]() {
134135 auto bit = finfo.local_box .begin ();
135136 for (std::uint32_t i = 0 ; i < finfo.local_box .rows ();
136137 ++i, bit += finfo.primal_row_len , data_offset += finfo.primal_row_len )
137- {
138- PHARE_LOG_LINE_SS (data_offset << " " << finfo.primal_row_len << " " << *bit);
139138 ds.select ({data_offset}, {finfo.primal_row_len }).write_raw (&field (*bit));
140- }
141139 };
142140 write ();
143141 write ();
@@ -155,10 +153,12 @@ class H5TypeWriter : public PHARE::diagnostic::TypeWriter
155153 }
156154 void operator ()(auto const & field)
157155 {
156+ auto & tmp = fw->typewriter ->h5Writer_ .modelView ().tmpField ();
157+ auto const frimal = core::convert_to_fortran_primal (tmp, field, finfo.layout );
158158 if constexpr (dimension == 2 )
159- write2D (field );
159+ write2D (frimal );
160160 if constexpr (dimension == 3 )
161- write3D (field );
161+ write3D (frimal );
162162 }
163163
164164 VTKFileWriter* fw;
@@ -201,6 +201,8 @@ class H5TypeWriter : public PHARE::diagnostic::TypeWriter
201201 }
202202 void operator ()(auto const & tf)
203203 {
204+ auto & tmp = fw->typewriter ->h5Writer_ .modelView ().template tmpTensorField <rank>();
205+ auto const frimal = core::convert_to_fortran_primal (tmp, tf, finfo.layout );
204206 if constexpr (dimension == 2 )
205207 write2D (tf);
206208 if constexpr (dimension == 3 )
@@ -257,17 +259,13 @@ class H5TypeWriter : public PHARE::diagnostic::TypeWriter
257259
258260 void writeField (auto const & field, auto const & layout)
259261 {
260- PHARE_LOG_LINE_SS (" writeField " << field.name ());
261262 VTKFileFieldWriter{this , {field, layout}}(field);
262- PHARE_LOG_LINE_SS (" done" );
263263 }
264264
265265 template <std::size_t rank = 2 > // TODO convert duals to primals
266266 void writeTensorField (auto const & tf, auto const & layout)
267267 {
268- PHARE_LOG_LINE_SS (" writeTensorField " << tf.name ());
269268 VTKFileTensorFieldWriter<rank>{this , {tf[0 ], layout}}(tf);
270- PHARE_LOG_LINE_SS (" done" );
271269 }
272270
273271 template <typename T = FloatType>
@@ -308,15 +306,13 @@ class H5TypeWriter : public PHARE::diagnostic::TypeWriter
308306
309307 void initFieldFileLevel (int const level, auto & boxes)
310308 {
311- PHARE_LOG_LINE_SS (" initFieldFileLevel" );
312309 initDSDefault (level_base + std::to_string (level) + " /PointData/data" );
313310 resize (level, boxes);
314311 }
315312
316313 template <std::size_t rank = 2 >
317314 void initTensorFieldFileLevel (auto const level, auto & boxes)
318315 {
319- PHARE_LOG_LINE_SS (" initTensorFieldFileLevel" );
320316 auto constexpr N = core::detail::tensor_field_dim_from_rank<rank>();
321317 auto const path = level_base + std::to_string (level) + " /PointData/data" ;
322318 h5file.template create_chunked_data_set <FloatType>(
@@ -336,7 +332,6 @@ class H5TypeWriter : public PHARE::diagnostic::TypeWriter
336332 // and 1d data is * 4
337333 constexpr static auto X_TIMES = std::array{4 , 2 , /* 3d noop */ 1 }[dimension - 1 ];
338334
339- PHARE_LOG_LINE_SS (" resize_data" );
340335 auto const lvl = std::to_string (ilvl);
341336 auto const data_path = level_base + lvl + " /PointData/data" ;
342337 auto point_data_ds = h5file.getDataSet (data_path);
@@ -353,21 +348,17 @@ class H5TypeWriter : public PHARE::diagnostic::TypeWriter
353348 core::sum_from (boxes, [](auto const & b) { return b.size () * X_TIMES; }));
354349 auto const new_size = data_offset + core::sum (rank_data_size);
355350
356- PHARE_LOG_LINE_SS (new_size);
357351 if constexpr (N == 1 )
358352 point_data_ds.resize ({new_size});
359353 else
360354 point_data_ds.resize ({new_size, N});
361355 for (int i = 0 ; i < core::mpi::rank (); ++i)
362356 data_offset += rank_data_size[i];
363- PHARE_LOG_LINE_SS (" done" );
364357 }
365358
366359
367360 void resize_boxes (auto const ilvl, auto const & boxes)
368361 {
369- PHARE_LOG_LINE_SS (" resize_boxes" );
370-
371362 auto const lvl = std::to_string (ilvl);
372363 auto const rank_box_size = core::mpi::collect (boxes.size ());
373364 auto const total_boxes = core::sum (rank_box_size);
@@ -389,17 +380,12 @@ class H5TypeWriter : public PHARE::diagnostic::TypeWriter
389380 ds.select ({old_size}, {1 }).write (box_offset);
390381 }
391382
392-
393383 amrbox_ds.resize ({box_offset + total_boxes, 6 });
394- PHARE_LOG_LINE_SS (" resize" );
395384 for (int i = 0 ; i < core::mpi::rank (); ++i)
396385 box_offset += rank_box_size[i];
397386
398- PHARE_LOG_LINE_SS (" writeBoxesForLevel" );
399387 auto const vtk_boxes = VTKBoxes{boxes};
400388 amrbox_ds.select ({box_offset, 0 }, {boxes.size (), dimension * 2 }).write (vtk_boxes.data );
401-
402- PHARE_LOG_LINE_SS (" done" );
403389 }
404390
405391 template <std::size_t N = 1 >
0 commit comments