Shamrock 2025.10.0
Astrophysical Code
Loading...
Searching...
No Matches
exact_solutions_coag.py
1import numpy as np
2from mpmath import mp
3
4
5def exact_sol_coag(kernel, x, tau):
6 """
7 Function to compute exact solution of the Smoluchowski equation for simple kernel (constant and additive)
8
9 Parameters
10 ----------
11 kernel : scalar, type -> integer
12 select the collisional kernel function
13 x : scalar or 1D array, type -> float
14 mass value to evaluate the solution
15 tau : scalar, type -> float
16 time to evaluate the solution
17
18
19 Returns
20 -------
21 res : scalar or 1D array, type -> float
22 exact solution evaluated at x and tau
23
24 """
25 match kernel:
26 # solution kconst, K0 = 1
27 # #g(x,0)=x exp(-x)
28 case 0:
29 if np.size(x) == 1:
30 if tau == 0.0:
31 res = x * mp.exp(-x)
32 else:
33 res = 4.0 * x / ((2.0 + tau) ** 2) * mp.exp(-(1.0 - tau / (2.0 + tau)) * x)
34
35 else:
36 if tau == 0:
37 res = [x[i] * mp.exp(-x[i]) for i in range(np.size(x))]
38 else:
39 res = [
40 4.0 * x[i] / ((2.0 + tau) ** 2) * mp.exp(-(1.0 - tau / (2.0 + tau)) * x[i])
41 for i in range(np.size(x))
42 ]
43
44 return res
45
46 # solution kadd, K0 = 1
47 # #g(x,0)=x exp(-x)
48 case 1:
49 if np.size(x) == 1:
50 if tau == 0.0:
51 res = x * mp.exp(-x)
52 else:
53 T = 1 - mp.exp(-tau)
54 res = ((1 - T) * mp.exp(-x * (T + 1)) * mp.besseli(1, 2 * x * mp.sqrt(T))) / (
55 mp.sqrt(T)
56 )
57
58 else:
59 if tau == 0:
60 res = [x[i] * mp.exp(-x[i]) for i in range(np.size(x))]
61 else:
62 T = 1 - mp.exp(-tau)
63 res = [
64 ((1 - T) * mp.exp(-x[i] * (T + 1)) * mp.besseli(1, 2 * x[i] * mp.sqrt(T)))
65 / (mp.sqrt(T))
66 for i in range(np.size(x))
67 ]
68
69 return res
70
71 case _:
72 raise ValueError("Need to choose a kernel with analytic solution.")