aboutsummaryrefslogtreecommitdiff
path: root/Examples/Tests/Larmor/plot_particle_path.py
blob: ef52b4f4b73cc96787c80f7e4abcc8ec086a4718 (plain) (blame)
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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
import numpy as np

class AMReXParticleHeader(object):
    '''

    This class is designed to parse and store the information
    contained in an AMReX particle header file.

    Usage:

        header = AMReXParticleHeader("plt00000/particle0/Header")
        print(header.num_particles)
        print(header.version_string)

    etc...

    '''

    def __init__(self, header_filename):

        self.real_component_names = []
        self.int_component_names = []
        with open(header_filename, "r") as f:
            self.version_string = f.readline().strip()

            particle_real_type = self.version_string.split('_')[-1]
            particle_real_type = self.version_string.split('_')[-1]
            if particle_real_type == 'double':
                self.real_type = np.float64
            elif particle_real_type == 'single':
                self.real_type = np.float32
            else:
                raise RuntimeError("Did not recognize particle real type.")
            self.int_type = np.int32

            self.dim = int(f.readline().strip())
            self.num_int_base = 2
            self.num_real_base = self.dim
            self.num_real_extra = int(f.readline().strip())
            for i in range(self.num_real_extra):
                self.real_component_names.append(f.readline().strip())
            self.num_int_extra = int(f.readline().strip())
            for i in range(self.num_int_extra):
                self.int_component_names.append(f.readline().strip())
            self.num_int = self.num_int_base + self.num_int_extra
            self.num_real = self.num_real_base + self.num_real_extra
            self.is_checkpoint = bool(int(f.readline().strip()))
            self.num_particles = int(f.readline().strip())
            self.max_next_id = int(f.readline().strip())
            self.finest_level = int(f.readline().strip())
            self.num_levels = self.finest_level + 1

            if not self.is_checkpoint:
                self.num_int_base = 0
                self.num_int_extra = 0
                self.num_int = 0

            self.grids_per_level = np.zeros(self.num_levels, dtype='int64')
            self.grids = []
            for level_num in range(self.num_levels):
                self.grids_per_level[level_num] = int(f.readline().strip())
                self.grids.append([])

            for level_num in range(self.num_levels):
                for grid_num in range(self.grids_per_level[level_num]):
                    entry = [int(val) for val in f.readline().strip().split()]
                    self.grids[level_num].append(tuple(entry))


def read_particle_data(fn, ptype="particle0"):
    '''

    This function returns the particle data stored in a particular
    plot file and particle type. It returns two numpy arrays, the
    first containing the particle integer data, and the second the
    particle real data. For example, if a dataset has 3000 particles,
    which have two integer and five real components, this function will
    return two numpy arrays, one with the shape (3000, 2) and the other
    with the shape (3000, 5).

    Usage:

        idata, rdata = read_particle_data("plt00000", "particle0")

    '''
    base_fn = fn + "/" + ptype
    header = AMReXParticleHeader(base_fn + "/Header")

    idtype = "(%d,)i4" % header.num_int
    if header.real_type == np.float64:
        fdtype = "(%d,)f8" % header.num_real
    elif header.real_type == np.float32:
        fdtype = "(%d,)f4" % header.num_real

    idata = np.empty((header.num_particles, header.num_int ))
    rdata = np.empty((header.num_particles, header.num_real))

    ip = 0
    for lvl, level_grids in enumerate(header.grids):
        for (which, count, where) in level_grids:
            if count == 0: continue
            fn = base_fn + "/Level_%d/DATA_%04d" % (lvl, which)

            with open(fn, 'rb') as f:
                f.seek(where)
                ints   = np.fromfile(f, dtype = idtype, count=count)
                floats = np.fromfile(f, dtype = fdtype, count=count)

            idata[ip:ip+count] = ints
            rdata[ip:ip+count] = floats
            ip += count

    return idata, rdata


if __name__ == "__main__":
    import pylab as plt
    import glob

    x0 = []
    y0 = []
    x1 = []
    y1 = []

    fn_list = glob.glob("plt?????")
    fn_list.sort()

    for fn in fn_list:
        idata, rdata = read_particle_data(fn, ptype="particle0")
        x0.append(rdata[0][0])
        y0.append(rdata[0][1])
        idata, rdata = read_particle_data(fn, ptype="particle1")
        x1.append(rdata[0][0])
        y1.append(rdata[0][1])

    fig = plt.gcf()
    fig.set_size_inches(8, 8)
    plt.plot(x0, y0, 'r.')
    plt.plot(x1, y1, 'b.')
    plt.axis((-2., 2., -2., 2.))
    ax = plt.gca()
    ax.set_xlabel(r'$x$')
    ax.set_ylabel(r'$y$')
    plt.savefig('particles.png')
r-highlight'> 2022-07-08Adds a new `<Picture>` component to the image integration (#3866)Gravatar Tony Sullivan 28-164/+1052 * moving all normalization logic out of the Image component * refactor: only require loaders to provide the image src * Adding a `<Picture />` component * fixing types.ts imports * refactor: moving getImage to it's own file * updating component types to use astroHTML.JSX * Revert "updating component types to use astroHTML.JSX" This reverts commit 6e5f578da8d1d3fd262f3cd9add7549f7580af97. * going back to letting loaders add extra HTML attributes * Always use lazy loading and async decoding * Cleaning up the Picture component * Adding test coverage for <Picture> * updating the README * using JSX types for the Image and Picture elements * chore: adding changeset * Update packages/integrations/image/src/get-image.ts Co-authored-by: Nate Moore <natemoo-re@users.noreply.github.com> * allow users to override loading and async on the <img> * renaming config to constants, exporting getPicture() * found the right syntax to import astro-jsx Co-authored-by: Nate Moore <natemoo-re@users.noreply.github.com> 2022-07-08[ci] formatGravatar bholmesdev 7-31/+60 2022-07-08[astro add] Support adapters and third party packages (#3854)Gravatar Ben Holmes 20-37/+221 * feat: support adapters and third part integrations by keywords * refactor: add keywords to all official integrations * docs: add adapter ex to astro add help * nit: clarify astro add usage * nit: highlight link * fix: use process.exit(1) on error * chore: changeset * nit: bold integration name * fix: log install instructions for adapters instead * nit: change to logAdapterConfigInstructions * Revert "fix: log install instructions for adapters instead" This reverts commit 1a459f152bc7b7991db289999f7393e5be64ea3e. * feat: add hardcoded adapter export map * refactor: inline adapter config log 2022-07-08Ignore big formatting commit (#3870)Gravatar Marcus Otterström 1-1/+3 2022-07-08[ci] formatGravatar tony-sull 1-3/+3 2022-07-08fix: Always add @astrojs/image to vite.ssr.noExternal (#3869)Gravatar Tony Sullivan 2-0/+8 * fix: always add @astrojs/image to vite.ssr.noExternal * chore: add changeset 2022-07-08Format astro files in examples (#3862)Gravatar Marcus Otterström 73-694/+957 2022-07-08Integration README fixes (#3865)Gravatar Chris Swithinbank 8-8/+17 * Remove stray XML tag in sitemap integration README * Fix link errors * Add changeset 2022-07-08fix(#3843): move @babel/types to dependencies (#3863)Gravatar Nate Moore 2-2/+2 * fix(#3843): move @babel/types to dependencies * chore: update lockfile Co-authored-by: Nate Moore <nate@astro.build> 2022-07-08Fixed broken Markdown link (#3868)Gravatar Isaac McFadyen 1-2/+2 2022-07-08chore: bump Vite minimum version (#3861)Gravatar Nate Moore 2-2/+2 Co-authored-by: Nate Moore <nate@astro.build> 2022-07-08[ci] formatGravatar matthewp 1-1/+1 2022-07-08Better response.arrayBuffer() handling in Node (#3860)Gravatar Matthew Phillips 8-3/+125 * Better response.arrayBuffer() handling in Node * Adds a changeset 2022-07-08[ci] update lockfile (#3858)Gravatar Fred K. Bot 1-411/+437 Co-authored-by: FredKSchott <FredKSchott@users.noreply.github.com> 2022-07-08Fix manual import (#3857)Gravatar Chris Williams 1-1/+1 2022-07-07[ci] formatGravatar bholmesdev 1-3/+3 2022-07-07Docs: add adapter heading for configuration docs (#3842)Gravatar Ben Holmes 2-4/+20 * Docs: add adapter heading for configuration docs * docs: add adapter example, rework doc links * chore: changeset 2022-07-07[ci] formatGravatar natemoo-re 2-3/+3 2022-07-07fix: lint failing on astro and some integrations (#3794)Gravatar Joaquín Sánchez 7-17/+18 * fix: lint failing on astro and some integrations * chore: fix telemetry lint * chore: fix turbo cache (thx nate) * chore: fix runtime server 2022-07-07update solid peer dependenciesGravatar Fred K. Schott 2-1/+6 2022-07-07update lockfile (#3828)Gravatar Fred K. Schott 3-7/+1 2022-07-07Improve JSX definitions (#3801)Gravatar Erika 2-477/+858 2022-07-07Fix slot attribute inside expressions (#3837)Gravatar Nate Moore 8-5/+89 * fix: use slots inside expressions * test: add test for conditional named slots * test: fix incorrect test fixture * chore: update `@astrojs/compiler` * chore: add test coverage for `switch` Co-authored-by: Nate Moore <nate@astro.build> 2022-07-07[ci] formatGravatar FredKSchott 1-2/+1 2022-07-07detect package manager and improve types (#3847)Gravatar Fred K. Schott 7-44/+78 2022-07-07small create-astro wording changes (#3831)Gravatar Fred K. Schott 3-10/+15 2022-07-07Upgrade to pnpm@7.4.1, remove `patch-package` (#3747)Gravatar Nate Moore 6-127/+100 * chore: upgrade to pnpm@7.4.0, remove `patch-package` * chore: update contributing * chore: pnpm@7.4.1 * chore: bump to pnpm@7.5.0 Co-authored-by: Nate Moore <nate@astro.build> 2022-07-07[ci] formatGravatar matthewp 1-1/+1 2022-07-07Allow importing Image component from @astrojs/image (#3848)Gravatar Matthew Phillips 7-6/+20 * Allow importing Image component from @astrojs/image * Adds a changeset * Export the Image type 2022-07-06[ci] release (#3818)astro@1.0.0-beta.64@astrojs/telemetry@0.2.4@astrojs/node@0.1.4Gravatar Fred K. Bot 41-90/+90 Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com> 2022-07-07[ci] formatGravatar bholmesdev 1-1/+1 2022-07-06Fix: Infer content type with charset in dev and prod (#3841)Gravatar Ben Holmes 4-3/+23 * fix: add text/plain;charset;utf-8 header in dev * test: ensure content type for body shorthand * chore: changeset * feat: infer content type by pathname * feat: add charset to prod build handler * test: update for charset in prod build test 2022-07-06[ci] formatGravatar bholmesdev 1-2/+2 2022-07-06Fix `client:visible` directive in safari (#3839)Gravatar Ben Holmes 2-2/+20 * fix: client visible on safari * chore: changeset * refactor: wait for children with mutation observer * fix: remove unecessary settimeout * refactor: remove unecessary awaits 2022-07-06[ci] formatGravatar matthewp 1-1/+1 2022-07-06Ensure that maybeRenderHead runs last (#3821)Gravatar Matthew Phillips 5-8/+67 * Ensure that maybeRenderHead runs last * Adds a changeset * Make work with MDX 2022-07-05Fix portfolio example to use lowercase srcset (#3829)Gravatar Matthew Phillips 1-1/+1 2022-07-05[ci] formatGravatar delucis 1-29/+29