Skip to content

Commit

Permalink
Merge pull request #291 from MC-kit/devel
Browse files Browse the repository at this point in the history
Devel
  • Loading branch information
dvp2015 authored Jan 2, 2024
2 parents 68b90d4 + adf3c47 commit 1301d2b
Show file tree
Hide file tree
Showing 34 changed files with 3,433 additions and 3,720 deletions.
137 changes: 137 additions & 0 deletions .clang-format
Original file line number Diff line number Diff line change
@@ -0,0 +1,137 @@
---
Language: Cpp
# BasedOnStyle: Microsoft
AccessModifierOffset: -2
AlignAfterOpenBracket: BlockIndent
AlignConsecutiveMacros: false
AlignConsecutiveAssignments: false
AlignConsecutiveDeclarations: false
AlignEscapedNewlines: Right
AlignOperands: true
AlignTrailingComments: true
AllowAllArgumentsOnNextLine: true
AllowAllConstructorInitializersOnNextLine: true
AllowAllParametersOfDeclarationOnNextLine: true
AllowShortBlocksOnASingleLine: Never
AllowShortCaseLabelsOnASingleLine: false
AllowShortFunctionsOnASingleLine: None
AllowShortLambdasOnASingleLine: All
AllowShortIfStatementsOnASingleLine: Never
AllowShortLoopsOnASingleLine: false
AlwaysBreakAfterDefinitionReturnType: None
AlwaysBreakAfterReturnType: None
AlwaysBreakBeforeMultilineStrings: false
AlwaysBreakTemplateDeclarations: MultiLine
BinPackArguments: true
BinPackParameters: true
BraceWrapping:
AfterCaseLabel: false
AfterClass: true
AfterControlStatement: true
AfterEnum: true
AfterFunction: true
AfterNamespace: true
AfterObjCDeclaration: true
AfterStruct: true
AfterUnion: false
AfterExternBlock: true
BeforeCatch: true
BeforeElse: true
IndentBraces: false
SplitEmptyFunction: true
SplitEmptyRecord: true
SplitEmptyNamespace: true
BreakBeforeBinaryOperators: None
BreakBeforeBraces: Custom
BreakBeforeInheritanceComma: false
BreakInheritanceList: BeforeColon
BreakBeforeTernaryOperators: true
BreakConstructorInitializersBeforeComma: false
BreakConstructorInitializers: BeforeColon
BreakAfterJavaFieldAnnotations: false
BreakStringLiterals: true
ColumnLimit: 120
CommentPragmas: '^ IWYU pragma:'
CompactNamespaces: false
ConstructorInitializerAllOnOneLineOrOnePerLine: false
ConstructorInitializerIndentWidth: 4
ContinuationIndentWidth: 4
Cpp11BracedListStyle: true
DeriveLineEnding: true
DerivePointerAlignment: false
DisableFormat: false
ExperimentalAutoDetectBinPacking: false
FixNamespaceComments: true
ForEachMacros:
- foreach
- Q_FOREACH
- BOOST_FOREACH
IncludeBlocks: Preserve
IncludeCategories:
- Regex: '^"(llvm|llvm-c|clang|clang-c)/'
Priority: 2
SortPriority: 0
- Regex: '^(<|"(gtest|gmock|isl|json)/)'
Priority: 3
SortPriority: 0
- Regex: '.*'
Priority: 1
SortPriority: 0
IncludeIsMainRegex: '(Test)?$'
IncludeIsMainSourceRegex: ''
IndentCaseLabels: false
IndentGotoLabels: true
IndentPPDirectives: None
IndentWidth: 4
IndentWrappedFunctionNames: false
JavaScriptQuotes: Leave
JavaScriptWrapImports: true
KeepEmptyLinesAtTheStartOfBlocks: true
MacroBlockBegin: ''
MacroBlockEnd: ''
MaxEmptyLinesToKeep: 1
NamespaceIndentation: None
ObjCBinPackProtocolList: Auto
ObjCBlockIndentWidth: 2
ObjCSpaceAfterProperty: false
ObjCSpaceBeforeProtocolList: true
PenaltyBreakAssignment: 2
PenaltyBreakBeforeFirstCallParameter: 19
PenaltyBreakComment: 300
PenaltyBreakFirstLessLess: 120
PenaltyBreakString: 1000
PenaltyBreakTemplateDeclaration: 10
PenaltyExcessCharacter: 1000000
PenaltyReturnTypeOnItsOwnLine: 1000
PointerAlignment: Right
ReflowComments: true
SortIncludes: true
SortUsingDeclarations: true
SpaceAfterCStyleCast: false
SpaceAfterLogicalNot: false
SpaceAfterTemplateKeyword: true
SpaceBeforeAssignmentOperators: true
SpaceBeforeCpp11BracedList: false
SpaceBeforeCtorInitializerColon: true
SpaceBeforeInheritanceColon: true
SpaceBeforeParens: ControlStatements
SpaceBeforeRangeBasedForLoopColon: true
SpaceInEmptyBlock: false
SpaceInEmptyParentheses: false
SpacesBeforeTrailingComments: 1
SpacesInAngles: false
SpacesInConditionalStatement: false
SpacesInContainerLiterals: true
SpacesInCStyleCastParentheses: false
SpacesInParentheses: false
SpacesInSquareBrackets: false
SpaceBeforeSquareBrackets: false
Standard: Latest
StatementMacros:
- Q_UNUSED
- QT_REQUIRE_VERSION
TabWidth: 4
UseCRLF: false
UseTab: Never
...

5 changes: 5 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -108,3 +108,8 @@ poetry_setup_kwargs.txt
#cmake work folders
cmake-build-debug

#scibuild work folders
_skbuild

# Visual studio
.vs
20 changes: 10 additions & 10 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ repos:
rev: "v0.7.3"
hooks:
- id: pydocstringformatter
exclude: _parser\.py$|_tab\.py
exclude: _parser\.py$|_tab\.py|extern
#- repo: https://github.com/sirosen/texthooks
# rev: "0.3.1"
# hooks:
Expand All @@ -76,7 +76,7 @@ repos:
# Upgrade Python code
- id: pyupgrade
name: pyupgrade
exclude: \.idea|\.cache|^notebooks
exclude: \.idea|\.cache|^notebooks|^extern
entry: pyupgrade
args:
- --py39-plus
Expand All @@ -85,7 +85,7 @@ repos:
# Nicely sort imports
- id: isort
name: isort
exclude: tools|\.idea|\.cache|^notebooks
exclude: tools|\.idea|\.cache|^notebooks|^extern
entry: isort
language: system
types: [python]
Expand All @@ -95,14 +95,14 @@ repos:
entry: black
language: system
types: [python]
exclude: ^notebooks
exclude: ^notebooks|^extern
# Lint
- id: ruff
name: ruff
entry: ruff --force-exclude --fix --config pyproject.toml
language: system
types: [python]
exclude: ^notebooks
exclude: ^notebooks|^extern
# Also code format the docs
# - id: blacken-docs
# name: blacken-docs
Expand Down Expand Up @@ -187,11 +187,11 @@ repos:
# exclude: ^\.pre-commit-config.yaml$

# Clang format the codebase automatically
#- repo: https://github.com/pre-commit/mirrors-clang-format
# rev: "v13.0.1"
# hooks:
# - id: clang-format
# types_or: [c++, c, cuda]
- repo: https://github.com/pre-commit/mirrors-clang-format
rev: "v17.0.6"
hooks:
- id: clang-format
types_or: [c++, c, cuda]

# Automatic pre-commit check and updates with precommit.ci
# See https://results.pre-commit.ci/
Expand Down
134 changes: 101 additions & 33 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,18 +1,34 @@
cmake_minimum_required(VERSION 3.19...3.27)

# mckit_version=0.9.0 # TODO: retrieve from poetry
# project(mckit VERSION ${mckit_version} LANGUAGES C CXX)
project(${SKBUILD_PROJECT_NAME} VERSION ${SKBUILD_PROJECT_VERSION}
DESCRIPTION "mckit geometry extension"
LANGUAGES C)

list(APPEND CMAKE_MODULE_PATH ${PROJECT_SOURCE_DIR}/cmake)
include(CMakePrintHelpers)


if (NOT DEFINED SKBUILD_PROJECT_NAME)
set(SKBUILD_PROJECT_NAME mckit)
set(SKBUILD_PROJECT_VERSION 0.6.28)
endif ()

cmake_print_variables(SKBUILD_PROJECT_NAME SKBUILD_PROJECT_VERSION)

# TODO: setup SKBUILD variables in build.py - retrieve from poetry
project(
${SKBUILD_PROJECT_NAME}
VERSION ${SKBUILD_PROJECT_VERSION}
DESCRIPTION "mckit geometry extension"
LANGUAGES C # TODO: upgrade to CXX
)

#https://cliutils.gitlab.io/modern-cmake/chapters/packages/CUDA.html
#include(CheckLanguage)
#check_language(CUDA)
#if(CMAKE_CUDA_COMPILER)
# enable_language(CUDA)
#endif()


# Only do these if this is the main project, and not if it is included through add_subdirectory
if(CMAKE_PROJECT_NAME STREQUAL PROJECT_NAME)


# Set CMAKE_BUILD_TYPE to Release by default.
# Must be done before calling project()
set(default_build_type "Release")
Expand Down Expand Up @@ -44,48 +60,100 @@ if(CMAKE_PROJECT_NAME STREQUAL PROJECT_NAME)
endif()
endif()

find_package(Python REQUIRED COMPONENTS Interpreter Development.Module)
cmake_print_variables(PYTHON_EXECUTABLE)
list(APPEND CMAKE_MODULE_PATH ${PROJECT_SOURCE_DIR}/cmake)
list(APPEND CMAKE_PREFIX_PATH ${PROJECT_SOURCE_DIR}/cmake)


if (WIN32)
set(Python_FIND_VIRTUALENV FIRST)
endif ()

find_package(Python REQUIRED COMPONENTS Interpreter Development.Module NumPy)


cmake_print_variables(
Python_EXECUTABLE
Python_LIBRARIES
Python_LIBRARY_DIRS
Python_NumPy_INCLUDE_DIRS
Python_STDLIB
Python_SITELIB
)

# TODO dvp: check if CLI variable provided by sci-build are sufficient instead of own search

if (NOT DEFINED PythonEnv_ROOT)

execute_process(
COMMAND ${Python_EXECUTABLE} -c "import sys; print(sys.prefix)"
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
RESULT_VARIABLE Python_ROOT_FOUND
OUTPUT_VARIABLE PythonEnv_ROOT
OUTPUT_STRIP_TRAILING_WHITESPACE
)
if (NOT Python_ROOT_FOUND STREQUAL "0")
message(FATAL_ERROR "Cannot find python environment")
endif ()
endif ()
cmake_print_variables(PythonEnv_ROOT)

list(APPEND CMAKE_PREFIX_PATH ${PythonEnv_ROOT})


add_subdirectory(extern)

# ========================
# MKL
# https://gitlab.inria.fr/solverstack/test_fembem/-/blob/master/CMakeLists.txt
# ========================
# find_package(MKL REQUIRED)
# if(MKL_FOUND)
# set(CMAKE_C_FLAGS "${MKL_COMPILER_FLAGS} ${CMAKE_C_FLAGS}")
# set(CMAKE_CXX_FLAGS "${MKL_COMPILER_FLAGS} ${CMAKE_CXX_FLAGS}")
# endif()

if (NOT WIN32)
message("Creating symlinks in environment ${PythonEnv_ROOT}")
execute_process(
COMMAND ${Python_EXECUTABLE} building/create_mkl_symlinks.py
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
OUTPUT_VARIABLE CREATED_MKL_SYMLINKS
OUTPUT_STRIP_TRAILING_WHITESPACE
)
endif ()


if (WIN32)
set(MKL_DIR ${PythonEnv_ROOT}/Library)
else ()
set(MKL_DIR ${PythonEnv_ROOT})
endif ()

cmake_print_variables(MKL_DIR)
cmake_print_variables(CMAKE_MODULE_PATH CMAKE_PREFIX_PATH)

find_package(MKL REQUIRED)

set(geometry_dir ${CMAKE_CURRENT_SOURCE_DIR}/src/mckit/src/)

set(geometry_sources
${geometry_dir}box.c
${geometry_dir}box.h
${geometry_dir}box_doc.h
${geometry_dir}geometrymodule.c
${geometry_dir}rbtree.c
${geometry_dir}rbtree.h
${geometry_dir}shape.c
${geometry_dir}shape.h
${geometry_dir}surface.c
${geometry_dir}surface.h
${geometry_dir}surf_doc.h
${geometry_dir}shape.h
)


Python_add_library(geometry MODULE ${geometry_sources})
target_include_directories(geometry PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}/src/mckit/src ${MKL_INCLUDE_DIR} ${Python_NumPy_INCLUDE_DIRS})
target_link_libraries(geometry PUBLIC nlopt ${MKL_LIBRARIES})
cmake_print_properties(
TARGETS geometry
PROPERTIES SOURCES
python_add_library(geometry MODULE ${geometry_sources} WITH_SOABI)
target_include_directories(geometry
PUBLIC
${CMAKE_CURRENT_SOURCE_DIR}/src/mckit/src
${MKL_INCLUDE_DIR}
${Python_NumPy_INCLUDE_DIRS}
)
install(TARGETS geometry DESTINATION src/mckit)
target_link_libraries(geometry PUBLIC nlopt ${MKL_LIBRARIES})
if (WIN32)
target_link_libraries(geometry PUBLIC Python::Module)
else ()
target_link_libraries(geometry PUBLIC pthread m dl)
endif ()


install(TARGETS nlopt LIBRARY DESTINATION src/mckit)
install(TARGETS geometry LIBRARY DESTINATION src/mckit)


include(FeatureSummary)

Expand Down
18 changes: 18 additions & 0 deletions adhoc/simplify_up08.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
from __future__ import annotations

from pathlib import Path

from mckit.parser import from_file

HERE = Path(__file__).parent

WRK_DIR = HERE / "../wrk"
assert WRK_DIR.is_dir()

path = WRK_DIR / "UPP08_#3h.i"
assert path.exists()


model = from_file(path).universe
model.simplify(min_volume=1e-3)
model.save(WRK_DIR / "up08-simplified.i")
Loading

0 comments on commit 1301d2b

Please sign in to comment.