@@ -784,7 +784,7 @@ end subroutine set_particle_scalar_attribute_from_python
784784 ! ! specified in the string func at that location.
785785 subroutine set_particle_scalar_attribute_from_python_fields (particle_list , state , positions , lcoords , ele , natt , &
786786 attributes , old_attr_names , old_attr_counts , old_attr_Dims , old_attributes , field_names , field_counts , old_field_names , &
787- old_field_counts , func , time , dt , is_array )
787+ old_field_counts , func , time , dt , is_array , first_newly_init_part )
788788 ! ! Particle list for which to evaluate the function
789789 type (detector_linked_list), intent (in ) :: particle_list
790790 ! ! Model state structure
@@ -828,6 +828,8 @@ subroutine set_particle_scalar_attribute_from_python_fields(particle_list, state
828828 real , intent (in ) :: dt
829829 ! ! Whether this is an array-valued attribute
830830 logical , intent (in ) :: is_array
831+ ! > Pointer to the first newly initialised particle
832+ type (detector_type), pointer , optional :: first_newly_init_part
831833
832834 ! locals
833835 integer :: i
@@ -864,7 +866,12 @@ subroutine set_particle_scalar_attribute_from_python_fields(particle_list, state
864866 field_vals, dim)
865867
866868 ! copy old fields off particles
867- particle = > particle_list% first
869+ if (present (first_newly_init_part)) then
870+ particle = > first_newly_init_part
871+ else
872+ particle = > particle_list% first
873+ end if
874+
868875 do i = 1 , nparts
869876 old_field_vals(:,i) = particle% old_fields(:)
870877 particle = > particle% next
@@ -874,9 +881,9 @@ subroutine set_particle_scalar_attribute_from_python_fields(particle_list, state
874881 lvx, lvy, lvz, time, dt, field_counts, field_names, field_vals, old_field_counts, old_field_names, &
875882 old_field_vals, old_attr_counts, old_attr_names, old_attr_dims, old_attributes, is_array, attributes, stat)
876883 if (stat/= 0 ) then
877- ewrite(- 1 , * ) " Python error, Python string was:"
878- ewrite(- 1 , * ) trim (func)
879- FLExit(" Dying" )
884+ ewrite(- 1 , * ) " Python error, Python string was:"
885+ ewrite(- 1 , * ) trim (func)
886+ FLExit(" Dying" )
880887 end if
881888
882889 deallocate (field_vals)
@@ -943,7 +950,7 @@ end subroutine set_particle_vector_attribute_from_python
943950 ! ! specified in the string func at that location.
944951 subroutine set_particle_vector_attribute_from_python_fields (particle_list , state , positions , lcoords , ele , natt , &
945952 attributes , old_attr_names , old_attr_counts , old_attr_dims , old_attributes , field_names , field_counts , old_field_names , &
946- old_field_counts , func , time , dt , is_array )
953+ old_field_counts , func , time , dt , is_array , first_newly_init_part )
947954 ! ! Particle list for which to evaluate the function
948955 type (detector_linked_list), intent (in ) :: particle_list
949956 ! ! Model state structure
@@ -987,6 +994,8 @@ subroutine set_particle_vector_attribute_from_python_fields(particle_list, state
987994 real , intent (in ) :: dt
988995 ! ! Whether this is an array-valued attribute
989996 logical , intent (in ) :: is_array
997+ ! > Pointer to the first newly initialised particle
998+ type (detector_type), pointer , optional :: first_newly_init_part
990999
9911000 ! locals
9921001 integer :: i
@@ -1023,7 +1032,12 @@ subroutine set_particle_vector_attribute_from_python_fields(particle_list, state
10231032 field_vals, dim)
10241033
10251034 ! copy old fields off particles
1026- particle = > particle_list% first
1035+ if (present (first_newly_init_part)) then
1036+ particle = > first_newly_init_part
1037+ else
1038+ particle = > particle_list% first
1039+ end if
1040+
10271041 do i = 1 , nparts
10281042 old_field_vals(:,i) = particle% old_fields(:)
10291043 particle = > particle% next
@@ -1109,7 +1123,7 @@ end subroutine set_particle_tensor_attribute_from_python
11091123 ! ! specified in the string func at that location.
11101124 subroutine set_particle_tensor_attribute_from_python_fields (particle_list , state , positions , lcoords , ele , natt , &
11111125 attributes , old_attr_names , old_attr_counts , old_attr_dims , old_attributes , field_names , field_counts , old_field_names , &
1112- old_field_counts , func , time , dt , is_array )
1126+ old_field_counts , func , time , dt , is_array , first_newly_init_part )
11131127 ! ! Particle list for which to evaluate the function
11141128 type (detector_linked_list), intent (in ) :: particle_list
11151129 ! ! Model state structure
@@ -1153,6 +1167,8 @@ subroutine set_particle_tensor_attribute_from_python_fields(particle_list, state
11531167 real , intent (in ) :: dt
11541168 ! ! Whether this is an array-valued attribute
11551169 logical , intent (in ) :: is_array
1170+ ! > Pointer to the first newly initialised particle
1171+ type (detector_type), pointer , optional :: first_newly_init_part
11561172
11571173 ! locals
11581174 integer :: i
@@ -1190,7 +1206,12 @@ subroutine set_particle_tensor_attribute_from_python_fields(particle_list, state
11901206 field_vals, dim)
11911207
11921208 ! copy old fields off particles
1193- particle = > particle_list% first
1209+ if (present (first_newly_init_part)) then
1210+ particle = > first_newly_init_part
1211+ else
1212+ particle = > particle_list% first
1213+ end if
1214+
11941215 do i = 1 , nparts
11951216 old_field_vals(:,i) = particle% old_fields(:)
11961217 particle = > particle% next
0 commit comments