-
Notifications
You must be signed in to change notification settings - Fork 23
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
12 changed files
with
317 additions
and
33 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
/* Copyright 2022 The Regents of the University of California, through Lawrence | ||
* Berkeley National Laboratory (subject to receipt of any required | ||
* approvals from the U.S. Dept. of Energy). All rights reserved. | ||
* | ||
* This file is part of ImpactX. | ||
* | ||
* Authors: Axel Huebl | ||
* License: BSD-3-Clause-LBNL | ||
*/ | ||
#ifndef IMPACTX_NONE_H | ||
#define IMPACTX_NONE_H | ||
|
||
#include "particles/ImpactXParticleContainer.H" | ||
|
||
#include <AMReX_Extension.H> | ||
#include <AMReX_REAL.H> | ||
|
||
|
||
namespace impactx | ||
{ | ||
struct None | ||
{ | ||
using PType = ImpactXParticleContainer::ParticleType; | ||
|
||
/** This element does nothing. | ||
*/ | ||
None () | ||
{ | ||
} | ||
|
||
/** Does nothing to a particle. | ||
* | ||
* @param p Particle AoS data for positions and cpu/id | ||
* @param px particle momentum in x | ||
* @param py particle momentum in y | ||
* @param pt particle momentum in t | ||
* @param refpart reference particle | ||
*/ | ||
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE | ||
void operator() ( | ||
[[maybe_unused]] PType& AMREX_RESTRICT p, | ||
[[maybe_unused]] amrex::ParticleReal & AMREX_RESTRICT px, | ||
[[maybe_unused]] amrex::ParticleReal & AMREX_RESTRICT py, | ||
[[maybe_unused]] amrex::ParticleReal & AMREX_RESTRICT pt, | ||
[[maybe_unused]] RefPart const refpart) const | ||
{ | ||
// nothing to do | ||
} | ||
|
||
|
||
/** This pushes the reference particle. | ||
* | ||
* @param[in,out] refpart reference particle | ||
*/ | ||
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE | ||
void operator() ( | ||
[[maybe_unused]] RefPart & AMREX_RESTRICT refpart) const { | ||
|
||
// nothing to do: this is a zero-length element | ||
|
||
} | ||
|
||
}; | ||
|
||
} // namespace impactx | ||
|
||
#endif // IMPACTX_NONE_H |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,5 +4,6 @@ | |
# | ||
target_sources(pyImpactX | ||
PRIVATE | ||
elements.cpp | ||
ImpactX.cpp | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,116 @@ | ||
/* Copyright 2021-2022 The ImpactX Community | ||
* | ||
* Authors: Axel Huebl | ||
* License: BSD-3-Clause-LBNL | ||
*/ | ||
#include "pyImpactX.H" | ||
|
||
#include <particles/elements/All.H> | ||
#include <AMReX.H> | ||
|
||
namespace py = pybind11; | ||
using namespace impactx; | ||
|
||
|
||
void init_elements(py::module& m) | ||
{ | ||
py::module_ me = m.def_submodule( | ||
"elements", | ||
"Accelerator lattice elements in ImpactX" | ||
); | ||
|
||
using KnownElementsList = std::list<KnownElements>; | ||
py::class_<KnownElementsList> kel(me, "KnownElementsList"); | ||
kel | ||
.def(py::init<>()) | ||
.def(py::init<KnownElements>()) | ||
.def(py::init([](py::list l){ | ||
auto v = new KnownElementsList; | ||
for (auto &handle : l) | ||
v->push_back(handle.cast<KnownElements>()); | ||
return v; | ||
})) | ||
|
||
.def("append", [](KnownElementsList &v, KnownElements el) { v.emplace_back(el); }) | ||
|
||
.def("extend", [](KnownElementsList &v, KnownElementsList l) { | ||
for (auto &el : l) | ||
v.push_back(el); | ||
return v; | ||
}) | ||
.def("extend", [](KnownElementsList &v, py::list l) { | ||
for (auto &handle : l) | ||
{ | ||
auto el = handle.cast<KnownElements>(); | ||
v.push_back(el); | ||
} | ||
return v; | ||
}) | ||
|
||
.def("clear", &KnownElementsList::clear) | ||
.def("pop_back", &KnownElementsList::pop_back) | ||
.def("__len__", [](const KnownElementsList &v) { return v.size(); }) | ||
.def("__iter__", [](KnownElementsList &v) { | ||
return py::make_iterator(v.begin(), v.end()); | ||
}, py::keep_alive<0, 1>()) /* Keep list alive while iterator is used */ | ||
; | ||
|
||
py::class_<ConstF>(me, "ConstF") | ||
.def(py::init< | ||
amrex::ParticleReal const, | ||
amrex::ParticleReal const, | ||
amrex::ParticleReal const, | ||
amrex::ParticleReal const>(), | ||
py::arg("ds"), py::arg("kx"), py::arg("ky"), py::arg("kt") | ||
); | ||
|
||
py::class_<DipEdge>(me, "DipEdge") | ||
.def(py::init< | ||
amrex::ParticleReal const, | ||
amrex::ParticleReal const, | ||
amrex::ParticleReal const, | ||
amrex::ParticleReal const>(), | ||
py::arg("psi"), py::arg("rc"), py::arg("g"), py::arg("K2") | ||
); | ||
|
||
py::class_<Drift>(me, "Drift") | ||
.def(py::init<amrex::ParticleReal const>(), | ||
py::arg("ds") | ||
); | ||
|
||
py::class_<Multipole>(me, "Multipole") | ||
.def(py::init< | ||
int const, | ||
amrex::ParticleReal const, | ||
amrex::ParticleReal const>(), | ||
py::arg("multiple"), py::arg("K_normal"), py::arg("K_skew") | ||
); | ||
|
||
py::class_<NonlinearLens>(me, "NonlinearLens") | ||
.def(py::init< | ||
amrex::ParticleReal const, | ||
amrex::ParticleReal const>(), | ||
py::arg("knll"), py::arg("cnll") | ||
); | ||
|
||
py::class_<Sbend>(me, "Sbend") | ||
.def(py::init< | ||
amrex::ParticleReal const, | ||
amrex::ParticleReal const>(), | ||
py::arg("ds"), py::arg("rc") | ||
); | ||
|
||
py::class_<ShortRF>(me, "ShortRF") | ||
.def(py::init< | ||
amrex::ParticleReal const, | ||
amrex::ParticleReal const>(), | ||
py::arg("V"), py::arg("k") | ||
); | ||
|
||
py::class_<Quad>(me, "Quad") | ||
.def(py::init< | ||
amrex::ParticleReal const, | ||
amrex::ParticleReal const>(), | ||
py::arg("ds"), py::arg("k") | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
/* Copyright 2021-2022 The ImpactX Community | ||
* | ||
* This header is used to centrally define classes that shall not violate the | ||
* C++ one-definition-rule (ODR) for various Python translation units. | ||
* | ||
* Authors: Axel Huebl | ||
* License: BSD-3-Clause-LBNL | ||
*/ | ||
#include <pybind11/pybind11.h> | ||
#include <pybind11/stl.h> | ||
#include <pybind11/stl_bind.h> | ||
#include <pybind11/functional.h> | ||
|
||
#include <particles/elements/All.H> | ||
|
||
#include <list> | ||
|
||
namespace py = pybind11; | ||
using namespace impactx; | ||
|
||
PYBIND11_MAKE_OPAQUE(std::list<KnownElements>) |
Oops, something went wrong.