Skip to content

Commit 6eb1f5c

Browse files
committed
renamed inference module (still in prep)
1 parent 57205cf commit 6eb1f5c

File tree

7 files changed

+164
-0
lines changed

7 files changed

+164
-0
lines changed

05-statistical-thinking/05-inference-and-machine-learning/.DS_Store renamed to 05-statistical-thinking/module-5-inference-and-machine-learning/.DS_Store

File renamed without changes.

05-statistical-thinking/05-inference-and-machine-learning/01-bayesian-statistics-inference/draft-02-inferential_thinking_part2_v1.md renamed to 05-statistical-thinking/module-5-inference-and-machine-learning/01-bayesian-statistics-inference/draft-02-inferential_thinking_part2_v1.md

File renamed without changes.

05-statistical-thinking/05-inference-and-machine-learning/01-bayesian-statistics-inference/draft-module-outline-v1.md renamed to 05-statistical-thinking/module-5-inference-and-machine-learning/01-bayesian-statistics-inference/draft-module-outline-v1.md

File renamed without changes.

05-statistical-thinking/05-inference-and-machine-learning/01-bayesian-statistics-inference/draft-outline-v2.md renamed to 05-statistical-thinking/module-5-inference-and-machine-learning/01-bayesian-statistics-inference/draft-outline-v2.md

File renamed without changes.

05-statistical-thinking/05-inference-and-machine-learning/01-bayesian-statistics-inference/draft_01_fundamental_problem.md renamed to 05-statistical-thinking/module-5-inference-and-machine-learning/01-bayesian-statistics-inference/draft_01_fundamental_problem.md

File renamed without changes.

05-statistical-thinking/05-inference-and-machine-learning/01-bayesian-statistics-inference/draft_statistical_inference_module_v1.md renamed to 05-statistical-thinking/module-5-inference-and-machine-learning/01-bayesian-statistics-inference/draft_statistical_inference_module_v1.md

File renamed without changes.
Lines changed: 164 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,164 @@
1+
# Cell Boundary Crossing Mathematics for MCRT
2+
3+
## Ray-Grid Intersection in 3D Cartesian Coordinates
4+
5+
### Problem Statement
6+
7+
Given a photon packet at position $\vec{r}_0 = (x_0, y_0, z_0)$ traveling in direction $\hat{n} = (n_x, n_y, n_z)$ through a regular 3D grid, determine:
8+
1. The distance to the next cell boundary
9+
2. Which cell face will be crossed
10+
3. The position where optical depth accumulation should continue
11+
12+
---
13+
14+
## Mathematical Formulation
15+
16+
### 1. Distance to Next Boundary in Each Dimension
17+
18+
For each spatial dimension, calculate the distance to the nearest boundary in the direction of travel:
19+
20+
#### X-dimension:
21+
$$d_x = \begin{cases}
22+
\dfrac{x_{\text{right}} - x_0}{n_x} & \text{if } n_x > 0 \quad \text{(moving toward +x)} \\[1em]
23+
\dfrac{x_{\text{left}} - x_0}{n_x} & \text{if } n_x < 0 \quad \text{(moving toward -x)} \\[1em]
24+
\infty & \text{if } n_x = 0 \quad \text{(parallel to x-planes)}
25+
\end{cases}$$
26+
27+
#### Y-dimension:
28+
$$d_y = \begin{cases}
29+
\dfrac{y_{\text{top}} - y_0}{n_y} & \text{if } n_y > 0 \quad \text{(moving toward +y)} \\[1em]
30+
\dfrac{y_{\text{bottom}} - y_0}{n_y} & \text{if } n_y < 0 \quad \text{(moving toward -y)} \\[1em]
31+
\infty & \text{if } n_y = 0 \quad \text{(parallel to y-planes)}
32+
\end{cases}$$
33+
34+
#### Z-dimension:
35+
$$d_z = \begin{cases}
36+
\dfrac{z_{\text{back}} - z_0}{n_z} & \text{if } n_z > 0 \quad \text{(moving toward +z)} \\[1em]
37+
\dfrac{z_{\text{front}} - z_0}{n_z} & \text{if } n_z < 0 \quad \text{(moving toward -z)} \\[1em]
38+
\infty & \text{if } n_z = 0 \quad \text{(parallel to z-planes)}
39+
\end{cases}$$
40+
41+
---
42+
43+
## 2. Term Definitions
44+
45+
### Photon State Variables
46+
- **$\vec{r}_0 = (x_0, y_0, z_0)$**: Current photon position [cm]
47+
- **$\hat{n} = (n_x, n_y, n_z)$**: Unit propagation direction vector, where $|\hat{n}| = 1$
48+
49+
### Grid Parameters
50+
- **$L$**: Total box size = $3.086 \times 10^{18}$ cm (1 parsec)
51+
- **$N_{\text{grid}}$**: Number of cells per dimension = 128
52+
- **$\Delta x = \Delta y = \Delta z$**: Cell size = $L/N_{\text{grid}}$ [cm]
53+
54+
### Current Cell Indices
55+
For a position $(x_0, y_0, z_0)$, the cell indices are:
56+
$$i_x = \left\lfloor \frac{x_0 + L/2}{\Delta x} \right\rfloor, \quad i_y = \left\lfloor \frac{y_0 + L/2}{\Delta y} \right\rfloor, \quad i_z = \left\lfloor \frac{z_0 + L/2}{\Delta z} \right\rfloor$$
57+
58+
### Cell Boundary Positions
59+
For the current cell with indices $(i_x, i_y, i_z)$:
60+
61+
**X-boundaries:**
62+
- $x_{\text{left}} = i_x \cdot \Delta x - L/2$ (left face)
63+
- $x_{\text{right}} = (i_x + 1) \cdot \Delta x - L/2$ (right face)
64+
65+
**Y-boundaries:**
66+
- $y_{\text{bottom}} = i_y \cdot \Delta y - L/2$ (bottom face)
67+
- $y_{\text{top}} = (i_y + 1) \cdot \Delta y - L/2$ (top face)
68+
69+
**Z-boundaries:**
70+
- $z_{\text{front}} = i_z \cdot \Delta z - L/2$ (front face)
71+
- $z_{\text{back}} = (i_z + 1) \cdot \Delta z - L/2$ (back face)
72+
73+
---
74+
75+
## 3. Next Boundary Selection
76+
77+
The distance to the next cell boundary crossing is the minimum of the three calculated distances:
78+
79+
$$\boxed{d_{\text{next}} = \min(d_x, d_y, d_z)}$$
80+
81+
The crossed boundary type is determined by which distance equals $d_{\text{next}}$:
82+
83+
$$\text{Boundary crossed} = \begin{cases}
84+
\text{x-face at } x_{\text{right/left}} & \text{if } d_{\text{next}} = d_x \\[0.5em]
85+
\text{y-face at } y_{\text{top/bottom}} & \text{if } d_{\text{next}} = d_y \\[0.5em]
86+
\text{z-face at } z_{\text{back/front}} & \text{if } d_{\text{next}} = d_z
87+
\end{cases}$$
88+
89+
---
90+
91+
## 4. Optical Depth Accumulation
92+
93+
As the photon traverses each cell, accumulate optical depth:
94+
95+
$$\tau_{\text{accumulated}} = \tau_{\text{accumulated}} + \Delta\tau_{\text{cell}}$$
96+
97+
where the optical depth through the current cell (or portion thereof) is:
98+
99+
$$\Delta\tau_{\text{cell}} = \kappa_{\text{band}} \cdot \rho_{\text{dust}} \cdot d_{\text{step}}$$
100+
101+
### Terms:
102+
- **$\kappa_{\text{band}}$**: Band-averaged mass absorption coefficient [cm²/g dust]
103+
- **$\rho_{\text{dust}}$**: Dust density in current cell [g/cm³]
104+
- **$d_{\text{step}}$**: Distance traveled in cell [cm]
105+
106+
---
107+
108+
## 5. Interaction Position Determination
109+
110+
The photon interacts when $\tau_{\text{accumulated}} \geq \tau_{\text{target}}$.
111+
112+
### Case 1: Interaction Within Current Cell
113+
If $\tau_{\text{accumulated}} + \Delta\tau_{\text{cell}} \geq \tau_{\text{target}}$:
114+
115+
The interaction occurs at fractional distance through the cell:
116+
$$f = \frac{\tau_{\text{target}} - \tau_{\text{accumulated}}}{\kappa_{\text{band}} \cdot \rho_{\text{dust}} \cdot d_{\text{next}}}$$
117+
118+
where $0 \leq f < 1$.
119+
120+
The interaction position is:
121+
$$\vec{r}_{\text{interaction}} = \vec{r}_0 + f \cdot d_{\text{next}} \cdot \hat{n}$$
122+
123+
### Case 2: Continue to Next Cell
124+
If $\tau_{\text{accumulated}} + \Delta\tau_{\text{cell}} < \tau_{\text{target}}$:
125+
126+
Update position to the cell boundary:
127+
$$\vec{r}_{\text{new}} = \vec{r}_0 + (d_{\text{next}} + \epsilon) \cdot \hat{n}$$
128+
129+
where $\epsilon \sim 10^{-10}$ cm ensures numerical stability at boundaries.
130+
131+
---
132+
133+
## 6. Physical Interpretation
134+
135+
### Why Minimum Distance?
136+
The photon travels in a straight line and encounters whichever boundary is geometrically closest along its path. The other boundaries are not reached during this step.
137+
138+
### Sign Convention
139+
When a direction component is negative (e.g., $n_x < 0$), both the numerator and denominator in the distance calculation are negative, yielding a positive distance. This ensures all distances represent forward propagation along the ray.
140+
141+
### Parallel Motion
142+
When $n_i = 0$ for any dimension $i$, the photon travels parallel to that set of boundaries and never crosses them, hence $d_i = \infty$.
143+
144+
### Numerical Precision
145+
The epsilon adjustment ($\sim 10^{-10}$ cm) after boundary crossing prevents photons from becoming numerically "stuck" at cell interfaces due to floating-point precision limits.
146+
147+
---
148+
149+
## 7. Validation Tests
150+
151+
### Test 1: Axis-Aligned Ray
152+
For $\hat{n} = (1, 0, 0)$:
153+
- $d_x = \Delta x$ (regular spacing)
154+
- $d_y = d_z = \infty$ (never crossed)
155+
156+
### Test 2: Diagonal Ray
157+
For $\hat{n} = \frac{1}{\sqrt{3}}(1, 1, 1)$:
158+
- Distances depend on position within starting cell
159+
- Pattern of boundary crossings alternates between x, y, and z faces
160+
161+
### Test 3: Energy Conservation
162+
$$\left|L_{\text{in}} - (L_{\text{absorbed}} + L_{\text{escaped}})\right| < 0.001 \cdot L_{\text{in}}$$
163+
164+
This must hold for all packet counts and grid resolutions.

0 commit comments

Comments
 (0)