diff --git a/.gitignore b/.gitignore index 2ec607fe88cb09dace70c5df9b331a9a54f82aff..065def9d844b8b5db086c007ea9f503ba4edc04e 100644 --- a/.gitignore +++ b/.gitignore @@ -2,3 +2,4 @@ *.ipynb_checkpoints* test_*.py *.hdf5 +bk_*.py \ No newline at end of file diff --git a/mbtrack2/utilities/check_alive.py b/mbtrack2/utilities/check_alive.py new file mode 100644 index 0000000000000000000000000000000000000000..a35f0b996938aa3661833ef1d0fb88ff1594f4a5 --- /dev/null +++ b/mbtrack2/utilities/check_alive.py @@ -0,0 +1,40 @@ +################################################################################### +### from nytool/utilities to mbtrack2/utilities +### 2023/02/06 written by Naoto Yamamoto, naotoy@post.kek.jp +### +### These functions are made to keep the similar usage as the original mbtrack. +### +################################################################################### + +def check_alive(turn,beam,filename=None): + """ + turn : int + turn nuber + beam ; Beam or Bunch_object + beam or bunch object + I0 : float + total beam current + """ + if check_alive.enable: + from mpi4py import MPI + comm = MPI.COMM_WORLD + rank = comm.Get_rank() + size = comm.Get_size() + if size == 1: + for idx in beam.bunch_index: + if False in beam[idx].alive: + print("!!!!! Beam loss at turn %d of Bunch %d !!!!!" % (turn,idx),flush=True) + if filename is not None: + with open("%s.loss.txt" %(filename),'a') as f: + print("!!!!! Beam loss at turn %d of Bunch %d !!!!!" % (turn,idx),file=f) + check_alive.enable = False + else: #MPI + #bunch = beam[beam.mpi.rank_to_bunch(size)] + bunch = beam[beam.mpi.bunch_num] + if False in bunch.alive: + print("!!!!! Beam loss at turn %d of Bunch %d !!!!!" % (turn,beam.mpi.bunch_num),flush=True) + if filename is not None: + with open("%s.loss.txt" %(filename),'a') as f: + print("!!!!! Beam loss at turn %d of Bunch %d !!!!!" % (turn,beam.mpi.bunch_num),file=f) + check_alive.enable = False +check_alive.enable = True diff --git a/mbtrack2/utilities/print_time.py b/mbtrack2/utilities/print_time.py new file mode 100644 index 0000000000000000000000000000000000000000..c8781f7e1558ea3056f0fabac3fdc9b1a8c5fc02 --- /dev/null +++ b/mbtrack2/utilities/print_time.py @@ -0,0 +1,20 @@ +################################################################################### +### from nytool/utilities to mbtrack2/utilities +### 2023/02/06 written by Naoto Yamamoto, naotoy@post.kek.jp +### +### These functions are made to keep the similar usage as the original mbtrack. +### +################################################################################### + +def print_time(message = "",flush=False): + """ + Print a message only once even if mpi is used. + """ + + from time import strftime,localtime + from mpi4py import MPI + comm = MPI.COMM_WORLD + rank = comm.Get_rank() + if rank == 0: + mess = strftime(" [%d %b %Y %H:%M:%S] ", localtime()) + message + print(mess,flush=flush)