--- /dev/null
+New: The new setting OutputStyle::KeepOnlyChanged allows
+to print only changed parameters with
+ParameterHandler::print_parameters().
+<br>
+(Peter Munch, 2024/08/22)
* values as a LaTeX file.
*/
ShortLaTeX = LaTeX | Short,
+
+ /**
+ * Write out only parameters with changed values.
+ */
+ KeepOnlyChanged = 0x0200,
};
}
}
}
+
+ void
+ recursively_keep_non_default(const boost::property_tree::ptree &tree_in,
+ boost::property_tree::ptree &tree_out)
+ {
+ for (const auto &p : tree_in)
+ {
+ if (is_parameter_node(p.second))
+ {
+ const std::string value = p.second.get<std::string>("value");
+
+ if (value != p.second.get<std::string>("default_value"))
+ tree_out.put_child(p.first, p.second);
+ }
+ else if (is_alias_node(p.second))
+ {
+ // nothing to do
+ }
+ else
+ {
+ boost::property_tree::ptree temp;
+
+ if (const auto val = p.second.get_value_optional<std::string>())
+ temp.put_value<std::string>(*val);
+
+ recursively_keep_non_default(p.second, temp);
+
+ if (temp.size() > 0)
+ tree_out.put_child(p.first, temp);
+ }
+ }
+ }
} // namespace
current_entries);
}
+ if ((style & KeepOnlyChanged) != 0)
+ {
+ boost::property_tree::ptree current_entries_without_default;
+ recursively_keep_non_default(current_entries,
+ current_entries_without_default);
+ current_entries = current_entries_without_default;
+ }
+
// we'll have to print some text that is padded with spaces;
// set the appropriate fill character, but also make sure that
// we will restore the previous setting (and all other stream
--- /dev/null
+// ------------------------------------------------------------------------
+//
+// SPDX-License-Identifier: LGPL-2.1-or-later
+// Copyright (C) 2020 - 2024 by the deal.II authors
+//
+// This file is part of the deal.II library.
+//
+// Part of the source code is dual licensed under Apache-2.0 WITH
+// LLVM-exception OR LGPL-2.1-or-later. Detailed license information
+// governing the source code and code contributions can be found in
+// LICENSE.md and CONTRIBUTING.md at the top level directory of deal.II.
+//
+// ------------------------------------------------------------------------
+
+
+
+// Like parameter_handler_read_json_05 but output with
+// ParameterHandler::OutputStyle::KeepOnlyChanged. This is achieved
+// by adding two parameters with default values, altering one of
+// the value of the parameters and printing the parameters
+// using the ParameterHandler::OutputStyle::KeepOnlyChanged.
+
+#include <deal.II/base/parameter_handler.h>
+
+#include "../tests.h"
+
+
+int
+main()
+{
+ initlog();
+
+ ParameterHandler prm;
+
+ double test_0 = 0;
+ double test_1 = 1;
+
+ // test if underscore can be parsed
+ prm.add_parameter("test 0", test_0);
+ prm.add_parameter("test 1", test_1);
+
+ std::string source = SOURCE_DIR;
+ std::string filename = source + "/prm/parameter_handler_read_json_04.json";
+
+ std::ifstream file;
+ file.open(filename);
+ prm.parse_input_from_json(file, true);
+
+ prm.print_parameters(deallog.get_file_stream(),
+ ParameterHandler::OutputStyle::ShortJSON |
+ ParameterHandler::OutputStyle::KeepOnlyChanged);
+
+ return 0;
+}
--- /dev/null
+
+{
+ "test 0": "1"
+}