|
11 | 11 | "from lcode2dPy.simulation.interface import Simulation\n",
|
12 | 12 | "from lcode2dPy.diagnostics.targets import BeamDiagnostics, PlasmaDiagnostics\n",
|
13 | 13 | "from lcode2dPy.config.default_config import default_config\n",
|
14 |
| - "from lcode2dPy.beam.beam_generator import make_beam, Gauss, rGauss\n", |
| 14 | + "from lcode2dPy.beam_generator.beam_generator import make_beam, Gauss, rGauss\n", |
15 | 15 | "import numpy as np\n",
|
16 | 16 | "import matplotlib.pyplot as plt\n",
|
17 | 17 | "import subprocess"
|
|
43 | 43 | },
|
44 | 44 | "outputs": [],
|
45 | 45 | "source": [
|
46 |
| - "!rm ../c_code/*" |
| 46 | + "import numpy as np\n", |
| 47 | + "#import openpmd_api as io\n", |
| 48 | + "import shutil\n", |
| 49 | + "from pathlib import Path\n", |
| 50 | + "import matplotlib.pyplot as plt\n", |
| 51 | + "\n", |
| 52 | + "class Diagnostics:\n", |
| 53 | + " def __init__(self, diag_list):\n", |
| 54 | + " self.diag_list = diag_list\n", |
| 55 | + "\n", |
| 56 | + "class TDiagnostics():\n", |
| 57 | + " def __init__(self, t_start=0, t_end=None, period=100):\n", |
| 58 | + " self.t_start = t_start\n", |
| 59 | + " self.t_end = t_end \n", |
| 60 | + " self.period = period \n", |
| 61 | + " self.data = {}\n", |
| 62 | + " \n", |
| 63 | + " def process(self, config, t, layer_idx, steps, plasma_particles, plasma_fields, rho_beam, beam): \n", |
| 64 | + " if self.t_end and (t<self.t_start or t>self.t_end):\n", |
| 65 | + " return False\n", |
| 66 | + " elif t<self.t_start:\n", |
| 67 | + " return False\n", |
| 68 | + " if (t-self.t_start)%self.period != 0:\n", |
| 69 | + " return False\n", |
| 70 | + " return True\n", |
| 71 | + "\n", |
| 72 | + "class BeamDiagnostics(TDiagnostics):\n", |
| 73 | + " def __init__(self, t_start=0, t_end=None, period=100):\n", |
| 74 | + " super().__init__(t_start, t_end, period)\n", |
| 75 | + " def process(self, config, t, layer_idx, steps, plasma_particles, plasma_fields, rho_beam, beam):\n", |
| 76 | + " if super().process(config, t, layer_idx, steps, plasma_particles, plasma_fields, rho_beam, beam):\n", |
| 77 | + " beam_slice = beam\n", |
| 78 | + " #lost_slice = beam[1]\n", |
| 79 | + " #self.lost[t] = np.array([],dtype=particle_dtype)\n", |
| 80 | + " if layer_idx == 0:\n", |
| 81 | + " particle_dtype = np.dtype([('xi', 'f8'), ('r', 'f8'), ('p_z', 'f8'), ('p_r', 'f8'), ('M', 'f8'), ('q_m', 'f8'),\n", |
| 82 | + " ('q_norm', 'f8'), ('id', 'i8')])\n", |
| 83 | + " self.data[t] = np.array([],dtype=particle_dtype)\n", |
| 84 | + " self.data[t] = np.append(self.data[t], beam_slice.particles)\n", |
| 85 | + " #self.lost[t] = np.append(self.data[t], lost_slice.particles)\n", |
| 86 | + " #self.test[t].append(rho_beam.tolist())" |
47 | 87 | ]
|
48 | 88 | },
|
49 | 89 | {
|
|
53 | 93 | "Collapsed": "false"
|
54 | 94 | },
|
55 | 95 | "outputs": [],
|
| 96 | + "source": [ |
| 97 | + "class EveryxiDiagnostics(TDiagnostics):\n", |
| 98 | + " def __init__(self, t_start=0, t_end=None, period=1, xi_period=100):\n", |
| 99 | + " super().__init__(t_start, t_end, period)\n", |
| 100 | + " self.xi_period = xi_period\n", |
| 101 | + " def process(self, config, t, layer_idx, steps, plasma_particles, plasma_fields, rho_beam, beam):\n", |
| 102 | + " super().process(config, t, layer_idx, steps, plasma_particles, plasma_fields, rho_beam, beam)\n", |
| 103 | + " if layer_idx % self.xi_period == 0:\n", |
| 104 | + " xi_step_p = config.getfloat('time-step')\n", |
| 105 | + " print('xi={xi:.6f} Ez={Ez:e} N={N}'.format(xi=layer_idx * -xi_step_p, Ez=plasma_fields.E_z[0], N=steps))" |
| 106 | + ] |
| 107 | + }, |
| 108 | + { |
| 109 | + "cell_type": "code", |
| 110 | + "execution_count": 5, |
| 111 | + "metadata": { |
| 112 | + "Collapsed": "false" |
| 113 | + }, |
| 114 | + "outputs": [], |
56 | 115 | "source": [
|
57 | 116 | "# Config\n",
|
58 | 117 | "config = default_config\n",
|
|
74 | 133 | " pz_distr=Gauss(gamma*m_proton, gamma*m_proton*1e-4, vmin=None, vmax=None),\n",
|
75 | 134 | " Ipeak_kA=2*40/1000,\n",
|
76 | 135 | " q_m=1/m_proton,\n",
|
77 |
| - " saveto=\"../c_code\")\n", |
| 136 | + " saveto=None)\n", |
78 | 137 | "\n",
|
79 |
| - "diagnostics = [\n", |
| 138 | + "diagnostics = [EveryxiDiagnostics(),\n", |
80 | 139 | " BeamDiagnostics(period=time_limit//time_step * time_step),\n",
|
81 |
| - " PlasmaDiagnostics(period=time_limit//time_step * time_step)\n", |
| 140 | + "# PlasmaDiagnostics(period=time_limit//time_step * time_step)\n", |
82 | 141 | "]\n",
|
83 | 142 | "\n",
|
84 | 143 | "sim = Simulation(beam_pars=beam_pars, diagnostics=diagnostics, config=config)"
|
85 | 144 | ]
|
86 | 145 | },
|
87 | 146 | {
|
88 | 147 | "cell_type": "code",
|
89 |
| - "execution_count": 5, |
| 148 | + "execution_count": 6, |
90 | 149 | "metadata": {
|
91 | 150 | "Collapsed": "false"
|
92 | 151 | },
|
|
96 | 155 | "output_type": "stream",
|
97 | 156 | "text": [
|
98 | 157 | "Number of particles: 10093\n",
|
99 |
| - "Number of particles in the middle layer: 1261\n" |
| 158 | + "Number of particles in the middle layer: 1261\n", |
| 159 | + "xi=-0.000000 Ez=-3.149575e-09 N=1\n" |
100 | 160 | ]
|
101 | 161 | }
|
102 | 162 | ],
|
|
200 | 260 | {
|
201 | 261 | "cell_type": "code",
|
202 | 262 | "execution_count": null,
|
203 |
| - "metadata": {}, |
| 263 | + "metadata": { |
| 264 | + "Collapsed": "false" |
| 265 | + }, |
204 | 266 | "outputs": [
|
205 | 267 | {
|
206 | 268 | "ename": "Error",
|
|
232 | 294 | "hash": "40d3a090f54c6569ab1632332b64b2c03c39dcf918b08424e98f38b5ae0af88f"
|
233 | 295 | },
|
234 | 296 | "kernelspec": {
|
235 |
| - "display_name": "Python 3.7.4 64-bit ('base': conda)", |
| 297 | + "display_name": "Python 3", |
| 298 | + "language": "python", |
236 | 299 | "name": "python3"
|
237 | 300 | },
|
238 | 301 | "language_info": {
|
|
0 commit comments