Merge remote-tracking branch 'gitlab/master' into get_surface_point

This commit is contained in:
Michael Neunteufel 2019-02-11 09:12:09 +01:00
commit ba26ddd834
93 changed files with 2556 additions and 757 deletions

View File

@ -5,25 +5,10 @@ stages:
- cleanup - cleanup
############################################ ############################################
# System templates # Windows
############################################ ############################################
# Windows .template_windows: &win
.template_windows_32: &win32
tags:
- windows
- x86
before_script:
- "echo off"
- 'call "%VS140COMNTOOLS%\..\..\VC\bin\vcvars32.bat"'
- set CMAKE_GENERATOR=Visual Studio 14 2015
- set CI_DIR=C:\ci\%CI_BUILD_REF%_32
- set NETGEN_BUILD_DIR=%CI_DIR%\build
- set INSTALL_DIR=%CI_DIR%\install
- set NETGENDIR=%INSTALL_DIR%\bin
- set PYTHONPATH=%INSTALL_DIR%\lib\site-packages
.template_windows_64: &win64
tags: tags:
- windows - windows
- x64 - x64
@ -31,37 +16,14 @@ stages:
- "echo off" - "echo off"
- 'call "%VS140COMNTOOLS%\..\..\VC\bin\amd64\vcvars64.bat"' - 'call "%VS140COMNTOOLS%\..\..\VC\bin\amd64\vcvars64.bat"'
- set CMAKE_GENERATOR=Visual Studio 14 2015 Win64 - set CMAKE_GENERATOR=Visual Studio 14 2015 Win64
- set CI_DIR=C:\ci\%CI_BUILD_REF%_64 - set CI_DIR=C:\ci\%CI_PIPELINE_ID%
- set NETGEN_BUILD_DIR=%CI_DIR%\build - set NETGEN_BUILD_DIR=%CI_DIR%\build
- set INSTALL_DIR=%CI_DIR%\install - set INSTALL_DIR=%CI_DIR%\install
- set NETGENDIR=%INSTALL_DIR%\bin - set NETGENDIR=%INSTALL_DIR%\bin
- set PYTHONPATH=%INSTALL_DIR%\lib\site-packages - set PYTHONPATH=%INSTALL_DIR%\lib\site-packages
# Linux build_win:
.template_ubuntu: &ubuntu <<: *win
tags:
- linux
before_script:
- pwd
- ls
- docker info
.template_ubuntu_1510: &ubuntu_1510
<<: *ubuntu
variables:
UBUNTU_VERSION: "15.10"
.template_ubuntu_1604: &ubuntu_1604
<<: *ubuntu
variables:
UBUNTU_VERSION: "16.04"
############################################
# Build stage
############################################
# Windows
.template_build_win: &tbuild_netgen_win
stage: build stage: build
script: script:
- git submodule update --init --recursive - git submodule update --init --recursive
@ -76,66 +38,52 @@ stages:
-DCMAKE_BUILD_TYPE=Release -DCMAKE_BUILD_TYPE=Release
- cmake --build . --target INSTALL --config Release - cmake --build . --target INSTALL --config Release
.build_netgen_win32: test_win:
<<: *win32 <<: *win
<<: *tbuild_netgen_win stage: test
cache: script:
paths: - cd %NETGEN_BUILD_DIR%\netgen
- build/ - ctest -C Release -V
- src/ - cd ..
key: "netgen_win32_${CI_BUILD_REF_NAME}"
build_netgen_win64: cleanup_win:
<<: *win64 <<: *win
<<: *tbuild_netgen_win stage: cleanup
cache: tags:
paths: - windows
- build/ - x64
- src/ script:
key: "netgen_win64_${CI_BUILD_REF_NAME}" - cd %CI_PROJECT_DIR%
- rd /s /q %CI_DIR%
when: always
allow_failure: true
# Linux ############################################
.template_build_linux: &build_linux # Ubuntu/Linux
############################################
.template_ubuntu: &ubuntu
tags:
- linux
before_script:
- pwd
- ls
- docker info
variables:
UBUNTU_VERSION: "18.04"
build_ubuntu:
<<: *ubuntu
stage: build stage: build
script: script:
- docker build -t netgen_${CI_BUILD_REF_NAME}:${UBUNTU_VERSION} -f tests/docker_${UBUNTU_VERSION} . - docker build -t netgen_${CI_BUILD_REF_NAME}:${UBUNTU_VERSION} -f tests/dockerfile .
- rm -f netgen_${CI_BUILD_REF_NAME}_$UBUNTU_VERSION.id - rm -f netgen_${CI_BUILD_REF_NAME}_$UBUNTU_VERSION.id
- docker run --cidfile netgen_${CI_BUILD_REF_NAME}_${UBUNTU_VERSION}.id -e CCACHE_DIR=/ccache -v /mnt/ccache:/ccache netgen_${CI_BUILD_REF_NAME}:${UBUNTU_VERSION} bash /root/src/netgen/tests/build.sh - docker run --cidfile netgen_${CI_BUILD_REF_NAME}_${UBUNTU_VERSION}.id -e CCACHE_DIR=/ccache -v /mnt/ccache:/ccache netgen_${CI_BUILD_REF_NAME}:${UBUNTU_VERSION} bash /root/src/netgen/tests/build.sh
- docker commit `cat netgen_${CI_BUILD_REF_NAME}_${UBUNTU_VERSION}.id` netgen_${CI_BUILD_REF_NAME}_installed:${UBUNTU_VERSION} - docker commit `cat netgen_${CI_BUILD_REF_NAME}_${UBUNTU_VERSION}.id` netgen_${CI_BUILD_REF_NAME}_installed:${UBUNTU_VERSION}
- rm netgen_${CI_BUILD_REF_NAME}_${UBUNTU_VERSION}.id - rm netgen_${CI_BUILD_REF_NAME}_${UBUNTU_VERSION}.id
.build_ubuntu_1510: test_ubuntu:
<<: *ubuntu_1510 <<: *ubuntu
<<: *build_linux
build_ubuntu_1604:
<<: *ubuntu_1604
<<: *build_linux
############################################
# Test stage
############################################
# Windows
.template_test_win: &test_win
stage: test
script:
- cd %NETGEN_BUILD_DIR%/netgen
- ctest -C Release -V
- cd ..
# skip since we have no machine with 32 bits
.test_win32:
<<: *win32
<<: *test_win
test_win64:
<<: *win64
<<: *test_win
# Linux
.template_test_linux: &test_linux
stage: test stage: test
script: script:
- >- - >-
@ -145,12 +93,76 @@ test_win64:
netgen_${CI_BUILD_REF_NAME}_installed:${UBUNTU_VERSION} netgen_${CI_BUILD_REF_NAME}_installed:${UBUNTU_VERSION}
bash -c 'cd /root/build/netgen && make test_netgen ARGS="-V"' bash -c 'cd /root/build/netgen && make test_netgen ARGS="-V"'
.test_ubuntu_1510: # cpp guideline checks
<<: *ubuntu_1510 test_guidelines:
<<: *test_linux <<: *ubuntu
test_ubuntu_1604: stage: test
<<: *ubuntu_1604 script:
<<: *test_linux - docker run -e CCACHE_DIR=/ccache -v /mnt/ccache:/ccache netgen_${CI_BUILD_REF_NAME}:${UBUNTU_VERSION} bash /root/src/netgen/tests/build_guidelines.sh
when: always
cleanup_ubuntu:
stage: cleanup
tags:
- linux
script:
# remove intermediate and old docker images and containers
- docker rm -f `docker ps --no-trunc -aq`
- docker images --no-trunc -aqf "dangling=true" | xargs docker rmi -f || true
when: always
allow_failure: true
############################################
# MacOSX
############################################
.template_mac: &mac
tags:
- mac
before_script:
- export ROOT_DIR=/tmp/$CI_PIPELINE_ID
- export SRC_DIR=$ROOT_DIR/src
- export BUILD_DIR=$ROOT_DIR/build
- export CMAKE_INSTALL_PREFIX=/tmp/$CI_PIPELINE_ID/install/Netgen.app
- export PYTHONPATH=$CMAKE_INSTALL_PREFIX/Contents/Resources/`python3 -c "from distutils.sysconfig import get_python_lib; print(get_python_lib(1,0,''))"`:.
- export PATH=$CMAKE_INSTALL_PREFIX/Contents/MacOS:$PATH
build_mac:
<<: *mac
stage: build
script:
- git submodule update --init --recursive
- rm -rf $BUILD_DIR
- mkdir -p $BUILD_DIR
- rm -rf $SRC_DIR
- mkdir -p $SRC_DIR
- cp -a . $SRC_DIR/
- cd $BUILD_DIR
- >-
cmake $SRC_DIR
-DCMAKE_INSTALL_PREFIX=$CMAKE_INSTALL_PREFIX
-DCMAKE_BUILD_TYPE=Release
-DUSE_NATIVE_ARCH=OFF
-DUSE_CCACHE=ON
-DENABLE_UNIT_TESTS=ON
-DCMAKE_OSX_DEPLOYMENT_TARGET=10.9
-DCMAKE_OSX_SYSROOT=/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk
- make -j5 install
test_mac:
<<: *mac
stage: test
script:
- cd $BUILD_DIR/netgen
- ctest . --output-on-failure
cleanup_mac:
<<: *mac
stage: cleanup
script:
- rm -rf $ROOT_DIR
when: always
allow_failure: true
############################################ ############################################
# Deploy stage # Deploy stage
@ -171,43 +183,3 @@ deploy_sourceforge:
- git push github master - git push github master
only: only:
- master - master
############################################
# Cleanup stage
############################################
linux_cleanup:
stage: cleanup
tags:
- linux
script:
# remove intermediate and old docker images and containers
- docker rm -f `docker ps --no-trunc -aq`
- docker images --no-trunc -aqf "dangling=true" | xargs docker rmi -f
when: always
allow_failure: true
win64_cleanup:
<<: *win64
stage: cleanup
tags:
- windows
- x64
script:
- cd %CI_PROJECT_DIR%
- rd /s /q %CI_DIR%
when: always
allow_failure: true
.win32_cleanup:
<<: *win32
stage: cleanup
tags:
- windows
- x86
script:
- cd %CI_PROJECT_DIR%
- rd /s /q %CI_DIR%
when: always
allow_failure: true

2
.gitmodules vendored
View File

@ -1,3 +1,3 @@
[submodule "external_dependencies/pybind11"] [submodule "external_dependencies/pybind11"]
path = external_dependencies/pybind11 path = external_dependencies/pybind11
url = https://github.com/pybind/pybind11.git url = https://github.com/ngsolve/pybind11.git

View File

@ -17,6 +17,8 @@ option( INTEL_MIC "cross compile for intel xeon phi")
option( INSTALL_PROFILES "install environment variable settings to /etc/profile.d" OFF ) option( INSTALL_PROFILES "install environment variable settings to /etc/profile.d" OFF )
option( USE_CCACHE "use ccache") option( USE_CCACHE "use ccache")
option( USE_INTERNAL_TCL "Compile tcl files into the code and don't install them" ON) option( USE_INTERNAL_TCL "Compile tcl files into the code and don't install them" ON)
option( ENABLE_UNIT_TESTS "Enable Catch unit tests")
option( ENABLE_CPP_CORE_GUIDELINES_CHECK "Enable cpp core guideline checks on ngcore" OFF)
option( USE_SUPERBUILD "use ccache" ON) option( USE_SUPERBUILD "use ccache" ON)
@ -341,8 +343,27 @@ execute_process(COMMAND hdiutil create -volname Netgen -srcfolder ${CMAKE_INSTAL
enable_testing() enable_testing()
include(CTest) include(CTest)
if(ENABLE_UNIT_TESTS)
include(${CMAKE_CURRENT_LIST_DIR}/cmake/external_projects/catch.cmake)
endif(ENABLE_UNIT_TESTS)
####################################################################### #######################################################################
if(ENABLE_CPP_CORE_GUIDELINES_CHECK)
find_program(
CLANG_TIDY_EXE
NAMES "clang-tidy"
DOC "Path to clang-tidy executable"
)
if(NOT CLANG_TIDY_EXE)
message(WARNING "clang-tidy not found.")
else()
message(STATUS "clang-tidy found: ${CLANG_TIDY_EXE}")
set(DO_CLANG_TIDY "${CLANG_TIDY_EXE}" "-header-filter=libsrc/core/")
endif()
endif(ENABLE_CPP_CORE_GUIDELINES_CHECK)
add_subdirectory(libsrc) add_subdirectory(libsrc)
add_subdirectory(ng) add_subdirectory(ng)
add_subdirectory(tutorials) add_subdirectory(tutorials)

View File

@ -121,6 +121,8 @@ set_vars( NETGEN_CMAKE_ARGS
CMAKE_SHARED_LINKER_FLAGS_RELEASE CMAKE_SHARED_LINKER_FLAGS_RELEASE
CMAKE_CXX_FLAGS CMAKE_CXX_FLAGS
CMAKE_CXX_FLAGS_RELEASE CMAKE_CXX_FLAGS_RELEASE
CMAKE_OSX_DEPLOYMENT_TARGET
CMAKE_OSX_SYSROOT
USE_GUI USE_GUI
USE_PYTHON USE_PYTHON
@ -138,6 +140,8 @@ set_vars( NETGEN_CMAKE_ARGS
INTEL_MIC INTEL_MIC
CMAKE_PREFIX_PATH CMAKE_PREFIX_PATH
CMAKE_INSTALL_PREFIX CMAKE_INSTALL_PREFIX
ENABLE_UNIT_TESTS
ENABLE_CPP_CORE_GUIDELINES_CHECK
) )
# propagate all variables set on the command line using cmake -DFOO=BAR # propagate all variables set on the command line using cmake -DFOO=BAR

View File

@ -0,0 +1,18 @@
include (ExternalProject)
find_program(GIT_EXECUTABLE git)
ExternalProject_Add(
project_catch
PREFIX ${CMAKE_BINARY_DIR}/catch
GIT_REPOSITORY https://github.com/catchorg/Catch2.git
GIT_TAG v2.0.1
TIMEOUT 10
UPDATE_COMMAND "" # ${GIT_EXECUTABLE} pull
CONFIGURE_COMMAND ""
BUILD_COMMAND ""
INSTALL_COMMAND ""
LOG_DOWNLOAD ON
)
# Expose required variable (CATCH_INCLUDE_DIR) to parent scope
ExternalProject_Get_Property(project_catch source_dir)
set(CATCH_INCLUDE_DIR ${source_dir}/single_include CACHE INTERNAL "Path to include folder for Catch")

View File

@ -3,8 +3,8 @@ set(METIS_DIR ${CMAKE_CURRENT_BINARY_DIR}/dependencies/metis)
ExternalProject_Add(project_metis ExternalProject_Add(project_metis
PREFIX ${CMAKE_CURRENT_BINARY_DIR}/dependencies PREFIX ${CMAKE_CURRENT_BINARY_DIR}/dependencies
URL "http://glaros.dtc.umn.edu/gkhome/fetch/sw/metis/metis-5.1.0.tar.gz" URL "http://ftp.mcs.anl.gov/pub/petsc/externalpackages/metis-5.1.0-p3.tar.gz"
URL_MD5 5465e67079419a69e0116de24fce58fe URL_MD5 09d2d771c63a2efb3499882688100088
DOWNLOAD_DIR ${CMAKE_CURRENT_SOURCE_DIR}/external_dependencies DOWNLOAD_DIR ${CMAKE_CURRENT_SOURCE_DIR}/external_dependencies
CMAKE_ARGS CMAKE_ARGS
-DGKLIB_PATH=${METIS_SRC_DIR}/GKlib -DGKLIB_PATH=${METIS_SRC_DIR}/GKlib

View File

@ -1,77 +1,61 @@
if(APPLE) if(APPLE)
# use system tcl/tk # use system tcl/tk
find_package(TCL 8.5 REQUIRED) if(${PYTHON_VERSION_STRING} STREQUAL "3.7")
# set(HOME $ENV{HOME}) # fetch tcl/tk sources to match the one used in Python 3.7
# set(tcl_prefix ${CMAKE_INSTALL_PREFIX}/../../) ExternalProject_Add(project_tcl
# ExternalProject_Add(project_tcl URL "https://prdownloads.sourceforge.net/tcl/tcl8.6.8-src.tar.gz"
# URL "http://sourceforge.net/projects/tcl/files/Tcl/8.6.4/tcl8.6.4-src.tar.gz" URL_MD5 81656d3367af032e0ae6157eff134f89
# URL_MD5 d7cbb91f1ded1919370a30edd1534304 DOWNLOAD_DIR ${CMAKE_CURRENT_SOURCE_DIR}/external_dependencies
# DOWNLOAD_DIR ${CMAKE_CURRENT_SOURCE_DIR}/external_dependencies UPDATE_COMMAND "" # Disable update
# UPDATE_COMMAND "" # Disable update CONFIGURE_COMMAND ""
# CONFIGURE_COMMAND ../project_tcl/macosx/configure --enable-threads --enable-framework --prefix=${tcl_prefix} --libdir=${tcl_prefix}/Contents/Frameworks --bindir=${tcl_prefix}/Contents/Frameworks/Tcl.framework/bin BUILD_COMMAND ""
# BUILD_COMMAND make -j4 binaries libraries INSTALL_COMMAND ""
# INSTALL_COMMAND make install-binaries install-headers install-libraries install-private-headers )
# LOG_DOWNLOAD 1 ExternalProject_Add(project_tk
# LOG_BUILD 1 URL "https://prdownloads.sourceforge.net/tcl/tk8.6.8-src.tar.gz"
# LOG_CONFIGURE 1 URL_MD5 5e0faecba458ee1386078fb228d008ba
# LOG_INSTALL 1 DOWNLOAD_DIR ${CMAKE_CURRENT_SOURCE_DIR}/external_dependencies
# ) UPDATE_COMMAND "" # Disable update
# CONFIGURE_COMMAND ""
# ExternalProject_Add(project_tk BUILD_COMMAND ""
# DEPENDS project_tcl INSTALL_COMMAND ""
# URL "http://sourceforge.net/projects/tcl/files/Tcl/8.6.4/tk8.6.4-src.tar.gz" )
# URL_MD5 261754d7dc2a582f00e35547777e1fea
# DOWNLOAD_DIR ${CMAKE_CURRENT_SOURCE_DIR}/external_dependencies
# UPDATE_COMMAND "" # Disable update
# CONFIGURE_COMMAND ../project_tk/macosx/configure --enable-aqua=yes --enable-threads --enable-framework --prefix=${tcl_prefix} --libdir=${tcl_prefix}/Contents/Frameworks --bindir=${tcl_prefix}/Contents/Frameworks/Tcl.framework/bin --with-tcl=${tcl_prefix}/Contents/Frameworks/Tcl.framework
# BUILD_COMMAND make -j4 binaries libraries
# INSTALL_COMMAND make install-binaries install-headers install-libraries install-private-headers
# LOG_DOWNLOAD 1
# LOG_BUILD 1
# LOG_CONFIGURE 1
# LOG_INSTALL 1
# )
#
# ExternalProject_Add(project_tkdnd
# URL "https://sourceforge.net/projects/tkdnd/files/OS%20X%20Binaries/TkDND%202.8/tkdnd2.8-OSX-MountainLion.tar.gz"
# URL_MD5 2dbb471b1d66c5f391f3c3c5b71548fb
# DOWNLOAD_DIR ${CMAKE_CURRENT_SOURCE_DIR}/external_dependencies
# BUILD_IN_SOURCE 1
# CONFIGURE_COMMAND ""
# BUILD_COMMAND ""
# INSTALL_COMMAND ${CMAKE_COMMAND} -E copy_directory . ${CMAKE_INSTALL_PREFIX}/../MacOS
# LOG_DOWNLOAD 1
# LOG_CONFIGURE 1
# LOG_BUILD 1
# LOG_INSTALL 1
# )
#
# list(APPEND NETGEN_DEPENDENCIES project_tcl project_tk project_tkdnd)
# list(APPEND CMAKE_PREFIX_PATH ${CMAKE_INSTALL_PREFIX}../Frameworks)
# set(TCL_INCLUDE_PATH ${CMAKE_INSTALL_PREFIX}/../Frameworks/Tcl.framework/Headers)
# set(TCL_LIBRARY ${CMAKE_INSTALL_PREFIX}/../Frameworks/Tcl.framework)
# set(TK_LIBRARY ${CMAKE_INSTALL_PREFIX}/../Frameworks/Tk.framework)
# set(TK_INCLUDE_PATH ${CMAKE_INSTALL_PREFIX}/../Frameworks/Tk.framework/Headers)
#
get_filename_component(PYTHON_LIB_DIR ${PYTHON_LIBRARY} DIRECTORY)
find_library(TCL_LIBRARY libtcl8.6.dylib PATHS ${PYTHON_LIB_DIR} NO_DEFAULT_PATH)
find_library(TK_LIBRARY libtk8.6.dylib PATHS ${PYTHON_LIB_DIR} NO_DEFAULT_PATH)
set(TCL_DIR ${CMAKE_CURRENT_BINARY_DIR}/dependencies/src/project_tcl)
set(TK_DIR ${CMAKE_CURRENT_BINARY_DIR}/dependencies/src/project_tk)
set(TCL_INCLUDE_PATH "${TCL_DIR}/generic;${TCL_DIR}/macosx")
set(TK_INCLUDE_PATH "${TK_DIR}/generic;${TK_DIR}/macosx;${TK_DIR}/xlib")
string(REPLACE ";" "$<SEMICOLON>" TCL_INC "${TCL_INCLUDE_PATH}")
string(REPLACE ";" "$<SEMICOLON>" TK_INC "${TK_INCLUDE_PATH}")
ExternalProject_Add(project_tkdnd ExternalProject_Add(project_tkdnd
URL "http://sourceforge.net/projects/tkdnd/files/TkDND/TkDND%202.8/tkdnd2.8-src.tar.gz" URL "http://sourceforge.net/projects/tkdnd/files/TkDND/TkDND%202.8/tkdnd2.8-src.tar.gz"
URL_MD5 a6d47a996ea957416469b12965d4db91 URL_MD5 a6d47a996ea957416469b12965d4db91
DEPENDS project_tcl project_tk
DOWNLOAD_DIR ${CMAKE_CURRENT_SOURCE_DIR}/external_dependencies DOWNLOAD_DIR ${CMAKE_CURRENT_SOURCE_DIR}/external_dependencies
PATCH_COMMAND patch -p1 < ${CMAKE_CURRENT_LIST_DIR}/tkdnd_macosx.patch PATCH_COMMAND patch < ${CMAKE_CURRENT_LIST_DIR}/tkdnd_macosx.patch
UPDATE_COMMAND "" # Disable update UPDATE_COMMAND "" # Disable update
BUILD_IN_SOURCE 1 BUILD_IN_SOURCE 1
CONFIGURE_COMMAND ./configure --prefix=${CMAKE_INSTALL_PREFIX}/Contents/MacOS --libdir=${CMAKE_INSTALL_PREFIX}/Contents/MacOS CMAKE_ARGS
BUILD_COMMAND make -DCMAKE_INSTALL_PREFIX=${CMAKE_INSTALL_PREFIX}/Contents/MacOS
INSTALL_COMMAND make install -DTCL_INCLUDE_PATH=${TCL_INC}
-DTK_INCLUDE_PATH=${TK_INC}
-DTK_LIBRARY=${TK_LIBRARY}
-DTCL_LIBRARY=${TCL_LIBRARY}
LOG_DOWNLOAD 1 LOG_DOWNLOAD 1
LOG_CONFIGURE 1 LOG_CONFIGURE 1
LOG_BUILD 1 LOG_BUILD 1
LOG_INSTALL 1 LOG_INSTALL 1
) )
list(APPEND NETGEN_DEPENDENCIES project_tkdnd) list(APPEND NETGEN_DEPENDENCIES project_tkdnd)
else()
find_package(TCL 8.5 REQUIRED)
endif()
elseif(WIN32) elseif(WIN32)

View File

@ -1,35 +1,55 @@
diff -Naur orig/tkdnd2.8/configure changed/tkdnd2.8/configure --- CMakeLists.txt 19:24:32.000000000 +0200
--- tkdnd2.8/configure 2015-05-13 19:24:32.000000000 +0200 +++ CMakeLists.txt 2018-12-05 11:34:59.000000000 +0100
+++ tkdnd2.8/configure 2016-02-22 15:26:37.000000000 +0100 @@ -43,17 +43,18 @@
@@ -6145,7 +6145,7 @@ ELSE ( WIN32 )
## Unix and OS X...
IF ( APPLE )
- SET ( CMAKE_OSX_ARCHITECTURES "x86_64;i386" )
+ SET ( CMAKE_OSX_ARCHITECTURES "x86_64")
+ SET( TK_DIR ${CMAKE_CURRENT_SOURCE_DIR}/../project_tk/)
+ SET( TCL_DIR ${CMAKE_CURRENT_SOURCE_DIR}/../project_tcl/)
FIND_LIBRARY ( COCOA_LIBRARY Cocoa )
INCLUDE_DIRECTORIES ( macosx )
- INCLUDE_DIRECTORIES ( /Library/Frameworks/Tk.framework/Versions/8.6/PrivateHeaders )
- INCLUDE_DIRECTORIES ( /System/Library/Frameworks/Tk.framework/Versions/8.5/Headers/tk-private )
- INCLUDE_DIRECTORIES ( /System/Library/Frameworks/Tk.framework/Versions/8.5/Headers/tk-private )
+ INCLUDE_DIRECTORIES ( ${TCL_DIR}/macosx ${TCL_DIR}/generic )
+ INCLUDE_DIRECTORIES ( ${TK_DIR}/macosx ${TK_DIR}/generic ${TK_DIR}/xlib )
ADD_DEFINITIONS ( -DMAC_TK_COCOA -DMAC_OSX_TK)
ADD_DEFINITIONS ( -DMAC_OSX_TK )
ADD_DEFINITIONS ( -std=gnu99 )
ADD_DEFINITIONS ( -x objective-c )
- ADD_DEFINITIONS ( -fobjc-gc )
+# ADD_DEFINITIONS ( -fobjc-gc )
ADD_DEFINITIONS ( -fno-objc-arc )
# ADD_DEFINITIONS ( -fobjc-arc )
LINK_LIBRARIES ( ${COCOA_LIBRARY} )
@@ -125,8 +126,8 @@
## Locate Tcl/Tk
## ===========================================================================
MESSAGE ( STATUS "Searching for Tcl/Tk..." )
-FIND_PACKAGE ( TCL REQUIRED )
-FIND_PACKAGE ( TclStub REQUIRED )
+#FIND_PACKAGE ( TCL REQUIRED )
+#FIND_PACKAGE ( TclStub REQUIRED )
## Tcl/Tk info (useful for debug purposes)...
# MESSAGE ( STATUS " TCL_TCLSH: " ${TCL_TCLSH} )
@@ -139,13 +140,13 @@
# MESSAGE ( STATUS " TK_LIBRARY: " ${TK_LIBRARY} )
## Enable Tcl/Tk stubs globally...
-ADD_DEFINITIONS ( -DUSE_TCL_STUBS )
-ADD_DEFINITIONS ( -DUSE_TK_STUBS )
+#ADD_DEFINITIONS ( -DUSE_TCL_STUBS )
+#ADD_DEFINITIONS ( -DUSE_TK_STUBS )
ADD_DEFINITIONS ( -DTCL_THREADS )
INCLUDE_DIRECTORIES ( ${TCL_INCLUDE_PATH} )
INCLUDE_DIRECTORIES ( ${TK_INCLUDE_PATH} )
-LINK_LIBRARIES ( ${TCL_STUB_LIBRARY} )
-LINK_LIBRARIES ( ${TK_STUB_LIBRARY} )
+LINK_LIBRARIES ( ${TCL_LIBRARY} )
+LINK_LIBRARIES ( ${TK_LIBRARY} )
- PKG_CFLAGS="$PKG_CFLAGS -DMAC_TK_COCOA -std=gnu99 -x objective-c -fobjc-gc" IF ( WIN32 AND NO_MSVCRT )
+ PKG_CFLAGS="$PKG_CFLAGS -DMAC_TK_COCOA -std=gnu99 -x objective-c" STRING ( REPLACE /MD /MT CMAKE_C_FLAGS_RELEASE ${CMAKE_C_FLAGS_RELEASE} )
diff -Naur orig/tkdnd2.8/configure.in changed/tkdnd2.8/configure.in
--- tkdnd2.8/configure.in 2015-05-13 19:24:32.000000000 +0200
+++ tkdnd2.8/configure.in 2016-02-22 15:26:44.000000000 +0100
@@ -126,7 +126,7 @@
if test "${TEA_WINDOWINGSYSTEM}" = "aqua"; then
TEA_ADD_SOURCES([macosx/macdnd.m])
- TEA_ADD_CFLAGS([-DMAC_TK_COCOA -std=gnu99 -x objective-c -fobjc-gc])
+ TEA_ADD_CFLAGS([-DMAC_TK_COCOA -std=gnu99 -x objective-c])
TEA_ADD_LIBS([-framework Cocoa -framework Carbon])
fi
diff -Naur orig/tkdnd2.8/macosx/macdnd.m changed/tkdnd2.8/macosx/macdnd.m
--- tkdnd2.8/macosx/macdnd.m 2015-07-06 21:49:14.000000000 +0200
+++ tkdnd2.8/macosx/macdnd.m 2016-02-22 15:27:04.000000000 +0100
@@ -16,6 +16,7 @@
#import <tcl.h>
#import <tk.h>
#import <tkInt.h>
+#undef panic
#import <tkMacOSXInt.h>
#import <Cocoa/Cocoa.h>

@ -1 +1 @@
Subproject commit 2a5a5ec0a47c245fbf1bb1a8a90b4c3278e01693 Subproject commit 2a150736601bb3113877bb673fb934bb60d46ec5

View File

@ -1,3 +1,4 @@
add_subdirectory(core)
add_subdirectory(general) add_subdirectory(general)
add_subdirectory(gprim) add_subdirectory(gprim)
add_subdirectory(linalg) add_subdirectory(linalg)

5
libsrc/core/.clang-tidy Normal file
View File

@ -0,0 +1,5 @@
Checks: '*,-clang-analyzer-alpha.*,-*braces-around-statements,-fuchsia-*,-google-runtime-references,-readability-implicit-bool-conversion,-google-explicit-constructor,-hicpp-explicit-conversions,-google-runtime-int,-llvm-header-guard'
CheckOptions:
- key: cppcoreguidelines-special-member-functions.AllowSoleDefaultDtor
value: 1
WarningsAsErrors: '*'

View File

@ -0,0 +1,16 @@
add_library(ngcore SHARED archive.cpp)
target_compile_definitions(ngcore PRIVATE -DNGCORE_EXPORTS)
install(TARGETS ngcore DESTINATION ${NG_INSTALL_DIR} COMPONENT netgen)
if(USE_PYTHON)
target_include_directories(ngcore PUBLIC ${PYTHON_INCLUDE_DIRS})
endif(USE_PYTHON)
install(FILES ngcore.hpp archive.hpp type_traits.hpp version.hpp ngcore_api.hpp
DESTINATION ${NG_INSTALL_DIR_INCLUDE}/core COMPONENT netgen_devel)
if(ENABLE_CPP_CORE_GUIDELINES_CHECK)
set_target_properties(ngcore PROPERTIES CXX_CLANG_TIDY "${DO_CLANG_TIDY}")
endif(ENABLE_CPP_CORE_GUIDELINES_CHECK)

52
libsrc/core/archive.cpp Normal file
View File

@ -0,0 +1,52 @@
#include "archive.hpp"
#ifndef WIN32
#include <cxxabi.h>
#endif
namespace ngcore
{
// clang-tidy should ignore this static object
static std::map<std::string, VersionInfo> library_versions; // NOLINT
std::map<std::string, VersionInfo>& Archive :: GetLibraryVersions()
{
return library_versions;
}
const VersionInfo& GetLibraryVersion(const std::string& library)
{ return library_versions[library]; }
void SetLibraryVersion(const std::string& library, const VersionInfo& version)
{ library_versions[library] = version; }
#ifdef WIN32
// windows does demangling in typeid(T).name()
std::string Demangle(const char* typeinfo) { return typeinfo; }
#else
std::string Demangle(const char* typeinfo) { int status; return abi::__cxa_demangle(typeinfo,
nullptr,
nullptr,
&status); }
#endif
// clang-tidy should ignore this static object
static std::unique_ptr<std::map<std::string, detail::ClassArchiveInfo>> type_register; // NOLINT
const detail::ClassArchiveInfo& Archive :: GetArchiveRegister(const std::string& classname)
{
if(type_register == nullptr) type_register =
std::make_unique<std::map<std::string, detail::ClassArchiveInfo>>();
return (*type_register)[classname];
}
void Archive :: SetArchiveRegister(const std::string& classname, const detail::ClassArchiveInfo& info)
{
if(type_register == nullptr) type_register =
std::make_unique<std::map<std::string, detail::ClassArchiveInfo>>();
(*type_register)[classname] = info;
}
bool Archive :: IsRegistered(const std::string& classname)
{
if(type_register == nullptr) type_register =
std::make_unique<std::map<std::string, detail::ClassArchiveInfo>>();
return type_register->count(classname) != 0;
}
} // namespace ngcore

869
libsrc/core/archive.hpp Normal file
View File

@ -0,0 +1,869 @@
#ifndef NETGEN_CORE_ARCHIVE_HPP
#define NETGEN_CORE_ARCHIVE_HPP
#include <complex> // for complex
#include <cstring> // for size_t, strlen
#include <fstream> // for operator<<, ifstream, ofstream, basic...
#include <functional> // for function
#include <map> // for map, _Rb_tree_iterator
#include <memory> // for __shared_ptr_access, __shared_ptr_acc...
#include <stdexcept> // for runtime_error
#include <string> // for string, operator+
#include <type_traits> // for declval, enable_if, false_type, is_co...
#include <typeinfo> // for type_info
#include <utility> // for move, swap, pair
#include <vector> // for vector
#include "ngcore_api.hpp" // for NGCORE_API, unlikely
#include "type_traits.hpp" // for all_of_tmpl
#include "version.hpp" // for VersionInfo
#ifdef NG_PYTHON
#include <pybind11/pybind11.h>
#endif // NG_PYTHON
namespace ngcore
{
// Libraries using this archive can store their version here to implement backwards compatibility
NGCORE_API const VersionInfo& GetLibraryVersion(const std::string& library);
NGCORE_API void SetLibraryVersion(const std::string& library, const VersionInfo& version);
NGCORE_API std::string Demangle(const char* typeinfo);
class NGCORE_API Archive;
namespace detail
{
// create new pointer of type T if it is default constructible, else throw
template<typename T, typename ...Rest>
T* constructIfPossible_impl(Rest... /*unused*/)
{ throw std::runtime_error(std::string(Demangle(typeid(T).name())) + " is not default constructible!"); }
template<typename T, typename= typename std::enable_if<std::is_constructible<T>::value>::type>
T* constructIfPossible_impl(int /*unused*/) { return new T; } // NOLINT
template<typename T>
T* constructIfPossible() { return constructIfPossible_impl<T>(int{}); }
//Type trait to check if a class implements a 'void DoArchive(Archive&)' function
template<typename T>
struct has_DoArchive
{
private:
template<typename T2>
static constexpr auto check(T2*) ->
typename std::is_same<decltype(std::declval<T2>().DoArchive(std::declval<Archive&>())),void>::type;
template<typename>
static constexpr std::false_type check(...);
using type = decltype(check<T>(nullptr)); // NOLINT
public:
NGCORE_API static constexpr bool value = type::value;
};
// Check if class is archivable
template<typename T>
struct is_Archivable_struct
{
private:
template<typename T2>
static constexpr auto check(T2*) ->
typename std::is_same<decltype(std::declval<Archive>() & std::declval<T2&>()),Archive&>::type;
template<typename>
static constexpr std::false_type check(...);
using type = decltype(check<T>(nullptr)); // NOLINT
public:
NGCORE_API static constexpr bool value = type::value;
};
struct ClassArchiveInfo
{
// create new object of this type and return a void* pointer that is points to the location
// of the (base)class given by type_info
std::function<void*(const std::type_info&)> creator;
// This caster takes a void* pointer to the type stored in this info and casts it to a
// void* pointer pointing to the (base)class type_info
std::function<void*(const std::type_info&, void*)> upcaster;
// This caster takes a void* pointer to the (base)class type_info and returns void* pointing
// to the type stored in this info
std::function<void*(const std::type_info&, void*)> downcaster;
};
} // namespace detail
template<typename T>
constexpr bool is_archivable = detail::is_Archivable_struct<T>::value;
// Base Archive class
class NGCORE_API Archive
{
const bool is_output;
// how many different shared_ptr/pointer have been (un)archived
int shared_ptr_count, ptr_count;
// maps for archived shared pointers and pointers
std::map<void*, int> shared_ptr2nr, ptr2nr;
// vectors for storing the unarchived (shared) pointers
std::vector<std::shared_ptr<void>> nr2shared_ptr;
std::vector<void*> nr2ptr;
protected:
bool shallow_to_python = false;
public:
Archive() = delete;
Archive(const Archive&) = delete;
Archive(Archive&&) = delete;
Archive (bool ais_output) :
is_output(ais_output), shared_ptr_count(0), ptr_count(0) { ; }
virtual ~Archive() { ; }
template<typename T>
Archive& Shallow(T& val)
{
static_assert(detail::is_any_pointer<T>, "ShallowArchive must be given pointer type!");
#ifdef NG_PYTHON
if(shallow_to_python)
{
if(is_output)
ShallowOutPython(pybind11::cast(val));
else
val = pybind11::cast<T>(ShallowInPython());
}
else
#endif // NG_PYTHON
*this & val;
return *this;
}
#ifdef NG_PYTHON
virtual void ShallowOutPython(pybind11::object /*unused*/) // NOLINT (copy by val is ok for this virt func)
{ throw std::runtime_error("Should not get in ShallowToPython base class implementation!"); }
virtual pybind11::object ShallowInPython()
{ throw std::runtime_error("Should not get in ShallowFromPython base class implementation!"); }
#endif // NG_PYTHON
Archive& operator=(const Archive&) = delete;
Archive& operator=(Archive&&) = delete;
bool Output () const { return is_output; }
bool Input () const { return !is_output; }
virtual const VersionInfo& GetVersion(const std::string& library)
{ return GetLibraryVersions()[library]; }
// Pure virtual functions that have to be implemented by In-/OutArchive
virtual Archive & operator & (double & d) = 0;
virtual Archive & operator & (int & i) = 0;
virtual Archive & operator & (long & i) = 0;
virtual Archive & operator & (size_t & i) = 0;
virtual Archive & operator & (short & i) = 0;
virtual Archive & operator & (unsigned char & i) = 0;
virtual Archive & operator & (bool & b) = 0;
virtual Archive & operator & (std::string & str) = 0;
virtual Archive & operator & (char *& str) = 0;
virtual Archive & operator & (VersionInfo & version)
{
if(Output())
(*this) << version.to_string();
else
{
std::string s;
(*this) & s;
version = VersionInfo(s);
}
return *this;
}
// Archive std classes ================================================
template<typename T>
Archive& operator & (std::complex<T>& c)
{
if(Output())
(*this) << c.real() << c.imag();
else
{
T tmp;
(*this) & tmp;
c.real(tmp);
(*this) & tmp;
c.imag(tmp);
}
return (*this);
}
template<typename T>
Archive& operator & (std::vector<T>& v)
{
size_t size;
if(Output())
size = v.size();
(*this) & size;
if(Input())
v.resize(size);
Do(&v[0], size);
return (*this);
}
template<typename T1, typename T2>
Archive& operator& (std::map<T1, T2>& map)
{
if(Output())
{
(*this) << size_t(map.size());
for(auto& pair : map)
(*this) << pair.first << pair.second;
}
else
{
size_t size = 0;
(*this) & size;
T1 key; T2 val;
for(size_t i = 0; i < size; i++)
{
T1 key; T2 val;
(*this) & key & val;
map[key] = val;
}
}
return (*this);
}
// Archive arrays =====================================================
// this functions can be overloaded in Archive implementations for more efficiency
template <typename T, typename = typename std::enable_if<is_archivable<T>>::type>
Archive & Do (T * data, size_t n)
{ for (size_t j = 0; j < n; j++) { (*this) & data[j]; }; return *this; }; // NOLINT
virtual Archive & Do (double * d, size_t n)
{ for (size_t j = 0; j < n; j++) { (*this) & d[j]; }; return *this; }; // NOLINT
virtual Archive & Do (int * i, size_t n)
{ for (size_t j = 0; j < n; j++) { (*this) & i[j]; }; return *this; }; // NOLINT
virtual Archive & Do (long * i, size_t n)
{ for (size_t j = 0; j < n; j++) { (*this) & i[j]; }; return *this; }; // NOLINT
virtual Archive & Do (size_t * i, size_t n)
{ for (size_t j = 0; j < n; j++) { (*this) & i[j]; }; return *this; }; // NOLINT
virtual Archive & Do (short * i, size_t n)
{ for (size_t j = 0; j < n; j++) { (*this) & i[j]; }; return *this; }; // NOLINT
virtual Archive & Do (unsigned char * i, size_t n)
{ for (size_t j = 0; j < n; j++) { (*this) & i[j]; }; return *this; }; // NOLINT
virtual Archive & Do (bool * b, size_t n)
{ for (size_t j = 0; j < n; j++) { (*this) & b[j]; }; return *this; }; // NOLINT
// Archive a class implementing a (void DoArchive(Archive&)) method =======
template<typename T, typename=std::enable_if_t<detail::has_DoArchive<T>::value>>
Archive& operator & (T& val)
{
val.DoArchive(*this); return *this;
}
// Archive shared_ptrs =================================================
template <typename T>
Archive& operator & (std::shared_ptr<T>& ptr)
{
if(Output())
{
// save -2 for nullptr
if(!ptr)
return (*this) << -2;
void* reg_ptr = ptr.get();
bool neededDowncast = false;
// Downcasting is only possible for our registered classes
if(typeid(T) != typeid(*ptr))
{
if(!IsRegistered(Demangle(typeid(*ptr).name())))
throw std::runtime_error(std::string("Archive error: Polymorphic type ")
+ Demangle(typeid(*ptr).name())
+ " not registered for archive");
reg_ptr = GetArchiveRegister(Demangle(typeid(*ptr).name())).downcaster(typeid(T), ptr.get());
// if there was a true downcast we have to store more information
if(reg_ptr != static_cast<void*>(ptr.get()) )
neededDowncast = true;
}
auto pos = shared_ptr2nr.find(reg_ptr);
// if not found store -1 and the pointer
if(pos == shared_ptr2nr.end())
{
auto p = ptr.get();
(*this) << -1;
(*this) & neededDowncast & p;
// if we did downcast we store the true type as well
if(neededDowncast)
(*this) << Demangle(typeid(*ptr).name());
shared_ptr2nr[reg_ptr] = shared_ptr_count++;
return *this;
}
// if found store the position and if it has to be downcasted and how
(*this) << pos->second << neededDowncast;
if(neededDowncast)
(*this) << Demangle(typeid(*ptr).name());
}
else // Input
{
int nr;
(*this) & nr;
// -2 restores a nullptr
if(nr == -2)
{
ptr = nullptr;
return *this;
}
// -1 restores a new shared ptr by restoring the inner pointer and creating a shared_ptr to it
if (nr == -1)
{
T* p = nullptr;
bool neededDowncast;
(*this) & neededDowncast & p;
ptr = std::shared_ptr<T>(p);
// if we did downcast we need to store a shared_ptr<void> to the true object
if(neededDowncast)
{
std::string name;
(*this) & name;
auto info = GetArchiveRegister(name);
// for this we use an aliasing constructor to create a shared pointer sharing lifetime
// with our shared ptr, but pointing to the true object
nr2shared_ptr.push_back(std::shared_ptr<void>(std::static_pointer_cast<void>(ptr),
info.downcaster(typeid(T),
ptr.get())));
}
else
nr2shared_ptr.push_back(ptr);
}
else
{
auto other = nr2shared_ptr[nr];
bool neededDowncast;
(*this) & neededDowncast;
if(neededDowncast)
{
// if there was a downcast we can expect the class to be registered (since archiving
// wouldn't have worked else)
std::string name;
(*this) & name;
auto info = GetArchiveRegister(name);
// same trick as above, create a shared ptr sharing lifetime with
// the shared_ptr<void> in the register, but pointing to our object
ptr = std::static_pointer_cast<T>(std::shared_ptr<void>(other,
info.upcaster(typeid(T),
other.get())));
}
else
ptr = std::static_pointer_cast<T>(other);
}
}
return *this;
}
// Archive pointers =======================================================
template <typename T>
Archive & operator& (T *& p)
{
if (Output())
{
// if the pointer is null store -2
if (!p)
return (*this) << -2;
auto reg_ptr = static_cast<void*>(p);
if(typeid(T) != typeid(*p))
{
if(!IsRegistered(Demangle(typeid(*p).name())))
throw std::runtime_error(std::string("Archive error: Polymorphic type ")
+ Demangle(typeid(*p).name())
+ " not registered for archive");
reg_ptr = GetArchiveRegister(Demangle(typeid(*p).name())).downcaster(typeid(T), static_cast<void*>(p));
}
auto pos = ptr2nr.find(reg_ptr);
// if the pointer is not found in the map create a new entry
if (pos == ptr2nr.end())
{
ptr2nr[reg_ptr] = ptr_count++;
if(typeid(*p) == typeid(T))
if (std::is_constructible<T>::value)
{
return (*this) << -1 & (*p);
}
else
throw std::runtime_error(std::string("Archive error: Class ") +
Demangle(typeid(*p).name()) + " does not provide a default constructor!");
else
{
// if a pointer to a base class is archived, the class hierarchy must be registered
// to avoid compile time issues we allow this behaviour only for "our" classes that
// implement a void DoArchive(Archive&) member function
// To recreate the object we need to store the true type of it
if(!IsRegistered(Demangle(typeid(*p).name())))
throw std::runtime_error(std::string("Archive error: Polymorphic type ")
+ Demangle(typeid(*p).name())
+ " not registered for archive");
return (*this) << -3 << Demangle(typeid(*p).name()) & (*p);
}
}
else
{
(*this) & pos->second;
bool downcasted = !(reg_ptr == static_cast<void*>(p) );
// store if the class has been downcasted and the name
(*this) << downcasted << Demangle(typeid(*p).name());
}
}
else
{
int nr;
(*this) & nr;
if (nr == -2) // restore a nullptr
p = nullptr;
else if (nr == -1) // create a new pointer of standard type (no virtual or multiple inheritance,...)
{
p = detail::constructIfPossible<T>();
nr2ptr.push_back(p);
(*this) & *p;
}
else if(nr == -3) // restore one of our registered classes that can have multiple inheritance,...
{
// As stated above, we want this special behaviour only for our classes that implement DoArchive
std::string name;
(*this) & name;
auto info = GetArchiveRegister(name);
// the creator creates a new object of type name, and returns a void* pointing
// to T (which may have an offset)
p = static_cast<T*>(info.creator(typeid(T)));
// we store the downcasted pointer (to be able to find it again from
// another class in a multiple inheritance tree)
nr2ptr.push_back(info.downcaster(typeid(T),p));
(*this) & *p;
}
else
{
bool downcasted;
std::string name;
(*this) & downcasted & name;
if(downcasted)
{
// if the class has been downcasted we can assume it is in the register
auto info = GetArchiveRegister(name);
p = static_cast<T*>(info.upcaster(typeid(T), nr2ptr[nr]));
}
else
p = static_cast<T*>(nr2ptr[nr]);
}
}
return *this;
}
// const ptr
template<typename T>
Archive& operator &(const T*& t)
{
return (*this) & const_cast<T*&>(t); // NOLINT
}
// Write a read only variable
template <typename T>
Archive & operator << (const T & t)
{
T ht(t);
(*this) & ht;
return *this;
}
virtual void FlushBuffer() {}
protected:
static std::map<std::string, VersionInfo>& GetLibraryVersions();
private:
template<typename T, typename ... Bases>
friend class RegisterClassForArchive;
// Returns ClassArchiveInfo of Demangled typeid
static const detail::ClassArchiveInfo& GetArchiveRegister(const std::string& classname);
// Set ClassArchiveInfo for Demangled typeid, this is done by creating an instance of
// RegisterClassForArchive<type, bases...>
static void SetArchiveRegister(const std::string& classname, const detail::ClassArchiveInfo& info);
static bool IsRegistered(const std::string& classname);
// Helper class for up-/downcasting
template<typename T, typename ... Bases>
struct Caster{};
template<typename T>
struct Caster<T>
{
static void* tryUpcast (const std::type_info& /*unused*/, T* /*unused*/)
{
throw std::runtime_error("Upcast not successful, some classes are not registered properly for archiving!");
}
static void* tryDowncast (const std::type_info& /*unused*/, void* /*unused*/)
{
throw std::runtime_error("Downcast not successful, some classes are not registered properly for archiving!");
}
};
template<typename T, typename B1, typename ... Brest>
struct Caster<T,B1,Brest...>
{
static void* tryUpcast(const std::type_info& ti, T* p)
{
try
{ return GetArchiveRegister(Demangle(typeid(B1).name())).
upcaster(ti, static_cast<void*>(dynamic_cast<B1*>(p))); }
catch(std::exception&)
{ return Caster<T, Brest...>::tryUpcast(ti, p); }
}
static void* tryDowncast(const std::type_info& ti, void* p)
{
if(typeid(B1) == ti)
return dynamic_cast<T*>(static_cast<B1*>(p));
try
{
return dynamic_cast<T*>(static_cast<B1*>(GetArchiveRegister(Demangle(typeid(B1).name())).
downcaster(ti, p)));
}
catch(std::exception&)
{
return Caster<T, Brest...>::tryDowncast(ti, p);
}
}
};
};
template<typename T, typename ... Bases>
class RegisterClassForArchive
{
public:
RegisterClassForArchive()
{
static_assert(detail::all_of_tmpl<std::is_base_of<Bases,T>::value...>,
"Variadic template arguments must be base classes of T");
detail::ClassArchiveInfo info;
info.creator = [this,&info](const std::type_info& ti) -> void*
{ return typeid(T) == ti ? detail::constructIfPossible<T>()
: Archive::Caster<T, Bases...>::tryUpcast(ti, detail::constructIfPossible<T>()); };
info.upcaster = [this](const std::type_info& ti, void* p) -> void*
{ return typeid(T) == ti ? p : Archive::Caster<T, Bases...>::tryUpcast(ti, static_cast<T*>(p)); };
info.downcaster = [this](const std::type_info& ti, void* p) -> void*
{ return typeid(T) == ti ? p : Archive::Caster<T, Bases...>::tryDowncast(ti, p); };
Archive::SetArchiveRegister(std::string(Demangle(typeid(T).name())),info);
}
};
// BinaryOutArchive ======================================================================
class NGCORE_API BinaryOutArchive : public Archive
{
static constexpr size_t BUFFERSIZE = 1024;
char buffer[BUFFERSIZE] = {};
size_t ptr = 0;
protected:
std::shared_ptr<std::ostream> stream;
public:
BinaryOutArchive() = delete;
BinaryOutArchive(const BinaryOutArchive&) = delete;
BinaryOutArchive(BinaryOutArchive&&) = delete;
BinaryOutArchive(std::shared_ptr<std::ostream>&& astream)
: Archive(true), stream(std::move(astream))
{ }
BinaryOutArchive(const std::string& filename)
: BinaryOutArchive(std::make_shared<std::ofstream>(filename)) {}
~BinaryOutArchive () override { FlushBuffer(); }
BinaryOutArchive& operator=(const BinaryOutArchive&) = delete;
BinaryOutArchive& operator=(BinaryOutArchive&&) = delete;
using Archive::operator&;
Archive & operator & (double & d) override
{ return Write(d); }
Archive & operator & (int & i) override
{ return Write(i); }
Archive & operator & (short & i) override
{ return Write(i); }
Archive & operator & (long & i) override
{ return Write(i); }
Archive & operator & (size_t & i) override
{ return Write(i); }
Archive & operator & (unsigned char & i) override
{ return Write(i); }
Archive & operator & (bool & b) override
{ return Write(b); }
Archive & operator & (std::string & str) override
{
int len = str.length();
(*this) & len;
FlushBuffer();
if(len)
stream->write (&str[0], len);
return *this;
}
Archive & operator & (char *& str) override
{
long len = str ? strlen (str) : -1;
(*this) & len;
FlushBuffer();
if(len > 0)
stream->write (&str[0], len); // NOLINT
return *this;
}
void FlushBuffer() override
{
if (ptr > 0)
{
stream->write(&buffer[0], ptr);
ptr = 0;
}
}
private:
template <typename T>
Archive & Write (T x)
{
if (unlikely(ptr > BUFFERSIZE-sizeof(T)))
{
stream->write(&buffer[0], ptr);
*reinterpret_cast<T*>(&buffer[0]) = x; // NOLINT
ptr = sizeof(T);
return *this;
}
*reinterpret_cast<T*>(&buffer[ptr]) = x; // NOLINT
ptr += sizeof(T);
return *this;
}
};
// BinaryInArchive ======================================================================
class NGCORE_API BinaryInArchive : public Archive
{
protected:
std::shared_ptr<std::istream> stream;
public:
BinaryInArchive (std::shared_ptr<std::istream>&& astream)
: Archive(false), stream(std::move(astream))
{ }
BinaryInArchive (const std::string& filename)
: BinaryInArchive(std::make_shared<std::ifstream>(filename)) { ; }
using Archive::operator&;
Archive & operator & (double & d) override
{ Read(d); return *this; }
Archive & operator & (int & i) override
{ Read(i); return *this; }
Archive & operator & (short & i) override
{ Read(i); return *this; }
Archive & operator & (long & i) override
{ Read(i); return *this; }
Archive & operator & (size_t & i) override
{ Read(i); return *this; }
Archive & operator & (unsigned char & i) override
{ Read(i); return *this; }
Archive & operator & (bool & b) override
{ Read(b); return *this; }
Archive & operator & (std::string & str) override
{
int len;
(*this) & len;
str.resize(len);
if(len)
stream->read(&str[0], len); // NOLINT
return *this;
}
Archive & operator & (char *& str) override
{
long len;
(*this) & len;
if(len == -1)
str = nullptr;
else
{
str = new char[len+1]; // NOLINT
stream->read(&str[0], len); // NOLINT
str[len] = '\0'; // NOLINT
}
return *this;
}
Archive & Do (double * d, size_t n) override
{ stream->read(reinterpret_cast<char*>(d), n*sizeof(double)); return *this; } // NOLINT
Archive & Do (int * i, size_t n) override
{ stream->read(reinterpret_cast<char*>(i), n*sizeof(int)); return *this; } // NOLINT
Archive & Do (size_t * i, size_t n) override
{ stream->read(reinterpret_cast<char*>(i), n*sizeof(size_t)); return *this; } // NOLINT
private:
template<typename T>
inline void Read(T& val)
{ stream->read(reinterpret_cast<char*>(&val), sizeof(T)); } // NOLINT
};
// TextOutArchive ======================================================================
class NGCORE_API TextOutArchive : public Archive
{
protected:
std::shared_ptr<std::ostream> stream;
public:
TextOutArchive (std::shared_ptr<std::ostream>&& astream)
: Archive(true), stream(std::move(astream))
{ }
TextOutArchive (const std::string& filename) :
TextOutArchive(std::make_shared<std::ofstream>(filename)) { }
using Archive::operator&;
Archive & operator & (double & d) override
{ *stream << d << '\n'; return *this; }
Archive & operator & (int & i) override
{ *stream << i << '\n'; return *this; }
Archive & operator & (short & i) override
{ *stream << i << '\n'; return *this; }
Archive & operator & (long & i) override
{ *stream << i << '\n'; return *this; }
Archive & operator & (size_t & i) override
{ *stream << i << '\n'; return *this; }
Archive & operator & (unsigned char & i) override
{ *stream << int(i) << '\n'; return *this; }
Archive & operator & (bool & b) override
{ *stream << (b ? 't' : 'f') << '\n'; return *this; }
Archive & operator & (std::string & str) override
{
int len = str.length();
*stream << len << '\n';
if(len)
{
stream->write(&str[0], len); // NOLINT
*stream << '\n';
}
return *this;
}
Archive & operator & (char *& str) override
{
long len = str ? strlen (str) : -1;
*this & len;
if(len > 0)
{
stream->write (&str[0], len); // NOLINT
*stream << '\n';
}
return *this;
}
};
// TextInArchive ======================================================================
class NGCORE_API TextInArchive : public Archive
{
protected:
std::shared_ptr<std::istream> stream;
public:
TextInArchive (std::shared_ptr<std::istream>&& astream) :
Archive(false), stream(std::move(astream))
{ }
TextInArchive (const std::string& filename)
: TextInArchive(std::make_shared<std::ifstream>(filename)) {}
using Archive::operator&;
Archive & operator & (double & d) override
{ *stream >> d; return *this; }
Archive & operator & (int & i) override
{ *stream >> i; return *this; }
Archive & operator & (short & i) override
{ *stream >> i; return *this; }
Archive & operator & (long & i) override
{ *stream >> i; return *this; }
Archive & operator & (size_t & i) override
{ *stream >> i; return *this; }
Archive & operator & (unsigned char & i) override
{ int _i; *stream >> _i; i = _i; return *this; }
Archive & operator & (bool & b) override
{ char c; *stream >> c; b = (c=='t'); return *this; }
Archive & operator & (std::string & str) override
{
int len;
*stream >> len;
char ch;
stream->get(ch); // '\n'
str.resize(len);
if(len)
stream->get(&str[0], len+1, '\0');
return *this;
}
Archive & operator & (char *& str) override
{
long len;
(*this) & len;
char ch;
if(len == -1)
{
str = nullptr;
return (*this);
}
str = new char[len+1]; // NOLINT
if(len)
{
stream->get(ch); // \n
stream->get(&str[0], len+1, '\0'); // NOLINT
}
str[len] = '\0'; // NOLINT
return *this;
}
};
#ifdef NG_PYTHON
template<typename ARCHIVE>
class PyArchive : public ARCHIVE
{
private:
pybind11::list lst;
size_t index = 0;
using ARCHIVE::stream;
public:
PyArchive(const pybind11::object& alst = pybind11::none()) :
ARCHIVE(std::make_shared<std::stringstream>()),
lst(alst.is_none() ? pybind11::list() : pybind11::cast<pybind11::list>(alst))
{
ARCHIVE::shallow_to_python = true;
if(Input())
stream = std::make_shared<std::stringstream>
(pybind11::cast<pybind11::bytes>(lst[pybind11::len(lst)-1]));
}
using ARCHIVE::Output;
using ARCHIVE::Input;
using ARCHIVE::FlushBuffer;
using ARCHIVE::operator&;
using ARCHIVE::operator<<;
using ARCHIVE::GetVersion;
void ShallowOutPython(pybind11::object val) override { lst.append(val); }
pybind11::object ShallowInPython() override { return lst[index++]; }
pybind11::list WriteOut()
{
FlushBuffer();
lst.append(pybind11::bytes(std::static_pointer_cast<std::stringstream>(stream)->str()));
return lst;
}
};
template<typename T, typename T_ARCHIVE_OUT=BinaryOutArchive, typename T_ARCHIVE_IN=BinaryInArchive>
auto NGSPickle(bool printoutput=false)
{
return pybind11::pickle([printoutput](T* self)
{
PyArchive<T_ARCHIVE_OUT> ar;
ar & self;
auto output = pybind11::make_tuple(ar.WriteOut());
if(printoutput)
pybind11::print("pickle output of", Demangle(typeid(T).name()),"=", output);
return output;
},
[](pybind11::tuple state)
{
T* val = nullptr;
PyArchive<T_ARCHIVE_IN> ar(state[0]);
ar & val;
return val;
});
}
#endif // NG_PYTHON
} // namespace ngcore
#endif // NETGEN_CORE_ARCHIVE_HPP

7
libsrc/core/ngcore.hpp Normal file
View File

@ -0,0 +1,7 @@
#ifndef NETGEN_CORE_NGCORE_HPP
#define NETGEN_CORE_NGCORE_HPP
#include "archive.hpp"
#include "version.hpp"
#endif // NETGEN_CORE_NGCORE_HPP

View File

@ -0,0 +1,29 @@
#ifndef NETGEN_CORE_NGCORE_API_HPP
#define NETGEN_CORE_NGCORE_API_HPP
#ifdef WIN32
#define NGCORE_API_EXPORT __declspec(dllexport)
#define NGCORE_API_IMPORT __declspec(dllimport)
#else
#define NGCORE_API_EXPORT
#define NGCORE_API_IMPORT
#endif
#ifdef NGCORE_EXPORTS
#define NGCORE_API NGCORE_API_EXPORT
#else
#define NGCORE_API NGCORE_API_IMPORT
#endif
namespace ngcore
{
#if defined(__GNUC__)
inline bool likely (bool x) { return bool(__builtin_expect(long(x), 1L)); }
inline bool unlikely (bool x) { return bool(__builtin_expect(long(x), 0L)); }
#else
inline bool likely (bool x) { return x; }
inline bool unlikely (bool x) { return x; }
#endif
} // namespace ngcore
#endif // NETGEN_CORE_NGCORE_API_HPP

View File

@ -0,0 +1,33 @@
#ifndef NETGEN_CORE_TYPE_TRAITS_HPP
#define NETGEN_CORE_TYPE_TRAITS_HPP
#include <memory>
#include <type_traits>
namespace ngcore
{
namespace detail
{
template<bool... b> struct _BoolArray{};
template<bool ... vals>
constexpr bool all_of_tmpl = std::is_same<_BoolArray<vals...>, _BoolArray<(vals || true)...>>::value; // NOLINT
template<typename T>
struct is_any_pointer_impl : std::false_type {};
template<typename T>
struct is_any_pointer_impl<T*> : std::true_type {};
template<typename T>
struct is_any_pointer_impl<std::shared_ptr<T>> : std::true_type {};
template<typename T>
struct is_any_pointer_impl<std::unique_ptr<T>> : std::true_type {};
template<typename T>
constexpr bool is_any_pointer = is_any_pointer_impl<T>::value;
} // namespace detail
} // namespace ngcore
#endif // NETGEN_CORE_TYPE_TRAITS_HPP

88
libsrc/core/version.hpp Normal file
View File

@ -0,0 +1,88 @@
#ifndef NETGEN_CORE_VERSION_HPP
#define NETGEN_CORE_VERSION_HPP
#include <string>
#include <tuple>
#include "ngcore_api.hpp"
namespace ngcore
{
class VersionInfo
{
private:
size_t mayor_{}, minor_{}, release{}, patch{};
std::string git_hash{};
public:
VersionInfo() = default;
VersionInfo(std::string vstring)
{
minor_ = release = patch = 0;
git_hash = "";
if(vstring.substr(0,1) == "v")
vstring = vstring.substr(1,vstring.size()-1);
auto dot = vstring.find('.');
mayor_ = std::stoi(vstring.substr(0,dot));
if(dot == size_t(-1)) vstring = "";
else vstring = vstring.substr(dot+1, vstring.size()-dot-1);
if(!vstring.empty())
{
dot = vstring.find('.');
minor_ = std::stoi(vstring.substr(0,dot));
if (dot == size_t(-1)) vstring = "";
else vstring = vstring.substr(dot+1, vstring.size()-dot-1);
if(!vstring.empty())
{
dot = vstring.find('-');
release = std::stoi(vstring.substr(0,dot));
if(dot == size_t(-1)) vstring = "";
else vstring = vstring.substr(dot+1,vstring.size()-dot-1);
if(!vstring.empty())
{
dot = vstring.find('-');
patch = std::stoi(vstring.substr(0,dot));
if(dot == size_t(-1)) vstring = "";
else vstring = vstring.substr(dot+1, vstring.size()-dot-1);
if(!vstring.empty())
git_hash = vstring;
}
}
}
}
VersionInfo(const char* cstr) : VersionInfo(std::string(cstr)) { }
std::string to_string() const
{ std::string vstring = "v" + std::to_string(mayor_);
if(minor_ || release || patch || !git_hash.empty())
{
vstring += "." + std::to_string(minor_);
if(release || patch || !git_hash.empty())
{
vstring += "." + std::to_string(release);
if(patch || !git_hash.empty())
{
vstring += "-" + std::to_string(patch);
if(!git_hash.empty())
vstring += "-" + git_hash;
}
}
}
return vstring;
}
bool operator <(const VersionInfo& other) const
{
return std::tie(mayor_, minor_, release, patch) <
std::tie(other.mayor_, other.minor_, other.release, other.patch);
}
bool operator ==(const VersionInfo& other) const
{
return mayor_ == other.mayor_ && minor_ == other.minor_ && release == other.release
&& patch == other.patch;
}
bool operator >(const VersionInfo& other) const { return other < (*this); }
bool operator <=(const VersionInfo& other) const { return !((*this) > other); }
bool operator >=(const VersionInfo& other) const { return !((*this) < other); }
};
} // namespace ngcore
#endif // NETGEN_CORE_VERSION_HPP

View File

@ -557,7 +557,8 @@ namespace netgen
Point<3> Sphere :: GetSurfacePoint () const Point<3> Sphere :: GetSurfacePoint () const
{ {
return c + Vec<3> (r, 0, 0); // if two spheres touch at exactly that point meshing fails.
return c + r * Vec<3> (0.12345, 0.54321, 0.8304715488203073);
} }
@ -1235,7 +1236,15 @@ namespace netgen
return max2(bb/(aa*aa),aa/(bb*bb)); return max2(bb/(aa*aa),aa/(bb*bb));
} }
int EllipticCylinder :: IsIdentic(const Surface& s2, int& inv, double eps) const
{
const EllipticCylinder* ps2 = dynamic_cast<const EllipticCylinder*>(&s2);
if (!ps2) return 0;
if((vl - ps2->vl).Length() > eps || (vs - ps2->vs).Length() > eps || (a-ps2->a).Length() > eps)
return 0;
return 1;
}
Point<3> EllipticCylinder :: GetSurfacePoint () const Point<3> EllipticCylinder :: GetSurfacePoint () const
{ {
@ -1940,6 +1949,13 @@ void EllipticCone :: GetTriangleApproximation
<< R << " " << r << endl; << R << " " << r << endl;
} }
RegisterClassForArchive<QuadraticSurface, OneSurfacePrimitive> regqs;
RegisterClassForArchive<Plane, QuadraticSurface> regpl;
RegisterClassForArchive<Sphere, QuadraticSurface> regsph;
RegisterClassForArchive<Cylinder, QuadraticSurface> regcyl;
RegisterClassForArchive<EllipticCylinder, QuadraticSurface> regelcyl;
RegisterClassForArchive<Ellipsoid, QuadraticSurface> regell;
RegisterClassForArchive<Cone, QuadraticSurface> regcone;
RegisterClassForArchive<EllipticCone, QuadraticSurface> regellcone;
RegisterClassForArchive<Torus, OneSurfacePrimitive> regtorus;
} }

View File

@ -47,6 +47,11 @@ namespace netgen
virtual void Print (ostream & str) const; virtual void Print (ostream & str) const;
virtual void Read (istream & ist); virtual void Read (istream & ist);
void PrintCoeff (ostream & ost) const; void PrintCoeff (ostream & ost) const;
virtual void DoArchive(Archive& ar)
{
OneSurfacePrimitive::DoArchive(ar);
ar & cxx & cyy & czz & cxy & cxz & cyz & cx & cy & cz & c1;
}
}; };
@ -64,6 +69,14 @@ namespace netgen
public: public:
/// ///
Plane (const Point<3> & ap, Vec<3> an); Plane (const Point<3> & ap, Vec<3> an);
// default constructor for archive
Plane() {}
virtual void DoArchive(Archive& ar)
{
QuadraticSurface::DoArchive(ar);
ar & p & n & eps_base;
}
Point<3> P() const { return p; } Point<3> P() const { return p; }
Vec<3> N() const { return n; } Vec<3> N() const { return n; }
virtual void GetPrimitiveData (const char *& classname, virtual void GetPrimitiveData (const char *& classname,
@ -130,6 +143,14 @@ namespace netgen
public: public:
/// ///
Sphere (const Point<3> & ac, double ar); Sphere (const Point<3> & ac, double ar);
// default constructor for archive
Sphere() {}
virtual void DoArchive(Archive& ar)
{
QuadraticSurface::DoArchive(ar);
ar & c & r & invr;
}
virtual void GetPrimitiveData (const char *& classname, virtual void GetPrimitiveData (const char *& classname,
Array<double> & coeffs) const; Array<double> & coeffs) const;
@ -188,6 +209,14 @@ namespace netgen
public: public:
Cylinder (const Point<3> & aa, const Point<3> & ab, double ar); Cylinder (const Point<3> & aa, const Point<3> & ab, double ar);
Cylinder (Array<double> & coeffs); Cylinder (Array<double> & coeffs);
// default constructor for archive
Cylinder() {}
virtual void DoArchive(Archive& ar)
{
QuadraticSurface::DoArchive(ar);
ar & a & b & r & vab;
}
Point<3> A() const { return a; } Point<3> A() const { return a; }
Point<3> B() const { return b; } Point<3> B() const { return b; }
double R() const { return r; } double R() const { return r; }
@ -250,7 +279,14 @@ namespace netgen
EllipticCylinder (const Point<3> & aa, EllipticCylinder (const Point<3> & aa,
const Vec<3> & avl, const Vec<3> & avs); const Vec<3> & avl, const Vec<3> & avs);
EllipticCylinder (Array<double> & coeffs); EllipticCylinder (Array<double> & coeffs);
// default constructor for archive
EllipticCylinder() {}
virtual void DoArchive(Archive& ar)
{
QuadraticSurface::DoArchive(ar);
ar & a & vl & vs & vab & t0vec & t1vec & vabl & t0 & t1;
}
// static Primitive * CreateDefault (); // static Primitive * CreateDefault ();
virtual void GetPrimitiveData (const char *& classname, Array<double> & coeffs) const; virtual void GetPrimitiveData (const char *& classname, Array<double> & coeffs) const;
@ -267,6 +303,7 @@ namespace netgen
const Box<3> & bbox, const Box<3> & bbox,
double facets) const; double facets) const;
virtual int IsIdentic (const Surface & s2, int & inv, double eps) const;
virtual double MaxCurvature () const; virtual double MaxCurvature () const;
@ -299,6 +336,14 @@ namespace netgen
const Vec<3> & av1, const Vec<3> & av1,
const Vec<3> & av2, const Vec<3> & av2,
const Vec<3> & av3); const Vec<3> & av3);
// default constructor for archive
Ellipsoid() {}
virtual void DoArchive(Archive& ar)
{
QuadraticSurface::DoArchive(ar);
ar & a & v1 & v2 & v3 & rmin;
}
/// ///
virtual INSOLID_TYPE BoxInSolid (const BoxSphere<3> & box) const; virtual INSOLID_TYPE BoxInSolid (const BoxSphere<3> & box) const;
/// ///
@ -339,6 +384,14 @@ namespace netgen
/// ///
Cone (const Point<3> & aa, const Point<3> & ab, double ara, double arb); Cone (const Point<3> & aa, const Point<3> & ab, double ara, double arb);
/// ///
// default constructor for archive
Cone() {}
virtual void DoArchive(Archive& ar)
{
QuadraticSurface::DoArchive(ar);
ar & a & b & ra & rb & minr & vab & t0vec & t1vec & vabl & t0 & t1 & cosphi;
}
static Primitive * CreateDefault (); static Primitive * CreateDefault ();
virtual void GetPrimitiveData (const char *& classname, Array<double> & coeffs) const; virtual void GetPrimitiveData (const char *& classname, Array<double> & coeffs) const;
virtual void SetPrimitiveData (Array<double> & coeffs); virtual void SetPrimitiveData (Array<double> & coeffs);
@ -383,7 +436,14 @@ namespace netgen
/// ///
EllipticCone (const Point<3> & aa, const Vec<3> & avl, EllipticCone (const Point<3> & aa, const Vec<3> & avl,
const Vec<3> & avs, double ah, double avlr); const Vec<3> & avs, double ah, double avlr);
// default constructor for archive
EllipticCone() {}
virtual void DoArchive(Archive& ar)
{
QuadraticSurface::DoArchive(ar);
ar & a & vl & vs & h & vlr;
}
static Primitive * CreateDefault (); static Primitive * CreateDefault ();
virtual void GetPrimitiveData (const char *& classname, Array<double> & coeffs) const; virtual void GetPrimitiveData (const char *& classname, Array<double> & coeffs) const;
virtual void SetPrimitiveData (Array<double> & coeffs); virtual void SetPrimitiveData (Array<double> & coeffs);
@ -425,6 +485,14 @@ namespace netgen
public: public:
/// OK /// OK
Torus (const Point<3> & ac, const Vec<3> & an, double aR, double ar); Torus (const Point<3> & ac, const Vec<3> & an, double aR, double ar);
// default constructor for archive
Torus() {}
virtual void DoArchive(Archive& ar)
{
OneSurfacePrimitive::DoArchive(ar);
ar & c & n & R & r;
}
/// OK /// OK
const Point<3> & Center () const { return c; } const Point<3> & Center () const { return c; }
/// OK /// OK

View File

@ -523,4 +523,8 @@ void OrthoBrick :: Reduce (const BoxSphere<3> & box)
surfaceactive.Elem(6) = surfaceactive.Elem(6) =
(box.PMin()(0) < pmax(0)) && (pmax(0) < box.PMax()(0)); (box.PMin()(0) < pmax(0)) && (pmax(0) < box.PMax()(0));
} }
RegisterClassForArchive<Parallelogram3d, Surface> regpar;
RegisterClassForArchive<Brick, Primitive> regbrick;
RegisterClassForArchive<OrthoBrick, Brick> regob;
} }

View File

@ -28,8 +28,16 @@ namespace netgen
public: public:
Parallelogram3d (Point<3> ap1, Point<3> ap2, Point<3> ap3); Parallelogram3d (Point<3> ap1, Point<3> ap2, Point<3> ap3);
// default constructor for archive
Parallelogram3d() {}
virtual ~Parallelogram3d (); virtual ~Parallelogram3d ();
virtual void DoArchive(Archive& ar)
{
Surface::DoArchive(ar);
ar & p1 & p2 & p3 & p4 & v12 & v13 & n;
}
void SetPoints (Point<3> ap1, Point<3> ap2, Point<3> ap3); void SetPoints (Point<3> ap1, Point<3> ap2, Point<3> ap3);
virtual int IsIdentic (const Surface & s2, int & inv, double eps) const; virtual int IsIdentic (const Surface & s2, int & inv, double eps) const;
@ -60,7 +68,15 @@ namespace netgen
public: public:
Brick (Point<3> ap1, Point<3> ap2, Point<3> ap3, Point<3> ap4); Brick (Point<3> ap1, Point<3> ap2, Point<3> ap3, Point<3> ap4);
// default constructor for archive
Brick() {}
virtual ~Brick (); virtual ~Brick ();
virtual void DoArchive(Archive& ar)
{
Primitive::DoArchive(ar);
ar & p1 & p2 & p3 & p4 & v12 & v13 & v14 & faces;
}
static Primitive * CreateDefault (); static Primitive * CreateDefault ();
virtual Primitive * Copy () const; virtual Primitive * Copy () const;
@ -116,6 +132,14 @@ namespace netgen
Point<3> pmin, pmax; Point<3> pmin, pmax;
public: public:
OrthoBrick (const Point<3> & ap1, const Point<3> & ap2); OrthoBrick (const Point<3> & ap1, const Point<3> & ap2);
// default constructor for archive
OrthoBrick() {}
virtual void DoArchive(Archive& ar)
{
Brick::DoArchive(ar);
ar & pmin & pmax;
}
virtual INSOLID_TYPE BoxInSolid (const BoxSphere<3> & box) const; virtual INSOLID_TYPE BoxInSolid (const BoxSphere<3> & box) const;
virtual void Reduce (const BoxSphere<3> & box); virtual void Reduce (const BoxSphere<3> & box);

View File

@ -324,6 +324,14 @@ namespace netgen
} }
void CSGeometry :: DoArchive(Archive& archive)
{
archive & surfaces & solids & toplevelobjects & userpoints & userpoints_ref_factor
& identpoints & boundingbox & isidenticto & ideps
& filename & spline_surfaces & splinecurves2d & splinecurves3d & surf2prim;
if(archive.Input())
FindIdenticSurfaces(1e-6);
}
void CSGeometry :: SaveSurfaces (ostream & out) const void CSGeometry :: SaveSurfaces (ostream & out) const
{ {
@ -1584,5 +1592,5 @@ namespace netgen
}; };
CSGInit csginit; CSGInit csginit;
static RegisterClassForArchive<CSGeometry, NetgenGeometry> regcsg;
} }

View File

@ -39,7 +39,14 @@ namespace netgen
public: public:
TopLevelObject (Solid * asolid, TopLevelObject (Solid * asolid,
Surface * asurface = NULL); Surface * asurface = NULL);
// default constructor for archive
TopLevelObject() {}
void DoArchive(Archive& archive)
{
archive & solid & surface & red & blue & green & visible & transp & maxh
& material & layer & bc & bcname;
}
const Solid * GetSolid() const { return solid; } const Solid * GetSolid() const { return solid; }
Solid * GetSolid() { return solid; } Solid * GetSolid() { return solid; }
@ -124,6 +131,11 @@ namespace netgen
UserPoint() = default; UserPoint() = default;
UserPoint (Point<3> p, int _index) : Point<3>(p), index(_index) { ; } UserPoint (Point<3> p, int _index) : Point<3>(p), index(_index) { ; }
int GetIndex() const { return index; } int GetIndex() const { return index; }
void DoArchive(Archive& archive)
{
archive & index;
Point<3>::DoArchive(archive);
}
}; };
private: private:
@ -165,14 +177,14 @@ namespace netgen
void Clean (); void Clean ();
virtual void Save (string filename) const; virtual void Save (string filename) const override;
void Save (ostream & ost) const; void Save (ostream & ost) const;
void Load (istream & ist); void Load (istream & ist);
void SaveSurfaces (ostream & out) const; void SaveSurfaces (ostream & out) const;
void LoadSurfaces (istream & in); void LoadSurfaces (istream & in);
virtual void SaveToMeshFile (ostream & ost) const; virtual void SaveToMeshFile (ostream & ost) const override;
int GetChangeVal() { return changeval; } int GetChangeVal() { return changeval; }
void Change() { changeval++; } void Change() { changeval++; }
@ -199,6 +211,8 @@ namespace netgen
const SplineGeometry<2> * GetSplineCurve2d (const string & name) const; const SplineGeometry<2> * GetSplineCurve2d (const string & name) const;
const SplineGeometry<3> * GetSplineCurve3d (const string & name) const; const SplineGeometry<3> * GetSplineCurve3d (const string & name) const;
void DoArchive(Archive& archive) override;
void SetFlags (const char * solidname, const Flags & flags); void SetFlags (const char * solidname, const Flags & flags);
@ -330,9 +344,9 @@ namespace netgen
Array<BCModification> bcmodifications; Array<BCModification> bcmodifications;
virtual int GenerateMesh (shared_ptr<Mesh> & mesh, MeshingParameters & mparam); virtual int GenerateMesh (shared_ptr<Mesh> & mesh, MeshingParameters & mparam) override;
virtual const Refinement & GetRefinement () const; virtual const Refinement & GetRefinement () const override;
void AddSplineSurface (shared_ptr<SplineSurface> ss) { spline_surfaces.Append(ss); } void AddSplineSurface (shared_ptr<SplineSurface> ss) { spline_surfaces.Append(ss); }
}; };

View File

@ -653,15 +653,15 @@ namespace netgen
Extrusion :: Extrusion(const SplineGeometry<3> & path_in, Extrusion :: Extrusion(const SplineGeometry<3> & path_in,
const SplineGeometry<2> & profile_in, const SplineGeometry<2> & profile_in,
const Vec<3> & z_dir) : const Vec<3> & z_dir) :
path(path_in), profile(profile_in), z_direction(z_dir) path(&path_in), profile(&profile_in), z_direction(z_dir)
{ {
surfaceactive.SetSize(0); surfaceactive.SetSize(0);
surfaceids.SetSize(0); surfaceids.SetSize(0);
for(int j=0; j<profile.GetNSplines(); j++) for(int j=0; j<profile->GetNSplines(); j++)
{ {
ExtrusionFace * face = new ExtrusionFace(&(profile.GetSpline(j)), ExtrusionFace * face = new ExtrusionFace(&((*profile).GetSpline(j)),
&path, path,
z_direction); z_direction);
faces.Append(face); faces.Append(face);
surfaceactive.Append(true); surfaceactive.Append(true);
@ -872,5 +872,6 @@ namespace netgen
surfaceactive[i] = true; surfaceactive[i] = true;
} }
RegisterClassForArchive<ExtrusionFace, Surface> regexf;
RegisterClassForArchive<Extrusion, Primitive> regextr;
} }

View File

@ -49,10 +49,19 @@ namespace netgen
const Vec<3> & z_direction); const Vec<3> & z_direction);
ExtrusionFace(const Array<double> & raw_data); ExtrusionFace(const Array<double> & raw_data);
// default constructor for archive
ExtrusionFace() {}
~ExtrusionFace(); ~ExtrusionFace();
virtual void DoArchive(Archive& ar)
{
Surface::DoArchive(ar);
ar & profile & path & glob_z_direction & deletable & spline3_path & line_path &
x_dir & y_dir & z_dir & loc_z_dir & p0 & profile_tangent & profile_par &
profile_spline_coeff & latest_seg & latest_t & latest_point2d & latest_point3d;
}
virtual int IsIdentic (const Surface & s2, int & inv, double eps) const; virtual int IsIdentic (const Surface & s2, int & inv, double eps) const;
virtual double CalcFunctionValue (const Point<3> & point) const; virtual double CalcFunctionValue (const Point<3> & point) const;
@ -109,10 +118,10 @@ namespace netgen
class Extrusion : public Primitive class Extrusion : public Primitive
{ {
private: private:
const SplineGeometry<3> & path; const SplineGeometry<3>* path;
const SplineGeometry<2> & profile; // closed, clockwise oriented curve const SplineGeometry<2>* profile; // closed, clockwise oriented curve
const Vec<3> & z_direction; Vec<3> z_direction;
Array<ExtrusionFace*> faces; Array<ExtrusionFace*> faces;
@ -122,7 +131,15 @@ namespace netgen
Extrusion(const SplineGeometry<3> & path_in, Extrusion(const SplineGeometry<3> & path_in,
const SplineGeometry<2> & profile_in, const SplineGeometry<2> & profile_in,
const Vec<3> & z_dir); const Vec<3> & z_dir);
// default constructor for archive
Extrusion() {}
~Extrusion(); ~Extrusion();
virtual void DoArchive(Archive& ar)
{
Primitive::DoArchive(ar);
ar & path & profile & z_direction & faces & latestfacenum;
}
virtual INSOLID_TYPE BoxInSolid (const BoxSphere<3> & box) const; virtual INSOLID_TYPE BoxInSolid (const BoxSphere<3> & box) const;
virtual INSOLID_TYPE PointInSolid (const Point<3> & p, virtual INSOLID_TYPE PointInSolid (const Point<3> & p,
double eps) const; double eps) const;

View File

@ -1274,6 +1274,7 @@ BuildSurfaceElements (Array<Segment> & segs,
if (nst1 * dvec < 0) continue; if (nst1 * dvec < 0) continue;
Element2d el(s1[0], s1[1], s2[0], s2[1]); Element2d el(s1[0], s1[1], s2[0], s2[1]);
el.SetIndex(s1.si);
Vec<3> n = Cross (mesh[el[1]] - mesh[el[0]], Vec<3> n = Cross (mesh[el[1]] - mesh[el[0]],
mesh[el[3]] - mesh[el[0]]); mesh[el[3]] - mesh[el[0]]);

View File

@ -235,13 +235,17 @@ DLL_HEADER void ExportCSG(py::module &m)
return self.GetNP()-1; return self.GetNP()-1;
}), }),
py::arg("x"),py::arg("y"),py::arg("z"),py::arg("hpref")=false) py::arg("x"),py::arg("y"),py::arg("z"),py::arg("hpref")=false)
.def("AddSegment", FunctionPointer .def("AddSegment", [] (SplineSurface & self, int i1, int i2, string bcname, double maxh)
([] (SplineSurface & self, int i1, int i2, string bcname, double maxh)
{ {
auto seg = make_shared<LineSeg<3>>(self.GetPoint(i1),self.GetPoint(i2)); auto seg = make_shared<LineSeg<3>>(self.GetPoint(i1),self.GetPoint(i2));
self.AppendSegment(seg,bcname,maxh); self.AppendSegment(seg,bcname,maxh);
}), },
py::arg("pnt1"),py::arg("pnt2"),py::arg("bcname")="default", py::arg("maxh")=-1.) py::arg("pnt1"),py::arg("pnt2"),py::arg("bcname")="default", py::arg("maxh")=-1.)
.def("AddSegment", [] (SplineSurface& self, int i1, int i2, int i3, string bcname, double maxh)
{
auto seg = make_shared<SplineSeg3<3>>(self.GetPoint(i1), self.GetPoint(i2), self.GetPoint(i3));
self.AppendSegment(seg, bcname, maxh);
}, py::arg("pnt1"),py::arg("pnt2"), py::arg("pnt3"),py::arg("bcname")="default", py::arg("maxh")=-1.)
; ;
py::class_<SPSolid, shared_ptr<SPSolid>> (m, "Solid") py::class_<SPSolid, shared_ptr<SPSolid>> (m, "Solid")
@ -360,37 +364,15 @@ However, when r = 0, the top part becomes a point(tip) and meshing fails!
py::class_<CSGeometry, NetgenGeometry, shared_ptr<CSGeometry>> (m, "CSGeometry") py::class_<CSGeometry, NetgenGeometry, shared_ptr<CSGeometry>> (m, "CSGeometry")
.def(py::init<>()) .def(py::init<>())
.def("__init__", .def(py::init([](const string& filename)
[](CSGeometry *instance, const string & filename)
{ {
cout << "load geometry";
ifstream ist (filename); ifstream ist (filename);
ParseCSG(ist, instance); auto geo = make_shared<CSGeometry>();
instance -> FindIdenticSurfaces(1e-8 * instance->MaxSize()); ParseCSG(ist, geo.get());
}) geo->FindIdenticSurfaces(1e-8 * geo->MaxSize());
.def("__init__", return geo;
[](CSGeometry *instance, const py::list & solidlist) }), py::arg("filename"))
{ .def(NGSPickle<CSGeometry>())
cout << "csg from list";
new (instance) CSGeometry();
for (int i = 0; i < len(solidlist); i++)
{
py::object obj = solidlist[i];
cout << "obj " << i << endl;
py::extract<shared_ptr<SPSolid>> solid(solidlist[i]);
if(solid.check())
{
cout << "its a solid" << endl;
solid()->AddSurfaces (*instance);
solid()->GiveUpOwner();
int tlonr = instance->SetTopLevelObject (solid()->GetSolid());
instance->GetTopLevelObject(tlonr) -> SetMaterial(solid()->GetMaterial());
}
}
instance -> FindIdenticSurfaces(1e-8 * instance->MaxSize());
})
.def("Save", FunctionPointer([] (CSGeometry & self, string filename) .def("Save", FunctionPointer([] (CSGeometry & self, string filename)
{ {
cout << "save geometry to file " << filename << endl; cout << "save geometry to file " << filename << endl;
@ -477,7 +459,12 @@ However, when r = 0, the top part becomes a point(tip) and meshing fails!
self.GetTopLevelObject(tlonr) -> SetBCProp(surf->GetBase()->GetBCProperty()); self.GetTopLevelObject(tlonr) -> SetBCProp(surf->GetBase()->GetBCProperty());
self.GetTopLevelObject(tlonr) -> SetBCName(surf->GetBase()->GetBCName()); self.GetTopLevelObject(tlonr) -> SetBCName(surf->GetBase()->GetBCName());
self.GetTopLevelObject(tlonr) -> SetMaxH(surf->GetBase()->GetMaxH()); self.GetTopLevelObject(tlonr) -> SetMaxH(surf->GetBase()->GetMaxH());
for(auto p : surf->GetPoints()) Array<Point<3>> non_midpoints;
for(auto spline : surf->GetSplines())
{
non_midpoints.Append(spline->GetPoint(0));
}
for(auto p : non_midpoints)
self.AddUserPoint(p); self.AddUserPoint(p);
self.AddSplineSurface(surf); self.AddSplineSurface(surf);
}), }),

View File

@ -640,9 +640,9 @@ namespace netgen
Revolution :: Revolution(const Point<3> & p0_in, Revolution :: Revolution(const Point<3> & p0_in,
const Point<3> & p1_in, const Point<3> & p1_in,
const SplineGeometry<2> & spline_in) : const SplineGeometry<2> & spline_in) :
p0(p0_in), p1(p1_in), splinecurve(spline_in), p0(p0_in), p1(p1_in)
nsplines(spline_in.GetNSplines())
{ {
auto nsplines = spline_in.GetNSplines();
surfaceactive.SetSize(0); surfaceactive.SetSize(0);
surfaceids.SetSize(0); surfaceids.SetSize(0);
@ -650,21 +650,21 @@ namespace netgen
v_axis.Normalize(); v_axis.Normalize();
if(splinecurve.GetSpline(0).StartPI()(1) <= 0. && if(spline_in.GetSpline(0).StartPI()(1) <= 0. &&
splinecurve.GetSpline(nsplines-1).EndPI()(1) <= 0.) spline_in.GetSpline(nsplines-1).EndPI()(1) <= 0.)
type = 2; type = 2;
else if (Dist(splinecurve.GetSpline(0).StartPI(), else if (Dist(spline_in.GetSpline(0).StartPI(),
splinecurve.GetSpline(nsplines-1).EndPI()) < 1e-7) spline_in.GetSpline(nsplines-1).EndPI()) < 1e-7)
type = 1; type = 1;
else else
cerr << "Surface of revolution cannot be constructed" << endl; cerr << "Surface of revolution cannot be constructed" << endl;
for(int i=0; i<splinecurve.GetNSplines(); i++) for(int i=0; i<spline_in.GetNSplines(); i++)
{ {
RevolutionFace * face = new RevolutionFace(splinecurve.GetSpline(i), RevolutionFace * face = new RevolutionFace(spline_in.GetSpline(i),
p0,v_axis, p0,v_axis,
type==2 && i==0, type==2 && i==0,
type==2 && i==splinecurve.GetNSplines()-1); type==2 && i==spline_in.GetNSplines()-1);
faces.Append(face); faces.Append(face);
surfaceactive.Append(1); surfaceactive.Append(1);
surfaceids.Append(0); surfaceids.Append(0);
@ -959,4 +959,7 @@ namespace netgen
for(int i=0; i<faces.Size(); i++) for(int i=0; i<faces.Size(); i++)
surfaceactive[i] = true; surfaceactive[i] = true;
} }
RegisterClassForArchive<RevolutionFace, Surface> regrevf;
RegisterClassForArchive<Revolution, Primitive> regrev;
} }

View File

@ -45,9 +45,18 @@ namespace netgen
const int id_in = 0); const int id_in = 0);
RevolutionFace(const Array<double> & raw_data); RevolutionFace(const Array<double> & raw_data);
// default constructor for archive
RevolutionFace() {}
~RevolutionFace(); ~RevolutionFace();
virtual void DoArchive(Archive& ar)
{
Surface::DoArchive(ar);
ar & isfirst & islast & spline & deletable & p0 & v_axis & id & spline_coefficient
& spline_coefficient_shifted & checklines_vec & checklines_start & checklines_normal;
}
virtual int IsIdentic (const Surface & s2, int & inv, double eps) const; virtual int IsIdentic (const Surface & s2, int & inv, double eps) const;
virtual double CalcFunctionValue (const Point<3> & point) const; virtual double CalcFunctionValue (const Point<3> & point) const;
@ -96,8 +105,6 @@ namespace netgen
private: private:
Point<3> p0,p1; Point<3> p0,p1;
Vec<3> v_axis; Vec<3> v_axis;
const SplineGeometry<2> & splinecurve;
const int nsplines;
// 1 ... torus-like // 1 ... torus-like
// 2 ... sphere-like // 2 ... sphere-like
@ -112,9 +119,16 @@ namespace netgen
Revolution(const Point<3> & p0_in, Revolution(const Point<3> & p0_in,
const Point<3> & p1_in, const Point<3> & p1_in,
const SplineGeometry<2> & spline_in); const SplineGeometry<2> & spline_in);
// default constructor for archive
Revolution() {}
~Revolution(); ~Revolution();
virtual void DoArchive(Archive& ar)
{
Primitive::DoArchive(ar);
ar & p0 & p1 & v_axis & type & faces & intersecting_face;
}
/* /*
Check, whether box intersects solid defined by surface. Check, whether box intersects solid defined by surface.

View File

@ -55,8 +55,22 @@ namespace netgen
public: public:
Solid (Primitive * aprim); Solid (Primitive * aprim);
Solid (optyp aop, Solid * as1, Solid * as2 = NULL); Solid (optyp aop, Solid * as1, Solid * as2 = NULL);
// default constructor for archive
Solid () {}
~Solid (); ~Solid ();
void DoArchive(Archive& archive)
{
archive & name & prim & s1 & s2 & visited & maxh & num_surfs;
if(archive.Output())
archive << int(op);
else
{
int iop;
archive & iop;
op = optyp(iop);
}
}
const char * Name () const { return name; } const char * Name () const { return name; }
void SetName (const char * aname); void SetName (const char * aname);

View File

@ -61,9 +61,32 @@ void SplineSurface :: AppendPoint(const Point<3> & p, const double reffac, const
} }
cuttings->Append(plane); cuttings->Append(plane);
} }
else
{
auto spline3 = dynamic_cast<SplineSeg3<3>*>(spline.get());
if(spline3)
{
auto p1 = Point<3>(spline3->StartPI());
Project(p1);
auto p2 = Point<3>(spline3->TangentPoint());
Project(p2);
auto p3 = Point<3>(spline3->EndPI());
Project(p3);
Vec<3> v1 = p2-p1;
Vec<3> v2 = p2-p3;
Point<3> mid = p1 - v2;
cout << "mid point = " << mid << endl;
cout << "v1 = " << v1 << endl;
cout << "v2 = " << v2 << endl;
auto cyl = make_shared<EllipticCylinder>(mid, v1, v2);
if(maxh[i] > 0)
cyl->SetMaxH(maxh[i]);
cuttings->Append(cyl);
}
else else
throw NgException("Spline type not implemented for SplineSurface!"); throw NgException("Spline type not implemented for SplineSurface!");
} }
}
all_cuts = cuttings; all_cuts = cuttings;
return cuttings; return cuttings;
} }
@ -73,4 +96,5 @@ void SplineSurface :: AppendPoint(const Point<3> & p, const double reffac, const
str << "SplineSurface with base " << *baseprimitive << endl; str << "SplineSurface with base " << *baseprimitive << endl;
} }
static RegisterClassForArchive<SplineSurface, OneSurfacePrimitive> regss;
} }

View File

@ -19,6 +19,8 @@ namespace netgen
SplineSurface(shared_ptr<OneSurfacePrimitive> abaseprimitive, shared_ptr<Array<shared_ptr<OneSurfacePrimitive>>> acuts) : SplineSurface(shared_ptr<OneSurfacePrimitive> abaseprimitive, shared_ptr<Array<shared_ptr<OneSurfacePrimitive>>> acuts) :
OneSurfacePrimitive(), baseprimitive(abaseprimitive), cuts(acuts) OneSurfacePrimitive(), baseprimitive(abaseprimitive), cuts(acuts)
{ ; } { ; }
// default constructor for archive
SplineSurface() {}
virtual ~SplineSurface() { ; } virtual ~SplineSurface() { ; }
const auto & GetSplines() const { return splines; } const auto & GetSplines() const { return splines; }
@ -54,6 +56,10 @@ namespace netgen
virtual INSOLID_TYPE BoxInSolid(const BoxSphere<3> & box) const virtual INSOLID_TYPE BoxInSolid(const BoxSphere<3> & box) const
{ return baseprimitive->BoxInSolid(box); } { return baseprimitive->BoxInSolid(box); }
virtual void DoArchive(Archive& ar)
{
ar & geompoints & splines & bcnames & maxh & baseprimitive & cuts & all_cuts;
}
/* /*
virtual void Project (Point<3> & p3d) const; virtual void Project (Point<3> & p3d) const;

View File

@ -566,4 +566,8 @@ void ProjectToEdge (const Surface * f1, const Surface * f2, Point<3> & hp)
if (Abs2 (rs) < 1e-24 && i > 1) i = 1; if (Abs2 (rs) < 1e-24 && i > 1) i = 1;
} }
} }
RegisterClassForArchive<Surface> regsurf;
RegisterClassForArchive<Primitive> regprim;
RegisterClassForArchive<OneSurfacePrimitive, Surface, Primitive> regosf;
} }

View File

@ -63,6 +63,12 @@ namespace netgen
//@} //@}
public: public:
virtual void DoArchive(Archive& archive)
{
archive & inverse & maxh & name & bcprop & bcname
& p1 & p2 & ex & ey & ez;
}
void SetName (const char * aname); void SetName (const char * aname);
const char * Name () const { return name; } const char * Name () const { return name; }
@ -234,6 +240,9 @@ namespace netgen
class Primitive class Primitive
{ {
protected:
Array<int> surfaceids;
Array<int> surfaceactive;
public: public:
@ -241,6 +250,10 @@ namespace netgen
virtual ~Primitive(); virtual ~Primitive();
virtual void DoArchive(Archive& archive)
{
archive & surfaceids & surfaceactive;
}
/* /*
Check, whether box intersects solid defined by surface. Check, whether box intersects solid defined by surface.
@ -299,9 +312,6 @@ namespace netgen
virtual Surface & GetSurface (int i = 0) = 0; virtual Surface & GetSurface (int i = 0) = 0;
virtual const Surface & GetSurface (int i = 0) const = 0; virtual const Surface & GetSurface (int i = 0) const = 0;
Array<int> surfaceids;
Array<int> surfaceactive;
int GetSurfaceId (int i = 0) const; int GetSurfaceId (int i = 0) const;
void SetSurfaceId (int i, int id); void SetSurfaceId (int i, int id);
int SurfaceActive (int i) const { return surfaceactive[i]; } int SurfaceActive (int i) const { return surfaceactive[i]; }
@ -329,6 +339,12 @@ namespace netgen
OneSurfacePrimitive(); OneSurfacePrimitive();
~OneSurfacePrimitive(); ~OneSurfacePrimitive();
virtual void DoArchive(Archive& archive)
{
Surface::DoArchive(archive);
Primitive::DoArchive(archive);
}
virtual INSOLID_TYPE PointInSolid (const Point<3> & p, virtual INSOLID_TYPE PointInSolid (const Point<3> & p,
double eps) const; double eps) const;
virtual INSOLID_TYPE VecInSolid (const Point<3> & p, virtual INSOLID_TYPE VecInSolid (const Point<3> & p,

View File

@ -11,7 +11,7 @@ set_target_properties( gen PROPERTIES POSITION_INDEPENDENT_CODE ON )
install( FILES ngexception.hpp DESTINATION ${NG_INSTALL_DIR_INCLUDE} COMPONENT netgen_devel ) install( FILES ngexception.hpp DESTINATION ${NG_INSTALL_DIR_INCLUDE} COMPONENT netgen_devel )
install(FILES install(FILES
archive_base.hpp array.hpp autodiff.hpp autoptr.hpp bitarray.hpp array.hpp autodiff.hpp autoptr.hpp bitarray.hpp
dynamicmem.hpp flags.hpp hashtabl.hpp mpi_interface.hpp myadt.hpp dynamicmem.hpp flags.hpp hashtabl.hpp mpi_interface.hpp myadt.hpp
ngsimd.hpp mystring.hpp netgenout.hpp ngexception.hpp ngpython.hpp ngsimd.hpp mystring.hpp netgenout.hpp ngexception.hpp ngpython.hpp
optmem.hpp parthreads.hpp profiler.hpp seti.hpp sort.hpp optmem.hpp parthreads.hpp profiler.hpp seti.hpp sort.hpp

View File

@ -1,144 +0,0 @@
#ifndef NGS_ARCHIVE_BASE
#define NGS_ARCHIVE_BASE
// copied from netgen
#include <vector>
#include <map>
namespace ngstd
{
class Archive
{
bool is_output;
public:
Archive (bool ais_output) : is_output(ais_output) { ; }
virtual ~Archive() { ; }
bool Output () { return is_output; }
bool Input () { return !is_output; }
virtual Archive & operator & (double & d) = 0;
virtual Archive & operator & (int & i) = 0;
virtual Archive & operator & (long & i) = 0;
virtual Archive & operator & (size_t & i) = 0;
virtual Archive & operator & (short & i) = 0;
virtual Archive & operator & (unsigned char & i) = 0;
virtual Archive & operator & (bool & b) = 0;
virtual Archive & operator & (string & str) = 0;
virtual Archive & operator & (char *& str) = 0;
template <typename T>
Archive & Do (T * data, size_t n)
{ for (size_t j = 0; j < n; j++) { (*this) & data[j]; }; return *this; };
virtual Archive & Do (double * d, size_t n)
{ for (size_t j = 0; j < n; j++) { (*this) & d[j]; }; return *this; };
virtual Archive & Do (int * i, size_t n)
{ for (size_t j = 0; j < n; j++) { (*this) & i[j]; }; return *this; };
virtual Archive & Do (long * i, size_t n)
{ for (size_t j = 0; j < n; j++) { (*this) & i[j]; }; return *this; };
virtual Archive & Do (size_t * i, size_t n)
{ for (size_t j = 0; j < n; j++) { (*this) & i[j]; }; return *this; };
virtual Archive & Do (short * i, size_t n)
{ for (size_t j = 0; j < n; j++) { (*this) & i[j]; }; return *this; };
virtual Archive & Do (unsigned char * i, size_t n)
{ for (size_t j = 0; j < n; j++) { (*this) & i[j]; }; return *this; };
virtual Archive & Do (bool * b, size_t n)
{ for (size_t j = 0; j < n; j++) { (*this) & b[j]; }; return *this; };
// nvirtual Archive & Do (string * str, size_t n)
// { for (size_t j = 0; j < n; j++) { (*this) & str[j]; }; return *this; };
// virtual Archive & operator & (char *& str) = 0;
// archive a pointer ...
int cnt = 0;
std::map<void*,int> ptr2nr;
std::vector<void*> nr2ptr;
/*
// necessary for msvc ???
Archive & operator& (string* & ps)
{
return operator&<string> (ps);
}
*/
template <typename T>
Archive & operator& (T *& p)
{
if (Output())
{
if (!p)
{
int m2 = -2;
(*this) & m2;
return *this;
}
auto pos = ptr2nr.find( (void*) p);
if (pos == ptr2nr.end())
{
ptr2nr[p] = cnt;
int m1 = -1;
(*this) & m1;
cnt++;
(*this) & (*p);
}
else
{
(*this) & pos->second;
}
}
else
{
int nr;
(*this) & nr;
// cout << "in, got nr " << nr << endl;
if (nr == -2)
{
p = nullptr;
}
else if (nr == -1)
{
p = new T;
// cout << "create new ptr, p = " << p << endl;
(*this) & *p;
nr2ptr.push_back(p);
}
else
{
p = (T*)nr2ptr[nr];
// cout << "reuse ptr " << nr << ": " << p << endl;
}
}
return *this;
}
template <typename T>
Archive & operator << (const T & t)
{
T ht(t);
(*this) & ht;
return *this;
}
};
}
#endif

View File

@ -401,6 +401,21 @@ namespace netgen
return data; return data;
} }
// Only provide this function if T is archivable
template<typename T2=T>
auto DoArchive(Archive& archive) -> typename std::enable_if<is_archivable<T2>, void>::type
{
if(archive.Output())
archive << size;
else
{
size_t s;
archive & s;
SetSize(s);
}
archive.Do(data, size);
}
private: private:
/// resize array, at least to size minsize. copy contents /// resize array, at least to size minsize. copy contents
@ -778,30 +793,6 @@ namespace netgen
if(in2.Contains(in1[i]) && in3.Contains(in1[i])) if(in2.Contains(in1[i]) && in3.Contains(in1[i]))
out.Append(in1[i]); out.Append(in1[i]);
} }
template <typename T, int BASE, typename TIND>
ngstd::Archive & operator & (ngstd::Archive & archive, Array<T,BASE,TIND> & a)
{
if (archive.Output())
archive << a.Size();
else
{
size_t size;
archive & size;
a.SetSize (size);
}
/*
for (auto & ai : a)
archive & ai;
*/
archive.Do (&a[BASE], a.Size());
return archive;
}
} }
#endif #endif

View File

@ -259,20 +259,13 @@ public:
const T & GetData (const Iterator & it) const const T & GetData (const Iterator & it) const
{ return cont[it.BagNr()][it.Pos()]; } { return cont[it.BagNr()][it.Pos()]; }
ngstd::Archive & DoArchive (ngstd::Archive & ar) void DoArchive (Archive & ar)
{ {
ar & hash & cont; ar & hash & cont;
return ar;
} }
}; };
template <typename T>
inline ngstd::Archive & operator & (ngstd::Archive & archive, INDEX_2_HASHTABLE<T> & mp)
{ return mp.DoArchive(archive); }
template <typename T> template <typename T>
inline ostream & operator<< (ostream & ost, const INDEX_2_HASHTABLE<T> & ht) inline ostream & operator<< (ostream & ost, const INDEX_2_HASHTABLE<T> & ht)
{ {
@ -436,24 +429,15 @@ public:
{ return cont[it.BagNr()][it.Pos()]; } { return cont[it.BagNr()][it.Pos()]; }
ngstd::Archive & DoArchive (ngstd::Archive & ar) void DoArchive (Archive & ar)
{ {
ar & hash & cont; ar & hash & cont;
return ar;
} }
}; };
template <typename T>
inline ngstd::Archive & operator & (ngstd::Archive & archive, INDEX_3_HASHTABLE<T> & mp)
{ return mp.DoArchive(archive); }
template <typename T> template <typename T>
inline ostream & operator<< (ostream & ost, const INDEX_3_HASHTABLE<T> & ht) inline ostream & operator<< (ostream & ost, const INDEX_3_HASHTABLE<T> & ht)
{ {

View File

@ -17,11 +17,15 @@
#include "../include/mydefs.hpp" #include "../include/mydefs.hpp"
#include "../core/ngcore.hpp"
namespace netgen
{
using namespace ngcore;
}
#include "ngexception.hpp" #include "ngexception.hpp"
#include "parthreads.hpp" #include "parthreads.hpp"
// #include "moveablemem.hpp" // #include "moveablemem.hpp"
#include "dynamicmem.hpp" #include "dynamicmem.hpp"
#include "archive_base.hpp"
#include "template.hpp" #include "template.hpp"
#include "array.hpp" #include "array.hpp"

View File

@ -1,17 +1,5 @@
#ifdef NG_PYTHON #ifdef NG_PYTHON
// BEGIN EVIL HACK: Patch PyThread_get_key_value inside pybind11 to avoid deadlocks
// see https://github.com/pybind/pybind11/pull/1211
#include <Python.h>
#include <pythread.h>
namespace pybind11 {
inline void * PyThread_get_key_value(int state) {
PyThreadState *tstate = (PyThreadState *) ::PyThread_get_key_value(state);
if (!tstate) tstate = PyGILState_GetThisThreadState();
return tstate;
}
}
// END EVIL HACK
#include <pybind11/pybind11.h> #include <pybind11/pybind11.h>
#include <pybind11/operators.h> #include <pybind11/operators.h>
#include <pybind11/numpy.h> #include <pybind11/numpy.h>

View File

@ -69,6 +69,8 @@ public:
/// Deletes symboltable /// Deletes symboltable
inline void DeleteAll (); inline void DeleteAll ();
void DoArchive(Archive& archive) { archive & names & data;}
inline T & operator[] (int i) inline T & operator[] (int i)
{ return data[i]; } { return data[i]; }
inline const T & operator[] (int i) const inline const T & operator[] (int i) const

View File

@ -213,7 +213,7 @@ namespace netgen
ngstd::Archive & BASE_TABLE :: DoArchive (ngstd::Archive & ar, int elemsize) void BASE_TABLE :: DoArchive (Archive & ar, int elemsize)
{ {
if (ar.Output()) if (ar.Output())
{ {
@ -248,7 +248,6 @@ namespace netgen
cnt += data[i].size*elemsize; cnt += data[i].size*elemsize;
} }
} }
return ar;
} }

View File

@ -89,7 +89,7 @@ public:
void SetElementSizesToMaxSizes (); void SetElementSizesToMaxSizes ();
ngstd::Archive & DoArchive (ngstd::Archive & ar, int elemsize); void DoArchive (Archive & ar, int elemsize);
}; };
@ -238,21 +238,13 @@ public:
return FlatArray<T> (data[i-BASE].size, (T*)data[i-BASE].col); return FlatArray<T> (data[i-BASE].size, (T*)data[i-BASE].col);
} }
ngstd::Archive & DoArchive (ngstd::Archive & ar) void DoArchive (Archive & ar)
{ {
return BASE_TABLE::DoArchive(ar, sizeof(T)); BASE_TABLE::DoArchive(ar, sizeof(T));
} }
}; };
template <typename T, int BASE>
inline ngstd::Archive & operator & (ngstd::Archive & archive, TABLE<T,BASE> & mp)
{ return mp.DoArchive(archive); }
template <class T, int BASE> template <class T, int BASE>
inline ostream & operator<< (ostream & ost, const TABLE<T,BASE> & table) inline ostream & operator<< (ostream & ost, const TABLE<T,BASE> & table)
{ {

View File

@ -208,6 +208,9 @@ namespace netgen
// mesh size restrictions ... // mesh size restrictions ...
for (auto & point : geompoints)
mesh2d.RestrictLocalH (Point<3> (point(0), point(1), 0), point.hmax);
for (int i = 0; i < splines.Size(); i++) for (int i = 0; i < splines.Size(); i++)
{ {
const SplineSegExt & spline = GetSpline(i); const SplineSegExt & spline = GetSpline(i);
@ -238,6 +241,23 @@ namespace netgen
} }
} }
for (auto mspnt : mp.meshsize_points)
mesh2d.RestrictLocalH (mspnt.pnt, mspnt.h);
// add point elements
for (auto & point : geompoints)
if (point.name.length())
{
Point<3> newp(point(0), point(1), 0);
PointIndex npi = mesh2d.AddPoint (newp, 1, FIXEDPOINT);
mesh2d.AddLockedPoint(npi);
Element0d el(npi, npi);
el.name = point.name;
mesh2d.SetCD2Name(npi, point.name);
mesh2d.pointelements.Append (el);
searchtree.Insert (newp, npi);
}
// first add all vertices (for compatible orientation on periodic bnds) // first add all vertices (for compatible orientation on periodic bnds)
{ {
double diam2 = Dist2(pmin, pmax); double diam2 = Dist2(pmin, pmax);
@ -581,7 +601,9 @@ namespace netgen
// not complete, use at own risk ... // not complete, use at own risk ...
// meshing.Delaunay(*mesh, domnr, mp); // meshing.Delaunay(*mesh, domnr, mp);
mp.checkoverlap = 0; mp.checkoverlap = 0;
meshing.GenerateMesh (*mesh, mp, h, domnr); auto res = meshing.GenerateMesh (*mesh, mp, h, domnr);
if (res != 0)
throw NgException("meshing failed");
for (SurfaceElementIndex sei = oldnf; sei < mesh->GetNSE(); sei++) for (SurfaceElementIndex sei = oldnf; sei < mesh->GetNSE(); sei++)
(*mesh)[sei].SetIndex (domnr); (*mesh)[sei].SetIndex (domnr);

View File

@ -47,8 +47,8 @@ namespace netgen
auto ext = dynamic_cast<const SplineSegExt *>(spline); auto ext = dynamic_cast<const SplineSegExt *>(spline);
if(ext) if(ext)
{ {
ss3 = dynamic_cast<const SplineSeg3<2> *>(&ext->seg); ss3 = dynamic_cast<const SplineSeg3<2> *>(ext->seg);
ls = dynamic_cast<const LineSeg<2> *>(&ext->seg); ls = dynamic_cast<const LineSeg<2> *>(ext->seg);
} }
else else
{ {

View File

@ -1034,5 +1034,6 @@ namespace netgen
}; };
SplineGeoInit sginit; SplineGeoInit sginit;
static RegisterClassForArchive<SplineGeometry2d, SplineGeometry<2>, NetgenGeometry> regspg2;
static RegisterClassForArchive<SplineSegExt, SplineSeg<2>> regssext;
} }

View File

@ -21,7 +21,7 @@ namespace netgen
class SplineSegExt : public SplineSeg<2> class SplineSegExt : public SplineSeg<2>
{ {
public: public:
const SplineSeg<2> & seg; SplineSeg<2>* seg;
/// left domain /// left domain
int leftdom; int leftdom;
@ -42,35 +42,43 @@ namespace netgen
/// ///
int layer; int layer;
SplineSegExt (const SplineSeg<2> & hseg) SplineSegExt (SplineSeg<2> & hseg)
: seg(hseg) : seg(&hseg)
{ {
layer = 1; layer = 1;
} }
// default constructor for archive
SplineSegExt() {}
~SplineSegExt () ~SplineSegExt ()
{ {
delete &seg; delete seg;
}
virtual void DoArchive(Archive& ar)
{
ar & seg & leftdom & rightdom & reffak & hmax & bc & copyfrom
& hpref_left & hpref_right & layer;
} }
virtual const GeomPoint<2> & StartPI () const virtual const GeomPoint<2> & StartPI () const
{ {
return seg.StartPI(); return seg->StartPI();
} }
virtual const GeomPoint<2> & EndPI () const virtual const GeomPoint<2> & EndPI () const
{ {
return seg.EndPI(); return seg->EndPI();
} }
virtual Point<2> GetPoint (double t) const virtual Point<2> GetPoint (double t) const
{ {
return seg.GetPoint(t); return seg->GetPoint(t);
} }
virtual Vec<2> GetTangent (const double t) const virtual Vec<2> GetTangent (const double t) const
{ {
return seg.GetTangent(t); return seg->GetTangent(t);
} }
virtual void GetDerivatives (const double t, virtual void GetDerivatives (const double t,
@ -78,27 +86,27 @@ namespace netgen
Vec<2> & first, Vec<2> & first,
Vec<2> & second) const Vec<2> & second) const
{ {
seg.GetDerivatives (t, point, first, second); seg->GetDerivatives (t, point, first, second);
} }
virtual void GetCoeff (Vector & coeffs) const virtual void GetCoeff (Vector & coeffs) const
{ {
seg.GetCoeff (coeffs); seg->GetCoeff (coeffs);
} }
virtual void GetPoints (int n, Array<Point<2> > & points) const virtual void GetPoints (int n, Array<Point<2> > & points) const
{ {
seg.GetPoints (n, points); seg->GetPoints (n, points);
} }
virtual double MaxCurvature () const virtual double MaxCurvature () const
{ {
return seg.MaxCurvature(); return seg->MaxCurvature();
} }
virtual string GetType () const virtual string GetType () const
{ {
return seg.GetType(); return seg->GetType();
} }
virtual double CalcCurvature (double t) const virtual double CalcCurvature (double t) const
@ -112,7 +120,7 @@ namespace netgen
virtual bool InConvexHull (Point<2> p, double eps) const virtual bool InConvexHull (Point<2> p, double eps) const
{ {
return seg.InConvexHull (p, eps); return seg->InConvexHull (p, eps);
} }
}; };
@ -143,7 +151,11 @@ namespace netgen
void TestComment ( ifstream & infile ) ; void TestComment ( ifstream & infile ) ;
void DoArchive(Archive& ar)
{
SplineGeometry<2>::DoArchive(ar);
ar & materials & maxh & quadmeshing & tensormeshing & layer & bcnames & elto0;
}
const SplineSegExt & GetSpline (const int i) const const SplineSegExt & GetSpline (const int i) const
{ {

View File

@ -17,21 +17,20 @@ DLL_HEADER void ExportGeom2d(py::module &m)
{ {
py::class_<SplineGeometry2d, NetgenGeometry, shared_ptr<SplineGeometry2d>> py::class_<SplineGeometry2d, NetgenGeometry, shared_ptr<SplineGeometry2d>>
(m, "SplineGeometry", (m, "SplineGeometry",
"a 2d boundary representation geometry model by lines and splines") "a 2d boundary representation geometry model by lines and splines",
py::multiple_inheritance())
.def(py::init<>()) .def(py::init<>())
.def("__init__", .def(py::init([](const string& filename)
[](SplineGeometry2d *instance, const string & filename)
{ {
cout << "load geometry"; auto geo = make_shared<SplineGeometry2d>();
ifstream ist(filename); geo->Load(filename.c_str());
new (instance) SplineGeometry2d(); ng_geometry = geo;
instance->Load (filename.c_str()); return geo;
ng_geometry = shared_ptr<SplineGeometry2d>(instance, NOOP_Deleter); }))
}) .def(NGSPickle<SplineGeometry2d>())
.def("Load",&SplineGeometry2d::Load) .def("Load",&SplineGeometry2d::Load)
.def("AppendPoint", FunctionPointer .def("AppendPoint", FunctionPointer
([](SplineGeometry2d &self, double px, double py, double maxh, double hpref) ([](SplineGeometry2d &self, double px, double py, double maxh, double hpref, string name)
{ {
Point<2> p; Point<2> p;
p(0) = px; p(0) = px;
@ -39,10 +38,11 @@ DLL_HEADER void ExportGeom2d(py::module &m)
GeomPoint<2> gp(p); GeomPoint<2> gp(p);
gp.hmax = maxh; gp.hmax = maxh;
gp.hpref = hpref; gp.hpref = hpref;
gp.name = name;
self.geompoints.Append(gp); self.geompoints.Append(gp);
return self.geompoints.Size()-1; return self.geompoints.Size()-1;
}), }),
py::arg("x"), py::arg("y"), py::arg("maxh") = 1e99, py::arg("hpref")=0) py::arg("x"), py::arg("y"), py::arg("maxh") = 1e99, py::arg("hpref")=0, py::arg("name")="")
.def("Append", FunctionPointer([](SplineGeometry2d &self, py::list segment, int leftdomain, int rightdomain, .def("Append", FunctionPointer([](SplineGeometry2d &self, py::list segment, int leftdomain, int rightdomain,
py::object bc, py::object copy, double maxh, double hpref) py::object bc, py::object copy, double maxh, double hpref)
{ {

View File

@ -64,6 +64,12 @@ namespace netgen
const T & operator() (int i) const { return x[i]; } const T & operator() (int i) const { return x[i]; }
operator const T* () const { return x; } operator const T* () const { return x; }
void DoArchive(Archive& archive)
{
for(int i=0; i<D; i++)
archive & x[i];
}
}; };
template <int D, typename T> template <int D, typename T>
@ -117,6 +123,12 @@ namespace netgen
operator const T* () const { return x; } operator const T* () const { return x; }
void DoArchive(Archive& archive)
{
for(int i=0; i<D; i++)
archive & x[i];
}
T Length () const T Length () const
{ {
T l = 0; T l = 0;
@ -324,6 +336,9 @@ namespace netgen
pmax(i) += dist; pmax(i) += dist;
} }
} }
void DoArchive(Archive& archive)
{ archive & pmin & pmax; }
}; };

View File

@ -99,7 +99,7 @@ namespace netgen
} }
template<int D> template<int D>
inline Point<D> SplineSeg3<D> :: GetPoint (double t) const Point<D> SplineSeg3<D> :: GetPoint (double t) const
{ {
double b1, b2, b3; double b1, b2, b3;
@ -551,11 +551,10 @@ namespace netgen
template class SplineSeg3<2>; template class SplineSeg3<2>;
template class SplineSeg3<3>; template class SplineSeg3<3>;
RegisterClassForArchive<SplineSeg<2>> regss2;
RegisterClassForArchive<SplineSeg<3>> regss3;
RegisterClassForArchive<LineSeg<2>, SplineSeg<2>> regls2;
RegisterClassForArchive<LineSeg<3>, SplineSeg<3>> regls3;
RegisterClassForArchive<SplineSeg3<2>, SplineSeg<2>> regsss2;
RegisterClassForArchive<SplineSeg3<3>, SplineSeg<3>> regsss3;
} }

View File

@ -28,13 +28,19 @@ namespace netgen
double hmax; double hmax;
/// hp-refinement /// hp-refinement
double hpref; double hpref;
///
string name;
/// ///
GeomPoint () { ; } GeomPoint () { ; }
/// ///
GeomPoint (const Point<D> & ap, double aref = 1, double ahpref=0) GeomPoint (const Point<D> & ap, double aref = 1, double ahpref=0)
: Point<D>(ap), refatpoint(aref), hmax(1e99), hpref(ahpref) { ; } : Point<D>(ap), refatpoint(aref), hmax(1e99), hpref(ahpref) { ; }
void DoArchive(Archive& ar)
{
Point<D>::DoArchive(ar);
ar & refatpoint & hmax & hpref;
}
}; };
@ -72,6 +78,7 @@ namespace netgen
second = 1.0/sqr(eps) * ( (pr-point)+(pl-point)); second = 1.0/sqr(eps) * ( (pr-point)+(pl-point));
} }
virtual void DoArchive(Archive& ar) = 0;
/// returns initial point on curve /// returns initial point on curve
virtual const GeomPoint<D> & StartPI () const = 0; virtual const GeomPoint<D> & StartPI () const = 0;
@ -122,6 +129,12 @@ namespace netgen
/// ///
LineSeg (const GeomPoint<D> & ap1, const GeomPoint<D> & ap2); LineSeg (const GeomPoint<D> & ap1, const GeomPoint<D> & ap2);
/// ///
// default constructor for archive
LineSeg() {}
virtual void DoArchive(Archive& ar)
{
ar & p1 & p2;
}
virtual double Length () const; virtual double Length () const;
/// ///
inline virtual Point<D> GetPoint (double t) const; inline virtual Point<D> GetPoint (double t) const;
@ -172,8 +185,14 @@ namespace netgen
SplineSeg3 (const GeomPoint<D> & ap1, SplineSeg3 (const GeomPoint<D> & ap1,
const GeomPoint<D> & ap2, const GeomPoint<D> & ap2,
const GeomPoint<D> & ap3); const GeomPoint<D> & ap3);
// default constructor for archive
SplineSeg3() {}
/// ///
inline virtual Point<D> GetPoint (double t) const; virtual void DoArchive(Archive& ar)
{
ar & p1 & p2 & p3 & weight & proj_latest_t;
}
virtual Point<D> GetPoint (double t) const;
/// ///
virtual Vec<D> GetTangent (const double t) const; virtual Vec<D> GetTangent (const double t) const;
@ -226,6 +245,12 @@ namespace netgen
CircleSeg (const GeomPoint<D> & ap1, CircleSeg (const GeomPoint<D> & ap1,
const GeomPoint<D> & ap2, const GeomPoint<D> & ap2,
const GeomPoint<D> & ap3); const GeomPoint<D> & ap3);
// default constructor for archive
CircleSeg() {}
virtual void DoArchive(Archive& ar)
{
ar & p1 & p2 & p3 & pm & radius & w1 & w3;
}
/// ///
virtual Point<D> GetPoint (double t) const; virtual Point<D> GetPoint (double t) const;
/// ///
@ -270,6 +295,12 @@ namespace netgen
public: public:
/// ///
DiscretePointsSeg (const Array<Point<D> > & apts); DiscretePointsSeg (const Array<Point<D> > & apts);
// default constructor for archive
DiscretePointsSeg() {}
virtual void DoArchive(Archive& ar)
{
ar & pts & p1n & p2n;
}
/// ///
virtual ~DiscretePointsSeg (); virtual ~DiscretePointsSeg ();
/// ///
@ -624,8 +655,14 @@ namespace netgen
/// ///
BSplineSeg (const Array<Point<D> > & apts); BSplineSeg (const Array<Point<D> > & apts);
/// ///
//default constructor for archive
BSplineSeg() {}
virtual ~BSplineSeg(); virtual ~BSplineSeg();
/// ///
virtual void DoArchive(Archive& ar)
{
ar & pts & p1n & p2n & ti;
}
virtual Point<D> GetPoint (double t) const; virtual Point<D> GetPoint (double t) const;
/// ///
virtual const GeomPoint<D> & StartPI () const { return p1n; }; virtual const GeomPoint<D> & StartPI () const { return p1n; };

View File

@ -129,6 +129,8 @@ namespace netgen
template class SplineGeometry<2>; template class SplineGeometry<2>;
template class SplineGeometry<3>; template class SplineGeometry<3>;
static RegisterClassForArchive<SplineGeometry<2>> regsp2;
static RegisterClassForArchive<SplineGeometry<3>> regsp3;
} }

View File

@ -34,6 +34,11 @@ namespace netgen
DLL_HEADER int Load (const Array<double> & raw_data, const int startpos = 0); DLL_HEADER int Load (const Array<double> & raw_data, const int startpos = 0);
virtual void DoArchive(Archive& ar)
{
ar & geompoints & splines;
}
DLL_HEADER void GetRawData (Array<double> & raw_data) const; DLL_HEADER void GetRawData (Array<double> & raw_data) const;
@ -55,7 +60,6 @@ namespace netgen
// void SetGrading (const double grading); // void SetGrading (const double grading);
DLL_HEADER void AppendPoint (const Point<D> & p, const double reffac = 1., const bool hpref = false); DLL_HEADER void AppendPoint (const Point<D> & p, const double reffac = 1., const bool hpref = false);
void AppendSegment(SplineSeg<D> * spline) void AppendSegment(SplineSeg<D> * spline)
{ {
splines.Append (spline); splines.Append (spline);

View File

@ -230,7 +230,7 @@ namespace netgen
void LoadMesh (istream & str); void LoadMesh (istream & str);
void SaveMesh (ostream & str) const; void SaveMesh (ostream & str) const;
void UpdateTopology (); void UpdateTopology ();
void DoArchive (ngstd::Archive & archive); void DoArchive (Archive & archive);
virtual ~Ngx_Mesh(); virtual ~Ngx_Mesh();

View File

@ -47,6 +47,7 @@ NGX_INLINE DLL_HEADER Ng_Element Ngx_Mesh :: GetElement<0> (size_t nr) const
Ng_Element ret; Ng_Element ret;
ret.type = NG_PNT; ret.type = NG_PNT;
ret.index = el.index; ret.index = el.index;
ret.mat = &el.name;
ret.points.num = 1; ret.points.num = 1;
ret.points.ptr = (int*)&el.pnum; ret.points.ptr = (int*)&el.pnum;

View File

@ -9,9 +9,7 @@ add_library(interface ${NG_LIB_TYPE}
if(NOT WIN32) if(NOT WIN32)
target_link_libraries(interface mesh csg geom2d) target_link_libraries(interface mesh csg geom2d)
if(USE_GUI)
target_link_libraries(interface visual) target_link_libraries(interface visual)
endif(USE_GUI)
install( TARGETS interface ${NG_INSTALL_DIR}) install( TARGETS interface ${NG_INSTALL_DIR})
endif(NOT WIN32) endif(NOT WIN32)

View File

@ -124,7 +124,6 @@ void Ng_LoadMesh (const char * filename)
#ifdef PARALLEL #ifdef PARALLEL
MPI_Comm_size(MPI_COMM_WORLD, &ntasks); MPI_Comm_size(MPI_COMM_WORLD, &ntasks);
MPI_Comm_rank(MPI_COMM_WORLD, &id); MPI_Comm_rank(MPI_COMM_WORLD, &id);
ng_geometry = nullptr;
#endif #endif
{ {

View File

@ -69,7 +69,7 @@ namespace netgen
mesh -> Save (ost); mesh -> Save (ost);
} }
void Ngx_Mesh :: DoArchive (ngstd::Archive & archive) void Ngx_Mesh :: DoArchive (Archive & archive)
{ {
if (archive.Input()) mesh = make_shared<Mesh>(); if (archive.Input()) mesh = make_shared<Mesh>();
mesh->DoArchive(archive); mesh->DoArchive(archive);

View File

@ -139,6 +139,14 @@ public:
~Vector () ~Vector ()
{ if (ownmem) delete [] data; } { if (ownmem) delete [] data; }
virtual void DoArchive(Archive& ar)
{
auto size = s;
ar & ownmem & size;
if(!ar.Output())
SetSize(size);
ar.Do(data, size);
}
Vector & operator= (const FlatVector & v) Vector & operator= (const FlatVector & v)
{ memcpy (data, &v(0), s*sizeof(double)); return *this; } { memcpy (data, &v(0), s*sizeof(double)); return *this; }

View File

@ -30,7 +30,7 @@ if(APPLE)
endif(APPLE) endif(APPLE)
if(NOT WIN32) if(NOT WIN32)
target_link_libraries( mesh ${ZLIB_LIBRARIES} ${MPI_CXX_LIBRARIES} ${PYTHON_LIBRARIES} ${METIS_LIBRARY}) target_link_libraries( mesh ngcore ${ZLIB_LIBRARIES} ${MPI_CXX_LIBRARIES} ${PYTHON_LIBRARIES} ${METIS_LIBRARY})
install( TARGETS mesh ${NG_INSTALL_DIR}) install( TARGETS mesh ${NG_INSTALL_DIR})
endif(NOT WIN32) endif(NOT WIN32)

View File

@ -22,7 +22,7 @@ namespace netgen
mgi = new MultiPointGeomInfo (*amgi); mgi = new MultiPointGeomInfo (*amgi);
for (int i = 1; i <= mgi->GetNPGI(); i++) for (int i = 1; i <= mgi->GetNPGI(); i++)
if (mgi->GetPGI(i).trignum <= 0) if (mgi->GetPGI(i).trignum <= 0)
cout << "Add FrontPoint2, illegal geominfo = " << mgi->GetPGI(i).trignum << endl; cout << "WARNING: Add FrontPoint2, illegal geominfo = " << mgi->GetPGI(i).trignum << endl;
} }
else else
mgi = NULL; mgi = NULL;
@ -136,7 +136,7 @@ namespace netgen
if (!gi1.trignum || !gi2.trignum) if (!gi1.trignum || !gi2.trignum)
{ {
cout << "ERROR: in AdFront::AddLine, illegal geominfo" << endl; cout << "WARNING: in AdFront::AddLine, illegal geominfo" << endl;
} }
lines[li].SetGeomInfo (gi1, gi2); lines[li].SetGeomInfo (gi1, gi2);

View File

@ -74,4 +74,5 @@ namespace netgen
throw NgException("Cannot save geometry - no geometry available"); throw NgException("Cannot save geometry - no geometry available");
} }
static RegisterClassForArchive<NetgenGeometry> regnggeo;
} }

View File

@ -22,6 +22,9 @@ namespace netgen
virtual const Refinement & GetRefinement () const; virtual const Refinement & GetRefinement () const;
virtual void DoArchive(Archive&)
{ throw NgException("DoArchive not implemented for " + Demangle(typeid(*this).name())); }
virtual void Save (string filename) const; virtual void Save (string filename) const;
virtual void SaveToMeshFile (ostream & /* ost */) const { ; } virtual void SaveToMeshFile (ostream & /* ost */) const { ; }
}; };

View File

@ -1752,6 +1752,18 @@ namespace netgen
} }
} }
Point<2> _xi(xi);
Point<3> _x;
Mat<3,2> _dxdxi;
if (EvaluateMapping (info, _xi, _x, _dxdxi))
{
if (x) *x = _x;
if (dxdxi) *dxdxi = _dxdxi;
return;
}
ArrayMem<Vec<3>,100> coefs(info.ndof); ArrayMem<Vec<3>,100> coefs(info.ndof);
ArrayMem<double, 100> shapes_mem(info.ndof); ArrayMem<double, 100> shapes_mem(info.ndof);
TFlatVector<double> shapes(info.ndof, &shapes_mem[0]); TFlatVector<double> shapes(info.ndof, &shapes_mem[0]);
@ -2254,6 +2266,18 @@ namespace netgen
} }
break; break;
} }
case QUAD:
{
if (info.order >= 2) return false; // not yet supported
AutoDiff<2,T> lami[4] = { (1-x)*(1-y), x*(1-y), x*y, (1-x)*y };
for (int j = 0; j < 4; j++)
{
Point<3> p = mesh[el[j]];
for (int k = 0; k < DIM_SPACE; k++)
mapped_x[k] += p(k) * lami[j];
}
break;
}
default: default:
return false; return false;
} }

View File

@ -48,6 +48,11 @@ public:
int GetOrder () { return order; } int GetOrder () { return order; }
virtual void DoArchive(Archive& ar)
{
ar & edgeorder & faceorder & edgecoeffsindex & facecoeffsindex & edgecoeffs & facecoeffs
& edgeweight & order & rational & ishighorder;
}
bool IsSegmentCurved (SegmentIndex segnr) const; bool IsSegmentCurved (SegmentIndex segnr) const;
bool IsSurfaceElementCurved (SurfaceElementIndex sei) const; bool IsSurfaceElementCurved (SurfaceElementIndex sei) const;

View File

@ -517,7 +517,7 @@ namespace netgen
DLL_HEADER void Merge (const string & filename, const int surfindex_offset = 0); DLL_HEADER void Merge (const string & filename, const int surfindex_offset = 0);
DLL_HEADER void DoArchive (ngstd::Archive & archive); DLL_HEADER void DoArchive (Archive & archive);
/// ///
DLL_HEADER void ImproveMesh (const MeshingParameters & mp, OPTIMIZEGOAL goal = OPT_QUALITY); DLL_HEADER void ImproveMesh (const MeshingParameters & mp, OPTIMIZEGOAL goal = OPT_QUALITY);

View File

@ -148,9 +148,9 @@ namespace netgen
return *this; return *this;
} }
ngstd::Archive & Segment :: DoArchive (ngstd::Archive & ar) void Segment :: DoArchive (Archive & ar)
{ {
return ar & pnums[0] & pnums[1] & pnums[2] ar & pnums[0] & pnums[1] & pnums[2]
& edgenr & singedge_left & singedge_right & edgenr & singedge_left & singedge_right
& si & cd2i & domin & domout & tlosurf & si & cd2i & domin & domout & tlosurf
& surfnr1 & surfnr2 & surfnr1 & surfnr2
@ -2427,9 +2427,9 @@ namespace netgen
bcn = &default_bcname; bcn = &default_bcname;
} }
ngstd::Archive & FaceDescriptor :: DoArchive (ngstd::Archive & ar) void FaceDescriptor :: DoArchive (Archive & ar)
{ {
return ar & surfnr & domin & domout & tlosurf & bcprop ar & surfnr & domin & domout & tlosurf & bcprop
& surfcolour.X() & surfcolour.Y() & surfcolour.Z() & surfcolour.X() & surfcolour.Y() & surfcolour.Z()
& bcname & bcname
& domin_singular & domout_singular ; & domin_singular & domout_singular ;
@ -2482,7 +2482,7 @@ namespace netgen
maxidentnr = 0; maxidentnr = 0;
} }
ngstd::Archive & Identifications :: DoArchive (ngstd::Archive & ar) void Identifications :: DoArchive (Archive & ar)
{ {
ar & maxidentnr; ar & maxidentnr;
ar & identifiedpoints & identifiedpoints_nr; ar & identifiedpoints & identifiedpoints_nr;
@ -2503,7 +2503,6 @@ namespace netgen
for (auto & t : type) for (auto & t : type)
ar & (unsigned char&)(t); ar & (unsigned char&)(t);
} }
return ar;
} }

View File

@ -171,13 +171,9 @@ namespace netgen
enum { BASE = 1 }; enum { BASE = 1 };
#endif #endif
ngstd::Archive & DoArchive (ngstd::Archive & ar) { return ar & i; } void DoArchive (Archive & ar) { ar & i; }
}; };
inline ngstd::Archive & operator & (ngstd::Archive & archive, PointIndex & mp)
{ return mp.DoArchive(archive); }
inline istream & operator>> (istream & ist, PointIndex & pi) inline istream & operator>> (istream & ist, PointIndex & pi)
{ {
int i; ist >> i; pi = PointIndex(i); return ist; int i; ist >> i; pi = PointIndex(i); return ist;
@ -247,14 +243,9 @@ namespace netgen
SurfaceElementIndex & operator-- () { --i; return *this; } SurfaceElementIndex & operator-- () { --i; return *this; }
SurfaceElementIndex & operator+= (int inc) { i+=inc; return *this; } SurfaceElementIndex & operator+= (int inc) { i+=inc; return *this; }
ngstd::Archive & DoArchive (ngstd::Archive & ar) { return ar & i; } void DoArchive (Archive & ar) { ar & i; }
}; };
inline ngstd::Archive & operator & (ngstd::Archive & archive, SurfaceElementIndex & mp)
{ return mp.DoArchive(archive); }
inline istream & operator>> (istream & ist, SurfaceElementIndex & pi) inline istream & operator>> (istream & ist, SurfaceElementIndex & pi)
{ {
int i; ist >> i; pi = i; return ist; int i; ist >> i; pi = i; return ist;
@ -337,19 +328,13 @@ namespace netgen
static MPI_Datatype MyGetMPIType ( ); static MPI_Datatype MyGetMPIType ( );
#endif #endif
ngstd::Archive & DoArchive (ngstd::Archive & ar) void DoArchive (Archive & ar)
{ {
ar & x[0] & x[1] & x[2] & layer & singular; ar & x[0] & x[1] & x[2] & layer & singular;
ar & (unsigned char&)(type); ar & (unsigned char&)(type);
return ar;
} }
}; };
inline ngstd::Archive & operator & (ngstd::Archive & archive, MeshPoint & mp)
{ return mp.DoArchive(archive); }
inline ostream & operator<<(ostream & s, const MeshPoint & pt) inline ostream & operator<<(ostream & s, const MeshPoint & pt)
{ {
return (s << Point<3> (pt)); return (s << Point<3> (pt));
@ -497,7 +482,7 @@ namespace netgen
/// ///
const PointGeomInfo & GeomInfoPiMod (int i) const { return geominfo[(i-1) % np]; } const PointGeomInfo & GeomInfoPiMod (int i) const { return geominfo[(i-1) % np]; }
ngstd::Archive & DoArchive (ngstd::Archive & ar) void DoArchive (Archive & ar)
{ {
short _np, _typ; short _np, _typ;
bool _curved, _vis, _deleted; bool _curved, _vis, _deleted;
@ -511,7 +496,6 @@ namespace netgen
visible = _vis; deleted = _deleted; } visible = _vis; deleted = _deleted; }
for (size_t i = 0; i < np; i++) for (size_t i = 0; i < np; i++)
ar & pnum[i]; ar & pnum[i];
return ar;
} }
void SetIndex (int si) { index = si; } void SetIndex (int si) { index = si; }
@ -630,9 +614,6 @@ namespace netgen
#endif #endif
}; };
inline ngstd::Archive & operator & (ngstd::Archive & archive, Element2d & mp)
{ return mp.DoArchive(archive); }
ostream & operator<<(ostream & s, const Element2d & el); ostream & operator<<(ostream & s, const Element2d & el);
@ -774,7 +755,7 @@ namespace netgen
/// ///
const PointIndex & PNumMod (int i) const { return pnum[(i-1) % np]; } const PointIndex & PNumMod (int i) const { return pnum[(i-1) % np]; }
ngstd::Archive & DoArchive (ngstd::Archive & ar) void DoArchive (Archive & ar)
{ {
short _np, _typ; short _np, _typ;
if (ar.Output()) if (ar.Output())
@ -784,7 +765,6 @@ namespace netgen
{ np = _np; typ = ELEMENT_TYPE(_typ); } { np = _np; typ = ELEMENT_TYPE(_typ); }
for (size_t i = 0; i < np; i++) for (size_t i = 0; i < np; i++)
ar & pnum[i]; ar & pnum[i];
return ar;
} }
/// ///
@ -928,9 +908,6 @@ namespace netgen
int hp_elnr; int hp_elnr;
}; };
inline ngstd::Archive & operator & (ngstd::Archive & archive, Element & mp)
{ return mp.DoArchive(archive); }
ostream & operator<<(ostream & s, const Element & el); ostream & operator<<(ostream & s, const Element & el);
@ -1049,12 +1026,9 @@ namespace netgen
#else #else
int GetPartition () const { return 0; } int GetPartition () const { return 0; }
#endif #endif
ngstd::Archive & DoArchive (ngstd::Archive & ar); void DoArchive (Archive & ar);
}; };
inline ngstd::Archive & operator & (ngstd::Archive & archive, Segment & mp)
{ return mp.DoArchive(archive); }
ostream & operator<<(ostream & s, const Segment & seg); ostream & operator<<(ostream & s, const Segment & seg);
@ -1062,6 +1036,7 @@ namespace netgen
{ {
public: public:
PointIndex pnum; PointIndex pnum;
string name;
int index; int index;
Element0d () = default; Element0d () = default;
Element0d (PointIndex _pnum, int _index) Element0d (PointIndex _pnum, int _index)
@ -1142,13 +1117,9 @@ namespace netgen
// friend ostream & operator<<(ostream & s, const FaceDescriptor & fd); // friend ostream & operator<<(ostream & s, const FaceDescriptor & fd);
friend class Mesh; friend class Mesh;
ngstd::Archive & DoArchive (ngstd::Archive & ar); void DoArchive (Archive & ar);
}; };
inline ngstd::Archive & operator & (ngstd::Archive & archive, FaceDescriptor & mp)
{ return mp.DoArchive(archive); }
ostream & operator<< (ostream & s, const FaceDescriptor & fd); ostream & operator<< (ostream & s, const FaceDescriptor & fd);
@ -1516,12 +1487,8 @@ namespace netgen
DLL_HEADER void Print (ostream & ost) const; DLL_HEADER void Print (ostream & ost) const;
ngstd::Archive & DoArchive (ngstd::Archive & ar); void DoArchive (Archive & ar);
}; };
inline ngstd::Archive & operator & (ngstd::Archive & archive, Identifications & mp)
{ return mp.DoArchive(archive); }
} }

View File

@ -61,6 +61,15 @@ DLL_HEADER void ExportNetgenMeshing(py::module &m)
m.attr("_ngscript") = py::cast(script); m.attr("_ngscript") = py::cast(script);
m.def("_GetStatus", []()
{
MyStr s; double percent;
GetStatus(s, percent);
return py::make_tuple(s.c_str(), percent);
});
m.def("_PushStatus", [](string s) { PushStatus(MyStr(s)); });
m.def("_SetThreadPercentage", [](double percent) { SetThreadPercent(percent); });
py::class_<NGDummyArgument>(m, "NGDummyArgument") py::class_<NGDummyArgument>(m, "NGDummyArgument")
.def("__bool__", []( NGDummyArgument &self ) { return false; } ) .def("__bool__", []( NGDummyArgument &self ) { return false; } )
; ;
@ -263,6 +272,7 @@ DLL_HEADER void ExportNetgenMeshing(py::module &m)
) )
.def("__repr__", &ToString<Element>) .def("__repr__", &ToString<Element>)
.def_property("index", &Element::GetIndex, &Element::SetIndex) .def_property("index", &Element::GetIndex, &Element::SetIndex)
.def_property("curved", &Element::IsCurved, &Element::SetCurved)
.def_property_readonly("vertices", .def_property_readonly("vertices",
FunctionPointer ([](const Element & self) -> py::list FunctionPointer ([](const Element & self) -> py::list
{ {
@ -314,6 +324,7 @@ DLL_HEADER void ExportNetgenMeshing(py::module &m)
"create surface element" "create surface element"
) )
.def_property("index", &Element2d::GetIndex, &Element2d::SetIndex) .def_property("index", &Element2d::GetIndex, &Element2d::SetIndex)
.def_property("curved", &Element2d::IsCurved, &Element2d::SetCurved)
.def_property_readonly("vertices", .def_property_readonly("vertices",
FunctionPointer([](const Element2d & self) -> py::list FunctionPointer([](const Element2d & self) -> py::list
{ {
@ -477,11 +488,12 @@ DLL_HEADER void ExportNetgenMeshing(py::module &m)
auto mesh = make_shared<Mesh>(); auto mesh = make_shared<Mesh>();
mesh -> SetDimension(dim); mesh -> SetDimension(dim);
SetGlobalMesh(mesh); // for visualization SetGlobalMesh(mesh); // for visualization
mesh -> SetGeometry (make_shared<NetgenGeometry>()); mesh -> SetGeometry (nullptr);
return mesh; return mesh;
} ), } ),
py::arg("dim")=3 py::arg("dim")=3
) )
.def(NGSPickle<Mesh>())
/* /*
.def("__init__", .def("__init__",
@ -554,8 +566,6 @@ DLL_HEADER void ExportNetgenMeshing(py::module &m)
break; break;
} }
} }
if (!ng_geometry)
ng_geometry = make_shared<NetgenGeometry>();
self.SetGeometry(ng_geometry); self.SetGeometry(ng_geometry);
delete infile; delete infile;
}),py::call_guard<py::gil_scoped_release>()) }),py::call_guard<py::gil_scoped_release>())

View File

@ -4,13 +4,17 @@ add_library(occ ${NG_LIB_TYPE}
Partition_Loop.cxx Partition_Loop2d.cxx Partition_Loop3d.cxx Partition_Spliter.cxx Partition_Loop.cxx Partition_Loop2d.cxx Partition_Loop3d.cxx Partition_Spliter.cxx
occconstruction.cpp occgenmesh.cpp occgeom.cpp occmeshsurf.cpp python_occ.cpp occconstruction.cpp occgenmesh.cpp occgeom.cpp occmeshsurf.cpp python_occ.cpp
) )
if(USE_GUI)
add_library(occvis ${NG_LIB_TYPE} vsocc.cpp) add_library(occvis ${NG_LIB_TYPE} vsocc.cpp)
endif(USE_GUI)
if(NOT WIN32) if(NOT WIN32)
target_link_libraries( occ ${OCC_LIBRARIES} ${PYTHON_LIBRARIES}) target_link_libraries( occ ${OCC_LIBRARIES} ${PYTHON_LIBRARIES})
install( TARGETS occ ${NG_INSTALL_DIR})
if (USE_GUI)
target_link_libraries( occvis occ ) target_link_libraries( occvis occ )
install( TARGETS occ occvis ${NG_INSTALL_DIR}) install( TARGETS occvis ${NG_INSTALL_DIR})
endif(USE_GUI)
endif(NOT WIN32) endif(NOT WIN32)
install(FILES install(FILES

View File

@ -3,6 +3,7 @@
#include <mystdlib.h> #include <mystdlib.h>
#include <occgeom.hpp> #include <occgeom.hpp>
#include <cstdio>
#include "ShapeAnalysis_ShapeTolerance.hxx" #include "ShapeAnalysis_ShapeTolerance.hxx"
#include "ShapeAnalysis_ShapeContents.hxx" #include "ShapeAnalysis_ShapeContents.hxx"
#include "ShapeAnalysis_CheckSmallFace.hxx" #include "ShapeAnalysis_CheckSmallFace.hxx"
@ -1106,94 +1107,8 @@ void STEP_GetEntityName(const TopoDS_Shape & theShape, STEPCAFControl_Reader * a
// } // }
void LoadOCCInto(OCCGeometry* occgeo, const char* filename)
// Philippose - 23/02/2009
/* Special IGES File load function including the ability
to extract individual surface colours via the extended
OpenCascade XDE and XCAF Feature set.
*/
OCCGeometry *LoadOCC_IGES(const char *filename)
{ {
OCCGeometry *occgeo;
occgeo = new OCCGeometry;
// Initiate a dummy XCAF Application to handle the IGES XCAF Document
static Handle_XCAFApp_Application dummy_app = XCAFApp_Application::GetApplication();
// Create an XCAF Document to contain the IGES file itself
Handle_TDocStd_Document iges_doc;
// Check if a IGES File is already open under this handle, if so, close it to prevent
// Segmentation Faults when trying to create a new document
if(dummy_app->NbDocuments() > 0)
{
dummy_app->GetDocument(1,iges_doc);
dummy_app->Close(iges_doc);
}
dummy_app->NewDocument ("IGES-XCAF",iges_doc);
IGESCAFControl_Reader reader;
Standard_Integer stat = reader.ReadFile((char*)filename);
if(stat != IFSelect_RetDone)
{
delete occgeo;
return NULL;
}
// Enable transfer of colours
reader.SetColorMode(Standard_True);
reader.Transfer(iges_doc);
// Read in the shape(s) and the colours present in the IGES File
Handle_XCAFDoc_ShapeTool iges_shape_contents = XCAFDoc_DocumentTool::ShapeTool(iges_doc->Main());
Handle_XCAFDoc_ColorTool iges_colour_contents = XCAFDoc_DocumentTool::ColorTool(iges_doc->Main());
TDF_LabelSequence iges_shapes;
iges_shape_contents->GetShapes(iges_shapes);
// List out the available colours in the IGES File as Colour Names
TDF_LabelSequence all_colours;
iges_colour_contents->GetColors(all_colours);
PrintMessage(1,"Number of colours in IGES File: ",all_colours.Length());
for(int i = 1; i <= all_colours.Length(); i++)
{
Quantity_Color col;
stringstream col_rgb;
iges_colour_contents->GetColor(all_colours.Value(i),col);
col_rgb << " : (" << col.Red() << "," << col.Green() << "," << col.Blue() << ")";
PrintMessage(1, "Colour [", i, "] = ",col.StringName(col.Name()),col_rgb.str());
}
// For the IGES Reader, all the shapes can be exported as one compound shape
// using the "OneShape" member
occgeo->shape = reader.OneShape();
occgeo->face_colours = iges_colour_contents;
occgeo->changed = 1;
occgeo->BuildFMap();
occgeo->CalcBoundingBox();
PrintContents (occgeo);
return occgeo;
}
// Philippose - 29/01/2009
/* Special STEP File load function including the ability
to extract individual surface colours via the extended
OpenCascade XDE and XCAF Feature set.
*/
OCCGeometry * LoadOCC_STEP (const char * filename)
{
OCCGeometry * occgeo;
occgeo = new OCCGeometry;
// Initiate a dummy XCAF Application to handle the STEP XCAF Document // Initiate a dummy XCAF Application to handle the STEP XCAF Document
static Handle_XCAFApp_Application dummy_app = XCAFApp_Application::GetApplication(); static Handle_XCAFApp_Application dummy_app = XCAFApp_Application::GetApplication();
@ -1219,8 +1134,7 @@ void STEP_GetEntityName(const TopoDS_Shape & theShape, STEPCAFControl_Reader * a
if(stat != IFSelect_RetDone) if(stat != IFSelect_RetDone)
{ {
delete occgeo; throw NgException("Couldn't load OCC geometry");
return NULL;
} }
reader.Transfer(step_doc); reader.Transfer(step_doc);
@ -1287,6 +1201,94 @@ void STEP_GetEntityName(const TopoDS_Shape & theShape, STEPCAFControl_Reader * a
// cout << occgeo->enames[i] << endl; // cout << occgeo->enames[i] << endl;
// cout << " " <<endl; // cout << " " <<endl;
// Gerhard END // Gerhard END
}
// Philippose - 23/02/2009
/* Special IGES File load function including the ability
to extract individual surface colours via the extended
OpenCascade XDE and XCAF Feature set.
*/
OCCGeometry *LoadOCC_IGES(const char *filename)
{
OCCGeometry *occgeo;
occgeo = new OCCGeometry;
// Initiate a dummy XCAF Application to handle the IGES XCAF Document
static Handle_XCAFApp_Application dummy_app = XCAFApp_Application::GetApplication();
// Create an XCAF Document to contain the IGES file itself
Handle_TDocStd_Document iges_doc;
// Check if a IGES File is already open under this handle, if so, close it to prevent
// Segmentation Faults when trying to create a new document
if(dummy_app->NbDocuments() > 0)
{
dummy_app->GetDocument(1,iges_doc);
dummy_app->Close(iges_doc);
}
dummy_app->NewDocument ("IGES-XCAF",iges_doc);
IGESCAFControl_Reader reader;
Standard_Integer stat = reader.ReadFile((char*)filename);
if(stat != IFSelect_RetDone)
{
throw NgException("Couldn't load occ");
}
// Enable transfer of colours
reader.SetColorMode(Standard_True);
reader.Transfer(iges_doc);
// Read in the shape(s) and the colours present in the IGES File
Handle_XCAFDoc_ShapeTool iges_shape_contents = XCAFDoc_DocumentTool::ShapeTool(iges_doc->Main());
Handle_XCAFDoc_ColorTool iges_colour_contents = XCAFDoc_DocumentTool::ColorTool(iges_doc->Main());
TDF_LabelSequence iges_shapes;
iges_shape_contents->GetShapes(iges_shapes);
// List out the available colours in the IGES File as Colour Names
TDF_LabelSequence all_colours;
iges_colour_contents->GetColors(all_colours);
PrintMessage(1,"Number of colours in IGES File: ",all_colours.Length());
for(int i = 1; i <= all_colours.Length(); i++)
{
Quantity_Color col;
stringstream col_rgb;
iges_colour_contents->GetColor(all_colours.Value(i),col);
col_rgb << " : (" << col.Red() << "," << col.Green() << "," << col.Blue() << ")";
PrintMessage(1, "Colour [", i, "] = ",col.StringName(col.Name()),col_rgb.str());
}
// For the IGES Reader, all the shapes can be exported as one compound shape
// using the "OneShape" member
occgeo->shape = reader.OneShape();
occgeo->face_colours = iges_colour_contents;
occgeo->changed = 1;
occgeo->BuildFMap();
occgeo->CalcBoundingBox();
PrintContents (occgeo);
return occgeo;
}
// Philippose - 29/01/2009
/* Special STEP File load function including the ability
to extract individual surface colours via the extended
OpenCascade XDE and XCAF Feature set.
*/
OCCGeometry * LoadOCC_STEP (const char * filename)
{
OCCGeometry * occgeo;
occgeo = new OCCGeometry;
LoadOCCInto(occgeo, filename);
return occgeo; return occgeo;
} }
@ -1355,7 +1357,33 @@ void STEP_GetEntityName(const TopoDS_Shape & theShape, STEPCAFControl_Reader * a
} }
} }
void OCCGeometry :: DoArchive(Archive& ar)
{
if(ar.Output())
{
std::stringstream ss;
STEPControl_Writer writer;
writer.Transfer(shape, STEPControl_AsIs);
auto filename = ".tmpfile_out.step";
writer.Write(filename);
std::ifstream is(filename);
ss << is.rdbuf();
ar << ss.str();
std::remove(filename);
}
else
{
std::string str;
ar & str;
auto filename = ".tmpfile.step";
auto tmpfile = std::fopen(filename, "w");
std::fputs(str.c_str(), tmpfile);
std::fclose(tmpfile);
LoadOCCInto(this, filename);
std::remove(filename);
}
}
const char * shapesname[] = const char * shapesname[] =
{" ", "CompSolids", "Solids", "Shells", {" ", "CompSolids", "Solids", "Shells",

View File

@ -246,6 +246,7 @@ namespace netgen
DLL_HEADER virtual void Save (string filename) const; DLL_HEADER virtual void Save (string filename) const;
void DoArchive(Archive& ar);
DLL_HEADER void BuildFMap(); DLL_HEADER void BuildFMap();

View File

@ -18,6 +18,7 @@ DLL_HEADER void ExportNgOCC(py::module &m)
{ {
py::class_<OCCGeometry, shared_ptr<OCCGeometry>, NetgenGeometry> (m, "OCCGeometry", R"raw_string(Use LoadOCCGeometry to load the geometry from a *.step file.)raw_string") py::class_<OCCGeometry, shared_ptr<OCCGeometry>, NetgenGeometry> (m, "OCCGeometry", R"raw_string(Use LoadOCCGeometry to load the geometry from a *.step file.)raw_string")
.def(py::init<>()) .def(py::init<>())
.def(NGSPickle<OCCGeometry>())
.def("Heal",[](OCCGeometry & self, double tolerance, bool fixsmalledges, bool fixspotstripfaces, bool sewfaces, bool makesolids, bool splitpartitions) .def("Heal",[](OCCGeometry & self, double tolerance, bool fixsmalledges, bool fixspotstripfaces, bool sewfaces, bool makesolids, bool splitpartitions)
{ {
self.tolerance = tolerance; self.tolerance = tolerance;

View File

@ -20,6 +20,7 @@ DLL_HEADER void ExportSTL(py::module & m)
{ {
py::class_<STLGeometry,shared_ptr<STLGeometry>, NetgenGeometry> (m,"STLGeometry") py::class_<STLGeometry,shared_ptr<STLGeometry>, NetgenGeometry> (m,"STLGeometry")
.def(py::init<>()) .def(py::init<>())
.def(NGSPickle<STLGeometry>())
.def("_visualizationData", [](shared_ptr<STLGeometry> stl_geo) .def("_visualizationData", [](shared_ptr<STLGeometry> stl_geo)
{ {
std::vector<float> vertices; std::vector<float> vertices;

View File

@ -3579,5 +3579,5 @@ void STLGeometry :: SmoothGeometry ()
STLInit stlinit; STLInit stlinit;
static RegisterClassForArchive<STLGeometry, NetgenGeometry, STLTopology> stlgeo;
} }

View File

@ -184,6 +184,10 @@ namespace netgen
STLGeometry(); STLGeometry();
virtual ~STLGeometry(); virtual ~STLGeometry();
void DoArchive(Archive& ar)
{
STLTopology::DoArchive(ar);
}
void Clear(); void Clear();

View File

@ -1074,5 +1074,5 @@ void STLTopology :: OrientAfterTrig (int trig)
} }
} }
static RegisterClassForArchive<STLTopology> stltop;
} }

View File

@ -96,6 +96,17 @@ public:
STLTriangle (const int * apts); STLTriangle (const int * apts);
STLTriangle () {pts[0]=0;pts[1]=0;pts[2]=0;} STLTriangle () {pts[0]=0;pts[1]=0;pts[2]=0;}
void DoArchive(Archive& ar)
{
ar.Do(&topedges[0],3);
ar.Do(&nbtrigs[0][0], 6);
ar.Do(&pts[0],3);
ar.Do(&domains[0],2);
size_t i = flags.toperror;
ar & normal & box & center & rad & facenum & i;
flags.toperror = i;
}
int operator[] (int i) const { return pts[i]; } int operator[] (int i) const { return pts[i]; }
int & operator[] (int i) { return pts[i]; } int & operator[] (int i) { return pts[i]; }
@ -280,6 +291,13 @@ public:
void SaveBinary (const char* filename, const char* aname) const; void SaveBinary (const char* filename, const char* aname) const;
void SaveSTLE (const char * filename) const; // stores trigs and edges void SaveSTLE (const char * filename) const; // stores trigs and edges
virtual void DoArchive(Archive& ar)
{
ar & trias & points & boundingbox & pointtol;
if(ar.Input())
FindNeighbourTrigs();
}
virtual void InitSTLGeometry (const Array<STLReadTriangle> & readtrigs); virtual void InitSTLGeometry (const Array<STLReadTriangle> & readtrigs);
virtual void TopologyChanged() {}; //do some things, if topology changed! virtual void TopologyChanged() {}; //do some things, if topology changed!

View File

@ -24,19 +24,13 @@ if(USE_GUI)
add_executable(netgen ngappinit.cpp onetcl.cpp) add_executable(netgen ngappinit.cpp onetcl.cpp)
target_link_libraries( gui PUBLIC nglib ${ZLIB_LIBRARIES} ${JPEG_LIBRARIES} ${FFMPEG_LIBRARIES} ${X11_X11_LIB} ${OCC_LIBRARIES} ) target_link_libraries( gui PUBLIC nglib )
target_link_libraries( gui PRIVATE ${LIBTOGL}) target_link_libraries( gui PRIVATE ${LIBTOGL} ${ZLIB_LIBRARIES} ${JPEG_LIBRARIES} ${FFMPEG_LIBRARIES} ${X11_Xmu_LIB} ${X11_X11_LIB} ${OCC_LIBRARIES} )
if(NOT APPLE)
target_link_libraries( gui PRIVATE ${TCL_LIBRARY} ${TK_LIBRARY})
endif(NOT APPLE)
target_link_libraries( netgen nglib gui ) target_link_libraries( netgen nglib gui ${LIBTOGL} ${ZLIB_LIBRARIES} ${JPEG_LIBRARIES} ${FFMPEG_LIBRARIES} ${X11_Xmu_LIB} ${X11_X11_LIB} ${OCC_LIBRARIES} ${TK_LIBRARY} ${TCL_LIBRARY})
if(APPLE)
# Leave decision about which tcl/tk version to use open to python (and it's tkinter package).
# Thus, only link tcl/tk to the netgen executable and not to the gui library.
target_link_libraries( netgen ${TK_LIBRARY} ${TCL_LIBRARY})
else(APPLE)
# On other systems assume that the found libraries are compatible with python/tkinter
target_link_libraries( gui PUBLIC ${TK_LIBRARY} ${TCL_LIBRARY})
endif(APPLE)
if(NOT WIN32) if(NOT WIN32)
target_link_libraries( netgen mesh stlvis stl geom2dvis interface geom2d csg stl visual csgvis ) target_link_libraries( netgen mesh stlvis stl geom2dvis interface geom2d csg stl visual csgvis )
@ -57,7 +51,7 @@ endif(USE_GUI)
if(USE_PYTHON) if(USE_PYTHON)
add_library(ngpy SHARED netgenpy.cpp) add_library(ngpy SHARED netgenpy.cpp)
target_link_libraries( ngpy nglib ) target_link_libraries( ngpy PUBLIC nglib PRIVATE ${PYTHON_LIBRARIES})
if(APPLE) if(APPLE)
set_target_properties( ngpy PROPERTIES SUFFIX ".so") set_target_properties( ngpy PROPERTIES SUFFIX ".so")
elseif(WIN32) elseif(WIN32)

View File

@ -2009,7 +2009,7 @@ proc surfacemeshsizedialog { } {
frame $w.face -borderwidth 3 frame $w.face -borderwidth 3
pack $w.face -fill x -padx 5 pack $w.face -fill x -padx 5
ttk::label $w.face.lab -text "face index:" ttk::label $w.face.lab -text "face index:"
ttk::label $w.face.ent -text 1 -padx 4 ttk::label $w.face.ent -text 1
ttk::button $w.face.next -text "next" -command { ttk::button $w.face.next -text "next" -command {
set w .surfacemeshsize_dlg; set w .surfacemeshsize_dlg;
set facenr [$w.face.ent cget -text] set facenr [$w.face.ent cget -text]

View File

@ -2687,7 +2687,7 @@ const char * ngscript[] = {""
,"frame $w.face -borderwidth 3\n" ,"frame $w.face -borderwidth 3\n"
,"pack $w.face -fill x -padx 5\n" ,"pack $w.face -fill x -padx 5\n"
,"ttk::label $w.face.lab -text \"face index:\"\n" ,"ttk::label $w.face.lab -text \"face index:\"\n"
,"ttk::label $w.face.ent -text 1 -padx 4\n" ,"ttk::label $w.face.ent -text 1\n"
,"ttk::button $w.face.next -text \"next\" -command {\n" ,"ttk::button $w.face.next -text \"next\" -command {\n"
,"set w .surfacemeshsize_dlg;\n" ,"set w .surfacemeshsize_dlg;\n"
,"set facenr [$w.face.ent cget -text]\n" ,"set facenr [$w.face.ent cget -text]\n"

View File

@ -26,20 +26,22 @@ endif(WIN32)
add_library(nglib SHARED nglib.cpp ${nglib_objects}) add_library(nglib SHARED nglib.cpp ${nglib_objects})
if(NOT WIN32) if(NOT WIN32)
target_link_libraries( nglib mesh stl interface geom2d csg stl visual) target_link_libraries( nglib PUBLIC mesh stl interface geom2d csg stl visual)
if(USE_GUI) if(USE_GUI)
target_link_libraries( nglib stlvis geom2dvis csgvis ) target_link_libraries( nglib PUBLIC stlvis geom2dvis csgvis )
endif(USE_GUI) endif(USE_GUI)
endif(NOT WIN32) endif(NOT WIN32)
target_link_libraries( nglib ${OCC_LIBRARIES} ${MPI_CXX_LIBRARIES} ${OPENGL_LIBRARIES} ${CMAKE_THREAD_LIBS_INIT} ${X11_Xmu_LIB} ${JPEG_LIBRARIES} ${MKL_LIBRARIES} ${ZLIB_LIBRARIES} ${OCC_LIBRARIES} ) target_link_libraries(nglib PUBLIC ngcore)
target_link_libraries( nglib PRIVATE ${OCC_LIBRARIES} ${MPI_CXX_LIBRARIES} ${OPENGL_LIBRARIES} ${CMAKE_THREAD_LIBS_INIT} ${X11_Xmu_LIB} ${JPEG_LIBRARIES} ${MKL_LIBRARIES} ${ZLIB_LIBRARIES} ${OCC_LIBRARIES} )
if(USE_OCC AND NOT WIN32) if(USE_OCC AND NOT WIN32)
target_link_libraries(nglib occ) target_link_libraries(nglib PUBLIC occ)
endif(USE_OCC AND NOT WIN32) endif(USE_OCC AND NOT WIN32)
if(USE_PYTHON) if(USE_PYTHON)
target_link_libraries(nglib ${PYTHON_LIBRARIES}) target_link_libraries(nglib PRIVATE ${PYTHON_LIBRARIES})
endif(USE_PYTHON) endif(USE_PYTHON)
install(TARGETS nglib ${NG_INSTALL_DIR}) install(TARGETS nglib ${NG_INSTALL_DIR})

View File

@ -11,5 +11,12 @@ def StartGUI():
win.tk.eval('load "'+netgen._netgen_lib_dir.replace('\\','/')+'/libgui[info sharedlibextension]" gui') win.tk.eval('load "'+netgen._netgen_lib_dir.replace('\\','/')+'/libgui[info sharedlibextension]" gui')
win.tk.eval( netgen.libngpy._meshing._ngscript) win.tk.eval( netgen.libngpy._meshing._ngscript)
try:
from IPython import get_ipython
ipython = get_ipython()
ipython.magic('gui tk')
except:
pass
if not netgen.libngpy._meshing._netgen_executable_started: if not netgen.libngpy._meshing._netgen_executable_started:
StartGUI() StartGUI()

View File

@ -1 +1,2 @@
add_subdirectory(catch)
add_subdirectory(pytest) add_subdirectory(pytest)

View File

@ -0,0 +1,8 @@
cd
mkdir -p build/netgen
cd build/netgen
cmake ../../src/netgen -DUSE_CCACHE=ON -DENABLE_CPP_CORE_GUIDELINES_CHECK=ON -DCMAKE_CXX_COMPILER=clang++ \
-DCMAKE_C_COMPILER=clang
make -j12
make install

View File

@ -0,0 +1,37 @@
if(ENABLE_UNIT_TESTS)
add_custom_target(unit_tests)
# Build catch_main test object
message("netgen include dir = ${NETGEN_INCLUDE_DIR_ABSOLUTE} --------------------------------------")
include_directories(${CATCH_INCLUDE_DIR} ${CMAKE_CURRENT_SOURCE_DIR}/../../libsrc/include})
add_library(catch_main STATIC main.cpp)
set_target_properties(catch_main PROPERTIES CXX_STANDARD 17)
add_dependencies(unit_tests catch_main)
add_dependencies(catch_main project_catch)
# ensure the test targets are built before testing
add_test(NAME unit_tests_built COMMAND ${CMAKE_COMMAND} --build . --target unit_tests --config ${CMAKE_BUILD_TYPE} WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/../.. )
macro(add_unit_test name sources)
add_executable(test_${name} ${sources} )
if (WIN32)
target_link_libraries(test_${name} ngcore catch_main)
else(WIN32)
target_link_libraries(test_${name} ngcore catch_main)
endif(WIN32)
add_dependencies(unit_tests test_${name})
add_test(NAME unit_${name} COMMAND test_${name})
set_tests_properties(unit_${name} PROPERTIES DEPENDS unit_tests_built)
endmacro()
add_unit_test(archive archive.cpp)
add_unit_test(version version.cpp)
if(ENABLE_CPP_CORE_GUIDELINES_CHECK)
set_target_properties(test_archive PROPERTIES CXX_CLANG_TIDY "${DO_CLANG_TIDY}")
set_target_properties(test_version PROPERTIES CXX_CLANG_TIDY "${DO_CLANG_TIDY}")
endif(ENABLE_CPP_CORE_GUIDELINES_CHECK)
endif(ENABLE_UNIT_TESTS)

306
tests/catch/archive.cpp Normal file
View File

@ -0,0 +1,306 @@
#include "catch.hpp"
#include <../core/ngcore.hpp>
using namespace ngcore;
using namespace std;
class CommonBase
{
public:
int a;
virtual ~CommonBase() {}
virtual void DoArchive(Archive& archive) { archive & a; }
};
// pure abstract base class
class SharedPtrHolder : virtual public CommonBase
{
public:
vector<shared_ptr<string>> names;
virtual ~SharedPtrHolder()
{ }
virtual void abstract() = 0;
virtual void DoArchive(Archive& archive)
{
CommonBase::DoArchive(archive);
archive & names;
}
};
class PtrHolder : virtual public CommonBase
{
public:
vector<int*> numbers;
virtual ~PtrHolder() {}
virtual void DoArchive(Archive& archive)
{
CommonBase::DoArchive(archive);
archive & numbers;
}
};
class SharedPtrAndPtrHolder : public SharedPtrHolder, public PtrHolder
{
public:
virtual ~SharedPtrAndPtrHolder() {}
virtual void DoArchive(Archive& archive)
{
SharedPtrHolder::DoArchive(archive);
PtrHolder::DoArchive(archive);
}
virtual void abstract() {}
};
// Classes without virt. or multiple inheritance do not need to be registered
class SimpleClass : public CommonBase
{
public:
double d;
virtual void DoArchive(Archive& ar)
{
CommonBase::DoArchive(ar);
ar & d;
}
};
class NotRegisteredForArchive : public SharedPtrAndPtrHolder {};
class ClassWithConstPtr
{
private:
const int* ptr;
public:
ClassWithConstPtr(const int* aptr) : ptr(aptr) { }
// constructor only for archive
ClassWithConstPtr() {}
void DoArchive(Archive& ar)
{
ar & ptr;
}
const int* getPtr() { return ptr; }
};
class OneMoreDerivedClass : public SharedPtrAndPtrHolder {};
static RegisterClassForArchive<CommonBase> regb;
static RegisterClassForArchive<SharedPtrHolder, CommonBase> regsp;
static RegisterClassForArchive<PtrHolder, CommonBase> regp;
static RegisterClassForArchive<SharedPtrAndPtrHolder, SharedPtrHolder, PtrHolder> regspp;
static RegisterClassForArchive<OneMoreDerivedClass, SharedPtrAndPtrHolder> regom;
void testNullPtr(Archive& in, Archive& out)
{
SharedPtrHolder* p = nullptr;
shared_ptr<string> sp = nullptr;
out & p & sp;
out.FlushBuffer();
SharedPtrHolder* pin = nullptr;
shared_ptr<string> spin = nullptr;
in & pin & spin;
CHECK(pin == nullptr);
CHECK(spin == nullptr);
}
void testSharedPointer(Archive& in, Archive& out)
{
SECTION("Same shared ptr")
{
static_assert(detail::has_DoArchive<SharedPtrHolder>::value, "");
SharedPtrAndPtrHolder holder, holder2;
holder.names.push_back(make_shared<string>("name"));
holder2.names = holder.names; // same shared ptr
out & holder & holder2;
out.FlushBuffer();
SharedPtrAndPtrHolder inholder, inholder2;
in & inholder & inholder2;
CHECK(inholder.names.size() == 1);
CHECK(inholder.names[0] == inholder2.names[0]);
CHECK(inholder.names[0].use_count() == 3); // one shared ptr is still kept in the archive
CHECK(*inholder.names[0] == "name");
}
}
void testPointer(Archive& in, Archive& out)
{
PtrHolder holder, holder2;
holder.numbers.push_back(new int(3));
holder2.numbers = holder.numbers; // same shared ptr
out & holder & holder2;
out.FlushBuffer();
PtrHolder inholder, inholder2;
in & inholder & inholder2;
CHECK(inholder.numbers.size() == 1);
CHECK(inholder.numbers[0] == inholder2.numbers[0]);
CHECK(*inholder.numbers[0] == 3);
}
void testConstPointer(Archive& in, Archive& out)
{
SECTION("Const pointer")
{
int* iptr = new int(4);
double d = 0.1;
ClassWithConstPtr cls(iptr);
out & cls & iptr & d;
out.FlushBuffer();
ClassWithConstPtr incls;
int* iniptr;
double ind;
in & incls & iniptr & ind;
CHECK(*incls.getPtr() == 4);
CHECK(incls.getPtr() == iniptr);
CHECK(ind == 0.1);
delete iptr;
delete iniptr;
}
}
void testMultipleInheritance(Archive& in, Archive& out)
{
PtrHolder* p = new OneMoreDerivedClass;
p->numbers.push_back(new int(2));
p->a = 5;
auto p2 = dynamic_cast<SharedPtrHolder*>(p);
p2->names.push_back(make_shared<string>("test"));
auto sp1 = shared_ptr<PtrHolder>(p);
auto sp2 = dynamic_pointer_cast<SharedPtrHolder>(sp1);
auto checkPtr = [] (auto pin, auto pin2)
{
CHECK(typeid(*pin) == typeid(*pin2));
CHECK(typeid(*pin) == typeid(OneMoreDerivedClass));
CHECK(*pin2->names[0] == "test");
CHECK(*pin->numbers[0] == 2);
CHECK(dynamic_cast<SharedPtrAndPtrHolder*>(pin) == dynamic_cast<SharedPtrAndPtrHolder*>(pin2));
CHECK(pin->a == pin2->a);
CHECK(pin->a == 5);
REQUIRE(dynamic_cast<SharedPtrAndPtrHolder*>(pin2) != nullptr);
CHECK(*dynamic_cast<SharedPtrAndPtrHolder*>(pin2)->numbers[0] == 2);
CHECK(*pin->numbers[0] == *dynamic_cast<SharedPtrAndPtrHolder*>(pin2)->numbers[0]);
REQUIRE(dynamic_cast<SharedPtrAndPtrHolder*>(pin) != nullptr);
CHECK(dynamic_cast<SharedPtrAndPtrHolder*>(pin)->names[0] == pin2->names[0]);
};
SECTION("Archive ptrs to leaves of mult. inh.")
{
out & p & p2;
out.FlushBuffer();
PtrHolder* pin = nullptr;
SharedPtrHolder* pin2 = nullptr;
in & pin & pin2;
checkPtr(pin, pin2);
}
SECTION("Archive shared ptrs to leaves of mult. inh.")
{
out & sp1 & sp2;
out.FlushBuffer();
shared_ptr<PtrHolder> pin;
shared_ptr<SharedPtrHolder> pin2;
in & pin & pin2;
checkPtr(pin.get(), pin2.get());
}
SECTION("Virtual base class")
{
CommonBase* b = dynamic_cast<CommonBase*>(p);
out & b & p;
PtrHolder* pin;
CommonBase* bin;
in & bin & pin;
checkPtr(pin, dynamic_cast<SharedPtrHolder*>(bin));
}
SECTION("Simple class without register")
{
auto a = new SimpleClass;
a->a = 5;
a->d = 2.3;
SECTION("check pointer")
{
out & a;
out.FlushBuffer();
SimpleClass* ain;
in & ain;
CHECK(ain->a == 5);
CHECK(ain->d == 2.3);
}
SECTION("check shared pointer")
{
auto spa = shared_ptr<SimpleClass>(a);
out & spa;
out.FlushBuffer();
shared_ptr<SimpleClass> spain;
in & spain;
CHECK(spain->a == 5);
CHECK(spain->d == 2.3);
}
}
}
void testArchive(Archive& in, Archive& out)
{
SECTION("Empty String")
{
char* cstr = nullptr;
char* empty = new char[1];
char* simple = new char[7] {'s','i','m','p','l','e','\0'};
empty[0] = '\0';
out << string("") << cstr << empty << simple << string("simple") << long(1);
out.FlushBuffer();
string str; long i; char* readempty; char* readsimple;
string simplestr;
in & str & cstr & readempty & readsimple & simplestr & i;
CHECK(str == "");
CHECK(cstr == nullptr);
CHECK(strcmp(readempty,"") == 0);
CHECK(strcmp(readsimple,"simple") == 0);
CHECK(i == 1);
CHECK(simplestr == "simple");
delete[] readempty;
delete[] empty;
delete[] simple;
delete[] readsimple;
}
SECTION("SharedPtr")
{
testSharedPointer(in, out);
}
SECTION("Pointer")
{
testPointer(in, out);
}
SECTION("Const Pointer")
{
testConstPointer(in, out);
}
SECTION("Multiple inheritance")
{
testMultipleInheritance(in, out);
}
SECTION("Not registered")
{
SharedPtrAndPtrHolder* p = new NotRegisteredForArchive;
REQUIRE_THROWS(out & p, Catch::Contains("not registered for archive"));
}
SECTION("nullptr")
{
testNullPtr(in, out);
}
}
TEST_CASE("BinaryArchive")
{
SetLibraryVersion("netgen","v6.2.1811");
auto stream = make_shared<stringstream>();
BinaryOutArchive out(stream);
BinaryInArchive in(stream);
testArchive(in, out);
}
TEST_CASE("TextArchive")
{
SetLibraryVersion("netgen","v6.2.1811");
auto stream = make_shared<stringstream>();
TextOutArchive out(stream);
TextInArchive in(stream);
testArchive(in, out);
}

3
tests/catch/main.cpp Normal file
View File

@ -0,0 +1,3 @@
#define CATCH_CONFIG_MAIN
#include <catch.hpp>

19
tests/catch/version.cpp Normal file
View File

@ -0,0 +1,19 @@
#include "catch.hpp"
#include <../core/ngcore.hpp>
using namespace ngcore;
using namespace std;
TEST_CASE("Version")
{
VersionInfo v("v6.2.1811-3-asdf");
CHECK(v.to_string() == "v6.2.1811-3-asdf");
VersionInfo v2("6.2");
CHECK(v2.to_string() == "v6.2");
CHECK(v < "v7");
CHECK(v >= "6.2");
CHECK(v > "6.2.1811");
CHECK(v < "6.2.1811-5");
CHECK(v == "v6.2.1811-3");
}

View File

@ -1,4 +0,0 @@
FROM ubuntu:16.04
MAINTAINER Matthias Hochsteger <matthias.hochsteger@tuwien.ac.at>
RUN apt-get update && apt-get -y install python3 libpython3-dev libxmu-dev tk-dev tcl-dev cmake git g++ libglu1-mesa-dev ccache python3-pytest python3-numpy python3-tk
ADD . /root/src/netgen

View File

@ -1,4 +1,5 @@
FROM ubuntu:15.10 FROM ubuntu:18.04
ENV DEBIAN_FRONTEND=noninteractive
MAINTAINER Matthias Hochsteger <matthias.hochsteger@tuwien.ac.at> MAINTAINER Matthias Hochsteger <matthias.hochsteger@tuwien.ac.at>
RUN apt-get update && apt-get -y install python3 libpython3-dev libxmu-dev tk-dev tcl-dev cmake git g++ libglu1-mesa-dev ccache python3-pytest python3-numpy python3-tk RUN apt-get update && apt-get -y install python3 libpython3-dev libxmu-dev tk-dev tcl-dev cmake git g++ libglu1-mesa-dev ccache python3-pytest python3-numpy python3-tk clang-tidy python3-distutils clang
ADD . /root/src/netgen ADD . /root/src/netgen

View File

@ -0,0 +1,105 @@
import pickle, numpy
def test_pickle_csg():
import netgen.csg as csg
geo = csg.CSGeometry()
geo.Add(csg.Sphere(csg.Pnt(0,0,0), 2).bc("sphere"))
brick = csg.OrthoBrick(csg.Pnt(-3,-3,-3), csg.Pnt(3,3,3))
geo.Add(csg.Cylinder(csg.Pnt(0,0,0), csg.Pnt(1,0,0), 0.5) * brick)
geo.Add(csg.Ellipsoid(csg.Pnt(0,0,0), csg.Vec(1,0,0), csg.Vec(0,1,0), csg.Vec(0,0,0.5)))
geo.Add(csg.Cone(csg.Pnt(0,0,0), csg.Pnt(3,0,0), 1, 0.5) * brick)
geo.Add(csg.EllipticCone(csg.Pnt(0,0,0), csg.Vec(2,0,0), csg.Vec(0,1,0), 3, 0.5) * brick)
geo.Add(csg.Torus(csg.Pnt(0,0,0), csg.Vec(0,1,0), 0.3, 0.05))
pts2d = [[1,1], [1,-1], [-1,-1], [-1,1]]
segs = [[0,1], [1,2], [2,3], [3,0]]
curve = csg.SplineCurve2d()
pnrs = [curve.AddPoint(*p) for p in pts2d]
for s in segs:
curve.AddSegment(pnrs[s[0]], pnrs[s[1]])
geo.Add(csg.Revolution(csg.Pnt(0,0,0), csg.Pnt(1,0,0), curve))
path = csg.SplineCurve3d()
pnts = [(0,0,0), (2,0,0), (2,2,0)]
segs = [(0,1,2)]
for pnt in pnts:
path.AddPoint (*pnt)
for seg in segs:
path.AddSegment (*seg)
geo.Add(csg.Extrusion(path, curve, csg.Vec(0,0,1)))
geo_dump = pickle.dumps(geo)
geo2 = pickle.loads(geo_dump)
vd1 = geo._visualizationData()
vd2 = geo2._visualizationData()
for val1, val2 in zip(vd1.values(), vd2.values()):
assert numpy.array_equal(val1, val2)
def test_pickle_stl():
import netgen.stl as stl
geo = stl.LoadSTLGeometry("../../tutorials/hinge.stl")
geo_dump = pickle.dumps(geo)
geo2 = pickle.loads(geo_dump)
vd1 = geo._visualizationData()
vd2 = geo2._visualizationData()
for val1, val2 in zip(vd1.values(), vd2.values()):
assert numpy.array_equal(val1, val2)
def test_pickle_occ():
try:
import netgen.NgOCC as occ
except:
import pytest
pytest.skip("can't import occ")
geo = occ.LoadOCCGeometry("../../tutorials/frame.step")
geo_dump = pickle.dumps(geo)
geo2 = pickle.loads(geo_dump)
vd1 = geo._visualizationData()
vd2 = geo2._visualizationData()
# TODO: it looks fine, but tests fail, so I assume we loose some info?
# for val1, val2 in zip(vd1.values(), vd2.values()):
# assert numpy.allclose(val1, val2, rtol=0.01)
def test_pickle_geom2d():
import netgen.geom2d as geom2d
geo = geom2d.SplineGeometry()
# point coordinates ...
pnts = [ (0,0), (1,0), (1,0.6), (0,0.6), \
(0.2,0.6), (0.8,0.6), (0.8,0.8), (0.2,0.8), \
(0.5,0.15), (0.65,0.3), (0.5,0.45), (0.35,0.3) ]
pnums = [geo.AppendPoint(*p) for p in pnts]
# start-point, end-point, boundary-condition, domain on left side, domain on right side:
lines = [ (0,1,1,1,0), (1,2,2,1,0), (2,5,2,1,0), (5,4,2,1,2), (4,3,2,1,0), (3,0,2,1,0), \
(5,6,2,2,0), (6,7,2,2,0), (7,4,2,2,0), \
(8,9,2,3,1), (9,10,2,3,1), (10,11,2,3,1), (11,8,2,3,1) ]
for p1,p2,bc,left,right in lines:
geo.Append( ["line", pnums[p1], pnums[p2]], bc=bc, leftdomain=left, rightdomain=right)
geo_dump = pickle.dumps(geo)
geo2 = pickle.loads(geo_dump)
vd1 = geo._visualizationData()
vd2 = geo2._visualizationData()
for val1, val2 in zip(vd1.values(), vd2.values()):
assert numpy.array_equal(val1, val2)
def test_pickle_mesh():
import netgen.csg as csg
geo = csg.CSGeometry()
brick = csg.OrthoBrick(csg.Pnt(-3,-3,-3), csg.Pnt(3,3,3))
mesh = geo.GenerateMesh(maxh=0.2)
assert geo == mesh.GetGeometry()
dump = pickle.dumps([geo,mesh])
geo2, mesh2 = pickle.loads(dump)
assert geo2 == mesh2.GetGeometry()
mesh.Save("msh1.vol.gz")
mesh2.Save("msh2.vol.gz")
import filecmp, os
assert filecmp.cmp("msh1.vol.gz", "msh2.vol.gz")
os.remove("msh1.vol.gz")
os.remove("msh2.vol.gz")
if __name__ == "__main__":
test_pickle_mesh()