Skip to content

Commit

Permalink
Merge remote-tracking branch 'upstream/mtao/attribute_types' into mta…
Browse files Browse the repository at this point in the history
…o/application_utils
  • Loading branch information
mtao committed Dec 16, 2024
2 parents b2930db + 01aa6a1 commit 114203a
Show file tree
Hide file tree
Showing 10 changed files with 72 additions and 22 deletions.
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()
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()
24 changes: 24 additions & 0 deletions src/wmtk/attribute/AttributeType.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
#include "AttributeType.hpp"
namespace wmtk::attribute {
const std::string_view attribute_type_name(AttributeType pt) {

switch(pt) {
case AttributeType::Char:
return attribute_type_traits<AttributeType::Char>::name;
case AttributeType::Int64:
return attribute_type_traits<AttributeType::Int64>::name;
case AttributeType::Double:
return attribute_type_traits<AttributeType::Double>::name;
case AttributeType::Rational:
return attribute_type_traits<AttributeType::Rational>::name;
default:
break;
}
return "";
}

const std::string_view attribute_type_traits<AttributeType::Rational>::name = "Rational";
const std::string_view attribute_type_traits<AttributeType::Double>::name = "Double";
const std::string_view attribute_type_traits<AttributeType::Int64>::name = "Int64";
const std::string_view attribute_type_traits<AttributeType::Char>::name = "Char";
}
17 changes: 11 additions & 6 deletions src/wmtk/attribute/AttributeType.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,32 +5,36 @@ namespace wmtk::attribute {
enum class AttributeType { Char = 0, Int64 = 1, Double = 2, Rational = 3 };

template <AttributeType AT>
struct type_from_attribute_type_enum
struct attribute_type_traits
{
};
template <>
struct type_from_attribute_type_enum<AttributeType::Char>
struct attribute_type_traits<AttributeType::Char>
{
using type = char;
const static std::string_view name;
};
template <>
struct type_from_attribute_type_enum<AttributeType::Double>
struct attribute_type_traits<AttributeType::Double>
{
using type = double;
const static std::string_view name;
};
template <>
struct type_from_attribute_type_enum<AttributeType::Int64>
struct attribute_type_traits<AttributeType::Int64>
{
using type = int64_t;
const static std::string_view name;
};
template <>
struct type_from_attribute_type_enum<AttributeType::Rational>
struct attribute_type_traits<AttributeType::Rational>
{
using type = wmtk::Rational;
const static std::string_view name;
};

template <AttributeType AT>
using type_from_attribute_type_enum_t = typename type_from_attribute_type_enum<AT>::type;
using type_from_attribute_type_enum_t = typename attribute_type_traits<AT>::type;

template <typename T>
inline constexpr auto attribute_type_enum_from_type() -> AttributeType
Expand All @@ -53,4 +57,5 @@ inline constexpr auto attribute_type_enum_from_type() -> AttributeType
return AttributeType::Char;
}
}
const std::string_view attribute_type_name(AttributeType pt);
} // namespace wmtk::attribute
1 change: 1 addition & 0 deletions src/wmtk/attribute/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ set(SRC_FILES
Accessor.hpp

AttributeType.hpp
AttributeType.cpp

)
target_sources(wildmeshing_toolkit PRIVATE ${SRC_FILES})
Expand Down
21 changes: 7 additions & 14 deletions src/wmtk/attribute/MeshAttributeHandle.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@

#include <tuple>
#include <variant>
#include <tuple>

namespace wmtk {
class Mesh;
Expand Down Expand Up @@ -76,21 +77,13 @@ class MeshAttributeHandle

bool operator==(const MeshAttributeHandle& o) const
{
#if defined(MTAO_DEBUG_MESH_COMP)
std::visit(
[&](const auto& h, const auto& oh) {
spdlog::warn(
"{} {} == {} {}",
std::string(h),
fmt::ptr(m_mesh),
std::string(oh),
fmt::ptr(m_mesh));
},
m_handle,
o.m_handle);
#endif
return m_handle == o.m_handle && m_mesh == o.m_mesh;
return std::tie(m_mesh, m_handle) == std::tie(o.m_mesh, o.m_handle);
}
bool operator<(const MeshAttributeHandle& o) const
{
return std::tie(m_mesh, m_handle) < std::tie(o.m_mesh, o.m_handle);
}


// reutrns if the target mesh is the same as the one represented in the handle
bool is_same_mesh(const Mesh&) const;
Expand Down
2 changes: 2 additions & 0 deletions tests/attributes/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ set(TEST_SOURCES
old_wmtk_attributecollection.cpp

transaction_stack.cpp

attribute_type.cpp
)
target_sources(wmtk_tests PRIVATE ${TEST_SOURCES})

Expand Down
19 changes: 19 additions & 0 deletions tests/attributes/attribute_type.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
#include <numeric>

#include <catch2/catch_test_macros.hpp>
#include <wmtk/attribute/AttributeType.hpp>


using namespace wmtk::attribute;

TEST_CASE("test_attribute_type_names", "[attributes]")
{
using AT = AttributeType;
// converting to string because some compilers fail with this combo of catch + string_view comparisons?
CHECK(std::string(attribute_type_name(AT::Char)) == "Char");
CHECK(std::string(attribute_type_name(AT::Double)) == "Double");
CHECK(std::string(attribute_type_name(AT::Int64)) == "Int64");
CHECK(std::string(attribute_type_name(AT::Rational)) == "Rational");

}

0 comments on commit 114203a

Please sign in to comment.