LST_calc_variances_periodic_avg.F90 26.2 KB
Newer Older
Femi Kadri's avatar
Femi Kadri committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40
SUBROUTINE LST_calc_variances_periodic_avg(&
& My_MPI_Process_ID,&
& LST_time_step_number,&
& include_nonbrownian_LST_markers,&
& LST_marker_ID,&
& LST_marker_loop_index,&
& LST_marker_old_position_x,&
& LST_marker_old_position_y,&
& LST_marker_old_position_z,&
& total_number_of_LST_rxn_bins,&
& global_var_abs_lagrangian_pos_x,&
& global_var_abs_lagrangian_pos_y,&
& global_var_abs_lagrangian_pos_z,&
& global_var_abs_init_position_x,&
& global_var_abs_init_position_y,&
& global_var_abs_init_position_z,&
& periodic_marker_old_position_x,&
& periodic_marker_old_position_y,&
& periodic_marker_old_position_z,&
& global_avg_absolute_position_x,&
& global_avg_absolute_position_y,&
& global_avg_absolute_position_z,&
& tot_plus_nonbrownian_lattice_dim,&
& transient_reacted_average,&
& total_number_of_LST_markers,&
& LST_marker_reacted_probability,&
& tot_num_LST_markers_lattice_dim,&
& LST_reaction_bins_max_bounds,&
& global_avg_periodic_position_x,&
& global_avg_periodic_position_y,&
& global_avg_periodic_position_z,&
& global_var_absolute_position_x,&
& global_var_absolute_position_y,&
& global_var_absolute_position_z,&
& global_mean_square_disp_mean_pos,&
& global_mean_square_disp_init_pos,&
& global_mean_square_disp_lagrang,&
& marker_in_this_PRD_rxn_bin_exist,&
& old_time_step,&
& initial_LST_marker_positions_lu,&
Femi Kadri's avatar
Femi Kadri committed
41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59
& LST_marker_ID_times_three,&
& LST_marker_old_pos_in_VOLUMEMASK,&
& global_MSD_mean_pos_VOLUME_MASK,&
& global_MSD_init_pos_VOLUME_MASK,&
& global_MSD_lagrang_VOLUME_MASK,&
& global_var_absolute_pos_VOLMSK_x,&
& global_var_absolute_pos_VOLMSK_y,&
& global_var_absolute_pos_VOLMSK_z,&
& global_var_abs_init_pos_VOLMSK_x,&
& global_var_abs_init_pos_VOLMSK_y,&
& global_var_abs_init_pos_VOLMSK_z,&
& global_var_abs_lagr_pos_VOLMSK_x,&
& global_var_abs_lagr_pos_VOLMSK_y,&
& global_var_abs_lagr_pos_VOLMSK_z,&
& global_avg_abs_pos_VOLUME_MASK_x,&
& global_avg_abs_pos_VOLUME_MASK_y,&
& global_avg_abs_pos_VOLUME_MASK_z,&
& cartesian_communicator,&
& LST_Current_Step,&
Femi Kadri's avatar
Femi Kadri committed
60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76
& LST_marker_old_pos_passed_exit_x)

USE debug_module


	IMPLICIT NONE

	!-----------INTENT(IN)------------------------------------------
	INTEGER,INTENT(IN) :: My_MPI_Process_ID
	INTEGER,INTENT(IN) :: LST_time_step_number
	INTEGER,INTENT(IN) :: LST_marker_ID
	INTEGER,INTENT(IN) :: LST_marker_loop_index
	INTEGER,INTENT(IN) :: total_number_of_LST_rxn_bins
	INTEGER,INTENT(IN) :: tot_plus_nonbrownian_lattice_dim
	INTEGER,INTENT(IN) :: total_number_of_LST_markers
	INTEGER,INTENT(IN) :: tot_num_LST_markers_lattice_dim
	INTEGER,INTENT(IN) :: old_time_step
Femi Kadri's avatar
Femi Kadri committed
77 78
	INTEGER,INTENT(IN) :: LST_marker_ID_times_three
	INTEGER,INTENT(IN) :: cartesian_communicator
Femi Kadri's avatar
Femi Kadri committed
79 80 81 82 83 84 85 86 87 88 89 90 91 92 93
	INTEGER,INTENT(IN) :: LST_Current_Step

	REAL,INTENT(IN)    :: LST_marker_old_position_x
	REAL,INTENT(IN)    :: LST_marker_old_position_y
	REAL,INTENT(IN)    :: LST_marker_old_position_z
	REAL,INTENT(IN)    :: periodic_marker_old_position_x
	REAL,INTENT(IN)    :: periodic_marker_old_position_y
	REAL,INTENT(IN)    :: periodic_marker_old_position_z

	REAL,INTENT(IN)    :: LST_reaction_bins_max_bounds(0:total_number_of_LST_rxn_bins+1)

	REAL,DIMENSION(tot_plus_nonbrownian_lattice_dim) :: global_position_recieve_buffer

	REAL,INTENT(IN),DIMENSION(0:total_number_of_LST_rxn_bins+1) :: global_avg_absolute_position_x
	REAL,INTENT(IN),DIMENSION(0:total_number_of_LST_rxn_bins+1) :: global_avg_absolute_position_y
Femi Kadri's avatar
Femi Kadri committed
94 95 96 97
	REAL,INTENT(IN),DIMENSION(0:total_number_of_LST_rxn_bins+1) :: global_avg_absolute_position_z

	REAL,INTENT(IN),DIMENSION(0:total_number_of_LST_rxn_bins+1) :: global_avg_abs_pos_VOLUME_MASK_x
	REAL,INTENT(IN),DIMENSION(0:total_number_of_LST_rxn_bins+1) :: global_avg_abs_pos_VOLUME_MASK_y
Femi Kadri's avatar
Femi Kadri committed
98 99 100 101
	REAL,INTENT(IN),DIMENSION(0:total_number_of_LST_rxn_bins+1) :: global_avg_abs_pos_VOLUME_MASK_z

	REAL,INTENT(IN),DIMENSION(0:1,total_number_of_LST_markers) :: LST_marker_reacted_probability

Femi Kadri's avatar
Femi Kadri committed
102
	REAL,INTENT(IN),DIMENSION(tot_num_LST_markers_lattice_dim) :: initial_LST_marker_positions_lu
Femi Kadri's avatar
Femi Kadri committed
103 104 105 106 107 108 109 110
	LOGICAL*4,INTENT(IN) :: LST_marker_old_pos_passed_exit_x
	LOGICAL,INTENT(IN) :: include_nonbrownian_LST_markers,LST_marker_old_pos_in_VOLUMEMASK
	LOGICAL*4,INTENT(IN) :: marker_in_this_PRD_rxn_bin_exist(0:total_number_of_LST_rxn_bins+1)
	LOGICAL*4,PARAMETER :: debug = GLOBAL_DEBUG
	!-----------INTENT(OUT)------------------------------------------
	!-----------INTENT(INOUT)------------------------------------------	
	REAL,INTENT(INOUT),DIMENSION(0:total_number_of_LST_rxn_bins+1) :: global_var_abs_lagrangian_pos_x
	REAL,INTENT(INOUT),DIMENSION(0:total_number_of_LST_rxn_bins+1) :: global_var_abs_lagrangian_pos_y
Femi Kadri's avatar
Femi Kadri committed
111 112 113 114
	REAL,INTENT(INOUT),DIMENSION(0:total_number_of_LST_rxn_bins+1) :: global_var_abs_lagrangian_pos_z

	REAL,INTENT(INOUT),DIMENSION(0:total_number_of_LST_rxn_bins+1) :: global_var_abs_lagr_pos_VOLMSK_x
	REAL,INTENT(INOUT),DIMENSION(0:total_number_of_LST_rxn_bins+1) :: global_var_abs_lagr_pos_VOLMSK_y
Femi Kadri's avatar
Femi Kadri committed
115 116 117 118
	REAL,INTENT(INOUT),DIMENSION(0:total_number_of_LST_rxn_bins+1) :: global_var_abs_lagr_pos_VOLMSK_z

	REAL,INTENT(INOUT),DIMENSION(0:total_number_of_LST_rxn_bins+1) :: global_var_abs_init_position_x
	REAL,INTENT(INOUT),DIMENSION(0:total_number_of_LST_rxn_bins+1) :: global_var_abs_init_position_y
Femi Kadri's avatar
Femi Kadri committed
119 120 121 122
	REAL,INTENT(INOUT),DIMENSION(0:total_number_of_LST_rxn_bins+1) :: global_var_abs_init_position_z

	REAL,INTENT(INOUT),DIMENSION(0:total_number_of_LST_rxn_bins+1) :: global_var_abs_init_pos_VOLMSK_x
	REAL,INTENT(INOUT),DIMENSION(0:total_number_of_LST_rxn_bins+1) :: global_var_abs_init_pos_VOLMSK_y
Femi Kadri's avatar
Femi Kadri committed
123 124 125 126 127 128 129 130
	REAL,INTENT(INOUT),DIMENSION(0:total_number_of_LST_rxn_bins+1) :: global_var_abs_init_pos_VOLMSK_z

	REAL,INTENT(INOUT),DIMENSION(0:total_number_of_LST_rxn_bins+1) :: global_avg_periodic_position_x
	REAL,INTENT(INOUT),DIMENSION(0:total_number_of_LST_rxn_bins+1) :: global_avg_periodic_position_y
	REAL,INTENT(INOUT),DIMENSION(0:total_number_of_LST_rxn_bins+1) :: global_avg_periodic_position_z

	REAL,INTENT(INOUT),DIMENSION(0:total_number_of_LST_rxn_bins+1) :: global_var_absolute_position_x
	REAL,INTENT(INOUT),DIMENSION(0:total_number_of_LST_rxn_bins+1) :: global_var_absolute_position_y
Femi Kadri's avatar
Femi Kadri committed
131 132 133 134
	REAL,INTENT(INOUT),DIMENSION(0:total_number_of_LST_rxn_bins+1) :: global_var_absolute_position_z

	REAL,INTENT(INOUT),DIMENSION(0:total_number_of_LST_rxn_bins+1) :: global_var_absolute_pos_VOLMSK_x
	REAL,INTENT(INOUT),DIMENSION(0:total_number_of_LST_rxn_bins+1) :: global_var_absolute_pos_VOLMSK_y
Femi Kadri's avatar
Femi Kadri committed
135 136 137 138
	REAL,INTENT(INOUT),DIMENSION(0:total_number_of_LST_rxn_bins+1) :: global_var_absolute_pos_VOLMSK_z

	REAL,INTENT(INOUT),DIMENSION(0:total_number_of_LST_rxn_bins+1) :: global_mean_square_disp_mean_pos
	REAL,INTENT(INOUT),DIMENSION(0:total_number_of_LST_rxn_bins+1) :: global_mean_square_disp_init_pos
Femi Kadri's avatar
Femi Kadri committed
139 140 141 142
	REAL,INTENT(INOUT),DIMENSION(0:total_number_of_LST_rxn_bins+1) :: global_mean_square_disp_lagrang

	REAL,INTENT(INOUT),DIMENSION(0:total_number_of_LST_rxn_bins+1) :: global_MSD_mean_pos_VOLUME_MASK
	REAL,INTENT(INOUT),DIMENSION(0:total_number_of_LST_rxn_bins+1) :: global_MSD_init_pos_VOLUME_MASK
Femi Kadri's avatar
Femi Kadri committed
143 144 145 146
	REAL,INTENT(INOUT),DIMENSION(0:total_number_of_LST_rxn_bins+1) :: global_MSD_lagrang_VOLUME_MASK

	REAL,INTENT(INOUT) :: transient_reacted_average
	!-----------NO INTENT------------------------------------------
Femi Kadri's avatar
Femi Kadri committed
147
	INTEGER :: LST_reaction_bin_number
Femi Kadri's avatar
Femi Kadri committed
148 149 150 151
!	INTEGER :: mpi_abort_error,mpi_error_code
	REAL :: LST_marker_old_pos_nonbrownian_x,LST_marker_old_pos_nonbrownian_y,LST_marker_old_pos_nonbrownian_z
	REAL :: LST_lagrang_old_pos_disp_x_sqrd,LST_lagrang_old_pos_disp_y_sqrd,LST_lagrang_old_pos_disp_z_sqrd
	REAL :: LST_marker_old_pos_disp_x_sqrd,LST_marker_old_pos_disp_y_sqrd,LST_marker_old_pos_disp_z_sqrd
Femi Kadri's avatar
Femi Kadri committed
152
	REAL :: LST_mean_old_pos_disp_x_sqrd,LST_mean_old_pos_disp_y_sqrd,LST_mean_old_pos_disp_z_sqrd
Femi Kadri's avatar
Femi Kadri committed
153 154 155 156 157
	REAL :: LST_avg_old_pos_disp_sq_VOLMSK_x,LST_avg_old_pos_disp_sq_VOLMSK_y,LST_avg_old_pos_disp_sq_VOLMSK_z

	REAL :: LST_marker_old_pos_x_minus_mean,LST_marker_old_pos_y_minus_mean,LST_marker_old_pos_z_minus_mean
	REAL :: LST_marker_old_pos_x_minus_conv,LST_marker_old_pos_y_minus_conv,LST_marker_old_pos_z_minus_conv
	REAL :: LST_marker_old_pos_x_minus_init,LST_marker_old_pos_y_minus_init,LST_marker_old_pos_z_minus_init
Femi Kadri's avatar
Femi Kadri committed
158 159

	REAL :: LST_old_pos_x_minus_mean_VOLMASK,LST_old_pos_y_minus_mean_VOLMASK,LST_old_pos_z_minus_mean_VOLMASK
Femi Kadri's avatar
Femi Kadri committed
160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269

	REAL :: LST_reaction_bin_LOWER_bound


	IF(debug) WRITE (0,*) My_MPI_Process_ID,'entered SUBROUTINE LST_calc_variances_periodic_avg',LST_time_step_number
	IF(debug) WRITE (9,*) My_MPI_Process_ID,'entered SUBROUTINE LST_calc_variances_periodic_avg',LST_time_step_number

	!RETRIEVE GOOD POSITIONS, WHICH WERE ALLGATHERED AT THE END OF THE LAST TIME STEP
				
	IF(include_nonbrownian_LST_markers) THEN  !ALSO RETRIEVE THE NONBROWNIAN MARKER POSITIONS IF PRESENT
				 
		!FIGURE OUT THE CORRESPONDING NONBROWNIAN MARKER ID, ASSUMING THAT THEY'VE BEEN SORTED 
		LST_marker_old_pos_nonbrownian_x = global_position_recieve_buffer(LST_marker_loop_index &
		& + tot_num_LST_markers_lattice_dim)
		LST_marker_old_pos_nonbrownian_y = global_position_recieve_buffer(LST_marker_loop_index + 1 &
		& + tot_num_LST_markers_lattice_dim ) 
		LST_marker_old_pos_nonbrownian_z = global_position_recieve_buffer(LST_marker_loop_index + 2 &
		& + tot_num_LST_markers_lattice_dim )

		IF(debug) WRITE (9,*) 'LST_marker_ID',&
		& LST_marker_ID,'LST_marker_old_pos_nonbrownian_x',LST_marker_old_pos_nonbrownian_x
		IF(debug) WRITE (9,*) 'LST_marker_ID',&
		& LST_marker_ID,'LST_marker_old_pos_nonbrownian_y',LST_marker_old_pos_nonbrownian_y
		IF(debug) WRITE (9,*) 'LST_marker_ID',&
		& LST_marker_ID,'LST_marker_old_pos_nonbrownian_z',LST_marker_old_pos_nonbrownian_z

		IF(debug) WRITE (0,*) 'LST_marker_ID',&
		& LST_marker_ID,'LST_marker_old_pos_nonbrownian_x',LST_marker_old_pos_nonbrownian_x
		IF(debug) WRITE (0,*) 'LST_marker_ID',&
		& LST_marker_ID,'LST_marker_old_pos_nonbrownian_y',LST_marker_old_pos_nonbrownian_y
		IF(debug) WRITE (0,*) 'LST_marker_ID',&
		& LST_marker_ID,'LST_marker_old_pos_nonbrownian_z',LST_marker_old_pos_nonbrownian_z

	ENDIF !! include_nonbrownian_LST_markers

	IF(debug) WRITE (9,*) 'LST_marker_loop_index ',LST_marker_loop_index
	IF(debug) WRITE (9,*) 'LST_marker_ID ',&
	& LST_marker_ID,'LST_marker_old_position_x',LST_marker_old_position_x
	IF(debug) WRITE (9,*) 'LST_marker_ID',&
	& LST_marker_ID,'LST_marker_old_position_y',LST_marker_old_position_y
	IF(debug) WRITE (9,*) 'LST_marker_ID',&
	& LST_marker_ID,'LST_marker_old_position_z',LST_marker_old_position_z

	IF(debug) WRITE (0,*) 'LST_marker_loop_index ',LST_marker_loop_index
	IF(debug) WRITE (0,*) 'LST_marker_ID ',&
	& LST_marker_ID,'LST_marker_old_position_x',LST_marker_old_position_x
	IF(debug) WRITE (0,*) 'LST_marker_ID',&
	& LST_marker_ID,'LST_marker_old_position_y',LST_marker_old_position_y
	IF(debug) WRITE (0,*) 'LST_marker_ID',&
	& LST_marker_ID,'LST_marker_old_position_z',LST_marker_old_position_z




!	global_avg_absolute_position_x = global_avg_absolute_position_x + LST_marker_old_position_x
!	global_avg_absolute_position_y = global_avg_absolute_position_y + LST_marker_old_position_y
!	global_avg_absolute_position_z = global_avg_absolute_position_z + LST_marker_old_position_z

	transient_reacted_average = transient_reacted_average + &
	& LST_marker_reacted_probability(old_time_step,LST_marker_ID)
				
	!CALCULATE global_avg_periodic_position_  X,Y AND Z
	DO LST_reaction_bin_number = 0,total_number_of_LST_rxn_bins+1

		IF(LST_reaction_bin_number.EQ.0) THEN

			LST_reaction_bin_LOWER_bound = 0.0
			!LST_reaction_bin_UPPER_bound = LST_reaction_bins_max_bounds(LST_reaction_bin_number)

		ELSE

			LST_reaction_bin_LOWER_bound = LST_reaction_bins_max_bounds(LST_reaction_bin_number-1)
			!LST_reaction_bin_UPPER_bound = LST_reaction_bins_max_bounds(LST_reaction_bin_number)
					
		ENDIF !! LST_reaction_bin_number.EQ.0

		IF( (LST_marker_reacted_probability(old_time_step,LST_marker_ID).LE.&
		& LST_reaction_bin_LOWER_bound).AND.(marker_in_this_PRD_rxn_bin_exist(LST_reaction_bin_number))   )THEN  !make sure that stats are done for unreacted markers ONLY!

			IF(debug) WRITE (9,*) My_MPI_Process_ID,' time step ',LST_time_step_number,&
			& 'LST_calc_variances_periodic_avg: LST_marker_old_position_x',&
			& global_avg_absolute_position_x(:)
			IF(debug) WRITE (9,*) My_MPI_Process_ID,' time step ',&
			& LST_time_step_number,'LST_calc_variances_periodic_avg: LST_marker_old_position_x',&
			& global_avg_absolute_position_x(:)
						
						
			LST_marker_old_pos_x_minus_mean = &
			& LST_marker_old_position_x - &
			& global_avg_absolute_position_x(LST_reaction_bin_number)
					
			LST_marker_old_pos_x_minus_init = &
			& LST_marker_old_position_x - &
			& initial_LST_marker_positions_lu(LST_marker_ID_times_three - 2)



!			IF(LST_reaction_bin_number.EQ.1) PRINT*,LST_marker_old_position_x,LST_marker_old_pos_x_minus_mean

			IF(debug) WRITE (9,*) My_MPI_Process_ID,' time step ',&
			& LST_time_step_number,&
			& 'LST_calc_variances_periodic_avg: LST_marker_old_pos_x_minus_mean',&
			& LST_marker_old_pos_x_minus_mean
					
			LST_marker_old_pos_y_minus_mean = &
			& LST_marker_old_position_y - &
			& global_avg_absolute_position_y(LST_reaction_bin_number)

			LST_marker_old_pos_y_minus_init = &
			& LST_marker_old_position_y - &
Femi Kadri's avatar
Femi Kadri committed
270 271 272 273 274 275 276 277 278 279
			& initial_LST_marker_positions_lu(LST_marker_ID_times_three - 1)

!			IF(LST_Current_Step.EQ.500.OR.LST_Current_Step.EQ.501) THEN
				
!				WRITE (29,'(3I6.5,2E19.10)') LST_Current_Step,&
!				& LST_reaction_bin_number,&
!				& LST_marker_ID,&
!				& LST_marker_old_position_y,&
!				& initial_LST_marker_positions_lu(LST_marker_ID_times_three - 1)

Femi Kadri's avatar
Femi Kadri committed
280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433
!			ENDIF !! LST_Current_Step

				
			IF(debug) WRITE (9,*) My_MPI_Process_ID,' time step ',&
			& LST_time_step_number,&
			& 'LST_calc_variances_periodic_avg: LST_marker_old_pos_y_minus_mean',&
			& LST_marker_old_pos_y_minus_mean

			LST_marker_old_pos_z_minus_mean = &
			& LST_marker_old_position_z - &
			& global_avg_absolute_position_z(LST_reaction_bin_number)
									
			LST_marker_old_pos_z_minus_init = &
			& LST_marker_old_position_z - &
			& initial_LST_marker_positions_lu(LST_marker_ID_times_three)


			IF(include_nonbrownian_LST_markers) THEN
					
				LST_marker_old_pos_x_minus_conv = &
				& LST_marker_old_position_x - &
				& LST_marker_old_pos_nonbrownian_x
							
				LST_marker_old_pos_y_minus_conv = &
				& LST_marker_old_position_y - &
				& LST_marker_old_pos_nonbrownian_y


				LST_marker_old_pos_z_minus_conv = &
				& LST_marker_old_position_z - &
				& LST_marker_old_pos_nonbrownian_z

			ENDIF !! include_nonbrownian_LST_markers



			IF(debug) WRITE (9,*) My_MPI_Process_ID,' time step ',&
			& LST_time_step_number,&
			& 'LST_calc_variances_periodic_avg: LST_marker_old_pos_z_minus_mean',&
			& LST_marker_old_pos_z_minus_mean
						
			!square displacement relative to mean positions
			LST_mean_old_pos_disp_x_sqrd = LST_marker_old_pos_x_minus_mean &
			& * LST_marker_old_pos_x_minus_mean
			LST_mean_old_pos_disp_y_sqrd = LST_marker_old_pos_y_minus_mean &
			& * LST_marker_old_pos_y_minus_mean
			LST_mean_old_pos_disp_z_sqrd = LST_marker_old_pos_z_minus_mean &
			& * LST_marker_old_pos_z_minus_mean

			!square displacement relative to initial positions
			LST_marker_old_pos_disp_x_sqrd = LST_marker_old_pos_x_minus_init &
			& * LST_marker_old_pos_x_minus_init
			LST_marker_old_pos_disp_y_sqrd = LST_marker_old_pos_y_minus_init &
			& * LST_marker_old_pos_y_minus_init
			LST_marker_old_pos_disp_z_sqrd = LST_marker_old_pos_z_minus_init &
			& * LST_marker_old_pos_z_minus_init
						

			IF(include_nonbrownian_LST_markers) THEN
							
				!lagrangian displacement squared: brownian+conv relative to pure convective
				LST_lagrang_old_pos_disp_x_sqrd = LST_marker_old_pos_x_minus_conv &
				& * LST_marker_old_pos_x_minus_conv
				LST_lagrang_old_pos_disp_y_sqrd = LST_marker_old_pos_y_minus_conv &
				& * LST_marker_old_pos_y_minus_conv
				LST_lagrang_old_pos_disp_z_sqrd = LST_marker_old_pos_z_minus_conv &
				& * LST_marker_old_pos_z_minus_conv

				IF(debug) WRITE (9,*) My_MPI_Process_ID,' time step ',&
				& LST_time_step_number,'LST_lagrang_old_pos_disp_x_sqrd',LST_lagrang_old_pos_disp_x_sqrd
				IF(debug) WRITE (9,*) My_MPI_Process_ID,' time step ',&
				& LST_time_step_number,'LST_lagrang_old_pos_disp_Y_sqrd',LST_lagrang_old_pos_disp_Y_sqrd
				IF(debug) WRITE (9,*) My_MPI_Process_ID,' time step ',&
				& LST_time_step_number,'LST_lagrang_old_pos_disp_Z_sqrd',LST_lagrang_old_pos_disp_Z_sqrd

				IF(debug) WRITE (0,*) My_MPI_Process_ID,' time step ',&
				& LST_time_step_number,'LST_lagrang_old_pos_disp_x_sqrd',LST_lagrang_old_pos_disp_x_sqrd
				IF(debug) WRITE (0,*) My_MPI_Process_ID,' time step ',&
				& LST_time_step_number,'LST_lagrang_old_pos_disp_Y_sqrd',LST_lagrang_old_pos_disp_Y_sqrd
				IF(debug) WRITE (0,*) My_MPI_Process_ID,' time step ',&
				& LST_time_step_number,'LST_lagrang_old_pos_disp_Z_sqrd',LST_lagrang_old_pos_disp_Z_sqrd

			ENDIF !!include_nonbrownian_LST_markers


			!VARIANCE-X RELATIVE TO CURRENT MEAN POSITION
			global_var_absolute_position_x(LST_reaction_bin_number) = &
			& global_var_absolute_position_x(LST_reaction_bin_number) + &
			& LST_mean_old_pos_disp_x_sqrd

			!VARIANCE-X RELATIVE TO INITIAL POSITIONS
			global_var_abs_init_position_x(LST_reaction_bin_number) = &
			& global_var_abs_init_position_x(LST_reaction_bin_number) + &
			& LST_marker_old_pos_disp_x_sqrd
						

			!VARIANCE-Y RELATIVE TO CURRENT MEAN POSITION
			global_var_absolute_position_y(LST_reaction_bin_number) = &
			& global_var_absolute_position_y(LST_reaction_bin_number) + &
			& LST_mean_old_pos_disp_y_sqrd
						
			!VARIANCE-Y RELATIVE TO INITIAL POSITIONS
			global_var_abs_init_position_y(LST_reaction_bin_number) = &
			& global_var_abs_init_position_y(LST_reaction_bin_number) + &
			& LST_marker_old_pos_disp_y_sqrd


			!VARIANCE-Z RELATIVE TO CURRENT MEAN POSITION
			global_var_absolute_position_z(LST_reaction_bin_number) = &
			& global_var_absolute_position_z(LST_reaction_bin_number) + &
			& LST_mean_old_pos_disp_z_sqrd

			!VARIANCE-Z RELATIVE TO INITIAL POSITIONS
			global_var_abs_init_position_z(LST_reaction_bin_number) = &
			& global_var_abs_init_position_z(LST_reaction_bin_number) + &
			& LST_marker_old_pos_disp_z_sqrd



			!MEAN SQUARE DISPLACMENT RELATIVE TO INITIAL POSITIONS
			global_mean_square_disp_mean_pos(LST_reaction_bin_number) = &
			& global_mean_square_disp_mean_pos(LST_reaction_bin_number) + &
			& (LST_mean_old_pos_disp_x_sqrd + LST_mean_old_pos_disp_y_sqrd &
			& + LST_mean_old_pos_disp_z_sqrd )
						
			!MEAN SQUARE DISPLACEMENT RELATIVE TO INITIAL POSITIONS
			global_mean_square_disp_init_pos(LST_reaction_bin_number) = &
			& global_mean_square_disp_init_pos(LST_reaction_bin_number) + &
			& (LST_marker_old_pos_disp_x_sqrd + LST_marker_old_pos_disp_y_sqrd &
			& + LST_marker_old_pos_disp_z_sqrd )

			IF(include_nonbrownian_LST_markers) THEN

				!VARIANCE-X LAGRANGIAN:  BROWNIAN+CONVECTIVE RELATIVE TO PURE CONVECTIVE
				global_var_abs_lagrangian_pos_x(LST_reaction_bin_number) = &
				& global_var_abs_lagrangian_pos_x(LST_reaction_bin_number) + &
				& LST_lagrang_old_pos_disp_x_sqrd

				!VARIANCE-Y LAGRANGIAN:  BROWNIAN+CONVECTIVE RELATIVE TO PURE CONVECTIVE
				global_var_abs_lagrangian_pos_y(LST_reaction_bin_number) = &
				& global_var_abs_lagrangian_pos_y(LST_reaction_bin_number) + &
				& LST_lagrang_old_pos_disp_y_sqrd

				!VARIANCE-Z LAGRANGIAN:  BROWNIAN+CONVECTIVE RELATIVE TO PURE CONVECTIVE
				global_var_abs_lagrangian_pos_z(LST_reaction_bin_number) = &
				& global_var_abs_lagrangian_pos_z(LST_reaction_bin_number) + &
				& LST_lagrang_old_pos_disp_z_sqrd

				!LAGRANGIAN MEAN SQUARE DISPLACEMENT:  BROWNIAN+CONVECTIVE RELATIVE TO PURE CONVECTIVE
				global_mean_square_disp_lagrang(LST_reaction_bin_number) = &
				& global_mean_square_disp_lagrang(LST_reaction_bin_number) + &
				& (LST_lagrang_old_pos_disp_x_sqrd + LST_lagrang_old_pos_disp_y_sqrd &
				& + LST_lagrang_old_pos_disp_z_sqrd )
	
Femi Kadri's avatar
Femi Kadri committed
434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551
			ENDIF !! include_nonbrownian_LST_markers

			IF(LST_marker_old_pos_in_VOLUMEMASK) THEN

				LST_old_pos_x_minus_mean_VOLMASK = &
				& LST_marker_old_position_x - &
				& global_avg_abs_pos_VOLUME_MASK_x(LST_reaction_bin_number)

				LST_old_pos_y_minus_mean_VOLMASK = &
				& LST_marker_old_position_y - &
				& global_avg_abs_pos_VOLUME_MASK_y(LST_reaction_bin_number)

				LST_old_pos_z_minus_mean_VOLMASK = &
				& LST_marker_old_position_z - &
				& global_avg_abs_pos_VOLUME_MASK_z(LST_reaction_bin_number)

				!square displacement relative to mean positions
				LST_avg_old_pos_disp_sq_VOLMSK_x = LST_old_pos_x_minus_mean_VOLMASK &
				& * LST_old_pos_x_minus_mean_VOLMASK
				LST_avg_old_pos_disp_sq_VOLMSK_y = LST_old_pos_y_minus_mean_VOLMASK &
				& * LST_old_pos_y_minus_mean_VOLMASK
				LST_avg_old_pos_disp_sq_VOLMSK_z = LST_old_pos_z_minus_mean_VOLMASK &
				& * LST_old_pos_z_minus_mean_VOLMASK

				!VOLUME MASK VARIANCE-X RELATIVE TO CURRENT MEAN POSITION
				global_var_absolute_pos_VOLMSK_x(LST_reaction_bin_number) = &
				& global_var_absolute_pos_VOLMSK_x(LST_reaction_bin_number) + &
				& LST_avg_old_pos_disp_sq_VOLMSK_x


!				IF(global_var_absolute_pos_VOLMSK_x(LST_reaction_bin_number).NE.&
!				& global_var_absolute_position_x(LST_reaction_bin_number).AND.LST_time_step_number.GT.1) THEN

!					IF(debug) WRITE (0,*) My_MPI_Process_ID,'LST_calc_variances_periodic_avg: ERROR:  MASK VAR NE ALL VAR'
!					IF(debug) WRITE (9,*) My_MPI_Process_ID,'LST_calc_variances_periodic_avg: ERROR:  MASK VAR NE ALL VAR'
!					PRINT*,'LST_calc_variances_periodic_avg: ERROR: MASK VAR NE ALL VAR'

!					PRINT*,'LST_calc_variances_periodic_avg: LST_time_step_number',LST_time_step_number
!					PRINT*,'LST_calc_variances_periodic_avg: LST_reaction_bin_number',LST_reaction_bin_number
!					PRINT*,'LST_calc_variances_periodic_avg: global_var_absolute_pos_VOLMSK_x(LST_reaction_bin_number)',global_var_absolute_pos_VOLMSK_x(LST_reaction_bin_number)
!					PRINT*,'LST_calc_variances_periodic_avg: global_var_absolute_position_x(LST_reaction_bin_number)',global_var_absolute_position_x(LST_reaction_bin_number)

!					PRINT*,'LST_calc_variances_periodic_avg: LST_marker_old_position_x',LST_marker_old_position_x
!					PRINT*,'LST_calc_variances_periodic_avg: global_avg_abs_pos_VOLUME_MASK_x(LST_reaction_bin_number)',global_avg_abs_pos_VOLUME_MASK_x(LST_reaction_bin_number)
					
!					PRINT*,'LST_calc_variances_periodic_avg: global_avg_absolute_position_x(LST_reaction_bin_number)',global_avg_absolute_position_x(LST_reaction_bin_number)

!					CALL MPI_Abort(cartesian_communicator,mpi_abort_error,mpi_error_code)

!				ENDIF !!global_var_absolute_pos_VOLMSK_x(LST_reaction_bin_number).NE.global_var_absolute_position_x(LST_reaction_bin_number)

				!VOLUME MASK VARIANCE-X RELATIVE TO INITIAL POSITIONS
				global_var_abs_init_pos_VOLMSK_x(LST_reaction_bin_number) = &
				& global_var_abs_init_pos_VOLMSK_x(LST_reaction_bin_number) + &
				& LST_marker_old_pos_disp_x_sqrd
						

				!VOLUME MASK VARIANCE-Y RELATIVE TO CURRENT MEAN POSITION
				global_var_absolute_pos_VOLMSK_y(LST_reaction_bin_number) = &
				& global_var_absolute_pos_VOLMSK_y(LST_reaction_bin_number) + &
				& LST_avg_old_pos_disp_sq_VOLMSK_y
						
				!VOLUME MASK VARIANCE-Y RELATIVE TO INITIAL POSITIONS
				global_var_abs_init_pos_VOLMSK_y(LST_reaction_bin_number) = &
				& global_var_abs_init_pos_VOLMSK_y(LST_reaction_bin_number) + &
				& LST_marker_old_pos_disp_y_sqrd


				!VOLUME MASK VARIANCE-Z RELATIVE TO CURRENT MEAN POSITION
				global_var_absolute_pos_VOLMSK_z(LST_reaction_bin_number) = &
				& global_var_absolute_pos_VOLMSK_z(LST_reaction_bin_number) + &
				& LST_avg_old_pos_disp_sq_VOLMSK_z

				!VOLUME MASK VARIANCE-Z RELATIVE TO INITIAL POSITIONS
				global_var_abs_init_pos_VOLMSK_z(LST_reaction_bin_number) = &
				& global_var_abs_init_pos_VOLMSK_z(LST_reaction_bin_number) + &
				& LST_marker_old_pos_disp_z_sqrd

				!-----------MSD-------------
				!VOLUME MASK MEAN SQUARE DISPLACMENT RELATIVE TO ENSEMBLE MEAN 
				global_MSD_mean_pos_VOLUME_MASK(LST_reaction_bin_number) = &
				& global_MSD_mean_pos_VOLUME_MASK(LST_reaction_bin_number) + &
				& (LST_avg_old_pos_disp_sq_VOLMSK_x + LST_avg_old_pos_disp_sq_VOLMSK_y &
				& + LST_avg_old_pos_disp_sq_VOLMSK_z )
						
				!VOLUME MASK MEAN SQUARE DISPLACEMENT RELATIVE TO INITIAL POSITIONS
				global_MSD_init_pos_VOLUME_MASK(LST_reaction_bin_number) = &
				& global_MSD_init_pos_VOLUME_MASK(LST_reaction_bin_number) + &
				& (LST_marker_old_pos_disp_x_sqrd + LST_marker_old_pos_disp_y_sqrd &
				& + LST_marker_old_pos_disp_z_sqrd )

				IF(include_nonbrownian_LST_markers) THEN

					!VOLUME MASK VARIANCE-X LAGRANGIAN:  BROWNIAN+CONVECTIVE RELATIVE TO PURE CONVECTIVE
					global_var_abs_lagr_pos_VOLMSK_x(LST_reaction_bin_number) = &
					& global_var_abs_lagr_pos_VOLMSK_x(LST_reaction_bin_number) + &
					& LST_lagrang_old_pos_disp_x_sqrd

					!VOLUME MASK VARIANCE-Y LAGRANGIAN:  BROWNIAN+CONVECTIVE RELATIVE TO PURE CONVECTIVE
					global_var_abs_lagr_pos_VOLMSK_y(LST_reaction_bin_number) = &
					& global_var_abs_lagr_pos_VOLMSK_y(LST_reaction_bin_number) + &
					& LST_lagrang_old_pos_disp_y_sqrd

					!VOLUME MASK VARIANCE-Z LAGRANGIAN:  BROWNIAN+CONVECTIVE RELATIVE TO PURE CONVECTIVE
					global_var_abs_lagr_pos_VOLMSK_z(LST_reaction_bin_number) = &
					& global_var_abs_lagr_pos_VOLMSK_z(LST_reaction_bin_number) + &
					& LST_lagrang_old_pos_disp_z_sqrd
				
					!---------MSD----------
					!VOLUME MASK LAGRANGIAN MEAN SQUARE DISPLACEMENT:  BROWNIAN+CONVECTIVE RELATIVE TO PURE CONVECTIVE
					global_MSD_lagrang_VOLUME_MASK(LST_reaction_bin_number) = &
					& global_MSD_lagrang_VOLUME_MASK(LST_reaction_bin_number) + &
					& (LST_lagrang_old_pos_disp_x_sqrd + LST_lagrang_old_pos_disp_y_sqrd &
					& + LST_lagrang_old_pos_disp_z_sqrd )
					
				ENDIF !!include_nonbrownian_LST_markers 				


Femi Kadri's avatar
Femi Kadri committed
552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578
			ENDIF !!LST_marker_old_pos_in_VOLUMEMASK

			!PERIODIC AVERAGE POSITIONS (GLOBAL)
			global_avg_periodic_position_x(LST_reaction_bin_number) = &
			& global_avg_periodic_position_x(LST_reaction_bin_number) + &
			& periodic_marker_old_position_x

			global_avg_periodic_position_y(LST_reaction_bin_number) = &
			& global_avg_periodic_position_y(LST_reaction_bin_number) + &
			& periodic_marker_old_position_y

			global_avg_periodic_position_z(LST_reaction_bin_number) = &
			& global_avg_periodic_position_z(LST_reaction_bin_number) + &
			& periodic_marker_old_position_z


		ENDIF !!LST_marker_reacted_probability(LST_marker_ID).LE.LST_reaction_bins_max_bounds(LST_reaction_bin_number)

	END DO !!LST_reaction_bin_number = 0,total_number_of_LST_rxn_bins
				


	IF(debug) WRITE (0,*) My_MPI_Process_ID,'about to END SUBROUTINE LST_calc_variances_periodic_avg'
	IF(debug) WRITE (9,*) My_MPI_Process_ID,'about to END SUBROUTINE LST_calc_variances_periodic_avg'

RETURN
END SUBROUTINE LST_calc_variances_periodic_avg