Commit 90eaabb3 authored by ext-rogers_c's avatar ext-rogers_c

Hacky updates

parent d0c9255c
......@@ -52,3 +52,9 @@ python_module(ndgrid "${NDGRID_SRCS}")
set (POLYNOMIALPATCH_SRCS PyPolynomialPatch.cpp ${PYUTILS_SRCS})
python_module(polynomial_patch "${POLYNOMIALPATCH_SRCS}")
set (TRACKRUN_SRCS PyTrackRun.cpp ${PYUTILS_SRCS})
python_module(track_run "${TRACKRUN_SRCS}")
set (VERTICALFFAMAGNET_SRCS PyVerticalFFAMagnet.cpp ${PYUTILS_SRCS})
python_module(vertical_ffa_magnet "${VERTICALFFAMAGNET_SRCS}")
#include <string>
namespace PyOpal {
namespace Field {
std::string field_docstring =
"field module enables user to get the field at a point";
std::string get_field_value_docstring =
"Get the field value at a point in the field map.\n"
"\n"
"The field lookup is performed against the last RINGDEFINITION that was\n"
"instantiated. This should be instantiated by calling\n"
"pyopal.parser.initialise_from_opal_file\n"
"\n"
"Parameters\n"
"----------\n"
"x : float\n"
" x position [m]\n"
"y : float\n"
" y position [m]\n"
"z : float\n"
" z position [m]\n"
"t: float\n"
" time [ns]\n"
"\n"
"Returns\n"
"-------\n"
"The function returns a tuple containing 6 values:\n"
"out of bounds : int\n"
" 1 if the event was out of the field map boundary, else 0.\n"
"Bx : float\n"
" x magnetic field [T]\n"
"By : float\n"
" y magnetic field [T]\n"
"Bz : float\n"
" z magnetic field [T]\n"
"Ex : float\n"
" x electric field\n"
"Ey : float\n"
" y electric field\n"
"Ez : float\n"
" z electric field\n";
}
}
\ No newline at end of file
#include <Python.h>
#include <structmember.h>
#include <exception>
#include <iostream>
#include <boost/python.hpp>
#include "Track/TrackRun.h"
//using namespace boost::python;
std::string track_run_docstring = std::string();
boost::python::object track_run(std::string method) {
TrackRun track();
return boost::python::object(); // PyNone
}
const char* module_docstring = "field module returns the field";
BOOST_PYTHON_MODULE(track_run) {
boost::python::def("track_run",
track_run,
boost::python::args("method"),
track_run_docstring.c_str());
}
namespace PyOpal {
namespace PyTrack {
} // PyTrack
} // PyOpal
\ No newline at end of file
#include <Python.h>
#include <structmember.h>
#include <exception>
#include <iostream>
#include <boost/python.hpp>
#include <boost/noncopyable.hpp>
#include "Elements/OpalElement.h"
#include "AbstractObjects/OpalData.h"
#include "AbstractObjects/Object.h"
#include "OpalConfigure/Configure.h"
#include "Elements/OpalVerticalFFAMagnet.h"
//using namespace boost::python;
namespace PyOpal {
namespace PyVerticalFFAMagnet {
std::string track_run_docstring = std::string();
// .add_property("name", OpalVerticalFFAMagnet::getName, OpalVerticalFFAMagnet::setName);
boost::python::object vertical_ffa_magnet(
std::string name,
double b0, double field_index, double width, int max_horizontal_power,
double end_length, double centre_length, double bb_length,
double height_neg_extent, double height_pos_extent) {
Configure::configure();
OpalData* data = OpalData::getInstance();
Object* vffa_object = data->find("VERTICALFFAMAGNET");
if (!vffa_object) {
throw("Could not find vffa object");
}
vffa_object->clone(name);
OpalVerticalFFAMagnet* vffa = dynamic_cast<OpalVerticalFFAMagnet*>(vffa_object);
if (!vffa) {
throw("Could not convert vffa object");
}
return boost::python::object(); // PyNone
}
const char* module_docstring = "build a vertical_ffa_magnet";
template <class C>
class PyElement {
public:
typedef PyElement<C> PyC;
PyElement() {}
PyElement(const PyElement<C>&) { throw("Copying not allowed");}
~PyElement() {}
void setRealAttribute(std::string pyName, double value) {
if (realAttributes.find(pyName) != realAttributes.end()) {
std::string opalName = realAttributes[pyName];
element->setRegisteredAttribute(opalName, value);
}
}
double getRealAttribute(std::string name) const;
boost::python::class_<PyC> make_class(std::string className) {
auto pyclass = boost::python::class_<PyC>(className);
for (std::map<std::string, std::string>::iterator iter = realAttributes.begin(); iter != realAttributes.end(); ++iter) {
std::string pyName = iter->first;
// I don't think this works - pyName is the attribute name, I need to pass that to the get and set functions,,,
pyclass.add_property(pyName, &getRealAttribute, &setRealAttribute);
}
}
static std::map<std::string, std::string> realAttributes; // maps python name to opal name
static std::string docstring;
private:
std::shared_ptr<OpalElement> element;
};
template <>
std::map<std::string, std::string> PyElement<OpalVerticalFFAMagnet>::realAttributes = {{"b0", "B0"}};
template <>
std::string PyElement<OpalVerticalFFAMagnet>::docstring = "";
BOOST_PYTHON_MODULE(vertical_ffa_magnet) {
PyElement<OpalVerticalFFAMagnet> element;
element.make_class("OpalVerticalFFAMagnet");
}
/*
boost::python::def("vertical_ffa_magnet",
vertical_ffa_magnet,
boost::python::args("name", "b0", "field_index", "width",
"max_horizontal_power", "end_length", "centre_length",
"bb_length", "height_neg_extent", "height_pos_extent"
),
track_run_docstring.c_str());
*/
} // PyVerticalFFAMagnet
} // PyOpal
\ No newline at end of file
......@@ -138,7 +138,6 @@ TrackRun::TrackRun():
registerOwnership(AttributeHandler::SUB_COMMAND);
opal = OpalData::getInstance();
std::cerr << "TRACKRUN Ctor " << this << std::endl;
}
......@@ -150,14 +149,12 @@ TrackRun::TrackRun(const std::string &name, TrackRun *parent):
ds(NULL),
phaseSpaceSink_m(NULL) {
opal = OpalData::getInstance();
std::cerr << "TRACKRUN Ctor 2 " << this << std::endl;
}
TrackRun::~TrackRun()
{
delete phaseSpaceSink_m;
std::cerr << "TRACKRUN Dtor " << this << std::endl;
}
......
import os
import PyOpal.parser
import PyOpal.vertical_ffa_magnet
print("Running vertical_ffa_magnet test")
#os.chdir("tests/opal_src/PyOpal/dummy_lattice")
#PyOpal.parser.initialise_from_opal_file("dummy_lattice.opal")
magnet = PyOpal.vertical_ffa_magnet.vertical_ffa_magnet(
"test_vffa_magnet", 1.0, 1.0, 1.0, 4, 0.1, 1.0, 4.0, 0.1, 0.2
)
print("Generated", magnet)
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment