Wildmeshing Toolkit
Loading...
Searching...
No Matches
run_components.cpp
Go to the documentation of this file.
1#include "run_components.hpp"
2
3#include <jse/jse.h>
6
7
8#include <wmtk/components/utils/Paths.hpp>
10
11#include <fstream>
12
13//inside ${CMAKE_CURRENT_BINARY_DIR}/autogen
14#include <components_include.hpp>
15
16namespace wmtk::components {
17
18
19wmtk::io::Cache run_components(const nlohmann::json& json_input_file, bool strict)
20{
21 const std::filesystem::path wmtk_spec_file = WMTK_APP_INPUT_SPEC;
22 nlohmann::json rules_json;
23 {
24 std::ifstream f(wmtk_spec_file);
25 if (!f.is_open()) {
27 "Could not open wmtk specification file: {}",
28 wmtk_spec_file.string());
29 }
30 rules_json = nlohmann::json::parse(f);
31 }
32
33 jse::JSE spec_engine;
34 spec_engine.strict = strict;
35
36//inside ${CMAKE_CURRENT_BINARY_DIR}/autogen
37#include <spec_include.hpp>
38 rules_json = spec_engine.inject_include(rules_json);
39
40 // std::cout << rules_json.dump(2) << std::endl;
41 nlohmann::json spec_json;
42 bool r = spec_engine.verify_json(json_input_file, rules_json);
43 if (!r) {
44 log_and_throw_error("{}", spec_engine.log2str());
45 } else {
46 spec_json = spec_engine.inject_defaults(json_input_file, rules_json);
47 }
48
49 // {
50 // std::ofstream o("debug_output.json");
51 // o << std::setw(4) << spec_json << std::endl;
52 // o.close();
53 // }
54
55
57 wmtk::logger().set_level(spec_json["settings"]["log_level"]);
58 wmtk::opt_logger().set_level(spec_json["settings"]["opt_log_level"]);
59 }
60
61 const std::string root_path = spec_json["root_path"];
62
63 const std::string output_dir =
64 wmtk::utils::resolve_path(spec_json["output"]["directory"], root_path, false);
65 if (!output_dir.empty()) {
66 std::filesystem::create_directories(output_dir);
67 }
68
69 std::map<
70 std::string,
71 std::function<void(const utils::Paths&, const nlohmann::json&, wmtk::io::Cache&)>>
72 components;
73
74// register components
75// inside ${CMAKE_CURRENT_BINARY_DIR}/autogen
76#include <components_map.hpp>
77
78 utils::Paths paths;
79 paths.root_path = root_path;
80 paths.output_dir = output_dir;
81
82 logger().info("Root path: {}, output dir: {}", root_path, output_dir);
83
84
85 wmtk::io::Cache cache(spec_json["output"]["cache"], output_dir);
86
87 // iterate through components array
88 for (const nlohmann::json& component_json : spec_json["components"]) {
89 for (auto& el : component_json.items()) {
90 wmtk::logger().info("Component {}", el.key());
91 wmtk::utils::StopWatch sw(el.key());
92 components[el.key()](paths, el.value(), cache);
93 cache.flush_multimeshes();
94 }
95 }
96
97 return cache;
98}
99} // namespace wmtk::components
void flush_multimeshes()
Unsets the mesh held by each cached mm - useful for debugging whether cache loading works.
Definition Cache.cpp:177
wmtk::io::Cache run_components(const nlohmann::json &json_input_file, bool strict)
bool has_user_overloaded_logger_level()
Definition Logger.cpp:9
void log_and_throw_error(const std::string &msg)
Definition Logger.cpp:101
spdlog::logger & logger()
Retrieves the current logger.
Definition Logger.cpp:58
spdlog::logger & opt_logger()
Retrieves the logger for the optimization.
Definition Logger.cpp:75