Vlasov-Poisson-1D1V.ipynb 44.8 KB
Newer Older
1
2
3
4
{
 "cells": [
  {
   "cell_type": "code",
5
   "execution_count": 1,
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
   "metadata": {},
   "outputs": [],
   "source": [
    "using Plots, LinearAlgebra, Statistics, BenchmarkTools\n",
    "using HermiteGF\n",
    "using SparseArrays"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "slideshow": {
     "slide_type": "slide"
    }
   },
   "source": [
    "# Vlasov-Poisson equation\n",
    "We consider the dimensionless Vlasov-Poisson equation for one species\n",
    "with a neutralizing background.\n",
    "\n",
    "$$ \n",
    "\\frac{\\partial f}{\\partial t}+ v\\cdot \\nabla_x f + E(t,x) \\cdot \\nabla_v f = 0, \\\\\n",
    "- \\Delta \\phi = 1 - \\rho, E = - \\nabla \\phi \\\\\n",
    "\\rho(t,x)  =  \\int f(t,x,v)dv.\n",
    "$$\n",
    "\n",
    "- [Vlasov Equation - Wikipedia](https://en.wikipedia.org/wiki/Vlasov_equation)"
   ]
  },
  {
   "cell_type": "code",
37
   "execution_count": 2,
38
39
40
41
42
43
44
45
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "SparseMatrixCSC{Float64,Int64}"
      ]
     },
46
     "execution_count": 2,
47
48
49
50
51
52
53
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "nx = 64\n",
    "matrix = spdiagm(-1 => ones(Float64,nx-2),\n",
54
55
    "                  0 => -2*ones(Float64,nx),\n",
    "                  1 => ones(Float64,nx-2))\n",
56
57
58
59
60
61
    "\n",
    "typeof(matrix)"
   ]
  },
  {
   "cell_type": "code",
62
   "execution_count": 3,
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
   "metadata": {},
   "outputs": [],
   "source": [
    "struct UniformMesh\n",
    "    nx :: Int64\n",
    "    dx :: Float64\n",
    "    x  :: Vector{Float64}\n",
    "    function UniformMesh( xmin, xmax, nx)\n",
    "        dx = (xmax - xmin)/ nx\n",
    "        x = range(xmin, stop=xmax, length=nx+1)[1:end-1]\n",
    "        new( nx, dx, x)\n",
    "    end\n",
    "end"
   ]
  },
  {
   "cell_type": "code",
80
   "execution_count": 4,
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
   "metadata": {},
   "outputs": [],
   "source": [
    "struct ChebyshevMesh\n",
    "    nx :: Int64\n",
    "    x  :: Vector{Float64}\n",
    "    dx :: Vector{Float64}\n",
    "    function ChebyshevMesh( nodes::HermiteGF.NodesType)\n",
    "        dx =[ x1 - x0 for (x1,x0) in zip(nodes.xk[2:end],nodes[1:end-1]) ]\n",
    "        x = nodes.xk\n",
    "        new( nx, dx, x)\n",
    "    end\n",
    "end"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "$$\n",
    "f_i'' \\approx \\frac{2 \\Big[ f_{i+1}\n",
    "- \\big(1+\\frac{h_i}{h_{i-1}}\\big) f_i\n",
    "+\\frac{h_i}{h_{i-1}}f_{i-1} \n",
    " \\Big]}\n",
    "{ h_i h_{i-1} (1+\\frac{h_i}{h_{i-1}})}\n",
    "$$"
   ]
  },
  {
   "cell_type": "code",
111
   "execution_count": 6,
112
113
114
   "metadata": {},
   "outputs": [
    {
115
116
117
118
119
     "data": {
      "image/svg+xml": [
       "<?xml version=\"1.0\" encoding=\"utf-8\"?>\n",
       "<svg xmlns=\"http://www.w3.org/2000/svg\" xmlns:xlink=\"http://www.w3.org/1999/xlink\" width=\"600\" height=\"400\" viewBox=\"0 0 2400 1600\">\n",
       "<defs>\n",
120
       "  <clipPath id=\"clip1200\">\n",
121
122
123
124
       "    <rect x=\"0\" y=\"0\" width=\"2000\" height=\"2000\"/>\n",
       "  </clipPath>\n",
       "</defs>\n",
       "<defs>\n",
125
       "  <clipPath id=\"clip1201\">\n",
126
127
128
       "    <rect x=\"0\" y=\"0\" width=\"2400\" height=\"1600\"/>\n",
       "  </clipPath>\n",
       "</defs>\n",
129
       "<polygon clip-path=\"url(#clip1201)\" points=\"\n",
130
131
132
       "0,1600 2400,1600 2400,0 0,0 \n",
       "  \" fill=\"#ffffff\" fill-opacity=\"1\"/>\n",
       "<defs>\n",
133
       "  <clipPath id=\"clip1202\">\n",
134
135
136
       "    <rect x=\"480\" y=\"0\" width=\"1681\" height=\"1600\"/>\n",
       "  </clipPath>\n",
       "</defs>\n",
137
       "<polygon clip-path=\"url(#clip1201)\" points=\"\n",
138
139
140
       "189.504,1503.47 2321.26,1503.47 2321.26,47.2441 189.504,47.2441 \n",
       "  \" fill=\"#ffffff\" fill-opacity=\"1\"/>\n",
       "<defs>\n",
141
       "  <clipPath id=\"clip1203\">\n",
142
143
144
       "    <rect x=\"189\" y=\"47\" width=\"2133\" height=\"1457\"/>\n",
       "  </clipPath>\n",
       "</defs>\n",
145
       "<polyline clip-path=\"url(#clip1203)\" style=\"stroke:#000000; stroke-width:2; stroke-opacity:0.1; fill:none\" points=\"\n",
146
147
       "  249.837,1503.47 249.837,47.2441 \n",
       "  \"/>\n",
148
       "<polyline clip-path=\"url(#clip1203)\" style=\"stroke:#000000; stroke-width:2; stroke-opacity:0.1; fill:none\" points=\"\n",
149
150
       "  752.609,1503.47 752.609,47.2441 \n",
       "  \"/>\n",
151
       "<polyline clip-path=\"url(#clip1203)\" style=\"stroke:#000000; stroke-width:2; stroke-opacity:0.1; fill:none\" points=\"\n",
152
153
       "  1255.38,1503.47 1255.38,47.2441 \n",
       "  \"/>\n",
154
       "<polyline clip-path=\"url(#clip1203)\" style=\"stroke:#000000; stroke-width:2; stroke-opacity:0.1; fill:none\" points=\"\n",
155
156
       "  1758.15,1503.47 1758.15,47.2441 \n",
       "  \"/>\n",
157
       "<polyline clip-path=\"url(#clip1203)\" style=\"stroke:#000000; stroke-width:2; stroke-opacity:0.1; fill:none\" points=\"\n",
158
159
       "  2260.93,1503.47 2260.93,47.2441 \n",
       "  \"/>\n",
160
161
       "<polyline clip-path=\"url(#clip1203)\" style=\"stroke:#000000; stroke-width:2; stroke-opacity:0.1; fill:none\" points=\"\n",
       "  189.504,1463.98 2321.26,1463.98 \n",
162
       "  \"/>\n",
163
164
       "<polyline clip-path=\"url(#clip1203)\" style=\"stroke:#000000; stroke-width:2; stroke-opacity:0.1; fill:none\" points=\"\n",
       "  189.504,1119.67 2321.26,1119.67 \n",
165
       "  \"/>\n",
166
       "<polyline clip-path=\"url(#clip1203)\" style=\"stroke:#000000; stroke-width:2; stroke-opacity:0.1; fill:none\" points=\"\n",
167
168
       "  189.504,775.359 2321.26,775.359 \n",
       "  \"/>\n",
169
170
       "<polyline clip-path=\"url(#clip1203)\" style=\"stroke:#000000; stroke-width:2; stroke-opacity:0.1; fill:none\" points=\"\n",
       "  189.504,431.049 2321.26,431.049 \n",
171
       "  \"/>\n",
172
173
       "<polyline clip-path=\"url(#clip1203)\" style=\"stroke:#000000; stroke-width:2; stroke-opacity:0.1; fill:none\" points=\"\n",
       "  189.504,86.7388 2321.26,86.7388 \n",
174
       "  \"/>\n",
175
       "<polyline clip-path=\"url(#clip1201)\" style=\"stroke:#000000; stroke-width:4; stroke-opacity:1; fill:none\" points=\"\n",
176
177
       "  189.504,1503.47 2321.26,1503.47 \n",
       "  \"/>\n",
178
       "<polyline clip-path=\"url(#clip1201)\" style=\"stroke:#000000; stroke-width:4; stroke-opacity:1; fill:none\" points=\"\n",
179
180
       "  189.504,1503.47 189.504,47.2441 \n",
       "  \"/>\n",
181
       "<polyline clip-path=\"url(#clip1201)\" style=\"stroke:#000000; stroke-width:4; stroke-opacity:1; fill:none\" points=\"\n",
182
183
       "  249.837,1503.47 249.837,1481.63 \n",
       "  \"/>\n",
184
       "<polyline clip-path=\"url(#clip1201)\" style=\"stroke:#000000; stroke-width:4; stroke-opacity:1; fill:none\" points=\"\n",
185
186
       "  752.609,1503.47 752.609,1481.63 \n",
       "  \"/>\n",
187
       "<polyline clip-path=\"url(#clip1201)\" style=\"stroke:#000000; stroke-width:4; stroke-opacity:1; fill:none\" points=\"\n",
188
189
       "  1255.38,1503.47 1255.38,1481.63 \n",
       "  \"/>\n",
190
       "<polyline clip-path=\"url(#clip1201)\" style=\"stroke:#000000; stroke-width:4; stroke-opacity:1; fill:none\" points=\"\n",
191
192
       "  1758.15,1503.47 1758.15,1481.63 \n",
       "  \"/>\n",
193
       "<polyline clip-path=\"url(#clip1201)\" style=\"stroke:#000000; stroke-width:4; stroke-opacity:1; fill:none\" points=\"\n",
194
195
       "  2260.93,1503.47 2260.93,1481.63 \n",
       "  \"/>\n",
196
197
       "<polyline clip-path=\"url(#clip1201)\" style=\"stroke:#000000; stroke-width:4; stroke-opacity:1; fill:none\" points=\"\n",
       "  189.504,1463.98 221.48,1463.98 \n",
198
       "  \"/>\n",
199
200
       "<polyline clip-path=\"url(#clip1201)\" style=\"stroke:#000000; stroke-width:4; stroke-opacity:1; fill:none\" points=\"\n",
       "  189.504,1119.67 221.48,1119.67 \n",
201
       "  \"/>\n",
202
       "<polyline clip-path=\"url(#clip1201)\" style=\"stroke:#000000; stroke-width:4; stroke-opacity:1; fill:none\" points=\"\n",
203
204
       "  189.504,775.359 221.48,775.359 \n",
       "  \"/>\n",
205
206
       "<polyline clip-path=\"url(#clip1201)\" style=\"stroke:#000000; stroke-width:4; stroke-opacity:1; fill:none\" points=\"\n",
       "  189.504,431.049 221.48,431.049 \n",
207
       "  \"/>\n",
208
209
       "<polyline clip-path=\"url(#clip1201)\" style=\"stroke:#000000; stroke-width:4; stroke-opacity:1; fill:none\" points=\"\n",
       "  189.504,86.7388 221.48,86.7388 \n",
210
       "  \"/>\n",
211
212
       "<g clip-path=\"url(#clip1201)\">\n",
       "<text style=\"fill:#000000; fill-opacity:1; font-family:Arial,Helvetica Neue,Helvetica,sans-serif; font-size:48px; text-anchor:middle;\" transform=\"rotate(0, 249.837, 1557.47)\" x=\"249.837\" y=\"1557.47\">0.00</text>\n",
213
       "</g>\n",
214
215
       "<g clip-path=\"url(#clip1201)\">\n",
       "<text style=\"fill:#000000; fill-opacity:1; font-family:Arial,Helvetica Neue,Helvetica,sans-serif; font-size:48px; text-anchor:middle;\" transform=\"rotate(0, 752.609, 1557.47)\" x=\"752.609\" y=\"1557.47\">0.25</text>\n",
216
       "</g>\n",
217
218
       "<g clip-path=\"url(#clip1201)\">\n",
       "<text style=\"fill:#000000; fill-opacity:1; font-family:Arial,Helvetica Neue,Helvetica,sans-serif; font-size:48px; text-anchor:middle;\" transform=\"rotate(0, 1255.38, 1557.47)\" x=\"1255.38\" y=\"1557.47\">0.50</text>\n",
219
       "</g>\n",
220
221
       "<g clip-path=\"url(#clip1201)\">\n",
       "<text style=\"fill:#000000; fill-opacity:1; font-family:Arial,Helvetica Neue,Helvetica,sans-serif; font-size:48px; text-anchor:middle;\" transform=\"rotate(0, 1758.15, 1557.47)\" x=\"1758.15\" y=\"1557.47\">0.75</text>\n",
222
       "</g>\n",
223
224
       "<g clip-path=\"url(#clip1201)\">\n",
       "<text style=\"fill:#000000; fill-opacity:1; font-family:Arial,Helvetica Neue,Helvetica,sans-serif; font-size:48px; text-anchor:middle;\" transform=\"rotate(0, 2260.93, 1557.47)\" x=\"2260.93\" y=\"1557.47\">1.00</text>\n",
225
       "</g>\n",
226
227
       "<g clip-path=\"url(#clip1201)\">\n",
       "<text style=\"fill:#000000; fill-opacity:1; font-family:Arial,Helvetica Neue,Helvetica,sans-serif; font-size:48px; text-anchor:end;\" transform=\"rotate(0, 165.504, 1481.48)\" x=\"165.504\" y=\"1481.48\">-1.0</text>\n",
228
       "</g>\n",
229
230
       "<g clip-path=\"url(#clip1201)\">\n",
       "<text style=\"fill:#000000; fill-opacity:1; font-family:Arial,Helvetica Neue,Helvetica,sans-serif; font-size:48px; text-anchor:end;\" transform=\"rotate(0, 165.504, 1137.17)\" x=\"165.504\" y=\"1137.17\">-0.5</text>\n",
231
       "</g>\n",
232
       "<g clip-path=\"url(#clip1201)\">\n",
233
234
       "<text style=\"fill:#000000; fill-opacity:1; font-family:Arial,Helvetica Neue,Helvetica,sans-serif; font-size:48px; text-anchor:end;\" transform=\"rotate(0, 165.504, 792.859)\" x=\"165.504\" y=\"792.859\">0.0</text>\n",
       "</g>\n",
235
236
       "<g clip-path=\"url(#clip1201)\">\n",
       "<text style=\"fill:#000000; fill-opacity:1; font-family:Arial,Helvetica Neue,Helvetica,sans-serif; font-size:48px; text-anchor:end;\" transform=\"rotate(0, 165.504, 448.549)\" x=\"165.504\" y=\"448.549\">0.5</text>\n",
237
       "</g>\n",
238
239
       "<g clip-path=\"url(#clip1201)\">\n",
       "<text style=\"fill:#000000; fill-opacity:1; font-family:Arial,Helvetica Neue,Helvetica,sans-serif; font-size:48px; text-anchor:end;\" transform=\"rotate(0, 165.504, 104.239)\" x=\"165.504\" y=\"104.239\">1.0</text>\n",
240
       "</g>\n",
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
270
271
272
273
274
275
276
277
278
279
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
       "<polyline clip-path=\"url(#clip1203)\" style=\"stroke:#009af9; stroke-width:4; stroke-opacity:1; fill:none\" points=\"\n",
       "  2260.93,775.359 2257.83,782.028 2248.55,801.987 2233.14,835.058 2211.71,880.825 2184.38,938.471 2151.33,1006.57 2112.75,1082.89 2068.89,1164.18 2020,1246.11 \n",
       "  1966.41,1323.29 1908.43,1389.47 1846.43,1437.96 1780.78,1462.26 1711.89,1456.8 1640.19,1417.74 1566.11,1343.71 1490.12,1236.32 1412.68,1100.32 1334.28,943.382 \n",
       "  1255.38,775.359 1176.49,607.337 1098.08,450.394 1020.64,314.402 944.651,207.013 870.577,132.982 798.874,93.9198 729.986,88.4582 664.337,112.761 602.333,161.253 \n",
       "  544.354,227.429 490.759,304.607 441.879,386.54 398.014,467.832 359.435,544.147 326.379,612.248 299.052,669.893 277.62,715.66 262.217,748.731 252.937,768.691 \n",
       "  249.837,775.359 \n",
       "  \"/>\n",
       "<circle clip-path=\"url(#clip1203)\" style=\"fill:#000000; stroke:none; fill-opacity:1\" cx=\"2260.93\" cy=\"775.359\" r=\"18\"/>\n",
       "<circle clip-path=\"url(#clip1203)\" style=\"fill:#e26f46; stroke:none; fill-opacity:1\" cx=\"2260.93\" cy=\"775.359\" r=\"14\"/>\n",
       "<circle clip-path=\"url(#clip1203)\" style=\"fill:#000000; stroke:none; fill-opacity:1\" cx=\"2257.83\" cy=\"782.028\" r=\"18\"/>\n",
       "<circle clip-path=\"url(#clip1203)\" style=\"fill:#e26f46; stroke:none; fill-opacity:1\" cx=\"2257.83\" cy=\"782.028\" r=\"14\"/>\n",
       "<circle clip-path=\"url(#clip1203)\" style=\"fill:#000000; stroke:none; fill-opacity:1\" cx=\"2248.55\" cy=\"801.987\" r=\"18\"/>\n",
       "<circle clip-path=\"url(#clip1203)\" style=\"fill:#e26f46; stroke:none; fill-opacity:1\" cx=\"2248.55\" cy=\"801.987\" r=\"14\"/>\n",
       "<circle clip-path=\"url(#clip1203)\" style=\"fill:#000000; stroke:none; fill-opacity:1\" cx=\"2233.14\" cy=\"835.058\" r=\"18\"/>\n",
       "<circle clip-path=\"url(#clip1203)\" style=\"fill:#e26f46; stroke:none; fill-opacity:1\" cx=\"2233.14\" cy=\"835.058\" r=\"14\"/>\n",
       "<circle clip-path=\"url(#clip1203)\" style=\"fill:#000000; stroke:none; fill-opacity:1\" cx=\"2211.71\" cy=\"880.825\" r=\"18\"/>\n",
       "<circle clip-path=\"url(#clip1203)\" style=\"fill:#e26f46; stroke:none; fill-opacity:1\" cx=\"2211.71\" cy=\"880.825\" r=\"14\"/>\n",
       "<circle clip-path=\"url(#clip1203)\" style=\"fill:#000000; stroke:none; fill-opacity:1\" cx=\"2184.38\" cy=\"938.471\" r=\"18\"/>\n",
       "<circle clip-path=\"url(#clip1203)\" style=\"fill:#e26f46; stroke:none; fill-opacity:1\" cx=\"2184.38\" cy=\"938.471\" r=\"14\"/>\n",
       "<circle clip-path=\"url(#clip1203)\" style=\"fill:#000000; stroke:none; fill-opacity:1\" cx=\"2151.33\" cy=\"1006.57\" r=\"18\"/>\n",
       "<circle clip-path=\"url(#clip1203)\" style=\"fill:#e26f46; stroke:none; fill-opacity:1\" cx=\"2151.33\" cy=\"1006.57\" r=\"14\"/>\n",
       "<circle clip-path=\"url(#clip1203)\" style=\"fill:#000000; stroke:none; fill-opacity:1\" cx=\"2112.75\" cy=\"1082.89\" r=\"18\"/>\n",
       "<circle clip-path=\"url(#clip1203)\" style=\"fill:#e26f46; stroke:none; fill-opacity:1\" cx=\"2112.75\" cy=\"1082.89\" r=\"14\"/>\n",
       "<circle clip-path=\"url(#clip1203)\" style=\"fill:#000000; stroke:none; fill-opacity:1\" cx=\"2068.89\" cy=\"1164.18\" r=\"18\"/>\n",
       "<circle clip-path=\"url(#clip1203)\" style=\"fill:#e26f46; stroke:none; fill-opacity:1\" cx=\"2068.89\" cy=\"1164.18\" r=\"14\"/>\n",
       "<circle clip-path=\"url(#clip1203)\" style=\"fill:#000000; stroke:none; fill-opacity:1\" cx=\"2020\" cy=\"1246.11\" r=\"18\"/>\n",
       "<circle clip-path=\"url(#clip1203)\" style=\"fill:#e26f46; stroke:none; fill-opacity:1\" cx=\"2020\" cy=\"1246.11\" r=\"14\"/>\n",
       "<circle clip-path=\"url(#clip1203)\" style=\"fill:#000000; stroke:none; fill-opacity:1\" cx=\"1966.41\" cy=\"1323.29\" r=\"18\"/>\n",
       "<circle clip-path=\"url(#clip1203)\" style=\"fill:#e26f46; stroke:none; fill-opacity:1\" cx=\"1966.41\" cy=\"1323.29\" r=\"14\"/>\n",
       "<circle clip-path=\"url(#clip1203)\" style=\"fill:#000000; stroke:none; fill-opacity:1\" cx=\"1908.43\" cy=\"1389.47\" r=\"18\"/>\n",
       "<circle clip-path=\"url(#clip1203)\" style=\"fill:#e26f46; stroke:none; fill-opacity:1\" cx=\"1908.43\" cy=\"1389.47\" r=\"14\"/>\n",
       "<circle clip-path=\"url(#clip1203)\" style=\"fill:#000000; stroke:none; fill-opacity:1\" cx=\"1846.43\" cy=\"1437.96\" r=\"18\"/>\n",
       "<circle clip-path=\"url(#clip1203)\" style=\"fill:#e26f46; stroke:none; fill-opacity:1\" cx=\"1846.43\" cy=\"1437.96\" r=\"14\"/>\n",
       "<circle clip-path=\"url(#clip1203)\" style=\"fill:#000000; stroke:none; fill-opacity:1\" cx=\"1780.78\" cy=\"1462.26\" r=\"18\"/>\n",
       "<circle clip-path=\"url(#clip1203)\" style=\"fill:#e26f46; stroke:none; fill-opacity:1\" cx=\"1780.78\" cy=\"1462.26\" r=\"14\"/>\n",
       "<circle clip-path=\"url(#clip1203)\" style=\"fill:#000000; stroke:none; fill-opacity:1\" cx=\"1711.89\" cy=\"1456.8\" r=\"18\"/>\n",
       "<circle clip-path=\"url(#clip1203)\" style=\"fill:#e26f46; stroke:none; fill-opacity:1\" cx=\"1711.89\" cy=\"1456.8\" r=\"14\"/>\n",
       "<circle clip-path=\"url(#clip1203)\" style=\"fill:#000000; stroke:none; fill-opacity:1\" cx=\"1640.19\" cy=\"1417.74\" r=\"18\"/>\n",
       "<circle clip-path=\"url(#clip1203)\" style=\"fill:#e26f46; stroke:none; fill-opacity:1\" cx=\"1640.19\" cy=\"1417.74\" r=\"14\"/>\n",
       "<circle clip-path=\"url(#clip1203)\" style=\"fill:#000000; stroke:none; fill-opacity:1\" cx=\"1566.11\" cy=\"1343.71\" r=\"18\"/>\n",
       "<circle clip-path=\"url(#clip1203)\" style=\"fill:#e26f46; stroke:none; fill-opacity:1\" cx=\"1566.11\" cy=\"1343.71\" r=\"14\"/>\n",
       "<circle clip-path=\"url(#clip1203)\" style=\"fill:#000000; stroke:none; fill-opacity:1\" cx=\"1490.12\" cy=\"1236.32\" r=\"18\"/>\n",
       "<circle clip-path=\"url(#clip1203)\" style=\"fill:#e26f46; stroke:none; fill-opacity:1\" cx=\"1490.12\" cy=\"1236.32\" r=\"14\"/>\n",
       "<circle clip-path=\"url(#clip1203)\" style=\"fill:#000000; stroke:none; fill-opacity:1\" cx=\"1412.68\" cy=\"1100.32\" r=\"18\"/>\n",
       "<circle clip-path=\"url(#clip1203)\" style=\"fill:#e26f46; stroke:none; fill-opacity:1\" cx=\"1412.68\" cy=\"1100.32\" r=\"14\"/>\n",
       "<circle clip-path=\"url(#clip1203)\" style=\"fill:#000000; stroke:none; fill-opacity:1\" cx=\"1334.28\" cy=\"943.382\" r=\"18\"/>\n",
       "<circle clip-path=\"url(#clip1203)\" style=\"fill:#e26f46; stroke:none; fill-opacity:1\" cx=\"1334.28\" cy=\"943.382\" r=\"14\"/>\n",
       "<circle clip-path=\"url(#clip1203)\" style=\"fill:#000000; stroke:none; fill-opacity:1\" cx=\"1255.38\" cy=\"775.359\" r=\"18\"/>\n",
       "<circle clip-path=\"url(#clip1203)\" style=\"fill:#e26f46; stroke:none; fill-opacity:1\" cx=\"1255.38\" cy=\"775.359\" r=\"14\"/>\n",
       "<circle clip-path=\"url(#clip1203)\" style=\"fill:#000000; stroke:none; fill-opacity:1\" cx=\"1176.49\" cy=\"607.337\" r=\"18\"/>\n",
       "<circle clip-path=\"url(#clip1203)\" style=\"fill:#e26f46; stroke:none; fill-opacity:1\" cx=\"1176.49\" cy=\"607.337\" r=\"14\"/>\n",
       "<circle clip-path=\"url(#clip1203)\" style=\"fill:#000000; stroke:none; fill-opacity:1\" cx=\"1098.08\" cy=\"450.394\" r=\"18\"/>\n",
       "<circle clip-path=\"url(#clip1203)\" style=\"fill:#e26f46; stroke:none; fill-opacity:1\" cx=\"1098.08\" cy=\"450.394\" r=\"14\"/>\n",
       "<circle clip-path=\"url(#clip1203)\" style=\"fill:#000000; stroke:none; fill-opacity:1\" cx=\"1020.64\" cy=\"314.402\" r=\"18\"/>\n",
       "<circle clip-path=\"url(#clip1203)\" style=\"fill:#e26f46; stroke:none; fill-opacity:1\" cx=\"1020.64\" cy=\"314.402\" r=\"14\"/>\n",
       "<circle clip-path=\"url(#clip1203)\" style=\"fill:#000000; stroke:none; fill-opacity:1\" cx=\"944.651\" cy=\"207.013\" r=\"18\"/>\n",
       "<circle clip-path=\"url(#clip1203)\" style=\"fill:#e26f46; stroke:none; fill-opacity:1\" cx=\"944.651\" cy=\"207.013\" r=\"14\"/>\n",
       "<circle clip-path=\"url(#clip1203)\" style=\"fill:#000000; stroke:none; fill-opacity:1\" cx=\"870.577\" cy=\"132.982\" r=\"18\"/>\n",
       "<circle clip-path=\"url(#clip1203)\" style=\"fill:#e26f46; stroke:none; fill-opacity:1\" cx=\"870.577\" cy=\"132.982\" r=\"14\"/>\n",
       "<circle clip-path=\"url(#clip1203)\" style=\"fill:#000000; stroke:none; fill-opacity:1\" cx=\"798.874\" cy=\"93.9198\" r=\"18\"/>\n",
       "<circle clip-path=\"url(#clip1203)\" style=\"fill:#e26f46; stroke:none; fill-opacity:1\" cx=\"798.874\" cy=\"93.9198\" r=\"14\"/>\n",
       "<circle clip-path=\"url(#clip1203)\" style=\"fill:#000000; stroke:none; fill-opacity:1\" cx=\"729.986\" cy=\"88.4582\" r=\"18\"/>\n",
       "<circle clip-path=\"url(#clip1203)\" style=\"fill:#e26f46; stroke:none; fill-opacity:1\" cx=\"729.986\" cy=\"88.4582\" r=\"14\"/>\n",
       "<circle clip-path=\"url(#clip1203)\" style=\"fill:#000000; stroke:none; fill-opacity:1\" cx=\"664.337\" cy=\"112.761\" r=\"18\"/>\n",
       "<circle clip-path=\"url(#clip1203)\" style=\"fill:#e26f46; stroke:none; fill-opacity:1\" cx=\"664.337\" cy=\"112.761\" r=\"14\"/>\n",
       "<circle clip-path=\"url(#clip1203)\" style=\"fill:#000000; stroke:none; fill-opacity:1\" cx=\"602.333\" cy=\"161.253\" r=\"18\"/>\n",
       "<circle clip-path=\"url(#clip1203)\" style=\"fill:#e26f46; stroke:none; fill-opacity:1\" cx=\"602.333\" cy=\"161.253\" r=\"14\"/>\n",
       "<circle clip-path=\"url(#clip1203)\" style=\"fill:#000000; stroke:none; fill-opacity:1\" cx=\"544.354\" cy=\"227.429\" r=\"18\"/>\n",
       "<circle clip-path=\"url(#clip1203)\" style=\"fill:#e26f46; stroke:none; fill-opacity:1\" cx=\"544.354\" cy=\"227.429\" r=\"14\"/>\n",
       "<circle clip-path=\"url(#clip1203)\" style=\"fill:#000000; stroke:none; fill-opacity:1\" cx=\"490.759\" cy=\"304.607\" r=\"18\"/>\n",
       "<circle clip-path=\"url(#clip1203)\" style=\"fill:#e26f46; stroke:none; fill-opacity:1\" cx=\"490.759\" cy=\"304.607\" r=\"14\"/>\n",
       "<circle clip-path=\"url(#clip1203)\" style=\"fill:#000000; stroke:none; fill-opacity:1\" cx=\"441.879\" cy=\"386.54\" r=\"18\"/>\n",
       "<circle clip-path=\"url(#clip1203)\" style=\"fill:#e26f46; stroke:none; fill-opacity:1\" cx=\"441.879\" cy=\"386.54\" r=\"14\"/>\n",
       "<circle clip-path=\"url(#clip1203)\" style=\"fill:#000000; stroke:none; fill-opacity:1\" cx=\"398.014\" cy=\"467.832\" r=\"18\"/>\n",
       "<circle clip-path=\"url(#clip1203)\" style=\"fill:#e26f46; stroke:none; fill-opacity:1\" cx=\"398.014\" cy=\"467.832\" r=\"14\"/>\n",
       "<circle clip-path=\"url(#clip1203)\" style=\"fill:#000000; stroke:none; fill-opacity:1\" cx=\"359.435\" cy=\"544.147\" r=\"18\"/>\n",
       "<circle clip-path=\"url(#clip1203)\" style=\"fill:#e26f46; stroke:none; fill-opacity:1\" cx=\"359.435\" cy=\"544.147\" r=\"14\"/>\n",
       "<circle clip-path=\"url(#clip1203)\" style=\"fill:#000000; stroke:none; fill-opacity:1\" cx=\"326.379\" cy=\"612.248\" r=\"18\"/>\n",
       "<circle clip-path=\"url(#clip1203)\" style=\"fill:#e26f46; stroke:none; fill-opacity:1\" cx=\"326.379\" cy=\"612.248\" r=\"14\"/>\n",
       "<circle clip-path=\"url(#clip1203)\" style=\"fill:#000000; stroke:none; fill-opacity:1\" cx=\"299.052\" cy=\"669.893\" r=\"18\"/>\n",
       "<circle clip-path=\"url(#clip1203)\" style=\"fill:#e26f46; stroke:none; fill-opacity:1\" cx=\"299.052\" cy=\"669.893\" r=\"14\"/>\n",
       "<circle clip-path=\"url(#clip1203)\" style=\"fill:#000000; stroke:none; fill-opacity:1\" cx=\"277.62\" cy=\"715.66\" r=\"18\"/>\n",
       "<circle clip-path=\"url(#clip1203)\" style=\"fill:#e26f46; stroke:none; fill-opacity:1\" cx=\"277.62\" cy=\"715.66\" r=\"14\"/>\n",
       "<circle clip-path=\"url(#clip1203)\" style=\"fill:#000000; stroke:none; fill-opacity:1\" cx=\"262.217\" cy=\"748.731\" r=\"18\"/>\n",
       "<circle clip-path=\"url(#clip1203)\" style=\"fill:#e26f46; stroke:none; fill-opacity:1\" cx=\"262.217\" cy=\"748.731\" r=\"14\"/>\n",
       "<circle clip-path=\"url(#clip1203)\" style=\"fill:#000000; stroke:none; fill-opacity:1\" cx=\"252.937\" cy=\"768.691\" r=\"18\"/>\n",
       "<circle clip-path=\"url(#clip1203)\" style=\"fill:#e26f46; stroke:none; fill-opacity:1\" cx=\"252.937\" cy=\"768.691\" r=\"14\"/>\n",
       "<circle clip-path=\"url(#clip1203)\" style=\"fill:#000000; stroke:none; fill-opacity:1\" cx=\"249.837\" cy=\"775.359\" r=\"18\"/>\n",
       "<circle clip-path=\"url(#clip1203)\" style=\"fill:#e26f46; stroke:none; fill-opacity:1\" cx=\"249.837\" cy=\"775.359\" r=\"14\"/>\n",
       "<polygon clip-path=\"url(#clip1201)\" points=\"\n",
       "1958.43,312.204 2249.26,312.204 2249.26,130.764 1958.43,130.764 \n",
332
       "  \" fill=\"#ffffff\" fill-opacity=\"1\"/>\n",
333
334
335
336
337
       "<polyline clip-path=\"url(#clip1201)\" style=\"stroke:#000000; stroke-width:4; stroke-opacity:1; fill:none\" points=\"\n",
       "  1958.43,312.204 2249.26,312.204 2249.26,130.764 1958.43,130.764 1958.43,312.204 \n",
       "  \"/>\n",
       "<polyline clip-path=\"url(#clip1201)\" style=\"stroke:#009af9; stroke-width:4; stroke-opacity:1; fill:none\" points=\"\n",
       "  1982.43,191.244 2126.43,191.244 \n",
338
       "  \"/>\n",
339
       "<g clip-path=\"url(#clip1201)\">\n",
340
341
       "<text style=\"fill:#000000; fill-opacity:1; font-family:Arial,Helvetica Neue,Helvetica,sans-serif; font-size:48px; text-anchor:start;\" transform=\"rotate(0, 2150.43, 208.744)\" x=\"2150.43\" y=\"208.744\">y1</text>\n",
       "</g>\n",
342
343
344
345
346
       "<circle clip-path=\"url(#clip1201)\" style=\"fill:#000000; stroke:none; fill-opacity:1\" cx=\"2066.43\" cy=\"251.724\" r=\"25\"/>\n",
       "<circle clip-path=\"url(#clip1201)\" style=\"fill:#e26f46; stroke:none; fill-opacity:1\" cx=\"2066.43\" cy=\"251.724\" r=\"21\"/>\n",
       "<g clip-path=\"url(#clip1201)\">\n",
       "<text style=\"fill:#000000; fill-opacity:1; font-family:Arial,Helvetica Neue,Helvetica,sans-serif; font-size:48px; text-anchor:start;\" transform=\"rotate(0, 2150.43, 269.224)\" x=\"2150.43\" y=\"269.224\">y2</text>\n",
       "</g>\n",
347
348
349
       "</svg>\n"
      ]
     },
350
     "execution_count": 6,
351
352
     "metadata": {},
     "output_type": "execute_result"
353
354
355
    }
   ],
   "source": [
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
    "struct ChebyshevPoisson\n",
    "    x  :: Vector{Float64}\n",
    "    D2 :: Array{Float64, 2}\n",
    "    function ChebyshevPoisson( xmin, xmax, nx )\n",
    "        @assert( isodd(nx) )\n",
    "        N = nx-1\n",
    "        x = zeros(Float64, N+1)\n",
    "        x .= cos.(pi*(0:N)/N)\n",
    "        x .= xmin .+ (0.5 .+ 0.5 * x) * (xmax - xmin)\n",
    "        c = ones(N+1) \n",
    "        c[1] = 2\n",
    "        c[end] = 2\n",
    "        c[2:2:end-1] = -c[2:2:end-1]\n",
    "        dx = x .- transpose(x)\n",
    "        dx .+= Matrix{Float64}(I, N+1,N+1)\n",
    "        D = c ./ transpose(c) \n",
    "        D = D ./ dx  # off-diagonal entries\n",
    "        D = D - Diagonal(vec(sum(D,dims=2)))\n",
    "        D2 = zeros(Float64,(N-1,N-1))\n",
    "        D2 .= -(D*D)[2:end-1,2:end-1]\n",
    "        new( x, D2)\n",
    "    end      \n",
378
    "end\n",
379
380
381
382
383
384
385
386
387
388
389
390
391
    "\n",
    "function(p::ChebyshevPoisson)(f::Vector{Float64})\n",
    "    @assert (length(f) == length(p.x))\n",
    "    [f[1]; p.D2 \\ f[2:end-1]; f[end]]\n",
    "end\n",
    "\n",
    "xmin, xmax, nx = 0., 1., 41\n",
    "poisson = ChebyshevPoisson(xmin, xmax, nx)\n",
    "x = poisson.x\n",
    "f = sin.(2π * x) * 4π^2\n",
    "u = poisson(f)\n",
    "plot( x, sin.(2π * x) )\n",
    "scatter!( x, u)"
392
393
394
395
   ]
  },
  {
   "cell_type": "code",
396
   "execution_count": 10,
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
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
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
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
   "metadata": {},
   "outputs": [],
   "source": [
    "struct Poisson\n",
    "    \n",
    "    nx     :: Int64\n",
    "    dx     :: Float64\n",
    "    Φ      :: Array{Float64,1}\n",
    "    matrix :: SparseMatrixCSC{Float64,Int64}\n",
    "    \n",
    "    function Poisson( meshx )\n",
    "        nx = meshx.nx\n",
    "        dx = meshx.dx\n",
    "        Φ  = zeros(Float64,nx)\n",
    "        matrix = spdiagm(-1 => -ones(Float64,nx-2),\n",
    "                          0 => +2*ones(Float64,nx),\n",
    "                          1 => -ones(Float64,nx-2))\n",
    "        new( nx, dx, Φ, matrix)\n",
    "\n",
    "    end\n",
    "  \n",
    "end"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 10,
   "metadata": {},
   "outputs": [],
   "source": [
    "function (p::Poisson)( rho::Array{Float64,1} )\n",
    "    p.Φ .= p.matrix \\  rho\n",
    "    (circshift(p.Φ, 1) - circshift(p.Φ, -1)) ./ (2*p.dx)\n",
    "end  "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 11,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "compute_rho"
      ]
     },
     "execution_count": 11,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "\"\"\"\n",
    "Compute charge density\n",
    "ρ(x,t) = ∫ f(x,v,t) dv\n",
    "\"\"\"\n",
    "function compute_rho(meshv::UniformMesh, \n",
    "        f::Array{Complex{Float64},2})\n",
    "    \n",
    "   dv = meshv.dx\n",
    "   rho = dv * vec(sum(real(f), dims=2))\n",
    "   rho .- mean(rho)\n",
    "end"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# Landau Damping\n",
    "\n",
    "[Landau damping - Wikipedia](https://en.wikipedia.org/wiki/Landau_damping)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 12,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "landau (generic function with 1 method)"
      ]
     },
     "execution_count": 12,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "function landau(tf::Float64, nt::Int64)\n",
    "    \n",
    "  nx, nv = 128, 256\n",
    "  xmin, xmax = 0.0, 4*pi\n",
    "  vmin, vmax = -6., 6.\n",
    "  meshx = UniformMesh(xmin, xmax, nx)\n",
    "  meshv = UniformMesh(vmin, vmax, nv)\n",
    "  x = meshx.x\n",
    "  v = meshv.x\n",
    "  dx = meshx.dx\n",
    "  \n",
    "  # Create Vlasov-Poisson simulation\n",
    "  poisson = Poisson(meshx)\n",
    "  \n",
    "  eps, kx = 0.001, 0.5\n",
    "  f = zeros(Complex{Float64},(nx,nv))\n",
    "  f .= (1.0.+eps*cos.(kx*x))/sqrt(2π) * transpose(exp.(-0.5*v.^2))\n",
    "\n",
    "  ρ = compute_rho( meshv, f)\n",
    "  \n",
    "  e = poisson( ρ )\n",
    "  \n",
    "  ## Set time domain\n",
    "  #dt = tf / nt\n",
    "  #\n",
    "  ## Run simulation\n",
    "  #ℰ = Float64[]\n",
    "  #\n",
    "  #for it in 1:nt\n",
    "  #   advection!(f, p, meshx, v, nv, 0.5*dt)\n",
    "  #   rho = compute_rho(meshv, f)\n",
    "  #   e   = compute_e(meshx, rho)\n",
    "  #   push!(ℰ, 0.5*log(sum(e.*e)*dx))\n",
    "  #   transpose!(fᵗ, f)\n",
    "  #   advection!(fᵗ, p, meshv, e, nx, dt)\n",
    "  #   transpose!(f, fᵗ)\n",
    "  #   advection!(f, p, meshx, v, nv, 0.5*dt)\n",
    "  #end\n",
    "  #                \n",
    "  #ℰ\n",
    "  meshx.x, e\n",
    "\n",
    "end"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 13,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "image/svg+xml": [
       "<?xml version=\"1.0\" encoding=\"utf-8\"?>\n",
       "<svg xmlns=\"http://www.w3.org/2000/svg\" xmlns:xlink=\"http://www.w3.org/1999/xlink\" width=\"600\" height=\"400\" viewBox=\"0 0 2400 1600\">\n",
       "<defs>\n",
       "  <clipPath id=\"clip9500\">\n",
       "    <rect x=\"0\" y=\"0\" width=\"2000\" height=\"2000\"/>\n",
       "  </clipPath>\n",
       "</defs>\n",
       "<defs>\n",
       "  <clipPath id=\"clip9501\">\n",
       "    <rect x=\"0\" y=\"0\" width=\"2400\" height=\"1600\"/>\n",
       "  </clipPath>\n",
       "</defs>\n",
       "<polygon clip-path=\"url(#clip9501)\" points=\"\n",
       "0,1600 2400,1600 2400,0 0,0 \n",
       "  \" fill=\"#ffffff\" fill-opacity=\"1\"/>\n",
       "<defs>\n",
       "  <clipPath id=\"clip9502\">\n",
       "    <rect x=\"480\" y=\"0\" width=\"1681\" height=\"1600\"/>\n",
       "  </clipPath>\n",
       "</defs>\n",
       "<polygon clip-path=\"url(#clip9501)\" points=\"\n",
       "243.029,1503.47 2321.26,1503.47 2321.26,47.2441 243.029,47.2441 \n",
       "  \" fill=\"#ffffff\" fill-opacity=\"1\"/>\n",
       "<defs>\n",
       "  <clipPath id=\"clip9503\">\n",
       "    <rect x=\"243\" y=\"47\" width=\"2079\" height=\"1457\"/>\n",
       "  </clipPath>\n",
       "</defs>\n",
       "<polyline clip-path=\"url(#clip9503)\" style=\"stroke:#000000; stroke-width:2; stroke-opacity:0.1; fill:none\" points=\"\n",
       "  301.847,1503.47 301.847,47.2441 \n",
       "  \"/>\n",
       "<polyline clip-path=\"url(#clip9503)\" style=\"stroke:#000000; stroke-width:2; stroke-opacity:0.1; fill:none\" points=\"\n",
       "  616.342,1503.47 616.342,47.2441 \n",
       "  \"/>\n",
       "<polyline clip-path=\"url(#clip9503)\" style=\"stroke:#000000; stroke-width:2; stroke-opacity:0.1; fill:none\" points=\"\n",
       "  930.838,1503.47 930.838,47.2441 \n",
       "  \"/>\n",
       "<polyline clip-path=\"url(#clip9503)\" style=\"stroke:#000000; stroke-width:2; stroke-opacity:0.1; fill:none\" points=\"\n",
       "  1245.33,1503.47 1245.33,47.2441 \n",
       "  \"/>\n",
       "<polyline clip-path=\"url(#clip9503)\" style=\"stroke:#000000; stroke-width:2; stroke-opacity:0.1; fill:none\" points=\"\n",
       "  1559.83,1503.47 1559.83,47.2441 \n",
       "  \"/>\n",
       "<polyline clip-path=\"url(#clip9503)\" style=\"stroke:#000000; stroke-width:2; stroke-opacity:0.1; fill:none\" points=\"\n",
       "  1874.32,1503.47 1874.32,47.2441 \n",
       "  \"/>\n",
       "<polyline clip-path=\"url(#clip9503)\" style=\"stroke:#000000; stroke-width:2; stroke-opacity:0.1; fill:none\" points=\"\n",
       "  2188.82,1503.47 2188.82,47.2441 \n",
       "  \"/>\n",
       "<polyline clip-path=\"url(#clip9503)\" style=\"stroke:#000000; stroke-width:2; stroke-opacity:0.1; fill:none\" points=\"\n",
       "  243.029,1462.4 2321.26,1462.4 \n",
       "  \"/>\n",
       "<polyline clip-path=\"url(#clip9503)\" style=\"stroke:#000000; stroke-width:2; stroke-opacity:0.1; fill:none\" points=\"\n",
       "  243.029,1118.88 2321.26,1118.88 \n",
       "  \"/>\n",
       "<polyline clip-path=\"url(#clip9503)\" style=\"stroke:#000000; stroke-width:2; stroke-opacity:0.1; fill:none\" points=\"\n",
       "  243.029,775.359 2321.26,775.359 \n",
       "  \"/>\n",
       "<polyline clip-path=\"url(#clip9503)\" style=\"stroke:#000000; stroke-width:2; stroke-opacity:0.1; fill:none\" points=\"\n",
       "  243.029,431.84 2321.26,431.84 \n",
       "  \"/>\n",
       "<polyline clip-path=\"url(#clip9503)\" style=\"stroke:#000000; stroke-width:2; stroke-opacity:0.1; fill:none\" points=\"\n",
       "  243.029,88.3202 2321.26,88.3202 \n",
       "  \"/>\n",
       "<polyline clip-path=\"url(#clip9501)\" style=\"stroke:#000000; stroke-width:4; stroke-opacity:1; fill:none\" points=\"\n",
       "  243.029,1503.47 2321.26,1503.47 \n",
       "  \"/>\n",
       "<polyline clip-path=\"url(#clip9501)\" style=\"stroke:#000000; stroke-width:4; stroke-opacity:1; fill:none\" points=\"\n",
       "  243.029,1503.47 243.029,47.2441 \n",
       "  \"/>\n",
       "<polyline clip-path=\"url(#clip9501)\" style=\"stroke:#000000; stroke-width:4; stroke-opacity:1; fill:none\" points=\"\n",
       "  301.847,1503.47 301.847,1481.63 \n",
       "  \"/>\n",
       "<polyline clip-path=\"url(#clip9501)\" style=\"stroke:#000000; stroke-width:4; stroke-opacity:1; fill:none\" points=\"\n",
       "  616.342,1503.47 616.342,1481.63 \n",
       "  \"/>\n",
       "<polyline clip-path=\"url(#clip9501)\" style=\"stroke:#000000; stroke-width:4; stroke-opacity:1; fill:none\" points=\"\n",
       "  930.838,1503.47 930.838,1481.63 \n",
       "  \"/>\n",
       "<polyline clip-path=\"url(#clip9501)\" style=\"stroke:#000000; stroke-width:4; stroke-opacity:1; fill:none\" points=\"\n",
       "  1245.33,1503.47 1245.33,1481.63 \n",
       "  \"/>\n",
       "<polyline clip-path=\"url(#clip9501)\" style=\"stroke:#000000; stroke-width:4; stroke-opacity:1; fill:none\" points=\"\n",
       "  1559.83,1503.47 1559.83,1481.63 \n",
       "  \"/>\n",
       "<polyline clip-path=\"url(#clip9501)\" style=\"stroke:#000000; stroke-width:4; stroke-opacity:1; fill:none\" points=\"\n",
       "  1874.32,1503.47 1874.32,1481.63 \n",
       "  \"/>\n",
       "<polyline clip-path=\"url(#clip9501)\" style=\"stroke:#000000; stroke-width:4; stroke-opacity:1; fill:none\" points=\"\n",
       "  2188.82,1503.47 2188.82,1481.63 \n",
       "  \"/>\n",
       "<polyline clip-path=\"url(#clip9501)\" style=\"stroke:#000000; stroke-width:4; stroke-opacity:1; fill:none\" points=\"\n",
       "  243.029,1462.4 274.202,1462.4 \n",
       "  \"/>\n",
       "<polyline clip-path=\"url(#clip9501)\" style=\"stroke:#000000; stroke-width:4; stroke-opacity:1; fill:none\" points=\"\n",
       "  243.029,1118.88 274.202,1118.88 \n",
       "  \"/>\n",
       "<polyline clip-path=\"url(#clip9501)\" style=\"stroke:#000000; stroke-width:4; stroke-opacity:1; fill:none\" points=\"\n",
       "  243.029,775.359 274.202,775.359 \n",
       "  \"/>\n",
       "<polyline clip-path=\"url(#clip9501)\" style=\"stroke:#000000; stroke-width:4; stroke-opacity:1; fill:none\" points=\"\n",
       "  243.029,431.84 274.202,431.84 \n",
       "  \"/>\n",
       "<polyline clip-path=\"url(#clip9501)\" style=\"stroke:#000000; stroke-width:4; stroke-opacity:1; fill:none\" points=\"\n",
       "  243.029,88.3202 274.202,88.3202 \n",
       "  \"/>\n",
       "<g clip-path=\"url(#clip9501)\">\n",
       "<text style=\"fill:#000000; fill-opacity:1; font-family:Arial,Helvetica Neue,Helvetica,sans-serif; font-size:48px; text-anchor:middle;\" transform=\"rotate(0, 301.847, 1557.47)\" x=\"301.847\" y=\"1557.47\">0</text>\n",
       "</g>\n",
       "<g clip-path=\"url(#clip9501)\">\n",
       "<text style=\"fill:#000000; fill-opacity:1; font-family:Arial,Helvetica Neue,Helvetica,sans-serif; font-size:48px; text-anchor:middle;\" transform=\"rotate(0, 616.342, 1557.47)\" x=\"616.342\" y=\"1557.47\">2</text>\n",
       "</g>\n",
       "<g clip-path=\"url(#clip9501)\">\n",
       "<text style=\"fill:#000000; fill-opacity:1; font-family:Arial,Helvetica Neue,Helvetica,sans-serif; font-size:48px; text-anchor:middle;\" transform=\"rotate(0, 930.838, 1557.47)\" x=\"930.838\" y=\"1557.47\">4</text>\n",
       "</g>\n",
       "<g clip-path=\"url(#clip9501)\">\n",
       "<text style=\"fill:#000000; fill-opacity:1; font-family:Arial,Helvetica Neue,Helvetica,sans-serif; font-size:48px; text-anchor:middle;\" transform=\"rotate(0, 1245.33, 1557.47)\" x=\"1245.33\" y=\"1557.47\">6</text>\n",
       "</g>\n",
       "<g clip-path=\"url(#clip9501)\">\n",
       "<text style=\"fill:#000000; fill-opacity:1; font-family:Arial,Helvetica Neue,Helvetica,sans-serif; font-size:48px; text-anchor:middle;\" transform=\"rotate(0, 1559.83, 1557.47)\" x=\"1559.83\" y=\"1557.47\">8</text>\n",
       "</g>\n",
       "<g clip-path=\"url(#clip9501)\">\n",
       "<text style=\"fill:#000000; fill-opacity:1; font-family:Arial,Helvetica Neue,Helvetica,sans-serif; font-size:48px; text-anchor:middle;\" transform=\"rotate(0, 1874.32, 1557.47)\" x=\"1874.32\" y=\"1557.47\">10</text>\n",
       "</g>\n",
       "<g clip-path=\"url(#clip9501)\">\n",
       "<text style=\"fill:#000000; fill-opacity:1; font-family:Arial,Helvetica Neue,Helvetica,sans-serif; font-size:48px; text-anchor:middle;\" transform=\"rotate(0, 2188.82, 1557.47)\" x=\"2188.82\" y=\"1557.47\">12</text>\n",
       "</g>\n",
       "<g clip-path=\"url(#clip9501)\">\n",
       "<text style=\"fill:#000000; fill-opacity:1; font-family:Arial,Helvetica Neue,Helvetica,sans-serif; font-size:48px; text-anchor:end;\" transform=\"rotate(0, 219.029, 1479.9)\" x=\"219.029\" y=\"1479.9\">-0.002</text>\n",
       "</g>\n",
       "<g clip-path=\"url(#clip9501)\">\n",
       "<text style=\"fill:#000000; fill-opacity:1; font-family:Arial,Helvetica Neue,Helvetica,sans-serif; font-size:48px; text-anchor:end;\" transform=\"rotate(0, 219.029, 1136.38)\" x=\"219.029\" y=\"1136.38\">-0.001</text>\n",
       "</g>\n",
       "<g clip-path=\"url(#clip9501)\">\n",
       "<text style=\"fill:#000000; fill-opacity:1; font-family:Arial,Helvetica Neue,Helvetica,sans-serif; font-size:48px; text-anchor:end;\" transform=\"rotate(0, 219.029, 792.859)\" x=\"219.029\" y=\"792.859\">0.000</text>\n",
       "</g>\n",
       "<g clip-path=\"url(#clip9501)\">\n",
       "<text style=\"fill:#000000; fill-opacity:1; font-family:Arial,Helvetica Neue,Helvetica,sans-serif; font-size:48px; text-anchor:end;\" transform=\"rotate(0, 219.029, 449.34)\" x=\"219.029\" y=\"449.34\">0.001</text>\n",
       "</g>\n",
       "<g clip-path=\"url(#clip9501)\">\n",
       "<text style=\"fill:#000000; fill-opacity:1; font-family:Arial,Helvetica Neue,Helvetica,sans-serif; font-size:48px; text-anchor:end;\" transform=\"rotate(0, 219.029, 105.82)\" x=\"219.029\" y=\"105.82\">0.002</text>\n",
       "</g>\n",
       "<polyline clip-path=\"url(#clip9503)\" style=\"stroke:#009af9; stroke-width:4; stroke-opacity:1; fill:none\" points=\"\n",
       "  301.847,766.938 317.284,741.655 332.722,708.031 348.16,674.57 363.598,641.352 379.035,608.456 394.473,575.963 409.911,543.949 425.349,512.494 440.786,481.671 \n",
       "  456.224,451.556 471.662,422.222 487.1,393.738 502.538,366.173 517.975,339.594 533.413,314.065 548.851,289.647 564.289,266.399 579.726,244.378 595.164,223.635 \n",
       "  610.602,204.222 626.04,186.185 641.477,169.567 656.915,154.408 672.353,140.745 687.791,128.612 703.228,118.036 718.666,109.044 734.104,101.657 749.542,95.8928 \n",
       "  764.979,91.7658 780.417,89.2856 795.855,88.4582 811.293,89.2856 826.73,91.7658 842.168,95.8928 857.606,101.657 873.044,109.044 888.481,118.036 903.919,128.612 \n",
       "  919.357,140.745 934.795,154.408 950.233,169.567 965.67,186.185 981.108,204.222 996.546,223.635 1011.98,244.378 1027.42,266.399 1042.86,289.647 1058.3,314.065 \n",
       "  1073.73,339.594 1089.17,366.173 1104.61,393.738 1120.05,422.222 1135.49,451.556 1150.92,481.671 1166.36,512.494 1181.8,543.949 1197.24,575.963 1212.67,608.456 \n",
       "  1228.11,641.352 1243.55,674.57 1258.99,708.031 1274.43,741.655 1289.86,775.359 1305.3,809.064 1320.74,842.688 1336.18,876.149 1351.61,909.367 1367.05,942.263 \n",
       "  1382.49,974.756 1397.93,1006.77 1413.37,1038.23 1428.8,1069.05 1444.24,1099.16 1459.68,1128.5 1475.12,1156.98 1490.55,1184.55 1505.99,1211.12 1521.43,1236.65 \n",
       "  1536.87,1261.07 1552.31,1284.32 1567.74,1306.34 1583.18,1327.08 1598.62,1346.5 1614.06,1364.53 1629.49,1381.15 1644.93,1396.31 1660.37,1409.97 1675.81,1422.11 \n",
       "  1691.24,1432.68 1706.68,1441.68 1722.12,1449.06 1737.56,1454.83 1753,1458.95 1768.43,1461.43 1783.87,1462.26 1799.31,1461.43 1814.75,1458.95 1830.18,1454.83 \n",
       "  1845.62,1449.06 1861.06,1441.68 1876.5,1432.68 1891.94,1422.11 1907.37,1409.97 1922.81,1396.31 1938.25,1381.15 1953.69,1364.53 1969.12,1346.5 1984.56,1327.08 \n",
       "  2000,1306.34 2015.44,1284.32 2030.88,1261.07 2046.31,1236.65 2061.75,1211.12 2077.19,1184.55 2092.63,1156.98 2108.06,1128.5 2123.5,1099.16 2138.94,1069.05 \n",
       "  2154.38,1038.23 2169.82,1006.77 2185.25,974.756 2200.69,942.263 2216.13,909.367 2231.57,876.149 2247,851.109 2262.44,809.064 \n",
       "  \"/>\n",
       "<polygon clip-path=\"url(#clip9501)\" points=\"\n",
       "1958.43,251.724 2249.26,251.724 2249.26,130.764 1958.43,130.764 \n",
       "  \" fill=\"#ffffff\" fill-opacity=\"1\"/>\n",
       "<polyline clip-path=\"url(#clip9501)\" style=\"stroke:#000000; stroke-width:4; stroke-opacity:1; fill:none\" points=\"\n",
       "  1958.43,251.724 2249.26,251.724 2249.26,130.764 1958.43,130.764 1958.43,251.724 \n",
       "  \"/>\n",
       "<polyline clip-path=\"url(#clip9501)\" style=\"stroke:#009af9; stroke-width:4; stroke-opacity:1; fill:none\" points=\"\n",
       "  1982.43,191.244 2126.43,191.244 \n",
       "  \"/>\n",
       "<g clip-path=\"url(#clip9501)\">\n",
       "<text style=\"fill:#000000; fill-opacity:1; font-family:Arial,Helvetica Neue,Helvetica,sans-serif; font-size:48px; text-anchor:start;\" transform=\"rotate(0, 2150.43, 208.744)\" x=\"2150.43\" y=\"208.744\">y1</text>\n",
       "</g>\n",
       "</svg>\n"
      ]
     },
     "execution_count": 13,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "nt = 1000\n",
    "tf = 100.0\n",
    "t  = range(0.0, stop=tf, length=nt)\n",
    "x, e = landau(tf, nt)\n",
    "plot( x, e)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "metadata": {},
   "outputs": [
    {
     "ename": "MethodError",
     "evalue": "MethodError: no method matching adjoint(::Type{Poisson})\nClosest candidates are:\n  adjoint(!Matched::Missing) at missing.jl:79\n  adjoint(!Matched::Number) at number.jl:193\n  adjoint(!Matched::Adjoint{#s177,#s176} where #s176<:Union{StaticArray{Tuple{N},T,1} where T where N, StaticArray{Tuple{N,M},T,2} where T where M where N} where #s177) at /Users/navaro/.julia/packages/StaticArrays/WmJnA/src/linalg.jl:78\n  ...",
     "output_type": "error",
     "traceback": [
      "MethodError: no method matching adjoint(::Type{Poisson})\nClosest candidates are:\n  adjoint(!Matched::Missing) at missing.jl:79\n  adjoint(!Matched::Number) at number.jl:193\n  adjoint(!Matched::Adjoint{#s177,#s176} where #s176<:Union{StaticArray{Tuple{N},T,1} where T where N, StaticArray{Tuple{N,M},T,2} where T where M where N} where #s177) at /Users/navaro/.julia/packages/StaticArrays/WmJnA/src/linalg.jl:78\n  ...",
      "",
      "Stacktrace:",
      " [1] \\(::Type, ::Array{Float64,1}) at ./operators.jl:536",
      " [2] (::Poisson)(::Array{Float64,1}) at ./In[5]:2",
      " [3] landau(::Float64, ::Int64) at ./In[7]:21",
      " [4] top-level scope at util.jl:156",
      " [5] top-level scope at In[9]:6"
     ]
    }
   ],
   "source": [
    "using Profile\n",
    "\n",
    "nt = 1000\n",
    "tf = 100.0\n",
    "t  = range(0.0, stop=tf, length=nt)\n",
    "@time nrj = landau(tf, nt)\n",
    "plot( t, nrj; label = \"E\")\n",
    "plot!(t, -0.1533*t.-5.50; label=\"-0.1533t.-5.5\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "using ProfileView\n",
    "ProfileView.v"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Julia 1.0.1",
   "language": "julia",
   "name": "julia-1.0"
  },
  "language_info": {
   "file_extension": ".jl",
   "mimetype": "application/julia",
   "name": "julia",
   "version": "1.0.1"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}