@@ -2620,26 +2620,34 @@ void init_elements(py::module& m)
26202620 " transfer_map" ,
26212621 [](
26222622 KnownElementsList &v,
2623- RefPart const & ref,
2623+ RefPart ref, // note: intentional copy
26242624 std::string order,
26252625 bool fallback_identity_map
26262626 )
26272627 {
26282628 if (order != " linear" ) {
26292629 throw std::runtime_error (" So far, only the calculation of linear transfer maps are supported in this function." );
26302630 }
2631- Map6x6 result = Map6x6::Identity ();
2632- for (auto & el_v : v) {
2633- std::visit ([&result, &ref, &fallback_identity_map](auto const & el) {
2631+ Map6x6 linear_transfer_map = Map6x6::Identity ();
2632+ for (auto & el_v : v)
2633+ {
2634+ // advance reference particle
2635+ std::visit ([&ref](auto && el) {
2636+ el (ref);
2637+ }, el_v);
2638+
2639+ // extract element transport map, handle fallback
2640+ Map6x6 element_transport_map = Map6x6::Identity ();
2641+ std::visit ([&linear_transfer_map, &ref, &fallback_identity_map, &element_transport_map](auto const & el) {
26342642 using Element = std::decay_t <decltype (el)>;
26352643 std::string not_impl_msg = " Undefined transfer map in lattice for element " ;
26362644 if (el.has_name ()) not_impl_msg += el.name () + " " ;
26372645 not_impl_msg += std::string (" of type " ) + Element::type;
26382646
26392647 if constexpr (std::is_base_of_v<elements::mixin::LinearTransport<Element>, Element>) {
26402648 try {
2641- result = result * el.transport_map (ref);
2642- } catch (std::exception const & e ) {
2649+ element_transport_map = el.transport_map (ref);
2650+ } catch (std::exception const &) {
26432651 if (!fallback_identity_map) {
26442652 throw std::runtime_error (not_impl_msg);
26452653 }
@@ -2650,8 +2658,13 @@ void init_elements(py::module& m)
26502658 }
26512659 }
26522660 }, el_v);
2661+
2662+ // advance linear transfer map
2663+ linear_transfer_map = linear_transfer_map * element_transport_map;
2664+ // TODO: shorthand needs https://github.com/AMReX-Codes/amrex/pull/4880 from AMReX 26.02+
2665+ // result *= element_transport_map;
26532666 }
2654- return result ;
2667+ return linear_transfer_map ;
26552668 },
26562669 py::arg (" ref" ),
26572670 py::arg (" order" ) = " linear" ,
0 commit comments