54#include <gtest/gtest.h>
91 double& xIni,
double& xFinal,
double& yIni,
double& yFinal,
double& zIni,
92 double& zFinal)
const override {
94 xFinal = yFinal = 0.0;
102 void applyField(std::shared_ptr<ParticleContainer_t>,
double = 1.0)
override {}
115 void getOnaxisEz(std::vector<std::pair<double, double>>& F)
override {
117 F.push_back({0.0, 1.0});
118 F.push_back({1.0, 1.0});
119 F.push_back({2.0, 1.0});
202 tw_ = std::make_unique<TestTravelingWave>();
203 fmap_ = std::make_unique<FakeTWFieldmap>();
208 tw_->periodLength_m = 2.0;
209 tw_->cellLength_m = 1.0;
213 tw_->setStartField(-1.0);
214 tw_->setEndField(3.0);
215 tw_->startCoreField_m = 1.0;
216 tw_->startExitField_m = 3.0;
217 tw_->mappedStartExitField_m = 1.0;
219 tw_->setTestElementLength(4.0);
223 tw_->setScaleError(0.0);
224 tw_->setScaleCore(1.0);
225 tw_->setScaleCoreError(0.0);
226 tw_->setFrequencyInternal(1.0);
227 tw_->setPhaseInternal(0.0);
228 tw_->setPhaseError(0.0);
231 tw_->phaseCore1_m = 0.0;
232 tw_->phaseCore2_m = 0.0;
233 tw_->phaseExit_m = 0.0;
236 std::unique_ptr<TestTravelingWave>
tw_;
237 std::unique_ptr<FakeTWFieldmap>
fmap_;
248 tw_->setAmplitude(5.0);
249 tw_->setFrequency(2.0);
252 EXPECT_DOUBLE_EQ(tw_->getAmplitude(), 5.0);
253 EXPECT_DOUBLE_EQ(tw_->getFrequency(), 2.0);
254 EXPECT_DOUBLE_EQ(tw_->getPhase(), 0.5);
261 double zBegin = 0.0, zEnd = 0.0;
262 tw_->getFieldExtend(zBegin, zEnd);
264 EXPECT_DOUBLE_EQ(zBegin, -1.0);
265 EXPECT_DOUBLE_EQ(zEnd, 3.0);
269 double begin = 0.0, end = 0.0;
270 tw_->getElementDimensions(begin, end);
272 EXPECT_DOUBLE_EQ(begin, 0.0);
273 EXPECT_DOUBLE_EQ(end, 4.0);
277 auto beg = tw_->getEdgeToBegin();
278 auto end = tw_->getEdgeToEnd();
280 EXPECT_DOUBLE_EQ(beg.getOrigin()(2), 0.0);
281 EXPECT_DOUBLE_EQ(end.getOrigin()(2), 4.0);
293 EXPECT_NEAR(tw_->getPhasem(), 0.2, 1e-12);
294 EXPECT_NEAR(tw_->phaseCore1_m, 0.2 +
Physics::pi * 0.5 / 2.0, 1e-12);
295 EXPECT_NEAR(tw_->phaseCore2_m, 0.2 +
Physics::pi * 0.5 * 1.5, 1e-12);
297 const double expectedExit = 0.2 -
Physics::two_pi * ((3 - 1) * 0.5 - std::floor((3 - 1) * 0.5));
298 EXPECT_NEAR(tw_->phaseExit_m, expectedExit, 1e-12);
311 tw_->apply(R, P, 0.0, E, B);
314 EXPECT_DOUBLE_EQ(E(0), 1.0);
315 EXPECT_DOUBLE_EQ(E(1), 0.0);
316 EXPECT_DOUBLE_EQ(E(2), 0.0);
318 EXPECT_DOUBLE_EQ(B(0), 0.0);
319 EXPECT_DOUBLE_EQ(B(1), 0.0);
320 EXPECT_DOUBLE_EQ(B(2), 0.0);
330 tw_->setScaleCore(1.0);
331 tw_->phaseCore1_m = 0.0;
332 tw_->phaseCore2_m = 0.0;
334 tw_->apply(R, P, 0.0, E, B);
337 EXPECT_DOUBLE_EQ(E(0), 2.0);
338 EXPECT_DOUBLE_EQ(E(1), 0.0);
339 EXPECT_DOUBLE_EQ(E(2), 0.0);
341 EXPECT_DOUBLE_EQ(B(0), 0.0);
342 EXPECT_DOUBLE_EQ(B(1), 0.0);
343 EXPECT_DOUBLE_EQ(B(2), 0.0);
353 tw_->phaseExit_m = 0.0;
355 tw_->apply(R, P, 0.0, E, B);
357 EXPECT_DOUBLE_EQ(E(0), 1.0);
358 EXPECT_DOUBLE_EQ(E(1), 0.0);
359 EXPECT_DOUBLE_EQ(E(2), 0.0);
368 tw_->apply(R, P, 0.0, E, B);
370 EXPECT_DOUBLE_EQ(E(0), 1.0);
371 EXPECT_DOUBLE_EQ(E(1), 2.0);
372 EXPECT_DOUBLE_EQ(E(2), 3.0);
373 EXPECT_DOUBLE_EQ(B(0), 4.0);
374 EXPECT_DOUBLE_EQ(B(1), 5.0);
375 EXPECT_DOUBLE_EQ(B(2), 6.0);
384 tw_->apply(R, P, 0.0, E, B);
386 EXPECT_DOUBLE_EQ(E(0), 1.0);
387 EXPECT_DOUBLE_EQ(E(1), 2.0);
388 EXPECT_DOUBLE_EQ(E(2), 3.0);
389 EXPECT_DOUBLE_EQ(B(0), 4.0);
390 EXPECT_DOUBLE_EQ(B(1), 5.0);
391 EXPECT_DOUBLE_EQ(B(2), 6.0);
408 tw_->apply(R, P, 0.0, E, B);
410 EXPECT_NEAR(E(0), 0.0, 1e-12);
411 EXPECT_DOUBLE_EQ(B(1), -1.0);
423 tw_->applyToReferenceParticle(R, P, 0.0, E, B);
425 EXPECT_DOUBLE_EQ(E(0), 1.0);
432 fmap_->setOutOfBounds(
true);
439 bool out = tw_->apply(R, P, 0.0, E, B);
444 EXPECT_TRUE(tw_->isInside({0.0, 0.0, 0.0}));
445 EXPECT_TRUE(tw_->isInside({0.0, 0.0, 2.5}));
446 EXPECT_FALSE(tw_->isInside({0.0, 0.0, -1.1}));
447 EXPECT_FALSE(tw_->isInside({0.0, 0.0, 3.0}));
ippl::Vector< T, Dim > Vector_t
TEST_F(TravelingWaveTest, GetType)
Abstract base class for accelerator geometry classes.
void scale(double) override
Scale the field.
double getArcLength() const override
Get arc length.
double getElementLength() const override
Get geometry length.
Euclid3D getTransform(double, double) const override
Get transform.
void setElementLength(double length) override
Set geometry length.
Abstract base class for electromagnetic fields.
Displacement and rotation in space.
void getFieldDimensions(double &xIni, double &xFinal, double &yIni, double &yFinal, double &zIni, double &zFinal) const override
Get the full 3D bounding box of the field.
void getInfo(Inform *) override
Print info about the field map.
bool getFieldDerivative(const Vector_t< double, 3 > &, Vector_t< double, 3 > &, Vector_t< double, 3 > &, const DiffDirection &) const override
Get the field derivative with respect to a direction.
bool getFieldstrength(const Vector_t< double, 3 > &, Vector_t< double, 3 > &E, Vector_t< double, 3 > &B) const override
Get the field strength at a given point.
void getOnaxisEz(std::vector< std::pair< double, double > > &F) override
void freeMap() override
Pure virtual method to free the map data.
void setFrequency(double) override
Set the frequency.
void setOutOfBounds(bool v)
void applyField(std::shared_ptr< ParticleContainer_t >, double=1.0) override
Apply the FM to all the particles.
void readMap() override
Pure virtual method to read the map data. Called by the public static readMap().
void getFieldDimensions(double &zBegin, double &zEnd) const override
Get the longitudinal dimensions of the field.
void swap() override
Swap coordinates (implementation dependent).
double getFrequency() const override
Get the frequency.
bool isInside(const Vector_t< double, 3 > &) const override
Check if a point is inside the field map.
Abstract base class for all field maps. It acts as a factory for creating specific field map types ba...
double getFrequency() const override
Get RF frequency.
BGeometryBase & getGeometry() override
Get geometry.
ElementBase * clone() const override
Return clone.
void setFrequencyInternal(double v)
void setScaleCoreError(double v)
void setScaleCore(double v)
const BGeometryBase & getGeometry() const override
Get geometry.
double getPhase() const override
Get RF phase.
const EMField & getField() const override
Return field.
void setFieldmap(Fieldmap *fmap)
void setTestElementLength(double v)
void setAmplitude(double v)
void setEndField(double v)
double getAmplitude() const override
Get RF amplitude.
void setPhaseInternal(double v)
void setStartField(double v)
void setFrequency(double v)
void setScaleError(double v)
EMField & getField() override
Return field.
std::unique_ptr< FakeTWFieldmap > fmap_
std::unique_ptr< TestTravelingWave > tw_
Interface for traveling wave cavities.
constexpr double two_pi
The value of.
constexpr double pi
The value of.