Loading CMakeLists.txt +37 −27 Original line number Diff line number Diff line cmake_minimum_required(VERSION 3.14) ################################################################################ # CSG Parser ################################################################################ add_library(csg) target_sources(csg PRIVATE src/csg/impl/parser.cpp src/csg/impl/levelset.cpp src/csg/impl/csg.cpp ) set(CMAKE_CXX_STANDARD 17) set(CMAKE_CXX_STANDARD_REQUIRED ON) set(CMAKE_CXX_EXTENSIONS OFF) target_include_directories(csg PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/subprojects/PEGTL/include) project(MFIX-Parser DESCRIPTION "A parser for MFIX-Exa input files" HOMEPAGE_URL "https://mfix.netl.doe.gov/gitlab/exa/mfix-parser" LANGUAGES CXX ) target_link_libraries(csg PRIVATE stdc++fs) target_compile_features(csg PRIVATE cxx_std_17) set( CMAKE_EXPORT_COMPILE_COMMANDS ON ) set(USE_CCACHE "") find_program(CCACHE_FOUND ccache) if(CCACHE_FOUND) set( CMAKE_CXX_COMPILER_LAUNCHER ccache ) SET(catch2_dir ${CMAKE_CURRENT_SOURCE_DIR}/subprojects/Catch2) if(NOT EXISTS "${catch2_dir}/CMakeLists.txt") message(FATAL_ERROR "File ${catch2_dir}/CMakeLists.txt does not exist! The submodules were not downloaded! GIT_SUBMODULE was turned off or failed. Please update submodules and try again.") endif() add_subdirectory(src) add_subdirectory(tests) add_subdirectory(${catch2_dir} ${CMAKE_CURRENT_BINARY_DIR}/catch_build) list(APPEND CMAKE_MODULE_PATH "${catch2_dir}/contrib/") include(CTest) include(Catch) find_program(CLANG_FMT NAMES clang-format-9 clang-format-8 clang-format-7 clang-format) if(CLANG_FMT) get_target_property(_psrcs unit_tests SOURCES) get_target_property(_csg_srcs csg SOURCES) file(GLOB _csg_incs ${CMAKE_CURRENT_SOURCE_DIR}/*.hpp ${CMAKE_CURRENT_SOURCE_DIR}/impl/*.hpp) add_custom_target(fmt_csg COMMAND ${CLANG_FMT} -i ${_csg_srcs} ${_csg_incs} WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} ) add_custom_target(fmt_test COMMAND ${CLANG_FMT} -i ${_psrcs} COMMAND ${CLANG_FMT} -i ${_ut_srcs} ${_ft_srcs} WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/tests ) file(GLOB _includes ${PROJECT_SOURCE_DIR}/src/*.hpp) add_custom_target(fmt) add_dependencies(fmt fmt_test) add_dependencies(fmt fmt_test fmt_csg) endif() set(EXENAME "mfix-parser") add_executable(${EXENAME} src/main.cpp) target_link_libraries(${EXENAME} parser) meson.build +15 −3 Original line number Diff line number Diff line Loading @@ -4,7 +4,19 @@ project('mfix-parser', 'cpp', tao_inc = include_directories('subprojects/PEGTL/include') catch2_inc = include_directories('subprojects/Catch2/single_include') parser_inc = include_directories('src') parser_inc = include_directories( 'src/csg', 'src/csg/impl', 'src/inputs') subdir('src') subdir('tests') subdir('src/csg') subdir('src/inputs') executable( 'mfix-parser', 'src/main.cpp', include_directories: parser_inc, link_with: [ lib_csg_parser, lib_inputs_parser, ]) src/CMakeLists.txtdeleted 100644 → 0 +0 −13 Original line number Diff line number Diff line ################################################################################ # inputs Parser ################################################################################ add_library(parser parser.cpp solver.cpp ) target_include_directories(parser PRIVATE ${CMAKE_SOURCE_DIR}/subprojects/PEGTL/include) target_link_libraries(parser PRIVATE stdc++fs) src/csg/csg.hpp 0 → 100644 +52 −0 Original line number Diff line number Diff line #ifndef CSG_H_ #define CSG_H_ #if defined(CSG_USE_GPU) && !defined(CSG_GPU_HOST_DEVICE) #define CSG_GPU_HOST_DEVICE __host__ __device__ #else #define CSG_GPU_HOST_DEVICE #endif #include <array> #include <memory> #include <tuple> #include <vector> namespace csg { struct GPUable {}; template <class D, class Enable = void> struct IsGPUable : std::false_type {}; template <class D> struct IsGPUable< D, typename std::enable_if<std::is_base_of<GPUable, D>::value>::type> : std::true_type {}; struct Tree; std::shared_ptr<Tree> parse_csg(std::string); class CsgIF : GPUable { public: CsgIF(std::shared_ptr<Tree> a_state); CsgIF(const CsgIF &rhs); CsgIF(CsgIF &&rhs) noexcept; CsgIF &operator=(const CsgIF &rhs) = delete; CsgIF &operator=(CsgIF &&rhs) = delete; ~CsgIF(); CSG_GPU_HOST_DEVICE double operator()(double xx, double yy, double zz) const noexcept; inline double operator()(const std::array<double, 3> &p) const noexcept { return this->operator()(p[0], p[1], p[2]); } private: std::shared_ptr<Tree> m_state; class Impl; std::unique_ptr<Impl> m_pimpl; }; } // namespace csg #endif src/csg/impl/csg.cpp 0 → 100644 +28 −0 Original line number Diff line number Diff line #include "../csg.hpp" #include "csg_types.hpp" namespace csg { class CsgIF::Impl { public: double call_signed_distance(const std::shared_ptr<Tree> &a_tree, double xx, double yy, double zz) const { return signed_distance(a_tree->top, xx, yy, zz); } }; CsgIF::CsgIF(const CsgIF &rhs) : m_state(rhs.m_state), m_pimpl(std::make_unique<Impl>(*rhs.m_pimpl)) {} CsgIF::CsgIF(std::shared_ptr<Tree> a_state) : m_state(a_state), m_pimpl(std::make_unique<Impl>()) {} CsgIF::CsgIF(CsgIF &&rhs) noexcept = default; CsgIF::~CsgIF() = default; double CsgIF::operator()(double xx, double yy, double zz) const noexcept { return m_pimpl->call_signed_distance(m_state, xx, yy, zz); } } // namespace csg Loading
CMakeLists.txt +37 −27 Original line number Diff line number Diff line cmake_minimum_required(VERSION 3.14) ################################################################################ # CSG Parser ################################################################################ add_library(csg) target_sources(csg PRIVATE src/csg/impl/parser.cpp src/csg/impl/levelset.cpp src/csg/impl/csg.cpp ) set(CMAKE_CXX_STANDARD 17) set(CMAKE_CXX_STANDARD_REQUIRED ON) set(CMAKE_CXX_EXTENSIONS OFF) target_include_directories(csg PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/subprojects/PEGTL/include) project(MFIX-Parser DESCRIPTION "A parser for MFIX-Exa input files" HOMEPAGE_URL "https://mfix.netl.doe.gov/gitlab/exa/mfix-parser" LANGUAGES CXX ) target_link_libraries(csg PRIVATE stdc++fs) target_compile_features(csg PRIVATE cxx_std_17) set( CMAKE_EXPORT_COMPILE_COMMANDS ON ) set(USE_CCACHE "") find_program(CCACHE_FOUND ccache) if(CCACHE_FOUND) set( CMAKE_CXX_COMPILER_LAUNCHER ccache ) SET(catch2_dir ${CMAKE_CURRENT_SOURCE_DIR}/subprojects/Catch2) if(NOT EXISTS "${catch2_dir}/CMakeLists.txt") message(FATAL_ERROR "File ${catch2_dir}/CMakeLists.txt does not exist! The submodules were not downloaded! GIT_SUBMODULE was turned off or failed. Please update submodules and try again.") endif() add_subdirectory(src) add_subdirectory(tests) add_subdirectory(${catch2_dir} ${CMAKE_CURRENT_BINARY_DIR}/catch_build) list(APPEND CMAKE_MODULE_PATH "${catch2_dir}/contrib/") include(CTest) include(Catch) find_program(CLANG_FMT NAMES clang-format-9 clang-format-8 clang-format-7 clang-format) if(CLANG_FMT) get_target_property(_psrcs unit_tests SOURCES) get_target_property(_csg_srcs csg SOURCES) file(GLOB _csg_incs ${CMAKE_CURRENT_SOURCE_DIR}/*.hpp ${CMAKE_CURRENT_SOURCE_DIR}/impl/*.hpp) add_custom_target(fmt_csg COMMAND ${CLANG_FMT} -i ${_csg_srcs} ${_csg_incs} WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} ) add_custom_target(fmt_test COMMAND ${CLANG_FMT} -i ${_psrcs} COMMAND ${CLANG_FMT} -i ${_ut_srcs} ${_ft_srcs} WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/tests ) file(GLOB _includes ${PROJECT_SOURCE_DIR}/src/*.hpp) add_custom_target(fmt) add_dependencies(fmt fmt_test) add_dependencies(fmt fmt_test fmt_csg) endif() set(EXENAME "mfix-parser") add_executable(${EXENAME} src/main.cpp) target_link_libraries(${EXENAME} parser)
meson.build +15 −3 Original line number Diff line number Diff line Loading @@ -4,7 +4,19 @@ project('mfix-parser', 'cpp', tao_inc = include_directories('subprojects/PEGTL/include') catch2_inc = include_directories('subprojects/Catch2/single_include') parser_inc = include_directories('src') parser_inc = include_directories( 'src/csg', 'src/csg/impl', 'src/inputs') subdir('src') subdir('tests') subdir('src/csg') subdir('src/inputs') executable( 'mfix-parser', 'src/main.cpp', include_directories: parser_inc, link_with: [ lib_csg_parser, lib_inputs_parser, ])
src/CMakeLists.txtdeleted 100644 → 0 +0 −13 Original line number Diff line number Diff line ################################################################################ # inputs Parser ################################################################################ add_library(parser parser.cpp solver.cpp ) target_include_directories(parser PRIVATE ${CMAKE_SOURCE_DIR}/subprojects/PEGTL/include) target_link_libraries(parser PRIVATE stdc++fs)
src/csg/csg.hpp 0 → 100644 +52 −0 Original line number Diff line number Diff line #ifndef CSG_H_ #define CSG_H_ #if defined(CSG_USE_GPU) && !defined(CSG_GPU_HOST_DEVICE) #define CSG_GPU_HOST_DEVICE __host__ __device__ #else #define CSG_GPU_HOST_DEVICE #endif #include <array> #include <memory> #include <tuple> #include <vector> namespace csg { struct GPUable {}; template <class D, class Enable = void> struct IsGPUable : std::false_type {}; template <class D> struct IsGPUable< D, typename std::enable_if<std::is_base_of<GPUable, D>::value>::type> : std::true_type {}; struct Tree; std::shared_ptr<Tree> parse_csg(std::string); class CsgIF : GPUable { public: CsgIF(std::shared_ptr<Tree> a_state); CsgIF(const CsgIF &rhs); CsgIF(CsgIF &&rhs) noexcept; CsgIF &operator=(const CsgIF &rhs) = delete; CsgIF &operator=(CsgIF &&rhs) = delete; ~CsgIF(); CSG_GPU_HOST_DEVICE double operator()(double xx, double yy, double zz) const noexcept; inline double operator()(const std::array<double, 3> &p) const noexcept { return this->operator()(p[0], p[1], p[2]); } private: std::shared_ptr<Tree> m_state; class Impl; std::unique_ptr<Impl> m_pimpl; }; } // namespace csg #endif
src/csg/impl/csg.cpp 0 → 100644 +28 −0 Original line number Diff line number Diff line #include "../csg.hpp" #include "csg_types.hpp" namespace csg { class CsgIF::Impl { public: double call_signed_distance(const std::shared_ptr<Tree> &a_tree, double xx, double yy, double zz) const { return signed_distance(a_tree->top, xx, yy, zz); } }; CsgIF::CsgIF(const CsgIF &rhs) : m_state(rhs.m_state), m_pimpl(std::make_unique<Impl>(*rhs.m_pimpl)) {} CsgIF::CsgIF(std::shared_ptr<Tree> a_state) : m_state(a_state), m_pimpl(std::make_unique<Impl>()) {} CsgIF::CsgIF(CsgIF &&rhs) noexcept = default; CsgIF::~CsgIF() = default; double CsgIF::operator()(double xx, double yy, double zz) const noexcept { return m_pimpl->call_signed_distance(m_state, xx, yy, zz); } } // namespace csg