Skip to content

Commit

Permalink
Almost fixed the test suite
Browse files Browse the repository at this point in the history
  • Loading branch information
Atraxus committed Jan 21, 2025
1 parent a4f2da4 commit 05abd20
Show file tree
Hide file tree
Showing 14 changed files with 99 additions and 92 deletions.
32 changes: 16 additions & 16 deletions Intern/rayx-core/src/Beamline/Beamline.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ void Group::addChild(const BeamlineNode& child) { children.push_back(child); }
std::vector<Ray> Group::getInputRays(int thread_count) const {
RAYX_PROFILE_FUNCTION_STDOUT();

std::vector<DesignSource> sources = getAllSources();
std::vector<DesignSource> sources = getSources();

if (sources.size() == 0) {
return {};
Expand Down Expand Up @@ -76,7 +76,7 @@ std::vector<Ray> Group::getInputRays(int thread_count) const {
}

MaterialTables Group::calcMinimalMaterialTables() const {
std::vector<DesignElement> elements = getAllElements();
std::vector<DesignElement> elements = getElements();

std::array<bool, 92> relevantMaterials{};
relevantMaterials.fill(false);
Expand All @@ -102,7 +102,7 @@ std::vector<OpticalElement> Group::compile() const {
}

// Retrieve all DesignElements (deep)
std::vector<DesignElement> Group::getAllElements() const {
std::vector<DesignElement> Group::getElements() const {
std::vector<DesignElement> elements;
traverse([&elements](const BeamlineNode& node) {
if (std::holds_alternative<DesignElement>(node)) {
Expand All @@ -112,18 +112,8 @@ std::vector<DesignElement> Group::getAllElements() const {
return elements;
}

size_t Group::numberOfElements() const {
size_t count = 0;
traverse([&count](const BeamlineNode& node) {
if (std::holds_alternative<DesignElement>(node)) {
count++;
}
});
return count;
}

// Retrieve all DesignSources (deep)
std::vector<DesignSource> Group::getAllSources() const {
std::vector<DesignSource> Group::getSources() const {
std::vector<DesignSource> sources;
traverse([&sources](const BeamlineNode& node) {
if (std::holds_alternative<DesignSource>(node)) {
Expand All @@ -133,7 +123,17 @@ std::vector<DesignSource> Group::getAllSources() const {
return sources;
}

size_t Group::numberOfSources() const {
size_t Group::numElements() const {
size_t count = 0;
traverse([&count](const BeamlineNode& node) {
if (std::holds_alternative<DesignElement>(node)) {
count++;
}
});
return count;
}

size_t Group::numSources() const {
size_t count = 0;
traverse([&count](const BeamlineNode& node) {
if (std::holds_alternative<DesignSource>(node)) {
Expand All @@ -144,7 +144,7 @@ size_t Group::numberOfSources() const {
}

// Retrieve all Groups (deep)
std::vector<Group> Group::getAllGroups() const {
std::vector<Group> Group::getGroups() const {
std::vector<Group> groups;
traverse([&groups](const BeamlineNode& node) {
if (std::holds_alternative<Group>(node)) {
Expand Down
10 changes: 5 additions & 5 deletions Intern/rayx-core/src/Beamline/Beamline.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,11 +35,11 @@ class Group {
std::vector<OpticalElement> compile() const;

// New methods for retrieving elements, sources, and groups
std::vector<DesignElement> getAllElements() const;
std::vector<DesignSource> getAllSources() const;
size_t numberOfElements() const;
size_t numberOfSources() const;
std::vector<Group> getAllGroups() const;
std::vector<DesignElement> getElements() const;
std::vector<DesignSource> getSources() const;
std::vector<Group> getGroups() const;
size_t numElements() const;
size_t numSources() const;

// Getter & Setter
const glm::dvec4& getPosition() const { return m_position; }
Expand Down
11 changes: 5 additions & 6 deletions Intern/rayx-core/src/Data/Importer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -115,16 +115,17 @@ void handleObjectCollection(rapidxml::xml_node<>* collection, Group& group, cons
if (strcmp(object->name(), "object") == 0) {
addBeamlineObjectFromXML(object, group, filename);
} else if (strcmp(object->name(), "group") == 0) {
Group group;
auto groupOpt = xml::parseGroup(object);
if (!groupOpt) {
RAYX_EXIT << "parseGroup failed!";
}
auto g = groupOpt.value();
Group nestedGroup = groupOpt.value();

// Recursively parse all objects from within the group.
handleObjectCollection(object, group, filename);
handleObjectCollection(object, nestedGroup, filename);

// Add the group to the beamline.
group.addChild(nestedGroup);
} else if (strcmp(object->name(), "param") != 0) {
RAYX_EXIT << "received weird object->name(): " << object->name();
}
Expand Down Expand Up @@ -163,9 +164,7 @@ Beamline importBeamline(const std::filesystem::path& filename) {
// For each group we call handleObjectCollection recursively, and push the group onto the group context stack.
handleObjectCollection(xml_beamline, root, filename);

Beamline beamline;
// TODO
return beamline;
return root;
}

} // namespace RAYX
4 changes: 2 additions & 2 deletions Intern/rayx-core/src/Data/xml.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -434,13 +434,13 @@ std::optional<Group> parseGroup(rapidxml::xml_node<>* node) {
if (auto position = paramPosition(node); position) {
group.setPosition(*position);
} else {
return std::nullopt;
group.setPosition(glm::dvec4(0, 0, 0, 1));
}

if (auto orientation = paramOrientation(node); orientation) {
group.setOrientation(*orientation);
} else {
return std::nullopt;
group.setOrientation(glm::dmat4(1));
}

return group;
Expand Down
4 changes: 4 additions & 0 deletions Intern/rayx-core/src/Debug/Debug.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,10 @@ Verb::~Verb() {
}
}

// The default error_fn value. Exit with an error code of 1.
void exit1() { exit(1); }
void (*error_fn)() = exit1;

const int PREC = 17; // precision

// the implementation of RAYX_DBG.
Expand Down
1 change: 1 addition & 0 deletions Intern/rayx-core/src/Design/DesignElement.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

namespace RAYX {

// TODO: This needs to apply group transformations
OpticalElement DesignElement::compile() const {
RAYX_PROFILE_FUNCTION_STDOUT();
if (getType() == ElementType::ExpertsMirror) {
Expand Down
19 changes: 10 additions & 9 deletions Intern/rayx-core/src/Design/DesignSource.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,30 +6,31 @@
#include "Debug/Debug.h"
namespace RAYX {

std::vector<Ray> DesignSource::compile(int i) const {
std::vector<Ray> ray;
// TODO: This needs to apply group transformations
std::vector<Ray> DesignSource::compile(int numThreads) const {
std::vector<Ray> rays;

if (getType() == ElementType::PointSource) {
PointSource ps(*this);
ray = ps.getRays(i);
rays = ps.getRays(numThreads);
} else if (getType() == ElementType::MatrixSource) {
MatrixSource ms(*this);
ray = ms.getRays(i);
rays = ms.getRays(numThreads);
} else if (getType() == ElementType::DipoleSource) {
DipoleSource ds(*this);
ray = ds.getRays(i);
rays = ds.getRays(numThreads);
} else if (getType() == ElementType::PixelSource) {
PixelSource ps(*this);
ray = ps.getRays(i);
rays = ps.getRays(numThreads);
} else if (getType() == ElementType::CircleSource) {
CircleSource cs(*this);
ray = cs.getRays(i);
rays = cs.getRays(numThreads);
} else if (getType() == ElementType::SimpleUndulatorSource) {
SimpleUndulatorSource su(*this);
ray = su.getRays(i);
rays = su.getRays(numThreads);
}

return ray;
return rays;
}

void DesignSource::setName(std::string s) { m_elementParameters["name"] = s; }
Expand Down
2 changes: 1 addition & 1 deletion Intern/rayx-core/src/Design/DesignSource.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ namespace RAYX {

struct RAYX_API DesignSource {
DesignMap m_elementParameters;
std::vector<Ray> compile(int thread_count) const;
std::vector<Ray> compile(int numThreads) const;

void setStokeslin0(double value);
void setStokeslin45(double value);
Expand Down
2 changes: 1 addition & 1 deletion Intern/rayx-core/src/Tracer/SimpleTracer.h
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ BundleHistory SimpleTracer<Acc>::trace(const Group& group, Sequential seq, uint6
RAYX_VERB << "maxEvents: " << maxEvents;

// don't trace if there are no optical elements
if (group.numberOfElements() == 0) {
if (group.numElements() == 0) {
// an empty history suffices, nothing is happening to the rays!
BundleHistory result;
return result;
Expand Down
2 changes: 1 addition & 1 deletion Intern/rayx-core/src/Tracer/Tracer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ BundleHistory convertToBundleHistory(const std::vector<Ray>& rays) {
}

int Tracer::defaultMaxEvents(const Group* group) {
if (group) return group->numberOfElements() * 2 + 8;
if (group) return group->numElements() * 2 + 8;
return 32;
}

Expand Down
8 changes: 4 additions & 4 deletions Intern/rayx-core/tests/setupTests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ void writeToOutputCSV(const RAYX::BundleHistory& hist, std::string filename) {

RAYX::BundleHistory traceRML(std::string filename) {
auto beamline = loadBeamline(filename);
return tracer->trace(beamline, Sequential::No, DEFAULT_BATCH_SIZE, 1, beamline.m_DesignElements.size() + 2);
return tracer->trace(beamline, Sequential::No, DEFAULT_BATCH_SIZE, 1, beamline.numElements() + 2);
}

std::vector<RAYX::Ray> extractLastHit(const RAYX::BundleHistory& hist) {
Expand Down Expand Up @@ -179,18 +179,18 @@ std::optional<RAYX::Ray> lastSequentialHit(RayHistory ray_hist, uint32_t beamlin
// returns the rayx rays converted to be ray-UI compatible.
std::vector<RAYX::Ray> rayUiCompat(std::string filename, Sequential seq = Sequential::No) {
auto beamline = loadBeamline(filename);
BundleHistory hist = tracer->trace(beamline, seq, DEFAULT_BATCH_SIZE, 1, beamline.m_DesignElements.size() + 2);
BundleHistory hist = tracer->trace(beamline, seq, DEFAULT_BATCH_SIZE, 1, beamline.numElements() + 2);

std::vector<RAYX::Ray> out;

for (auto ray_hist : hist) {
auto opt_ray = lastSequentialHit(ray_hist, beamline.m_DesignElements.size());
auto opt_ray = lastSequentialHit(ray_hist, beamline.numElements());

if (opt_ray) {
auto orig_r = *opt_ray;
auto r = orig_r;
int elem = (int)r.m_lastElement;
double btype = beamline.m_DesignElements[elem].compile().m_behaviour.m_type; // m_element.m_behaviour.m_type;
double btype = beamline.getElements()[elem].compile().m_behaviour.m_type; // m_element.m_behaviour.m_type;
// these types of behaviours indicate that Ray-UI uses a DesignPlane::XY for this.
// Thus, (as rayx uses an XZ plane) to allow comparison with Ray-UI we need to swap the y and z coordinates here.
if (btype == BTYPE_IMAGE_PLANE || btype == BTYPE_SLIT) {
Expand Down
Loading

0 comments on commit 05abd20

Please sign in to comment.