Cholla 3.0.1-dev
Cholla - Massively parallel hydro on GPUs
Loading...
Searching...
No Matches
Functions
dual_energy.h File Reference

Declaration/implementation of functions used in dual-energy formalism. More...

#include "../global/global.h"
#include "../grid/grid_enum.h"
#include "../hydro/hydro_cuda.h"
#include "../utils/basic_structs.h"
Include dependency graph for dual_energy.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Functions

template<int NDim>
__global__ void dual_energy::Select_Internal_Energy (Real *dev_conserved, hydro_utilities::VectorXYZ< int > grid_shape, int n_ghost, int n_fields)
 
template<int NDim>
__global__ void dual_energy::Sync_Energies (Real *dev_conserved, hydro_utilities::VectorXYZ< int > grid_shape, int n_ghost, int n_fields)
 

Detailed Description

Declaration/implementation of functions used in dual-energy formalism.

Note
A major goal of this file is to provide 1 implementation of each function that can be used for 1, 2, or 3 dimensions. Previously, we maintained a different versions of each function for each number of dimensions. There are 3 particular factors that strongly motivate this goal:
  1. MOST IMPORTANTLY, it is very hard to come up with robust test-problems for the dual-energy formalism. Additionally, maintaining 3 variants of a function always invites mistakes. While we maintain 3 implementations of lots of other functions, those implementations are either simpler or are a lot easier to test.
  2. The dual energy formalism has a lot of subtlties and we make an extension to it. I'd argue that this makes mistakes more likely here than in other sections of the code.
  3. We sometimes need to make adjustments to the formalism based on scenarios only encountered in 3D. When leaving comments explaining why we implement a particular action (or an action in a particular way), that means that we need to leave slightly different versions of the same comment in 1D/2D vs 3D implementations.

Function Documentation

◆ Select_Internal_Energy()

template<int NDim>
__global__ void dual_energy::Select_Internal_Energy ( Real *  dev_conserved,
hydro_utilities::VectorXYZ< int >  grid_shape,
int  n_ghost,
int  n_fields 
)

Overwrites the total energy with the sum of the internal energy and the kinetic energy

Template Parameters
NDimThe number of dimensions

\param[in,out] dev_conserved Pointer to the conserved quantities on the device

Parameters
[in]grid_shapeSpecifies the shape of the grid (including ghost zones). Values along unused dimensions aren't used.
[in]n_ghostThe number of ghost zones (along each used dimension)
[in]gammaThe adiabatic index
[in]n_fieldsThe number of fields used in the current simulation.
Note
The scenario where E > 0 and E doesn't exceed the kinetic energy (i.e. U_total <= 0), comes up with some frequency when we include particle feedback.
  • in that scenario, we explicitly use the value held by the U_advected field
  • in the separate Sync_Energies_3D kernel, we then override the E field with KE + U_advected
  • one might argue we should actually override the E field with KE + U_advected before this kernel (we leave that for future consideration)
  • regardless, it is REALLY IMPORTANT that the E field is NOT modified in this kernel (modifying it will produce race conditions!!!)

◆ Sync_Energies()

template<int NDim>
__global__ void dual_energy::Sync_Energies ( Real *  dev_conserved,
hydro_utilities::VectorXYZ< int >  grid_shape,
int  n_ghost,
int  n_fields 
)

Overwrites the total energy with the sum of the internal energy and the kinetic energy

This functionality MUST be invoke in a separate kernel from the functionality implemented by Select_Internal_Energy in order to avoid race-conditions (the race-conditions would interfere with the energy selection in the other function).

Template Parameters
NDimThe number of dimensions

\param[in,out] dev_conserved Pointer to the conserved quantities on the device

Parameters
[in]grid_shapeSpecifies the shape of the grid (including ghost zones). Values along unused dimensions aren't used.
[in]n_ghostThe number of ghost zones (along each used dimension)
[in]n_fieldsThe number of fields used in the current simulation.
Note
This is not technically a part of the dual energy formalism. But it is a common extension.