Changes between Version 5 and Version 6 of ThermalConduction


Ignore:
Timestamp:
10/13/15 13:20:05 (9 years ago)
Author:
Jonathan
Comment:

Legend:

Unmodified
Added
Removed
Modified
  • ThermalConduction

    v5 v6  
    1 == Thermal Conduction Solver ==
    2 
    3 === !!Update 5.22.2015 ===
    4 In the newer version of the code, the unit of temperature in the code or Info%q(iTemp) was changed to Kelvin from C.U.. However the following equations and source code keep the same except the term "gamma7*rho" has to be changed to function getdEdT() which gives C.U energy/Kelvin.. and no gamma7 appears...
    5 
    6 === Before temperature unit was changed to Kelvin ===
    7 
    8 The equation we are trying to solve in AstroBEAR is
    9 
    10 {{{
    11 #!latex
    12 \begin{equation}
    13 \rho c_v \frac{\partial T}{\partial t} = \nabla \left ( \kappa T^{n} \nabla T \right )
    14 \end{equation}
    15 }}}
    16 
    17 which can be "Laplacetasized" as
    18 
    19 {{{
    20 #!latex
    21 \setcounter{equation} 1
    22 \begin{equation}
    23 \rho c_v \frac{\partial T}{\partial t} =\nabla^2 \left ( \frac{1}{n+1} \kappa T^{n+1} \right )
    24 \end{equation}
    25 }}}
    26 
    27 For backward euler we evaluate the RHS at time [[latex($j+1$)]] although we still have to linearize
    28 
    29 [[latex($T_i^{{j+1}^{n+1}}$)]]
    30 
    31 So we can Taylor expand about [[latex($T_i^j$)]]
    32 
    33 
    34 [[latex($T_i^{{j+1}^{n+1}} = T_i^{j^{n+1}} + \left (n + 1 \right ) T_i^{j^n} \left ( T_i^{j+1} - T_i^j \right ) $)]]
    35 
    36 now if we substitute that back into the discretized form of equation 2 we get
    37 
    38 {{{
    39 #!latex
    40 \setcounter{equation} 2
    41 \begin{eqnarray}
    42 \rho_i c_v \left ( T_i^{j+1}-T_i^j \right ) & =  & \frac{\kappa \Delta t}{\Delta x^2}\left (T_{i+1}^{j^n}  T_{i+1}^{j+1} - 2 T_{i}^{j^n}  T_{i}^{j+1} + T_{i-1}^{j^n}  T_{i-1}^{j+1} \right ) \\
    43  & - & \frac{n \kappa \Delta t}{ \left ( n+ 1 \right ) \Delta x^2} \left (T_{i+1}^{j^{n+1}} - 2 T_{i}^{j^{n+1}} + T_{i-1}^{j^{n+1}} \right ) 
    44 \end{eqnarray}
    45 }}}
    46 
    47 == Normal CK scheme ==
    48 We can identify the left and right coefficients as
    49 
    50 [[latex($A_\pm = -\frac{\kappa \Delta t}{\Delta x^2}T_{i\pm1}^{j^n} $)]]
    51 
    52 and the center coefficient as
    53 
    54 [[latex($A_0 =  2 \frac{\kappa \Delta t}{ \Delta x^2}T_{i}^{j^n}  + \rho c_v$)]]
    55 
    56 and the RHS left and right contributions
    57 
    58 [[latex($B_\pm = -\frac{n \kappa \Delta t}{ \left ( n+ 1 \right ) \Delta x^2} T_{i\pm 1}^{j^{n+1}}$)]]
    59 
    60 and the RHS center term contribution as
    61 
    62 [[latex($B_0 = 2 \frac{n \kappa \Delta t}{ \left ( n+ 1 \right ) \Delta x^2} T_{i}^{j^{n+1}} + \rho c_v T_i^j$)]]
    63 
    64 and finally in the code the values for [[latex($A$)]] and [[latex($B$)]] are negated:
    65 
    66 {{{
    67     kx = kappa1*dt_diff/(dx**2)
    68     CALL getTemp(Info,i,j,k,T)
    69     stencil_fixed(0) = -2.0*REAL(nDim,8)*kx*T(0)**ndiff
    70     DO l = 1, 2*nDim
    71        stencil_fixed(l) = kx*T(l)**ndiff
    72     END DO
    73     source = ((ndiff)/(ndiff+1.0))*dot_product(T(0:2*nDim),stencil_fixed(0:2*nDim)) - T(0)*gamma7*Info%q(i,j,k,1)
    74     stencil_fixed(0) = stencil_fixed(0) - gamma7*Info%q(i,j,k,1)
    75 }}}
    76 
    77 also note that the equation is multipled by the mean molecular weight... which is why [[latex($c_v \rightarrow c_v \times  \chi = \gamma_7$)]] and [[latex($\kappa \rightarrow \kappa \times \chi = \kappa_1$)]]
    78 
    79 
    80 == a note about flux boundary conditions ==
    81 If we have a specified flux at a boundary - then the equation is just
    82 
    83 [[latex($\rho c_v \frac{\partial T}{\partial t} = -\nabla Q $)]]
    84 
    85 which can be discretized as
    86 
    87 [[latex($\rho_i c_v \left (T_i^{j+1}-T_i^j \right ) = \frac{-\Delta t}{\Delta x} \left ( Q_{i+1/2} - Q_{i-1/2} \right ) $)]]
    88 
    89 which leads to a center coefficient of
    90 
    91 [[latex($A_0 = \rho c_v$)]]
    92 
    93 and a left right source term contribution
    94 
    95 [[latex($B_\pm = \mp \frac{\Delta t}{\Delta x} Q_{i\pm 1/2}$)]]
    96 
    97 === Now if the left boundary is a flux boundary, but the right side is normal, then we have to adjust the coefficients ===
    98 
    99 [[latex($A_+ = -\frac{\kappa \Delta t}{\Delta x^2}T_{i+1}^{j^n} $)]]
    100 
    101 [[latex($A_- = 0 $)]]
    102 
    103 and the center coefficient as
    104 
    105 [[latex($A_0 =  \frac{2\kappa \Delta t}{ \Delta x^2}T_{i}^{j^n}  + \rho c_v$)]]
    106 
    107 and the RHS left and right contributions
    108 
    109 [[latex($B_+ = -\frac{n \kappa \Delta t}{ 2  \left ( n+ 1 \right ) \Delta x^2} T_{i+1}^{j^{n+1}}$)]]
    110 
    111 [[latex($B_-  =  \frac{\Delta t}{\Delta x} Q_{i-1/2}$)]]
    112 
    113 and the RHS center term contribution as
    114 
    115 [[latex($B_0 = \frac{2n \kappa \Delta t}{ \left ( n+ 1 \right ) \Delta x^2} T_{i}^{j^{n+1}} + \rho c_v T_i^j$)]]
    116 
    117 
    118 Of course - remembering that in AstroBEAR everything is negated...
    119 
    120 This is accomplished by
    121 {{{
    122      source = source + (ndiff/(ndiff+1.0))*(T(0)*kx*T(0)**ndiff)
    123      source = source - (ndiff/(ndiff+1.0))*(T(p)*kx*T(p)**ndiff)
    124      stencil_fixed(0)=stencil_fixed(0)+kx*T(0)**ndiff
    125      stencil_fixed(p)=0.0
    126      source = source - flb*dt_diff/dx
    127 }}}
    128 
    129 == If the right boundary is a zero-slope boundary, we have ==
    130 [[latex($T_{i+1}^{j+1}=T_{i}^{j+1}$)]]
    131 and
    132 [[latex($T_{i+1}^{j}=T_{i}^{j}$)]]
    133 
    134 So now on the right boundary, the equation becomes
    135 {{{
    136 #!latex
    137 \setcounter{equation} 4
    138 \begin{eqnarray}
    139 \rho_i c_v \left ( T_i^{j+1}-T_i^j \right ) & =  & \frac{\kappa \Delta t}{\Delta x^2}\left (- T_{i}^{j^n}  T_{i}^{j+1} + T_{i-1}^{j^n}  T_{i-1}^{j+1} \right ) \\
    140  & - & \frac{n\kappa \Delta t}{ \left ( n+ 1 \right ) \Delta x^2} \left (-  T_{i}^{j^{n+1}} + T_{i-1}^{j^{n+1}} \right ) 
    141 \end{eqnarray}
    142 }}}
    143 And the coeeficients becomes
    144 
    145 [[latex($A_+ = 0 $)]]
    146 
    147 [[latex($A_-=-\frac{\kappa \Delta t}{\Delta x^2}T_{i-1}^{j^n} $)]]
    148 
    149 [[latex($A_0=\frac{\kappa \Delta t}{\Delta x^2}T_{i}^{j^n}+ \rho c_v$)]]
    150 
    151 and the RHS left and right contributions
    152 
    153 [[latex($B_+=0 $)]]
    154 
    155 [[latex($B_-=-\frac{n \kappa \Delta t}{ \left ( n+ 1 \right ) \Delta x^2} T_{i\pm 1}^{j^{n+1}}$)]]
    156 
    157 [[latex($B_0=\frac{n \kappa \Delta t}{ \left ( n+ 1 \right ) \Delta x^2} T_{i}^{j^n}+\rho C_vT_{i}^{j}$)]]
    158 
    159 Again in AstroBEAR everything is negated
    160 
    161 This is accomplished by
    162 
    163 {{{
    164 stencil_fixed(0) =stencil_fixed(0)+kx*info%q(iq(1),iq(2),iq(3),itemp)**ndiff ! store the stencil value to temp
    165 ource = source -(ndiff)/(ndiff+1.0)*(stencil_fixed(p)*info%q(ip(1),ip(2),ip(3),itemp)+kx*info%q(iq(1),iq(2),iq(3),itemp)**(ndiff+1))
    166 stencil_fixed(p) = 0.0 ! zero out the stencil
    167 }}}
    168 
    169 == 2nd order in Time CK scheme ==
    170 Now to make the scheme 2nd order in time we can set [[latex($T_i^{j+1}=\frac{T_i^{j}+T_i^{j+1}}{2}$)]] and we get
    171 
    172 {{{
    173 #!latex
    174 \setcounter{equation} 4
    175 \begin{eqnarray}
    176 \rho_i c_v \left ( T_i^{j+1}-T_i^j \right ) & =  & \frac{\kappa \Delta t}{2 \Delta x^2}\left (T_{i+1}^{j^n}  T_{i+1}^{j+1} - 2 T_{i}^{j^n}  T_{i}^{j+1} + T_{i-1}^{j^n}  T_{i-1}^{j+1} \right ) \\
    177  & - & \frac{\left (n - 1 \right ) \kappa \Delta t}{ 2 \left ( n+ 1 \right ) \Delta x^2} \left (T_{i+1}^{j^{n+1}} - 2 T_{i}^{j^{n+1}} + T_{i-1}^{j^{n+1}} \right ) 
    178 \end{eqnarray}
    179 }}}
    180 
    181 Where we can identify the left and right coefficients as
    182 
    183 [[latex($A_\pm = -\frac{\kappa \Delta t}{2 \Delta x^2}T_{i\pm1}^{j^n} $)]]
    184 
    185 and the center coefficient as
    186 
    187 [[latex($A_0 =  2 \frac{\kappa \Delta t}{ 2\Delta x^2}T_{i}^{j^n}  + \rho c_v$)]]
    188 
    189 and the RHS left and right contributions
    190 
    191 [[latex($B_\pm = -\frac{\left (n - 1 \right ) \kappa \Delta t}{ 2  \left ( n+ 1 \right ) \Delta x^2} T_{i\pm 1}^{j^{n+1}}$)]]
    192 
    193 and the RHS center term contribution as
    194 
    195 [[latex($B_0 = 2 \frac{\left (n - 1 \right ) \kappa \Delta t}{ 2  \left ( n+ 1 \right ) \Delta x^2} T_{i}^{j^{n+1}} + \rho c_v T_i^j$)]]
    196 
    197 and finally in the code the values for [[latex($A$)]] and [[latex($B$)]] are negated:
    198 
    199 {{{
    200     kx = (0.5*kappa1*dt_diff/(dx**2))
    201     CALL getTemp(Info,i,j,k,T)
    202     stencil_fixed(0) = -2.0*REAL(nDim,8)*kx*T(0)**ndiff
    203     DO l = 1, 2*nDim
    204        stencil_fixed(l) = kx*T(l)**ndiff
    205     END DO 
    206     source = ((ndiff-1.0)/(ndiff+1.0))*dot_product(T(0:2*nDim),stencil_fixed(0:2*nDim)) - T(0)*gamma7*Info%q(i,j,k,1)
    207     stencil_fixed(0) = stencil_fixed(0) - gamma7*Info%q(i,j,k,1)
    208 }}}
    209 
    210 also note that the equation is multipled by the mean molecular weight... which is why [[latex($c_v \rightarrow c_v \times  \chi = \gamma_7$)]] and [[latex($\kappa \rightarrow \kappa \times \chi = \kappa_1$)]]
    211 
    212 
    213 == a note about flux boundary conditions ==
    214 If we have a specified flux at a boundary - then the equation is just
    215 
    216 [[latex($\rho c_v \frac{\partial T}{\partial t} = -\nabla Q $)]]
    217 
    218 which can be discretized as
    219 
    220 [[latex($\rho_i c_v \left (T_i^{j+1}-T_i^j \right ) = \frac{-\Delta t}{\Delta x} \left ( Q_{i+1/2} - Q_{i-1/2} \right ) $)]]
    221 
    222 which leads to a center coefficient of
    223 
    224 [[latex($A_0 = \rho c_v$)]]
    225 
    226 and a left right source term contribution
    227 
    228 [[latex($B_\pm = \mp \frac{\Delta t}{\Delta x} Q_{i\pm 1/2}$)]]
    229 
    230 === Now if the left boundary is a flux boundary, but the right side is normal, then we have to adjust the coefficients ===
    231 
    232 [[latex($A_+ = -\frac{\kappa \Delta t}{2 \Delta x^2}T_{i+1}^{j^n} $)]]
    233 
    234 [[latex($A_- = 0 $)]]
    235 
    236 and the center coefficient as
    237 
    238 [[latex($A_0 =  \frac{\kappa \Delta t}{ 2\Delta x^2}T_{i}^{j^n}  + \rho c_v$)]]
    239 
    240 and the RHS left and right contributions
    241 
    242 [[latex($B_+ = -\frac{\left (n - 1 \right ) \kappa \Delta t}{ 2  \left ( n+ 1 \right ) \Delta x^2} T_{i+1}^{j^{n+1}}$)]]
    243 
    244 [[latex($B_-  =  \frac{\Delta t}{\Delta x} Q_{i-1/2}$)]]
    245 
    246 and the RHS center term contribution as
    247 
    248 [[latex($B_0 = \frac{\left (n - 1 \right ) \kappa \Delta t}{ 2  \left ( n+ 1 \right ) \Delta x^2} T_{i}^{j^{n+1}} + \rho c_v T_i^j$)]]
    249 
    250 
    251 Of course - remembering that in AstroBEAR everything is negated...
    252 
    253 This is accomplished by
    254 {{{
    255      source = source + ((ndiff-1.0)/(ndiff+1.0))*(T(0)*kx*T(0)**ndiff)
    256      source = source - ((ndiff-1.0)/(ndiff+1.0))*(T(p)*kx*T(p)**ndiff)
    257      stencil_fixed(0)=stencil_fixed(0)+kx*T(0)**ndiff
    258      stencil_fixed(p)=0.0
    259      source = source - flb*dt_diff/dx
    260 }}}
    261 
    262 == If the right boundary is a zero-slope boundary, we have ==
    263 [[latex($T_{i+1}^{j+1}=T_{i}^{j+1}$)]]
    264 and
    265 [[latex($T_{i+1}^{j}=T_{i}^{j}$)]]
    266 
    267 So now on the right boundary, the equation becomes
    268 {{{
    269 #!latex
    270 \setcounter{equation} 4
    271 \begin{eqnarray}
    272 \rho_i c_v \left ( T_i^{j+1}-T_i^j \right ) & =  & \frac{\kappa \Delta t}{2 \Delta x^2}\left (- T_{i}^{j^n}  T_{i}^{j+1} + T_{i-1}^{j^n}  T_{i-1}^{j+1} \right ) \\
    273  & - & \frac{\left (n - 1 \right ) \kappa \Delta t}{ 2 \left ( n+ 1 \right ) \Delta x^2} \left (-  T_{i}^{j^{n+1}} + T_{i-1}^{j^{n+1}} \right ) 
    274 \end{eqnarray}
    275 }}}
    276 And the coeeficients becomes
    277 
    278 [[latex($A_+ = 0 $)]]
    279 
    280 [[latex($A_-=-\frac{\kappa \Delta t}{2 \Delta x^2}T_{i-1}^{j^n} $)]]
    281 
    282 [[latex($A_0=\frac{\kappa \Delta t}{2 \Delta x^2}T_{i}^{j^n}+ \rho c_v$)]]
    283 
    284 and the RHS left and right contributions
    285 
    286 [[latex($B_+=0 $)]]
    287 
    288 [[latex($B_-=-\frac{\left (n - 1 \right ) \kappa \Delta t}{ 2  \left ( n+ 1 \right ) \Delta x^2} T_{i\pm 1}^{j^{n+1}}$)]]
    289 
    290 [[latex($B_0=\frac{\left (n - 1 \right ) \kappa \Delta t}{ 2  \left ( n+ 1 \right ) \Delta x^2} T_{i}^{j^n}+\rho C_vT_{i}^{j}$)]]
    291 
    292 Again in AstroBEAR everything is negated
    293 
    294 This is accomplished by
    295 
    296 {{{
    297 stencil_fixed(0) =stencil_fixed(0)+kx*info%q(iq(1),iq(2),iq(3),itemp)**ndiff ! store the stencil value to temp
    298 !source = source -((ndiff-1.0)/(ndiff+1.0))*(stencil_fixed(p)*info%q(ip(1),ip(2),ip(3),itemp)-kx*info%q(iq(1),iq(2),iq(3),itemp)**(ndiff+1))
    299 source = source -((ndiff-1.0)/(ndiff+1.0))*(stencil_fixed(p)*info%q(ip(1),ip(2),ip(3),itemp)+kx*info%q(iq(1),iq(2),iq(3),itemp)**(ndiff+1))
    300 stencil_fixed(p) = 0.0 ! zero out the stencil
    301 }}}
    302 
    303 where the commented out line is the old-version which got the sign before the "kx" wrong.
    304 
    305 == Limiting case ==
    306 
    307 In the limit of [[latex($T \rightarrow 0$)]] with a flux from the left boundary:
    308 
    309 our equation becomes [[latex($\rho_i c_v T_i^{j+1} = \rho_i c_v T_i^j + \frac{\Delta t}{\Delta x} Q \delta_i^1$)]]
    310 
    311 and the total energy [[latex($E^{j+1}=\rho c_v \sum T_i^{j+1} \Delta x = E^{j} + \Delta t Q$)]]
    312 
    313 or [[latex($\dot{E} = Q$)]]
     1= Diffusion Solvers in AstroBEAR =
     2
     3Astrobear supports both implicit and explicit thermal diffusion that is both isotropic and anistropic.  We first derive the equations for the implicit-anisotropic case, and then discuss simplifications that arise for isotropic and explicit versions.
     4
     5== Basic Equations ==
     6
     7The anisotropic conduction equation is
     8
     9$\rho c_v\frac{\partial T}{\partial t} = \nabla \cdot \left [ n \hat{b} \left ( \chi_\parallel - \chi_\perp \right ) \left ( \hat{b} \cdot \nabla T \right ) + n \chi_\perp \nabla T \right ]$
     10
     11however, the conduction coefficients have a Temperature dependence.
     12
     13$\chi_\parallel = \kappa_\parallel T^{5/2} n^{-1}$
     14
     15$\chi_\perp = \kappa_\perp \frac{n}{B^2 T^{1/2}}$
     16
     17== Collecting power's of T ==
     18
     19So we can rewrite the equations as
     20
     21$\rho c_v \frac{\partial T}{\partial t} = \nabla \cdot \left [ \hat{b} \left ( \kappa_\parallel T^{\lambda_\parallel} - \frac{n^2 \kappa_\perp}{B^2} T^{\lambda_\perp} \right ) \left ( \hat{b} \cdot \nabla T \right ) + \frac{n^2 \kappa_\perp}{B^2} T^{\lambda_\perp} \nabla T \right ]$
     22
     23or
     24
     25$\rho c_v \frac{\partial T}{\partial t} = \nabla \cdot \left [ \hat{b} \left ( \frac{\kappa_\parallel}{\lambda_\parallel+1} \left ( \hat{b} \cdot \nabla T^{\lambda_\parallel+1} \right )  - \frac{n^2 \kappa_\perp}{B^2 \left ( \lambda_\perp+1 \right )} \left ( \hat{b} \cdot \nabla T^{\lambda_\perp + 1} \right )  \right ) + \frac{n^2 \kappa_\perp}{B^2 \left ( \lambda_\perp +1 \right )} \nabla T^{\lambda_\perp+1} \right ]$
     26
     27== Einstein simplification ==
     28
     29or in Einstein notation
     30
     31$\rho c_v \partial_t T = \partial_i \left [ b_i \left ( \frac{\kappa_\parallel}{\lambda_\parallel+1} \left ( b_j \partial_j T^{\lambda_\parallel+1} \right )  - \frac{n^2 \kappa_\perp}{B^2 \left ( \lambda_\perp+1 \right )} \left ( b_j \partial_j  T^{\lambda_\perp + 1} \right )  \right ) + \frac{n^2 \kappa_\perp}{B^2 \left ( \lambda_\perp +1 \right )} \partial_i T^{\lambda_\perp+1} \right ]$
     32
     33or
     34
     35$\rho c_v  \partial_t T = \partial_i \left [ b_i \left ( \frac{\kappa_\parallel}{\lambda_\parallel+1} \left ( b_j \partial_j T^{\lambda_\parallel+1} \right )  - \frac{n^2 \kappa_\perp}{B^2 \left ( \lambda_\perp+1 \right )} \left ( b_j \partial_j  T^{\lambda_\perp + 1} \right )  \right ) + \frac{n^2 \kappa_\perp}{B^2 \left ( \lambda_\perp +1 \right )} \delta_{ij} \partial_j T^{\lambda_\perp+1} \right ]$
     36
     37or
     38
     39$\rho c_v \partial_t T = \partial_i b_i \frac{\kappa_\parallel}{\lambda_\parallel+1} b_j \partial_j T^{\lambda_\parallel+1} +   \partial_i \left ( \delta_{ij} - b_i b_j \right ) \frac{n^2 \kappa_\perp}{B^2 \left ( \lambda_\perp + 1\right )} \partial_j T^{\lambda_\perp+1} $
     40
     41or
     42
     43$\rho c_v  \partial_t T = \frac{\kappa_\parallel}{\lambda_\parallel+1}  \partial_i b_i  b_j \partial_j T^{\lambda_\parallel+1} +   \frac{\kappa_\perp}{\left ( \lambda_\perp + 1\right )} \partial_i n^2 B^{-2} \left ( \delta_{ij} - b_i b_j \right )  \partial_j T^{\lambda_\perp +1} $
     44
     45== Implicitization ==
     46
     47Now we can rewrite the equation
     48
     49$\partial_t T = \displaystyle \sum_{\parallel, \perp} A \partial_i  B_{ij} \partial_j T^{\lambda+1}$
     50
     51where the $\parallel$ or $\perp$ subscript on $A$, $B_{ij}$, and $\lambda$ is implied. 
     52
     53$A_\parallel = \frac{\kappa_\parallel}{\rho c_v  \left ( \lambda_\parallel + 1\right ) }$ and $A_\perp = \frac{\kappa_\perp}{\rho c_v  \left (\lambda_\perp + 1 \right )}$
     54
     55and $B_{\parallel, ij} = b_i b_j$ and $B_{\perp, ij} = n^2 B^{-2} \left ( \delta_{ij}-b_i b_j \right )$
     56
     57Now to solve this implicitly, we need to replace $T$ with $T_*$ where
     58
     59$T_* = T + \phi ( T' - T ) = (1-\phi) T + \phi T'$
     60
     61Note for Backward Euler, $\phi = 1$ and for Crank Nicholson, $\phi = 1/2$
     62
     63$ \partial_t T = \displaystyle \sum_{\parallel, \perp} A \partial_i  B_{ij} \partial_j T_*^{\lambda+1}$
     64
     65It is simpler to linearize the equation in terms of $T_*$ and then subsitute then vice-versa - though both give the same answer
     66
     67$T_*^{\lambda + 1} \approx T^{\lambda + 1} +  \left ( \lambda + 1 \right ) T^{\lambda} \left ( T_{*} - T \right ) =  T^{\lambda + 1} +  \left ( \lambda + 1 \right ) T^{\lambda} \phi \left ( T' - T \right )$
     68$= \left(1 - \phi \left ( \lambda + 1\right ) \right ) T^{\lambda + 1}+  \phi \left ( \lambda + 1 \right ) T^{\lambda} T' $
     69
     70
     71So we have
     72
     73$\partial_t T = \displaystyle \sum_{\parallel, \perp}{A \partial_i  B_{ij} \partial_j \left [ \left ( 1 - \phi \left ( \lambda + 1 \right ) \right )T^{\lambda + 1} + \phi \left ( \lambda + 1 \right ) T^{\lambda} T' \right ]}$
     74
     75$\partial_t T = \displaystyle \sum_{\parallel, \perp}{A \partial_i  B_{ij} \left [ \left ( 1 - \phi \left ( \lambda + 1 \right ) \right ) \partial_j T^{\lambda + 1} + \phi \left ( \lambda + 1 \right ) \partial_j T^{\lambda} T' \right ]}$
     76
     77$\partial_t T = \displaystyle \sum_{\parallel, \perp}{A \partial_i  B_{ij} \left [ C \partial_j T^{\lambda + 1} + D \partial_j T^{\lambda} T' \right ]}$
     78
     79where $ C= \left ( 1 - \phi \left ( \lambda + 1 \right ) \right )$ and $ D = \phi \left ( \lambda + 1 \right )$
     80
     81Now we can expand the derivatives and get
     82
     83== Discretization ==
     84
     85We then need expressions for
     86
     87$ \partial_t T = \frac{ T'_0 - T_0}{\Delta t}$
     88
     89$ \partial_i B_{ij} \partial_j T^{\lambda+1} = \left [ \frac{B^{ij}_{\hat{i}} T^{\lambda+1}_{\hat{i}+\hat{j}} - B^{ij}_{\hat{i}}T^{\lambda+1}_{\hat{i}-\hat{j}}-B^{ij}_{-\hat{i}} T^{\lambda+1}_{-\hat{i}+\hat{j}} + B^{ij}_{-\hat{i}}T^{\lambda+1}_{-\hat{i}-\hat{j}}}{4 \Delta x^2} \right ] \left ( 1-\delta_{ij} \right )$
     90$ + \left [ \frac{B^{ij}_{\hat{i/2}} T^{\lambda+1}_{\hat{i}} - B^{ij}_{\hat{i/2}}T^{\lambda+1}_{0}-B^{ij}_{-\hat{i/2}} T^{\lambda+1}_{0} + B^{ij}_{-\hat{i/2}}T^{\lambda+1}_{\hat{-i}}}{\Delta x^2} \right ] \delta_{ij} $
     91
     92$ \partial_i B_{ij} \partial_j T^{\lambda}T' =  \left [ \frac{B^{ij}_{\hat{i}} T^{\lambda}_{\hat{i}+\hat{j}}T'_{\hat{i}+\hat{j}} - B^{ij}_{\hat{i}}T^{\lambda}_{\hat{i}-\hat{j}}T'_{\hat{i}-\hat{j}}-B^{ij}_{-\hat{i}} T^{\lambda}_{-\hat{i}+\hat{j}}T'_{-\hat{i}+\hat{j}} + B^{ij}_{-\hat{i}}T^{\lambda}_{-\hat{i}-\hat{j}}T'_{-\hat{i}-\hat{j}}}{4 \Delta x^2} \right ]  \left ( 1-\delta_{ij} \right )  $
     93$+ \left [ \frac{B^{ij}_{\hat{i/2}} T^{\lambda}_{\hat{i}}T'_{\hat{i}} - B^{ij}_{\hat{i/2}}T^{\lambda}_{0}T'_{0}-B^{ij}_{-\hat{i/2}} T^{\lambda}_{0}T'_{0} + B^{ij}_{-\hat{i/2}}T^{\lambda}_{-\hat{i}}T'_{-\hat{i}}}{\Delta x^2} \right ] \delta_{ij}$
     94
     95Using the above definitions, we can write the discretized equation as
     96
     97
     98$T_0 + \Delta t \displaystyle \sum_{\parallel, \perp} AC \left [ \alpha_0 T^{\lambda+1}_0 +  \displaystyle \sum_{\pm j} \alpha_{\pm j} T^{\lambda+1}_{\pm \hat{j}} +  \sum_{\pm i, \pm j,i \ne j} \alpha_{\pm i, \pm j} T^{\lambda+1}_{\pm \hat{i} \pm \hat{j}} \right ] = $
     99$T'_0 - \Delta t \displaystyle \sum_{\parallel, \perp} AD \left [  \alpha_0 T^{\lambda}_0T'_0 + \displaystyle \sum_{\pm j} \alpha_{\pm j} T^{\lambda}_{\pm \hat{j}} T'_{\pm \hat{j}} + \sum_{\pm i, \pm j,i \ne j} \alpha_{\pm i, \pm j} T^{\lambda}_{\pm \hat{i} \pm \hat{j}} T'_{\pm \hat{i} \pm \hat{j}} \right ]$
     100
     101where
     102
     103$\alpha_0 = - \displaystyle \sum_{i} \frac{B^{ii}_{\hat{i}} + B^{ii}_{-\hat{i}}}{\Delta x^2}$
     104
     105$\alpha_{\pm i} = \frac{B^{ii}_{\pm \hat{i}}}{\Delta x^2}$
     106
     107$\alpha_{\pm i, \pm j} =  \pm \pm \frac{B^{ij}_{\pm \hat{i}}}{4 \Delta x^2} $ where the $\pm$ in $B_{\pm \hat{i}}$ corresponds to the $\pm i$ term.
     108
     109
     110Also note, that the indexing of the temperatures is commutative, and that all of the diagonal temperature terms will have two contributions.  One from $\alpha_{\pm i \pm j}$ and one from $\alpha_{\pm j \pm i}$.  We can rewrite
     111
     112$\displaystyle \sum_{\pm i, \pm j,i \ne j} \alpha_{\pm i, \pm j} T^{\lambda+1}_{\pm \hat{i} \pm \hat{j}} = \sum_{\pm i, \pm j,i < j} \left ( \alpha_{\pm i, \pm j} + \alpha_{\pm j, \pm i} \right ) T^{\lambda+1}_{\pm \hat{i} \pm \hat{j}} $
     113$= \sum_{\pm i, \pm j,i < j} \alpha*_{\pm i, \pm j}T^{\lambda+1}_{\pm \hat{i} \pm \hat{j}}$
     114
     115where
     116
     117$\alpha*_{\pm i \pm j} = \pm \pm \frac{B^{ij}_{\pm \hat{i}}+B^{ji}_{\pm \hat{j}}}{4 \Delta x^2}$
     118
     119
     120== Summary ==
     121
     122||  ||   $\parallel$   ||   $\perp$   ||
     123|| $A$ || $\frac{\kappa_\parallel}{\rho c_v  \left ( \lambda_\parallel + 1 \right ) }$ || $\frac{\kappa_\perp}{\rho c_v  \left (\lambda_\perp + 1\right )}$ ||
     124|| $B_{ij} $ || $b_i b_j$ || $n^2 B^{-2} \left (\delta_{ij} - b_i b_j \right )$ ||
     125|| $C$ ||  $\left ( 1 - \phi \left ( \lambda_\parallel + 1 \right ) \right )$ ||  $ \left ( 1 - \phi \left ( \lambda_\perp + 1 \right ) \right )$ ||
     126|| $D$ ||  $\phi \left ( \lambda_\parallel + 1 \right )$ ||  $ \phi \left ( \lambda_\perp + 1 \right ) $||
     127
     128||$\alpha_0$ || $- \displaystyle \sum_{i} \frac{B^{ii}_{\hat{i}} + B^{ii}_{-\hat{i}}}{\Delta x^2}$ ||
     129||$\alpha_{\pm i}$ || $ \frac{B^{ii}_{\pm \hat{i}}}{\Delta x^2}$ ||
     130|| $\alpha*_{\pm i \pm j}$ || $ \pm \pm \frac{B^{ij}_{\pm \hat{i}}+B^{ji}_{\pm \hat{j}}}{4 \Delta x^2}$ ||
     131
     132
     133=== Effective diffusion coeffiient ==
     134
     135The traditional diffusion equation looks like
     136
     137$\frac{\partial T}{\partial t} =  D \nabla^2 T$
     138
     139where $D$ is the diffusion coefficient.  For uniform density, magnetic field, and for $\lambda = 0$, the equations revert to the traditional diffusion equation with
     140
     141$D = \frac{n \chi}{\rho c_v}$
     142
     143
     144=== Isotropic Case ===
     145
     146For the Isotropic Case, the diffusion equation looks like
     147
     148$\rho c_v \frac{\partial T}{\partial t} = \nabla \cdot \kappa T^\lambda \nabla T$
     149
     150or
     151
     152$\rho c_v \frac{\partial T}{\partial t} = \nabla \cdot \frac{\kappa}{\lambda+1} \nabla T^{\lambda+1}$
     153
     154or in Einstein notation
     155
     156$\rho c_v \partial_t T = \partial_i \frac{\kappa}{\lambda+1} \partial_i T^{\lambda+1}$
     157
     158which we can rewrite as
     159
     160$\partial_t T = A \partial_i B \partial i T^{\lambda+1}$
     161
     162$\partial_t T = A \partial_i B \delta_{ij} \partial j T^{\lambda+1}$
     163
     164This is the exact same form as before, but now
     165
     166$B_{ij}=\kappa \delta{ij}$
     167
     168is diagonal so the cross terms vanish
     169
     170and $\alpha_{\pm i, \pm j} = 0$
     171
     172and it is independent of direction, so it is just a scalar.
     173
     174
     175||$\alpha_0$ || $- \displaystyle \sum_{i} \frac{B_{\hat{i}} + B_{-\hat{i}}}{\Delta x^2}$ ||
     176||$\alpha_{\pm i}$ || $ \frac{B_{\pm \hat{i}}}{\Delta x^2}$ ||
     177|| $\alpha*_{\pm i \pm j}$ || $ 0$ ||
     178
     179Also if $\kappa$ is a constant, then we have
     180
     181||$\alpha_0$ || $- \displaystyle \sum_{i} \frac{2B}{\Delta x^2}$ ||
     182||$\alpha_{\pm i}$ || $ \frac{B}{\Delta x^2}$ ||
     183|| $\alpha*_{\pm i \pm j}$ || $ 0$ ||
     184
     185
     186
     187=== Time stepping ===
     188The implicit method requires approximating
     189
     190$T*^{\lambda+1} = T^{\lambda + 1} +  \left ( \lambda + 1 \right ) T^{\lambda} \left [ \left ( T_{*} - T \right ) + \frac{\lambda}{2} \frac{T_{*} - T}{T} \right ]$
     191
     192but solving this accurately with a linear method requires
     193
     194$\frac{T_{*}-T}{T} << 1$
     195
     196but this restricts our time step.  Using the instantaneous derivatives, we can calculate the maximum time step as
     197
     198
     199$T_0'-T_0 \approx \displaystyle \sum_{\parallel, \perp} \left [ \alpha_0 T^{\lambda+1}_0 +  \displaystyle \sum_{\pm j} \alpha_{\pm j} T^{\lambda+1}_{\pm \hat{j}} +  \sum_{\pm i, \pm j,i \ne j} \alpha_{\pm i, \pm j} T^{\lambda+1}_{\pm \hat{i} \pm \hat{j}} \right ]$
     200
     201so
     202
     203$\Delta t < \epsilon \frac{T_0}{\displaystyle \sum_{\parallel, \perp} \left [ \alpha_0 T^{\lambda+1}_0 +  \displaystyle \sum_{\pm j} \alpha_{\pm j} T^{\lambda+1}_{\pm \hat{j}} +  \sum_{\pm i, \pm j,i \ne j} \alpha_{\pm i, \pm j} T^{\lambda+1}_{\pm \hat{i} \pm \hat{j}} \right ]}$
     204
     205=== Explicit Case ===
     206
     207For the Explicit case, we just set $\phi = 0$ which sets $D = 0$ and $C=1$ and we have
     208
     209$T_0 +  \Delta t \displaystyle \sum_{\parallel, \perp} A \left [ \alpha_0 T^{\lambda+1}_0 +  \displaystyle \sum_{\pm j} \alpha_{\pm j} T^{\lambda+1}_{\pm \hat{j}} +  \sum_{\pm i, \pm j,i \ne j} \alpha_{\pm i, \pm j} T^{\lambda+1}_{\pm \hat{i} \pm \hat{j}} \right ] = T'_0$
     210
     211=== Explicit time stepping ===
     212
     213For the explicit scheme to be stable, we must have
     214
     215$\Delta t < \frac{1}{2\displaystyle \max_{\parallel, \perp, i} A \left [ | \alpha_i T_i^{\lambda} |  \right ]}$
     216
     217
     218=== Flux limiting ===
     219Limiting the fluxes in the explicit case is not too difficult, however in the implicit case, we cannot limit the flux directly, but must instead, limit the conductivities.
     220
     221$n \chi_\parallel \hat{b} \cdot \nabla T < 5 \phi \rho c_s^3 \rightarrow \chi_\parallel < \frac{5 \phi \rho c_s^3}{n \hat{b} \cdot \nabla T} \equiv \chi_{\max}$
     222
     223We can limit $\chi$ using $\chi = \min{\left ( \chi, \chi_{\max} \right )}$ or do something like
     224
     225$\chi = \chi_{\max} \tanh \frac{\chi}{\chi_{\max}}$
     226
     227
     228
     229=== Boundary Terms ===
     230
     231==== Explicit ====
     232
     233Here, the boundary terms are quite straightforward.  We can just use the regular boundary conditions (or user specified boundary conditions).  The only difficulty arises when trying to set a heat flux since this involves solving a non-linear equation.  One solution is to set the heat flux explicitly - instead of indirectly through the temprature.   Then use extrapolating (pr reflecting) BC's for temperature so there is no heat flux initially calculated along the boundary - and then add in the flux in a separate step.
     234
     235==== Implicit ====
     236
     237For reflecting - or extrapolating boundary terms, we can just transfer the coefficients for the boundary terms and apply them to their mirror zone.  The only thing to be careful about - is that for the anisotropic case, there are corner zones who's coefficients may need to be transferred twice.  This just requires transferring corner zone coefficients, to edge zones, before transferring edge zones, to the central cell in the stencil.