Skip to content

Commit

Permalink
Update to Kassiopeia 3.7.6
Browse files Browse the repository at this point in the history
* Build fixes (update FindFFTW)
* Add `CurrentTurns` field to KGElectromagnet
* Fix segfault in KGComplexAnnulus
  • Loading branch information
zykure committed Aug 24, 2020
1 parent 9954f98 commit 9cf2f80
Show file tree
Hide file tree
Showing 8 changed files with 119 additions and 62 deletions.
2 changes: 1 addition & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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 )
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ class KGElectromagnetAttributor : public KTagged, public KGElectromagnetData
std::vector<KGSurface*> fSurfaces;
std::vector<KGSpace*> fSpaces;
K_SET_GET(double, LineCurrent)
K_SET_GET(double, ScalingFactor)
K_SET_GET(double, CurrentTurns)
K_SET_GET(double, Direction)
};

Expand All @@ -47,8 +47,8 @@ template<> inline bool KGElectromagnetBuilder::AddAttribute(KContainer* aContain
fObject->SetLineCurrent(aContainer->AsReference<double>());
return true;
}
if (aContainer->GetName() == "scaling_factor") {
fObject->SetScalingFactor(aContainer->AsReference<double>());
if (aContainer->GetName() == "scaling_factor" || aContainer->GetName() == "num_turns") {
fObject->SetCurrentTurns(aContainer->AsReference<double>());
return true;
}
if (aContainer->GetName() == "direction") {
Expand Down Expand Up @@ -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;
}

Expand Down
10 changes: 6 additions & 4 deletions KEMField/Source/Bindings/KGeoBag/src/KGElectromagnetBuilder.cc
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ KGElectromagnetAttributor::KGElectromagnetAttributor() :
fSurfaces(),
fSpaces(),
fLineCurrent(0.0),
fScalingFactor(1.0),
fCurrentTurns(1.0),
fDirection(1.0)
{}

Expand All @@ -21,14 +21,16 @@ KGElectromagnetAttributor::~KGElectromagnetAttributor()
tElectromagnetSurface = (*tIt)->MakeExtension<KGElectromagnet>();
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<KGElectromagnet>();
tElectromagnetSpace->SetName(GetName());
tElectromagnetSpace->SetTags(GetTags());
tElectromagnetSpace->SetCurrent(GetCurrent());
tElectromagnetSpace->SetLineCurrent(GetLineCurrent());
tElectromagnetSpace->SetCurrentTurns(GetCurrentTurns());
}
}

Expand All @@ -54,7 +56,7 @@ template<> inline KGElectromagnetBuilder::~KComplexElement() {}

STATICINT sKGElectromagnetStructure =
KGElectromagnetBuilder::Attribute<string>("name") + KGElectromagnetBuilder::Attribute<double>("current") +
KGElectromagnetBuilder::Attribute<double>("scaling_factor") +
KGElectromagnetBuilder::Attribute<double>("scaling_factor") + KGElectromagnetBuilder::Attribute<double>("num_turns") +
KGElectromagnetBuilder::Attribute<string>("direction") + KGElectromagnetBuilder::Attribute<string>("surfaces") +
KGElectromagnetBuilder::Attribute<string>("spaces");

Expand Down
21 changes: 14 additions & 7 deletions KEMField/Source/Interface/KGeoBag/include/KGElectromagnet.hh
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
23 changes: 21 additions & 2 deletions KEMField/Source/Interface/KGeoBag/src/KGElectromagnet.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down Expand Up @@ -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);

Expand Down Expand Up @@ -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
}
}
Expand Down
5 changes: 5 additions & 0 deletions KGeoBag/Source/Shapes/Complex/Source/KGComplexAnnulus.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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:

Expand Down
101 changes: 59 additions & 42 deletions Kommon/cmake/FindFFTW.cmake
Original file line number Diff line number Diff line change
@@ -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)

# ==================================================================================================

0 comments on commit 9cf2f80

Please sign in to comment.