Skip to content

Commit

Permalink
Merge pull request #229 from fnalacceleratormodeling/egstern/cpp-vers…
Browse files Browse the repository at this point in the history
…ions-of-failing-clang-python-tests

tests added to perform same actions in C++ as failing python tests
  • Loading branch information
egstern authored Jan 18, 2024
2 parents 127b97c + 9a5b6d7 commit bff3a2d
Show file tree
Hide file tree
Showing 3 changed files with 172 additions and 0 deletions.
10 changes: 10 additions & 0 deletions src/synergia/simulation/tests/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,16 @@ target_link_libraries(test_closed_orbits_and_others synergia_simulation
synergia_test_main)
add_mpi_test(test_closed_orbits_and_others 1)

add_executable(test_propagator test_propagator.cc)
target_link_libraries(test_propagator synergia_simulation
synergia_test_main)
add_mpi_test(test_propagator 1)

add_executable(test_lattice_no_beam_statement test_lattice_no_beam_statement.cc)
target_link_libraries(test_lattice_no_beam_statement synergia_simulation
synergia_test_main)
add_mpi_test(test_lattice_no_beam_statement 1)

if(BUILD_PYTHON_BINDINGS)
add_py_test(test_propagator.py)
add_py_test(test_nonlinear_maps.py)
Expand Down
59 changes: 59 additions & 0 deletions src/synergia/simulation/tests/test_lattice_no_beam_statement.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
#include "synergia/utils/catch.hpp"


#include "synergia/lattice/lattice.h"
#include "synergia/lattice/lattice_element.h"

#include "synergia/lattice/madx_reader.h"
#include "synergia/utils/commxx.h"
#include "synergia/utils/logger.h"
#include "synergia/utils/simple_timer.h"
#include "synergia/utils/utils.h"
#include "synergia/simulation/propagator.h"
#include "synergia/simulation/independent_stepper_elements.h"

#include <iomanip>
#include <iostream>
#include <string>


Lattice
get_lattice()
{
static std::string fodo_madx(R"foo(
d: drift, l=1.0;
q: quadrupole, l=1.0, k1=0.1;
s: sextupole, l=0.1, k2=0.1;
o: octupole, l=0.1, k3=0.05;
b: sbend, l=1.0, angle=pi/24;
cf1: sbend, l=2.889612, angle=0.07074218219630160065, k1=0.05410921561;
cf2: sbend, l=2.889612, angle=0.07074218219630160065, e1=0.03537109109815080032, e2=0.03537109109815080032, k1=0.05410921561, k2=-0.006384940;
rfc: rfcavity, l=0.0, volt=0.2, freq=44.0;
elems: line=(d, q, s, o, b, cf1, cf2, rfc);
)foo");

MadX_reader reader;
reader.parse(fodo_madx);
return reader.get_lattice("elems");
}

// this lattice failed with the clang build without the llvm unwinder
TEST_CASE("get_lattice")
{
Lattice lattice(get_lattice());
}

Propagator
create_propagator(Lattice lattice)
{
Independent_stepper_elements stepper(1);
Propagator prop(lattice, stepper);
return prop;
}

TEST_CASE("create_propagator")
{
Lattice lattice(get_lattice());
Propagator p(create_propagator(lattice));
}
103 changes: 103 additions & 0 deletions src/synergia/simulation/tests/test_propagator.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,103 @@
#include "synergia/utils/catch.hpp"


#include "synergia/lattice/lattice.h"
#include "synergia/lattice/lattice_element.h"

#include "synergia/lattice/madx_reader.h"
#include "synergia/utils/commxx.h"
#include "synergia/utils/logger.h"
#include "synergia/utils/simple_timer.h"
#include "synergia/utils/utils.h"
#include "synergia/simulation/propagator.h"
#include "synergia/simulation/independent_stepper_elements.h"

#include <iomanip>
#include <iostream>
#include <string>


Lattice
get_lattice()
{
static std::string fodo_madx(R"foo(
beam, particle=proton,pc=3.0;
o: drift, l=8.0;
f: quadrupole, l=2.0, k1=0.071428571428571425, a1=1.0;
d: quadrupole, l=2.0, k1=-0.071428571428571425;
fodo: sequence, l=20.0, refer=entry;
fodo_1: f, at=0.0;
fodo_2: o, at=2.0;
fodo_3: d, at=10.0;
fodo_4: o, at=12.0;
endsequence;
)foo");

MadX_reader reader;
reader.parse(fodo_madx);
return reader.get_lattice("fodo");
}

Propagator
create_propagator(Lattice lattice)
{
Independent_stepper_elements stepper(1);
Propagator prop(lattice, stepper);
return prop;
}

TEST_CASE("create_propagator")
{
Lattice lattice(get_lattice());
Propagator p(create_propagator(lattice));
}

TEST_CASE("test_prop_get_lattice_elements")
{
Lattice lattice(get_lattice());
Propagator p(create_propagator(lattice));

int nlattice_elem = lattice.get_elements().size();
int nprop_elem = p.get_lattice().get_elements().size();
CHECK (nlattice_elem == nprop_elem);
}

TEST_CASE("test_modify_lattice_elements")
{
Lattice lattice(get_lattice());
Propagator p(create_propagator(lattice));

std::list<Lattice_element>& elems(p.get_lattice().get_elements());
std::list<Lattice_element>::iterator first = elems.begin();
int orig_a1 = (*first).get_double_attribute("a1");

int new_a1 = orig_a1 + 100.0;
(*first).set_double_attribute("a1", new_a1);

std::list<Lattice_element> const& newelems(p.get_lattice().get_elements());
std::list<Lattice_element>::const_iterator newfirst = newelems.begin();
CHECK ( (*newfirst).get_double_attribute("a1") == Approx(new_a1) );

Propagator::Lattice_element_slices les = p.get_lattice_element_slices();
// with Independent_stepper_elements, first slice is first element
// check a1 attribute
Propagator::Slice_iterator sit = les.begin();

double test_a1 = (*sit).get_lattice_element().get_double_attribute("a1");
CHECK (test_a1 == Approx(new_a1));
}

TEST_CASE("test_modify_reference_particle_energy")
{
Lattice lattice(get_lattice());
Propagator p(create_propagator(lattice));

double orig_energy = lattice.get_reference_particle().get_total_energy();
int new_energy = orig_energy + 1.0;
p.get_lattice().get_reference_particle().set_total_energy(new_energy);

CHECK ( p.get_lattice().get_reference_particle().get_total_energy() == Approx(new_energy) );

}

0 comments on commit bff3a2d

Please sign in to comment.