Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

start of geometry glueing tool #10

Merged
merged 31 commits into from
Dec 8, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
31 commits
Select commit Hold shift + click to select a range
416eebd
start of geometry glueing tool
smason Nov 17, 2021
6d340d4
allow input brep to be just a solid
smason Nov 17, 2021
e82578b
add a brep_flatten tool
smason Nov 17, 2021
1843b74
reorder includes
smason Nov 17, 2021
d8a69d6
get merge_solids doing something sensible
smason Nov 17, 2021
8090cdb
sanity check output of volume_of_shape
smason Nov 17, 2021
59432f3
try using git lfs to track larger test-data files
smason Nov 17, 2021
197fcf7
add git-lfs to README and add .gitattributes that I missed before
smason Nov 17, 2021
e90ca3f
put SALOME license back in
smason Nov 23, 2021
d431841
add merge to README
smason Nov 23, 2021
bd96b5d
build instructions for salome tool
smason Nov 23, 2021
0f510cb
describe brep file format
smason Nov 23, 2021
1181a67
example of creating input for gluer regression test
smason Nov 23, 2021
65d230d
note numerical differences
smason Nov 24, 2021
cad5ac0
refactor out code to test is a shape is a compound
smason Nov 25, 2021
9df2a78
correct reference in README
smason Nov 25, 2021
86154ca
Merge branch 'main' into shape-merge-tool
smason Dec 7, 2021
aed41bc
forgot to get aixlog looking nice!
smason Dec 7, 2021
0a9164f
add intermediate shape merge data files
smason Dec 7, 2021
3a3b633
start automatic testing of shape merge code
smason Dec 7, 2021
f0e221a
verbose ctest output to see what's breaking
smason Dec 7, 2021
fdaed85
flatten first
smason Dec 7, 2021
e054c5d
works in act, what does github make of it?!
smason Dec 7, 2021
a5b4c44
maybe I just forgot to turn on lfs?
smason Dec 7, 2021
8113093
forgot git-lfs package
smason Dec 7, 2021
a7735fb
clean up tests now it appears to be mostly working
smason Dec 7, 2021
a4bffa6
more warnings and turn them into errors when building in CI
smason Dec 8, 2021
83d347c
give an option for generating code coverage
smason Dec 8, 2021
69c9588
add helper method to format pair of indexes nicely and use it
smason Dec 8, 2021
2c40812
oops, cmake syntax typo
smason Dec 8, 2021
71defda
resurrect brep_flatten tool
smason Dec 8, 2021
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
data/paramak_reactor.step filter=lfs diff=lfs merge=lfs -text
data/paramak_reactor-salome_glued.brep filter=lfs diff=lfs merge=lfs -text
data/paramak_reactor.brep filter=lfs diff=lfs merge=lfs -text
7 changes: 4 additions & 3 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,16 @@ jobs:
- name: Install system packages
run: |
apt-get -y update
apt-get -y install git g++ cmake libocct-foundation-dev libocct-data-exchange-dev
apt-get -y install git git-lfs g++ cmake libocct-foundation-dev libocct-data-exchange-dev
- uses: actions/checkout@v2
with:
lfs: true
submodules: recursive
- name: Build
run: |
git submodule update
cmake build . -B build
cmake build . -B build -DWERROR=ON
cmake --build build
- name: Test
run: |
env -C build ctest
env -C build ctest -V
27 changes: 24 additions & 3 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,14 +1,35 @@
cmake_minimum_required(VERSION 3.10)
cmake_minimum_required(VERSION 3.13)

project(overlap_checker LANGUAGES CXX)

set(CMAKE_CXX_STANDARD 11)
set(CMAKE_CXX_STANDARD 17)

include(CheckSymbolExists)
include(CTest)

# Code Coverage Configuration
add_library(coverage_config INTERFACE)

option(CODE_COVERAGE "Enable coverage reporting" OFF)
if(CODE_COVERAGE AND CMAKE_CXX_COMPILER_ID MATCHES "Clang")
# Add required flags (GCC & LLVM/Clang)
target_compile_options(coverage_config INTERFACE
-g -O0 # debug, no optimization
-fprofile-instr-generate -fcoverage-mapping
)
target_link_options(coverage_config INTERFACE
-fprofile-instr-generate -fcoverage-mapping)
elseif(CODE_COVERAGE)
message(SEND_ERROR "Clang is required for coverage at the moment")
endif()

option(WERROR "Enable -Werror compile flag" OFF)
if(WERROR)
add_compile_options(-Werror)
endif()

check_symbol_exists(argp_parse "argp.h" HAVE_ARGP)
if(NOT (HAVE_ARGP))
if(NOT HAVE_ARGP)
message(SEND_ERROR "GNU argp is required for command line parsing")
endif()

Expand Down
94 changes: 94 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,15 @@ Under ArchLinux the above dependencies would be installed via:
pacman -S cmake catch2 opencascade
```

## Git Large File Storage (LFS)

Testing this code involves a number of geometry files that aren't
suitable for tracking directly in Git. We're using Git LFS instead to
track these so this must be installed first, if you want to run
regression tests. See https://git-lfs.github.com/ for details.

## Compiling

Next we set up a build directory, compile the code, and run the unit
tests via:

Expand Down Expand Up @@ -123,6 +132,9 @@ grep overlap overlaps.csv | overlap_collecter test_geometry.brep common.brep

# perform imprinting
imprint_solids test_geometry.brep imprinted.brep < overlaps.csv

# merging of imprinted solids
merge_solids imprinted.brep merged.brep
```

# Tool descriptions
Expand All @@ -148,6 +160,9 @@ from the input file and outputs them to standard out, under the
expectation that this is directed to a file so it can be used by other
tools.

Note that the `brep_flatten` tool might be useful if you already have
a BREP file that you got from somewhere else.

## `overlap_checker`

This tool performs pairwise comparisons between all nearby solids
Expand Down Expand Up @@ -180,4 +195,83 @@ uses the same tolerance options as `overlap_checker`, and hence
vertices/edges of "touching" shapes might move due nearby shapes being
within this tolerance.

## `merge_solids`

This tool glues shared parts of solids together. It works from
verticies upto compound solid, merging any shared edges/faces as
appropriate. This is an intermediate step in our neutronics workflow
and aims to produce output compatible with [occ_faceter][].

[pyvenv]: https://docs.python.org/3/tutorial/venv.html
[occ_faceter]: https://github.com/makeclean/occ_faceter/


# File formats

The geometry data is stored in [BREP][brep_format] format with some constraints
designed to simplify subsequent processing tasks. Our workflow is
centered around [solids][occt_topological_types] and their materials.
Each solid has a defined material, and it's important to be able to
maintain this link during the processing steps. During import, e.g.
`step_to_brep`, the hierchial structure is flattened to a list of
solids, represented in OCCT and the BREP file as a COMPOUND. A CSV
file describing material information is also written that uses the
same ordering.

Subsequent tools that modify the shapes, e.g. `imprint_solids`,
maintain the top-level order. For example if there is an intersection
between shapes 3 and 4, the overlapping volume will be added to the
larger shape (e.g. shape 4). Hence, after imprinting shape 3 will be
slightly smaller while shape 4 will now be a COMPSOLID containing two
SOLIDS, one solid being this small intersecting volume and a copy of
shape 4 that has been modified to remove this intersection.

As a visual representation, our BREP format has a COMPOUND as the
top-level shape with either SOLIDS or COMPSOLIDs inside. For example,
after the above imprinting we might have:

```
* COMPOUND
* SOLID
* SOLID
* SOLID
* SOLID
* COMPSOLID
* SOLID
* SOLID
* SOLID
```

note that numbering is zero based.

[brep_format]: https://dev.opencascade.org/doc/occt-6.7.0/overview/html/occt_brep_format.html
[occt_topological_types]: https://dev.opencascade.org/doc/overview/html/occt_user_guides__modeling_data.html#occt_modat_5_2_1


# Coverage

Currently a few commands I found useful to run:

```shell
# configure with coverage enabled
env CXX=clang++ cmake build . -B build \
-DCMAKE_EXPORT_COMPILE_COMMANDS=ON -DCMAKE_BUILD_TYPE=Debug -DCODE_COVERAGE=ON

cd build

# run program
./merge_solids ../data/paramak_reactor.brep out.brep

# convert data into a format usable by llvm-cov
llvm-profdata merge -o testcov.profdata default.profraw

# generate html coverage report
llvm-cov show -output-dir=report -format=html ./merge_solids -instr-profile=testcov.profdata
```

can use `LLVM_PROFILE_FILE=paramak_reactor-merge.profraw` to output
raw profile to another file. see [cov1][1] and [cov2][2] for more
details

[cov1]: https://alastairs-place.net/blog/2016/05/20/code-coverage-from-the-command-line-with-clang/
[cov2]: https://clang.llvm.org/docs/SourceBasedCodeCoverage.html
3 changes: 3 additions & 0 deletions data/paramak_reactor-salome_glued.brep
Git LFS file not shown
3 changes: 3 additions & 0 deletions data/paramak_reactor.brep
Git LFS file not shown
3 changes: 3 additions & 0 deletions data/paramak_reactor.step
Git LFS file not shown
127 changes: 0 additions & 127 deletions meson.build

This file was deleted.

18 changes: 15 additions & 3 deletions src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,27 +3,39 @@
link_libraries(
TKernel
TKBO TKBRep TKPrim
TKG3d TKLCAF TKMath
TKG2d TKG3d TKLCAF TKMath
TKTopAlgo TKXCAF TKSTEP
TKXSBase TKXDESTEP TKShHealing)
TKXSBase TKXDESTEP TKShHealing
TKGeomAlgo)

add_library(shared OBJECT utils.cpp geometry.cpp thread_pool.cpp)
# supported by GCC and Clang
add_compile_options(-Wall -Wextra -Wconversion)

link_libraries(coverage_config)
link_libraries(pthread)

add_library(shared OBJECT utils.cpp geometry.cpp thread_pool.cpp)

add_executable(step_to_brep step_to_brep.cpp $<TARGET_OBJECTS:shared>)

add_executable(brep_flatten brep_flatten.cpp $<TARGET_OBJECTS:shared>)

add_executable(overlap_checker overlap_checker.cpp $<TARGET_OBJECTS:shared>)

add_executable(overlap_collecter overlap_collecter.cpp $<TARGET_OBJECTS:shared>)

add_executable(imprint_solids imprint_solids.cpp $<TARGET_OBJECTS:shared>)

add_executable(merge_solids merge_solids.cpp salome/geom_gluer.cpp $<TARGET_OBJECTS:shared>)

if(BUILD_TESTING)
add_executable(test_runner geometry.cpp utils.cpp thread_pool.cpp)
target_compile_definitions(test_runner PUBLIC -DINCLUDE_TESTS)
target_link_libraries(test_runner Catch2WithMain)

add_test(NAME unit-tests COMMAND test_runner)

add_test(NAME shape-merge
COMMAND bash ${PROJECT_SOURCE_DIR}/tests/test_merge_solids.sh
WORKING_DIRECTORY ${PROJECT_BINARY_DIR})
endif()
Loading