From 22d08bfba3bc180befe4a6595b4dd5ca33f57cbe Mon Sep 17 00:00:00 2001 From: Jan Nikl Date: Wed, 11 Mar 2026 16:57:23 -0700 Subject: [PATCH 1/8] Added settings commands to StreamReader. --- lib/stream_reader.cpp | 98 +++++++++++++++++++++++++++++++++++++++---- lib/stream_reader.hpp | 2 + 2 files changed, 92 insertions(+), 8 deletions(-) diff --git a/lib/stream_reader.cpp b/lib/stream_reader.cpp index c88766b1..3416416c 100644 --- a/lib/stream_reader.cpp +++ b/lib/stream_reader.cpp @@ -19,6 +19,11 @@ using namespace mfem; enum class Command { + // Settings + FixOrientation, + SaveColoring, + KeepAttributes, + // Solution Mesh, Solution, Quadrature, @@ -66,6 +71,11 @@ static const StreamCommands commands; StreamCommands::StreamCommands() { + // Settings + (*this)[Command::FixOrientation] = {"fix_orientations", false, "<0/off/1/on>", "Turn off/on fix of the orientations for inverted elements."}; + (*this)[Command::SaveColoring] = {"save_coloring", false, "<0/off/1/on>", "Turn off/on saving of the mesh coloring generated when opening only a mesh."}; + (*this)[Command::KeepAttributes] = {"keep_attributes", false, "", "Toggles between processor rank and real attributes when loading a parallel solution."}; + // Solution (*this)[Command::Mesh] = {"mesh", false, "", "Visualize the mesh."}; (*this)[Command::Solution] = {"solution", false, " ", "Visualize the solution."}; (*this)[Command::Quadrature] = {"quadrature", false, " ", "Visualize the quadrature."}; @@ -120,6 +130,25 @@ int StreamReader::ReadStream( data.SetMesh(NULL); data.keys.clear(); + string str_cmd = data_type; + + while (true) + { + int err = ReadStreamOne(is, str_cmd); + if (err) { return err; } + + if (data.mesh) { break; } + + // load next command + is >> ws >> str_cmd; + } + + data.ExtrudeMeshAndSolution(); + return 0; +} + +int StreamReader::ReadStreamOne(istream &is, const string &data_type) +{ auto it = find(commands.begin(), commands.end(), data_type); if (it == commands.end()) { @@ -131,6 +160,27 @@ int StreamReader::ReadStream( Command cmd = (Command)(it - commands.begin()); switch (cmd) { + case Command::FixOrientation: + { + string mode; + is >> ws >> mode; + data.fix_elem_orient = (mode != "off" && mode != "0"); + } + break; + case Command::SaveColoring: + { + string mode; + is >> ws >> mode; + data.save_coloring = (mode != "off" && mode != "0"); + } + break; + case Command::KeepAttributes: + { + string mode; + is >> ws >> mode; + data.keep_attr = (mode != "proc"); + } + break; case Command::Fem2D: { Vector sol; @@ -313,7 +363,7 @@ int StreamReader::ReadStream( } break; case Command::Max: //dummy - break; + return 1; } if (commands[cmd].keys) @@ -321,7 +371,6 @@ int StreamReader::ReadStream( is >> data.keys; } - data.ExtrudeMeshAndSolution(); return 0; } @@ -333,8 +382,6 @@ int StreamReader::ReadStreams(const StreamCollection &input_streams) std::vector cgf_array(nproc); std::vector qf_array(nproc); - std::string data_type; - int gf_count = 0; int cgf_count = 0; int qf_count = 0; @@ -346,10 +393,45 @@ int StreamReader::ReadStreams(const StreamCollection &input_streams) #endif istream &isock = *input_streams[p]; // assuming the "parallel nproc p" part of the stream has been read - isock >> ws >> data_type >> ws; // "*_data" / "mesh" / "solution" + bool load_data = false; + Command cmd; + while (!load_data) + { + std::string data_type; + isock >> ws >> data_type; + + auto it = find(commands.begin(), commands.end(), data_type); + if (it == commands.end()) + { + cerr << "Unknown data format " << data_type << endl; + PrintCommands(); + return 1; + } + + cmd = (Command)(it - commands.begin()); + switch (cmd) + { + case Command::FixOrientation: + case Command::SaveColoring: + case Command::KeepAttributes: + // process on root + ReadStreamOne(isock, data_type); + break; + case Command::Mesh: + case Command::Solution: + case Command::Quadrature: #ifdef GLVIS_DEBUG - cout << " type " << data_type << " ... " << flush; + cout << " type " << data_type << " ... " << flush; #endif + load_data = true; + break; + default: + cerr << "Command not available in parallel"; + return 1; + } + } + + isock >> ws; mesh_array[p] = new Mesh(isock, 1, 0, data.fix_elem_orient); if (!data.keep_attr) { @@ -364,12 +446,12 @@ int StreamReader::ReadStreams(const StreamCollection &input_streams) } } gf_array[p] = NULL; - if (data_type == "quadrature") + if (cmd == Command::Quadrature) { qf_array[p] = new QuadratureFunction(mesh_array[p], isock); qf_count++; } - else if (data_type != "mesh") + else if (cmd != Command::Mesh) { if (CheckStreamIsComplex(isock, true)) { diff --git a/lib/stream_reader.hpp b/lib/stream_reader.hpp index e5ed9672..aaae3c20 100644 --- a/lib/stream_reader.hpp +++ b/lib/stream_reader.hpp @@ -26,6 +26,8 @@ class StreamReader static bool CheckStreamIsComplex(std::istream &sol, bool parallel = false); + int ReadStreamOne(std::istream &is, const std::string &data_type); + public: StreamReader(DataState &data_): data(data_) { } From 174a9b4a2c5907879c79c53c7e3e57627d803870 Mon Sep 17 00:00:00 2001 From: Jan Nikl Date: Wed, 11 Mar 2026 19:30:52 -0700 Subject: [PATCH 2/8] Fixed shadowing. --- lib/stream_reader.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/stream_reader.cpp b/lib/stream_reader.cpp index 3416416c..25264242 100644 --- a/lib/stream_reader.cpp +++ b/lib/stream_reader.cpp @@ -134,8 +134,8 @@ int StreamReader::ReadStream( while (true) { - int err = ReadStreamOne(is, str_cmd); - if (err) { return err; } + int ierr = ReadStreamOne(is, str_cmd); + if (ierr) { return ierr; } if (data.mesh) { break; } From 873359df7c8eee30b75ca1e7dc8a99706288e3d2 Mon Sep 17 00:00:00 2001 From: Jan Nikl Date: Wed, 11 Mar 2026 19:38:53 -0700 Subject: [PATCH 3/8] Minor changes based on review. --- lib/stream_reader.cpp | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/lib/stream_reader.cpp b/lib/stream_reader.cpp index 25264242..4621140f 100644 --- a/lib/stream_reader.cpp +++ b/lib/stream_reader.cpp @@ -20,7 +20,7 @@ using namespace mfem; enum class Command { // Settings - FixOrientation, + FixOrientations, SaveColoring, KeepAttributes, // Solution @@ -72,9 +72,9 @@ static const StreamCommands commands; StreamCommands::StreamCommands() { // Settings - (*this)[Command::FixOrientation] = {"fix_orientations", false, "<0/off/1/on>", "Turn off/on fix of the orientations for inverted elements."}; + (*this)[Command::FixOrientations] = {"fix_orientations", false, "<0/off/1/on>", "Turn off/on fix of the orientations for inverted elements."}; (*this)[Command::SaveColoring] = {"save_coloring", false, "<0/off/1/on>", "Turn off/on saving of the mesh coloring generated when opening only a mesh."}; - (*this)[Command::KeepAttributes] = {"keep_attributes", false, "", "Toggles between processor rank and real attributes when loading a parallel solution."}; + (*this)[Command::KeepAttributes] = {"keep_attributes", false, "", "Toggles between processor rank and real attributes when loading a parallel solution."}; // Solution (*this)[Command::Mesh] = {"mesh", false, "", "Visualize the mesh."}; (*this)[Command::Solution] = {"solution", false, " ", "Visualize the solution."}; @@ -160,7 +160,7 @@ int StreamReader::ReadStreamOne(istream &is, const string &data_type) Command cmd = (Command)(it - commands.begin()); switch (cmd) { - case Command::FixOrientation: + case Command::FixOrientations: { string mode; is >> ws >> mode; @@ -178,7 +178,7 @@ int StreamReader::ReadStreamOne(istream &is, const string &data_type) { string mode; is >> ws >> mode; - data.keep_attr = (mode != "proc"); + data.keep_attr = (mode != "proc" && mode != "off" && mode != "0"); } break; case Command::Fem2D: @@ -411,10 +411,10 @@ int StreamReader::ReadStreams(const StreamCollection &input_streams) cmd = (Command)(it - commands.begin()); switch (cmd) { - case Command::FixOrientation: + case Command::FixOrientations: case Command::SaveColoring: case Command::KeepAttributes: - // process on root + // assume the options are the same on all ranks ReadStreamOne(isock, data_type); break; case Command::Mesh: From b00eafedf6e609152e9e0d2597e366dc826eac2e Mon Sep 17 00:00:00 2001 From: Jan Nikl Date: Thu, 4 Jun 2026 12:38:55 -0700 Subject: [PATCH 4/8] Updated Changelog. --- CHANGELOG | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/CHANGELOG b/CHANGELOG index 492b96e1..76125c98 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -17,6 +17,12 @@ Version 4.5.1 (development) script. The overlay appears as a red line connecting the given points. The points line format is: number of points, followed by x y z coordinates. +- Added stream options to set up the parameters for loading the data. There are + 'fix_orientations', 'save_coloring' and 'keep_attributes' commands for the + corresponding options. These commands (to have an effect) must send before the + 'solution' command. However, they can be send only after the parallel streams + have been initialized by 'parallel' command (if used). + Version 4.5 released on Feb 6, 2026 =================================== From 035d6883989a4de591e6c04aed90f7b351ba4bb1 Mon Sep 17 00:00:00 2001 From: Jan Nikl Date: Sat, 6 Jun 2026 18:11:24 -0700 Subject: [PATCH 5/8] Keep attributes suggestion. Co-authored-by: John Camier --- lib/stream_reader.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/stream_reader.cpp b/lib/stream_reader.cpp index 4621140f..9a72290a 100644 --- a/lib/stream_reader.cpp +++ b/lib/stream_reader.cpp @@ -74,7 +74,7 @@ StreamCommands::StreamCommands() // Settings (*this)[Command::FixOrientations] = {"fix_orientations", false, "<0/off/1/on>", "Turn off/on fix of the orientations for inverted elements."}; (*this)[Command::SaveColoring] = {"save_coloring", false, "<0/off/1/on>", "Turn off/on saving of the mesh coloring generated when opening only a mesh."}; - (*this)[Command::KeepAttributes] = {"keep_attributes", false, "", "Toggles between processor rank and real attributes when loading a parallel solution."}; + (*this)[Command::KeepAttributes] = {"keep_attributes", false, "", "When loading a parallel solution, toggle between processor ranks and the original (real) attributes."}; // Solution (*this)[Command::Mesh] = {"mesh", false, "", "Visualize the mesh."}; (*this)[Command::Solution] = {"solution", false, " ", "Visualize the solution."}; From 66a54593792f8229bcfdb0df269cd8d916c85bac Mon Sep 17 00:00:00 2001 From: Jan Nikl Date: Sat, 6 Jun 2026 18:12:06 -0700 Subject: [PATCH 6/8] Save coloring suggestion. Co-authored-by: John Camier --- lib/stream_reader.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/stream_reader.cpp b/lib/stream_reader.cpp index 9a72290a..1ae8b930 100644 --- a/lib/stream_reader.cpp +++ b/lib/stream_reader.cpp @@ -73,7 +73,7 @@ StreamCommands::StreamCommands() { // Settings (*this)[Command::FixOrientations] = {"fix_orientations", false, "<0/off/1/on>", "Turn off/on fix of the orientations for inverted elements."}; - (*this)[Command::SaveColoring] = {"save_coloring", false, "<0/off/1/on>", "Turn off/on saving of the mesh coloring generated when opening only a mesh."}; + (*this)[Command::SaveColoring] = {"save_coloring", false, "<0/off/1/on>", "Turn on/off saving of the mesh coloring generated when loading only a mesh."}; (*this)[Command::KeepAttributes] = {"keep_attributes", false, "", "When loading a parallel solution, toggle between processor ranks and the original (real) attributes."}; // Solution (*this)[Command::Mesh] = {"mesh", false, "", "Visualize the mesh."}; From 458114b442b20bbe18513f7e2996f55ea601db4e Mon Sep 17 00:00:00 2001 From: Jan Nikl Date: Sat, 6 Jun 2026 18:13:34 -0700 Subject: [PATCH 7/8] Fix orientation suggestion. Co-authored-by: John Camier --- lib/stream_reader.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/stream_reader.cpp b/lib/stream_reader.cpp index 1ae8b930..3d38b5d5 100644 --- a/lib/stream_reader.cpp +++ b/lib/stream_reader.cpp @@ -72,7 +72,7 @@ static const StreamCommands commands; StreamCommands::StreamCommands() { // Settings - (*this)[Command::FixOrientations] = {"fix_orientations", false, "<0/off/1/on>", "Turn off/on fix of the orientations for inverted elements."}; + (*this)[Command::FixOrientations] = {"fix_orientations", false, "<0/off/1/on>", "Turn on/off automatic fixing of orientations for inverted elements."}; (*this)[Command::SaveColoring] = {"save_coloring", false, "<0/off/1/on>", "Turn on/off saving of the mesh coloring generated when loading only a mesh."}; (*this)[Command::KeepAttributes] = {"keep_attributes", false, "", "When loading a parallel solution, toggle between processor ranks and the original (real) attributes."}; // Solution From 3b91c055a8129830df7d551d09281bbbb10d2204 Mon Sep 17 00:00:00 2001 From: Jan Nikl Date: Sat, 6 Jun 2026 18:14:43 -0700 Subject: [PATCH 8/8] Changelog suggestion. Co-authored-by: John Camier --- CHANGELOG | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/CHANGELOG b/CHANGELOG index 76125c98..0525dd2a 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -17,12 +17,11 @@ Version 4.5.1 (development) script. The overlay appears as a red line connecting the given points. The points line format is: number of points, followed by x y z coordinates. -- Added stream options to set up the parameters for loading the data. There are - 'fix_orientations', 'save_coloring' and 'keep_attributes' commands for the - corresponding options. These commands (to have an effect) must send before the - 'solution' command. However, they can be send only after the parallel streams - have been initialized by 'parallel' command (if used). - +- Added stream options to configure parameters for loading data. The new + commands are 'fix_orientations', 'save_coloring', and 'keep_attributes'. + These commands must be sent before the 'solution' command to take effect. + They can only be issued after parallel streams have been initialized with + the 'parallel' command (if used). Version 4.5 released on Feb 6, 2026 ===================================