Skip to content

Commit

Permalink
Energy load file only when necessary
Browse files Browse the repository at this point in the history
  • Loading branch information
F Zotter committed Sep 24, 2024
1 parent 07daa3b commit 989fdd4
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 7 deletions.
10 changes: 7 additions & 3 deletions Intern/rayx-core/src/Data/DesignSourceWriter.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,15 @@ void setAllMandatory(xml::Parser parser, DesignSource* ds) {
}

void setDefaultEnergy(xml::Parser parser, DesignSource* ds) {
ds->setEnergy(parser.parsePhotonEnergy());
ds->setEnergyDistributionFile(parser.parseEnergyDistributionFile().generic_string());
ds->setEnergyDistributionType(parser.parseEnergyDistributionType());
ds->setEnergySpread(parser.parseEnergySpread());
ds->setEnergySpreadType(parser.parseEnergySpreadType());

if (ds->getEnergyDistributionType() == EnergyDistributionType::File) {
ds->setEnergyDistributionFile(parser.parseEnergyDistributionFile().generic_string());
} else {
ds->setEnergy(parser.parsePhotonEnergy());
ds->setEnergySpread(parser.parseEnergySpread());
}
}

void setDefaultOrientation(xml::Parser parser, DesignSource* ds) {
Expand Down
4 changes: 3 additions & 1 deletion Intern/rayx-core/src/Design/DesignSource.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -194,6 +194,8 @@ void DesignSource::setEnergySpreadUnit(EnergySpreadUnit value) { m_elementParame
EnergySpreadUnit DesignSource::getEnergySpreadUnit() const { return m_elementParameters["energySpreadUnit"].as_energySpreadUnit(); }

void DesignSource::setEnergyDistributionType(EnergyDistributionType value) { m_elementParameters["energyDistributionType"] = value; }
EnergyDistributionType DesignSource::getEnergyDistributionType() const { return m_elementParameters["energyDistributionType"].as_energyDistributionType(); }

void DesignSource::setEnergyDistributionFile(std::string value) { m_elementParameters["photonEnergyDistributionFile"] = value; }

void DesignSource::setEnergySpreadType(SpreadType value) { m_elementParameters["energyDistribution"] = value; }
Expand All @@ -207,7 +209,7 @@ double DesignSource::getPhotonFlux() const { return m_elementParameters["photonF
EnergyDistribution DesignSource::getEnergyDistribution() const {
EnergyDistribution en;
SpreadType spreadType = m_elementParameters["energyDistribution"].as_energySpreadType();
EnergyDistributionType energyDistributionType = m_elementParameters["energyDistributionType"].as_energyDistType();
EnergyDistributionType energyDistributionType = m_elementParameters["energyDistributionType"].as_energyDistributionType();

if (energyDistributionType == EnergyDistributionType::File) {
std::string filename = m_elementParameters["photonEnergyDistributionFile"].as_string();
Expand Down
2 changes: 2 additions & 0 deletions Intern/rayx-core/src/Design/DesignSource.h
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,8 @@ struct RAYX_API DesignSource {
SpreadType getEnergySpreadType() const;

void setEnergyDistributionType(EnergyDistributionType value);
EnergyDistributionType getEnergyDistributionType() const;

void setEnergyDistributionFile(std::string value);

void setEnergySpreadUnit(EnergySpreadUnit value);
Expand Down
4 changes: 2 additions & 2 deletions Intern/rayx-core/src/Design/Value.h
Original file line number Diff line number Diff line change
Expand Up @@ -254,9 +254,9 @@ class DesignMap {
return *x;
}

inline EnergyDistributionType as_energyDistType() const {
inline EnergyDistributionType as_energyDistributionType() const {
auto* x = std::get_if<EnergyDistributionType>(&m_variant);
if (!x) throw std::runtime_error("as_energyDistType() called on non-energyDistType!");
if (!x) throw std::runtime_error("as_energyDistributionType() called on non-energyDistributionType!");
return *x;
}

Expand Down
2 changes: 1 addition & 1 deletion Intern/rayx-ui/src/UserInterface/BeamlineDesignHandler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -321,7 +321,7 @@ void BeamlineDesignHandler::createInputField(const std::string& key, RAYX::Desig
break;
}
case RAYX::ValueType::EnergyDistributionType: {
auto currentValue = element.as_energyDistType();
auto currentValue = element.as_energyDistributionType();
if (ImGui::BeginCombo("##energydisttype", RAYX::EnergyDistributionTypeToString.at(currentValue).c_str())) {
for (const auto& [value, name] : RAYX::EnergyDistributionTypeToString) {
bool isSelected = (currentValue == value);
Expand Down

0 comments on commit 989fdd4

Please sign in to comment.