From 367396e82c7022e1fed3fd1373c9e70d963865fb Mon Sep 17 00:00:00 2001 From: Aiden Woodruff Date: Fri, 20 Sep 2024 17:46:57 -0400 Subject: [PATCH 1/4] Add apf::smoothCAPAnisoSizes Signed-off-by: Aiden Woodruff --- apf_cap/apfCAP.cc | 78 +++++++++++++++++++++++++++++++++++++++++++++++ apf_cap/apfCAP.h | 25 +++++++++++++++ 2 files changed, 103 insertions(+) diff --git a/apf_cap/apfCAP.cc b/apf_cap/apfCAP.cc index 8e59797e8..8b75d9606 100644 --- a/apf_cap/apfCAP.cc +++ b/apf_cap/apfCAP.cc @@ -5,9 +5,14 @@ #include #include #include +#include #include #include +#include +#ifdef HAVE_CAPSTONE_SIZINGMETRICTOOL +#include +#endif namespace apf { @@ -942,5 +947,78 @@ Mesh2* createMesh(MeshDatabaseInterface* mdb, GeometryDatabaseInterface* gdb) return m; } +bool has_smoothCAPAnisoSizes(void) noexcept { +#ifdef HAVE_CAPSTONE_SIZINGMETRICTOOL + return true; +#else + return false; +#endif +} + +bool smoothCAPAnisoSizes(apf::Mesh2* mesh, std::string analysis, + apf::Field* scales, apf::Field* frames) { +#ifdef HAVE_CAPSTONE_SIZINGMETRICTOOL + apf::MeshCAP* m = dynamic_cast(mesh); + if (!m) { + lion_eprint(1, "ERROR: smoothCAPAnisoSizes: mesh is not an apf::MeshCAP*\n"); + return false; + } + std::vector sizing6(m->count(0)); + apf::Matrix3x3 Q; + apf::Vector3 H; + apf::MeshIterator* it = m->begin(0); + for (apf::MeshEntity* e = m->iterate(it); e; e = m->iterate(it)) { + apf::getVector(scales, e, 0, H); + apf::getMatrix(frames, e, 0, Q); + apf::Matrix3x3 L(H[0], 0, 0, 0, H[1], 0, 0, 0, H[2]); + apf::Matrix3x3 t = Q * L * apf::invert(Q); + size_t id; + MG_API_CALL(m->getMesh(), get_id(fromEntity(e), id)); + PCU_DEBUG_ASSERT(id != 0); + --id; + sizing6[id][0] = t[0][0]; + sizing6[id][1] = t[0][1]; + sizing6[id][2] = t[0][2]; + sizing6[id][3] = t[1][1]; + sizing6[id][4] = t[1][2]; + sizing6[id][5] = t[2][2]; + } + m->end(it); + auto smooth_tool = get_sizing_metric_tool(m->getMesh()->get_context(), + "CreateSmoothingBase"); + if (smooth_tool == nullptr) { + lion_eprint(1, "ERROR: Unable to find \"CreateSmoothingBase\"\n"); + return false; + } + smooth_tool->set_context(m->getMesh()->get_context()); + M_MModel mmodel; + MG_API_CALL(m->getMesh(), get_current_model(mmodel)); + smooth_tool->set_metric(mmodel, "sizing6", sizing6); + std::vector ometric; + smooth_tool->smooth_metric(mmodel, analysis, "sizing6", ometric); + it = m->begin(0); + for (apf::MeshEntity* e = m->iterate(it); e; e = m->iterate(it)) { + size_t id; + MG_API_CALL(m->getMesh(), get_id(fromEntity(e), id)); + PCU_DEBUG_ASSERT(id != 0); + --id; + const Metric6& m = ometric[id]; + apf::Matrix3x3 t(m[0], m[1], m[2], + m[1], m[3], m[4], + m[2], m[4], m[5]); + PCU_DEBUG_ASSERT(apf::eigen(t, &Q[0], &H[0]) == 3); + apf::setMatrix(frames, e, 0, Q); + apf::setVector(scales, e, 0, H); + } + m->end(it); + return true; +#else + (void) mesh; + (void) analysis; + (void) scales; + (void) frames; + apf::fail("smoothCAPAnisoSizes: Capstone does not have SizingMetricTool."); +#endif +} }//namespace apf diff --git a/apf_cap/apfCAP.h b/apf_cap/apfCAP.h index 102716bed..9b8c5005d 100644 --- a/apf_cap/apfCAP.h +++ b/apf_cap/apfCAP.h @@ -182,6 +182,31 @@ class MeshCAP : public Mesh2 std::vector tags; }; +/** + * \brief Test for smoothCAPAnisoSizes support. + * + * \return A boolean indicating whether support was compiled. False indicates + * the call would fail. + * + * \details smoothCAPAnisoSizes is only compiled if support for the underlying + * call is detected in the version of Capstone apf_cap was compiled + * against. Otherwise the call will always apf::fail. Use this + * function to programmatically test for the capability. + */ +bool has_smoothCAPAnisoSizes(void) noexcept; + +/** + * \brief Use the SizingMetricTool to smooth a size field on a Capstone mesh. + * + * \param m A Capstone mesh. + * \param analysis The Capstone analysis to use. + * \param frames An apf::Field of apf::Matrix3x3 with orthogonal basis frames. + * \param scales An apf::Field of apf::Vector3 with frame scales (eigenvalues). + * \return A boolean indicating success. + * \pre m must be an apf::MeshCAP. + */ +bool smoothCAPAnisoSizes(apf::Mesh2* m, std::string analysis, + apf::Field* frames, apf::Field* scales); }//namespace apf From 594fd521b54379139f3ef2eb3d8ddc63cde925e6 Mon Sep 17 00:00:00 2001 From: Aiden Woodruff Date: Fri, 20 Sep 2024 17:50:12 -0400 Subject: [PATCH 2/4] Add apf::smoothCAPAnisoSizes compile flags - If given HAVE_CAPSTONE_SIZINGMETRICTOOL, compile apf_cap with C++14 and link to framework_meshing. - Install to CMAKE_INSTALL_INCLUDEDIR. - Remove -I${CMAKE_BINARY_DIR} because there's no apf_capConfig.h.in. Signed-off-by: Aiden Woodruff --- apf_cap/CMakeLists.txt | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) diff --git a/apf_cap/CMakeLists.txt b/apf_cap/CMakeLists.txt index d4d2a74a6..5dcb4a580 100644 --- a/apf_cap/CMakeLists.txt +++ b/apf_cap/CMakeLists.txt @@ -16,14 +16,19 @@ add_library(apf_cap ${SOURCES}) target_link_libraries(apf_cap PUBLIC apf gmi_cap) target_link_libraries(apf_cap PUBLIC capstone_module framework_testing) -target_include_directories(apf_cap PUBLIC - $ - $ - ) -#directory containing apf_simConfig.h -target_include_directories(apf_cap PRIVATE - $) +if(HAVE_CAPSTONE_SIZINGMETRICTOOL) +target_compile_definitions(apf_cap PRIVATE HAVE_CAPSTONE_SIZINGMETRICTOOL) +target_link_libraries(apf_cap PRIVATE framework_meshing) +target_compile_features(apf_cap PRIVATE cxx_std_14) +endif() + +include(GNUInstallDirs) + +target_include_directories(apf_cap PUBLIC + $ + $ +) scorec_export_library(apf_cap) From 91bbfe968b454680c9453c8ae19ad00a0c65a684 Mon Sep 17 00:00:00 2001 From: Aiden Woodruff Date: Sat, 21 Sep 2024 20:27:24 -0400 Subject: [PATCH 3/4] Add feature test for sizing metric tool - I had to add C++14 to the check_include_file_cxx call. Signed-off-by: Aiden Woodruff --- apf_cap/CMakeLists.txt | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/apf_cap/CMakeLists.txt b/apf_cap/CMakeLists.txt index 5dcb4a580..597d6406a 100644 --- a/apf_cap/CMakeLists.txt +++ b/apf_cap/CMakeLists.txt @@ -7,6 +7,10 @@ if(NOT ENABLE_CAPSTONE) return() endif() +include(CMakePushCheckState) +include(CheckIncludeFileCXX) +cmake_policy(SET CMP0075 NEW) # Observe CMAKE_REQUIRED_LIBRARIES. + #Sources & Headers set(SOURCES apfCAP.cc) set(HEADERS apfCAP.h) @@ -17,6 +21,14 @@ target_link_libraries(apf_cap PUBLIC apf gmi_cap) target_link_libraries(apf_cap PUBLIC capstone_module framework_testing) +set(CMAKE_CXX_OLD_STANDARD "${CMAKE_CXX_STANDARD}") +cmake_push_check_state(RESET) +set(CMAKE_CXX_STANDARD 14) +set(CMAKE_REQUIRED_LIBRARIES "framework_meshing") +check_include_file_cxx("CreateMG_SizingMetricTool.h" HAVE_CAPSTONE_SIZINGMETRICTOOL) +cmake_pop_check_state() +set(CMAKE_CXX_STANDARD "${CMAKE_CXX_OLD_STANDARD}") + if(HAVE_CAPSTONE_SIZINGMETRICTOOL) target_compile_definitions(apf_cap PRIVATE HAVE_CAPSTONE_SIZINGMETRICTOOL) target_link_libraries(apf_cap PRIVATE framework_meshing) From ecc2e72ea182de0e47e25f520a32f9aff928b257 Mon Sep 17 00:00:00 2001 From: Aiden Woodruff Date: Sat, 21 Sep 2024 20:29:20 -0400 Subject: [PATCH 4/4] Add apf::smoothCAPAnisoSizes compilation test - Add compilation test to check that the compile definition worked. Signed-off-by: Aiden Woodruff --- test/CMakeLists.txt | 3 +++ test/cap_smooth.cc | 8 ++++++++ test/testing.cmake | 3 +++ 3 files changed, 14 insertions(+) create mode 100644 test/cap_smooth.cc diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt index 2495c0567..36cbaa07b 100644 --- a/test/CMakeLists.txt +++ b/test/CMakeLists.txt @@ -212,6 +212,9 @@ endif() if(ENABLE_CAPSTONE) util_exe_func(capVol capVol.cc) target_include_directories(capVol PRIVATE "${PROJECT_SOURCE_DIR}/capstone_clis") + if(HAVE_CAPSTONE_SIZINGMETRICTOOL) + util_exe_func(cap_smooth cap_smooth.cc) + endif() endif() # send all the newly added utility executable targets diff --git a/test/cap_smooth.cc b/test/cap_smooth.cc new file mode 100644 index 000000000..c66cb6115 --- /dev/null +++ b/test/cap_smooth.cc @@ -0,0 +1,8 @@ +#include +#include + +int main (void) { + PCU_ALWAYS_ASSERT(apf::has_smoothCAPAnisoSizes()); + // FIXME: Test apf::smoothCAPAnisoSizes. + return 0; +} diff --git a/test/testing.cmake b/test/testing.cmake index e8b97537a..1d0e617c5 100644 --- a/test/testing.cmake +++ b/test/testing.cmake @@ -895,4 +895,7 @@ if(ENABLE_CAPSTONE) mpi_test(capVolWing 1 ./capVol -vg 2 ${MESHES}/cap/wing_surf_only.cre) mpi_test(capVolCube 1 ./capVol -vg 3 ${MESHES}/cap/cube_surf_only.cre) mpi_test(capVolCyl2 1 ./capVol -vg 4 ${MESHES}/cap/cyl_surf_only.cre) + if(HAVE_CAPSTONE_SIZINGMETRICTOOL) + mpi_test(cap_smooth 1 ./cap_smooth) + endif() endif()