Skip to content

Commit 9919a36

Browse files
use variants for tagged unions
1 parent e88ea0a commit 9919a36

28 files changed

+636
-1038
lines changed

.github/workflows/releaseDeploy.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ jobs:
7070
uses: Jimver/cuda-toolkit@master
7171
id: cuda-toolkit-ubuntu
7272
with:
73-
cuda: '12.4.1'
73+
cuda: '12.8.1'
7474

7575
- name: Configure CMake (Ubuntu)
7676
if: matrix.os == 'ubuntu-24.04'

.github/workflows/testUbuntu.yml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,8 @@ jobs:
4242
uses: Jimver/cuda-toolkit@master
4343
id: cuda-toolkit
4444
with:
45-
cuda: '12.4.1'
45+
cuda: '12.8.1'
46+
method: 'network'
4647

4748
- name: Configure CMake
4849
run: cmake -B ${{github.workspace}}/build -DRAYX_WERROR=ON -DCMAKE_BUILD_TYPE=${{env.BUILD_TYPE}} -DRAYX_REQUIRE_CUDA=ON

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

Lines changed: 62 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -35,14 +35,14 @@ OpticalElement DesignElement::compile(const glm::dvec4& parentPos, const glm::dm
3535
DesignPlane plane = getDesignPlane();
3636

3737
if (getType() == ElementType::ExpertsMirror) {
38-
return makeElement(*dePtr, serializeMirror(), makeQuadric(*dePtr), plane);
38+
return makeElement(*dePtr, Behaviour::Mirror{}, makeQuadric(*dePtr), plane);
3939
} else {
4040
Surface surface = makeSurface(*dePtr);
4141
Behaviour behaviour = makeBehaviour(*dePtr);
4242
if (getType() == ElementType::Slit) {
4343
return makeElement(*dePtr, behaviour, surface, plane, {});
4444
} else if (getType() == ElementType::ImagePlane) {
45-
return makeElement(*dePtr, behaviour, surface, plane, serializeUnlimited());
45+
return makeElement(*dePtr, behaviour, surface, plane, Cutout::Unlimited{});
4646
} else {
4747
return makeElement(*dePtr, behaviour, surface, plane);
4848
}
@@ -159,49 +159,52 @@ SlopeError DesignElement::getSlopeError() const {
159159
}
160160

161161
void DesignElement::setCutout(Cutout c) {
162-
m_elementParameters["geometricalShape"] = c.m_type;
163-
if (c.m_type == CutoutType::Rect) {
164-
RectCutout rect = deserializeRect(c);
165-
m_elementParameters["CutoutWidth"] = rect.m_width;
166-
m_elementParameters["CutoutLength"] = rect.m_length;
167-
} else if (c.m_type == CutoutType::Elliptical) {
168-
EllipticalCutout elli = deserializeElliptical(c);
169-
m_elementParameters["CutoutDiameterX"] = elli.m_diameter_x;
170-
m_elementParameters["CutoutDiameterZ"] = elli.m_diameter_z;
171-
} else if (c.m_type == CutoutType::Trapezoid) {
172-
TrapezoidCutout trapi = deserializeTrapezoid(c);
173-
m_elementParameters["CutoutWidthA"] = trapi.m_widthA;
174-
m_elementParameters["CutoutWidthB"] = trapi.m_widthB;
175-
m_elementParameters["CutoutLength"] = trapi.m_length;
176-
}
162+
variant::visit(
163+
[&]<typename T>(const T& arg) {
164+
if constexpr (std::is_same_v<T, Cutout::Unlimited>) {
165+
m_elementParameters["geometricalShape"] = CutoutType::Unlimited;
166+
} else if constexpr (std::is_same_v<T, Cutout::Rect>) {
167+
m_elementParameters["geometricalShape"] = CutoutType::Rect;
168+
m_elementParameters["CutoutWidth"] = arg.m_width;
169+
m_elementParameters["CutoutLength"] = arg.m_length;
170+
} else if constexpr (std::is_same_v<T, Cutout::Elliptical>) {
171+
m_elementParameters["geometricalShape"] = CutoutType::Elliptical;
172+
m_elementParameters["CutoutDiameterX"] = arg.m_diameter_x;
173+
m_elementParameters["CutoutDiameterZ"] = arg.m_diameter_z;
174+
} else if constexpr (std::is_same_v<T, Cutout::Trapezoid>) {
175+
m_elementParameters["geometricalShape"] = CutoutType::Trapezoid;
176+
m_elementParameters["CutoutWidthA"] = arg.m_widthA;
177+
m_elementParameters["CutoutWidthB"] = arg.m_widthB;
178+
m_elementParameters["CutoutLength"] = arg.m_length;
179+
}
180+
},
181+
c.m_variant);
177182
}
178183
Cutout DesignElement::getCutout() const {
179-
Cutout c;
180-
181-
c.m_type = m_elementParameters["geometricalShape"].as_openingShape();
182-
183-
if (c.m_type == CutoutType::Rect) { // Rectangle
184-
RectCutout rect;
185-
rect.m_width = m_elementParameters["CutoutWidth"].as_double();
186-
rect.m_length = m_elementParameters["CutoutLength"].as_double();
187-
c = serializeRect(rect);
188-
} else if (c.m_type == CutoutType::Elliptical) { // Ellipsoid
189-
EllipticalCutout elli;
190-
elli.m_diameter_x = m_elementParameters["CutoutDiameterX"].as_double();
191-
elli.m_diameter_z = m_elementParameters["CutoutDiameterZ"].as_double();
192-
c = serializeElliptical(elli);
193-
} else if (c.m_type == CutoutType::Trapezoid) { // Trapezoid
194-
TrapezoidCutout trapi;
195-
trapi.m_widthA = m_elementParameters["CutoutWidthA"].as_double();
196-
trapi.m_widthB = m_elementParameters["CutoutWidthB"].as_double();
197-
trapi.m_length = m_elementParameters["CutoutLength"].as_double();
198-
c = serializeTrapezoid(trapi);
184+
CutoutType type = m_elementParameters["geometricalShape"].as_openingShape();
185+
186+
if (type == CutoutType::Rect) { // Rectangle
187+
return Cutout::Rect{
188+
.m_width = m_elementParameters["CutoutWidth"].as_double(),
189+
.m_length = m_elementParameters["CutoutLength"].as_double(),
190+
};
191+
} else if (type == CutoutType::Elliptical) { // Ellipsoid
192+
return Cutout::Elliptical{
193+
.m_diameter_x = m_elementParameters["CutoutDiameterX"].as_double(),
194+
.m_diameter_z = m_elementParameters["CutoutDiameterZ"].as_double(),
195+
};
196+
} else if (type == CutoutType::Trapezoid) { // Trapezoid
197+
return Cutout::Trapezoid{
198+
.m_widthA = m_elementParameters["CutoutWidthA"].as_double(),
199+
.m_widthB = m_elementParameters["CutoutWidthB"].as_double(),
200+
.m_length = m_elementParameters["CutoutLength"].as_double(),
201+
};
199202
}
200203

201-
return c;
204+
return Cutout::Unlimited{};
202205
}
203206

204-
Cutout DesignElement::getGlobalCutout() const { return serializeUnlimited(); }
207+
Cutout DesignElement::getGlobalCutout() const { return Cutout::Unlimited{}; }
205208

206209
void DesignElement::setVLSParameters(const std::array<double, 6>& values) {
207210
m_elementParameters["vlsParams"] = Map();
@@ -221,8 +224,9 @@ std::array<double, 6> DesignElement::getVLSParameters() const {
221224
}
222225

223226
void DesignElement::setExpertsOptics(Surface value) {
224-
QuadricSurface qua = deserializeQuadric(value);
227+
Surface::Quadric qua = variant::get<Surface::Quadric>(value.m_surface);
225228
m_elementParameters["expertsParams"] = Map();
229+
m_elementParameters["expertsParams"]["surfaceBending"] = qua.m_icurv;
226230
m_elementParameters["expertsParams"]["A11"] = qua.m_a11;
227231
m_elementParameters["expertsParams"]["A12"] = qua.m_a12;
228232
m_elementParameters["expertsParams"]["A13"] = qua.m_a13;
@@ -236,7 +240,8 @@ void DesignElement::setExpertsOptics(Surface value) {
236240
}
237241

238242
Surface DesignElement::getExpertsOptics() const {
239-
QuadricSurface qua;
243+
Surface::Quadric qua;
244+
qua.m_icurv = m_elementParameters["expertsParams"]["surfaceBending"].as_int();
240245
qua.m_a11 = m_elementParameters["expertsParams"]["A11"].as_double();
241246
qua.m_a12 = m_elementParameters["expertsParams"]["A12"].as_double();
242247
qua.m_a13 = m_elementParameters["expertsParams"]["A13"].as_double();
@@ -248,11 +253,11 @@ Surface DesignElement::getExpertsOptics() const {
248253
qua.m_a34 = m_elementParameters["expertsParams"]["A34"].as_double();
249254
qua.m_a44 = m_elementParameters["expertsParams"]["A44"].as_double();
250255

251-
return serializeQuadric(qua);
256+
return qua;
252257
}
253258

254259
void DesignElement::setExpertsCubic(Surface value) {
255-
CubicSurface cub = deserializeCubic(value);
260+
Surface::Cubic cub = variant::get<Surface::Cubic>(value.m_surface);
256261
m_elementParameters["expertsParams"] = Map();
257262
m_elementParameters["expertsParams"]["A11"] = cub.m_a11;
258263
m_elementParameters["expertsParams"]["A12"] = cub.m_a12;
@@ -271,10 +276,12 @@ void DesignElement::setExpertsCubic(Surface value) {
271276
m_elementParameters["expertsParams"]["B23"] = cub.m_b23;
272277
m_elementParameters["expertsParams"]["B31"] = cub.m_b31;
273278
m_elementParameters["expertsParams"]["B32"] = cub.m_b32;
279+
280+
m_elementParameters["expertsParams"]["tangentAngleAlpha"] = cub.m_psi * 180 / PI;
274281
}
275282

276283
Surface DesignElement::getExpertsCubic() const {
277-
CubicSurface cub;
284+
Surface::Cubic cub;
278285
cub.m_a11 = m_elementParameters["expertsParams"]["A11"].as_double();
279286
cub.m_a12 = m_elementParameters["expertsParams"]["A12"].as_double();
280287
cub.m_a13 = m_elementParameters["expertsParams"]["A13"].as_double();
@@ -293,7 +300,9 @@ Surface DesignElement::getExpertsCubic() const {
293300
cub.m_b31 = m_elementParameters["expertsParams"]["B31"].as_double();
294301
cub.m_b32 = m_elementParameters["expertsParams"]["B32"].as_double();
295302

296-
return serializeCubic(cub);
303+
cub.m_psi = m_elementParameters["expertsParams"]["tangentAngleAlpha"].as_double() * PI / 180;
304+
305+
return Surface::Cubic{cub};
297306
}
298307

299308
// for the spherical Mirror the radius can be calculated from grazing Inc angle, entrace Armlength and exit Armlength
@@ -426,8 +435,8 @@ Rad DesignElement::getDesignAlphaAngle() const { return m_elementParameters["Des
426435
void DesignElement::setDesignBetaAngle(Rad value) { m_elementParameters["DesignBetaAngle"] = value; }
427436
Rad DesignElement::getDesignBetaAngle() const { return m_elementParameters["DesignBetaAngle"].as_rad(); }
428437

429-
void DesignElement::setDesignOrderOfDiffraction(double value) { m_elementParameters["DesignOrderDiffraction"] = value; }
430-
double DesignElement::getDesignOrderOfDiffraction() const { return m_elementParameters["DesignOrderDiffraction"].as_double(); }
438+
void DesignElement::setDesignOrderOfDiffraction(int value) { m_elementParameters["DesignOrderDiffraction"] = value; }
439+
int DesignElement::getDesignOrderOfDiffraction() const { return m_elementParameters["DesignOrderDiffraction"].as_int(); }
431440

432441
void DesignElement::setDesignEnergy(double value) { m_elementParameters["DesignEnergy"] = value; }
433442
double DesignElement::getDesignEnergy() const { return m_elementParameters["DesignEnergy"].as_double(); }
@@ -444,14 +453,14 @@ double DesignElement::getDesignMeridionalEntranceArmLength() const { return m_el
444453
void DesignElement::setDesignMeridionalExitArmLength(double value) { m_elementParameters["DesignMeridionalExitArmLength"] = value; }
445454
double DesignElement::getDesignMeridionalExitArmLength() const { return m_elementParameters["DesignMeridionalExitArmLength"].as_double(); }
446455

447-
void DesignElement::setOrderOfDiffraction(double value) { m_elementParameters["OrderDiffraction"] = value; }
448-
double DesignElement::getOrderOfDiffraction() const { return m_elementParameters["OrderDiffraction"].as_double(); }
456+
void DesignElement::setOrderOfDiffraction(int value) { m_elementParameters["OrderDiffraction"] = value; }
457+
int DesignElement::getOrderOfDiffraction() const { return m_elementParameters["OrderDiffraction"].as_int(); }
449458

450-
void DesignElement::setAdditionalOrder(double value) { m_elementParameters["additionalOrder"] = value; }
451-
double DesignElement::getAdditionalOrder() const { return m_elementParameters["additionalOrder"].as_double(); }
459+
void DesignElement::setAdditionalOrder(int value) { m_elementParameters["additionalOrder"] = value; }
460+
int DesignElement::getAdditionalOrder() const { return m_elementParameters["additionalOrder"].as_int(); }
452461

453-
void DesignElement::setImageType(double value) { m_elementParameters["imageType"] = value; }
454-
double DesignElement::getImageType() const { return m_elementParameters["imageType"].as_double(); }
462+
void DesignElement::setImageType(int value) { m_elementParameters["imageType"] = value; }
463+
int DesignElement::getImageType() const { return m_elementParameters["imageType"].as_int(); }
455464

456465
void DesignElement::setCurvatureType(CurvatureType value) { m_elementParameters["curvatureType"] = value; }
457466
CurvatureType DesignElement::getCurvatureType() const { return m_elementParameters["curvatureType"].as_curvatureType(); }

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

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -163,8 +163,8 @@ struct RAYX_API DesignElement : public BeamlineNode {
163163
void setDesignBetaAngle(Rad value);
164164
Rad getDesignBetaAngle() const;
165165

166-
void setDesignOrderOfDiffraction(double value);
167-
double getDesignOrderOfDiffraction() const;
166+
void setDesignOrderOfDiffraction(int value);
167+
int getDesignOrderOfDiffraction() const;
168168

169169
void setDesignEnergy(double value);
170170
double getDesignEnergy() const;
@@ -184,14 +184,14 @@ struct RAYX_API DesignElement : public BeamlineNode {
184184
double getDesignMeridionalExitArmLength() const;
185185

186186
// Setter and Getter for orderOfDiffraction
187-
void setOrderOfDiffraction(double value);
188-
double getOrderOfDiffraction() const;
187+
void setOrderOfDiffraction(int value);
188+
int getOrderOfDiffraction() const;
189189

190-
void setAdditionalOrder(double value);
191-
double getAdditionalOrder() const;
190+
void setAdditionalOrder(int value);
191+
int getAdditionalOrder() const;
192192

193-
void setImageType(double value);
194-
double getImageType() const;
193+
void setImageType(int value);
194+
int getImageType() const;
195195

196196
void setCurvatureType(CurvatureType value);
197197
CurvatureType getCurvatureType() const;

0 commit comments

Comments
 (0)