diff --git a/environment.yml b/environment.yml index 556ecff3..beb9679b 100644 --- a/environment.yml +++ b/environment.yml @@ -2,7 +2,7 @@ name: pyorbit channels: - conda-forge dependencies: - - python=3.10 + - python>=3.11 - fftw - numpy - scipy diff --git a/meson.build b/meson.build index d37025ea..ce4cd76f 100644 --- a/meson.build +++ b/meson.build @@ -10,4 +10,6 @@ project('PyORBIT', ) subdir('src') -subdir('py/orbit') +if get_option('BUILD_PYTHON') + subdir('py/orbit') +endif diff --git a/meson_options.txt b/meson_options.txt index 3ae5f6ab..64ce4c8f 100644 --- a/meson_options.txt +++ b/meson_options.txt @@ -1 +1,2 @@ option('USE_MPI', type: 'string', value: 'auto', description: 'Choose MPI implementation (mpich, openmpi, none, auto)') +option('BUILD_PYTHON', type: 'boolean', value: true, description: 'Build and install Python bindings') diff --git a/pyproject.toml b/pyproject.toml index d601642b..268f1bc1 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -6,7 +6,7 @@ requires = ['meson-python', "setuptools>=45", "wheel", "setuptools_scm"] name = 'PyORBIT' dynamic = ["version"] description = 'Use meson-python to build c++ anf python modules.' -requires-python = '>=3.9' +requires-python = '>=3.11' #dependencies = [ #'setuptools', #'setuptools-scm' diff --git a/src/core/aperture_init.cc b/src/core/aperture_init.cc index 08f949de..1950d6ba 100644 --- a/src/core/aperture_init.cc +++ b/src/core/aperture_init.cc @@ -1,4 +1,4 @@ -#include "wrap_aperture.hh" +#include "orbit/Apertures/wrap_aperture.hh" PyMODINIT_FUNC PyInit_aperture(void) { return wrap_aperture::initaperture(); } \ No newline at end of file diff --git a/src/core/bunch_init.cc b/src/core/bunch_init.cc index d9d6b8de..a1f2b3ba 100644 --- a/src/core/bunch_init.cc +++ b/src/core/bunch_init.cc @@ -1,4 +1,4 @@ -#include "wrap_bunch.hh" +#include "orbit/wrap_bunch.hh" PyMODINIT_FUNC PyInit_bunch(void) { return wrap_orbit_bunch::initbunch(); } \ No newline at end of file diff --git a/src/core/collimator_init.cc b/src/core/collimator_init.cc index 2f88f044..5d1e7e3c 100644 --- a/src/core/collimator_init.cc +++ b/src/core/collimator_init.cc @@ -1,4 +1,4 @@ -# include "wrap_collimator.hh" +# include "orbit/MaterialInteractions/wrap_collimator.hh" PyMODINIT_FUNC PyInit_collimator(void) { return wrap_collimator::initcollimator(); } diff --git a/src/core/error_base_init.cc b/src/core/error_base_init.cc index 1e6888aa..76b02342 100644 --- a/src/core/error_base_init.cc +++ b/src/core/error_base_init.cc @@ -1,5 +1,5 @@ #include -# include "wrap_errorbase.hh" +# include "orbit/Errors/wrap_errorbase.hh" PyMODINIT_FUNC PyInit_error_base(void) { return wrap_errorbase::initerrorbase(); } \ No newline at end of file diff --git a/src/core/field_sources_init.cc b/src/core/field_sources_init.cc index e592a9c4..aa8f9220 100644 --- a/src/core/field_sources_init.cc +++ b/src/core/field_sources_init.cc @@ -1,4 +1,4 @@ -#include "wrap_field_sources_module.hh" +#include "utils/field_sources/wrap_field_sources_module.hh" PyMODINIT_FUNC PyInit_field_sources(void) { return wrap_field_sources_module::initFieldSourcesModule(); } \ No newline at end of file diff --git a/src/core/fieldtracker_init.cc b/src/core/fieldtracker_init.cc index 15b9c9cd..16f0f3d1 100644 --- a/src/core/fieldtracker_init.cc +++ b/src/core/fieldtracker_init.cc @@ -1,4 +1,4 @@ -#include "wrap_fieldtracker.hh" +#include "orbit/FieldTracker/wrap_fieldtracker.hh" PyMODINIT_FUNC PyInit_fieldtracker(void) { return wrap_fieldtracker::initfieldtracker(); } \ No newline at end of file diff --git a/src/core/foil_init.cc b/src/core/foil_init.cc index 3c5869c2..8132a765 100644 --- a/src/core/foil_init.cc +++ b/src/core/foil_init.cc @@ -1,4 +1,4 @@ -#include "wrap_foil.hh" +#include "orbit/MaterialInteractions/wrap_foil.hh" PyMODINIT_FUNC PyInit_foil(void) { return wrap_foil::initfoil(); } diff --git a/src/core/impedances_init.cc b/src/core/impedances_init.cc index 48b9cf5a..af13db5c 100644 --- a/src/core/impedances_init.cc +++ b/src/core/impedances_init.cc @@ -1,4 +1,4 @@ -#include "wrap_impedances.hh" +#include "orbit/Impedances/wrap_impedances.hh" PyMODINIT_FUNC PyInit_impedances(void) { return wrap_impedances::initimpedances(); } \ No newline at end of file diff --git a/src/core/linac_init.cc b/src/core/linac_init.cc index 9797a77e..7003f8ee 100644 --- a/src/core/linac_init.cc +++ b/src/core/linac_init.cc @@ -1,4 +1,4 @@ -#include "wrap_linacmodule.hh" +#include "linac/wrap_linacmodule.hh" PyMODINIT_FUNC PyInit_linac(void) { return wrap_linac::initlinac(); } \ No newline at end of file diff --git a/src/core/mpi_init.cc b/src/core/mpi_init.cc index 19fcf616..821b0d20 100644 --- a/src/core/mpi_init.cc +++ b/src/core/mpi_init.cc @@ -1,6 +1,6 @@ -#include "Python.h" -#include "wrap_orbit_mpi.hh" +#include +#include "mpi/wrap_orbit_mpi.hh" PyMODINIT_FUNC PyInit_orbit_mpi(void) { return wrap_orbit_mpi::initorbit_mpi(); -} \ No newline at end of file +} diff --git a/src/core/rfcavities_init.cc b/src/core/rfcavities_init.cc index 112c15dc..bb742bfb 100644 --- a/src/core/rfcavities_init.cc +++ b/src/core/rfcavities_init.cc @@ -1,4 +1,4 @@ -#include "wrap_rfcavities.hh" +#include "orbit/RFCavities/wrap_rfcavities.hh" PyMODINIT_FUNC PyInit_rfcavities(void) { return wrap_rfcavities::initrfcavities(); } \ No newline at end of file diff --git a/src/core/spacecharge_init.cc b/src/core/spacecharge_init.cc index 730b25b5..04b42c62 100644 --- a/src/core/spacecharge_init.cc +++ b/src/core/spacecharge_init.cc @@ -1,4 +1,4 @@ -#include "wrap_spacecharge.hh" +#include "spacecharge/wrap_spacecharge.hh" PyMODINIT_FUNC PyInit_spacecharge(void) { return initspacecharge(); } \ No newline at end of file diff --git a/src/core/teapot_base_init.cc b/src/core/teapot_base_init.cc index 9dc74c73..a682fdce 100644 --- a/src/core/teapot_base_init.cc +++ b/src/core/teapot_base_init.cc @@ -1,7 +1,7 @@ #include -#include "wrap_orbit_mpi.hh" -#include "wrap_teapotbase.hh" -#include "wrap_errorbase.hh" +#include "mpi/wrap_orbit_mpi.hh" +#include "teapot/wrap_teapotbase.hh" +#include "orbit/Errors/wrap_errorbase.hh" PyMODINIT_FUNC PyInit_teapot_base(void) { return wrap_teapotbase::initteapotbase(); diff --git a/src/core/trackerrk4_init.cc b/src/core/trackerrk4_init.cc index 87f23f7d..77c3744a 100644 --- a/src/core/trackerrk4_init.cc +++ b/src/core/trackerrk4_init.cc @@ -1,4 +1,4 @@ -#include "wrap_trackerrk4.hh" +#include "trackerrk4/wrap_trackerrk4.hh" PyMODINIT_FUNC PyInit_trackerrk4(void) { return inittrackerrk4(); } \ No newline at end of file diff --git a/src/core/type_accessors.cc b/src/core/type_accessors.cc new file mode 100644 index 00000000..ce2594e1 --- /dev/null +++ b/src/core/type_accessors.cc @@ -0,0 +1,68 @@ +#include + +#include "orbit/wrap_bunch.hh" +#include "spacecharge/wrap_spacecharge.hh" +#include "mpi/wrap_mpi_comm.hh" +#include "utils/wrap_utils.hh" +#include "trackerrk4/wrap_trackerrk4.hh" + +extern "C" { + +namespace { + +PyObject* getModuleAttribute(const char* module_name, const char* name){ + PyObject* module = PyImport_ImportModule(module_name); + if(module == NULL){ + return NULL; + } + PyObject* attribute = PyDict_GetItemString(PyModule_GetDict(module), name); + Py_DECREF(module); + if(attribute == NULL){ + PyErr_Format(PyExc_AttributeError, "module '%s' has no attribute '%s'", module_name, name); + } + return attribute; +} + +} + +namespace wrap_orbit_bunch { + +PyObject* getBunchType(const char* name){ + return getModuleAttribute("orbit.core.bunch", name); +} + +} + +PyObject* getSpaceChargeType(const char* name){ + return getModuleAttribute("orbit.core.spacecharge", name); +} + +namespace wrap_orbit_mpi_comm { + +PyObject* getMPI_CommType(const char* name){ + PyObject* mpi_comm_module = getModuleAttribute("orbit.core.orbit_mpi", "mpi_comm"); + if(mpi_comm_module == NULL){ + return NULL; + } + PyObject* type = PyDict_GetItemString(PyModule_GetDict(mpi_comm_module), name); + if(type == NULL){ + PyErr_Format(PyExc_AttributeError, "module 'mpi_comm' has no attribute '%s'", name); + } + return type; +} + +} + +namespace wrap_orbit_utils { + +PyObject* getOrbitUtilsType(const char* name){ + return getModuleAttribute("orbit.core.orbit_utils", name); +} + +} + +PyObject* getTrackerRK4Type(const char* name){ + return getModuleAttribute("orbit.core.trackerrk4", name); +} + +} diff --git a/src/core/utils_init.cc b/src/core/utils_init.cc index 5f8cd02f..d3af5291 100644 --- a/src/core/utils_init.cc +++ b/src/core/utils_init.cc @@ -1,4 +1,4 @@ -#include "wrap_utils.hh" +#include "utils/wrap_utils.hh" PyMODINIT_FUNC PyInit_orbit_utils(void) { return wrap_orbit_utils::initutils(); } \ No newline at end of file diff --git a/src/linac/rfgap/BaseRfGap.cc b/src/linac/rfgap/BaseRfGap.cc index b185f539..4fd2ffdc 100644 --- a/src/linac/rfgap/BaseRfGap.cc +++ b/src/linac/rfgap/BaseRfGap.cc @@ -8,20 +8,20 @@ A. Shishlo, J. Holmes, ORNL Tech. Note ORNL/TM-2015/247, June 2015 */ -#include "BaseRfGap.hh" -#include "ParticleMacroSize.hh" +#include "linac/rfgap/BaseRfGap.hh" +#include "orbit/ParticlesAttributes/ParticleMacroSize.hh" #include #include -#include "Bunch.hh" -#include "bessel.hh" -#include "OrbitConst.hh" +#include "orbit/Bunch.hh" +#include "utils/bessel.hh" +#include "orbit/OrbitConst.hh" using namespace OrbitUtils; // Constructor -BaseRfGap::BaseRfGap(): CppPyWrapper(NULL) +BaseRfGap::BaseRfGap() { } diff --git a/src/linac/rfgap/BaseRfGap.hh b/src/linac/rfgap/BaseRfGap.hh index 5deb4d68..284a02c4 100644 --- a/src/linac/rfgap/BaseRfGap.hh +++ b/src/linac/rfgap/BaseRfGap.hh @@ -5,25 +5,22 @@ #define BASE_RF_GAP_H //MPI Function Wrappers -#include "orbit_mpi.hh" -#include "wrap_mpi_comm.hh" +#include "mpi/orbit_mpi.hh" #include #include //ORBIT bunch -#include "Bunch.hh" +#include "orbit/Bunch.hh" //pyORBIT utils -#include "CppPyWrapper.hh" -using namespace std; /** This class represents a 2D rectangular grid. */ -class BaseRfGap: public OrbitUtils::CppPyWrapper +class BaseRfGap { public: diff --git a/src/linac/rfgap/BaseRfGap_slow.cc b/src/linac/rfgap/BaseRfGap_slow.cc index d43d721a..2345ad4d 100644 --- a/src/linac/rfgap/BaseRfGap_slow.cc +++ b/src/linac/rfgap/BaseRfGap_slow.cc @@ -15,20 +15,20 @@ so the name of the class has the word slow in the name. */ -#include "BaseRfGap_slow.hh" -#include "ParticleMacroSize.hh" +#include "linac/rfgap/BaseRfGap_slow.hh" +#include "orbit/ParticlesAttributes/ParticleMacroSize.hh" #include #include -#include "Bunch.hh" -#include "bessel.hh" -#include "OrbitConst.hh" +#include "orbit/Bunch.hh" +#include "utils/bessel.hh" +#include "orbit/OrbitConst.hh" using namespace OrbitUtils; // Constructor -BaseRfGap_slow::BaseRfGap_slow(): CppPyWrapper(NULL) +BaseRfGap_slow::BaseRfGap_slow() { } diff --git a/src/linac/rfgap/BaseRfGap_slow.hh b/src/linac/rfgap/BaseRfGap_slow.hh index de39488f..49211096 100644 --- a/src/linac/rfgap/BaseRfGap_slow.hh +++ b/src/linac/rfgap/BaseRfGap_slow.hh @@ -9,25 +9,22 @@ #define BASE_RF_GAP_SLOW_H //MPI Function Wrappers -#include "orbit_mpi.hh" -#include "wrap_mpi_comm.hh" +#include "mpi/orbit_mpi.hh" #include #include //ORBIT bunch -#include "Bunch.hh" +#include "orbit/Bunch.hh" //pyORBIT utils -#include "CppPyWrapper.hh" -using namespace std; /** This class represents a 2D rectangular grid. */ -class BaseRfGap_slow: public OrbitUtils::CppPyWrapper +class BaseRfGap_slow { public: diff --git a/src/linac/rfgap/MatrixRfGap.cc b/src/linac/rfgap/MatrixRfGap.cc index 6283f8c8..2a50d253 100644 --- a/src/linac/rfgap/MatrixRfGap.cc +++ b/src/linac/rfgap/MatrixRfGap.cc @@ -9,12 +9,12 @@ A. Shishlo, J. Holmes, ORNL Tech. Note ORNL/TM-2015/247, June 2015 */ -#include "MatrixRfGap.hh" -#include "ParticleMacroSize.hh" +#include "linac/rfgap/MatrixRfGap.hh" +#include "orbit/ParticlesAttributes/ParticleMacroSize.hh" -#include "Bunch.hh" -#include "bessel.hh" -#include "OrbitConst.hh" +#include "orbit/Bunch.hh" +#include "utils/bessel.hh" +#include "orbit/OrbitConst.hh" #include #include @@ -22,7 +22,7 @@ ORNL Tech. Note ORNL/TM-2015/247, June 2015 using namespace OrbitUtils; // Constructor -MatrixRfGap::MatrixRfGap(): CppPyWrapper(NULL) +MatrixRfGap::MatrixRfGap() { } diff --git a/src/linac/rfgap/MatrixRfGap.hh b/src/linac/rfgap/MatrixRfGap.hh index c021514c..d3ef91b2 100644 --- a/src/linac/rfgap/MatrixRfGap.hh +++ b/src/linac/rfgap/MatrixRfGap.hh @@ -8,25 +8,22 @@ For this RF gap we know the E0TL, frequency, and phase only. #define MATRIX_RF_GAP_H //MPI Function Wrappers -#include "orbit_mpi.hh" -#include "wrap_mpi_comm.hh" +#include "mpi/orbit_mpi.hh" #include #include //ORBIT bunch -#include "Bunch.hh" +#include "orbit/Bunch.hh" //pyORBIT utils -#include "CppPyWrapper.hh" -using namespace std; /** This class represents a RF gap as transport matrix. No nonlinear effects. */ -class MatrixRfGap: public OrbitUtils::CppPyWrapper +class MatrixRfGap { public: diff --git a/src/linac/rfgap/RfGapTTF.cc b/src/linac/rfgap/RfGapTTF.cc index 5d26751a..58e419c1 100644 --- a/src/linac/rfgap/RfGapTTF.cc +++ b/src/linac/rfgap/RfGapTTF.cc @@ -10,10 +10,10 @@ ORNL Tech. Note ORNL/TM-2015/247, June 2015 */ -#include "Bunch.hh" -#include "bessel.hh" -#include "OrbitConst.hh" -#include "RfGapTTF.hh" +#include "orbit/Bunch.hh" +#include "utils/bessel.hh" +#include "orbit/OrbitConst.hh" +#include "linac/rfgap/RfGapTTF.hh" #include #include @@ -22,7 +22,7 @@ using namespace OrbitUtils; // Constructor -RfGapTTF::RfGapTTF(): CppPyWrapper(NULL) +RfGapTTF::RfGapTTF() { } diff --git a/src/linac/rfgap/RfGapTTF.hh b/src/linac/rfgap/RfGapTTF.hh index 9d4f81b6..a83438db 100644 --- a/src/linac/rfgap/RfGapTTF.hh +++ b/src/linac/rfgap/RfGapTTF.hh @@ -8,27 +8,24 @@ #define TTF_RF_GAP_H //MPI Function Wrappers -#include "orbit_mpi.hh" -#include "wrap_mpi_comm.hh" +#include "mpi/orbit_mpi.hh" #include #include //ORBIT bunch -#include "Bunch.hh" +#include "orbit/Bunch.hh" //pyORBIT utils -#include "CppPyWrapper.hh" -#include "OU_Polynomial.hh" +#include "utils/polynomial/OU_Polynomial.hh" -using namespace std; /** This class represents a RF gap as a Parmila type gap. */ -class RfGapTTF: public OrbitUtils::CppPyWrapper +class RfGapTTF { public: diff --git a/src/linac/rfgap/RfGapTTF_slow.cc b/src/linac/rfgap/RfGapTTF_slow.cc index 2d1b2a43..3bdcdd32 100644 --- a/src/linac/rfgap/RfGapTTF_slow.cc +++ b/src/linac/rfgap/RfGapTTF_slow.cc @@ -17,10 +17,10 @@ */ -#include "Bunch.hh" -#include "bessel.hh" -#include "OrbitConst.hh" -#include "RfGapTTF_slow.hh" +#include "orbit/Bunch.hh" +#include "utils/bessel.hh" +#include "orbit/OrbitConst.hh" +#include "linac/rfgap/RfGapTTF_slow.hh" #include #include @@ -29,7 +29,7 @@ using namespace OrbitUtils; // Constructor -RfGapTTF_slow::RfGapTTF_slow(): CppPyWrapper(NULL) +RfGapTTF_slow::RfGapTTF_slow() { } diff --git a/src/linac/rfgap/RfGapTTF_slow.hh b/src/linac/rfgap/RfGapTTF_slow.hh index fe22376c..22ba0645 100644 --- a/src/linac/rfgap/RfGapTTF_slow.hh +++ b/src/linac/rfgap/RfGapTTF_slow.hh @@ -10,27 +10,24 @@ #define TTF_RF_GAP_SLOW_H //MPI Function Wrappers -#include "orbit_mpi.hh" -#include "wrap_mpi_comm.hh" +#include "mpi/orbit_mpi.hh" #include #include //ORBIT bunch -#include "Bunch.hh" +#include "orbit/Bunch.hh" //pyORBIT utils -#include "CppPyWrapper.hh" -#include "OU_Polynomial.hh" +#include "utils/polynomial/OU_Polynomial.hh" -using namespace std; /** This class represents a RF gap as a Parmila type gap. */ -class RfGapTTF_slow: public OrbitUtils::CppPyWrapper +class RfGapTTF_slow { public: diff --git a/src/linac/rfgap/RfGapThreePointTTF.cc b/src/linac/rfgap/RfGapThreePointTTF.cc index 2fab396e..1b267d19 100644 --- a/src/linac/rfgap/RfGapThreePointTTF.cc +++ b/src/linac/rfgap/RfGapThreePointTTF.cc @@ -11,10 +11,10 @@ ORNL Tech. Note ORNL/TM-2015/247, June 2015 */ -#include "Bunch.hh" -#include "bessel.hh" -#include "OrbitConst.hh" -#include "RfGapThreePointTTF.hh" +#include "orbit/Bunch.hh" +#include "utils/bessel.hh" +#include "orbit/OrbitConst.hh" +#include "linac/rfgap/RfGapThreePointTTF.hh" #include #include @@ -23,7 +23,7 @@ using namespace OrbitUtils; // Constructor -RfGapThreePointTTF::RfGapThreePointTTF(): CppPyWrapper(NULL) +RfGapThreePointTTF::RfGapThreePointTTF() { } diff --git a/src/linac/rfgap/RfGapThreePointTTF.hh b/src/linac/rfgap/RfGapThreePointTTF.hh index ddba6822..e845794a 100644 --- a/src/linac/rfgap/RfGapThreePointTTF.hh +++ b/src/linac/rfgap/RfGapThreePointTTF.hh @@ -9,26 +9,23 @@ #define THREE_POINTS_RF_GAP_H //MPI Function Wrappers -#include "orbit_mpi.hh" -#include "wrap_mpi_comm.hh" +#include "mpi/orbit_mpi.hh" #include #include //ORBIT bunch -#include "Bunch.hh" +#include "orbit/Bunch.hh" //pyORBIT utils -#include "CppPyWrapper.hh" -using namespace std; /** This class represents a RF gap as a Three Points type gap. */ -class RfGapThreePointTTF: public OrbitUtils::CppPyWrapper +class RfGapThreePointTTF { public: diff --git a/src/linac/rfgap/RfGapThreePointTTF_slow.cc b/src/linac/rfgap/RfGapThreePointTTF_slow.cc index 0d09aa29..3a5c4f98 100644 --- a/src/linac/rfgap/RfGapThreePointTTF_slow.cc +++ b/src/linac/rfgap/RfGapThreePointTTF_slow.cc @@ -13,10 +13,10 @@ ORNL Tech. Note ORNL/TM-2015/247, June 2015 */ -#include "Bunch.hh" -#include "bessel.hh" -#include "OrbitConst.hh" -#include "RfGapThreePointTTF_slow.hh" +#include "orbit/Bunch.hh" +#include "utils/bessel.hh" +#include "orbit/OrbitConst.hh" +#include "linac/rfgap/RfGapThreePointTTF_slow.hh" #include #include @@ -25,7 +25,7 @@ using namespace OrbitUtils; // Constructor -RfGapThreePointTTF_slow::RfGapThreePointTTF_slow(): CppPyWrapper(NULL) +RfGapThreePointTTF_slow::RfGapThreePointTTF_slow() { } diff --git a/src/linac/rfgap/RfGapThreePointTTF_slow.hh b/src/linac/rfgap/RfGapThreePointTTF_slow.hh index 133580b6..d06fe1a1 100644 --- a/src/linac/rfgap/RfGapThreePointTTF_slow.hh +++ b/src/linac/rfgap/RfGapThreePointTTF_slow.hh @@ -12,26 +12,23 @@ #define THREE_POINTS_RF_GAP_SLOW_H //MPI Function Wrappers -#include "orbit_mpi.hh" -#include "wrap_mpi_comm.hh" +#include "mpi/orbit_mpi.hh" #include #include //ORBIT bunch -#include "Bunch.hh" +#include "orbit/Bunch.hh" //pyORBIT utils -#include "CppPyWrapper.hh" -using namespace std; /** This class represents a RF gap as a Three Points type gap. */ -class RfGapThreePointTTF_slow: public OrbitUtils::CppPyWrapper +class RfGapThreePointTTF_slow { public: diff --git a/src/linac/rfgap/SuperFishFieldSource.cc b/src/linac/rfgap/SuperFishFieldSource.cc index 5eddc2d8..50c92471 100644 --- a/src/linac/rfgap/SuperFishFieldSource.cc +++ b/src/linac/rfgap/SuperFishFieldSource.cc @@ -5,8 +5,8 @@ The class can represent several RF gaps. */ -#include "OrbitConst.hh" -#include "SuperFishFieldSource.hh" +#include "orbit/OrbitConst.hh" +#include "linac/rfgap/SuperFishFieldSource.hh" #include #include @@ -24,9 +24,12 @@ SuperFishFieldSource::SuperFishFieldSource(): BaseFieldSource() amplitude = 0.; time_init = 0.; field_center_pos = 0.; - grid2D_Ez = new Grid2D(3,3); - grid2D_Er = new Grid2D(3,3); - grid2D_H = new Grid2D(3,3); + ownedGrid2D_Ez.reset(new Grid2D(3,3)); + ownedGrid2D_Er.reset(new Grid2D(3,3)); + ownedGrid2D_H.reset(new Grid2D(3,3)); + grid2D_Ez = ownedGrid2D_Ez.get(); + grid2D_Er = ownedGrid2D_Er.get(); + grid2D_H = ownedGrid2D_H.get(); avg_ez_field = 0.; @@ -35,36 +38,15 @@ SuperFishFieldSource::SuperFishFieldSource(): BaseFieldSource() // Destructor SuperFishFieldSource::~SuperFishFieldSource() { - deleteGrids(); -} - -/** Delete all Grid2D grids. */ -void SuperFishFieldSource::deleteGrids() -{ - if(grid2D_Ez->getPyWrapper() != NULL){ - Py_XDECREF(grid2D_Ez->getPyWrapper()); - } else { - delete grid2D_Ez; - } - - if(grid2D_Er->getPyWrapper() != NULL){ - Py_XDECREF(grid2D_Er->getPyWrapper()); - } else { - delete grid2D_Er; - } - - if(grid2D_H->getPyWrapper() != NULL){ - Py_XDECREF(grid2D_H->getPyWrapper()); - } else { - delete grid2D_H; - } } /** Sets the Ez, Er, and H fields. */ void SuperFishFieldSource::setGrid2D_Fields(Grid2D* grid2D_Ez_in,Grid2D* grid2D_Er_in,Grid2D* grid2D_H_in) { - deleteGrids(); + ownedGrid2D_Ez.reset(); + ownedGrid2D_Er.reset(); + ownedGrid2D_H.reset(); grid2D_Ez = grid2D_Ez_in; grid2D_Er = grid2D_Er_in; grid2D_H = grid2D_H_in; diff --git a/src/linac/rfgap/SuperFishFieldSource.hh b/src/linac/rfgap/SuperFishFieldSource.hh index 45f121f0..206f2565 100644 --- a/src/linac/rfgap/SuperFishFieldSource.hh +++ b/src/linac/rfgap/SuperFishFieldSource.hh @@ -8,13 +8,13 @@ #ifndef SUPER_FISH_RF_FIELD_SOURCE_H #define SUPER_FISH_RF_FIELD_SOURCE_H -#include "BaseFieldSource.hh" -#include "Grid2D.hh" +#include "utils/BaseFieldSource.hh" +#include "spacecharge/Grid2D.hh" #include #include +#include -using namespace std; class SuperFishFieldSource: public OrbitUtils::BaseFieldSource { @@ -93,13 +93,13 @@ public: /** Returns the Grid2D instance with H field. */ Grid2D* getGrid2D_H(); - /** Sets the Ez, Er, and H fields. */ + /** Sets borrowed Ez, Er, and H fields. The caller retains ownership. */ void setGrid2D_Fields(Grid2D* grid2D_Ez_in,Grid2D* grid2D_Er_in,Grid2D* grid2D_H_in); private: - - /** Delete all Grid2D grids. */ - void deleteGrids(); + std::unique_ptr ownedGrid2D_Ez; + std::unique_ptr ownedGrid2D_Er; + std::unique_ptr ownedGrid2D_H; //grids 2D for Ez, Er, and H Grid2D* grid2D_Ez; diff --git a/src/linac/rfgap/wrap_BaseRfGap.cc b/src/linac/rfgap/wrap_BaseRfGap.cc index 6140c94f..36d13ee8 100644 --- a/src/linac/rfgap/wrap_BaseRfGap.cc +++ b/src/linac/rfgap/wrap_BaseRfGap.cc @@ -1,13 +1,13 @@ -#include "orbit_mpi.hh" -#include "pyORBIT_Object.hh" +#include "mpi/orbit_mpi.hh" +#include "main/pyORBIT_Object.hh" -#include "wrap_BaseRfGap.hh" -#include "wrap_linacmodule.hh" -#include "wrap_bunch.hh" +#include "linac/rfgap/wrap_BaseRfGap.hh" +#include "linac/wrap_linacmodule.hh" +#include "orbit/wrap_bunch.hh" #include -#include "BaseRfGap.hh" +#include "linac/rfgap/BaseRfGap.hh" using namespace OrbitUtils; @@ -36,7 +36,6 @@ extern "C" { //this is implementation of the __init__ method static int BaseRfGap_init(pyORBIT_Object *self, PyObject *args, PyObject *kwds){ self->cpp_obj = new BaseRfGap(); - ((BaseRfGap*) self->cpp_obj)->setPyWrapper((PyObject*) self); return 0; } diff --git a/src/linac/rfgap/wrap_BaseRfGap.hh b/src/linac/rfgap/wrap_BaseRfGap.hh index 588ec5d5..6960adfd 100644 --- a/src/linac/rfgap/wrap_BaseRfGap.hh +++ b/src/linac/rfgap/wrap_BaseRfGap.hh @@ -1,7 +1,7 @@ #ifndef WRAP_BASE_RF_GAP_H #define WRAP_BASE_RF_GAP_H -#include "Python.h" +#include #ifdef __cplusplus extern "C" { diff --git a/src/linac/rfgap/wrap_BaseRfGap_slow.cc b/src/linac/rfgap/wrap_BaseRfGap_slow.cc index c1c64486..27fa57e7 100644 --- a/src/linac/rfgap/wrap_BaseRfGap_slow.cc +++ b/src/linac/rfgap/wrap_BaseRfGap_slow.cc @@ -1,13 +1,13 @@ -#include "orbit_mpi.hh" -#include "pyORBIT_Object.hh" +#include "mpi/orbit_mpi.hh" +#include "main/pyORBIT_Object.hh" -#include "wrap_BaseRfGap_slow.hh" -#include "wrap_linacmodule.hh" -#include "wrap_bunch.hh" +#include "linac/rfgap/wrap_BaseRfGap_slow.hh" +#include "linac/wrap_linacmodule.hh" +#include "orbit/wrap_bunch.hh" #include -#include "BaseRfGap_slow.hh" +#include "linac/rfgap/BaseRfGap_slow.hh" using namespace OrbitUtils; @@ -36,7 +36,6 @@ extern "C" { //this is implementation of the __init__ method static int BaseRfGap_slow_init(pyORBIT_Object *self, PyObject *args, PyObject *kwds){ self->cpp_obj = new BaseRfGap_slow(); - ((BaseRfGap_slow*) self->cpp_obj)->setPyWrapper((PyObject*) self); return 0; } diff --git a/src/linac/rfgap/wrap_BaseRfGap_slow.hh b/src/linac/rfgap/wrap_BaseRfGap_slow.hh index 54b11437..5b2908d6 100644 --- a/src/linac/rfgap/wrap_BaseRfGap_slow.hh +++ b/src/linac/rfgap/wrap_BaseRfGap_slow.hh @@ -1,7 +1,7 @@ #ifndef WRAP_BASE_RF_GAP_SLOW_H #define WRAP_BASE_RF_GAP_SLOW_H -#include "Python.h" +#include #ifdef __cplusplus extern "C" { diff --git a/src/linac/rfgap/wrap_MatrixRfGap.cc b/src/linac/rfgap/wrap_MatrixRfGap.cc index dac308c5..1a490d62 100644 --- a/src/linac/rfgap/wrap_MatrixRfGap.cc +++ b/src/linac/rfgap/wrap_MatrixRfGap.cc @@ -1,13 +1,13 @@ -#include "orbit_mpi.hh" -#include "pyORBIT_Object.hh" +#include "mpi/orbit_mpi.hh" +#include "main/pyORBIT_Object.hh" -#include "wrap_MatrixRfGap.hh" -#include "wrap_linacmodule.hh" -#include "wrap_bunch.hh" +#include "linac/rfgap/wrap_MatrixRfGap.hh" +#include "linac/wrap_linacmodule.hh" +#include "orbit/wrap_bunch.hh" #include -#include "MatrixRfGap.hh" +#include "linac/rfgap/MatrixRfGap.hh" using namespace OrbitUtils; @@ -35,7 +35,6 @@ extern "C" { //this is implementation of the __init__ method static int MatrixRfGap_init(pyORBIT_Object *self, PyObject *args, PyObject *kwds){ self->cpp_obj = new MatrixRfGap(); - ((MatrixRfGap*) self->cpp_obj)->setPyWrapper((PyObject*) self); return 0; } diff --git a/src/linac/rfgap/wrap_MatrixRfGap.hh b/src/linac/rfgap/wrap_MatrixRfGap.hh index 745dd3f1..8086e6ff 100644 --- a/src/linac/rfgap/wrap_MatrixRfGap.hh +++ b/src/linac/rfgap/wrap_MatrixRfGap.hh @@ -1,7 +1,7 @@ #ifndef WRAP_MATRIX_RF_GAP_H #define WRAP_MATRIX_RF_GAP_H -#include "Python.h" +#include #ifdef __cplusplus extern "C" { diff --git a/src/linac/rfgap/wrap_RfGapTTF.cc b/src/linac/rfgap/wrap_RfGapTTF.cc index 08cc1a88..bc279188 100644 --- a/src/linac/rfgap/wrap_RfGapTTF.cc +++ b/src/linac/rfgap/wrap_RfGapTTF.cc @@ -1,15 +1,15 @@ -#include "orbit_mpi.hh" -#include "pyORBIT_Object.hh" +#include "mpi/orbit_mpi.hh" +#include "main/pyORBIT_Object.hh" -#include "wrap_RfGapTTF.hh" -#include "wrap_linacmodule.hh" -#include "wrap_bunch.hh" +#include "linac/rfgap/wrap_RfGapTTF.hh" +#include "linac/wrap_linacmodule.hh" +#include "orbit/wrap_bunch.hh" #include -#include "wrap_utils.hh" -#include "RfGapTTF.hh" -#include "OU_Polynomial.hh" +#include "utils/wrap_utils.hh" +#include "linac/rfgap/RfGapTTF.hh" +#include "utils/polynomial/OU_Polynomial.hh" using namespace OrbitUtils; @@ -38,7 +38,6 @@ extern "C" { //this is implementation of the __init__ method static int RfGapTTF_init(pyORBIT_Object *self, PyObject *args, PyObject *kwds){ self->cpp_obj = new RfGapTTF(); - ((RfGapTTF*) self->cpp_obj)->setPyWrapper((PyObject*) self); return 0; } diff --git a/src/linac/rfgap/wrap_RfGapTTF.hh b/src/linac/rfgap/wrap_RfGapTTF.hh index 190061d4..41acb227 100644 --- a/src/linac/rfgap/wrap_RfGapTTF.hh +++ b/src/linac/rfgap/wrap_RfGapTTF.hh @@ -1,7 +1,7 @@ #ifndef WRAP_RF_GAP_TTF_H #define WRAP_RF_GAP_TTF_H -#include "Python.h" +#include #ifdef __cplusplus extern "C" { diff --git a/src/linac/rfgap/wrap_RfGapTTF_slow.cc b/src/linac/rfgap/wrap_RfGapTTF_slow.cc index 3b20342b..07272b15 100644 --- a/src/linac/rfgap/wrap_RfGapTTF_slow.cc +++ b/src/linac/rfgap/wrap_RfGapTTF_slow.cc @@ -1,15 +1,15 @@ -#include "orbit_mpi.hh" -#include "pyORBIT_Object.hh" +#include "mpi/orbit_mpi.hh" +#include "main/pyORBIT_Object.hh" -#include "wrap_RfGapTTF_slow.hh" -#include "wrap_linacmodule.hh" -#include "wrap_bunch.hh" +#include "linac/rfgap/wrap_RfGapTTF_slow.hh" +#include "linac/wrap_linacmodule.hh" +#include "orbit/wrap_bunch.hh" #include -#include "wrap_utils.hh" -#include "RfGapTTF_slow.hh" -#include "OU_Polynomial.hh" +#include "utils/wrap_utils.hh" +#include "linac/rfgap/RfGapTTF_slow.hh" +#include "utils/polynomial/OU_Polynomial.hh" using namespace OrbitUtils; @@ -38,7 +38,6 @@ extern "C" { //this is implementation of the __init__ method static int RfGapTTF_slow_init(pyORBIT_Object *self, PyObject *args, PyObject *kwds){ self->cpp_obj = new RfGapTTF_slow(); - ((RfGapTTF_slow*) self->cpp_obj)->setPyWrapper((PyObject*) self); return 0; } diff --git a/src/linac/rfgap/wrap_RfGapTTF_slow.hh b/src/linac/rfgap/wrap_RfGapTTF_slow.hh index 2c7a6a8f..442e556d 100644 --- a/src/linac/rfgap/wrap_RfGapTTF_slow.hh +++ b/src/linac/rfgap/wrap_RfGapTTF_slow.hh @@ -1,7 +1,7 @@ #ifndef WRAP_RF_GAP_TTF_SLOW_H #define WRAP_RF_GAP_TTF_SLOW_H -#include "Python.h" +#include #ifdef __cplusplus extern "C" { diff --git a/src/linac/rfgap/wrap_RfGapThreePointTTF.cc b/src/linac/rfgap/wrap_RfGapThreePointTTF.cc index f3b4e503..b809deb0 100644 --- a/src/linac/rfgap/wrap_RfGapThreePointTTF.cc +++ b/src/linac/rfgap/wrap_RfGapThreePointTTF.cc @@ -1,15 +1,15 @@ -#include "orbit_mpi.hh" -#include "pyORBIT_Object.hh" +#include "mpi/orbit_mpi.hh" +#include "main/pyORBIT_Object.hh" -#include "wrap_RfGapThreePointTTF.hh" -#include "wrap_linacmodule.hh" -#include "wrap_bunch.hh" +#include "linac/rfgap/wrap_RfGapThreePointTTF.hh" +#include "linac/wrap_linacmodule.hh" +#include "orbit/wrap_bunch.hh" #include -#include "wrap_utils.hh" -#include "RfGapThreePointTTF.hh" -#include "OU_Polynomial.hh" +#include "utils/wrap_utils.hh" +#include "linac/rfgap/RfGapThreePointTTF.hh" +#include "utils/polynomial/OU_Polynomial.hh" using namespace OrbitUtils; @@ -38,7 +38,6 @@ extern "C" { //this is implementation of the __init__ method static int RfGapThreePointTTF_init(pyORBIT_Object *self, PyObject *args, PyObject *kwds){ self->cpp_obj = new RfGapThreePointTTF(); - ((RfGapThreePointTTF*) self->cpp_obj)->setPyWrapper((PyObject*) self); return 0; } diff --git a/src/linac/rfgap/wrap_RfGapThreePointTTF.hh b/src/linac/rfgap/wrap_RfGapThreePointTTF.hh index 2f9a9611..3e1d3e04 100644 --- a/src/linac/rfgap/wrap_RfGapThreePointTTF.hh +++ b/src/linac/rfgap/wrap_RfGapThreePointTTF.hh @@ -1,7 +1,7 @@ #ifndef WRAP_RF_GAP_THREE_POINT_TTF_H #define WRAP_RF_GAP_THREE_POINT_TTF_H -#include "Python.h" +#include #ifdef __cplusplus extern "C" { diff --git a/src/linac/rfgap/wrap_RfGapThreePointTTF_slow.cc b/src/linac/rfgap/wrap_RfGapThreePointTTF_slow.cc index 0b7da02b..5c0462a8 100644 --- a/src/linac/rfgap/wrap_RfGapThreePointTTF_slow.cc +++ b/src/linac/rfgap/wrap_RfGapThreePointTTF_slow.cc @@ -1,15 +1,15 @@ -#include "orbit_mpi.hh" -#include "pyORBIT_Object.hh" +#include "mpi/orbit_mpi.hh" +#include "main/pyORBIT_Object.hh" -#include "wrap_RfGapThreePointTTF_slow.hh" -#include "wrap_linacmodule.hh" -#include "wrap_bunch.hh" +#include "linac/rfgap/wrap_RfGapThreePointTTF_slow.hh" +#include "linac/wrap_linacmodule.hh" +#include "orbit/wrap_bunch.hh" #include -#include "wrap_utils.hh" -#include "RfGapThreePointTTF_slow.hh" -#include "OU_Polynomial.hh" +#include "utils/wrap_utils.hh" +#include "linac/rfgap/RfGapThreePointTTF_slow.hh" +#include "utils/polynomial/OU_Polynomial.hh" using namespace OrbitUtils; @@ -38,7 +38,6 @@ extern "C" { //this is implementation of the __init__ method static int RfGapThreePointTTF_slow_init(pyORBIT_Object *self, PyObject *args, PyObject *kwds){ self->cpp_obj = new RfGapThreePointTTF_slow(); - ((RfGapThreePointTTF_slow*) self->cpp_obj)->setPyWrapper((PyObject*) self); return 0; } diff --git a/src/linac/rfgap/wrap_RfGapThreePointTTF_slow.hh b/src/linac/rfgap/wrap_RfGapThreePointTTF_slow.hh index 62f99b3c..eabae2e4 100644 --- a/src/linac/rfgap/wrap_RfGapThreePointTTF_slow.hh +++ b/src/linac/rfgap/wrap_RfGapThreePointTTF_slow.hh @@ -1,7 +1,7 @@ #ifndef WRAP_RF_GAP_THREE_POINT_TTF_SLOW_H #define WRAP_RF_GAP_THREE_POINT_TTF_SLOW_H -#include "Python.h" +#include #ifdef __cplusplus extern "C" { diff --git a/src/linac/rfgap/wrap_SuperFishFieldSource.cc b/src/linac/rfgap/wrap_SuperFishFieldSource.cc index a42ac010..ca2a7c90 100644 --- a/src/linac/rfgap/wrap_SuperFishFieldSource.cc +++ b/src/linac/rfgap/wrap_SuperFishFieldSource.cc @@ -1,12 +1,12 @@ -#include "orbit_mpi.hh" -#include "pyORBIT_Object.hh" +#include "mpi/orbit_mpi.hh" +#include "main/pyORBIT_Object.hh" -#include "wrap_SuperFishFieldSource.hh" -#include "wrap_linacmodule.hh" +#include "linac/rfgap/wrap_SuperFishFieldSource.hh" +#include "linac/wrap_linacmodule.hh" -#include "wrap_utils.hh" -#include "wrap_spacecharge.hh" -#include "SuperFishFieldSource.hh" +#include "utils/wrap_utils.hh" +#include "spacecharge/wrap_spacecharge.hh" +#include "linac/rfgap/SuperFishFieldSource.hh" #include @@ -14,6 +14,12 @@ using namespace OrbitUtils; namespace wrap_linac{ + typedef struct { + PyObject_HEAD + void* cpp_obj; + PyObject* grids[3]; + } pyORBIT_SuperFishFieldSource; + #ifdef __cplusplus extern "C" { #endif @@ -26,18 +32,21 @@ extern "C" { //It never will be called directly static PyObject* SuperFishFieldSource_new(PyTypeObject *type, PyObject *args, PyObject *kwds) { - pyORBIT_Object* self; - self = (pyORBIT_Object *) type->tp_alloc(type, 0); + pyORBIT_SuperFishFieldSource* self; + self = (pyORBIT_SuperFishFieldSource *) type->tp_alloc(type, 0); self->cpp_obj = NULL; + self->grids[0] = NULL; + self->grids[1] = NULL; + self->grids[2] = NULL; //std::cerr<<"The SuperFishFieldSource new has been called!"<cpp_obj = new SuperFishFieldSource(); - ((SuperFishFieldSource*) self->cpp_obj)->setPyWrapper((PyObject*) self); + pyorbit::registerPyWrapper(self->cpp_obj, (PyObject*) self); return 0; } @@ -55,7 +64,7 @@ extern "C" { //setGrid2D_Fields(grid2D_Ez,grid2D_Er,grid2D_H) - sets the Grid2D instances with Ez, Er, H fields. static PyObject* SuperFishFieldSource_setGrid2D_Fields(PyObject *self, PyObject *args){ - pyORBIT_Object* pySuperFishFieldSource = (pyORBIT_Object*) self; + pyORBIT_SuperFishFieldSource* pySuperFishFieldSource = (pyORBIT_SuperFishFieldSource*) self; SuperFishFieldSource* cpp_SuperFishFieldSource = (SuperFishFieldSource*) pySuperFishFieldSource->cpp_obj; PyObject* pyGrid2D_Ez; PyObject* pyGrid2D_Er; @@ -76,25 +85,24 @@ extern "C" { Py_INCREF(pyGrid2D_Ez); Py_INCREF(pyGrid2D_Er); Py_INCREF(pyGrid2D_H); + Py_XDECREF(pySuperFishFieldSource->grids[0]); + Py_XDECREF(pySuperFishFieldSource->grids[1]); + Py_XDECREF(pySuperFishFieldSource->grids[2]); + pySuperFishFieldSource->grids[0] = pyGrid2D_Ez; + pySuperFishFieldSource->grids[1] = pyGrid2D_Er; + pySuperFishFieldSource->grids[2] = pyGrid2D_H; Py_INCREF(Py_None); return Py_None; } //getGrid2D_Fields returns the Grid2D instances with Ez, Er, H fields. static PyObject* SuperFishFieldSource_getGrid2D_Fields(PyObject *self, PyObject *args){ - pyORBIT_Object* pySuperFishFieldSource = (pyORBIT_Object*) self; - SuperFishFieldSource* cpp_SuperFishFieldSource = (SuperFishFieldSource*) pySuperFishFieldSource->cpp_obj; - Grid2D* grid2d_Ez = cpp_SuperFishFieldSource->getGrid2D_Ez(); - Grid2D* grid2d_Er = cpp_SuperFishFieldSource->getGrid2D_Er(); - Grid2D* grid2d_H = cpp_SuperFishFieldSource->getGrid2D_H(); - PyObject* pyGrid2D_Ez = (PyObject*) grid2d_Ez->getPyWrapper(); - PyObject* pyGrid2D_Er = (PyObject*) grid2d_Er->getPyWrapper(); - PyObject* pyGrid2D_H = (PyObject*) grid2d_H->getPyWrapper(); - if(pyGrid2D_Ez == NULL || pyGrid2D_Er == NULL || pyGrid2D_H == NULL){ + pyORBIT_SuperFishFieldSource* source = (pyORBIT_SuperFishFieldSource*) self; + if(source->grids[0] == NULL || source->grids[1] == NULL || source->grids[2] == NULL){ Py_INCREF(Py_None); return Py_None; } - return Py_BuildValue("(OOO)",pyGrid2D_Ez,pyGrid2D_Er,pyGrid2D_H); + return Py_BuildValue("(OOO)", source->grids[0], source->grids[1], source->grids[2]); } //setFrequency(frequency) sets the RF frequency. @@ -254,10 +262,14 @@ extern "C" { //----------------------------------------------------- //destructor for python SuperFishFieldSource class (__del__ method). //----------------------------------------------------- - static void SuperFishFieldSource_del(pyORBIT_Object* self){ + static void SuperFishFieldSource_del(pyORBIT_SuperFishFieldSource* self){ //std::cerr<<"The SuperFishFieldSource __del__ has been called!"<cpp_obj; + pyorbit::unregisterPyWrapper(cpp_SuperFishFieldSource, (PyObject*) self); delete cpp_SuperFishFieldSource; + Py_CLEAR(self->grids[0]); + Py_CLEAR(self->grids[1]); + Py_CLEAR(self->grids[2]); self->ob_base.ob_type->tp_free((PyObject*)self); } @@ -296,7 +308,7 @@ extern "C" { static PyTypeObject pyORBIT_SuperFishFieldSource_Type = { PyVarObject_HEAD_INIT(NULL, 0) "SuperFishFieldSource", /*tp_name*/ - sizeof(pyORBIT_Object), /*tp_basicsize*/ + sizeof(pyORBIT_SuperFishFieldSource), /*tp_basicsize*/ 0, /*tp_itemsize*/ (destructor) SuperFishFieldSource_del , /*tp_dealloc*/ 0, /*tp_print*/ diff --git a/src/linac/rfgap/wrap_SuperFishFieldSource.hh b/src/linac/rfgap/wrap_SuperFishFieldSource.hh index 474817c6..23b5ba93 100644 --- a/src/linac/rfgap/wrap_SuperFishFieldSource.hh +++ b/src/linac/rfgap/wrap_SuperFishFieldSource.hh @@ -1,7 +1,7 @@ #ifndef WRAP_SUPER_FISH_RF_FIELD_SOURCE_H #define WRAP_SUPER_FISH_RF_FIELD_SOURCE_H -#include "Python.h" +#include #ifdef __cplusplus extern "C" { diff --git a/src/linac/tracking/linac_tracking.cc b/src/linac/tracking/linac_tracking.cc index 7302a565..fa3360a8 100644 --- a/src/linac/tracking/linac_tracking.cc +++ b/src/linac/tracking/linac_tracking.cc @@ -27,10 +27,11 @@ // /////////////////////////////////////////////////////////////////////////// -#include "OrbitConst.hh" -#include "Bunch.hh" -#include "SyncPart.hh" +#include "orbit/OrbitConst.hh" +#include "orbit/Bunch.hh" +#include "orbit/SyncPart.hh" +#include #include namespace linac_tracking diff --git a/src/linac/tracking/linac_tracking.hh b/src/linac/tracking/linac_tracking.hh index 129696a9..9984f925 100644 --- a/src/linac/tracking/linac_tracking.hh +++ b/src/linac/tracking/linac_tracking.hh @@ -18,7 +18,7 @@ #ifndef LINAC_TRACKING_H #define LINAC_TRACKING_H -#include "Bunch.hh" +#include "orbit/Bunch.hh" namespace linac_tracking { diff --git a/src/linac/tracking/wrap_linac_tracking.cc b/src/linac/tracking/wrap_linac_tracking.cc index 579d9477..85ca36d8 100644 --- a/src/linac/tracking/wrap_linac_tracking.cc +++ b/src/linac/tracking/wrap_linac_tracking.cc @@ -1,11 +1,11 @@ -#include "Python.h" -#include "orbit_mpi.hh" +#include +#include "mpi/orbit_mpi.hh" -#include "pyORBIT_Object.hh" +#include "main/pyORBIT_Object.hh" -#include "linac_tracking.hh" +#include "linac/tracking/linac_tracking.hh" -#include "wrap_linac_tracking.hh" +#include "linac/tracking/wrap_linac_tracking.hh" namespace wrap_linac_tracking { diff --git a/src/linac/tracking/wrap_linac_tracking.hh b/src/linac/tracking/wrap_linac_tracking.hh index db48ced3..0bbfec87 100644 --- a/src/linac/tracking/wrap_linac_tracking.hh +++ b/src/linac/tracking/wrap_linac_tracking.hh @@ -1,7 +1,7 @@ #ifndef WRAP_LINAC_TRACKING_H #define WRAP_LINAC_TRACKING_H -#include "Python.h" +#include #ifdef __cplusplus extern "C" diff --git a/src/linac/wrap_linacmodule.cc b/src/linac/wrap_linacmodule.cc index 42a6d89a..c9bbb6cd 100644 --- a/src/linac/wrap_linacmodule.cc +++ b/src/linac/wrap_linacmodule.cc @@ -1,15 +1,15 @@ -#include "orbit_mpi.hh" - -#include "wrap_linacmodule.hh" -#include "wrap_BaseRfGap.hh" -#include "wrap_BaseRfGap_slow.hh" -#include "wrap_MatrixRfGap.hh" -#include "wrap_RfGapTTF.hh" -#include "wrap_RfGapTTF_slow.hh" -#include "wrap_SuperFishFieldSource.hh" -#include "wrap_RfGapThreePointTTF.hh" -#include "wrap_RfGapThreePointTTF_slow.hh" -#include "wrap_linac_tracking.hh" +#include "mpi/orbit_mpi.hh" + +#include "linac/wrap_linacmodule.hh" +#include "linac/rfgap/wrap_BaseRfGap.hh" +#include "linac/rfgap/wrap_BaseRfGap_slow.hh" +#include "linac/rfgap/wrap_MatrixRfGap.hh" +#include "linac/rfgap/wrap_RfGapTTF.hh" +#include "linac/rfgap/wrap_RfGapTTF_slow.hh" +#include "linac/rfgap/wrap_SuperFishFieldSource.hh" +#include "linac/rfgap/wrap_RfGapThreePointTTF.hh" +#include "linac/rfgap/wrap_RfGapThreePointTTF_slow.hh" +#include "linac/tracking/wrap_linac_tracking.hh" static PyMethodDef linacmoduleMethods[] = { {NULL,NULL} }; diff --git a/src/linac/wrap_linacmodule.hh b/src/linac/wrap_linacmodule.hh index 62fd8d56..75b83f66 100644 --- a/src/linac/wrap_linacmodule.hh +++ b/src/linac/wrap_linacmodule.hh @@ -1,7 +1,7 @@ #ifndef WRAP_LINAC_H #define WRAP_LINAC_H -#include "Python.h" +#include #ifdef __cplusplus extern "C" { diff --git a/src/main/pyORBIT_Object.cc b/src/main/pyORBIT_Object.cc new file mode 100644 index 00000000..10f29f1a --- /dev/null +++ b/src/main/pyORBIT_Object.cc @@ -0,0 +1,32 @@ +#include "main/pyORBIT_Object.hh" + +#include + +namespace { + +std::unordered_map wrappers; + +} + +namespace pyorbit { + +void registerPyWrapper(void* cpp_obj, PyObject* py_wrapper) +{ + wrappers[cpp_obj] = py_wrapper; +} + +void unregisterPyWrapper(void* cpp_obj, PyObject* py_wrapper) +{ + auto wrapper = wrappers.find(cpp_obj); + if(wrapper != wrappers.end() && wrapper->second == py_wrapper) { + wrappers.erase(wrapper); + } +} + +PyObject* getPyWrapper(void* cpp_obj) +{ + auto wrapper = wrappers.find(cpp_obj); + return wrapper == wrappers.end() ? nullptr : wrapper->second; +} + +} diff --git a/src/main/pyORBIT_Object.hh b/src/main/pyORBIT_Object.hh index 7a037e54..fa80d7f1 100644 --- a/src/main/pyORBIT_Object.hh +++ b/src/main/pyORBIT_Object.hh @@ -17,7 +17,8 @@ #ifndef PY_ORBIT_OBJECT_H #define PY_ORBIT_OBJECT_H -#include "structmember.h" +#include +#include #ifdef __cplusplus extern "C" { @@ -29,6 +30,15 @@ extern "C" { } pyORBIT_Object; #ifdef __cplusplus +} + +namespace pyorbit { + +// Registry entries are borrowed references owned by their Python wrappers. +void registerPyWrapper(void* cpp_obj, PyObject* py_wrapper); +void unregisterPyWrapper(void* cpp_obj, PyObject* py_wrapper); +PyObject* getPyWrapper(void* cpp_obj); + } #endif diff --git a/src/meson.build b/src/meson.build index c7474e58..05307bbb 100644 --- a/src/meson.build +++ b/src/meson.build @@ -1,49 +1,52 @@ -# Add Python installation details -python = import('python').find_installation('python3', pure: false) +build_python = get_option('BUILD_PYTHON') +if build_python + python = import('python').find_installation('python3', pure: false) + python_dependency = python.dependency() +endif -# Add C++ compiler details cpp = meson.get_compiler('cpp') -# Add -march=native if the compiler supports it if cpp.has_argument('-march=native') add_project_arguments('-march=native', language: 'cpp') endif -dependencies = [] - -dependencies += python.dependency() -dependencies += dependency('fftw3', version: '>= 3.0.0', required: true) +core_dependencies = [dependency('fftw3', version: '>= 3.0.0', required: true)] +pc_requires = ['fftw3 >= 3.0.0'] # Detecting if MPICH or OPENMPI are installed and enabling support if present - mpi_use = get_option('USE_MPI') +use_mpi_flag = '0' if mpi_use == 'mpich' message('Requested to use MPICH as the MPI implementation.') - dependencies += dependency('mpich', version: '>= 4.0.0', required: true) + core_dependencies += dependency('mpich', version: '>= 4.0.0', required: true) + pc_requires += ['mpich >= 4.0.0'] add_project_arguments('-DUSE_MPI=1', language: 'cpp') - - # Configure dependencies or settings specific to MPICH + use_mpi_flag = '1' elif mpi_use == 'ompi' message('Requested to use OpenMPI as the MPI implementation.') - dependencies += dependency('ompi', version: '>= 4.0.0', required: true) + core_dependencies += dependency('ompi', version: '>= 4.0.0', required: true) + pc_requires += ['ompi >= 4.0.0'] add_project_arguments('-DUSE_MPI=1', language: 'cpp') - + use_mpi_flag = '1' elif mpi_use == 'none' message('Requested to not use MPI.') - else mpich_dependency = dependency('mpich', version: '>= 4.0.0', required: false) openmpi_dependency = dependency('ompi', version: '>= 4.0.0', required: false) if mpich_dependency.found() add_project_arguments('-DUSE_MPI=1', language: 'cpp') - dependencies += mpich_dependency + core_dependencies += mpich_dependency + pc_requires += ['mpich >= 4.0.0'] message('Using MPICH as the MPI implementation.') + use_mpi_flag = '1' elif openmpi_dependency.found() add_project_arguments('-DUSE_MPI=1', language: 'cpp') - dependencies += openmpi_dependency + core_dependencies += openmpi_dependency + pc_requires += ['ompi >= 4.0.0'] message('Using OpenMPI as the MPI implementation.') + use_mpi_flag = '1' else message('MPI will not be used.') endif @@ -51,61 +54,34 @@ else endif sources = files([ - 'linac/wrap_linacmodule.cc', 'linac/tracking/linac_tracking.cc', - 'linac/tracking/wrap_linac_tracking.cc', - 'linac/rfgap/wrap_BaseRfGap.cc', 'linac/rfgap/BaseRfGap_slow.cc', - 'linac/rfgap/wrap_RfGapTTF_slow.cc', - 'linac/rfgap/wrap_RfGapThreePointTTF.cc', 'linac/rfgap/BaseRfGap.cc', 'linac/rfgap/RfGapThreePointTTF.cc', 'linac/rfgap/MatrixRfGap.cc', - 'linac/rfgap/wrap_BaseRfGap_slow.cc', - 'linac/rfgap/wrap_RfGapThreePointTTF_slow.cc', - 'linac/rfgap/wrap_SuperFishFieldSource.cc', 'linac/rfgap/RfGapTTF.cc', 'linac/rfgap/SuperFishFieldSource.cc', 'linac/rfgap/RfGapTTF_slow.cc', 'linac/rfgap/RfGapThreePointTTF_slow.cc', - 'linac/rfgap/wrap_RfGapTTF.cc', - 'linac/rfgap/wrap_MatrixRfGap.cc', 'orbit/OrbitConst.cc', - 'orbit/wrap_bunch.cc', - 'orbit/wrap_syncpart.cc', 'orbit/Bunch.cc', 'orbit/SyncPart.cc', - 'orbit/BunchDiagnostics/wrap_bunch_tune_analysis.cc', - 'orbit/BunchDiagnostics/wrap_bunch_twiss_analysis.cc', 'orbit/BunchDiagnostics/BunchTwissAnalysis.cc', 'orbit/BunchDiagnostics/BunchTuneAnalysis.cc', - 'orbit/FieldTracker/wrap_fieldtracker.cc', 'orbit/FieldTracker/FieldTracker.cc', - 'orbit/MaterialInteractions/wrap_foil.cc', 'orbit/MaterialInteractions/Foil.cc', 'orbit/MaterialInteractions/Collimator.cc', 'orbit/MaterialInteractions/numrecipes.cc', 'orbit/MaterialInteractions/cross_sections.cc', - 'orbit/MaterialInteractions/wrap_collimator.cc', 'orbit/MaterialInteractions/MaterialInteractions.cc', 'orbit/RFCavities/Dual_Harmonic_Cav.cc', 'orbit/RFCavities/Frequency_Cav.cc', 'orbit/RFCavities/Barrier_Cav.cc', - 'orbit/RFCavities/wrap_Harmonic_Cav.cc', 'orbit/RFCavities/Harmonic_Cav.cc', - 'orbit/RFCavities/wrap_Dual_Harmonic_Cav.cc', - 'orbit/RFCavities/wrap_Barrier_Cav.cc', - 'orbit/RFCavities/wrap_Frequency_Cav.cc', - 'orbit/RFCavities/wrap_rfcavities.cc', - 'orbit/Impedances/wrap_TImpedance.cc', 'orbit/Impedances/TImpedance.cc', - 'orbit/Impedances/wrap_impedances.cc', 'orbit/Impedances/LImpedance.cc', - 'orbit/Impedances/wrap_LImpedance.cc', 'orbit/SynchPartRedefinition/SynchPartRedefinitionZdE.cc', - 'orbit/SynchPartRedefinition/wrap_synch_part_redefinition_z_de.cc', 'orbit/Errors/errorbase.cc', - 'orbit/Errors/wrap_errorbase.cc', 'orbit/ParticlesAttributes/ParticleInitialCoordinates.cc', 'orbit/ParticlesAttributes/ParticleIdNumber.cc', 'orbit/ParticlesAttributes/ParticleMacroSize.cc', @@ -122,197 +98,383 @@ sources = files([ 'orbit/Apertures/CircleApertureShape.cc', 'orbit/Apertures/PhaseAperture.cc', 'orbit/Apertures/Aperture.cc', - 'orbit/Apertures/wrap_aperture.cc', - 'orbit/Apertures/wrap_CompositeApertureShape.cc', 'orbit/Apertures/RectangularApertureShape.cc', - 'orbit/Apertures/PyBaseApertureShape.cc', 'orbit/Apertures/ConvexApertureShape.cc', - 'orbit/Apertures/wrap_ConvexApertureShape.cc', - 'orbit/Apertures/wrap_PyBaseApertureShape.cc', 'orbit/Apertures/EnergyAperture.cc', 'orbit/Apertures/BaseAperture.cc', 'orbit/Apertures/EllipseApertureShape.cc', - 'orbit/Apertures/wrap_BaseAperture.cc', - 'orbit/Apertures/wrap_PrimitiveApertureShape.cc', 'orbit/Apertures/CompositeApertureShape.cc', - 'orbit/Apertures/wrap_EnergyAperture.cc', - 'orbit/Apertures/wrap_TAperture.cc', - 'orbit/Apertures/wrap_PhaseAperture.cc', 'orbit/Apertures/BaseApertureShape.cc', - 'trackerrk4/wrap_runge_kutta_tracker.cc', - 'trackerrk4/wrap_py_external_effects.cc', 'trackerrk4/ExternalEffects.cc', 'trackerrk4/ExtEffectsContainer.cc', - 'trackerrk4/wrap_trackerrk4.cc', - 'trackerrk4/PyExternalEffects.cc', 'trackerrk4/RungeKuttaTracker.cc', - 'trackerrk4/wrap_ext_effects_container.cc', - 'mpi/wrap_orbit_mpi.cc', - 'mpi/wrap_mpi_comm.cc', 'mpi/orbit_mpi.cc', - 'mpi/wrap_mpi_datatype.cc', - 'mpi/wrap_mpi_request.cc', - 'mpi/wrap_mpi_op.cc', - 'mpi/wrap_mpi_status.cc', - 'mpi/wrap_mpi_group.cc', 'spacecharge/PoissonSolverFFT3D.cc', 'spacecharge/SpaceChargeCalcUnifEllipse.cc', 'spacecharge/ForceSolver2D.cc', 'spacecharge/PoissonSolverFFT2D.cc', - 'spacecharge/wrap_poissonsolverfft2d.cc', - 'spacecharge/wrap_poissonsolverfft3d.cc', 'spacecharge/PoissonSolver2D.cc', 'spacecharge/SpaceChargeForceCalc2p5D.cc', 'spacecharge/PoissonSolver3D.cc', 'spacecharge/SpaceChargeCalc3D.cc', - 'spacecharge/wrap_boundary2d.cc', - 'spacecharge/wrap_forcesolverfft2d.cc', 'spacecharge/ForceSolverFFT2D.cc', 'spacecharge/SpaceChargeCalcSliceBySlice2D.cc', 'spacecharge/Grid3D.cc', - 'spacecharge/wrap_spacecharge.cc', - 'spacecharge/wrap_spacechargecalc2p5d_rb.cc', - 'spacecharge/Grid2D.cc', 'spacecharge/SpaceChargeCalc2p5Drb.cc', + 'spacecharge/Grid2D.cc', + 'spacecharge/SpaceChargeCalc2p5D.cc', 'spacecharge/Grid1D.cc', 'spacecharge/LSpaceChargeCalc.cc', - 'spacecharge/wrap_grid1D.cc', - 'spacecharge/wrap_uniform_ellipsoid_field_calculator.cc', 'spacecharge/ShapedBoundary2D.cc', - 'spacecharge/wrap_grid3D.cc', 'spacecharge/BaseBoundary2D.cc', - 'spacecharge/wrap_grid2D.cc', - 'spacecharge/wrap_spacechargecalc_uniform_ellipse.cc', - 'spacecharge/wrap_spacechargecalc3d.cc', 'spacecharge/UniformEllipsoidFieldCalculator.cc', - 'spacecharge/wrap_spacechargeforcecalc2p5d.cc', - 'spacecharge/SpaceChargeCalc2p5D.cc', - 'spacecharge/wrap_spacechargecalc_slicebyslice_2D.cc', - 'spacecharge/wrap_spacechargecalc2p5d.cc', - 'spacecharge/wrap_lspacechargecalc.cc', - 'utils/wrap_function.cc', 'utils/FieldSourceContainer.cc', 'utils/AttributesBucket.cc', 'utils/bessel.cc', - 'utils/PyBaseFieldSource.cc', - 'utils/wrap_field_source_container.cc', 'utils/OU_SplineCH.cc', - 'utils/CppPyWrapper.cc', - 'utils/wrap_random.cc', - 'utils/wrap_utils.cc', 'utils/StringUtils.cc', - 'utils/wrap_py_base_field_source.cc', - 'utils/wrap_splinech.cc', 'utils/Random.cc', - 'utils/wrap_numrecipes.cc', 'utils/BaseFieldSource.cc', 'utils/OU_Function.cc', 'utils/MathPolynomial.cc', 'utils/BufferStore.cc', - 'utils/statistics/wrap_statmoments2d.cc', 'utils/statistics/StatMoments2D.cc', - 'utils/field_sources/wrap_loop_field_source.cc', 'utils/field_sources/LoopFieldSource.cc', 'utils/field_sources/QuadFieldSource.cc', 'utils/field_sources/ShiftedFieldSource.cc', - 'utils/field_sources/wrap_dipole_field_source.cc', - 'utils/field_sources/wrap_quad_field_source.cc', - 'utils/field_sources/wrap_magnetic_field_source_grid3d.cc', 'utils/field_sources/DipoleFieldSource.cc', - 'utils/field_sources/wrap_field_sources_module.cc', 'utils/field_sources/MagnetFieldSourceGrid3D.cc', 'utils/integration/gauss_legendre_points.cc', - 'utils/integration/wrap_gauss_legendre_integrator.cc', 'utils/integration/GaussLegendreIntegrator.cc', 'utils/bunch/ParticlesWithIdFunctions.cc', - 'utils/bunch/wrap_bunch_extrema_calculator.cc', 'utils/bunch/TwissFilteringFunctions.cc', 'utils/bunch/InitialCoordsAttrFunctions.cc', 'utils/bunch/BunchExtremaCalculator.cc', - 'utils/bunch/wrap_bunch_utils_functions.cc', 'utils/harmonic_analysis/HarmonicData.cc', - 'utils/harmonic_analysis/wrap_harmonic_data.cc', - 'utils/polynomial/wrap_polynomial.cc', 'utils/polynomial/OU_Polynomial.cc', - 'utils/matrix/wrap_matrix.cc', 'utils/matrix/PhaseVector.cc', 'utils/matrix/MatrixOperations.cc', - 'utils/matrix/wrap_phase_vector.cc', 'utils/matrix/Matrix.cc', - 'teapot/wrap_teapotbase.cc', - 'teapot/wrap_matrix_generator.cc', 'teapot/teapotbase.cc', 'teapot/MatrixGenerator.cc' ]) -inc = include_directories([ - 'main', - 'orbit/SynchPartRedefinition', - 'trackerrk4', - 'utils/ellipticalint', - 'teapot', - 'mpi', - 'orbit/ParticlesAttributes', - 'orbit/Errors', - 'orbit/FieldTracker', - 'utils/statistics', - 'utils', - 'linac/tracking', - 'spacecharge', - 'orbit/MaterialInteractions', - 'utils/field_sources', - 'utils/bunch', - 'orbit/Impedances', - 'utils/harmonic_analysis', - 'linac', - 'utils/polynomial', - 'linac/rfgap', - 'orbit/RFCavities', - 'utils/matrix', - 'orbit/BunchDiagnostics', - 'orbit', - 'utils/integration', - 'orbit/Apertures' -]) +inc = include_directories('.') core_lib = library( - 'core', + 'pyorbit3', sources: sources, include_directories: inc, - override_options: ['b_lundef=false'], - dependencies: dependencies, + dependencies: core_dependencies, install: true, ) -core_dep = declare_dependency(link_with : core_lib) +api_headers = [ + 'linac/rfgap/BaseRfGap.hh', + 'linac/rfgap/BaseRfGap_slow.hh', + 'linac/rfgap/MatrixRfGap.hh', + 'linac/rfgap/RfGapThreePointTTF.hh', + 'linac/rfgap/RfGapThreePointTTF_slow.hh', + 'linac/rfgap/RfGapTTF.hh', + 'linac/rfgap/RfGapTTF_slow.hh', + 'linac/rfgap/SuperFishFieldSource.hh', + 'linac/tracking/linac_tracking.hh', + 'mpi/orbit_mpi.hh', + 'orbit/Apertures/Aperture.hh', + 'orbit/Apertures/BaseAperture.hh', + 'orbit/Apertures/BaseApertureShape.hh', + 'orbit/Apertures/CircleApertureShape.hh', + 'orbit/Apertures/CompositeApertureShape.hh', + 'orbit/Apertures/ConvexApertureShape.hh', + 'orbit/Apertures/EllipseApertureShape.hh', + 'orbit/Apertures/EnergyAperture.hh', + 'orbit/Apertures/PhaseAperture.hh', + 'orbit/Apertures/RectangularApertureShape.hh', + 'orbit/Bunch.hh', + 'orbit/BunchDiagnostics/BunchTuneAnalysis.hh', + 'orbit/BunchDiagnostics/BunchTwissAnalysis.hh', + 'orbit/Errors/errorbase.hh', + 'orbit/FieldTracker/FieldTracker.hh', + 'orbit/Impedances/LImpedance.hh', + 'orbit/Impedances/TImpedance.hh', + 'orbit/MaterialInteractions/Collimator.hh', + 'orbit/MaterialInteractions/Foil.hh', + 'orbit/MaterialInteractions/MaterialInteractions.hh', + 'orbit/MaterialInteractions/cross_sections.hh', + 'orbit/MaterialInteractions/numrecipes.hh', + 'orbit/OrbitConst.hh', + 'orbit/ParticlesAttributes/AtomPopulations.hh', + 'orbit/ParticlesAttributes/Evolution.hh', + 'orbit/ParticlesAttributes/LostParticleAttributes.hh', + 'orbit/ParticlesAttributes/ParticleAttributes.hh', + 'orbit/ParticlesAttributes/ParticleAttributesFactory.hh', + 'orbit/ParticlesAttributes/ParticleIdNumber.hh', + 'orbit/ParticlesAttributes/ParticleInitialCoordinates.hh', + 'orbit/ParticlesAttributes/ParticleMacroSize.hh', + 'orbit/ParticlesAttributes/ParticlePhaseAttributes.hh', + 'orbit/ParticlesAttributes/TurnNumberAttributes.hh', + 'orbit/ParticlesAttributes/WaveFunctionAmplitudes.hh', + 'orbit/ParticlesAttributes/part_time.hh', + 'orbit/ParticlesAttributes/pq_coordinates.hh', + 'orbit/RFCavities/Barrier_Cav.hh', + 'orbit/RFCavities/Dual_Harmonic_Cav.hh', + 'orbit/RFCavities/Frequency_Cav.hh', + 'orbit/RFCavities/Harmonic_Cav.hh', + 'orbit/SynchPartRedefinition/SynchPartRedefinitionZdE.hh', + 'orbit/SyncPart.hh', + 'spacecharge/BaseBoundary2D.hh', + 'spacecharge/ForceSolver2D.hh', + 'spacecharge/ForceSolverFFT2D.hh', + 'spacecharge/Grid1D.hh', + 'spacecharge/Grid2D.hh', + 'spacecharge/Grid3D.hh', + 'spacecharge/LSpaceChargeCalc.hh', + 'spacecharge/PoissonSolver2D.hh', + 'spacecharge/PoissonSolver3D.hh', + 'spacecharge/PoissonSolverFFT2D.hh', + 'spacecharge/PoissonSolverFFT3D.hh', + 'spacecharge/ShapedBoundary2D.hh', + 'spacecharge/SpaceChargeCalc2p5D.hh', + 'spacecharge/SpaceChargeCalc2p5Drb.hh', + 'spacecharge/SpaceChargeCalc3D.hh', + 'spacecharge/SpaceChargeCalcSliceBySlice2D.hh', + 'spacecharge/SpaceChargeCalcUnifEllipse.hh', + 'spacecharge/SpaceChargeForceCalc2p5D.hh', + 'spacecharge/UniformEllipsoidFieldCalculator.hh', + 'teapot/MatrixGenerator.hh', + 'teapot/teapotbase.hh', + 'trackerrk4/ExtEffectsContainer.hh', + 'trackerrk4/ExternalEffects.hh', + 'trackerrk4/RungeKuttaTracker.hh', + 'utils/AttributesBucket.hh', + 'utils/BaseFieldSource.hh', + 'utils/BufferStore.hh', + 'utils/FieldSourceContainer.hh', + 'utils/MathPolynomial.hh', + 'utils/OU_Function.hh', + 'utils/OU_SplineCH.hh', + 'utils/Random.hh', + 'utils/StringUtils.hh', + 'utils/bessel.hh', + 'utils/bunch/BunchExtremaCalculator.hh', + 'utils/bunch/InitialCoordsAttrFunctions.hh', + 'utils/bunch/ParticlesWithIdFunctions.hh', + 'utils/bunch/TwissFilteringFunctions.hh', + 'utils/field_sources/DipoleFieldSource.hh', + 'utils/field_sources/LoopFieldSource.hh', + 'utils/field_sources/MagnetFieldSourceGrid3D.hh', + 'utils/field_sources/QuadFieldSource.hh', + 'utils/field_sources/ShiftedFieldSource.hh', + 'utils/harmonic_analysis/HarmonicData.hh', + 'utils/integration/GaussLegendreIntegrator.hh', + 'utils/integration/gauss_legendre_points.hh', + 'utils/matrix/Matrix.hh', + 'utils/matrix/MatrixOperations.hh', + 'utils/matrix/PhaseVector.hh', + 'utils/polynomial/OU_Polynomial.hh', + 'utils/statistics/StatMoments2D.hh', + 'utils/tcomplex.hh', +] + +install_headers(api_headers, subdir : 'pyorbit3', preserve_path : true) + +pkgconfig = import('pkgconfig') + +pkgconfig.generate( + name: 'pyorbit3', + description: 'PyORBIT3 core library', + filebase: 'pyorbit3', + version: meson.project_version(), + libraries: core_lib, + requires: pc_requires, + subdirs: 'pyorbit3', + extra_cflags: '-DUSE_MPI=' + use_mpi_flag, + install_dir: get_option('libdir') / 'pkgconfig', +) + +if build_python +core_install_dir = get_option('prefix') / get_option('libdir') +extension_install_dir = python.get_install_dir() / 'orbit/core' +core_relative_install_dir = run_command( + python, + '-c', + 'import os, sys; print(os.path.relpath(sys.argv[1], sys.argv[2]))', + core_install_dir, + extension_install_dir, + check: true, +).stdout().strip() +if host_machine.system() == 'darwin' + core_install_rpath = '@loader_path/' + core_relative_install_dir +else + core_install_rpath = '$ORIGIN/' + core_relative_install_dir +endif + +binding_lib = shared_library( + 'pyorbit3_python', + sources: 'main/pyORBIT_Object.cc', + dependencies: python_dependency, + gnu_symbol_visibility: 'default', + install: true, +) ext_modules = { - 'orbit_mpi': 'mpi_init.cc', - 'bunch': 'bunch_init.cc', - 'spacecharge': 'spacecharge_init.cc', - 'trackerrk4': 'trackerrk4_init.cc', - 'teapot_base': 'teapot_base_init.cc', - 'linac': 'linac_init.cc', - 'orbit_utils': 'utils_init.cc', - 'aperture': 'aperture_init.cc', - 'foil': 'foil_init.cc', - 'field_sources': 'field_sources_init.cc', - 'rfcavities': 'rfcavities_init.cc', - 'impedances': 'impedances_init.cc', - 'fieldtracker': 'fieldtracker_init.cc', - 'collimator': 'collimator_init.cc', - 'error_base': 'error_base_init.cc', + 'orbit_mpi': files( + 'core/mpi_init.cc', + 'mpi/wrap_orbit_mpi.cc', + 'mpi/wrap_mpi_comm.cc', + 'mpi/wrap_mpi_datatype.cc', + 'mpi/wrap_mpi_request.cc', + 'mpi/wrap_mpi_op.cc', + 'mpi/wrap_mpi_status.cc', + 'mpi/wrap_mpi_group.cc', + ), + 'bunch': files( + 'core/bunch_init.cc', + 'core/type_accessors.cc', + 'orbit/wrap_bunch.cc', + 'orbit/wrap_syncpart.cc', + 'orbit/BunchDiagnostics/wrap_bunch_tune_analysis.cc', + 'orbit/BunchDiagnostics/wrap_bunch_twiss_analysis.cc', + 'orbit/SynchPartRedefinition/wrap_synch_part_redefinition_z_de.cc', + ), + 'spacecharge': files( + 'core/spacecharge_init.cc', + 'core/type_accessors.cc', + 'spacecharge/wrap_spacecharge.cc', + 'spacecharge/wrap_grid1D.cc', + 'spacecharge/wrap_grid2D.cc', + 'spacecharge/wrap_grid3D.cc', + 'spacecharge/wrap_poissonsolverfft2d.cc', + 'spacecharge/wrap_poissonsolverfft3d.cc', + 'spacecharge/wrap_forcesolverfft2d.cc', + 'spacecharge/wrap_boundary2d.cc', + 'spacecharge/wrap_spacechargecalc2p5d.cc', + 'spacecharge/wrap_spacechargeforcecalc2p5d.cc', + 'spacecharge/wrap_spacechargecalc2p5d_rb.cc', + 'spacecharge/wrap_spacechargecalc_slicebyslice_2D.cc', + 'spacecharge/wrap_lspacechargecalc.cc', + 'spacecharge/wrap_spacechargecalc3d.cc', + 'spacecharge/wrap_uniform_ellipsoid_field_calculator.cc', + 'spacecharge/wrap_spacechargecalc_uniform_ellipse.cc', + ), + 'trackerrk4': files( + 'core/trackerrk4_init.cc', + 'trackerrk4/wrap_trackerrk4.cc', + 'trackerrk4/wrap_runge_kutta_tracker.cc', + 'trackerrk4/wrap_py_external_effects.cc', + 'trackerrk4/wrap_ext_effects_container.cc', + 'trackerrk4/PyExternalEffects.cc', + ), + 'teapot_base': files( + 'core/teapot_base_init.cc', + 'core/type_accessors.cc', + 'teapot/wrap_teapotbase.cc', + 'teapot/wrap_matrix_generator.cc', + ), + 'linac': files( + 'core/linac_init.cc', + 'core/type_accessors.cc', + 'linac/wrap_linacmodule.cc', + 'linac/tracking/wrap_linac_tracking.cc', + 'linac/rfgap/wrap_BaseRfGap.cc', + 'linac/rfgap/wrap_BaseRfGap_slow.cc', + 'linac/rfgap/wrap_MatrixRfGap.cc', + 'linac/rfgap/wrap_RfGapTTF.cc', + 'linac/rfgap/wrap_RfGapTTF_slow.cc', + 'linac/rfgap/wrap_SuperFishFieldSource.cc', + 'linac/rfgap/wrap_RfGapThreePointTTF.cc', + 'linac/rfgap/wrap_RfGapThreePointTTF_slow.cc', + ), + 'orbit_utils': files( + 'core/utils_init.cc', + 'core/type_accessors.cc', + 'utils/wrap_utils.cc', + 'utils/matrix/wrap_matrix.cc', + 'utils/matrix/wrap_phase_vector.cc', + 'utils/wrap_py_base_field_source.cc', + 'utils/wrap_field_source_container.cc', + 'utils/wrap_function.cc', + 'utils/wrap_splinech.cc', + 'utils/statistics/wrap_statmoments2d.cc', + 'utils/bunch/wrap_bunch_extrema_calculator.cc', + 'utils/integration/wrap_gauss_legendre_integrator.cc', + 'utils/polynomial/wrap_polynomial.cc', + 'utils/wrap_numrecipes.cc', + 'utils/bunch/wrap_bunch_utils_functions.cc', + 'utils/harmonic_analysis/wrap_harmonic_data.cc', + 'utils/wrap_random.cc', + 'utils/PyBaseFieldSource.cc', + ), + 'aperture': files( + 'core/aperture_init.cc', + 'core/type_accessors.cc', + 'orbit/Apertures/wrap_aperture.cc', + 'orbit/Apertures/wrap_TAperture.cc', + 'orbit/Apertures/wrap_PhaseAperture.cc', + 'orbit/Apertures/wrap_EnergyAperture.cc', + 'orbit/Apertures/wrap_BaseAperture.cc', + 'orbit/Apertures/wrap_PyBaseApertureShape.cc', + 'orbit/Apertures/wrap_PrimitiveApertureShape.cc', + 'orbit/Apertures/wrap_CompositeApertureShape.cc', + 'orbit/Apertures/wrap_ConvexApertureShape.cc', + 'orbit/Apertures/PyBaseApertureShape.cc', + ), + 'foil': files( + 'core/foil_init.cc', + 'core/type_accessors.cc', + 'orbit/MaterialInteractions/wrap_foil.cc', + ), + 'field_sources': files( + 'core/field_sources_init.cc', + 'core/type_accessors.cc', + 'utils/field_sources/wrap_field_sources_module.cc', + 'utils/field_sources/wrap_magnetic_field_source_grid3d.cc', + 'utils/field_sources/wrap_quad_field_source.cc', + 'utils/field_sources/wrap_dipole_field_source.cc', + 'utils/field_sources/wrap_loop_field_source.cc', + ), + 'rfcavities': files( + 'core/rfcavities_init.cc', + 'core/type_accessors.cc', + 'orbit/RFCavities/wrap_rfcavities.cc', + 'orbit/RFCavities/wrap_Frequency_Cav.cc', + 'orbit/RFCavities/wrap_Harmonic_Cav.cc', + 'orbit/RFCavities/wrap_Barrier_Cav.cc', + 'orbit/RFCavities/wrap_Dual_Harmonic_Cav.cc', + ), + 'impedances': files( + 'core/impedances_init.cc', + 'core/type_accessors.cc', + 'orbit/Impedances/wrap_impedances.cc', + 'orbit/Impedances/wrap_LImpedance.cc', + 'orbit/Impedances/wrap_TImpedance.cc', + ), + 'fieldtracker': files( + 'core/fieldtracker_init.cc', + 'core/type_accessors.cc', + 'orbit/FieldTracker/wrap_fieldtracker.cc', + ), + 'collimator': files( + 'core/collimator_init.cc', + 'core/type_accessors.cc', + 'orbit/MaterialInteractions/wrap_collimator.cc', + ), + 'error_base': files( + 'core/error_base_init.cc', + 'orbit/Errors/wrap_errorbase.cc', + ), } -base = meson.current_source_dir() + '/core' - -foreach name, src : ext_modules +foreach name, src_list : ext_modules python.extension_module( name, - sources: base / src, - include_directories: inc, - dependencies: [core_dep], + sources: src_list, + include_directories: inc, + link_with: [core_lib, binding_lib], + dependencies: core_dependencies + [python_dependency], + install_rpath: core_install_rpath, install: true, subdir: 'orbit/core', ) endforeach +endif diff --git a/src/mpi/orbit_mpi.cc b/src/mpi/orbit_mpi.cc index 4965a9e1..180ea3e7 100644 --- a/src/mpi/orbit_mpi.cc +++ b/src/mpi/orbit_mpi.cc @@ -1,4 +1,4 @@ -#include "orbit_mpi.hh" +#include "mpi/orbit_mpi.hh" #include #include @@ -33,9 +33,6 @@ int ORBIT_MPI_Init(){ #if USE_MPI > 0 // Ignoring result; if it fails, the proc is doomed anyway. MPI_Init(NULL, NULL); - - // Registering MPI finalize method at cleanup stage - Py_AtExit(ORBIT_MPI_Finalize); #endif return MPI_SUCCESS; } @@ -52,57 +49,37 @@ int ORBIT_MPI_Initialized(int *init){ return res; } -/** A C wrapper around MPI_Finalize. */ +/** Finalizes MPI without terminating the process. */ +int ORBIT_MPI_FinalizeMPI(){ +#if USE_MPI > 0 + int initialized = 0; + int finalized = 0; + MPI_Initialized(&initialized); + if(initialized == 0) return MPI_SUCCESS; + MPI_Finalized(&finalized); + if(finalized == 0) return MPI_Finalize(); +#endif + return MPI_SUCCESS; +} + +/** A C wrapper around MPI_Finalize that terminates successfully. */ void ORBIT_MPI_Finalize(){ - int res = 0; - res = ORBIT_MPI_Finalize(NULL); - if(res != MPI_SUCCESS){ - PyErr_SetString(PyExc_RuntimeError,"ORBIT_MPI_Finalize."); - PyErr_Print(); - PyRun_SimpleString("import traceback; traceback.print_stack()"); - } + ORBIT_MPI_Finalize(NULL); } /** A C wrapper around MPI_Finalize(message). */ int ORBIT_MPI_Finalize(const char* message){ - int res = 0; - int rank; - ORBIT_MPI_Comm_rank(MPI_COMM_WORLD, &rank); - int init; - ORBIT_MPI_Initialized(&init); -#if USE_MPI > 0 - if(init > 0){ - res = MPI_Finalize(); - } -#else - if(message != NULL){res = MPI_SUCCESS;} -#endif + int rank = 0; + int initialized = 0; + ORBIT_MPI_Initialized(&initialized); + if(initialized > 0) ORBIT_MPI_Comm_rank(MPI_COMM_WORLD, &rank); + int res = ORBIT_MPI_FinalizeMPI(); if(rank == 0){ - if(Py_IsInitialized()){ - PyErr_SetString(PyExc_RuntimeError,"ORBIT_MPI_Finalize."); - PyErr_Print(); - PyRun_SimpleString("import traceback; traceback.print_stack()"); - } if(message != NULL){ std::cerr< -//c++ header for cerr and cout -#include - -#include "wrap_mpi_comm.hh" +#include "mpi/wrap_mpi_comm.hh" namespace wrap_orbit_mpi_comm{ @@ -20,13 +17,14 @@ namespace wrap_orbit_mpi_comm{ #ifdef __cplusplus extern "C" { #endif + //--------------------------------------------------------- //Python MPI_Comm class definition //--------------------------------------------------------- //constructor for python class wrapping MPI_Comm instance //It never will be called directly - static PyObject* mpi_comm_new(PyTypeObject *type, PyObject *args, PyObject *kwds) + static PyObject* mpi_comm_new(PyTypeObject *type, PyObject *Py_UNUSED(args), PyObject *Py_UNUSED(kwds)) { pyORBIT_MPI_Comm* self; self = (pyORBIT_MPI_Comm *) type->tp_alloc(type, 0); @@ -36,44 +34,43 @@ extern "C" { //initializator for python MPI_Comm class //this is implementation of the __init__ method - static int mpi_comm_init(pyORBIT_MPI_Comm *self, PyObject *args, PyObject *kwds){ - if(PyTuple_Size(args) != 0){ - error("MPI_Comm constructor cannot have an input parameter."); - } - return 0; - } + static int mpi_comm_init(pyORBIT_MPI_Comm *Py_UNUSED(self), PyObject *args, PyObject *Py_UNUSED(kwds)){ + if(PyTuple_Size(args) != 0){ + error("MPI_Comm constructor cannot have an input parameter."); + } + return 0; + } //feeing the mpi comm in the python MPI_Comm class - static PyObject* mpi_comm_free(PyObject *self, PyObject *args){ - pyORBIT_MPI_Comm* pyMPI_Comm = (pyORBIT_MPI_Comm*) self; + static PyObject* mpi_comm_free(PyObject *self, PyObject *Py_UNUSED(ignored)){ + pyORBIT_MPI_Comm* pyMPI_Comm = (pyORBIT_MPI_Comm*) self; if(pyMPI_Comm->comm != MPI_COMM_WORLD && pyMPI_Comm->comm != MPI_COMM_SELF){ ORBIT_MPI_Comm_free(&pyMPI_Comm->comm); } pyMPI_Comm->comm = MPI_COMM_WORLD; - Py_INCREF(Py_None); - return Py_None; - } + Py_INCREF(Py_None); + return Py_None; + } //----------------------------------------------------- //destructor for python MPI_Comm class. //----------------------------------------------------- //this is implementation of the __del__ method - static void mpi_comm_del(pyORBIT_MPI_Comm* self){ + static void mpi_comm_del(pyORBIT_MPI_Comm* self){ //std::cerr<<"The MPI_Comm __del__ has been called!"<comm; if(comm != MPI_COMM_NULL && comm != MPI_COMM_WORLD && comm != MPI_COMM_SELF){ ORBIT_MPI_Comm_free(&comm); } self->ob_base.ob_type->tp_free((PyObject*)self); - } + } // defenition of the methods of the python MPI_Comm wrapper class // they will be vailable from python level - static PyMethodDef MPI_CommClassMethods[] = { - //{ "test", MPI_Comm_test ,METH_VARARGS,"document string"}, - { "free", mpi_comm_free ,METH_VARARGS,"Free MPI communicator."}, - {NULL} - }; + static PyMethodDef MPI_CommClassMethods[] = { + { "free", mpi_comm_free ,METH_NOARGS,"Free MPI communicator."}, + {NULL} + }; // defenition of the memebers of the python MPI_Comm wrapper class // they will be vailable from python level @@ -81,13 +78,13 @@ extern "C" { {NULL} }; - //new python SyncPart wrapper type definition - static PyTypeObject pyORBIT_MPI_Comm_Type = { + //new python MPI_Comm wrapper type definition + PyTypeObject pyORBIT_MPI_Comm_Type = { PyVarObject_HEAD_INIT(NULL, 0) "MPI_Comm", /*tp_name*/ sizeof(pyORBIT_MPI_Comm), /*tp_basicsize*/ 0, /*tp_itemsize*/ - (destructor) mpi_comm_del , /*tp_dealloc*/ + (destructor) mpi_comm_del, /*tp_dealloc*/ 0, /*tp_print*/ 0, /*tp_getattr*/ 0, /*tp_setattr*/ @@ -127,11 +124,10 @@ extern "C" { //Initialization function of the MPI_Comm class //It will be called from orbit_mpi wrapper initialization //-------------------------------------------------- - void init_orbit_mpi_comm(PyObject* module){ + void init_orbit_mpi_comm(PyObject* module){ if (PyType_Ready(&pyORBIT_MPI_Comm_Type) < 0) return; - Py_INCREF(&pyORBIT_MPI_Comm_Type); - //we put Py_INCREF(...) because PyModule_AddObject() steal the reference + Py_INCREF(&pyORBIT_MPI_Comm_Type); PyObject * comm_module = PyModule_New("mpi_comm"); PyModule_AddObject(comm_module, "MPI_Comm", (PyObject *)&pyORBIT_MPI_Comm_Type); @@ -149,9 +145,9 @@ extern "C" { pyMPI_Comm_NULL->comm = MPI_COMM_NULL; Py_INCREF((PyObject *) pyMPI_Comm_NULL); - PyModule_AddObject(comm_module, "MPI_COMM_WORLD", (PyObject *) pyMPI_Comm_WORLD); - PyModule_AddObject(comm_module, "MPI_COMM_SELF", (PyObject *) pyMPI_Comm_SELF); - PyModule_AddObject(comm_module, "MPI_COMM_NULL", (PyObject *) pyMPI_Comm_NULL); + PyModule_AddObject(comm_module, "MPI_COMM_WORLD", (PyObject *) pyMPI_Comm_WORLD); + PyModule_AddObject(comm_module, "MPI_COMM_SELF", (PyObject *) pyMPI_Comm_SELF); + PyModule_AddObject(comm_module, "MPI_COMM_NULL", (PyObject *) pyMPI_Comm_NULL); PyModule_AddObject(module, "mpi_comm", comm_module); } @@ -170,16 +166,6 @@ extern "C" { Py_DECREF(pyMPI_Comm); } - PyObject* getMPI_CommType(const char* name){ - PyObject* mod = PyImport_ImportModule("orbit.core.orbit_mpi"); - PyObject* mpi_comm_mod = PyObject_GetAttrString(mod,"mpi_comm"); - PyObject* pyType = PyObject_GetAttrString(mpi_comm_mod,name); - Py_DECREF(mpi_comm_mod); - Py_DECREF(mod); - Py_DECREF(pyType); - return pyType; - } - #ifdef __cplusplus } #endif diff --git a/src/mpi/wrap_mpi_comm.hh b/src/mpi/wrap_mpi_comm.hh index 9b06b544..4e5a4e21 100644 --- a/src/mpi/wrap_mpi_comm.hh +++ b/src/mpi/wrap_mpi_comm.hh @@ -6,13 +6,13 @@ // This is a wrapper for the MPI_Comm data type from MPI // /////////////////////////////////////////////////////////////////////////// -#include "orbit_mpi.hh" +#include "mpi/wrap_orbit_mpi_types.hh" #ifdef __cplusplus extern "C" { #endif - namespace wrap_orbit_mpi_comm{ + namespace wrap_orbit_mpi_comm { void init_orbit_mpi_comm(PyObject* module); //The function that will be exposed as C/C++ API for MPI_Comm diff --git a/src/mpi/wrap_mpi_datatype.cc b/src/mpi/wrap_mpi_datatype.cc index 12ab0442..08c61853 100644 --- a/src/mpi/wrap_mpi_datatype.cc +++ b/src/mpi/wrap_mpi_datatype.cc @@ -3,15 +3,15 @@ // INCLUDE FILES // /////////////////////////////////////////////////////////////////////////// -#include "orbit_mpi.hh" +#include "mpi/orbit_mpi.hh" //this header is from Python package -#include "structmember.h" +#include //c++ header for cerr and cout #include -#include "wrap_mpi_datatype.hh" +#include "mpi/wrap_mpi_datatype.hh" namespace wrap_orbit_mpi_datatype{ diff --git a/src/mpi/wrap_mpi_datatype.hh b/src/mpi/wrap_mpi_datatype.hh index 670192ee..4eaed246 100644 --- a/src/mpi/wrap_mpi_datatype.hh +++ b/src/mpi/wrap_mpi_datatype.hh @@ -6,7 +6,7 @@ // This is a wrapper for the MPI_Datatype data type from MPI // /////////////////////////////////////////////////////////////////////////// -#include "orbit_mpi.hh" +#include "mpi/wrap_orbit_mpi_types.hh" #ifdef __cplusplus extern "C" { diff --git a/src/mpi/wrap_mpi_group.cc b/src/mpi/wrap_mpi_group.cc index 2aad7957..6bff418b 100644 --- a/src/mpi/wrap_mpi_group.cc +++ b/src/mpi/wrap_mpi_group.cc @@ -3,15 +3,15 @@ // INCLUDE FILES // /////////////////////////////////////////////////////////////////////////// -#include "orbit_mpi.hh" +#include "mpi/orbit_mpi.hh" //this header is from Python package -#include "structmember.h" +#include //c++ header for cerr and cout #include -#include "wrap_mpi_group.hh" +#include "mpi/wrap_mpi_group.hh" namespace wrap_orbit_mpi_group{ diff --git a/src/mpi/wrap_mpi_group.hh b/src/mpi/wrap_mpi_group.hh index fc06e37c..af486d88 100644 --- a/src/mpi/wrap_mpi_group.hh +++ b/src/mpi/wrap_mpi_group.hh @@ -6,7 +6,7 @@ // This is a wrapper for the MPI_Group data type from MPI // /////////////////////////////////////////////////////////////////////////// -#include "orbit_mpi.hh" +#include "mpi/wrap_orbit_mpi_types.hh" #ifdef __cplusplus extern "C" { diff --git a/src/mpi/wrap_mpi_op.cc b/src/mpi/wrap_mpi_op.cc index 3d73c313..a59c573c 100644 --- a/src/mpi/wrap_mpi_op.cc +++ b/src/mpi/wrap_mpi_op.cc @@ -3,15 +3,15 @@ // INCLUDE FILES // /////////////////////////////////////////////////////////////////////////// -#include "orbit_mpi.hh" +#include "mpi/orbit_mpi.hh" //this header is from Python package -#include "structmember.h" +#include //c++ header for cerr and cout #include -#include "wrap_mpi_op.hh" +#include "mpi/wrap_mpi_op.hh" namespace wrap_orbit_mpi_op{ diff --git a/src/mpi/wrap_mpi_op.hh b/src/mpi/wrap_mpi_op.hh index 76d7102c..bcae888e 100644 --- a/src/mpi/wrap_mpi_op.hh +++ b/src/mpi/wrap_mpi_op.hh @@ -6,7 +6,7 @@ // This is a wrapper for the MPI_Op data type from MPI // /////////////////////////////////////////////////////////////////////////// -#include "orbit_mpi.hh" +#include "mpi/wrap_orbit_mpi_types.hh" #ifdef __cplusplus extern "C" { diff --git a/src/mpi/wrap_mpi_request.cc b/src/mpi/wrap_mpi_request.cc index 73c6fad9..45b15ea9 100644 --- a/src/mpi/wrap_mpi_request.cc +++ b/src/mpi/wrap_mpi_request.cc @@ -3,15 +3,15 @@ // INCLUDE FILES // /////////////////////////////////////////////////////////////////////////// -#include "orbit_mpi.hh" +#include "mpi/orbit_mpi.hh" //this header is from Python package -#include "structmember.h" +#include //c++ header for cerr and cout #include -#include "wrap_mpi_request.hh" +#include "mpi/wrap_mpi_request.hh" namespace wrap_orbit_mpi_request{ diff --git a/src/mpi/wrap_mpi_request.hh b/src/mpi/wrap_mpi_request.hh index 059da4ae..177aa6da 100644 --- a/src/mpi/wrap_mpi_request.hh +++ b/src/mpi/wrap_mpi_request.hh @@ -6,7 +6,7 @@ // This is a wrapper for the MPI_Request data type from MPI // /////////////////////////////////////////////////////////////////////////// -#include "orbit_mpi.hh" +#include "mpi/wrap_orbit_mpi_types.hh" #ifdef __cplusplus extern "C" { diff --git a/src/mpi/wrap_mpi_status.cc b/src/mpi/wrap_mpi_status.cc index 81ad503c..c602bf07 100644 --- a/src/mpi/wrap_mpi_status.cc +++ b/src/mpi/wrap_mpi_status.cc @@ -3,15 +3,15 @@ // INCLUDE FILES // /////////////////////////////////////////////////////////////////////////// -#include "orbit_mpi.hh" +#include "mpi/orbit_mpi.hh" //this header is from Python package -#include "structmember.h" +#include //c++ header for cerr and cout #include -#include "wrap_mpi_status.hh" +#include "mpi/wrap_mpi_status.hh" namespace wrap_orbit_mpi_status{ diff --git a/src/mpi/wrap_mpi_status.hh b/src/mpi/wrap_mpi_status.hh index 19d021b5..99556942 100644 --- a/src/mpi/wrap_mpi_status.hh +++ b/src/mpi/wrap_mpi_status.hh @@ -6,7 +6,7 @@ // This is a wrapper for the MPI_Status data type from MPI // /////////////////////////////////////////////////////////////////////////// -#include "orbit_mpi.hh" +#include "mpi/wrap_orbit_mpi_types.hh" #ifdef __cplusplus extern "C" { diff --git a/src/mpi/wrap_orbit_mpi.cc b/src/mpi/wrap_orbit_mpi.cc index f83ff846..5129bb52 100644 --- a/src/mpi/wrap_orbit_mpi.cc +++ b/src/mpi/wrap_orbit_mpi.cc @@ -1,22 +1,22 @@ #define PY_SSIZE_T_CLEAN -#include "Python.h" -#include "orbit_mpi.hh" +#include +#include "mpi/orbit_mpi.hh" #include #include //arrays buffers for MPI exchange -#include "BufferStore.hh" +#include "utils/BufferStore.hh" -#include "wrap_orbit_mpi.hh" +#include "mpi/wrap_orbit_mpi.hh" //wrappers of mpi objects -#include "wrap_mpi_comm.hh" -#include "wrap_mpi_group.hh" -#include "wrap_mpi_status.hh" -#include "wrap_mpi_request.hh" -#include "wrap_mpi_datatype.hh" -#include "wrap_mpi_op.hh" +#include "mpi/wrap_mpi_comm.hh" +#include "mpi/wrap_mpi_group.hh" +#include "mpi/wrap_mpi_status.hh" +#include "mpi/wrap_mpi_request.hh" +#include "mpi/wrap_mpi_datatype.hh" +#include "mpi/wrap_mpi_op.hh" using namespace OrbitUtils; @@ -28,6 +28,10 @@ using namespace OrbitUtils; /** The namespace for the python wrappers around MPI functions. */ namespace wrap_orbit_mpi{ + static void finalize_mpi_at_exit(){ + ORBIT_MPI_FinalizeMPI(); + } + /** A local error(message) function. */ void error(const char* msg){ ORBIT_MPI_Finalize(msg); } @@ -68,27 +72,27 @@ namespace wrap_orbit_mpi{ //------------------------------------------------------------------ // Wrappers for MPI functions related to the MPI_Comm manipulations //------------------------------------------------------------------ - #include "wrap_orbit_mpi_comm_functions.hh" + #include "mpi/wrap_orbit_mpi_comm_functions.hh" //------------------------------------------------------------------ // Wrappers for MPI functions related to the MPI_Group manipulations //------------------------------------------------------------------ - #include "wrap_orbit_mpi_group_functions.hh" + #include "mpi/wrap_orbit_mpi_group_functions.hh" //---------------------------------------------------------------------- // Wrappers for MPI functions related to the MPI_Intercomm manipulations //---------------------------------------------------------------------- - #include "wrap_orbit_mpi_intercomm_functions.hh" + #include "mpi/wrap_orbit_mpi_intercomm_functions.hh" //------------------------------------------------------------------- // Wrappers for MPI functions related to the MPI_Graph manipulations //------------------------------------------------------------------- - #include "wrap_orbit_mpi_graph_functions.hh" + #include "mpi/wrap_orbit_mpi_graph_functions.hh" //------------------------------------------------------------------ // Wrappers for MPI functions related to the Send-Receive operations //------------------------------------------------------------------ - #include "wrap_orbit_mpi_send_receive_functions.hh" + #include "mpi/wrap_orbit_mpi_send_receive_functions.hh" //Finalizes the execution of program // the action is depended on the number of arguments @@ -181,6 +185,7 @@ namespace wrap_orbit_mpi{ PyMODINIT_FUNC initorbit_mpi(void) { // Initialize MPI ORBIT_MPI_Init(); + Py_AtExit(finalize_mpi_at_exit); PyObject *m, *d; m = PyModule_Create(&cModPyDem); diff --git a/src/mpi/wrap_orbit_mpi.hh b/src/mpi/wrap_orbit_mpi.hh index 2f4cc15f..16d769ed 100644 --- a/src/mpi/wrap_orbit_mpi.hh +++ b/src/mpi/wrap_orbit_mpi.hh @@ -1,3 +1,5 @@ +#include + #ifdef __cplusplus extern "C" { #endif diff --git a/src/mpi/wrap_orbit_mpi_types.hh b/src/mpi/wrap_orbit_mpi_types.hh new file mode 100644 index 00000000..90c99a06 --- /dev/null +++ b/src/mpi/wrap_orbit_mpi_types.hh @@ -0,0 +1,38 @@ +#ifndef WRAP_ORBIT_MPI_TYPES_H +#define WRAP_ORBIT_MPI_TYPES_H + +#include + +#include "mpi/orbit_mpi.hh" + +typedef struct { + PyObject_HEAD + MPI_Comm comm; +} pyORBIT_MPI_Comm; + +typedef struct { + PyObject_HEAD + MPI_Group group; +} pyORBIT_MPI_Group; + +typedef struct { + PyObject_HEAD + MPI_Status status; +} pyORBIT_MPI_Status; + +typedef struct { + PyObject_HEAD + MPI_Request request; +} pyORBIT_MPI_Request; + +typedef struct { + PyObject_HEAD + MPI_Datatype datatype; +} pyORBIT_MPI_Datatype; + +typedef struct { + PyObject_HEAD + MPI_Op op; +} pyORBIT_MPI_Op; + +#endif diff --git a/src/orbit/Apertures/Aperture.cc b/src/orbit/Apertures/Aperture.cc index dbadba45..b5dac547 100644 --- a/src/orbit/Apertures/Aperture.cc +++ b/src/orbit/Apertures/Aperture.cc @@ -1,14 +1,14 @@ -#include "Aperture.hh" -#include "SyncPart.hh" -#include "OrbitConst.hh" -#include "Random.hh" +#include "orbit/Apertures/Aperture.hh" +#include "orbit/SyncPart.hh" +#include "orbit/OrbitConst.hh" +#include "utils/Random.hh" #include #include #include #include -#include "ParticleAttributes.hh" +#include "orbit/ParticlesAttributes/ParticleAttributes.hh" // Constructor /////////////////////////////////////////////////////////////////////////// // @@ -31,7 +31,7 @@ // /////////////////////////////////////////////////////////////////////////// -Aperture::Aperture(int shape, double a, double b, double c, double d, double pos): CppPyWrapper(NULL) +Aperture::Aperture(int shape, double a, double b, double c, double d, double pos) { shape_ = shape; a_ = a; diff --git a/src/orbit/Apertures/Aperture.hh b/src/orbit/Apertures/Aperture.hh index 1f9243b4..de727b2e 100644 --- a/src/orbit/Apertures/Aperture.hh +++ b/src/orbit/Apertures/Aperture.hh @@ -3,16 +3,14 @@ #define APERTURE_H //pyORBIT utils -#include "CppPyWrapper.hh" -#include "Bunch.hh" +#include "orbit/Bunch.hh" -using namespace std; /** The aperture class is used to define how a bunch propogates through an aperture */ -class Aperture: public OrbitUtils::CppPyWrapper +class Aperture { public: diff --git a/src/orbit/Apertures/BaseAperture.cc b/src/orbit/Apertures/BaseAperture.cc index 696e0543..eae142d4 100644 --- a/src/orbit/Apertures/BaseAperture.cc +++ b/src/orbit/Apertures/BaseAperture.cc @@ -1,5 +1,5 @@ -#include "BaseAperture.hh" -#include "ParticleAttributes.hh" +#include "orbit/Apertures/BaseAperture.hh" +#include "orbit/ParticlesAttributes/ParticleAttributes.hh" #include #include @@ -24,7 +24,7 @@ /////////////////////////////////////////////////////////////////////////// /** BaseAperture constructor */ -BaseAperture::BaseAperture(): CppPyWrapper(NULL) +BaseAperture::BaseAperture() { apertureName = "no_name"; isActive = 1; @@ -36,9 +36,6 @@ BaseAperture::BaseAperture(): CppPyWrapper(NULL) /** BaseAperture decstructor */ BaseAperture::~BaseAperture() { - if(apertureShape != NULL){ - Py_XDECREF(apertureShape->getPyWrapper()); - } } /** Returns aperture shape */ @@ -55,18 +52,7 @@ void BaseAperture::setApertureShape(BaseApertureShape* apertureShapeIn){ return; } - if( ((PyObject*) apertureShapeIn->getPyWrapper()) == NULL){ - ORBIT_MPI_Finalize("BaseAperture class setApertureShape(...): BaseApertureShape Python class needed! Stop."); - } - - if(apertureShape != NULL){ - if( ((PyObject*) apertureShape->getPyWrapper()) != NULL){ - Py_XDECREF( (PyObject*) apertureShape->getPyWrapper()); - } - } - apertureShape = apertureShapeIn; - Py_INCREF((PyObject*) apertureShape->getPyWrapper()); } /** @@ -196,12 +182,12 @@ int BaseAperture::getNumberOfLost(){ } /** Returns the aperture name */ -string BaseAperture::getName(){ +std::string BaseAperture::getName(){ return apertureName; } /** Sets the aperture name */ -void BaseAperture::setName(string apertureNameIn){ +void BaseAperture::setName(std::string apertureNameIn){ apertureName = apertureNameIn; } diff --git a/src/orbit/Apertures/BaseAperture.hh b/src/orbit/Apertures/BaseAperture.hh index 7a6c40de..178bab22 100644 --- a/src/orbit/Apertures/BaseAperture.hh +++ b/src/orbit/Apertures/BaseAperture.hh @@ -2,13 +2,9 @@ #ifndef BASE_APERTURE_H #define BASE_APERTURE_H -#include "Bunch.hh" -#include "BaseApertureShape.hh" +#include "orbit/Bunch.hh" +#include "orbit/Apertures/BaseApertureShape.hh" -//pyORBIT utils -#include "CppPyWrapper.hh" - -using namespace std; /////////////////////////////////////////////////////////////////////////// // @@ -29,7 +25,7 @@ using namespace std; of particle's coordinates. */ -class BaseAperture: public OrbitUtils::CppPyWrapper +class BaseAperture { public: @@ -42,7 +38,7 @@ public: /** Returns aperture shape */ BaseApertureShape* getApertureShape(); - /** Sets aperture shape */ + /** Sets a borrowed aperture shape. The caller retains ownership. */ void setApertureShape(BaseApertureShape* apertureShape); /** Routine for transfering particles through a aperture */ @@ -52,10 +48,10 @@ public: int getNumberOfLost(); /** Returns the aperture name */ - string getName(); + std::string getName(); /** Sets the aperture name */ - void setName(string apertureNameIn); + void setName(std::string apertureNameIn); /** Sets the position of the node in the lattice */ double getPosition(); @@ -76,7 +72,7 @@ public: protected: //name of the aperture - string apertureName; + std::string apertureName; //Counters int nLost_; diff --git a/src/orbit/Apertures/BaseApertureShape.cc b/src/orbit/Apertures/BaseApertureShape.cc index fbf2016f..980dd210 100644 --- a/src/orbit/Apertures/BaseApertureShape.cc +++ b/src/orbit/Apertures/BaseApertureShape.cc @@ -1,4 +1,4 @@ -#include "BaseApertureShape.hh" +#include "orbit/Apertures/BaseApertureShape.hh" #include #include @@ -20,7 +20,7 @@ /////////////////////////////////////////////////////////////////////////// /** BaseApertureShape constructor */ -BaseApertureShape::BaseApertureShape(): CppPyWrapper(NULL) +BaseApertureShape::BaseApertureShape() { shapeName = "no_shape"; typeName = "no_type"; @@ -65,19 +65,19 @@ double BaseApertureShape::getCenterY() /** Returns the shape name */ -string BaseApertureShape::getName() +std::string BaseApertureShape::getName() { return shapeName; } /** Sets the shape name */ -void BaseApertureShape::setName(string shapeNameIn) +void BaseApertureShape::setName(std::string shapeNameIn) { shapeName = shapeNameIn; } /** Returns the shape type name */ -string BaseApertureShape::getTypeName() +std::string BaseApertureShape::getTypeName() { return typeName; } diff --git a/src/orbit/Apertures/BaseApertureShape.hh b/src/orbit/Apertures/BaseApertureShape.hh index b6f26e59..10684f1a 100644 --- a/src/orbit/Apertures/BaseApertureShape.hh +++ b/src/orbit/Apertures/BaseApertureShape.hh @@ -2,13 +2,9 @@ #ifndef BASE_APERTURE_SHAPE_H #define BASE_APERTURE_SHAPE_H -#include "Bunch.hh" -#include "BaseApertureShape.hh" +#include "orbit/Bunch.hh" +#include "orbit/Apertures/BaseApertureShape.hh" -//pyORBIT utils -#include "CppPyWrapper.hh" - -using namespace std; /////////////////////////////////////////////////////////////////////////// // @@ -26,7 +22,7 @@ using namespace std; It defines the interface for BaseApertureShape subclasses. */ -class BaseApertureShape: public OrbitUtils::CppPyWrapper +class BaseApertureShape { public: @@ -52,19 +48,19 @@ public: double getCenterY(); /** Returns the shape name */ - string getName(); + std::string getName(); /** Sets the shape name */ - void setName(string shapeName); + void setName(std::string shapeName); /** Returns the shape type name */ - string getTypeName(); + std::string getTypeName(); protected: - string shapeName; + std::string shapeName; - string typeName; + std::string typeName; double x_center, y_center; diff --git a/src/orbit/Apertures/CircleApertureShape.cc b/src/orbit/Apertures/CircleApertureShape.cc index 4bdcd123..08b81314 100644 --- a/src/orbit/Apertures/CircleApertureShape.cc +++ b/src/orbit/Apertures/CircleApertureShape.cc @@ -1,4 +1,4 @@ -#include "CircleApertureShape.hh" +#include "orbit/Apertures/CircleApertureShape.hh" #include #include diff --git a/src/orbit/Apertures/CircleApertureShape.hh b/src/orbit/Apertures/CircleApertureShape.hh index 46ca8095..491115cf 100644 --- a/src/orbit/Apertures/CircleApertureShape.hh +++ b/src/orbit/Apertures/CircleApertureShape.hh @@ -1,13 +1,9 @@ #ifndef CIRCULAR_APERTURE_SHAPE_H #define CIRCULAR_APERTURE_SHAPE_H -//pyORBIT utils -#include "CppPyWrapper.hh" +#include "orbit/Bunch.hh" +#include "orbit/Apertures/BaseApertureShape.hh" -#include "Bunch.hh" -#include "BaseApertureShape.hh" - -using namespace std; /////////////////////////////////////////////////////////////////////////// // diff --git a/src/orbit/Apertures/CompositeApertureShape.cc b/src/orbit/Apertures/CompositeApertureShape.cc index 20b4ada4..4729246a 100644 --- a/src/orbit/Apertures/CompositeApertureShape.cc +++ b/src/orbit/Apertures/CompositeApertureShape.cc @@ -1,4 +1,4 @@ -#include "CompositeApertureShape.hh" +#include "orbit/Apertures/CompositeApertureShape.hh" #include #include @@ -32,12 +32,6 @@ CompositeApertureShape::CompositeApertureShape(): BaseApertureShape() /** CompositeApertureShape decstructor */ CompositeApertureShape::~CompositeApertureShape() { - int n_shapes = apertureShapes.size(); - for(int ind = 0; ind < n_shapes; ind++){ - if(apertureShapes[ind]->getPyWrapper() != NULL){ - Py_XDECREF((PyObject*) apertureShapes[ind]->getPyWrapper()); - } - } } /** Return 1 if the particular macro-particle is inside this shape */ @@ -59,7 +53,6 @@ int CompositeApertureShape::inside(Bunch* bunch, int count){ void CompositeApertureShape::addApertureShape(BaseApertureShape* apertureShape) { apertureShapes.push_back(apertureShape); - Py_INCREF((PyObject*) apertureShape->getPyWrapper()); } /** Returns vector of pointers to aperture shapes that are in this collection */ diff --git a/src/orbit/Apertures/CompositeApertureShape.hh b/src/orbit/Apertures/CompositeApertureShape.hh index 54030614..efd2b8c1 100644 --- a/src/orbit/Apertures/CompositeApertureShape.hh +++ b/src/orbit/Apertures/CompositeApertureShape.hh @@ -1,13 +1,9 @@ #ifndef COMPOSITE_APERTURE_SHAPE_H #define COMPOSITE_APERTURE_SHAPE_H -//pyORBIT utils -#include "CppPyWrapper.hh" +#include "orbit/Bunch.hh" +#include "orbit/Apertures/BaseApertureShape.hh" -#include "Bunch.hh" -#include "BaseApertureShape.hh" - -using namespace std; /////////////////////////////////////////////////////////////////////////// // @@ -39,7 +35,7 @@ public: /** Return 1 if the particular macro-particle is inside this shape */ int inside(Bunch* bunch, int count); - /** Adds the new aperture shape to the collection */ + /** Adds a non-owning aperture-shape reference to the collection. */ void addApertureShape(BaseApertureShape* apertureShape); diff --git a/src/orbit/Apertures/ConvexApertureShape.cc b/src/orbit/Apertures/ConvexApertureShape.cc index 6e0e74a7..fb60117d 100644 --- a/src/orbit/Apertures/ConvexApertureShape.cc +++ b/src/orbit/Apertures/ConvexApertureShape.cc @@ -1,6 +1,6 @@ -#include "orbit_mpi.hh" +#include "mpi/orbit_mpi.hh" -#include "ConvexApertureShape.hh" +#include "orbit/Apertures/ConvexApertureShape.hh" #include #include diff --git a/src/orbit/Apertures/ConvexApertureShape.hh b/src/orbit/Apertures/ConvexApertureShape.hh index 2d2a4672..f153a38f 100644 --- a/src/orbit/Apertures/ConvexApertureShape.hh +++ b/src/orbit/Apertures/ConvexApertureShape.hh @@ -1,13 +1,9 @@ #ifndef CONVEX_APERTURE_SHAPE_H #define CONVEX_APERTURE_SHAPE_H -//pyORBIT utils -#include "CppPyWrapper.hh" +#include "orbit/Bunch.hh" +#include "orbit/Apertures/BaseApertureShape.hh" -#include "Bunch.hh" -#include "BaseApertureShape.hh" - -using namespace std; /////////////////////////////////////////////////////////////////////////// // diff --git a/src/orbit/Apertures/EllipseApertureShape.cc b/src/orbit/Apertures/EllipseApertureShape.cc index a8ad1b98..5de82490 100644 --- a/src/orbit/Apertures/EllipseApertureShape.cc +++ b/src/orbit/Apertures/EllipseApertureShape.cc @@ -1,4 +1,4 @@ -#include "EllipseApertureShape.hh" +#include "orbit/Apertures/EllipseApertureShape.hh" #include #include diff --git a/src/orbit/Apertures/EllipseApertureShape.hh b/src/orbit/Apertures/EllipseApertureShape.hh index 981d0c66..a9709072 100644 --- a/src/orbit/Apertures/EllipseApertureShape.hh +++ b/src/orbit/Apertures/EllipseApertureShape.hh @@ -1,13 +1,9 @@ #ifndef ELLIPSE_APERTURE_SHAPE_H #define ELLIPSE_APERTURE_SHAPE_H -//pyORBIT utils -#include "CppPyWrapper.hh" +#include "orbit/Bunch.hh" +#include "orbit/Apertures/BaseApertureShape.hh" -#include "Bunch.hh" -#include "BaseApertureShape.hh" - -using namespace std; /////////////////////////////////////////////////////////////////////////// // diff --git a/src/orbit/Apertures/EnergyAperture.cc b/src/orbit/Apertures/EnergyAperture.cc index d28281d8..cba9f8fa 100644 --- a/src/orbit/Apertures/EnergyAperture.cc +++ b/src/orbit/Apertures/EnergyAperture.cc @@ -19,21 +19,21 @@ /////////////////////////////////////////////////////////////////////////// -#include "EnergyAperture.hh" -#include "SyncPart.hh" -#include "OrbitConst.hh" +#include "orbit/Apertures/EnergyAperture.hh" +#include "orbit/SyncPart.hh" +#include "orbit/OrbitConst.hh" #include #include #include #include -#include "ParticleAttributes.hh" +#include "orbit/ParticlesAttributes/ParticleAttributes.hh" /** The EnergyAperture class constructor. */ -EnergyAperture::EnergyAperture(): CppPyWrapper(NULL) +EnergyAperture::EnergyAperture() { minEnergy_ = -1.0e+36; maxEnergy_ = +1.0e+36; diff --git a/src/orbit/Apertures/EnergyAperture.hh b/src/orbit/Apertures/EnergyAperture.hh index fcc5d33e..1430843d 100644 --- a/src/orbit/Apertures/EnergyAperture.hh +++ b/src/orbit/Apertures/EnergyAperture.hh @@ -21,12 +21,10 @@ /////////////////////////////////////////////////////////////////////////// //pyORBIT utils -#include "CppPyWrapper.hh" -#include "Bunch.hh" +#include "orbit/Bunch.hh" -using namespace std; -class EnergyAperture: public OrbitUtils::CppPyWrapper +class EnergyAperture { public: diff --git a/src/orbit/Apertures/PhaseAperture.cc b/src/orbit/Apertures/PhaseAperture.cc index 9f87726d..f822eaa4 100644 --- a/src/orbit/Apertures/PhaseAperture.cc +++ b/src/orbit/Apertures/PhaseAperture.cc @@ -20,22 +20,22 @@ /////////////////////////////////////////////////////////////////////////// -#include "PhaseAperture.hh" -#include "SyncPart.hh" -#include "OrbitConst.hh" +#include "orbit/Apertures/PhaseAperture.hh" +#include "orbit/SyncPart.hh" +#include "orbit/OrbitConst.hh" #include #include #include #include -#include "ParticleAttributes.hh" +#include "orbit/ParticlesAttributes/ParticleAttributes.hh" /** The PhaseAperture class constructor. It needs the RF frequency in Hz to translate from z coordinate in meters to phase in degrees. */ -PhaseAperture::PhaseAperture(double frequency): CppPyWrapper(NULL) +PhaseAperture::PhaseAperture(double frequency) { frequency_ = frequency; minPhase_ = -1.0e+36; diff --git a/src/orbit/Apertures/PhaseAperture.hh b/src/orbit/Apertures/PhaseAperture.hh index a7471856..c02e8494 100644 --- a/src/orbit/Apertures/PhaseAperture.hh +++ b/src/orbit/Apertures/PhaseAperture.hh @@ -22,12 +22,10 @@ /////////////////////////////////////////////////////////////////////////// //pyORBIT utils -#include "CppPyWrapper.hh" -#include "Bunch.hh" +#include "orbit/Bunch.hh" -using namespace std; -class PhaseAperture: public OrbitUtils::CppPyWrapper +class PhaseAperture { public: diff --git a/src/orbit/Apertures/PyBaseApertureShape.cc b/src/orbit/Apertures/PyBaseApertureShape.cc index 876424dd..f935a4d9 100644 --- a/src/orbit/Apertures/PyBaseApertureShape.cc +++ b/src/orbit/Apertures/PyBaseApertureShape.cc @@ -1,4 +1,5 @@ -#include "PyBaseApertureShape.hh" +#include "orbit/Apertures/PyBaseApertureShape.hh" +#include "main/pyORBIT_Object.hh" #include #include @@ -22,8 +23,9 @@ /////////////////////////////////////////////////////////////////////////// /** PyBaseApertureShape constructor */ -PyBaseApertureShape::PyBaseApertureShape(): BaseApertureShape() +PyBaseApertureShape::PyBaseApertureShape(PyObject* py_wrapper): BaseApertureShape() { + this->py_wrapper = py_wrapper; shapeName = "python_class_shape"; typeName = "python_class_shape"; } @@ -38,12 +40,11 @@ int PyBaseApertureShape::inside(Bunch* bunch, int count){ double** coord = bunch->coordArr(); - PyObject* py_wrp = getPyWrapper(); - PyObject* py_bunch = bunch->getPyWrapper(); + PyObject* py_bunch = pyorbit::getPyWrapper(bunch); int res_isinside = 0; - PyObject* py_res = PyObject_CallMethod(py_wrp,const_cast("inside"),const_cast("Oi"),py_bunch,count); + PyObject* py_res = PyObject_CallMethod(py_wrapper,const_cast("inside"),const_cast("Oi"),py_bunch,count); res_isinside = (int) PyLong_AS_LONG(py_res); diff --git a/src/orbit/Apertures/PyBaseApertureShape.hh b/src/orbit/Apertures/PyBaseApertureShape.hh index 9fa6d06c..559f3ab2 100644 --- a/src/orbit/Apertures/PyBaseApertureShape.hh +++ b/src/orbit/Apertures/PyBaseApertureShape.hh @@ -1,13 +1,11 @@ #ifndef PY_BASE_APERTURE_SHAPE_H #define PY_BASE_APERTURE_SHAPE_H -//pyORBIT utils -#include "CppPyWrapper.hh" +#include -#include "Bunch.hh" -#include "BaseApertureShape.hh" +#include "orbit/Bunch.hh" +#include "orbit/Apertures/BaseApertureShape.hh" -using namespace std; /////////////////////////////////////////////////////////////////////////// // @@ -32,7 +30,7 @@ class PyBaseApertureShape: public BaseApertureShape public: /** PyBaseApertureShape constructor */ - PyBaseApertureShape(); + PyBaseApertureShape(PyObject* py_wrapper); /** PyBaseApertureShape decstructor */ virtual ~PyBaseApertureShape(); @@ -40,6 +38,9 @@ public: /** Return 1 if the particular macro-particle is inside this shape */ int inside(Bunch* bunch, int count); +private: + PyObject* py_wrapper; + }; //end of PY_BASE_APERTURE_SHAPE_H ifdef diff --git a/src/orbit/Apertures/RectangularApertureShape.cc b/src/orbit/Apertures/RectangularApertureShape.cc index 0518ee34..61253fa4 100644 --- a/src/orbit/Apertures/RectangularApertureShape.cc +++ b/src/orbit/Apertures/RectangularApertureShape.cc @@ -1,4 +1,4 @@ -#include "RectangularApertureShape.hh" +#include "orbit/Apertures/RectangularApertureShape.hh" #include #include diff --git a/src/orbit/Apertures/RectangularApertureShape.hh b/src/orbit/Apertures/RectangularApertureShape.hh index dd746658..43f57b75 100644 --- a/src/orbit/Apertures/RectangularApertureShape.hh +++ b/src/orbit/Apertures/RectangularApertureShape.hh @@ -1,13 +1,9 @@ #ifndef RECTANGULAR_APERTURE_SHAPE_H #define RECTANGULAR_APERTURE_SHAPE_H -//pyORBIT utils -#include "CppPyWrapper.hh" +#include "orbit/Bunch.hh" +#include "orbit/Apertures/BaseApertureShape.hh" -#include "Bunch.hh" -#include "BaseApertureShape.hh" - -using namespace std; /////////////////////////////////////////////////////////////////////////// // diff --git a/src/orbit/Apertures/wrap_BaseAperture.cc b/src/orbit/Apertures/wrap_BaseAperture.cc index 64ae2387..d16edd80 100644 --- a/src/orbit/Apertures/wrap_BaseAperture.cc +++ b/src/orbit/Apertures/wrap_BaseAperture.cc @@ -1,14 +1,19 @@ -#include "orbit_mpi.hh" -#include "pyORBIT_Object.hh" +#include "mpi/orbit_mpi.hh" +#include "main/pyORBIT_Object.hh" -#include "wrap_bunch.hh" +#include "orbit/wrap_bunch.hh" #include -#include "BaseAperture.hh" -#include "BaseApertureShape.hh" +#include "orbit/Apertures/BaseAperture.hh" +#include "orbit/Apertures/BaseApertureShape.hh" namespace wrap_base_aperture{ + typedef struct { + PyObject_HEAD + void* cpp_obj; + PyObject* shape; + } pyORBIT_BaseAperture; #ifdef __cplusplus extern "C" { @@ -19,26 +24,31 @@ extern "C" { It never will be called directly. */ static PyObject* BaseAperture_new(PyTypeObject *type, PyObject *args, PyObject *kwds){ - pyORBIT_Object* self; - self = (pyORBIT_Object *) type->tp_alloc(type, 0); + pyORBIT_BaseAperture* self; + self = (pyORBIT_BaseAperture *) type->tp_alloc(type, 0); self->cpp_obj = NULL; + self->shape = NULL; return (PyObject *) self; } /** This is implementation of the __init__ method */ - static int BaseAperture_init(pyORBIT_Object *self, PyObject *args, PyObject *kwds){ + static int BaseAperture_init(pyORBIT_BaseAperture *self, PyObject *args, PyObject *kwds){ self->cpp_obj = new BaseAperture(); - ((BaseAperture*) self->cpp_obj)->setPyWrapper((PyObject*) self); + pyorbit::registerPyWrapper(self->cpp_obj, (PyObject*) self); return 0; } /** Sets the pyBaseApertureShape object for inside(...) method */ static PyObject* BaseAperture_setApertureShape(PyObject *self, PyObject *args){ - BaseAperture* cpp_BaseAperture = (BaseAperture*)((pyORBIT_Object*) self)->cpp_obj; + pyORBIT_BaseAperture* aperture = (pyORBIT_BaseAperture*) self; + BaseAperture* cpp_BaseAperture = (BaseAperture*) aperture->cpp_obj; PyObject* pyBaseApertureShape; if(!PyArg_ParseTuple(args,"O:setApertureShape",&pyBaseApertureShape)){ ORBIT_MPI_Finalize("BaseAperture - setApertureShape(BaseApertureShape) - parameter is needed. Stop."); } + Py_INCREF(pyBaseApertureShape); + Py_XDECREF(aperture->shape); + aperture->shape = pyBaseApertureShape; cpp_BaseAperture->setApertureShape((BaseApertureShape*) ((pyORBIT_Object*) pyBaseApertureShape)->cpp_obj); Py_INCREF(Py_None); return Py_None; @@ -46,15 +56,13 @@ extern "C" { /** Returns the pyBaseApertureShape object for inside(...) method */ static PyObject* BaseAperture_getApertureShape(PyObject *self, PyObject *args){ - BaseAperture* cpp_BaseAperture = (BaseAperture*)((pyORBIT_Object*) self)->cpp_obj; - BaseApertureShape* baseApertureShape = cpp_BaseAperture->getApertureShape(); - if(baseApertureShape == NULL){ + pyORBIT_BaseAperture* aperture = (pyORBIT_BaseAperture*) self; + if(aperture->shape == NULL){ Py_INCREF(Py_None); return Py_None; } - PyObject* pyBaseApertureShape = baseApertureShape->getPyWrapper(); - Py_INCREF(pyBaseApertureShape); - return pyBaseApertureShape; + Py_INCREF(aperture->shape); + return aperture->shape; } /** Performs the collimation tracking of the bunch */ @@ -149,9 +157,11 @@ extern "C" { //----------------------------------------------------- //destructor for python BaseAperture class (__del__ method). //----------------------------------------------------- - static void BaseAperture_del(pyORBIT_Object* self){ + static void BaseAperture_del(pyORBIT_BaseAperture* self){ //std::cerr<<"The BaseAperture __del__ has been called!"<cpp_obj, (PyObject*) self); delete ((BaseAperture*)self->cpp_obj); + Py_CLEAR(self->shape); self->ob_base.ob_type->tp_free((PyObject*)self); } @@ -177,7 +187,7 @@ extern "C" { static PyTypeObject pyORBIT_BaseAperture_Type = { PyVarObject_HEAD_INIT(NULL, 0) "BaseAperture", /*tp_name*/ - sizeof(pyORBIT_Object), /*tp_basicsize*/ + sizeof(pyORBIT_BaseAperture), /*tp_basicsize*/ 0, /*tp_itemsize*/ (destructor) BaseAperture_del , /*tp_dealloc*/ 0, /*tp_print*/ diff --git a/src/orbit/Apertures/wrap_BaseAperture.hh b/src/orbit/Apertures/wrap_BaseAperture.hh index bd6d0c13..6df9220e 100644 --- a/src/orbit/Apertures/wrap_BaseAperture.hh +++ b/src/orbit/Apertures/wrap_BaseAperture.hh @@ -1,7 +1,7 @@ #ifndef WRAP_ORBIT_BASE_APERTURE_HH_ #define WRAP_ORBIT_BASE_APERTURE_HH_ -#include "Python.h" +#include #ifdef __cplusplus extern "C" { diff --git a/src/orbit/Apertures/wrap_CompositeApertureShape.cc b/src/orbit/Apertures/wrap_CompositeApertureShape.cc index 3bff3478..e19f370d 100644 --- a/src/orbit/Apertures/wrap_CompositeApertureShape.cc +++ b/src/orbit/Apertures/wrap_CompositeApertureShape.cc @@ -1,13 +1,18 @@ -#include "orbit_mpi.hh" -#include "pyORBIT_Object.hh" +#include "mpi/orbit_mpi.hh" +#include "main/pyORBIT_Object.hh" -#include "wrap_bunch.hh" +#include "orbit/wrap_bunch.hh" #include -#include "CompositeApertureShape.hh" +#include "orbit/Apertures/CompositeApertureShape.hh" namespace wrap_py_composite_aperture_shape{ + typedef struct { + PyObject_HEAD + void* cpp_obj; + PyObject* shapes; + } pyORBIT_CompositeApertureShape; #ifdef __cplusplus extern "C" { @@ -17,16 +22,23 @@ extern "C" { Constructor for python class wrapping c++ Circle, Ellipse, and Rectangular ApertureShape instances. */ static PyObject* CompositeApertureShape_new(PyTypeObject *type, PyObject *args, PyObject *kwds){ - pyORBIT_Object* self; - self = (pyORBIT_Object *) type->tp_alloc(type, 0); + pyORBIT_CompositeApertureShape* self; + self = (pyORBIT_CompositeApertureShape *) type->tp_alloc(type, 0); self->cpp_obj = NULL; + self->shapes = NULL; return (PyObject *) self; } /** This is implementation of the __init__ method */ - static int CompositeApertureShape_init(pyORBIT_Object *self, PyObject *args, PyObject *kwds){ + static int CompositeApertureShape_init(pyORBIT_CompositeApertureShape *self, PyObject *args, PyObject *kwds){ self->cpp_obj = (pyORBIT_Object*) new CompositeApertureShape(); - ((BaseApertureShape*) self->cpp_obj)->setPyWrapper((PyObject*) self); + self->shapes = PyList_New(0); + if(self->shapes == NULL) { + delete ((CompositeApertureShape*) self->cpp_obj); + self->cpp_obj = NULL; + return -1; + } + pyorbit::registerPyWrapper(self->cpp_obj, (PyObject*) self); return 0; } @@ -58,12 +70,13 @@ extern "C" { // addApertureShape() - adds the ApertureShape instance to composite static PyObject* CompositeApertureShape_addApertureShape(PyObject *self, PyObject *args){ - pyORBIT_Object* pyCompositeApertureShape= (pyORBIT_Object*) self; - CompositeApertureShape* cpp_CompositeApertureShape = (CompositeApertureShape*) pyCompositeApertureShape->cpp_obj; + pyORBIT_CompositeApertureShape* composite = (pyORBIT_CompositeApertureShape*) self; + CompositeApertureShape* cpp_CompositeApertureShape = (CompositeApertureShape*) composite->cpp_obj; PyObject* pyBaseApertureShape; if(!PyArg_ParseTuple(args,"O:setApertureShape",&pyBaseApertureShape)){ ORBIT_MPI_Finalize("CompositeApertureShape.addApertureShape(BaseApertureShape) - parameter is needed. Stop."); } + if(PyList_Append(composite->shapes, pyBaseApertureShape) < 0) return NULL; cpp_CompositeApertureShape->addApertureShape((BaseApertureShape*) ((pyORBIT_Object*) pyBaseApertureShape)->cpp_obj); Py_INCREF(Py_None); return Py_None; @@ -71,26 +84,18 @@ extern "C" { // getApertureShapes() - returns the ApertureShape instances inside the composite static PyObject* CompositeApertureShape_getApertureShapes(PyObject *self, PyObject *args){ - pyORBIT_Object* pyCompositeApertureShape= (pyORBIT_Object*) self; - CompositeApertureShape* cpp_CompositeApertureShape = (CompositeApertureShape*) pyCompositeApertureShape->cpp_obj; - std::vector apertureShapes = cpp_CompositeApertureShape->getApertureShape(); - //create tuple with apertureShapes - PyObject* resTuple = PyTuple_New(apertureShapes.size()); - for(int i = 0, n = apertureShapes.size(); i < n; i++){ - PyObject* py_nm = apertureShapes[i]->getPyWrapper(); - if(PyTuple_SetItem(resTuple,i,py_nm)){ - ORBIT_MPI_Finalize("CompositeApertureShape.getApertureShapes(...) - cannot add the ApertureShape instance to composite"); - } - } - return resTuple; + pyORBIT_CompositeApertureShape* composite = (pyORBIT_CompositeApertureShape*) self; + return PyList_AsTuple(composite->shapes); } //----------------------------------------------------- //destructor for python CompositeApertureShape class (__del__ method). //----------------------------------------------------- - static void CompositeApertureShape_del(pyORBIT_Object* self){ + static void CompositeApertureShape_del(pyORBIT_CompositeApertureShape* self){ //std::cerr<<"debug CompositeApertureShape __del__ has been called!"<cpp_obj, (PyObject*) self); delete ((BaseApertureShape*)self->cpp_obj); + Py_CLEAR(self->shapes); self->ob_base.ob_type->tp_free((PyObject*)self); } @@ -113,7 +118,7 @@ extern "C" { static PyTypeObject pyORBIT_CompositeApertureShape_Type = { PyVarObject_HEAD_INIT(NULL, 0) "CompositeApertureShape", /*tp_name*/ - sizeof(pyORBIT_Object), /*tp_basicsize*/ + sizeof(pyORBIT_CompositeApertureShape), /*tp_basicsize*/ 0, /*tp_itemsize*/ (destructor) CompositeApertureShape_del , /*tp_dealloc*/ 0, /*tp_print*/ diff --git a/src/orbit/Apertures/wrap_CompositeApertureShape.hh b/src/orbit/Apertures/wrap_CompositeApertureShape.hh index a2a4c165..63d46246 100644 --- a/src/orbit/Apertures/wrap_CompositeApertureShape.hh +++ b/src/orbit/Apertures/wrap_CompositeApertureShape.hh @@ -1,7 +1,7 @@ #ifndef WRAP_ORBIT_COMPOSITE_APERTURE_SHAPE_HH_ #define WRAP_ORBIT_COMPOSITE_APERTURE_SHAPE_HH_ -#include "Python.h" +#include #ifdef __cplusplus extern "C" { diff --git a/src/orbit/Apertures/wrap_ConvexApertureShape.cc b/src/orbit/Apertures/wrap_ConvexApertureShape.cc index f316fb30..184646be 100644 --- a/src/orbit/Apertures/wrap_ConvexApertureShape.cc +++ b/src/orbit/Apertures/wrap_ConvexApertureShape.cc @@ -1,11 +1,11 @@ -#include "orbit_mpi.hh" -#include "pyORBIT_Object.hh" +#include "mpi/orbit_mpi.hh" +#include "main/pyORBIT_Object.hh" -#include "wrap_bunch.hh" +#include "orbit/wrap_bunch.hh" #include -#include "ConvexApertureShape.hh" +#include "orbit/Apertures/ConvexApertureShape.hh" namespace wrap_convex_aperture_shape{ @@ -26,7 +26,7 @@ extern "C" { /** This is implementation of the __init__ method */ static int ConvexApertureShape_init(pyORBIT_Object *self, PyObject *args, PyObject *kwds){ self->cpp_obj = new ConvexApertureShape(); - ((BaseApertureShape*) self->cpp_obj)->setPyWrapper((PyObject*) self); + pyorbit::registerPyWrapper(self->cpp_obj, (PyObject*) self); return 0; } @@ -132,6 +132,7 @@ extern "C" { //destructor for python ConvexApertureShape class (__del__ method). //----------------------------------------------------- static void ConvexApertureShape_del(pyORBIT_Object* self){ + pyorbit::unregisterPyWrapper(self->cpp_obj, (PyObject*) self); delete ((ConvexApertureShape*) self->cpp_obj); self->ob_base.ob_type->tp_free((PyObject*)self); } diff --git a/src/orbit/Apertures/wrap_ConvexApertureShape.hh b/src/orbit/Apertures/wrap_ConvexApertureShape.hh index 92a67841..b4e9cfa9 100644 --- a/src/orbit/Apertures/wrap_ConvexApertureShape.hh +++ b/src/orbit/Apertures/wrap_ConvexApertureShape.hh @@ -1,7 +1,7 @@ #ifndef WRAP_ORBIT_CONVEX_APERTURE_SHAPE_HH_ #define WRAP_ORBIT_CONVEX_APERTURE_SHAPE_HH_ -#include "Python.h" +#include #ifdef __cplusplus extern "C" { diff --git a/src/orbit/Apertures/wrap_EnergyAperture.cc b/src/orbit/Apertures/wrap_EnergyAperture.cc index 238e388d..0a82f792 100644 --- a/src/orbit/Apertures/wrap_EnergyAperture.cc +++ b/src/orbit/Apertures/wrap_EnergyAperture.cc @@ -1,12 +1,12 @@ -#include "orbit_mpi.hh" -#include "pyORBIT_Object.hh" +#include "mpi/orbit_mpi.hh" +#include "main/pyORBIT_Object.hh" -#include "wrap_aperture.hh" -#include "wrap_bunch.hh" +#include "orbit/Apertures/wrap_aperture.hh" +#include "orbit/wrap_bunch.hh" #include -#include "EnergyAperture.hh" +#include "orbit/Apertures/EnergyAperture.hh" namespace wrap_energy_aperture{ @@ -28,7 +28,6 @@ extern "C" { /** This is implementation of the __init__ method */ static int EnergyAperture_init(pyORBIT_Object *self, PyObject *args, PyObject *kwds){ self->cpp_obj = new EnergyAperture(); - ((EnergyAperture*) self->cpp_obj)->setPyWrapper((PyObject*) self); return 0; } diff --git a/src/orbit/Apertures/wrap_EnergyAperture.hh b/src/orbit/Apertures/wrap_EnergyAperture.hh index b022d90e..acf0525d 100644 --- a/src/orbit/Apertures/wrap_EnergyAperture.hh +++ b/src/orbit/Apertures/wrap_EnergyAperture.hh @@ -1,7 +1,7 @@ #ifndef WRAP_ORBIT_ENERGY_APERTURE_HH_ #define WRAP_ORBIT_ENERGY_APERTURE_HH_ -#include "Python.h" +#include #ifdef __cplusplus extern "C" { diff --git a/src/orbit/Apertures/wrap_PhaseAperture.cc b/src/orbit/Apertures/wrap_PhaseAperture.cc index d6d03518..12c71366 100644 --- a/src/orbit/Apertures/wrap_PhaseAperture.cc +++ b/src/orbit/Apertures/wrap_PhaseAperture.cc @@ -1,12 +1,12 @@ -#include "orbit_mpi.hh" -#include "pyORBIT_Object.hh" +#include "mpi/orbit_mpi.hh" +#include "main/pyORBIT_Object.hh" -#include "wrap_aperture.hh" -#include "wrap_bunch.hh" +#include "orbit/Apertures/wrap_aperture.hh" +#include "orbit/wrap_bunch.hh" #include -#include "PhaseAperture.hh" +#include "orbit/Apertures/PhaseAperture.hh" namespace wrap_phase_aperture{ @@ -35,7 +35,6 @@ extern "C" { ORBIT_MPI_Finalize("PhaseAperture class constructor - cannot parse arguments! It should be (frequency)"); } self->cpp_obj = new PhaseAperture(frequency); - ((PhaseAperture*) self->cpp_obj)->setPyWrapper((PyObject*) self); return 0; } diff --git a/src/orbit/Apertures/wrap_PhaseAperture.hh b/src/orbit/Apertures/wrap_PhaseAperture.hh index 921b1e27..e438bb4f 100644 --- a/src/orbit/Apertures/wrap_PhaseAperture.hh +++ b/src/orbit/Apertures/wrap_PhaseAperture.hh @@ -1,7 +1,7 @@ #ifndef WRAP_ORBIT_PHASE_APERTURE_HH_ #define WRAP_ORBIT_PHASE_APERTURE_HH_ -#include "Python.h" +#include #ifdef __cplusplus extern "C" { diff --git a/src/orbit/Apertures/wrap_PrimitiveApertureShape.cc b/src/orbit/Apertures/wrap_PrimitiveApertureShape.cc index 84359118..941618c2 100644 --- a/src/orbit/Apertures/wrap_PrimitiveApertureShape.cc +++ b/src/orbit/Apertures/wrap_PrimitiveApertureShape.cc @@ -1,13 +1,13 @@ -#include "orbit_mpi.hh" -#include "pyORBIT_Object.hh" +#include "mpi/orbit_mpi.hh" +#include "main/pyORBIT_Object.hh" -#include "wrap_bunch.hh" +#include "orbit/wrap_bunch.hh" #include -#include "CircleApertureShape.hh" -#include "EllipseApertureShape.hh" -#include "RectangularApertureShape.hh" +#include "orbit/Apertures/CircleApertureShape.hh" +#include "orbit/Apertures/EllipseApertureShape.hh" +#include "orbit/Apertures/RectangularApertureShape.hh" namespace wrap_py_base_aperture_shape{ @@ -58,7 +58,7 @@ extern "C" { if(self->cpp_obj == NULL){ ORBIT_MPI_Finalize("PrimitiveApertureShape(shapeType, par1[,par2]) - shapeType should be circle,ellipse, or rectangular. Stop."); } - ((BaseApertureShape*) self->cpp_obj)->setPyWrapper((PyObject*) self); + pyorbit::registerPyWrapper(self->cpp_obj, (PyObject*) self); return 0; } @@ -198,6 +198,7 @@ extern "C" { //----------------------------------------------------- static void PrimitiveApertureShape_del(pyORBIT_Object* self){ //std::cerr<<"debug PrimitiveApertureShape __del__ has been called!"<cpp_obj, (PyObject*) self); delete ((BaseApertureShape*)self->cpp_obj); self->ob_base.ob_type->tp_free((PyObject*)self); } diff --git a/src/orbit/Apertures/wrap_PrimitiveApertureShape.hh b/src/orbit/Apertures/wrap_PrimitiveApertureShape.hh index 627dd19b..45fc9b77 100644 --- a/src/orbit/Apertures/wrap_PrimitiveApertureShape.hh +++ b/src/orbit/Apertures/wrap_PrimitiveApertureShape.hh @@ -1,7 +1,7 @@ #ifndef WRAP_ORBIT_PRIMITIVE_APERTURE_SHAPE_HH_ #define WRAP_ORBIT_PRIMITIVE_APERTURE_SHAPE_HH_ -#include "Python.h" +#include #ifdef __cplusplus extern "C" { diff --git a/src/orbit/Apertures/wrap_PyBaseApertureShape.cc b/src/orbit/Apertures/wrap_PyBaseApertureShape.cc index 1c51be6c..72246450 100644 --- a/src/orbit/Apertures/wrap_PyBaseApertureShape.cc +++ b/src/orbit/Apertures/wrap_PyBaseApertureShape.cc @@ -1,11 +1,11 @@ -#include "orbit_mpi.hh" -#include "pyORBIT_Object.hh" +#include "mpi/orbit_mpi.hh" +#include "main/pyORBIT_Object.hh" -#include "wrap_bunch.hh" +#include "orbit/wrap_bunch.hh" #include -#include "PyBaseApertureShape.hh" +#include "orbit/Apertures/PyBaseApertureShape.hh" namespace wrap_py_base_aperture_shape{ @@ -26,8 +26,8 @@ extern "C" { /** This is implementation of the __init__ method */ static int PyBaseApertureShape_init(pyORBIT_Object *self, PyObject *args, PyObject *kwds){ - self->cpp_obj = new PyBaseApertureShape(); - ((PyBaseApertureShape*) self->cpp_obj)->setPyWrapper((PyObject*) self); + self->cpp_obj = new PyBaseApertureShape((PyObject*) self); + pyorbit::registerPyWrapper(self->cpp_obj, (PyObject*) self); return 0; } @@ -100,6 +100,7 @@ extern "C" { //----------------------------------------------------- static void PyBaseApertureShape_del(pyORBIT_Object* self){ //std::cerr<<"debug PyBaseApertureShape __del__ has been called!"<cpp_obj, (PyObject*) self); delete ((PyBaseApertureShape*)self->cpp_obj); self->ob_base.ob_type->tp_free((PyObject*)self); } diff --git a/src/orbit/Apertures/wrap_PyBaseApertureShape.hh b/src/orbit/Apertures/wrap_PyBaseApertureShape.hh index 41299cc5..46527930 100644 --- a/src/orbit/Apertures/wrap_PyBaseApertureShape.hh +++ b/src/orbit/Apertures/wrap_PyBaseApertureShape.hh @@ -1,7 +1,7 @@ #ifndef WRAP_ORBIT_PY_BASE_APERTURE_SHAPE_HH_ #define WRAP_ORBIT_PY_BASE_APERTURE_SHAPE_HH_ -#include "Python.h" +#include #ifdef __cplusplus extern "C" { diff --git a/src/orbit/Apertures/wrap_TAperture.cc b/src/orbit/Apertures/wrap_TAperture.cc index 4017b25d..bd02719f 100644 --- a/src/orbit/Apertures/wrap_TAperture.cc +++ b/src/orbit/Apertures/wrap_TAperture.cc @@ -1,12 +1,12 @@ -#include "orbit_mpi.hh" -#include "pyORBIT_Object.hh" +#include "mpi/orbit_mpi.hh" +#include "main/pyORBIT_Object.hh" -#include "wrap_aperture.hh" -#include "wrap_bunch.hh" +#include "orbit/Apertures/wrap_aperture.hh" +#include "orbit/wrap_bunch.hh" #include -#include "Aperture.hh" +#include "orbit/Apertures/Aperture.hh" namespace wrap_aperture{ @@ -40,7 +40,6 @@ extern "C" { ORBIT_MPI_Finalize("Aperture class constructor - cannot parse arguments! It should be (shape,a,b,c,d,pos)"); } self->cpp_obj = new Aperture(shape,a,b,c,d,pos); - ((Aperture*) self->cpp_obj)->setPyWrapper((PyObject*) self); return 0; } diff --git a/src/orbit/Apertures/wrap_TAperture.hh b/src/orbit/Apertures/wrap_TAperture.hh index 4d49cf5e..b028e599 100644 --- a/src/orbit/Apertures/wrap_TAperture.hh +++ b/src/orbit/Apertures/wrap_TAperture.hh @@ -1,7 +1,7 @@ #ifndef WRAP_ORBIT_APERTURE_HH_ #define WRAP_ORBIT_APERTURE_HH_ -#include "Python.h" +#include #ifdef __cplusplus extern "C" { diff --git a/src/orbit/Apertures/wrap_aperture.cc b/src/orbit/Apertures/wrap_aperture.cc index da663cd9..33375937 100644 --- a/src/orbit/Apertures/wrap_aperture.cc +++ b/src/orbit/Apertures/wrap_aperture.cc @@ -1,18 +1,18 @@ -#include "orbit_mpi.hh" -#include "pyORBIT_Object.hh" +#include "mpi/orbit_mpi.hh" +#include "main/pyORBIT_Object.hh" -#include "wrap_aperture.hh" +#include "orbit/Apertures/wrap_aperture.hh" -#include "wrap_TAperture.hh" -#include "wrap_PhaseAperture.hh" -#include "wrap_EnergyAperture.hh" -#include "wrap_BaseAperture.hh" -#include "wrap_PyBaseApertureShape.hh" -#include "wrap_PrimitiveApertureShape.hh" -#include "wrap_CompositeApertureShape.hh" -#include "wrap_ConvexApertureShape.hh" +#include "orbit/Apertures/wrap_TAperture.hh" +#include "orbit/Apertures/wrap_PhaseAperture.hh" +#include "orbit/Apertures/wrap_EnergyAperture.hh" +#include "orbit/Apertures/wrap_BaseAperture.hh" +#include "orbit/Apertures/wrap_PyBaseApertureShape.hh" +#include "orbit/Apertures/wrap_PrimitiveApertureShape.hh" +#include "orbit/Apertures/wrap_CompositeApertureShape.hh" +#include "orbit/Apertures/wrap_ConvexApertureShape.hh" -#include "wrap_bunch.hh" +#include "orbit/wrap_bunch.hh" #include diff --git a/src/orbit/Apertures/wrap_aperture.hh b/src/orbit/Apertures/wrap_aperture.hh index 6de0fef3..81609f59 100644 --- a/src/orbit/Apertures/wrap_aperture.hh +++ b/src/orbit/Apertures/wrap_aperture.hh @@ -1,7 +1,7 @@ #ifndef WRAP_ORBIT_APERTURE_MODULE_HH_ #define WRAP_ORBIT_APERTURE_MODULE_HH_ -#include "Python.h" +#include #ifdef __cplusplus extern "C" { diff --git a/src/orbit/Bunch.cc b/src/orbit/Bunch.cc index 8a2a2714..5ba616f0 100644 --- a/src/orbit/Bunch.cc +++ b/src/orbit/Bunch.cc @@ -14,13 +14,15 @@ // /////////////////////////////////////////////////////////////////////////// -#include "Bunch.hh" +#include "orbit/Bunch.hh" -#include "ParticleAttributesFactory.hh" -#include "OrbitConst.hh" -#include "StringUtils.hh" -#include "BufferStore.hh" +#include "orbit/ParticlesAttributes/ParticleAttributesFactory.hh" +#include "orbit/OrbitConst.hh" +#include "utils/StringUtils.hh" +#include "utils/BufferStore.hh" +#include +#include #include #include @@ -32,7 +34,7 @@ using namespace OrbitUtils; changed, and dumped to a file. */ -Bunch::Bunch(): CppPyWrapper(NULL) +Bunch::Bunch() { //initialization all necessary variables and attributes @@ -56,15 +58,15 @@ Bunch::Bunch(): CppPyWrapper(NULL) } //for MPI - pyComm_Local = wrap_orbit_mpi_comm::newMPI_Comm(); + comm_ = MPI_COMM_WORLD; rank_MPI = 0; size_MPI = 1; iMPIini = 0; ORBIT_MPI_Initialized(&iMPIini); if(iMPIini > 0){ - ORBIT_MPI_Comm_size(pyComm_Local->comm, &size_MPI); - ORBIT_MPI_Comm_rank(pyComm_Local->comm, &rank_MPI); + ORBIT_MPI_Comm_size(comm_, &size_MPI); + ORBIT_MPI_Comm_rank(comm_, &rank_MPI); } //data members related to the ParticleAttributes @@ -103,8 +105,7 @@ Bunch::~Bunch() //delete synchronous particle instance delete syncPart; - //delete the python instance of the mpi communicator - wrap_orbit_mpi_comm::freeMPI_Comm(this->pyComm_Local); + //MPI communicator is handled by the caller; no cleanup needed } AttributesBucket* Bunch::getBunchAttributes(){ @@ -196,7 +197,7 @@ void Bunch::initBunchAttributes(const char* fileName){ std::vector attr_names; attr_names.clear(); - ifstream is; + std::ifstream is; int error_ind = 0; if(rank_MPI == 0){ @@ -209,7 +210,7 @@ void Bunch::initBunchAttributes(const char* fileName){ } if(size_MPI > 1){ - ORBIT_MPI_Bcast (&error_ind,1, MPI_INT, 0, pyComm_Local->comm ); + ORBIT_MPI_Bcast (&error_ind,1, MPI_INT, 0, comm_ ); } if(error_ind > 0){ @@ -249,18 +250,18 @@ void Bunch::initBunchAttributes(const char* fileName){ if(size_MPI > 1){ - ORBIT_MPI_Bcast (&stop_ind,1, MPI_INT, 0, pyComm_Local->comm ); - ORBIT_MPI_Bcast (&def_found_ind,1, MPI_INT, 0, pyComm_Local->comm ); + ORBIT_MPI_Bcast (&stop_ind,1, MPI_INT, 0, comm_ ); + ORBIT_MPI_Bcast (&def_found_ind,1, MPI_INT, 0, comm_ ); } if(stop_ind == 0 && def_found_ind == 1){ if(size_MPI > 1){ int strLength = strlen(str.c_str()); - ORBIT_MPI_Bcast ( &strLength,1, MPI_INT, 0, pyComm_Local->comm ); + ORBIT_MPI_Bcast ( &strLength,1, MPI_INT, 0, comm_ ); int buff_index = 0; char* char_tmp = BufferStore::getBufferStore()->getFreeCharArr(buff_index,strLength+1); strcpy(char_tmp, str.c_str()); - ORBIT_MPI_Bcast ( char_tmp, strLength+1, MPI_CHAR, 0, pyComm_Local->comm ); + ORBIT_MPI_Bcast ( char_tmp, strLength+1, MPI_CHAR, 0, comm_ ); std::string str_new(char_tmp); BufferStore::getBufferStore()->setUnusedCharArr(buff_index); StringUtils::Tokenize(str_new,v_str); @@ -560,7 +561,7 @@ void Bunch::resize() std::map::iterator pos; for (pos = attrCntrMap.begin(); pos != attrCntrMap.end(); ++pos) { - string name = pos->first; + std::string name = pos->first; ParticleAttributes* attrCntrl = pos->second; for(int i = nOldTotalSize; i < nTotalSize; i++){ attrCntrl->init(i); @@ -856,7 +857,7 @@ int Bunch::getSizeGlobal() } else{ ORBIT_MPI_Allreduce(&nSize,&sizeGlobal,1, - MPI_INT,MPI_SUM,pyComm_Local->comm); + MPI_INT,MPI_SUM,comm_); return sizeGlobal; } } @@ -985,7 +986,7 @@ void Bunch::print(std::ostream& Out) if(i==rank_MPI){nSizeArr[i]=nSize;} } ORBIT_MPI_Allreduce(nSizeArr,nSizeArr_MPI,size_MPI, - MPI_INT,MPI_SUM,pyComm_Local->comm); + MPI_INT,MPI_SUM,comm_); //at this point all CPUs know about number of macro-particles on each CPU @@ -1023,11 +1024,11 @@ void Bunch::print(std::ostream& Out) j_count++; } ORBIT_MPI_Send(dump_arr, (nDimAndAttr)*nSizeChank, MPI_DOUBLE, 0, - 1111, pyComm_Local->comm); + 1111, comm_); } if(rank_MPI == 0){ ORBIT_MPI_Recv(dump_arr, (nDimAndAttr)*nSizeChank, MPI_DOUBLE, i, - 1111, pyComm_Local->comm, &statusMPI); + 1111, comm_, &statusMPI); for( int j = 0; j < (j_stop - j_start); j++){ int flg = (int) dump_arr[(nDimAndAttr)*j + 6]; if(flg > 0){ @@ -1075,10 +1076,10 @@ void Bunch::print(std::ostream& Out) void Bunch::print(const char* fileName) { - ofstream F_dump; + std::ofstream F_dump; if(rank_MPI == 0){ - F_dump.open (fileName, ios::out); + F_dump.open (fileName, std::ios::out); } print(F_dump); @@ -1110,7 +1111,7 @@ int Bunch::readBunchCoords(const char* fileName, int nParts) { double x,y,z, px,py,pz; - ifstream is; + std::ifstream is; int error_ind = 0; @@ -1124,7 +1125,7 @@ int Bunch::readBunchCoords(const char* fileName, int nParts) } if(size_MPI > 1){ - ORBIT_MPI_Bcast (&error_ind,1, MPI_INT, 0, pyComm_Local->comm ); + ORBIT_MPI_Bcast (&error_ind,1, MPI_INT, 0, comm_ ); } if(error_ind > 0){ @@ -1196,10 +1197,10 @@ int Bunch::readBunchCoords(const char* fileName, int nParts) } if(size_MPI > 1){ - ORBIT_MPI_Bcast ( &nT, 1, MPI_INT, 0, pyComm_Local->comm ); - ORBIT_MPI_Bcast ( &error_ind, 1, MPI_INT, 0, pyComm_Local->comm ); - ORBIT_MPI_Bcast ( &nn, 1, MPI_INT, 0, pyComm_Local->comm ); - ORBIT_MPI_Bcast ( arr_0, chunk_size*(nDimAndAttr) , MPI_DOUBLE, 0, pyComm_Local->comm ); + ORBIT_MPI_Bcast ( &nT, 1, MPI_INT, 0, comm_ ); + ORBIT_MPI_Bcast ( &error_ind, 1, MPI_INT, 0, comm_ ); + ORBIT_MPI_Bcast ( &nn, 1, MPI_INT, 0, comm_ ); + ORBIT_MPI_Bcast ( arr_0, chunk_size*(nDimAndAttr) , MPI_DOUBLE, 0, comm_ ); } if(error_ind > 0){ @@ -1229,7 +1230,7 @@ int Bunch::readBunchCoords(const char* fileName, int nParts) } if(size_MPI > 1){ - ORBIT_MPI_Bcast ( &info_stop, 1, MPI_INT, 0, pyComm_Local->comm ); + ORBIT_MPI_Bcast ( &info_stop, 1, MPI_INT, 0, comm_ ); } } @@ -1303,7 +1304,7 @@ int Bunch::readParticleAttributesNames(const char* fileName, attr_names.clear(); - ifstream is; + std::ifstream is; int error_ind = 0; @@ -1317,7 +1318,7 @@ int Bunch::readParticleAttributesNames(const char* fileName, } if(size_MPI > 1){ - ORBIT_MPI_Bcast (&error_ind,1, MPI_INT, 0, pyComm_Local->comm ); + ORBIT_MPI_Bcast (&error_ind,1, MPI_INT, 0, comm_ ); } if(error_ind > 0){ @@ -1370,8 +1371,8 @@ int Bunch::readParticleAttributesNames(const char* fileName, if(strLength < ln_str) { strLength = ln_str;} } - ORBIT_MPI_Bcast ( &nTypes, 1, MPI_INT, 0, pyComm_Local->comm ); - ORBIT_MPI_Bcast ( &strLength,1, MPI_INT, 0, pyComm_Local->comm ); + ORBIT_MPI_Bcast ( &nTypes, 1, MPI_INT, 0, comm_ ); + ORBIT_MPI_Bcast ( &strLength,1, MPI_INT, 0, comm_ ); if(nTypes == 0) return 0; @@ -1380,8 +1381,8 @@ int Bunch::readParticleAttributesNames(const char* fileName, strcpy(char_tmp, str.c_str()); int ln_str = strlen(str.c_str()); - ORBIT_MPI_Bcast ( &ln_str, 1, MPI_INT, 0, pyComm_Local->comm ); - ORBIT_MPI_Bcast ( char_tmp,ln_str +1, MPI_CHAR, 0, pyComm_Local->comm ); + ORBIT_MPI_Bcast ( &ln_str, 1, MPI_INT, 0, comm_ ); + ORBIT_MPI_Bcast ( char_tmp,ln_str +1, MPI_CHAR, 0, comm_ ); std::string str_new(char_tmp); StringUtils::Tokenize(str_new,v_str); @@ -1393,7 +1394,7 @@ int Bunch::readParticleAttributesNames(const char* fileName, //spreading all attr. dictionaries across all CPUs int nDicts = v_str_part_attr.size(); - ORBIT_MPI_Bcast ( &nDicts, 1, MPI_INT, 0, pyComm_Local->comm ); + ORBIT_MPI_Bcast ( &nDicts, 1, MPI_INT, 0, comm_ ); if(rank_MPI != 0){ v_str_part_attr.clear(); } @@ -1403,8 +1404,8 @@ int Bunch::readParticleAttributesNames(const char* fileName, ln_str = strlen(v_str_part_attr[i].c_str()); strcpy(char_tmp, v_str_part_attr[i].c_str()); } - ORBIT_MPI_Bcast ( &ln_str, 1, MPI_INT, 0, pyComm_Local->comm ); - ORBIT_MPI_Bcast ( char_tmp,ln_str +1, MPI_CHAR, 0, pyComm_Local->comm ); + ORBIT_MPI_Bcast ( &ln_str, 1, MPI_INT, 0, comm_ ); + ORBIT_MPI_Bcast ( char_tmp,ln_str +1, MPI_CHAR, 0, comm_ ); std::string str_tmp(char_tmp); if(rank_MPI != 0){ v_str_part_attr.push_back(str_tmp); @@ -1416,7 +1417,7 @@ int Bunch::readParticleAttributesNames(const char* fileName, for(int i = 0; i < nDicts; i++){ int nT = StringUtils::Tokenize(v_str_part_attr[i],v_str_dict); int dict_size = (v_str_dict.size() - 3)/2; - map attr_dict; + std::map attr_dict; for(int k = 0; k < dict_size; k++){ int val = 0; sscanf(v_str_dict[2*k+3+1].c_str(),"%df",&val); @@ -1604,7 +1605,7 @@ ParticleAttributes* Bunch::removeParticleAttributesWithoutDelete(const std::stri std::map::iterator pos; for (pos = attrCntrLowIndMap.begin(); pos != attrCntrLowIndMap.end(); ++pos) { - string name = pos->first; + std::string name = pos->first; int ind = pos->second; if(ind >= lowInd) { attrCntrLowIndMap[name] = attrCntrLowIndMap[name] - attr_length; @@ -1675,17 +1676,17 @@ void Bunch::restoreAllParticleAttributesFromMemory(){ attrCntrMapTemp.clear(); } -pyORBIT_MPI_Comm* Bunch::getMPI_Comm_Local(){ - return pyComm_Local; +MPI_Comm Bunch::getMPI_Comm_Local() const noexcept { + return comm_; } -void Bunch::setMPI_Comm_Local(pyORBIT_MPI_Comm* pyComm_Local){ - wrap_orbit_mpi_comm::freeMPI_Comm(this->pyComm_Local); - this->pyComm_Local = pyComm_Local; - Py_INCREF((PyObject *) this->pyComm_Local); - if(iMPIini > 0){ - ORBIT_MPI_Comm_size(pyComm_Local->comm, &size_MPI); - ORBIT_MPI_Comm_rank(pyComm_Local->comm, &rank_MPI); +void Bunch::setMPI_Comm_Local(MPI_Comm comm){ + comm_ = comm; + rank_MPI = 0; + size_MPI = 1; + if(iMPIini > 0 && comm_ != MPI_COMM_NULL) { + ORBIT_MPI_Comm_size(comm_, &size_MPI); + ORBIT_MPI_Comm_rank(comm_, &rank_MPI); } } diff --git a/src/orbit/Bunch.hh b/src/orbit/Bunch.hh index 9f525b86..1690daec 100644 --- a/src/orbit/Bunch.hh +++ b/src/orbit/Bunch.hh @@ -20,27 +20,20 @@ // INCLUDE FILES // /////////////////////////////////////////////////////////////////////////// -#include "orbit_mpi.hh" -#include "wrap_mpi_comm.hh" +#include "mpi/orbit_mpi.hh" #include -#include #include -#include #include -#include #include #include -#include "ParticleAttributes.hh" -#include "SyncPart.hh" +#include "orbit/ParticlesAttributes/ParticleAttributes.hh" +#include "orbit/SyncPart.hh" //from utils -#include "AttributesBucket.hh" -#include "CppPyWrapper.hh" - -using namespace std; +#include "utils/AttributesBucket.hh" #ifndef BUNCH_H #define BUNCH_H @@ -51,7 +44,7 @@ using namespace std; // /////////////////////////////////////////////////////////////////////////// -class Bunch: public OrbitUtils::CppPyWrapper +class Bunch { public: //-------------------------------------- @@ -191,8 +184,8 @@ public: void addParticlesTo(Bunch* bunch); //Parallel case - pyORBIT_MPI_Comm* getMPI_Comm_Local(); - void setMPI_Comm_Local(pyORBIT_MPI_Comm* pyComm_Local); + MPI_Comm getMPI_Comm_Local() const noexcept; + void setMPI_Comm_Local(MPI_Comm comm); int getMPI_Size(); int getMPI_Rank(); @@ -285,10 +278,7 @@ protected: int rank_MPI; int size_MPI; - pyORBIT_MPI_Comm* pyComm_Local; - - //reference to the python wrapping class instance - PyObject* py_wrapper; + MPI_Comm comm_; }; diff --git a/src/orbit/BunchDiagnostics/BunchTuneAnalysis.cc b/src/orbit/BunchDiagnostics/BunchTuneAnalysis.cc index 659b58a6..592a41d9 100644 --- a/src/orbit/BunchDiagnostics/BunchTuneAnalysis.cc +++ b/src/orbit/BunchDiagnostics/BunchTuneAnalysis.cc @@ -1,6 +1,6 @@ -#include "BunchTuneAnalysis.hh" -#include "SyncPart.hh" -#include "OrbitConst.hh" +#include "orbit/BunchDiagnostics/BunchTuneAnalysis.hh" +#include "orbit/SyncPart.hh" +#include "orbit/OrbitConst.hh" #include #include @@ -8,7 +8,7 @@ #include -BunchTuneAnalysis::BunchTuneAnalysis(): CppPyWrapper(NULL) { +BunchTuneAnalysis::BunchTuneAnalysis() { double matrix[6][6] = { {1.0, 0.0, 0.0, 0.0, 0.0, 0.0}, {0.0, 1.0, 0.0, 0.0, 0.0, 0.0}, @@ -77,7 +77,7 @@ void BunchTuneAnalysis::analyzeBunch(Bunch* bunch){ double** part_coord_arr = bunch->coordArr(); if(!bunch->hasParticleAttributes("ParticlePhaseAttributes")){ - cerr<<"BunchTuneAnalysis: Adding particle phase information attribute.\n"; + std::cerr<<"BunchTuneAnalysis: Adding particle phase information attribute.\n"; std::map tunemap; tunemap.insert(std::make_pair("phase_1", 0)); tunemap.insert(std::make_pair("phase_2", 0)); @@ -89,7 +89,7 @@ void BunchTuneAnalysis::analyzeBunch(Bunch* bunch){ } if (bunch->hasParticleAttributes("ParticlePhaseAttributes") && erase == 1) { - cerr<<"BunchTuneAnalysis: Normalization matrix has been updated. Setting particle phases to zero. Tunes will be accurate after the next `analyzeBunch` call.\n"; + std::cerr<<"BunchTuneAnalysis: Normalization matrix has been updated. Setting particle phases to zero. Tunes will be accurate after the next `analyzeBunch` call.\n"; for (int i=0; i < bunch->getSize(); i++) { bunch->getParticleAttributes("ParticlePhaseAttributes")->attValue(i, 0) = 0.0; bunch->getParticleAttributes("ParticlePhaseAttributes")->attValue(i, 1) = 0.0; @@ -158,4 +158,4 @@ void BunchTuneAnalysis::analyzeBunch(Bunch* bunch){ erase = 0; } -} \ No newline at end of file +} diff --git a/src/orbit/BunchDiagnostics/BunchTuneAnalysis.hh b/src/orbit/BunchDiagnostics/BunchTuneAnalysis.hh index 84b137b0..923fe9fa 100644 --- a/src/orbit/BunchDiagnostics/BunchTuneAnalysis.hh +++ b/src/orbit/BunchDiagnostics/BunchTuneAnalysis.hh @@ -1,16 +1,15 @@ #ifndef BUNCH_TUNE_ANALYSIS_H #define BUNCH_TUNE_ANALYSIS_H -#include "CppPyWrapper.hh" +//pyORBIT utils -#include "Bunch.hh" -#include "BunchTwissAnalysis.hh" +#include "orbit/Bunch.hh" +#include "orbit/BunchDiagnostics/BunchTwissAnalysis.hh" -using namespace std; /** Estimates particle tunes using average phase advance (APA) over one turn. */ -class BunchTuneAnalysis: public OrbitUtils::CppPyWrapper +class BunchTuneAnalysis { public: /** Constructor*/ diff --git a/src/orbit/BunchDiagnostics/BunchTwissAnalysis.cc b/src/orbit/BunchDiagnostics/BunchTwissAnalysis.cc index 0a361326..e5afc1b2 100644 --- a/src/orbit/BunchDiagnostics/BunchTwissAnalysis.cc +++ b/src/orbit/BunchDiagnostics/BunchTwissAnalysis.cc @@ -1,15 +1,15 @@ -#include "BunchTwissAnalysis.hh" +#include "orbit/BunchDiagnostics/BunchTwissAnalysis.hh" #include #include #include #include -#include "ParticleMacroSize.hh" -#include "SyncPart.hh" +#include "orbit/ParticlesAttributes/ParticleMacroSize.hh" +#include "orbit/SyncPart.hh" /** Constructor */ -BunchTwissAnalysis::BunchTwissAnalysis(): CppPyWrapper(NULL) +BunchTwissAnalysis::BunchTwissAnalysis() { avg_arr = (double* ) malloc (6*sizeof(double)); @@ -108,15 +108,15 @@ void BunchTwissAnalysis::analyzeBunch(Bunch* bunch){ } int count_MPI = 0; - ORBIT_MPI_Allreduce(&count,&count_MPI,1,MPI_INT,MPI_SUM,bunch->getMPI_Comm_Local()->comm); + ORBIT_MPI_Allreduce(&count,&count_MPI,1,MPI_INT,MPI_SUM,bunch->getMPI_Comm_Local()); count = count_MPI; double total_macrosize_MPI = 0.; - ORBIT_MPI_Allreduce(&total_macrosize,&total_macrosize_MPI,1,MPI_DOUBLE,MPI_SUM,bunch->getMPI_Comm_Local()->comm); + ORBIT_MPI_Allreduce(&total_macrosize,&total_macrosize_MPI,1,MPI_DOUBLE,MPI_SUM,bunch->getMPI_Comm_Local()); total_macrosize = total_macrosize_MPI; - ORBIT_MPI_Allreduce(avg_arr,avg_arr_MPI,6,MPI_DOUBLE,MPI_SUM,bunch->getMPI_Comm_Local()->comm); - ORBIT_MPI_Allreduce(corr_arr,corr_arr_MPI,36,MPI_DOUBLE,MPI_SUM,bunch->getMPI_Comm_Local()->comm); + ORBIT_MPI_Allreduce(avg_arr,avg_arr_MPI,6,MPI_DOUBLE,MPI_SUM,bunch->getMPI_Comm_Local()); + ORBIT_MPI_Allreduce(corr_arr,corr_arr_MPI,36,MPI_DOUBLE,MPI_SUM,bunch->getMPI_Comm_Local()); if(fabs(total_macrosize) > 0.){ for(int i = 0; i < 6; i++){ @@ -189,11 +189,11 @@ void BunchTwissAnalysis::computeBunchMoments(Bunch* bunch, int order, int disper } - ORBIT_MPI_Allreduce(&total_macrosize,&total_macrosize_MPI,1,MPI_DOUBLE,MPI_SUM,bunch->getMPI_Comm_Local()->comm); + ORBIT_MPI_Allreduce(&total_macrosize,&total_macrosize_MPI,1,MPI_DOUBLE,MPI_SUM,bunch->getMPI_Comm_Local()); total_macrosize = total_macrosize_MPI; double xAvg_MPI = 0; - ORBIT_MPI_Allreduce(&xAvg,&xAvg_MPI,1,MPI_DOUBLE,MPI_SUM,bunch->getMPI_Comm_Local()->comm); + ORBIT_MPI_Allreduce(&xAvg,&xAvg_MPI,1,MPI_DOUBLE,MPI_SUM,bunch->getMPI_Comm_Local()); if(fabs(total_macrosize) > 0.){ xAvg = xAvg_MPI/total_macrosize; } @@ -294,7 +294,7 @@ void BunchTwissAnalysis::computeBunchMoments(Bunch* bunch, int order, int disper } - ORBIT_MPI_Allreduce(&total_macrosize,&total_macrosize_MPI,1,MPI_DOUBLE,MPI_SUM,bunch->getMPI_Comm_Local()->comm); + ORBIT_MPI_Allreduce(&total_macrosize,&total_macrosize_MPI,1,MPI_DOUBLE,MPI_SUM,bunch->getMPI_Comm_Local()); total_macrosize = total_macrosize_MPI; //if( nMPIsize_ > 1){ @@ -310,7 +310,7 @@ void BunchTwissAnalysis::computeBunchMoments(Bunch* bunch, int order, int disper //MPI_Allreduce(buff_0, buff_1, count, MPI_DOUBLE,MPI_SUM,MPI_COMM_WORLD); - ORBIT_MPI_Allreduce(buff_0, buff_1, count, MPI_DOUBLE, MPI_SUM, bunch->getMPI_Comm_Local()->comm); + ORBIT_MPI_Allreduce(buff_0, buff_1, count, MPI_DOUBLE, MPI_SUM, bunch->getMPI_Comm_Local()); count = 0; for(j=0; j<_order+1; j++){ diff --git a/src/orbit/BunchDiagnostics/BunchTwissAnalysis.hh b/src/orbit/BunchDiagnostics/BunchTwissAnalysis.hh index deaa20ee..de741e78 100644 --- a/src/orbit/BunchDiagnostics/BunchTwissAnalysis.hh +++ b/src/orbit/BunchDiagnostics/BunchTwissAnalysis.hh @@ -2,18 +2,16 @@ #define BUNCH_TWISS_ANALYSIS_H //pyORBIT utils -#include "CppPyWrapper.hh" -#include "Bunch.hh" +#include "orbit/Bunch.hh" -using namespace std; /** The BunchTwissAnalysis class calculates the average of 6D coordinates and they correlations. As results it returns the Twiss parameters for each plane. */ -class BunchTwissAnalysis: public OrbitUtils::CppPyWrapper +class BunchTwissAnalysis { public: diff --git a/src/orbit/BunchDiagnostics/wrap_bunch_tune_analysis.cc b/src/orbit/BunchDiagnostics/wrap_bunch_tune_analysis.cc index 3adeff0a..6fd6abfc 100644 --- a/src/orbit/BunchDiagnostics/wrap_bunch_tune_analysis.cc +++ b/src/orbit/BunchDiagnostics/wrap_bunch_tune_analysis.cc @@ -1,12 +1,12 @@ -#include "orbit_mpi.hh" -#include "pyORBIT_Object.hh" +#include "mpi/orbit_mpi.hh" +#include "main/pyORBIT_Object.hh" -#include "wrap_bunch_tune_analysis.hh" -#include "wrap_bunch.hh" +#include "orbit/BunchDiagnostics/wrap_bunch_tune_analysis.hh" +#include "orbit/wrap_bunch.hh" #include -#include "BunchTuneAnalysis.hh" +#include "orbit/BunchDiagnostics/BunchTuneAnalysis.hh" namespace wrap_bunch_tune_analysis{ @@ -31,7 +31,6 @@ static PyObject* BunchTuneAnalysis_new(PyTypeObject *type, PyObject *args, PyObj /** Implementation of the __init__ method */ static int BunchTuneAnalysis_init(pyORBIT_Object *self, PyObject *args, PyObject *kwds){ self->cpp_obj = new BunchTuneAnalysis(); - ((BunchTuneAnalysis*) self->cpp_obj)->setPyWrapper((PyObject*) self); return 0; } diff --git a/src/orbit/BunchDiagnostics/wrap_bunch_tune_analysis.hh b/src/orbit/BunchDiagnostics/wrap_bunch_tune_analysis.hh index 6511745e..460c5504 100644 --- a/src/orbit/BunchDiagnostics/wrap_bunch_tune_analysis.hh +++ b/src/orbit/BunchDiagnostics/wrap_bunch_tune_analysis.hh @@ -1,7 +1,7 @@ #ifndef WRAP_BUNCH_TUNE_ANALYSIS_HH_ #define WRAP_BUNCH_TUNE_ANALYSIS_HH_ -#include "Python.h" +#include #ifdef __cplusplus extern "C" { diff --git a/src/orbit/BunchDiagnostics/wrap_bunch_twiss_analysis.cc b/src/orbit/BunchDiagnostics/wrap_bunch_twiss_analysis.cc index ca3efe39..c9a980ec 100644 --- a/src/orbit/BunchDiagnostics/wrap_bunch_twiss_analysis.cc +++ b/src/orbit/BunchDiagnostics/wrap_bunch_twiss_analysis.cc @@ -1,12 +1,12 @@ -#include "orbit_mpi.hh" -#include "pyORBIT_Object.hh" +#include "mpi/orbit_mpi.hh" +#include "main/pyORBIT_Object.hh" -#include "wrap_bunch_twiss_analysis.hh" -#include "wrap_bunch.hh" +#include "orbit/BunchDiagnostics/wrap_bunch_twiss_analysis.hh" +#include "orbit/wrap_bunch.hh" #include -#include "BunchTwissAnalysis.hh" +#include "orbit/BunchDiagnostics/BunchTwissAnalysis.hh" namespace wrap_bunch_twiss_analysis{ @@ -30,7 +30,6 @@ extern "C" { /** This is implementation of the __init__ method */ static int BunchTwissAnalysis_init(pyORBIT_Object *self, PyObject *args, PyObject *kwds){ self->cpp_obj = new BunchTwissAnalysis(); - ((BunchTwissAnalysis*) self->cpp_obj)->setPyWrapper((PyObject*) self); return 0; } diff --git a/src/orbit/BunchDiagnostics/wrap_bunch_twiss_analysis.hh b/src/orbit/BunchDiagnostics/wrap_bunch_twiss_analysis.hh index 7f01e87d..c2e94d47 100644 --- a/src/orbit/BunchDiagnostics/wrap_bunch_twiss_analysis.hh +++ b/src/orbit/BunchDiagnostics/wrap_bunch_twiss_analysis.hh @@ -1,7 +1,7 @@ #ifndef WRAP_BUNCH_TWISS_ANALYSIS_HH_ #define WRAP_BUNCH_TWISS_ANALYSIS_HH_ -#include "Python.h" +#include #ifdef __cplusplus extern "C" { diff --git a/src/orbit/Errors/errorbase.cc b/src/orbit/Errors/errorbase.cc index 07fb506f..7a35cee4 100644 --- a/src/orbit/Errors/errorbase.cc +++ b/src/orbit/Errors/errorbase.cc @@ -22,11 +22,11 @@ // ///////////////////////////////////////////////////////////////////////////// -#include "errorbase.hh" -#include "teapotbase.hh" -#include "OrbitConst.hh" -#include "SyncPart.hh" -#include "Random.hh" +#include "orbit/Errors/errorbase.hh" +#include "teapot/teapotbase.hh" +#include "orbit/OrbitConst.hh" +#include "orbit/SyncPart.hh" +#include "utils/Random.hh" #include #include diff --git a/src/orbit/Errors/errorbase.hh b/src/orbit/Errors/errorbase.hh index 6cb82b70..a22e0865 100644 --- a/src/orbit/Errors/errorbase.hh +++ b/src/orbit/Errors/errorbase.hh @@ -18,7 +18,7 @@ #ifndef ERROR_BASE_H #define ERROR_BASE_H -#include "Bunch.hh" +#include "orbit/Bunch.hh" namespace error_base { diff --git a/src/orbit/Errors/wrap_errorbase.cc b/src/orbit/Errors/wrap_errorbase.cc index 82494511..f533ed2f 100644 --- a/src/orbit/Errors/wrap_errorbase.cc +++ b/src/orbit/Errors/wrap_errorbase.cc @@ -1,11 +1,11 @@ -#include "Python.h" -#include "orbit_mpi.hh" +#include +#include "mpi/orbit_mpi.hh" -#include "pyORBIT_Object.hh" +#include "main/pyORBIT_Object.hh" -#include "errorbase.hh" +#include "orbit/Errors/errorbase.hh" -#include "wrap_errorbase.hh" +#include "orbit/Errors/wrap_errorbase.hh" namespace wrap_errorbase { diff --git a/src/orbit/FieldTracker/FieldTracker.cc b/src/orbit/FieldTracker/FieldTracker.cc index 02a4bd23..960c98b7 100644 --- a/src/orbit/FieldTracker/FieldTracker.cc +++ b/src/orbit/FieldTracker/FieldTracker.cc @@ -1,12 +1,12 @@ -#include "FieldTracker.hh" +#include "orbit/FieldTracker/FieldTracker.hh" #include #include #include #include #include -#include "OrbitConst.hh" -#include "SyncPart.hh" +#include "orbit/OrbitConst.hh" +#include "orbit/SyncPart.hh" ////////////////////////////////////////////////////////////////////////// //Constructor for FieldTracker @@ -46,9 +46,9 @@ FieldTracker::FieldTracker(const double &bx, const double &by, const double &resid, const double &xrefi, const double &yrefi, const double &eulerai, const double &eulerbi, - const double &eulergi, Bunch* b, string &filename) { + const double &eulergi, Bunch* b, std::string &filename) { - cerr << "Instantiating the 3D field track class \n" ; + std::cerr << "Instantiating the 3D field track class \n" ; double ZPARSEMIN = 100.0 * zi - 1.0; double ZPARSEMAX = 100.0 * zf + 1.0; @@ -151,7 +151,7 @@ void FieldTracker::trackBunch(Bunch* b) { double xj, yj, zj, pxj, pyj, pzj, sj; int lost = 0; - ofstream fio("Path", std::ios::out); + std::ofstream fio("Path", std::ios::out); if(getPath == 1) { @@ -359,7 +359,7 @@ void FieldTracker::trackBunch(Bunch* b) { // //////////////////////////////////////////////////////////////////////////////// -void FieldTracker::ParseGrid3D(const string &fileName, const double &xmin, +void FieldTracker::ParseGrid3D(const std::string &fileName, const double &xmin, const double &xmax, const double &ymin, const double &ymax, const double &zmin, const double &zmax, const int &skipX, const int &skipY, const int &skipZ) { @@ -368,13 +368,13 @@ void FieldTracker::ParseGrid3D(const string &fileName, const double &xmin, int nZTab = 0; int iDummy, i, j, k; int xindex, yindex, zindex; - string Dummy; + std::string Dummy; double x, y, z, Bx, By, Bz; std::cerr << "Filename: " << fileName << "\n"; - ifstream fio(fileName.c_str(), ios::in); + std::ifstream fio(fileName.c_str(), std::ios::in); if (!fio) { std::cerr << "Filename " << fileName << " not found\n"; } @@ -424,7 +424,7 @@ void FieldTracker::ParseGrid3D(const string &fileName, const double &xmin, BZGrid = new Grid3D(nXTab, nYTab, nZTab); BMagGrid = new Grid3D(nXTab, nYTab, nZTab); - ifstream fio2(fileName.c_str(), ios::in); + std::ifstream fio2(fileName.c_str(), std::ios::in); if (!fio2) { std::cerr << "Filename " << fileName << " not found\n"; } @@ -671,7 +671,7 @@ void FieldTracker::nodeCalculator(Bunch* b) int iquit = 0; double xwidth = FieldTracker::xFoilMax - FieldTracker::xFoilMin; - ofstream fio("RefPath", ios::out); + std::ofstream fio("RefPath", std::ios::out); xField3D = xref; yField3D = yref; diff --git a/src/orbit/FieldTracker/FieldTracker.hh b/src/orbit/FieldTracker/FieldTracker.hh index 06ac3cc2..f2ad7b6b 100644 --- a/src/orbit/FieldTracker/FieldTracker.hh +++ b/src/orbit/FieldTracker/FieldTracker.hh @@ -3,19 +3,16 @@ #ifndef FIELDTRACKER_H #define FIELDTRACKER_H -//pyORBIT utils -#include "CppPyWrapper.hh" -#include "Bunch.hh" -#include "Grid3D.hh" +#include "orbit/Bunch.hh" +#include "spacecharge/Grid3D.hh" -using namespace std; /** The FieldTracker class is used to define how a particle/bunch propogates through an 3-dimensional magnetic field */ -class FieldTracker: public OrbitUtils::CppPyWrapper +class FieldTracker { public: @@ -29,14 +26,14 @@ public: const double &resid, const double &xrefi, const double &yrefi, const double &eulerai, const double &eulerbi, - const double &eulergi, Bunch* b, string &filename); + const double &eulergi, Bunch* b, std::string &filename); /** Routine for transfering particles through a aperture */ void trackBunch(Bunch* b); void BGrid3D(); - void ParseGrid3D(const string &fileName, + void ParseGrid3D(const std::string &fileName, const double &xmin, const double &xmax, const double &ymin, const double &ymax, const double &zmin, const double &zmax, diff --git a/src/orbit/FieldTracker/wrap_fieldtracker.cc b/src/orbit/FieldTracker/wrap_fieldtracker.cc index 9e6f2107..169216cb 100644 --- a/src/orbit/FieldTracker/wrap_fieldtracker.cc +++ b/src/orbit/FieldTracker/wrap_fieldtracker.cc @@ -1,13 +1,13 @@ -#include "orbit_mpi.hh" -#include "pyORBIT_Object.hh" -#include "wrap_fieldtracker.hh" -#include "wrap_bunch.hh" +#include "mpi/orbit_mpi.hh" +#include "main/pyORBIT_Object.hh" +#include "orbit/FieldTracker/wrap_fieldtracker.hh" +#include "orbit/wrap_bunch.hh" #include -#include "FieldTracker.hh" +#include "orbit/FieldTracker/FieldTracker.hh" -#include "wrap_fieldtracker.hh" +#include "orbit/FieldTracker/wrap_fieldtracker.hh" namespace wrap_fieldtracker{ @@ -68,7 +68,6 @@ namespace wrap_fieldtracker{ ax, ay, ex, epx, l, zi, zf, ds, niters, resid, xrefi, yrefi, eulerai, eulerbi, eulergi, cpp_bunch, filename_str); - ((FieldTracker*) self->cpp_obj)->setPyWrapper((PyObject*) self); return 0; } diff --git a/src/orbit/FieldTracker/wrap_fieldtracker.hh b/src/orbit/FieldTracker/wrap_fieldtracker.hh index c981ff1b..036086f4 100644 --- a/src/orbit/FieldTracker/wrap_fieldtracker.hh +++ b/src/orbit/FieldTracker/wrap_fieldtracker.hh @@ -1,7 +1,7 @@ #ifndef WRAP_ORBIT_FIELDTRACKER_HH_ #define WRAP_ORBIT_FIELDTRACKER_HH_ -#include "Python.h" +#include #ifdef __cplusplus extern "C" { diff --git a/src/orbit/Impedances/LImpedance.cc b/src/orbit/Impedances/LImpedance.cc index c2f95e1d..e4576d4f 100644 --- a/src/orbit/Impedances/LImpedance.cc +++ b/src/orbit/Impedances/LImpedance.cc @@ -11,10 +11,10 @@ // ///////////////////////////////////////////////////////////////////////////// -#include "Grid1D.hh" -#include "BufferStore.hh" -#include "LImpedance.hh" -#include "OrbitConst.hh" +#include "spacecharge/Grid1D.hh" +#include "utils/BufferStore.hh" +#include "orbit/Impedances/LImpedance.hh" +#include "orbit/OrbitConst.hh" #include #include #include @@ -29,12 +29,12 @@ using namespace OrbitUtils; LImpedance::LImpedance(double length, int nMacrosMin, - int nBins): CppPyWrapper(NULL) + int nBins) { _length = length; _nMacrosMin = nMacrosMin; _nBins = nBins; - zGrid = new Grid1D(_nBins, _length); + zGrid.reset(new Grid1D(_nBins, _length)); _fftmagnitude = new double[_nBins / 2]; _fftphase = new double[_nBins / 2]; @@ -64,14 +64,6 @@ LImpedance::LImpedance(double length, LImpedance::~LImpedance() { - if(zGrid->getPyWrapper() != NULL) - { - Py_DECREF(zGrid->getPyWrapper()); - } - else - { - delete zGrid; - } delete[] _fftmagnitude; delete[] _fftphase; delete[] _z; diff --git a/src/orbit/Impedances/LImpedance.hh b/src/orbit/Impedances/LImpedance.hh index a826af87..d0b84643 100644 --- a/src/orbit/Impedances/LImpedance.hh +++ b/src/orbit/Impedances/LImpedance.hh @@ -4,27 +4,25 @@ #define LIMPEDANCE_H //MPI Function Wrappers -#include "orbit_mpi.hh" -#include "wrap_mpi_comm.hh" +#include "mpi/orbit_mpi.hh" #include #include +#include #include //ORBIT bunch -#include "Bunch.hh" +#include "orbit/Bunch.hh" //pyORBIT utils -#include "CppPyWrapper.hh" -#include "BunchExtremaCalculator.hh" -#include "Grid1D.hh" +#include "utils/bunch/BunchExtremaCalculator.hh" +#include "spacecharge/Grid1D.hh" //FFTW library header #include "fftw3.h" -using namespace std; -class LImpedance: public OrbitUtils::CppPyWrapper +class LImpedance { public: @@ -52,7 +50,7 @@ public: int _nBins; //protected: - Grid1D* zGrid; + std::unique_ptr zGrid; OrbitUtils::BunchExtremaCalculator* bunchExtremaCalc; //FFT arrays diff --git a/src/orbit/Impedances/TImpedance.cc b/src/orbit/Impedances/TImpedance.cc index b6031982..e7821b40 100644 --- a/src/orbit/Impedances/TImpedance.cc +++ b/src/orbit/Impedances/TImpedance.cc @@ -10,10 +10,10 @@ // ///////////////////////////////////////////////////////////////////////////// -#include "Grid1D.hh" -#include "BufferStore.hh" -#include "TImpedance.hh" -#include "OrbitConst.hh" +#include "spacecharge/Grid1D.hh" +#include "utils/BufferStore.hh" +#include "orbit/Impedances/TImpedance.hh" +#include "orbit/OrbitConst.hh" #include #include #include @@ -30,14 +30,14 @@ TImpedance::TImpedance(double length, int nMacrosMin, int nBins, int useX, - int useY): CppPyWrapper(NULL) + int useY) { _length = length; _nMacrosMin = nMacrosMin; _nBins = nBins; _useX = useX; _useY = useY; - zGrid = new Grid1D(_nBins, _length); + zGrid.reset(new Grid1D(_nBins, _length)); _qX = 0.0; _qY = 0.0; @@ -97,15 +97,6 @@ TImpedance::TImpedance(double length, TImpedance::~TImpedance() { - if(zGrid->getPyWrapper() != NULL) - { - Py_DECREF(zGrid->getPyWrapper()); - } - else - { - delete zGrid; - } - delete[] _xCentroid; delete[] _xpCentroid; delete[] _zXImped_nplus; diff --git a/src/orbit/Impedances/TImpedance.hh b/src/orbit/Impedances/TImpedance.hh index 08e31d1f..7873a5ec 100644 --- a/src/orbit/Impedances/TImpedance.hh +++ b/src/orbit/Impedances/TImpedance.hh @@ -4,27 +4,25 @@ #define TIMPEDANCE_H //MPI Function Wrappers -#include "orbit_mpi.hh" -#include "wrap_mpi_comm.hh" +#include "mpi/orbit_mpi.hh" #include #include +#include #include //ORBIT bunch -#include "Bunch.hh" +#include "orbit/Bunch.hh" //pyORBIT utils -#include "CppPyWrapper.hh" -#include "BunchExtremaCalculator.hh" -#include "Grid1D.hh" +#include "utils/bunch/BunchExtremaCalculator.hh" +#include "spacecharge/Grid1D.hh" //FFTW library header #include "fftw3.h" -using namespace std; -class TImpedance: public OrbitUtils::CppPyWrapper +class TImpedance { public: @@ -82,7 +80,7 @@ public: double _betaY; double _charge2TKick; int _Turns; - Grid1D* zGrid; + std::unique_ptr zGrid; OrbitUtils::BunchExtremaCalculator* bunchExtremaCalc; double* _xCentroid; diff --git a/src/orbit/Impedances/wrap_LImpedance.cc b/src/orbit/Impedances/wrap_LImpedance.cc index fb3e00b9..90a0ae1d 100644 --- a/src/orbit/Impedances/wrap_LImpedance.cc +++ b/src/orbit/Impedances/wrap_LImpedance.cc @@ -1,12 +1,12 @@ -#include "orbit_mpi.hh" -#include "pyORBIT_Object.hh" +#include "mpi/orbit_mpi.hh" +#include "main/pyORBIT_Object.hh" -#include "wrap_LImpedance.hh" -#include "wrap_bunch.hh" +#include "orbit/Impedances/wrap_LImpedance.hh" +#include "orbit/wrap_bunch.hh" #include -#include "LImpedance.hh" +#include "orbit/Impedances/LImpedance.hh" using namespace OrbitUtils; @@ -63,7 +63,6 @@ extern "C" self->cpp_obj = new LImpedance(length, nMacrosMin, nBins); - ((LImpedance*) self->cpp_obj)->setPyWrapper((PyObject*) self); return 0; } diff --git a/src/orbit/Impedances/wrap_LImpedance.hh b/src/orbit/Impedances/wrap_LImpedance.hh index d2936333..5ffebd3d 100644 --- a/src/orbit/Impedances/wrap_LImpedance.hh +++ b/src/orbit/Impedances/wrap_LImpedance.hh @@ -1,7 +1,7 @@ #ifndef WRAP_LIMPEDANCE_H #define WRAP_LIMPEDANCE_H -#include "Python.h" +#include #ifdef __cplusplus extern "C" diff --git a/src/orbit/Impedances/wrap_TImpedance.cc b/src/orbit/Impedances/wrap_TImpedance.cc index 119c8965..73b78f21 100644 --- a/src/orbit/Impedances/wrap_TImpedance.cc +++ b/src/orbit/Impedances/wrap_TImpedance.cc @@ -1,12 +1,12 @@ -#include "orbit_mpi.hh" -#include "pyORBIT_Object.hh" +#include "mpi/orbit_mpi.hh" +#include "main/pyORBIT_Object.hh" -#include "wrap_TImpedance.hh" -#include "wrap_bunch.hh" +#include "orbit/Impedances/wrap_TImpedance.hh" +#include "orbit/wrap_bunch.hh" #include -#include "TImpedance.hh" +#include "orbit/Impedances/TImpedance.hh" using namespace OrbitUtils; @@ -69,7 +69,6 @@ extern "C" self->cpp_obj = new TImpedance(length, nMacrosMin, nBins, useX, useY); - ((TImpedance*) self->cpp_obj)->setPyWrapper((PyObject*) self); return 0; } diff --git a/src/orbit/Impedances/wrap_TImpedance.hh b/src/orbit/Impedances/wrap_TImpedance.hh index d001bb24..ffca3037 100644 --- a/src/orbit/Impedances/wrap_TImpedance.hh +++ b/src/orbit/Impedances/wrap_TImpedance.hh @@ -1,7 +1,7 @@ #ifndef WRAP_TIMPEDANCE_H #define WRAP_TIMPEDANCE_H -#include "Python.h" +#include #ifdef __cplusplus extern "C" diff --git a/src/orbit/Impedances/wrap_impedances.cc b/src/orbit/Impedances/wrap_impedances.cc index 16293211..95d85a93 100644 --- a/src/orbit/Impedances/wrap_impedances.cc +++ b/src/orbit/Impedances/wrap_impedances.cc @@ -1,7 +1,7 @@ -#include "orbit_mpi.hh" +#include "mpi/orbit_mpi.hh" -#include "wrap_LImpedance.hh" -#include "wrap_TImpedance.hh" +#include "orbit/Impedances/wrap_LImpedance.hh" +#include "orbit/Impedances/wrap_TImpedance.hh" static PyMethodDef impedancesMethods[] = {{NULL,NULL}}; diff --git a/src/orbit/Impedances/wrap_impedances.hh b/src/orbit/Impedances/wrap_impedances.hh index c6270c41..cef05bc4 100644 --- a/src/orbit/Impedances/wrap_impedances.hh +++ b/src/orbit/Impedances/wrap_impedances.hh @@ -1,7 +1,7 @@ #ifndef WRAP_IMPEDANCES_H #define WRAP_IMPEDANCES_H -#include "Python.h" +#include #ifdef __cplusplus extern "C" diff --git a/src/orbit/MaterialInteractions/Collimator.cc b/src/orbit/MaterialInteractions/Collimator.cc index a4d88b94..22ce198e 100644 --- a/src/orbit/MaterialInteractions/Collimator.cc +++ b/src/orbit/MaterialInteractions/Collimator.cc @@ -1,17 +1,17 @@ -#include "MaterialInteractions.hh" -#include "Collimator.hh" -#include "SyncPart.hh" -#include "cross_sections.hh" -#include "numrecipes.hh" -#include "OrbitConst.hh" -#include "Random.hh" +#include "orbit/MaterialInteractions/MaterialInteractions.hh" +#include "orbit/MaterialInteractions/Collimator.hh" +#include "orbit/SyncPart.hh" +#include "orbit/MaterialInteractions/cross_sections.hh" +#include "orbit/MaterialInteractions/numrecipes.hh" +#include "orbit/OrbitConst.hh" +#include "utils/Random.hh" #include #include #include #include -#include "ParticleInitialCoordinates.hh" +#include "orbit/ParticlesAttributes/ParticleInitialCoordinates.hh" using namespace OrbitUtils; @@ -51,7 +51,7 @@ using namespace OrbitUtils; Collimator::Collimator(double length, int ma, double density_fac, int shape, - double a, double b, double c, double d, double angle, double pos): CppPyWrapper(NULL) + double a, double b, double c, double d, double angle, double pos) { length_ = length; ma_ = ma; diff --git a/src/orbit/MaterialInteractions/Collimator.hh b/src/orbit/MaterialInteractions/Collimator.hh index 6cd57395..ea64f623 100644 --- a/src/orbit/MaterialInteractions/Collimator.hh +++ b/src/orbit/MaterialInteractions/Collimator.hh @@ -2,17 +2,14 @@ #ifndef COLLIMATOR_H #define COLLIMATOR_H -//pyORBIT utils -#include "CppPyWrapper.hh" -#include "Bunch.hh" +#include "orbit/Bunch.hh" -using namespace std; /** The collimator class is used to define how a bunch propogates through a collimator */ -class Collimator: public OrbitUtils::CppPyWrapper +class Collimator { public: diff --git a/src/orbit/MaterialInteractions/Foil.cc b/src/orbit/MaterialInteractions/Foil.cc index a0eaa2b9..54661fe8 100644 --- a/src/orbit/MaterialInteractions/Foil.cc +++ b/src/orbit/MaterialInteractions/Foil.cc @@ -1,17 +1,17 @@ -#include "MaterialInteractions.hh" -#include "Foil.hh" -#include "SyncPart.hh" -#include "cross_sections.hh" -#include "numrecipes.hh" -#include "OrbitConst.hh" -#include "Random.hh" +#include "orbit/MaterialInteractions/MaterialInteractions.hh" +#include "orbit/MaterialInteractions/Foil.hh" +#include "orbit/SyncPart.hh" +#include "orbit/MaterialInteractions/cross_sections.hh" +#include "orbit/MaterialInteractions/numrecipes.hh" +#include "orbit/OrbitConst.hh" +#include "utils/Random.hh" #include #include #include #include -#include "ParticleInitialCoordinates.hh" +#include "orbit/ParticlesAttributes/ParticleInitialCoordinates.hh" using namespace OrbitUtils; @@ -35,7 +35,7 @@ using namespace OrbitUtils; // /////////////////////////////////////////////////////////////////////////// -Foil::Foil(double xmin, double xmax, double ymin, double ymax, double thick): CppPyWrapper(NULL) +Foil::Foil(double xmin, double xmax, double ymin, double ymax, double thick) { xmin_ = xmin; xmax_ = xmax; diff --git a/src/orbit/MaterialInteractions/Foil.hh b/src/orbit/MaterialInteractions/Foil.hh index 3b2052ae..70cb95d0 100644 --- a/src/orbit/MaterialInteractions/Foil.hh +++ b/src/orbit/MaterialInteractions/Foil.hh @@ -2,17 +2,14 @@ #ifndef FOIL_H #define FOIL_H -//pyORBIT utils -#include "CppPyWrapper.hh" -#include "Bunch.hh" +#include "orbit/Bunch.hh" -using namespace std; /** The foil class is used to define how a bunch propogates through a foil */ -class Foil: public OrbitUtils::CppPyWrapper +class Foil { public: diff --git a/src/orbit/MaterialInteractions/MaterialInteractions.cc b/src/orbit/MaterialInteractions/MaterialInteractions.cc index 362114c8..1e1dc94c 100644 --- a/src/orbit/MaterialInteractions/MaterialInteractions.cc +++ b/src/orbit/MaterialInteractions/MaterialInteractions.cc @@ -13,10 +13,10 @@ // A class for storing hadron material interaction methods. // /////////////////////////////////////////////////////////////////////////// -#include "MaterialInteractions.hh" -#include "OrbitConst.hh" -#include "Random.hh" -#include "bessel.hh" +#include "orbit/MaterialInteractions/MaterialInteractions.hh" +#include "orbit/OrbitConst.hh" +#include "utils/Random.hh" +#include "utils/bessel.hh" #include #include @@ -338,7 +338,7 @@ double MaterialInteractions::elastic_t(double p, double a) theta+=1.768e-3; } - if(found==0) cout<<"Warning, never found elastic t.\n"; + if(found==0) std::cout<<"Warning, never found elastic t.\n"; t=2.*p_cm*p_cm*(1. - cos(angle_cm)); return t; } diff --git a/src/orbit/MaterialInteractions/MaterialInteractions.hh b/src/orbit/MaterialInteractions/MaterialInteractions.hh index 14e05375..e8769aa3 100644 --- a/src/orbit/MaterialInteractions/MaterialInteractions.hh +++ b/src/orbit/MaterialInteractions/MaterialInteractions.hh @@ -1,11 +1,6 @@ #ifndef MATERIAL_INTERACTIONS_H #define MATERIAL_INTERACTIONS_H -//pyORBIT utils -#include "CppPyWrapper.hh" - - -using namespace std; /** The MaterialInteractions class contains a set of routines for calculating common interactions of a particle with a diff --git a/src/orbit/MaterialInteractions/cross_sections.cc b/src/orbit/MaterialInteractions/cross_sections.cc index 8312eaa5..4cb292c3 100644 --- a/src/orbit/MaterialInteractions/cross_sections.cc +++ b/src/orbit/MaterialInteractions/cross_sections.cc @@ -2,7 +2,7 @@ #include #include #include -#include "cross_sections.hh" +#include "orbit/MaterialInteractions/cross_sections.hh" namespace OrbitUtils{ diff --git a/src/orbit/MaterialInteractions/numrecipes.cc b/src/orbit/MaterialInteractions/numrecipes.cc index a38dd327..1434f870 100644 --- a/src/orbit/MaterialInteractions/numrecipes.cc +++ b/src/orbit/MaterialInteractions/numrecipes.cc @@ -2,7 +2,7 @@ #include #include #include -#include "numrecipes.hh" +#include "orbit/MaterialInteractions/numrecipes.hh" namespace OrbitUtils{ diff --git a/src/orbit/MaterialInteractions/wrap_collimator.cc b/src/orbit/MaterialInteractions/wrap_collimator.cc index 444b8e24..b0b19ce5 100644 --- a/src/orbit/MaterialInteractions/wrap_collimator.cc +++ b/src/orbit/MaterialInteractions/wrap_collimator.cc @@ -1,12 +1,12 @@ -#include "orbit_mpi.hh" -#include "pyORBIT_Object.hh" +#include "mpi/orbit_mpi.hh" +#include "main/pyORBIT_Object.hh" -#include "wrap_collimator.hh" -#include "wrap_bunch.hh" +#include "orbit/MaterialInteractions/wrap_collimator.hh" +#include "orbit/wrap_bunch.hh" #include -#include "Collimator.hh" +#include "orbit/MaterialInteractions/Collimator.hh" namespace wrap_collimator{ @@ -38,7 +38,6 @@ extern "C" { error("Collimator - cannot parse arguments! It should be (length,ma,density_fac,shape,a,b,c,d,angle,pos)"); } self->cpp_obj = new Collimator(length,ma,density_fac,shape,a,b,c,d,angle,pos); - ((Collimator*) self->cpp_obj)->setPyWrapper((PyObject*) self); return 0; } diff --git a/src/orbit/MaterialInteractions/wrap_collimator.hh b/src/orbit/MaterialInteractions/wrap_collimator.hh index 278e7b70..5f3069a0 100644 --- a/src/orbit/MaterialInteractions/wrap_collimator.hh +++ b/src/orbit/MaterialInteractions/wrap_collimator.hh @@ -1,7 +1,7 @@ #ifndef WRAP_ORBIT_COLLIMATOR_HH_ #define WRAP_ORBIT_COLLIMATOR_HH_ -#include "Python.h" +#include #ifdef __cplusplus extern "C" { diff --git a/src/orbit/MaterialInteractions/wrap_foil.cc b/src/orbit/MaterialInteractions/wrap_foil.cc index 3d9398a9..322de28d 100644 --- a/src/orbit/MaterialInteractions/wrap_foil.cc +++ b/src/orbit/MaterialInteractions/wrap_foil.cc @@ -1,12 +1,12 @@ -#include "orbit_mpi.hh" -#include "pyORBIT_Object.hh" +#include "mpi/orbit_mpi.hh" +#include "main/pyORBIT_Object.hh" -#include "wrap_foil.hh" -#include "wrap_bunch.hh" +#include "orbit/MaterialInteractions/wrap_foil.hh" +#include "orbit/wrap_bunch.hh" #include -#include "Foil.hh" +#include "orbit/MaterialInteractions/Foil.hh" namespace wrap_foil{ @@ -37,7 +37,6 @@ extern "C" { error("PyBunch - addParticle - cannot parse arguments! It should be (xmin, xmax, ymin, ymax, thick)"); } self->cpp_obj = new Foil(xmin, xmax, ymin, ymax, thick); - ((Foil*) self->cpp_obj)->setPyWrapper((PyObject*) self); return 0; } diff --git a/src/orbit/MaterialInteractions/wrap_foil.hh b/src/orbit/MaterialInteractions/wrap_foil.hh index eafb1808..7f9b35e7 100644 --- a/src/orbit/MaterialInteractions/wrap_foil.hh +++ b/src/orbit/MaterialInteractions/wrap_foil.hh @@ -1,7 +1,7 @@ #ifndef WRAP_ORBIT_FOIL_HH_ #define WRAP_ORBIT_FOIL_HH_ -#include "Python.h" +#include #ifdef __cplusplus extern "C" { diff --git a/src/orbit/OrbitConst.cc b/src/orbit/OrbitConst.cc index f57a4a40..b9e9c9ca 100644 --- a/src/orbit/OrbitConst.cc +++ b/src/orbit/OrbitConst.cc @@ -21,7 +21,7 @@ ///////////////////////////////////////////////////////////////////////////// -#include "OrbitConst.hh" +#include "orbit/OrbitConst.hh" const double OrbitConst::PI = 3.14159265358979323846264; const double OrbitConst::c = 2.99792458e+8; diff --git a/src/orbit/ParticlesAttributes/AtomPopulations.cc b/src/orbit/ParticlesAttributes/AtomPopulations.cc index f4617c09..2fd4fbfe 100644 --- a/src/orbit/ParticlesAttributes/AtomPopulations.cc +++ b/src/orbit/ParticlesAttributes/AtomPopulations.cc @@ -16,8 +16,8 @@ // /////////////////////////////////////////////////////////////////////////// -#include "../Bunch.hh" -#include "AtomPopulations.hh" +#include "orbit/Bunch.hh" +#include "orbit/ParticlesAttributes/AtomPopulations.hh" AtomPopulations::AtomPopulations(Bunch* bunch, int size_in): ParticleAttributes(bunch,size_in) diff --git a/src/orbit/ParticlesAttributes/AtomPopulations.hh b/src/orbit/ParticlesAttributes/AtomPopulations.hh index f94b2489..9e219f57 100644 --- a/src/orbit/ParticlesAttributes/AtomPopulations.hh +++ b/src/orbit/ParticlesAttributes/AtomPopulations.hh @@ -21,7 +21,7 @@ #include -#include "ParticleAttributes.hh" +#include "orbit/ParticlesAttributes/ParticleAttributes.hh" class AtomPopulations : public ParticleAttributes { diff --git a/src/orbit/ParticlesAttributes/Evolution.cc b/src/orbit/ParticlesAttributes/Evolution.cc index c9d4e2cf..e5c36488 100644 --- a/src/orbit/ParticlesAttributes/Evolution.cc +++ b/src/orbit/ParticlesAttributes/Evolution.cc @@ -16,8 +16,8 @@ // /////////////////////////////////////////////////////////////////////////// -#include "../Bunch.hh" -#include "Evolution.hh" +#include "orbit/Bunch.hh" +#include "orbit/ParticlesAttributes/Evolution.hh" Evolution::Evolution(Bunch* bunch, int size_in): ParticleAttributes(bunch,size_in) diff --git a/src/orbit/ParticlesAttributes/Evolution.hh b/src/orbit/ParticlesAttributes/Evolution.hh index 5fb71833..eb9ed07e 100644 --- a/src/orbit/ParticlesAttributes/Evolution.hh +++ b/src/orbit/ParticlesAttributes/Evolution.hh @@ -33,7 +33,7 @@ // WaveFunctionAmplitudes // /////////////////////////////////////////////////////////////////////////// -#include "ParticleAttributes.hh" +#include "orbit/ParticlesAttributes/ParticleAttributes.hh" class Evolution : public ParticleAttributes { diff --git a/src/orbit/ParticlesAttributes/LostParticleAttributes.cc b/src/orbit/ParticlesAttributes/LostParticleAttributes.cc index cf26a17e..5a0c67a2 100644 --- a/src/orbit/ParticlesAttributes/LostParticleAttributes.cc +++ b/src/orbit/ParticlesAttributes/LostParticleAttributes.cc @@ -15,8 +15,8 @@ // /////////////////////////////////////////////////////////////////////////// -#include "../Bunch.hh" -#include "LostParticleAttributes.hh" +#include "orbit/Bunch.hh" +#include "orbit/ParticlesAttributes/LostParticleAttributes.hh" LostParticleAttributes::LostParticleAttributes(Bunch* bunch): ParticleAttributes(bunch,1) diff --git a/src/orbit/ParticlesAttributes/LostParticleAttributes.hh b/src/orbit/ParticlesAttributes/LostParticleAttributes.hh index 774254aa..45727600 100644 --- a/src/orbit/ParticlesAttributes/LostParticleAttributes.hh +++ b/src/orbit/ParticlesAttributes/LostParticleAttributes.hh @@ -21,7 +21,7 @@ // INCLUDE FILES // /////////////////////////////////////////////////////////////////////////// -#include "ParticleAttributes.hh" +#include "orbit/ParticlesAttributes/ParticleAttributes.hh" class LostParticleAttributes : public ParticleAttributes { diff --git a/src/orbit/ParticlesAttributes/ParticleAttributes.cc b/src/orbit/ParticlesAttributes/ParticleAttributes.cc index e1779486..51f838d5 100644 --- a/src/orbit/ParticlesAttributes/ParticleAttributes.cc +++ b/src/orbit/ParticlesAttributes/ParticleAttributes.cc @@ -17,8 +17,8 @@ // /////////////////////////////////////////////////////////////////////////// -#include "../Bunch.hh" -#include "ParticleAttributes.hh" +#include "orbit/Bunch.hh" +#include "orbit/ParticlesAttributes/ParticleAttributes.hh" ParticleAttributes::ParticleAttributes(Bunch* bunch, int size_in) { diff --git a/src/orbit/ParticlesAttributes/ParticleAttributes.hh b/src/orbit/ParticlesAttributes/ParticleAttributes.hh index bff57fc1..6547aa5a 100644 --- a/src/orbit/ParticlesAttributes/ParticleAttributes.hh +++ b/src/orbit/ParticlesAttributes/ParticleAttributes.hh @@ -19,7 +19,7 @@ #ifndef PARTICLE_ATTRIBUTES_H #define PARTICLE_ATTRIBUTES_H -#include "../../mpi/orbit_mpi.hh" +#include "mpi/orbit_mpi.hh" #include #include diff --git a/src/orbit/ParticlesAttributes/ParticleAttributesFactory.cc b/src/orbit/ParticlesAttributes/ParticleAttributesFactory.cc index 6f2c9d9d..7884541a 100644 --- a/src/orbit/ParticlesAttributes/ParticleAttributesFactory.cc +++ b/src/orbit/ParticlesAttributes/ParticleAttributesFactory.cc @@ -15,19 +15,19 @@ // /////////////////////////////////////////////////////////////////////////// -#include "ParticleAttributesFactory.hh" - -#include "ParticleMacroSize.hh" -#include "WaveFunctionAmplitudes.hh" -#include "AtomPopulations.hh" -#include "pq_coordinates.hh" -#include "part_time.hh" -#include "Evolution.hh" -#include "LostParticleAttributes.hh" -#include "ParticlePhaseAttributes.hh" -#include "ParticleIdNumber.hh" -#include "ParticleInitialCoordinates.hh" -#include "TurnNumberAttributes.hh" +#include "orbit/ParticlesAttributes/ParticleAttributesFactory.hh" + +#include "orbit/ParticlesAttributes/ParticleMacroSize.hh" +#include "orbit/ParticlesAttributes/WaveFunctionAmplitudes.hh" +#include "orbit/ParticlesAttributes/AtomPopulations.hh" +#include "orbit/ParticlesAttributes/pq_coordinates.hh" +#include "orbit/ParticlesAttributes/part_time.hh" +#include "orbit/ParticlesAttributes/Evolution.hh" +#include "orbit/ParticlesAttributes/LostParticleAttributes.hh" +#include "orbit/ParticlesAttributes/ParticlePhaseAttributes.hh" +#include "orbit/ParticlesAttributes/ParticleIdNumber.hh" +#include "orbit/ParticlesAttributes/ParticleInitialCoordinates.hh" +#include "orbit/ParticlesAttributes/TurnNumberAttributes.hh" ParticleAttributesFactory::ParticleAttributesFactory() { @@ -46,7 +46,7 @@ ParticleAttributes* ParticleAttributesFactory::getParticleAttributesInstance( int rank_MPI = 0; int size_MPI = 1; int iMPIini = 0; - MPI_Comm MPI_COMM_Local = bunch->getMPI_Comm_Local()->comm; + MPI_Comm MPI_COMM_Local = bunch->getMPI_Comm_Local(); ORBIT_MPI_Initialized(&iMPIini); if(iMPIini > 0){ @@ -78,7 +78,7 @@ ParticleAttributes* ParticleAttributesFactory::getParticleAttributesInstance( if(name == "Amplitudes"){ if(params_dict.size() == 0){ - cout<<"dictionary Amplitudes(dict) should be defined "<<"\n"; + std::cout<<"dictionary Amplitudes(dict) should be defined "<<"\n"; } else { if(params_dict.count("size") == 1){ part_atrs = new WaveFunctionAmplitudes(bunch,(int) params_dict["size"]); @@ -99,7 +99,7 @@ ParticleAttributes* ParticleAttributesFactory::getParticleAttributesInstance( if(name == "Populations"){ if(params_dict.size() == 0){ - cout<<"dictionary AtomPopulations(dict) should be defined "<<"\n"; + std::cout<<"dictionary AtomPopulations(dict) should be defined "<<"\n"; } else { if(params_dict.count("size") == 1){ part_atrs = new AtomPopulations(bunch,(int) params_dict["size"]); @@ -119,7 +119,7 @@ ParticleAttributes* ParticleAttributesFactory::getParticleAttributesInstance( if(name == "pq_coords"){ if(params_dict.size() == 0){ - cout<<"dictionary pq_coords(dict) should be defined "<<"\n"; + std::cout<<"dictionary pq_coords(dict) should be defined "<<"\n"; } else { if(params_dict.count("size") == 1){ part_atrs = new pq_coordinates(bunch,(int) params_dict["size"]); @@ -139,7 +139,7 @@ ParticleAttributes* ParticleAttributesFactory::getParticleAttributesInstance( if(name == "part_time"){ if(params_dict.size() == 0){ - cout<<"dictionary prf_time(dict) should be defined "<<"\n"; + std::cout<<"dictionary prf_time(dict) should be defined "<<"\n"; } else { if(params_dict.count("size") == 1){ part_atrs = new part_time(bunch, (int)params_dict["size"]); @@ -159,7 +159,7 @@ ParticleAttributes* ParticleAttributesFactory::getParticleAttributesInstance( if(name == "Evolution"){ if(params_dict.size() == 0){ - cout<<"dictionary Evolution(dict) should be defined "<<"\n"; + std::cout<<"dictionary Evolution(dict) should be defined "<<"\n"; } else { if(params_dict.count("size") == 1){ part_atrs = new Evolution(bunch, (int) params_dict["size"]); @@ -205,7 +205,7 @@ ParticleAttributes* ParticleAttributesFactory::getParticleAttributesInstance( return part_atrs; } -void ParticleAttributesFactory::getParticleAttributesNames(std::vector& names){ +void ParticleAttributesFactory::getParticleAttributesNames(std::vector& names){ names.clear(); names.push_back("macrosize"); names.push_back("ParticleIdNumber"); diff --git a/src/orbit/ParticlesAttributes/ParticleAttributesFactory.hh b/src/orbit/ParticlesAttributes/ParticleAttributesFactory.hh index 3a72aedf..b7361872 100644 --- a/src/orbit/ParticlesAttributes/ParticleAttributesFactory.hh +++ b/src/orbit/ParticlesAttributes/ParticleAttributesFactory.hh @@ -28,9 +28,9 @@ // INCLUDE FILES // /////////////////////////////////////////////////////////////////////////// -#include "../Bunch.hh" +#include "orbit/Bunch.hh" -#include "ParticleAttributes.hh" +#include "orbit/ParticlesAttributes/ParticleAttributes.hh" /////////////////////////////////////////////////////////////////////////// // // CLASS NAME @@ -47,12 +47,12 @@ class ParticleAttributesFactory //returns the name of the particle attributes bucket static ParticleAttributes* getParticleAttributesInstance( - const string name, + const std::string name, std::map part_attr_dict, Bunch* bunch); //returns the vector of possible particle attributes names - static void getParticleAttributesNames(std::vector& names); + static void getParticleAttributesNames(std::vector& names); private: ParticleAttributesFactory(); diff --git a/src/orbit/ParticlesAttributes/ParticleIdNumber.cc b/src/orbit/ParticlesAttributes/ParticleIdNumber.cc index a9431ab4..04916994 100644 --- a/src/orbit/ParticlesAttributes/ParticleIdNumber.cc +++ b/src/orbit/ParticlesAttributes/ParticleIdNumber.cc @@ -16,8 +16,8 @@ // /////////////////////////////////////////////////////////////////////////// -#include "../Bunch.hh" -#include "ParticleIdNumber.hh" +#include "orbit/Bunch.hh" +#include "orbit/ParticlesAttributes/ParticleIdNumber.hh" ParticleIdNumber::ParticleIdNumber(Bunch* bunch): ParticleAttributes(bunch,1) diff --git a/src/orbit/ParticlesAttributes/ParticleIdNumber.hh b/src/orbit/ParticlesAttributes/ParticleIdNumber.hh index 69fd79e5..ca2f2934 100644 --- a/src/orbit/ParticlesAttributes/ParticleIdNumber.hh +++ b/src/orbit/ParticlesAttributes/ParticleIdNumber.hh @@ -36,7 +36,7 @@ // ParticleIdNumber // /////////////////////////////////////////////////////////////////////////// -#include "ParticleAttributes.hh" +#include "orbit/ParticlesAttributes/ParticleAttributes.hh" class ParticleIdNumber : public ParticleAttributes { diff --git a/src/orbit/ParticlesAttributes/ParticleInitialCoordinates.cc b/src/orbit/ParticlesAttributes/ParticleInitialCoordinates.cc index 56d63685..b5c19331 100644 --- a/src/orbit/ParticlesAttributes/ParticleInitialCoordinates.cc +++ b/src/orbit/ParticlesAttributes/ParticleInitialCoordinates.cc @@ -23,8 +23,8 @@ // /////////////////////////////////////////////////////////////////////////// -#include "../Bunch.hh" -#include "ParticleInitialCoordinates.hh" +#include "orbit/Bunch.hh" +#include "orbit/ParticlesAttributes/ParticleInitialCoordinates.hh" ParticleInitialCoordinates::ParticleInitialCoordinates(Bunch* bunch): ParticleAttributes(bunch,6) diff --git a/src/orbit/ParticlesAttributes/ParticleInitialCoordinates.hh b/src/orbit/ParticlesAttributes/ParticleInitialCoordinates.hh index bc2032b2..cfc7d2c4 100644 --- a/src/orbit/ParticlesAttributes/ParticleInitialCoordinates.hh +++ b/src/orbit/ParticlesAttributes/ParticleInitialCoordinates.hh @@ -31,7 +31,7 @@ // /////////////////////////////////////////////////////////////////////////// #include -#include "ParticleAttributes.hh" +#include "orbit/ParticlesAttributes/ParticleAttributes.hh" class ParticleInitialCoordinates : public ParticleAttributes { diff --git a/src/orbit/ParticlesAttributes/ParticleMacroSize.cc b/src/orbit/ParticlesAttributes/ParticleMacroSize.cc index e182b5fc..4708e58d 100644 --- a/src/orbit/ParticlesAttributes/ParticleMacroSize.cc +++ b/src/orbit/ParticlesAttributes/ParticleMacroSize.cc @@ -16,8 +16,8 @@ // /////////////////////////////////////////////////////////////////////////// -#include "../Bunch.hh" -#include "ParticleMacroSize.hh" +#include "orbit/Bunch.hh" +#include "orbit/ParticlesAttributes/ParticleMacroSize.hh" ParticleMacroSize::ParticleMacroSize(Bunch* bunch): ParticleAttributes(bunch,1) diff --git a/src/orbit/ParticlesAttributes/ParticleMacroSize.hh b/src/orbit/ParticlesAttributes/ParticleMacroSize.hh index 7623d10d..c0697c56 100644 --- a/src/orbit/ParticlesAttributes/ParticleMacroSize.hh +++ b/src/orbit/ParticlesAttributes/ParticleMacroSize.hh @@ -17,9 +17,9 @@ #ifndef PARTICLE_MACROSIZE_H #define PARTICLE_MACROSIZE_H -#include "../../mpi/orbit_mpi.hh" +#include "mpi/orbit_mpi.hh" -#include "ParticleAttributes.hh" +#include "orbit/ParticlesAttributes/ParticleAttributes.hh" #include diff --git a/src/orbit/ParticlesAttributes/ParticlePhaseAttributes.cc b/src/orbit/ParticlesAttributes/ParticlePhaseAttributes.cc index 1ec7fc8e..65fd9f7e 100644 --- a/src/orbit/ParticlesAttributes/ParticlePhaseAttributes.cc +++ b/src/orbit/ParticlesAttributes/ParticlePhaseAttributes.cc @@ -15,8 +15,8 @@ // /////////////////////////////////////////////////////////////////////////// -#include "../Bunch.hh" -#include "ParticlePhaseAttributes.hh" +#include "orbit/Bunch.hh" +#include "orbit/ParticlesAttributes/ParticlePhaseAttributes.hh" ParticlePhaseAttributes::ParticlePhaseAttributes(Bunch* bunch): ParticleAttributes(bunch,6) diff --git a/src/orbit/ParticlesAttributes/ParticlePhaseAttributes.hh b/src/orbit/ParticlesAttributes/ParticlePhaseAttributes.hh index 3e676992..edf91bf7 100644 --- a/src/orbit/ParticlesAttributes/ParticlePhaseAttributes.hh +++ b/src/orbit/ParticlesAttributes/ParticlePhaseAttributes.hh @@ -21,7 +21,7 @@ // INCLUDE FILES // /////////////////////////////////////////////////////////////////////////// -#include "ParticleAttributes.hh" +#include "orbit/ParticlesAttributes/ParticleAttributes.hh" class ParticlePhaseAttributes : public ParticleAttributes { diff --git a/src/orbit/ParticlesAttributes/TurnNumberAttributes.cc b/src/orbit/ParticlesAttributes/TurnNumberAttributes.cc index 4ae1d529..e3579791 100644 --- a/src/orbit/ParticlesAttributes/TurnNumberAttributes.cc +++ b/src/orbit/ParticlesAttributes/TurnNumberAttributes.cc @@ -21,8 +21,8 @@ // /////////////////////////////////////////////////////////////////////////// -#include "../Bunch.hh" -#include "TurnNumberAttributes.hh" +#include "orbit/Bunch.hh" +#include "orbit/ParticlesAttributes/TurnNumberAttributes.hh" TurnNumberAttributes::TurnNumberAttributes(Bunch* bunch): ParticleAttributes(bunch,1) diff --git a/src/orbit/ParticlesAttributes/TurnNumberAttributes.hh b/src/orbit/ParticlesAttributes/TurnNumberAttributes.hh index 36fcbe7c..d5012c1d 100644 --- a/src/orbit/ParticlesAttributes/TurnNumberAttributes.hh +++ b/src/orbit/ParticlesAttributes/TurnNumberAttributes.hh @@ -26,7 +26,7 @@ #include -#include "ParticleAttributes.hh" +#include "orbit/ParticlesAttributes/ParticleAttributes.hh" class TurnNumberAttributes : public ParticleAttributes { diff --git a/src/orbit/ParticlesAttributes/WaveFunctionAmplitudes.cc b/src/orbit/ParticlesAttributes/WaveFunctionAmplitudes.cc index 55c065cb..75aad7d8 100644 --- a/src/orbit/ParticlesAttributes/WaveFunctionAmplitudes.cc +++ b/src/orbit/ParticlesAttributes/WaveFunctionAmplitudes.cc @@ -15,8 +15,8 @@ // /////////////////////////////////////////////////////////////////////////// -#include "../Bunch.hh" -#include "WaveFunctionAmplitudes.hh" +#include "orbit/Bunch.hh" +#include "orbit/ParticlesAttributes/WaveFunctionAmplitudes.hh" WaveFunctionAmplitudes::WaveFunctionAmplitudes(Bunch* bunch, int size_in): ParticleAttributes(bunch, size_in) diff --git a/src/orbit/ParticlesAttributes/WaveFunctionAmplitudes.hh b/src/orbit/ParticlesAttributes/WaveFunctionAmplitudes.hh index 2c77e818..020c32fb 100644 --- a/src/orbit/ParticlesAttributes/WaveFunctionAmplitudes.hh +++ b/src/orbit/ParticlesAttributes/WaveFunctionAmplitudes.hh @@ -18,7 +18,7 @@ #include -#include "ParticleAttributes.hh" +#include "orbit/ParticlesAttributes/ParticleAttributes.hh" class WaveFunctionAmplitudes : public ParticleAttributes { diff --git a/src/orbit/ParticlesAttributes/part_time.cc b/src/orbit/ParticlesAttributes/part_time.cc index f0341e48..840c7f7c 100644 --- a/src/orbit/ParticlesAttributes/part_time.cc +++ b/src/orbit/ParticlesAttributes/part_time.cc @@ -16,8 +16,8 @@ // /////////////////////////////////////////////////////////////////////////// -#include "../Bunch.hh" -#include "part_time.hh" +#include "orbit/Bunch.hh" +#include "orbit/ParticlesAttributes/part_time.hh" part_time::part_time(Bunch* bunch, int size_in): ParticleAttributes(bunch,size_in) diff --git a/src/orbit/ParticlesAttributes/part_time.hh b/src/orbit/ParticlesAttributes/part_time.hh index 71ae8ae2..662e390d 100644 --- a/src/orbit/ParticlesAttributes/part_time.hh +++ b/src/orbit/ParticlesAttributes/part_time.hh @@ -36,7 +36,7 @@ // WaveFunctionAmplitudes // /////////////////////////////////////////////////////////////////////////// -#include "ParticleAttributes.hh" +#include "orbit/ParticlesAttributes/ParticleAttributes.hh" class part_time : public ParticleAttributes { diff --git a/src/orbit/ParticlesAttributes/pq_coordinates.cc b/src/orbit/ParticlesAttributes/pq_coordinates.cc index c00ed4dc..a8d89a48 100644 --- a/src/orbit/ParticlesAttributes/pq_coordinates.cc +++ b/src/orbit/ParticlesAttributes/pq_coordinates.cc @@ -15,8 +15,8 @@ // /////////////////////////////////////////////////////////////////////////// -#include "../Bunch.hh" -#include "pq_coordinates.hh" +#include "orbit/Bunch.hh" +#include "orbit/ParticlesAttributes/pq_coordinates.hh" pq_coordinates::pq_coordinates(Bunch* bunch, int size_in): ParticleAttributes(bunch,size_in) diff --git a/src/orbit/ParticlesAttributes/pq_coordinates.hh b/src/orbit/ParticlesAttributes/pq_coordinates.hh index 45439411..1d9fdbf8 100644 --- a/src/orbit/ParticlesAttributes/pq_coordinates.hh +++ b/src/orbit/ParticlesAttributes/pq_coordinates.hh @@ -23,7 +23,7 @@ /////////////////////////////////////////////////////////////////////////// #include -#include "ParticleAttributes.hh" +#include "orbit/ParticlesAttributes/ParticleAttributes.hh" class pq_coordinates : public ParticleAttributes { diff --git a/src/orbit/RFCavities/Barrier_Cav.cc b/src/orbit/RFCavities/Barrier_Cav.cc index 0a95ce5a..23761b6c 100644 --- a/src/orbit/RFCavities/Barrier_Cav.cc +++ b/src/orbit/RFCavities/Barrier_Cav.cc @@ -1,11 +1,11 @@ -#include "Barrier_Cav.hh" -#include "ParticleMacroSize.hh" +#include "orbit/RFCavities/Barrier_Cav.hh" +#include "orbit/ParticlesAttributes/ParticleMacroSize.hh" #include #include -#include "Bunch.hh" -#include "OrbitConst.hh" +#include "orbit/Bunch.hh" +#include "orbit/OrbitConst.hh" using namespace OrbitUtils; @@ -15,7 +15,7 @@ Barrier_Cav::Barrier_Cav(double ZtoPhi, double RFPhasep, double RFPhasem, double dRFPhasep, - double dRFPhasem): CppPyWrapper(NULL) + double dRFPhasem) { _ZtoPhi = ZtoPhi; _RFVoltage = RFVoltage; diff --git a/src/orbit/RFCavities/Barrier_Cav.hh b/src/orbit/RFCavities/Barrier_Cav.hh index 0c49c5fe..7fbf72c4 100644 --- a/src/orbit/RFCavities/Barrier_Cav.hh +++ b/src/orbit/RFCavities/Barrier_Cav.hh @@ -2,21 +2,18 @@ #define BARRIER_CAV_H //MPI Function Wrappers -#include "orbit_mpi.hh" -#include "wrap_mpi_comm.hh" +#include "mpi/orbit_mpi.hh" #include #include //ORBIT bunch -#include "Bunch.hh" +#include "orbit/Bunch.hh" //pyORBIT utils -#include "CppPyWrapper.hh" -using namespace std; -class Barrier_Cav: public OrbitUtils::CppPyWrapper +class Barrier_Cav { public: Barrier_Cav(double ZtoPhi, double RFVoltage, diff --git a/src/orbit/RFCavities/Dual_Harmonic_Cav.cc b/src/orbit/RFCavities/Dual_Harmonic_Cav.cc index 610cbf57..3979efd4 100644 --- a/src/orbit/RFCavities/Dual_Harmonic_Cav.cc +++ b/src/orbit/RFCavities/Dual_Harmonic_Cav.cc @@ -1,11 +1,11 @@ -#include "Dual_Harmonic_Cav.hh" -#include "ParticleMacroSize.hh" +#include "orbit/RFCavities/Dual_Harmonic_Cav.hh" +#include "orbit/ParticlesAttributes/ParticleMacroSize.hh" #include #include -#include "Bunch.hh" -#include "OrbitConst.hh" +#include "orbit/Bunch.hh" +#include "orbit/OrbitConst.hh" using namespace OrbitUtils; @@ -16,7 +16,7 @@ Dual_Harmonic_Cav::Dual_Harmonic_Cav(double ZtoPhi , double RFVoltage, double RatioVoltage, double RFPhase, - double RFPhase2): CppPyWrapper(NULL) + double RFPhase2) { _ZtoPhi = ZtoPhi; _RFHNum = RFHNum; diff --git a/src/orbit/RFCavities/Dual_Harmonic_Cav.hh b/src/orbit/RFCavities/Dual_Harmonic_Cav.hh index 64c396b6..66ef4455 100644 --- a/src/orbit/RFCavities/Dual_Harmonic_Cav.hh +++ b/src/orbit/RFCavities/Dual_Harmonic_Cav.hh @@ -2,21 +2,18 @@ #define Dual_Harmonic_Cav_H //MPI Function Wrappers -#include "orbit_mpi.hh" -#include "wrap_mpi_comm.hh" +#include "mpi/orbit_mpi.hh" #include #include //ORBIT bunch -#include "Bunch.hh" +#include "orbit/Bunch.hh" //pyORBIT utils -#include "CppPyWrapper.hh" -using namespace std; -class Dual_Harmonic_Cav: public OrbitUtils::CppPyWrapper +class Dual_Harmonic_Cav { public: Dual_Harmonic_Cav(double ZtoPhi, double RFHNum, diff --git a/src/orbit/RFCavities/Frequency_Cav.cc b/src/orbit/RFCavities/Frequency_Cav.cc index 0777f449..300d12a5 100644 --- a/src/orbit/RFCavities/Frequency_Cav.cc +++ b/src/orbit/RFCavities/Frequency_Cav.cc @@ -1,19 +1,19 @@ -#include "Frequency_Cav.hh" -#include "ParticleMacroSize.hh" +#include "orbit/RFCavities/Frequency_Cav.hh" +#include "orbit/ParticlesAttributes/ParticleMacroSize.hh" #include #include -#include "Bunch.hh" -#include "bessel.hh" -#include "OrbitConst.hh" +#include "orbit/Bunch.hh" +#include "utils/bessel.hh" +#include "orbit/OrbitConst.hh" using namespace OrbitUtils; // Constructor Frequency_Cav::Frequency_Cav(double RFFreq, double RFE0TL, - double RFPhase): CppPyWrapper(NULL) + double RFPhase) { _RFFreq = RFFreq; _RFE0TL = RFE0TL; diff --git a/src/orbit/RFCavities/Frequency_Cav.hh b/src/orbit/RFCavities/Frequency_Cav.hh index 3f424514..bcc564be 100644 --- a/src/orbit/RFCavities/Frequency_Cav.hh +++ b/src/orbit/RFCavities/Frequency_Cav.hh @@ -2,21 +2,18 @@ #define FREQUENCY_CAV_H //MPI Function Wrappers -#include "orbit_mpi.hh" -#include "wrap_mpi_comm.hh" +#include "mpi/orbit_mpi.hh" #include #include //ORBIT bunch -#include "Bunch.hh" +#include "orbit/Bunch.hh" //pyORBIT utils -#include "CppPyWrapper.hh" -using namespace std; -class Frequency_Cav: public OrbitUtils::CppPyWrapper +class Frequency_Cav { public: Frequency_Cav(double RFFreq, double RFE0TL, double RFPhase); diff --git a/src/orbit/RFCavities/Harmonic_Cav.cc b/src/orbit/RFCavities/Harmonic_Cav.cc index 8b893235..7da3725e 100644 --- a/src/orbit/RFCavities/Harmonic_Cav.cc +++ b/src/orbit/RFCavities/Harmonic_Cav.cc @@ -1,11 +1,11 @@ -#include "Harmonic_Cav.hh" -#include "ParticleMacroSize.hh" +#include "orbit/RFCavities/Harmonic_Cav.hh" +#include "orbit/ParticlesAttributes/ParticleMacroSize.hh" #include #include -#include "Bunch.hh" -#include "OrbitConst.hh" +#include "orbit/Bunch.hh" +#include "orbit/OrbitConst.hh" using namespace OrbitUtils; @@ -14,7 +14,7 @@ Harmonic_Cav::Harmonic_Cav(double ZtoPhi , double dESync , double RFHNum , double RFVoltage, - double RFPhase): CppPyWrapper(NULL) + double RFPhase) { _ZtoPhi = ZtoPhi; _dESync = dESync; diff --git a/src/orbit/RFCavities/Harmonic_Cav.hh b/src/orbit/RFCavities/Harmonic_Cav.hh index a538e8d7..a83eebc2 100644 --- a/src/orbit/RFCavities/Harmonic_Cav.hh +++ b/src/orbit/RFCavities/Harmonic_Cav.hh @@ -2,21 +2,18 @@ #define HARMONIC_CAV_H //MPI Function Wrappers -#include "orbit_mpi.hh" -#include "wrap_mpi_comm.hh" +#include "mpi/orbit_mpi.hh" #include #include //ORBIT bunch -#include "Bunch.hh" +#include "orbit/Bunch.hh" //pyORBIT utils -#include "CppPyWrapper.hh" -using namespace std; -class Harmonic_Cav: public OrbitUtils::CppPyWrapper +class Harmonic_Cav { public: Harmonic_Cav(double ZtoPhi, double dESync , diff --git a/src/orbit/RFCavities/wrap_Barrier_Cav.cc b/src/orbit/RFCavities/wrap_Barrier_Cav.cc index 3f360f7b..938f6b50 100644 --- a/src/orbit/RFCavities/wrap_Barrier_Cav.cc +++ b/src/orbit/RFCavities/wrap_Barrier_Cav.cc @@ -1,12 +1,12 @@ -#include "orbit_mpi.hh" -#include "pyORBIT_Object.hh" +#include "mpi/orbit_mpi.hh" +#include "main/pyORBIT_Object.hh" -#include "wrap_Barrier_Cav.hh" -#include "wrap_bunch.hh" +#include "orbit/RFCavities/wrap_Barrier_Cav.hh" +#include "orbit/wrap_bunch.hh" #include -#include "Barrier_Cav.hh" +#include "orbit/RFCavities/Barrier_Cav.hh" using namespace OrbitUtils; @@ -69,7 +69,6 @@ static int Barrier_Cav_init(pyORBIT_Object *self, RFPhasem, dRFPhasep, dRFPhasem); - ((Barrier_Cav*) self->cpp_obj)->setPyWrapper((PyObject*) self); return 0; } diff --git a/src/orbit/RFCavities/wrap_Barrier_Cav.hh b/src/orbit/RFCavities/wrap_Barrier_Cav.hh index ccb7d80d..13b6760f 100644 --- a/src/orbit/RFCavities/wrap_Barrier_Cav.hh +++ b/src/orbit/RFCavities/wrap_Barrier_Cav.hh @@ -1,7 +1,7 @@ #ifndef WRAP_BARRIER_CAV_H #define WRAP_BARRIER_CAV_H -#include "Python.h" +#include #ifdef __cplusplus extern "C" diff --git a/src/orbit/RFCavities/wrap_Dual_Harmonic_Cav.cc b/src/orbit/RFCavities/wrap_Dual_Harmonic_Cav.cc index bf9b7b32..232400d5 100644 --- a/src/orbit/RFCavities/wrap_Dual_Harmonic_Cav.cc +++ b/src/orbit/RFCavities/wrap_Dual_Harmonic_Cav.cc @@ -1,12 +1,12 @@ -#include "orbit_mpi.hh" -#include "pyORBIT_Object.hh" +#include "mpi/orbit_mpi.hh" +#include "main/pyORBIT_Object.hh" -#include "wrap_Dual_Harmonic_Cav.hh" -#include "wrap_bunch.hh" +#include "orbit/RFCavities/wrap_Dual_Harmonic_Cav.hh" +#include "orbit/wrap_bunch.hh" #include -#include "Dual_Harmonic_Cav.hh" +#include "orbit/RFCavities/Dual_Harmonic_Cav.hh" using namespace OrbitUtils; @@ -72,7 +72,6 @@ static int Dual_Harmonic_Cav_init(pyORBIT_Object *self, RatioVoltage, RFPhase, RFPhase2); - ((Dual_Harmonic_Cav*) self->cpp_obj)->setPyWrapper((PyObject*) self); return 0; } diff --git a/src/orbit/RFCavities/wrap_Dual_Harmonic_Cav.hh b/src/orbit/RFCavities/wrap_Dual_Harmonic_Cav.hh index d12449e6..5b6f969a 100644 --- a/src/orbit/RFCavities/wrap_Dual_Harmonic_Cav.hh +++ b/src/orbit/RFCavities/wrap_Dual_Harmonic_Cav.hh @@ -1,7 +1,7 @@ #ifndef WRAP_Dual_Harmonic_Cav_H #define WRAP_Dual_Harmonic_Cav_H -#include "Python.h" +#include #ifdef __cplusplus extern "C" diff --git a/src/orbit/RFCavities/wrap_Frequency_Cav.cc b/src/orbit/RFCavities/wrap_Frequency_Cav.cc index b245b043..fae840a3 100644 --- a/src/orbit/RFCavities/wrap_Frequency_Cav.cc +++ b/src/orbit/RFCavities/wrap_Frequency_Cav.cc @@ -1,12 +1,12 @@ -#include "orbit_mpi.hh" -#include "pyORBIT_Object.hh" +#include "mpi/orbit_mpi.hh" +#include "main/pyORBIT_Object.hh" -#include "wrap_Frequency_Cav.hh" -#include "wrap_bunch.hh" +#include "orbit/RFCavities/wrap_Frequency_Cav.hh" +#include "orbit/wrap_bunch.hh" #include -#include "Frequency_Cav.hh" +#include "orbit/RFCavities/Frequency_Cav.hh" using namespace OrbitUtils; @@ -54,7 +54,6 @@ static int Frequency_Cav_init(pyORBIT_Object *self, PyObject *args, PyObject *kw ORBIT_MPI_Finalize("PyFrequency_Cav - Frequency_Cav_init - cannot parse arguments! They should be (RFFreq, RFE0TL, RFPhase)"); } self->cpp_obj = new Frequency_Cav(RFFreq, RFE0TL, RFPhase); - ((Frequency_Cav*) self->cpp_obj)->setPyWrapper((PyObject*) self); return 0; } diff --git a/src/orbit/RFCavities/wrap_Frequency_Cav.hh b/src/orbit/RFCavities/wrap_Frequency_Cav.hh index c2e8333d..e3311012 100644 --- a/src/orbit/RFCavities/wrap_Frequency_Cav.hh +++ b/src/orbit/RFCavities/wrap_Frequency_Cav.hh @@ -1,7 +1,7 @@ #ifndef WRAP_FREQUENCY_CAV_H #define WRAP_FREQUENCY_CAV_H -#include "Python.h" +#include #ifdef __cplusplus extern "C" diff --git a/src/orbit/RFCavities/wrap_Harmonic_Cav.cc b/src/orbit/RFCavities/wrap_Harmonic_Cav.cc index 11ce38e7..5d844677 100644 --- a/src/orbit/RFCavities/wrap_Harmonic_Cav.cc +++ b/src/orbit/RFCavities/wrap_Harmonic_Cav.cc @@ -1,12 +1,12 @@ -#include "orbit_mpi.hh" -#include "pyORBIT_Object.hh" +#include "mpi/orbit_mpi.hh" +#include "main/pyORBIT_Object.hh" -#include "wrap_Harmonic_Cav.hh" -#include "wrap_bunch.hh" +#include "orbit/RFCavities/wrap_Harmonic_Cav.hh" +#include "orbit/wrap_bunch.hh" #include -#include "Harmonic_Cav.hh" +#include "orbit/RFCavities/Harmonic_Cav.hh" using namespace OrbitUtils; @@ -66,7 +66,6 @@ static int Harmonic_Cav_init(pyORBIT_Object *self, RFHNum, RFVoltage, RFPhase); - ((Harmonic_Cav*) self->cpp_obj)->setPyWrapper((PyObject*) self); return 0; } diff --git a/src/orbit/RFCavities/wrap_Harmonic_Cav.hh b/src/orbit/RFCavities/wrap_Harmonic_Cav.hh index 63710662..5b686371 100644 --- a/src/orbit/RFCavities/wrap_Harmonic_Cav.hh +++ b/src/orbit/RFCavities/wrap_Harmonic_Cav.hh @@ -1,7 +1,7 @@ #ifndef WRAP_HARMONIC_CAV_H #define WRAP_HARMONIC_CAV_H -#include "Python.h" +#include #ifdef __cplusplus extern "C" diff --git a/src/orbit/RFCavities/wrap_rfcavities.cc b/src/orbit/RFCavities/wrap_rfcavities.cc index 4034c5dd..209ae43a 100644 --- a/src/orbit/RFCavities/wrap_rfcavities.cc +++ b/src/orbit/RFCavities/wrap_rfcavities.cc @@ -1,9 +1,9 @@ -#include "orbit_mpi.hh" +#include "mpi/orbit_mpi.hh" -#include "wrap_Frequency_Cav.hh" -#include "wrap_Harmonic_Cav.hh" -#include "wrap_Barrier_Cav.hh" -#include "wrap_Dual_Harmonic_Cav.hh" +#include "orbit/RFCavities/wrap_Frequency_Cav.hh" +#include "orbit/RFCavities/wrap_Harmonic_Cav.hh" +#include "orbit/RFCavities/wrap_Barrier_Cav.hh" +#include "orbit/RFCavities/wrap_Dual_Harmonic_Cav.hh" static PyMethodDef rfcavitiesMethods[] = {{NULL,NULL}}; diff --git a/src/orbit/RFCavities/wrap_rfcavities.hh b/src/orbit/RFCavities/wrap_rfcavities.hh index 1a327081..cecebb20 100644 --- a/src/orbit/RFCavities/wrap_rfcavities.hh +++ b/src/orbit/RFCavities/wrap_rfcavities.hh @@ -1,7 +1,7 @@ #ifndef WRAP_RFCAVITIES_H #define WRAP_RFCAVITIES_H -#include "Python.h" +#include #ifdef __cplusplus extern "C" diff --git a/src/orbit/SyncPart.cc b/src/orbit/SyncPart.cc index 6494ecbf..2ba19eb7 100644 --- a/src/orbit/SyncPart.cc +++ b/src/orbit/SyncPart.cc @@ -24,15 +24,15 @@ // INCLUDE FILES // /////////////////////////////////////////////////////////////////////////// -#include "Python.h" +#include "orbit/SyncPart.hh" -#include "SyncPart.hh" - -#include "Bunch.hh" -#include "OrbitConst.hh" -#include "StringUtils.hh" -#include "BufferStore.hh" +#include "orbit/Bunch.hh" +#include "orbit/OrbitConst.hh" +#include "utils/StringUtils.hh" +#include "utils/BufferStore.hh" +#include +#include #include #include @@ -55,24 +55,11 @@ SyncPart::SyncPart(Bunch* bunchIn) SyncPart::~SyncPart() { - Py_XDECREF(py_wrapper); -} - -void SyncPart::setPyWrapper(PyObject* py_wrapper_In){ - if(py_wrapper != NULL) Py_XDECREF(py_wrapper); - Py_INCREF(py_wrapper_In); - py_wrapper = py_wrapper_In; -} - -PyObject* SyncPart::getPyWrapper(){ - return py_wrapper; } //initialization all necessary variables and attributes void SyncPart::init() { - py_wrapper = NULL; - energy = 0.; time = 0.; @@ -326,7 +313,7 @@ void SyncPart::readSyncPart(const char* fileName){ int rank_MPI = 0; int size_MPI = 1; int iMPIini = 0; - MPI_Comm MPI_COMM_Local = bunch->getMPI_Comm_Local()->comm; + MPI_Comm MPI_COMM_Local = bunch->getMPI_Comm_Local(); ORBIT_MPI_Initialized(&iMPIini); if(iMPIini > 0){ @@ -337,7 +324,7 @@ void SyncPart::readSyncPart(const char* fileName){ std::vector attr_names; attr_names.clear(); - ifstream is; + std::ifstream is; int error_ind = 0; if(rank_MPI == 0){ @@ -358,7 +345,7 @@ void SyncPart::readSyncPart(const char* fileName){ } std::string str; - std::vector v_str; + std::vector v_str; int stop_ind = 0; int def_found_ind = 0; @@ -469,7 +456,7 @@ void SyncPart::print(std::ostream& Out) int rank_MPI = 0; int size_MPI = 1; int iMPIini = 0; - MPI_Comm MPI_COMM_Local = bunch->getMPI_Comm_Local()->comm; + MPI_Comm MPI_COMM_Local = bunch->getMPI_Comm_Local(); ORBIT_MPI_Initialized(&iMPIini); if(iMPIini > 0){ diff --git a/src/orbit/SyncPart.hh b/src/orbit/SyncPart.hh index d14aa9ba..48f408aa 100644 --- a/src/orbit/SyncPart.hh +++ b/src/orbit/SyncPart.hh @@ -23,7 +23,7 @@ // INCLUDE FILES // /////////////////////////////////////////////////////////////////////////// -#include "orbit_mpi.hh" +#include "mpi/orbit_mpi.hh" #include #include @@ -35,7 +35,6 @@ #include #include -using namespace std; #ifndef SYNC_PARTICLE_H #define SYNC_PARTICLE_H @@ -55,9 +54,6 @@ class SyncPart //-------------------------------------- virtual ~SyncPart(); - void setPyWrapper(PyObject* py_wrapper_In); - PyObject* getPyWrapper(); - /** Kinetic energy in GeV */ @@ -134,7 +130,7 @@ private: friend class Bunch; - SyncPart(Bunch* bunch); + SyncPart(Bunch* bunch); //initilaze the sync. particle from file void readSyncPart(const char* fileName); @@ -143,7 +139,6 @@ private: void print(std::ostream& Out); Bunch* bunch; - PyObject* py_wrapper; //-------------------------------------------- //parameters diff --git a/src/orbit/SynchPartRedefinition/SynchPartRedefinitionZdE.cc b/src/orbit/SynchPartRedefinition/SynchPartRedefinitionZdE.cc index 22021ae7..24b0721b 100644 --- a/src/orbit/SynchPartRedefinition/SynchPartRedefinitionZdE.cc +++ b/src/orbit/SynchPartRedefinition/SynchPartRedefinitionZdE.cc @@ -1,4 +1,4 @@ -#include "SynchPartRedefinitionZdE.hh" +#include "orbit/SynchPartRedefinition/SynchPartRedefinitionZdE.hh" #include #include @@ -6,13 +6,13 @@ #include //#include "Bunch.hh" -#include "ParticlesAttributes/ParticleMacroSize.hh" -#include "SyncPart.hh" +#include "orbit/ParticlesAttributes/ParticleMacroSize.hh" +#include "orbit/SyncPart.hh" -#include "OrbitConst.hh" +#include "orbit/OrbitConst.hh" /** Constructor */ -SynchPartRedefinitionZdE::SynchPartRedefinitionZdE(): CppPyWrapper(NULL) +SynchPartRedefinitionZdE::SynchPartRedefinitionZdE() { z_dE_avg_arr = (double* ) malloc (2*sizeof(double)); @@ -70,14 +70,14 @@ void SynchPartRedefinitionZdE::analyzeBunch(Bunch* bunch){ } int count_MPI = 0; - ORBIT_MPI_Allreduce(&count,&count_MPI,1,MPI_INT,MPI_SUM,bunch->getMPI_Comm_Local()->comm); + ORBIT_MPI_Allreduce(&count,&count_MPI,1,MPI_INT,MPI_SUM,bunch->getMPI_Comm_Local()); count = count_MPI; double total_macrosize_MPI = 0.; - ORBIT_MPI_Allreduce(&total_macrosize,&total_macrosize_MPI,1,MPI_DOUBLE,MPI_SUM,bunch->getMPI_Comm_Local()->comm); + ORBIT_MPI_Allreduce(&total_macrosize,&total_macrosize_MPI,1,MPI_DOUBLE,MPI_SUM,bunch->getMPI_Comm_Local()); total_macrosize = total_macrosize_MPI; - ORBIT_MPI_Allreduce(z_dE_avg_arr,z_dE_avg_arr_MPI,2,MPI_DOUBLE,MPI_SUM,bunch->getMPI_Comm_Local()->comm); + ORBIT_MPI_Allreduce(z_dE_avg_arr,z_dE_avg_arr_MPI,2,MPI_DOUBLE,MPI_SUM,bunch->getMPI_Comm_Local()); if(fabs(total_macrosize) > 0.){ for(int i = 0; i < 2; i++){ diff --git a/src/orbit/SynchPartRedefinition/SynchPartRedefinitionZdE.hh b/src/orbit/SynchPartRedefinition/SynchPartRedefinitionZdE.hh index 7c920ecb..d31b65b7 100644 --- a/src/orbit/SynchPartRedefinition/SynchPartRedefinitionZdE.hh +++ b/src/orbit/SynchPartRedefinition/SynchPartRedefinitionZdE.hh @@ -2,11 +2,9 @@ #define SYNCH_PARTICLE_REDEFINITION_H //pyORBIT utils -#include "CppPyWrapper.hh" -#include "Bunch.hh" +#include "orbit/Bunch.hh" -using namespace std; /** The SynchPartRedefinitionZdE class calculates the average of z and dE coordinates @@ -14,7 +12,7 @@ using namespace std; to the center of the bunch's phase space. */ -class SynchPartRedefinitionZdE: public OrbitUtils::CppPyWrapper +class SynchPartRedefinitionZdE { public: diff --git a/src/orbit/SynchPartRedefinition/wrap_synch_part_redefinition_z_de.cc b/src/orbit/SynchPartRedefinition/wrap_synch_part_redefinition_z_de.cc index c834a765..cec7efbd 100644 --- a/src/orbit/SynchPartRedefinition/wrap_synch_part_redefinition_z_de.cc +++ b/src/orbit/SynchPartRedefinition/wrap_synch_part_redefinition_z_de.cc @@ -1,12 +1,12 @@ -#include "orbit_mpi.hh" -#include "pyORBIT_Object.hh" +#include "mpi/orbit_mpi.hh" +#include "main/pyORBIT_Object.hh" -#include "wrap_synch_part_redefinition_z_de.hh" -#include "wrap_bunch.hh" +#include "orbit/SynchPartRedefinition/wrap_synch_part_redefinition_z_de.hh" +#include "orbit/wrap_bunch.hh" #include -#include "SynchPartRedefinitionZdE.hh" +#include "orbit/SynchPartRedefinition/SynchPartRedefinitionZdE.hh" namespace wrap_synch_part_redefinition{ @@ -30,7 +30,6 @@ extern "C" { /** This is implementation of the __init__ method */ static int SynchPartRedefinitionZdE_init(pyORBIT_Object *self, PyObject *args, PyObject *kwds){ self->cpp_obj = new SynchPartRedefinitionZdE(); - ((SynchPartRedefinitionZdE*) self->cpp_obj)->setPyWrapper((PyObject*) self); return 0; } diff --git a/src/orbit/SynchPartRedefinition/wrap_synch_part_redefinition_z_de.hh b/src/orbit/SynchPartRedefinition/wrap_synch_part_redefinition_z_de.hh index ef7ace81..2df15fb3 100644 --- a/src/orbit/SynchPartRedefinition/wrap_synch_part_redefinition_z_de.hh +++ b/src/orbit/SynchPartRedefinition/wrap_synch_part_redefinition_z_de.hh @@ -1,7 +1,7 @@ #ifndef WRAP_SYNCH_PARTICLE_REDEFINITION_HH_ #define WRAP_SYNCH_PARTICLE_REDEFINITION_HH_ -#include "Python.h" +#include #ifdef __cplusplus extern "C" { diff --git a/src/orbit/wrap_bunch.cc b/src/orbit/wrap_bunch.cc index 8bda038d..2fd74023 100644 --- a/src/orbit/wrap_bunch.cc +++ b/src/orbit/wrap_bunch.cc @@ -8,19 +8,35 @@ // INCLUDE FILES // /////////////////////////////////////////////////////////////////////////// -#include "wrap_bunch.hh" -#include "wrap_syncpart.hh" -#include "wrap_bunch_twiss_analysis.hh" -#include "wrap_bunch_tune_analysis.hh" -#include "wrap_synch_part_redefinition_z_de.hh" +#include "orbit/wrap_bunch.hh" +#include "mpi/wrap_mpi_comm.hh" +#include "orbit/wrap_syncpart.hh" +#include "orbit/BunchDiagnostics/wrap_bunch_twiss_analysis.hh" +#include "orbit/BunchDiagnostics/wrap_bunch_tune_analysis.hh" +#include "orbit/SynchPartRedefinition/wrap_synch_part_redefinition_z_de.hh" -#include "pyORBIT_Object.hh" +#include "main/pyORBIT_Object.hh" -#include "Bunch.hh" -#include "ParticleAttributesFactory.hh" +#include "orbit/Bunch.hh" +#include "orbit/ParticlesAttributes/ParticleAttributesFactory.hh" namespace wrap_orbit_bunch{ + typedef struct { + pyORBIT_Object base; + PyObject* mpi_comm; + PyObject* sync_part; + } pyORBIT_Bunch; + + PyObject* getSyncPartWrapper(PyObject* pyBunch){ + return ((pyORBIT_Bunch*) pyBunch)->sync_part; + } + + static void setMPICommOwner(pyORBIT_Bunch* bunch, PyObject* mpi_comm){ + Py_INCREF(mpi_comm); + Py_XSETREF(bunch->mpi_comm, mpi_comm); + } + void error(const char* msg){ ORBIT_MPI_Finalize(msg); } //--------------------------------------------------------- //Python Bunch class definition @@ -28,30 +44,49 @@ namespace wrap_orbit_bunch{ //constructor for python class wrapping Bunch instance //It never will be called directly - static PyObject* Bunch_new(PyTypeObject *type, PyObject *args, PyObject *kwds){ - pyORBIT_Object* self; - self = (pyORBIT_Object *) type->tp_alloc(type, 0); - self->cpp_obj = NULL; + static PyObject* Bunch_new(PyTypeObject *type, PyObject *Py_UNUSED(args), PyObject *Py_UNUSED(kwds)) { + pyORBIT_Bunch* self; + self = (pyORBIT_Bunch *) type->tp_alloc(type, 0); + if (self == NULL) { + return NULL; + } + self->base.cpp_obj = NULL; + self->mpi_comm = NULL; + self->sync_part = NULL; return (PyObject *) self; } //initializator for python Bunch class //this is implementation of the __init__ method - static int Bunch_init(pyORBIT_Object *self, PyObject *args, PyObject *kwds){ + static int Bunch_init(pyORBIT_Bunch *self, PyObject *Py_UNUSED(args), PyObject *Py_UNUSED(kwds)){ //std::cerr<<"The Bunch __init__ has been called!"<cpp_obj = (void*) new Bunch(); - ((Bunch*) self->cpp_obj)->setPyWrapper((PyObject*) self); + self->base.cpp_obj = (void*) new Bunch(); + pyorbit::registerPyWrapper(self->base.cpp_obj, (PyObject*) self); + + PyObject* mpi_comm_type = wrap_orbit_mpi_comm::getMPI_CommType("MPI_Comm"); + if (mpi_comm_type == NULL) { + return -1; + } + self->mpi_comm = PyObject_CallNoArgs(mpi_comm_type); + if (self->mpi_comm == NULL) { + return -1; + } //This is the way to create new class instance from the C-level // Template: PyObject* PyObject_CallMethod( PyObject *o, char *method, char *format, ...) //see Python/C API documentation //It will create a SyncParticle object and set the reference to it from pyBunch PyObject* mod = PyImport_ImportModule("orbit.core.bunch"); + if (mod == NULL) { + return -1; + } PyObject* pySyncPart = PyObject_CallMethod(mod,const_cast("SyncParticle"),const_cast("O"),self); - - //the references should be decreased because they were created as "new reference" - Py_DECREF(pySyncPart); Py_DECREF(mod); + if (pySyncPart == NULL) { + return -1; + } + + self->sync_part = pySyncPart; return 0; } @@ -62,9 +97,8 @@ namespace wrap_orbit_bunch{ //---------------------------------------------------------------- //returns the SyncPart python class wrapper instance - static PyObject* Bunch_getSyncParticle(PyObject *self, PyObject *args){ - Bunch* cpp_bunch = (Bunch*) ((pyORBIT_Object *) self)->cpp_obj; - PyObject* pySyncPart = cpp_bunch->getSyncPart()->getPyWrapper(); + static PyObject* Bunch_getSyncParticle(PyObject *self, PyObject *Py_UNUSED(ignored)){ + PyObject* pySyncPart = ((pyORBIT_Bunch*) self)->sync_part; Py_INCREF(pySyncPart); return pySyncPart; } @@ -76,29 +110,34 @@ namespace wrap_orbit_bunch{ //---------------------------------------------------------------- //returns the local MPI Comm for this bunch - static PyObject* Bunch_getMPIComm(PyObject *self, PyObject *args){ - Bunch* cpp_bunch = (Bunch*) ((pyORBIT_Object *) self)->cpp_obj; - PyObject* pyMPIComm = (PyObject*) cpp_bunch->getMPI_Comm_Local(); - Py_INCREF(pyMPIComm); - return pyMPIComm; + static PyObject* Bunch_getMPIComm(PyObject *self, PyObject *Py_UNUSED(ignored)) { + PyObject* mpi_comm = ((pyORBIT_Bunch*) self)->mpi_comm; + if (mpi_comm == NULL) { + PyErr_SetString(PyExc_RuntimeError, "Bunch has no MPI communicator"); + return NULL; + } + Py_INCREF(mpi_comm); + return mpi_comm; } - //sets a new local MPI Comm for this bunch - static PyObject* Bunch_setMPIComm(PyObject *self, PyObject *args){ - Bunch* cpp_bunch = (Bunch*) ((pyORBIT_Object *) self)->cpp_obj; - int nVars = PyTuple_Size(args); - PyObject* pyMPIComm; - if(nVars == 1){ - if(!PyArg_ParseTuple(args,"O:setMPIComm",&pyMPIComm)){ - error("The Bunch method setMPIComm(mpi_comm) - mpi_comm is needed."); - } - cpp_bunch->setMPI_Comm_Local( (pyORBIT_MPI_Comm*) pyMPIComm); - } - else{ - error("The Bunch method should be setMPIComm(mpi_comm)."); - } - Py_INCREF(Py_None); - return Py_None; + //sets a new local MPI Comm for this bunch + static PyObject* Bunch_setMPIComm(PyObject *self, PyObject *arg) { + Bunch* cpp_bunch = (Bunch*) ((pyORBIT_Object *) self)->cpp_obj; + + PyObject* mpi_comm_type = wrap_orbit_mpi_comm::getMPI_CommType("MPI_Comm"); + if (mpi_comm_type == NULL) { + return NULL; + } + if (!PyObject_TypeCheck(arg, (PyTypeObject*)mpi_comm_type)) { + PyErr_SetString(PyExc_TypeError, "expected an MPI_Comm object"); + return NULL; + } + + pyORBIT_MPI_Comm *pyComm = (pyORBIT_MPI_Comm*)arg; + cpp_bunch->setMPI_Comm_Local(pyComm->comm); + setMPICommOwner((pyORBIT_Bunch*) self, arg); + + Py_RETURN_NONE; } //--------------------------------------------------------------- @@ -1139,8 +1178,18 @@ namespace wrap_orbit_bunch{ if(!PyArg_ParseTuple(args,"O:copyEmptyBunchTo",&pyBunch_Target)){ error("PyBunch - copyEmptyBunchTo(pyBunch) - target pyBunch object is needed"); } + PyObject* bunch_type = getBunchType("Bunch"); + if (bunch_type == NULL) { + return NULL; + } + if (!PyObject_TypeCheck(pyBunch_Target, (PyTypeObject*) bunch_type)) { + PyErr_SetString(PyExc_TypeError, "expected a Bunch object"); + return NULL; + } Bunch* cpp_target_bunch = (Bunch*) ((pyORBIT_Object *) pyBunch_Target)->cpp_obj; cpp_bunch->copyEmptyBunchTo(cpp_target_bunch); + setMPICommOwner((pyORBIT_Bunch*) pyBunch_Target, + ((pyORBIT_Bunch*) self)->mpi_comm); Py_INCREF(Py_None); return Py_None; } @@ -1153,8 +1202,18 @@ namespace wrap_orbit_bunch{ if(!PyArg_ParseTuple(args,"O:copyBunchTo",&pyBunch_Target)){ error("PyBunch - copyBunchTo(pyBunch) - target pyBunch object is needed"); } + PyObject* bunch_type = getBunchType("Bunch"); + if (bunch_type == NULL) { + return NULL; + } + if (!PyObject_TypeCheck(pyBunch_Target, (PyTypeObject*) bunch_type)) { + PyErr_SetString(PyExc_TypeError, "expected a Bunch object"); + return NULL; + } Bunch* cpp_target_bunch = (Bunch*) ((pyORBIT_Object *) pyBunch_Target)->cpp_obj; cpp_bunch->copyBunchTo(cpp_target_bunch); + setMPICommOwner((pyORBIT_Bunch*) pyBunch_Target, + ((pyORBIT_Bunch*) self)->mpi_comm); Py_INCREF(Py_None); return Py_None; } @@ -1180,7 +1239,10 @@ namespace wrap_orbit_bunch{ //this is implementation of the __del__ method static void Bunch_del(pyORBIT_Object* self){ Bunch* cpp_bunch = (Bunch*) self->cpp_obj; + pyorbit::unregisterPyWrapper(cpp_bunch, (PyObject*) self); delete cpp_bunch; + Py_XDECREF(((pyORBIT_Bunch*) self)->sync_part); + Py_XDECREF(((pyORBIT_Bunch*) self)->mpi_comm); self->ob_base.ob_type->tp_free((PyObject*)self); } @@ -1188,9 +1250,9 @@ namespace wrap_orbit_bunch{ //-------------------------------------------------------- // class Bunch wrapper START //-------------------------------------------------------- - { "getMPIComm", Bunch_getMPIComm ,METH_VARARGS,"Returns MPI Comm of this bunch"}, - { "setMPIComm", Bunch_setMPIComm ,METH_VARARGS,"Sets a new MPI Comm for this bunch"}, - { "getSyncParticle", Bunch_getSyncParticle ,METH_VARARGS,"Returns syncParticle class instance"}, + { "getMPIComm", Bunch_getMPIComm ,METH_NOARGS,"Returns MPI Comm of this bunch"}, + { "setMPIComm", Bunch_setMPIComm ,METH_O,"Sets a new MPI Comm for this bunch"}, + { "getSyncParticle", Bunch_getSyncParticle ,METH_NOARGS,"Returns syncParticle class instance"}, { "addParticle", Bunch_addParticle ,METH_VARARGS,"Adds a macro-particle to the bunch"}, { "deleteParticle", Bunch_deleteParticle ,METH_VARARGS,"Removes macro-particle from the bunch and call compress inside"}, { "deleteParticleFast", Bunch_deleteParticleFast ,METH_VARARGS,"Removes macro-particle from the bunch very fast"}, @@ -1260,7 +1322,7 @@ namespace wrap_orbit_bunch{ static PyTypeObject pyORBIT_Bunch_Type = { PyVarObject_HEAD_INIT(NULL, 0) "Bunch", /*tp_name*/ - sizeof(pyORBIT_Object), /*tp_basicsize*/ + sizeof(pyORBIT_Bunch), /*tp_basicsize*/ 0, /*tp_itemsize*/ (destructor) Bunch_del , /*tp_dealloc*/ 0, /*tp_print*/ @@ -1328,15 +1390,6 @@ extern "C" { return module; } - PyObject* getBunchType(const char* name){ - PyObject* mod = PyImport_ImportModule("orbit.core.bunch"); - PyObject* pyType = PyObject_GetAttrString(mod,name); - Py_DECREF(mod); - Py_DECREF(pyType); - return pyType; - } - - #ifdef __cplusplus } #endif diff --git a/src/orbit/wrap_bunch.hh b/src/orbit/wrap_bunch.hh index f096625c..d1386f1c 100644 --- a/src/orbit/wrap_bunch.hh +++ b/src/orbit/wrap_bunch.hh @@ -16,7 +16,7 @@ // INCLUDE FILES // /////////////////////////////////////////////////////////////////////////// -#include "Python.h" +#include #ifdef __cplusplus extern "C" { @@ -25,7 +25,8 @@ extern "C" { namespace wrap_orbit_bunch{ /* The name of the function was changed to avoid collision with PyImport magic naming */ PyMODINIT_FUNC initbunch(void); - PyObject* getBunchType(const char* name); + PyObject* getBunchType(const char* name); + PyObject* getSyncPartWrapper(PyObject* pyBunch); } #ifdef __cplusplus diff --git a/src/orbit/wrap_syncpart.cc b/src/orbit/wrap_syncpart.cc index 787c00a7..73a4923e 100644 --- a/src/orbit/wrap_syncpart.cc +++ b/src/orbit/wrap_syncpart.cc @@ -3,12 +3,13 @@ // INCLUDE FILES // /////////////////////////////////////////////////////////////////////////// -#include "wrap_syncpart.hh" +#include "orbit/wrap_syncpart.hh" +#include "orbit/wrap_bunch.hh" -#include "pyORBIT_Object.hh" +#include "main/pyORBIT_Object.hh" -#include "Bunch.hh" -#include "SyncPart.hh" +#include "orbit/Bunch.hh" +#include "orbit/SyncPart.hh" namespace wrap_orbit_syncpart{ @@ -43,12 +44,11 @@ extern "C" { pyORBIT_Object* pyBunch = (pyORBIT_Object*) PyTuple_GetItem(args,0); Bunch* cpp_bunch = (Bunch*) pyBunch->cpp_obj; - if(cpp_bunch->getSyncPart()->getPyWrapper() != NULL){ + if(wrap_orbit_bunch::getSyncPartWrapper((PyObject*) pyBunch) != NULL){ error("You should not create SyncParticle class instance directly!"); } self->cpp_obj = (void*) cpp_bunch->getSyncPart(); - cpp_bunch->getSyncPart()->setPyWrapper((PyObject *) self); return 0; } diff --git a/src/orbit/wrap_syncpart.hh b/src/orbit/wrap_syncpart.hh index 01770894..af1c37d6 100644 --- a/src/orbit/wrap_syncpart.hh +++ b/src/orbit/wrap_syncpart.hh @@ -11,7 +11,7 @@ // INCLUDE FILES // /////////////////////////////////////////////////////////////////////////// -#include "Python.h" +#include #ifdef __cplusplus extern "C" { diff --git a/src/spacecharge/BaseBoundary2D.cc b/src/spacecharge/BaseBoundary2D.cc index b897048d..bd2876dd 100644 --- a/src/spacecharge/BaseBoundary2D.cc +++ b/src/spacecharge/BaseBoundary2D.cc @@ -1,6 +1,7 @@ -#include "BaseBoundary2D.hh" -#include "OrbitConst.hh" +#include "spacecharge/BaseBoundary2D.hh" +#include "orbit/OrbitConst.hh" +#include #include #include @@ -19,7 +20,7 @@ surface. */ // Constructor -BaseBoundary2D::BaseBoundary2D(int nPoints, int nModes): CppPyWrapper(NULL) +BaseBoundary2D::BaseBoundary2D(int nPoints, int nModes) { initialized_ = 0; @@ -234,7 +235,7 @@ void BaseBoundary2D::initializeBPs(){ } /** Returns the name of the shape */ -string BaseBoundary2D::getShapeName(){ +std::string BaseBoundary2D::getShapeName(){ return shape_; } diff --git a/src/spacecharge/BaseBoundary2D.hh b/src/spacecharge/BaseBoundary2D.hh index 4e9481bf..36eb0704 100644 --- a/src/spacecharge/BaseBoundary2D.hh +++ b/src/spacecharge/BaseBoundary2D.hh @@ -1,13 +1,9 @@ #ifndef SC_BASE_BOUNDARY_2D_H #define SC_BASE_BOUNDARY_2D_H -#include "Grid2D.hh" +#include "spacecharge/Grid2D.hh" #include -//pyORBIT utils -#include "CppPyWrapper.hh" - -using namespace std; /** The BaseBoundary2D class defines a boundary geometry @@ -15,7 +11,7 @@ and calculates the potential created by charges on the boundary surface. */ -class BaseBoundary2D: public OrbitUtils::CppPyWrapper +class BaseBoundary2D { public: @@ -62,7 +58,7 @@ class BaseBoundary2D: public OrbitUtils::CppPyWrapper void initializeBPs(); /** Returns the name of the shape */ - string getShapeName(); + std::string getShapeName(); /** Returns the shape index */ int getShapeType(); @@ -74,7 +70,7 @@ class BaseBoundary2D: public OrbitUtils::CppPyWrapper public: /** NOSHAPE String constant */ - string NO_SHAPE; + std::string NO_SHAPE; const static int IS_INSIDE; const static int IS_OUTSIDE; @@ -92,7 +88,7 @@ class BaseBoundary2D: public OrbitUtils::CppPyWrapper protected: - string shape_; + std::string shape_; int shape_type_; //should be set to 1 in the base constructor diff --git a/src/spacecharge/ForceSolver2D.cc b/src/spacecharge/ForceSolver2D.cc index e1205425..1409b8fa 100644 --- a/src/spacecharge/ForceSolver2D.cc +++ b/src/spacecharge/ForceSolver2D.cc @@ -1,11 +1,11 @@ -#include "ForceSolver2D.hh" +#include "spacecharge/ForceSolver2D.hh" #include using namespace OrbitUtils; // Constructor -ForceSolver2D::ForceSolver2D(int xSize, int ySize): CppPyWrapper(NULL) +ForceSolver2D::ForceSolver2D(int xSize, int ySize) { xSize_ = xSize; ySize_ = ySize; diff --git a/src/spacecharge/ForceSolver2D.hh b/src/spacecharge/ForceSolver2D.hh index 0e82629a..d4ba52c7 100644 --- a/src/spacecharge/ForceSolver2D.hh +++ b/src/spacecharge/ForceSolver2D.hh @@ -4,26 +4,21 @@ #define SC_Force_SOLVER_BASE_2D_H //MPI Function Wrappers -#include "orbit_mpi.hh" -#include "wrap_mpi_comm.hh" +#include "mpi/orbit_mpi.hh" #include #include #include -//pyORBIT utils -#include "CppPyWrapper.hh" +#include "spacecharge/Grid2D.hh" -#include "Grid2D.hh" - -using namespace std; /** The ForceSolver2D class calculates 2D forces along X and Y axes created by a 2D charge distribution. */ -class ForceSolver2D: public OrbitUtils::CppPyWrapper +class ForceSolver2D { public: diff --git a/src/spacecharge/ForceSolverFFT2D.cc b/src/spacecharge/ForceSolverFFT2D.cc index abe7b890..18d7c409 100644 --- a/src/spacecharge/ForceSolverFFT2D.cc +++ b/src/spacecharge/ForceSolverFFT2D.cc @@ -1,5 +1,6 @@ -#include "ForceSolverFFT2D.hh" +#include "spacecharge/ForceSolverFFT2D.hh" +#include #include using namespace OrbitUtils; @@ -114,22 +115,22 @@ void ForceSolverFFT2D::_defineGreenF() { rTransX = iX * dx_; rTot2 = rTransX*rTransX + rTransY*rTransY; - greensF_[iX][iY] = complex(rTransX/rTot2, rTransY/rTot2); + greensF_[iX][iY] = std::complex(rTransX/rTot2, rTransY/rTot2); } - greensF_[xSize2_/2][iY] = complex(0,0); //end point + greensF_[xSize2_/2][iY] = std::complex(0,0); //end point for (iX = xSize2_/2+1; iX < xSize2_; iX++) { rTransX = (iX - xSize2_) * dx_; rTot2 = rTransX*rTransX + rTransY*rTransY; - greensF_[iX][iY] = complex(rTransX/rTot2, rTransY/rTot2); + greensF_[iX][iY] = std::complex(rTransX/rTot2, rTransY/rTot2); } } for(iX=0; iX < xSize_/2; iX++) // Null the top row: { - greensF_[iX][ySize2_/2] = complex(0,0); + greensF_[iX][ySize2_/2] = std::complex(0,0); } for (iY = ySize2_/2+1; iY < ySize2_; iY++) // Bottom rows: @@ -140,20 +141,20 @@ void ForceSolverFFT2D::_defineGreenF() { rTransX = iX * dx_; rTot2 = rTransX*rTransX + rTransY*rTransY; - greensF_[iX][iY] = complex(rTransX/rTot2, rTransY/rTot2); + greensF_[iX][iY] = std::complex(rTransX/rTot2, rTransY/rTot2); } - greensF_[xSize2_/2][iY] = complex(0,0); //end point + greensF_[xSize2_/2][iY] = std::complex(0,0); //end point for (iX = xSize2_/2+1; iX < xSize2_; iX++) { rTransX = (iX - xSize2_) * dx_; //rTransX = (iX - 1 - xSize2_) * dx_; rTot2 = rTransX*rTransX + rTransY*rTransY; - greensF_[iX][iY] = complex(rTransX/rTot2, rTransY/rTot2); + greensF_[iX][iY] = std::complex(rTransX/rTot2, rTransY/rTot2); } } - greensF_[0][0] = complex(0,0); //end point + greensF_[0][0] = std::complex(0,0); //end point // Calculate the FFT of the Greens Function: diff --git a/src/spacecharge/ForceSolverFFT2D.hh b/src/spacecharge/ForceSolverFFT2D.hh index 7bd77583..58a1ab98 100644 --- a/src/spacecharge/ForceSolverFFT2D.hh +++ b/src/spacecharge/ForceSolverFFT2D.hh @@ -4,23 +4,18 @@ #define SC_FORCE_SOLVER_FFT_2D_H //MPI Function Wrappers -#include "orbit_mpi.hh" -#include "wrap_mpi_comm.hh" +#include "mpi/orbit_mpi.hh" #include #include #include #include -//pyORBIT utils -#include "CppPyWrapper.hh" - //FFTW library header #include "fftw3.h" -#include "ForceSolver2D.hh" +#include "spacecharge/ForceSolver2D.hh" -using namespace std; /** The ForceSolverFFT2D class is used to calculate the force diff --git a/src/spacecharge/Grid1D.cc b/src/spacecharge/Grid1D.cc index 36caeb54..b3db4416 100644 --- a/src/spacecharge/Grid1D.cc +++ b/src/spacecharge/Grid1D.cc @@ -14,12 +14,12 @@ // Correction done by A. Shishlo 2023.02.10 // ///////////////////////////////////////////////////////////////////////////// -#include "orbit_mpi.hh" +#include "mpi/orbit_mpi.hh" -#include "Grid1D.hh" -#include "Bunch.hh" -#include "ParticleMacroSize.hh" -#include "BufferStore.hh" +#include "spacecharge/Grid1D.hh" +#include "orbit/Bunch.hh" +#include "orbit/ParticlesAttributes/ParticleMacroSize.hh" +#include "utils/BufferStore.hh" #include @@ -27,7 +27,7 @@ using namespace OrbitUtils; /** Constructor with grid size only */ -Grid1D::Grid1D(int zSize):CppPyWrapper(NULL) +Grid1D::Grid1D(int zSize) { zSize_ = zSize; zMin_ = -0.5; @@ -37,7 +37,7 @@ Grid1D::Grid1D(int zSize):CppPyWrapper(NULL) } /** Constructor with grid size and grid physical length */ -Grid1D::Grid1D(int zSize, double length):CppPyWrapper(NULL) +Grid1D::Grid1D(int zSize, double length) { zSize_ = zSize; zMin_ = 0.; @@ -47,7 +47,7 @@ Grid1D::Grid1D(int zSize, double length):CppPyWrapper(NULL) } /** Constructor with grid size and spatial limits */ -Grid1D::Grid1D(int zSize, double zMin, double zMax):CppPyWrapper(NULL) +Grid1D::Grid1D(int zSize, double zMin, double zMax) { zSize_ = zSize; zMin_ = zMin; @@ -759,7 +759,7 @@ void Grid1D::getBinIndAndWZSmoothed(double z, } /** synchronizeMPI */ -void Grid1D::synchronizeMPI(pyORBIT_MPI_Comm* pyComm) +void Grid1D::synchronizeMPI(MPI_Comm comm) { // ====== MPI start ======== @@ -776,7 +776,7 @@ void Grid1D::synchronizeMPI(pyORBIT_MPI_Comm* pyComm) inArr[i] = arr_[i]; } - if(pyComm == NULL) + if(comm == MPI_COMM_NULL) { ORBIT_MPI_Allreduce(inArr, outArr, size_MPI, MPI_DOUBLE, MPI_SUM, MPI_COMM_WORLD); @@ -784,7 +784,7 @@ void Grid1D::synchronizeMPI(pyORBIT_MPI_Comm* pyComm) else { ORBIT_MPI_Allreduce(inArr, outArr, size_MPI, - MPI_DOUBLE, MPI_SUM, pyComm->comm); + MPI_DOUBLE, MPI_SUM, comm); } for(int i = 0; i < zSize_; i++) diff --git a/src/spacecharge/Grid1D.hh b/src/spacecharge/Grid1D.hh index 18b292e5..ab1ec525 100644 --- a/src/spacecharge/Grid1D.hh +++ b/src/spacecharge/Grid1D.hh @@ -2,22 +2,17 @@ #define SC_GRID_1D_H // MPI Function Wrappers -#include "orbit_mpi.hh" -#include "wrap_mpi_comm.hh" +#include "mpi/orbit_mpi.hh" #include #include // ORBIT bunch -#include "Bunch.hh" +#include "orbit/Bunch.hh" -// pyORBIT utils -#include "CppPyWrapper.hh" -using namespace std; - -class Grid1D:public OrbitUtils::CppPyWrapper +class Grid1D { public: @@ -135,7 +130,7 @@ public: void calcGradientSmoothed(double z, double& ez); /** synchronizeMPI */ - void synchronizeMPI(pyORBIT_MPI_Comm* comm); + void synchronizeMPI(MPI_Comm comm); private: diff --git a/src/spacecharge/Grid2D.cc b/src/spacecharge/Grid2D.cc index c3c324c1..fedd477a 100644 --- a/src/spacecharge/Grid2D.cc +++ b/src/spacecharge/Grid2D.cc @@ -1,15 +1,15 @@ //This class repersents a 2D rectangular grid -#include "Grid2D.hh" -#include "ParticleMacroSize.hh" -#include "BufferStore.hh" +#include "spacecharge/Grid2D.hh" +#include "orbit/ParticlesAttributes/ParticleMacroSize.hh" +#include "utils/BufferStore.hh" #include using namespace OrbitUtils; // Constructor -Grid2D::Grid2D(int xSize, int ySize): CppPyWrapper(NULL) +Grid2D::Grid2D(int xSize, int ySize) { xSize_ = xSize; ySize_ = ySize; @@ -23,7 +23,7 @@ Grid2D::Grid2D(int xSize, int ySize): CppPyWrapper(NULL) Grid2D::Grid2D(int xSize, int ySize, double xMin, double xMax, - double yMin, double yMax): CppPyWrapper(NULL) + double yMin, double yMax) { xSize_ = xSize; ySize_ = ySize; @@ -440,7 +440,7 @@ int Grid2D::isInside(double x,double y){ } /**synchronizeMPI */ -void Grid2D::synchronizeMPI(pyORBIT_MPI_Comm* pyComm){ +void Grid2D::synchronizeMPI(MPI_Comm comm){ // ====== MPI start ======== int size_MPI = xSize_ * ySize_; int buff_index0 = 0; @@ -456,10 +456,10 @@ void Grid2D::synchronizeMPI(pyORBIT_MPI_Comm* pyComm){ } } - if(pyComm == NULL) { + if(comm == MPI_COMM_NULL) { ORBIT_MPI_Allreduce(inArr,outArr,size_MPI,MPI_DOUBLE,MPI_SUM,MPI_COMM_WORLD); } else { - ORBIT_MPI_Allreduce(inArr,outArr,size_MPI,MPI_DOUBLE,MPI_SUM,pyComm->comm); + ORBIT_MPI_Allreduce(inArr,outArr,size_MPI,MPI_DOUBLE,MPI_SUM,comm); } count = 0; diff --git a/src/spacecharge/Grid2D.hh b/src/spacecharge/Grid2D.hh index 419be46d..a22be2df 100644 --- a/src/spacecharge/Grid2D.hh +++ b/src/spacecharge/Grid2D.hh @@ -4,25 +4,20 @@ #define SC_GRID_2D_H //MPI Function Wrappers -#include "orbit_mpi.hh" -#include "wrap_mpi_comm.hh" +#include "mpi/orbit_mpi.hh" #include #include //ORBIT bunch -#include "Bunch.hh" +#include "orbit/Bunch.hh" -//pyORBIT utils -#include "CppPyWrapper.hh" - -using namespace std; /** This class repersents a 2D rectangular grid. */ -class Grid2D: public OrbitUtils::CppPyWrapper +class Grid2D { public: @@ -93,7 +88,7 @@ public: int getSizeY(); /** synchronizeMPI */ - void synchronizeMPI(pyORBIT_MPI_Comm* comm); + void synchronizeMPI(MPI_Comm comm); /** Returns 1 if (x,y) is inside the grid region, and 0 otherwise */ int isInside(double x,double y); diff --git a/src/spacecharge/Grid3D.cc b/src/spacecharge/Grid3D.cc index 401b34e2..d223e463 100644 --- a/src/spacecharge/Grid3D.cc +++ b/src/spacecharge/Grid3D.cc @@ -14,17 +14,17 @@ // /////////////////////////////////////////////////////////////////////////// -#include "ParticleMacroSize.hh" -#include "BufferStore.hh" +#include "orbit/ParticlesAttributes/ParticleMacroSize.hh" +#include "utils/BufferStore.hh" -#include "Grid3D.hh" +#include "spacecharge/Grid3D.hh" #include using namespace OrbitUtils; /** Constructor */ -Grid3D::Grid3D(int nX, int nY, int nZ): CppPyWrapper(NULL) +Grid3D::Grid3D(int nX, int nY, int nZ) { nX_ = nX; nY_ = nY; @@ -809,7 +809,7 @@ double Grid3D::calcSheetGradient(int iZ,int iX,int iY, } /**synchronize MPI */ -void Grid3D::synchronizeMPI(pyORBIT_MPI_Comm* pyComm){ +void Grid3D::synchronizeMPI(MPI_Comm pyComm){ // ====== MPI start ======== int size_MPI = nX_ * nY_*nZ_; int buff_index0 = 0; @@ -827,10 +827,10 @@ void Grid3D::synchronizeMPI(pyORBIT_MPI_Comm* pyComm){ } } - if(pyComm == NULL) { + if(pyComm == MPI_COMM_NULL) { ORBIT_MPI_Allreduce(inArr,outArr,size_MPI,MPI_DOUBLE,MPI_SUM,MPI_COMM_WORLD); } else { - ORBIT_MPI_Allreduce(inArr,outArr,size_MPI,MPI_DOUBLE,MPI_SUM,pyComm->comm); + ORBIT_MPI_Allreduce(inArr,outArr,size_MPI,MPI_DOUBLE,MPI_SUM,pyComm); } count = 0; diff --git a/src/spacecharge/Grid3D.hh b/src/spacecharge/Grid3D.hh index fa15ebad..41ec7966 100644 --- a/src/spacecharge/Grid3D.hh +++ b/src/spacecharge/Grid3D.hh @@ -17,21 +17,17 @@ #define SC_GRID3D_HH //MPI Function Wrappers -#include "orbit_mpi.hh" -#include "wrap_mpi_comm.hh" +#include "mpi/orbit_mpi.hh" //ORBIT bunch -#include "Bunch.hh" +#include "orbit/Bunch.hh" -//pyORBIT utils -#include "CppPyWrapper.hh" - -#include "Grid2D.hh" +#include "spacecharge/Grid2D.hh" #include #include -class Grid3D: public OrbitUtils::CppPyWrapper +class Grid3D { public: //-------------------------------------- @@ -175,7 +171,7 @@ public: double getSliceSum(double z); /** synchronize MPI */ - void synchronizeMPI(pyORBIT_MPI_Comm* pyComm); + void synchronizeMPI(MPI_Comm pyComm); protected: //--------------------------------------- diff --git a/src/spacecharge/LSpaceChargeCalc.cc b/src/spacecharge/LSpaceChargeCalc.cc index bd008e86..d849f27a 100644 --- a/src/spacecharge/LSpaceChargeCalc.cc +++ b/src/spacecharge/LSpaceChargeCalc.cc @@ -11,10 +11,10 @@ // ///////////////////////////////////////////////////////////////////////////// -#include "LSpaceChargeCalc.hh" -#include "BufferStore.hh" -#include "Grid1D.hh" -#include "OrbitConst.hh" +#include "spacecharge/Grid1D.hh" +#include "utils/BufferStore.hh" +#include "spacecharge/LSpaceChargeCalc.hh" +#include "orbit/OrbitConst.hh" #include #include #include @@ -25,13 +25,13 @@ using namespace OrbitUtils; -LSpaceChargeCalc::LSpaceChargeCalc(double b_a_in, double length_in, int nMacrosMin_in, int useSpaceCharge_in, int nBins_in) : CppPyWrapper(NULL) { +LSpaceChargeCalc::LSpaceChargeCalc(double b_a_in, double length_in, int nMacrosMin_in, int useSpaceCharge_in, int nBins_in) { b_a = b_a_in; length = length_in; nMacrosMin = nMacrosMin_in; useSpaceCharge = useSpaceCharge_in; nBins = nBins_in; - zGrid = new Grid1D(nBins, length); + zGrid.reset(new Grid1D(nBins, length)); nModes = nBins / 2; useGrad = 0; @@ -62,11 +62,6 @@ LSpaceChargeCalc::LSpaceChargeCalc(double b_a_in, double length_in, int nMacrosM } LSpaceChargeCalc::~LSpaceChargeCalc() { - if (zGrid->getPyWrapper() != NULL) { - Py_DECREF(zGrid->getPyWrapper()); - } else { - delete zGrid; - } delete[] _fftmagnitude; delete[] _fftphase; delete[] _z; diff --git a/src/spacecharge/LSpaceChargeCalc.hh b/src/spacecharge/LSpaceChargeCalc.hh index f9b24a70..66f93f6f 100644 --- a/src/spacecharge/LSpaceChargeCalc.hh +++ b/src/spacecharge/LSpaceChargeCalc.hh @@ -4,27 +4,25 @@ #define SC_SPACECHARGE_CALC_L_H //MPI Function Wrappers -#include "orbit_mpi.hh" -#include "wrap_mpi_comm.hh" +#include "mpi/orbit_mpi.hh" #include #include +#include #include //ORBIT bunch -#include "Bunch.hh" +#include "orbit/Bunch.hh" //pyORBIT utils -#include "CppPyWrapper.hh" -#include "BunchExtremaCalculator.hh" -#include "Grid1D.hh" +#include "utils/bunch/BunchExtremaCalculator.hh" +#include "spacecharge/Grid1D.hh" //FFTW library header #include "fftw3.h" -using namespace std; -class LSpaceChargeCalc: public OrbitUtils::CppPyWrapper +class LSpaceChargeCalc { public: @@ -64,7 +62,7 @@ public: int smooth; //protected: - Grid1D* zGrid; + std::unique_ptr zGrid; OrbitUtils::BunchExtremaCalculator* bunchExtremaCalc; //FFT arrays diff --git a/src/spacecharge/PoissonSolver2D.cc b/src/spacecharge/PoissonSolver2D.cc index cf4426ad..3b3aef10 100644 --- a/src/spacecharge/PoissonSolver2D.cc +++ b/src/spacecharge/PoissonSolver2D.cc @@ -1,11 +1,11 @@ -#include "PoissonSolver2D.hh" +#include "spacecharge/PoissonSolver2D.hh" #include using namespace OrbitUtils; // Constructor -PoissonSolver2D::PoissonSolver2D(int xSize, int ySize): CppPyWrapper(NULL) +PoissonSolver2D::PoissonSolver2D(int xSize, int ySize) { xSize_ = xSize; ySize_ = ySize; @@ -20,7 +20,7 @@ PoissonSolver2D::PoissonSolver2D(int xSize, int ySize): CppPyWrapper(NULL) // Constructor PoissonSolver2D::PoissonSolver2D(int xSize, int ySize, double xMin, double xMax, - double yMin, double yMax): CppPyWrapper(NULL) + double yMin, double yMax) { xSize_ = xSize; ySize_ = ySize; diff --git a/src/spacecharge/PoissonSolver2D.hh b/src/spacecharge/PoissonSolver2D.hh index a1cb3a0a..0d7d53cb 100644 --- a/src/spacecharge/PoissonSolver2D.hh +++ b/src/spacecharge/PoissonSolver2D.hh @@ -4,26 +4,21 @@ #define SC_POISSON_SOLVER_BASE_2D_H //MPI Function Wrappers -#include "orbit_mpi.hh" -#include "wrap_mpi_comm.hh" +#include "mpi/orbit_mpi.hh" #include #include #include -//pyORBIT utils -#include "CppPyWrapper.hh" +#include "spacecharge/Grid2D.hh" -#include "Grid2D.hh" - -using namespace std; /** The PoissonSolver2D class calculates electrostatic potential of a 2D charge distribution. */ -class PoissonSolver2D: public OrbitUtils::CppPyWrapper +class PoissonSolver2D { public: diff --git a/src/spacecharge/PoissonSolver3D.cc b/src/spacecharge/PoissonSolver3D.cc index aef8bc62..9015a291 100644 --- a/src/spacecharge/PoissonSolver3D.cc +++ b/src/spacecharge/PoissonSolver3D.cc @@ -1,11 +1,11 @@ -#include "PoissonSolver3D.hh" +#include "spacecharge/PoissonSolver3D.hh" #include using namespace OrbitUtils; // Constructor -PoissonSolver3D::PoissonSolver3D(int xSize, int ySize, int zSize): CppPyWrapper(NULL) +PoissonSolver3D::PoissonSolver3D(int xSize, int ySize, int zSize) { xSize_ = xSize; ySize_ = ySize; @@ -32,7 +32,7 @@ PoissonSolver3D::PoissonSolver3D(int xSize, int ySize, int zSize): CppPyWrapper( PoissonSolver3D::PoissonSolver3D(int xSize, int ySize, int zSize, double xMin, double xMax, double yMin, double yMax, - double zMin, double zMax): CppPyWrapper(NULL) + double zMin, double zMax) { xSize_ = xSize; ySize_ = ySize; diff --git a/src/spacecharge/PoissonSolver3D.hh b/src/spacecharge/PoissonSolver3D.hh index 06844ca6..7dac49f4 100644 --- a/src/spacecharge/PoissonSolver3D.hh +++ b/src/spacecharge/PoissonSolver3D.hh @@ -4,26 +4,21 @@ #define SC_POISSON_SOLVER_BASE_3D_H //MPI Function Wrappers -#include "orbit_mpi.hh" -#include "wrap_mpi_comm.hh" +#include "mpi/orbit_mpi.hh" #include #include #include -//pyORBIT utils -#include "CppPyWrapper.hh" +#include "spacecharge/Grid3D.hh" -#include "Grid3D.hh" - -using namespace std; /** The PoissonSolver3D class calculates 3D voltage distribution created by 3D charge distribution. */ -class PoissonSolver3D: public OrbitUtils::CppPyWrapper +class PoissonSolver3D { public: diff --git a/src/spacecharge/PoissonSolverFFT2D.cc b/src/spacecharge/PoissonSolverFFT2D.cc index a855c6de..88b2f093 100644 --- a/src/spacecharge/PoissonSolverFFT2D.cc +++ b/src/spacecharge/PoissonSolverFFT2D.cc @@ -1,4 +1,4 @@ -#include "PoissonSolverFFT2D.hh" +#include "spacecharge/PoissonSolverFFT2D.hh" #include diff --git a/src/spacecharge/PoissonSolverFFT2D.hh b/src/spacecharge/PoissonSolverFFT2D.hh index 98b489dc..ae6f372a 100644 --- a/src/spacecharge/PoissonSolverFFT2D.hh +++ b/src/spacecharge/PoissonSolverFFT2D.hh @@ -4,22 +4,17 @@ #define SC_POISSON_SOLVER_FFT_2D_H //MPI Function Wrappers -#include "orbit_mpi.hh" -#include "wrap_mpi_comm.hh" +#include "mpi/orbit_mpi.hh" #include #include #include -//pyORBIT utils -#include "CppPyWrapper.hh" - //FFTW library header #include "fftw3.h" -#include "PoissonSolver2D.hh" +#include "spacecharge/PoissonSolver2D.hh" -using namespace std; /** The PoissonSolverFFT2D class calculates electrostatic diff --git a/src/spacecharge/PoissonSolverFFT3D.cc b/src/spacecharge/PoissonSolverFFT3D.cc index fec5d5c8..a1b637c4 100644 --- a/src/spacecharge/PoissonSolverFFT3D.cc +++ b/src/spacecharge/PoissonSolverFFT3D.cc @@ -1,4 +1,4 @@ -#include "PoissonSolverFFT3D.hh" +#include "spacecharge/PoissonSolverFFT3D.hh" #include diff --git a/src/spacecharge/PoissonSolverFFT3D.hh b/src/spacecharge/PoissonSolverFFT3D.hh index 6134af5d..11c3f6f4 100644 --- a/src/spacecharge/PoissonSolverFFT3D.hh +++ b/src/spacecharge/PoissonSolverFFT3D.hh @@ -4,23 +4,18 @@ #define SC_POISSON_SOLVER_FFT_3D_H //MPI Function Wrappers -#include "orbit_mpi.hh" -#include "wrap_mpi_comm.hh" +#include "mpi/orbit_mpi.hh" #include #include #include #include -//pyORBIT utils -#include "CppPyWrapper.hh" - //FFTW library header #include "fftw3.h" -#include "PoissonSolver3D.hh" +#include "spacecharge/PoissonSolver3D.hh" -using namespace std; /** The PoissonSolverFFT3D class calculates electrostatic diff --git a/src/spacecharge/ShapedBoundary2D.cc b/src/spacecharge/ShapedBoundary2D.cc index 1a77ee2d..cd7468e7 100644 --- a/src/spacecharge/ShapedBoundary2D.cc +++ b/src/spacecharge/ShapedBoundary2D.cc @@ -1,12 +1,13 @@ -#include "ShapedBoundary2D.hh" +#include "spacecharge/ShapedBoundary2D.hh" +#include #include #include using namespace OrbitUtils; /** Constructor */ -ShapedBoundary2D::ShapedBoundary2D(int nPoints, int nModes, string shape, double xDim, double yDim): +ShapedBoundary2D::ShapedBoundary2D(int nPoints, int nModes, std::string shape, double xDim, double yDim): BaseBoundary2D(4*((int)(nPoints/4)),nModes) { nPoints = getNumberOfPoints(); diff --git a/src/spacecharge/ShapedBoundary2D.hh b/src/spacecharge/ShapedBoundary2D.hh index 4eb98f5c..f275066b 100644 --- a/src/spacecharge/ShapedBoundary2D.hh +++ b/src/spacecharge/ShapedBoundary2D.hh @@ -1,12 +1,11 @@ #ifndef SC_SHAPED_BOUNDARY_2D_H #define SC_SHAPED_BOUNDARY_2D_H -#include "Grid2D.hh" +#include "spacecharge/Grid2D.hh" #include -#include "BaseBoundary2D.hh" +#include "spacecharge/BaseBoundary2D.hh" -using namespace std; /** The ShapedBoundary2D class defines a boundary geometry for three cases: @@ -20,7 +19,7 @@ class ShapedBoundary2D: public BaseBoundary2D public: /** Constructor */ - ShapedBoundary2D(int nPoints, int nModes, string shape, double xDim, double yDim); + ShapedBoundary2D(int nPoints, int nModes, std::string shape, double xDim, double yDim); /** Destructor */ virtual ~ShapedBoundary2D(); diff --git a/src/spacecharge/SpaceChargeCalc2p5D.cc b/src/spacecharge/SpaceChargeCalc2p5D.cc index c6fded05..3f457178 100644 --- a/src/spacecharge/SpaceChargeCalc2p5D.cc +++ b/src/spacecharge/SpaceChargeCalc2p5D.cc @@ -10,11 +10,11 @@ // ///////////////////////////////////////////////////////////////////////////// -#include "Grid1D.hh" -#include "Grid2D.hh" -#include "PoissonSolverFFT2D.hh" -#include "SpaceChargeCalc2p5D.hh" -#include "BufferStore.hh" +#include "spacecharge/Grid1D.hh" +#include "spacecharge/Grid2D.hh" +#include "spacecharge/PoissonSolverFFT2D.hh" +#include "spacecharge/SpaceChargeCalc2p5D.hh" +#include "utils/BufferStore.hh" #include #include @@ -22,56 +22,41 @@ using namespace OrbitUtils; -SpaceChargeCalc2p5D::SpaceChargeCalc2p5D(int xSize, int ySize, int zSize, double xy_ratio_in): CppPyWrapper(NULL) +SpaceChargeCalc2p5D::SpaceChargeCalc2p5D(int xSize, int ySize, int zSize, double xy_ratio_in) { xy_ratio = xy_ratio_in; poissonSolver = new PoissonSolverFFT2D(xSize, ySize, -xy_ratio, xy_ratio, -1.0, 1.0); - rhoGrid = new Grid2D(xSize, ySize); - phiGrid = new Grid2D(xSize, ySize); - zGrid = new Grid1D(zSize); + rhoGrid.reset(new Grid2D(xSize, ySize)); + phiGrid.reset(new Grid2D(xSize, ySize)); + zGrid.reset(new Grid1D(zSize)); bunchExtremaCalc = new BunchExtremaCalculator(); } -SpaceChargeCalc2p5D::SpaceChargeCalc2p5D(int xSize, int ySize, int zSize): CppPyWrapper(NULL) +SpaceChargeCalc2p5D::SpaceChargeCalc2p5D(int xSize, int ySize, int zSize) { xy_ratio = 1.0; poissonSolver = new PoissonSolverFFT2D(xSize, ySize, -xy_ratio, xy_ratio, -1.0, 1.0); - rhoGrid = new Grid2D(xSize, ySize); - phiGrid = new Grid2D(xSize, ySize); - zGrid = new Grid1D(zSize); + rhoGrid.reset(new Grid2D(xSize, ySize)); + phiGrid.reset(new Grid2D(xSize, ySize)); + zGrid.reset(new Grid1D(zSize)); bunchExtremaCalc = new BunchExtremaCalculator(); } SpaceChargeCalc2p5D::~SpaceChargeCalc2p5D(){ delete poissonSolver; - if(rhoGrid->getPyWrapper() != NULL){ - Py_DECREF(rhoGrid->getPyWrapper()); - } else { - delete rhoGrid; - } - if(phiGrid->getPyWrapper() != NULL){ - Py_DECREF(phiGrid->getPyWrapper()); - } else { - delete phiGrid; - } - if(zGrid->getPyWrapper() != NULL){ - Py_DECREF(zGrid->getPyWrapper()); - } else { - delete zGrid; - } delete bunchExtremaCalc; } Grid2D* SpaceChargeCalc2p5D::getRhoGrid(){ - return rhoGrid; + return rhoGrid.get(); } Grid2D* SpaceChargeCalc2p5D::getPhiGrid(){ - return phiGrid; + return phiGrid.get(); } Grid1D* SpaceChargeCalc2p5D::getLongGrid(){ - return zGrid; + return zGrid.get(); } void SpaceChargeCalc2p5D::trackBunch(Bunch* bunch, double length, BaseBoundary2D* boundary){ @@ -85,11 +70,11 @@ void SpaceChargeCalc2p5D::trackBunch(Bunch* bunch, double length, BaseBoundary2D double z_step = zGrid->getStepZ(); //calculate phiGrid - poissonSolver->findPotential(rhoGrid,phiGrid); + poissonSolver->findPotential(rhoGrid.get(),phiGrid.get()); if(boundary != NULL){ //update potential with boundary condition - boundary->addBoundaryPotential(rhoGrid,phiGrid); + boundary->addBoundaryPotential(rhoGrid.get(),phiGrid.get()); //std::cerr<<"Boundary ADDED."< #include +#include //ORBIT bunch -#include "Bunch.hh" +#include "orbit/Bunch.hh" //pyORBIT utils -#include "CppPyWrapper.hh" -#include "BunchExtremaCalculator.hh" +#include "utils/bunch/BunchExtremaCalculator.hh" -#include "Grid1D.hh" -#include "Grid2D.hh" -#include "PoissonSolverFFT2D.hh" -#include "BaseBoundary2D.hh" +#include "spacecharge/Grid1D.hh" +#include "spacecharge/Grid2D.hh" +#include "spacecharge/PoissonSolverFFT2D.hh" +#include "spacecharge/BaseBoundary2D.hh" -using namespace std; -class SpaceChargeCalc2p5D: public OrbitUtils::CppPyWrapper +class SpaceChargeCalc2p5D { public: @@ -55,9 +53,9 @@ private: protected: PoissonSolverFFT2D* poissonSolver; - Grid2D* rhoGrid; - Grid2D* phiGrid; - Grid1D* zGrid; + std::unique_ptr rhoGrid; + std::unique_ptr phiGrid; + std::unique_ptr zGrid; OrbitUtils::BunchExtremaCalculator* bunchExtremaCalc; double xy_ratio; diff --git a/src/spacecharge/SpaceChargeCalc2p5Drb.cc b/src/spacecharge/SpaceChargeCalc2p5Drb.cc index 9348ea04..c8aa5a75 100644 --- a/src/spacecharge/SpaceChargeCalc2p5Drb.cc +++ b/src/spacecharge/SpaceChargeCalc2p5Drb.cc @@ -16,11 +16,11 @@ // ///////////////////////////////////////////////////////////////////////////// -#include "Grid1D.hh" -#include "Grid2D.hh" -#include "PoissonSolverFFT2D.hh" -#include "SpaceChargeCalc2p5Drb.hh" -#include "BufferStore.hh" +#include "spacecharge/Grid1D.hh" +#include "spacecharge/Grid2D.hh" +#include "spacecharge/PoissonSolverFFT2D.hh" +#include "spacecharge/SpaceChargeCalc2p5Drb.hh" +#include "utils/BufferStore.hh" #include #include @@ -28,14 +28,14 @@ using namespace OrbitUtils; -SpaceChargeCalc2p5Drb::SpaceChargeCalc2p5Drb(int xSize, int ySize, int zSize, double xy_ratio_in): CppPyWrapper(NULL) +SpaceChargeCalc2p5Drb::SpaceChargeCalc2p5Drb(int xSize, int ySize, int zSize, double xy_ratio_in) { xy_ratio = xy_ratio_in; poissonSolver = new PoissonSolverFFT2D(xSize, ySize, -xy_ratio, xy_ratio, -1.0, 1.0); - rhoGrid = new Grid2D(xSize, ySize); - phiGrid = new Grid2D(xSize, ySize); - zGrid = new Grid1D(zSize); - zDerivGrid = new Grid1D(zSize); + rhoGrid.reset(new Grid2D(xSize, ySize)); + phiGrid.reset(new Grid2D(xSize, ySize)); + zGrid.reset(new Grid1D(zSize)); + zDerivGrid.reset(new Grid1D(zSize)); bunchExtremaCalc = new BunchExtremaCalculator(); //we will use 3 points by default to calculate the longitudinal density derivative n_long_avg = 3; @@ -45,14 +45,14 @@ SpaceChargeCalc2p5Drb::SpaceChargeCalc2p5Drb(int xSize, int ySize, int zSize, do } } -SpaceChargeCalc2p5Drb::SpaceChargeCalc2p5Drb(int xSize, int ySize, int zSize): CppPyWrapper(NULL) +SpaceChargeCalc2p5Drb::SpaceChargeCalc2p5Drb(int xSize, int ySize, int zSize) { xy_ratio = 1.0; poissonSolver = new PoissonSolverFFT2D(xSize, ySize, -xy_ratio, xy_ratio, -1.0, 1.0); - rhoGrid = new Grid2D(xSize, ySize); - phiGrid = new Grid2D(xSize, ySize); - zGrid = new Grid1D(zSize); - zDerivGrid = new Grid1D(zSize); + rhoGrid.reset(new Grid2D(xSize, ySize)); + phiGrid.reset(new Grid2D(xSize, ySize)); + zGrid.reset(new Grid1D(zSize)); + zDerivGrid.reset(new Grid1D(zSize)); bunchExtremaCalc = new BunchExtremaCalculator(); //we will use 3 points by default to calculate the longitudinal density derivative n_long_avg = 3; @@ -64,26 +64,6 @@ SpaceChargeCalc2p5Drb::SpaceChargeCalc2p5Drb(int xSize, int ySize, int zSize): C SpaceChargeCalc2p5Drb::~SpaceChargeCalc2p5Drb(){ delete poissonSolver; - if(rhoGrid->getPyWrapper() != NULL){ - Py_DECREF(rhoGrid->getPyWrapper()); - } else { - delete rhoGrid; - } - if(phiGrid->getPyWrapper() != NULL){ - Py_DECREF(phiGrid->getPyWrapper()); - } else { - delete phiGrid; - } - if(zGrid->getPyWrapper() != NULL){ - Py_DECREF(zGrid->getPyWrapper()); - } else { - delete zGrid; - } - if(zDerivGrid->getPyWrapper() != NULL){ - Py_DECREF(zDerivGrid->getPyWrapper()); - } else { - delete zDerivGrid; - } delete bunchExtremaCalc; for(int i = 0; i < 5; i++){ delete [] S_arr[i]; @@ -92,19 +72,19 @@ SpaceChargeCalc2p5Drb::~SpaceChargeCalc2p5Drb(){ } Grid2D* SpaceChargeCalc2p5Drb::getRhoGrid(){ - return rhoGrid; + return rhoGrid.get(); } Grid2D* SpaceChargeCalc2p5Drb::getPhiGrid(){ - return phiGrid; + return phiGrid.get(); } Grid1D* SpaceChargeCalc2p5Drb::getLongGrid(){ - return zGrid; + return zGrid.get(); } Grid1D* SpaceChargeCalc2p5Drb::getLongDerivativeGrid(){ - return zDerivGrid; + return zDerivGrid.get(); } void SpaceChargeCalc2p5Drb::trackBunch(Bunch* bunch, double length, double pipe_radius){ @@ -122,7 +102,7 @@ void SpaceChargeCalc2p5Drb::trackBunch(Bunch* bunch, double length, double pipe_ double z_step = zGrid->getStepZ(); //calculate phiGrid - poissonSolver->findPotential(rhoGrid,phiGrid); + poissonSolver->findPotential(rhoGrid.get(),phiGrid.get()); SyncPart* syncPart = bunch->getSyncPart(); double factor = 2*length*bunch->getClassicalRadius()/(pow(syncPart->getBeta(),2)*pow(syncPart->getGamma(),3)); diff --git a/src/spacecharge/SpaceChargeCalc2p5Drb.hh b/src/spacecharge/SpaceChargeCalc2p5Drb.hh index c343cade..99ed3531 100644 --- a/src/spacecharge/SpaceChargeCalc2p5Drb.hh +++ b/src/spacecharge/SpaceChargeCalc2p5Drb.hh @@ -8,26 +8,24 @@ #define SC_SPACECHARGE_CALC_2P5D_RB_H //MPI Function Wrappers -#include "orbit_mpi.hh" -#include "wrap_mpi_comm.hh" +#include "mpi/orbit_mpi.hh" #include #include +#include //ORBIT bunch -#include "Bunch.hh" +#include "orbit/Bunch.hh" //pyORBIT utils -#include "CppPyWrapper.hh" -#include "BunchExtremaCalculator.hh" +#include "utils/bunch/BunchExtremaCalculator.hh" -#include "Grid1D.hh" -#include "Grid2D.hh" -#include "PoissonSolverFFT2D.hh" +#include "spacecharge/Grid1D.hh" +#include "spacecharge/Grid2D.hh" +#include "spacecharge/PoissonSolverFFT2D.hh" -using namespace std; -class SpaceChargeCalc2p5Drb: public OrbitUtils::CppPyWrapper +class SpaceChargeCalc2p5Drb { public: @@ -72,10 +70,10 @@ private: protected: PoissonSolverFFT2D* poissonSolver; - Grid2D* rhoGrid; - Grid2D* phiGrid; - Grid1D* zGrid; - Grid1D* zDerivGrid; + std::unique_ptr rhoGrid; + std::unique_ptr phiGrid; + std::unique_ptr zGrid; + std::unique_ptr zDerivGrid; OrbitUtils::BunchExtremaCalculator* bunchExtremaCalc; double xy_ratio; diff --git a/src/spacecharge/SpaceChargeCalc3D.cc b/src/spacecharge/SpaceChargeCalc3D.cc index be539037..18fac0e3 100644 --- a/src/spacecharge/SpaceChargeCalc3D.cc +++ b/src/spacecharge/SpaceChargeCalc3D.cc @@ -18,11 +18,11 @@ // ///////////////////////////////////////////////////////////////////////////// -#include "Grid3D.hh" -#include "PoissonSolverFFT3D.hh" -#include "SpaceChargeCalc3D.hh" -#include "BufferStore.hh" -#include "OrbitConst.hh" +#include "spacecharge/Grid3D.hh" +#include "spacecharge/PoissonSolverFFT3D.hh" +#include "spacecharge/SpaceChargeCalc3D.hh" +#include "utils/BufferStore.hh" +#include "orbit/OrbitConst.hh" #include #include @@ -30,16 +30,16 @@ using namespace OrbitUtils; -SpaceChargeCalc3D::SpaceChargeCalc3D(int xSize, int ySize, int zSize): CppPyWrapper(NULL) +SpaceChargeCalc3D::SpaceChargeCalc3D(int xSize, int ySize, int zSize) { xy_ratio = 1.0; xz_ratio = 1.0; poissonSolver = new PoissonSolverFFT3D(xSize, ySize, zSize, -xy_ratio, xy_ratio, -1./xy_ratio, 1./xy_ratio, -1./xz_ratio, 1./xz_ratio); - rhoGrid = new Grid3D(xSize, ySize, zSize); + rhoGrid.reset(new Grid3D(xSize, ySize, zSize)); rhoGrid->setGridX(poissonSolver->getMinX(),poissonSolver->getMaxX()); rhoGrid->setGridY(poissonSolver->getMinY(),poissonSolver->getMaxY()); rhoGrid->setGridZ(poissonSolver->getMinZ(),poissonSolver->getMaxZ()); - phiGrid = new Grid3D(xSize, ySize, zSize); + phiGrid.reset(new Grid3D(xSize, ySize, zSize)); phiGrid->setGridX(poissonSolver->getMinX(),poissonSolver->getMaxX()); phiGrid->setGridY(poissonSolver->getMinY(),poissonSolver->getMaxY()); phiGrid->setGridZ(poissonSolver->getMinZ(),poissonSolver->getMaxZ()); @@ -60,25 +60,15 @@ SpaceChargeCalc3D::SpaceChargeCalc3D(int xSize, int ySize, int zSize): CppPyWrap SpaceChargeCalc3D::~SpaceChargeCalc3D(){ delete poissonSolver; - if(rhoGrid->getPyWrapper() != NULL){ - Py_DECREF(rhoGrid->getPyWrapper()); - } else { - delete rhoGrid; - } - if(phiGrid->getPyWrapper() != NULL){ - Py_DECREF(phiGrid->getPyWrapper()); - } else { - delete phiGrid; - } delete bunchExtremaCalc; } Grid3D* SpaceChargeCalc3D::getRhoGrid(){ - return rhoGrid; + return rhoGrid.get(); } Grid3D* SpaceChargeCalc3D::getPhiGrid(){ - return phiGrid; + return phiGrid.get(); } void SpaceChargeCalc3D::setNumberOfExternalBunches(int nBunches){ @@ -113,7 +103,7 @@ void SpaceChargeCalc3D::trackBunch(Bunch* bunch, double length){ } //calculate phiGrid with potential. The z-coordinate is in the center of mass coordinate system - poissonSolver->findPotential(rhoGrid,phiGrid); + poissonSolver->findPotential(rhoGrid.get(),phiGrid.get()); SyncPart* syncPart = bunch->getSyncPart(); double gamma = syncPart->getGamma(); diff --git a/src/spacecharge/SpaceChargeCalc3D.hh b/src/spacecharge/SpaceChargeCalc3D.hh index f29ae565..778c9508 100644 --- a/src/spacecharge/SpaceChargeCalc3D.hh +++ b/src/spacecharge/SpaceChargeCalc3D.hh @@ -10,25 +10,23 @@ #define SC_SPACECHARGE_CALC_3D_H //MPI Function Wrappers -#include "orbit_mpi.hh" -#include "wrap_mpi_comm.hh" +#include "mpi/orbit_mpi.hh" #include #include +#include //ORBIT bunch -#include "Bunch.hh" +#include "orbit/Bunch.hh" //pyORBIT utils -#include "CppPyWrapper.hh" -#include "BunchExtremaCalculator.hh" +#include "utils/bunch/BunchExtremaCalculator.hh" -#include "Grid3D.hh" -#include "PoissonSolverFFT3D.hh" +#include "spacecharge/Grid3D.hh" +#include "spacecharge/PoissonSolverFFT3D.hh" -using namespace std; -class SpaceChargeCalc3D: public OrbitUtils::CppPyWrapper +class SpaceChargeCalc3D { public: @@ -75,8 +73,8 @@ private: protected: PoissonSolverFFT3D* poissonSolver; - Grid3D* rhoGrid; - Grid3D* phiGrid; + std::unique_ptr rhoGrid; + std::unique_ptr phiGrid; OrbitUtils::BunchExtremaCalculator* bunchExtremaCalc; double xy_ratio; diff --git a/src/spacecharge/SpaceChargeCalcSliceBySlice2D.cc b/src/spacecharge/SpaceChargeCalcSliceBySlice2D.cc index f09a2dba..3c7b7f03 100755 --- a/src/spacecharge/SpaceChargeCalcSliceBySlice2D.cc +++ b/src/spacecharge/SpaceChargeCalcSliceBySlice2D.cc @@ -10,10 +10,10 @@ // ///////////////////////////////////////////////////////////////////////////// -#include "Grid3D.hh" -#include "PoissonSolverFFT2D.hh" -#include "SpaceChargeCalcSliceBySlice2D.hh" -#include "BufferStore.hh" +#include "spacecharge/Grid3D.hh" +#include "spacecharge/PoissonSolverFFT2D.hh" +#include "spacecharge/SpaceChargeCalcSliceBySlice2D.hh" +#include "utils/BufferStore.hh" #include #include @@ -21,38 +21,28 @@ using namespace OrbitUtils; -SpaceChargeCalcSliceBySlice2D::SpaceChargeCalcSliceBySlice2D(int xSize, int ySize, int zSize, double xy_ratio_in): CppPyWrapper(NULL) +SpaceChargeCalcSliceBySlice2D::SpaceChargeCalcSliceBySlice2D(int xSize, int ySize, int zSize, double xy_ratio_in) { xy_ratio = xy_ratio_in; useLongTracking = 0; poissonSolver = new PoissonSolverFFT2D(xSize, ySize, -xy_ratio, xy_ratio, -1.0, 1.0); - rhoGrid3D = new Grid3D(xSize, ySize, zSize); - phiGrid3D = new Grid3D(xSize, ySize, zSize); + rhoGrid3D.reset(new Grid3D(xSize, ySize, zSize)); + phiGrid3D.reset(new Grid3D(xSize, ySize, zSize)); bunchExtremaCalc = new BunchExtremaCalculator(); } -SpaceChargeCalcSliceBySlice2D::SpaceChargeCalcSliceBySlice2D(int xSize, int ySize, int zSize): CppPyWrapper(NULL) +SpaceChargeCalcSliceBySlice2D::SpaceChargeCalcSliceBySlice2D(int xSize, int ySize, int zSize) { xy_ratio = 1.0; useLongTracking = 0; poissonSolver = new PoissonSolverFFT2D(xSize, ySize, -xy_ratio, xy_ratio, -1.0, 1.0); - rhoGrid3D = new Grid3D(xSize, ySize, zSize); - phiGrid3D = new Grid3D(xSize, ySize, zSize); + rhoGrid3D.reset(new Grid3D(xSize, ySize, zSize)); + phiGrid3D.reset(new Grid3D(xSize, ySize, zSize)); bunchExtremaCalc = new BunchExtremaCalculator(); } SpaceChargeCalcSliceBySlice2D::~SpaceChargeCalcSliceBySlice2D(){ delete poissonSolver; - if(rhoGrid3D->getPyWrapper() != NULL){ - Py_DECREF(rhoGrid3D->getPyWrapper()); - } else { - delete rhoGrid3D; - } - if(phiGrid3D->getPyWrapper() != NULL){ - Py_DECREF(phiGrid3D->getPyWrapper()); - } else { - delete phiGrid3D; - } delete bunchExtremaCalc; } @@ -66,11 +56,11 @@ int SpaceChargeCalcSliceBySlice2D::getLongitudinalTracking() } Grid3D* SpaceChargeCalcSliceBySlice2D::getRhoGrid(){ - return rhoGrid3D; + return rhoGrid3D.get(); } Grid3D* SpaceChargeCalcSliceBySlice2D::getPhiGrid(){ - return phiGrid3D; + return phiGrid3D.get(); } diff --git a/src/spacecharge/SpaceChargeCalcSliceBySlice2D.hh b/src/spacecharge/SpaceChargeCalcSliceBySlice2D.hh index 0babb55a..dc327edf 100755 --- a/src/spacecharge/SpaceChargeCalcSliceBySlice2D.hh +++ b/src/spacecharge/SpaceChargeCalcSliceBySlice2D.hh @@ -4,26 +4,24 @@ #define SC_SPACECHARGE_CALC_2P5D_H //MPI Function Wrappers -#include "orbit_mpi.hh" -#include "wrap_mpi_comm.hh" +#include "mpi/orbit_mpi.hh" #include #include +#include //ORBIT bunch -#include "Bunch.hh" +#include "orbit/Bunch.hh" //pyORBIT utils -#include "CppPyWrapper.hh" -#include "BunchExtremaCalculator.hh" +#include "utils/bunch/BunchExtremaCalculator.hh" -#include "Grid3D.hh" -#include "PoissonSolverFFT2D.hh" -#include "BaseBoundary2D.hh" +#include "spacecharge/Grid3D.hh" +#include "spacecharge/PoissonSolverFFT2D.hh" +#include "spacecharge/BaseBoundary2D.hh" -using namespace std; -class SpaceChargeCalcSliceBySlice2D: public OrbitUtils::CppPyWrapper +class SpaceChargeCalcSliceBySlice2D { public: @@ -62,8 +60,8 @@ private: protected: PoissonSolverFFT2D* poissonSolver; - Grid3D* rhoGrid3D; - Grid3D* phiGrid3D; + std::unique_ptr rhoGrid3D; + std::unique_ptr phiGrid3D; OrbitUtils::BunchExtremaCalculator* bunchExtremaCalc; double xy_ratio; diff --git a/src/spacecharge/SpaceChargeCalcUnifEllipse.cc b/src/spacecharge/SpaceChargeCalcUnifEllipse.cc index 250ee81b..e6ea6179 100644 --- a/src/spacecharge/SpaceChargeCalcUnifEllipse.cc +++ b/src/spacecharge/SpaceChargeCalcUnifEllipse.cc @@ -15,18 +15,19 @@ // The space charge kick is transformed later into the lab system. // ///////////////////////////////////////////////////////////////////////////// -#include "SpaceChargeCalcUnifEllipse.hh" -#include "BufferStore.hh" +#include "spacecharge/SpaceChargeCalcUnifEllipse.hh" +#include "utils/BufferStore.hh" -#include "ParticleMacroSize.hh" +#include "orbit/ParticlesAttributes/ParticleMacroSize.hh" +#include #include #include #include using namespace OrbitUtils; -SpaceChargeCalcUnifEllipse::SpaceChargeCalcUnifEllipse(int nEllipses_in): CppPyWrapper(NULL) +SpaceChargeCalcUnifEllipse::SpaceChargeCalcUnifEllipse(int nEllipses_in) { nEllipses = nEllipses_in; ellipsoidCalc_arr = new UniformEllipsoidFieldCalculator*[nEllipses]; @@ -44,11 +45,7 @@ SpaceChargeCalcUnifEllipse::SpaceChargeCalcUnifEllipse(int nEllipses_in): CppPyW SpaceChargeCalcUnifEllipse::~SpaceChargeCalcUnifEllipse(){ for(int ie = 0; ie < nEllipses; ie++){ - if(ellipsoidCalc_arr[ie]->getPyWrapper() != NULL){ - Py_DECREF(ellipsoidCalc_arr[ie]->getPyWrapper()); - } else { - delete ellipsoidCalc_arr[ie]; - } + delete ellipsoidCalc_arr[ie]; } delete [] ellipsoidCalc_arr; @@ -143,7 +140,7 @@ void SpaceChargeCalcUnifEllipse::bunchAnalysis(Bunch* bunch){ } //calculates sum over all CPUs - ORBIT_MPI_Allreduce(coord_avg,coord_avg_out,7,MPI_DOUBLE,MPI_SUM,bunch->getMPI_Comm_Local()->comm); + ORBIT_MPI_Allreduce(coord_avg,coord_avg_out,7,MPI_DOUBLE,MPI_SUM,bunch->getMPI_Comm_Local()); total_macrosize = coord_avg_out[6]; if(total_macrosize == 0.){ @@ -233,7 +230,7 @@ void SpaceChargeCalcUnifEllipse::bunchAnalysis(Bunch* bunch){ } } //calculates sum over all CPUs - ORBIT_MPI_Allreduce(macroSizesEll_arr,macroSizesEll_MPI_arr,nEllipses,MPI_DOUBLE,MPI_SUM,bunch->getMPI_Comm_Local()->comm); + ORBIT_MPI_Allreduce(macroSizesEll_arr,macroSizesEll_MPI_arr,nEllipses,MPI_DOUBLE,MPI_SUM,bunch->getMPI_Comm_Local()); for(int ie = 0; ie < nEllipses; ie++){ macroSizesEll_arr[ie] = macroSizesEll_MPI_arr[ie]; //std::cout<<"debug 0 ie ="<< ie <<" macrosize="<< macroSizesEll_MPI_arr[ie] << std::endl; diff --git a/src/spacecharge/SpaceChargeCalcUnifEllipse.hh b/src/spacecharge/SpaceChargeCalcUnifEllipse.hh index d88f9ba3..8b847e64 100644 --- a/src/spacecharge/SpaceChargeCalcUnifEllipse.hh +++ b/src/spacecharge/SpaceChargeCalcUnifEllipse.hh @@ -8,23 +8,20 @@ #define SC_SPACECHARGE_CALC_UNIFORM_ELLIPSE_HH //MPI Function Wrappers -#include "orbit_mpi.hh" -#include "wrap_mpi_comm.hh" +#include "mpi/orbit_mpi.hh" #include #include //ORBIT bunch -#include "Bunch.hh" +#include "orbit/Bunch.hh" //pyORBIT utils -#include "CppPyWrapper.hh" -#include "UniformEllipsoidFieldCalculator.hh" +#include "spacecharge/UniformEllipsoidFieldCalculator.hh" -using namespace std; -class SpaceChargeCalcUnifEllipse: public OrbitUtils::CppPyWrapper +class SpaceChargeCalcUnifEllipse { public: diff --git a/src/spacecharge/SpaceChargeForceCalc2p5D.cc b/src/spacecharge/SpaceChargeForceCalc2p5D.cc index ae14eb03..f1100f17 100644 --- a/src/spacecharge/SpaceChargeForceCalc2p5D.cc +++ b/src/spacecharge/SpaceChargeForceCalc2p5D.cc @@ -10,11 +10,11 @@ // ///////////////////////////////////////////////////////////////////////////// -#include "Grid1D.hh" -#include "Grid2D.hh" -#include "ForceSolverFFT2D.hh" -#include "SpaceChargeForceCalc2p5D.hh" -#include "BufferStore.hh" +#include "spacecharge/Grid1D.hh" +#include "spacecharge/Grid2D.hh" +#include "spacecharge/ForceSolverFFT2D.hh" +#include "spacecharge/SpaceChargeForceCalc2p5D.hh" +#include "utils/BufferStore.hh" #include #include @@ -22,55 +22,35 @@ using namespace OrbitUtils; -SpaceChargeForceCalc2p5D::SpaceChargeForceCalc2p5D(int xSize, int ySize, int zSize): CppPyWrapper(NULL) +SpaceChargeForceCalc2p5D::SpaceChargeForceCalc2p5D(int xSize, int ySize, int zSize) { forceSolver = new ForceSolverFFT2D(xSize, ySize); - rhoGrid = new Grid2D(xSize, ySize); - forceGridX = new Grid2D(xSize, ySize); - forceGridY = new Grid2D(xSize, ySize); - zGrid = new Grid1D(zSize); + rhoGrid.reset(new Grid2D(xSize, ySize)); + forceGridX.reset(new Grid2D(xSize, ySize)); + forceGridY.reset(new Grid2D(xSize, ySize)); + zGrid.reset(new Grid1D(zSize)); bunchExtremaCalc = new BunchExtremaCalculator(); } SpaceChargeForceCalc2p5D::~SpaceChargeForceCalc2p5D(){ delete forceSolver; - if(rhoGrid->getPyWrapper() != NULL){ - Py_DECREF(rhoGrid->getPyWrapper()); - } else { - delete rhoGrid; - } - if(forceGridX->getPyWrapper() != NULL){ - Py_DECREF(forceGridX->getPyWrapper()); - } else { - delete forceGridX; - } - if(forceGridY->getPyWrapper() != NULL){ - Py_DECREF(forceGridY->getPyWrapper()); - } else { - delete forceGridY; - } - if(zGrid->getPyWrapper() != NULL){ - Py_DECREF(zGrid->getPyWrapper()); - } else { - delete zGrid; - } delete bunchExtremaCalc; } Grid2D* SpaceChargeForceCalc2p5D::getRhoGrid(){ - return rhoGrid; + return rhoGrid.get(); } Grid2D* SpaceChargeForceCalc2p5D::getForceGridX(){ - return forceGridX; + return forceGridX.get(); } Grid2D* SpaceChargeForceCalc2p5D::getForceGridY(){ - return forceGridY; + return forceGridY.get(); } Grid1D* SpaceChargeForceCalc2p5D::getLongGrid(){ - return zGrid; + return zGrid.get(); } void SpaceChargeForceCalc2p5D::trackBunch(Bunch* bunch, double length){ @@ -86,7 +66,7 @@ void SpaceChargeForceCalc2p5D::trackBunch(Bunch* bunch, double length){ double z_step = zGrid->getStepZ(); //calculate phiGrid - forceSolver->findForce(rhoGrid, forceGridX, forceGridY); + forceSolver->findForce(rhoGrid.get(), forceGridX.get(), forceGridY.get()); SyncPart* syncPart = bunch->getSyncPart(); double factor = 2*length*bunch->getClassicalRadius()/(pow(syncPart->getBeta(),2)*pow(syncPart->getGamma(),3)); diff --git a/src/spacecharge/SpaceChargeForceCalc2p5D.hh b/src/spacecharge/SpaceChargeForceCalc2p5D.hh index 35b49a52..7325f7a6 100644 --- a/src/spacecharge/SpaceChargeForceCalc2p5D.hh +++ b/src/spacecharge/SpaceChargeForceCalc2p5D.hh @@ -4,26 +4,24 @@ #define SC_SPACEFORCECHARGE_CALC_2P5D_H //MPI Function Wrappers -#include "orbit_mpi.hh" -#include "wrap_mpi_comm.hh" +#include "mpi/orbit_mpi.hh" #include #include +#include //ORBIT bunch -#include "Bunch.hh" +#include "orbit/Bunch.hh" //pyORBIT utils -#include "CppPyWrapper.hh" -#include "BunchExtremaCalculator.hh" +#include "utils/bunch/BunchExtremaCalculator.hh" -#include "Grid1D.hh" -#include "Grid2D.hh" -#include "ForceSolverFFT2D.hh" -#include "BaseBoundary2D.hh" +#include "spacecharge/Grid1D.hh" +#include "spacecharge/Grid2D.hh" +#include "spacecharge/ForceSolverFFT2D.hh" +#include "spacecharge/BaseBoundary2D.hh" -using namespace std; -class SpaceChargeForceCalc2p5D: public OrbitUtils::CppPyWrapper +class SpaceChargeForceCalc2p5D { public: @@ -57,11 +55,11 @@ private: protected: ForceSolverFFT2D* forceSolver; - Grid2D* rhoGrid; - Grid2D* phiGrid; - Grid2D* forceGridX; - Grid2D* forceGridY; - Grid1D* zGrid; + std::unique_ptr rhoGrid; + std::unique_ptr phiGrid; + std::unique_ptr forceGridX; + std::unique_ptr forceGridY; + std::unique_ptr zGrid; OrbitUtils::BunchExtremaCalculator* bunchExtremaCalc; }; diff --git a/src/spacecharge/UniformEllipsoidFieldCalculator.cc b/src/spacecharge/UniformEllipsoidFieldCalculator.cc index 811eb52d..d0a16bcc 100644 --- a/src/spacecharge/UniformEllipsoidFieldCalculator.cc +++ b/src/spacecharge/UniformEllipsoidFieldCalculator.cc @@ -4,11 +4,10 @@ */ //MPI Function Wrappers -#include "orbit_mpi.hh" -#include "wrap_mpi_comm.hh" +#include "mpi/orbit_mpi.hh" -#include "UniformEllipsoidFieldCalculator.hh" -#include "gauss_legendre_points.hh" +#include "spacecharge/UniformEllipsoidFieldCalculator.hh" +#include "utils/integration/gauss_legendre_points.hh" #include @@ -26,7 +25,7 @@ using namespace OrbitUtils; #endif /** Constructor. There is no parameters */ -UniformEllipsoidFieldCalculator::UniformEllipsoidFieldCalculator(): CppPyWrapper(NULL) +UniformEllipsoidFieldCalculator::UniformEllipsoidFieldCalculator() { intFuncX0 = new Function(); intFuncY0 = new Function(); diff --git a/src/spacecharge/UniformEllipsoidFieldCalculator.hh b/src/spacecharge/UniformEllipsoidFieldCalculator.hh index 6df271e7..5f4ecefb 100644 --- a/src/spacecharge/UniformEllipsoidFieldCalculator.hh +++ b/src/spacecharge/UniformEllipsoidFieldCalculator.hh @@ -1,16 +1,12 @@ #ifndef UNIFORM_SC_ELLIPSOID_HH #define UNIFORM_SC_ELLIPSOID_HH -//pyORBIT utils -#include "CppPyWrapper.hh" - //Function from OrbitUtils -#include "OU_Function.hh" +#include "utils/OU_Function.hh" #include #include -using namespace std; /** This class calculates the field of uniformly charged ellipsoid by using @@ -18,7 +14,7 @@ using namespace std; */ -class UniformEllipsoidFieldCalculator: public OrbitUtils::CppPyWrapper +class UniformEllipsoidFieldCalculator { public: diff --git a/src/spacecharge/wrap_boundary2d.cc b/src/spacecharge/wrap_boundary2d.cc index f634b438..9cf41bea 100644 --- a/src/spacecharge/wrap_boundary2d.cc +++ b/src/spacecharge/wrap_boundary2d.cc @@ -1,14 +1,14 @@ -#include "orbit_mpi.hh" -#include "pyORBIT_Object.hh" +#include "mpi/orbit_mpi.hh" +#include "main/pyORBIT_Object.hh" -#include "wrap_boundary2d.hh" -#include "wrap_spacecharge.hh" +#include "spacecharge/wrap_boundary2d.hh" +#include "spacecharge/wrap_spacecharge.hh" #include -#include "BaseBoundary2D.hh" -#include "ShapedBoundary2D.hh" -#include "Grid2D.hh" +#include "spacecharge/BaseBoundary2D.hh" +#include "spacecharge/ShapedBoundary2D.hh" +#include "spacecharge/Grid2D.hh" using namespace OrbitUtils; @@ -45,7 +45,6 @@ extern "C" { ORBIT_MPI_Finalize("PyBoundary2D - Boundary2D(nPoints,nModes) - constructor needs parameters."); } self->cpp_obj = new BaseBoundary2D(nPoints, nModes); - ((BaseBoundary2D*) self->cpp_obj)->setPyWrapper((PyObject*) self); //std::cerr<<"The Boundary2D __init__ has been called!"<cpp_obj = new ShapedBoundary2D(nPoints, nModes,shape,xDim,yDim); - ((BaseBoundary2D*) self->cpp_obj)->setPyWrapper((PyObject*) self); //std::cerr<<"The Boundary2D __init__ has been called!"< #ifdef __cplusplus extern "C" { diff --git a/src/spacecharge/wrap_forcesolverfft2d.cc b/src/spacecharge/wrap_forcesolverfft2d.cc index b8e03f56..b148c8be 100644 --- a/src/spacecharge/wrap_forcesolverfft2d.cc +++ b/src/spacecharge/wrap_forcesolverfft2d.cc @@ -1,11 +1,11 @@ -#include "orbit_mpi.hh" -#include "pyORBIT_Object.hh" +#include "mpi/orbit_mpi.hh" +#include "main/pyORBIT_Object.hh" -#include "ForceSolverFFT2D.hh" -#include "Grid2D.hh" +#include "spacecharge/ForceSolverFFT2D.hh" +#include "spacecharge/Grid2D.hh" -#include "wrap_forcesolverfft2d.hh" -#include "wrap_spacecharge.hh" +#include "spacecharge/wrap_forcesolverfft2d.hh" +#include "spacecharge/wrap_spacecharge.hh" #include @@ -40,7 +40,6 @@ extern "C" { ORBIT_MPI_Finalize("PyForceSolverFFT2D - ForceSolverFFT2D(nX,nY) - constructor needs parameters."); } self->cpp_obj = new ForceSolverFFT2D(xSize,ySize); - ((ForceSolverFFT2D*) self->cpp_obj)->setPyWrapper((PyObject*) self); //std::cerr<<"The ForceSolverFFT2D __init__ has been called!"< #ifdef __cplusplus extern "C" { diff --git a/src/spacecharge/wrap_grid.hh b/src/spacecharge/wrap_grid.hh new file mode 100644 index 00000000..d076dcfb --- /dev/null +++ b/src/spacecharge/wrap_grid.hh @@ -0,0 +1,13 @@ +#ifndef WRAP_SPACE_CHARGE_GRID_H +#define WRAP_SPACE_CHARGE_GRID_H + +#include + +typedef struct { + PyObject_HEAD + void* cpp_obj; + int owns_cpp; + PyObject* owner; +} pyORBIT_Grid; + +#endif diff --git a/src/spacecharge/wrap_grid1D.cc b/src/spacecharge/wrap_grid1D.cc index a194ae7c..dd1bfa96 100644 --- a/src/spacecharge/wrap_grid1D.cc +++ b/src/spacecharge/wrap_grid1D.cc @@ -1,14 +1,16 @@ -#include "orbit_mpi.hh" -#include "pyORBIT_Object.hh" +#include "mpi/orbit_mpi.hh" +#include "mpi/wrap_orbit_mpi_types.hh" +#include "main/pyORBIT_Object.hh" -#include "wrap_grid1D.hh" -#include "wrap_spacecharge.hh" -#include "wrap_bunch.hh" -#include "wrap_mpi_comm.hh" +#include "spacecharge/wrap_grid1D.hh" +#include "spacecharge/wrap_grid.hh" +#include "spacecharge/wrap_spacecharge.hh" +#include "orbit/wrap_bunch.hh" +#include "mpi/wrap_mpi_comm.hh" #include -#include "Grid1D.hh" +#include "spacecharge/Grid1D.hh" using namespace OrbitUtils; @@ -30,9 +32,11 @@ extern "C" static PyObject* Grid1D_new(PyTypeObject *type, PyObject *args, PyObject *kwds) { - pyORBIT_Object* self; - self = (pyORBIT_Object *) type->tp_alloc(type, 0); + pyORBIT_Grid* self; + self = (pyORBIT_Grid *) type->tp_alloc(type, 0); self->cpp_obj = NULL; + self->owns_cpp = 0; + self->owner = NULL; // std::cerr << "The Grid1D new has been called!" << std::endl; return (PyObject *) self; } @@ -41,7 +45,7 @@ static PyObject* Grid1D_new(PyTypeObject *type, PyObject *args, PyObject *kwds) // Initializator for python Grid1D class // This is implementation of the __init__ method -static int Grid1D_init(pyORBIT_Object *self, PyObject *args, PyObject *kwds) +static int Grid1D_init(pyORBIT_Grid *self, PyObject *args, PyObject *kwds) { int nVars = PyTuple_Size(args); int binZ; @@ -61,7 +65,8 @@ static int Grid1D_init(pyORBIT_Object *self, PyObject *args, PyObject *kwds) } self->cpp_obj = new Grid1D(binZ, zMin, zMax); } - ((Grid1D*) self->cpp_obj)->setPyWrapper((PyObject*) self); + self->owns_cpp = 1; + pyorbit::registerPyWrapper(self->cpp_obj, (PyObject*) self); // std::cerr << "The Grid1D __init__ has been called!" << std::endl; return 0; } @@ -445,7 +450,7 @@ static PyObject* Grid1D_synchronizeMPI(PyObject *self, PyObject *args) { ORBIT_MPI_Finalize("Grid1D.synchronizeMPI(MPI_Comm) - input parameter is not MPI_Comm"); } - cpp_Grid1D->synchronizeMPI((pyORBIT_MPI_Comm*) pyMPIComm); + cpp_Grid1D->synchronizeMPI(((pyORBIT_MPI_Comm*) pyMPIComm)->comm); } Py_INCREF(Py_None); return Py_None; @@ -456,11 +461,14 @@ static PyObject* Grid1D_synchronizeMPI(PyObject *self, PyObject *args) // Destructor for python Grid1D class (__del__ method). //----------------------------------------------------- -static void Grid1D_del(pyORBIT_Object* self) +static void Grid1D_del(pyORBIT_Grid* self) { //std::cerr << "The Grid1D __del__ has been called!" << std::endl; Grid1D* cpp_Grid1D = (Grid1D*) self->cpp_obj; - delete cpp_Grid1D; + pyorbit::unregisterPyWrapper(cpp_Grid1D, (PyObject*) self); + if(self->owns_cpp) delete cpp_Grid1D; + self->cpp_obj = NULL; + Py_CLEAR(self->owner); self->ob_base.ob_type->tp_free((PyObject*)self); } @@ -511,7 +519,7 @@ static PyTypeObject pyORBIT_Grid1D_Type = { PyVarObject_HEAD_INIT(NULL, 0) "Grid1D", /*tp_name*/ - sizeof(pyORBIT_Object), /*tp_basicsize*/ + sizeof(pyORBIT_Grid), /*tp_basicsize*/ 0, /*tp_itemsize*/ (destructor) Grid1D_del , /*tp_dealloc*/ 0, /*tp_print*/ @@ -549,6 +557,24 @@ static PyTypeObject pyORBIT_Grid1D_Type = Grid1D_new, /* tp_new */ }; +PyObject* wrapGrid1D(Grid1D* grid, PyObject* owner) +{ + PyObject* wrapper = pyorbit::getPyWrapper(grid); + if(wrapper != NULL) { + Py_INCREF(wrapper); + return wrapper; + } + + pyORBIT_Grid* self = (pyORBIT_Grid*) pyORBIT_Grid1D_Type.tp_alloc(&pyORBIT_Grid1D_Type, 0); + if(self == NULL) return NULL; + self->cpp_obj = grid; + self->owns_cpp = 0; + self->owner = owner; + Py_XINCREF(owner); + pyorbit::registerPyWrapper(grid, (PyObject*) self); + return (PyObject*) self; +} + //-------------------------------------------------- // Initialization function of the pyGrid1D class diff --git a/src/spacecharge/wrap_grid1D.hh b/src/spacecharge/wrap_grid1D.hh index e7ed0805..bbb2b9d4 100644 --- a/src/spacecharge/wrap_grid1D.hh +++ b/src/spacecharge/wrap_grid1D.hh @@ -1,7 +1,9 @@ #ifndef WRAP_SPACE_CHARGE_GRID_1D_H #define WRAP_SPACE_CHARGE_GRID_1D_H -#include "Python.h" +#include + +class Grid1D; #ifdef __cplusplus extern "C" @@ -11,6 +13,7 @@ extern "C" namespace wrap_spacecharge { void initGrid1D(PyObject* module); + PyObject* wrapGrid1D(Grid1D* grid, PyObject* owner); } #ifdef __cplusplus diff --git a/src/spacecharge/wrap_grid2D.cc b/src/spacecharge/wrap_grid2D.cc index e1fb5f84..952680f6 100644 --- a/src/spacecharge/wrap_grid2D.cc +++ b/src/spacecharge/wrap_grid2D.cc @@ -1,13 +1,16 @@ -#include "orbit_mpi.hh" -#include "pyORBIT_Object.hh" +#include "mpi/orbit_mpi.hh" +#include "mpi/wrap_orbit_mpi_types.hh" +#include "main/pyORBIT_Object.hh" -#include "wrap_grid2D.hh" -#include "wrap_spacecharge.hh" -#include "wrap_bunch.hh" +#include "spacecharge/wrap_grid2D.hh" +#include "spacecharge/wrap_grid.hh" +#include "spacecharge/wrap_spacecharge.hh" +#include "orbit/wrap_bunch.hh" +#include "mpi/wrap_mpi_comm.hh" #include -#include "Grid2D.hh" +#include "spacecharge/Grid2D.hh" using namespace OrbitUtils; @@ -25,23 +28,26 @@ extern "C" { //It never will be called directly static PyObject* Grid2D_new(PyTypeObject *type, PyObject *args, PyObject *kwds) { - pyORBIT_Object* self; - self = (pyORBIT_Object *) type->tp_alloc(type, 0); + pyORBIT_Grid* self; + self = (pyORBIT_Grid *) type->tp_alloc(type, 0); self->cpp_obj = NULL; + self->owns_cpp = 0; + self->owner = NULL; //std::cerr<<"The Grid2D new has been called!"<cpp_obj = new Grid2D(binX,binY,xMin,xMax,yMin,yMax); - ((Grid2D*) self->cpp_obj)->setPyWrapper((PyObject*) self); + self->owns_cpp = 1; + pyorbit::registerPyWrapper(self->cpp_obj, (PyObject*) self); //std::cerr<<"The Grid2D __init__ has been called!"<synchronizeMPI((pyORBIT_MPI_Comm*) pyMPIComm); + cpp_Grid2D->synchronizeMPI(((pyORBIT_MPI_Comm*) pyMPIComm)->comm); } Py_INCREF(Py_None); return Py_None; @@ -350,10 +356,13 @@ extern "C" { //----------------------------------------------------- //destructor for python Grid2D class (__del__ method). //----------------------------------------------------- - static void Grid2D_del(pyORBIT_Object* self){ + static void Grid2D_del(pyORBIT_Grid* self){ //std::cerr<<"The Grid2D __del__ has been called!"<cpp_obj; - delete cpp_Grid2D; + pyorbit::unregisterPyWrapper(cpp_Grid2D, (PyObject*) self); + if(self->owns_cpp) delete cpp_Grid2D; + self->cpp_obj = NULL; + Py_CLEAR(self->owner); self->ob_base.ob_type->tp_free((PyObject*)self); } @@ -398,7 +407,7 @@ extern "C" { static PyTypeObject pyORBIT_Grid2D_Type = { PyVarObject_HEAD_INIT(NULL, 0) "Grid2D", /*tp_name*/ - sizeof(pyORBIT_Object), /*tp_basicsize*/ + sizeof(pyORBIT_Grid), /*tp_basicsize*/ 0, /*tp_itemsize*/ (destructor) Grid2D_del , /*tp_dealloc*/ 0, /*tp_print*/ @@ -436,6 +445,24 @@ extern "C" { Grid2D_new, /* tp_new */ }; + PyObject* wrapGrid2D(Grid2D* grid, PyObject* owner) + { + PyObject* wrapper = pyorbit::getPyWrapper(grid); + if(wrapper != NULL) { + Py_INCREF(wrapper); + return wrapper; + } + + pyORBIT_Grid* self = (pyORBIT_Grid*) pyORBIT_Grid2D_Type.tp_alloc(&pyORBIT_Grid2D_Type, 0); + if(self == NULL) return NULL; + self->cpp_obj = grid; + self->owns_cpp = 0; + self->owner = owner; + Py_XINCREF(owner); + pyorbit::registerPyWrapper(grid, (PyObject*) self); + return (PyObject*) self; + } + //-------------------------------------------------- //Initialization function of the pyGrid2D class //It will be called from SpaceCharge wrapper initialization diff --git a/src/spacecharge/wrap_grid2D.hh b/src/spacecharge/wrap_grid2D.hh index 73501b59..becee2c4 100644 --- a/src/spacecharge/wrap_grid2D.hh +++ b/src/spacecharge/wrap_grid2D.hh @@ -1,7 +1,9 @@ #ifndef WRAP_SPACE_CHARGE_GRID_2D_H #define WRAP_SPACE_CHARGE_GRID_2D_H -#include "Python.h" +#include + +class Grid2D; #ifdef __cplusplus extern "C" { @@ -9,6 +11,7 @@ extern "C" { namespace wrap_spacecharge{ void initGrid2D(PyObject* module); + PyObject* wrapGrid2D(Grid2D* grid, PyObject* owner); } #ifdef __cplusplus diff --git a/src/spacecharge/wrap_grid3D.cc b/src/spacecharge/wrap_grid3D.cc index 5dcc32b0..c82252cb 100644 --- a/src/spacecharge/wrap_grid3D.cc +++ b/src/spacecharge/wrap_grid3D.cc @@ -1,13 +1,16 @@ -#include "orbit_mpi.hh" -#include "pyORBIT_Object.hh" +#include "mpi/orbit_mpi.hh" +#include "mpi/wrap_orbit_mpi_types.hh" +#include "main/pyORBIT_Object.hh" -#include "wrap_grid3D.hh" -#include "wrap_spacecharge.hh" -#include "wrap_bunch.hh" +#include "spacecharge/wrap_grid3D.hh" +#include "spacecharge/wrap_grid.hh" +#include "spacecharge/wrap_spacecharge.hh" +#include "orbit/wrap_bunch.hh" +#include "mpi/wrap_mpi_comm.hh" #include -#include "Grid3D.hh" +#include "spacecharge/Grid3D.hh" using namespace OrbitUtils; @@ -25,21 +28,24 @@ extern "C" { //It never will be called directly static PyObject* Grid3D_new(PyTypeObject *type, PyObject *args, PyObject *kwds) { - pyORBIT_Object* self; - self = (pyORBIT_Object *) type->tp_alloc(type, 0); + pyORBIT_Grid* self; + self = (pyORBIT_Grid *) type->tp_alloc(type, 0); self->cpp_obj = NULL; + self->owns_cpp = 0; + self->owner = NULL; return (PyObject *) self; } //initializator for python Grid3D class //this is implementation of the __init__ method - static int Grid3D_init(pyORBIT_Object *self, PyObject *args, PyObject *kwds){ + static int Grid3D_init(pyORBIT_Grid *self, PyObject *args, PyObject *kwds){ int binX, binY, binZ; if(!PyArg_ParseTuple(args,"iii:__init__",&binX,&binY,&binZ)){ ORBIT_MPI_Finalize("PyGrid3D - Grid3D(nX,nY,nZ) - constructor needs parameters."); } self->cpp_obj = new Grid3D(binX,binY,binZ); - ((Grid3D*) self->cpp_obj)->setPyWrapper((PyObject*) self); + self->owns_cpp = 1; + pyorbit::registerPyWrapper(self->cpp_obj, (PyObject*) self); return 0; } @@ -195,7 +201,7 @@ extern "C" { if((!PyObject_IsInstance(pyMPIComm,py_mpi_comm_type))){ ORBIT_MPI_Finalize("Grid3D.synchronizeMPI(MPI_Comm) - input parameter is not MPI_Comm"); } - cpp_Grid3D->synchronizeMPI((pyORBIT_MPI_Comm*) pyMPIComm); + cpp_Grid3D->synchronizeMPI(((pyORBIT_MPI_Comm*) pyMPIComm)->comm); } Py_INCREF(Py_None); return Py_None; @@ -311,10 +317,13 @@ extern "C" { //----------------------------------------------------- //destructor for python Grid3D class (__del__ method). //----------------------------------------------------- - static void Grid3D_del(pyORBIT_Object* self){ + static void Grid3D_del(pyORBIT_Grid* self){ //std::cerr<<"The Grid3D __del__ has been called!"<cpp_obj; - delete cpp_Grid3D; + pyorbit::unregisterPyWrapper(cpp_Grid3D, (PyObject*) self); + if(self->owns_cpp) delete cpp_Grid3D; + self->cpp_obj = NULL; + Py_CLEAR(self->owner); self->ob_base.ob_type->tp_free((PyObject*)self); } @@ -358,7 +367,7 @@ extern "C" { static PyTypeObject pyORBIT_Grid3D_Type = { PyVarObject_HEAD_INIT(NULL, 0) "Grid3D", /*tp_name*/ - sizeof(pyORBIT_Object), /*tp_basicsize*/ + sizeof(pyORBIT_Grid), /*tp_basicsize*/ 0, /*tp_itemsize*/ (destructor) Grid3D_del , /*tp_dealloc*/ 0, /*tp_print*/ @@ -396,6 +405,24 @@ extern "C" { Grid3D_new, /* tp_new */ }; + PyObject* wrapGrid3D(Grid3D* grid, PyObject* owner) + { + PyObject* wrapper = pyorbit::getPyWrapper(grid); + if(wrapper != NULL) { + Py_INCREF(wrapper); + return wrapper; + } + + pyORBIT_Grid* self = (pyORBIT_Grid*) pyORBIT_Grid3D_Type.tp_alloc(&pyORBIT_Grid3D_Type, 0); + if(self == NULL) return NULL; + self->cpp_obj = grid; + self->owns_cpp = 0; + self->owner = owner; + Py_XINCREF(owner); + pyorbit::registerPyWrapper(grid, (PyObject*) self); + return (PyObject*) self; + } + //-------------------------------------------------- //Initialization function of the pyGrid3D class //It will be called from SpaceCharge wrapper initialization diff --git a/src/spacecharge/wrap_grid3D.hh b/src/spacecharge/wrap_grid3D.hh index 4a465399..4883ef1a 100644 --- a/src/spacecharge/wrap_grid3D.hh +++ b/src/spacecharge/wrap_grid3D.hh @@ -1,7 +1,9 @@ #ifndef WRAP_SPACE_CHARGE_GRID_3D_H #define WRAP_SPACE_CHARGE_GRID_3D_H -#include "Python.h" +#include + +class Grid3D; #ifdef __cplusplus extern "C" { @@ -9,6 +11,7 @@ extern "C" { namespace wrap_spacecharge{ void initGrid3D(PyObject* module); + PyObject* wrapGrid3D(Grid3D* grid, PyObject* owner); } #ifdef __cplusplus diff --git a/src/spacecharge/wrap_lspacechargecalc.cc b/src/spacecharge/wrap_lspacechargecalc.cc index fd089ad5..9c7c7712 100644 --- a/src/spacecharge/wrap_lspacechargecalc.cc +++ b/src/spacecharge/wrap_lspacechargecalc.cc @@ -1,12 +1,12 @@ -#include "orbit_mpi.hh" -#include "pyORBIT_Object.hh" +#include "mpi/orbit_mpi.hh" +#include "main/pyORBIT_Object.hh" -#include "wrap_lspacechargecalc.hh" -#include "wrap_bunch.hh" +#include "spacecharge/wrap_lspacechargecalc.hh" +#include "orbit/wrap_bunch.hh" #include -#include "LSpaceChargeCalc.hh" +#include "spacecharge/LSpaceChargeCalc.hh" using namespace OrbitUtils; @@ -55,7 +55,6 @@ extern "C" self->cpp_obj = new LSpaceChargeCalc(b_a, length, nMacrosMin, useSpaceCharge, nBins); - ((LSpaceChargeCalc*) self->cpp_obj)->setPyWrapper((PyObject*) self); return 0; } diff --git a/src/spacecharge/wrap_lspacechargecalc.hh b/src/spacecharge/wrap_lspacechargecalc.hh index 17963c15..6c55a07a 100644 --- a/src/spacecharge/wrap_lspacechargecalc.hh +++ b/src/spacecharge/wrap_lspacechargecalc.hh @@ -1,7 +1,7 @@ #ifndef WRAP_SPACE_CHARGE_CALC_L_H #define WRAP_SPACE_CHARGE_CALC_L_H -#include "Python.h" +#include #ifdef __cplusplus extern "C" diff --git a/src/spacecharge/wrap_poissonsolverfft2d.cc b/src/spacecharge/wrap_poissonsolverfft2d.cc index 1e04e405..4835f00b 100644 --- a/src/spacecharge/wrap_poissonsolverfft2d.cc +++ b/src/spacecharge/wrap_poissonsolverfft2d.cc @@ -1,11 +1,11 @@ -#include "orbit_mpi.hh" -#include "pyORBIT_Object.hh" +#include "mpi/orbit_mpi.hh" +#include "main/pyORBIT_Object.hh" -#include "PoissonSolverFFT2D.hh" -#include "Grid2D.hh" +#include "spacecharge/PoissonSolverFFT2D.hh" +#include "spacecharge/Grid2D.hh" -#include "wrap_poissonsolverfft2d.hh" -#include "wrap_spacecharge.hh" +#include "spacecharge/wrap_poissonsolverfft2d.hh" +#include "spacecharge/wrap_spacecharge.hh" #include @@ -42,7 +42,6 @@ extern "C" { ORBIT_MPI_Finalize("PyPoissonSolverFFT2D - PoissonSolverFFT2D(nX,nY[,xMin,xMax,yMin,yMax]) - constructor needs parameters."); } self->cpp_obj = new PoissonSolverFFT2D(xSize,ySize,xMin,xMax,yMin,yMax); - ((PoissonSolverFFT2D*) self->cpp_obj)->setPyWrapper((PyObject*) self); //std::cerr<<"The PoissonSolverFFT2D __init__ has been called!"< #ifdef __cplusplus extern "C" { diff --git a/src/spacecharge/wrap_poissonsolverfft3d.cc b/src/spacecharge/wrap_poissonsolverfft3d.cc index 65af4b89..6ab6378f 100644 --- a/src/spacecharge/wrap_poissonsolverfft3d.cc +++ b/src/spacecharge/wrap_poissonsolverfft3d.cc @@ -1,11 +1,11 @@ -#include "orbit_mpi.hh" -#include "pyORBIT_Object.hh" +#include "mpi/orbit_mpi.hh" +#include "main/pyORBIT_Object.hh" -#include "PoissonSolverFFT3D.hh" -#include "Grid3D.hh" +#include "spacecharge/PoissonSolverFFT3D.hh" +#include "spacecharge/Grid3D.hh" -#include "wrap_poissonsolverfft2d.hh" -#include "wrap_spacecharge.hh" +#include "spacecharge/wrap_poissonsolverfft2d.hh" +#include "spacecharge/wrap_spacecharge.hh" #include @@ -43,7 +43,6 @@ extern "C" { ORBIT_MPI_Finalize("PyPoissonSolverFFT3D - PoissonSolverFFT3D(nX,nY,nZ,[,xMin,xMax,yMin,yMax,zMin,zMax]) - constructor needs parameters."); } self->cpp_obj = new PoissonSolverFFT3D(xSize,ySize,zSize,xMin,xMax,yMin,yMax,zMin,zMax); - ((PoissonSolverFFT3D*) self->cpp_obj)->setPyWrapper((PyObject*) self); //std::cerr<<"The PoissonSolverFFT3D __init__ has been called!"< #ifdef __cplusplus extern "C" { diff --git a/src/spacecharge/wrap_spacecharge.cc b/src/spacecharge/wrap_spacecharge.cc index ab8d9ed5..be8fe364 100644 --- a/src/spacecharge/wrap_spacecharge.cc +++ b/src/spacecharge/wrap_spacecharge.cc @@ -1,21 +1,21 @@ -#include "orbit_mpi.hh" +#include "mpi/orbit_mpi.hh" -#include "wrap_grid1D.hh" -#include "wrap_grid2D.hh" -#include "wrap_grid3D.hh" -#include "wrap_poissonsolverfft2d.hh" -#include "wrap_poissonsolverfft3d.hh" -#include "wrap_forcesolverfft2d.hh" -#include "wrap_boundary2d.hh" -#include "wrap_spacecharge.hh" -#include "wrap_spacechargecalc2p5d.hh" -#include "wrap_spacechargeforcecalc2p5d.hh" -#include "wrap_spacechargecalc2p5d_rb.hh" -#include "wrap_spacechargecalc_slicebyslice_2D.hh" -#include "wrap_lspacechargecalc.hh" -#include "wrap_spacechargecalc3d.hh" -#include "wrap_uniform_ellipsoid_field_calculator.hh" -#include "wrap_spacechargecalc_uniform_ellipse.hh" +#include "spacecharge/wrap_grid1D.hh" +#include "spacecharge/wrap_grid2D.hh" +#include "spacecharge/wrap_grid3D.hh" +#include "spacecharge/wrap_poissonsolverfft2d.hh" +#include "spacecharge/wrap_poissonsolverfft3d.hh" +#include "spacecharge/wrap_forcesolverfft2d.hh" +#include "spacecharge/wrap_boundary2d.hh" +#include "spacecharge/wrap_spacecharge.hh" +#include "spacecharge/wrap_spacechargecalc2p5d.hh" +#include "spacecharge/wrap_spacechargeforcecalc2p5d.hh" +#include "spacecharge/wrap_spacechargecalc2p5d_rb.hh" +#include "spacecharge/wrap_spacechargecalc_slicebyslice_2D.hh" +#include "spacecharge/wrap_lspacechargecalc.hh" +#include "spacecharge/wrap_spacechargecalc3d.hh" +#include "spacecharge/wrap_uniform_ellipsoid_field_calculator.hh" +#include "spacecharge/wrap_spacechargecalc_uniform_ellipse.hh" static PyMethodDef spacechargeMethods[] = { {NULL,NULL} }; @@ -52,14 +52,6 @@ extern "C" { return module; } - PyObject* getSpaceChargeType(const char* name){ - PyObject* mod = PyImport_ImportModule("orbit.core.spacecharge"); - PyObject* pyType = PyObject_GetAttrString(mod,name); - Py_DECREF(mod); - Py_DECREF(pyType); - return pyType; - } - #ifdef __cplusplus } #endif diff --git a/src/spacecharge/wrap_spacecharge.hh b/src/spacecharge/wrap_spacecharge.hh index 12bddf42..1120c9f1 100644 --- a/src/spacecharge/wrap_spacecharge.hh +++ b/src/spacecharge/wrap_spacecharge.hh @@ -1,7 +1,7 @@ #ifndef WRAP_SPACE_CHARGE_H #define WRAP_SPACE_CHARGE_H -#include "Python.h" +#include #ifdef __cplusplus extern "C" { diff --git a/src/spacecharge/wrap_spacechargecalc2p5d.cc b/src/spacecharge/wrap_spacechargecalc2p5d.cc index 2ba12f3c..c5ff65ec 100644 --- a/src/spacecharge/wrap_spacechargecalc2p5d.cc +++ b/src/spacecharge/wrap_spacechargecalc2p5d.cc @@ -1,13 +1,15 @@ -#include "orbit_mpi.hh" -#include "pyORBIT_Object.hh" +#include "mpi/orbit_mpi.hh" +#include "main/pyORBIT_Object.hh" # -#include "wrap_spacechargecalc2p5d.hh" -#include "wrap_spacecharge.hh" -#include "wrap_bunch.hh" +#include "spacecharge/wrap_spacechargecalc2p5d.hh" +#include "spacecharge/wrap_spacecharge.hh" +#include "spacecharge/wrap_grid1D.hh" +#include "spacecharge/wrap_grid2D.hh" +#include "orbit/wrap_bunch.hh" #include -#include "SpaceChargeCalc2p5D.hh" +#include "spacecharge/SpaceChargeCalc2p5D.hh" using namespace OrbitUtils; @@ -46,7 +48,6 @@ extern "C" { } else { self->cpp_obj = new SpaceChargeCalc2p5D(xSize,ySize,zSize); } - ((SpaceChargeCalc2p5D*) self->cpp_obj)->setPyWrapper((PyObject*) self); //std::cerr<<"The SpaceChargeCalc2p5D __init__ has been called!"<cpp_obj; - Grid2D* cpp_grid2d = cpp_SpaceChargeCalc2p5D->getRhoGrid(); - if(cpp_grid2d->getPyWrapper() != NULL){ - Py_INCREF(cpp_grid2d->getPyWrapper()); - return cpp_grid2d->getPyWrapper(); - } - //It will create a pyGrid2D object - PyObject* mod = PyImport_ImportModule("orbit.core.spacecharge"); - PyObject* pyGrid2D = PyObject_CallMethod(mod,const_cast("Grid2D"),const_cast("ii"),cpp_grid2d->getSizeX(),cpp_grid2d->getSizeY()); - //delete the c++ reference to the internal Grid2D inside pyGrid2D and assign the new one - delete ((Grid2D*)((pyORBIT_Object*) pyGrid2D)->cpp_obj); - ((pyORBIT_Object*) pyGrid2D)->cpp_obj = cpp_grid2d; - cpp_grid2d->setPyWrapper(pyGrid2D); - Py_INCREF(cpp_grid2d->getPyWrapper()); - Py_DECREF(mod); - return pyGrid2D; + return wrapGrid2D(cpp_SpaceChargeCalc2p5D->getRhoGrid(), self); } //Grid2D* getPhiGrid() returns the 2D grid with potential static PyObject* SpaceChargeCalc2p5D_getPhiGrid(PyObject *self, PyObject *args){ pyORBIT_Object* pySpaceChargeCalc2p5D = (pyORBIT_Object*) self; SpaceChargeCalc2p5D* cpp_SpaceChargeCalc2p5D = (SpaceChargeCalc2p5D*) pySpaceChargeCalc2p5D->cpp_obj; - Grid2D* cpp_grid2d = cpp_SpaceChargeCalc2p5D->getPhiGrid(); - if(cpp_grid2d->getPyWrapper() != NULL){ - Py_INCREF(cpp_grid2d->getPyWrapper()); - return cpp_grid2d->getPyWrapper(); - } - //It will create a pyGrid2D object - PyObject* mod = PyImport_ImportModule("orbit.core.spacecharge"); - PyObject* pyGrid2D = PyObject_CallMethod(mod,const_cast("Grid2D"),const_cast("ii"),cpp_grid2d->getSizeX(),cpp_grid2d->getSizeY()); - //delete the c++ reference to the internal Grid2D inside pyGrid2D and assign the new one - delete ((Grid2D*)((pyORBIT_Object*) pyGrid2D)->cpp_obj); - ((pyORBIT_Object*) pyGrid2D)->cpp_obj = cpp_grid2d; - cpp_grid2d->setPyWrapper(pyGrid2D); - Py_INCREF(cpp_grid2d->getPyWrapper()); - Py_DECREF(mod); - return pyGrid2D; + return wrapGrid2D(cpp_SpaceChargeCalc2p5D->getPhiGrid(), self); } //Grid1D* getLongGrid() returns the 1D grid with longitudinal density static PyObject* SpaceChargeCalc2p5D_getLongGrid(PyObject *self, PyObject *args){ pyORBIT_Object* pySpaceChargeCalc2p5D = (pyORBIT_Object*) self; SpaceChargeCalc2p5D* cpp_SpaceChargeCalc2p5D = (SpaceChargeCalc2p5D*) pySpaceChargeCalc2p5D->cpp_obj; - Grid1D* cpp_grid1d = cpp_SpaceChargeCalc2p5D->getLongGrid(); - if(cpp_grid1d->getPyWrapper() != NULL){ - Py_INCREF(cpp_grid1d->getPyWrapper()); - return cpp_grid1d->getPyWrapper(); - } - //It will create a pyGrid2D object - PyObject* mod = PyImport_ImportModule("orbit.core.spacecharge"); - PyObject* pyGrid1D = PyObject_CallMethod(mod,const_cast("Grid1D"),const_cast("i"),cpp_grid1d->getSizeZ()); - //delete the c++ reference to the internal Grid1D inside pyGrid1D and assign the new one - delete ((Grid1D*)((pyORBIT_Object*) pyGrid1D)->cpp_obj); - ((pyORBIT_Object*) pyGrid1D)->cpp_obj = cpp_grid1d; - cpp_grid1d->setPyWrapper(pyGrid1D); - Py_INCREF(cpp_grid1d->getPyWrapper()); - Py_DECREF(mod); - return pyGrid1D; + return wrapGrid1D(cpp_SpaceChargeCalc2p5D->getLongGrid(), self); } //trackBunch(Bunch* bunch, double length[,BaseBoundary2D* boundary]) diff --git a/src/spacecharge/wrap_spacechargecalc2p5d.hh b/src/spacecharge/wrap_spacechargecalc2p5d.hh index 9ca19c00..bac019d2 100644 --- a/src/spacecharge/wrap_spacechargecalc2p5d.hh +++ b/src/spacecharge/wrap_spacechargecalc2p5d.hh @@ -1,7 +1,7 @@ #ifndef WRAP_SPACE_CHARGE_CALC_2P5D_H #define WRAP_SPACE_CHARGE_CALC_2P5D_H -#include "Python.h" +#include #ifdef __cplusplus extern "C" { diff --git a/src/spacecharge/wrap_spacechargecalc2p5d_rb.cc b/src/spacecharge/wrap_spacechargecalc2p5d_rb.cc index 31bdbae8..12bc3d6a 100644 --- a/src/spacecharge/wrap_spacechargecalc2p5d_rb.cc +++ b/src/spacecharge/wrap_spacechargecalc2p5d_rb.cc @@ -1,13 +1,15 @@ -#include "orbit_mpi.hh" -#include "pyORBIT_Object.hh" +#include "mpi/orbit_mpi.hh" +#include "main/pyORBIT_Object.hh" # -#include "wrap_spacechargecalc2p5d_rb.hh" -#include "wrap_spacecharge.hh" -#include "wrap_bunch.hh" +#include "spacecharge/wrap_spacechargecalc2p5d_rb.hh" +#include "spacecharge/wrap_spacecharge.hh" +#include "spacecharge/wrap_grid1D.hh" +#include "spacecharge/wrap_grid2D.hh" +#include "orbit/wrap_bunch.hh" #include -#include "SpaceChargeCalc2p5Drb.hh" +#include "spacecharge/SpaceChargeCalc2p5Drb.hh" using namespace OrbitUtils; @@ -46,7 +48,6 @@ extern "C" { } else { self->cpp_obj = new SpaceChargeCalc2p5Drb(xSize,ySize,zSize); } - ((SpaceChargeCalc2p5Drb*) self->cpp_obj)->setPyWrapper((PyObject*) self); return 0; } @@ -54,84 +55,28 @@ extern "C" { static PyObject* SpaceChargeCalc2p5Drb_getRhoGrid(PyObject *self, PyObject *args){ pyORBIT_Object* pySpaceChargeCalc2p5Drb = (pyORBIT_Object*) self; SpaceChargeCalc2p5Drb* cpp_SpaceChargeCalc2p5Drb = (SpaceChargeCalc2p5Drb*) pySpaceChargeCalc2p5Drb->cpp_obj; - Grid2D* cpp_grid2d = cpp_SpaceChargeCalc2p5Drb->getRhoGrid(); - if(cpp_grid2d->getPyWrapper() != NULL){ - Py_INCREF(cpp_grid2d->getPyWrapper()); - return cpp_grid2d->getPyWrapper(); - } - //It will create a pyGrid2D object - PyObject* mod = PyImport_ImportModule("orbit.core.spacecharge"); - PyObject* pyGrid2D = PyObject_CallMethod(mod,const_cast("Grid2D"),const_cast("ii"),cpp_grid2d->getSizeX(),cpp_grid2d->getSizeY()); - //delete the c++ reference to the internal Grid2D inside pyGrid2D and assign the new one - delete ((Grid2D*)((pyORBIT_Object*) pyGrid2D)->cpp_obj); - ((pyORBIT_Object*) pyGrid2D)->cpp_obj = cpp_grid2d; - cpp_grid2d->setPyWrapper(pyGrid2D); - Py_INCREF(cpp_grid2d->getPyWrapper()); - Py_DECREF(mod); - return pyGrid2D; + return wrapGrid2D(cpp_SpaceChargeCalc2p5Drb->getRhoGrid(), self); } //Grid2D* getPhiGrid() returns the 2D grid with potential static PyObject* SpaceChargeCalc2p5Drb_getPhiGrid(PyObject *self, PyObject *args){ pyORBIT_Object* pySpaceChargeCalc2p5Drb = (pyORBIT_Object*) self; SpaceChargeCalc2p5Drb* cpp_SpaceChargeCalc2p5Drb = (SpaceChargeCalc2p5Drb*) pySpaceChargeCalc2p5Drb->cpp_obj; - Grid2D* cpp_grid2d = cpp_SpaceChargeCalc2p5Drb->getPhiGrid(); - if(cpp_grid2d->getPyWrapper() != NULL){ - Py_INCREF(cpp_grid2d->getPyWrapper()); - return cpp_grid2d->getPyWrapper(); - } - //It will create a pyGrid2D object - PyObject* mod = PyImport_ImportModule("orbit.core.spacecharge"); - PyObject* pyGrid2D = PyObject_CallMethod(mod,const_cast("Grid2D"),const_cast("ii"),cpp_grid2d->getSizeX(),cpp_grid2d->getSizeY()); - //delete the c++ reference to the internal Grid2D inside pyGrid2D and assign the new one - delete ((Grid2D*)((pyORBIT_Object*) pyGrid2D)->cpp_obj); - ((pyORBIT_Object*) pyGrid2D)->cpp_obj = cpp_grid2d; - cpp_grid2d->setPyWrapper(pyGrid2D); - Py_INCREF(cpp_grid2d->getPyWrapper()); - Py_DECREF(mod); - return pyGrid2D; + return wrapGrid2D(cpp_SpaceChargeCalc2p5Drb->getPhiGrid(), self); } //Grid1D* getLongGrid() returns the 1D grid with longitudinal density static PyObject* SpaceChargeCalc2p5Drb_getLongGrid(PyObject *self, PyObject *args){ pyORBIT_Object* pySpaceChargeCalc2p5Drb = (pyORBIT_Object*) self; SpaceChargeCalc2p5Drb* cpp_SpaceChargeCalc2p5Drb = (SpaceChargeCalc2p5Drb*) pySpaceChargeCalc2p5Drb->cpp_obj; - Grid1D* cpp_grid1d = cpp_SpaceChargeCalc2p5Drb->getLongGrid(); - if(cpp_grid1d->getPyWrapper() != NULL){ - Py_INCREF(cpp_grid1d->getPyWrapper()); - return cpp_grid1d->getPyWrapper(); - } - //It will create a pyGrid2D object - PyObject* mod = PyImport_ImportModule("orbit.core.spacecharge"); - PyObject* pyGrid1D = PyObject_CallMethod(mod,const_cast("Grid1D"),const_cast("i"),cpp_grid1d->getSizeZ()); - //delete the c++ reference to the internal Grid1D inside pyGrid1D and assign the new one - delete ((Grid1D*)((pyORBIT_Object*) pyGrid1D)->cpp_obj); - ((pyORBIT_Object*) pyGrid1D)->cpp_obj = cpp_grid1d; - cpp_grid1d->setPyWrapper(pyGrid1D); - Py_INCREF(cpp_grid1d->getPyWrapper()); - Py_DECREF(mod); - return pyGrid1D; + return wrapGrid1D(cpp_SpaceChargeCalc2p5Drb->getLongGrid(), self); } //Grid1D* getLongDerivativeGrid() returns the 1D grid with the derivative of the longitudinal density static PyObject* SpaceChargeCalc2p5Drb_getLongDerivativeGrid(PyObject *self, PyObject *args){ pyORBIT_Object* pySpaceChargeCalc2p5Drb = (pyORBIT_Object*) self; SpaceChargeCalc2p5Drb* cpp_SpaceChargeCalc2p5Drb = (SpaceChargeCalc2p5Drb*) pySpaceChargeCalc2p5Drb->cpp_obj; - Grid1D* cpp_grid1d = cpp_SpaceChargeCalc2p5Drb->getLongDerivativeGrid(); - if(cpp_grid1d->getPyWrapper() != NULL){ - Py_INCREF(cpp_grid1d->getPyWrapper()); - return cpp_grid1d->getPyWrapper(); - } - //It will create a pyGrid2D object - PyObject* mod = PyImport_ImportModule("orbit.core.spacecharge"); - PyObject* pyGrid1D = PyObject_CallMethod(mod,const_cast("Grid1D"),const_cast("i"),cpp_grid1d->getSizeZ()); - //delete the c++ reference to the internal Grid1D inside pyGrid1D and assign the new one - delete ((Grid1D*)((pyORBIT_Object*) pyGrid1D)->cpp_obj); - ((pyORBIT_Object*) pyGrid1D)->cpp_obj = cpp_grid1d; - cpp_grid1d->setPyWrapper(pyGrid1D); - Py_INCREF(cpp_grid1d->getPyWrapper()); - Py_DECREF(mod); - return pyGrid1D; + return wrapGrid1D(cpp_SpaceChargeCalc2p5Drb->getLongDerivativeGrid(), self); } //trackBunch(Bunch* bunch, double length, double pipe_radius) diff --git a/src/spacecharge/wrap_spacechargecalc2p5d_rb.hh b/src/spacecharge/wrap_spacechargecalc2p5d_rb.hh index b2551e92..bbf671d5 100644 --- a/src/spacecharge/wrap_spacechargecalc2p5d_rb.hh +++ b/src/spacecharge/wrap_spacechargecalc2p5d_rb.hh @@ -1,7 +1,7 @@ #ifndef WRAP_SPACE_CHARGE_CALC_2P5D_RB_H #define WRAP_SPACE_CHARGE_CALC_2P5D_RB_H -#include "Python.h" +#include #ifdef __cplusplus extern "C" { diff --git a/src/spacecharge/wrap_spacechargecalc3d.cc b/src/spacecharge/wrap_spacechargecalc3d.cc index 18bae349..026c3e45 100644 --- a/src/spacecharge/wrap_spacechargecalc3d.cc +++ b/src/spacecharge/wrap_spacechargecalc3d.cc @@ -1,13 +1,14 @@ -#include "orbit_mpi.hh" -#include "pyORBIT_Object.hh" +#include "mpi/orbit_mpi.hh" +#include "main/pyORBIT_Object.hh" # -#include "wrap_spacechargecalc3d.hh" -#include "wrap_spacecharge.hh" -#include "wrap_bunch.hh" +#include "spacecharge/wrap_spacechargecalc3d.hh" +#include "spacecharge/wrap_spacecharge.hh" +#include "spacecharge/wrap_grid3D.hh" +#include "orbit/wrap_bunch.hh" #include -#include "SpaceChargeCalc3D.hh" +#include "spacecharge/SpaceChargeCalc3D.hh" using namespace OrbitUtils; @@ -41,7 +42,6 @@ extern "C" { ORBIT_MPI_Finalize("PySpaceChargeCalc3D - SpaceChargeCalc3D(xSize,ySize,xzSize) - constructor needs parameters."); } self->cpp_obj = new SpaceChargeCalc3D(xSize,ySize,zSize); - ((SpaceChargeCalc3D*) self->cpp_obj)->setPyWrapper((PyObject*) self); return 0; } @@ -49,42 +49,14 @@ extern "C" { static PyObject* SpaceChargeCalc3D_getRhoGrid(PyObject *self, PyObject *args){ pyORBIT_Object* pySpaceChargeCalc3D = (pyORBIT_Object*) self; SpaceChargeCalc3D* cpp_SpaceChargeCalc3D = (SpaceChargeCalc3D*) pySpaceChargeCalc3D->cpp_obj; - Grid3D* cpp_grid3d = cpp_SpaceChargeCalc3D->getRhoGrid(); - if(cpp_grid3d->getPyWrapper() != NULL){ - Py_INCREF(cpp_grid3d->getPyWrapper()); - return cpp_grid3d->getPyWrapper(); - } - //It will create a pyGrid3D object - PyObject* mod = PyImport_ImportModule("orbit.core.spacecharge"); - PyObject* pyGrid3D = PyObject_CallMethod(mod,const_cast("Grid3D"),const_cast("iii"),cpp_grid3d->getSizeX(),cpp_grid3d->getSizeY(),cpp_grid3d->getSizeZ()); - //delete the c++ reference to the internal Grid3D inside pyGrid3D and assign the new one - delete ((Grid3D*)((pyORBIT_Object*) pyGrid3D)->cpp_obj); - ((pyORBIT_Object*) pyGrid3D)->cpp_obj = cpp_grid3d; - cpp_grid3d->setPyWrapper(pyGrid3D); - Py_INCREF(cpp_grid3d->getPyWrapper()); - Py_DECREF(mod); - return pyGrid3D; + return wrapGrid3D(cpp_SpaceChargeCalc3D->getRhoGrid(), self); } //Grid3D* getPhiGrid() returns the 3D grid with potential static PyObject* SpaceChargeCalc3D_getPhiGrid(PyObject *self, PyObject *args){ pyORBIT_Object* pySpaceChargeCalc3D = (pyORBIT_Object*) self; SpaceChargeCalc3D* cpp_SpaceChargeCalc3D = (SpaceChargeCalc3D*) pySpaceChargeCalc3D->cpp_obj; - Grid3D* cpp_grid3d = cpp_SpaceChargeCalc3D->getPhiGrid(); - if(cpp_grid3d->getPyWrapper() != NULL){ - Py_INCREF(cpp_grid3d->getPyWrapper()); - return cpp_grid3d->getPyWrapper(); - } - //It will create a pyGrid3D object - PyObject* mod = PyImport_ImportModule("orbit.core.spacecharge"); - PyObject* pyGrid3D = PyObject_CallMethod(mod,const_cast("Grid3D"),const_cast("iii"),cpp_grid3d->getSizeX(),cpp_grid3d->getSizeY(),cpp_grid3d->getSizeZ()); - //delete the c++ reference to the internal Grid3D inside pyGrid3D and assign the new one - delete ((Grid3D*)((pyORBIT_Object*) pyGrid3D)->cpp_obj); - ((pyORBIT_Object*) pyGrid3D)->cpp_obj = cpp_grid3d; - cpp_grid3d->setPyWrapper(pyGrid3D); - Py_INCREF(cpp_grid3d->getPyWrapper()); - Py_DECREF(mod); - return pyGrid3D; + return wrapGrid3D(cpp_SpaceChargeCalc3D->getPhiGrid(), self); } //trackBunch(Bunch* bunch, double length) diff --git a/src/spacecharge/wrap_spacechargecalc3d.hh b/src/spacecharge/wrap_spacechargecalc3d.hh index ec48fc43..61af06ff 100644 --- a/src/spacecharge/wrap_spacechargecalc3d.hh +++ b/src/spacecharge/wrap_spacechargecalc3d.hh @@ -1,7 +1,7 @@ #ifndef WRAP_SPACE_CHARGE_CALC_3D_H #define WRAP_SPACE_CHARGE_CALC_3D_H -#include "Python.h" +#include #ifdef __cplusplus extern "C" { diff --git a/src/spacecharge/wrap_spacechargecalc_slicebyslice_2D.cc b/src/spacecharge/wrap_spacechargecalc_slicebyslice_2D.cc index ba761988..89456476 100755 --- a/src/spacecharge/wrap_spacechargecalc_slicebyslice_2D.cc +++ b/src/spacecharge/wrap_spacechargecalc_slicebyslice_2D.cc @@ -1,13 +1,14 @@ -#include "orbit_mpi.hh" -#include "pyORBIT_Object.hh" +#include "mpi/orbit_mpi.hh" +#include "main/pyORBIT_Object.hh" # -#include "wrap_spacechargecalc_slicebyslice_2D.hh" -#include "wrap_spacecharge.hh" -#include "wrap_bunch.hh" +#include "spacecharge/wrap_spacechargecalc_slicebyslice_2D.hh" +#include "spacecharge/wrap_spacecharge.hh" +#include "spacecharge/wrap_grid3D.hh" +#include "orbit/wrap_bunch.hh" #include -#include "SpaceChargeCalcSliceBySlice2D.hh" +#include "spacecharge/SpaceChargeCalcSliceBySlice2D.hh" using namespace OrbitUtils; @@ -46,7 +47,6 @@ extern "C" { } else { self->cpp_obj = new SpaceChargeCalcSliceBySlice2D(xSize,ySize,zSize); } - ((SpaceChargeCalcSliceBySlice2D*) self->cpp_obj)->setPyWrapper((PyObject*) self); //std::cerr<<"The SpaceChargeCalcSliceBySlice2D __init__ has been called!"<cpp_obj; - Grid3D* cpp_grid3d = cpp_SpaceChargeCalcSliceBySlice2D->getRhoGrid(); - if(cpp_grid3d->getPyWrapper() != NULL){ - Py_INCREF(cpp_grid3d->getPyWrapper()); - return cpp_grid3d->getPyWrapper(); - } - //It will create a pyGrid3D object - PyObject* mod = PyImport_ImportModule("orbit.core.spacecharge"); - PyObject* pyGrid3D = PyObject_CallMethod(mod,const_cast("Grid3D"),const_cast("iii"),cpp_grid3d->getSizeX(),cpp_grid3d->getSizeY(),cpp_grid3d->getSizeZ()); - //delete the c++ reference to the internal Grid3D inside pyGrid3D and assign the new one - delete ((Grid3D*)((pyORBIT_Object*) pyGrid3D)->cpp_obj); - ((pyORBIT_Object*) pyGrid3D)->cpp_obj = cpp_grid3d; - cpp_grid3d->setPyWrapper(pyGrid3D); - Py_INCREF(cpp_grid3d->getPyWrapper()); - Py_DECREF(mod); - return pyGrid3D; + return wrapGrid3D(cpp_SpaceChargeCalcSliceBySlice2D->getRhoGrid(), self); } //Grid3D* getPhiGrid() returns the 3D grid with potential static PyObject* SpaceChargeCalcSliceBySlice2D_getPhiGrid(PyObject *self, PyObject *args){ pyORBIT_Object* pySpaceChargeCalcSliceBySlice2D = (pyORBIT_Object*) self; SpaceChargeCalcSliceBySlice2D* cpp_SpaceChargeCalcSliceBySlice2D = (SpaceChargeCalcSliceBySlice2D*) pySpaceChargeCalcSliceBySlice2D->cpp_obj; - Grid3D* cpp_grid3d = cpp_SpaceChargeCalcSliceBySlice2D->getPhiGrid(); - if(cpp_grid3d->getPyWrapper() != NULL){ - Py_INCREF(cpp_grid3d->getPyWrapper()); - return cpp_grid3d->getPyWrapper(); - } - //It will create a pyGrid3D object - PyObject* mod = PyImport_ImportModule("orbit.core.spacecharge"); - PyObject* pyGrid3D = PyObject_CallMethod(mod,const_cast("Grid3D"),const_cast("iii"),cpp_grid3d->getSizeX(),cpp_grid3d->getSizeY(),cpp_grid3d->getSizeZ()); - //delete the c++ reference to the internal Grid3D inside pyGrid3D and assign the new one - delete ((Grid3D*)((pyORBIT_Object*) pyGrid3D)->cpp_obj); - ((pyORBIT_Object*) pyGrid3D)->cpp_obj = cpp_grid3d; - cpp_grid3d->setPyWrapper(pyGrid3D); - Py_INCREF(cpp_grid3d->getPyWrapper()); - Py_DECREF(mod); - return pyGrid3D; + return wrapGrid3D(cpp_SpaceChargeCalcSliceBySlice2D->getPhiGrid(), self); } //trackBunch(Bunch* bunch, double length[,BaseBoundary2D* boundary]) diff --git a/src/spacecharge/wrap_spacechargecalc_slicebyslice_2D.hh b/src/spacecharge/wrap_spacechargecalc_slicebyslice_2D.hh index 6a8fb982..812733b5 100755 --- a/src/spacecharge/wrap_spacechargecalc_slicebyslice_2D.hh +++ b/src/spacecharge/wrap_spacechargecalc_slicebyslice_2D.hh @@ -1,7 +1,7 @@ #ifndef WRAP_SPACE_CHARGE_CALC_SLICE_BY_SLICE_2D_H #define WRAP_SPACE_CHARGE_CALC_SLICE_BY_SLICE_2D_H -#include "Python.h" +#include #ifdef __cplusplus extern "C" { diff --git a/src/spacecharge/wrap_spacechargecalc_uniform_ellipse.cc b/src/spacecharge/wrap_spacechargecalc_uniform_ellipse.cc index 657c610f..a59e663f 100644 --- a/src/spacecharge/wrap_spacechargecalc_uniform_ellipse.cc +++ b/src/spacecharge/wrap_spacechargecalc_uniform_ellipse.cc @@ -1,13 +1,14 @@ -#include "orbit_mpi.hh" -#include "pyORBIT_Object.hh" +#include "mpi/orbit_mpi.hh" +#include "main/pyORBIT_Object.hh" -#include "wrap_spacechargecalc_uniform_ellipse.hh" -#include "wrap_spacecharge.hh" -#include "wrap_bunch.hh" +#include "spacecharge/wrap_spacechargecalc_uniform_ellipse.hh" +#include "spacecharge/wrap_spacecharge.hh" +#include "spacecharge/wrap_uniform_ellipsoid_field_calculator.hh" +#include "orbit/wrap_bunch.hh" #include -#include "SpaceChargeCalcUnifEllipse.hh" +#include "spacecharge/SpaceChargeCalcUnifEllipse.hh" using namespace OrbitUtils; @@ -75,20 +76,7 @@ extern "C" { Py_INCREF(Py_None); return Py_None; } - if(cpp_ellipseFieldCalc->getPyWrapper() != NULL){ - Py_INCREF(cpp_ellipseFieldCalc->getPyWrapper()); - return cpp_ellipseFieldCalc->getPyWrapper(); - } - //It will create a pyUniformEllipsoidFieldCalculator object - PyObject* mod = PyImport_ImportModule("orbit.core.spacecharge"); - PyObject* pyUniformEllipsoidFieldCalculator = PyObject_CallMethod(mod,const_cast("UniformEllipsoidFieldCalculator"),const_cast("")); - //delete the c++ reference to the internal UniformEllipsoidFieldCalculator inside pyUniformEllipsoidFieldCalculator and assign the new one - delete ((UniformEllipsoidFieldCalculator*)((pyORBIT_Object*) pyUniformEllipsoidFieldCalculator)->cpp_obj); - ((pyORBIT_Object*) pyUniformEllipsoidFieldCalculator)->cpp_obj = cpp_ellipseFieldCalc; - cpp_ellipseFieldCalc->setPyWrapper(pyUniformEllipsoidFieldCalculator); - Py_INCREF(cpp_ellipseFieldCalc->getPyWrapper()); - Py_DECREF(mod); - return pyUniformEllipsoidFieldCalculator; + return wrapUniformEllipsoidFieldCalculator(cpp_ellipseFieldCalc, self); } //getNEllipses() - returns the number of ellipses inside the Space Charge calculator diff --git a/src/spacecharge/wrap_spacechargecalc_uniform_ellipse.hh b/src/spacecharge/wrap_spacechargecalc_uniform_ellipse.hh index 85cc0fd9..fd9acf06 100644 --- a/src/spacecharge/wrap_spacechargecalc_uniform_ellipse.hh +++ b/src/spacecharge/wrap_spacechargecalc_uniform_ellipse.hh @@ -1,7 +1,7 @@ #ifndef WRAP_SPACE_CHARGE_CALC_UNIFORM_ELLIPSE_H #define WRAP_SPACE_CHARGE_CALC_UNIFORM_ELLIPSE_H -#include "Python.h" +#include #ifdef __cplusplus extern "C" { diff --git a/src/spacecharge/wrap_spacechargeforcecalc2p5d.cc b/src/spacecharge/wrap_spacechargeforcecalc2p5d.cc index 65e98689..ce46fbe3 100644 --- a/src/spacecharge/wrap_spacechargeforcecalc2p5d.cc +++ b/src/spacecharge/wrap_spacechargeforcecalc2p5d.cc @@ -1,13 +1,15 @@ -#include "orbit_mpi.hh" -#include "pyORBIT_Object.hh" +#include "mpi/orbit_mpi.hh" +#include "main/pyORBIT_Object.hh" # -#include "wrap_spacechargeforcecalc2p5d.hh" -#include "wrap_spacecharge.hh" -#include "wrap_bunch.hh" +#include "spacecharge/wrap_spacechargeforcecalc2p5d.hh" +#include "spacecharge/wrap_spacecharge.hh" +#include "spacecharge/wrap_grid1D.hh" +#include "spacecharge/wrap_grid2D.hh" +#include "orbit/wrap_bunch.hh" #include -#include "SpaceChargeForceCalc2p5D.hh" +#include "spacecharge/SpaceChargeForceCalc2p5D.hh" using namespace OrbitUtils; @@ -42,7 +44,6 @@ extern "C" { } self->cpp_obj = new SpaceChargeForceCalc2p5D(xSize,ySize,zSize); - ((SpaceChargeForceCalc2p5D*) self->cpp_obj)->setPyWrapper((PyObject*) self); //std::cerr<<"The SpaceChargeForceCalc2p5D __init__ has been called!"<cpp_obj; - Grid2D* cpp_grid2d = cpp_SpaceChargeForceCalc2p5D->getRhoGrid(); - if(cpp_grid2d->getPyWrapper() != NULL){ - Py_INCREF(cpp_grid2d->getPyWrapper()); - return cpp_grid2d->getPyWrapper(); - } - //It will create a pyGrid2D object - PyObject* mod = PyImport_ImportModule("orbit.core.spacecharge"); - PyObject* pyGrid2D = PyObject_CallMethod(mod,const_cast("Grid2D"),const_cast("ii"),cpp_grid2d->getSizeX(),cpp_grid2d->getSizeY()); - //delete the c++ reference to the internal Grid2D inside pyGrid2D and assign the new one - delete ((Grid2D*)((pyORBIT_Object*) pyGrid2D)->cpp_obj); - ((pyORBIT_Object*) pyGrid2D)->cpp_obj = cpp_grid2d; - cpp_grid2d->setPyWrapper(pyGrid2D); - Py_INCREF(cpp_grid2d->getPyWrapper()); - Py_DECREF(mod); - return pyGrid2D; + return wrapGrid2D(cpp_SpaceChargeForceCalc2p5D->getRhoGrid(), self); } //Grid2D* getPhiGrid() returns the 2D grid with horizontal force static PyObject* SpaceChargeForceCalc2p5D_getForceGridX(PyObject *self, PyObject *args){ pyORBIT_Object* pySpaceChargeForceCalc2p5D = (pyORBIT_Object*) self; SpaceChargeForceCalc2p5D* cpp_SpaceChargeForceCalc2p5D = (SpaceChargeForceCalc2p5D*) pySpaceChargeForceCalc2p5D->cpp_obj; - Grid2D* cpp_grid2d = cpp_SpaceChargeForceCalc2p5D->getForceGridX(); - if(cpp_grid2d->getPyWrapper() != NULL){ - Py_INCREF(cpp_grid2d->getPyWrapper()); - return cpp_grid2d->getPyWrapper(); - } - //It will create a pyGrid2D object - PyObject* mod = PyImport_ImportModule("orbit.core.spacecharge"); - PyObject* pyGrid2D = PyObject_CallMethod(mod,const_cast("Grid2D"),const_cast("ii"),cpp_grid2d->getSizeX(),cpp_grid2d->getSizeY()); - //delete the c++ reference to the internal Grid2D inside pyGrid2D and assign the new one - delete ((Grid2D*)((pyORBIT_Object*) pyGrid2D)->cpp_obj); - ((pyORBIT_Object*) pyGrid2D)->cpp_obj = cpp_grid2d; - cpp_grid2d->setPyWrapper(pyGrid2D); - Py_INCREF(cpp_grid2d->getPyWrapper()); - Py_DECREF(mod); - return pyGrid2D; + return wrapGrid2D(cpp_SpaceChargeForceCalc2p5D->getForceGridX(), self); } @@ -94,21 +67,7 @@ extern "C" { static PyObject* SpaceChargeForceCalc2p5D_getForceGridY(PyObject *self, PyObject *args){ pyORBIT_Object* pySpaceChargeForceCalc2p5D = (pyORBIT_Object*) self; SpaceChargeForceCalc2p5D* cpp_SpaceChargeForceCalc2p5D = (SpaceChargeForceCalc2p5D*) pySpaceChargeForceCalc2p5D->cpp_obj; - Grid2D* cpp_grid2d = cpp_SpaceChargeForceCalc2p5D->getForceGridY(); - if(cpp_grid2d->getPyWrapper() != NULL){ - Py_INCREF(cpp_grid2d->getPyWrapper()); - return cpp_grid2d->getPyWrapper(); - } - //It will create a pyGrid2D object - PyObject* mod = PyImport_ImportModule("orbit.core.spacecharge"); - PyObject* pyGrid2D = PyObject_CallMethod(mod,const_cast("Grid2D"),const_cast("ii"),cpp_grid2d->getSizeX(),cpp_grid2d->getSizeY()); - //delete the c++ reference to the internal Grid2D inside pyGrid2D and assign the new one - delete ((Grid2D*)((pyORBIT_Object*) pyGrid2D)->cpp_obj); - ((pyORBIT_Object*) pyGrid2D)->cpp_obj = cpp_grid2d; - cpp_grid2d->setPyWrapper(pyGrid2D); - Py_INCREF(cpp_grid2d->getPyWrapper()); - Py_DECREF(mod); - return pyGrid2D; + return wrapGrid2D(cpp_SpaceChargeForceCalc2p5D->getForceGridY(), self); } @@ -116,21 +75,7 @@ extern "C" { static PyObject* SpaceChargeForceCalc2p5D_getLongGrid(PyObject *self, PyObject *args){ pyORBIT_Object* pySpaceChargeForceCalc2p5D = (pyORBIT_Object*) self; SpaceChargeForceCalc2p5D* cpp_SpaceChargeForceCalc2p5D = (SpaceChargeForceCalc2p5D*) pySpaceChargeForceCalc2p5D->cpp_obj; - Grid1D* cpp_grid1d = cpp_SpaceChargeForceCalc2p5D->getLongGrid(); - if(cpp_grid1d->getPyWrapper() != NULL){ - Py_INCREF(cpp_grid1d->getPyWrapper()); - return cpp_grid1d->getPyWrapper(); - } - //It will create a pyGrid2D object - PyObject* mod = PyImport_ImportModule("orbit.core.spacecharge"); - PyObject* pyGrid1D = PyObject_CallMethod(mod,const_cast("Grid1D"),const_cast("i"),cpp_grid1d->getSizeZ()); - //delete the c++ reference to the internal Grid1D inside pyGrid1D and assign the new one - delete ((Grid1D*)((pyORBIT_Object*) pyGrid1D)->cpp_obj); - ((pyORBIT_Object*) pyGrid1D)->cpp_obj = cpp_grid1d; - cpp_grid1d->setPyWrapper(pyGrid1D); - Py_INCREF(cpp_grid1d->getPyWrapper()); - Py_DECREF(mod); - return pyGrid1D; + return wrapGrid1D(cpp_SpaceChargeForceCalc2p5D->getLongGrid(), self); } //trackBunch(Bunch* bunch, double length[,BaseBoundary2D* boundary]) diff --git a/src/spacecharge/wrap_spacechargeforcecalc2p5d.hh b/src/spacecharge/wrap_spacechargeforcecalc2p5d.hh index eb91c908..f483312c 100644 --- a/src/spacecharge/wrap_spacechargeforcecalc2p5d.hh +++ b/src/spacecharge/wrap_spacechargeforcecalc2p5d.hh @@ -1,7 +1,7 @@ #ifndef WRAP_SPACE_CHARGE_FORCE_CALC_2P5D_H #define WRAP_SPACE_CHARGE_FORCE_CALC_2P5D_H -#include "Python.h" +#include #ifdef __cplusplus extern "C" { diff --git a/src/spacecharge/wrap_uniform_ellipsoid_field_calculator.cc b/src/spacecharge/wrap_uniform_ellipsoid_field_calculator.cc index 37e0b3d1..e4c1a715 100644 --- a/src/spacecharge/wrap_uniform_ellipsoid_field_calculator.cc +++ b/src/spacecharge/wrap_uniform_ellipsoid_field_calculator.cc @@ -1,16 +1,22 @@ -#include "orbit_mpi.hh" -#include "pyORBIT_Object.hh" +#include "mpi/orbit_mpi.hh" +#include "main/pyORBIT_Object.hh" -#include "UniformEllipsoidFieldCalculator.hh" +#include "spacecharge/UniformEllipsoidFieldCalculator.hh" -#include "wrap_uniform_ellipsoid_field_calculator.hh" -#include "wrap_spacecharge.hh" +#include "spacecharge/wrap_uniform_ellipsoid_field_calculator.hh" +#include "spacecharge/wrap_spacecharge.hh" #include using namespace OrbitUtils; namespace wrap_spacecharge{ + typedef struct { + PyObject_HEAD + void* cpp_obj; + int owns_cpp; + PyObject* owner; + } pyORBIT_UniformEllipsoidFieldCalculator; #ifdef __cplusplus extern "C" { @@ -24,17 +30,20 @@ extern "C" { //It never will be called directly static PyObject* UniformEllipsoidFieldCalculator_new(PyTypeObject *type, PyObject *args, PyObject *kwds) { - pyORBIT_Object* self; - self = (pyORBIT_Object *) type->tp_alloc(type, 0); + pyORBIT_UniformEllipsoidFieldCalculator* self; + self = (pyORBIT_UniformEllipsoidFieldCalculator *) type->tp_alloc(type, 0); self->cpp_obj = NULL; + self->owns_cpp = 0; + self->owner = NULL; return (PyObject *) self; } //initializator for python UniformEllipsoidFieldCalculator class //this is implementation of the __init__ method - static int UniformEllipsoidFieldCalculator_init(pyORBIT_Object *self, PyObject *args, PyObject *kwds){ + static int UniformEllipsoidFieldCalculator_init(pyORBIT_UniformEllipsoidFieldCalculator *self, PyObject *args, PyObject *kwds){ self->cpp_obj = new UniformEllipsoidFieldCalculator(); - ((UniformEllipsoidFieldCalculator*) self->cpp_obj)->setPyWrapper((PyObject*) self); + self->owns_cpp = 1; + pyorbit::registerPyWrapper(self->cpp_obj, (PyObject*) self); return 0; } @@ -69,11 +78,12 @@ extern "C" { //----------------------------------------------------- //destructor for python UniformEllipsoidFieldCalculator class (__del__ method). //----------------------------------------------------- - static void UniformEllipsoidFieldCalculator_del(pyORBIT_Object* self){ + static void UniformEllipsoidFieldCalculator_del(pyORBIT_UniformEllipsoidFieldCalculator* self){ UniformEllipsoidFieldCalculator* cpp_UniformEllipsoidFieldCalculator = (UniformEllipsoidFieldCalculator*) self->cpp_obj; - if(cpp_UniformEllipsoidFieldCalculator != NULL){ - delete cpp_UniformEllipsoidFieldCalculator; - } + pyorbit::unregisterPyWrapper(cpp_UniformEllipsoidFieldCalculator, (PyObject*) self); + if(self->owns_cpp) delete cpp_UniformEllipsoidFieldCalculator; + self->cpp_obj = NULL; + Py_CLEAR(self->owner); self->ob_base.ob_type->tp_free((PyObject*)self); } @@ -95,7 +105,7 @@ extern "C" { static PyTypeObject pyORBIT_UniformEllipsoidFieldCalculator_Type = { PyVarObject_HEAD_INIT(NULL, 0) "UniformEllipsoidFieldCalculator", /*tp_name*/ - sizeof(pyORBIT_Object), /*tp_basicsize*/ + sizeof(pyORBIT_UniformEllipsoidFieldCalculator), /*tp_basicsize*/ 0, /*tp_itemsize*/ (destructor) UniformEllipsoidFieldCalculator_del , /*tp_dealloc*/ 0, /*tp_print*/ @@ -133,6 +143,30 @@ extern "C" { UniformEllipsoidFieldCalculator_new, /* tp_new */ }; + PyObject* wrapUniformEllipsoidFieldCalculator( + UniformEllipsoidFieldCalculator* calculator, + PyObject* owner + ){ + PyObject* wrapper = pyorbit::getPyWrapper(calculator); + if(wrapper != NULL){ + Py_INCREF(wrapper); + return wrapper; + } + + pyORBIT_UniformEllipsoidFieldCalculator* self = + (pyORBIT_UniformEllipsoidFieldCalculator*) + pyORBIT_UniformEllipsoidFieldCalculator_Type.tp_alloc( + &pyORBIT_UniformEllipsoidFieldCalculator_Type, 0 + ); + if(self == NULL) return NULL; + self->cpp_obj = calculator; + self->owns_cpp = 0; + self->owner = owner; + Py_XINCREF(owner); + pyorbit::registerPyWrapper(calculator, (PyObject*) self); + return (PyObject*) self; + } + //-------------------------------------------------- //Initialization function of the pyUniformEllipsoidFieldCalculator class //It will be called from SpaceCharge wrapper initialization diff --git a/src/spacecharge/wrap_uniform_ellipsoid_field_calculator.hh b/src/spacecharge/wrap_uniform_ellipsoid_field_calculator.hh index 680a1c4f..2ddcbec4 100644 --- a/src/spacecharge/wrap_uniform_ellipsoid_field_calculator.hh +++ b/src/spacecharge/wrap_uniform_ellipsoid_field_calculator.hh @@ -1,7 +1,9 @@ #ifndef WRAP_UNIFORM_ELLIPSOID_FIELD_CALC_H #define WRAP_UNIFORM_ELLIPSOID_FIELD_CALC_H -#include "Python.h" +#include + +class UniformEllipsoidFieldCalculator; #ifdef __cplusplus extern "C" { @@ -9,6 +11,10 @@ extern "C" { namespace wrap_spacecharge{ void initUniformEllipsoidFieldCalculator(PyObject* module); + PyObject* wrapUniformEllipsoidFieldCalculator( + UniformEllipsoidFieldCalculator* calculator, + PyObject* owner + ); } #ifdef __cplusplus diff --git a/src/teapot/MatrixGenerator.cc b/src/teapot/MatrixGenerator.cc index 48ed1a4d..3d1af484 100644 --- a/src/teapot/MatrixGenerator.cc +++ b/src/teapot/MatrixGenerator.cc @@ -20,8 +20,8 @@ // b = ((y1-y0)*x2^2 - (y2-y0)*x1^2) / (x1*x2*(x2-x1)) // ///////////////////////////////////////////////////////////////////////////// -#include "orbit_mpi.hh" -#include "MatrixGenerator.hh" +#include "mpi/orbit_mpi.hh" +#include "teapot/MatrixGenerator.hh" using namespace OrbitUtils; diff --git a/src/teapot/MatrixGenerator.hh b/src/teapot/MatrixGenerator.hh index 03c290d9..66d5530a 100644 --- a/src/teapot/MatrixGenerator.hh +++ b/src/teapot/MatrixGenerator.hh @@ -16,8 +16,8 @@ #ifndef TEAPOT_BASE_MATRIX_GENERATOR_H #define TEAPOT_BASE_MATRIX_GENERATOR_H -#include "Bunch.hh" -#include "Matrix.hh" +#include "orbit/Bunch.hh" +#include "utils/matrix/Matrix.hh" using namespace OrbitUtils; diff --git a/src/teapot/teapotbase.cc b/src/teapot/teapotbase.cc index 042d3922..b124b43f 100644 --- a/src/teapot/teapotbase.cc +++ b/src/teapot/teapotbase.cc @@ -31,11 +31,12 @@ // /////////////////////////////////////////////////////////////////////////// -#include "teapotbase.hh" -#include "OrbitConst.hh" -#include "Bunch.hh" -#include "SyncPart.hh" +#include "teapot/teapotbase.hh" +#include "orbit/OrbitConst.hh" +#include "orbit/Bunch.hh" +#include "orbit/SyncPart.hh" +#include #include namespace teapot_base diff --git a/src/teapot/teapotbase.hh b/src/teapot/teapotbase.hh index 351a407a..4e83b866 100644 --- a/src/teapot/teapotbase.hh +++ b/src/teapot/teapotbase.hh @@ -23,7 +23,7 @@ #ifndef TEAPOT_BASE_H #define TEAPOT_BASE_H -#include "Bunch.hh" +#include "orbit/Bunch.hh" namespace teapot_base { diff --git a/src/teapot/wrap_matrix_generator.cc b/src/teapot/wrap_matrix_generator.cc index 793d58f7..15ce3f9a 100644 --- a/src/teapot/wrap_matrix_generator.cc +++ b/src/teapot/wrap_matrix_generator.cc @@ -1,15 +1,15 @@ -#include "orbit_mpi.hh" -#include "pyORBIT_Object.hh" +#include "mpi/orbit_mpi.hh" +#include "main/pyORBIT_Object.hh" -#include "wrap_matrix_generator.hh" -#include "wrap_teapotbase.hh" -#include "wrap_bunch.hh" -#include "wrap_utils.hh" +#include "teapot/wrap_matrix_generator.hh" +#include "teapot/wrap_teapotbase.hh" +#include "orbit/wrap_bunch.hh" +#include "utils/wrap_utils.hh" #include -#include "MatrixGenerator.hh" -#include "MatrixOperations.hh" +#include "teapot/MatrixGenerator.hh" +#include "utils/matrix/MatrixOperations.hh" using namespace OrbitUtils; using namespace teapot_base; diff --git a/src/teapot/wrap_matrix_generator.hh b/src/teapot/wrap_matrix_generator.hh index 9c9eaab2..0bf9bb8a 100644 --- a/src/teapot/wrap_matrix_generator.hh +++ b/src/teapot/wrap_matrix_generator.hh @@ -1,7 +1,7 @@ #ifndef WRAP_MATRIX_GENERATOR_H #define WRAP_MATRIX_GENERATOR_H -#include "Python.h" +#include #ifdef __cplusplus extern "C" diff --git a/src/teapot/wrap_teapotbase.cc b/src/teapot/wrap_teapotbase.cc index da405a16..c6a50b53 100644 --- a/src/teapot/wrap_teapotbase.cc +++ b/src/teapot/wrap_teapotbase.cc @@ -1,12 +1,12 @@ -#include "Python.h" -#include "orbit_mpi.hh" +#include +#include "mpi/orbit_mpi.hh" -#include "pyORBIT_Object.hh" +#include "main/pyORBIT_Object.hh" -#include "teapotbase.hh" +#include "teapot/teapotbase.hh" -#include "wrap_teapotbase.hh" -#include "wrap_matrix_generator.hh" +#include "teapot/wrap_teapotbase.hh" +#include "teapot/wrap_matrix_generator.hh" namespace wrap_teapotbase { diff --git a/src/trackerrk4/ExtEffectsContainer.cc b/src/trackerrk4/ExtEffectsContainer.cc index 4bab44d3..b35c04d3 100644 --- a/src/trackerrk4/ExtEffectsContainer.cc +++ b/src/trackerrk4/ExtEffectsContainer.cc @@ -21,8 +21,8 @@ // This is an example of embedding Python in C++ Orbit level. // /////////////////////////////////////////////////////////////////////////// -#include "orbit_mpi.hh" -#include "ExtEffectsContainer.hh" +#include "mpi/orbit_mpi.hh" +#include "trackerrk4/ExtEffectsContainer.hh" #include #include #include @@ -37,22 +37,9 @@ ExtEffectsContainer::ExtEffectsContainer(){ } ExtEffectsContainer::~ExtEffectsContainer(){ - - for (int i=0;igetPyWrapper() == NULL){ - delete ref[i]; - } else { - Py_XDECREF(ref[i]->getPyWrapper()); - } - } - } void ExtEffectsContainer::AddEffect(ExternalEffects* eff) { - if(eff->getPyWrapper() != NULL){ - Py_INCREF(eff->getPyWrapper()); - } - ref.push_back(eff); ref_setup.push_back(eff); diff --git a/src/trackerrk4/ExtEffectsContainer.hh b/src/trackerrk4/ExtEffectsContainer.hh index 321ba9db..12bdf8cd 100644 --- a/src/trackerrk4/ExtEffectsContainer.hh +++ b/src/trackerrk4/ExtEffectsContainer.hh @@ -1,11 +1,7 @@ #ifndef EXTEFFECTSCONTAINER_HH_ #define EXTEFFECTSCONTAINER_HH_ - - -#include "Python.h" - -#include "ExternalEffects.hh" +#include "trackerrk4/ExternalEffects.hh" #include @@ -25,7 +21,7 @@ using namespace OrbitUtils; /** Destructor. */ ~ExtEffectsContainer(); - /** Adds the instance of the ExternalEffects class to the container. */ + /** Adds a non-owning external-effects reference to the container. */ void AddEffect(ExternalEffects* eff); /** It initializes effects. */ @@ -52,11 +48,11 @@ using namespace OrbitUtils; private: - vector ref; - vector ref_setup; - vector ref_prepare; - vector ref_apply; - vector ref_finalize; + std::vector ref; + std::vector ref_setup; + std::vector ref_prepare; + std::vector ref_apply; + std::vector ref_finalize; }; diff --git a/src/trackerrk4/ExternalEffects.cc b/src/trackerrk4/ExternalEffects.cc index 0cede32f..bfc1c22a 100644 --- a/src/trackerrk4/ExternalEffects.cc +++ b/src/trackerrk4/ExternalEffects.cc @@ -11,12 +11,12 @@ // slow changing magnetic and electric fields. // /////////////////////////////////////////////////////////////////////////// -#include "RungeKuttaTracker.hh" +#include "trackerrk4/RungeKuttaTracker.hh" #include #include #include -#include "ExternalEffects.hh" +#include "trackerrk4/ExternalEffects.hh" using namespace TrackerRK4; diff --git a/src/trackerrk4/ExternalEffects.hh b/src/trackerrk4/ExternalEffects.hh index c613e82c..f1ad6daf 100644 --- a/src/trackerrk4/ExternalEffects.hh +++ b/src/trackerrk4/ExternalEffects.hh @@ -16,16 +16,14 @@ #include -#include "Bunch.hh" -#include "BaseFieldSource.hh" - -#include "CppPyWrapper.hh" +#include "orbit/Bunch.hh" +#include "utils/BaseFieldSource.hh" namespace TrackerRK4{ class RungeKuttaTracker; - class ExternalEffects: public OrbitUtils::CppPyWrapper + class ExternalEffects { //-------------------------------------------------- // public methods of the ExternalEffects class diff --git a/src/trackerrk4/PyExternalEffects.cc b/src/trackerrk4/PyExternalEffects.cc index cfca4c28..d390cff6 100644 --- a/src/trackerrk4/PyExternalEffects.cc +++ b/src/trackerrk4/PyExternalEffects.cc @@ -26,11 +26,12 @@ // debugging only. // /////////////////////////////////////////////////////////////////////////// -#include "orbit_mpi.hh" +#include "mpi/orbit_mpi.hh" #include -#include "PyExternalEffects.hh" -#include "RungeKuttaTracker.hh" +#include "trackerrk4/PyExternalEffects.hh" +#include "trackerrk4/RungeKuttaTracker.hh" +#include "main/pyORBIT_Object.hh" //#include using namespace TrackerRK4; @@ -39,7 +40,7 @@ using namespace OrbitUtils; PyExternalEffects::PyExternalEffects(PyObject* py_wrapperIn) { setName("PyExternalEffects"); - setPyWrapper(py_wrapperIn); + py_wrapper = py_wrapperIn; } PyExternalEffects::~PyExternalEffects() @@ -47,24 +48,21 @@ PyExternalEffects::~PyExternalEffects() } void PyExternalEffects::setupEffects(Bunch* bunch){ - PyObject* py_wrp = getPyWrapper(); - PyObject* py_bunch = bunch->getPyWrapper(); - PyObject* res_tuple = PyObject_CallMethod(py_wrp,const_cast("setupEffects"),const_cast("O"),py_bunch); + PyObject* py_bunch = pyorbit::getPyWrapper(bunch); + PyObject* res_tuple = PyObject_CallMethod(py_wrapper,const_cast("setupEffects"),const_cast("O"),py_bunch); Py_DECREF(res_tuple); } void PyExternalEffects::prepareEffects(Bunch* bunch, double t){ - PyObject* py_wrp = getPyWrapper(); - PyObject* py_bunch = bunch->getPyWrapper(); - PyObject* res_tuple = PyObject_CallMethod(py_wrp,const_cast("prepareEffects"),const_cast("Od"),py_bunch, time); + PyObject* py_bunch = pyorbit::getPyWrapper(bunch); + PyObject* res_tuple = PyObject_CallMethod(py_wrapper,const_cast("prepareEffects"),const_cast("Od"),py_bunch, t); Py_DECREF(res_tuple); } void PyExternalEffects::finalizeEffects(Bunch* bunch){ - PyObject* py_wrp = getPyWrapper(); - PyObject* py_bunch = bunch->getPyWrapper(); - PyObject* res_tuple = PyObject_CallMethod(py_wrp,const_cast("finalizeEffects"),const_cast("O"),py_bunch); + PyObject* py_bunch = pyorbit::getPyWrapper(bunch); + PyObject* res_tuple = PyObject_CallMethod(py_wrapper,const_cast("finalizeEffects"),const_cast("O"),py_bunch); Py_DECREF(res_tuple); } @@ -73,11 +71,10 @@ void PyExternalEffects::applyEffects(Bunch* bunch, BaseFieldSource* fieldSource, RungeKuttaTracker* tracker) { - PyObject* py_wrp = getPyWrapper(); - PyObject* py_bunch = bunch->getPyWrapper(); - PyObject* py_field = fieldSource->getPyWrapper(); - PyObject* py_tracker = tracker->getPyWrapper(); - PyObject* res_tuple = PyObject_CallMethod(py_wrp,const_cast("applyEffects"),const_cast("OddOO"), + PyObject* py_bunch = pyorbit::getPyWrapper(bunch); + PyObject* py_field = pyorbit::getPyWrapper(fieldSource); + PyObject* py_tracker = pyorbit::getPyWrapper(tracker); + PyObject* res_tuple = PyObject_CallMethod(py_wrapper,const_cast("applyEffects"),const_cast("OddOO"), py_bunch, t,t_step, py_field, @@ -91,15 +88,14 @@ void PyExternalEffects::applyEffectsForEach(Bunch* bunch, int index, BaseFieldSource* fieldSource, RungeKuttaTracker* tracker) { - PyObject* py_wrp = getPyWrapper(); - PyObject* py_bunch = bunch->getPyWrapper(); - PyObject* py_field = fieldSource->getPyWrapper(); - PyObject* py_tracker = tracker->getPyWrapper(); + PyObject* py_bunch = pyorbit::getPyWrapper(bunch); + PyObject* py_field = pyorbit::getPyWrapper(fieldSource); + PyObject* py_tracker = pyorbit::getPyWrapper(tracker); PyObject* pyInVct = Py_BuildValue("(dddddd)",y_in_vct[0],y_in_vct[1],y_in_vct[2], y_in_vct[3],y_in_vct[4],y_in_vct[5]); PyObject* pyOutVct = Py_BuildValue("(dddddd)",y_out_vct[0],y_out_vct[1],y_out_vct[2], y_out_vct[3],y_out_vct[4],y_out_vct[5]); - PyObject* res_tuple = PyObject_CallMethod(py_wrp,const_cast("applyEffectsForEach"),const_cast("OiOOddOO"), + PyObject* res_tuple = PyObject_CallMethod(py_wrapper,const_cast("applyEffectsForEach"),const_cast("OiOOddOO"), py_bunch, index, pyInVct,pyOutVct, diff --git a/src/trackerrk4/PyExternalEffects.hh b/src/trackerrk4/PyExternalEffects.hh index 9c100b95..15149e1b 100644 --- a/src/trackerrk4/PyExternalEffects.hh +++ b/src/trackerrk4/PyExternalEffects.hh @@ -29,9 +29,9 @@ #ifndef PY_EXTERNAL_EFFECTS_H #define PY_EXTERNAL_EFFECTS_H -#include "Python.h" +#include -#include "ExternalEffects.hh" +#include "trackerrk4/ExternalEffects.hh" namespace TrackerRK4{ @@ -67,7 +67,8 @@ namespace TrackerRK4{ OrbitUtils::BaseFieldSource* fieldSource, RungeKuttaTracker* tracker); - + private: + PyObject* py_wrapper; }; }; diff --git a/src/trackerrk4/RungeKuttaTracker.cc b/src/trackerrk4/RungeKuttaTracker.cc index 91d58667..e224f7a0 100644 --- a/src/trackerrk4/RungeKuttaTracker.cc +++ b/src/trackerrk4/RungeKuttaTracker.cc @@ -14,8 +14,9 @@ // // /////////////////////////////////////////////////////////////////////////// -#include "RungeKuttaTracker.hh" +#include "trackerrk4/RungeKuttaTracker.hh" +#include #include #include #include @@ -23,7 +24,7 @@ using namespace TrackerRK4; using namespace OrbitUtils; -#include "OrbitConst.hh" +#include "orbit/OrbitConst.hh" RungeKuttaTracker::RungeKuttaTracker(double lengthIn){ diff --git a/src/trackerrk4/RungeKuttaTracker.hh b/src/trackerrk4/RungeKuttaTracker.hh index 40ce050d..874bcf35 100644 --- a/src/trackerrk4/RungeKuttaTracker.hh +++ b/src/trackerrk4/RungeKuttaTracker.hh @@ -17,15 +17,13 @@ #ifndef RUNGE_KUTTA_3D_TRACKER_H #define RUNGE_KUTTA_3D_TRACKER_H -#include "Bunch.hh" -#include "BaseFieldSource.hh" -#include "ExternalEffects.hh" - -#include "CppPyWrapper.hh" +#include "orbit/Bunch.hh" +#include "utils/BaseFieldSource.hh" +#include "trackerrk4/ExternalEffects.hh" namespace TrackerRK4{ - class RungeKuttaTracker: public OrbitUtils::CppPyWrapper + class RungeKuttaTracker { //-------------------------------------------------- // public methods of the RungeKuttaTracker class diff --git a/src/trackerrk4/wrap_ext_effects_container.cc b/src/trackerrk4/wrap_ext_effects_container.cc index 407187b9..fd297bb7 100644 --- a/src/trackerrk4/wrap_ext_effects_container.cc +++ b/src/trackerrk4/wrap_ext_effects_container.cc @@ -1,20 +1,25 @@ -#include "orbit_mpi.hh" -#include "pyORBIT_Object.hh" +#include "mpi/orbit_mpi.hh" +#include "main/pyORBIT_Object.hh" -#include "wrap_utils.hh" -#include "wrap_ext_effects_container.hh" +#include "utils/wrap_utils.hh" +#include "trackerrk4/wrap_ext_effects_container.hh" #include #include -#include "ExtEffectsContainer.hh" -#include "ExternalEffects.hh" +#include "trackerrk4/ExtEffectsContainer.hh" +#include "trackerrk4/ExternalEffects.hh" using namespace OrbitUtils; namespace wrap_ext_effects_container{ + typedef struct { + PyObject_HEAD + void* cpp_obj; + PyObject* effects; + } pyORBIT_ExtEffectsContainer; void error(const char* msg){ ORBIT_MPI_Finalize(msg); } @@ -27,27 +32,30 @@ extern "C" { //It never will be called directly static PyObject* ExtEffectsContainer_new(PyTypeObject *type, PyObject *args, PyObject *kwds) { - pyORBIT_Object* self; - self = (pyORBIT_Object *) type->tp_alloc(type, 0); + pyORBIT_ExtEffectsContainer* self; + self = (pyORBIT_ExtEffectsContainer *) type->tp_alloc(type, 0); self->cpp_obj = NULL; + self->effects = NULL; return (PyObject *) self; } //this is implementation of the __init__ method - static int ExtEffectsContainer_init(pyORBIT_Object *self, PyObject *args, PyObject *kwds){ - - + static int ExtEffectsContainer_init(pyORBIT_ExtEffectsContainer *self, PyObject *args, PyObject *kwds){ self->cpp_obj = new ExtEffectsContainer(); - ((ExtEffectsContainer*) self->cpp_obj)->setPyWrapper((PyObject*) self); - - + self->effects = PyList_New(0); + if(self->effects == NULL) { + delete ((ExtEffectsContainer*) self->cpp_obj); + self->cpp_obj = NULL; + return -1; + } + pyorbit::registerPyWrapper(self->cpp_obj, (PyObject*) self); return 0; } static PyObject* ExtEffectsContainer_AddEffect(PyObject *self, PyObject *args){ - - ExtEffectsContainer* cpp_ExtEffectsContainer = (ExtEffectsContainer*)((pyORBIT_Object*) self)->cpp_obj; + pyORBIT_ExtEffectsContainer* container = (pyORBIT_ExtEffectsContainer*) self; + ExtEffectsContainer* cpp_ExtEffectsContainer = (ExtEffectsContainer*) container->cpp_obj; ExternalEffects* extEf; PyObject* pyExtEffects; @@ -56,6 +64,7 @@ extern "C" { error(" AddEffect(ExternalEffects effect) - parameter is needed"); else { extEf = (ExternalEffects*) ((pyORBIT_Object*) pyExtEffects)->cpp_obj; + if(PyList_Append(container->effects, pyExtEffects) < 0) return NULL; cpp_ExtEffectsContainer->AddEffect(extEf); } @@ -67,8 +76,10 @@ extern "C" { //----------------------------------------------------- //destructor for python ExtEffectsContainer class (__del__ method). //----------------------------------------------------- - static void ExtEffectsContainer_del(pyORBIT_Object* self){ + static void ExtEffectsContainer_del(pyORBIT_ExtEffectsContainer* self){ + pyorbit::unregisterPyWrapper(self->cpp_obj, (PyObject*) self); delete ((ExtEffectsContainer*)self->cpp_obj); + Py_CLEAR(self->effects); self->ob_base.ob_type->tp_free((PyObject*)self); } @@ -89,7 +100,7 @@ extern "C" { static PyTypeObject pyORBIT_ExtEffectsContainer_Type = { PyVarObject_HEAD_INIT(NULL, 0) "ExtEffectsContainer", /*tp_name*/ - sizeof(pyORBIT_Object), /*tp_basicsize*/ + sizeof(pyORBIT_ExtEffectsContainer), /*tp_basicsize*/ 0, /*tp_itemsize*/ (destructor) ExtEffectsContainer_del , /*tp_dealloc*/ 0, /*tp_print*/ diff --git a/src/trackerrk4/wrap_ext_effects_container.hh b/src/trackerrk4/wrap_ext_effects_container.hh index d0a532c6..0ab910a7 100644 --- a/src/trackerrk4/wrap_ext_effects_container.hh +++ b/src/trackerrk4/wrap_ext_effects_container.hh @@ -1,7 +1,7 @@ #ifndef WRAP_EXT_EFFECTS_CONTAINER_HH_ #define WRAP_EXT_EFFECTS_CONTAINER_HH_ -#include "Python.h" +#include #ifdef __cplusplus extern "C" { diff --git a/src/trackerrk4/wrap_py_external_effects.cc b/src/trackerrk4/wrap_py_external_effects.cc index 67f80279..635ef11e 100644 --- a/src/trackerrk4/wrap_py_external_effects.cc +++ b/src/trackerrk4/wrap_py_external_effects.cc @@ -1,13 +1,13 @@ -#include "orbit_mpi.hh" -#include "pyORBIT_Object.hh" +#include "mpi/orbit_mpi.hh" +#include "main/pyORBIT_Object.hh" -#include "wrap_utils.hh" -#include "wrap_py_external_effects.hh" +#include "utils/wrap_utils.hh" +#include "trackerrk4/wrap_py_external_effects.hh" #include #include -#include "PyExternalEffects.hh" +#include "trackerrk4/PyExternalEffects.hh" using namespace OrbitUtils; using namespace TrackerRK4; @@ -38,6 +38,7 @@ extern "C" { //this is implementation of the __init__ method static int PyExternalEffects_init(pyORBIT_Object *self, PyObject *args, PyObject *kwds){ self->cpp_obj = new PyExternalEffects((PyObject*) self); + pyorbit::registerPyWrapper(self->cpp_obj, (PyObject*) self); return 0; } @@ -61,6 +62,7 @@ extern "C" { //----------------------------------------------------- static void PyExternalEffects_del(pyORBIT_Object* self){ //std::cerr<<"The PyExternalEffects __del__ has been called!"<cpp_obj, (PyObject*) self); delete ((PyExternalEffects*)self->cpp_obj); self->ob_base.ob_type->tp_free((PyObject*)self); } diff --git a/src/trackerrk4/wrap_py_external_effects.hh b/src/trackerrk4/wrap_py_external_effects.hh index ec7dc15a..88beeff6 100644 --- a/src/trackerrk4/wrap_py_external_effects.hh +++ b/src/trackerrk4/wrap_py_external_effects.hh @@ -1,7 +1,7 @@ #ifndef WRAP_PY_EXTERNAL_EFFECTS_H #define WRAP_PY_EXTERNAL_EFFECTS_H -#include "Python.h" +#include #ifdef __cplusplus extern "C" { diff --git a/src/trackerrk4/wrap_runge_kutta_tracker.cc b/src/trackerrk4/wrap_runge_kutta_tracker.cc index 4f73283d..64617f84 100644 --- a/src/trackerrk4/wrap_runge_kutta_tracker.cc +++ b/src/trackerrk4/wrap_runge_kutta_tracker.cc @@ -1,11 +1,11 @@ -#include "orbit_mpi.hh" -#include "pyORBIT_Object.hh" +#include "mpi/orbit_mpi.hh" +#include "main/pyORBIT_Object.hh" -#include "wrap_runge_kutta_tracker.hh" +#include "trackerrk4/wrap_runge_kutta_tracker.hh" #include -#include "RungeKuttaTracker.hh" +#include "trackerrk4/RungeKuttaTracker.hh" using namespace TrackerRK4; using namespace OrbitUtils; @@ -41,7 +41,7 @@ extern "C" { error("PyRungeKuttaTracker - RungeKuttaTracker(length[m]) - constructor needs a parameter."); } self->cpp_obj = new RungeKuttaTracker(length); - ((RungeKuttaTracker*) self->cpp_obj)->setPyWrapper((PyObject*) self); + pyorbit::registerPyWrapper(self->cpp_obj, (PyObject*) self); //std::cerr<<"The RungeKuttaTracker __init__ has been called!"<cpp_obj, (PyObject*) self); delete ((RungeKuttaTracker*)self->cpp_obj); self->ob_base.ob_type->tp_free((PyObject*)self); } diff --git a/src/trackerrk4/wrap_runge_kutta_tracker.hh b/src/trackerrk4/wrap_runge_kutta_tracker.hh index c8bce3f1..b25398be 100644 --- a/src/trackerrk4/wrap_runge_kutta_tracker.hh +++ b/src/trackerrk4/wrap_runge_kutta_tracker.hh @@ -1,7 +1,7 @@ #ifndef WRAP_RUNGE_KUTTA_TRACKER_H #define WRAP_RUNGE_KUTTA_TRACKER_H -#include "Python.h" +#include #ifdef __cplusplus extern "C" { diff --git a/src/trackerrk4/wrap_trackerrk4.cc b/src/trackerrk4/wrap_trackerrk4.cc index 5d23b55c..8ea7aca7 100644 --- a/src/trackerrk4/wrap_trackerrk4.cc +++ b/src/trackerrk4/wrap_trackerrk4.cc @@ -1,9 +1,9 @@ -#include "orbit_mpi.hh" +#include "mpi/orbit_mpi.hh" -#include "wrap_trackerrk4.hh" -#include "wrap_runge_kutta_tracker.hh" -#include "wrap_py_external_effects.hh" -#include "wrap_ext_effects_container.hh" +#include "trackerrk4/wrap_trackerrk4.hh" +#include "trackerrk4/wrap_runge_kutta_tracker.hh" +#include "trackerrk4/wrap_py_external_effects.hh" +#include "trackerrk4/wrap_ext_effects_container.hh" static PyMethodDef trackerrk4Methods[] = { {NULL,NULL} }; @@ -29,14 +29,6 @@ extern "C" { return module; } - PyObject* getTrackerRK4Type(const char* name){ - PyObject* mod = PyImport_ImportModule("orbit.core.trackerrk4"); - PyObject* pyType = PyObject_GetAttrString(mod,name); - Py_DECREF(mod); - Py_DECREF(pyType); - return pyType; - } - #ifdef __cplusplus } #endif diff --git a/src/trackerrk4/wrap_trackerrk4.hh b/src/trackerrk4/wrap_trackerrk4.hh index dcbf5693..59bf3177 100644 --- a/src/trackerrk4/wrap_trackerrk4.hh +++ b/src/trackerrk4/wrap_trackerrk4.hh @@ -1,7 +1,7 @@ #ifndef WRAP_RK4_TRACKER_H #define WRAP_RK4_TRACKER_H -#include "Python.h" +#include #ifdef __cplusplus extern "C" { diff --git a/src/utils/AttributesBucket.cc b/src/utils/AttributesBucket.cc index 676f5521..10931988 100644 --- a/src/utils/AttributesBucket.cc +++ b/src/utils/AttributesBucket.cc @@ -13,7 +13,7 @@ // A class for collection of int and double attributes in the dictionary. /////////////////////////////////////////////////////////////////////////// -#include "AttributesBucket.hh" +#include "utils/AttributesBucket.hh" using namespace OrbitUtils; diff --git a/src/utils/BaseFieldSource.cc b/src/utils/BaseFieldSource.cc index baace095..b6d9bd8b 100644 --- a/src/utils/BaseFieldSource.cc +++ b/src/utils/BaseFieldSource.cc @@ -14,11 +14,11 @@ /////////////////////////////////////////////////////////////////////////// -#include "BaseFieldSource.hh" +#include "utils/BaseFieldSource.hh" using namespace OrbitUtils; -BaseFieldSource::BaseFieldSource(): CppPyWrapper(NULL) +BaseFieldSource::BaseFieldSource() { } diff --git a/src/utils/BaseFieldSource.hh b/src/utils/BaseFieldSource.hh index f4727445..6f9ee257 100644 --- a/src/utils/BaseFieldSource.hh +++ b/src/utils/BaseFieldSource.hh @@ -12,8 +12,6 @@ #ifndef BASE_FIELD_SOURCE_H #define BASE_FIELD_SOURCE_H -#include "CppPyWrapper.hh" - namespace OrbitUtils{ @@ -23,7 +21,7 @@ namespace OrbitUtils{ subclasses. */ - class BaseFieldSource: public CppPyWrapper + class BaseFieldSource { public: diff --git a/src/utils/BufferStore.cc b/src/utils/BufferStore.cc index 7822570e..9c5f06ef 100644 --- a/src/utils/BufferStore.cc +++ b/src/utils/BufferStore.cc @@ -19,7 +19,7 @@ #include #include -#include "BufferStore.hh" +#include "utils/BufferStore.hh" using namespace OrbitUtils; diff --git a/src/utils/CppPyWrapper.cc b/src/utils/CppPyWrapper.cc deleted file mode 100644 index b3178252..00000000 --- a/src/utils/CppPyWrapper.cc +++ /dev/null @@ -1,39 +0,0 @@ -//////////////////////////////// -*- C++ -*- ////////////////////////////// -// -// FILE NAME -// CppPyWrapper.cc -// -// CREATED -// 04/22/2003 -// -// DESCRIPTION -// The base class that provides capability to keep the reference to -// the Python class instance that is wrapping the c++ subclassing -// this class. -// -/////////////////////////////////////////////////////////////////////////// -#include "CppPyWrapper.hh" - -using namespace OrbitUtils; - -CppPyWrapper::CppPyWrapper(PyObject* py_wrapperIn) -{ - cpp_py_wrapper = py_wrapperIn; -} - -CppPyWrapper::CppPyWrapper() -{ - cpp_py_wrapper = NULL; -} - -CppPyWrapper::~CppPyWrapper() -{ -} - -void CppPyWrapper::setPyWrapper(PyObject* py_wrapperIn){ - cpp_py_wrapper = py_wrapperIn; -} - -PyObject* CppPyWrapper::getPyWrapper(){ - return cpp_py_wrapper; -} diff --git a/src/utils/CppPyWrapper.hh b/src/utils/CppPyWrapper.hh deleted file mode 100644 index ada658e6..00000000 --- a/src/utils/CppPyWrapper.hh +++ /dev/null @@ -1,54 +0,0 @@ -//////////////////////////////// -*- C++ -*- ////////////////////////////// -// -// FILE NAME -// CppPyWrapper.hh -// -// CREATED -// 04/22/2003 -// -// DESCRIPTION -// The base class that provides capability to keep the reference to -// the Python class instance that is wrapping the c++ subclassing -// this class. -// -/////////////////////////////////////////////////////////////////////////// -#ifndef CPP_PY_WRAPPER_H -#define CPP_PY_WRAPPER_H - -#include "Python.h" - -namespace OrbitUtils{ - - /** - The base class that provides capability to keep the reference to - the Python class instance that is wrapping the c++ subclassing - this class. - */ - - class CppPyWrapper - { - public: - - /** Constructor of the CppPyWrapper class with reference to Python class instance. */ - CppPyWrapper(PyObject* py_wrapperIn); - - /** Constructor of the CppPyWrapper class with NULL reference to Python class. */ - CppPyWrapper(); - - /** Destrictor. It is empty. */ - ~CppPyWrapper(); - - /** Sets the reference to Python class instance. */ - void setPyWrapper(PyObject* py_wrapperIn); - - /** Returns the reference to Python class instance. */ - PyObject* getPyWrapper(); - - private: - - PyObject* cpp_py_wrapper; - - }; -}; - -#endif diff --git a/src/utils/FieldSourceContainer.cc b/src/utils/FieldSourceContainer.cc index 15ad959a..8ec9426b 100644 --- a/src/utils/FieldSourceContainer.cc +++ b/src/utils/FieldSourceContainer.cc @@ -13,13 +13,13 @@ // The container for instances of the BaseFieldSource class. // /////////////////////////////////////////////////////////////////////////// -#include "orbit_mpi.hh" +#include "mpi/orbit_mpi.hh" #include #include #include #include -#include "FieldSourceContainer.hh" +#include "utils/FieldSourceContainer.hh" using namespace OrbitUtils; @@ -29,23 +29,10 @@ FieldSourceContainer::FieldSourceContainer():BaseFieldSource() } FieldSourceContainer::~FieldSourceContainer(){ - - for (int i=0;igetPyWrapper() == NULL){ - delete ref[i]; - } else { - Py_XDECREF(ref[i]->getPyWrapper()); - } - } - } /** Adds the instance of the ExternalEffects class to the container. */ void FieldSourceContainer::AddFieldSource(BaseFieldSource* fs) { - if(fs->getPyWrapper() != NULL){ - Py_INCREF(fs->getPyWrapper()); - } - ref.push_back(fs); } diff --git a/src/utils/FieldSourceContainer.hh b/src/utils/FieldSourceContainer.hh index ce8c4c01..8a11d21b 100644 --- a/src/utils/FieldSourceContainer.hh +++ b/src/utils/FieldSourceContainer.hh @@ -18,9 +18,7 @@ #ifndef FIELDSOURCECONTAINER_HH_ #define FIELDSOURCECONTAINER_HH_ -#include "Python.h" - -#include "BaseFieldSource.hh" +#include "utils/BaseFieldSource.hh" #include namespace OrbitUtils{ @@ -40,7 +38,7 @@ namespace OrbitUtils{ /** Destructor. */ ~FieldSourceContainer(); - /** Adds the instance of the ExternalEffects class to the container. */ + /** Adds a non-owning field-source reference to the container. */ void AddFieldSource(BaseFieldSource* fs); /** Adds the instance of the ExternalEffects class to the container. */ @@ -50,7 +48,7 @@ namespace OrbitUtils{ private: - std::vector ref; + std::vector ref; }; }; diff --git a/src/utils/MathPolynomial.cc b/src/utils/MathPolynomial.cc index ad623772..fffa77d9 100644 --- a/src/utils/MathPolynomial.cc +++ b/src/utils/MathPolynomial.cc @@ -14,8 +14,8 @@ // different polynomials. // /////////////////////////////////////////////////////////////////////////// -#include "orbit_mpi.hh" -#include "MathPolynomial.hh" +#include "mpi/orbit_mpi.hh" +#include "utils/MathPolynomial.hh" using namespace OrbitUtils; diff --git a/src/utils/MathPolynomial.hh b/src/utils/MathPolynomial.hh index 9ce9c95b..af6fa605 100644 --- a/src/utils/MathPolynomial.hh +++ b/src/utils/MathPolynomial.hh @@ -19,7 +19,7 @@ /////////////////////////////////////////////////////////////////////////// #include #include -#include "tcomplex.hh" +#include "utils/tcomplex.hh" #include namespace OrbitUtils{ diff --git a/src/utils/OU_Function.cc b/src/utils/OU_Function.cc index 2cfa3145..e6c14e39 100644 --- a/src/utils/OU_Function.cc +++ b/src/utils/OU_Function.cc @@ -15,14 +15,14 @@ // It is using linear interpolation. // /////////////////////////////////////////////////////////////////////////// -#include "orbit_mpi.hh" -#include "OU_Function.hh" +#include "mpi/orbit_mpi.hh" +#include "utils/OU_Function.hh" #include using namespace OrbitUtils; -Function::Function(): CppPyWrapper(NULL) +Function::Function() { x_arr = NULL; y_arr = NULL; @@ -641,7 +641,7 @@ void Function::findMinMaxXY(){ } -void Function::print(ostream& Out) +void Function::print(std::ostream& Out) { if(rank_MPI == 0){ Out< #include #include #include -using namespace std; namespace OrbitUtils{ - class Function : public CppPyWrapper + class Function { public: //----------------------------------------- diff --git a/src/utils/OU_SplineCH.cc b/src/utils/OU_SplineCH.cc index 169a4509..232694d3 100644 --- a/src/utils/OU_SplineCH.cc +++ b/src/utils/OU_SplineCH.cc @@ -23,15 +23,15 @@ // m[n-2] = (y[n-1] - y[n-2])/(x[n-1]-x[n-2]) // /////////////////////////////////////////////////////////////////////////// -#include "orbit_mpi.hh" -#include "OU_SplineCH.hh" +#include "mpi/orbit_mpi.hh" +#include "utils/OU_SplineCH.hh" #include namespace OrbitUtils{ - SplineCH::SplineCH(): CppPyWrapper(NULL) + SplineCH::SplineCH() { x_arr = NULL; y_arr = NULL; @@ -207,7 +207,7 @@ namespace OrbitUtils{ return yyp; } - void SplineCH::print(ostream& Out) + void SplineCH::print(std::ostream& Out) { if(rank_MPI == 0){ Out< #include -#include "CppPyWrapper.hh" -#include "OU_Function.hh" +#include "utils/OU_Function.hh" namespace OrbitUtils{ - class SplineCH : public CppPyWrapper + class SplineCH { public: //----------------------------------------- diff --git a/src/utils/PyBaseFieldSource.cc b/src/utils/PyBaseFieldSource.cc index f2ba47bf..c03809bf 100644 --- a/src/utils/PyBaseFieldSource.cc +++ b/src/utils/PyBaseFieldSource.cc @@ -19,16 +19,16 @@ // debugging only. // /////////////////////////////////////////////////////////////////////////// -#include "PyBaseFieldSource.hh" +#include "utils/PyBaseFieldSource.hh" -#include "orbit_mpi.hh" +#include "mpi/orbit_mpi.hh" #include using namespace OrbitUtils; PyBaseFieldSource::PyBaseFieldSource(PyObject* py_wrapperIn) { - setPyWrapper(py_wrapperIn); + py_wrapper = py_wrapperIn; } PyBaseFieldSource::~PyBaseFieldSource() @@ -40,8 +40,7 @@ void PyBaseFieldSource::getElectricMagneticField( double& fe_x, double& fe_y, double& fe_z, double& fm_x, double& fm_y, double& fm_z) { - PyObject* py_wrp = getPyWrapper(); - PyObject* ef_tuple = PyObject_CallMethod(py_wrp,const_cast("getElectricMagneticField"),const_cast("dddd"),x,y,z,t); + PyObject* ef_tuple = PyObject_CallMethod(py_wrapper,const_cast("getElectricMagneticField"),const_cast("dddd"),x,y,z,t); if(!PyArg_ParseTuple( ef_tuple,"dddddd:electric_magnetic_field",&fe_x,&fe_y,&fe_z,&fm_x,&fm_y,&fm_z)){ ORBIT_MPI_Finalize("PyBaseFieldSource - getElectricMagneticField(x,y,z,t0 method does not work!"); } diff --git a/src/utils/PyBaseFieldSource.hh b/src/utils/PyBaseFieldSource.hh index f00cee04..89207f3d 100644 --- a/src/utils/PyBaseFieldSource.hh +++ b/src/utils/PyBaseFieldSource.hh @@ -22,9 +22,9 @@ #ifndef PY_BASE_FIELD_SOURCE_H #define PY_BASE_FIELD_SOURCE_H -#include "Python.h" +#include -#include "BaseFieldSource.hh" +#include "utils/BaseFieldSource.hh" namespace OrbitUtils{ @@ -55,6 +55,9 @@ namespace OrbitUtils{ double& fe_x, double& fe_y, double& fe_z, double& fm_x, double& fm_y, double& fm_z); + private: + PyObject* py_wrapper; + }; }; diff --git a/src/utils/Random.cc b/src/utils/Random.cc index 4725232a..ef8090d5 100644 --- a/src/utils/Random.cc +++ b/src/utils/Random.cc @@ -15,7 +15,7 @@ // a random number between 0 and 1. /////////////////////////////////////////////////////////////////////////// -#include "Random.hh" +#include "utils/Random.hh" #include using namespace OrbitUtils; diff --git a/src/utils/StringUtils.cc b/src/utils/StringUtils.cc index 03671cf8..e62adbf5 100644 --- a/src/utils/StringUtils.cc +++ b/src/utils/StringUtils.cc @@ -1,19 +1,19 @@ -#include "StringUtils.hh" +#include "utils/StringUtils.hh" #include #include using namespace OrbitUtils; -int StringUtils::Tokenize(const string& str,vector& tokens, const string& delimiters) +int StringUtils::Tokenize(const std::string& str,std::vector& tokens, const std::string& delimiters) { tokens.clear(); // Skip delimiters at beginning. - string::size_type lastPos = str.find_first_not_of(delimiters, 0); + std::string::size_type lastPos = str.find_first_not_of(delimiters, 0); // Find first "non-delimiter". - string::size_type pos = str.find_first_of(delimiters, lastPos); + std::string::size_type pos = str.find_first_of(delimiters, lastPos); - while (string::npos != pos || string::npos != lastPos) + while (std::string::npos != pos || std::string::npos != lastPos) { // Found a token, add it to the vector. tokens.push_back(str.substr(lastPos, pos - lastPos)); diff --git a/src/utils/StringUtils.hh b/src/utils/StringUtils.hh index bbb10191..ad4f97e0 100644 --- a/src/utils/StringUtils.hh +++ b/src/utils/StringUtils.hh @@ -4,7 +4,6 @@ #include #include -using namespace std; //======================================= //Usage @@ -22,7 +21,7 @@ namespace OrbitUtils{ The Tokenizer. It returns the vector with tokens. The delimiter is optional, and by default it is a space. */ - int Tokenize(const string& str,vector& tokens, const string& delimiters = " "); + int Tokenize(const std::string& str,std::vector& tokens, const std::string& delimiters = " "); }; }; #endif diff --git a/src/utils/bessel.cc b/src/utils/bessel.cc index f7817d0d..6a0a9bdc 100644 --- a/src/utils/bessel.cc +++ b/src/utils/bessel.cc @@ -13,7 +13,7 @@ // /////////////////////////////////////////////////////////////////////////// -#include "bessel.hh" +#include "utils/bessel.hh" namespace OrbitUtils{ diff --git a/src/utils/bunch/BunchExtremaCalculator.cc b/src/utils/bunch/BunchExtremaCalculator.cc index 03057d2c..c2e6e9dc 100644 --- a/src/utils/bunch/BunchExtremaCalculator.cc +++ b/src/utils/bunch/BunchExtremaCalculator.cc @@ -14,9 +14,9 @@ // /////////////////////////////////////////////////////////////////////////// -#include "orbit_mpi.hh" -#include "BunchExtremaCalculator.hh" -#include "BufferStore.hh" +#include "mpi/orbit_mpi.hh" +#include "utils/bunch/BunchExtremaCalculator.hh" +#include "utils/BufferStore.hh" #include #include @@ -25,7 +25,7 @@ using namespace OrbitUtils; -BunchExtremaCalculator::BunchExtremaCalculator(): CppPyWrapper(NULL) +BunchExtremaCalculator::BunchExtremaCalculator() { } @@ -65,7 +65,7 @@ void BunchExtremaCalculator::getExtremaXYZ(Bunch* bunch, gridLimArr[2] = - gridLimArr[2]; gridLimArr[4] = - gridLimArr[4]; - ORBIT_MPI_Allreduce(gridLimArr,gridLimArr_out,6,MPI_DOUBLE,MPI_MAX,bunch->getMPI_Comm_Local()->comm); + ORBIT_MPI_Allreduce(gridLimArr,gridLimArr_out,6,MPI_DOUBLE,MPI_MAX,bunch->getMPI_Comm_Local()); gridLimArr_out[0] = - gridLimArr_out[0]; gridLimArr_out[2] = - gridLimArr_out[2]; @@ -114,7 +114,7 @@ void BunchExtremaCalculator::getExtremaXpYpdE(Bunch* bunch, gridLimArr[2] = - gridLimArr[2]; gridLimArr[4] = - gridLimArr[4]; - ORBIT_MPI_Allreduce(gridLimArr,gridLimArr_out,6,MPI_DOUBLE,MPI_MAX,bunch->getMPI_Comm_Local()->comm); + ORBIT_MPI_Allreduce(gridLimArr,gridLimArr_out,6,MPI_DOUBLE,MPI_MAX,bunch->getMPI_Comm_Local()); gridLimArr_out[0] = - gridLimArr_out[0]; gridLimArr_out[2] = - gridLimArr_out[2]; @@ -152,7 +152,7 @@ void BunchExtremaCalculator::getExtremaZ(Bunch* bunch, gridLimArr[0] = - gridLimArr[0]; - ORBIT_MPI_Allreduce(gridLimArr,gridLimArr_out,2,MPI_DOUBLE,MPI_MAX,bunch->getMPI_Comm_Local()->comm); + ORBIT_MPI_Allreduce(gridLimArr,gridLimArr_out,2,MPI_DOUBLE,MPI_MAX,bunch->getMPI_Comm_Local()); gridLimArr_out[0] = - gridLimArr_out[0]; @@ -182,8 +182,8 @@ void BunchExtremaCalculator::getExtremaR(Bunch* bunch, double& rMax) double x_avg_global = 0.; double y_avg_global = 0.; - ORBIT_MPI_Allreduce(&x_avg,&x_avg_global,1,MPI_DOUBLE,MPI_SUM,bunch->getMPI_Comm_Local()->comm); - ORBIT_MPI_Allreduce(&y_avg,&y_avg_global,1,MPI_DOUBLE,MPI_SUM,bunch->getMPI_Comm_Local()->comm); + ORBIT_MPI_Allreduce(&x_avg,&x_avg_global,1,MPI_DOUBLE,MPI_SUM,bunch->getMPI_Comm_Local()); + ORBIT_MPI_Allreduce(&y_avg,&y_avg_global,1,MPI_DOUBLE,MPI_SUM,bunch->getMPI_Comm_Local()); if(nParts > 0){ x_avg = x_avg_global/nParts; @@ -203,7 +203,7 @@ void BunchExtremaCalculator::getExtremaR(Bunch* bunch, double& rMax) if(rMax > rMax_local) rMax_local = rMax; } - ORBIT_MPI_Allreduce(&rMax_local,&rMax_global,1,MPI_DOUBLE,MPI_MAX,bunch->getMPI_Comm_Local()->comm); + ORBIT_MPI_Allreduce(&rMax_local,&rMax_global,1,MPI_DOUBLE,MPI_MAX,bunch->getMPI_Comm_Local()); rMax = rMax_global; } diff --git a/src/utils/bunch/BunchExtremaCalculator.hh b/src/utils/bunch/BunchExtremaCalculator.hh index 104446a7..486d7d16 100644 --- a/src/utils/bunch/BunchExtremaCalculator.hh +++ b/src/utils/bunch/BunchExtremaCalculator.hh @@ -18,13 +18,13 @@ #define BUNCH_EXTREMA_CALCULATIONS_H //ORBIT bunch -#include "Bunch.hh" +#include "orbit/Bunch.hh" namespace OrbitUtils{ /** A class calculates the extrema and averages of the particles coordinates in the bunch.*/ - class BunchExtremaCalculator : public CppPyWrapper + class BunchExtremaCalculator { public: diff --git a/src/utils/bunch/InitialCoordsAttrFunctions.cc b/src/utils/bunch/InitialCoordsAttrFunctions.cc index 2ba87291..9ea60ceb 100644 --- a/src/utils/bunch/InitialCoordsAttrFunctions.cc +++ b/src/utils/bunch/InitialCoordsAttrFunctions.cc @@ -39,14 +39,14 @@ // wx = exp(-(x^2+(alphax*x+betax*x')^2)/(2*(betax*emittancex)) etc. // /////////////////////////////////////////////////////////////////////////// -#include "orbit_mpi.hh" -#include "InitialCoordsAttrFunctions.hh" -#include "ParticleInitialCoordinates.hh" -#include "ParticleMacroSize.hh" +#include "mpi/orbit_mpi.hh" +#include "utils/bunch/InitialCoordsAttrFunctions.hh" +#include "orbit/ParticlesAttributes/ParticleInitialCoordinates.hh" +#include "orbit/ParticlesAttributes/ParticleMacroSize.hh" -#include "BufferStore.hh" -#include "MatrixOperations.hh" -#include "BunchTwissAnalysis.hh" +#include "utils/BufferStore.hh" +#include "utils/matrix/MatrixOperations.hh" +#include "orbit/BunchDiagnostics/BunchTwissAnalysis.hh" #include // std::sort #include // std::vector @@ -113,8 +113,8 @@ namespace OrbitUtils{ int transport_mtrx_from_init_coords(Bunch* bunch, Matrix* A_mtr, int appl_twiss_x, int appl_twiss_y, int appl_twiss_z){ int size_MPI,rank_MPI; - ORBIT_MPI_Comm_size(bunch->getMPI_Comm_Local()->comm, &size_MPI); - ORBIT_MPI_Comm_rank(bunch->getMPI_Comm_Local()->comm, &rank_MPI); + ORBIT_MPI_Comm_size(bunch->getMPI_Comm_Local(), &size_MPI); + ORBIT_MPI_Comm_rank(bunch->getMPI_Comm_Local(), &rank_MPI); if(bunch->hasParticleAttributes("ParticleInitialCoordinates") == 0){ if(rank_MPI == 0){ @@ -190,9 +190,9 @@ namespace OrbitUtils{ } } - ORBIT_MPI_Allreduce(&total_macrosize,&total_macrosize_mpi,1,MPI_DOUBLE,MPI_SUM,b_tmp->getMPI_Comm_Local()->comm); - ORBIT_MPI_Allreduce(arr_avg,arr_avg_mpi,6,MPI_DOUBLE,MPI_SUM,b_tmp->getMPI_Comm_Local()->comm); - ORBIT_MPI_Allreduce(arr_init_avg,arr_init_avg_mpi,6,MPI_DOUBLE,MPI_SUM,b_tmp->getMPI_Comm_Local()->comm); + ORBIT_MPI_Allreduce(&total_macrosize,&total_macrosize_mpi,1,MPI_DOUBLE,MPI_SUM,b_tmp->getMPI_Comm_Local()); + ORBIT_MPI_Allreduce(arr_avg,arr_avg_mpi,6,MPI_DOUBLE,MPI_SUM,b_tmp->getMPI_Comm_Local()); + ORBIT_MPI_Allreduce(arr_init_avg,arr_init_avg_mpi,6,MPI_DOUBLE,MPI_SUM,b_tmp->getMPI_Comm_Local()); total_macrosize = total_macrosize_mpi; @@ -249,7 +249,7 @@ namespace OrbitUtils{ count++; } } - ORBIT_MPI_Allreduce(mtrx_arr,mtrx_arr_mpi,36,MPI_DOUBLE,MPI_SUM,b_tmp->getMPI_Comm_Local()->comm); + ORBIT_MPI_Allreduce(mtrx_arr,mtrx_arr_mpi,36,MPI_DOUBLE,MPI_SUM,b_tmp->getMPI_Comm_Local()); count = 0; for (int i = 0; i < 6; i++){ for (int j = 0; j < 6; j++){ @@ -265,7 +265,7 @@ namespace OrbitUtils{ count++; } } - ORBIT_MPI_Allreduce(mtrx_arr,mtrx_arr_mpi,36,MPI_DOUBLE,MPI_SUM,b_tmp->getMPI_Comm_Local()->comm); + ORBIT_MPI_Allreduce(mtrx_arr,mtrx_arr_mpi,36,MPI_DOUBLE,MPI_SUM,b_tmp->getMPI_Comm_Local()); count = 0; for (int i = 0; i < 6; i++){ for (int j = 0; j < 6; j++){ diff --git a/src/utils/bunch/InitialCoordsAttrFunctions.hh b/src/utils/bunch/InitialCoordsAttrFunctions.hh index 53d77820..d06522b7 100644 --- a/src/utils/bunch/InitialCoordsAttrFunctions.hh +++ b/src/utils/bunch/InitialCoordsAttrFunctions.hh @@ -18,9 +18,9 @@ #define PARTICLES_INIT_COORDS_FUNCTIONS_H //ORBIT bunch -#include "Bunch.hh" +#include "orbit/Bunch.hh" -#include "Matrix.hh" +#include "utils/matrix/Matrix.hh" #include diff --git a/src/utils/bunch/ParticlesWithIdFunctions.cc b/src/utils/bunch/ParticlesWithIdFunctions.cc index 059f641e..f2a93729 100644 --- a/src/utils/bunch/ParticlesWithIdFunctions.cc +++ b/src/utils/bunch/ParticlesWithIdFunctions.cc @@ -23,14 +23,14 @@ // wx = exp(-(x^2+(alphax*x+betax*x')^2)/(2*(betax*emittancex)) etc. // /////////////////////////////////////////////////////////////////////////// -#include "orbit_mpi.hh" -#include "ParticlesWithIdFunctions.hh" -#include "ParticleIdNumber.hh" -#include "ParticleMacroSize.hh" +#include "mpi/orbit_mpi.hh" +#include "utils/bunch/ParticlesWithIdFunctions.hh" +#include "orbit/ParticlesAttributes/ParticleIdNumber.hh" +#include "orbit/ParticlesAttributes/ParticleMacroSize.hh" -#include "BufferStore.hh" -#include "MatrixOperations.hh" -#include "BunchTwissAnalysis.hh" +#include "utils/BufferStore.hh" +#include "utils/matrix/MatrixOperations.hh" +#include "orbit/BunchDiagnostics/BunchTwissAnalysis.hh" #include // std::sort #include // std::vector @@ -51,8 +51,8 @@ namespace OrbitUtils{ int n_parts = bunch->getSize(); if(n_parts == 0) return; int size_MPI,rank_MPI; - ORBIT_MPI_Comm_size(bunch->getMPI_Comm_Local()->comm, &size_MPI); - ORBIT_MPI_Comm_rank(bunch->getMPI_Comm_Local()->comm, &rank_MPI); + ORBIT_MPI_Comm_size(bunch->getMPI_Comm_Local(), &size_MPI); + ORBIT_MPI_Comm_rank(bunch->getMPI_Comm_Local(), &rank_MPI); if(bunch->hasParticleAttributes("ParticleIdNumber") == 0){ if(rank_MPI == 0){ std::cerr << "OrbitUtils::bunch_utils_functions::bunch_sort_id(Bunch* bunch) function"<< std::endl; @@ -99,8 +99,8 @@ namespace OrbitUtils{ */ int transport_mtrx(Bunch* bunch_in, Bunch* bunch_out, Matrix* A_mtr, int appl_twiss_x, int appl_twiss_y, int appl_twiss_z){ int size_MPI,rank_MPI; - ORBIT_MPI_Comm_size(bunch_in->getMPI_Comm_Local()->comm, &size_MPI); - ORBIT_MPI_Comm_rank(bunch_in->getMPI_Comm_Local()->comm, &rank_MPI); + ORBIT_MPI_Comm_size(bunch_in->getMPI_Comm_Local(), &size_MPI); + ORBIT_MPI_Comm_rank(bunch_in->getMPI_Comm_Local(), &rank_MPI); if(bunch_in->hasParticleAttributes("ParticleIdNumber") == 0 || bunch_out->hasParticleAttributes("ParticleIdNumber") == 0){ if(rank_MPI == 0){ std::cerr << "OrbitUtils::bunch_utils_functions::transport_mtrx(...) function"<< std::endl; @@ -117,7 +117,11 @@ namespace OrbitUtils{ } ORBIT_MPI_Finalize(); } - if(bunch_in->getMPI_Comm_Local() != bunch_out->getMPI_Comm_Local()){ + int comm_comparison = MPI_UNEQUAL; + if(ORBIT_MPI_Comm_compare(bunch_in->getMPI_Comm_Local(), + bunch_out->getMPI_Comm_Local(), + &comm_comparison) != MPI_SUCCESS || + (comm_comparison != MPI_IDENT && comm_comparison != MPI_CONGRUENT)){ if(rank_MPI == 0){ std::cerr << "OrbitUtils::bunch_utils_functions::transport_mtrx(...) function"<< std::endl; std::cerr << "Bunches In and Out have different MPI communicators!"<< std::endl; @@ -218,9 +222,9 @@ namespace OrbitUtils{ } } - ORBIT_MPI_Allreduce(&total_macrosize,&total_macrosize_mpi,1,MPI_DOUBLE,MPI_SUM,b_in_tmp->getMPI_Comm_Local()->comm); - ORBIT_MPI_Allreduce(arr_avg_in,arr_avg_in_mpi,6,MPI_DOUBLE,MPI_SUM,b_in_tmp->getMPI_Comm_Local()->comm); - ORBIT_MPI_Allreduce(arr_avg_out,arr_avg_out_mpi,6,MPI_DOUBLE,MPI_SUM,b_in_tmp->getMPI_Comm_Local()->comm); + ORBIT_MPI_Allreduce(&total_macrosize,&total_macrosize_mpi,1,MPI_DOUBLE,MPI_SUM,b_in_tmp->getMPI_Comm_Local()); + ORBIT_MPI_Allreduce(arr_avg_in,arr_avg_in_mpi,6,MPI_DOUBLE,MPI_SUM,b_in_tmp->getMPI_Comm_Local()); + ORBIT_MPI_Allreduce(arr_avg_out,arr_avg_out_mpi,6,MPI_DOUBLE,MPI_SUM,b_in_tmp->getMPI_Comm_Local()); total_macrosize = total_macrosize_mpi; @@ -276,7 +280,7 @@ namespace OrbitUtils{ count++; } } - ORBIT_MPI_Allreduce(mtrx_arr,mtrx_arr_mpi,36,MPI_DOUBLE,MPI_SUM,b_in_tmp->getMPI_Comm_Local()->comm); + ORBIT_MPI_Allreduce(mtrx_arr,mtrx_arr_mpi,36,MPI_DOUBLE,MPI_SUM,b_in_tmp->getMPI_Comm_Local()); count = 0; for (int i = 0; i < 6; i++){ for (int j = 0; j < 6; j++){ @@ -292,7 +296,7 @@ namespace OrbitUtils{ count++; } } - ORBIT_MPI_Allreduce(mtrx_arr,mtrx_arr_mpi,36,MPI_DOUBLE,MPI_SUM,b_in_tmp->getMPI_Comm_Local()->comm); + ORBIT_MPI_Allreduce(mtrx_arr,mtrx_arr_mpi,36,MPI_DOUBLE,MPI_SUM,b_in_tmp->getMPI_Comm_Local()); count = 0; for (int i = 0; i < 6; i++){ for (int j = 0; j < 6; j++){ diff --git a/src/utils/bunch/ParticlesWithIdFunctions.hh b/src/utils/bunch/ParticlesWithIdFunctions.hh index 023e5bfe..0865a418 100644 --- a/src/utils/bunch/ParticlesWithIdFunctions.hh +++ b/src/utils/bunch/ParticlesWithIdFunctions.hh @@ -20,9 +20,9 @@ #include //ORBIT bunch -#include "Bunch.hh" +#include "orbit/Bunch.hh" -#include "Matrix.hh" +#include "utils/matrix/Matrix.hh" namespace OrbitUtils{ diff --git a/src/utils/bunch/TwissFilteringFunctions.cc b/src/utils/bunch/TwissFilteringFunctions.cc index 56902267..e9afbe8e 100644 --- a/src/utils/bunch/TwissFilteringFunctions.cc +++ b/src/utils/bunch/TwissFilteringFunctions.cc @@ -15,9 +15,9 @@ // /////////////////////////////////////////////////////////////////////////// -#include "BunchTwissAnalysis.hh" +#include "orbit/BunchDiagnostics/BunchTwissAnalysis.hh" -#include "orbit_mpi.hh" +#include "mpi/orbit_mpi.hh" namespace OrbitUtils{ diff --git a/src/utils/bunch/TwissFilteringFunctions.hh b/src/utils/bunch/TwissFilteringFunctions.hh index 63d99bc4..a09fe2f9 100644 --- a/src/utils/bunch/TwissFilteringFunctions.hh +++ b/src/utils/bunch/TwissFilteringFunctions.hh @@ -21,7 +21,7 @@ #include //ORBIT bunch -#include "Bunch.hh" +#include "orbit/Bunch.hh" namespace OrbitUtils{ diff --git a/src/utils/bunch/wrap_bunch_extrema_calculator.cc b/src/utils/bunch/wrap_bunch_extrema_calculator.cc index c23ebaf8..b84052bd 100644 --- a/src/utils/bunch/wrap_bunch_extrema_calculator.cc +++ b/src/utils/bunch/wrap_bunch_extrema_calculator.cc @@ -1,13 +1,13 @@ -#include "orbit_mpi.hh" -#include "pyORBIT_Object.hh" +#include "mpi/orbit_mpi.hh" +#include "main/pyORBIT_Object.hh" -#include "wrap_utils.hh" -#include "wrap_matrix.hh" -#include "wrap_bunch.hh" +#include "utils/wrap_utils.hh" +#include "utils/matrix/wrap_matrix.hh" +#include "orbit/wrap_bunch.hh" #include -#include "BunchExtremaCalculator.hh" +#include "utils/bunch/BunchExtremaCalculator.hh" using namespace OrbitUtils; using namespace wrap_orbit_utils; diff --git a/src/utils/bunch/wrap_bunch_extrema_calculator.hh b/src/utils/bunch/wrap_bunch_extrema_calculator.hh index fcd41ae3..3358057a 100644 --- a/src/utils/bunch/wrap_bunch_extrema_calculator.hh +++ b/src/utils/bunch/wrap_bunch_extrema_calculator.hh @@ -1,7 +1,7 @@ #ifndef WRAP_UTILS_BUNCH_H #define WRAP_UTILS_BUNCH_H -#include "Python.h" +#include #ifdef __cplusplus extern "C" { diff --git a/src/utils/bunch/wrap_bunch_utils_functions.cc b/src/utils/bunch/wrap_bunch_utils_functions.cc index 0e29cc67..c6666b43 100644 --- a/src/utils/bunch/wrap_bunch_utils_functions.cc +++ b/src/utils/bunch/wrap_bunch_utils_functions.cc @@ -1,14 +1,14 @@ -#include "orbit_mpi.hh" -#include "pyORBIT_Object.hh" +#include "mpi/orbit_mpi.hh" +#include "main/pyORBIT_Object.hh" #include -#include "wrap_bunch.hh" -#include "wrap_utils.hh" +#include "orbit/wrap_bunch.hh" +#include "utils/wrap_utils.hh" -#include "ParticlesWithIdFunctions.hh" -#include "TwissFilteringFunctions.hh" -#include "InitialCoordsAttrFunctions.hh" +#include "utils/bunch/ParticlesWithIdFunctions.hh" +#include "utils/bunch/TwissFilteringFunctions.hh" +#include "utils/bunch/InitialCoordsAttrFunctions.hh" using namespace OrbitUtils; diff --git a/src/utils/bunch/wrap_bunch_utils_functions.hh b/src/utils/bunch/wrap_bunch_utils_functions.hh index 2eeb0f3d..b4cf027f 100644 --- a/src/utils/bunch/wrap_bunch_utils_functions.hh +++ b/src/utils/bunch/wrap_bunch_utils_functions.hh @@ -1,7 +1,7 @@ #ifndef WRAP_UTILS_BUNCH_FUNCTIONS_H #define WRAP_UTILS_BUNCH_FUNCTIONS_H -#include "Python.h" +#include #ifdef __cplusplus extern "C" { diff --git a/src/utils/ellipticalint/elliptint.hh b/src/utils/ellipticalint/elliptint.hh index 9d767714..46f72e73 100644 --- a/src/utils/ellipticalint/elliptint.hh +++ b/src/utils/ellipticalint/elliptint.hh @@ -22,6 +22,8 @@ Chapter 6. Special Functions elliptint.hh **/ +#include +#include #include #include @@ -36,10 +38,10 @@ namespace EllipticalIntegrals{ static const double ERRTOL=0.0012, THIRD=1.0/3.0, C1=0.3, C2=1.0/7.0, C3=0.375, C4=9.0/22.0; static const double TINY=5.0*std::numeric_limits::min(), - BIG=0.2*std::numeric_limits::max(), COMP1=2.236/sqrt(TINY), + BIG=0.2*std::numeric_limits::max(), COMP1=2.236/std::sqrt(TINY), COMP2=(TINY*BIG)*(TINY*BIG)/25.0; double alamb,ave,s,w,xt,yt; - if (x < 0.0 || y == 0.0 || (x+fabs(y)) < TINY || (x+fabs(y)) > BIG || + if (x < 0.0 || y == 0.0 || (x+std::fabs(y)) < TINY || (x+std::fabs(y)) > BIG || (y<-COMP1 && x > 0.0 && x < COMP2)) throw("invalid arguments in rc"); if (y > 0.0) { xt=x; @@ -48,16 +50,16 @@ namespace EllipticalIntegrals{ } else { xt=x-y; yt= -y; - w=sqrt(x)/sqrt(xt); + w=std::sqrt(x)/std::sqrt(xt); } do { - alamb=2.0*sqrt(xt)*sqrt(yt)+yt; + alamb=2.0*std::sqrt(xt)*std::sqrt(yt)+yt; xt=0.25*(xt+alamb); yt=0.25*(yt+alamb); ave=THIRD*(xt+yt+yt); s=(yt-ave)/ave; - } while (fabs(s) > ERRTOL); - return w*(1.0+s*s*(C1+s*(C2+s*(C3+s*C4))))/sqrt(ave); + } while (std::fabs(s) > ERRTOL); + return w*(1.0+s*s*(C1+s*(C2+s*(C3+s*C4))))/std::sqrt(ave); } /* @@ -75,9 +77,9 @@ namespace EllipticalIntegrals{ yt=y; zt=z; do { - sqrtx=sqrt(xt); - sqrty=sqrt(yt); - sqrtz=sqrt(zt); + sqrtx=std::sqrt(xt); + sqrty=std::sqrt(yt); + sqrtz=std::sqrt(zt); alamb=sqrtx*(sqrty+sqrtz)+sqrty*sqrtz; xt=0.25*(xt+alamb); yt=0.25*(yt+alamb); @@ -86,10 +88,10 @@ namespace EllipticalIntegrals{ delx=(ave-xt)/ave; dely=(ave-yt)/ave; delz=(ave-zt)/ave; - } while (std::max(std::max(fabs(delx),fabs(dely)),fabs(delz)) > ERRTOL); + } while (std::max(std::max(std::fabs(delx),std::fabs(dely)),std::fabs(delz)) > ERRTOL); e2=delx*dely-delz*delz; e3=delx*dely*delz; - return (1.0+(C1*e2-C2-C3*e3)*e2+C4*e3)/sqrt(ave); + return (1.0+(C1*e2-C2-C3*e3)*e2+C4*e3)/std::sqrt(ave); } /* @@ -100,8 +102,8 @@ namespace EllipticalIntegrals{ double rd(const double x, const double y, const double z) { static const double ERRTOL=0.0015, C1=3.0/14.0, C2=1.0/6.0, C3=9.0/22.0, C4=3.0/26.0, C5=0.25*C3, C6=1.5*C4; - static const double TINY=2.0*pow(std::numeric_limits::max(),-2./3.), - BIG=0.1*ERRTOL*pow(std::numeric_limits::min(),-2./3.); + static const double TINY=2.0*std::pow(std::numeric_limits::max(),-2./3.), + BIG=0.1*ERRTOL*std::pow(std::numeric_limits::min(),-2./3.); double alamb,ave,delx,dely,delz,ea,eb,ec,ed,ee,fac,sqrtx,sqrty, sqrtz,sum,xt,yt,zt; if (std::min(x,y) < 0.0 || std::min(x+y,z) < TINY || std::max(std::max(x,y),z) > BIG) @@ -112,9 +114,9 @@ namespace EllipticalIntegrals{ sum=0.0; fac=1.0; do { - sqrtx=sqrt(xt); - sqrty=sqrt(yt); - sqrtz=sqrt(zt); + sqrtx=std::sqrt(xt); + sqrty=std::sqrt(yt); + sqrtz=std::sqrt(zt); alamb=sqrtx*(sqrty+sqrtz)+sqrty*sqrtz; sum += fac/(sqrtz*(zt+alamb)); fac=0.25*fac; @@ -125,14 +127,14 @@ namespace EllipticalIntegrals{ delx=(ave-xt)/ave; dely=(ave-yt)/ave; delz=(ave-zt)/ave; - } while (std::max(std::max(abs(delx),abs(dely)),abs(delz)) > ERRTOL); + } while (std::max(std::max(std::abs(delx),std::abs(dely)),std::abs(delz)) > ERRTOL); ea=delx*dely; eb=delz*delz; ec=ea-eb; ed=ea-6.0*eb; ee=ed+ec+ec; return 3.0*sum+fac*(1.0+ed*(-C1+C5*ed-C6*delz*ee) - +delz*(C2*ee+delz*(-C3*ec+delz*C4*ea)))/(ave*sqrt(ave)); + +delz*(C2*ee+delz*(-C3*ec+delz*C4*ea)))/(ave*std::sqrt(ave)); } /* @@ -143,12 +145,12 @@ namespace EllipticalIntegrals{ double rj(const double x, const double y, const double z, const double p) { static const double ERRTOL=0.0015, C1=3.0/14.0, C2=1.0/3.0, C3=3.0/22.0, C4=3.0/26.0, C5=0.75*C3, C6=1.5*C4, C7=0.5*C2, C8=C3+C3; - static const double TINY=pow(5.0*std::numeric_limits::min(),1./3.), - BIG=0.3*pow(0.2*std::numeric_limits::max(),1./3.); + static const double TINY=std::pow(5.0*std::numeric_limits::min(),1./3.), + BIG=0.3*std::pow(0.2*std::numeric_limits::max(),1./3.); double a,alamb,alpha,ans,ave,b,beta,delp,delx,dely,delz,ea,eb,ec,ed,ee, fac,pt,rcx,rho,sqrtx,sqrty,sqrtz,sum,tau,xt,yt,zt; - if (std::min(std::min(x,y),z) < 0.0 || std::min(std::min(x+y,x+z),std::min(y+z,fabs(p))) < TINY - || std::max(std::max(x,y),std::max(z,fabs(p))) > BIG) throw("invalid arguments in rj"); + if (std::min(std::min(x,y),z) < 0.0 || std::min(std::min(x+y,x+z),std::min(y+z,std::fabs(p))) < TINY + || std::max(std::max(x,y),std::max(z,std::fabs(p))) > BIG) throw("invalid arguments in rj"); sum=0.0; fac=1.0; if (p > 0.0) { @@ -168,12 +170,12 @@ namespace EllipticalIntegrals{ rcx=rc(rho,tau); } do { - sqrtx=sqrt(xt); - sqrty=sqrt(yt); - sqrtz=sqrt(zt); + sqrtx=std::sqrt(xt); + sqrty=std::sqrt(yt); + sqrtz=std::sqrt(zt); alamb=sqrtx*(sqrty+sqrtz)+sqrty*sqrtz; - alpha=pow((pt*(sqrtx+sqrty+sqrtz)+sqrtx*sqrty*sqrtz),2); - beta=pt*pow((pt+alamb),2); + alpha=std::pow((pt*(sqrtx+sqrty+sqrtz)+sqrtx*sqrty*sqrtz),2); + beta=pt*std::pow((pt+alamb),2); sum += fac*rc(alpha,beta); fac=0.25*fac; xt=0.25*(xt+alamb); @@ -185,15 +187,15 @@ namespace EllipticalIntegrals{ dely=(ave-yt)/ave; delz=(ave-zt)/ave; delp=(ave-pt)/ave; - } while (std::max(std::max(fabs(delx),fabs(dely)), - std::max(fabs(delz),fabs(delp))) > ERRTOL); + } while (std::max(std::max(std::fabs(delx),std::fabs(dely)), + std::max(std::fabs(delz),std::fabs(delp))) > ERRTOL); ea=delx*(dely+delz)+dely*delz; eb=delx*dely*delz; ec=delp*delp; ed=ea-3.0*ec; ee=eb+2.0*delp*(ea-ec); ans=3.0*sum+fac*(1.0+ed*(-C1+C5*ed-C6*ee)+eb*(C7+delp*(-C8+delp*C4)) - +delp*ea*(C2-delp*C3)-C2*delp*ec)/(ave*sqrt(ave)); + +delp*ea*(C2-delp*C3)-C2*delp*ec)/(ave*std::sqrt(ave)); if (p <= 0.0) ans=a*(b*ans+3.0*(rcx-rf(xt,yt,zt))); return ans; } @@ -201,37 +203,37 @@ namespace EllipticalIntegrals{ /* Legendre elliptic integral of the first kind F(phi,ak), evaluated using Carlson’s function RF . - The argument ranges are 0<= phi <= pi/2, 0 <= k*sin(phi) <= 1. + The argument ranges are 0<= phi <= pi/2, 0 <= k*std::sin(phi) <= 1. **/ double ellf(const double phi, const double ak) { - double s=sin(phi); - return s*rf(pow(cos(phi),2),(1.0-s*ak)*(1.0+s*ak),1.0); + double s=std::sin(phi); + return s*rf(std::pow(cos(phi),2),(1.0-s*ak)*(1.0+s*ak),1.0); } /* Legendre elliptic integral of the second kind E(phi,ak), evaluated using Carlson’s function RF and RD. - The argument ranges are 0<= phi <= pi/2, 0 <= k*sin(phi) <= 1. + The argument ranges are 0<= phi <= pi/2, 0 <= k*std::sin(phi) <= 1. **/ double elle(const double phi, const double ak) { double cc,q,s; - s=sin(phi); - cc=pow(cos(phi),2); + s=std::sin(phi); + cc=std::pow(cos(phi),2); q=(1.0-s*ak)*(1.0+s*ak); - return s*(rf(cc,q,1.0)-(pow(s*ak,2))*rd(cc,q,1.0)/3.0); + return s*(rf(cc,q,1.0)-(std::pow(s*ak,2))*rd(cc,q,1.0)/3.0); } /* Legendre elliptic integral of the third kind P(phi,ak), evaluated using Carlson’s function RJ and RD. (Note that the sign convention on n is opposite that of Abramowitz and Stegun.) - The argument ranges are 0<= phi <= pi/2, 0 <= k*sin(phi) <= 1. + The argument ranges are 0<= phi <= pi/2, 0 <= k*std::sin(phi) <= 1. **/ double ellpi(const double phi, const double en, const double ak) { double cc,enss,q,s; - s=sin(phi); + s=std::sin(phi); enss=en*s*s; - cc=pow(cos(phi),2); + cc=std::pow(cos(phi),2); q=(1.0-s*ak)*(1.0+s*ak); return s*(rf(cc,q,1.0)-enss*rj(cc,q,1.0,1.0+enss)/3.0); } diff --git a/src/utils/field_sources/DipoleFieldSource.cc b/src/utils/field_sources/DipoleFieldSource.cc index 7cbc091e..f73f1dcb 100644 --- a/src/utils/field_sources/DipoleFieldSource.cc +++ b/src/utils/field_sources/DipoleFieldSource.cc @@ -17,16 +17,16 @@ // /////////////////////////////////////////////////////////////////////////// -#include "orbit_mpi.hh" -#include "BufferStore.hh" +#include "mpi/orbit_mpi.hh" +#include "utils/BufferStore.hh" #include #include #include #include -#include "ShiftedFieldSource.hh" -#include "DipoleFieldSource.hh" +#include "utils/field_sources/ShiftedFieldSource.hh" +#include "utils/field_sources/DipoleFieldSource.hh" using namespace OrbitUtils; diff --git a/src/utils/field_sources/DipoleFieldSource.hh b/src/utils/field_sources/DipoleFieldSource.hh index c95553f1..7fc73dfb 100644 --- a/src/utils/field_sources/DipoleFieldSource.hh +++ b/src/utils/field_sources/DipoleFieldSource.hh @@ -19,8 +19,8 @@ #ifndef DIPOLE_FIELD_SOURCE_H #define DIPOLE_FIELD_SOURCE_H -#include "Grid3D.hh" -#include "ShiftedFieldSource.hh" +#include "spacecharge/Grid3D.hh" +#include "utils/field_sources/ShiftedFieldSource.hh" namespace OrbitUtils{ diff --git a/src/utils/field_sources/LoopFieldSource.cc b/src/utils/field_sources/LoopFieldSource.cc index 0263c9f9..da78cbc2 100644 --- a/src/utils/field_sources/LoopFieldSource.cc +++ b/src/utils/field_sources/LoopFieldSource.cc @@ -20,19 +20,19 @@ // /////////////////////////////////////////////////////////////////////////// -#include "orbit_mpi.hh" -#include "BufferStore.hh" +#include "mpi/orbit_mpi.hh" +#include "utils/BufferStore.hh" #include #include #include #include -#include "ShiftedFieldSource.hh" -#include "LoopFieldSource.hh" -#include "elliptint.hh" +#include "utils/field_sources/ShiftedFieldSource.hh" +#include "utils/field_sources/LoopFieldSource.hh" +#include "utils/ellipticalint/elliptint.hh" -#include "OrbitConst.hh" +#include "orbit/OrbitConst.hh" using namespace OrbitUtils; diff --git a/src/utils/field_sources/LoopFieldSource.hh b/src/utils/field_sources/LoopFieldSource.hh index 194d7443..b155c476 100644 --- a/src/utils/field_sources/LoopFieldSource.hh +++ b/src/utils/field_sources/LoopFieldSource.hh @@ -23,7 +23,7 @@ #ifndef CURRENT_LOOP_FIELD_SOURCE_H #define CURRENT_LOOP_FIELD_SOURCE_H -#include "ShiftedFieldSource.hh" +#include "utils/field_sources/ShiftedFieldSource.hh" namespace OrbitUtils{ diff --git a/src/utils/field_sources/MagnetFieldSourceGrid3D.cc b/src/utils/field_sources/MagnetFieldSourceGrid3D.cc index f6199526..12c8aaf0 100644 --- a/src/utils/field_sources/MagnetFieldSourceGrid3D.cc +++ b/src/utils/field_sources/MagnetFieldSourceGrid3D.cc @@ -22,16 +22,16 @@ // /////////////////////////////////////////////////////////////////////////// -#include "orbit_mpi.hh" -#include "BufferStore.hh" +#include "mpi/orbit_mpi.hh" +#include "utils/BufferStore.hh" #include #include #include #include -#include "ShiftedFieldSource.hh" -#include "MagnetFieldSourceGrid3D.hh" +#include "utils/field_sources/ShiftedFieldSource.hh" +#include "utils/field_sources/MagnetFieldSourceGrid3D.hh" using namespace OrbitUtils; @@ -85,28 +85,6 @@ MagnetFieldSourceGrid3D::MagnetFieldSourceGrid3D(Grid3D* BxGrid_In, Grid3D* ByGr MagnetFieldSourceGrid3D::~MagnetFieldSourceGrid3D() { - - if(BxGrid->getPyWrapper() == NULL){ - delete BxGrid; - } - else { - Py_XDECREF(BxGrid->getPyWrapper()); - } - - if(ByGrid->getPyWrapper() == NULL){ - delete ByGrid; - } - else { - Py_XDECREF(ByGrid->getPyWrapper()); - } - - if(BzGrid->getPyWrapper() == NULL){ - delete BzGrid; - } - else { - Py_XDECREF(BzGrid->getPyWrapper()); - } - for(int i = 0; i < 8; i++){ delete [] field_sign_arr[i]; } diff --git a/src/utils/field_sources/MagnetFieldSourceGrid3D.hh b/src/utils/field_sources/MagnetFieldSourceGrid3D.hh index b55925fc..f3e239f1 100644 --- a/src/utils/field_sources/MagnetFieldSourceGrid3D.hh +++ b/src/utils/field_sources/MagnetFieldSourceGrid3D.hh @@ -25,8 +25,8 @@ #ifndef MAGNET_FIELD_SOURCE_GRID3D_H #define MAGNET_FIELD_SOURCE_GRID3D_H -#include "Grid3D.hh" -#include "ShiftedFieldSource.hh" +#include "spacecharge/Grid3D.hh" +#include "utils/field_sources/ShiftedFieldSource.hh" namespace OrbitUtils{ @@ -36,7 +36,7 @@ namespace OrbitUtils{ { public: - /** Constructor. */ + /** Constructor. The caller retains ownership of the grids. */ MagnetFieldSourceGrid3D(Grid3D* BxGrid, Grid3D* ByGrid, Grid3D* BzGrid); /** Destructor */ diff --git a/src/utils/field_sources/QuadFieldSource.cc b/src/utils/field_sources/QuadFieldSource.cc index dcd2cb00..c89e9bed 100644 --- a/src/utils/field_sources/QuadFieldSource.cc +++ b/src/utils/field_sources/QuadFieldSource.cc @@ -18,16 +18,16 @@ // /////////////////////////////////////////////////////////////////////////// -#include "orbit_mpi.hh" -#include "BufferStore.hh" +#include "mpi/orbit_mpi.hh" +#include "utils/BufferStore.hh" #include #include #include #include -#include "ShiftedFieldSource.hh" -#include "QuadFieldSource.hh" +#include "utils/field_sources/ShiftedFieldSource.hh" +#include "utils/field_sources/QuadFieldSource.hh" using namespace OrbitUtils; diff --git a/src/utils/field_sources/QuadFieldSource.hh b/src/utils/field_sources/QuadFieldSource.hh index 00eab099..8a8a2dd3 100644 --- a/src/utils/field_sources/QuadFieldSource.hh +++ b/src/utils/field_sources/QuadFieldSource.hh @@ -21,8 +21,8 @@ #ifndef QUAD_FIELD_SOURCE_H #define QUAD_FIELD_SOURCE_H -#include "Grid3D.hh" -#include "ShiftedFieldSource.hh" +#include "spacecharge/Grid3D.hh" +#include "utils/field_sources/ShiftedFieldSource.hh" namespace OrbitUtils{ diff --git a/src/utils/field_sources/ShiftedFieldSource.cc b/src/utils/field_sources/ShiftedFieldSource.cc index 3fe1bb80..842fad81 100644 --- a/src/utils/field_sources/ShiftedFieldSource.cc +++ b/src/utils/field_sources/ShiftedFieldSource.cc @@ -23,12 +23,10 @@ // the external coordinate system by coordTransformBack (3x3) matrix. // /////////////////////////////////////////////////////////////////////////// -#include "Python.h" +#include "mpi/orbit_mpi.hh" -#include "orbit_mpi.hh" - -#include "ShiftedFieldSource.hh" -#include "MatrixOperations.hh" +#include "utils/field_sources/ShiftedFieldSource.hh" +#include "utils/matrix/MatrixOperations.hh" using namespace OrbitUtils; @@ -36,8 +34,9 @@ using namespace OrbitUtils; ShiftedFieldSource::ShiftedFieldSource(): BaseFieldSource() { - coordTransformM4x4 = new Matrix(4,4); - coordTransformM3x3 = new Matrix(3,3); + ownedCoordTransformM4x4.reset(new Matrix(4,4)); + coordTransformM4x4 = ownedCoordTransformM4x4.get(); + coordTransformM3x3.reset(new Matrix(3,3)); coordTransformM4x4->unit(); coordTransformM3x3->unit(); @@ -58,15 +57,6 @@ ShiftedFieldSource::ShiftedFieldSource(): BaseFieldSource() /** Destructor */ ShiftedFieldSource::~ShiftedFieldSource() { - if(coordTransformM4x4->getPyWrapper() == NULL){ - delete coordTransformM4x4; - } - else { - Py_XDECREF(coordTransformM4x4->getPyWrapper()); - } - - delete coordTransformM3x3; - delete coordVectExt; delete coordVectInn; @@ -101,7 +91,7 @@ void ShiftedFieldSource::getElectricMagneticField( innArr[1] = E_y; innArr[2] = E_z; - MatrixOperations::mult(coordTransformM3x3,fieldVectInn,fieldVectExt); + MatrixOperations::mult(coordTransformM3x3.get(),fieldVectInn,fieldVectExt); extArr = fieldVectExt->getArray(); E_x = extArr[0]; @@ -115,7 +105,7 @@ void ShiftedFieldSource::getElectricMagneticField( innArr[1] = H_y; innArr[2] = H_z; - MatrixOperations::mult(coordTransformM3x3,fieldVectInn,fieldVectExt); + MatrixOperations::mult(coordTransformM3x3.get(),fieldVectInn,fieldVectExt); extArr = fieldVectExt->getArray(); H_x = extArr[0]; @@ -148,21 +138,11 @@ Matrix* ShiftedFieldSource::getCoordsTransformMatrix() */ void ShiftedFieldSource::setCoordsTransformMatrix(Matrix* coordTransformM4x4_In) { - if(coordTransformM4x4->getPyWrapper() == NULL){ - delete coordTransformM4x4; - } - else { - Py_XDECREF(coordTransformM4x4->getPyWrapper()); - } - + ownedCoordTransformM4x4.reset(); coordTransformM4x4 = coordTransformM4x4_In; - if(coordTransformM4x4->getPyWrapper() != NULL){ - Py_INCREF(coordTransformM4x4->getPyWrapper()); - } - - for(int ind_x; ind_x < 3; ind_x++){ - for(int ind_y; ind_y < 3; ind_y++){ + for(int ind_x = 0; ind_x < 3; ind_x++){ + for(int ind_y = 0; ind_y < 3; ind_y++){ coordTransformM3x3->getArray()[ind_x][ind_y] = coordTransformM4x4->getArray()[ind_x][ind_y]; } } diff --git a/src/utils/field_sources/ShiftedFieldSource.hh b/src/utils/field_sources/ShiftedFieldSource.hh index 6aaed8ac..bbaa5274 100644 --- a/src/utils/field_sources/ShiftedFieldSource.hh +++ b/src/utils/field_sources/ShiftedFieldSource.hh @@ -27,16 +27,17 @@ #ifndef SHIFTED_FIELD_SOURCE_H #define SHIFTED_FIELD_SOURCE_H -#include "orbit_mpi.hh" +#include "mpi/orbit_mpi.hh" #include #include #include #include +#include -#include "BaseFieldSource.hh" -#include "Matrix.hh" -#include "PhaseVector.hh" +#include "utils/BaseFieldSource.hh" +#include "utils/matrix/Matrix.hh" +#include "utils/matrix/PhaseVector.hh" namespace OrbitUtils{ @@ -80,6 +81,7 @@ namespace OrbitUtils{ /** Sets coordinates transformation matrix 4x4. It includes rotation 3x3 matrix and origin shift. + The caller retains ownership of the matrix. */ void setCoordsTransformMatrix(Matrix* coordTransformM4x4); @@ -87,6 +89,7 @@ namespace OrbitUtils{ protected: //Matrix for transformation from external to shifted system + std::unique_ptr ownedCoordTransformM4x4; Matrix* coordTransformM4x4; //----------------------------------- @@ -103,7 +106,7 @@ namespace OrbitUtils{ //Matrix for transformation E and B from shifted to external system - Matrix* coordTransformM3x3; + std::unique_ptr coordTransformM3x3; }; }; diff --git a/src/utils/field_sources/wrap_dipole_field_source.cc b/src/utils/field_sources/wrap_dipole_field_source.cc index 07ba696e..0ea8dd04 100644 --- a/src/utils/field_sources/wrap_dipole_field_source.cc +++ b/src/utils/field_sources/wrap_dipole_field_source.cc @@ -1,9 +1,9 @@ -#include "orbit_mpi.hh" -#include "pyORBIT_Object.hh" -#include "wrap_spacecharge.hh" +#include "mpi/orbit_mpi.hh" +#include "main/pyORBIT_Object.hh" +#include "spacecharge/wrap_spacecharge.hh" -#include "wrap_utils.hh" -#include "DipoleFieldSource.hh" +#include "utils/wrap_utils.hh" +#include "utils/field_sources/DipoleFieldSource.hh" #include @@ -12,6 +12,12 @@ using namespace wrap_orbit_utils; namespace wrap_dipole_field_source{ + typedef struct { + PyObject_HEAD + void* cpp_obj; + PyObject* transform; + } pyORBIT_DipoleFieldSource; + void error(const char* msg){ ORBIT_MPI_Finalize(msg); } #ifdef __cplusplus @@ -25,17 +31,18 @@ extern "C" { //It never will be called directly static PyObject* DipoleFieldSource_new(PyTypeObject *type, PyObject *args, PyObject *kwds) { - pyORBIT_Object* self; - self = (pyORBIT_Object *) type->tp_alloc(type, 0); + pyORBIT_DipoleFieldSource* self; + self = (pyORBIT_DipoleFieldSource *) type->tp_alloc(type, 0); self->cpp_obj = NULL; + self->transform = NULL; return (PyObject *) self; } //initializator for python DipoleFieldSource class //this is implementation of the __init__ method - static int DipoleFieldSource_init(pyORBIT_Object *self, PyObject *args, PyObject *kwds){ + static int DipoleFieldSource_init(pyORBIT_DipoleFieldSource *self, PyObject *args, PyObject *kwds){ self->cpp_obj = new DipoleFieldSource(); - ((DipoleFieldSource*) self->cpp_obj)->setPyWrapper((PyObject*) self); + pyorbit::registerPyWrapper(self->cpp_obj, (PyObject*) self); return 0; } @@ -85,6 +92,7 @@ extern "C" { /** Sets / Returns the coordinates transformation matrix 4x4 from external to inner system */ static PyObject* DipoleFieldSource_transormfMatrix(PyObject *self, PyObject *args){ + pyORBIT_DipoleFieldSource* source = (pyORBIT_DipoleFieldSource*) self; DipoleFieldSource* cpp_fieldSource = (DipoleFieldSource*)((pyORBIT_Object*) self)->cpp_obj; int nArgs = PyTuple_Size(args); PyObject* pyMatrix; @@ -101,25 +109,27 @@ extern "C" { if(cpp_matrix->rows() != 4 || cpp_matrix->columns() != 4){ error("DipoleFieldSource.transormfMatrix(Matrix) - Matrix is not 4x4."); } - // the Py_INCREF(pyMatrix) call will be performed inside setCoordsTransformMatrix(...) method cpp_fieldSource->setCoordsTransformMatrix(cpp_matrix); + Py_INCREF(pyMatrix); + Py_XDECREF(source->transform); + source->transform = pyMatrix; Py_INCREF(Py_None); return Py_None; } - cpp_matrix = cpp_fieldSource->getCoordsTransformMatrix(); - pyMatrix = (PyObject*) ((pyORBIT_Object*) cpp_matrix->getPyWrapper()); - if(pyMatrix == NULL){ + if(source->transform == NULL){ error("DipoleFieldSource.transormfMatrix() - cannot return Matrix 4x4. You have to assign it first."); } - Py_INCREF(pyMatrix); - return pyMatrix; + Py_INCREF(source->transform); + return source->transform; } //----------------------------------------------------- //destructor for python DipoleFieldSource class (__del__ method). //----------------------------------------------------- - static void DipoleFieldSource_del(pyORBIT_Object* self){ + static void DipoleFieldSource_del(pyORBIT_DipoleFieldSource* self){ + pyorbit::unregisterPyWrapper(self->cpp_obj, (PyObject*) self); delete ((DipoleFieldSource*)self->cpp_obj); + Py_CLEAR(self->transform); self->ob_base.ob_type->tp_free((PyObject*)self); } @@ -143,7 +153,7 @@ extern "C" { static PyTypeObject pyORBIT_DipoleFieldSource_Type = { PyVarObject_HEAD_INIT(NULL, 0) "DipoleFieldSource", /*tp_name*/ - sizeof(pyORBIT_Object), /*tp_basicsize*/ + sizeof(pyORBIT_DipoleFieldSource), /*tp_basicsize*/ 0, /*tp_itemsize*/ (destructor) DipoleFieldSource_del , /*tp_dealloc*/ 0, /*tp_print*/ diff --git a/src/utils/field_sources/wrap_dipole_field_source.hh b/src/utils/field_sources/wrap_dipole_field_source.hh index b7050bb5..b39db8d6 100644 --- a/src/utils/field_sources/wrap_dipole_field_source.hh +++ b/src/utils/field_sources/wrap_dipole_field_source.hh @@ -1,7 +1,7 @@ #ifndef WRAP_DIPOLE_FIELD_SOURCE_H #define WRAP_DIPOLE_FIELD_SOURCE_H -#include "Python.h" +#include #ifdef __cplusplus extern "C" { diff --git a/src/utils/field_sources/wrap_field_sources_module.cc b/src/utils/field_sources/wrap_field_sources_module.cc index a1973289..309e3c94 100644 --- a/src/utils/field_sources/wrap_field_sources_module.cc +++ b/src/utils/field_sources/wrap_field_sources_module.cc @@ -1,15 +1,15 @@ -#include "orbit_mpi.hh" -#include "pyORBIT_Object.hh" +#include "mpi/orbit_mpi.hh" +#include "main/pyORBIT_Object.hh" #include -#include "wrap_bunch.hh" -#include "wrap_utils.hh" +#include "orbit/wrap_bunch.hh" +#include "utils/wrap_utils.hh" -#include "wrap_magnetic_field_source_grid3d.hh" -#include "wrap_quad_field_source.hh" -#include "wrap_dipole_field_source.hh" -#include "wrap_loop_field_source.hh" +#include "utils/field_sources/wrap_magnetic_field_source_grid3d.hh" +#include "utils/field_sources/wrap_quad_field_source.hh" +#include "utils/field_sources/wrap_dipole_field_source.hh" +#include "utils/field_sources/wrap_loop_field_source.hh" namespace wrap_field_sources_module{ diff --git a/src/utils/field_sources/wrap_field_sources_module.hh b/src/utils/field_sources/wrap_field_sources_module.hh index 008d89c0..e56441c3 100644 --- a/src/utils/field_sources/wrap_field_sources_module.hh +++ b/src/utils/field_sources/wrap_field_sources_module.hh @@ -1,7 +1,7 @@ #ifndef WRAP_FIELD_SOURCES_MODULE_H #define WRAP_FIELD_SOURCES_MODULE_H -#include "Python.h" +#include #ifdef __cplusplus extern "C" { diff --git a/src/utils/field_sources/wrap_loop_field_source.cc b/src/utils/field_sources/wrap_loop_field_source.cc index a3c638be..6443014a 100644 --- a/src/utils/field_sources/wrap_loop_field_source.cc +++ b/src/utils/field_sources/wrap_loop_field_source.cc @@ -1,9 +1,9 @@ -#include "orbit_mpi.hh" -#include "pyORBIT_Object.hh" -#include "wrap_spacecharge.hh" +#include "mpi/orbit_mpi.hh" +#include "main/pyORBIT_Object.hh" +#include "spacecharge/wrap_spacecharge.hh" -#include "wrap_utils.hh" -#include "LoopFieldSource.hh" +#include "utils/wrap_utils.hh" +#include "utils/field_sources/LoopFieldSource.hh" #include @@ -12,6 +12,12 @@ using namespace wrap_orbit_utils; namespace wrap_loop_field_source{ + typedef struct { + PyObject_HEAD + void* cpp_obj; + PyObject* transform; + } pyORBIT_LoopFieldSource; + void error(const char* msg){ ORBIT_MPI_Finalize(msg); } #ifdef __cplusplus @@ -25,17 +31,18 @@ extern "C" { //It never will be called directly static PyObject* LoopFieldSource_new(PyTypeObject *type, PyObject *args, PyObject *kwds) { - pyORBIT_Object* self; - self = (pyORBIT_Object *) type->tp_alloc(type, 0); + pyORBIT_LoopFieldSource* self; + self = (pyORBIT_LoopFieldSource *) type->tp_alloc(type, 0); self->cpp_obj = NULL; + self->transform = NULL; return (PyObject *) self; } //initializator for python LoopFieldSource class //this is implementation of the __init__ method - static int LoopFieldSource_init(pyORBIT_Object *self, PyObject *args, PyObject *kwds){ + static int LoopFieldSource_init(pyORBIT_LoopFieldSource *self, PyObject *args, PyObject *kwds){ self->cpp_obj = new LoopFieldSource(); - ((LoopFieldSource*) self->cpp_obj)->setPyWrapper((PyObject*) self); + pyorbit::registerPyWrapper(self->cpp_obj, (PyObject*) self); return 0; } @@ -115,6 +122,7 @@ extern "C" { /** Sets / Returns the coordinates transformation matrix 4x4 from external to inner system */ static PyObject* LoopFieldSource_transormfMatrix(PyObject *self, PyObject *args){ + pyORBIT_LoopFieldSource* source = (pyORBIT_LoopFieldSource*) self; LoopFieldSource* cpp_fieldSource = (LoopFieldSource*)((pyORBIT_Object*) self)->cpp_obj; int nArgs = PyTuple_Size(args); PyObject* pyMatrix; @@ -131,25 +139,27 @@ extern "C" { if(cpp_matrix->rows() != 4 || cpp_matrix->columns() != 4){ error("LoopFieldSource.transormfMatrix(Matrix) - Matrix is not 4x4."); } - // the Py_INCREF(pyMatrix) call will be performed inside setCoordsTransformMatrix(...) method cpp_fieldSource->setCoordsTransformMatrix(cpp_matrix); + Py_INCREF(pyMatrix); + Py_XDECREF(source->transform); + source->transform = pyMatrix; Py_INCREF(Py_None); return Py_None; } - cpp_matrix = cpp_fieldSource->getCoordsTransformMatrix(); - pyMatrix = (PyObject*) ((pyORBIT_Object*) cpp_matrix->getPyWrapper()); - if(pyMatrix == NULL){ + if(source->transform == NULL){ error("LoopFieldSource.transormfMatrix() - cannot return Matrix 4x4. You have to assign it first."); } - Py_INCREF(pyMatrix); - return pyMatrix; + Py_INCREF(source->transform); + return source->transform; } //----------------------------------------------------- //destructor for python LoopFieldSource class (__del__ method). //----------------------------------------------------- - static void LoopFieldSource_del(pyORBIT_Object* self){ + static void LoopFieldSource_del(pyORBIT_LoopFieldSource* self){ + pyorbit::unregisterPyWrapper(self->cpp_obj, (PyObject*) self); delete ((LoopFieldSource*)self->cpp_obj); + Py_CLEAR(self->transform); self->ob_base.ob_type->tp_free((PyObject*)self); } @@ -175,7 +185,7 @@ extern "C" { static PyTypeObject pyORBIT_LoopFieldSource_Type = { PyVarObject_HEAD_INIT(NULL, 0) "LoopFieldSource", /*tp_name*/ - sizeof(pyORBIT_Object), /*tp_basicsize*/ + sizeof(pyORBIT_LoopFieldSource), /*tp_basicsize*/ 0, /*tp_itemsize*/ (destructor) LoopFieldSource_del , /*tp_dealloc*/ 0, /*tp_print*/ diff --git a/src/utils/field_sources/wrap_loop_field_source.hh b/src/utils/field_sources/wrap_loop_field_source.hh index d09e8485..39f96d4b 100644 --- a/src/utils/field_sources/wrap_loop_field_source.hh +++ b/src/utils/field_sources/wrap_loop_field_source.hh @@ -1,7 +1,7 @@ #ifndef WRAP_LOOP_FIELD_SOURCE_H #define WRAP_LOOP_FIELD_SOURCE_H -#include "Python.h" +#include #ifdef __cplusplus extern "C" { diff --git a/src/utils/field_sources/wrap_magnetic_field_source_grid3d.cc b/src/utils/field_sources/wrap_magnetic_field_source_grid3d.cc index 53c6d1db..26049a98 100644 --- a/src/utils/field_sources/wrap_magnetic_field_source_grid3d.cc +++ b/src/utils/field_sources/wrap_magnetic_field_source_grid3d.cc @@ -1,9 +1,9 @@ -#include "orbit_mpi.hh" -#include "pyORBIT_Object.hh" -#include "wrap_spacecharge.hh" +#include "mpi/orbit_mpi.hh" +#include "main/pyORBIT_Object.hh" +#include "spacecharge/wrap_spacecharge.hh" -#include "wrap_utils.hh" -#include "MagnetFieldSourceGrid3D.hh" +#include "utils/wrap_utils.hh" +#include "utils/field_sources/MagnetFieldSourceGrid3D.hh" #include @@ -12,6 +12,13 @@ using namespace wrap_orbit_utils; namespace wrap_field_source_grid3d{ + typedef struct { + PyObject_HEAD + void* cpp_obj; + PyObject* grids[3]; + PyObject* transform; + } pyORBIT_MagnetFieldSourceGrid3D; + void error(const char* msg){ ORBIT_MPI_Finalize(msg); } #ifdef __cplusplus @@ -25,15 +32,19 @@ extern "C" { //It never will be called directly static PyObject* MagnetFieldSourceGrid3D_new(PyTypeObject *type, PyObject *args, PyObject *kwds) { - pyORBIT_Object* self; - self = (pyORBIT_Object *) type->tp_alloc(type, 0); + pyORBIT_MagnetFieldSourceGrid3D* self; + self = (pyORBIT_MagnetFieldSourceGrid3D *) type->tp_alloc(type, 0); self->cpp_obj = NULL; + self->grids[0] = NULL; + self->grids[1] = NULL; + self->grids[2] = NULL; + self->transform = NULL; return (PyObject *) self; } //initializator for python MagnetFieldSourceGrid3D class //this is implementation of the __init__ method - static int MagnetFieldSourceGrid3D_init(pyORBIT_Object *self, PyObject *args, PyObject *kwds){ + static int MagnetFieldSourceGrid3D_init(pyORBIT_MagnetFieldSourceGrid3D *self, PyObject *args, PyObject *kwds){ PyObject* pyBxGrid3D; PyObject* pyByGrid3D; PyObject* pyBzGrid3D; @@ -55,20 +66,17 @@ extern "C" { Py_INCREF(pyBxGrid3D); Py_INCREF(pyByGrid3D); Py_INCREF(pyBzGrid3D); - ((MagnetFieldSourceGrid3D*) self->cpp_obj)->setPyWrapper((PyObject*) self); + self->grids[0] = pyBxGrid3D; + self->grids[1] = pyByGrid3D; + self->grids[2] = pyBzGrid3D; + pyorbit::registerPyWrapper(self->cpp_obj, (PyObject*) self); return 0; } /** Returns 3 Grid3D objects with Bx,By,Bz fields that were used in the constructor */ static PyObject* MagnetFieldSourceGrid3D_getGrid3Ds(PyObject *self, PyObject *args){ - MagnetFieldSourceGrid3D* cpp_fieldSource = (MagnetFieldSourceGrid3D*)((pyORBIT_Object*) self)->cpp_obj; - Grid3D* BxGrid3D = cpp_fieldSource->getBxGrid(); - Grid3D* ByGrid3D = cpp_fieldSource->getByGrid(); - Grid3D* BzGrid3D = cpp_fieldSource->getBzGrid(); - PyObject* pyBxGrid3D = (PyObject*) BxGrid3D->getPyWrapper(); - PyObject* pyByGrid3D = (PyObject*) ByGrid3D->getPyWrapper(); - PyObject* pyBzGrid3D = (PyObject*) BzGrid3D->getPyWrapper(); - return Py_BuildValue("(OOO)",pyBxGrid3D,pyByGrid3D,pyBzGrid3D); + pyORBIT_MagnetFieldSourceGrid3D* source = (pyORBIT_MagnetFieldSourceGrid3D*) self; + return Py_BuildValue("(OOO)", source->grids[0], source->grids[1], source->grids[2]); } /** Sets or returns X,Y,Z axis symmetries */ @@ -156,6 +164,7 @@ extern "C" { /** Sets / Returns the coordinates transformation matrix 4x4 from external to inner system */ static PyObject* MagnetFieldSourceGrid3D_transormfMatrix(PyObject *self, PyObject *args){ + pyORBIT_MagnetFieldSourceGrid3D* source = (pyORBIT_MagnetFieldSourceGrid3D*) self; MagnetFieldSourceGrid3D* cpp_fieldSource = (MagnetFieldSourceGrid3D*)((pyORBIT_Object*) self)->cpp_obj; int nArgs = PyTuple_Size(args); PyObject* pyMatrix; @@ -172,25 +181,30 @@ extern "C" { if(cpp_matrix->rows() != 4 || cpp_matrix->columns() != 4){ error("MagnetFieldSourceGrid3D.transormfMatrix(Matrix) - Matrix is not 4x4."); } - // the Py_INCREF(pyMatrix) call will be performed inside setCoordsTransformMatrix(...) method cpp_fieldSource->setCoordsTransformMatrix(cpp_matrix); + Py_INCREF(pyMatrix); + Py_XDECREF(source->transform); + source->transform = pyMatrix; Py_INCREF(Py_None); return Py_None; } - cpp_matrix = cpp_fieldSource->getCoordsTransformMatrix(); - pyMatrix = (PyObject*) ((pyORBIT_Object*) cpp_matrix->getPyWrapper()); - if(pyMatrix == NULL){ + if(source->transform == NULL){ error("MagnetFieldSourceGrid3D.transormfMatrix() - cannot return Matrix 4x4. You have to assign it first."); } - Py_INCREF(pyMatrix); - return pyMatrix; + Py_INCREF(source->transform); + return source->transform; } //----------------------------------------------------- //destructor for python MagnetFieldSourceGrid3D class (__del__ method). //----------------------------------------------------- - static void MagnetFieldSourceGrid3D_del(pyORBIT_Object* self){ + static void MagnetFieldSourceGrid3D_del(pyORBIT_MagnetFieldSourceGrid3D* self){ + pyorbit::unregisterPyWrapper(self->cpp_obj, (PyObject*) self); delete ((MagnetFieldSourceGrid3D*)self->cpp_obj); + Py_CLEAR(self->grids[0]); + Py_CLEAR(self->grids[1]); + Py_CLEAR(self->grids[2]); + Py_CLEAR(self->transform); self->ob_base.ob_type->tp_free((PyObject*)self); } @@ -216,7 +230,7 @@ extern "C" { static PyTypeObject pyORBIT_MagnetFieldSourceGrid3D_Type = { PyVarObject_HEAD_INIT(NULL, 0) "MagnetFieldSourceGrid3D", /*tp_name*/ - sizeof(pyORBIT_Object), /*tp_basicsize*/ + sizeof(pyORBIT_MagnetFieldSourceGrid3D), /*tp_basicsize*/ 0, /*tp_itemsize*/ (destructor) MagnetFieldSourceGrid3D_del , /*tp_dealloc*/ 0, /*tp_print*/ diff --git a/src/utils/field_sources/wrap_magnetic_field_source_grid3d.hh b/src/utils/field_sources/wrap_magnetic_field_source_grid3d.hh index c29b0f54..ccf97665 100644 --- a/src/utils/field_sources/wrap_magnetic_field_source_grid3d.hh +++ b/src/utils/field_sources/wrap_magnetic_field_source_grid3d.hh @@ -1,7 +1,7 @@ #ifndef WRAP_MAGNET_FIELD_SOURCE_GRID3D_H #define WRAP_MAGNET_FIELD_SOURCE_GRID3D_H -#include "Python.h" +#include #ifdef __cplusplus extern "C" { diff --git a/src/utils/field_sources/wrap_quad_field_source.cc b/src/utils/field_sources/wrap_quad_field_source.cc index ba1b29e4..be510d00 100644 --- a/src/utils/field_sources/wrap_quad_field_source.cc +++ b/src/utils/field_sources/wrap_quad_field_source.cc @@ -1,9 +1,9 @@ -#include "orbit_mpi.hh" -#include "pyORBIT_Object.hh" -#include "wrap_spacecharge.hh" +#include "mpi/orbit_mpi.hh" +#include "main/pyORBIT_Object.hh" +#include "spacecharge/wrap_spacecharge.hh" -#include "wrap_utils.hh" -#include "QuadFieldSource.hh" +#include "utils/wrap_utils.hh" +#include "utils/field_sources/QuadFieldSource.hh" #include @@ -12,6 +12,12 @@ using namespace wrap_orbit_utils; namespace wrap_quad_field_source{ + typedef struct { + PyObject_HEAD + void* cpp_obj; + PyObject* transform; + } pyORBIT_QuadFieldSource; + void error(const char* msg){ ORBIT_MPI_Finalize(msg); } #ifdef __cplusplus @@ -25,17 +31,18 @@ extern "C" { //It never will be called directly static PyObject* QuadFieldSource_new(PyTypeObject *type, PyObject *args, PyObject *kwds) { - pyORBIT_Object* self; - self = (pyORBIT_Object *) type->tp_alloc(type, 0); + pyORBIT_QuadFieldSource* self; + self = (pyORBIT_QuadFieldSource *) type->tp_alloc(type, 0); self->cpp_obj = NULL; + self->transform = NULL; return (PyObject *) self; } //initializator for python QuadFieldSource class //this is implementation of the __init__ method - static int QuadFieldSource_init(pyORBIT_Object *self, PyObject *args, PyObject *kwds){ + static int QuadFieldSource_init(pyORBIT_QuadFieldSource *self, PyObject *args, PyObject *kwds){ self->cpp_obj = new QuadFieldSource(); - ((QuadFieldSource*) self->cpp_obj)->setPyWrapper((PyObject*) self); + pyorbit::registerPyWrapper(self->cpp_obj, (PyObject*) self); return 0; } @@ -85,6 +92,7 @@ extern "C" { /** Sets / Returns the coordinates transformation matrix 4x4 from external to inner system */ static PyObject* QuadFieldSource_transormfMatrix(PyObject *self, PyObject *args){ + pyORBIT_QuadFieldSource* source = (pyORBIT_QuadFieldSource*) self; QuadFieldSource* cpp_fieldSource = (QuadFieldSource*)((pyORBIT_Object*) self)->cpp_obj; int nArgs = PyTuple_Size(args); PyObject* pyMatrix; @@ -101,25 +109,27 @@ extern "C" { if(cpp_matrix->rows() != 4 || cpp_matrix->columns() != 4){ error("QuadFieldSource.transormfMatrix(Matrix) - Matrix is not 4x4."); } - // the Py_INCREF(pyMatrix) call will be performed inside setCoordsTransformMatrix(...) method cpp_fieldSource->setCoordsTransformMatrix(cpp_matrix); + Py_INCREF(pyMatrix); + Py_XDECREF(source->transform); + source->transform = pyMatrix; Py_INCREF(Py_None); return Py_None; } - cpp_matrix = cpp_fieldSource->getCoordsTransformMatrix(); - pyMatrix = (PyObject*) ((pyORBIT_Object*) cpp_matrix->getPyWrapper()); - if(pyMatrix == NULL){ + if(source->transform == NULL){ error("QuadFieldSource.transormfMatrix() - cannot return Matrix 4x4. You have to assign it first."); } - Py_INCREF(pyMatrix); - return pyMatrix; + Py_INCREF(source->transform); + return source->transform; } //----------------------------------------------------- //destructor for python QuadFieldSource class (__del__ method). //----------------------------------------------------- - static void QuadFieldSource_del(pyORBIT_Object* self){ + static void QuadFieldSource_del(pyORBIT_QuadFieldSource* self){ + pyorbit::unregisterPyWrapper(self->cpp_obj, (PyObject*) self); delete ((QuadFieldSource*)self->cpp_obj); + Py_CLEAR(self->transform); self->ob_base.ob_type->tp_free((PyObject*)self); } @@ -143,7 +153,7 @@ extern "C" { static PyTypeObject pyORBIT_QuadFieldSource_Type = { PyVarObject_HEAD_INIT(NULL, 0) "QuadFieldSource", /*tp_name*/ - sizeof(pyORBIT_Object), /*tp_basicsize*/ + sizeof(pyORBIT_QuadFieldSource), /*tp_basicsize*/ 0, /*tp_itemsize*/ (destructor) QuadFieldSource_del , /*tp_dealloc*/ 0, /*tp_print*/ diff --git a/src/utils/field_sources/wrap_quad_field_source.hh b/src/utils/field_sources/wrap_quad_field_source.hh index 5d91fff8..d83fc376 100644 --- a/src/utils/field_sources/wrap_quad_field_source.hh +++ b/src/utils/field_sources/wrap_quad_field_source.hh @@ -1,7 +1,7 @@ #ifndef WRAP_QUAD_FIELD_SOURCE_H #define WRAP_QUAD_FIELD_SOURCE_H -#include "Python.h" +#include #ifdef __cplusplus extern "C" { diff --git a/src/utils/harmonic_analysis/HarmonicData.cc b/src/utils/harmonic_analysis/HarmonicData.cc index 2f10c1ed..95000bb6 100644 --- a/src/utils/harmonic_analysis/HarmonicData.cc +++ b/src/utils/harmonic_analysis/HarmonicData.cc @@ -29,14 +29,15 @@ // /////////////////////////////////////////////////////////////////////////// #include +#include -#include "orbit_mpi.hh" -#include "HarmonicData.hh" -#include "OrbitConst.hh" +#include "mpi/orbit_mpi.hh" +#include "utils/harmonic_analysis/HarmonicData.hh" +#include "orbit/OrbitConst.hh" using namespace OrbitUtils; -HarmonicData::HarmonicData(int order_in, Function* inFunc): CppPyWrapper(NULL) +HarmonicData::HarmonicData(int order_in, Function* inFunc) { this->init(order_in,inFunc); } diff --git a/src/utils/harmonic_analysis/HarmonicData.hh b/src/utils/harmonic_analysis/HarmonicData.hh index ab8f97aa..45464052 100644 --- a/src/utils/harmonic_analysis/HarmonicData.hh +++ b/src/utils/harmonic_analysis/HarmonicData.hh @@ -31,14 +31,12 @@ #ifndef ORBIT_UTILS_HARMONICDATA_H #define ORBIT_UTILS_HARMONICDATA_H -#include "CppPyWrapper.hh" -#include "OU_Function.hh" +#include "utils/OU_Function.hh" -using namespace std; namespace OrbitUtils{ - class HarmonicData : public CppPyWrapper + class HarmonicData { public: //----------------------------------------- diff --git a/src/utils/harmonic_analysis/wrap_harmonic_data.cc b/src/utils/harmonic_analysis/wrap_harmonic_data.cc index 19188a7a..c33cd260 100644 --- a/src/utils/harmonic_analysis/wrap_harmonic_data.cc +++ b/src/utils/harmonic_analysis/wrap_harmonic_data.cc @@ -1,14 +1,14 @@ -#include "orbit_mpi.hh" -#include "pyORBIT_Object.hh" +#include "mpi/orbit_mpi.hh" +#include "main/pyORBIT_Object.hh" -#include "wrap_utils.hh" -#include "wrap_harmonic_data.hh" +#include "utils/wrap_utils.hh" +#include "utils/harmonic_analysis/wrap_harmonic_data.hh" #include #include #include -#include "HarmonicData.hh" +#include "utils/harmonic_analysis/HarmonicData.hh" using namespace OrbitUtils; using namespace wrap_orbit_utils; @@ -62,7 +62,6 @@ extern "C" { else{ error("HarmonicData(order,pyFunction) or HarmonicData(harmonicData)- constructor parameters are needed"); } - ((HarmonicData*) self->cpp_obj)->setPyWrapper((PyObject*) self); return 0; } diff --git a/src/utils/harmonic_analysis/wrap_harmonic_data.hh b/src/utils/harmonic_analysis/wrap_harmonic_data.hh index 4b0e5ada..b38609d1 100644 --- a/src/utils/harmonic_analysis/wrap_harmonic_data.hh +++ b/src/utils/harmonic_analysis/wrap_harmonic_data.hh @@ -1,7 +1,7 @@ #ifndef WRAP_ORBIT_UTILS_HARMONIC_DATA_HH_ #define WRAP_ORBIT_UTILS_HARMONIC_DATA_HH_ -#include "Python.h" +#include #ifdef __cplusplus extern "C" { diff --git a/src/utils/integration/GaussLegendreIntegrator.cc b/src/utils/integration/GaussLegendreIntegrator.cc index d6dcb56b..90697885 100644 --- a/src/utils/integration/GaussLegendreIntegrator.cc +++ b/src/utils/integration/GaussLegendreIntegrator.cc @@ -13,18 +13,18 @@ // The integrator for the Gauss-Legendre schema. // /////////////////////////////////////////////////////////////////////////// -#include "orbit_mpi.hh" -#include "orbit_mpi.hh" -#include "GaussLegendreIntegrator.hh" -#include "gauss_legendre_points.hh" -#include "OU_Function.hh" -#include "OU_SplineCH.hh" +#include "mpi/orbit_mpi.hh" +#include "mpi/orbit_mpi.hh" +#include "utils/integration/GaussLegendreIntegrator.hh" +#include "utils/integration/gauss_legendre_points.hh" +#include "utils/OU_Function.hh" +#include "utils/OU_SplineCH.hh" #include using namespace OrbitUtils; -GaussLegendreIntegrator::GaussLegendreIntegrator(): CppPyWrapper(NULL) +GaussLegendreIntegrator::GaussLegendreIntegrator() { n_int_points = 1024; x0 = 0.; @@ -34,7 +34,7 @@ GaussLegendreIntegrator::GaussLegendreIntegrator(): CppPyWrapper(NULL) n_int_points = pw_finc->getSize(); } -GaussLegendreIntegrator::GaussLegendreIntegrator(int nPoints): CppPyWrapper(NULL) +GaussLegendreIntegrator::GaussLegendreIntegrator(int nPoints) { n_int_points = nPoints; x0 = 0.; @@ -44,7 +44,7 @@ GaussLegendreIntegrator::GaussLegendreIntegrator(int nPoints): CppPyWrapper(NULL n_int_points = pw_finc->getSize(); } -GaussLegendreIntegrator::GaussLegendreIntegrator(int nPoints, double x_from, double x_to): CppPyWrapper(NULL) +GaussLegendreIntegrator::GaussLegendreIntegrator(int nPoints, double x_from, double x_to) { n_int_points = nPoints; x0 = x_from; diff --git a/src/utils/integration/GaussLegendreIntegrator.hh b/src/utils/integration/GaussLegendreIntegrator.hh index b6e7d63c..7ae3a992 100644 --- a/src/utils/integration/GaussLegendreIntegrator.hh +++ b/src/utils/integration/GaussLegendreIntegrator.hh @@ -21,16 +21,13 @@ #include #include -#include "CppPyWrapper.hh" +#include "utils/OU_Function.hh" +#include "utils/OU_SplineCH.hh" -#include "OU_Function.hh" -#include "OU_SplineCH.hh" - -using namespace std; namespace OrbitUtils{ - class GaussLegendreIntegrator : public CppPyWrapper + class GaussLegendreIntegrator { public: //----------------------------------------- diff --git a/src/utils/integration/gauss_legendre_points.cc b/src/utils/integration/gauss_legendre_points.cc index c2311d5c..14702461 100644 --- a/src/utils/integration/gauss_legendre_points.cc +++ b/src/utils/integration/gauss_legendre_points.cc @@ -1,4 +1,4 @@ -#include "gauss_legendre_points.hh" +#include "utils/integration/gauss_legendre_points.hh" #include namespace OrbitUtils{ diff --git a/src/utils/integration/gauss_legendre_points.hh b/src/utils/integration/gauss_legendre_points.hh index 1936d604..21ceb2e7 100644 --- a/src/utils/integration/gauss_legendre_points.hh +++ b/src/utils/integration/gauss_legendre_points.hh @@ -12,7 +12,7 @@ #ifndef GAUSS_LEGENDRE_POINTS_H #define GAUSS_LEGENDRE_POINTS_H -#include "OU_Function.hh" +#include "utils/OU_Function.hh" namespace OrbitUtils{ diff --git a/src/utils/integration/wrap_gauss_legendre_integrator.cc b/src/utils/integration/wrap_gauss_legendre_integrator.cc index 3d5388d4..2a7d8466 100644 --- a/src/utils/integration/wrap_gauss_legendre_integrator.cc +++ b/src/utils/integration/wrap_gauss_legendre_integrator.cc @@ -1,15 +1,15 @@ -#include "orbit_mpi.hh" -#include "pyORBIT_Object.hh" +#include "mpi/orbit_mpi.hh" +#include "main/pyORBIT_Object.hh" -#include "wrap_utils.hh" +#include "utils/wrap_utils.hh" #include #include -#include "GaussLegendreIntegrator.hh" -#include "wrap_gauss_legendre_integrator.hh" -#include "OU_SplineCH.hh" -#include "OU_Function.hh" +#include "utils/integration/GaussLegendreIntegrator.hh" +#include "utils/integration/wrap_gauss_legendre_integrator.hh" +#include "utils/OU_SplineCH.hh" +#include "utils/OU_Function.hh" using namespace OrbitUtils; using namespace wrap_orbit_utils; @@ -61,7 +61,6 @@ extern "C" { if(self->cpp_obj == NULL){ error("GaussLegendreIntegrator([nPoints[,x_min,x_max]]) - constructor signature."); } - ((GaussLegendreIntegrator*) self->cpp_obj)->setPyWrapper((PyObject*) self); return 0; } diff --git a/src/utils/integration/wrap_gauss_legendre_integrator.hh b/src/utils/integration/wrap_gauss_legendre_integrator.hh index d3452f87..258a5d7a 100644 --- a/src/utils/integration/wrap_gauss_legendre_integrator.hh +++ b/src/utils/integration/wrap_gauss_legendre_integrator.hh @@ -2,7 +2,7 @@ #define WRAP_ORBIT_UTILS_GAUSS_LEGENDRE_INTEGRATOR_HH_ -#include "Python.h" +#include #ifdef __cplusplus extern "C" { diff --git a/src/utils/matrix/Matrix.cc b/src/utils/matrix/Matrix.cc index cee5cbcc..be9fbf98 100644 --- a/src/utils/matrix/Matrix.cc +++ b/src/utils/matrix/Matrix.cc @@ -14,15 +14,15 @@ // /////////////////////////////////////////////////////////////////////////// -#include "orbit_mpi.hh" -#include "Matrix.hh" -#include "BufferStore.hh" +#include "mpi/orbit_mpi.hh" +#include "utils/matrix/Matrix.hh" +#include "utils/BufferStore.hh" #include using namespace OrbitUtils; -Matrix::Matrix(int n_in, int m_in): CppPyWrapper(NULL) +Matrix::Matrix(int n_in, int m_in) { n = n_in; m = m_in; @@ -34,7 +34,7 @@ Matrix::Matrix(int n_in, int m_in): CppPyWrapper(NULL) zero(); } -Matrix::Matrix(Matrix* mtrx): CppPyWrapper(NULL) +Matrix::Matrix(Matrix* mtrx) { n = mtrx->rows(); m = mtrx->columns(); diff --git a/src/utils/matrix/Matrix.hh b/src/utils/matrix/Matrix.hh index 2b8f353f..64a9ce57 100644 --- a/src/utils/matrix/Matrix.hh +++ b/src/utils/matrix/Matrix.hh @@ -17,13 +17,11 @@ #ifndef PLAIN_MATRIX_H #define PLAIN_MATRIX_H -#include "CppPyWrapper.hh" - namespace OrbitUtils{ /** A class for plain NxM matrices with double values. */ - class Matrix : public CppPyWrapper + class Matrix { public: diff --git a/src/utils/matrix/MatrixOperations.cc b/src/utils/matrix/MatrixOperations.cc index 8e29aa0a..c468479a 100644 --- a/src/utils/matrix/MatrixOperations.cc +++ b/src/utils/matrix/MatrixOperations.cc @@ -1,7 +1,7 @@ -#include "orbit_mpi.hh" +#include "mpi/orbit_mpi.hh" -#include "MatrixOperations.hh" -#include "BufferStore.hh" +#include "utils/matrix/MatrixOperations.hh" +#include "utils/BufferStore.hh" #include diff --git a/src/utils/matrix/MatrixOperations.hh b/src/utils/matrix/MatrixOperations.hh index 0b6f7976..92c5295d 100644 --- a/src/utils/matrix/MatrixOperations.hh +++ b/src/utils/matrix/MatrixOperations.hh @@ -1,9 +1,9 @@ #ifndef __MATRIX_OPERATIONS_H_ #define __MATRIX_OPERATIONS_H_ -#include "Matrix.hh" -#include "PhaseVector.hh" -#include "Bunch.hh" +#include "utils/matrix/Matrix.hh" +#include "utils/matrix/PhaseVector.hh" +#include "orbit/Bunch.hh" namespace OrbitUtils{ diff --git a/src/utils/matrix/PhaseVector.cc b/src/utils/matrix/PhaseVector.cc index 87a024d4..757e9816 100644 --- a/src/utils/matrix/PhaseVector.cc +++ b/src/utils/matrix/PhaseVector.cc @@ -13,22 +13,22 @@ // A class for a plain double values vector // /////////////////////////////////////////////////////////////////////////// -#include "orbit_mpi.hh" +#include "mpi/orbit_mpi.hh" -#include "PhaseVector.hh" +#include "utils/matrix/PhaseVector.hh" #include using namespace OrbitUtils; -PhaseVector::PhaseVector(int n_in): CppPyWrapper(NULL) +PhaseVector::PhaseVector(int n_in) { n = n_in; v = (double* ) malloc (sizeof(double)*n); zero(); } -PhaseVector::PhaseVector(PhaseVector* vIn): CppPyWrapper(NULL) +PhaseVector::PhaseVector(PhaseVector* vIn) { n = vIn->size(); v = (double* ) malloc (sizeof(double)*n); diff --git a/src/utils/matrix/PhaseVector.hh b/src/utils/matrix/PhaseVector.hh index bbcd37f3..3a9d6784 100644 --- a/src/utils/matrix/PhaseVector.hh +++ b/src/utils/matrix/PhaseVector.hh @@ -17,13 +17,11 @@ #ifndef PHASE_VECTOR_H #define PHASE_VECTOR_H -#include "CppPyWrapper.hh" - namespace OrbitUtils{ /** A double values vector. */ - class PhaseVector : public CppPyWrapper + class PhaseVector { public: diff --git a/src/utils/matrix/wrap_matrix.cc b/src/utils/matrix/wrap_matrix.cc index eb2bc14d..581b0c75 100644 --- a/src/utils/matrix/wrap_matrix.cc +++ b/src/utils/matrix/wrap_matrix.cc @@ -1,15 +1,15 @@ -#include "orbit_mpi.hh" -#include "pyORBIT_Object.hh" +#include "mpi/orbit_mpi.hh" +#include "main/pyORBIT_Object.hh" -#include "wrap_utils.hh" -#include "wrap_matrix.hh" -#include "wrap_bunch.hh" +#include "utils/wrap_utils.hh" +#include "utils/matrix/wrap_matrix.hh" +#include "orbit/wrap_bunch.hh" #include -#include "Matrix.hh" -#include "PhaseVector.hh" -#include "MatrixOperations.hh" +#include "utils/matrix/Matrix.hh" +#include "utils/matrix/PhaseVector.hh" +#include "utils/matrix/MatrixOperations.hh" using namespace OrbitUtils; using namespace wrap_orbit_utils; @@ -51,7 +51,7 @@ extern "C" { Matrix* mtrx = (Matrix*)(((pyORBIT_Object*) pyIn)->cpp_obj); self->cpp_obj = new Matrix(mtrx->rows(),mtrx->columns()); mtrx->copyTo((Matrix*) self->cpp_obj); - ((Matrix*) self->cpp_obj)->setPyWrapper((PyObject*) self); + pyorbit::registerPyWrapper(self->cpp_obj, (PyObject*) self); return 0; } if(nArgs == 2){ @@ -60,7 +60,7 @@ extern "C" { error("PyMatrix - Matrix(n,m) - a maririx size is needed."); } self->cpp_obj = new Matrix(n,m); - ((Matrix*) self->cpp_obj)->setPyWrapper((PyObject*) self); + pyorbit::registerPyWrapper(self->cpp_obj, (PyObject*) self); } return 0; } @@ -68,8 +68,9 @@ extern "C" { //----------------------------------------------------- //destructor for python Matrix class (__del__ method). //----------------------------------------------------- - static void Matrix_del(pyORBIT_Object* self){ + static void Matrix_del(pyORBIT_Object* self){ //std::cerr<<"The Matrix __del__ has been called!"<cpp_obj, (PyObject*) self); delete ((Matrix*)self->cpp_obj); self->ob_base.ob_type->tp_free((PyObject*)self); } diff --git a/src/utils/matrix/wrap_matrix.hh b/src/utils/matrix/wrap_matrix.hh index c2aa7570..3fca2cef 100644 --- a/src/utils/matrix/wrap_matrix.hh +++ b/src/utils/matrix/wrap_matrix.hh @@ -1,7 +1,7 @@ #ifndef WRAP_UTILS_MATRIX_H #define WRAP_UTILS_MATRIX_H -#include "Python.h" +#include #ifdef __cplusplus extern "C" { diff --git a/src/utils/matrix/wrap_phase_vector.cc b/src/utils/matrix/wrap_phase_vector.cc index bff60f33..1cde8737 100644 --- a/src/utils/matrix/wrap_phase_vector.cc +++ b/src/utils/matrix/wrap_phase_vector.cc @@ -1,14 +1,14 @@ -#include "orbit_mpi.hh" -#include "pyORBIT_Object.hh" +#include "mpi/orbit_mpi.hh" +#include "main/pyORBIT_Object.hh" -#include "wrap_utils.hh" -#include "wrap_phase_vector.hh" +#include "utils/wrap_utils.hh" +#include "utils/matrix/wrap_phase_vector.hh" #include -#include "PhaseVector.hh" -#include "Matrix.hh" -#include "MatrixOperations.hh" +#include "utils/matrix/PhaseVector.hh" +#include "utils/matrix/Matrix.hh" +#include "utils/matrix/MatrixOperations.hh" using namespace OrbitUtils; using namespace wrap_orbit_utils; @@ -48,7 +48,6 @@ extern "C" { error("PyPhaseVector - __init__(size) - input parameter is needed."); } self->cpp_obj = new PhaseVector(size); - ((PhaseVector*) self->cpp_obj)->setPyWrapper((PyObject*) self); return 0; } PyObject* pyORBIT_PhaseVector_Type = getOrbitUtilsType("PhaseVector"); @@ -58,7 +57,6 @@ extern "C" { PhaseVector* v = (PhaseVector*)(((pyORBIT_Object*) pyIn)->cpp_obj); self->cpp_obj = new PhaseVector(v->size()); v->copyTo((PhaseVector*) self->cpp_obj); - ((PhaseVector*) self->cpp_obj)->setPyWrapper((PyObject*) self); return 0; } diff --git a/src/utils/matrix/wrap_phase_vector.hh b/src/utils/matrix/wrap_phase_vector.hh index 33b04fdd..27f44540 100644 --- a/src/utils/matrix/wrap_phase_vector.hh +++ b/src/utils/matrix/wrap_phase_vector.hh @@ -1,7 +1,7 @@ #ifndef WRAP_UTILS_PHASE_VECTOR_H #define WRAP_UTILS_PHASE_VECTOR_H -#include "Python.h" +#include #ifdef __cplusplus extern "C" { diff --git a/src/utils/polynomial/OU_Polynomial.cc b/src/utils/polynomial/OU_Polynomial.cc index fec8a1a6..cfc19d38 100644 --- a/src/utils/polynomial/OU_Polynomial.cc +++ b/src/utils/polynomial/OU_Polynomial.cc @@ -19,12 +19,12 @@ /////////////////////////////////////////////////////////////////////////// #include -#include "orbit_mpi.hh" -#include "OU_Polynomial.hh" +#include "mpi/orbit_mpi.hh" +#include "utils/polynomial/OU_Polynomial.hh" using namespace OrbitUtils; -Polynomial::Polynomial(int order_in): CppPyWrapper(NULL) +Polynomial::Polynomial(int order_in) { if(order_in < 0){ ORBIT_MPI_Finalize("Orbit Utilites Polynomial::Polynomial(order) - order should be >= 0. Stop."); diff --git a/src/utils/polynomial/OU_Polynomial.hh b/src/utils/polynomial/OU_Polynomial.hh index f1e480c9..0882fa5e 100644 --- a/src/utils/polynomial/OU_Polynomial.hh +++ b/src/utils/polynomial/OU_Polynomial.hh @@ -18,13 +18,10 @@ #ifndef ORBIT_UTILS_POLYNOMIAL_H #define ORBIT_UTILS_POLYNOMIAL_H -#include "CppPyWrapper.hh" - -using namespace std; namespace OrbitUtils{ - class Polynomial : public CppPyWrapper + class Polynomial { public: //----------------------------------------- diff --git a/src/utils/polynomial/wrap_polynomial.cc b/src/utils/polynomial/wrap_polynomial.cc index 309481d1..3ff73cc4 100644 --- a/src/utils/polynomial/wrap_polynomial.cc +++ b/src/utils/polynomial/wrap_polynomial.cc @@ -1,14 +1,14 @@ -#include "orbit_mpi.hh" -#include "pyORBIT_Object.hh" +#include "mpi/orbit_mpi.hh" +#include "main/pyORBIT_Object.hh" -#include "wrap_utils.hh" -#include "wrap_polynomial.hh" +#include "utils/wrap_utils.hh" +#include "utils/polynomial/wrap_polynomial.hh" #include #include #include -#include "OU_Polynomial.hh" +#include "utils/polynomial/OU_Polynomial.hh" using namespace OrbitUtils; using namespace wrap_orbit_utils; @@ -35,7 +35,6 @@ extern "C" { /** This is implementation of the __init__ method */ static int Polynomial_init(pyORBIT_Object *self, PyObject *args, PyObject *kwds){ self->cpp_obj = new Polynomial(0); - ((Polynomial*) self->cpp_obj)->setPyWrapper((PyObject*) self); int nVars = PyTuple_Size(args); int order = -1; if(nVars == 1){ diff --git a/src/utils/polynomial/wrap_polynomial.hh b/src/utils/polynomial/wrap_polynomial.hh index c3e4adc3..49086229 100644 --- a/src/utils/polynomial/wrap_polynomial.hh +++ b/src/utils/polynomial/wrap_polynomial.hh @@ -1,7 +1,7 @@ #ifndef WRAP_ORBIT_UTILS_POLYNOMIAL_HH_ #define WRAP_ORBIT_UTILS_POLYNOMIAL_HH_ -#include "Python.h" +#include #ifdef __cplusplus extern "C" { diff --git a/src/utils/statistics/StatMoments2D.cc b/src/utils/statistics/StatMoments2D.cc index 3656b76a..88cf4226 100644 --- a/src/utils/statistics/StatMoments2D.cc +++ b/src/utils/statistics/StatMoments2D.cc @@ -1,15 +1,15 @@ -#include "StatMoments2D.hh" +#include "utils/statistics/StatMoments2D.hh" #include #include #include -#include "BufferStore.hh" +#include "utils/BufferStore.hh" using namespace OrbitUtils; /** Constructor with max order = 2 by default */ -StatMoments2D::StatMoments2D(): CppPyWrapper(NULL) +StatMoments2D::StatMoments2D() { max_order = 2; stat_arr = NULL; @@ -17,7 +17,7 @@ StatMoments2D::StatMoments2D(): CppPyWrapper(NULL) } /** Constructor with maximal order parameter */ -StatMoments2D::StatMoments2D(int maxOrder): CppPyWrapper(NULL) +StatMoments2D::StatMoments2D(int maxOrder) { max_order = maxOrder; if(max_order < 2) max_order = 2; @@ -167,7 +167,7 @@ int StatMoments2D::getCount() } /** It will synchronize the moments through the MPI communicator */ -void StatMoments2D::synchronizeMPI(pyORBIT_MPI_Comm* pyComm) +void StatMoments2D::synchronizeMPI(MPI_Comm pyComm) { int mpi_size = (max_order+1)*(max_order+1); int buff_index0 = -1; @@ -183,10 +183,10 @@ void StatMoments2D::synchronizeMPI(pyORBIT_MPI_Comm* pyComm) } } - if(pyComm == NULL) { + if(pyComm == MPI_COMM_NULL) { ORBIT_MPI_Allreduce(inArr,outArr,mpi_size,MPI_DOUBLE,MPI_SUM,MPI_COMM_WORLD); } else { - ORBIT_MPI_Allreduce(inArr,outArr,mpi_size,MPI_DOUBLE,MPI_SUM,pyComm->comm); + ORBIT_MPI_Allreduce(inArr,outArr,mpi_size,MPI_DOUBLE,MPI_SUM,pyComm); } ii = 0; @@ -198,10 +198,10 @@ void StatMoments2D::synchronizeMPI(pyORBIT_MPI_Comm* pyComm) } int count_MPI = -1; - if(pyComm == NULL) { + if(pyComm == MPI_COMM_NULL) { ORBIT_MPI_Allreduce(&count,&count_MPI,1,MPI_INT,MPI_SUM,MPI_COMM_WORLD); } else { - ORBIT_MPI_Allreduce(&count,&count_MPI,1,MPI_INT,MPI_SUM,pyComm->comm); + ORBIT_MPI_Allreduce(&count,&count_MPI,1,MPI_INT,MPI_SUM,pyComm); } count = count_MPI; diff --git a/src/utils/statistics/StatMoments2D.hh b/src/utils/statistics/StatMoments2D.hh index 79ac3161..70dfeacf 100644 --- a/src/utils/statistics/StatMoments2D.hh +++ b/src/utils/statistics/StatMoments2D.hh @@ -1,13 +1,8 @@ #ifndef STAT_MOMENTS_2D_H #define STAT_MOMENTS_2D_H -#include "orbit_mpi.hh" -#include "wrap_mpi_comm.hh" +#include "mpi/orbit_mpi.hh" -//pyORBIT utils -#include "CppPyWrapper.hh" - -using namespace std; /** The Moments1D class calculates the arbitrary moments of the (u,up) distribution. @@ -16,7 +11,7 @@ It is used by other classes to calculate Twiss paraemeters etc. namespace OrbitUtils{ - class StatMoments2D: public CppPyWrapper + class StatMoments2D { public: @@ -66,7 +61,7 @@ namespace OrbitUtils{ int getCount(); /** It will synchronize the moments through the MPI communicator */ - void synchronizeMPI(pyORBIT_MPI_Comm* pyComm); + void synchronizeMPI(MPI_Comm pyComm); /** Returns the emittance */ double getEmittance(); diff --git a/src/utils/statistics/wrap_statmoments2d.cc b/src/utils/statistics/wrap_statmoments2d.cc index d61a782d..1826066c 100644 --- a/src/utils/statistics/wrap_statmoments2d.cc +++ b/src/utils/statistics/wrap_statmoments2d.cc @@ -1,14 +1,15 @@ -#include "orbit_mpi.hh" -#include "pyORBIT_Object.hh" +#include "mpi/orbit_mpi.hh" +#include "mpi/wrap_orbit_mpi_types.hh" +#include "main/pyORBIT_Object.hh" -#include "wrap_utils.hh" -#include "wrap_statmoments2d.hh" -#include "wrap_mpi_comm.hh" +#include "utils/wrap_utils.hh" +#include "utils/statistics/wrap_statmoments2d.hh" +#include "mpi/wrap_mpi_comm.hh" #include #include -#include "StatMoments2D.hh" +#include "utils/statistics/StatMoments2D.hh" using namespace OrbitUtils; using namespace wrap_orbit_utils; @@ -47,7 +48,6 @@ extern "C" { self->cpp_obj = new StatMoments2D(max_order); } } - ((StatMoments2D*) self->cpp_obj)->setPyWrapper((PyObject*) self); return 0; } @@ -172,7 +172,7 @@ extern "C" { if((!PyObject_IsInstance(pyMPIComm,py_mpi_comm_type))){ error("StatMoments2D.synchronizeMPI(MPI_Comm) - input parameter is not MPI_Comm"); } - cpp_StatMoments2D->synchronizeMPI((pyORBIT_MPI_Comm*) pyMPIComm); + cpp_StatMoments2D->synchronizeMPI(((pyORBIT_MPI_Comm*) pyMPIComm)->comm); } Py_INCREF(Py_None); return Py_None; diff --git a/src/utils/statistics/wrap_statmoments2d.hh b/src/utils/statistics/wrap_statmoments2d.hh index 3696dd37..1da57091 100644 --- a/src/utils/statistics/wrap_statmoments2d.hh +++ b/src/utils/statistics/wrap_statmoments2d.hh @@ -2,7 +2,7 @@ #define WRAP_ORBIT_UTILS_STAT_MOMENTS_2D_HH_ -#include "Python.h" +#include #ifdef __cplusplus extern "C" { diff --git a/src/utils/wrap_field_source_container.cc b/src/utils/wrap_field_source_container.cc index b29a90d6..6f3484d8 100644 --- a/src/utils/wrap_field_source_container.cc +++ b/src/utils/wrap_field_source_container.cc @@ -1,20 +1,25 @@ -#include "orbit_mpi.hh" -#include "pyORBIT_Object.hh" +#include "mpi/orbit_mpi.hh" +#include "main/pyORBIT_Object.hh" -#include "wrap_utils.hh" -#include "wrap_field_source_container.hh" +#include "utils/wrap_utils.hh" +#include "utils/wrap_field_source_container.hh" #include #include -#include "FieldSourceContainer.hh" -#include "BaseFieldSource.hh" +#include "utils/FieldSourceContainer.hh" +#include "utils/BaseFieldSource.hh" using namespace OrbitUtils; namespace wrap_field_source_container{ + typedef struct { + PyObject_HEAD + void* cpp_obj; + PyObject* sources; + } pyORBIT_FieldSourceContainer; void error(const char* msg){ ORBIT_MPI_Finalize(msg); } @@ -26,27 +31,36 @@ extern "C" { //constructor for python class wrapping CppFieldSource instance //It never will be called directly static PyObject* FieldSourceContainer_new(PyTypeObject *type, PyObject *args, PyObject *kwds){ - pyORBIT_Object* self; - self = (pyORBIT_Object *) type->tp_alloc(type, 0); + pyORBIT_FieldSourceContainer* self; + self = (pyORBIT_FieldSourceContainer *) type->tp_alloc(type, 0); self->cpp_obj = NULL; + self->sources = NULL; return (PyObject *) self; } //this is implementation of the __init__ method - static int FieldSourceContainer_init(pyORBIT_Object *self, PyObject *args, PyObject *kwds){ + static int FieldSourceContainer_init(pyORBIT_FieldSourceContainer *self, PyObject *args, PyObject *kwds){ self->cpp_obj = new FieldSourceContainer(); - ((FieldSourceContainer*) self->cpp_obj)->setPyWrapper((PyObject*) self); + self->sources = PyList_New(0); + if(self->sources == NULL) { + delete ((FieldSourceContainer*) self->cpp_obj); + self->cpp_obj = NULL; + return -1; + } + pyorbit::registerPyWrapper(self->cpp_obj, (PyObject*) self); return 0; } static PyObject* FieldSourceContainer_AddFieldSource(PyObject *self, PyObject *args){ - FieldSourceContainer* cpp_FieldSourceContainer = (FieldSourceContainer*)((pyORBIT_Object*) self)->cpp_obj; + pyORBIT_FieldSourceContainer* container = (pyORBIT_FieldSourceContainer*) self; + FieldSourceContainer* cpp_FieldSourceContainer = (FieldSourceContainer*) container->cpp_obj; BaseFieldSource* fs; PyObject* pyfs; if(!PyArg_ParseTuple( args,"O:",&pyfs)) error(" AddFieldSource(BaseFieldSource fs) - parameter is needed"); else { fs = (BaseFieldSource*) ((pyORBIT_Object*) pyfs)->cpp_obj; + if(PyList_Append(container->sources, pyfs) < 0) return NULL; cpp_FieldSourceContainer->AddFieldSource(fs); } Py_INCREF(Py_None); @@ -68,9 +82,11 @@ extern "C" { //----------------------------------------------------- //destructor for python FieldSourceContainer class (__del__ method). //----------------------------------------------------- - static void FieldSourceContainer_del(pyORBIT_Object* self){ + static void FieldSourceContainer_del(pyORBIT_FieldSourceContainer* self){ //std::cerr<<"The FieldSourceContainer __del__ has been called!"<cpp_obj, (PyObject*) self); delete ((FieldSourceContainer*)self->cpp_obj); + Py_CLEAR(self->sources); self->ob_base.ob_type->tp_free((PyObject*)self); } @@ -93,7 +109,7 @@ extern "C" { static PyTypeObject pyORBIT_FieldSourceContainer_Type = { PyVarObject_HEAD_INIT(NULL, 0) "FieldSourceContainer", /*tp_name*/ - sizeof(pyORBIT_Object), /*tp_basicsize*/ + sizeof(pyORBIT_FieldSourceContainer), /*tp_basicsize*/ 0, /*tp_itemsize*/ (destructor) FieldSourceContainer_del , /*tp_dealloc*/ 0, /*tp_print*/ diff --git a/src/utils/wrap_field_source_container.hh b/src/utils/wrap_field_source_container.hh index bb97c187..e7d37304 100644 --- a/src/utils/wrap_field_source_container.hh +++ b/src/utils/wrap_field_source_container.hh @@ -2,7 +2,7 @@ #define WRAP_FIELD_SOURCE_CONTAINER_HH_ -#include "Python.h" +#include #ifdef __cplusplus extern "C" { diff --git a/src/utils/wrap_function.cc b/src/utils/wrap_function.cc index 4002e970..b93477be 100644 --- a/src/utils/wrap_function.cc +++ b/src/utils/wrap_function.cc @@ -1,13 +1,13 @@ -#include "orbit_mpi.hh" -#include "pyORBIT_Object.hh" +#include "mpi/orbit_mpi.hh" +#include "main/pyORBIT_Object.hh" -#include "wrap_utils.hh" -#include "wrap_function.hh" +#include "utils/wrap_utils.hh" +#include "utils/wrap_function.hh" #include #include -#include "OU_Function.hh" +#include "utils/OU_Function.hh" using namespace OrbitUtils; using namespace wrap_orbit_utils; @@ -34,7 +34,6 @@ extern "C" { /** This is implementation of the __init__ method */ static int Function_init(pyORBIT_Object *self, PyObject *args, PyObject *kwds){ self->cpp_obj = new Function(); - ((Function*) self->cpp_obj)->setPyWrapper((PyObject*) self); return 0; } diff --git a/src/utils/wrap_function.hh b/src/utils/wrap_function.hh index 7d22dd4f..15c8ed5a 100644 --- a/src/utils/wrap_function.hh +++ b/src/utils/wrap_function.hh @@ -2,7 +2,7 @@ #define WRAP_ORBIT_UTILS_FUNCTION_HH_ -#include "Python.h" +#include #ifdef __cplusplus extern "C" { diff --git a/src/utils/wrap_numrecipes.cc b/src/utils/wrap_numrecipes.cc index fe74a206..f0b0d3c0 100644 --- a/src/utils/wrap_numrecipes.cc +++ b/src/utils/wrap_numrecipes.cc @@ -1,12 +1,12 @@ -#include "orbit_mpi.hh" -#include "pyORBIT_Object.hh" +#include "mpi/orbit_mpi.hh" +#include "main/pyORBIT_Object.hh" -#include "wrap_utils.hh" +#include "utils/wrap_utils.hh" #include #include -#include "bessel.hh" +#include "utils/bessel.hh" using namespace OrbitUtils; using namespace wrap_orbit_utils; diff --git a/src/utils/wrap_numrecipes.hh b/src/utils/wrap_numrecipes.hh index f338562a..5ee49b3a 100644 --- a/src/utils/wrap_numrecipes.hh +++ b/src/utils/wrap_numrecipes.hh @@ -2,7 +2,7 @@ #define WRAP_ORBIT_UTILS_NUMRECIPES_HH_ -#include "Python.h" +#include #ifdef __cplusplus extern "C" { diff --git a/src/utils/wrap_py_base_field_source.cc b/src/utils/wrap_py_base_field_source.cc index ea0c442c..1f3ec90d 100644 --- a/src/utils/wrap_py_base_field_source.cc +++ b/src/utils/wrap_py_base_field_source.cc @@ -1,12 +1,12 @@ -#include "orbit_mpi.hh" -#include "pyORBIT_Object.hh" +#include "mpi/orbit_mpi.hh" +#include "main/pyORBIT_Object.hh" -#include "wrap_utils.hh" -#include "wrap_py_base_field_source.hh" +#include "utils/wrap_utils.hh" +#include "utils/wrap_py_base_field_source.hh" #include -#include "PyBaseFieldSource.hh" +#include "utils/PyBaseFieldSource.hh" using namespace OrbitUtils; using namespace wrap_orbit_utils; @@ -37,6 +37,7 @@ extern "C" { //this is implementation of the __init__ method static int PyBaseFieldSource_init(pyORBIT_Object *self, PyObject *args, PyObject *kwds){ self->cpp_obj = new PyBaseFieldSource((PyObject*) self); + pyorbit::registerPyWrapper(self->cpp_obj, (PyObject*) self); return 0; } @@ -45,6 +46,7 @@ extern "C" { //----------------------------------------------------- static void PyBaseFieldSource_del(pyORBIT_Object* self){ //std::cerr<<"The PyBaseFieldSource __del__ has been called!"<cpp_obj, (PyObject*) self); delete ((PyBaseFieldSource*)self->cpp_obj); self->ob_base.ob_type->tp_free((PyObject*)self); } diff --git a/src/utils/wrap_py_base_field_source.hh b/src/utils/wrap_py_base_field_source.hh index b0d17767..330ac517 100644 --- a/src/utils/wrap_py_base_field_source.hh +++ b/src/utils/wrap_py_base_field_source.hh @@ -1,7 +1,7 @@ #ifndef WRAP_UTILS_PY_BASE_FILELD_SOURCE_H #define WRAP_UTILS_PY_BASE_FILELD_SOURCE_H -#include "Python.h" +#include #ifdef __cplusplus extern "C" { diff --git a/src/utils/wrap_random.cc b/src/utils/wrap_random.cc index 94e41b0d..5c19e455 100644 --- a/src/utils/wrap_random.cc +++ b/src/utils/wrap_random.cc @@ -1,12 +1,12 @@ -#include "orbit_mpi.hh" -#include "pyORBIT_Object.hh" +#include "mpi/orbit_mpi.hh" +#include "main/pyORBIT_Object.hh" -#include "wrap_utils.hh" +#include "utils/wrap_utils.hh" #include #include -#include "Random.hh" +#include "utils/Random.hh" using namespace OrbitUtils; using namespace wrap_orbit_utils; diff --git a/src/utils/wrap_random.hh b/src/utils/wrap_random.hh index 3e7f14f6..abee30de 100644 --- a/src/utils/wrap_random.hh +++ b/src/utils/wrap_random.hh @@ -2,7 +2,7 @@ #define WRAP_ORBIT_UTILS_RANDOM_HH_ -#include "Python.h" +#include #ifdef __cplusplus extern "C" { diff --git a/src/utils/wrap_splinech.cc b/src/utils/wrap_splinech.cc index 90742fc3..fd61464c 100644 --- a/src/utils/wrap_splinech.cc +++ b/src/utils/wrap_splinech.cc @@ -1,13 +1,13 @@ -#include "orbit_mpi.hh" -#include "pyORBIT_Object.hh" +#include "mpi/orbit_mpi.hh" +#include "main/pyORBIT_Object.hh" -#include "wrap_utils.hh" -#include "wrap_function.hh" +#include "utils/wrap_utils.hh" +#include "utils/wrap_function.hh" #include #include -#include "OU_SplineCH.hh" +#include "utils/OU_SplineCH.hh" using namespace OrbitUtils; using namespace wrap_orbit_utils; @@ -34,7 +34,6 @@ extern "C" { /** This is implementation of the __init__ method */ static int SplineCH_init(pyORBIT_Object *self, PyObject *args, PyObject *kwds){ self->cpp_obj = new SplineCH(); - ((SplineCH*) self->cpp_obj)->setPyWrapper((PyObject*) self); return 0; } diff --git a/src/utils/wrap_splinech.hh b/src/utils/wrap_splinech.hh index e9289340..97e14cab 100644 --- a/src/utils/wrap_splinech.hh +++ b/src/utils/wrap_splinech.hh @@ -2,7 +2,7 @@ #define WRAP_ORBIT_UTILS_SPLINE_CH_HH_ -#include "Python.h" +#include #ifdef __cplusplus extern "C" { diff --git a/src/utils/wrap_utils.cc b/src/utils/wrap_utils.cc index 820976a1..82b6dcb1 100644 --- a/src/utils/wrap_utils.cc +++ b/src/utils/wrap_utils.cc @@ -1,20 +1,20 @@ -#include "orbit_mpi.hh" +#include "mpi/orbit_mpi.hh" -#include "wrap_utils.hh" -#include "wrap_matrix.hh" -#include "wrap_phase_vector.hh" -#include "wrap_py_base_field_source.hh" -#include "wrap_field_source_container.hh" -#include "wrap_function.hh" -#include "wrap_splinech.hh" -#include "wrap_statmoments2d.hh" -#include "wrap_bunch_extrema_calculator.hh" -#include "wrap_gauss_legendre_integrator.hh" -#include "wrap_polynomial.hh" -#include "wrap_numrecipes.hh" -#include "wrap_bunch_utils_functions.hh" -#include "wrap_harmonic_data.hh" -#include "wrap_random.hh" +#include "utils/wrap_utils.hh" +#include "utils/matrix/wrap_matrix.hh" +#include "utils/matrix/wrap_phase_vector.hh" +#include "utils/wrap_py_base_field_source.hh" +#include "utils/wrap_field_source_container.hh" +#include "utils/wrap_function.hh" +#include "utils/wrap_splinech.hh" +#include "utils/statistics/wrap_statmoments2d.hh" +#include "utils/bunch/wrap_bunch_extrema_calculator.hh" +#include "utils/integration/wrap_gauss_legendre_integrator.hh" +#include "utils/polynomial/wrap_polynomial.hh" +#include "utils/wrap_numrecipes.hh" +#include "utils/bunch/wrap_bunch_utils_functions.hh" +#include "utils/harmonic_analysis/wrap_harmonic_data.hh" +#include "utils/wrap_random.hh" //#include "wrap_field_sources_module.hh" namespace wrap_orbit_utils{ @@ -58,15 +58,6 @@ extern "C" { return module; } - PyObject* getOrbitUtilsType(const char* name){ - PyObject* mod = PyImport_ImportModule(const_cast("orbit.core.orbit_utils")); - PyObject* pyType = PyObject_GetAttrString(mod,name); - Py_DECREF(mod); - Py_DECREF(pyType); - return pyType; - } - - #ifdef __cplusplus } #endif diff --git a/src/utils/wrap_utils.hh b/src/utils/wrap_utils.hh index 291799a4..04ed7fc7 100644 --- a/src/utils/wrap_utils.hh +++ b/src/utils/wrap_utils.hh @@ -1,7 +1,7 @@ #ifndef WRAP_ORBIT_UTILS_H #define WRAP_ORBIT_UTILS_H -#include "Python.h" +#include #ifdef __cplusplus extern "C" {