Skip to content

Commit

Permalink
Merge branch 'develop' into apw/gmi_cap_improvements
Browse files Browse the repository at this point in the history
  • Loading branch information
bobpaw authored Oct 3, 2024
2 parents 32c22af + e8c9770 commit 4fdda7b
Show file tree
Hide file tree
Showing 14 changed files with 203 additions and 26 deletions.
20 changes: 15 additions & 5 deletions .github/workflows/cmake.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,12 @@ jobs:
fail-fast: false
matrix:
compiler:
- { compiler: GNU, CC: gcc-10, CXX: g++-10 }
- { compiler: LLVM, CC: clang, CXX: clang++ }
- { name: GNU, CC: gcc-10, CXX: g++-10 }
- { name: LLVM, CC: clang, CXX: clang++ }
build_type: [Debug, Release]

steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v4
with:
submodules: recursive

Expand All @@ -30,17 +30,27 @@ jobs:
env:
MPICH_CXX: ${{matrix.compiler.CXX}}
MPICH_CC: ${{matrix.compiler.CC}}
run: cmake -S ${{github.workspace}} -B ${{github.workspace}}/build -DCMAKE_CXX_COMPILER=mpicxx -DCMAKE_C_COMPILER=mpicc -DCMAKE_VERBOSE_MAKEFILE=ON -DMESHES=${{github.workspace}}/pumi-meshes -DIS_TESTING=ON -DSCOREC_CXX_WARNINGS=ON -DCMAKE_BUILD_TYPE=${{matrix.build_type}}
run: cmake -S ${{github.workspace}} -B ${{github.workspace}}/build -DCMAKE_CXX_COMPILER=mpicxx -DCMAKE_C_COMPILER=mpicc -DCMAKE_VERBOSE_MAKEFILE=ON -DMESHES=${{github.workspace}}/pumi-meshes -DIS_TESTING=ON -DSCOREC_CXX_WARNINGS=ON -DCMAKE_BUILD_TYPE=${{matrix.build_type}} -DCMAKE_INSTALL_PREFIX=${{github.workspace}}/build/install

- name: Build
env:
MPICH_CXX: ${{matrix.compiler.CXX}}
MPICH_CC: ${{matrix.compiler.CC}}
run: cmake --build ${{github.workspace}}/build --config ${{matrix.build_type}} -j
run: cmake --build ${{github.workspace}}/build --config ${{matrix.build_type}} -j --target install

- name: Test
env:
MPICH_CXX: ${{matrix.compiler.CXX}}
MPICH_CC: ${{matrix.compiler.CC}}
working-directory: ${{github.workspace}}/build
run: ctest --output-on-failure -C ${{matrix.build_type}}

- name: Build User Project
# only need to test with a single build config if the installed cmake config files work
if: matrix.compiler.name == 'GNU' && matrix.build_type == 'Release'
env:
MPICH_CXX: ${{matrix.compiler.CXX}}
MPICH_CC: ${{matrix.compiler.CC}}
run: |
cmake -S ${{github.workspace}}/doc -B ${{github.workspace}}/buildExample -DCMAKE_CXX_COMPILER=mpicxx -DSCOREC_PREFIX=${{github.workspace}}/build/install
cmake --build ${{github.workspace}}/buildExample
Original file line number Diff line number Diff line change
Expand Up @@ -99,9 +99,13 @@ jobs:
run: |
mkdir -p ./pr
echo "${{ github.event.issue.number }}" > ./pr/issueNumber
echo "[Build Log](https://github.com/${{github.repository}}/actions/runs/${{ github.run_id }})" >> ./pr/message
echo "Simmetrix Test Result: ${{ steps.build_sim.outcome }} " >> ./pr/message
echo "Simmetrix + CGNS Test Result: ${{ steps.build_sim_cgns.outcome }} " >> ./pr/message
message=$(cat << HEREDOC
[Build Log](https://github.com/${{github.repository}}/actions/runs/${{github.run_id}})
Simmetrix Test Result: ${{steps.build_sim.outcome}}
Simmetrix + CGNS Test Result: ${{steps.build_sim_cgns.outcome}}
HEREDOC
)
echo "$message" > ./pr/message
- name: Upload result
if: ${{ !cancelled() }} #upload unless the job was cancelled
Expand Down
31 changes: 24 additions & 7 deletions apf_cap/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -16,14 +20,27 @@ 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
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}>
$<INSTALL_INTERFACE:include>
)

#directory containing apf_simConfig.h
target_include_directories(apf_cap PRIVATE
$<BUILD_INTERFACE:${CMAKE_CURRENT_BINARY_DIR}>)
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)
target_compile_features(apf_cap PRIVATE cxx_std_14)
endif()

include(GNUInstallDirs)

target_include_directories(apf_cap PUBLIC
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}>
$<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}>
)

scorec_export_library(apf_cap)

Expand Down
79 changes: 79 additions & 0 deletions apf_cap/apfCAP.cc
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,14 @@
#include <gmi.h>
#include <gmi_cap.h>
#include <cstdlib>
#include <mth.h>
#include <pcu_util.h>
#include <algorithm>
#include <lionPrint.h>

#ifdef HAVE_CAPSTONE_SIZINGMETRICTOOL
#include <CreateMG_SizingMetricTool.h>
#endif

namespace apf {

Expand Down Expand Up @@ -942,5 +947,79 @@ 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<apf::MeshCAP*>(mesh);
if (!m) {
lion_eprint(1, "ERROR: smoothCAPAnisoSizes: mesh is not an apf::MeshCAP*\n");
return false;
}
std::vector<Metric6> 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<Metric6> 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]);
int n = apf::eigen(t, &Q[0], &H[0]);
PCU_DEBUG_ASSERT(n == 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
25 changes: 25 additions & 0 deletions apf_cap/apfCAP.h
Original file line number Diff line number Diff line change
Expand Up @@ -182,6 +182,31 @@ class MeshCAP : public Mesh2
std::vector<TagCAP*> 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

Expand Down
16 changes: 8 additions & 8 deletions cmake/bob.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -155,11 +155,11 @@ endmacro(bob_public_dep)

function(bob_export_target tgt_name)
install(TARGETS ${tgt_name} EXPORT ${tgt_name}-target
RUNTIME DESTINATION bin
ARCHIVE DESTINATION lib
LIBRARY DESTINATION lib)
RUNTIME DESTINATION "${CMAKE_INSTALL_BINDIR}"
ARCHIVE DESTINATION "${CMAKE_INSTALL_LIBDIR}"
LIBRARY DESTINATION "${CMAKE_INSTALL_LIBDIR}")
install(EXPORT ${tgt_name}-target NAMESPACE ${PROJECT_NAME}::
DESTINATION lib/cmake/${PROJECT_NAME})
DESTINATION "${CMAKE_INSTALL_LIBDIR}/cmake/${PROJECT_NAME}")
set(${PROJECT_NAME}_EXPORTED_TARGETS
${${PROJECT_NAME}_EXPORTED_TARGETS} ${tgt_name} PARENT_SCOPE)
endfunction(bob_export_target)
Expand All @@ -173,8 +173,8 @@ endmacro(bob_end_subdir)

function(bob_end_package)
include(CMakePackageConfigHelpers)
set(INCLUDE_INSTALL_DIR include)
set(LIB_INSTALL_DIR lib)
set(INCLUDE_INSTALL_DIR "${CMAKE_INSTALL_INCLUDEDIR}")
set(LIB_INSTALL_DIR "${CMAKE_INSTALL_LIBDIR}")
set(CONFIG_CONTENT "
set(${PROJECT_NAME}_VERSION ${${PROJECT_NAME}_VERSION})
include(CMakeFindDependencyMacro)
Expand Down Expand Up @@ -213,7 +213,7 @@ set(${PROJECT_NAME}_CXX_FLAGS \"${CMAKE_CXX_FLAGS}\")
")
install(FILES
"${PROJECT_BINARY_DIR}/${PROJECT_NAME}Config.cmake"
DESTINATION lib/cmake/${PROJECT_NAME})
DESTINATION "${CMAKE_INSTALL_LIBDIR}/cmake/${PROJECT_NAME}")
if(PROJECT_VERSION)
file(WRITE
${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}Config.cmake
Expand All @@ -224,6 +224,6 @@ set(${PROJECT_NAME}_CXX_FLAGS \"${CMAKE_CXX_FLAGS}\")
COMPATIBILITY SameMajorVersion)
install(FILES
"${PROJECT_BINARY_DIR}/${PROJECT_NAME}ConfigVersion.cmake"
DESTINATION lib/cmake/${PROJECT_NAME})
DESTINATION "${CMAKE_INSTALL_LIBDIR}/cmake/${PROJECT_NAME}")
endif()
endfunction(bob_end_package)
5 changes: 3 additions & 2 deletions doc/user_CMakeLists.cmake → doc/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -31,13 +31,14 @@ else()
endif()

#this is just example code, do your own thing
add_executable(mylibrary mylibrary.cpp)
add_library(mylibrary mylibrary.cpp)
add_executable(myprogram myprogram.cpp)
target_include_directories(myprogram PRIVATE ${CMAKE_CURRENT_SOURCE_DIR})

#for any targets that use PUMI, just use this command
#to it to include the right directories and link to all
#the scorec libraries automatically.
#we recommend PUBLIC if the target is a library and
#PRIVATE if the target is an executable
target_link_libraries(mylibrary PUBLIC SCOREC::core)
target_link_libraries(myprogram PRIVATE SCOREC::core)
target_link_libraries(myprogram PRIVATE mylibrary)
9 changes: 9 additions & 0 deletions doc/mylibrary.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
#include <gmi_mesh.h>
#include <apfBox.h>
#include <apfMesh2.h>
#include <apf.h>
void makeMesh() {
gmi_register_mesh();
apf::Mesh2* m = apf::makeMdsBox(1,1,1,1,1,1,0);
apf::destroyMesh(m);
}
4 changes: 4 additions & 0 deletions doc/mylibrary.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
#ifndef MYLIBRARY_H
#define MYLIBRARY_H
void makeMesh();
#endif
10 changes: 10 additions & 0 deletions doc/myprogram.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
#include <PCU.h>
#include "mylibrary.h"
int main(int argc, char** argv) {
MPI_Init(&argc,&argv);
PCU_Comm_Init();
makeMesh();
PCU_Comm_Free();
MPI_Finalize();
return 0;
}
6 changes: 5 additions & 1 deletion ma/maSnap.cc
Original file line number Diff line number Diff line change
Expand Up @@ -477,14 +477,16 @@ static void interpolateParametricCoordinatesOnRegularFace(
{
double range[2];
int dim = m->getModelType(g);
bool gface_isPeriodic = 0;
for (int d=0; d < dim; ++d) {
bool isPeriodic = m->getPeriodicRange(g,d,range);
if ((dim == 2) && (isPeriodic > 0)) gface_isPeriodic = 1;
p[d] = interpolateParametricCoordinate(t,a[d],b[d],range,isPeriodic, 0);
}

/* check if the new point is inside the model.
* otherwise re-run the above loop with last option
* in "interpolateParametricCoordinae" being 1.
* in "interpolateParametricCoordinate" being 1.
* Notes
* 1) we are assuming manifold surfaces
* 2) we only check for faces that are periodic
Expand All @@ -494,6 +496,8 @@ static void interpolateParametricCoordinatesOnRegularFace(
// this need to be done for faces, only
if (dim != 2)
return;
if (!gface_isPeriodic)
return;

Vector x;
bool ok;
Expand Down
3 changes: 3 additions & 0 deletions test/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -214,6 +214,9 @@ if(ENABLE_CAPSTONE)
target_include_directories(capVol PRIVATE "${PROJECT_SOURCE_DIR}/capstone_clis")
test_exe_func(cap_inClosureOf cap_inClosureOf.cc)
test_exe_func(cap_closestPoint cap_closestPoint.cc)
if(HAVE_CAPSTONE_SIZINGMETRICTOOL)
util_exe_func(cap_smooth cap_smooth.cc)
endif()
endif()

# send all the newly added utility executable targets
Expand Down
8 changes: 8 additions & 0 deletions test/cap_smooth.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
#include <pcu_util.h>
#include <apfCAP.h>

int main (void) {
PCU_ALWAYS_ASSERT(apf::has_smoothCAPAnisoSizes());
// FIXME: Test apf::smoothCAPAnisoSizes.
return 0;
}
3 changes: 3 additions & 0 deletions test/testing.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -897,4 +897,7 @@ if(ENABLE_CAPSTONE)
mpi_test(capVolCyl2 1 ./capVol -vg 4 ${MESHES}/cap/cyl_surf_only.cre)
mpi_test(cap_inClosureOf 1 ./cap_inClosureOf ${MESHES}/cap/cube_surf_only.cre)
mpi_test(cap_closestPoint 1 ./cap_closestPoint ${MESHES}/cap/cube_surf_only.cre)
if(HAVE_CAPSTONE_SIZINGMETRICTOOL)
mpi_test(cap_smooth 1 ./cap_smooth)
endif()
endif()

0 comments on commit 4fdda7b

Please sign in to comment.