-
Notifications
You must be signed in to change notification settings - Fork 77
Add particle unique ID #351
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 63 commits
Commits
Show all changes
76 commits
Select commit
Hold shift + click to select a range
d4b221b
Add particle ID type
ChunYen-Chen 610fa86
Add the initialization of particle ID
ChunYen-Chen c71fe29
Add id while simulation
ChunYen-Chen 5d2caca
Remove barrier
ChunYen-Chen 3fd7fe8
Merge branch 'par_attribute' into par_id
ChunYen-Chen a5c0c74
Bug fix
ChunYen-Chen 2da43c3
Rewrite and add particle ID check
ChunYen-Chen 1f23d82
Rename NextUniqueIdx to NextUID
ChunYen-Chen f9e28b1
Rename PIDX to PUID
ChunYen-Chen 3900542
Update id
ChunYen-Chen a953680
Move function
ChunYen-Chen 6b2ed7e
Add comments and optimize
ChunYen-Chen 4420fc5
Add comments and rename function
ChunYen-Chen c8168aa
Add analysis script
ChunYen-Chen 1407ccf
Update Particles.md
ChunYen-Chen a03a061
Update Adding-New-Simulations.md
ChunYen-Chen 8e662e2
Update Initial-Conditions.md
ChunYen-Chen 3d94bc2
Update Initial-Conditions.md
ChunYen-Chen c304808
Merge branch 'par_attribute' into par_id
ChunYen-Chen 986f52d
Merge branch 'par_attribute' into par_id
ChunYen-Chen 7e53455
Merge branch 'hyschive:main' into par_id
ChunYen-Chen bf1d4a6
Merge branch 'par_attribute' into par_id
ChunYen-Chen 5916244
Update according to merge
ChunYen-Chen 3d72fb2
Merge branch 'par_attribute' into par_id
ChunYen-Chen 1dacd40
Merge branch 'par_attribute' into par_id
ChunYen-Chen a3c08d3
Merge branch 'par_attribute' into par_id
ChunYen-Chen ecfeb43
Merge branch 'master' into par_id
ChunYen-Chen d20b868
Minor
ChunYen-Chen ddfc286
Merge branch 'master' into par_id
ChunYen-Chen 1f2123e
fix: improve the ParUID initialization
hsinhaoHHuang c77fcd0
[Workflow] Update all parameters wiki page
hsinhaoHHuang 12dd784
Merge pull request #9 from hsinhaoHHuang/pr_to_par_id
ChunYen-Chen d45b32a
Merge branch 'master' into par_id
ChunYen-Chen f688cad
Apply suggestions from code review
ChunYen-Chen 79702d3
[Workflow] Update all parameters wiki page
ChunYen-Chen 1939695
Apply suggestions from code review
ChunYen-Chen d80ebbd
Apply suggestions from code review
ChunYen-Chen 9620c94
Apply suggestions from code review
ChunYen-Chen 3ff73c7
Apply suggestions from code review
ChunYen-Chen c98f136
Apply suggestions from code review
ChunYen-Chen db80bab
Apply suggestions from code review
ChunYen-Chen ec5e34c
Update HDF5 version
ChunYen-Chen f44353b
Update wiki
ChunYen-Chen 2e40f0e
Simplify particle restart procedure
ChunYen-Chen eba2f65
Rename `PPUID_TBA` to `PUID_TBA`
ChunYen-Chen e3b3987
Update comment
ChunYen-Chen 5c1ea14
Update argument type
ChunYen-Chen 3ccdcba
Correct the argument type
ChunYen-Chen 743df30
Minor
ChunYen-Chen 4bcc9f7
Remove unnecessary barrier
ChunYen-Chen 8f3ad80
Update comment
ChunYen-Chen 8a66d49
Optimize `Par_SetParUID()`
ChunYen-Chen 6e54eaa
Set `hid_t` for unread data
ChunYen-Chen 597ea22
Merge branch 'master' into par_id
ChunYen-Chen a408601
Update wiki
ChunYen-Chen 81d5add
Update `UID` to `PUID`
ChunYen-Chen 68c27e6
Optimize `Check_InactiveMass`
ChunYen-Chen bc89be4
Use HDF5 files as default option
ChunYen-Chen 3429bb6
Apply suggestions from code review
hyschive af32fba
Minor
ChunYen-Chen 8843679
Update comment
ChunYen-Chen cc84012
Minor
ChunYen-Chen 0645374
Update variable names
ChunYen-Chen 1c44de4
Add common utilties
ChunYen-Chen b2124c2
Use common utilties
ChunYen-Chen 474fa17
Plot mesh values
ChunYen-Chen 4895c5b
Optimize `isPUIDStored`
ChunYen-Chen 7243895
Update binary file output
ChunYen-Chen 7d67878
Merge branch 'master' into par_id
ChunYen-Chen 105448b
Move `PUID` initialization to `amr->Par->InitRepo()`
ChunYen-Chen d91b4e6
Merge branch 'master' into par_id
ChunYen-Chen af8d359
Update wiki
ChunYen-Chen 660c49c
Update naming style
ChunYen-Chen 0582233
Style
ChunYen-Chen 05b9fe8
Merge branch 'master' into par_id
ChunYen-Chen 936e024
Update script
ChunYen-Chen File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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
179 changes: 179 additions & 0 deletions
179
example/test_problem/Hydro/ParticleTest/track_particle.py
This file contains hidden or 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,179 @@ | ||
| import yt | ||
| import numpy as np | ||
| import matplotlib.pylab as plt | ||
| import argparse | ||
| import sys | ||
|
|
||
|
|
||
|
|
||
| #==================================================================================================== | ||
| # Class | ||
| #==================================================================================================== | ||
| class particle(): | ||
| def __init__( self, PUID ): | ||
| self.PUID = PUID | ||
| self.idx = 0 | ||
| self.t = [] | ||
| self.x_PUID = [] | ||
| self.y_PUID = [] | ||
| self.z_PUID = [] | ||
| self.vx_PUID = [] | ||
| self.vy_PUID = [] | ||
| self.vz_PUID = [] | ||
| self.x_idx = [] | ||
| self.y_idx = [] | ||
| self.z_idx = [] | ||
| self.vx_idx = [] | ||
| self.vy_idx = [] | ||
| self.vz_idx = [] | ||
|
|
||
| def set_idx( self, ds, text=True ): | ||
| if not text: | ||
| dd = ds.all_data() | ||
| par_uid = dd['ParPUid'] | ||
| self.idx = np.where(par_uid == self.PUID)[0][0] | ||
| else: | ||
| par_uid = ds[:, 12] | ||
| print(np.where(par_uid == self.PUID)) | ||
| self.idx = np.where(par_uid == self.PUID)[0][0] | ||
|
|
||
| def append_particle_attributes( self, ds, text=True ): | ||
| if not text: | ||
| dd = ds.all_data() | ||
| time = ds.current_time | ||
| posx = dd['ParPosX'] | ||
| posy = dd['ParPosY'] | ||
| posz = dd['ParPosZ'] | ||
| velx = dd['ParVelX'] | ||
| vely = dd['ParVelY'] | ||
| velz = dd['ParVelZ'] | ||
| par_type = dd['ParType'] | ||
| par_uid = dd['ParPUid'] | ||
| self.t.append(time) | ||
| else: | ||
| time = ds[0, 10] | ||
| posx = ds[:, 1] | ||
| posy = ds[:, 2] | ||
| posz = ds[:, 3] | ||
| velx = ds[:, 4] | ||
| vely = ds[:, 5] | ||
| velz = ds[:, 6] | ||
| par_type = ds[:, 11] | ||
| par_uid = ds[:, 12] | ||
| self.t.append(time) | ||
|
|
||
| self.x_PUID.append(posx[par_uid == self.PUID]) | ||
| self.y_PUID.append(posy[par_uid == self.PUID]) | ||
| self.z_PUID.append(posz[par_uid == self.PUID]) | ||
| self.vx_PUID.append(velx[par_uid == self.PUID]) | ||
| self.vy_PUID.append(vely[par_uid == self.PUID]) | ||
| self.vz_PUID.append(velz[par_uid == self.PUID]) | ||
| self.x_idx.append(posx[self.idx]) | ||
| self.y_idx.append(posy[self.idx]) | ||
| self.z_idx.append(posz[self.idx]) | ||
| self.vx_idx.append(velx[self.idx]) | ||
| self.vy_idx.append(vely[self.idx]) | ||
| self.vz_idx.append(velz[self.idx]) | ||
|
|
||
| def plot_particle( self ): | ||
| lw_PUID = 10 | ||
| lw_idx = 5 | ||
| fig, ax = plt.subplots( 2, 3, sharex='col', figsize=(15, 10) ) | ||
| plt.subplots_adjust( hspace=0.1 ) | ||
|
|
||
| ax[0, 0].plot( self.t, self.x_PUID, label="PUID %05d"%(self.PUID), linewidth=lw_PUID ) | ||
| ax[0, 0].plot( self.t, self.x_idx, label=" idx %05d"%(self.idx), linewidth=lw_idx ) | ||
| ax[0, 0].set( ylim=[0, 1] ) | ||
| ax[0, 0].tick_params( which="both", direction="in" ) | ||
|
|
||
| ax[0, 1].plot( self.t, self.y_PUID, label="PUID %05d"%(self.PUID), linewidth=lw_PUID ) | ||
| ax[0, 1].plot( self.t, self.y_idx, label=" idx %05d"%(self.idx), linewidth=lw_idx ) | ||
| ax[0, 1].set( ylim=[0, 1] ) | ||
| ax[0, 1].tick_params( which="both", direction="in" ) | ||
|
|
||
| ax[0, 2].plot( self.t, self.z_PUID, label="PUID %05d"%(self.PUID), linewidth=lw_PUID ) | ||
| ax[0, 2].plot( self.t, self.z_idx, label=" idx %05d"%(self.idx), linewidth=lw_idx ) | ||
| ax[0, 2].set( ylim=[0, 1] ) | ||
| ax[0, 2].tick_params( which="both", direction="in" ) | ||
|
|
||
| ax[1, 0].plot( self.t, self.vx_PUID, label="PUID %05d"%(self.PUID), linewidth=lw_PUID ) | ||
| ax[1, 0].plot( self.t, self.vx_idx, label=" idx %05d"%(self.idx), linewidth=lw_idx ) | ||
| ax[1, 0].tick_params( which="both", direction="in" ) | ||
|
|
||
| ax[1, 1].plot( self.t, self.vy_PUID, label="PUID %05d"%(self.PUID), linewidth=lw_PUID ) | ||
| ax[1, 1].plot( self.t, self.vy_idx, label=" idx %05d"%(self.idx), linewidth=lw_idx ) | ||
| ax[1, 1].tick_params( which="both", direction="in" ) | ||
|
|
||
| ax[1, 2].plot( self.t, self.vz_PUID, label="PUID %05d"%(self.PUID), linewidth=lw_PUID ) | ||
| ax[1, 2].plot( self.t, self.vz_idx, label=" idx %05d"%(self.idx), linewidth=lw_idx ) | ||
| ax[1, 2].tick_params( which="both", direction="in" ) | ||
|
|
||
| ax[1, 2].legend() | ||
|
|
||
| ax[0, 0].set(title="x") | ||
| ax[0, 1].set(title="y") | ||
| ax[0, 2].set(title="z") | ||
|
|
||
| ax[1, 0].set(xlabel="time") | ||
| ax[1, 1].set(xlabel="time") | ||
| ax[1, 2].set(xlabel="time") | ||
|
|
||
| ax[0, 0].set(ylabel="pos") | ||
| ax[1, 0].set(ylabel="vel") | ||
|
|
||
| plt.suptitle( "Particle %05d"%self.PUID ) | ||
| plt.savefig( "particle_%05d.png"%self.PUID ) | ||
| # plt.show() | ||
| plt.close() | ||
| return | ||
|
|
||
|
|
||
| #==================================================================================================== | ||
| # Main | ||
| #==================================================================================================== | ||
| # load the command-line parameters | ||
| parser = argparse.ArgumentParser( description='Plot the particle positions and velocities by particle UIDs and array indices' ) | ||
|
|
||
| parser.add_argument( '-s', action='store', required=True, type=int, dest='idx_start', | ||
| help='first data index' ) | ||
| parser.add_argument( '-e', action='store', required=True, type=int, dest='idx_end', | ||
| help='last data index' ) | ||
| parser.add_argument( '-u', action='store', required=True, dest='uids', type=int, nargs='+', | ||
| help='PUID of particles' ) | ||
| parser.add_argument( '-t', action='store_true', required=False, dest='use_text', | ||
| help='Use `Particle_*.txt` for analysis (faster)' ) | ||
| parser.add_argument( '-d', action='store', required=False, type=int, dest='didx', | ||
| help='delta data index [%(default)d]', default=1 ) | ||
| parser.add_argument( '-p', action='store', required=False, type=str, dest='prefix', | ||
| help='data path prefix [%(default)s]', default='./' ) | ||
|
|
||
| args = parser.parse_args() | ||
|
|
||
| # take note | ||
| print( '\nCommand-line arguments:' ) | ||
| print( '-------------------------------------------------------------------' ) | ||
| print( ' '.join(map(str, sys.argv)) ) | ||
| print( '-------------------------------------------------------------------\n' ) | ||
|
|
||
| idx_start = args.idx_start | ||
| idx_end = args.idx_end | ||
| didx = args.didx | ||
| prefix = args.prefix | ||
| check_PUID = args.uids | ||
| use_text = args.use_text | ||
|
|
||
| pars = [ particle(PUID) for PUID in check_PUID ] | ||
| for i in range(idx_start, idx_end+1, didx): | ||
| if not use_text: | ||
| ds = yt.load( "%s/Data_%06d"%(prefix, i) ) | ||
| else: | ||
| print("Loading: %06d"%i) | ||
| ds = np.loadtxt( "%s/Particle_%06d.txt"%(prefix, i) ) | ||
|
|
||
| for p in pars: | ||
| if i == 0: p.set_idx( ds, use_text ) | ||
|
|
||
| p.append_particle_attributes( ds, use_text ) | ||
|
|
||
| for p in pars: | ||
| p.plot_particle() |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.