Skip to content

polykin.transport.diffusion¤

profile_sphere ¤

profile_sphere(
    t: float, r: float, a: float, D: float
) -> float

Concentration profile for transient diffusion in a sphere.

For a sphere of radius \(a\), where the concentration is initially \(C_0\) everywhere, and the surface concentration is maintained at \(C_s\), the normalized concentration is:

\[ \frac{C - C_0}{C_s - C_0} = 1 + \frac{2 a}{\pi r} \sum_{n=1}^\infty \frac{(-1)^n}{n} \exp \left(-\frac{D n^2 \pi^2 t}{a^2} \right) \sin \left(\frac{n \pi r}{a} \right) \]

where \(r\) is the radial distance from the center of the sphere, \(t\) is the time, and \(D\) is the diffusion coefficient.

References

  • J. Crank, "The mathematics of diffusion", Oxford University Press, 1975, p. 91.
PARAMETER DESCRIPTION
t

Time (s).

TYPE: float

r

Radial distance from center of sphere (m).

TYPE: float

a

Radius of sphere (m).

TYPE: float

D

Diffusion coefficient (m²/s).

TYPE: float

RETURNS DESCRIPTION
float

Normalized concentration.

See also

Examples:

Determine the fractional concentration change after 100 s at the center of a polymer sphere with a radius of 0.2 mm and a diffusivity of 1e-10 m²/s.

>>> from polykin.transport.diffusion import profile_sphere
>>> profile_sphere(t=100., r=0., a=0.2e-3, D=1e-10)
0.8304935009764247
Source code in src/polykin/transport/diffusion.py
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
def profile_sphere(t: float,
                   r: float,
                   a: float,
                   D: float
                   ) -> float:
    r"""Concentration profile for transient diffusion in a sphere. 

    For a sphere of radius $a$, where the concentration is initially $C_0$
    everywhere, and the surface concentration is maintained at $C_s$, the
    normalized concentration is:

    $$ \frac{C - C_0}{C_s - C_0} =
        1 + \frac{2 a}{\pi r} \sum_{n=1}^\infty \frac{(-1)^n}{n} 
        \exp \left(-\frac{D n^2 \pi^2 t}{a^2} \right)
        \sin \left(\frac{n \pi r}{a} \right) $$

    where $r$ is the radial distance from the center of the sphere, $t$ is the
    time, and $D$ is the diffusion coefficient.

    **References**

    * J. Crank, "The mathematics of diffusion", Oxford University Press, 1975,
      p. 91.

    Parameters
    ----------
    t : float
        Time (s).
    r : float
        Radial distance from center of sphere (m).
    a : float
        Radius of sphere (m).
    D : float
        Diffusion coefficient (m²/s).

    Returns
    -------
    float
        Normalized concentration.

    See also
    --------
    * [`uptake_sphere`](uptake_sphere.md): related method to determine the mass
      uptake.

    Examples
    --------
    Determine the fractional concentration change after 100 s at the center of
    a polymer sphere with a radius of 0.2 mm and a diffusivity of 1e-10 m²/s.
    >>> from polykin.transport.diffusion import profile_sphere
    >>> profile_sphere(t=100., r=0., a=0.2e-3, D=1e-10)
    0.8304935009764247
    """
    N = 4  # Number of terms in series expansion (sufficient for convergence)

    A = 2*sqrt(D*t)/a
    B = -D*pi**2*t/a**2
    C = r/a
    if abs(C) < eps:
        # Solution for particular case r->0
        S = sum((-1 if n % 2 else 1) * exp(B*n**2) for n in range(1, N))
        result = 1 + 2*S
    else:
        if A < 1.:
            # Solution for small times
            S = sum(erfc(((2*n + 1) - C)/A) - erfc(((2*n + 1) + C)/A)
                    for n in range(0, N))
            result = S/C
        else:
            # Solution for normal times
            S = sum((-1 if n % 2 else 1) / n * exp(B*n**2) * sin(C*pi*n)
                    for n in range(1, N))
            result = 1 + (2/(pi*C))*S

    return result

Graphical Illustration¤

The numbers in the legend are values of \(D t / a^2\).

profile_sphere