Code indexing in gitaly is broken and leads to code not being visible to the user. We work on the issue with highest priority.

Skip to content
Snippets Groups Projects
Commit 45cfd8c2 authored by ext-rogers_c's avatar ext-rogers_c
Browse files

Add SplineTimeDependence element

parent a479cd94
No related branches found
No related tags found
No related merge requests found
...@@ -16,6 +16,7 @@ set (_SRCS ...@@ -16,6 +16,7 @@ set (_SRCS
PartData.cpp PartData.cpp
OpalParticle.cpp OpalParticle.cpp
PolynomialTimeDependence.cpp PolynomialTimeDependence.cpp
SplineTimeDependence.cpp
Surveyor.cpp Surveyor.cpp
ThinMapper.cpp ThinMapper.cpp
ThinTracker.cpp ThinTracker.cpp
...@@ -57,6 +58,7 @@ set (HDRS ...@@ -57,6 +58,7 @@ set (HDRS
PolynomialTimeDependence.h PolynomialTimeDependence.h
Quaternion.h Quaternion.h
rbendmap.h rbendmap.h
SplineTimeDependence.h
Surveyor.h Surveyor.h
ThinMapper.h ThinMapper.h
ThinTracker.h ThinTracker.h
......
...@@ -33,13 +33,9 @@ ...@@ -33,13 +33,9 @@
#include <gsl/gsl_spline.h> #include <gsl/gsl_spline.h>
#include "Ippl.h" #include "Ippl.h"
#include "Utilities/GeneralClassicException.h"
#include "Algorithms/AbstractTimeDependence.h" #include "Algorithms/AbstractTimeDependence.h"
namespace interpolation {
class PolynomialPatch;
}
/** @class SplineTimeDependence /** @class SplineTimeDependence
* *
* Time dependence that follows a spline. Interpolation is supported at * Time dependence that follows a spline. Interpolation is supported at
...@@ -59,6 +55,10 @@ class SplineTimeDependence : public AbstractTimeDependence { ...@@ -59,6 +55,10 @@ class SplineTimeDependence : public AbstractTimeDependence {
* with quadratic smoothing) * with quadratic smoothing)
* @param times the times of successive elements in the time dependence * @param times the times of successive elements in the time dependence
* @param values the values at each time step. * @param values the values at each time step.
*
* It is an error if times and values are not of equal length, times and
* values length < splineOrder + 1, or times do not increase strictly
* monotonically.
*/ */
SplineTimeDependence(size_t splineOrder, SplineTimeDependence(size_t splineOrder,
std::vector<double> times, std::vector<double> times,
......
...@@ -46,6 +46,7 @@ set (_SRCS ...@@ -46,6 +46,7 @@ set (_SRCS
OpalSlit.cpp OpalSlit.cpp
OpalSolenoid.cpp OpalSolenoid.cpp
OpalSource.cpp OpalSource.cpp
OpalSplineTimeDependence.cpp
OpalSRot.cpp OpalSRot.cpp
OpalVariableRFCavity.cpp OpalVariableRFCavity.cpp
OpalVariableRFCavityFringeField.cpp OpalVariableRFCavityFringeField.cpp
...@@ -108,6 +109,7 @@ set (HDRS ...@@ -108,6 +109,7 @@ set (HDRS
OpalSlit.h OpalSlit.h
OpalSolenoid.h OpalSolenoid.h
OpalSource.h OpalSource.h
OpalSplineTimeDependence.h
OpalSRot.h OpalSRot.h
OpalStripper.h OpalStripper.h
OpalTravelingWave.h OpalTravelingWave.h
......
...@@ -28,11 +28,8 @@ ...@@ -28,11 +28,8 @@
#ifndef OPAL_OpalPolynomialTimeDependence_HH #ifndef OPAL_OpalPolynomialTimeDependence_HH
#define OPAL_OpalPolynomialTimeDependence_HH #define OPAL_OpalPolynomialTimeDependence_HH
#include "Algorithms/PolynomialTimeDependence.h"
#include "Elements/OpalElement.h" #include "Elements/OpalElement.h"
class PolynomialTimeDependence;
/** OpalPolynomialTimeDependence provides UI wrapper for the /** OpalPolynomialTimeDependence provides UI wrapper for the
* PolynomialTimeDependence * PolynomialTimeDependence
*/ */
......
/*
* Copyright (c) 2018, Chris Rogers
* All rights reserved.
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
* 1. Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
* 3. Neither the name of STFC nor the names of its contributors may be used to
* endorse or promote products derived from this software without specific
* prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*/
#include <string>
#include "Attributes/Attributes.h"
#include "Utilities/OpalException.h"
#include "Elements/OpalSplineTimeDependence.h"
const std::string OpalSplineTimeDependence::doc_string =
std::string("The \"SPLINE_TIME_DEPENDENCE\" element defines ")+\
std::string("an array of times and corresponding values for time lookup, ")+\
std::string("for use in time-dependent elements. Lookup is supported at ")+\
std::string("first order or third order with quadratic smoothing.");
// I investigated using a StringArray or RealArray here;
// Don't seem to have capacity to handle variables, so for now not implemented
OpalSplineTimeDependence::OpalSplineTimeDependence()
: OpalElement(int(SIZE),
"SPLINE_TIME_DEPENDENCE",
doc_string.c_str()) {
itsAttr[ORDER] = Attributes::makeReal("ORDER",
std::string("Order of the lookup - either 1 for linear interpolation, ")+
std::string("or 3 for cubic interpolation with quadratic smoothing. ")+
std::string("Other values make an error."));
itsAttr[TIMES] = Attributes::makeRealArray("TIMES",
std::string("Array of real times in ns. There must be at least \"ORDER\"+1 ")+
std::string("elements in the array and they must be strictly monotically ")+
std::string("increasing"));
itsAttr[VALUES] = Attributes::makeRealArray("VALUES",
std::string("Array of real values. The length of \"VALUES\" must be the ")+
std::string("same as the length of \"TIMES\"."));
registerRealAttribute("ORDER");
registerRealAttribute("TIMES");
registerRealAttribute("VALUES");
registerOwnership();
}
OpalSplineTimeDependence* OpalSplineTimeDependence::clone(const std::string &name) {
return new OpalSplineTimeDependence(name, this);
}
void OpalSplineTimeDependence::print(std::ostream& out) const {
OpalElement::print(out);
}
OpalSplineTimeDependence::OpalSplineTimeDependence(const std::string &name,
OpalSplineTimeDependence *parent):
OpalElement(name, parent) {
}
OpalSplineTimeDependence::~OpalSplineTimeDependence() {}
void OpalSplineTimeDependence::fillRegisteredAttributes
(const ElementBase &base, ValueFlag flag) {
OpalElement::fillRegisteredAttributes(base, flag);
}
void OpalSplineTimeDependence::update() {
double orderReal = Attributes::getReal(itsAttr[ORDER])+1e-10;
if ((orderReal - 1.) > 1e-9 && (orderReal - 3.) > 1e-9) {
throw OpalException("OpalSplineTimeDependence::update",
"SPLINE_TIME_DEPENDENCE \"ORDER\" should be 1 or 3.");
}
size_t order(floor(orderReal));
std::vector<double> times = Attributes::getRealArray(itsAttr[TIMES]);
std::vector<double> values = Attributes::getRealArray(itsAttr[VALUES]);
std::shared_ptr<SplineTimeDependence> spline =
std::make_shared<SplineTimeDependence>(order,
times,
values);
AbstractTimeDependence::setTimeDependence(getOpalName(), spline);
}
/*
* Copyright (c) 2018, Chris Rogers
* All rights reserved.
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
* 1. Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
* 3. Neither the name of STFC nor the names of its contributors may be used to
* endorse or promote products derived from this software without specific
* prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*/
#ifndef OPAL_OpalSplineTimeDependence_HH
#define OPAL_OpalSplineTimeDependence_HH
#include "Algorithms/SplineTimeDependence.h"
#include "Elements/OpalElement.h"
/** OpalSplineTimeDependence provides UI wrapper for the
* SplineTimeDependence
*/
class OpalSplineTimeDependence : public OpalElement {
public:
/** Enumeration maps to UI parameters */
enum {
ORDER = COMMON,
TIMES,
VALUES,
SIZE // size of the enum
};
/** Define mapping from enum variables to string UI parameter names */
OpalSplineTimeDependence();
/** No memory allocated so does nothing */
virtual ~OpalSplineTimeDependence();
/** Inherited copy constructor */
virtual OpalSplineTimeDependence *clone(const std::string &name);
/** Calls fillRegisteredAttributes on the OpalElement */
void fillRegisteredAttributes(const ElementBase &base, ValueFlag flag);
/** Receive parameters from the parser and hand them off to the
* SplineTimeDependence
*/
void update();
/** Calls print on the OpalElement */
virtual void print(std::ostream &) const;
private:
// Not implemented.
OpalSplineTimeDependence(const OpalSplineTimeDependence &);
void operator=(const OpalSplineTimeDependence &);
// Clone constructor.
OpalSplineTimeDependence(const std::string &name,
OpalSplineTimeDependence *parent);
static const std::string doc_string;
};
#endif // OPAL_OpalSplineTimeDependence_HH
set (_SRCS set (_SRCS
PolynomialTimeDependenceTest.cpp PolynomialTimeDependenceTest.cpp
SplineTimeDependenceTest.cpp
) )
include_directories ( include_directories (
......
/*
* Copyright (c) 2014, Chris Rogers
* All rights reserved.
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
* 1. Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
* 3. Neither the name of STFC nor the names of its contributors may be used to
* endorse or promote products derived from this software without specific
* prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*/
#include "gtest/gtest.h" #include "gtest/gtest.h"
#include "Utilities/GeneralClassicException.h" #include "Utilities/GeneralClassicException.h"
#include "Algorithms/AbstractTimeDependence.h" #include "Algorithms/AbstractTimeDependence.h"
......
...@@ -30,8 +30,6 @@ ...@@ -30,8 +30,6 @@
#include "Utilities/GeneralClassicException.h" #include "Utilities/GeneralClassicException.h"
#include "Algorithms/SplineTimeDependence.h" #include "Algorithms/SplineTimeDependence.h"
using interpolation::PolynomialPatch;
class SplineTimeDependenceTest : public ::testing::Test { class SplineTimeDependenceTest : public ::testing::Test {
public: public:
SplineTimeDependenceTest() : times_m(10), values_m(10) { SplineTimeDependenceTest() : times_m(10), values_m(10) {
......
set (_SRCS set (_SRCS
OpalOffsetTest.cpp OpalOffsetTest.cpp
OpalPolynomialTimeDependenceTest.cpp OpalPolynomialTimeDependenceTest.cpp
OpalSplineTimeDependenceTest.cpp
OpalVariableRFCavityTest.cpp OpalVariableRFCavityTest.cpp
OpalVariableRFCavityFringeFieldTest.cpp OpalVariableRFCavityFringeFieldTest.cpp
) )
......
#include <sstream>
#include "gtest/gtest.h"
#include "Elements/OpalSplineTimeDependence.h"
#include "opal_test_utilities/SilenceTest.h"
TEST(OpalSplineTimeDependenceTest, ConstructorTest) {
OpalTestUtilities::SilenceTest silencer;
OpalSplineTimeDependence dep;
OpalSplineTimeDependence* dep_clone = dep.clone("new name");
EXPECT_EQ(dep_clone->getOpalName(), "new name");
}
TEST(OpalSplineSplineDependenceTest, PrintTest) {
OpalTestUtilities::SilenceTest silencer;
OpalSplineTimeDependence dep;
std::stringstream _string;
dep.print(_string);
EXPECT_EQ(_string.str(), "SPLINE_TIME_DEPENDENCE;\n");
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment