Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ CMakeCache.txm
cmake.check_cache
imgui.ini
*.h5
*.testCsv.csv

# VSCode Debugger files
results.json
Expand Down
12 changes: 3 additions & 9 deletions Intern/rayx-core/src/Beamline/Beamline.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -266,21 +266,15 @@ MaterialTables Group::calcMinimalMaterialTables() const {
auto coating = elemPtr->getCoating();
if (coating.is<detail::CoatingTypes::OneCoating>()) {
int materialcoating = static_cast<int>(elemPtr->getMaterialCoating());
if (materialcoating >= 1 && materialcoating <= 133) {
relevantMaterials[materialcoating - 1] = true;
}
if (materialcoating >= 1 && materialcoating <= 133) { relevantMaterials[materialcoating - 1] = true; }
} else if (coating.is<detail::CoatingTypes::MultilayerCoating>()) {
auto mlCoating = coating.get<detail::CoatingTypes::MultilayerCoating>();
for (const auto& mat : mlCoating.material) {
if (mat >= 1 && mat <= 133) {
relevantMaterials[mat - 1] = true;
}
if (mat >= 1 && mat <= 133) { relevantMaterials[mat - 1] = true; }
}
}
int material = static_cast<int>(elemPtr->getMaterial()); // assuming getMaterial() exists
if (material >= 1 && material <= 133) {
relevantMaterials[material - 1] = true;
}
if (material >= 1 && material <= 133) { relevantMaterials[material - 1] = true; }
}
return loadMaterialTables(relevantMaterials);
}
Expand Down
8 changes: 6 additions & 2 deletions Intern/rayx-core/src/Beamline/StringConversion.h
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,9 @@ const std::map<ElementType, std::string> ElementTypeToString = {{ElementType::Ci
{ElementType::PixelSource, "Pixel Source"},
{ElementType::EllipsoidMirror, "Ellipsoid"},
{ElementType::Crystal, "Crystal"},
{ElementType::Foil, "Foil"}};
{ElementType::Foil, "Foil"},
{ElementType::RayListSource, "Ray List Source"},
{ElementType::Undefined, "Undefined"}};
const std::map<std::string, ElementType> StringToElementType = {{"Circle Source", ElementType::CircleSource},
{"Cylinder", ElementType::CylinderMirror},
{"ImagePlane", ElementType::ImagePlane},
Expand All @@ -163,7 +165,9 @@ const std::map<std::string, ElementType> StringToElementType = {{"Circle Source"
{"Pixel Source", ElementType::PixelSource},
{"Ellipsoid", ElementType::EllipsoidMirror},
{"Crystal", ElementType::Crystal},
{"Foil", ElementType::Foil}};
{"Foil", ElementType::Foil},
{"Ray List Source", ElementType::RayListSource},
{"Undefined", ElementType::Undefined}};

const std::map<std::string, EventType> StringToEventType = {
{"Uninitialized", EventType::Uninitialized}, {"Emitted", EventType::Emitted}, {"HitElement", EventType::HitElement},
Expand Down
8 changes: 2 additions & 6 deletions Intern/rayx-core/src/Design/DesignSource.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -185,18 +185,14 @@ double DesignSource::getEnergySpread() const { return m_elementParameters["energ

void DesignSource::setEnergySpreadUnit(EnergySpreadUnit value) { m_elementParameters["energySpreadUnit"] = value; }
EnergySpreadUnit DesignSource::getEnergySpreadUnit() const {
if (!m_elementParameters.hasKey("energySpreadUnit")) {
return EnergySpreadUnit::EU_eV;
}
if (!m_elementParameters.hasKey("energySpreadUnit")) { return EnergySpreadUnit::EU_eV; }

return m_elementParameters["energySpreadUnit"].as_energySpreadUnit();
}

double DesignSource::getEnergySpreadInEv() const {
const double energySpread = getEnergySpread();
if (getEnergySpreadUnit() == EnergySpreadUnit::EU_PERCENT) {
return getEnergy() * energySpread / 100.0;
}
if (getEnergySpreadUnit() == EnergySpreadUnit::EU_PERCENT) { return getEnergy() * energySpread / 100.0; }

return energySpread;
}
Expand Down
1 change: 1 addition & 0 deletions Intern/rayx-core/src/Element/Element.h
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ enum class ElementType {
CircleSource,
SimpleUndulatorSource,
RayListSource,
Count, // must stay last
};

/**
Expand Down
22 changes: 17 additions & 5 deletions Intern/rayx-core/src/Element/Surface.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -244,20 +244,32 @@ Surface makeParaboloid(const DesignElement& dele) {
y0 = ArmLength * sin1;
z0 = ArmLength * cos1 * sign;

a24 = -y0;
a34 = -parameterP;
a44 = pow(y0, 2) - 2 * parameterP * z0 - pow(parameterP, 2);

// The paraboloid is built with its axis along z, which leaves the surface tilted by the
// grazing angle at the pole. Rotate it about x so the surface is tangent to the element's
// xz plane there, as makeEllipsoid does. RAY-UI applies the equivalent rotation through its
// tangentAngle (= sign * grazingIncAngle) in the element transform instead.
const double alpha = -sign * grazingIncAngle.rad;
const double sa = sin(alpha);
const double ca = cos(alpha);

const double a22 = ca * ca;
const double a23 = sa * ca;
a24 = -y0 * ca + parameterP * sa;
const double a33 = sa * sa;
a34 = -y0 * sa - parameterP * ca;
//---------------------------- Serialization -------------------------------
return Surface::Quadric{
.m_icurv = 1,
.m_a11 = a11,
.m_a12 = 0,
.m_a13 = 0,
.m_a14 = 0,
.m_a22 = 1.0,
.m_a23 = 0,
.m_a22 = a22,
.m_a23 = a23,
.m_a24 = a24,
.m_a33 = 0,
.m_a33 = a33,
.m_a34 = a34,
.m_a44 = a44,
};
Expand Down
14 changes: 4 additions & 10 deletions Intern/rayx-core/src/Material/CromerTable.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,22 +16,16 @@ bool CromerTable::load(const char* element, CromerTable* out) {
RAYX_VERB << "Loading CromerTable from " << f;
std::ifstream s(f);

if (s.fail()) {
return false;
}
if (s.fail()) { return false; }

std::string line;

// ignore first three lines
for (int i = 0; i < 3; i++) {
std::getline(s, line);
}
for (int i = 0; i < 3; i++) { std::getline(s, line); }

// line 4..EOF
for (uint32_t lineidx = 4; std::getline(s, line); lineidx++) {
if (line.empty()) {
continue;
}
if (line.empty()) { continue; }

CromerEntry e{};
#if defined(WIN32)
Expand All @@ -50,4 +44,4 @@ bool CromerTable::load(const char* element, CromerTable* out) {
return true;
}

} // namespace RAYX
} // namespace rayx
2 changes: 1 addition & 1 deletion Intern/rayx-core/src/Material/CromerTable.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,4 +26,4 @@ struct CromerTable {
// double interpolate(double x) const;
};

} // namespace RAYX
} // namespace rayx
47 changes: 20 additions & 27 deletions Intern/rayx-core/src/Material/Material.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,11 @@
#include <strings.h>
#endif

#include "CromerTable.h"
#include "Debug/Debug.h"
#include "MolecTable.h"
#include "NffTable.h"
#include "PalikTable.h"
#include "CromerTable.h"
#include "MolecTable.h"

namespace rayx {

Expand Down Expand Up @@ -76,19 +76,15 @@ MaterialTables loadMaterialTables(std::array<bool, 133> relevantMaterials) {
MaterialTables out;

auto mats = allNormalMaterials();
if (mats.size() != 133) {
RAYX_EXIT << "unexpected number of materials. this is a bug.";
}
if (mats.size() != 133) { RAYX_EXIT << "unexpected number of materials. this is a bug."; }

// add palik table content
for (size_t i = 0; i < mats.size(); i++) {
out.indices.push_back(out.materials.size());
if (relevantMaterials[i]) {
PalikTable t;

if (!PalikTable::load(getMaterialName(mats[i]), &t)) {
RAYX_VERB << "could not load PalikTable!";
}
if (!PalikTable::load(getMaterialName(mats[i]), &t)) { RAYX_VERB << "could not load PalikTable!"; }

for (auto x : t.m_Lines) {
out.materials.push_back(x.m_energy);
Expand All @@ -105,22 +101,20 @@ MaterialTables loadMaterialTables(std::array<bool, 133> relevantMaterials) {
if (relevantMaterials[i]) {
NffTable t;

if (!NffTable::load(getMaterialName(mat), &t)) {
RAYX_VERB << "could not load NffTable!";
}
if (!NffTable::load(getMaterialName(mat), &t)) { RAYX_VERB << "could not load NffTable!"; }

glm::dvec2 massAndRho = getAtomicMassAndRho(getMaterialAtomicNumber(mat));
double mass = massAndRho.x;
double rho = massAndRho.y;
double mass = massAndRho.x;
double rho = massAndRho.y;

for (auto x : t.m_Lines) {
double en = x.m_energy;
double n = 1 - (415.252 * rho * x.m_f1) / (en * en * mass);
double k = (415.252 * rho * x.m_f2) / (en * en * mass);
double n = 1 - (415.252 * rho * x.m_f1) / (en * en * mass);
double k = (415.252 * rho * x.m_f2) / (en * en * mass);
NKEntry nk;
nk.m_energy = en;
nk.m_n = n;
nk.m_k = k;
nk.m_n = n;
nk.m_k = k;
out.materials.push_back(nk.m_energy);
out.materials.push_back(nk.m_n);
out.materials.push_back(nk.m_k);
Expand All @@ -140,29 +134,28 @@ MaterialTables loadMaterialTables(std::array<bool, 133> relevantMaterials) {
}

glm::dvec2 massAndRho = getAtomicMassAndRho(i);
double mass = massAndRho.x;
double rho = massAndRho.y;
double mass = massAndRho.x;
double rho = massAndRho.y;

for (auto x : t.m_Lines) {
double en = x.m_energy;
double n = 1 - (415.252 * rho * x.m_f1) / (en * en * mass);
double k = (415.252 * rho * x.m_f2) / (en * en * mass);
double n = 1 - (415.252 * rho * x.m_f1) / (en * en * mass);
double k = (415.252 * rho * x.m_f2) / (en * en * mass);
NKEntry nk;
nk.m_energy = en;
nk.m_n = n;
nk.m_k = k;
nk.m_n = n;
nk.m_k = k;
out.materials.push_back(nk.m_energy);
out.materials.push_back(nk.m_n);
out.materials.push_back(nk.m_k);
}
}
}



// add molec table content now
for (size_t i = 0; i < mats.size(); i++) {
out.indices.push_back(out.materials.size());
if(relevantMaterials[i]) {
if (relevantMaterials[i]) {
MolecTable t;
if (!MolecTable::load(getMaterialName(mats[i]), &t)) {
RAYX_VERB << "could not load MolecTable!";
Expand Down Expand Up @@ -208,4 +201,4 @@ glm::dvec2 getAtomicMassAndRho(int material) {
return glm::dvec2(0.0, 0.0);
}

} // namespace RAYX
} // namespace rayx
2 changes: 1 addition & 1 deletion Intern/rayx-core/src/Material/Material.h
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
#pragma once

#include <array>
#include <vector>
#include <glm.hpp>
#include <vector>

#include "Core.h"

Expand Down
8 changes: 2 additions & 6 deletions Intern/rayx-core/src/Material/MolecTable.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,7 @@ bool MolecTable::load(const char* element, MolecTable* out) {
RAYX_VERB << "Loading MolecTable from " << f;
std::ifstream s(f);

if (s.fail()) {
return false;
}
if (s.fail()) { return false; }

std::string line;

Expand All @@ -30,9 +28,7 @@ bool MolecTable::load(const char* element, MolecTable* out) {

// line 2..EOF
for (uint32_t lineidx = 3; std::getline(s, line); lineidx++) {
if (line.empty()) {
continue;
}
if (line.empty()) { continue; }

NKEntry e{};
#if defined(WIN32)
Expand Down
6 changes: 4 additions & 2 deletions Intern/rayx-core/src/ObjectMask.h
Original file line number Diff line number Diff line change
Expand Up @@ -88,8 +88,10 @@ class RAYX_API ObjectIndexMask {

void setShouldRecordObject(int object_id, bool value) {
const auto numSources = static_cast<int>(m_sourceMask.size());
if (object_id < numSources) m_sourceMask.at(object_id) = value;
m_elementMask.at(object_id - numSources) = value;
if (object_id < numSources)
m_sourceMask.at(object_id) = value;
else
m_elementMask.at(object_id - numSources) = value;
}

private:
Expand Down
4 changes: 1 addition & 3 deletions Intern/rayx-core/src/Rml/DesignSourceWriter.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,7 @@ namespace rayx {
namespace {
EnergySpreadUnit parseEnergySpreadUnitOrDefault(xml::Parser parser) {
int energySpreadUnit = 0;
if (!xml::paramInt(parser.node, "energySpreadUnit", &energySpreadUnit)) {
return EnergySpreadUnit::EU_eV;
}
if (!xml::paramInt(parser.node, "energySpreadUnit", &energySpreadUnit)) { return EnergySpreadUnit::EU_eV; }

return static_cast<EnergySpreadUnit>(energySpreadUnit);
}
Expand Down
2 changes: 1 addition & 1 deletion Intern/rayx-core/src/Rml/Locate.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ std::filesystem::path ResourceHandler::getFullPath(const std::filesystem::path&
};

{
std::shared_lock lock(m_lookUpPathsMutex); // lock lookUpPaths
std::shared_lock lock(m_lookUpPathsMutex); // lock lookUpPaths
// First, check in user-defined lookup paths
for (const auto& lookupPath : lookUpPaths) {
std::filesystem::path path = lookupPath / baseDir / relativePath;
Expand Down
4 changes: 2 additions & 2 deletions Intern/rayx-core/src/Rml/Locate.h
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
#pragma once

#include <filesystem>
#include <mutex>
#include <shared_mutex>
#include <string>
#include <vector>
#include <shared_mutex>
#include <mutex>

#include "Core.h"

Expand Down
Loading
Loading