From 9cf2f80c8382638990cad93d9ee53373e9b62292 Mon Sep 17 00:00:00 2001 From: Jan Behrens Date: Mon, 24 Aug 2020 06:20:07 -0700 Subject: [PATCH] Update to Kassiopeia 3.7.6 * Build fixes (update FindFFTW) * Add `CurrentTurns` field to KGElectromagnet * Fix segfault in KGComplexAnnulus --- CMakeLists.txt | 2 +- .../KGeoBag/include/KGElectromagnetBuilder.hh | 9 +- .../KGeoBag/src/KGElectromagnetBuilder.cc | 10 +- .../KGeoBag/include/KGElectromagnet.hh | 21 ++-- .../Interface/KGeoBag/src/KGElectromagnet.cc | 23 +++- .../KGeoBag/src/KGElectromagnetConverter.cc | 10 +- .../Shapes/Complex/Source/KGComplexAnnulus.cc | 5 + Kommon/cmake/FindFFTW.cmake | 101 ++++++++++-------- 8 files changed, 119 insertions(+), 62 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 39ae14d74..fa20ebf81 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -229,7 +229,7 @@ endif() #add_subdirectory( Documentation ) -install( EXPORT KasperTargets DESTINATION ${CMAKE_INSTALL_DIR}/${PROJECT_NAME} ) +install( EXPORT KasperTargets DESTINATION ${CMAKE_INSTALL_DIR}/{PROJECT_NAME} ) configure_file( kasperenv.sh.in ${CMAKE_CURRENT_BINARY_DIR}/kasperenv.sh @ONLY ) configure_file( create_kasper_user_directory.sh.in ${CMAKE_CURRENT_BINARY_DIR}/create_kasper_user_directory.sh @ONLY ) diff --git a/KEMField/Source/Bindings/KGeoBag/include/KGElectromagnetBuilder.hh b/KEMField/Source/Bindings/KGeoBag/include/KGElectromagnetBuilder.hh index 3a2cdd5a6..e687140e8 100644 --- a/KEMField/Source/Bindings/KGeoBag/include/KGElectromagnetBuilder.hh +++ b/KEMField/Source/Bindings/KGeoBag/include/KGElectromagnetBuilder.hh @@ -21,7 +21,7 @@ class KGElectromagnetAttributor : public KTagged, public KGElectromagnetData std::vector fSurfaces; std::vector fSpaces; K_SET_GET(double, LineCurrent) - K_SET_GET(double, ScalingFactor) + K_SET_GET(double, CurrentTurns) K_SET_GET(double, Direction) }; @@ -47,8 +47,8 @@ template<> inline bool KGElectromagnetBuilder::AddAttribute(KContainer* aContain fObject->SetLineCurrent(aContainer->AsReference()); return true; } - if (aContainer->GetName() == "scaling_factor") { - fObject->SetScalingFactor(aContainer->AsReference()); + if (aContainer->GetName() == "scaling_factor" || aContainer->GetName() == "num_turns") { + fObject->SetCurrentTurns(aContainer->AsReference()); return true; } if (aContainer->GetName() == "direction") { @@ -101,7 +101,8 @@ template<> inline bool KGElectromagnetBuilder::AddAttribute(KContainer* aContain template<> inline bool KGElectromagnetBuilder::End() { - fObject->SetCurrent(fObject->GetLineCurrent() * fObject->GetScalingFactor() * fObject->GetDirection()); + fObject->SetLineCurrent(fObject->GetLineCurrent() * fObject->GetDirection()); + fObject->SetCurrentTurns(fObject->GetCurrentTurns()); return true; } diff --git a/KEMField/Source/Bindings/KGeoBag/src/KGElectromagnetBuilder.cc b/KEMField/Source/Bindings/KGeoBag/src/KGElectromagnetBuilder.cc index aa6551351..f29877586 100644 --- a/KEMField/Source/Bindings/KGeoBag/src/KGElectromagnetBuilder.cc +++ b/KEMField/Source/Bindings/KGeoBag/src/KGElectromagnetBuilder.cc @@ -10,7 +10,7 @@ KGElectromagnetAttributor::KGElectromagnetAttributor() : fSurfaces(), fSpaces(), fLineCurrent(0.0), - fScalingFactor(1.0), + fCurrentTurns(1.0), fDirection(1.0) {} @@ -21,14 +21,16 @@ KGElectromagnetAttributor::~KGElectromagnetAttributor() tElectromagnetSurface = (*tIt)->MakeExtension(); tElectromagnetSurface->SetName(GetName()); tElectromagnetSurface->SetTags(GetTags()); - tElectromagnetSurface->SetCurrent(GetCurrent()); + tElectromagnetSurface->SetLineCurrent(GetLineCurrent()); + tElectromagnetSurface->SetCurrentTurns(GetCurrentTurns()); } KGElectromagnetSpace* tElectromagnetSpace; for (auto tIt = fSpaces.begin(); tIt != fSpaces.end(); tIt++) { tElectromagnetSpace = (*tIt)->MakeExtension(); tElectromagnetSpace->SetName(GetName()); tElectromagnetSpace->SetTags(GetTags()); - tElectromagnetSpace->SetCurrent(GetCurrent()); + tElectromagnetSpace->SetLineCurrent(GetLineCurrent()); + tElectromagnetSpace->SetCurrentTurns(GetCurrentTurns()); } } @@ -54,7 +56,7 @@ template<> inline KGElectromagnetBuilder::~KComplexElement() {} STATICINT sKGElectromagnetStructure = KGElectromagnetBuilder::Attribute("name") + KGElectromagnetBuilder::Attribute("current") + - KGElectromagnetBuilder::Attribute("scaling_factor") + + KGElectromagnetBuilder::Attribute("scaling_factor") + KGElectromagnetBuilder::Attribute("num_turns") + KGElectromagnetBuilder::Attribute("direction") + KGElectromagnetBuilder::Attribute("surfaces") + KGElectromagnetBuilder::Attribute("spaces"); diff --git a/KEMField/Source/Interface/KGeoBag/include/KGElectromagnet.hh b/KEMField/Source/Interface/KGeoBag/include/KGElectromagnet.hh index 121a9d995..d585fc78e 100644 --- a/KEMField/Source/Interface/KGeoBag/include/KGElectromagnet.hh +++ b/KEMField/Source/Interface/KGeoBag/include/KGElectromagnet.hh @@ -24,19 +24,26 @@ namespace KGeoBag class KGElectromagnetData { public: - KGElectromagnetData() : fCurrent(0.) {} - KGElectromagnetData(KGSpace*) : fCurrent(0.) {} - KGElectromagnetData(KGSurface*) : fCurrent(0.) {} - KGElectromagnetData(KGSpace*, const KGElectromagnetData& aCopy) : fCurrent(aCopy.fCurrent) {} - KGElectromagnetData(KGSurface*, const KGElectromagnetData& aCopy) : fCurrent(aCopy.fCurrent) {} + KGElectromagnetData() : fLineCurrent(0.), fCurrentTurns(1) {} + KGElectromagnetData(KGSpace*) : fLineCurrent(0.), fCurrentTurns(1) {} + KGElectromagnetData(KGSurface*) : fLineCurrent(0.), fCurrentTurns(1) {} + KGElectromagnetData(KGSpace*, const KGElectromagnetData& aCopy) : fLineCurrent(aCopy.fLineCurrent), fCurrentTurns(aCopy.fCurrentTurns) {} + KGElectromagnetData(KGSurface*, const KGElectromagnetData& aCopy) : fLineCurrent(aCopy.fLineCurrent), fCurrentTurns(aCopy.fCurrentTurns) {} virtual ~KGElectromagnetData() {} void SetCurrent(double d); double GetCurrent() const; - private: - double fCurrent; + void SetCurrentTurns(double d); + double GetCurrentTurns() const; + + void SetLineCurrent(double d); + double GetLineCurrent() const; + +private: + double fLineCurrent; + double fCurrentTurns; }; class KGElectromagnet diff --git a/KEMField/Source/Interface/KGeoBag/src/KGElectromagnet.cc b/KEMField/Source/Interface/KGeoBag/src/KGElectromagnet.cc index 291d661b4..227a55d75 100644 --- a/KEMField/Source/Interface/KGeoBag/src/KGElectromagnet.cc +++ b/KEMField/Source/Interface/KGeoBag/src/KGElectromagnet.cc @@ -4,11 +4,30 @@ namespace KGeoBag { void KGElectromagnetData::SetCurrent(double d) { - fCurrent = d; + fLineCurrent = d; + fCurrentTurns = 1; } double KGElectromagnetData::GetCurrent() const { - return fCurrent; + return fLineCurrent * fCurrentTurns; +} + +void KGElectromagnetData::SetCurrentTurns(double d) +{ + fCurrentTurns = d; +} +double KGElectromagnetData::GetCurrentTurns() const +{ + return fCurrentTurns; +} + +void KGElectromagnetData::SetLineCurrent(double d) +{ + fLineCurrent = d; +} +double KGElectromagnetData::GetLineCurrent() const +{ + return fLineCurrent; } } // namespace KGeoBag diff --git a/KEMField/Source/Interface/KGeoBag/src/KGElectromagnetConverter.cc b/KEMField/Source/Interface/KGeoBag/src/KGElectromagnetConverter.cc index f7774675a..c3c08e066 100644 --- a/KEMField/Source/Interface/KGeoBag/src/KGElectromagnetConverter.cc +++ b/KEMField/Source/Interface/KGeoBag/src/KGElectromagnetConverter.cc @@ -96,7 +96,7 @@ void KGElectromagnetConverter::VisitSpace(KGSpace* aSpace) Clear(); #ifdef PRINT_MAGFIELD3 - std::cout << "# " << aSpace->GetPath() << std::endl; + //std::cout << "# " << aSpace->GetPath() << std::endl; #endif fCurrentOrigin = aSpace->GetOrigin(); @@ -163,6 +163,8 @@ void KGElectromagnetConverter::VisitCylinderSurface(KGCylinderSurface* cylinder) double tZMin = cylinder->Z1() > cylinder->Z2() ? cylinder->Z2() : cylinder->Z1(); double tZMax = cylinder->Z1() > cylinder->Z2() ? cylinder->Z1() : cylinder->Z2(); double tCurrent = fCurrentElectromagnetSurface->GetCurrent(); + //double tNumTurns = fCurrentElectromagnetSurface->GetCurrentTurns(); + auto* solenoid = new KSolenoid(); solenoid->SetValues(tR, tZMin, tZMax, tCurrent); @@ -198,9 +200,13 @@ void KGElectromagnetConverter::VisitCylinderTubeSpace(KGCylinderTubeSpace* cylin auto p0 = coil->GetCoordinateSystem().ToGlobal(KPosition(0, 0, tZMin)); auto p1 = coil->GetCoordinateSystem().ToGlobal(KPosition(0, 0, tZMax)); + double tLineCurrent = fCurrentElectromagnetSpace->GetLineCurrent(); + double tNumTurns = fCurrentElectromagnetSpace->GetCurrentTurns(); + std::string tName = fCurrentElectromagnetSpace->GetName(); + std::cout << " " << coil->GetCurrentDensity() << " " << p0.X() << " " << p0.Y() << " " << p0.Z() << " " << p1.X() << " " << p1.Y() << " " << p1.Z() << " " << coil->GetR0() << " " << coil->GetR1() << " " - << coil->GetIntegrationScale() << std::endl; + << coil->GetIntegrationScale() << " " << tLineCurrent << " " << tNumTurns << "\t# " << tName << std::endl; #endif } } diff --git a/KGeoBag/Source/Shapes/Complex/Source/KGComplexAnnulus.cc b/KGeoBag/Source/Shapes/Complex/Source/KGComplexAnnulus.cc index 585e128cd..1f7d5cd62 100644 --- a/KGeoBag/Source/Shapes/Complex/Source/KGComplexAnnulus.cc +++ b/KGeoBag/Source/Shapes/Complex/Source/KGComplexAnnulus.cc @@ -90,6 +90,9 @@ bool KGComplexAnnulus::ContainsPoint(const double* P) const double KGComplexAnnulus::DistanceTo(const double* P, double* P_in, double* P_norm) const { + if (!P_in || !P_norm) + return NAN; + //Compute the closest point P_in to Point P as well as the norm vector pointing from point to closest point and returns the distance between them. double dist_main = 0; @@ -252,6 +255,8 @@ bool KGComplexAnnulus::Ring::ContainsPoint(const double* P) const double KGComplexAnnulus::Ring::DistanceTo(const double* P, double* P_in, double* P_norm) const { + if (!P_in || !P_norm) + return NAN; //Let's first transform to local coordinates: diff --git a/Kommon/cmake/FindFFTW.cmake b/Kommon/cmake/FindFFTW.cmake index 29cdf9591..191f41a64 100644 --- a/Kommon/cmake/FindFFTW.cmake +++ b/Kommon/cmake/FindFFTW.cmake @@ -1,43 +1,60 @@ -# FFTW_INCLUDE_DIR = fftw3.h -# FFTW_LIBRARIES = libfftw3.a -# FFTW_FOUND = true if FFTW3 is found - -IF(FFTW_INCLUDE_DIRS) - FIND_PATH(FFTW_INCLUDE_DIR fftw3.h ${FFTW_INCLUDE_DIRS}) - FIND_LIBRARY(FFTW_LIBRARY fftw3 ${FFTW_LIBRARY_DIRS}) -ELSE(FFTW_INCLUDE_DIRS) - # SET(TRIAL_PATHS - # $ENV{FFTW_HOME}/include - # /usr/include - # /usr/local/include - # /opt/include - # /usr/apps/include - # ) - # - # SET(TRIAL_LIBRARY_PATHS - # $ENV{FFTW_HOME}/lib - # /usr/lib - # /usr/local/lib - # /opt/lib - # /sw/lib - # ) - # - # FIND_PATH(FFTW_INCLUDE_DIR fftw3.h ${TRIAL_PATHS}) - # FIND_LIBRARY(FFTW_LIBRARY fftw3 ${TRIAL_LIBRARY_PATHS}) - FIND_PATH(FFTW_INCLUDE_DIR fftw3.h ${QMC_INCLUDE_PATHS}) - FIND_LIBRARY(FFTW_LIBRARIES fftw3 ${QMC_LIBRARY_PATHS}) - -ENDIF(FFTW_INCLUDE_DIRS) - -SET(FFTW_FOUND FALSE) -IF(FFTW_INCLUDE_DIR AND FFTW_LIBRARIES) - MESSAGE(STATUS "FFTW_INCLUDE_DIR=${FFTW_INCLUDE_DIR}") - MESSAGE(STATUS "FFTW_LIBRARIES=${FFTW_LIBRARIES}") - SET(FFTW_FOUND TRUE) -ENDIF() - -MARK_AS_ADVANCED( - FFTW_INCLUDE_DIR - FFTW_LIBRARIES - FFTW_FOUND + +# ================================================================================================== +# +# Defines the following variables: +# FFTW_FOUND Boolean holding whether or not the FFTW3 library was found +# FFTW_INCLUDE_DIRS The FFTW3 include directory +# FFTW_LIBRARIES The FFTW3 library +# +# In case FFTW3 is not installed in the default directory, set the FFTW_ROOT variable to point to +# the root of FFTW3, such that 'fftw3.h' can be found in $FFTW_ROOT/include. This can either be done +# using an environmental variable (e.g. export FFTW_ROOT=/path/to/fftw3) or using a CMake variable +# (e.g. cmake -DFFTW_ROOT=/path/to/fftw3 ..). +# +# ================================================================================================== + +# Sets the possible install locations +set(FFTW_HINTS + ${FFTW_ROOT} + $ENV{FFTW_ROOT} +) +set(FFTW_PATHS + /usr + /usr/local ) + +# Finds the include directories +find_path(FFTW_INCLUDE_DIRS + NAMES fftw3.h + HINTS ${FFTW_HINTS} + PATH_SUFFIXES include api inc include/x86_64 include/x64 + PATHS ${FFTW_PATHS} + DOC "FFTW3 include header fftw3.h" +) +mark_as_advanced(FFTW_INCLUDE_DIRS) + +# Finds the library +find_library(FFTW_LIBRARIES + NAMES fftw3 + HINTS ${FFTW_HINTS} + PATH_SUFFIXES lib lib64 lib/x86_64 lib/x64 lib/x86 lib/Win32 + PATHS ${FFTW_PATHS} + DOC "FFTW3 library" +) +mark_as_advanced(FFTW_LIBRARIES) + +# ================================================================================================== + +# Notification messages +if(NOT FFTW_INCLUDE_DIRS) + message(STATUS "Could NOT find 'fftw3.h', install FFTW3 or set FFTW_ROOT") +endif() +if(NOT FFTW_LIBRARIES) + message(STATUS "Could NOT find the FFTW3 library, install it or set FFTW_ROOT") +endif() + +# Determines whether or not FFTW3 was found +include(FindPackageHandleStandardArgs) +find_package_handle_standard_args(FFTW DEFAULT_MSG FFTW_INCLUDE_DIRS FFTW_LIBRARIES) + +# ==================================================================================================