Skip to content
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 33 commits into from
Nov 16, 2024
Merged
Show file tree
Hide file tree
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 Oct 27, 2024
d6f06f4
preparing output component to output named multimesh stuff
mtao Oct 27, 2024
293c7b4
making input/output both support writing json for name data
mtao Oct 29, 2024
5efcc0c
Updating input slightly
mtao Oct 29, 2024
6625c75
Merge branch 'mtao/simpler_app_declaration' into mtao/multimesh_namin…
mtao Oct 29, 2024
1e68032
fixing keys when htere are multiple meshes
mtao Oct 29, 2024
39e3c81
adding convert app
mtao Oct 29, 2024
6450327
adding basic convert app
mtao Oct 29, 2024
cce6bad
making convert output meshes potentially
mtao Oct 29, 2024
8751e61
adding example usage of convert app
mtao Oct 29, 2024
2a09c8d
updating convert to support output better
mtao Oct 30, 2024
c78b88f
being more explicit when fetching std::optional<fs::path> from json i…
mtao Nov 3, 2024
8a22d17
Merge remote-tracking branch 'upstream/main' into mtao/multimesh_nami…
mtao Nov 3, 2024
03ccb0e
adding a data dir for convert
mtao Nov 3, 2024
ea83f61
update on output component for windows std::optional<fs::path> to json
mtao Nov 3, 2024
4be06a5
updating named mesh tooling for getting all meshes
mtao Nov 5, 2024
184f4e6
Merge remote-tracking branch 'upstream/main' into mtao/multimesh_nami…
mtao Nov 5, 2024
5fc0f19
updates
mtao Nov 6, 2024
74d6ea3
Adding a path resolver class to encapsulate path stuff from json
mtao Nov 8, 2024
5834c11
fixing path resolver usage
mtao Nov 9, 2024
a4f7c7b
cnovert seems to work
mtao Nov 11, 2024
1fec8f2
naming works better now with convert app
mtao Nov 11, 2024
5868840
updates
mtao Nov 11, 2024
17e97a5
removing data dir printout
mtao Nov 12, 2024
cbee74a
updates
mtao Nov 12, 2024
c86b1dc
adding unit tests for convert app
mtao Nov 12, 2024
5f5c15e
removing temporary test filesl
mtao Nov 12, 2024
241468d
fixing camel split
mtao Nov 12, 2024
4e0d6b1
Merge remote-tracking branch 'upstream/main' into mtao/multimesh_nami…
mtao Nov 14, 2024
f2be66e
updating path for diff versions of split_path
mtao Nov 14, 2024
87c1efe
removing spurious print statements
mtao Nov 15, 2024
19f4428
missing cpp20 check
mtao Nov 15, 2024
b63a823
giving up on string_view for now
mtao Nov 15, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions applications/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ add_application(triwild ON)
add_application(cdt_sec ON)
add_application(shortest_edge_collapse ON)
add_application(insertion ON)
add_application(convert ON)



Expand Down
23 changes: 23 additions & 0 deletions applications/convert/CMakeLists.txt
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
)
22 changes: 22 additions & 0 deletions applications/convert/examples/make_boundary.json
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"
}


}
23 changes: 23 additions & 0 deletions applications/convert/examples/merge_uv.json
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"
}


}
19 changes: 19 additions & 0 deletions applications/convert/examples/split_uv.json
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"
}
}
}
168 changes: 168 additions & 0 deletions applications/convert/main.cpp
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(

Check warning on line 30 in applications/convert/main.cpp

View check run for this annotation

Codecov / codecov/patch

applications/convert/main.cpp#L30

Added line #L30 was not covered by tests
wmtk::components::multimesh::MeshCollection& mc,
const nlohmann::json& js)
{
for (const auto& [parent, child_datas] : js.items()) {
auto& parent_mesh = mc.get_mesh(parent);

Check warning on line 35 in applications/convert/main.cpp

View check run for this annotation

Codecov / codecov/patch

applications/convert/main.cpp#L35

Added line #L35 was not covered by tests
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();

Check warning on line 39 in applications/convert/main.cpp

View check run for this annotation

Codecov / codecov/patch

applications/convert/main.cpp#L37-L39

Added lines #L37 - L39 were not covered by tests

} else if (child_datas.is_object()) {
const std::string type = child_datas["type"];

Check warning on line 42 in applications/convert/main.cpp

View check run for this annotation

Codecov / codecov/patch

applications/convert/main.cpp#L42

Added line #L42 was not covered by tests

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();

Check warning on line 48 in applications/convert/main.cpp

View check run for this annotation

Codecov / codecov/patch

applications/convert/main.cpp#L45-L48

Added lines #L45 - L48 were not covered by tests

} else if (type == "boundary") {
const int64_t dimension = child_datas["dimension"];
std::string boundary_attr_name = fmt::format("boundary_{}", dimension);

Check warning on line 52 in applications/convert/main.cpp

View check run for this annotation

Codecov / codecov/patch

applications/convert/main.cpp#L51-L52

Added lines #L51 - L52 were not covered by tests
if (child_datas.contains("boundary_attribute_name")) {
boundary_attr_name = child_datas["boundary_attribute_name"];

Check warning on line 54 in applications/convert/main.cpp

View check run for this annotation

Codecov / codecov/patch

applications/convert/main.cpp#L54

Added line #L54 was not covered by tests
}
components::multimesh::from_boundary(

Check warning on line 56 in applications/convert/main.cpp

View check run for this annotation

Codecov / codecov/patch

applications/convert/main.cpp#L56

Added line #L56 was not covered by tests
parent_mesh,
wmtk::get_primitive_type_from_id(dimension),
boundary_attr_name);
return parent_mesh.shared_from_this();

Check warning on line 60 in applications/convert/main.cpp

View check run for this annotation

Codecov / codecov/patch

applications/convert/main.cpp#L60

Added line #L60 was not covered by tests
}
}
}
return nullptr;

Check warning on line 64 in applications/convert/main.cpp

View check run for this annotation

Codecov / codecov/patch

applications/convert/main.cpp#L64

Added line #L64 was not covered by tests
}
} // namespace

int run(const fs::path& config_path /*, const std::optional<fs::path>& name_spec_file*/)

Check warning on line 68 in applications/convert/main.cpp

View check run for this annotation

Codecov / codecov/patch

applications/convert/main.cpp#L68

Added line #L68 was not covered by tests
{
nlohmann::json j;
{
std::ifstream ifs(config_path);
j = nlohmann::json::parse(ifs);

Check warning on line 73 in applications/convert/main.cpp

View check run for this annotation

Codecov / codecov/patch

applications/convert/main.cpp#L70-L73

Added lines #L70 - L73 were not covered by tests
// 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;

Check warning on line 80 in applications/convert/main.cpp

View check run for this annotation

Codecov / codecov/patch

applications/convert/main.cpp#L79-L80

Added lines #L79 - L80 were not covered by tests
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));

Check warning on line 84 in applications/convert/main.cpp

View check run for this annotation

Codecov / codecov/patch

applications/convert/main.cpp#L83-L84

Added lines #L83 - L84 were not covered by tests
}
} else {
wmtk::components::input::InputOptions opts = j["input"];
output_mesh =
meshes.add_mesh(wmtk::components::input::input(opts)).root().shared_from_this();

Check warning on line 89 in applications/convert/main.cpp

View check run for this annotation

Codecov / codecov/patch

applications/convert/main.cpp#L87-L89

Added lines #L87 - L89 were not covered by tests
}

if (j.contains("tree")) {
output_mesh = merge_meshes(meshes, j["tree"]);

Check warning on line 93 in applications/convert/main.cpp

View check run for this annotation

Codecov / codecov/patch

applications/convert/main.cpp#L93

Added line #L93 was not covered by tests
}

if (!j.contains("output")) {
wmtk::logger().info("convert: No output path provided");

Check warning on line 97 in applications/convert/main.cpp

View check run for this annotation

Codecov / codecov/patch

applications/convert/main.cpp#L97

Added line #L97 was not covered by tests
} 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>();

Check warning on line 100 in applications/convert/main.cpp

View check run for this annotation

Codecov / codecov/patch

applications/convert/main.cpp#L100

Added line #L100 was not covered by tests

wmtk::components::output::output(meshes.get_mesh(mesh_path), opts);

Check warning on line 102 in applications/convert/main.cpp

View check run for this annotation

Codecov / codecov/patch

applications/convert/main.cpp#L102

Added line #L102 was not covered by tests
}
} else {
auto opts = j["output"].get<wmtk::components::output::OutputOptions>();
wmtk::components::output::output(*output_mesh, opts);

Check warning on line 106 in applications/convert/main.cpp

View check run for this annotation

Codecov / codecov/patch

applications/convert/main.cpp#L105-L106

Added lines #L105 - L106 were not covered by tests
}


// 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;

Check warning on line 123 in applications/convert/main.cpp

View check run for this annotation

Codecov / codecov/patch

applications/convert/main.cpp#L123

Added line #L123 was not covered by tests
}


int main(int argc, char* argv[])

Check warning on line 127 in applications/convert/main.cpp

View check run for this annotation

Codecov / codecov/patch

applications/convert/main.cpp#L127

Added line #L127 was not covered by tests
{
CLI::App app{argv[0]};

Check warning on line 129 in applications/convert/main.cpp

View check run for this annotation

Codecov / codecov/patch

applications/convert/main.cpp#L129

Added line #L129 was not covered by tests

app.ignore_case();

Check warning on line 131 in applications/convert/main.cpp

View check run for this annotation

Codecov / codecov/patch

applications/convert/main.cpp#L131

Added line #L131 was not covered by tests

fs::path json_input_file;
std::optional<fs::path> name_spec_file;

Check warning on line 134 in applications/convert/main.cpp

View check run for this annotation

Codecov / codecov/patch

applications/convert/main.cpp#L133-L134

Added lines #L133 - L134 were not covered by tests

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")

Check warning on line 138 in applications/convert/main.cpp

View check run for this annotation

Codecov / codecov/patch

applications/convert/main.cpp#L136-L138

Added lines #L136 - L138 were not covered by tests
->required(true)
->check(CLI::ExistingFile);

Check warning on line 140 in applications/convert/main.cpp

View check run for this annotation

Codecov / codecov/patch

applications/convert/main.cpp#L140

Added line #L140 was not covered by tests

// run_cmd->add_option("-n, --name_spec", name_spec_file, "json specification file")
// ->check(CLI::ExistingFile);

CLI11_PARSE(app, argc, argv);

Check warning on line 145 in applications/convert/main.cpp

View check run for this annotation

Codecov / codecov/patch

applications/convert/main.cpp#L145

Added line #L145 was not covered by tests

// someday may add other suboptions
assert(run_cmd->parsed());

Check warning on line 148 in applications/convert/main.cpp

View check run for this annotation

Codecov / codecov/patch

applications/convert/main.cpp#L148

Added line #L148 was not covered by tests

// 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;

Check warning on line 156 in applications/convert/main.cpp

View check run for this annotation

Codecov / codecov/patch

applications/convert/main.cpp#L156

Added line #L156 was not covered by tests

// 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*/);

Check warning on line 163 in applications/convert/main.cpp

View check run for this annotation

Codecov / codecov/patch

applications/convert/main.cpp#L163

Added line #L163 was not covered by tests


assert(exit_mode != -1); // "Some subcommand should have updated the exit mode"
return exit_mode;
}
7 changes: 7 additions & 0 deletions applications/convert/test_config.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"tests": [
Copy link
Collaborator

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

],
"input_tag": "input",
"oracle_tag": "report",
"input_directory_tag": "root"
}
10 changes: 2 additions & 8 deletions components/input/src/wmtk/components/input/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,6 @@ set(SRC_FILES
mesh_with_tag_from_image.hpp
input.cpp
input.hpp
NamedMultiMesh.hpp
NamedMultiMesh.cpp
utils/get_attribute.hpp
utils/get_attribute.cpp

MeshCollection.hpp
MeshCollection.cpp
)

include(stb)
Expand All @@ -25,5 +18,6 @@ include(stb)
target_compile_features(wmtk_${COMPONENT_NAME} PUBLIC cxx_std_20)

target_sources(wmtk_${COMPONENT_NAME} PRIVATE ${SRC_FILES})
target_link_libraries(wmtk_${COMPONENT_NAME} PRIVATE stb::image)
target_link_libraries(wmtk_${COMPONENT_NAME} PRIVATE stb::image nlohmann_json)
target_link_libraries(wmtk_${COMPONENT_NAME} PRIVATE stb::image nlohmann_json PUBLIC wmtk::multimesh)

18 changes: 15 additions & 3 deletions components/input/src/wmtk/components/input/InputOptions.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#include "InputOptions.hpp"
#include <wmtk/utils/Logger.hpp>
#include <wmtk/components/utils/json_utils.hpp>


namespace wmtk::components::input {
Expand All @@ -11,13 +12,19 @@
void adl_serializer<wmtk::components::input::InputOptions>::to_json(json& j, const Type& v)
{
//
j["file"] = v.file;
j["file"] = v.file.string();
if (!v.name_spec.is_null()) {
assert(!v.name_spec_file.has_value());

Check warning on line 18 in components/input/src/wmtk/components/input/InputOptions.cpp

View check run for this annotation

Codecov / codecov/patch

components/input/src/wmtk/components/input/InputOptions.cpp#L18

Added line #L18 was not covered by tests
j["name_spec"] = v.name_spec;
} else if(v.name_spec_file.has_value()) {
j["name_spec_file"] = v.name_spec_file.value();

Check warning on line 21 in components/input/src/wmtk/components/input/InputOptions.cpp

View check run for this annotation

Codecov / codecov/patch

components/input/src/wmtk/components/input/InputOptions.cpp#L21

Added line #L21 was not covered by tests

}
if (v.old_mode) {
j["old_mode"] = true;
j["ignore_z"] = v.ignore_z_if_zero;
j["ignore_z"] = v.ignore_z_if_zero; // keep around for deprecation purposes
//j["ignore_z_if_zero"] = v.ignore_z_if_zero;
if (v.imported_attributes.has_value()) {
const auto& imported_attrs = v.imported_attributes.value();
if (imported_attrs.size() > 3) {
Expand All @@ -33,13 +40,16 @@
void adl_serializer<wmtk::components::input::InputOptions>::from_json(const json& j, Type& v)
{
if (j.is_string()) {
v.file = j.get<std::string>();
v.file = j.get<std::filesystem::path>();
return;
}
v.file = j["file"].get<std::string>();
v.file = j["file"].get<std::filesystem::path>();
if (j.contains("name_spec")) {
v.name_spec = j["name_spec"];
}
if (j.contains("name_spec_file")) {
v.name_spec_file = j["name_spec_file"];

Check warning on line 51 in components/input/src/wmtk/components/input/InputOptions.cpp

View check run for this annotation

Codecov / codecov/patch

components/input/src/wmtk/components/input/InputOptions.cpp#L51

Added line #L51 was not covered by tests
}

v.old_mode = false;
if (j.contains("old_mode")) {
Expand All @@ -58,6 +68,8 @@

if (v.old_mode) {
v.ignore_z_if_zero = j.contains("ignore_z") ? bool(j["ignore_z"]) : false;
// overwrite old ignore_z
//v.ignore_z_if_zero = j.contains("ignore_z_if_zero") ? bool(j["ignore_z_if_zero"]) : false;
if (j.contains("tetrahedron_attributes")) {
v.imported_attributes = {
{},
Expand Down
2 changes: 2 additions & 0 deletions components/input/src/wmtk/components/input/InputOptions.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,9 @@
std::optional<std::vector<std::vector<std::string>>> imported_attributes;


// either you can have a name spec in json or you can have it in a file
nlohmann::json name_spec;
std::optional<std::filesystem::path> name_spec_file;

Check warning on line 20 in components/input/src/wmtk/components/input/InputOptions.hpp

View check run for this annotation

Codecov / codecov/patch

components/input/src/wmtk/components/input/InputOptions.hpp#L20

Added line #L20 was not covered by tests

bool old_mode = false;
bool ignore_z_if_zero = false;
Expand Down
14 changes: 11 additions & 3 deletions components/input/src/wmtk/components/input/input.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#include "input.hpp"

#include <fstream>
#include <wmtk/io/read_mesh.hpp>
#include <wmtk/utils/Logger.hpp>
#include <wmtk/utils/mesh_utils.hpp>
Expand All @@ -22,7 +23,7 @@
return input(options).root().shared_from_this();
}

NamedMultiMesh input(const InputOptions& options)
multimesh::NamedMultiMesh input(const InputOptions& options)
{
if (!std::filesystem::exists(options.file)) {
log_and_throw_error("file [{}] not found", options.file.string());
Expand All @@ -49,9 +50,16 @@
assert(mesh->is_connectivity_valid());


NamedMultiMesh mm;
multimesh::NamedMultiMesh mm;
mm.set_mesh(*mesh);
mm.set_names(options.name_spec);
if (!options.name_spec.is_null()) {
mm.set_names(options.name_spec);

Check warning on line 56 in components/input/src/wmtk/components/input/input.cpp

View check run for this annotation

Codecov / codecov/patch

components/input/src/wmtk/components/input/input.cpp#L56

Added line #L56 was not covered by tests
} else if (options.name_spec_file.has_value()) {
std::ifstream ifs(options.name_spec_file.value());
nlohmann::json js;
ifs >> js;
mm.set_names(js);
}

Check warning on line 62 in components/input/src/wmtk/components/input/input.cpp

View check run for this annotation

Codecov / codecov/patch

components/input/src/wmtk/components/input/input.cpp#L58-L62

Added lines #L58 - L62 were not covered by tests

return mm;
}
Expand Down
Loading
Loading