示例#1
0
int64_t montecarlo_one_packet_loop(storage_model_t *storage, rpacket_t *packet, int64_t virtual_packet)
{
  rpacket_set_tau_event(packet, 0.0);
  rpacket_set_nu_line(packet, 0.0);
  rpacket_set_virtual_packet(packet, virtual_packet);
  rpacket_set_status(packet, TARDIS_PACKET_STATUS_IN_PROCESS);
  // Initializing tau_event if it's a real packet.
  if (virtual_packet == 0)
    {
      rpacket_reset_tau_event(packet);
    }
  // For a virtual packet tau_event is the sum of all the tau's that the packet passes.
  while (rpacket_get_status(packet) == TARDIS_PACKET_STATUS_IN_PROCESS)
    {
      // Check if we are at the end of line list.
      if (!rpacket_get_last_line(packet))
	{
	  rpacket_set_nu_line(packet, storage->line_list_nu[rpacket_get_next_line_id(packet)]);
	}
      double distance;
      get_event_handler(packet, storage, &distance)(packet, storage, distance);
      if (virtual_packet > 0 && rpacket_get_tau_event(packet) > 10.0)
	{
	  rpacket_set_tau_event(packet, 100.0);
	  rpacket_set_status(packet, TARDIS_PACKET_STATUS_EMITTED);
	}
    } 
  if (virtual_packet > 0)
    {
      rpacket_set_energy(packet, rpacket_get_energy(packet) * exp(-1.0 * rpacket_get_tau_event(packet)));
    }
  return rpacket_get_status(packet) == TARDIS_PACKET_STATUS_REABSORBED ? 1 : 0;
}
示例#2
0
void
move_packet_across_shell_boundary (rpacket_t * packet,
                                   storage_model_t * storage, double distance, rk_state *mt_state)
{
  move_packet (packet, storage, distance);
  if (rpacket_get_virtual_packet (packet) > 0)
    {
      double delta_tau_event = rpacket_get_chi_continuum(packet) * distance;
      rpacket_set_tau_event (packet,
                             rpacket_get_tau_event (packet) +
                             delta_tau_event);
    }
  else
    {
      rpacket_reset_tau_event (packet, mt_state);
    }
  if ((rpacket_get_current_shell_id (packet) < storage->no_of_shells - 1
       && rpacket_get_next_shell_id (packet) == 1)
      || (rpacket_get_current_shell_id (packet) > 0
          && rpacket_get_next_shell_id (packet) == -1))
    {
      rpacket_set_current_shell_id (packet,
                                    rpacket_get_current_shell_id (packet) +
                                    rpacket_get_next_shell_id (packet));
    }
  else if (rpacket_get_next_shell_id (packet) == 1)
    {
      rpacket_set_status (packet, TARDIS_PACKET_STATUS_EMITTED);
    }
  else if ((storage->reflective_inner_boundary == 0) ||
           (rk_double (mt_state) > storage->inner_boundary_albedo))
    {
      rpacket_set_status (packet, TARDIS_PACKET_STATUS_REABSORBED);
    }
  else
    {
      double doppler_factor = rpacket_doppler_factor (packet, storage);
      double comov_nu = rpacket_get_nu (packet) * doppler_factor;
      double comov_energy = rpacket_get_energy (packet) * doppler_factor;
      rpacket_set_mu (packet, rk_double (mt_state));
      double inverse_doppler_factor = 1.0 / rpacket_doppler_factor (packet, storage);
      rpacket_set_nu (packet, comov_nu * inverse_doppler_factor);
      rpacket_set_energy (packet, comov_energy * inverse_doppler_factor);
      if (rpacket_get_virtual_packet_flag (packet) > 0)
        {
          montecarlo_one_packet (storage, packet, -2, mt_state);
        }
    }
}
示例#3
0
bool
test_rpacket_get_status(void) {
    rpacket_status_t inProcess = TARDIS_PACKET_STATUS_IN_PROCESS;
    rpacket_status_t emitted = TARDIS_PACKET_STATUS_EMITTED;
    rpacket_status_t reabsorbed = TARDIS_PACKET_STATUS_REABSORBED;

    rpacket_t rp;
    rpacket_set_status(&rp, inProcess);
    bool res=  inProcess==rpacket_get_status(&rp);
    rpacket_set_status(&rp, emitted);
    res &= emitted==rpacket_get_status(&rp);
    rpacket_set_status(&rp, reabsorbed);
    res &= reabsorbed==rpacket_get_status(&rp);
    return res;
}
示例#4
0
/* initialise RPacket */
static void init_rpacket(rpacket_t *rp){
	double MU = 0.3;
	double R = 7.5e14;
	double ENERGY = 0.9;
	int NEXT_LINE_ID = 1;
	double NU = 0.4;
	double NU_LINE = 0.2;
	int CURRENT_SHELL_ID = 0;

	double TAU_EVENT = 2.9e13;

	rpacket_set_current_shell_id(rp, CURRENT_SHELL_ID);
	rpacket_set_next_shell_id(rp, CURRENT_SHELL_ID+1);
	rpacket_set_mu(rp, MU);
	rpacket_set_nu(rp, NU);
	rpacket_set_r(rp, R);
	rpacket_set_last_line(rp, false);
	rpacket_set_recently_crossed_boundary(rp, 1);

	rpacket_set_close_line(rp, false);
	rpacket_set_nu_line(rp, NU_LINE);

	rpacket_set_next_line_id(rp, NEXT_LINE_ID);

	rpacket_set_tau_event(rp, TAU_EVENT);
	rpacket_set_virtual_packet(rp, 0);
	rpacket_set_energy(rp, ENERGY);
	rpacket_set_virtual_packet_flag(rp, true);
	rpacket_set_status(rp, TARDIS_PACKET_STATUS_IN_PROCESS);
	rpacket_set_id(rp, 0);

	rpacket_set_current_continuum_id(rp, 1);
}
示例#5
0
void move_packet_across_shell_boundary(rpacket_t *packet, storage_model_t *storage, double distance)
{
  double comov_energy, doppler_factor, comov_nu, inverse_doppler_factor;
  move_packet(packet, storage, distance);
  if (rpacket_get_virtual_packet(packet) > 0)
    {
      double delta_tau_event = distance * 
	storage->electron_densities[rpacket_get_current_shell_id(packet)] * 
	storage->sigma_thomson;
      rpacket_set_tau_event(packet, rpacket_get_tau_event(packet) + delta_tau_event);
    }
  else
    {
      rpacket_reset_tau_event(packet);
    }
  if ((rpacket_get_current_shell_id(packet) < storage->no_of_shells - 1 && rpacket_get_next_shell_id(packet) == 1) || 
      (rpacket_get_current_shell_id(packet) > 0 && rpacket_get_next_shell_id(packet) == -1))
    {
      rpacket_set_current_shell_id(packet, rpacket_get_current_shell_id(packet) + rpacket_get_next_shell_id(packet));
      rpacket_set_recently_crossed_boundary(packet, rpacket_get_next_shell_id(packet));
    }
  else if (rpacket_get_next_shell_id(packet) == 1)
    {
      rpacket_set_status(packet, TARDIS_PACKET_STATUS_EMITTED);
    }
  else if ((storage->reflective_inner_boundary == 0) || 
	   (rk_double(&mt_state) > storage->inner_boundary_albedo))
    {
      rpacket_set_status(packet, TARDIS_PACKET_STATUS_REABSORBED);
    }
  else
    {
      doppler_factor = rpacket_doppler_factor(packet, storage);
      comov_nu = rpacket_get_nu(packet) * doppler_factor;
      comov_energy = rpacket_get_energy(packet) * doppler_factor;
      rpacket_set_mu(packet, rk_double(&mt_state));
      inverse_doppler_factor = 1.0 / rpacket_doppler_factor(packet, storage);
      rpacket_set_nu(packet, comov_nu * inverse_doppler_factor);
      rpacket_set_energy(packet, comov_energy * inverse_doppler_factor);
      rpacket_set_recently_crossed_boundary(packet, 1);
      if (rpacket_get_virtual_packet_flag(packet) > 0)
	{
	  montecarlo_one_packet(storage, packet, -2);
	}
    }
}
示例#6
0
void
montecarlo_bound_free_scatter (rpacket_t * packet, storage_model_t * storage, double distance, rk_state *mt_state)
{
  /* current position in list of continuum edges -> indicates which bound-free processes are possible */
  int64_t current_continuum_id = rpacket_get_current_continuum_id(packet);

  // Determine in which continuum the bf-absorption occurs
  double nu = rpacket_get_nu(packet);
  double chi_bf = rpacket_get_chi_boundfree(packet);
  // get new zrand
  double zrand = rk_double(mt_state);
  double zrand_x_chibf = zrand * chi_bf;

  int64_t ccontinuum = current_continuum_id; /* continuum_id of the continuum in which bf-absorption occurs */

  while (storage->chi_bf_tmp_partial[ccontinuum] <= zrand_x_chibf)
    {
      ccontinuum++;
    }
  //  Alternative way to choose a continuum for bf-absorption:
  //  error =
  //  binary_search(storage->chi_bf_tmp_partial, zrand_x_chibf, current_continuum_id,no_of_continuum_edges-1,&ccontinuum);
  //  if (error == TARDIS_ERROR_BOUNDS_ERROR) // x_insert < x[imin] -> set index equal to imin
  //   {
  //      ccontinuum = current_continuum_id;
  //   }

  zrand = rk_double(mt_state);
  if (zrand < storage->continuum_list_nu[ccontinuum] / nu)
    {
      // go to ionization energy
      rpacket_set_status (packet, TARDIS_PACKET_STATUS_REABSORBED);
    }
  else
    {
      //go to the thermal pool
      //create_kpacket(packet);
      rpacket_set_status (packet, TARDIS_PACKET_STATUS_REABSORBED);
    }
}
示例#7
0
void
montecarlo_free_free_scatter(rpacket_t * packet, storage_model_t * storage, double distance, rk_state *mt_state)
{
  rpacket_set_status (packet, TARDIS_PACKET_STATUS_REABSORBED);
}