Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
2 changes: 1 addition & 1 deletion applications/utils/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ add_library(wmtk_application_utils)
add_subdirectory(src/wmtk/applications/utils)


target_link_libraries(wmtk_application_utils wildmeshing_toolkit nlohmann_json)
target_link_libraries(wmtk_application_utils wildmeshing_toolkit nlohmann_json wmtk::multimesh wmtk::output)

target_include_directories(wmtk_application_utils INTERFACE "${CMAKE_CURRENT_SOURCE_DIR}/src")

Expand Down
4 changes: 4 additions & 0 deletions applications/utils/src/wmtk/applications/utils/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,8 @@ target_sources(wmtk_application_utils PRIVATE
parse_jse.hpp
parse_jse.cpp

get_integration_test_data_root.hpp
get_integration_test_data_root.cpp


)
Original file line number Diff line number Diff line change
@@ -1,31 +1,40 @@
#include "element_count_report.hpp"
#include <wmtk/Mesh.hpp>
#include <wmtk/components/multimesh/MeshCollection.hpp>
#include <wmtk/utils/primitive_range.hpp>


namespace wmtk::applications::utils {

std::vector<int64_t> element_count_report(const Mesh& m) {
std::vector<int64_t> ret;
for(PrimitiveType pt:wmtk::utils::primitive_below(m.top_simplex_type(), /*lower_to_upper=*/true) ){

ret.emplace_back(m.get_all(pt).size());

}
return ret;
std::vector<int64_t> element_count_report(const Mesh& m)
{
std::vector<int64_t> ret;
for (PrimitiveType pt :
wmtk::utils::primitive_below(m.top_simplex_type(), /*lower_to_upper=*/true)) {
ret.emplace_back(m.get_all(pt).size());
}
nlohmann::json element_count_report_named(const Mesh& m) {
const static std::array<std::string_view,4> names{"vertices","edges","faces","cells"};

const auto sizes = element_count_report(m);
return ret;
}

Check warning on line 17 in applications/utils/src/wmtk/applications/utils/element_count_report.cpp

View check run for this annotation

Codecov / codecov/patch

applications/utils/src/wmtk/applications/utils/element_count_report.cpp#L17

Added line #L17 was not covered by tests
nlohmann::json element_count_report_named(const Mesh& m)
{
const static std::array<std::string_view, 4> names{"vertices", "edges", "faces", "cells"};

assert(sizes.size() <= names.size());
nlohmann::json js;
for(size_t i = 0; i < sizes.size(); ++i) {
js[names[i]] = sizes[i];
const auto sizes = element_count_report(m);

}
return js;
assert(sizes.size() <= names.size());
nlohmann::json js;
for (size_t i = 0; i < sizes.size(); ++i) {
js[names[i]] = sizes[i];
}
return js;
}

nlohmann::json element_count_report_named(const components::multimesh::MeshCollection& meshes)

Check warning on line 32 in applications/utils/src/wmtk/applications/utils/element_count_report.cpp

View check run for this annotation

Codecov / codecov/patch

applications/utils/src/wmtk/applications/utils/element_count_report.cpp#L32

Added line #L32 was not covered by tests
{
nlohmann::json out;

Check warning on line 34 in applications/utils/src/wmtk/applications/utils/element_count_report.cpp

View check run for this annotation

Codecov / codecov/patch

applications/utils/src/wmtk/applications/utils/element_count_report.cpp#L34

Added line #L34 was not covered by tests
for (const auto& [name, mesh] : meshes.all_meshes()) {
out[name] = wmtk::applications::utils::element_count_report_named(mesh);
}
return out;

Check warning on line 38 in applications/utils/src/wmtk/applications/utils/element_count_report.cpp

View check run for this annotation

Codecov / codecov/patch

applications/utils/src/wmtk/applications/utils/element_count_report.cpp#L36-L38

Added lines #L36 - L38 were not covered by tests
}
} // namespace wmtk::applications::utils
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,24 @@

namespace wmtk {
class Mesh;
namespace components::multimesh {
class MeshCollection;
}
}

namespace wmtk::applications::utils {

std::vector<int64_t> element_count_report(const Mesh& m);

// Generates size statistics for each mesh in a mesh collection. Useful for "reports" used in integratino tests
// Something like:
// {"pos": {"vertices": 3, "edges": 24}, "pos.uv": {"vertices": 0, "edges": 23}}
nlohmann::json element_count_report_named(const components::multimesh::MeshCollection& m);

// produces a json file corresponding colloquial simplex type names to the counts
// Soemthing like: {"vertices": 3, "edges": 24}
nlohmann::json element_count_report_named(const Mesh& m);


// produces the number of simplices of each type in a mesh - useful for generating json reports on the elements in a mesh
std::vector<int64_t> element_count_report(const Mesh& m);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
#include <filesystem>
#include <fstream>
#include <nlohmann/json.hpp>

namespace wmtk::applications::utils {
std::filesystem::path get_integration_test_data_root(const std::filesystem::path& js_path, const std::filesystem::path& app_path) {
std::ifstream ifs(js_path);
nlohmann::json js;
ifs >> js;
return js[app_path.filename()]["data_folder"];

Check warning on line 10 in applications/utils/src/wmtk/applications/utils/get_integration_test_data_root.cpp

View check run for this annotation

Codecov / codecov/patch

applications/utils/src/wmtk/applications/utils/get_integration_test_data_root.cpp#L6-L10

Added lines #L6 - L10 were not covered by tests


}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
#pragma once
#include <filesystem>

namespace wmtk::applications::utils {
// allows for some applications to retrieve the data folder used for their integration tests using the json manifest that exists in each build folder (typically as "test_config.json"). Requires knowing which app they are (i.e isotropic_remeshing_app) as app_path
std::filesystem::path get_integration_test_data_root(const std::filesystem::path& js_path, const std::filesystem::path& app_path) ;
}
4 changes: 3 additions & 1 deletion components/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,9 @@ include(add_component_test)
# wmtk::component_utils
add_subdirectory(utils)

if(WILDMESHING_TOOLKIT_TOPLEVEL_PROJECT)
option(WMTK_ENABLE_COMPONENT_TESTS "Enable unit tests for components" ${WILDMESHING_TOOLKIT_TOPLEVEL_PROJECT})

if(WMTK_ENABLE_COMPONENT_TESTS)
add_subdirectory(tests)
endif()

Expand Down
2 changes: 1 addition & 1 deletion components/cmake/add_component_test.cmake
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
function(add_component_test COMPONENT_TARGET_NAME ...)

if(NOT WILDMESHING_TOOLKIT_TOPLEVEL_PROJECT)
if(NOT WMTK_ENABLE_COMPONENT_TESTS)
return()
endif()
list(REMOVE_AT ARGV 0)
Expand Down
2 changes: 2 additions & 0 deletions components/input/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
set(COMPONENT_NAME input)
add_subdirectory("src/wmtk/components/input")
if(WMTK_ENABLE_COMPONENT_TESTS)
add_subdirectory("tests")
endif()
22 changes: 14 additions & 8 deletions components/input/src/wmtk/components/input/InputOptions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,16 +16,15 @@
void adl_serializer<wmtk::components::input::InputOptions>::to_json(json& j, const Type& v)
{
//
j["file"] = v.file;
j["file"] = v.file.string();
j["path"] = v.path.string();
j["validate"] = v.validate;
if (!v.name_spec.is_null()) {
assert(!v.name_spec_file.has_value());
j["name_spec"] = v.name_spec;
} else if (v.name_spec_file.has_value()) {
j["name_spec_file"] = v.name_spec_file.value();
}


if (v.old_mode) {
j["old_mode"] = true;
j["ignore_z"] = v.ignore_z_if_zero; // keep around for deprecation purposes
Expand All @@ -45,10 +44,18 @@
void adl_serializer<wmtk::components::input::InputOptions>::from_json(const json& j, Type& v)
{
if (j.is_string()) {
v.file = j.get<std::filesystem::path>();
v.path= j.get<std::filesystem::path>();
return;
} else if(j.contains("path")) {
v.path = j["path"].get<std::filesystem::path>();
} else if(j.contains("file")) {
wmtk::logger().warn("InputOptions using file is deprecated, use file");
v.path = j["file"].get<std::filesystem::path>();
}
if (j.contains("validate")) {
v.validate = j["validate"];
}
v.file = j["file"].get<std::filesystem::path>();

if (j.contains("name_spec")) {
v.name_spec = j["name_spec"];
}
Expand Down Expand Up @@ -85,9 +92,8 @@
j["tetrahedron_attributes"].get<std::vector<std::string>>()};
}
} else {
if (v.imported_attributes.has_value()) {
v.imported_attributes =
j["imported_attributes"].get<std::vector<std::vector<std::string>>>();
if (j.contains("imported_attributes")) {
v.imported_attributes = j["imported_attributes"].get<std::vector<std::vector<std::string>>>();

Check warning on line 96 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#L96

Added line #L96 was not covered by tests
}
}
}
Expand Down
8 changes: 7 additions & 1 deletion components/input/src/wmtk/components/input/InputOptions.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,20 @@
public:
InputOptions();
~InputOptions();
std::filesystem::path file;
std::filesystem::path path;

Check warning on line 21 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#L21

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

bool validate = false;

Check warning on line 30 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#L30

Added line #L30 was not covered by tests



// many applications use ignore_z_if_zero and imported attribute sonly works for tets. This flag enables that
bool old_mode = false;
bool ignore_z_if_zero = false;

Expand Down
16 changes: 13 additions & 3 deletions components/input/src/wmtk/components/input/input.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
#include <wmtk/utils/Logger.hpp>
#include <wmtk/utils/mesh_utils.hpp>
#include "InputOptions.hpp"
#include <wmtk/utils/verify_simplex_index_valences.hpp>

namespace wmtk::components::input {

Expand All @@ -16,7 +17,7 @@
{
InputOptions options;
options.old_mode = true;
options.file = file;
options.path = file;
options.ignore_z_if_zero = ignore_z_if_zero;
if (!tetrahedron_attributes.empty()) {
options.imported_attributes = {{}, {}, {}, tetrahedron_attributes};
Expand All @@ -33,7 +34,7 @@
const InputOptions& options,
const components::utils::PathResolver& resolver)
{
const auto [file_path, found] = resolver.resolve(options.file);
const auto [file_path, found] = resolver.resolve(options.path);
if (!found) {
const auto& paths = resolver.get_paths();
std::vector<std::string> path_strs;
Expand All @@ -46,10 +47,11 @@
log_and_throw_error(
"file [{}] not found (input path was [{}], paths searched were [{}]",
file_path.string(),
options.file.string(),
options.path.string(),
fmt::join(path_strs, ","));
}


std::shared_ptr<Mesh> mesh;

if (options.old_mode) {
Expand Down Expand Up @@ -81,6 +83,14 @@
ifs >> js;
mm.set_names(js);
}
if(options.validate) {
for(const auto& mptr: mm.root().get_all_meshes()) {
if(!wmtk::utils::verify_simplex_index_valences(*mptr)) {
throw std::runtime_error(fmt::format("Mesh {} was not valid, check env WMTK_LOGGER_LEVEL=debug for more info", mm.get_name(*mptr)));

Check warning on line 89 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#L89

Added line #L89 was not covered by tests
}
}

Check warning on line 91 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#L91

Added line #L91 was not covered by tests

}

return mm;
}
Expand Down
9 changes: 5 additions & 4 deletions components/input/tests/input.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,13 @@ TEST_CASE("component_input", "[components][input]")
auto a = wmtk::components::input::input(input_file, false, {});

json component_json = {
{"file", input_file.string()},
{"path", input_file.string()},
{"old_mode", true},
{"ignore_z", false},
{"validate", false},
{"tetrahedron_attributes", json::array()}};
auto opts = component_json.get<wmtk::components::input::InputOptions>();
CHECK(opts.file == input_file);
CHECK(opts.path == input_file);
CHECK(opts.ignore_z_if_zero == false);
CHECK(opts.old_mode == true);
CHECK(opts.old_mode == true);
Expand All @@ -50,15 +51,15 @@ TEST_CASE("component_input", "[components][input]")
nlohmann::json js = "path";
REQUIRE(js.is_string());
auto opts = js.get<wmtk::components::input::InputOptions>();
CHECK(opts.file.string() == "path");
CHECK(opts.path.string() == "path");
}

SECTION("should throw")
{
// json component_json = {
// {"type", "input"},
// {"name", "input_mesh"},
// {"file", "In case you ever name your file like that: What is wrong with
// {"path", "In case you ever name your file like that: What is wrong with
// you?"},
// {"ignore_z", false},
// {"tetrahedron_attributes", json::array()}};
Expand Down
2 changes: 2 additions & 0 deletions components/multimesh/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
set(COMPONENT_NAME multimesh)
add_subdirectory("src/wmtk/components/${COMPONENT_NAME}")
if(WMTK_ENABLE_COMPONENT_TESTS)
add_subdirectory("tests")
endif()
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@ set(SRC_FILES
from_facet_bijection.hpp
from_facet_bijection.cpp

vertex_fusion.hpp
vertex_fusion.cpp


from_boundary.hpp
from_boundary.cpp
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@
#endif
const auto nmm_name = *split.begin();
if (nmm_name.empty() && m_meshes.size() == 1) {
wmtk::logger().debug("MeshCollection accessed with an empty name, but has only 1 mesh so "
wmtk::logger().trace("MeshCollection accessed with an empty name, but has only 1 mesh so "
"assuming that is the right mesh");
return *m_meshes.begin()->second;
}
Expand Down Expand Up @@ -91,7 +91,7 @@
#endif
const auto nmm_name = *split.begin();
if (nmm_name.empty() && m_meshes.size() == 1) {
wmtk::logger().debug("MeshCollection accessed with an empty name, but has only 1 mesh so "
wmtk::logger().trace("MeshCollection accessed with an empty name, but has only 1 mesh so "

Check warning on line 94 in components/multimesh/src/wmtk/components/multimesh/MeshCollection.cpp

View check run for this annotation

Codecov / codecov/patch

components/multimesh/src/wmtk/components/multimesh/MeshCollection.cpp#L94

Added line #L94 was not covered by tests
"assuming that is the right mesh");
return *m_meshes.begin()->second;
}
Expand Down Expand Up @@ -124,4 +124,20 @@
}
}
}
bool MeshCollection::is_valid(bool pass_exceptions) const

Check warning on line 127 in components/multimesh/src/wmtk/components/multimesh/MeshCollection.cpp

View check run for this annotation

Codecov / codecov/patch

components/multimesh/src/wmtk/components/multimesh/MeshCollection.cpp#L127

Added line #L127 was not covered by tests
{
for (const auto& [name, nmmptr] : m_meshes) {
if (!nmmptr->is_valid(pass_exceptions)) {
return false;

Check warning on line 131 in components/multimesh/src/wmtk/components/multimesh/MeshCollection.cpp

View check run for this annotation

Codecov / codecov/patch

components/multimesh/src/wmtk/components/multimesh/MeshCollection.cpp#L131

Added line #L131 was not covered by tests
}
}
return true;
}

//std::vector<const NamedMultiMesh*> get_named_multimeshes(const Mesh& m) const {

// for(const& [_, nmm]: m_meshes) {
// if(m.is_string
// }
//}
} // namespace wmtk::components::multimesh
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,17 @@ class MeshCollection
NamedMultiMesh& get_named_multimesh(const std::string_view& path);
Mesh& get_mesh(const std::string_view& path);


//std::vector<const NamedMultiMesh*> get_named_multimeshes(const Mesh&) const;

// over time meshes can merge and have aliases
// Thsi operation removes meshes whose naming structure aren't the root of a naming tree
void make_canonical();

std::map<std::string, const Mesh&> all_meshes() const;

// checks whether the meshes / nodes are synchronized. Passes thrown errors if desired
bool is_valid(bool pass_exceptions = false) const;
private:
std::map<std::string_view, std::unique_ptr<NamedMultiMesh>> m_meshes;
};
Expand Down
Loading
Loading