Skip to content

Commit be2efd1

Browse files
authored
Foil (#391)
* optical Foil strings for ui * use complex + format --------- Co-authored-by: F Zotter <[email protected]>
1 parent 156e2db commit be2efd1

37 files changed

+881
-46
lines changed

Intern/rayx-core/src/Beamline/Definitions.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ enum class CurvatureType {
1717
Quadric,
1818
RzpSphere
1919
}; // order is crucial for xml prser
20-
enum class BehaviourType { Mirror, Grating, Slit, Rzp, ImagePlane, Crystal };
20+
enum class BehaviourType { Mirror, Grating, Slit, Rzp, ImagePlane, Crystal, Foil };
2121
enum class FigureRotation { Yes, Plane, A11 };
2222

2323
// the direction of a plane, either XY or XZ. This is only used in the parsing.

Intern/rayx-core/src/Design/DesignElement.cpp

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -32,17 +32,19 @@ OpticalElement DesignElement::compile(const glm::dvec4& parentPos, const glm::dm
3232
dePtr->setPosition(worldPos);
3333
dePtr->setOrientation(worldOri);
3434

35+
DesignPlane plane = getDesignPlane();
36+
3537
if (getType() == ElementType::ExpertsMirror) {
36-
return makeElement(*dePtr, serializeMirror(), makeQuadric(*dePtr));
38+
return makeElement(*dePtr, serializeMirror(), makeQuadric(*dePtr), plane);
3739
} else {
3840
Surface surface = makeSurface(*dePtr);
3941
Behaviour behaviour = makeBehaviour(*dePtr);
4042
if (getType() == ElementType::Slit) {
41-
return makeElement(*dePtr, behaviour, surface, {}, DesignPlane::XY);
43+
return makeElement(*dePtr, behaviour, surface, plane, {});
4244
} else if (getType() == ElementType::ImagePlane) {
43-
return makeElement(*dePtr, behaviour, surface, serializeUnlimited(), DesignPlane::XY);
45+
return makeElement(*dePtr, behaviour, surface, plane, serializeUnlimited());
4446
} else {
45-
return makeElement(*dePtr, behaviour, surface);
47+
return makeElement(*dePtr, behaviour, surface, plane);
4648
}
4749
}
4850
}
@@ -490,4 +492,13 @@ double DesignElement::getDSpacing2() const { return m_elementParameters["dSpacin
490492
void DesignElement::setOffsetAngle(Rad value) { m_elementParameters["offsetAngle"] = value; }
491493
Rad DesignElement::getOffsetAngle() const { return m_elementParameters["offsetAngle"].as_rad(); }
492494

495+
void DesignElement::setThicknessSubstrate(double value) { m_elementParameters["thicknessSubstrate"] = value; }
496+
double DesignElement::getThicknessSubstrate() const { return m_elementParameters["thicknessSubstrate"].as_double(); }
497+
498+
void DesignElement::setRoughnessSubstrate(double value) { m_elementParameters["roughnessSubstrate"] = value; }
499+
double DesignElement::getRoughnessSubstrate() const { return m_elementParameters["roughnessSubstrate"].as_double(); }
500+
501+
void DesignElement::setDesignPlane(DesignPlane value) { m_elementParameters["designPlane"] = value; }
502+
DesignPlane DesignElement::getDesignPlane() const { return m_elementParameters["designPlane"].as_designPlane(); }
503+
493504
} // namespace RAYX

Intern/rayx-core/src/Design/DesignElement.h

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -234,5 +234,14 @@ struct RAYX_API DesignElement : public BeamlineNode {
234234

235235
void setDSpacing2(double value);
236236
double getDSpacing2() const;
237+
238+
void setThicknessSubstrate(double value);
239+
double getThicknessSubstrate() const;
240+
241+
void setRoughnessSubstrate(double value);
242+
double getRoughnessSubstrate() const;
243+
244+
void setDesignPlane(DesignPlane value);
245+
DesignPlane getDesignPlane() const;
237246
};
238247
} // namespace RAYX

Intern/rayx-core/src/Design/Value.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ ValueType DesignMap::type() const {
5252
ValueType::ElementType,
5353
ValueType::GratingMount,
5454
ValueType::CrystalType,
55+
ValueType::DesignPlane,
5556
};
5657
return types[m_variant.index()];
5758
}
@@ -191,6 +192,11 @@ CrystalType DesignMap::as_crystalType() const {
191192
throw std::runtime_error("as_crystalType() called on non-crystalType!");
192193
}
193194

195+
DesignPlane DesignMap::as_designPlane() const {
196+
if (auto* x = std::get_if<DesignPlane>(&m_variant)) return *x;
197+
throw std::runtime_error("as_designPlane() called on non-designPlane!");
198+
}
199+
194200
const DesignMap& DesignMap::operator[](const std::string& s) const {
195201
if (auto* m = std::get_if<Map>(&m_variant)) {
196202
auto it = m->find(s);

Intern/rayx-core/src/Design/Value.h

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,8 @@ enum class ValueType {
4747
BehaviourType,
4848
ElementType,
4949
GratingMount,
50-
CrystalType
50+
CrystalType,
51+
DesignPlane
5152
};
5253

5354
class Undefined {};
@@ -96,6 +97,7 @@ class RAYX_API DesignMap {
9697
DesignMap(ElementType x) : m_variant(x) {}
9798
DesignMap(GratingMount x) : m_variant(x) {}
9899
DesignMap(CrystalType x) : m_variant(x) {}
100+
DesignMap(DesignPlane x) : m_variant(x) {}
99101

100102
// Assignment operators
101103
void operator=(double x) { m_variant = x; }
@@ -126,6 +128,7 @@ class RAYX_API DesignMap {
126128
void operator=(GratingMount x) { m_variant = x; }
127129
void operator=(ElementType x) { m_variant = x; }
128130
void operator=(CrystalType x) { m_variant = x; }
131+
void operator=(DesignPlane x) { m_variant = x; }
129132

130133
// Deep copy (clone) method.
131134
DesignMap clone() const;
@@ -160,6 +163,7 @@ class RAYX_API DesignMap {
160163
ElementType as_elementType() const;
161164
GratingMount as_gratingMount() const;
162165
CrystalType as_crystalType() const;
166+
DesignPlane as_designPlane() const;
163167

164168
// Subscript operators.
165169
const DesignMap& operator[](const std::string& s) const;
@@ -236,7 +240,7 @@ class RAYX_API DesignMap {
236240
private:
237241
std::variant<Undefined, double, int, ElectronEnergyOrientation, glm::dvec4, glm::dmat4x4, bool, EnergyDistributionType, Misalignment,
238242
CentralBeamstop, Cutout, CutoutType, EventType, CylinderDirection, FigureRotation, Map, Surface, CurvatureType, SourceDist,
239-
SpreadType, Rad, Material, EnergySpreadUnit, std::string, SigmaType, BehaviourType, ElementType, GratingMount, CrystalType>
243+
SpreadType, Rad, Material, EnergySpreadUnit, std::string, SigmaType, BehaviourType, ElementType, GratingMount, CrystalType, DesignPlane>
240244
m_variant;
241245
};
242246

Intern/rayx-core/src/Element/Behaviour.cpp

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@ Behaviour makeBehaviour(const DesignElement& dele) {
1919
return makeRZPBehaviour(dele);
2020
case BehaviourType::Slit:
2121
return makeSlit(dele);
22+
case BehaviourType::Foil:
23+
return makeFoil(dele);
2224
default:
2325
return serializeImagePlane();
2426
}
@@ -147,4 +149,15 @@ Behaviour makeRZPBehaviour(const DesignElement& dele) {
147149
.m_additionalOrder = (double)additionalOrder});
148150
}
149151

152+
// Foil Behaviour
153+
Behaviour makeFoil(const DesignElement& dele) {
154+
auto thicknessSubstrate = dele.getThicknessSubstrate();
155+
auto roughnessSubstrate = dele.getRoughnessSubstrate();
156+
157+
return serializeFoil({
158+
.m_thicknessSubstrate = thicknessSubstrate,
159+
.m_roughnessSubstrate = roughnessSubstrate,
160+
});
161+
}
162+
150163
} // namespace RAYX

Intern/rayx-core/src/Element/Behaviour.h

Lines changed: 29 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ enum class BehaveType {
1616
RZP,
1717
ImagePlane,
1818
Crystal,
19+
Foil
1920
};
2021

2122
struct Behaviour {
@@ -35,7 +36,7 @@ Behaviour makeCrystal(const DesignElement& dele);
3536
Behaviour makeGrating(const DesignElement& dele); //< creates a Grating Behaviour from the parameters given in `dele`.
3637
Behaviour makeSlit(const DesignElement& dele);
3738
Behaviour makeRZPBehaviour(const DesignElement& dele);
38-
Behaviour makeCrystalBehaviour(const DesignElement& dele);
39+
Behaviour makeFoil(const DesignElement& dele);
3940

4041
////////////////////
4142
// Mirror
@@ -266,6 +267,33 @@ inline CrystalBehaviour deserializeCrystal(const Behaviour& b) {
266267
return c;
267268
}
268269

270+
/////////////////
271+
// FOIL
272+
////////////////
273+
274+
struct FoilBehaviour {
275+
//Substrates
276+
double m_thicknessSubstrate;
277+
double m_roughnessSubstrate;
278+
};
279+
280+
RAYX_FN_ACC
281+
inline Behaviour serializeFoil(FoilBehaviour f) {
282+
Behaviour b;
283+
b.m_type = BehaveType::Foil;
284+
b.m_private_serialization_params[0] = f.m_thicknessSubstrate;
285+
b.m_private_serialization_params[1] = f.m_roughnessSubstrate;
286+
return b;
287+
}
288+
289+
RAYX_FN_ACC
290+
inline FoilBehaviour deserializeFoil(Behaviour b) {
291+
FoilBehaviour f;
292+
f.m_thicknessSubstrate = b.m_private_serialization_params[0];
293+
f.m_roughnessSubstrate = b.m_private_serialization_params[1];
294+
return f;
295+
}
296+
269297
// This prevents m_private_serialization_params from being used outside of this file - making them practically private.
270298
#define m_private_serialization_params "m_private_serialization_params are private! Use the corresponding serialize & deserialize functions instead."
271299

Intern/rayx-core/src/Element/Element.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ inline glm::dmat4x4 defaultOutMatrix(const DesignElement& dele, DesignPlane plan
5353

5454
inline int defaultMaterial(const DesignElement& dele) { return static_cast<int>(dele.getMaterial()); }
5555

56-
OpticalElement makeElement(const DesignElement& dele, Behaviour behaviour, Surface surface, std::optional<Cutout> cutout, DesignPlane plane) {
56+
OpticalElement makeElement(const DesignElement& dele, Behaviour behaviour, Surface surface, DesignPlane plane, std::optional<Cutout> cutout ) {
5757
if (!cutout) {
5858
cutout = dele.getCutout();
5959
}
@@ -95,7 +95,8 @@ std::map<ElementType, std::string> ElementStringMap = {{ElementType::CircleSourc
9595
{ElementType::DipoleSrc, "Dipole"},
9696
{ElementType::PixelSource, "Pixel Source"},
9797
{ElementType::EllipsoidMirror, "Ellipsoid"},
98-
{ElementType::Crystal, "Crystal"}};
98+
{ElementType::Crystal, "Crystal"},
99+
{ElementType::Foil, "Foil"}};
99100

100101
ElementType findElementString(const std::string& name) {
101102
auto it = std::find_if(ElementStringMap.begin(), ElementStringMap.end(),

Intern/rayx-core/src/Element/Element.h

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ enum class ElementType {
2323
CylinderMirror,
2424
EllipsoidMirror,
2525
ExpertsMirror,
26+
Foil,
2627
ParaboloidMirror,
2728
PlaneGrating,
2829
PlaneMirror,
@@ -63,8 +64,8 @@ static_assert(std::is_trivially_default_constructible_v<OpticalElement>);
6364
RAYX_API glm::dmat4 calcTransformationMatrices(glm::dvec4 position, glm::dmat4 orientation, bool calcInMatrix, DesignPlane plane);
6465

6566
// constructs an OpticalElement given all of its components. Some information that is not explicitly given, will be parsed from the ` dele`.
66-
OpticalElement makeElement(const DesignElement& dele, Behaviour behaviour, Surface surface, std::optional<Cutout> cutout = {},
67-
DesignPlane plane = DesignPlane::XZ);
67+
OpticalElement makeElement(const DesignElement& dele, Behaviour behaviour, Surface surface, DesignPlane plane = DesignPlane::XZ,
68+
std::optional<Cutout> cutout = {});
6869

6970
extern std::map<ElementType, std::string> RAYX_API ElementStringMap;
7071
ElementType RAYX_API findElementString(const std::string& name);

Intern/rayx-core/src/Element/Surface.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ Surface makeSurface(const DesignElement& dele) {
2727
}
2828
}
2929

30-
Surface makePlane() { return serializePlaneXZ(); }
30+
Surface makePlane() { return serializePlane(); }
3131

3232
Surface makeCylinder(const DesignElement& dele) {
3333
auto cyl_direction = dele.getRadiusDirection();

0 commit comments

Comments
 (0)