OPALX (Object Oriented Parallel Accelerator Library for Exascal) master (dc2a29eed580)
OPALX
Loading...
Searching...
No Matches
TestPlacedElement.cpp
Go to the documentation of this file.
1#include "gtest/gtest.h"
2
10
11#include <cmath>
12
13namespace {
14 constexpr double tol = 1e-12;
15
16 using Vector3 = ippl::Vector<double, 3>;
17
18 Quaternion rotationAroundZ(double angle) {
19 return Quaternion(std::cos(0.5 * angle), 0.0, 0.0, std::sin(0.5 * angle));
20 }
21
22 void expectVectorNear(const Vector3& actual, const Vector3& expected) {
23 EXPECT_NEAR(actual(0), expected(0), tol);
24 EXPECT_NEAR(actual(1), expected(1), tol);
25 EXPECT_NEAR(actual(2), expected(2), tol);
26 }
27} // namespace
28
29class PlacedElementTest : public ::testing::Test {
30protected:
31 static void SetUpTestSuite() {
32 int argc = 0;
33 char** argv = nullptr;
34
35 ippl::initialize(argc, argv);
36 }
37
38 static void TearDownTestSuite() { ippl::finalize(); }
39};
40
41TEST_F(PlacedElementTest, ActualBodyTransformAppliesCorrectionAfterNominalPlacement) {
42 PlacementPose nominal(
43 CoordinateSystemTrafo(Vector3(1.0, 2.0, 3.0), rotationAroundZ(M_PI / 2.0)));
44 Misalignment correction(
45 CoordinateSystemTrafo(Vector3(0.5, -0.25, 0.0), CoordinateSystemTrafo().getRotation()));
46 PlacedElement placed(nullptr, nominal, correction);
47 Vector3 point(2.0, 0.0, -1.0);
48
49 const Vector3 actual = placed.getActualBodyTransform().transformTo(point);
50 const Vector3 expected = correction.getNominalToActual().transformTo(
51 nominal.getParentToNominal().transformTo(point));
52
53 expectVectorNear(actual, expected);
54}
55
56TEST_F(PlacedElementTest, EntryExitAndSupportTransformsAreDerivedFromBodyFrame) {
57 PlacementPose nominal(
58 CoordinateSystemTrafo(Vector3(0.0, 0.0, 1.0), rotationAroundZ(M_PI / 4.0)));
59 Misalignment correction(CoordinateSystemTrafo(Vector3(0.0, 0.0, 0.5), Quaternion()));
60 ElementGeometry geometry(
61 Port("entry", CoordinateSystemTrafo(Vector3(0.0, 0.0, -0.2), Quaternion())),
62 Port("body", CoordinateSystemTrafo(Vector3(0.0, 0.0, 0.0), Quaternion())),
63 Port("exit", CoordinateSystemTrafo(Vector3(0.0, 0.0, 0.8), Quaternion())));
64 SupportPlacement support(CoordinateSystemTrafo(Vector3(0.1, 0.0, 0.0), Quaternion()));
65 PlacedElement placed(nullptr, nominal, correction, geometry, support);
66 Vector3 point(0.5, -0.5, 2.0);
67
68 const CoordinateSystemTrafo actualBody = placed.getActualBodyTransform();
69 expectVectorNear(
70 placed.getEntryTransform().transformTo(point),
71 geometry.getEntry().getBodyToPort().transformTo(actualBody.transformTo(point)));
72 expectVectorNear(
73 placed.getBodyTransform().transformTo(point),
74 geometry.getBody().getBodyToPort().transformTo(actualBody.transformTo(point)));
75 expectVectorNear(
76 placed.getExitTransform().transformTo(point),
77 geometry.getExit().getBodyToPort().transformTo(actualBody.transformTo(point)));
78 expectVectorNear(
79 placed.getSupportTransform().transformTo(point),
80 support.getBodyToSupport().transformTo(actualBody.transformTo(point)));
81}
82
83TEST_F(PlacedElementTest, DefaultGeometryExposesNamedPorts) {
84 ElementGeometry geometry;
85
86 EXPECT_EQ(geometry.getEntry().getName(), "entry");
87 EXPECT_EQ(geometry.getBody().getName(), "body");
88 EXPECT_EQ(geometry.getExit().getName(), "exit");
89}
90
91TEST_F(PlacedElementTest, ElementBaseBridgeUsesExistingPlacementAndEdgeState) {
92 DriftRep drift("D1");
93 drift.setElementLength(1.5);
95 CoordinateSystemTrafo(Vector3(1.0, 2.0, 3.0), rotationAroundZ(M_PI / 6.0)));
96 drift.setMisalignment(CoordinateSystemTrafo(Vector3(0.1, 0.2, 0.3), Quaternion()));
97
98 const PlacedElement placed = drift.getPlacedElement();
99
100 expectVectorNear(placed.getNominalBodyTransform().getOrigin(), Vector3(1.0, 2.0, 3.0));
101 expectVectorNear(placed.getNominalEntryTransform().getOrigin(), Vector3(1.0, 2.0, 3.0));
102 EXPECT_NEAR(placed.getNominalExitTransform().getOrigin()(2), 4.5, tol);
103 EXPECT_EQ(placed.getGeometry().getEntry().getName(), "entry");
104 EXPECT_EQ(placed.getGeometry().getExit().getName(), "exit");
105}
106
107TEST_F(PlacedElementTest, ElementBaseExposesExplicitStraightElementPortContract) {
108 DriftRep drift("D2");
109 drift.setElementLength(1.5);
110
111 const Port entry = drift.getEntryPort();
112 const Port body = drift.getBodyPort();
113 const Port exit = drift.getExitPort();
114
115 EXPECT_EQ(entry.getName(), "entry");
116 EXPECT_EQ(body.getName(), "body");
117 EXPECT_EQ(exit.getName(), "exit");
118 expectVectorNear(entry.getBodyToPort().getOrigin(), Vector3(0.0, 0.0, 0.0));
119 expectVectorNear(body.getBodyToPort().getOrigin(), Vector3(0.0, 0.0, 0.0));
120 expectVectorNear(exit.getBodyToPort().getOrigin(), Vector3(0.0, 0.0, 1.5));
121}
TEST_F(PlacedElementTest, ActualBodyTransformAppliesCorrectionAfterNominalPlacement)
Rigid spatial transform between a parent frame and a local frame.
ippl::Vector< double, 3 > getOrigin() const
ippl::Vector< double, 3 > transformTo(const ippl::Vector< double, 3 > &r) const
Map a point from the parent frame to the local frame.
virtual void setElementLength(double length)
Set design length.
void setMisalignment(const CoordinateSystemTrafo &cst)
virtual Port getEntryPort() const
Return the entrance port of the canonical local chart.
void setCSTrafoGlobal2Local(const CoordinateSystemTrafo &ori)
virtual Port getBodyPort() const
Return the body port of the canonical local chart.
virtual Port getExitPort() const
Return the exit port of the canonical local chart.
PlacedElement getPlacedElement() const
Return a placed-element view assembled from the current bridge objects.
Named body-relative ports used for placement and chaining.
const Port & getExit() const
const Port & getEntry() const
const Port & getBody() const
Local nominal-to-actual correction transform.
const CoordinateSystemTrafo & getNominalToActual() const
static void SetUpTestSuite()
static void TearDownTestSuite()
Geometric placement record for an element instance.
const ElementGeometry & getGeometry() const
CoordinateSystemTrafo getNominalEntryTransform() const
CoordinateSystemTrafo getNominalExitTransform() const
CoordinateSystemTrafo getBodyTransform() const
CoordinateSystemTrafo getEntryTransform() const
CoordinateSystemTrafo getExitTransform() const
CoordinateSystemTrafo getActualBodyTransform() const
CoordinateSystemTrafo getSupportTransform() const
CoordinateSystemTrafo getNominalBodyTransform() const
Nominal rigid placement transform.
const CoordinateSystemTrafo & getParentToNominal() const
Named local frame attached to an element body.
Definition Port.h:15
const CoordinateSystemTrafo & getBodyToPort() const
Definition Port.h:22
const std::string & getName() const
Definition Port.h:21
Quaternion storage and rotation algebra used by OPALX geometry code.
Optional offset from the canonical body frame to the support frame.
const CoordinateSystemTrafo & getBodyToSupport() const
constexpr double e
The value of.
Definition Physics.h:49