-
Notifications
You must be signed in to change notification settings - Fork 18
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Convert tool to convert wmtk mesh types #832
Merged
Merged
Changes from 11 commits
Commits
Show all changes
33 commits
Select commit
Hold shift + click to select a range
3062a30
moved named multimesh to from the input component to the multimesh co…
mtao d6f06f4
preparing output component to output named multimesh stuff
mtao 293c7b4
making input/output both support writing json for name data
mtao 5efcc0c
Updating input slightly
mtao 6625c75
Merge branch 'mtao/simpler_app_declaration' into mtao/multimesh_namin…
mtao 1e68032
fixing keys when htere are multiple meshes
mtao 39e3c81
adding convert app
mtao 6450327
adding basic convert app
mtao cce6bad
making convert output meshes potentially
mtao 8751e61
adding example usage of convert app
mtao 2a09c8d
updating convert to support output better
mtao c78b88f
being more explicit when fetching std::optional<fs::path> from json i…
mtao 8a22d17
Merge remote-tracking branch 'upstream/main' into mtao/multimesh_nami…
mtao 03ccb0e
adding a data dir for convert
mtao ea83f61
update on output component for windows std::optional<fs::path> to json
mtao 4be06a5
updating named mesh tooling for getting all meshes
mtao 184f4e6
Merge remote-tracking branch 'upstream/main' into mtao/multimesh_nami…
mtao 5fc0f19
updates
mtao 74d6ea3
Adding a path resolver class to encapsulate path stuff from json
mtao 5834c11
fixing path resolver usage
mtao a4f7c7b
cnovert seems to work
mtao 1fec8f2
naming works better now with convert app
mtao 5868840
updates
mtao 17e97a5
removing data dir printout
mtao cbee74a
updates
mtao c86b1dc
adding unit tests for convert app
mtao 5f5c15e
removing temporary test filesl
mtao 241468d
fixing camel split
mtao 4e0d6b1
Merge remote-tracking branch 'upstream/main' into mtao/multimesh_nami…
mtao f2be66e
updating path for diff versions of split_path
mtao 87c1efe
removing spurious print statements
mtao 19f4428
missing cpp20 check
mtao b63a823
giving up on string_view for now
mtao File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
include(wmtk_add_application) | ||
include(wmtk_register_jse_json) | ||
wmtk_add_application(convert_app | ||
main.cpp | ||
) | ||
|
||
target_compile_features(convert_app PUBLIC cxx_std_20) | ||
#register_jse_json(APPLICATION_NAME convert INPUT convert_spec.json ) | ||
|
||
# convert requires the output component and the convert component | ||
target_link_libraries(convert_app PRIVATE | ||
wmtk::input | ||
wmtk::output | ||
wmtk::multimesh | ||
wmtk::application_utils | ||
) | ||
|
||
wmtk_register_integration_test( | ||
EXEC_NAME convert_app | ||
CONFIG_FILE ${CMAKE_CURRENT_SOURCE_DIR}/test_config.json | ||
CONFIG_PATH ${CMAKE_CURRENT_SOURCE_DIR}/examples | ||
EXTRA_ARGUMENTS run | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
{ | ||
"input": [ | ||
{ | ||
"file": "_pos.msh", | ||
"name_spec": "position" | ||
} | ||
], | ||
"tree": { | ||
"position": { | ||
"type": "boundary", | ||
"dimension": 1 | ||
} | ||
|
||
}, | ||
|
||
"output": { | ||
"file": "ogre_boundary.hdf5", | ||
"type": ".hdf5" | ||
} | ||
|
||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
{ | ||
"input": [ | ||
{ | ||
"file": "_pos.msh", | ||
"name_spec": "position" | ||
}, | ||
{ | ||
"file": "_tex.msh", | ||
"name_spec": "uv" | ||
} | ||
], | ||
"tree": { | ||
"position": "uv" | ||
|
||
}, | ||
|
||
"output": { | ||
"file": "ogre.hdf5", | ||
"type": ".hdf5" | ||
} | ||
|
||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
{ | ||
"input": { | ||
"file": "ogre.hdf5", | ||
"name_spec": | ||
{ | ||
"position": "uv" | ||
} | ||
}, | ||
"output": { | ||
"position": { | ||
"file": "ogre_pos.vtu", | ||
"position_attribute": "vertices" | ||
}, | ||
"position.uv": { | ||
"file": "ogre_uv.vtu", | ||
"position_attribute": "vertices" | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,168 @@ | ||
|
||
#include <jse/jse.h> | ||
#include <CLI/App.hpp> | ||
#include <CLI/CLI.hpp> | ||
#include <filesystem> | ||
#include <nlohmann/json.hpp> | ||
#include <wmtk/applications/utils/element_count_report.hpp> | ||
|
||
#include <wmtk/Mesh.hpp> | ||
#include <wmtk/utils/Logger.hpp> | ||
|
||
#include <wmtk/components/input/InputOptions.hpp> | ||
#include <wmtk/components/input/input.hpp> | ||
|
||
#include <wmtk/components/output/OutputOptions.hpp> | ||
#include <wmtk/components/output/output.hpp> | ||
#include <wmtk/components/utils/resolve_path.hpp> | ||
|
||
#include "CLI/CLI.hpp" | ||
#include "wmtk/components/multimesh/MeshCollection.hpp" | ||
#include "wmtk/components/multimesh/from_boundary.hpp" | ||
#include "wmtk/components/multimesh/from_facet_bijection.hpp" | ||
|
||
using namespace wmtk::components; | ||
using namespace wmtk::applications; | ||
using namespace wmtk; | ||
namespace fs = std::filesystem; | ||
|
||
namespace { | ||
std::shared_ptr<wmtk::Mesh> merge_meshes( | ||
wmtk::components::multimesh::MeshCollection& mc, | ||
const nlohmann::json& js) | ||
{ | ||
for (const auto& [parent, child_datas] : js.items()) { | ||
auto& parent_mesh = mc.get_mesh(parent); | ||
if (child_datas.is_string()) { | ||
auto& child_mesh = mc.get_mesh(child_datas.get<std::string>()); | ||
components::multimesh::from_facet_bijection(parent_mesh, child_mesh); | ||
return parent_mesh.shared_from_this(); | ||
|
||
} else if (child_datas.is_object()) { | ||
const std::string type = child_datas["type"]; | ||
|
||
if (type == "facet_bijection") { | ||
const std::string child_name = child_datas["name"]; | ||
auto& child_mesh = mc.get_mesh(child_name); | ||
components::multimesh::from_facet_bijection(parent_mesh, child_mesh); | ||
return parent_mesh.shared_from_this(); | ||
|
||
} else if (type == "boundary") { | ||
const int64_t dimension = child_datas["dimension"]; | ||
std::string boundary_attr_name = fmt::format("boundary_{}", dimension); | ||
if (child_datas.contains("boundary_attribute_name")) { | ||
boundary_attr_name = child_datas["boundary_attribute_name"]; | ||
} | ||
components::multimesh::from_boundary( | ||
parent_mesh, | ||
wmtk::get_primitive_type_from_id(dimension), | ||
boundary_attr_name); | ||
return parent_mesh.shared_from_this(); | ||
} | ||
} | ||
} | ||
return nullptr; | ||
} | ||
} // namespace | ||
|
||
int run(const fs::path& config_path /*, const std::optional<fs::path>& name_spec_file*/) | ||
{ | ||
nlohmann::json j; | ||
{ | ||
std::ifstream ifs(config_path); | ||
j = nlohmann::json::parse(ifs); | ||
// if (name_spec_file.has_value()) { | ||
// j["name"] = nlohmann::json::parse(std::ifstream(name_spec_file.value())); | ||
// } | ||
} | ||
|
||
wmtk::components::multimesh::MeshCollection meshes; | ||
std::shared_ptr<wmtk::Mesh> output_mesh; | ||
if (j["input"].is_array()) { | ||
for (const auto& in_opts_js : j["input"]) { | ||
wmtk::components::input::InputOptions opts = in_opts_js; | ||
meshes.add_mesh(wmtk::components::input::input(opts)); | ||
} | ||
} else { | ||
wmtk::components::input::InputOptions opts = j["input"]; | ||
output_mesh = | ||
meshes.add_mesh(wmtk::components::input::input(opts)).root().shared_from_this(); | ||
} | ||
|
||
if (j.contains("tree")) { | ||
output_mesh = merge_meshes(meshes, j["tree"]); | ||
} | ||
|
||
if (!j.contains("output")) { | ||
wmtk::logger().info("convert: No output path provided"); | ||
} else if (j["output"].is_object()) { | ||
for (const auto& [mesh_path, out_opts_js] : j["output"].items()) { | ||
auto opts = out_opts_js.get<wmtk::components::output::OutputOptions>(); | ||
|
||
wmtk::components::output::output(meshes.get_mesh(mesh_path), opts); | ||
} | ||
} else { | ||
auto opts = j["output"].get<wmtk::components::output::OutputOptions>(); | ||
wmtk::components::output::output(*output_mesh, opts); | ||
} | ||
|
||
|
||
// if (j.contains("report")) { | ||
// const std::string report = j["report"]; | ||
// if (!report.empty()) { | ||
// nlohmann::json out_json; | ||
// out_json.update(wmtk::applications::utils::element_count_report_named(*mesh)); | ||
// j.erase("report"); | ||
// out_json["input"] = j; | ||
|
||
|
||
// std::ofstream ofs(report); | ||
// ofs << out_json; | ||
// } | ||
//} | ||
return 0; | ||
} | ||
|
||
|
||
int main(int argc, char* argv[]) | ||
{ | ||
CLI::App app{argv[0]}; | ||
|
||
app.ignore_case(); | ||
|
||
fs::path json_input_file; | ||
std::optional<fs::path> name_spec_file; | ||
|
||
CLI::App* run_cmd; // = app.add_subcommand("run", "Run application"); | ||
run_cmd = &app; | ||
run_cmd->add_option("-j, --json", json_input_file, "json specification file") | ||
->required(true) | ||
->check(CLI::ExistingFile); | ||
|
||
// run_cmd->add_option("-n, --name_spec", name_spec_file, "json specification file") | ||
// ->check(CLI::ExistingFile); | ||
|
||
CLI11_PARSE(app, argc, argv); | ||
|
||
// someday may add other suboptions | ||
assert(run_cmd->parsed()); | ||
|
||
// if (!json_input_file.has_value() && !fill_config_path.has_value()) { | ||
// wmtk::logger().error("An input json file with [-j] is required unless blank config " | ||
// "generation is being used with [--fill-config]"); | ||
// return 1; | ||
// } | ||
|
||
int exit_mode = -1; | ||
|
||
// run_cmd->callback([&]() { | ||
// spdlog::warn("YOW!"); | ||
// assert(json_input_file.has_value()); | ||
// exit_mode = run(json_input_file.value()); | ||
// }); | ||
exit_mode = run(json_input_file /*, name_spec_file*/); | ||
|
||
|
||
assert(exit_mode != -1); // "Some subcommand should have updated the exit mode" | ||
return exit_mode; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
{ | ||
"tests": [ | ||
], | ||
"input_tag": "input", | ||
"oracle_tag": "report", | ||
"input_directory_tag": "root" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
we need tests for this