Skip to content

Commit 075af6a

Browse files
Nush395Torax team
authored andcommitted
Update documentation to refer to use of non uniform grid.
PiperOrigin-RevId: 861591200
1 parent fda71f3 commit 075af6a

File tree

4 files changed

+61
-19
lines changed

4 files changed

+61
-19
lines changed

docs/configuration.rst

Lines changed: 30 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -861,14 +861,42 @@ geometry
861861

862862
Geometry dicts for all geometry types can contain the following additional keys.
863863

864-
``n_rho`` (int [default = 25])
865-
Number of radial grid points
864+
``n_rho`` (int | None [default = 25])
865+
Number of radial grid cells. Creates a uniform grid with cell width
866+
:math:`d\hat{\rho} = 1/n\_rho`. Must be at least 4.
867+
Either ``n_rho`` or ``face_centers`` must be specified.
868+
869+
``face_centers`` (array | None [default = None])
870+
Explicit array of face center coordinates in normalized :math:`\hat{\rho}`
871+
(ranging from 0 to 1) for defining non-uniform radial grids. For a grid with
872+
N cells, there should be N+1 face centers. The array must start at 0.0, end
873+
at 1.0, be strictly increasing, and have at least 5 elements (4 cells).
874+
This enables finer resolution in regions of interest, such as
875+
near the plasma edge.
876+
877+
Example of a non-uniform grid with finer resolution near the edge:
878+
879+
.. code-block:: python
880+
881+
import numpy as np
882+
883+
# Create non-uniform grid: coarse in core, fine near edge
884+
core_faces = np.linspace(0, 0.8, 9) # 8 cells from rho=0 to rho=0.8
885+
edge_faces = np.linspace(0.8, 1.0, 9)[1:] # 8 cells from rho=0.8 to rho=1.0
886+
face_centers = np.concatenate([core_faces, edge_faces])
887+
888+
'geometry': {
889+
'geometry_type': 'chease',
890+
'face_centers': face_centers,
891+
# ... other geometry parameters
892+
}
866893
867894
``hires_factor`` (int [default = 4])
868895
Only used when the initial condition ``psi`` is from plasma current. Sets up a
869896
higher resolution mesh with ``nrho_hires = nrho * hi_res_fac``, used for
870897
``j`` to ``psi`` conversions.
871898

899+
872900
Geometry dicts for all non-circular geometry types can contain the following
873901
additional keys.
874902

docs/fvm.rst

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,10 @@ arbitrary mesh topologies. `torax.fvm` is much less general ---it
2626
avoids hard-coded Tokamak physics into `torax.fvm` but has not attempted
2727
to include any more features than needed for the Tokamak core transport
2828
problem. `torax.fvm` thus supports only one topology, the 1-D
29-
grid topology. However, within this restricted domain, `torax.fvm`
29+
grid topology, though it does support both uniform and non-uniform radial
30+
grids (see :ref:`configuration` for details on configuring the grid via
31+
``n_rho`` or ``face_centers``).
32+
However, within this restricted domain, `torax.fvm`
3033
offers a variety of solver techniques not available in `fipy`,
3134
especially solver techniques that are possible only with differentiable
3235
solvers, in our case enabled by JAX. For example, in `torax.fvm` the

docs/solver_details.rst

Lines changed: 23 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,15 @@ The TORAX JAX 1D FVM library is significantly influenced by
1616
library API. This section summarizes 1D FVM numerics in general.
1717

1818
The 1D spatial domain, :math:`0 \leq \hat{\rho} \leq 1`, is divided into a
19-
uniform grid of :math:`N` cells, each with a width of
20-
:math:`d \hat{\rho} = 1/N`. The cell centers are denoted by
21-
:math:`\hat{\rho}_i`, where :math:`0 = 1, 2,..., N-1`, and the :math:`N+1` cell
22-
faces are located at :math:`\hat{\rho}_{i\pm1/2}`. Both :math:`\hat{\rho}=0` and
19+
grid of :math:`N` cells. TORAX supports both uniform grids (configured via
20+
``n_rho``) and non-uniform grids (configured via ``face_centers``). For uniform
21+
grids, each cell has width :math:`d \hat{\rho} = 1/N`. For non-uniform grids,
22+
cell widths :math:`d \hat{\rho}_i` vary across the domain, enabling finer
23+
resolution in regions of interest such as near the plasma edge.
24+
25+
The cell centers are denoted by :math:`\hat{\rho}_i`, where
26+
:math:`i = 0, 1, 2,..., N-1`, and the :math:`N+1` cell faces are located at
27+
:math:`\hat{\rho}_{i\pm1/2}`. Both :math:`\hat{\rho}=0` and
2328
:math:`\hat{\rho}=1` are on the face grid.
2429

2530
For a generic conservation law of the form:
@@ -37,12 +42,14 @@ of finite differences:
3742

3843
.. math::
3944
40-
\frac{\partial }{\partial t}(x_i) + \frac{1}{d \hat{\rho}}({\Gamma}_{i+1/2}
45+
\frac{\partial }{\partial t}(x_i) + \frac{1}{d \hat{\rho}_i}({\Gamma}_{i+1/2}
4146
- {\Gamma}_{i-1/2}) = S_i
4247
4348
where: :math:`x_i` is the cell-averaged value of :math:`x` in cell :math:`i`,
44-
:math:`\Gamma_{i+1/2}` is the flux at face :math:`i+1/2`, and :math:`S_i` is the
45-
cell-averaged source term in cell :math:`i`.
49+
:math:`\Gamma_{i+1/2}` is the flux at face :math:`i+1/2`, :math:`S_i` is the
50+
cell-averaged source term in cell :math:`i`, and :math:`d \hat{\rho}_i` is the
51+
width of cell :math:`i` (which may vary for non-uniform grids).
52+
4653

4754
In general, the fluxes in TORAX are decomposed as
4855

@@ -55,9 +62,9 @@ convection coefficient, leading to:
5562
.. math::
5663
5764
\begin{aligned}
58-
\Gamma_{i+1/2} &= -D_{i+1/2}\frac{x_{i+1} - x_{i}}{d\hat{\rho}} +
65+
\Gamma_{i+1/2} &= -D_{i+1/2}\frac{x_{i+1} - x_{i}}{\hat{\rho}_{i+1} - \hat{\rho}_{i}} +
5966
V_{i+1/2}x_{i+1/2} \\
60-
\Gamma_{i-1/2} &= -D_{i-1/2}\frac{x_{i} - x_{i-1}}{d\hat{\rho}} +
67+
\Gamma_{i-1/2} &= -D_{i-1/2}\frac{x_{i} - x_{i-1}}{\hat{\rho}_{i} - \hat{\rho}_{i-1}} +
6168
V_{i-1/2}x_{i-1/2}
6269
\end{aligned}
6370
@@ -78,9 +85,11 @@ defined as:
7885

7986
.. math::
8087
81-
Pe = \frac{V d \hat{\rho}}{D}
88+
Pe = \frac{V d \hat{\rho}_i}{D}
8289
83-
where :math:`V` is convection and :math:`D` is diffusion. The power-law scheme
90+
where :math:`V` is convection, :math:`D` is diffusion, and
91+
:math:`d \hat{\rho}_i` is the local cell width (which varies for non-uniform
92+
grids). The power-law scheme
8493
is as follows:
8594

8695
.. math::
@@ -327,9 +336,10 @@ as follows.
327336

328337
.. math::
329338
330-
\Delta t_{ \mathrm{base}}=\frac{(d\hat{\rho})^2}{2\chi_{\max}}
339+
\Delta t_{ \mathrm{base}}=\frac{(d\hat{\rho}_{\min})^2}{2\chi_{\max}}
331340
332-
where
341+
where :math:`d \hat{\rho}_{\min}` is the minimum cell width (for non-uniform
342+
grids, this is the smallest cell; for uniform grids, all cells are equal), and
333343
:math:`\Delta t = c_{ \mathrm{mult}}^{dt} \Delta t_{ \mathrm{base}}`.
334344

335345
:math:`c_{ \mathrm{mult}}^{dt}` is a user-configurable prefactor.

torax/_src/math_utils.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -68,10 +68,11 @@ def cell_to_face(
6868
"""Convert cell values to face values.
6969
7070
We make three assumptions:
71-
1) Inner face values are the average of neighbouring cells.
71+
1) Inner face values are the interpolation of neighboring cell values.
7272
2) The left most face value is linearly extrapolated from the left most cell
73-
values.
74-
3) The transformation from cell to face is integration preserving.
73+
values.
74+
3) The transformation from cell to face is integration preserving and the
75+
quantity to preserve the integral of is specified by `preserved_quantity`.
7576
7677
Args:
7778
cell_values: Values defined on the TORAX cell grid.

0 commit comments

Comments
 (0)