Skip to content

Commit

Permalink
Merge pull request #25 from karllark/internal_observer
Browse files Browse the repository at this point in the history
Add an internal observer as an option
  • Loading branch information
karllark committed Nov 21, 2023
2 parents ff67af7 + 91e8e4d commit 901e6e4
Show file tree
Hide file tree
Showing 34 changed files with 924 additions and 548 deletions.
35 changes: 35 additions & 0 deletions .readthedocs.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
# Read the Docs configuration file for Sphinx projects
# See https://docs.readthedocs.io/en/stable/config-file/v2.html for details

# Required
version: 2

# Set the OS, Python version and other tools you might need
build:
os: ubuntu-22.04
tools:
python: "3.12"
# You can also specify other tool versions:
# nodejs: "20"
# rust: "1.70"
# golang: "1.20"

# Build documentation in the "docs/" directory with Sphinx
sphinx:
configuration: docs/conf.py
# You can configure Sphinx to use a different builder, for instance use the dirhtml builder for simpler URLs
# builder: "dirhtml"
# Fail on all warnings to avoid broken references
# fail_on_warning: true

# Optionally build your docs in additional formats such as PDF and ePub
# formats:
# - pdf
# - epub

# Optional but recommended, declare the Python requirements required
# to build your documentation
# See https://docs.readthedocs.io/en/stable/guides/reproducible-builds.html
# python:
# install:
# - requirements: docs/requirements.txt
6 changes: 0 additions & 6 deletions .rtd-environment.yml

This file was deleted.

57 changes: 33 additions & 24 deletions DIRTY/calc_delta_dist.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,10 @@
double calc_delta_dist (photon_data& photon,
geometry_struct& geometry,
double target_tau,
double target_dist,
int& escape,
double& tau_traveled)

{
#ifdef DEBUG_CDD
if (photon.number == OUTNUM) {
Expand Down Expand Up @@ -101,7 +102,7 @@ double calc_delta_dist (photon_data& photon,
if (photon.number == OUTNUM) {
cout << "new "; cout.flush();
}

// add in handling of subgrids
// check if photon has already been in this grid
// basically, are we restarting the photon tracking in a subgrid?
Expand Down Expand Up @@ -138,9 +139,9 @@ double calc_delta_dist (photon_data& photon,
cout << geometry.grids[photon.grid_number[photon.current_grid_num]].grid.n3rd() << endl;
}
#endif
distance_traveled = calc_photon_trajectory(photon, geometry, target_tau, escape, tau_traveled);

distance_traveled = calc_photon_trajectory(photon, geometry, target_tau, target_dist, escape, tau_traveled);

#ifdef DEBUG_CDD
if (photon.number == OUTNUM) {
cout << "emerging from subgrid" << endl;
Expand All @@ -161,9 +162,9 @@ double calc_delta_dist (photon_data& photon,
escape_grid = 1;
exit_cell = 1;
for (i = 0; i < 3; i++) {
if (((photon.dir_cosines[i] > 0.0) &&
if (((photon.dir_cosines[i] > 0.0) &&
(photon.position[i] == geometry.grids[photon.grid_number[photon.current_grid_num]].positions[i][photon.position_index[k][i]+1])) ||
((photon.dir_cosines[i] < 0.0) &&
((photon.dir_cosines[i] < 0.0) &&
(photon.position[i] == geometry.grids[photon.grid_number[photon.current_grid_num]].positions[i][photon.position_index[k][i]])))
min_index = i;
#ifdef DEBUG_CDD
Expand All @@ -180,6 +181,9 @@ double calc_delta_dist (photon_data& photon,
if (fabs(target_tau - tau_traveled) < ROUNDOFF_ERR_TRIG) {
if (!escape_grid) exit_cell = 0;
escape = 1;
} else if (fabs(target_dist - distance_traveled) < ROUNDOFF_ERR_TRIG) {
if (!escape_grid) exit_cell = 0;
escape = 1;
}

#ifdef DEBUG_CDD
Expand All @@ -203,7 +207,7 @@ double calc_delta_dist (photon_data& photon,
double delta_position[3]; // x,y,z distance to the edge of the cell (parallel to the x,y,z axes)
double delta_distance[3]; // distance the photon would need to travelel to exit the cell in the x,y,z directions

// determine the x,y,z distances to the edge of the cell
// determine the x,y,z distances to the edge of the cell
// this is parallel to the x,y,z axes
int i = 0;
#ifdef DEBUG_CDD
Expand All @@ -214,17 +218,17 @@ double calc_delta_dist (photon_data& photon,
for (i = 0; i < 3; i++) {
if (photon.dir_cosines[i] > 0.0) {
delta_position[i] = geometry.grids[photon.grid_number[photon.current_grid_num]].positions[i][photon.position_index[k][i]+1] -
photon.position[i];
photon.position[i];
} else if (photon.dir_cosines[i] < 0.0) {
delta_position[i] = photon.position[i] -
delta_position[i] = photon.position[i] -
geometry.grids[photon.grid_number[photon.current_grid_num]].positions[i][photon.position_index[k][i]];
} else { // photon.dir_cosines[i] == 0.0
delta_position[i] = 0.0;
}

// calculate the distance the photon would have to travel in each x,y,z direction
// to exit the cell
if (photon.dir_cosines[i] != 0.0)
if (photon.dir_cosines[i] != 0.0)
delta_distance[i] = fabs(delta_position[i]/photon.dir_cosines[i]);
else
delta_distance[i] = 0.0;
Expand All @@ -244,12 +248,12 @@ double calc_delta_dist (photon_data& photon,
}
#endif
}

// determine the first axis the photon exits along
// minumum distance traveled
double min_dist = 1e20;
min_index = -1;
for (i = 0; i < 3; i++)
for (i = 0; i < 3; i++)
if ((delta_distance[i] < min_dist) && (delta_distance[i] >= 0.) &&
(!((photon.dir_cosines[i] == 0.0) && (delta_distance[i] == 0.0)))) {
min_dist = delta_distance[i];
Expand All @@ -274,19 +278,24 @@ double calc_delta_dist (photon_data& photon,
cout << geometry.grids[photon.grid_number[photon.current_grid_num]].grid.nCol() << " ";
cout << geometry.grids[photon.grid_number[photon.current_grid_num]].grid.n3rd() << endl;
}
#endif
#endif
// save the current cell dust coeff (tau/pc)
// and distance traveled
distance_traveled = delta_distance[min_index];

// determine the optical depth transversed before the photon exits the cell
tau_traveled = dust_tau_per_pc*distance_traveled;

// if this tau_traveled is larger than the amount of tau_left, then decrease the distance traveled

// if this tau_traveled is larger than the amount of tau_left, then decrease the distance/tau traveled
// 2nd if statement is the same for distance
if (tau_traveled > target_tau) {
distance_traveled *= target_tau/tau_traveled;
tau_traveled = target_tau;
exit_cell = 0;
} if (distance_traveled > target_dist) {
tau_traveled *= target_dist/distance_traveled;
distance_traveled = target_dist;
exit_cell = 0;
}

// if (photon.number == OUTNUM) {
Expand All @@ -299,7 +308,7 @@ double calc_delta_dist (photon_data& photon,
// for (i = 0; i < 3; i++) cout << photon.dir_cosines[i] << " ";
// cout << endl;
// }

#ifdef DEBUG_CDD
if (photon.number == OUTNUM) {
cout << "path info" << endl;
Expand All @@ -309,7 +318,7 @@ double calc_delta_dist (photon_data& photon,
cout << geometry.grids[photon.grid_number[photon.current_grid_num]].grid.nCol() << " ";
cout << geometry.grids[photon.grid_number[photon.current_grid_num]].grid.n3rd() << endl;
}
#endif
#endif

if (photon.path_cur_cells >= 0) { // if -1, don't save
if (photon.path_cur_cells >= photon.path_max_cells) {
Expand All @@ -320,7 +329,7 @@ double calc_delta_dist (photon_data& photon,
photon.path_pos_index[2].push_back(0);
photon.path_pos_index[3].push_back(0);
photon.path_max_cells++;
}
}
if (photon.path_max_cells < photon.path_cur_cells) {
cout << "photon path # cells is smaller than the current cell number" << endl;
exit(8);
Expand All @@ -331,7 +340,7 @@ double calc_delta_dist (photon_data& photon,
photon.path_pos_index[2][photon.path_cur_cells] = photon.position_index[k][1];
photon.path_pos_index[3][photon.path_cur_cells] = photon.position_index[k][2];

#ifdef DEBUG_CDD
#ifdef DEBUG_CDD
if (photon.number == OUTNUM) {
cout << "path: ";
cout << photon.path_pos_index[0][photon.path_cur_cells] << " ";
Expand All @@ -343,8 +352,8 @@ double calc_delta_dist (photon_data& photon,
#endif
photon.path_cur_cells++;

#ifdef DEBUG_CDD
if (photon.number == OUTNUM)
#ifdef DEBUG_CDD
if (photon.number == OUTNUM)
cout << "photon.path_cur_cells = " << photon.path_cur_cells << endl;
#endif
}
Expand Down Expand Up @@ -412,7 +421,7 @@ double calc_delta_dist (photon_data& photon,
cout << "escape (post check1) = " << escape << endl;
}
#endif

// determine if the photon has left the model while still inside the grid (-1 > dust_tau_per_pc > 0)
if (!escape) {
// if ((photon.position_index[k][min_index] < geometry.grids[photon.grid_number[photon.current_grid_num]].index_dim[min_index]) &&
Expand Down
13 changes: 8 additions & 5 deletions DIRTY/calc_photon_trajectory.cpp
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
// ======================================================================
// Function to calculate the trajectory of a photon. The stopping
// point is either reaching the target optical depth (target_tau) or
// point is either reaching the target optical depth (target_tau) or
// reaching the edge of the distribution (marked by negative optical
// depth between (0 and, but not including -1: integer negative
// depth between (0 and, but not including -1: integer negative
// optical depths denote subgrid indexes.
//
// This function returns the distance traveled.
Expand All @@ -17,11 +17,13 @@
double calc_photon_trajectory (photon_data& photon,
geometry_struct& geometry,
double target_tau,
double target_dist,
int& escape,
double& tau_traveled)

{
double tau_left = target_tau; // reduce till zero = done
double dist_left = target_dist; // reduce till zero = done
#ifdef DEBUG_CPT
if (photon.number == OUTNUM) {
cout << "oooooooooooooooooooooooooooooooooo" << endl;
Expand All @@ -37,7 +39,7 @@ double calc_photon_trajectory (photon_data& photon,
// move through the grid until escaping or reaching the target tau
// need to also handle the case where the photon starts several subgrids down
// multiple calls to calc_photon_trajectory needed
while ((tau_left > ROUNDOFF_ERR_TRIG) && (!escape)) {
while ((tau_left > ROUNDOFF_ERR_TRIG) && (dist_left > ROUNDOFF_ERR_TRIG) && (!escape)) {

#ifdef DEBUG_CPT
if (photon.number == OUTNUM) {
Expand All @@ -51,16 +53,17 @@ double calc_photon_trajectory (photon_data& photon,
cout << photon.num_current_grids << endl;
}
#endif
delta_dist = calc_delta_dist(photon, geometry, tau_left, escape, delta_tau);
delta_dist = calc_delta_dist(photon, geometry, tau_left, dist_left, escape, delta_tau);
#ifdef PHOTON_POS
int i = 0;
for (i = 0; i < 3; i++)
cout << photon.position[i] << " ";
cout << endl;
#endif
#endif
tau_traveled += delta_tau;
tau_left -= delta_tau;
distance_traveled += delta_dist;
dist_left -= delta_dist;
#ifdef DEBUG_CPT
if (photon.number == OUTNUM) {
cout << "cpt: photon.path_cur_cells = " << photon.path_cur_cells << endl;
Expand Down

0 comments on commit 901e6e4

Please sign in to comment.