Skip to content

Commit

Permalink
Merge pull request #117 from 2xB/2xB/errorpath
Browse files Browse the repository at this point in the history
Print geometry path in case of e.g. GSL error during calculation
  • Loading branch information
richeldichel authored Aug 30, 2024
2 parents 12b1002 + dfca7ca commit b883d8c
Show file tree
Hide file tree
Showing 9 changed files with 108 additions and 15 deletions.
4 changes: 3 additions & 1 deletion KEMField/Source/Interface/KGeoBag/include/KGBEMConverter.hh
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@
#include "KAxis.hh"
#include "KThreeVector.hh"

#include "KGPathAware.hh"

#include <vector>

namespace KGeoBag
Expand Down Expand Up @@ -219,7 +221,7 @@ class KGBEMConverter : public KGVisitor, public KGSurface::Visitor, public KGSpa
katrin::KThreeVector fCurrentZAxis;
katrin::KAxis fCurrentAxis;

katrin::KTagged* fCurrentElement;
KGPathAware* fCurrentElement;
};

template<class XBasisPolicy, class XBoundaryPolicy>
Expand Down
20 changes: 15 additions & 5 deletions KEMField/Source/Interface/KGeoBag/src/KGBEMConverter.cc
Original file line number Diff line number Diff line change
Expand Up @@ -217,12 +217,14 @@ void KGBEMMeshConverter::DispatchSurface(KGSurface* aSurface)
{
fCurrentElement = aSurface;
Add(aSurface->AsExtension<KGMesh>());
fCurrentElement = nullptr;
return;
}
void KGBEMMeshConverter::DispatchSpace(KGSpace* aSpace)
{
fCurrentElement = aSpace;
Add(aSpace->AsExtension<KGMesh>());
fCurrentElement = nullptr;
return;
}

Expand All @@ -249,7 +251,7 @@ bool KGBEMMeshConverter::Add(KGMeshData* aData)
if ((tMeshTriangle != nullptr) && (tMeshTriangle->Area() > fMinimumArea) &&
(tMeshTriangle->Aspect() < fMaximumAspectRatio)) {
tTriangle = new Triangle();
tTriangle->SetName(tTriangle->Name() + (fCurrentElement ? ("<" + fCurrentElement->GetName() + ">") : ""));
tTriangle->SetName(tTriangle->Name() + (fCurrentElement ? ("<" + fCurrentElement->GetPath() + ">") : ""));
tTriangle->SetTagsFrom(fCurrentElement);
tTriangle->SetValues(LocalToInternal(tMeshTriangle->GetP0()),
LocalToInternal(tMeshTriangle->GetP1()),
Expand All @@ -262,7 +264,7 @@ bool KGBEMMeshConverter::Add(KGMeshData* aData)
if ((tMeshRectangle != nullptr) && (tMeshRectangle->Area() > fMinimumArea) &&
(tMeshRectangle->Aspect() < fMaximumAspectRatio)) {
tRectangle = new Rectangle();
tRectangle->SetName(tRectangle->Name() + (fCurrentElement ? ("<" + fCurrentElement->GetName() + ">") : ""));
tRectangle->SetName(tRectangle->Name() + (fCurrentElement ? ("<" + fCurrentElement->GetPath() + ">") : ""));
tRectangle->SetTagsFrom(fCurrentElement);
tRectangle->SetValues(LocalToInternal(tMeshRectangle->GetP0()),
LocalToInternal(tMeshRectangle->GetP1()),
Expand All @@ -276,7 +278,7 @@ bool KGBEMMeshConverter::Add(KGMeshData* aData)
if ((tMeshWire != nullptr) && (tMeshWire->Area() > fMinimumArea) &&
(tMeshWire->Aspect() < fMaximumAspectRatio)) {
tLineSegment = new LineSegment();
tLineSegment->SetName(tLineSegment->Name() + (fCurrentElement ? ("<" + fCurrentElement->GetName() + ">") : ""));
tLineSegment->SetName(tLineSegment->Name() + (fCurrentElement ? ("<" + fCurrentElement->GetPath() + ">") : ""));
tLineSegment->SetTagsFrom(fCurrentElement);
tLineSegment->SetValues(LocalToInternal(tMeshWire->GetP0()),
LocalToInternal(tMeshWire->GetP1()),
Expand Down Expand Up @@ -320,14 +322,18 @@ KGBEMAxialMeshConverter::~KGBEMAxialMeshConverter() = default;

void KGBEMAxialMeshConverter::DispatchSurface(KGSurface* aSurface)
{
fCurrentElement = aSurface;
if (!Add(aSurface->AsExtension<KGAxialMesh>()))
coremsg(eWarning) << "not adding surface <" << aSurface->GetPath() << "> since it is not coaxial" << eom;
fCurrentElement = nullptr;
return;
}
void KGBEMAxialMeshConverter::DispatchSpace(KGSpace* aSpace)
{
fCurrentElement = aSpace;
if (!Add(aSpace->AsExtension<KGAxialMesh>()))
coremsg(eWarning) << "not adding space <" << aSpace->GetPath() << "> since it is not coaxial" << eom;
fCurrentElement = nullptr;
return;
}

Expand Down Expand Up @@ -362,7 +368,7 @@ bool KGBEMAxialMeshConverter::Add(KGAxialMeshData* aData)
tAxialMeshLoop = dynamic_cast<KGAxialMeshLoop*>(tAxialMeshElement);
if ((tAxialMeshLoop != nullptr) && (tAxialMeshLoop->Area() > fMinimumArea)) {
tConicSection = new ConicSection();
tConicSection->SetName(tConicSection->Name() + (fCurrentElement ? ("<" + fCurrentElement->GetName() + ">") : ""));
tConicSection->SetName(tConicSection->Name() + (fCurrentElement ? ("<" + fCurrentElement->GetPath() + ">") : ""));
tConicSection->SetTagsFrom(fCurrentElement);
tConicSection->SetValues(LocalToInternal(tAxialMeshLoop->GetP0()),
LocalToInternal(tAxialMeshLoop->GetP1()));
Expand All @@ -373,7 +379,7 @@ bool KGBEMAxialMeshConverter::Add(KGAxialMeshData* aData)
tAxialMeshRing = dynamic_cast<KGAxialMeshRing*>(tAxialMeshElement);
if ((tAxialMeshRing != nullptr) && (tAxialMeshRing->Area() > fMinimumArea)) {
tRing = new Ring();
tRing->SetName(tRing->Name() + (fCurrentElement ? ("<" + fCurrentElement->GetName() + ">") : ""));
tRing->SetName(tRing->Name() + (fCurrentElement ? ("<" + fCurrentElement->GetPath() + ">") : ""));
tRing->SetTagsFrom(fCurrentElement);
tRing->SetValues(LocalToInternal(tAxialMeshRing->GetP0()));
fRings.push_back(tRing);
Expand Down Expand Up @@ -409,14 +415,18 @@ KGBEMDiscreteRotationalMeshConverter::~KGBEMDiscreteRotationalMeshConverter() =

void KGBEMDiscreteRotationalMeshConverter::DispatchSurface(KGSurface* aSurface)
{
fCurrentElement = aSurface;
if (!Add(aSurface->AsExtension<KGDiscreteRotationalMesh>()))
coremsg(eWarning) << "not adding surface <" << aSurface->GetPath() << "> since it is not coaxial" << eom;
fCurrentElement = nullptr;
return;
}
void KGBEMDiscreteRotationalMeshConverter::DispatchSpace(KGSpace* aSpace)
{
fCurrentElement = aSpace;
if (!Add(aSpace->AsExtension<KGDiscreteRotationalMesh>()))
coremsg(eWarning) << "not adding space <" << aSpace->GetPath() << "> since it is not coaxial" << eom;
fCurrentElement = nullptr;
return;
}

Expand Down
46 changes: 43 additions & 3 deletions KEMField/Source/Surfaces/include/KSurface.hh
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
#include "KSurfaceID.hh"
#include "KSurfacePrimitive.hh"
#include "KSurfaceVisitors.hh"
#include "KEMCoreMessage.hh"

#include <iostream>
#include <sstream>
Expand Down Expand Up @@ -89,15 +90,54 @@ class KSurface :

void Accept(KBasisVisitor& visitor) override
{
visitor.Visit(*this);
try {
visitor.Visit(*this);
}
catch (...) {
std::string name = Shape::GetName();

if (name.length() == 0 || name == "(anonymous)") {
kem_cout(eWarning) << "Path of error is unavailable." << eom;
throw;
}

kem_cout(eWarning) << "Error in <" << name << ">" << eom;
throw;
}
}
void Accept(KBoundaryVisitor& visitor) override
{
visitor.Visit(*this);
try {
visitor.Visit(*this);
}
catch (...) {
std::string name = Shape::GetName();

if (name.length() == 0 || name == "(anonymous)") {
kem_cout(eWarning) << "Path of error is unavailable." << eom;
throw;
}

kem_cout(eWarning) << "Error in <" << name << ">" << eom;
throw;
}
}
void Accept(KShapeVisitor& visitor) override
{
visitor.Visit(*this);
try {
visitor.Visit(*this);
}
catch (...) {
std::string name = Shape::GetName();

if (name.length() == 0 || name == "(anonymous)") {
kem_cout(eWarning) << "Path of error is unavailable." << eom;
throw;
}

kem_cout(eWarning) << "Error in <" << name << ">" << eom;
throw;
}
}

private:
Expand Down
2 changes: 2 additions & 0 deletions KGeoBag/Source/Core/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ set( CORE_HEADER_FILES
Include/KGExtendedSpaceFunctions.hh
Include/KGInterface.hh
Include/KGTypelist.hh
Include/KGPathAware.hh
)

# source
Expand All @@ -32,6 +33,7 @@ set( CORE_SOURCE_FILES
Source/KGSpace.cc
Source/KGExtensibleSpace.cc
Source/KGInterface.cc
Source/KGPathAware.cc
)

# target
Expand Down
25 changes: 25 additions & 0 deletions KGeoBag/Source/Core/Include/KGPathAware.hh
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
#ifndef KGPATHAWARE_HH_
#define KGPATHAWARE_HH_

#include "KTagged.h"

#include <string>

namespace KGeoBag
{

class KGPathAware : public katrin::KTagged
{
public:
KGPathAware();
KGPathAware(const KGPathAware& aCopy);
~KGPathAware() override;

KGPathAware& operator=(const KGPathAware& other);

virtual std::string GetPath() const {return "";};
};

} // namespace KGeoBag

#endif
6 changes: 4 additions & 2 deletions KGeoBag/Source/Core/Include/KGSpace.hh
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,12 @@
#error "do not include KGSpace.hh directly; include KGCore.hh instead."
#else

#include "KGPathAware.hh"

namespace KGeoBag
{

class KGSpace : public katrin::KTagged
class KGSpace : public KGPathAware
{
public:
friend class KGSurface;
Expand Down Expand Up @@ -58,7 +60,7 @@ class KGSpace : public katrin::KTagged
void AddChildSpace(KGSpace* aSpace);

const KGSpace* GetParent() const;
std::string GetPath() const;
std::string GetPath() const override;

const std::vector<KGSurface*>* GetBoundaries() const;
const std::vector<KGSurface*>* GetChildSurfaces() const;
Expand Down
5 changes: 3 additions & 2 deletions KGeoBag/Source/Core/Include/KGSurface.hh
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,12 @@

#include "KThreeVector.hh"
#include "KTransformation.hh"
#include "KGPathAware.hh"

namespace KGeoBag
{

class KGSurface : public katrin::KTagged
class KGSurface : public KGPathAware
{
public:
friend class KGSpace;
Expand Down Expand Up @@ -58,7 +59,7 @@ class KGSurface : public katrin::KTagged
void Orphan();

const KGSpace* GetParent() const;
std::string GetPath() const;
std::string GetPath() const override;

protected:
KGSpace* fParent;
Expand Down
11 changes: 11 additions & 0 deletions KGeoBag/Source/Core/Source/KGPathAware.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
#include "KGPathAware.hh"

namespace KGeoBag
{

KGPathAware::KGPathAware() : KTagged() {}
KGPathAware::KGPathAware(const KGPathAware&) = default;
KGPathAware::~KGPathAware() = default;
KGPathAware& KGPathAware::operator=(const KGPathAware&) = default;

}
4 changes: 2 additions & 2 deletions Kassiopeia/Applications/Other/Source/DumpMagnetGeometry.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ void dumpRemoteSourcePoints(std::ostream& strm, const KZonalHarmonicContainer<Ba
int main(int argc, char** argv)
{
if (argc < 4) {
cout
std::cout
<< "usage: ./DumpMagnetGeometry <config_file.xml> <output_file.txt> <magnetic_field_name1> [<magnetic_field_name2> <...>] "
<< endl;
exit(-1);
Expand All @@ -99,7 +99,7 @@ int main(int argc, char** argv)
ofstream outFileStream;
streambuf* outFileBuf;
if (outFileName == "-") {
outFileBuf = cout.rdbuf();
outFileBuf = std::cout.rdbuf();
}
else {
outFileStream.open(outFileName);
Expand Down

0 comments on commit b883d8c

Please sign in to comment.